blob: e5224dc5a38f2566baa0cfbbd188724e7190d376 [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. */
1605 if (old_select && old_select == new_select)
1606 {
1607 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001608 {
Josh Bailey8196f132011-07-20 20:47:07 -07001609 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1610 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001611 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001612
Josh Bailey8196f132011-07-20 20:47:07 -07001613 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001614 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1615 return WQ_SUCCESS;
1616 }
paulfee0f4c2004-09-13 05:12:46 +00001617 }
paul718e3742002-12-13 20:15:29 +00001618
hasso338b3422005-02-23 14:27:24 +00001619 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001620 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001621 if (new_select)
1622 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001623 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1624 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001625 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001626 }
1627
1628
paul718e3742002-12-13 20:15:29 +00001629 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001630 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001631 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001632 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001633 }
1634
1635 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001636 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1637 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001638 {
1639 if (new_select
1640 && new_select->type == ZEBRA_ROUTE_BGP
1641 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001642 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001643 else
1644 {
1645 /* Withdraw the route from the kernel. */
1646 if (old_select
1647 && old_select->type == ZEBRA_ROUTE_BGP
1648 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001649 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001650 }
1651 }
paulb40d9392005-08-22 22:34:41 +00001652
Lou Berger050defe2016-01-12 13:41:59 -05001653 /* Reap old select bgp_info, if it has been removed */
paulb40d9392005-08-22 22:34:41 +00001654 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1655 bgp_info_reap (rn, old_select);
1656
paul200df112005-06-01 11:17:05 +00001657 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1658 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001659}
1660
paul200df112005-06-01 11:17:05 +00001661static void
paul0fb58d52005-11-14 14:31:49 +00001662bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001663{
paul0fb58d52005-11-14 14:31:49 +00001664 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001665 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001666
Chris Caputo228da422009-07-18 05:44:03 +00001667 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001668 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001669 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001670 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1671}
1672
1673static void
1674bgp_process_queue_init (void)
1675{
1676 bm->process_main_queue
1677 = work_queue_new (bm->master, "process_main_queue");
1678 bm->process_rsclient_queue
1679 = work_queue_new (bm->master, "process_rsclient_queue");
1680
1681 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1682 {
1683 zlog_err ("%s: Failed to allocate work queue", __func__);
1684 exit (1);
1685 }
1686
1687 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001688 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001689 bm->process_main_queue->spec.max_retries = 0;
1690 bm->process_main_queue->spec.hold = 50;
1691
Paul Jakma838bbde2010-01-08 14:05:32 +00001692 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
David Lamparterd43f8b32015-03-03 08:54:54 +01001693 bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del;
1694 bm->process_rsclient_queue->spec.max_retries = 0;
1695 bm->process_rsclient_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001696}
1697
1698void
paulfee0f4c2004-09-13 05:12:46 +00001699bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1700{
paul200df112005-06-01 11:17:05 +00001701 struct bgp_process_queue *pqnode;
1702
1703 /* already scheduled for processing? */
1704 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1705 return;
1706
Paul Jakma91b9e852015-12-01 14:32:11 +00001707 if (rn->info == NULL)
1708 {
1709 /* XXX: Perhaps remove before next release, after we've flushed out
1710 * any obvious cases
1711 */
1712 assert (rn->info != NULL);
1713 char buf[PREFIX_STRLEN];
1714 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1715 __func__,
1716 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1717 return;
1718 }
1719
paul200df112005-06-01 11:17:05 +00001720 if ( (bm->process_main_queue == NULL) ||
1721 (bm->process_rsclient_queue == NULL) )
1722 bgp_process_queue_init ();
1723
1724 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1725 sizeof (struct bgp_process_queue));
1726 if (!pqnode)
1727 return;
Chris Caputo228da422009-07-18 05:44:03 +00001728
1729 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001730 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001731 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001732 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001733 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001734 pqnode->afi = afi;
1735 pqnode->safi = safi;
1736
Avneesh Sachdev67174042012-08-17 08:19:49 -07001737 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001738 {
paul200df112005-06-01 11:17:05 +00001739 case BGP_TABLE_MAIN:
1740 work_queue_add (bm->process_main_queue, pqnode);
1741 break;
1742 case BGP_TABLE_RSCLIENT:
1743 work_queue_add (bm->process_rsclient_queue, pqnode);
1744 break;
paulfee0f4c2004-09-13 05:12:46 +00001745 }
paul200df112005-06-01 11:17:05 +00001746
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001747 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001748 return;
paulfee0f4c2004-09-13 05:12:46 +00001749}
hasso0a486e52005-02-01 20:57:17 +00001750
paul94f2b392005-06-28 12:44:16 +00001751static int
hasso0a486e52005-02-01 20:57:17 +00001752bgp_maximum_prefix_restart_timer (struct thread *thread)
1753{
1754 struct peer *peer;
1755
1756 peer = THREAD_ARG (thread);
1757 peer->t_pmax_restart = NULL;
1758
1759 if (BGP_DEBUG (events, EVENTS))
1760 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1761 peer->host);
1762
1763 peer_clear (peer);
1764
1765 return 0;
1766}
1767
paulfee0f4c2004-09-13 05:12:46 +00001768int
paul5228ad22004-06-04 17:58:18 +00001769bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1770 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001771{
hassoe0701b72004-05-20 09:19:34 +00001772 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1773 return 0;
1774
1775 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001776 {
hassoe0701b72004-05-20 09:19:34 +00001777 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1778 && ! always)
1779 return 0;
paul718e3742002-12-13 20:15:29 +00001780
hassoe0701b72004-05-20 09:19:34 +00001781 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001782 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1783 "limit %ld", afi_safi_print (afi, safi), peer->host,
1784 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001785 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001786
hassoe0701b72004-05-20 09:19:34 +00001787 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1788 return 0;
paul718e3742002-12-13 20:15:29 +00001789
hassoe0701b72004-05-20 09:19:34 +00001790 {
paul5228ad22004-06-04 17:58:18 +00001791 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001792
1793 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001794 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001795
1796 ndata[0] = (afi >> 8);
1797 ndata[1] = afi;
1798 ndata[2] = safi;
1799 ndata[3] = (peer->pmax[afi][safi] >> 24);
1800 ndata[4] = (peer->pmax[afi][safi] >> 16);
1801 ndata[5] = (peer->pmax[afi][safi] >> 8);
1802 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001803
1804 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1805 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1806 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1807 }
hasso0a486e52005-02-01 20:57:17 +00001808
1809 /* restart timer start */
1810 if (peer->pmax_restart[afi][safi])
1811 {
1812 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1813
1814 if (BGP_DEBUG (events, EVENTS))
1815 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1816 peer->host, peer->v_pmax_restart);
1817
1818 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1819 peer->v_pmax_restart);
1820 }
1821
hassoe0701b72004-05-20 09:19:34 +00001822 return 1;
paul718e3742002-12-13 20:15:29 +00001823 }
hassoe0701b72004-05-20 09:19:34 +00001824 else
1825 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1826
1827 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1828 {
1829 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1830 && ! always)
1831 return 0;
1832
1833 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001834 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1835 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1836 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001837 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1838 }
1839 else
1840 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001841 return 0;
1842}
1843
paulb40d9392005-08-22 22:34:41 +00001844/* Unconditionally remove the route from the RIB, without taking
1845 * damping into consideration (eg, because the session went down)
1846 */
paul94f2b392005-06-28 12:44:16 +00001847static void
paul718e3742002-12-13 20:15:29 +00001848bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1849 afi_t afi, safi_t safi)
1850{
paul902212c2006-02-05 17:51:19 +00001851 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1852
1853 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1854 bgp_info_delete (rn, ri); /* keep historical info */
1855
paulb40d9392005-08-22 22:34:41 +00001856 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001857}
1858
paul94f2b392005-06-28 12:44:16 +00001859static void
paul718e3742002-12-13 20:15:29 +00001860bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
Lou Berger050defe2016-01-12 13:41:59 -05001861 afi_t afi, safi_t safi, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00001862{
paul718e3742002-12-13 20:15:29 +00001863 int status = BGP_DAMP_NONE;
1864
paulb40d9392005-08-22 22:34:41 +00001865 /* apply dampening, if result is suppressed, we'll be retaining
1866 * the bgp_info in the RIB for historical reference.
1867 */
1868 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001869 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001870 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1871 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001872 {
paul902212c2006-02-05 17:51:19 +00001873 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1874 return;
1875 }
1876
1877 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001878}
1879
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05001880static struct bgp_info *
1881info_make (int type, int sub_type, struct peer *peer, struct attr *attr,
1882 struct bgp_node *rn)
1883{
1884 struct bgp_info *new;
1885
1886 /* Make new BGP info. */
1887 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
1888 new->type = type;
1889 new->sub_type = sub_type;
1890 new->peer = peer;
1891 new->attr = attr;
1892 new->uptime = bgp_clock ();
1893 new->net = rn;
1894 return new;
1895}
1896
paul94f2b392005-06-28 12:44:16 +00001897static void
paulfee0f4c2004-09-13 05:12:46 +00001898bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1899 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1900 int sub_type, struct prefix_rd *prd, u_char *tag)
1901{
1902 struct bgp_node *rn;
1903 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001904 struct attr new_attr;
1905 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001906 struct attr *attr_new;
1907 struct attr *attr_new2;
1908 struct bgp_info *ri;
1909 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001910 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001911 char buf[SU_ADDRSTRLEN];
1912
1913 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1914 if (peer == rsclient)
1915 return;
1916
1917 bgp = peer->bgp;
1918 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1919
1920 /* Check previously received route. */
1921 for (ri = rn->info; ri; ri = ri->next)
1922 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1923 break;
1924
1925 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001926 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001927 {
1928 reason = "as-path contains our own AS;";
1929 goto filtered;
1930 }
1931
1932 /* Route reflector originator ID check. */
1933 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001934 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001935 {
1936 reason = "originator is us;";
1937 goto filtered;
1938 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001939
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001940 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001941 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001942
1943 /* Apply export policy. */
1944 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1945 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1946 {
1947 reason = "export-policy;";
1948 goto filtered;
1949 }
1950
1951 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001952
paulfee0f4c2004-09-13 05:12:46 +00001953 /* Apply import policy. */
1954 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1955 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001956 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001957
1958 reason = "import-policy;";
1959 goto filtered;
1960 }
1961
1962 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001963 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001964
1965 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001966 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001967 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001968 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001969 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001970 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001971 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001972 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001973
1974 reason = "martian next-hop;";
1975 goto filtered;
1976 }
1977 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001978
paulfee0f4c2004-09-13 05:12:46 +00001979 /* If the update is implicit withdraw. */
1980 if (ri)
1981 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001982 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001983
1984 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001985 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1986 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001987 {
1988
Paul Jakma1a392d42006-09-07 00:24:49 +00001989 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001990
1991 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001992 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001993 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1994 peer->host,
1995 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1996 p->prefixlen, rsclient->host);
1997
Chris Caputo228da422009-07-18 05:44:03 +00001998 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001999 bgp_attr_unintern (&attr_new);
Lou Berger050defe2016-01-12 13:41:59 -05002000 bgp_attr_flush(&new_attr);
Chris Caputo228da422009-07-18 05:44:03 +00002001 return;
paulfee0f4c2004-09-13 05:12:46 +00002002 }
2003
Paul Jakma16d2e242007-04-10 19:32:10 +00002004 /* Withdraw/Announce before we fully processed the withdraw */
2005 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2006 bgp_info_restore (rn, ri);
2007
paulfee0f4c2004-09-13 05:12:46 +00002008 /* Received Logging. */
2009 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002010 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002011 peer->host,
2012 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2013 p->prefixlen, rsclient->host);
2014
2015 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002016 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00002017
2018 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002019 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00002020 ri->attr = attr_new;
2021
2022 /* Update MPLS tag. */
2023 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002024 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002025
Paul Jakma1a392d42006-09-07 00:24:49 +00002026 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002027
2028 /* Process change. */
2029 bgp_process (bgp, rn, afi, safi);
2030 bgp_unlock_node (rn);
2031
2032 return;
2033 }
2034
2035 /* Received Logging. */
2036 if (BGP_DEBUG (update, UPDATE_IN))
2037 {
ajsd2c1f162004-12-08 21:10:20 +00002038 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002039 peer->host,
2040 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2041 p->prefixlen, rsclient->host);
2042 }
2043
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05002044 new = info_make(type, sub_type, peer, attr_new, rn);
paulfee0f4c2004-09-13 05:12:46 +00002045
2046 /* Update MPLS tag. */
2047 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002048 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002049
Paul Jakma1a392d42006-09-07 00:24:49 +00002050 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002051
2052 /* Register new BGP information. */
2053 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002054
2055 /* route_node_get lock */
2056 bgp_unlock_node (rn);
2057
paulfee0f4c2004-09-13 05:12:46 +00002058 /* Process change. */
2059 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002060
paulfee0f4c2004-09-13 05:12:46 +00002061 return;
2062
2063 filtered:
2064
2065 /* This BGP update is filtered. Log the reason then update BGP entry. */
2066 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002067 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002068 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2069 peer->host,
2070 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2071 p->prefixlen, rsclient->host, reason);
2072
2073 if (ri)
paulb40d9392005-08-22 22:34:41 +00002074 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002075
2076 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002077
paulfee0f4c2004-09-13 05:12:46 +00002078 return;
2079}
2080
paul94f2b392005-06-28 12:44:16 +00002081static void
paulfee0f4c2004-09-13 05:12:46 +00002082bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2083 struct peer *peer, struct prefix *p, int type, int sub_type,
2084 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002085{
paulfee0f4c2004-09-13 05:12:46 +00002086 struct bgp_node *rn;
2087 struct bgp_info *ri;
2088 char buf[SU_ADDRSTRLEN];
2089
2090 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002091 return;
paulfee0f4c2004-09-13 05:12:46 +00002092
2093 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2094
2095 /* Lookup withdrawn route. */
2096 for (ri = rn->info; ri; ri = ri->next)
2097 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2098 break;
2099
2100 /* Withdraw specified route from routing table. */
2101 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Lou Berger050defe2016-01-12 13:41:59 -05002102 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
paulfee0f4c2004-09-13 05:12:46 +00002103 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002104 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002105 "%s Can't find the route %s/%d", peer->host,
2106 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2107 p->prefixlen);
2108
2109 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002110 bgp_unlock_node (rn);
2111}
paulfee0f4c2004-09-13 05:12:46 +00002112
paul94f2b392005-06-28 12:44:16 +00002113static int
paulfee0f4c2004-09-13 05:12:46 +00002114bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002115 afi_t afi, safi_t safi, int type, int sub_type,
2116 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2117{
2118 int ret;
2119 int aspath_loop_count = 0;
2120 struct bgp_node *rn;
2121 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002122 struct attr new_attr;
2123 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002124 struct attr *attr_new;
2125 struct bgp_info *ri;
2126 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002127 const char *reason;
paul718e3742002-12-13 20:15:29 +00002128 char buf[SU_ADDRSTRLEN];
2129
Lou Berger370b7e52016-02-04 21:29:49 -05002130 memset (&new_attr, 0, sizeof(struct attr));
2131 memset (&new_extra, 0, sizeof(struct attr_extra));
2132
paul718e3742002-12-13 20:15:29 +00002133 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002134 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002135
paul718e3742002-12-13 20:15:29 +00002136 /* When peer's soft reconfiguration enabled. Record input packet in
2137 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002138 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2139 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002140 bgp_adj_in_set (rn, peer, attr);
2141
2142 /* Check previously received route. */
2143 for (ri = rn->info; ri; ri = ri->next)
2144 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2145 break;
2146
2147 /* AS path local-as loop check. */
2148 if (peer->change_local_as)
2149 {
2150 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2151 aspath_loop_count = 1;
2152
2153 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2154 {
2155 reason = "as-path contains our own AS;";
2156 goto filtered;
2157 }
2158 }
2159
2160 /* AS path loop check. */
2161 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2162 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2163 && aspath_loop_check(attr->aspath, bgp->confed_id)
2164 > peer->allowas_in[afi][safi]))
2165 {
2166 reason = "as-path contains our own AS;";
2167 goto filtered;
2168 }
2169
2170 /* Route reflector originator ID check. */
2171 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002172 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002173 {
2174 reason = "originator is us;";
2175 goto filtered;
2176 }
2177
2178 /* Route reflector cluster ID check. */
2179 if (bgp_cluster_filter (peer, attr))
2180 {
2181 reason = "reflected from the same cluster;";
2182 goto filtered;
2183 }
2184
2185 /* Apply incoming filter. */
2186 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2187 {
2188 reason = "filter;";
2189 goto filtered;
2190 }
2191
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002192 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002193 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002194
David Lamparterc460e572014-06-04 00:54:58 +02002195 /* Apply incoming route-map.
2196 * NB: new_attr may now contain newly allocated values from route-map "set"
2197 * commands, so we need bgp_attr_flush in the error paths, until we intern
2198 * the attr (which takes over the memory references) */
paul718e3742002-12-13 20:15:29 +00002199 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2200 {
2201 reason = "route-map;";
David Lamparterc460e572014-06-04 00:54:58 +02002202 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002203 goto filtered;
2204 }
2205
2206 /* IPv4 unicast next hop check. */
2207 if (afi == AFI_IP && safi == SAFI_UNICAST)
2208 {
2209 /* If the peer is EBGP and nexthop is not on connected route,
2210 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002211 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002212 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002213 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002214 {
2215 reason = "non-connected next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002216 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002217 goto filtered;
2218 }
2219
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002220 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002221 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002222 if (new_attr.nexthop.s_addr == 0
2223 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2224 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002225 {
2226 reason = "martian next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002227 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002228 goto filtered;
2229 }
2230 }
2231
2232 attr_new = bgp_attr_intern (&new_attr);
2233
2234 /* If the update is implicit withdraw. */
2235 if (ri)
2236 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002237 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002238
2239 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002240 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2241 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002242 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002243 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002244
2245 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002246 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002247 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2248 {
2249 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002250 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002251 peer->host,
2252 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2253 p->prefixlen);
2254
paul902212c2006-02-05 17:51:19 +00002255 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2256 {
2257 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2258 bgp_process (bgp, rn, afi, safi);
2259 }
paul718e3742002-12-13 20:15:29 +00002260 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002261 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002262 {
2263 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002264 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002265 "%s rcvd %s/%d...duplicate ignored",
2266 peer->host,
2267 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2268 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002269
2270 /* graceful restart STALE flag unset. */
2271 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2272 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002273 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002274 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002275 }
paul718e3742002-12-13 20:15:29 +00002276 }
2277
2278 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002279 bgp_attr_unintern (&attr_new);
Lou Berger050defe2016-01-12 13:41:59 -05002280 bgp_attr_flush (&new_attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002281
paul718e3742002-12-13 20:15:29 +00002282 return 0;
2283 }
2284
Paul Jakma16d2e242007-04-10 19:32:10 +00002285 /* Withdraw/Announce before we fully processed the withdraw */
2286 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2287 {
2288 if (BGP_DEBUG (update, UPDATE_IN))
2289 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2290 peer->host,
2291 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2292 p->prefixlen);
2293 bgp_info_restore (rn, ri);
2294 }
2295
paul718e3742002-12-13 20:15:29 +00002296 /* Received Logging. */
2297 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002298 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002299 peer->host,
2300 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2301 p->prefixlen);
2302
hasso93406d82005-02-02 14:40:33 +00002303 /* graceful restart STALE flag unset. */
2304 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002305 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002306
paul718e3742002-12-13 20:15:29 +00002307 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002308 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002309
2310 /* implicit withdraw, decrement aggregate and pcount here.
2311 * only if update is accepted, they'll increment below.
2312 */
paul902212c2006-02-05 17:51:19 +00002313 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2314
paul718e3742002-12-13 20:15:29 +00002315 /* Update bgp route dampening information. */
2316 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002317 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002318 {
2319 /* This is implicit withdraw so we should update dampening
2320 information. */
2321 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2322 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002323 }
2324
paul718e3742002-12-13 20:15:29 +00002325 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002326 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002327 ri->attr = attr_new;
2328
2329 /* Update MPLS tag. */
2330 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002331 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002332
Lou Berger050defe2016-01-12 13:41:59 -05002333 bgp_attr_flush (&new_attr);
2334
paul718e3742002-12-13 20:15:29 +00002335 /* Update bgp route dampening information. */
2336 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002337 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002338 {
2339 /* Now we do normal update dampening. */
2340 ret = bgp_damp_update (ri, rn, afi, safi);
2341 if (ret == BGP_DAMP_SUPPRESSED)
2342 {
2343 bgp_unlock_node (rn);
2344 return 0;
2345 }
2346 }
2347
2348 /* Nexthop reachability check. */
2349 if ((afi == AFI_IP || afi == AFI_IP6)
2350 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002351 && (peer->sort == BGP_PEER_IBGP
2352 || peer->sort == BGP_PEER_CONFED
2353 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002354 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002355 {
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05002356 if (bgp_find_or_add_nexthop (afi, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002357 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002358 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002359 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002360 }
2361 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002362 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002363
Lou Berger050defe2016-01-12 13:41:59 -05002364 bgp_attr_flush (&new_attr);
2365
paul718e3742002-12-13 20:15:29 +00002366 /* Process change. */
2367 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2368
2369 bgp_process (bgp, rn, afi, safi);
2370 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002371
paul718e3742002-12-13 20:15:29 +00002372 return 0;
2373 }
2374
2375 /* Received Logging. */
2376 if (BGP_DEBUG (update, UPDATE_IN))
2377 {
ajsd2c1f162004-12-08 21:10:20 +00002378 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002379 peer->host,
2380 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2381 p->prefixlen);
2382 }
2383
paul718e3742002-12-13 20:15:29 +00002384 /* Make new BGP info. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05002385 new = info_make(type, sub_type, peer, attr_new, rn);
paul718e3742002-12-13 20:15:29 +00002386
2387 /* Update MPLS tag. */
2388 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002389 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002390
2391 /* Nexthop reachability check. */
2392 if ((afi == AFI_IP || afi == AFI_IP6)
2393 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002394 && (peer->sort == BGP_PEER_IBGP
2395 || peer->sort == BGP_PEER_CONFED
2396 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002397 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002398 {
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05002399 if (bgp_find_or_add_nexthop (afi, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002400 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002401 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002402 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002403 }
2404 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002405 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002406
paul902212c2006-02-05 17:51:19 +00002407 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002408 bgp_aggregate_increment (bgp, p, new, afi, safi);
2409
2410 /* Register new BGP information. */
2411 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002412
2413 /* route_node_get lock */
2414 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002415
Lou Berger050defe2016-01-12 13:41:59 -05002416 bgp_attr_flush (&new_attr);
2417
paul718e3742002-12-13 20:15:29 +00002418 /* If maximum prefix count is configured and current prefix
2419 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002420 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2421 return -1;
paul718e3742002-12-13 20:15:29 +00002422
2423 /* Process change. */
2424 bgp_process (bgp, rn, afi, safi);
2425
2426 return 0;
2427
2428 /* This BGP update is filtered. Log the reason then update BGP
2429 entry. */
2430 filtered:
2431 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002432 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002433 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2434 peer->host,
2435 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2436 p->prefixlen, reason);
2437
2438 if (ri)
paulb40d9392005-08-22 22:34:41 +00002439 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002440
2441 bgp_unlock_node (rn);
Lou Berger050defe2016-01-12 13:41:59 -05002442 bgp_attr_flush (&new_attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002443
paul718e3742002-12-13 20:15:29 +00002444 return 0;
2445}
2446
2447int
paulfee0f4c2004-09-13 05:12:46 +00002448bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2449 afi_t afi, safi_t safi, int type, int sub_type,
2450 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2451{
2452 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002453 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002454 struct bgp *bgp;
2455 int ret;
2456
2457 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2458 soft_reconfig);
2459
2460 bgp = peer->bgp;
2461
2462 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002463 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002464 {
2465 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2466 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2467 sub_type, prd, tag);
2468 }
2469
2470 return ret;
2471}
2472
2473int
paul718e3742002-12-13 20:15:29 +00002474bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002475 afi_t afi, safi_t safi, int type, int sub_type,
2476 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002477{
2478 struct bgp *bgp;
2479 char buf[SU_ADDRSTRLEN];
2480 struct bgp_node *rn;
2481 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002482 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002483 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002484
2485 bgp = peer->bgp;
2486
David Lamparter4584c232015-04-13 09:50:00 +02002487 /* Lookup node. */
2488 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2489
2490 /* Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2491 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2492 * the iteration over all RS clients.
2493 * Since we need to remove the entry from adj_in anyway, do that first and
2494 * if there was no entry, we don't need to do anything more. */
2495 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2496 && peer != bgp->peer_self)
2497 if (!bgp_adj_in_unset (rn, peer))
2498 {
2499 if (BGP_DEBUG (update, UPDATE_IN))
2500 zlog (peer->log, LOG_DEBUG, "%s withdrawing route %s/%d "
2501 "not in adj-in", peer->host,
2502 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2503 p->prefixlen);
2504 bgp_unlock_node (rn);
2505 return 0;
2506 }
2507
paulfee0f4c2004-09-13 05:12:46 +00002508 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002509 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002510 {
2511 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2512 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2513 }
2514
paul718e3742002-12-13 20:15:29 +00002515 /* Logging. */
2516 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002517 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002518 peer->host,
2519 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2520 p->prefixlen);
2521
paul718e3742002-12-13 20:15:29 +00002522 /* Lookup withdrawn route. */
2523 for (ri = rn->info; ri; ri = ri->next)
2524 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2525 break;
2526
2527 /* Withdraw specified route from routing table. */
2528 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Lou Berger050defe2016-01-12 13:41:59 -05002529 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
paul718e3742002-12-13 20:15:29 +00002530 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002531 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002532 "%s Can't find the route %s/%d", peer->host,
2533 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2534 p->prefixlen);
2535
2536 /* Unlock bgp_node_get() lock. */
2537 bgp_unlock_node (rn);
2538
2539 return 0;
2540}
David Lamparter6b0655a2014-06-04 06:53:35 +02002541
paul718e3742002-12-13 20:15:29 +00002542void
2543bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2544{
2545 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002546 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002547 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002548 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002549 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002550 struct bgp_node *rn;
2551 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002552 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002553
Paul Jakmab2497022007-06-14 11:17:58 +00002554 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002555 return;
2556
paul718e3742002-12-13 20:15:29 +00002557 bgp = peer->bgp;
2558 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002559
paul718e3742002-12-13 20:15:29 +00002560 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2561 aspath = attr.aspath;
2562 attr.local_pref = bgp->default_local_pref;
2563 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2564
2565 if (afi == AFI_IP)
2566 str2prefix ("0.0.0.0/0", &p);
paul718e3742002-12-13 20:15:29 +00002567 else if (afi == AFI_IP6)
2568 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002569 struct attr_extra *ae = attr.extra;
2570
paul718e3742002-12-13 20:15:29 +00002571 str2prefix ("::/0", &p);
2572
2573 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002574 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002575 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002576 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002577
2578 /* If the peer is on shared nextwork and we have link-local
2579 nexthop set it. */
2580 if (peer->shared_network
2581 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2582 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002583 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002584 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002585 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002586 }
2587 }
paul718e3742002-12-13 20:15:29 +00002588
2589 if (peer->default_rmap[afi][safi].name)
2590 {
paulfee0f4c2004-09-13 05:12:46 +00002591 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002592 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2593 {
2594 for (ri = rn->info; ri; ri = ri->next)
2595 {
2596 struct attr dummy_attr;
2597 struct attr_extra dummy_extra;
2598 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002599
Christian Frankedcab1bb2012-12-07 16:45:52 +00002600 /* Provide dummy so the route-map can't modify the attributes */
2601 dummy_attr.extra = &dummy_extra;
2602 bgp_attr_dup(&dummy_attr, ri->attr);
2603 info.peer = ri->peer;
2604 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002605
Christian Frankedcab1bb2012-12-07 16:45:52 +00002606 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2607 RMAP_BGP, &info);
2608
2609 /* The route map might have set attributes. If we don't flush them
2610 * here, they will be leaked. */
2611 bgp_attr_flush(&dummy_attr);
2612 if (ret != RMAP_DENYMATCH)
2613 break;
2614 }
2615 if (ret != RMAP_DENYMATCH)
2616 break;
2617 }
paulfee0f4c2004-09-13 05:12:46 +00002618 bgp->peer_self->rmap_type = 0;
2619
paul718e3742002-12-13 20:15:29 +00002620 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002621 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002622 }
2623
2624 if (withdraw)
2625 {
2626 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2627 bgp_default_withdraw_send (peer, afi, safi);
2628 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2629 }
2630 else
2631 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002632 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2633 {
2634 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2635 bgp_default_update_send (peer, &attr, afi, safi, from);
2636 }
paul718e3742002-12-13 20:15:29 +00002637 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002638
2639 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002640 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002641}
David Lamparter6b0655a2014-06-04 06:53:35 +02002642
paul718e3742002-12-13 20:15:29 +00002643static void
2644bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002645 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002646{
2647 struct bgp_node *rn;
2648 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002649 struct attr attr;
2650 struct attr_extra extra;
2651
Lou Berger298cc2f2016-01-12 13:42:02 -05002652 memset(&extra, 0, sizeof(extra));
2653
paul718e3742002-12-13 20:15:29 +00002654 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002655 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002656
Lou Berger298cc2f2016-01-12 13:42:02 -05002657 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP)
paul718e3742002-12-13 20:15:29 +00002658 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2659 bgp_default_originate (peer, afi, safi, 0);
2660
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002661 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2662 attr.extra = &extra;
2663
paul718e3742002-12-13 20:15:29 +00002664 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2665 for (ri = rn->info; ri; ri = ri->next)
2666 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2667 {
paulfee0f4c2004-09-13 05:12:46 +00002668 if ( (rsclient) ?
2669 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2670 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002671 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2672 else
2673 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2674 }
Lou Berger298cc2f2016-01-12 13:42:02 -05002675
2676 bgp_attr_flush_encap(&attr);
paul718e3742002-12-13 20:15:29 +00002677}
2678
2679void
2680bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2681{
2682 struct bgp_node *rn;
2683 struct bgp_table *table;
2684
2685 if (peer->status != Established)
2686 return;
2687
2688 if (! peer->afc_nego[afi][safi])
2689 return;
2690
2691 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2692 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2693 return;
2694
Lou Berger298cc2f2016-01-12 13:42:02 -05002695 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
paulfee0f4c2004-09-13 05:12:46 +00002696 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002697 else
2698 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2699 rn = bgp_route_next(rn))
2700 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002701 bgp_announce_table (peer, afi, safi, table, 0);
2702
2703 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2704 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002705}
2706
2707void
2708bgp_announce_route_all (struct peer *peer)
2709{
2710 afi_t afi;
2711 safi_t safi;
2712
2713 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2714 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2715 bgp_announce_route (peer, afi, safi);
2716}
David Lamparter6b0655a2014-06-04 06:53:35 +02002717
paul718e3742002-12-13 20:15:29 +00002718static void
paulfee0f4c2004-09-13 05:12:46 +00002719bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002720 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002721{
2722 struct bgp_node *rn;
2723 struct bgp_adj_in *ain;
2724
2725 if (! table)
2726 table = rsclient->bgp->rib[afi][safi];
2727
2728 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2729 for (ain = rn->adj_in; ain; ain = ain->next)
2730 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002731 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002732 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002733
paulfee0f4c2004-09-13 05:12:46 +00002734 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002735 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002736 }
2737}
2738
2739void
2740bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2741{
2742 struct bgp_table *table;
2743 struct bgp_node *rn;
2744
Lou Berger298cc2f2016-01-12 13:42:02 -05002745 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002746 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002747
2748 else
2749 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2750 rn = bgp_route_next (rn))
2751 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002752 {
2753 struct prefix_rd prd;
2754 prd.family = AF_UNSPEC;
2755 prd.prefixlen = 64;
2756 memcpy(&prd.val, rn->p.u.val, 8);
2757
2758 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2759 }
paulfee0f4c2004-09-13 05:12:46 +00002760}
David Lamparter6b0655a2014-06-04 06:53:35 +02002761
paulfee0f4c2004-09-13 05:12:46 +00002762static void
paul718e3742002-12-13 20:15:29 +00002763bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002764 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002765{
2766 int ret;
2767 struct bgp_node *rn;
2768 struct bgp_adj_in *ain;
2769
2770 if (! table)
2771 table = peer->bgp->rib[afi][safi];
2772
2773 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2774 for (ain = rn->adj_in; ain; ain = ain->next)
2775 {
2776 if (ain->peer == peer)
2777 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002778 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002779 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002780
paul718e3742002-12-13 20:15:29 +00002781 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2782 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002783 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002784
paul718e3742002-12-13 20:15:29 +00002785 if (ret < 0)
2786 {
2787 bgp_unlock_node (rn);
2788 return;
2789 }
2790 continue;
2791 }
2792 }
2793}
2794
2795void
2796bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2797{
2798 struct bgp_node *rn;
2799 struct bgp_table *table;
2800
2801 if (peer->status != Established)
2802 return;
2803
Lou Berger298cc2f2016-01-12 13:42:02 -05002804 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002805 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002806 else
2807 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2808 rn = bgp_route_next (rn))
2809 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002810 {
2811 struct prefix_rd prd;
2812 prd.family = AF_UNSPEC;
2813 prd.prefixlen = 64;
2814 memcpy(&prd.val, rn->p.u.val, 8);
2815
2816 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2817 }
paul718e3742002-12-13 20:15:29 +00002818}
David Lamparter6b0655a2014-06-04 06:53:35 +02002819
Chris Caputo228da422009-07-18 05:44:03 +00002820
2821struct bgp_clear_node_queue
2822{
2823 struct bgp_node *rn;
2824 enum bgp_clear_route_type purpose;
2825};
2826
paul200df112005-06-01 11:17:05 +00002827static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002828bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002829{
Chris Caputo228da422009-07-18 05:44:03 +00002830 struct bgp_clear_node_queue *cnq = data;
2831 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002832 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002833 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002834 afi_t afi = bgp_node_table (rn)->afi;
2835 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002836
Paul Jakma64e580a2006-02-21 01:09:01 +00002837 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002838
Paul Jakma64e580a2006-02-21 01:09:01 +00002839 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002840 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002841 {
2842 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002843 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2844 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002845 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002846 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2847 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002848 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002849 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002850 break;
2851 }
paul200df112005-06-01 11:17:05 +00002852 return WQ_SUCCESS;
2853}
2854
2855static void
paul0fb58d52005-11-14 14:31:49 +00002856bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002857{
Chris Caputo228da422009-07-18 05:44:03 +00002858 struct bgp_clear_node_queue *cnq = data;
2859 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002860 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002861
2862 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002863 bgp_table_unlock (table);
2864 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002865}
2866
2867static void
paul94f2b392005-06-28 12:44:16 +00002868bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002869{
Paul Jakma64e580a2006-02-21 01:09:01 +00002870 struct peer *peer = wq->spec.data;
2871
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002872 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002873 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002874
2875 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002876}
2877
2878static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002879bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002880{
Paul Jakmaa2943652009-07-21 14:02:04 +01002881 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002882
Paul Jakmaa2943652009-07-21 14:02:04 +01002883 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002884#undef CLEAR_QUEUE_NAME_LEN
2885
2886 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002887 {
2888 zlog_err ("%s: Failed to allocate work queue", __func__);
2889 exit (1);
2890 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002891 peer->clear_node_queue->spec.hold = 10;
2892 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2893 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2894 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2895 peer->clear_node_queue->spec.max_retries = 0;
2896
2897 /* we only 'lock' this peer reference when the queue is actually active */
2898 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002899}
2900
paul718e3742002-12-13 20:15:29 +00002901static void
2902bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002903 struct bgp_table *table, struct peer *rsclient,
2904 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002905{
2906 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002907
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002908
paul718e3742002-12-13 20:15:29 +00002909 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002910 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002911
hasso6cf159b2005-03-21 10:28:14 +00002912 /* If still no table => afi/safi isn't configured at all or smth. */
2913 if (! table)
2914 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002915
2916 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2917 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002918 struct bgp_info *ri;
2919 struct bgp_adj_in *ain;
2920 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002921
2922 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2923 * queued for every clearing peer, regardless of whether it is
2924 * relevant to the peer at hand.
2925 *
2926 * Overview: There are 3 different indices which need to be
2927 * scrubbed, potentially, when a peer is removed:
2928 *
2929 * 1 peer's routes visible via the RIB (ie accepted routes)
2930 * 2 peer's routes visible by the (optional) peer's adj-in index
2931 * 3 other routes visible by the peer's adj-out index
2932 *
2933 * 3 there is no hurry in scrubbing, once the struct peer is
2934 * removed from bgp->peer, we could just GC such deleted peer's
2935 * adj-outs at our leisure.
2936 *
2937 * 1 and 2 must be 'scrubbed' in some way, at least made
2938 * invisible via RIB index before peer session is allowed to be
2939 * brought back up. So one needs to know when such a 'search' is
2940 * complete.
2941 *
2942 * Ideally:
2943 *
2944 * - there'd be a single global queue or a single RIB walker
2945 * - rather than tracking which route_nodes still need to be
2946 * examined on a peer basis, we'd track which peers still
2947 * aren't cleared
2948 *
2949 * Given that our per-peer prefix-counts now should be reliable,
2950 * this may actually be achievable. It doesn't seem to be a huge
2951 * problem at this time,
2952 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002953 for (ain = rn->adj_in; ain; ain = ain->next)
2954 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2955 {
2956 bgp_adj_in_remove (rn, ain);
2957 bgp_unlock_node (rn);
2958 break;
2959 }
2960 for (aout = rn->adj_out; aout; aout = aout->next)
2961 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2962 {
2963 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2964 bgp_unlock_node (rn);
2965 break;
2966 }
2967
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002968 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002969 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002970 {
Chris Caputo228da422009-07-18 05:44:03 +00002971 struct bgp_clear_node_queue *cnq;
2972
2973 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002974 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002975 bgp_lock_node (rn);
2976 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2977 sizeof (struct bgp_clear_node_queue));
2978 cnq->rn = rn;
2979 cnq->purpose = purpose;
2980 work_queue_add (peer->clear_node_queue, cnq);
2981 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002982 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002983 }
2984 return;
2985}
2986
2987void
Chris Caputo228da422009-07-18 05:44:03 +00002988bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2989 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002990{
2991 struct bgp_node *rn;
2992 struct bgp_table *table;
2993 struct peer *rsclient;
2994 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002995
Paul Jakma64e580a2006-02-21 01:09:01 +00002996 if (peer->clear_node_queue == NULL)
2997 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002998
Paul Jakmaca058a32006-09-14 02:58:49 +00002999 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3000 * Idle until it receives a Clearing_Completed event. This protects
3001 * against peers which flap faster than we can we clear, which could
3002 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00003003 *
3004 * a) race with routes from the new session being installed before
3005 * clear_route_node visits the node (to delete the route of that
3006 * peer)
3007 * b) resource exhaustion, clear_route_node likely leads to an entry
3008 * on the process_main queue. Fast-flapping could cause that queue
3009 * to grow and grow.
paul200df112005-06-01 11:17:05 +00003010 */
Donald Sharp7ef42212015-03-30 06:32:52 -07003011
3012 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3013 * the unlock will happen upon work-queue completion; other wise, the
3014 * unlock happens at the end of this function.
3015 */
Paul Jakmaca058a32006-09-14 02:58:49 +00003016 if (!peer->clear_node_queue->thread)
Lou Berger050defe2016-01-12 13:41:59 -05003017 peer_lock (peer); /* bgp_clear_node_complete */
Chris Caputo228da422009-07-18 05:44:03 +00003018 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00003019 {
Chris Caputo228da422009-07-18 05:44:03 +00003020 case BGP_CLEAR_ROUTE_NORMAL:
Lou Berger298cc2f2016-01-12 13:42:02 -05003021 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Chris Caputo228da422009-07-18 05:44:03 +00003022 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
3023 else
3024 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3025 rn = bgp_route_next (rn))
3026 if ((table = rn->info) != NULL)
3027 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3028
3029 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
3030 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
3031 PEER_FLAG_RSERVER_CLIENT))
3032 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3033 break;
3034
3035 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
Lou Berger050defe2016-01-12 13:41:59 -05003036 /*
3037 * gpz 091009: TBD why don't we have special handling for
3038 * SAFI_MPLS_VPN here in the original quagga code?
3039 * (and, by extension, for SAFI_ENCAP)
3040 */
Chris Caputo228da422009-07-18 05:44:03 +00003041 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3042 break;
3043
3044 default:
3045 assert (0);
3046 break;
paulfee0f4c2004-09-13 05:12:46 +00003047 }
Donald Sharp7ef42212015-03-30 06:32:52 -07003048
3049 /* unlock if no nodes got added to the clear-node-queue. */
Paul Jakma65ca75e2006-05-04 08:08:15 +00003050 if (!peer->clear_node_queue->thread)
Donald Sharp7ef42212015-03-30 06:32:52 -07003051 peer_unlock (peer);
3052
paul718e3742002-12-13 20:15:29 +00003053}
3054
3055void
3056bgp_clear_route_all (struct peer *peer)
3057{
3058 afi_t afi;
3059 safi_t safi;
3060
3061 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3062 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003063 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003064}
3065
Lou Berger82dd7072016-01-12 13:41:57 -05003066/*
3067 * Finish freeing things when exiting
3068 */
3069static void
3070bgp_drain_workqueue_immediate (struct work_queue *wq)
3071{
3072 if (!wq)
3073 return;
3074
3075 if (!wq->thread)
3076 {
3077 /*
3078 * no thread implies no queued items
3079 */
3080 assert(!wq->items->count);
3081 return;
3082 }
3083
3084 while (wq->items->count)
3085 {
3086 if (wq->thread)
3087 thread_cancel(wq->thread);
3088 work_queue_run(wq->thread);
3089 }
3090}
3091
3092/*
3093 * Special function to process clear node queue when bgpd is exiting
3094 * and the thread scheduler is no longer running.
3095 */
3096void
3097bgp_peer_clear_node_queue_drain_immediate(struct peer *peer)
3098{
3099 if (!peer)
3100 return;
3101
3102 bgp_drain_workqueue_immediate(peer->clear_node_queue);
3103}
3104
3105/*
3106 * The work queues are not specific to a BGP instance, but the
3107 * items in them refer to BGP instances, so this should be called
3108 * before each BGP instance is deleted.
3109 */
3110void
3111bgp_process_queues_drain_immediate(void)
3112{
3113 bgp_drain_workqueue_immediate(bm->process_main_queue);
3114 bgp_drain_workqueue_immediate(bm->process_rsclient_queue);
3115}
3116
paul718e3742002-12-13 20:15:29 +00003117void
3118bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3119{
3120 struct bgp_table *table;
3121 struct bgp_node *rn;
3122 struct bgp_adj_in *ain;
3123
3124 table = peer->bgp->rib[afi][safi];
3125
3126 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3127 for (ain = rn->adj_in; ain ; ain = ain->next)
3128 if (ain->peer == peer)
3129 {
3130 bgp_adj_in_remove (rn, ain);
3131 bgp_unlock_node (rn);
3132 break;
3133 }
3134}
hasso93406d82005-02-02 14:40:33 +00003135
3136void
3137bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3138{
3139 struct bgp_node *rn;
3140 struct bgp_info *ri;
3141 struct bgp_table *table;
3142
3143 table = peer->bgp->rib[afi][safi];
3144
3145 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3146 {
3147 for (ri = rn->info; ri; ri = ri->next)
3148 if (ri->peer == peer)
3149 {
3150 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3151 bgp_rib_remove (rn, ri, peer, afi, safi);
3152 break;
3153 }
3154 }
3155}
David Lamparter6b0655a2014-06-04 06:53:35 +02003156
Lou Berger82dd7072016-01-12 13:41:57 -05003157static void
3158bgp_cleanup_table(struct bgp_table *table, safi_t safi)
3159{
3160 struct bgp_node *rn;
3161 struct bgp_info *ri;
3162 struct bgp_info *next;
3163
3164 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3165 for (ri = rn->info; ri; ri = next)
3166 {
3167 next = ri->next;
3168 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3169 && ri->type == ZEBRA_ROUTE_BGP
3170 && ri->sub_type == BGP_ROUTE_NORMAL)
3171 bgp_zebra_withdraw (&rn->p, ri, safi);
3172 }
3173}
3174
paul718e3742002-12-13 20:15:29 +00003175/* Delete all kernel routes. */
3176void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003177bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003178{
3179 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003180 struct listnode *node, *nnode;
Lou Berger82dd7072016-01-12 13:41:57 -05003181 afi_t afi;
paul718e3742002-12-13 20:15:29 +00003182
paul1eb8ef22005-04-07 07:30:20 +00003183 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003184 {
Lou Berger82dd7072016-01-12 13:41:57 -05003185 for (afi = AFI_IP; afi < AFI_MAX; ++afi)
3186 {
3187 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00003188
Lou Berger82dd7072016-01-12 13:41:57 -05003189 bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003190
Lou Berger82dd7072016-01-12 13:41:57 -05003191 /*
3192 * VPN and ENCAP tables are two-level (RD is top level)
3193 */
3194 for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn;
3195 rn = bgp_route_next (rn))
Lou Berger298cc2f2016-01-12 13:42:02 -05003196 {
3197 if (rn->info)
Lou Berger82dd7072016-01-12 13:41:57 -05003198 {
Lou Berger298cc2f2016-01-12 13:42:02 -05003199 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN);
3200 bgp_table_finish ((struct bgp_table **)&(rn->info));
3201 rn->info = NULL;
3202 bgp_unlock_node(rn);
Lou Berger82dd7072016-01-12 13:41:57 -05003203 }
Lou Berger298cc2f2016-01-12 13:42:02 -05003204 }
3205
3206 for (rn = bgp_table_top(bgp->rib[afi][SAFI_ENCAP]); rn;
3207 rn = bgp_route_next (rn))
3208 {
3209 if (rn->info)
3210 {
3211 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_ENCAP);
3212 bgp_table_finish ((struct bgp_table **)&(rn->info));
3213 rn->info = NULL;
3214 bgp_unlock_node(rn);
3215 }
3216 }
Lou Berger82dd7072016-01-12 13:41:57 -05003217 }
paul718e3742002-12-13 20:15:29 +00003218 }
3219}
3220
3221void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003222bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003223{
3224 vty_reset ();
3225 bgp_zclient_reset ();
3226 access_list_reset ();
3227 prefix_list_reset ();
3228}
David Lamparter6b0655a2014-06-04 06:53:35 +02003229
paul718e3742002-12-13 20:15:29 +00003230/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3231 value. */
3232int
Paul Jakma518a4b72016-02-04 13:27:04 +00003233bgp_nlri_parse_ip (struct peer *peer, struct attr *attr,
3234 struct bgp_nlri *packet)
paul718e3742002-12-13 20:15:29 +00003235{
3236 u_char *pnt;
3237 u_char *lim;
3238 struct prefix p;
3239 int psize;
3240 int ret;
3241
3242 /* Check peer status. */
3243 if (peer->status != Established)
3244 return 0;
3245
3246 pnt = packet->nlri;
3247 lim = pnt + packet->length;
3248
Paul Jakma405e9e12016-02-04 17:00:18 +00003249 /* RFC4771 6.3 The NLRI field in the UPDATE message is checked for
3250 syntactic validity. If the field is syntactically incorrect,
3251 then the Error Subcode is set to Invalid Network Field. */
paul718e3742002-12-13 20:15:29 +00003252 for (; pnt < lim; pnt += psize)
3253 {
3254 /* Clear prefix structure. */
3255 memset (&p, 0, sizeof (struct prefix));
3256
3257 /* Fetch prefix length. */
3258 p.prefixlen = *pnt++;
Paul Jakma405e9e12016-02-04 17:00:18 +00003259 /* afi/safi validity already verified by caller, bgp_update_receive */
paul718e3742002-12-13 20:15:29 +00003260 p.family = afi2family (packet->afi);
3261
Paul Jakma405e9e12016-02-04 17:00:18 +00003262 /* Prefix length check. */
3263 if (p.prefixlen > prefix_blen (&p) * 8)
3264 {
3265 plog_err (peer->log,
3266 "%s [Error] Update packet error"
3267 " (wrong prefix length %u for afi %u)",
3268 peer->host, p.prefixlen, packet->afi);
3269 return -1;
3270 }
3271
paul718e3742002-12-13 20:15:29 +00003272 /* Packet size overflow check. */
3273 psize = PSIZE (p.prefixlen);
3274
3275 /* When packet overflow occur return immediately. */
3276 if (pnt + psize > lim)
Paul Jakma405e9e12016-02-04 17:00:18 +00003277 {
3278 plog_err (peer->log,
3279 "%s [Error] Update packet error"
3280 " (prefix length %u overflows packet)",
3281 peer->host, p.prefixlen);
3282 return -1;
3283 }
3284
3285 /* Defensive coding, double-check the psize fits in a struct prefix */
3286 if (psize > (ssize_t) sizeof(p.u))
3287 {
3288 plog_err (peer->log,
3289 "%s [Error] Update packet error"
3290 " (prefix length %u too large for prefix storage %zu!?!!",
3291 peer->host, p.prefixlen, sizeof(p.u));
3292 return -1;
3293 }
paul718e3742002-12-13 20:15:29 +00003294
3295 /* Fetch prefix from NLRI packet. */
3296 memcpy (&p.u.prefix, pnt, psize);
3297
3298 /* Check address. */
3299 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3300 {
3301 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3302 {
paulf5ba3872004-07-09 12:11:31 +00003303 /*
Paul Jakma405e9e12016-02-04 17:00:18 +00003304 * From RFC4271 Section 6.3:
3305 *
3306 * If a prefix in the NLRI field is semantically incorrect
3307 * (e.g., an unexpected multicast IP address), an error SHOULD
3308 * be logged locally, and the prefix SHOULD be ignored.
paulf5ba3872004-07-09 12:11:31 +00003309 */
paul718e3742002-12-13 20:15:29 +00003310 zlog (peer->log, LOG_ERR,
Paul Jakma405e9e12016-02-04 17:00:18 +00003311 "%s: IPv4 unicast NLRI is multicast address %s, ignoring",
3312 peer->host, inet_ntoa (p.u.prefix4));
3313 continue;
paul718e3742002-12-13 20:15:29 +00003314 }
3315 }
3316
paul718e3742002-12-13 20:15:29 +00003317 /* Check address. */
3318 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3319 {
3320 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3321 {
3322 char buf[BUFSIZ];
3323
Paul Jakma405e9e12016-02-04 17:00:18 +00003324 zlog (peer->log, LOG_ERR,
3325 "%s: IPv6 unicast NLRI is link-local address %s, ignoring",
3326 peer->host,
paul718e3742002-12-13 20:15:29 +00003327 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00003328 continue;
3329 }
Paul Jakma405e9e12016-02-04 17:00:18 +00003330 if (IN6_IS_ADDR_MULTICAST (&p.u.prefix6))
3331 {
3332 char buf[BUFSIZ];
3333
3334 zlog (peer->log, LOG_ERR,
3335 "%s: IPv6 unicast NLRI is multicast address %s, ignoring",
3336 peer->host,
3337 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3338 continue;
3339 }
3340 }
paul718e3742002-12-13 20:15:29 +00003341
3342 /* Normal process. */
3343 if (attr)
3344 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3345 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3346 else
3347 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3348 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3349
3350 /* Address family configuration mismatch or maximum-prefix count
3351 overflow. */
3352 if (ret < 0)
3353 return -1;
3354 }
3355
3356 /* Packet length consistency check. */
3357 if (pnt != lim)
paul718e3742002-12-13 20:15:29 +00003358 {
3359 plog_err (peer->log,
Paul Jakma405e9e12016-02-04 17:00:18 +00003360 "%s [Error] Update packet error"
3361 " (prefix length mismatch with total length)",
3362 peer->host);
paul718e3742002-12-13 20:15:29 +00003363 return -1;
3364 }
Paul Jakma405e9e12016-02-04 17:00:18 +00003365
paul718e3742002-12-13 20:15:29 +00003366 return 0;
3367}
David Lamparter6b0655a2014-06-04 06:53:35 +02003368
paul94f2b392005-06-28 12:44:16 +00003369static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003370bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003371{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003372 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003373}
3374
paul94f2b392005-06-28 12:44:16 +00003375static void
paul718e3742002-12-13 20:15:29 +00003376bgp_static_free (struct bgp_static *bgp_static)
3377{
3378 if (bgp_static->rmap.name)
3379 free (bgp_static->rmap.name);
3380 XFREE (MTYPE_BGP_STATIC, bgp_static);
3381}
3382
paul94f2b392005-06-28 12:44:16 +00003383static void
paulfee0f4c2004-09-13 05:12:46 +00003384bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3385 struct prefix *p, afi_t afi, safi_t safi)
3386{
3387 struct bgp_node *rn;
3388 struct bgp_info *ri;
3389
3390 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3391
3392 /* Check selected route and self inserted route. */
3393 for (ri = rn->info; ri; ri = ri->next)
3394 if (ri->peer == bgp->peer_self
3395 && ri->type == ZEBRA_ROUTE_BGP
3396 && ri->sub_type == BGP_ROUTE_STATIC)
3397 break;
3398
3399 /* Withdraw static BGP route from routing table. */
3400 if (ri)
3401 {
paulfee0f4c2004-09-13 05:12:46 +00003402 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003403 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003404 }
3405
3406 /* Unlock bgp_node_lookup. */
3407 bgp_unlock_node (rn);
3408}
3409
paul94f2b392005-06-28 12:44:16 +00003410static void
paulfee0f4c2004-09-13 05:12:46 +00003411bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003412 struct bgp_static *bgp_static,
3413 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003414{
3415 struct bgp_node *rn;
3416 struct bgp_info *ri;
3417 struct bgp_info *new;
3418 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003419 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003420 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003421 struct attr new_attr;
3422 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003423 struct bgp *bgp;
3424 int ret;
3425 char buf[SU_ADDRSTRLEN];
3426
3427 bgp = rsclient->bgp;
3428
Paul Jakma06e110f2006-05-12 23:29:22 +00003429 assert (bgp_static);
3430 if (!bgp_static)
3431 return;
3432
paulfee0f4c2004-09-13 05:12:46 +00003433 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3434
3435 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003436
3437 attr.nexthop = bgp_static->igpnexthop;
3438 attr.med = bgp_static->igpmetric;
3439 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003440
Paul Jakma41367172007-08-06 15:24:51 +00003441 if (bgp_static->atomic)
3442 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3443
paulfee0f4c2004-09-13 05:12:46 +00003444 /* Apply network route-map for export to this rsclient. */
3445 if (bgp_static->rmap.name)
3446 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003447 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003448 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003449 info.attr = &attr_tmp;
3450
paulfee0f4c2004-09-13 05:12:46 +00003451 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3452 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3453
3454 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3455
3456 rsclient->rmap_type = 0;
3457
3458 if (ret == RMAP_DENYMATCH)
3459 {
3460 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003461 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003462
3463 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003464 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003465 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003466 bgp_attr_extra_free (&attr);
3467
paulfee0f4c2004-09-13 05:12:46 +00003468 return;
3469 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003470 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003471 }
3472 else
3473 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003474
3475 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003476 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003477
paulfee0f4c2004-09-13 05:12:46 +00003478 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3479
Paul Jakmafb982c22007-05-04 20:15:47 +00003480 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3481 == RMAP_DENY)
3482 {
paulfee0f4c2004-09-13 05:12:46 +00003483 /* This BGP update is filtered. Log the reason then update BGP entry. */
3484 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003485 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003486 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3487 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3488 p->prefixlen, rsclient->host);
3489
3490 bgp->peer_self->rmap_type = 0;
3491
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003492 bgp_attr_unintern (&attr_new);
3493 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003494 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003495
3496 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3497
3498 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003499 }
paulfee0f4c2004-09-13 05:12:46 +00003500
3501 bgp->peer_self->rmap_type = 0;
3502
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003503 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003504 attr_new = bgp_attr_intern (&new_attr);
3505
3506 for (ri = rn->info; ri; ri = ri->next)
3507 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3508 && ri->sub_type == BGP_ROUTE_STATIC)
3509 break;
3510
3511 if (ri)
3512 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003513 if (attrhash_cmp (ri->attr, attr_new) &&
3514 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003515 {
3516 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003517 bgp_attr_unintern (&attr_new);
3518 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003519 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003520 return;
3521 }
3522 else
3523 {
3524 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003525 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003526
3527 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003528 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3529 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003530 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003531 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003532 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003533
3534 /* Process change. */
3535 bgp_process (bgp, rn, afi, safi);
3536 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003537 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003538 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003539 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003540 }
paulfee0f4c2004-09-13 05:12:46 +00003541 }
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003542
paulfee0f4c2004-09-13 05:12:46 +00003543 /* Make new BGP info. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003544 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
3545 attr_new, rn);
paulfee0f4c2004-09-13 05:12:46 +00003546 SET_FLAG (new->flags, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00003547
3548 /* Register new BGP information. */
3549 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003550
3551 /* route_node_get lock */
3552 bgp_unlock_node (rn);
3553
paulfee0f4c2004-09-13 05:12:46 +00003554 /* Process change. */
3555 bgp_process (bgp, rn, afi, safi);
3556
3557 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003558 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003559 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003560}
3561
paul94f2b392005-06-28 12:44:16 +00003562static void
paulfee0f4c2004-09-13 05:12:46 +00003563bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003564 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3565{
3566 struct bgp_node *rn;
3567 struct bgp_info *ri;
3568 struct bgp_info *new;
3569 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003570 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003571 struct attr *attr_new;
3572 int ret;
3573
Paul Jakmadd8103a2006-05-12 23:27:30 +00003574 assert (bgp_static);
3575 if (!bgp_static)
3576 return;
3577
paulfee0f4c2004-09-13 05:12:46 +00003578 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003579
3580 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003581
3582 attr.nexthop = bgp_static->igpnexthop;
3583 attr.med = bgp_static->igpmetric;
3584 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003585
Paul Jakma41367172007-08-06 15:24:51 +00003586 if (bgp_static->atomic)
3587 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3588
paul718e3742002-12-13 20:15:29 +00003589 /* Apply route-map. */
3590 if (bgp_static->rmap.name)
3591 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003592 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003593 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003594 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003595
paulfee0f4c2004-09-13 05:12:46 +00003596 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3597
paul718e3742002-12-13 20:15:29 +00003598 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003599
paulfee0f4c2004-09-13 05:12:46 +00003600 bgp->peer_self->rmap_type = 0;
3601
paul718e3742002-12-13 20:15:29 +00003602 if (ret == RMAP_DENYMATCH)
3603 {
3604 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003605 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003606
3607 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003608 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003609 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003610 bgp_static_withdraw (bgp, p, afi, safi);
3611 return;
3612 }
paul286e1e72003-08-08 00:24:31 +00003613 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003614 }
paul286e1e72003-08-08 00:24:31 +00003615 else
3616 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003617
3618 for (ri = rn->info; ri; ri = ri->next)
3619 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3620 && ri->sub_type == BGP_ROUTE_STATIC)
3621 break;
3622
3623 if (ri)
3624 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003625 if (attrhash_cmp (ri->attr, attr_new) &&
3626 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003627 {
3628 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003629 bgp_attr_unintern (&attr_new);
3630 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003631 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003632 return;
3633 }
3634 else
3635 {
3636 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003637 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003638
3639 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003640 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3641 bgp_info_restore(rn, ri);
3642 else
3643 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003644 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003645 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003646 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003647
3648 /* Process change. */
3649 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3650 bgp_process (bgp, rn, afi, safi);
3651 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003652 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003653 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003654 return;
3655 }
3656 }
3657
3658 /* Make new BGP info. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003659 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self, attr_new,
3660 rn);
paul718e3742002-12-13 20:15:29 +00003661 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00003662
3663 /* Aggregate address increment. */
3664 bgp_aggregate_increment (bgp, p, new, afi, safi);
3665
3666 /* Register new BGP information. */
3667 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003668
3669 /* route_node_get lock */
3670 bgp_unlock_node (rn);
3671
paul718e3742002-12-13 20:15:29 +00003672 /* Process change. */
3673 bgp_process (bgp, rn, afi, safi);
3674
3675 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003676 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003677 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003678}
3679
3680void
paulfee0f4c2004-09-13 05:12:46 +00003681bgp_static_update (struct bgp *bgp, struct prefix *p,
3682 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3683{
3684 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003685 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003686
3687 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3688
paul1eb8ef22005-04-07 07:30:20 +00003689 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003690 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003691 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3692 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003693 }
3694}
3695
paul718e3742002-12-13 20:15:29 +00003696void
3697bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3698 safi_t safi)
3699{
3700 struct bgp_node *rn;
3701 struct bgp_info *ri;
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003702 struct bgp_info *new;
paul718e3742002-12-13 20:15:29 +00003703
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003704 /* Make new BGP info. */
3705 rn = bgp_node_get (bgp->rib[afi][safi], p);
3706 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
3707 bgp_attr_default_intern(BGP_ORIGIN_IGP), rn);
3708
3709 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00003710
3711 /* Check selected route and self inserted route. */
3712 for (ri = rn->info; ri; ri = ri->next)
3713 if (ri->peer == bgp->peer_self
3714 && ri->type == ZEBRA_ROUTE_BGP
3715 && ri->sub_type == BGP_ROUTE_STATIC)
3716 break;
3717
3718 /* Withdraw static BGP route from routing table. */
3719 if (ri)
3720 {
3721 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003722 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003723 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003724 }
3725
3726 /* Unlock bgp_node_lookup. */
3727 bgp_unlock_node (rn);
3728}
3729
3730void
paulfee0f4c2004-09-13 05:12:46 +00003731bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3732{
3733 struct bgp_static *bgp_static;
3734 struct bgp *bgp;
3735 struct bgp_node *rn;
3736 struct prefix *p;
3737
3738 bgp = rsclient->bgp;
3739
3740 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3741 if ((bgp_static = rn->info) != NULL)
3742 {
3743 p = &rn->p;
3744
3745 bgp_static_update_rsclient (rsclient, p, bgp_static,
3746 afi, safi);
3747 }
3748}
3749
Lou Bergera76d9ca2016-01-12 13:41:53 -05003750/*
3751 * Used for SAFI_MPLS_VPN and SAFI_ENCAP
3752 */
paul94f2b392005-06-28 12:44:16 +00003753static void
Lou Bergera76d9ca2016-01-12 13:41:53 -05003754bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
3755 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003756{
3757 struct bgp_node *rn;
3758 struct bgp_info *ri;
3759
paulfee0f4c2004-09-13 05:12:46 +00003760 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003761
3762 /* Check selected route and self inserted route. */
3763 for (ri = rn->info; ri; ri = ri->next)
3764 if (ri->peer == bgp->peer_self
3765 && ri->type == ZEBRA_ROUTE_BGP
3766 && ri->sub_type == BGP_ROUTE_STATIC)
3767 break;
3768
3769 /* Withdraw static BGP route from routing table. */
3770 if (ri)
3771 {
3772 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003773 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003774 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003775 }
3776
3777 /* Unlock bgp_node_lookup. */
3778 bgp_unlock_node (rn);
3779}
3780
Lou Bergera76d9ca2016-01-12 13:41:53 -05003781static void
3782bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
3783 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3784{
3785 struct bgp_node *rn;
3786 struct bgp_info *new;
3787 struct attr *attr_new;
3788 struct attr attr = { 0 };
3789 struct bgp_info *ri;
3790
3791 assert (bgp_static);
3792
3793 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
3794
3795 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3796
3797 attr.nexthop = bgp_static->igpnexthop;
3798 attr.med = bgp_static->igpmetric;
3799 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3800
3801 /* Apply route-map. */
3802 if (bgp_static->rmap.name)
3803 {
3804 struct attr attr_tmp = attr;
3805 struct bgp_info info;
3806 int ret;
3807
3808 info.peer = bgp->peer_self;
3809 info.attr = &attr_tmp;
3810
3811 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3812
3813 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3814
3815 bgp->peer_self->rmap_type = 0;
3816
3817 if (ret == RMAP_DENYMATCH)
3818 {
3819 /* Free uninterned attribute. */
3820 bgp_attr_flush (&attr_tmp);
3821
3822 /* Unintern original. */
3823 aspath_unintern (&attr.aspath);
3824 bgp_attr_extra_free (&attr);
3825 bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
3826 bgp_static->tag);
3827 return;
3828 }
3829
3830 attr_new = bgp_attr_intern (&attr_tmp);
3831 }
3832 else
3833 {
3834 attr_new = bgp_attr_intern (&attr);
3835 }
3836
3837 for (ri = rn->info; ri; ri = ri->next)
3838 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3839 && ri->sub_type == BGP_ROUTE_STATIC)
3840 break;
3841
3842 if (ri)
3843 {
3844 if (attrhash_cmp (ri->attr, attr_new) &&
3845 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3846 {
3847 bgp_unlock_node (rn);
3848 bgp_attr_unintern (&attr_new);
3849 aspath_unintern (&attr.aspath);
3850 bgp_attr_extra_free (&attr);
3851 return;
3852 }
3853 else
3854 {
3855 /* The attribute is changed. */
3856 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3857
3858 /* Rewrite BGP route information. */
3859 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3860 bgp_info_restore(rn, ri);
3861 else
3862 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3863 bgp_attr_unintern (&ri->attr);
3864 ri->attr = attr_new;
3865 ri->uptime = bgp_clock ();
3866
3867 /* Process change. */
3868 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3869 bgp_process (bgp, rn, afi, safi);
3870 bgp_unlock_node (rn);
3871 aspath_unintern (&attr.aspath);
3872 bgp_attr_extra_free (&attr);
3873 return;
3874 }
3875 }
3876
3877
3878 /* Make new BGP info. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003879 new = info_make (ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
3880 attr_new, rn);
Lou Bergera76d9ca2016-01-12 13:41:53 -05003881 SET_FLAG (new->flags, BGP_INFO_VALID);
Lou Bergera76d9ca2016-01-12 13:41:53 -05003882 new->extra = bgp_info_extra_new();
3883 memcpy (new->extra->tag, bgp_static->tag, 3);
3884
3885 /* Aggregate address increment. */
3886 bgp_aggregate_increment (bgp, p, new, afi, safi);
3887
3888 /* Register new BGP information. */
3889 bgp_info_add (rn, new);
3890
3891 /* route_node_get lock */
3892 bgp_unlock_node (rn);
3893
3894 /* Process change. */
3895 bgp_process (bgp, rn, afi, safi);
3896
3897 /* Unintern original. */
3898 aspath_unintern (&attr.aspath);
3899 bgp_attr_extra_free (&attr);
3900}
3901
paul718e3742002-12-13 20:15:29 +00003902/* Configure static BGP network. When user don't run zebra, static
3903 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003904static int
paulfd79ac92004-10-13 05:06:08 +00003905bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003906 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003907{
3908 int ret;
3909 struct prefix p;
3910 struct bgp_static *bgp_static;
3911 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003912 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003913
3914 /* Convert IP prefix string to struct prefix. */
3915 ret = str2prefix (ip_str, &p);
3916 if (! ret)
3917 {
3918 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3919 return CMD_WARNING;
3920 }
paul718e3742002-12-13 20:15:29 +00003921 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3922 {
3923 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3924 VTY_NEWLINE);
3925 return CMD_WARNING;
3926 }
paul718e3742002-12-13 20:15:29 +00003927
3928 apply_mask (&p);
3929
3930 /* Set BGP static route configuration. */
3931 rn = bgp_node_get (bgp->route[afi][safi], &p);
3932
3933 if (rn->info)
3934 {
3935 /* Configuration change. */
3936 bgp_static = rn->info;
3937
3938 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003939 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3940 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003941
paul718e3742002-12-13 20:15:29 +00003942 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003943
paul718e3742002-12-13 20:15:29 +00003944 if (rmap)
3945 {
3946 if (bgp_static->rmap.name)
3947 free (bgp_static->rmap.name);
3948 bgp_static->rmap.name = strdup (rmap);
3949 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3950 }
3951 else
3952 {
3953 if (bgp_static->rmap.name)
3954 free (bgp_static->rmap.name);
3955 bgp_static->rmap.name = NULL;
3956 bgp_static->rmap.map = NULL;
3957 bgp_static->valid = 0;
3958 }
3959 bgp_unlock_node (rn);
3960 }
3961 else
3962 {
3963 /* New configuration. */
3964 bgp_static = bgp_static_new ();
3965 bgp_static->backdoor = backdoor;
3966 bgp_static->valid = 0;
3967 bgp_static->igpmetric = 0;
3968 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003969
paul718e3742002-12-13 20:15:29 +00003970 if (rmap)
3971 {
3972 if (bgp_static->rmap.name)
3973 free (bgp_static->rmap.name);
3974 bgp_static->rmap.name = strdup (rmap);
3975 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3976 }
3977 rn->info = bgp_static;
3978 }
3979
3980 /* If BGP scan is not enabled, we should install this route here. */
3981 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3982 {
3983 bgp_static->valid = 1;
3984
3985 if (need_update)
3986 bgp_static_withdraw (bgp, &p, afi, safi);
3987
3988 if (! bgp_static->backdoor)
3989 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3990 }
3991
3992 return CMD_SUCCESS;
3993}
3994
3995/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003996static int
paulfd79ac92004-10-13 05:06:08 +00003997bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003998 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003999{
4000 int ret;
4001 struct prefix p;
4002 struct bgp_static *bgp_static;
4003 struct bgp_node *rn;
4004
4005 /* Convert IP prefix string to struct prefix. */
4006 ret = str2prefix (ip_str, &p);
4007 if (! ret)
4008 {
4009 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4010 return CMD_WARNING;
4011 }
paul718e3742002-12-13 20:15:29 +00004012 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4013 {
4014 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4015 VTY_NEWLINE);
4016 return CMD_WARNING;
4017 }
paul718e3742002-12-13 20:15:29 +00004018
4019 apply_mask (&p);
4020
4021 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4022 if (! rn)
4023 {
4024 vty_out (vty, "%% Can't find specified static route configuration.%s",
4025 VTY_NEWLINE);
4026 return CMD_WARNING;
4027 }
4028
4029 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00004030
paul718e3742002-12-13 20:15:29 +00004031 /* Update BGP RIB. */
4032 if (! bgp_static->backdoor)
4033 bgp_static_withdraw (bgp, &p, afi, safi);
4034
4035 /* Clear configuration. */
4036 bgp_static_free (bgp_static);
4037 rn->info = NULL;
4038 bgp_unlock_node (rn);
4039 bgp_unlock_node (rn);
4040
4041 return CMD_SUCCESS;
4042}
4043
4044/* Called from bgp_delete(). Delete all static routes from the BGP
4045 instance. */
4046void
4047bgp_static_delete (struct bgp *bgp)
4048{
4049 afi_t afi;
4050 safi_t safi;
4051 struct bgp_node *rn;
4052 struct bgp_node *rm;
4053 struct bgp_table *table;
4054 struct bgp_static *bgp_static;
4055
4056 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4057 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4058 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4059 if (rn->info != NULL)
4060 {
Lou Berger298cc2f2016-01-12 13:42:02 -05004061 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004062 {
4063 table = rn->info;
4064
4065 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4066 {
4067 bgp_static = rn->info;
Lou Bergera76d9ca2016-01-12 13:41:53 -05004068 bgp_static_withdraw_safi (bgp, &rm->p,
4069 AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00004070 (struct prefix_rd *)&rn->p,
4071 bgp_static->tag);
4072 bgp_static_free (bgp_static);
4073 rn->info = NULL;
4074 bgp_unlock_node (rn);
4075 }
4076 }
4077 else
4078 {
4079 bgp_static = rn->info;
4080 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4081 bgp_static_free (bgp_static);
4082 rn->info = NULL;
4083 bgp_unlock_node (rn);
4084 }
4085 }
4086}
4087
Lou Bergera76d9ca2016-01-12 13:41:53 -05004088/*
4089 * gpz 110624
4090 * Currently this is used to set static routes for VPN and ENCAP.
4091 * I think it can probably be factored with bgp_static_set.
4092 */
paul718e3742002-12-13 20:15:29 +00004093int
Lou Bergera76d9ca2016-01-12 13:41:53 -05004094bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
4095 const char *rd_str, const char *tag_str,
4096 const char *rmap_str)
paul718e3742002-12-13 20:15:29 +00004097{
4098 int ret;
4099 struct prefix p;
4100 struct prefix_rd prd;
4101 struct bgp *bgp;
4102 struct bgp_node *prn;
4103 struct bgp_node *rn;
4104 struct bgp_table *table;
4105 struct bgp_static *bgp_static;
4106 u_char tag[3];
4107
4108 bgp = vty->index;
4109
4110 ret = str2prefix (ip_str, &p);
4111 if (! ret)
4112 {
4113 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4114 return CMD_WARNING;
4115 }
4116 apply_mask (&p);
4117
4118 ret = str2prefix_rd (rd_str, &prd);
4119 if (! ret)
4120 {
4121 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4122 return CMD_WARNING;
4123 }
4124
4125 ret = str2tag (tag_str, tag);
4126 if (! ret)
4127 {
4128 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4129 return CMD_WARNING;
4130 }
4131
Lou Bergera76d9ca2016-01-12 13:41:53 -05004132 prn = bgp_node_get (bgp->route[AFI_IP][safi],
paul718e3742002-12-13 20:15:29 +00004133 (struct prefix *)&prd);
4134 if (prn->info == NULL)
Lou Bergera76d9ca2016-01-12 13:41:53 -05004135 prn->info = bgp_table_init (AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004136 else
4137 bgp_unlock_node (prn);
4138 table = prn->info;
4139
4140 rn = bgp_node_get (table, &p);
4141
4142 if (rn->info)
4143 {
4144 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4145 bgp_unlock_node (rn);
4146 }
4147 else
4148 {
4149 /* New configuration. */
4150 bgp_static = bgp_static_new ();
Lou Bergera76d9ca2016-01-12 13:41:53 -05004151 bgp_static->backdoor = 0;
4152 bgp_static->valid = 0;
4153 bgp_static->igpmetric = 0;
4154 bgp_static->igpnexthop.s_addr = 0;
4155 memcpy(bgp_static->tag, tag, 3);
4156 bgp_static->prd = prd;
4157
4158 if (rmap_str)
4159 {
4160 if (bgp_static->rmap.name)
4161 free (bgp_static->rmap.name);
4162 bgp_static->rmap.name = strdup (rmap_str);
4163 bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
4164 }
paul718e3742002-12-13 20:15:29 +00004165 rn->info = bgp_static;
4166
Lou Bergera76d9ca2016-01-12 13:41:53 -05004167 bgp_static->valid = 1;
4168 bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004169 }
4170
4171 return CMD_SUCCESS;
4172}
4173
4174/* Configure static BGP network. */
4175int
Lou Bergera76d9ca2016-01-12 13:41:53 -05004176bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
4177 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00004178{
4179 int ret;
4180 struct bgp *bgp;
4181 struct prefix p;
4182 struct prefix_rd prd;
4183 struct bgp_node *prn;
4184 struct bgp_node *rn;
4185 struct bgp_table *table;
4186 struct bgp_static *bgp_static;
4187 u_char tag[3];
4188
4189 bgp = vty->index;
4190
4191 /* Convert IP prefix string to struct prefix. */
4192 ret = str2prefix (ip_str, &p);
4193 if (! ret)
4194 {
4195 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4196 return CMD_WARNING;
4197 }
4198 apply_mask (&p);
4199
4200 ret = str2prefix_rd (rd_str, &prd);
4201 if (! ret)
4202 {
4203 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4204 return CMD_WARNING;
4205 }
4206
4207 ret = str2tag (tag_str, tag);
4208 if (! ret)
4209 {
4210 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4211 return CMD_WARNING;
4212 }
4213
Lou Bergera76d9ca2016-01-12 13:41:53 -05004214 prn = bgp_node_get (bgp->route[AFI_IP][safi],
paul718e3742002-12-13 20:15:29 +00004215 (struct prefix *)&prd);
4216 if (prn->info == NULL)
Lou Bergera76d9ca2016-01-12 13:41:53 -05004217 prn->info = bgp_table_init (AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004218 else
4219 bgp_unlock_node (prn);
4220 table = prn->info;
4221
4222 rn = bgp_node_lookup (table, &p);
4223
4224 if (rn)
4225 {
Lou Bergera76d9ca2016-01-12 13:41:53 -05004226 bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
paul718e3742002-12-13 20:15:29 +00004227
4228 bgp_static = rn->info;
4229 bgp_static_free (bgp_static);
4230 rn->info = NULL;
4231 bgp_unlock_node (rn);
4232 bgp_unlock_node (rn);
4233 }
4234 else
4235 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4236
4237 return CMD_SUCCESS;
4238}
David Lamparter6b0655a2014-06-04 06:53:35 +02004239
paul718e3742002-12-13 20:15:29 +00004240DEFUN (bgp_network,
4241 bgp_network_cmd,
4242 "network A.B.C.D/M",
4243 "Specify a network to announce via BGP\n"
4244 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4245{
4246 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004247 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004248}
4249
4250DEFUN (bgp_network_route_map,
4251 bgp_network_route_map_cmd,
4252 "network A.B.C.D/M route-map WORD",
4253 "Specify a network to announce via BGP\n"
4254 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4255 "Route-map to modify the attributes\n"
4256 "Name of the route map\n")
4257{
4258 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004259 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004260}
4261
4262DEFUN (bgp_network_backdoor,
4263 bgp_network_backdoor_cmd,
4264 "network A.B.C.D/M backdoor",
4265 "Specify a network to announce via BGP\n"
4266 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4267 "Specify a BGP backdoor route\n")
4268{
Paul Jakma41367172007-08-06 15:24:51 +00004269 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004270 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004271}
4272
4273DEFUN (bgp_network_mask,
4274 bgp_network_mask_cmd,
4275 "network A.B.C.D mask A.B.C.D",
4276 "Specify a network to announce via BGP\n"
4277 "Network number\n"
4278 "Network mask\n"
4279 "Network mask\n")
4280{
4281 int ret;
4282 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004283
paul718e3742002-12-13 20:15:29 +00004284 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4285 if (! ret)
4286 {
4287 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4288 return CMD_WARNING;
4289 }
4290
4291 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004292 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004293}
4294
4295DEFUN (bgp_network_mask_route_map,
4296 bgp_network_mask_route_map_cmd,
4297 "network A.B.C.D mask A.B.C.D route-map WORD",
4298 "Specify a network to announce via BGP\n"
4299 "Network number\n"
4300 "Network mask\n"
4301 "Network mask\n"
4302 "Route-map to modify the attributes\n"
4303 "Name of the route map\n")
4304{
4305 int ret;
4306 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004307
paul718e3742002-12-13 20:15:29 +00004308 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4309 if (! ret)
4310 {
4311 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4312 return CMD_WARNING;
4313 }
4314
4315 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004316 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004317}
4318
4319DEFUN (bgp_network_mask_backdoor,
4320 bgp_network_mask_backdoor_cmd,
4321 "network A.B.C.D mask A.B.C.D backdoor",
4322 "Specify a network to announce via BGP\n"
4323 "Network number\n"
4324 "Network mask\n"
4325 "Network mask\n"
4326 "Specify a BGP backdoor route\n")
4327{
4328 int ret;
4329 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004330
paul718e3742002-12-13 20:15:29 +00004331 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4332 if (! ret)
4333 {
4334 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4335 return CMD_WARNING;
4336 }
4337
Paul Jakma41367172007-08-06 15:24:51 +00004338 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004339 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004340}
4341
4342DEFUN (bgp_network_mask_natural,
4343 bgp_network_mask_natural_cmd,
4344 "network A.B.C.D",
4345 "Specify a network to announce via BGP\n"
4346 "Network number\n")
4347{
4348 int ret;
4349 char prefix_str[BUFSIZ];
4350
4351 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4352 if (! ret)
4353 {
4354 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4355 return CMD_WARNING;
4356 }
4357
4358 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004359 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004360}
4361
4362DEFUN (bgp_network_mask_natural_route_map,
4363 bgp_network_mask_natural_route_map_cmd,
4364 "network A.B.C.D route-map WORD",
4365 "Specify a network to announce via BGP\n"
4366 "Network number\n"
4367 "Route-map to modify the attributes\n"
4368 "Name of the route map\n")
4369{
4370 int ret;
4371 char prefix_str[BUFSIZ];
4372
4373 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4374 if (! ret)
4375 {
4376 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4377 return CMD_WARNING;
4378 }
4379
4380 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004381 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004382}
4383
4384DEFUN (bgp_network_mask_natural_backdoor,
4385 bgp_network_mask_natural_backdoor_cmd,
4386 "network A.B.C.D backdoor",
4387 "Specify a network to announce via BGP\n"
4388 "Network number\n"
4389 "Specify a BGP backdoor route\n")
4390{
4391 int ret;
4392 char prefix_str[BUFSIZ];
4393
4394 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4395 if (! ret)
4396 {
4397 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4398 return CMD_WARNING;
4399 }
4400
Paul Jakma41367172007-08-06 15:24:51 +00004401 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004402 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004403}
4404
4405DEFUN (no_bgp_network,
4406 no_bgp_network_cmd,
4407 "no network A.B.C.D/M",
4408 NO_STR
4409 "Specify a network to announce via BGP\n"
4410 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4411{
4412 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4413 bgp_node_safi (vty));
4414}
4415
4416ALIAS (no_bgp_network,
4417 no_bgp_network_route_map_cmd,
4418 "no network A.B.C.D/M route-map WORD",
4419 NO_STR
4420 "Specify a network to announce via BGP\n"
4421 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4422 "Route-map to modify the attributes\n"
4423 "Name of the route map\n")
4424
4425ALIAS (no_bgp_network,
4426 no_bgp_network_backdoor_cmd,
4427 "no network A.B.C.D/M backdoor",
4428 NO_STR
4429 "Specify a network to announce via BGP\n"
4430 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4431 "Specify a BGP backdoor route\n")
4432
4433DEFUN (no_bgp_network_mask,
4434 no_bgp_network_mask_cmd,
4435 "no network A.B.C.D mask A.B.C.D",
4436 NO_STR
4437 "Specify a network to announce via BGP\n"
4438 "Network number\n"
4439 "Network mask\n"
4440 "Network mask\n")
4441{
4442 int ret;
4443 char prefix_str[BUFSIZ];
4444
4445 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4446 if (! ret)
4447 {
4448 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4449 return CMD_WARNING;
4450 }
4451
4452 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4453 bgp_node_safi (vty));
4454}
4455
4456ALIAS (no_bgp_network_mask,
4457 no_bgp_network_mask_route_map_cmd,
4458 "no network A.B.C.D mask A.B.C.D route-map WORD",
4459 NO_STR
4460 "Specify a network to announce via BGP\n"
4461 "Network number\n"
4462 "Network mask\n"
4463 "Network mask\n"
4464 "Route-map to modify the attributes\n"
4465 "Name of the route map\n")
4466
4467ALIAS (no_bgp_network_mask,
4468 no_bgp_network_mask_backdoor_cmd,
4469 "no network A.B.C.D mask A.B.C.D backdoor",
4470 NO_STR
4471 "Specify a network to announce via BGP\n"
4472 "Network number\n"
4473 "Network mask\n"
4474 "Network mask\n"
4475 "Specify a BGP backdoor route\n")
4476
4477DEFUN (no_bgp_network_mask_natural,
4478 no_bgp_network_mask_natural_cmd,
4479 "no network A.B.C.D",
4480 NO_STR
4481 "Specify a network to announce via BGP\n"
4482 "Network number\n")
4483{
4484 int ret;
4485 char prefix_str[BUFSIZ];
4486
4487 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4488 if (! ret)
4489 {
4490 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4491 return CMD_WARNING;
4492 }
4493
4494 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4495 bgp_node_safi (vty));
4496}
4497
4498ALIAS (no_bgp_network_mask_natural,
4499 no_bgp_network_mask_natural_route_map_cmd,
4500 "no network A.B.C.D route-map WORD",
4501 NO_STR
4502 "Specify a network to announce via BGP\n"
4503 "Network number\n"
4504 "Route-map to modify the attributes\n"
4505 "Name of the route map\n")
4506
4507ALIAS (no_bgp_network_mask_natural,
4508 no_bgp_network_mask_natural_backdoor_cmd,
4509 "no network A.B.C.D backdoor",
4510 NO_STR
4511 "Specify a network to announce via BGP\n"
4512 "Network number\n"
4513 "Specify a BGP backdoor route\n")
4514
paul718e3742002-12-13 20:15:29 +00004515DEFUN (ipv6_bgp_network,
4516 ipv6_bgp_network_cmd,
4517 "network X:X::X:X/M",
4518 "Specify a network to announce via BGP\n"
4519 "IPv6 prefix <network>/<length>\n")
4520{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304521 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004522 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004523}
4524
4525DEFUN (ipv6_bgp_network_route_map,
4526 ipv6_bgp_network_route_map_cmd,
4527 "network X:X::X:X/M route-map WORD",
4528 "Specify a network to announce via BGP\n"
4529 "IPv6 prefix <network>/<length>\n"
4530 "Route-map to modify the attributes\n"
4531 "Name of the route map\n")
4532{
4533 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004534 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004535}
4536
4537DEFUN (no_ipv6_bgp_network,
4538 no_ipv6_bgp_network_cmd,
4539 "no network X:X::X:X/M",
4540 NO_STR
4541 "Specify a network to announce via BGP\n"
4542 "IPv6 prefix <network>/<length>\n")
4543{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304544 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004545}
4546
4547ALIAS (no_ipv6_bgp_network,
4548 no_ipv6_bgp_network_route_map_cmd,
4549 "no network X:X::X:X/M route-map WORD",
4550 NO_STR
4551 "Specify a network to announce via BGP\n"
4552 "IPv6 prefix <network>/<length>\n"
4553 "Route-map to modify the attributes\n"
4554 "Name of the route map\n")
4555
4556ALIAS (ipv6_bgp_network,
4557 old_ipv6_bgp_network_cmd,
4558 "ipv6 bgp network X:X::X:X/M",
4559 IPV6_STR
4560 BGP_STR
4561 "Specify a network to announce via BGP\n"
4562 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4563
4564ALIAS (no_ipv6_bgp_network,
4565 old_no_ipv6_bgp_network_cmd,
4566 "no ipv6 bgp network X:X::X:X/M",
4567 NO_STR
4568 IPV6_STR
4569 BGP_STR
4570 "Specify a network to announce via BGP\n"
4571 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004572
4573/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4574ALIAS_DEPRECATED (bgp_network,
4575 bgp_network_ttl_cmd,
4576 "network A.B.C.D/M pathlimit <0-255>",
4577 "Specify a network to announce via BGP\n"
4578 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4579 "AS-Path hopcount limit attribute\n"
4580 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4581ALIAS_DEPRECATED (bgp_network_backdoor,
4582 bgp_network_backdoor_ttl_cmd,
4583 "network A.B.C.D/M backdoor pathlimit <0-255>",
4584 "Specify a network to announce via BGP\n"
4585 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4586 "Specify a BGP backdoor route\n"
4587 "AS-Path hopcount limit attribute\n"
4588 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4589ALIAS_DEPRECATED (bgp_network_mask,
4590 bgp_network_mask_ttl_cmd,
4591 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4592 "Specify a network to announce via BGP\n"
4593 "Network number\n"
4594 "Network mask\n"
4595 "Network mask\n"
4596 "AS-Path hopcount limit attribute\n"
4597 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4598ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4599 bgp_network_mask_backdoor_ttl_cmd,
4600 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4601 "Specify a network to announce via BGP\n"
4602 "Network number\n"
4603 "Network mask\n"
4604 "Network mask\n"
4605 "Specify a BGP backdoor route\n"
4606 "AS-Path hopcount limit attribute\n"
4607 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4608ALIAS_DEPRECATED (bgp_network_mask_natural,
4609 bgp_network_mask_natural_ttl_cmd,
4610 "network A.B.C.D pathlimit <0-255>",
4611 "Specify a network to announce via BGP\n"
4612 "Network number\n"
4613 "AS-Path hopcount limit attribute\n"
4614 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4615ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4616 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004617 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004618 "Specify a network to announce via BGP\n"
4619 "Network number\n"
4620 "Specify a BGP backdoor route\n"
4621 "AS-Path hopcount limit attribute\n"
4622 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4623ALIAS_DEPRECATED (no_bgp_network,
4624 no_bgp_network_ttl_cmd,
4625 "no network A.B.C.D/M pathlimit <0-255>",
4626 NO_STR
4627 "Specify a network to announce via BGP\n"
4628 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4629 "AS-Path hopcount limit attribute\n"
4630 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4631ALIAS_DEPRECATED (no_bgp_network,
4632 no_bgp_network_backdoor_ttl_cmd,
4633 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4634 NO_STR
4635 "Specify a network to announce via BGP\n"
4636 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4637 "Specify a BGP backdoor route\n"
4638 "AS-Path hopcount limit attribute\n"
4639 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4640ALIAS_DEPRECATED (no_bgp_network,
4641 no_bgp_network_mask_ttl_cmd,
4642 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4643 NO_STR
4644 "Specify a network to announce via BGP\n"
4645 "Network number\n"
4646 "Network mask\n"
4647 "Network mask\n"
4648 "AS-Path hopcount limit attribute\n"
4649 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4650ALIAS_DEPRECATED (no_bgp_network_mask,
4651 no_bgp_network_mask_backdoor_ttl_cmd,
4652 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4653 NO_STR
4654 "Specify a network to announce via BGP\n"
4655 "Network number\n"
4656 "Network mask\n"
4657 "Network mask\n"
4658 "Specify a BGP backdoor route\n"
4659 "AS-Path hopcount limit attribute\n"
4660 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4661ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4662 no_bgp_network_mask_natural_ttl_cmd,
4663 "no network A.B.C.D pathlimit <0-255>",
4664 NO_STR
4665 "Specify a network to announce via BGP\n"
4666 "Network number\n"
4667 "AS-Path hopcount limit attribute\n"
4668 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4669ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4670 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4671 "no network A.B.C.D backdoor pathlimit <0-255>",
4672 NO_STR
4673 "Specify a network to announce via BGP\n"
4674 "Network number\n"
4675 "Specify a BGP backdoor route\n"
4676 "AS-Path hopcount limit attribute\n"
4677 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4678ALIAS_DEPRECATED (ipv6_bgp_network,
4679 ipv6_bgp_network_ttl_cmd,
4680 "network X:X::X:X/M pathlimit <0-255>",
4681 "Specify a network to announce via BGP\n"
4682 "IPv6 prefix <network>/<length>\n"
4683 "AS-Path hopcount limit attribute\n"
4684 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4685ALIAS_DEPRECATED (no_ipv6_bgp_network,
4686 no_ipv6_bgp_network_ttl_cmd,
4687 "no network X:X::X:X/M pathlimit <0-255>",
4688 NO_STR
4689 "Specify a network to announce via BGP\n"
4690 "IPv6 prefix <network>/<length>\n"
4691 "AS-Path hopcount limit attribute\n"
4692 "AS-Pathlimit TTL, in number of AS-Path hops\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02004693
paul718e3742002-12-13 20:15:29 +00004694/* Aggreagete address:
4695
4696 advertise-map Set condition to advertise attribute
4697 as-set Generate AS set path information
4698 attribute-map Set attributes of aggregate
4699 route-map Set parameters of aggregate
4700 summary-only Filter more specific routes from updates
4701 suppress-map Conditionally filter more specific routes from updates
4702 <cr>
4703 */
4704struct bgp_aggregate
4705{
4706 /* Summary-only flag. */
4707 u_char summary_only;
4708
4709 /* AS set generation. */
4710 u_char as_set;
4711
4712 /* Route-map for aggregated route. */
4713 struct route_map *map;
4714
4715 /* Suppress-count. */
4716 unsigned long count;
4717
4718 /* SAFI configuration. */
4719 safi_t safi;
4720};
4721
paul94f2b392005-06-28 12:44:16 +00004722static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004723bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004724{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004725 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004726}
4727
paul94f2b392005-06-28 12:44:16 +00004728static void
paul718e3742002-12-13 20:15:29 +00004729bgp_aggregate_free (struct bgp_aggregate *aggregate)
4730{
4731 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4732}
4733
paul94f2b392005-06-28 12:44:16 +00004734static void
paul718e3742002-12-13 20:15:29 +00004735bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4736 afi_t afi, safi_t safi, struct bgp_info *del,
4737 struct bgp_aggregate *aggregate)
4738{
4739 struct bgp_table *table;
4740 struct bgp_node *top;
4741 struct bgp_node *rn;
4742 u_char origin;
4743 struct aspath *aspath = NULL;
4744 struct aspath *asmerge = NULL;
4745 struct community *community = NULL;
4746 struct community *commerge = NULL;
paul718e3742002-12-13 20:15:29 +00004747 struct bgp_info *ri;
4748 struct bgp_info *new;
4749 int first = 1;
4750 unsigned long match = 0;
4751
paul718e3742002-12-13 20:15:29 +00004752 /* ORIGIN attribute: If at least one route among routes that are
4753 aggregated has ORIGIN with the value INCOMPLETE, then the
4754 aggregated route must have the ORIGIN attribute with the value
4755 INCOMPLETE. Otherwise, if at least one route among routes that
4756 are aggregated has ORIGIN with the value EGP, then the aggregated
4757 route must have the origin attribute with the value EGP. In all
4758 other case the value of the ORIGIN attribute of the aggregated
4759 route is INTERNAL. */
4760 origin = BGP_ORIGIN_IGP;
4761
4762 table = bgp->rib[afi][safi];
4763
4764 top = bgp_node_get (table, p);
4765 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4766 if (rn->p.prefixlen > p->prefixlen)
4767 {
4768 match = 0;
4769
4770 for (ri = rn->info; ri; ri = ri->next)
4771 {
4772 if (BGP_INFO_HOLDDOWN (ri))
4773 continue;
4774
4775 if (del && ri == del)
4776 continue;
4777
4778 if (! rinew && first)
Paul Jakma7aa9dce2014-09-19 14:42:23 +01004779 first = 0;
paul718e3742002-12-13 20:15:29 +00004780
4781#ifdef AGGREGATE_NEXTHOP_CHECK
4782 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4783 || ri->attr->med != med)
4784 {
4785 if (aspath)
4786 aspath_free (aspath);
4787 if (community)
4788 community_free (community);
4789 bgp_unlock_node (rn);
4790 bgp_unlock_node (top);
4791 return;
4792 }
4793#endif /* AGGREGATE_NEXTHOP_CHECK */
4794
4795 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4796 {
4797 if (aggregate->summary_only)
4798 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004799 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004800 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004801 match++;
4802 }
4803
4804 aggregate->count++;
4805
4806 if (aggregate->as_set)
4807 {
4808 if (origin < ri->attr->origin)
4809 origin = ri->attr->origin;
4810
4811 if (aspath)
4812 {
4813 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4814 aspath_free (aspath);
4815 aspath = asmerge;
4816 }
4817 else
4818 aspath = aspath_dup (ri->attr->aspath);
4819
4820 if (ri->attr->community)
4821 {
4822 if (community)
4823 {
4824 commerge = community_merge (community,
4825 ri->attr->community);
4826 community = community_uniq_sort (commerge);
4827 community_free (commerge);
4828 }
4829 else
4830 community = community_dup (ri->attr->community);
4831 }
4832 }
4833 }
4834 }
4835 if (match)
4836 bgp_process (bgp, rn, afi, safi);
4837 }
4838 bgp_unlock_node (top);
4839
4840 if (rinew)
4841 {
4842 aggregate->count++;
4843
4844 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004845 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004846
4847 if (aggregate->as_set)
4848 {
4849 if (origin < rinew->attr->origin)
4850 origin = rinew->attr->origin;
4851
4852 if (aspath)
4853 {
4854 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4855 aspath_free (aspath);
4856 aspath = asmerge;
4857 }
4858 else
4859 aspath = aspath_dup (rinew->attr->aspath);
4860
4861 if (rinew->attr->community)
4862 {
4863 if (community)
4864 {
4865 commerge = community_merge (community,
4866 rinew->attr->community);
4867 community = community_uniq_sort (commerge);
4868 community_free (commerge);
4869 }
4870 else
4871 community = community_dup (rinew->attr->community);
4872 }
4873 }
4874 }
4875
4876 if (aggregate->count > 0)
4877 {
4878 rn = bgp_node_get (table, p);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05004879 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, bgp->peer_self,
4880 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
4881 aggregate->as_set), rn);
paul718e3742002-12-13 20:15:29 +00004882 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00004883
4884 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004885 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004886 bgp_process (bgp, rn, afi, safi);
4887 }
4888 else
4889 {
4890 if (aspath)
4891 aspath_free (aspath);
4892 if (community)
4893 community_free (community);
4894 }
4895}
4896
4897void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4898 struct bgp_aggregate *);
4899
4900void
4901bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4902 struct bgp_info *ri, afi_t afi, safi_t safi)
4903{
4904 struct bgp_node *child;
4905 struct bgp_node *rn;
4906 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004907 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004908
4909 /* MPLS-VPN aggregation is not yet supported. */
Lou Berger298cc2f2016-01-12 13:42:02 -05004910 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004911 return;
4912
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004913 table = bgp->aggregate[afi][safi];
4914
4915 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004916 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004917 return;
4918
paul718e3742002-12-13 20:15:29 +00004919 if (p->prefixlen == 0)
4920 return;
4921
4922 if (BGP_INFO_HOLDDOWN (ri))
4923 return;
4924
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004925 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004926
4927 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004928 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004929 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4930 {
4931 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004932 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004933 }
4934 bgp_unlock_node (child);
4935}
4936
4937void
4938bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4939 struct bgp_info *del, afi_t afi, safi_t safi)
4940{
4941 struct bgp_node *child;
4942 struct bgp_node *rn;
4943 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004944 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004945
4946 /* MPLS-VPN aggregation is not yet supported. */
Lou Berger298cc2f2016-01-12 13:42:02 -05004947 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004948 return;
4949
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004950 table = bgp->aggregate[afi][safi];
4951
4952 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004953 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004954 return;
4955
paul718e3742002-12-13 20:15:29 +00004956 if (p->prefixlen == 0)
4957 return;
4958
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004959 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004960
4961 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004962 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004963 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4964 {
4965 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004966 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004967 }
4968 bgp_unlock_node (child);
4969}
4970
paul94f2b392005-06-28 12:44:16 +00004971static void
paul718e3742002-12-13 20:15:29 +00004972bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4973 struct bgp_aggregate *aggregate)
4974{
4975 struct bgp_table *table;
4976 struct bgp_node *top;
4977 struct bgp_node *rn;
4978 struct bgp_info *new;
4979 struct bgp_info *ri;
4980 unsigned long match;
4981 u_char origin = BGP_ORIGIN_IGP;
4982 struct aspath *aspath = NULL;
4983 struct aspath *asmerge = NULL;
4984 struct community *community = NULL;
4985 struct community *commerge = NULL;
4986
4987 table = bgp->rib[afi][safi];
4988
4989 /* Sanity check. */
4990 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4991 return;
4992 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4993 return;
4994
4995 /* If routes exists below this node, generate aggregate routes. */
4996 top = bgp_node_get (table, p);
4997 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4998 if (rn->p.prefixlen > p->prefixlen)
4999 {
5000 match = 0;
5001
5002 for (ri = rn->info; ri; ri = ri->next)
5003 {
5004 if (BGP_INFO_HOLDDOWN (ri))
5005 continue;
5006
5007 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5008 {
5009 /* summary-only aggregate route suppress aggregated
5010 route announcement. */
5011 if (aggregate->summary_only)
5012 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005013 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00005014 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005015 match++;
5016 }
5017 /* as-set aggregate route generate origin, as path,
5018 community aggregation. */
5019 if (aggregate->as_set)
5020 {
5021 if (origin < ri->attr->origin)
5022 origin = ri->attr->origin;
5023
5024 if (aspath)
5025 {
5026 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5027 aspath_free (aspath);
5028 aspath = asmerge;
5029 }
5030 else
5031 aspath = aspath_dup (ri->attr->aspath);
5032
5033 if (ri->attr->community)
5034 {
5035 if (community)
5036 {
5037 commerge = community_merge (community,
5038 ri->attr->community);
5039 community = community_uniq_sort (commerge);
5040 community_free (commerge);
5041 }
5042 else
5043 community = community_dup (ri->attr->community);
5044 }
5045 }
5046 aggregate->count++;
5047 }
5048 }
5049
5050 /* If this node is suppressed, process the change. */
5051 if (match)
5052 bgp_process (bgp, rn, afi, safi);
5053 }
5054 bgp_unlock_node (top);
5055
5056 /* Add aggregate route to BGP table. */
5057 if (aggregate->count)
5058 {
5059 rn = bgp_node_get (table, p);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05005060 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, bgp->peer_self,
5061 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
5062 aggregate->as_set), rn);
paul718e3742002-12-13 20:15:29 +00005063 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00005064
5065 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00005066 bgp_unlock_node (rn);
5067
paul718e3742002-12-13 20:15:29 +00005068 /* Process change. */
5069 bgp_process (bgp, rn, afi, safi);
5070 }
Denil Virae2a92582015-08-11 13:34:59 -07005071 else
5072 {
5073 if (aspath)
5074 aspath_free (aspath);
5075 if (community)
5076 community_free (community);
5077 }
paul718e3742002-12-13 20:15:29 +00005078}
5079
5080void
5081bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5082 safi_t safi, struct bgp_aggregate *aggregate)
5083{
5084 struct bgp_table *table;
5085 struct bgp_node *top;
5086 struct bgp_node *rn;
5087 struct bgp_info *ri;
5088 unsigned long match;
5089
5090 table = bgp->rib[afi][safi];
5091
5092 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5093 return;
5094 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5095 return;
5096
5097 /* If routes exists below this node, generate aggregate routes. */
5098 top = bgp_node_get (table, p);
5099 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5100 if (rn->p.prefixlen > p->prefixlen)
5101 {
5102 match = 0;
5103
5104 for (ri = rn->info; ri; ri = ri->next)
5105 {
5106 if (BGP_INFO_HOLDDOWN (ri))
5107 continue;
5108
5109 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5110 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005111 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00005112 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005113 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00005114
Paul Jakmafb982c22007-05-04 20:15:47 +00005115 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00005116 {
Paul Jakma1a392d42006-09-07 00:24:49 +00005117 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005118 match++;
5119 }
5120 }
5121 aggregate->count--;
5122 }
5123 }
5124
Paul Jakmafb982c22007-05-04 20:15:47 +00005125 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00005126 if (match)
5127 bgp_process (bgp, rn, afi, safi);
5128 }
5129 bgp_unlock_node (top);
5130
5131 /* Delete aggregate route from BGP table. */
5132 rn = bgp_node_get (table, p);
5133
5134 for (ri = rn->info; ri; ri = ri->next)
5135 if (ri->peer == bgp->peer_self
5136 && ri->type == ZEBRA_ROUTE_BGP
5137 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5138 break;
5139
5140 /* Withdraw static BGP route from routing table. */
5141 if (ri)
5142 {
paul718e3742002-12-13 20:15:29 +00005143 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005144 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00005145 }
5146
5147 /* Unlock bgp_node_lookup. */
5148 bgp_unlock_node (rn);
5149}
5150
5151/* Aggregate route attribute. */
5152#define AGGREGATE_SUMMARY_ONLY 1
5153#define AGGREGATE_AS_SET 1
5154
paul94f2b392005-06-28 12:44:16 +00005155static int
Robert Baysf6269b42010-08-05 10:26:28 -07005156bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5157 afi_t afi, safi_t safi)
5158{
5159 int ret;
5160 struct prefix p;
5161 struct bgp_node *rn;
5162 struct bgp *bgp;
5163 struct bgp_aggregate *aggregate;
5164
5165 /* Convert string to prefix structure. */
5166 ret = str2prefix (prefix_str, &p);
5167 if (!ret)
5168 {
5169 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5170 return CMD_WARNING;
5171 }
5172 apply_mask (&p);
5173
5174 /* Get BGP structure. */
5175 bgp = vty->index;
5176
5177 /* Old configuration check. */
5178 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5179 if (! rn)
5180 {
5181 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5182 VTY_NEWLINE);
5183 return CMD_WARNING;
5184 }
5185
5186 aggregate = rn->info;
5187 if (aggregate->safi & SAFI_UNICAST)
5188 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5189 if (aggregate->safi & SAFI_MULTICAST)
5190 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5191
5192 /* Unlock aggregate address configuration. */
5193 rn->info = NULL;
5194 bgp_aggregate_free (aggregate);
5195 bgp_unlock_node (rn);
5196 bgp_unlock_node (rn);
5197
5198 return CMD_SUCCESS;
5199}
5200
5201static int
5202bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00005203 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00005204 u_char summary_only, u_char as_set)
5205{
5206 int ret;
5207 struct prefix p;
5208 struct bgp_node *rn;
5209 struct bgp *bgp;
5210 struct bgp_aggregate *aggregate;
5211
5212 /* Convert string to prefix structure. */
5213 ret = str2prefix (prefix_str, &p);
5214 if (!ret)
5215 {
5216 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5217 return CMD_WARNING;
5218 }
5219 apply_mask (&p);
5220
5221 /* Get BGP structure. */
5222 bgp = vty->index;
5223
5224 /* Old configuration check. */
5225 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5226
5227 if (rn->info)
5228 {
5229 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005230 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005231 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5232 if (ret)
5233 {
Robert Bays368473f2010-08-05 10:26:29 -07005234 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5235 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005236 return CMD_WARNING;
5237 }
paul718e3742002-12-13 20:15:29 +00005238 }
5239
5240 /* Make aggregate address structure. */
5241 aggregate = bgp_aggregate_new ();
5242 aggregate->summary_only = summary_only;
5243 aggregate->as_set = as_set;
5244 aggregate->safi = safi;
5245 rn->info = aggregate;
5246
5247 /* Aggregate address insert into BGP routing table. */
5248 if (safi & SAFI_UNICAST)
5249 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5250 if (safi & SAFI_MULTICAST)
5251 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5252
5253 return CMD_SUCCESS;
5254}
5255
paul718e3742002-12-13 20:15:29 +00005256DEFUN (aggregate_address,
5257 aggregate_address_cmd,
5258 "aggregate-address A.B.C.D/M",
5259 "Configure BGP aggregate entries\n"
5260 "Aggregate prefix\n")
5261{
5262 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5263}
5264
5265DEFUN (aggregate_address_mask,
5266 aggregate_address_mask_cmd,
5267 "aggregate-address A.B.C.D A.B.C.D",
5268 "Configure BGP aggregate entries\n"
5269 "Aggregate address\n"
5270 "Aggregate mask\n")
5271{
5272 int ret;
5273 char prefix_str[BUFSIZ];
5274
5275 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5276
5277 if (! ret)
5278 {
5279 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5280 return CMD_WARNING;
5281 }
5282
5283 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5284 0, 0);
5285}
5286
5287DEFUN (aggregate_address_summary_only,
5288 aggregate_address_summary_only_cmd,
5289 "aggregate-address A.B.C.D/M summary-only",
5290 "Configure BGP aggregate entries\n"
5291 "Aggregate prefix\n"
5292 "Filter more specific routes from updates\n")
5293{
5294 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5295 AGGREGATE_SUMMARY_ONLY, 0);
5296}
5297
5298DEFUN (aggregate_address_mask_summary_only,
5299 aggregate_address_mask_summary_only_cmd,
5300 "aggregate-address A.B.C.D A.B.C.D summary-only",
5301 "Configure BGP aggregate entries\n"
5302 "Aggregate address\n"
5303 "Aggregate mask\n"
5304 "Filter more specific routes from updates\n")
5305{
5306 int ret;
5307 char prefix_str[BUFSIZ];
5308
5309 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5310
5311 if (! ret)
5312 {
5313 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5314 return CMD_WARNING;
5315 }
5316
5317 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5318 AGGREGATE_SUMMARY_ONLY, 0);
5319}
5320
5321DEFUN (aggregate_address_as_set,
5322 aggregate_address_as_set_cmd,
5323 "aggregate-address A.B.C.D/M as-set",
5324 "Configure BGP aggregate entries\n"
5325 "Aggregate prefix\n"
5326 "Generate AS set path information\n")
5327{
5328 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5329 0, AGGREGATE_AS_SET);
5330}
5331
5332DEFUN (aggregate_address_mask_as_set,
5333 aggregate_address_mask_as_set_cmd,
5334 "aggregate-address A.B.C.D A.B.C.D as-set",
5335 "Configure BGP aggregate entries\n"
5336 "Aggregate address\n"
5337 "Aggregate mask\n"
5338 "Generate AS set path information\n")
5339{
5340 int ret;
5341 char prefix_str[BUFSIZ];
5342
5343 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5344
5345 if (! ret)
5346 {
5347 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5348 return CMD_WARNING;
5349 }
5350
5351 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5352 0, AGGREGATE_AS_SET);
5353}
5354
5355
5356DEFUN (aggregate_address_as_set_summary,
5357 aggregate_address_as_set_summary_cmd,
5358 "aggregate-address A.B.C.D/M as-set summary-only",
5359 "Configure BGP aggregate entries\n"
5360 "Aggregate prefix\n"
5361 "Generate AS set path information\n"
5362 "Filter more specific routes from updates\n")
5363{
5364 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5365 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5366}
5367
5368ALIAS (aggregate_address_as_set_summary,
5369 aggregate_address_summary_as_set_cmd,
5370 "aggregate-address A.B.C.D/M summary-only as-set",
5371 "Configure BGP aggregate entries\n"
5372 "Aggregate prefix\n"
5373 "Filter more specific routes from updates\n"
5374 "Generate AS set path information\n")
5375
5376DEFUN (aggregate_address_mask_as_set_summary,
5377 aggregate_address_mask_as_set_summary_cmd,
5378 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5379 "Configure BGP aggregate entries\n"
5380 "Aggregate address\n"
5381 "Aggregate mask\n"
5382 "Generate AS set path information\n"
5383 "Filter more specific routes from updates\n")
5384{
5385 int ret;
5386 char prefix_str[BUFSIZ];
5387
5388 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5389
5390 if (! ret)
5391 {
5392 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5393 return CMD_WARNING;
5394 }
5395
5396 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5397 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5398}
5399
5400ALIAS (aggregate_address_mask_as_set_summary,
5401 aggregate_address_mask_summary_as_set_cmd,
5402 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5403 "Configure BGP aggregate entries\n"
5404 "Aggregate address\n"
5405 "Aggregate mask\n"
5406 "Filter more specific routes from updates\n"
5407 "Generate AS set path information\n")
5408
5409DEFUN (no_aggregate_address,
5410 no_aggregate_address_cmd,
5411 "no aggregate-address A.B.C.D/M",
5412 NO_STR
5413 "Configure BGP aggregate entries\n"
5414 "Aggregate prefix\n")
5415{
5416 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5417}
5418
5419ALIAS (no_aggregate_address,
5420 no_aggregate_address_summary_only_cmd,
5421 "no aggregate-address A.B.C.D/M summary-only",
5422 NO_STR
5423 "Configure BGP aggregate entries\n"
5424 "Aggregate prefix\n"
5425 "Filter more specific routes from updates\n")
5426
5427ALIAS (no_aggregate_address,
5428 no_aggregate_address_as_set_cmd,
5429 "no aggregate-address A.B.C.D/M as-set",
5430 NO_STR
5431 "Configure BGP aggregate entries\n"
5432 "Aggregate prefix\n"
5433 "Generate AS set path information\n")
5434
5435ALIAS (no_aggregate_address,
5436 no_aggregate_address_as_set_summary_cmd,
5437 "no aggregate-address A.B.C.D/M as-set summary-only",
5438 NO_STR
5439 "Configure BGP aggregate entries\n"
5440 "Aggregate prefix\n"
5441 "Generate AS set path information\n"
5442 "Filter more specific routes from updates\n")
5443
5444ALIAS (no_aggregate_address,
5445 no_aggregate_address_summary_as_set_cmd,
5446 "no aggregate-address A.B.C.D/M summary-only as-set",
5447 NO_STR
5448 "Configure BGP aggregate entries\n"
5449 "Aggregate prefix\n"
5450 "Filter more specific routes from updates\n"
5451 "Generate AS set path information\n")
5452
5453DEFUN (no_aggregate_address_mask,
5454 no_aggregate_address_mask_cmd,
5455 "no aggregate-address A.B.C.D A.B.C.D",
5456 NO_STR
5457 "Configure BGP aggregate entries\n"
5458 "Aggregate address\n"
5459 "Aggregate mask\n")
5460{
5461 int ret;
5462 char prefix_str[BUFSIZ];
5463
5464 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5465
5466 if (! ret)
5467 {
5468 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5469 return CMD_WARNING;
5470 }
5471
5472 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5473}
5474
5475ALIAS (no_aggregate_address_mask,
5476 no_aggregate_address_mask_summary_only_cmd,
5477 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5478 NO_STR
5479 "Configure BGP aggregate entries\n"
5480 "Aggregate address\n"
5481 "Aggregate mask\n"
5482 "Filter more specific routes from updates\n")
5483
5484ALIAS (no_aggregate_address_mask,
5485 no_aggregate_address_mask_as_set_cmd,
5486 "no aggregate-address A.B.C.D A.B.C.D as-set",
5487 NO_STR
5488 "Configure BGP aggregate entries\n"
5489 "Aggregate address\n"
5490 "Aggregate mask\n"
5491 "Generate AS set path information\n")
5492
5493ALIAS (no_aggregate_address_mask,
5494 no_aggregate_address_mask_as_set_summary_cmd,
5495 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5496 NO_STR
5497 "Configure BGP aggregate entries\n"
5498 "Aggregate address\n"
5499 "Aggregate mask\n"
5500 "Generate AS set path information\n"
5501 "Filter more specific routes from updates\n")
5502
5503ALIAS (no_aggregate_address_mask,
5504 no_aggregate_address_mask_summary_as_set_cmd,
5505 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5506 NO_STR
5507 "Configure BGP aggregate entries\n"
5508 "Aggregate address\n"
5509 "Aggregate mask\n"
5510 "Filter more specific routes from updates\n"
5511 "Generate AS set path information\n")
5512
paul718e3742002-12-13 20:15:29 +00005513DEFUN (ipv6_aggregate_address,
5514 ipv6_aggregate_address_cmd,
5515 "aggregate-address X:X::X:X/M",
5516 "Configure BGP aggregate entries\n"
5517 "Aggregate prefix\n")
5518{
5519 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5520}
5521
5522DEFUN (ipv6_aggregate_address_summary_only,
5523 ipv6_aggregate_address_summary_only_cmd,
5524 "aggregate-address X:X::X:X/M summary-only",
5525 "Configure BGP aggregate entries\n"
5526 "Aggregate prefix\n"
5527 "Filter more specific routes from updates\n")
5528{
5529 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5530 AGGREGATE_SUMMARY_ONLY, 0);
5531}
5532
5533DEFUN (no_ipv6_aggregate_address,
5534 no_ipv6_aggregate_address_cmd,
5535 "no aggregate-address X:X::X:X/M",
5536 NO_STR
5537 "Configure BGP aggregate entries\n"
5538 "Aggregate prefix\n")
5539{
5540 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5541}
5542
5543DEFUN (no_ipv6_aggregate_address_summary_only,
5544 no_ipv6_aggregate_address_summary_only_cmd,
5545 "no aggregate-address X:X::X:X/M summary-only",
5546 NO_STR
5547 "Configure BGP aggregate entries\n"
5548 "Aggregate prefix\n"
5549 "Filter more specific routes from updates\n")
5550{
5551 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5552}
5553
5554ALIAS (ipv6_aggregate_address,
5555 old_ipv6_aggregate_address_cmd,
5556 "ipv6 bgp aggregate-address X:X::X:X/M",
5557 IPV6_STR
5558 BGP_STR
5559 "Configure BGP aggregate entries\n"
5560 "Aggregate prefix\n")
5561
5562ALIAS (ipv6_aggregate_address_summary_only,
5563 old_ipv6_aggregate_address_summary_only_cmd,
5564 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5565 IPV6_STR
5566 BGP_STR
5567 "Configure BGP aggregate entries\n"
5568 "Aggregate prefix\n"
5569 "Filter more specific routes from updates\n")
5570
5571ALIAS (no_ipv6_aggregate_address,
5572 old_no_ipv6_aggregate_address_cmd,
5573 "no ipv6 bgp aggregate-address X:X::X:X/M",
5574 NO_STR
5575 IPV6_STR
5576 BGP_STR
5577 "Configure BGP aggregate entries\n"
5578 "Aggregate prefix\n")
5579
5580ALIAS (no_ipv6_aggregate_address_summary_only,
5581 old_no_ipv6_aggregate_address_summary_only_cmd,
5582 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5583 NO_STR
5584 IPV6_STR
5585 BGP_STR
5586 "Configure BGP aggregate entries\n"
5587 "Aggregate prefix\n"
5588 "Filter more specific routes from updates\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02005589
paul718e3742002-12-13 20:15:29 +00005590/* Redistribute route treatment. */
5591void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005592bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5593 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005594 u_int32_t metric, u_char type)
5595{
5596 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005597 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005598 struct bgp_info *new;
5599 struct bgp_info *bi;
5600 struct bgp_info info;
5601 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005602 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005603 struct attr *new_attr;
5604 afi_t afi;
5605 int ret;
5606
5607 /* Make default attribute. */
5608 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5609 if (nexthop)
5610 attr.nexthop = *nexthop;
5611
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005612 if (nexthop6)
5613 {
5614 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5615 extra->mp_nexthop_global = *nexthop6;
5616 extra->mp_nexthop_len = 16;
5617 }
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005618
paul718e3742002-12-13 20:15:29 +00005619 attr.med = metric;
5620 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5621
paul1eb8ef22005-04-07 07:30:20 +00005622 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005623 {
5624 afi = family2afi (p->family);
5625
5626 if (bgp->redist[afi][type])
5627 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005628 struct attr attr_new;
5629 struct attr_extra extra_new;
5630
paul718e3742002-12-13 20:15:29 +00005631 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005632 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005633 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005634
5635 if (bgp->redist_metric_flag[afi][type])
5636 attr_new.med = bgp->redist_metric[afi][type];
5637
5638 /* Apply route-map. */
Daniel Walton1994dc82015-09-17 10:15:59 -04005639 if (bgp->rmap[afi][type].name)
paul718e3742002-12-13 20:15:29 +00005640 {
5641 info.peer = bgp->peer_self;
5642 info.attr = &attr_new;
5643
paulfee0f4c2004-09-13 05:12:46 +00005644 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5645
paul718e3742002-12-13 20:15:29 +00005646 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5647 &info);
paulfee0f4c2004-09-13 05:12:46 +00005648
5649 bgp->peer_self->rmap_type = 0;
5650
paul718e3742002-12-13 20:15:29 +00005651 if (ret == RMAP_DENYMATCH)
5652 {
5653 /* Free uninterned attribute. */
5654 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005655
paul718e3742002-12-13 20:15:29 +00005656 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005657 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005658 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005659 bgp_redistribute_delete (p, type);
5660 return;
5661 }
5662 }
5663
Paul Jakmafb982c22007-05-04 20:15:47 +00005664 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5665 afi, SAFI_UNICAST, p, NULL);
5666
paul718e3742002-12-13 20:15:29 +00005667 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005668
paul718e3742002-12-13 20:15:29 +00005669 for (bi = bn->info; bi; bi = bi->next)
5670 if (bi->peer == bgp->peer_self
5671 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5672 break;
5673
5674 if (bi)
5675 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005676 if (attrhash_cmp (bi->attr, new_attr) &&
5677 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005678 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005679 bgp_attr_unintern (&new_attr);
5680 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005681 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005682 bgp_unlock_node (bn);
5683 return;
5684 }
5685 else
5686 {
5687 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005688 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005689
5690 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005691 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5692 bgp_info_restore(bn, bi);
5693 else
5694 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005695 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005696 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005697 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005698
5699 /* Process change. */
5700 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5701 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5702 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005703 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005704 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005705 return;
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05005706 }
paul718e3742002-12-13 20:15:29 +00005707 }
5708
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05005709 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, bgp->peer_self,
5710 new_attr, bn);
paul718e3742002-12-13 20:15:29 +00005711 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00005712
5713 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5714 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005715 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005716 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5717 }
5718 }
5719
5720 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005721 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005722 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005723}
5724
5725void
5726bgp_redistribute_delete (struct prefix *p, u_char type)
5727{
5728 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005729 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005730 afi_t afi;
5731 struct bgp_node *rn;
5732 struct bgp_info *ri;
5733
paul1eb8ef22005-04-07 07:30:20 +00005734 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005735 {
5736 afi = family2afi (p->family);
5737
5738 if (bgp->redist[afi][type])
5739 {
paulfee0f4c2004-09-13 05:12:46 +00005740 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005741
5742 for (ri = rn->info; ri; ri = ri->next)
5743 if (ri->peer == bgp->peer_self
5744 && ri->type == type)
5745 break;
5746
5747 if (ri)
5748 {
5749 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005750 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005751 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005752 }
5753 bgp_unlock_node (rn);
5754 }
5755 }
5756}
5757
5758/* Withdraw specified route type's route. */
5759void
5760bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5761{
5762 struct bgp_node *rn;
5763 struct bgp_info *ri;
5764 struct bgp_table *table;
5765
5766 table = bgp->rib[afi][SAFI_UNICAST];
5767
5768 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5769 {
5770 for (ri = rn->info; ri; ri = ri->next)
5771 if (ri->peer == bgp->peer_self
5772 && ri->type == type)
5773 break;
5774
5775 if (ri)
5776 {
5777 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005778 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005779 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005780 }
5781 }
5782}
David Lamparter6b0655a2014-06-04 06:53:35 +02005783
paul718e3742002-12-13 20:15:29 +00005784/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005785static void
paul718e3742002-12-13 20:15:29 +00005786route_vty_out_route (struct prefix *p, struct vty *vty)
5787{
5788 int len;
5789 u_int32_t destination;
5790 char buf[BUFSIZ];
5791
5792 if (p->family == AF_INET)
5793 {
5794 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5795 destination = ntohl (p->u.prefix4.s_addr);
5796
5797 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5798 || (IN_CLASSB (destination) && p->prefixlen == 16)
5799 || (IN_CLASSA (destination) && p->prefixlen == 8)
5800 || p->u.prefix4.s_addr == 0)
5801 {
5802 /* When mask is natural, mask is not displayed. */
5803 }
5804 else
5805 len += vty_out (vty, "/%d", p->prefixlen);
5806 }
5807 else
5808 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5809 p->prefixlen);
5810
5811 len = 17 - len;
5812 if (len < 1)
5813 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5814 else
5815 vty_out (vty, "%*s", len, " ");
5816}
5817
paul718e3742002-12-13 20:15:29 +00005818enum bgp_display_type
5819{
5820 normal_list,
5821};
5822
paulb40d9392005-08-22 22:34:41 +00005823/* Print the short form route status for a bgp_info */
5824static void
5825route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005826{
paulb40d9392005-08-22 22:34:41 +00005827 /* Route status display. */
5828 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5829 vty_out (vty, "R");
5830 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005831 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005832 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005833 vty_out (vty, "s");
5834 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5835 vty_out (vty, "*");
5836 else
5837 vty_out (vty, " ");
5838
5839 /* Selected */
5840 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5841 vty_out (vty, "h");
5842 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5843 vty_out (vty, "d");
5844 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5845 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005846 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5847 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005848 else
5849 vty_out (vty, " ");
5850
5851 /* Internal route. */
5852 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5853 vty_out (vty, "i");
5854 else
paulb40d9392005-08-22 22:34:41 +00005855 vty_out (vty, " ");
5856}
5857
5858/* called from terminal list command */
5859void
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005860route_vty_out(
5861 struct vty *vty,
5862 struct prefix *p,
5863 struct bgp_info *binfo,
5864 int display,
5865 safi_t safi)
paulb40d9392005-08-22 22:34:41 +00005866{
5867 struct attr *attr;
5868
5869 /* short status lead text */
5870 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005871
5872 /* print prefix and mask */
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005873 if (!display)
paul718e3742002-12-13 20:15:29 +00005874 route_vty_out_route (p, vty);
5875 else
5876 vty_out (vty, "%*s", 17, " ");
5877
5878 /* Print attribute */
5879 attr = binfo->attr;
5880 if (attr)
5881 {
paul718e3742002-12-13 20:15:29 +00005882
Lou Berger298cc2f2016-01-12 13:42:02 -05005883 /*
5884 * NEXTHOP start
5885 */
5886
5887 /*
5888 * For ENCAP routes, nexthop address family is not
5889 * neccessarily the same as the prefix address family.
5890 * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
5891 */
5892 if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN)) {
5893 if (attr->extra) {
5894 char buf[BUFSIZ];
5895 int af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len);
5896
5897 switch (af) {
5898 case AF_INET:
5899 vty_out (vty, "%s", inet_ntop(af,
5900 &attr->extra->mp_nexthop_global_in, buf, BUFSIZ));
5901 break;
Lou Berger298cc2f2016-01-12 13:42:02 -05005902 case AF_INET6:
5903 vty_out (vty, "%s", inet_ntop(af,
5904 &attr->extra->mp_nexthop_global, buf, BUFSIZ));
5905 break;
Lou Berger298cc2f2016-01-12 13:42:02 -05005906 default:
5907 vty_out(vty, "?");
5908 }
5909 } else {
5910 vty_out(vty, "?");
paul718e3742002-12-13 20:15:29 +00005911 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005912 } else {
5913
5914 if (p->family == AF_INET)
5915 {
5916 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5917 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005918 else if (p->family == AF_INET6)
5919 {
5920 int len;
5921 char buf[BUFSIZ];
5922
5923 len = vty_out (vty, "%s",
5924 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5925 buf, BUFSIZ));
5926 len = 16 - len;
5927 if (len < 1)
5928 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5929 else
5930 vty_out (vty, "%*s", len, " ");
5931 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005932 else
5933 {
5934 vty_out(vty, "?");
5935 }
5936 }
5937
5938 /*
5939 * NEXTHOP end
5940 */
5941
paul718e3742002-12-13 20:15:29 +00005942
5943 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005944 vty_out (vty, "%10u ", attr->med);
paul718e3742002-12-13 20:15:29 +00005945 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005946 vty_out (vty, " ");
paul718e3742002-12-13 20:15:29 +00005947
5948 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005949 vty_out (vty, "%7u ", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005950 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005951 vty_out (vty, " ");
paul718e3742002-12-13 20:15:29 +00005952
Paul Jakmafb982c22007-05-04 20:15:47 +00005953 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005954
Paul Jakmab2518c12006-05-12 23:48:40 +00005955 /* Print aspath */
5956 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005957 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005958
Paul Jakmab2518c12006-05-12 23:48:40 +00005959 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005960 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005961 }
paul718e3742002-12-13 20:15:29 +00005962 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005963}
5964
5965/* called from terminal list command */
5966void
5967route_vty_out_tmp (struct vty *vty, struct prefix *p,
5968 struct attr *attr, safi_t safi)
5969{
5970 /* Route status display. */
5971 vty_out (vty, "*");
5972 vty_out (vty, ">");
5973 vty_out (vty, " ");
5974
5975 /* print prefix and mask */
5976 route_vty_out_route (p, vty);
5977
5978 /* Print attribute */
5979 if (attr)
5980 {
5981 if (p->family == AF_INET)
5982 {
Lou Berger298cc2f2016-01-12 13:42:02 -05005983 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00005984 vty_out (vty, "%-16s",
5985 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005986 else
5987 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5988 }
paul718e3742002-12-13 20:15:29 +00005989 else if (p->family == AF_INET6)
5990 {
5991 int len;
5992 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005993
5994 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005995
5996 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005997 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5998 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005999 len = 16 - len;
6000 if (len < 1)
6001 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6002 else
6003 vty_out (vty, "%*s", len, " ");
6004 }
paul718e3742002-12-13 20:15:29 +00006005
6006 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006007 vty_out (vty, "%10u ", attr->med);
paul718e3742002-12-13 20:15:29 +00006008 else
6009 vty_out (vty, " ");
6010
6011 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006012 vty_out (vty, "%7u ", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006013 else
6014 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006015
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006016 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00006017
Paul Jakmab2518c12006-05-12 23:48:40 +00006018 /* Print aspath */
6019 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006020 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006021
Paul Jakmab2518c12006-05-12 23:48:40 +00006022 /* Print origin */
paul718e3742002-12-13 20:15:29 +00006023 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00006024 }
paul718e3742002-12-13 20:15:29 +00006025
6026 vty_out (vty, "%s", VTY_NEWLINE);
6027}
6028
ajs5a646652004-11-05 01:25:55 +00006029void
paul718e3742002-12-13 20:15:29 +00006030route_vty_out_tag (struct vty *vty, struct prefix *p,
6031 struct bgp_info *binfo, int display, safi_t safi)
6032{
6033 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006034 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00006035
6036 if (!binfo->extra)
6037 return;
6038
paulb40d9392005-08-22 22:34:41 +00006039 /* short status lead text */
6040 route_vty_short_status_out (vty, binfo);
6041
paul718e3742002-12-13 20:15:29 +00006042 /* print prefix and mask */
6043 if (! display)
6044 route_vty_out_route (p, vty);
6045 else
6046 vty_out (vty, "%*s", 17, " ");
6047
6048 /* Print attribute */
6049 attr = binfo->attr;
6050 if (attr)
6051 {
6052 if (p->family == AF_INET)
6053 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006054 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00006055 vty_out (vty, "%-16s",
6056 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00006057 else
6058 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6059 }
paul718e3742002-12-13 20:15:29 +00006060 else if (p->family == AF_INET6)
6061 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006062 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006063 char buf[BUFSIZ];
6064 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006065 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00006066 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006067 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6068 buf, BUFSIZ));
6069 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006070 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006071 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6072 buf, BUFSIZ),
6073 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6074 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006075
6076 }
paul718e3742002-12-13 20:15:29 +00006077 }
6078
Paul Jakmafb982c22007-05-04 20:15:47 +00006079 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00006080
6081 vty_out (vty, "notag/%d", label);
6082
6083 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006084}
6085
6086/* dampening route */
ajs5a646652004-11-05 01:25:55 +00006087static void
paul718e3742002-12-13 20:15:29 +00006088damp_route_vty_out (struct vty *vty, struct prefix *p,
6089 struct bgp_info *binfo, int display, safi_t safi)
6090{
6091 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006092 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00006093 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00006094
paulb40d9392005-08-22 22:34:41 +00006095 /* short status lead text */
6096 route_vty_short_status_out (vty, binfo);
6097
paul718e3742002-12-13 20:15:29 +00006098 /* print prefix and mask */
6099 if (! display)
6100 route_vty_out_route (p, vty);
6101 else
6102 vty_out (vty, "%*s", 17, " ");
6103
6104 len = vty_out (vty, "%s", binfo->peer->host);
6105 len = 17 - len;
6106 if (len < 1)
6107 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6108 else
6109 vty_out (vty, "%*s", len, " ");
6110
Chris Caputo50aef6f2009-06-23 06:06:49 +00006111 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006112
6113 /* Print attribute */
6114 attr = binfo->attr;
6115 if (attr)
6116 {
6117 /* Print aspath */
6118 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006119 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006120
6121 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006122 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006123 }
6124 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006125}
6126
paul718e3742002-12-13 20:15:29 +00006127/* flap route */
ajs5a646652004-11-05 01:25:55 +00006128static void
paul718e3742002-12-13 20:15:29 +00006129flap_route_vty_out (struct vty *vty, struct prefix *p,
6130 struct bgp_info *binfo, int display, safi_t safi)
6131{
6132 struct attr *attr;
6133 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00006134 char timebuf[BGP_UPTIME_LEN];
6135 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00006136
6137 if (!binfo->extra)
6138 return;
6139
6140 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00006141
paulb40d9392005-08-22 22:34:41 +00006142 /* short status lead text */
6143 route_vty_short_status_out (vty, binfo);
6144
paul718e3742002-12-13 20:15:29 +00006145 /* print prefix and mask */
6146 if (! display)
6147 route_vty_out_route (p, vty);
6148 else
6149 vty_out (vty, "%*s", 17, " ");
6150
6151 len = vty_out (vty, "%s", binfo->peer->host);
6152 len = 16 - len;
6153 if (len < 1)
6154 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6155 else
6156 vty_out (vty, "%*s", len, " ");
6157
6158 len = vty_out (vty, "%d", bdi->flap);
6159 len = 5 - len;
6160 if (len < 1)
6161 vty_out (vty, " ");
6162 else
6163 vty_out (vty, "%*s ", len, " ");
6164
6165 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6166 timebuf, BGP_UPTIME_LEN));
6167
6168 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6169 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00006170 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006171 else
6172 vty_out (vty, "%*s ", 8, " ");
6173
6174 /* Print attribute */
6175 attr = binfo->attr;
6176 if (attr)
6177 {
6178 /* Print aspath */
6179 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006180 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006181
6182 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006183 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006184 }
6185 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006186}
6187
paul94f2b392005-06-28 12:44:16 +00006188static void
paul718e3742002-12-13 20:15:29 +00006189route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6190 struct bgp_info *binfo, afi_t afi, safi_t safi)
6191{
6192 char buf[INET6_ADDRSTRLEN];
6193 char buf1[BUFSIZ];
6194 struct attr *attr;
6195 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03006196#ifdef HAVE_CLOCK_MONOTONIC
6197 time_t tbuf;
6198#endif
paul718e3742002-12-13 20:15:29 +00006199
6200 attr = binfo->attr;
6201
6202 if (attr)
6203 {
6204 /* Line1 display AS-path, Aggregator */
6205 if (attr->aspath)
6206 {
6207 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00006208 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00006209 vty_out (vty, "Local");
6210 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006211 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00006212 }
6213
paulb40d9392005-08-22 22:34:41 +00006214 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6215 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00006216 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6217 vty_out (vty, ", (stale)");
6218 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006219 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006220 attr->extra->aggregator_as,
6221 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006222 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6223 vty_out (vty, ", (Received from a RR-client)");
6224 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6225 vty_out (vty, ", (Received from a RS-client)");
6226 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6227 vty_out (vty, ", (history entry)");
6228 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6229 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006230 vty_out (vty, "%s", VTY_NEWLINE);
6231
6232 /* Line2 display Next-hop, Neighbor, Router-id */
6233 if (p->family == AF_INET)
6234 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006235 vty_out (vty, " %s", ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)) ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006236 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006237 inet_ntoa (attr->nexthop));
6238 }
paul718e3742002-12-13 20:15:29 +00006239 else
6240 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006241 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006242 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006243 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006244 buf, INET6_ADDRSTRLEN));
6245 }
paul718e3742002-12-13 20:15:29 +00006246
6247 if (binfo->peer == bgp->peer_self)
6248 {
6249 vty_out (vty, " from %s ",
6250 p->family == AF_INET ? "0.0.0.0" : "::");
6251 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6252 }
6253 else
6254 {
6255 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6256 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006257 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006258 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006259 if (!sockunion2str (&binfo->peer->su, buf, sizeof(buf))) {
6260 buf[0] = '?';
6261 buf[1] = 0;
6262 }
6263 vty_out (vty, " from %s", buf);
paul718e3742002-12-13 20:15:29 +00006264 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006265 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006266 else
6267 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6268 }
6269 vty_out (vty, "%s", VTY_NEWLINE);
6270
paul718e3742002-12-13 20:15:29 +00006271 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006272 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006273 {
6274 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006275 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006276 buf, INET6_ADDRSTRLEN),
6277 VTY_NEWLINE);
6278 }
paul718e3742002-12-13 20:15:29 +00006279
6280 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6281 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6282
6283 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006284 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006285
6286 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006287 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006288 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006289 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006290
Paul Jakmafb982c22007-05-04 20:15:47 +00006291 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006292 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006293
6294 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6295 vty_out (vty, ", valid");
6296
6297 if (binfo->peer != bgp->peer_self)
6298 {
6299 if (binfo->peer->as == binfo->peer->local_as)
6300 vty_out (vty, ", internal");
6301 else
6302 vty_out (vty, ", %s",
6303 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6304 }
6305 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6306 vty_out (vty, ", aggregated, local");
6307 else if (binfo->type != ZEBRA_ROUTE_BGP)
6308 vty_out (vty, ", sourced");
6309 else
6310 vty_out (vty, ", sourced, local");
6311
6312 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6313 vty_out (vty, ", atomic-aggregate");
6314
Josh Baileyde8d5df2011-07-20 20:46:01 -07006315 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6316 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6317 bgp_info_mpath_count (binfo)))
6318 vty_out (vty, ", multipath");
6319
paul718e3742002-12-13 20:15:29 +00006320 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6321 vty_out (vty, ", best");
6322
6323 vty_out (vty, "%s", VTY_NEWLINE);
6324
6325 /* Line 4 display Community */
6326 if (attr->community)
6327 vty_out (vty, " Community: %s%s", attr->community->str,
6328 VTY_NEWLINE);
6329
6330 /* Line 5 display Extended-community */
6331 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006332 vty_out (vty, " Extended Community: %s%s",
6333 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006334
6335 /* Line 6 display Originator, Cluster-id */
6336 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6337 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6338 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006339 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006340 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006341 vty_out (vty, " Originator: %s",
6342 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006343
6344 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6345 {
6346 int i;
6347 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006348 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6349 vty_out (vty, "%s ",
6350 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006351 }
6352 vty_out (vty, "%s", VTY_NEWLINE);
6353 }
Paul Jakma41367172007-08-06 15:24:51 +00006354
Paul Jakmafb982c22007-05-04 20:15:47 +00006355 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006356 bgp_damp_info_vty (vty, binfo);
6357
6358 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006359#ifdef HAVE_CLOCK_MONOTONIC
6360 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006361 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006362#else
6363 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6364#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006365 }
6366 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006367}
6368
6369#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6370 "h history, * valid, > best, = multipath,%s"\
6371 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006372#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006373#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6374#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6375#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6376
6377enum bgp_show_type
6378{
6379 bgp_show_type_normal,
6380 bgp_show_type_regexp,
6381 bgp_show_type_prefix_list,
6382 bgp_show_type_filter_list,
6383 bgp_show_type_route_map,
6384 bgp_show_type_neighbor,
6385 bgp_show_type_cidr_only,
6386 bgp_show_type_prefix_longer,
6387 bgp_show_type_community_all,
6388 bgp_show_type_community,
6389 bgp_show_type_community_exact,
6390 bgp_show_type_community_list,
6391 bgp_show_type_community_list_exact,
6392 bgp_show_type_flap_statistics,
6393 bgp_show_type_flap_address,
6394 bgp_show_type_flap_prefix,
6395 bgp_show_type_flap_cidr_only,
6396 bgp_show_type_flap_regexp,
6397 bgp_show_type_flap_filter_list,
6398 bgp_show_type_flap_prefix_list,
6399 bgp_show_type_flap_prefix_longer,
6400 bgp_show_type_flap_route_map,
6401 bgp_show_type_flap_neighbor,
6402 bgp_show_type_dampend_paths,
6403 bgp_show_type_damp_neighbor
6404};
6405
ajs5a646652004-11-05 01:25:55 +00006406static int
paulfee0f4c2004-09-13 05:12:46 +00006407bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006408 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006409{
paul718e3742002-12-13 20:15:29 +00006410 struct bgp_info *ri;
6411 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006412 int header = 1;
paul718e3742002-12-13 20:15:29 +00006413 int display;
ajs5a646652004-11-05 01:25:55 +00006414 unsigned long output_count;
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006415 unsigned long total_count;
paul718e3742002-12-13 20:15:29 +00006416
6417 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006418 output_count = 0;
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006419 total_count = 0;
paul718e3742002-12-13 20:15:29 +00006420
paul718e3742002-12-13 20:15:29 +00006421 /* Start processing of routes. */
6422 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6423 if (rn->info != NULL)
6424 {
6425 display = 0;
6426
6427 for (ri = rn->info; ri; ri = ri->next)
6428 {
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006429 total_count++;
ajs5a646652004-11-05 01:25:55 +00006430 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006431 || type == bgp_show_type_flap_address
6432 || type == bgp_show_type_flap_prefix
6433 || type == bgp_show_type_flap_cidr_only
6434 || type == bgp_show_type_flap_regexp
6435 || type == bgp_show_type_flap_filter_list
6436 || type == bgp_show_type_flap_prefix_list
6437 || type == bgp_show_type_flap_prefix_longer
6438 || type == bgp_show_type_flap_route_map
6439 || type == bgp_show_type_flap_neighbor
6440 || type == bgp_show_type_dampend_paths
6441 || type == bgp_show_type_damp_neighbor)
6442 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006443 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006444 continue;
6445 }
6446 if (type == bgp_show_type_regexp
6447 || type == bgp_show_type_flap_regexp)
6448 {
ajs5a646652004-11-05 01:25:55 +00006449 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006450
6451 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6452 continue;
6453 }
6454 if (type == bgp_show_type_prefix_list
6455 || type == bgp_show_type_flap_prefix_list)
6456 {
ajs5a646652004-11-05 01:25:55 +00006457 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006458
6459 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6460 continue;
6461 }
6462 if (type == bgp_show_type_filter_list
6463 || type == bgp_show_type_flap_filter_list)
6464 {
ajs5a646652004-11-05 01:25:55 +00006465 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006466
6467 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6468 continue;
6469 }
6470 if (type == bgp_show_type_route_map
6471 || type == bgp_show_type_flap_route_map)
6472 {
ajs5a646652004-11-05 01:25:55 +00006473 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006474 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006475 struct attr dummy_attr;
6476 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006477 int ret;
6478
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006479 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006480 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006481
paul718e3742002-12-13 20:15:29 +00006482 binfo.peer = ri->peer;
6483 binfo.attr = &dummy_attr;
6484
6485 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006486 if (ret == RMAP_DENYMATCH)
6487 continue;
6488 }
6489 if (type == bgp_show_type_neighbor
6490 || type == bgp_show_type_flap_neighbor
6491 || type == bgp_show_type_damp_neighbor)
6492 {
ajs5a646652004-11-05 01:25:55 +00006493 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006494
6495 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6496 continue;
6497 }
6498 if (type == bgp_show_type_cidr_only
6499 || type == bgp_show_type_flap_cidr_only)
6500 {
6501 u_int32_t destination;
6502
6503 destination = ntohl (rn->p.u.prefix4.s_addr);
6504 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6505 continue;
6506 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6507 continue;
6508 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6509 continue;
6510 }
6511 if (type == bgp_show_type_prefix_longer
6512 || type == bgp_show_type_flap_prefix_longer)
6513 {
ajs5a646652004-11-05 01:25:55 +00006514 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006515
6516 if (! prefix_match (p, &rn->p))
6517 continue;
6518 }
6519 if (type == bgp_show_type_community_all)
6520 {
6521 if (! ri->attr->community)
6522 continue;
6523 }
6524 if (type == bgp_show_type_community)
6525 {
ajs5a646652004-11-05 01:25:55 +00006526 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006527
6528 if (! ri->attr->community ||
6529 ! community_match (ri->attr->community, com))
6530 continue;
6531 }
6532 if (type == bgp_show_type_community_exact)
6533 {
ajs5a646652004-11-05 01:25:55 +00006534 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006535
6536 if (! ri->attr->community ||
6537 ! community_cmp (ri->attr->community, com))
6538 continue;
6539 }
6540 if (type == bgp_show_type_community_list)
6541 {
ajs5a646652004-11-05 01:25:55 +00006542 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006543
6544 if (! community_list_match (ri->attr->community, list))
6545 continue;
6546 }
6547 if (type == bgp_show_type_community_list_exact)
6548 {
ajs5a646652004-11-05 01:25:55 +00006549 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006550
6551 if (! community_list_exact_match (ri->attr->community, list))
6552 continue;
6553 }
6554 if (type == bgp_show_type_flap_address
6555 || type == bgp_show_type_flap_prefix)
6556 {
ajs5a646652004-11-05 01:25:55 +00006557 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006558
6559 if (! prefix_match (&rn->p, p))
6560 continue;
6561
6562 if (type == bgp_show_type_flap_prefix)
6563 if (p->prefixlen != rn->p.prefixlen)
6564 continue;
6565 }
6566 if (type == bgp_show_type_dampend_paths
6567 || type == bgp_show_type_damp_neighbor)
6568 {
6569 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6570 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6571 continue;
6572 }
6573
6574 if (header)
6575 {
hasso93406d82005-02-02 14:40:33 +00006576 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6577 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6578 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006579 if (type == bgp_show_type_dampend_paths
6580 || type == bgp_show_type_damp_neighbor)
6581 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6582 else if (type == bgp_show_type_flap_statistics
6583 || type == bgp_show_type_flap_address
6584 || type == bgp_show_type_flap_prefix
6585 || type == bgp_show_type_flap_cidr_only
6586 || type == bgp_show_type_flap_regexp
6587 || type == bgp_show_type_flap_filter_list
6588 || type == bgp_show_type_flap_prefix_list
6589 || type == bgp_show_type_flap_prefix_longer
6590 || type == bgp_show_type_flap_route_map
6591 || type == bgp_show_type_flap_neighbor)
6592 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6593 else
6594 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006595 header = 0;
6596 }
6597
6598 if (type == bgp_show_type_dampend_paths
6599 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006600 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006601 else if (type == bgp_show_type_flap_statistics
6602 || type == bgp_show_type_flap_address
6603 || type == bgp_show_type_flap_prefix
6604 || type == bgp_show_type_flap_cidr_only
6605 || type == bgp_show_type_flap_regexp
6606 || type == bgp_show_type_flap_filter_list
6607 || type == bgp_show_type_flap_prefix_list
6608 || type == bgp_show_type_flap_prefix_longer
6609 || type == bgp_show_type_flap_route_map
6610 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006611 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006612 else
ajs5a646652004-11-05 01:25:55 +00006613 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006614 display++;
6615 }
6616 if (display)
ajs5a646652004-11-05 01:25:55 +00006617 output_count++;
paul718e3742002-12-13 20:15:29 +00006618 }
6619
6620 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006621 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006622 {
6623 if (type == bgp_show_type_normal)
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006624 vty_out (vty, "No BGP prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006625 }
6626 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006627 vty_out (vty, "%sDisplayed %ld out of %ld total prefixes%s",
6628 VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006629
6630 return CMD_SUCCESS;
6631}
6632
ajs5a646652004-11-05 01:25:55 +00006633static int
paulfee0f4c2004-09-13 05:12:46 +00006634bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006635 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006636{
6637 struct bgp_table *table;
6638
6639 if (bgp == NULL) {
6640 bgp = bgp_get_default ();
6641 }
6642
6643 if (bgp == NULL)
6644 {
6645 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6646 return CMD_WARNING;
6647 }
6648
6649
6650 table = bgp->rib[afi][safi];
6651
ajs5a646652004-11-05 01:25:55 +00006652 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006653}
6654
paul718e3742002-12-13 20:15:29 +00006655/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006656static void
paul718e3742002-12-13 20:15:29 +00006657route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6658 struct bgp_node *rn,
6659 struct prefix_rd *prd, afi_t afi, safi_t safi)
6660{
6661 struct bgp_info *ri;
6662 struct prefix *p;
6663 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006664 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006665 char buf1[INET6_ADDRSTRLEN];
6666 char buf2[INET6_ADDRSTRLEN];
6667 int count = 0;
6668 int best = 0;
6669 int suppress = 0;
6670 int no_export = 0;
6671 int no_advertise = 0;
6672 int local_as = 0;
6673 int first = 0;
Lou Berger298cc2f2016-01-12 13:42:02 -05006674 int printrd = ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP));
paul718e3742002-12-13 20:15:29 +00006675
6676 p = &rn->p;
6677 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
Lou Berger298cc2f2016-01-12 13:42:02 -05006678 (printrd ? prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6679 printrd ? ":" : "",
paul718e3742002-12-13 20:15:29 +00006680 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6681 p->prefixlen, VTY_NEWLINE);
6682
6683 for (ri = rn->info; ri; ri = ri->next)
6684 {
6685 count++;
6686 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6687 {
6688 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006689 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006690 suppress = 1;
6691 if (ri->attr->community != NULL)
6692 {
6693 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6694 no_advertise = 1;
6695 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6696 no_export = 1;
6697 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6698 local_as = 1;
6699 }
6700 }
6701 }
6702
6703 vty_out (vty, "Paths: (%d available", count);
6704 if (best)
6705 {
6706 vty_out (vty, ", best #%d", best);
6707 if (safi == SAFI_UNICAST)
6708 vty_out (vty, ", table Default-IP-Routing-Table");
6709 }
6710 else
6711 vty_out (vty, ", no best path");
6712 if (no_advertise)
6713 vty_out (vty, ", not advertised to any peer");
6714 else if (no_export)
6715 vty_out (vty, ", not advertised to EBGP peer");
6716 else if (local_as)
6717 vty_out (vty, ", not advertised outside local AS");
6718 if (suppress)
6719 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6720 vty_out (vty, ")%s", VTY_NEWLINE);
6721
6722 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006723 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006724 {
6725 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6726 {
6727 if (! first)
6728 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6729 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6730 first = 1;
6731 }
6732 }
6733 if (! first)
6734 vty_out (vty, " Not advertised to any peer");
6735 vty_out (vty, "%s", VTY_NEWLINE);
6736}
6737
6738/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006739static int
paulfee0f4c2004-09-13 05:12:46 +00006740bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006741 struct bgp_table *rib, const char *ip_str,
6742 afi_t afi, safi_t safi, struct prefix_rd *prd,
6743 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006744{
6745 int ret;
6746 int header;
6747 int display = 0;
6748 struct prefix match;
6749 struct bgp_node *rn;
6750 struct bgp_node *rm;
6751 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006752 struct bgp_table *table;
6753
Lou Berger050defe2016-01-12 13:41:59 -05006754 memset (&match, 0, sizeof (struct prefix)); /* keep valgrind happy */
paul718e3742002-12-13 20:15:29 +00006755 /* Check IP address argument. */
6756 ret = str2prefix (ip_str, &match);
6757 if (! ret)
6758 {
6759 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6760 return CMD_WARNING;
6761 }
6762
6763 match.family = afi2family (afi);
6764
Lou Berger298cc2f2016-01-12 13:42:02 -05006765 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00006766 {
paulfee0f4c2004-09-13 05:12:46 +00006767 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006768 {
6769 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6770 continue;
6771
6772 if ((table = rn->info) != NULL)
6773 {
6774 header = 1;
6775
6776 if ((rm = bgp_node_match (table, &match)) != NULL)
6777 {
6778 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006779 {
6780 bgp_unlock_node (rm);
6781 continue;
6782 }
paul718e3742002-12-13 20:15:29 +00006783
6784 for (ri = rm->info; ri; ri = ri->next)
6785 {
6786 if (header)
6787 {
6788 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
Lou Berger298cc2f2016-01-12 13:42:02 -05006789 AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00006790
6791 header = 0;
6792 }
6793 display++;
Lou Berger298cc2f2016-01-12 13:42:02 -05006794 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00006795 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006796
6797 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006798 }
6799 }
6800 }
6801 }
6802 else
6803 {
6804 header = 1;
6805
paulfee0f4c2004-09-13 05:12:46 +00006806 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006807 {
6808 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6809 {
6810 for (ri = rn->info; ri; ri = ri->next)
6811 {
6812 if (header)
6813 {
6814 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6815 header = 0;
6816 }
6817 display++;
6818 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6819 }
6820 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006821
6822 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006823 }
6824 }
6825
6826 if (! display)
6827 {
6828 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6829 return CMD_WARNING;
6830 }
6831
6832 return CMD_SUCCESS;
6833}
6834
paulfee0f4c2004-09-13 05:12:46 +00006835/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006836static int
paulfd79ac92004-10-13 05:06:08 +00006837bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006838 afi_t afi, safi_t safi, struct prefix_rd *prd,
6839 int prefix_check)
6840{
6841 struct bgp *bgp;
6842
6843 /* BGP structure lookup. */
6844 if (view_name)
6845 {
6846 bgp = bgp_lookup_by_name (view_name);
6847 if (bgp == NULL)
6848 {
6849 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6850 return CMD_WARNING;
6851 }
6852 }
6853 else
6854 {
6855 bgp = bgp_get_default ();
6856 if (bgp == NULL)
6857 {
6858 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6859 return CMD_WARNING;
6860 }
6861 }
6862
6863 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6864 afi, safi, prd, prefix_check);
6865}
6866
paul718e3742002-12-13 20:15:29 +00006867/* BGP route print out function. */
Lou Bergerf9b6c392016-01-12 13:42:09 -05006868DEFUN (show_ip_bgp,
6869 show_ip_bgp_cmd,
6870 "show ip bgp",
6871 SHOW_STR
6872 IP_STR
6873 BGP_STR)
6874{
6875 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6876}
6877
6878DEFUN (show_ip_bgp_ipv4,
6879 show_ip_bgp_ipv4_cmd,
6880 "show ip bgp ipv4 (unicast|multicast)",
6881 SHOW_STR
6882 IP_STR
6883 BGP_STR
6884 "Address family\n"
6885 "Address Family modifier\n"
6886 "Address Family modifier\n")
6887{
6888 if (strncmp (argv[0], "m", 1) == 0)
6889 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6890 NULL);
6891
6892 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6893}
6894
6895DEFUN (show_ip_bgp_route,
6896 show_ip_bgp_route_cmd,
6897 "show ip bgp A.B.C.D",
6898 SHOW_STR
6899 IP_STR
6900 BGP_STR
6901 "Network in the BGP routing table to display\n")
6902{
6903 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6904}
6905
6906DEFUN (show_ip_bgp_ipv4_route,
6907 show_ip_bgp_ipv4_route_cmd,
6908 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6909 SHOW_STR
6910 IP_STR
6911 BGP_STR
6912 "Address family\n"
6913 "Address Family modifier\n"
6914 "Address Family modifier\n"
6915 "Network in the BGP routing table to display\n")
6916{
6917 if (strncmp (argv[0], "m", 1) == 0)
6918 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6919
6920 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6921}
6922
6923DEFUN (show_ip_bgp_vpnv4_all_route,
6924 show_ip_bgp_vpnv4_all_route_cmd,
6925 "show ip bgp vpnv4 all A.B.C.D",
6926 SHOW_STR
6927 IP_STR
6928 BGP_STR
6929 "Display VPNv4 NLRI specific information\n"
6930 "Display information about all VPNv4 NLRIs\n"
6931 "Network in the BGP routing table to display\n")
6932{
6933 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6934}
6935
6936DEFUN (show_ip_bgp_vpnv4_rd_route,
6937 show_ip_bgp_vpnv4_rd_route_cmd,
6938 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6939 SHOW_STR
6940 IP_STR
6941 BGP_STR
6942 "Display VPNv4 NLRI specific information\n"
6943 "Display information for a route distinguisher\n"
6944 "VPN Route Distinguisher\n"
6945 "Network in the BGP routing table to display\n")
6946{
6947 int ret;
6948 struct prefix_rd prd;
6949
6950 ret = str2prefix_rd (argv[0], &prd);
6951 if (! ret)
6952 {
6953 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6954 return CMD_WARNING;
6955 }
6956 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6957}
6958
6959DEFUN (show_ip_bgp_prefix,
6960 show_ip_bgp_prefix_cmd,
6961 "show ip bgp A.B.C.D/M",
6962 SHOW_STR
6963 IP_STR
6964 BGP_STR
6965 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6966{
6967 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6968}
6969
6970DEFUN (show_ip_bgp_ipv4_prefix,
6971 show_ip_bgp_ipv4_prefix_cmd,
6972 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6973 SHOW_STR
6974 IP_STR
6975 BGP_STR
6976 "Address family\n"
6977 "Address Family modifier\n"
6978 "Address Family modifier\n"
6979 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6980{
6981 if (strncmp (argv[0], "m", 1) == 0)
6982 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6983
6984 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6985}
6986
6987DEFUN (show_ip_bgp_vpnv4_all_prefix,
6988 show_ip_bgp_vpnv4_all_prefix_cmd,
6989 "show ip bgp vpnv4 all A.B.C.D/M",
6990 SHOW_STR
6991 IP_STR
6992 BGP_STR
6993 "Display VPNv4 NLRI specific information\n"
6994 "Display information about all VPNv4 NLRIs\n"
6995 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6996{
6997 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6998}
6999
7000DEFUN (show_ip_bgp_vpnv4_rd_prefix,
7001 show_ip_bgp_vpnv4_rd_prefix_cmd,
7002 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7003 SHOW_STR
7004 IP_STR
7005 BGP_STR
7006 "Display VPNv4 NLRI specific information\n"
7007 "Display information for a route distinguisher\n"
7008 "VPN Route Distinguisher\n"
7009 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7010{
7011 int ret;
7012 struct prefix_rd prd;
7013
7014 ret = str2prefix_rd (argv[0], &prd);
7015 if (! ret)
7016 {
7017 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7018 return CMD_WARNING;
7019 }
7020 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
7021}
7022
7023DEFUN (show_ip_bgp_view,
7024 show_ip_bgp_view_cmd,
7025 "show ip bgp view WORD",
7026 SHOW_STR
7027 IP_STR
7028 BGP_STR
7029 "BGP view\n"
7030 "View name\n")
7031{
7032 struct bgp *bgp;
7033
7034 /* BGP structure lookup. */
7035 bgp = bgp_lookup_by_name (argv[0]);
7036 if (bgp == NULL)
7037 {
7038 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7039 return CMD_WARNING;
7040 }
7041
7042 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
7043}
7044
7045DEFUN (show_ip_bgp_view_route,
7046 show_ip_bgp_view_route_cmd,
7047 "show ip bgp view WORD A.B.C.D",
7048 SHOW_STR
7049 IP_STR
7050 BGP_STR
7051 "BGP view\n"
7052 "View name\n"
7053 "Network in the BGP routing table to display\n")
7054{
7055 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
7056}
7057
7058DEFUN (show_ip_bgp_view_prefix,
7059 show_ip_bgp_view_prefix_cmd,
7060 "show ip bgp view WORD A.B.C.D/M",
7061 SHOW_STR
7062 IP_STR
7063 BGP_STR
7064 "BGP view\n"
7065 "View name\n"
7066 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7067{
7068 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
7069}
7070
7071DEFUN (show_bgp,
7072 show_bgp_cmd,
7073 "show bgp",
7074 SHOW_STR
7075 BGP_STR)
7076{
7077 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7078 NULL);
7079}
7080
7081ALIAS (show_bgp,
7082 show_bgp_ipv6_cmd,
7083 "show bgp ipv6",
7084 SHOW_STR
7085 BGP_STR
7086 "Address family\n")
7087
7088/* old command */
7089DEFUN (show_ipv6_bgp,
7090 show_ipv6_bgp_cmd,
7091 "show ipv6 bgp",
7092 SHOW_STR
7093 IP_STR
7094 BGP_STR)
7095{
7096 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7097 NULL);
7098}
7099
7100DEFUN (show_bgp_route,
7101 show_bgp_route_cmd,
7102 "show bgp X:X::X:X",
7103 SHOW_STR
7104 BGP_STR
7105 "Network in the BGP routing table to display\n")
7106{
7107 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7108}
7109
Lou Berger35c36862016-01-12 13:42:06 -05007110DEFUN (show_bgp_ipv4_safi,
7111 show_bgp_ipv4_safi_cmd,
7112 "show bgp ipv4 (unicast|multicast)",
paul718e3742002-12-13 20:15:29 +00007113 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007114 BGP_STR
7115 "Address family\n"
7116 "Address Family modifier\n"
7117 "Address Family modifier\n")
7118{
7119 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00007120 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
7121 NULL);
paul718e3742002-12-13 20:15:29 +00007122
ajs5a646652004-11-05 01:25:55 +00007123 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00007124}
7125
Lou Berger35c36862016-01-12 13:42:06 -05007126DEFUN (show_bgp_ipv4_safi_route,
7127 show_bgp_ipv4_safi_route_cmd,
7128 "show bgp ipv4 (unicast|multicast) A.B.C.D",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007129 SHOW_STR
7130 BGP_STR
7131 "Address family\n"
7132 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00007133 "Address Family modifier\n"
7134 "Network in the BGP routing table to display\n")
7135{
7136 if (strncmp (argv[0], "m", 1) == 0)
7137 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
7138
7139 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
7140}
7141
Lou Berger35c36862016-01-12 13:42:06 -05007142DEFUN (show_bgp_ipv4_vpn_route,
7143 show_bgp_ipv4_vpn_route_cmd,
7144 "show bgp ipv4 vpn A.B.C.D",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007145 SHOW_STR
7146 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007147 "Address Family\n"
7148 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +00007149 "Network in the BGP routing table to display\n")
7150{
7151 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
7152}
7153
Lou Berger35c36862016-01-12 13:42:06 -05007154DEFUN (show_bgp_ipv6_vpn_route,
7155 show_bgp_ipv6_vpn_route_cmd,
7156 "show bgp ipv6 vpn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007157 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007158 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007159 "Address Family\n"
7160 "Display VPN NLRI specific information\n"
7161 "Network in the BGP routing table to display\n")
7162{
7163 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MPLS_VPN, NULL, 0);
7164}
Lou Berger35c36862016-01-12 13:42:06 -05007165
7166DEFUN (show_bgp_ipv4_vpn_rd_route,
7167 show_bgp_ipv4_vpn_rd_route_cmd,
7168 "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn A.B.C.D",
7169 SHOW_STR
7170 BGP_STR
7171 IP_STR
7172 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +00007173 "Display information for a route distinguisher\n"
7174 "VPN Route Distinguisher\n"
7175 "Network in the BGP routing table to display\n")
7176{
7177 int ret;
7178 struct prefix_rd prd;
7179
7180 ret = str2prefix_rd (argv[0], &prd);
7181 if (! ret)
7182 {
7183 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7184 return CMD_WARNING;
7185 }
7186 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
7187}
7188
Lou Berger35c36862016-01-12 13:42:06 -05007189DEFUN (show_bgp_ipv6_vpn_rd_route,
7190 show_bgp_ipv6_vpn_rd_route_cmd,
7191 "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007192 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007193 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007194 "Address Family\n"
7195 "Display VPN NLRI specific information\n"
7196 "Display information for a route distinguisher\n"
7197 "VPN Route Distinguisher\n"
7198 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007199{
Lou Berger35c36862016-01-12 13:42:06 -05007200 int ret;
7201 struct prefix_rd prd;
7202
7203 ret = str2prefix_rd (argv[0], &prd);
7204 if (! ret)
7205 {
7206 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7207 return CMD_WARNING;
7208 }
7209 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MPLS_VPN, &prd, 0);
paul718e3742002-12-13 20:15:29 +00007210}
7211
Lou Berger651b4022016-01-12 13:42:07 -05007212DEFUN (show_bgp_ipv4_encap_route,
7213 show_bgp_ipv4_encap_route_cmd,
7214 "show bgp ipv4 encap A.B.C.D",
paul718e3742002-12-13 20:15:29 +00007215 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007216 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007217 IP_STR
7218 "Display ENCAP NLRI specific information\n"
7219 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007220{
Lou Berger651b4022016-01-12 13:42:07 -05007221 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 0);
paul718e3742002-12-13 20:15:29 +00007222}
7223
Lou Berger651b4022016-01-12 13:42:07 -05007224DEFUN (show_bgp_ipv6_encap_route,
7225 show_bgp_ipv6_encap_route_cmd,
7226 "show bgp ipv6 encap X:X::X:X",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007227 SHOW_STR
7228 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007229 IP6_STR
7230 "Display ENCAP NLRI specific information\n"
7231 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007232{
Lou Berger651b4022016-01-12 13:42:07 -05007233 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 0);
paul718e3742002-12-13 20:15:29 +00007234}
7235
Lou Berger651b4022016-01-12 13:42:07 -05007236DEFUN (show_bgp_ipv4_safi_rd_route,
7237 show_bgp_ipv4_safi_rd_route_cmd,
7238 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D",
paul718e3742002-12-13 20:15:29 +00007239 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007240 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007241 "Address Family\n"
7242 "Address Family Modifier\n"
7243 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00007244 "Display information for a route distinguisher\n"
Lou Berger651b4022016-01-12 13:42:07 -05007245 "ENCAP Route Distinguisher\n"
7246 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007247{
7248 int ret;
7249 struct prefix_rd prd;
Lou Berger651b4022016-01-12 13:42:07 -05007250 safi_t safi;
paul718e3742002-12-13 20:15:29 +00007251
Lou Berger651b4022016-01-12 13:42:07 -05007252 if (bgp_parse_safi(argv[0], &safi)) {
7253 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7254 return CMD_WARNING;
7255 }
7256 ret = str2prefix_rd (argv[1], &prd);
paul718e3742002-12-13 20:15:29 +00007257 if (! ret)
7258 {
7259 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7260 return CMD_WARNING;
7261 }
Lou Berger651b4022016-01-12 13:42:07 -05007262 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 0);
paul718e3742002-12-13 20:15:29 +00007263}
7264
Lou Berger651b4022016-01-12 13:42:07 -05007265DEFUN (show_bgp_ipv6_safi_rd_route,
7266 show_bgp_ipv6_safi_rd_route_cmd,
7267 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007268 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007269 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007270 "Address Family\n"
7271 "Address Family Modifier\n"
7272 "Address Family Modifier\n"
7273 "Display information for a route distinguisher\n"
7274 "ENCAP Route Distinguisher\n"
7275 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007276{
Lou Berger651b4022016-01-12 13:42:07 -05007277 int ret;
7278 struct prefix_rd prd;
7279 safi_t safi;
paulbb46e942003-10-24 19:02:03 +00007280
Lou Berger651b4022016-01-12 13:42:07 -05007281 if (bgp_parse_safi(argv[0], &safi)) {
7282 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7283 return CMD_WARNING;
7284 }
7285 ret = str2prefix_rd (argv[1], &prd);
7286 if (! ret)
7287 {
7288 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7289 return CMD_WARNING;
7290 }
7291 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, SAFI_ENCAP, &prd, 0);
paul718e3742002-12-13 20:15:29 +00007292}
7293
Lou Berger35c36862016-01-12 13:42:06 -05007294DEFUN (show_bgp_ipv4_prefix,
7295 show_bgp_ipv4_prefix_cmd,
7296 "show bgp ipv4 A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007297 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007298 BGP_STR
paul718e3742002-12-13 20:15:29 +00007299 IP_STR
paul718e3742002-12-13 20:15:29 +00007300 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7301{
Lou Berger35c36862016-01-12 13:42:06 -05007302 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
paul718e3742002-12-13 20:15:29 +00007303}
7304
Lou Berger35c36862016-01-12 13:42:06 -05007305DEFUN (show_bgp_ipv4_safi_prefix,
7306 show_bgp_ipv4_safi_prefix_cmd,
7307 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007308 SHOW_STR
7309 BGP_STR
7310 "Address family\n"
7311 "Address Family modifier\n"
Lou Berger35c36862016-01-12 13:42:06 -05007312 "Address Family modifier\n"
7313 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007314{
7315 if (strncmp (argv[0], "m", 1) == 0)
Lou Berger35c36862016-01-12 13:42:06 -05007316 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007317
Lou Berger35c36862016-01-12 13:42:06 -05007318 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007319}
7320
Lou Berger35c36862016-01-12 13:42:06 -05007321DEFUN (show_bgp_ipv4_vpn_prefix,
7322 show_bgp_ipv4_vpn_prefix_cmd,
7323 "show bgp ipv4 vpn A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007324 SHOW_STR
7325 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007326 IP_STR
7327 "Display VPN NLRI specific information\n"
7328 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paul718e3742002-12-13 20:15:29 +00007329{
Lou Berger35c36862016-01-12 13:42:06 -05007330 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
paul718e3742002-12-13 20:15:29 +00007331}
7332
Lou Berger35c36862016-01-12 13:42:06 -05007333DEFUN (show_bgp_ipv6_vpn_prefix,
7334 show_bgp_ipv6_vpn_prefix_cmd,
7335 "show bgp ipv6 vpn X:X::X:X/M",
7336 SHOW_STR
7337 BGP_STR
7338 "Address Family\n"
7339 "Display VPN NLRI specific information\n"
7340 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7341{
7342 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MPLS_VPN, NULL, 1);
7343}
Lou Berger35c36862016-01-12 13:42:06 -05007344
Lou Berger651b4022016-01-12 13:42:07 -05007345DEFUN (show_bgp_ipv4_encap_prefix,
7346 show_bgp_ipv4_encap_prefix_cmd,
7347 "show bgp ipv4 encap A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007348 SHOW_STR
7349 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007350 IP_STR
7351 "Display ENCAP NLRI specific information\n"
7352 "Display information about ENCAP NLRIs\n"
7353 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7354{
7355 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 1);
7356}
paul718e3742002-12-13 20:15:29 +00007357
Lou Berger651b4022016-01-12 13:42:07 -05007358DEFUN (show_bgp_ipv6_encap_prefix,
7359 show_bgp_ipv6_encap_prefix_cmd,
7360 "show bgp ipv6 encap X:X::X:X/M",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007361 SHOW_STR
7362 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007363 IP_STR
7364 "Display ENCAP NLRI specific information\n"
7365 "Display information about ENCAP NLRIs\n"
7366 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7367{
7368 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 1);
7369}
Lou Berger651b4022016-01-12 13:42:07 -05007370
7371DEFUN (show_bgp_ipv4_safi_rd_prefix,
7372 show_bgp_ipv4_safi_rd_prefix_cmd,
7373 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7374 SHOW_STR
7375 BGP_STR
7376 "Address Family\n"
7377 "Address Family Modifier\n"
7378 "Address Family Modifier\n"
7379 "Display information for a route distinguisher\n"
7380 "ENCAP Route Distinguisher\n"
7381 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7382{
7383 int ret;
7384 struct prefix_rd prd;
7385 safi_t safi;
7386
7387 if (bgp_parse_safi(argv[0], &safi)) {
7388 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7389 return CMD_WARNING;
7390 }
7391
7392 ret = str2prefix_rd (argv[1], &prd);
7393 if (! ret)
7394 {
7395 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7396 return CMD_WARNING;
7397 }
7398 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 1);
7399}
7400
Lou Berger651b4022016-01-12 13:42:07 -05007401DEFUN (show_bgp_ipv6_safi_rd_prefix,
7402 show_bgp_ipv6_safi_rd_prefix_cmd,
7403 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X/M",
7404 SHOW_STR
7405 BGP_STR
7406 "Address Family\n"
7407 "Address Family Modifier\n"
7408 "Address Family Modifier\n"
7409 "Display information for a route distinguisher\n"
7410 "ENCAP Route Distinguisher\n"
7411 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7412{
7413 int ret;
7414 struct prefix_rd prd;
7415 safi_t safi;
7416
7417 if (bgp_parse_safi(argv[0], &safi)) {
7418 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7419 return CMD_WARNING;
7420 }
7421
7422 ret = str2prefix_rd (argv[1], &prd);
7423 if (! ret)
7424 {
7425 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7426 return CMD_WARNING;
7427 }
7428 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, safi, &prd, 1);
7429}
Lou Berger651b4022016-01-12 13:42:07 -05007430
7431DEFUN (show_bgp_afi_safi_view,
7432 show_bgp_afi_safi_view_cmd,
7433 "show bgp view WORD (ipv4|ipv6) (encap|mulicast|unicast|vpn)",
7434 SHOW_STR
7435 BGP_STR
7436 "BGP view\n"
7437 "BGP view name\n"
7438 "Address Family\n"
7439 "Address Family\n"
7440 "Address Family Modifier\n"
7441 "Address Family Modifier\n"
7442 "Address Family Modifier\n"
7443 "Address Family Modifier\n"
7444 )
7445{
7446 struct bgp *bgp;
7447 safi_t safi;
7448 afi_t afi;
7449
7450 if (bgp_parse_afi(argv[1], &afi)) {
7451 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7452 return CMD_WARNING;
7453 }
7454 if (bgp_parse_safi(argv[2], &safi)) {
7455 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7456 return CMD_WARNING;
7457 }
7458
7459 /* BGP structure lookup. */
7460 bgp = bgp_lookup_by_name (argv[0]);
7461 if (bgp == NULL)
7462 {
7463 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7464 return CMD_WARNING;
7465 }
7466
7467 return bgp_show (vty, bgp, afi, safi, bgp_show_type_normal, NULL);
7468}
7469
7470DEFUN (show_bgp_view_afi_safi_route,
7471 show_bgp_view_afi_safi_route_cmd,
7472 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) A.B.C.D",
7473 SHOW_STR
7474 BGP_STR
7475 "BGP view\n"
7476 "View name\n"
7477 "Address Family\n"
7478 "Address Family\n"
7479 "Address Family Modifier\n"
7480 "Address Family Modifier\n"
7481 "Address Family Modifier\n"
7482 "Address Family Modifier\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007483 "Network in the BGP routing table to display\n")
7484{
Lou Berger651b4022016-01-12 13:42:07 -05007485 safi_t safi;
7486 afi_t afi;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007487
Lou Berger651b4022016-01-12 13:42:07 -05007488 if (bgp_parse_afi(argv[1], &afi)) {
7489 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7490 return CMD_WARNING;
7491 }
7492 if (bgp_parse_safi(argv[2], &safi)) {
7493 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7494 return CMD_WARNING;
7495 }
7496 return bgp_show_route (vty, argv[0], argv[3], afi, safi, NULL, 0);
7497}
7498
7499DEFUN (show_bgp_view_afi_safi_prefix,
7500 show_bgp_view_afi_safi_prefix_cmd,
7501 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) A.B.C.D/M",
7502 SHOW_STR
7503 BGP_STR
7504 "BGP view\n"
7505 "View name\n"
7506 "Address Family\n"
7507 "Address Family\n"
7508 "Address Family Modifier\n"
7509 "Address Family Modifier\n"
7510 "Address Family Modifier\n"
7511 "Address Family Modifier\n"
7512 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7513{
7514 safi_t safi;
7515 afi_t afi;
7516
7517 if (bgp_parse_afi(argv[1], &afi)) {
7518 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7519 return CMD_WARNING;
7520 }
7521 if (bgp_parse_safi(argv[2], &safi)) {
7522 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7523 return CMD_WARNING;
7524 }
7525 return bgp_show_route (vty, argv[0], argv[3], afi, safi, NULL, 1);
7526}
7527
7528/* new001 */
7529DEFUN (show_bgp_afi,
7530 show_bgp_afi_cmd,
7531 "show bgp (ipv4|ipv6)",
7532 SHOW_STR
7533 BGP_STR
7534 "Address family\n"
7535 "Address family\n")
7536{
7537 afi_t afi;
7538
7539 if (bgp_parse_afi(argv[0], &afi)) {
7540 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7541 return CMD_WARNING;
7542 }
7543 return bgp_show (vty, NULL, afi, SAFI_UNICAST, bgp_show_type_normal,
7544 NULL);
7545}
7546
Lou Berger651b4022016-01-12 13:42:07 -05007547DEFUN (show_bgp_ipv6_safi,
7548 show_bgp_ipv6_safi_cmd,
7549 "show bgp ipv6 (unicast|multicast)",
7550 SHOW_STR
7551 BGP_STR
7552 "Address family\n"
7553 "Address Family modifier\n"
7554 "Address Family modifier\n")
7555{
7556 if (strncmp (argv[0], "m", 1) == 0)
7557 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7558 NULL);
7559
7560 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007561}
7562
Lou Berger35c36862016-01-12 13:42:06 -05007563DEFUN (show_bgp_ipv6_route,
7564 show_bgp_ipv6_route_cmd,
7565 "show bgp ipv6 X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007566 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007567 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007568 "Address family\n"
paul718e3742002-12-13 20:15:29 +00007569 "Network in the BGP routing table to display\n")
7570{
7571 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7572}
7573
Lou Berger35c36862016-01-12 13:42:06 -05007574DEFUN (show_bgp_ipv6_safi_route,
7575 show_bgp_ipv6_safi_route_cmd,
7576 "show bgp ipv6 (unicast|multicast) X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007577 SHOW_STR
7578 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007579 "Address family\n"
7580 "Address Family modifier\n"
7581 "Address Family modifier\n"
7582 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007583{
Lou Berger35c36862016-01-12 13:42:06 -05007584 if (strncmp (argv[0], "m", 1) == 0)
7585 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7586
7587 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
paul718e3742002-12-13 20:15:29 +00007588}
7589
Lou Bergerf9b6c392016-01-12 13:42:09 -05007590/* old command */
7591DEFUN (show_ipv6_bgp_route,
7592 show_ipv6_bgp_route_cmd,
7593 "show ipv6 bgp X:X::X:X",
7594 SHOW_STR
7595 IP_STR
7596 BGP_STR
7597 "Network in the BGP routing table to display\n")
7598{
7599 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7600}
7601
7602DEFUN (show_bgp_prefix,
7603 show_bgp_prefix_cmd,
7604 "show bgp X:X::X:X/M",
7605 SHOW_STR
7606 BGP_STR
7607 "IPv6 prefix <network>/<length>\n")
7608{
7609 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7610}
7611
7612
Lou Berger35c36862016-01-12 13:42:06 -05007613/* new002 */
7614DEFUN (show_bgp_ipv6_prefix,
paul718e3742002-12-13 20:15:29 +00007615 show_bgp_ipv6_prefix_cmd,
7616 "show bgp ipv6 X:X::X:X/M",
7617 SHOW_STR
7618 BGP_STR
7619 "Address family\n"
Lou Berger35c36862016-01-12 13:42:06 -05007620 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7621{
7622 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7623}
Michael Lambert95cbbd22010-07-23 14:43:04 -04007624DEFUN (show_bgp_ipv6_safi_prefix,
7625 show_bgp_ipv6_safi_prefix_cmd,
7626 "show bgp ipv6 (unicast|multicast) 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 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7633{
7634 if (strncmp (argv[0], "m", 1) == 0)
7635 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7636
7637 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7638}
7639
Lou Bergerf9b6c392016-01-12 13:42:09 -05007640/* old command */
7641DEFUN (show_ipv6_bgp_prefix,
7642 show_ipv6_bgp_prefix_cmd,
7643 "show ipv6 bgp X:X::X:X/M",
7644 SHOW_STR
7645 IP_STR
7646 BGP_STR
7647 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7648{
7649 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7650}
7651
paulbb46e942003-10-24 19:02:03 +00007652DEFUN (show_bgp_view,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007653 show_bgp_view_cmd,
7654 "show bgp view WORD",
7655 SHOW_STR
7656 BGP_STR
7657 "BGP view\n"
7658 "View name\n")
7659{
7660 struct bgp *bgp;
7661
7662 /* BGP structure lookup. */
7663 bgp = bgp_lookup_by_name (argv[0]);
7664 if (bgp == NULL)
7665 {
7666 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7667 return CMD_WARNING;
7668 }
7669
7670 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
7671}
7672
7673DEFUN (show_bgp_view_ipv6,
Lou Berger35c36862016-01-12 13:42:06 -05007674 show_bgp_view_ipv6_cmd,
7675 "show bgp view WORD ipv6",
paulbb46e942003-10-24 19:02:03 +00007676 SHOW_STR
Lou Berger35c36862016-01-12 13:42:06 -05007677 BGP_STR
paulbb46e942003-10-24 19:02:03 +00007678 "BGP view\n"
Lou Berger35c36862016-01-12 13:42:06 -05007679 "View name\n"
7680 "Address family\n")
paulbb46e942003-10-24 19:02:03 +00007681{
7682 struct bgp *bgp;
7683
7684 /* BGP structure lookup. */
7685 bgp = bgp_lookup_by_name (argv[0]);
7686 if (bgp == NULL)
7687 {
7688 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7689 return CMD_WARNING;
7690 }
7691
ajs5a646652004-11-05 01:25:55 +00007692 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007693}
paulbb46e942003-10-24 19:02:03 +00007694
7695DEFUN (show_bgp_view_route,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007696 show_bgp_view_route_cmd,
7697 "show bgp view WORD X:X::X:X",
7698 SHOW_STR
7699 BGP_STR
7700 "BGP view\n"
7701 "View name\n"
7702 "Network in the BGP routing table to display\n")
7703{
7704 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7705}
7706
7707DEFUN (show_bgp_view_ipv6_route,
paulbb46e942003-10-24 19:02:03 +00007708 show_bgp_view_ipv6_route_cmd,
7709 "show bgp view WORD ipv6 X:X::X:X",
7710 SHOW_STR
7711 BGP_STR
7712 "BGP view\n"
7713 "View name\n"
7714 "Address family\n"
7715 "Network in the BGP routing table to display\n")
paulbb46e942003-10-24 19:02:03 +00007716{
Lou Berger35c36862016-01-12 13:42:06 -05007717 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
paulbb46e942003-10-24 19:02:03 +00007718}
7719
Lou Bergerf9b6c392016-01-12 13:42:09 -05007720/* old command */
7721DEFUN (show_ipv6_mbgp,
7722 show_ipv6_mbgp_cmd,
7723 "show ipv6 mbgp",
7724 SHOW_STR
7725 IP_STR
7726 MBGP_STR)
7727{
7728 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7729 NULL);
7730}
7731
7732/* old command */
7733DEFUN (show_ipv6_mbgp_route,
7734 show_ipv6_mbgp_route_cmd,
7735 "show ipv6 mbgp X:X::X:X",
7736 SHOW_STR
7737 IP_STR
7738 MBGP_STR
7739 "Network in the MBGP routing table to display\n")
7740{
7741 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7742}
7743
7744/* old command */
7745DEFUN (show_ipv6_mbgp_prefix,
7746 show_ipv6_mbgp_prefix_cmd,
7747 "show ipv6 mbgp X:X::X:X/M",
7748 SHOW_STR
7749 IP_STR
7750 MBGP_STR
7751 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7752{
7753 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7754}
7755
Lou Berger35c36862016-01-12 13:42:06 -05007756DEFUN (show_bgp_view_prefix,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007757 show_bgp_view_prefix_cmd,
7758 "show bgp view WORD X:X::X:X/M",
7759 SHOW_STR
7760 BGP_STR
7761 "BGP view\n"
7762 "View name\n"
7763 "IPv6 prefix <network>/<length>\n")
7764{
7765 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7766}
7767
7768DEFUN (show_bgp_view_ipv6_prefix,
paulbb46e942003-10-24 19:02:03 +00007769 show_bgp_view_ipv6_prefix_cmd,
7770 "show bgp view WORD ipv6 X:X::X:X/M",
7771 SHOW_STR
7772 BGP_STR
7773 "BGP view\n"
7774 "View name\n"
7775 "Address family\n"
7776 "IPv6 prefix <network>/<length>\n")
paul718e3742002-12-13 20:15:29 +00007777{
Lou Berger35c36862016-01-12 13:42:06 -05007778 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
paul718e3742002-12-13 20:15:29 +00007779}
7780
paul94f2b392005-06-28 12:44:16 +00007781static int
paulfd79ac92004-10-13 05:06:08 +00007782bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007783 safi_t safi, enum bgp_show_type type)
7784{
7785 int i;
7786 struct buffer *b;
7787 char *regstr;
7788 int first;
7789 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007790 int rc;
paul718e3742002-12-13 20:15:29 +00007791
7792 first = 0;
7793 b = buffer_new (1024);
7794 for (i = 0; i < argc; i++)
7795 {
7796 if (first)
7797 buffer_putc (b, ' ');
7798 else
7799 {
7800 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7801 continue;
7802 first = 1;
7803 }
7804
7805 buffer_putstr (b, argv[i]);
7806 }
7807 buffer_putc (b, '\0');
7808
7809 regstr = buffer_getstr (b);
7810 buffer_free (b);
7811
7812 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007813 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007814 if (! regex)
7815 {
7816 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7817 VTY_NEWLINE);
7818 return CMD_WARNING;
7819 }
7820
ajs5a646652004-11-05 01:25:55 +00007821 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7822 bgp_regex_free (regex);
7823 return rc;
paul718e3742002-12-13 20:15:29 +00007824}
7825
Lou Bergerf9b6c392016-01-12 13:42:09 -05007826
7827DEFUN (show_ip_bgp_regexp,
7828 show_ip_bgp_regexp_cmd,
7829 "show ip bgp regexp .LINE",
7830 SHOW_STR
7831 IP_STR
7832 BGP_STR
7833 "Display routes matching the AS path regular expression\n"
7834 "A regular-expression to match the BGP AS paths\n")
7835{
7836 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7837 bgp_show_type_regexp);
7838}
7839
7840DEFUN (show_ip_bgp_flap_regexp,
7841 show_ip_bgp_flap_regexp_cmd,
7842 "show ip bgp flap-statistics regexp .LINE",
7843 SHOW_STR
7844 IP_STR
7845 BGP_STR
7846 "Display flap statistics of routes\n"
7847 "Display routes matching the AS path regular expression\n"
7848 "A regular-expression to match the BGP AS paths\n")
7849{
7850 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7851 bgp_show_type_flap_regexp);
7852}
7853
7854ALIAS (show_ip_bgp_flap_regexp,
7855 show_ip_bgp_damp_flap_regexp_cmd,
7856 "show ip bgp dampening flap-statistics regexp .LINE",
7857 SHOW_STR
7858 IP_STR
7859 BGP_STR
7860 "Display detailed information about dampening\n"
7861 "Display flap statistics of routes\n"
7862 "Display routes matching the AS path regular expression\n"
7863 "A regular-expression to match the BGP AS paths\n")
7864
7865DEFUN (show_ip_bgp_ipv4_regexp,
7866 show_ip_bgp_ipv4_regexp_cmd,
7867 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7868 SHOW_STR
7869 IP_STR
7870 BGP_STR
7871 "Address family\n"
7872 "Address Family modifier\n"
7873 "Address Family modifier\n"
7874 "Display routes matching the AS path regular expression\n"
7875 "A regular-expression to match the BGP AS paths\n")
7876{
7877 if (strncmp (argv[0], "m", 1) == 0)
7878 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7879 bgp_show_type_regexp);
7880
7881 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7882 bgp_show_type_regexp);
7883}
7884
Lou Bergerf9b6c392016-01-12 13:42:09 -05007885DEFUN (show_bgp_regexp,
7886 show_bgp_regexp_cmd,
7887 "show bgp regexp .LINE",
7888 SHOW_STR
7889 BGP_STR
7890 "Display routes matching the AS path regular expression\n"
7891 "A regular-expression to match the BGP AS paths\n")
7892{
7893 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7894 bgp_show_type_regexp);
7895}
7896
7897/* old command */
7898DEFUN (show_ipv6_bgp_regexp,
7899 show_ipv6_bgp_regexp_cmd,
7900 "show ipv6 bgp regexp .LINE",
7901 SHOW_STR
7902 IP_STR
7903 BGP_STR
7904 "Display routes matching the AS path regular expression\n"
7905 "A regular-expression to match the BGP AS paths\n")
7906{
7907 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7908 bgp_show_type_regexp);
7909}
7910
7911/* old command */
7912DEFUN (show_ipv6_mbgp_regexp,
7913 show_ipv6_mbgp_regexp_cmd,
7914 "show ipv6 mbgp regexp .LINE",
7915 SHOW_STR
7916 IP_STR
7917 BGP_STR
7918 "Display routes matching the AS path regular expression\n"
7919 "A regular-expression to match the MBGP AS paths\n")
7920{
7921 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7922 bgp_show_type_regexp);
7923}
Lou Bergerf9b6c392016-01-12 13:42:09 -05007924
Lou Berger651b4022016-01-12 13:42:07 -05007925DEFUN (show_bgp_ipv4_safi_flap_regexp,
7926 show_bgp_ipv4_safi_flap_regexp_cmd,
7927 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics regexp .LINE",
paul718e3742002-12-13 20:15:29 +00007928 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007929 BGP_STR
paul718e3742002-12-13 20:15:29 +00007930 IP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007931 "Address Family Modifier\n"
7932 "Address Family Modifier\n"
7933 "Address Family Modifier\n"
7934 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00007935 "Display flap statistics of routes\n"
7936 "Display routes matching the AS path regular expression\n"
7937 "A regular-expression to match the BGP AS paths\n")
7938{
Lou Berger651b4022016-01-12 13:42:07 -05007939 safi_t safi;
7940
7941 if (bgp_parse_safi(argv[0], &safi)) {
7942 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7943 return CMD_WARNING;
7944 }
7945 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP, safi,
7946 bgp_show_type_flap_regexp);
paul718e3742002-12-13 20:15:29 +00007947}
7948
Lou Berger651b4022016-01-12 13:42:07 -05007949ALIAS (show_bgp_ipv4_safi_flap_regexp,
7950 show_bgp_ipv4_safi_damp_flap_regexp_cmd,
7951 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics regexp .LINE",
Balaji3921cc52015-05-16 23:12:17 +05307952 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05307953 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007954 IP_STR
7955 "Address Family Modifier\n"
7956 "Address Family Modifier\n"
7957 "Address Family Modifier\n"
7958 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05307959 "Display detailed information about dampening\n"
7960 "Display flap statistics of routes\n"
7961 "Display routes matching the AS path regular expression\n"
7962 "A regular-expression to match the BGP AS paths\n")
7963
Lou Berger651b4022016-01-12 13:42:07 -05007964DEFUN (show_bgp_ipv6_safi_flap_regexp,
7965 show_bgp_ipv6_safi_flap_regexp_cmd,
7966 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics regexp .LINE",
paul718e3742002-12-13 20:15:29 +00007967 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05007968 BGP_STR
7969 IPV6_STR
7970 "Address Family Modifier\n"
7971 "Address Family Modifier\n"
7972 "Address Family Modifier\n"
7973 "Address Family Modifier\n"
7974 "Display flap statistics of routes\n"
7975 "Display routes matching the AS path regular expression\n"
7976 "A regular-expression to match the BGP AS paths\n")
7977{
7978 safi_t safi;
7979
7980 if (bgp_parse_safi(argv[0], &safi)) {
7981 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7982 return CMD_WARNING;
7983 }
7984 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP6, safi,
7985 bgp_show_type_flap_regexp);
7986}
7987
7988ALIAS (show_bgp_ipv6_safi_flap_regexp,
7989 show_bgp_ipv6_safi_damp_flap_regexp_cmd,
7990 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics regexp .LINE",
7991 SHOW_STR
7992 BGP_STR
7993 IPV6_STR
7994 "Address Family Modifier\n"
7995 "Address Family Modifier\n"
7996 "Address Family Modifier\n"
7997 "Address Family Modifier\n"
7998 "Display detailed information about dampening\n"
7999 "Display flap statistics of routes\n"
8000 "Display routes matching the AS path regular expression\n"
8001 "A regular-expression to match the BGP AS paths\n")
Lou Berger651b4022016-01-12 13:42:07 -05008002
8003DEFUN (show_bgp_ipv4_safi_regexp,
8004 show_bgp_ipv4_safi_regexp_cmd,
8005 "show bgp ipv4 (encap|multicast|unicast|vpn) regexp .LINE",
8006 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008007 BGP_STR
8008 "Address family\n"
8009 "Address Family modifier\n"
8010 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05008011 "Address Family modifier\n"
8012 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008013 "Display routes matching the AS path regular expression\n"
8014 "A regular-expression to match the BGP AS paths\n")
8015{
Lou Berger651b4022016-01-12 13:42:07 -05008016 safi_t safi;
8017 if (bgp_parse_safi(argv[0], &safi)) {
8018 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8019 return CMD_WARNING;
8020 }
paul718e3742002-12-13 20:15:29 +00008021
Lou Berger651b4022016-01-12 13:42:07 -05008022 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008023 bgp_show_type_regexp);
8024}
Lou Berger205e6742016-01-12 13:42:11 -05008025
Lou Berger651b4022016-01-12 13:42:07 -05008026DEFUN (show_bgp_ipv6_safi_regexp,
8027 show_bgp_ipv6_safi_regexp_cmd,
8028 "show bgp ipv6 (encap|multicast|unicast|vpn) regexp .LINE",
paul718e3742002-12-13 20:15:29 +00008029 SHOW_STR
8030 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008031 "Address family\n"
8032 "Address Family modifier\n"
8033 "Address Family modifier\n"
8034 "Address Family modifier\n"
8035 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008036 "Display routes matching the AS path regular expression\n"
8037 "A regular-expression to match the BGP AS paths\n")
8038{
Lou Berger651b4022016-01-12 13:42:07 -05008039 safi_t safi;
8040 if (bgp_parse_safi(argv[0], &safi)) {
8041 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8042 return CMD_WARNING;
8043 }
8044
8045 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00008046 bgp_show_type_regexp);
8047}
8048
Lou Berger651b4022016-01-12 13:42:07 -05008049DEFUN (show_bgp_ipv6_regexp,
paul718e3742002-12-13 20:15:29 +00008050 show_bgp_ipv6_regexp_cmd,
8051 "show bgp ipv6 regexp .LINE",
8052 SHOW_STR
8053 BGP_STR
8054 "Address family\n"
8055 "Display routes matching the AS path regular expression\n"
8056 "A regular-expression to match the BGP AS paths\n")
paul718e3742002-12-13 20:15:29 +00008057{
8058 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8059 bgp_show_type_regexp);
8060}
8061
paul94f2b392005-06-28 12:44:16 +00008062static int
paulfd79ac92004-10-13 05:06:08 +00008063bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008064 safi_t safi, enum bgp_show_type type)
8065{
8066 struct prefix_list *plist;
8067
8068 plist = prefix_list_lookup (afi, prefix_list_str);
8069 if (plist == NULL)
8070 {
8071 vty_out (vty, "%% %s is not a valid prefix-list name%s",
8072 prefix_list_str, VTY_NEWLINE);
8073 return CMD_WARNING;
8074 }
8075
ajs5a646652004-11-05 01:25:55 +00008076 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00008077}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008078DEFUN (show_ip_bgp_prefix_list,
8079 show_ip_bgp_prefix_list_cmd,
8080 "show ip bgp prefix-list WORD",
8081 SHOW_STR
8082 IP_STR
8083 BGP_STR
8084 "Display routes conforming to the prefix-list\n"
8085 "IP prefix-list name\n")
8086{
8087 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8088 bgp_show_type_prefix_list);
8089}
8090
8091DEFUN (show_ip_bgp_flap_prefix_list,
8092 show_ip_bgp_flap_prefix_list_cmd,
8093 "show ip bgp flap-statistics prefix-list WORD",
8094 SHOW_STR
8095 IP_STR
8096 BGP_STR
8097 "Display flap statistics of routes\n"
8098 "Display routes conforming to the prefix-list\n"
8099 "IP prefix-list name\n")
8100{
8101 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8102 bgp_show_type_flap_prefix_list);
8103}
8104
8105ALIAS (show_ip_bgp_flap_prefix_list,
8106 show_ip_bgp_damp_flap_prefix_list_cmd,
8107 "show ip bgp dampening flap-statistics prefix-list WORD",
8108 SHOW_STR
8109 IP_STR
8110 BGP_STR
8111 "Display detailed information about dampening\n"
8112 "Display flap statistics of routes\n"
8113 "Display routes conforming to the prefix-list\n"
8114 "IP prefix-list name\n")
8115
8116DEFUN (show_ip_bgp_ipv4_prefix_list,
8117 show_ip_bgp_ipv4_prefix_list_cmd,
8118 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
8119 SHOW_STR
8120 IP_STR
8121 BGP_STR
8122 "Address family\n"
8123 "Address Family modifier\n"
8124 "Address Family modifier\n"
8125 "Display routes conforming to the prefix-list\n"
8126 "IP prefix-list name\n")
8127{
8128 if (strncmp (argv[0], "m", 1) == 0)
8129 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8130 bgp_show_type_prefix_list);
8131
8132 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8133 bgp_show_type_prefix_list);
8134}
8135
Lou Bergerf9b6c392016-01-12 13:42:09 -05008136DEFUN (show_bgp_prefix_list,
8137 show_bgp_prefix_list_cmd,
8138 "show bgp prefix-list WORD",
8139 SHOW_STR
8140 BGP_STR
8141 "Display routes conforming to the prefix-list\n"
8142 "IPv6 prefix-list name\n")
8143{
8144 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8145 bgp_show_type_prefix_list);
8146}
8147
8148ALIAS (show_bgp_prefix_list,
8149 show_bgp_ipv6_prefix_list_cmd,
8150 "show bgp ipv6 prefix-list WORD",
8151 SHOW_STR
8152 BGP_STR
8153 "Address family\n"
8154 "Display routes conforming to the prefix-list\n"
8155 "IPv6 prefix-list name\n")
8156
8157/* old command */
8158DEFUN (show_ipv6_bgp_prefix_list,
8159 show_ipv6_bgp_prefix_list_cmd,
8160 "show ipv6 bgp prefix-list WORD",
8161 SHOW_STR
8162 IPV6_STR
8163 BGP_STR
8164 "Display routes matching the prefix-list\n"
8165 "IPv6 prefix-list name\n")
8166{
8167 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8168 bgp_show_type_prefix_list);
8169}
8170
8171/* old command */
8172DEFUN (show_ipv6_mbgp_prefix_list,
8173 show_ipv6_mbgp_prefix_list_cmd,
8174 "show ipv6 mbgp prefix-list WORD",
8175 SHOW_STR
8176 IPV6_STR
8177 MBGP_STR
8178 "Display routes matching the prefix-list\n"
8179 "IPv6 prefix-list name\n")
8180{
8181 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8182 bgp_show_type_prefix_list);
8183}
paul718e3742002-12-13 20:15:29 +00008184
Lou Berger35c36862016-01-12 13:42:06 -05008185DEFUN (show_bgp_ipv4_prefix_list,
8186 show_bgp_ipv4_prefix_list_cmd,
8187 "show bgp ipv4 prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008188 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008189 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05008190 IP_STR
paul718e3742002-12-13 20:15:29 +00008191 "Display routes conforming to the prefix-list\n"
8192 "IP prefix-list name\n")
8193{
8194 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8195 bgp_show_type_prefix_list);
8196}
8197
Lou Berger651b4022016-01-12 13:42:07 -05008198DEFUN (show_bgp_ipv4_safi_flap_prefix_list,
8199 show_bgp_ipv4_safi_flap_prefix_list_cmd,
8200 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008201 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008202 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008203 IP_STR
8204 "Address Family Modifier\n"
8205 "Address Family Modifier\n"
8206 "Address Family Modifier\n"
8207 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00008208 "Display flap statistics of routes\n"
8209 "Display routes conforming to the prefix-list\n"
8210 "IP prefix-list name\n")
8211{
Lou Berger651b4022016-01-12 13:42:07 -05008212 safi_t safi;
8213 if (bgp_parse_safi(argv[0], &safi)) {
8214 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8215 return CMD_WARNING;
8216 }
8217 return bgp_show_prefix_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008218 bgp_show_type_flap_prefix_list);
8219}
8220
Lou Berger651b4022016-01-12 13:42:07 -05008221ALIAS (show_bgp_ipv4_safi_flap_prefix_list,
8222 show_bgp_ipv4_safi_damp_flap_prefix_list_cmd,
8223 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics prefix-list WORD",
Balaji3921cc52015-05-16 23:12:17 +05308224 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308225 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008226 IP_STR
8227 "Address Family Modifier\n"
8228 "Address Family Modifier\n"
8229 "Address Family Modifier\n"
8230 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308231 "Display detailed information about dampening\n"
8232 "Display flap statistics of routes\n"
8233 "Display routes conforming to the prefix-list\n"
8234 "IP prefix-list name\n")
8235
Lou Berger651b4022016-01-12 13:42:07 -05008236DEFUN (show_bgp_ipv6_safi_flap_prefix_list,
8237 show_bgp_ipv6_safi_flap_prefix_list_cmd,
8238 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008239 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05008240 BGP_STR
8241 IPV6_STR
8242 "Address Family Modifier\n"
8243 "Address Family Modifier\n"
8244 "Address Family Modifier\n"
8245 "Address Family Modifier\n"
8246 "Display flap statistics of routes\n"
8247 "Display routes conforming to the prefix-list\n"
8248 "IP prefix-list name\n")
8249{
8250 safi_t safi;
8251 if (bgp_parse_safi(argv[0], &safi)) {
8252 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8253 return CMD_WARNING;
8254 }
8255 return bgp_show_prefix_list (vty, argv[1], AFI_IP6, safi,
8256 bgp_show_type_flap_prefix_list);
8257}
8258ALIAS (show_bgp_ipv6_safi_flap_prefix_list,
8259 show_bgp_ipv6_safi_damp_flap_prefix_list_cmd,
8260 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics prefix-list WORD",
8261 SHOW_STR
8262 BGP_STR
8263 IPV6_STR
8264 "Address Family Modifier\n"
8265 "Address Family Modifier\n"
8266 "Address Family Modifier\n"
8267 "Address Family Modifier\n"
8268 "Display detailed information about dampening\n"
8269 "Display flap statistics of routes\n"
8270 "Display routes conforming to the prefix-list\n"
8271 "IP prefix-list name\n")
Lou Berger651b4022016-01-12 13:42:07 -05008272
8273DEFUN (show_bgp_ipv4_safi_prefix_list,
8274 show_bgp_ipv4_safi_prefix_list_cmd,
8275 "show bgp ipv4 (encap|multicast|unicast|vpn) prefix-list WORD",
8276 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008277 BGP_STR
8278 "Address family\n"
8279 "Address Family modifier\n"
8280 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05008281 "Address Family modifier\n"
8282 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008283 "Display routes conforming to the prefix-list\n"
8284 "IP prefix-list name\n")
8285{
Lou Berger651b4022016-01-12 13:42:07 -05008286 safi_t safi;
8287 if (bgp_parse_safi(argv[0], &safi)) {
8288 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8289 return CMD_WARNING;
8290 }
8291 return bgp_show_prefix_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008292 bgp_show_type_prefix_list);
8293}
Lou Berger205e6742016-01-12 13:42:11 -05008294
Lou Berger651b4022016-01-12 13:42:07 -05008295DEFUN (show_bgp_ipv6_safi_prefix_list,
8296 show_bgp_ipv6_safi_prefix_list_cmd,
8297 "show bgp ipv6 (encap|multicast|unicast|vpn) prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008298 SHOW_STR
8299 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008300 "Address family\n"
8301 "Address Family modifier\n"
8302 "Address Family modifier\n"
8303 "Address Family modifier\n"
8304 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008305 "Display routes conforming to the prefix-list\n"
Lou Berger651b4022016-01-12 13:42:07 -05008306 "IP prefix-list name\n")
paul718e3742002-12-13 20:15:29 +00008307{
Lou Berger651b4022016-01-12 13:42:07 -05008308 safi_t safi;
8309 if (bgp_parse_safi(argv[0], &safi)) {
8310 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8311 return CMD_WARNING;
8312 }
8313 return bgp_show_prefix_list (vty, argv[1], AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00008314 bgp_show_type_prefix_list);
8315}
8316
paul94f2b392005-06-28 12:44:16 +00008317static int
paulfd79ac92004-10-13 05:06:08 +00008318bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008319 safi_t safi, enum bgp_show_type type)
8320{
8321 struct as_list *as_list;
8322
8323 as_list = as_list_lookup (filter);
8324 if (as_list == NULL)
8325 {
8326 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
8327 return CMD_WARNING;
8328 }
8329
ajs5a646652004-11-05 01:25:55 +00008330 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00008331}
8332
Lou Bergerf9b6c392016-01-12 13:42:09 -05008333DEFUN (show_ip_bgp_filter_list,
8334 show_ip_bgp_filter_list_cmd,
8335 "show ip bgp filter-list WORD",
8336 SHOW_STR
8337 IP_STR
8338 BGP_STR
8339 "Display routes conforming to the filter-list\n"
8340 "Regular expression access list name\n")
8341{
8342 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8343 bgp_show_type_filter_list);
8344}
8345
8346DEFUN (show_ip_bgp_flap_filter_list,
8347 show_ip_bgp_flap_filter_list_cmd,
8348 "show ip bgp flap-statistics filter-list WORD",
8349 SHOW_STR
8350 IP_STR
8351 BGP_STR
8352 "Display flap statistics of routes\n"
8353 "Display routes conforming to the filter-list\n"
8354 "Regular expression access list name\n")
8355{
8356 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8357 bgp_show_type_flap_filter_list);
8358}
8359
8360ALIAS (show_ip_bgp_flap_filter_list,
8361 show_ip_bgp_damp_flap_filter_list_cmd,
8362 "show ip bgp dampening flap-statistics filter-list WORD",
8363 SHOW_STR
8364 IP_STR
8365 BGP_STR
8366 "Display detailed information about dampening\n"
8367 "Display flap statistics of routes\n"
8368 "Display routes conforming to the filter-list\n"
8369 "Regular expression access list name\n")
8370
8371DEFUN (show_ip_bgp_ipv4_filter_list,
8372 show_ip_bgp_ipv4_filter_list_cmd,
8373 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
8374 SHOW_STR
8375 IP_STR
8376 BGP_STR
8377 "Address family\n"
8378 "Address Family modifier\n"
8379 "Address Family modifier\n"
8380 "Display routes conforming to the filter-list\n"
8381 "Regular expression access list name\n")
8382{
8383 if (strncmp (argv[0], "m", 1) == 0)
8384 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8385 bgp_show_type_filter_list);
8386
8387 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8388 bgp_show_type_filter_list);
8389}
8390
Lou Bergerf9b6c392016-01-12 13:42:09 -05008391DEFUN (show_bgp_filter_list,
8392 show_bgp_filter_list_cmd,
8393 "show bgp filter-list WORD",
8394 SHOW_STR
8395 BGP_STR
8396 "Display routes conforming to the filter-list\n"
8397 "Regular expression access list name\n")
8398{
8399 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8400 bgp_show_type_filter_list);
8401}
8402
8403/* old command */
8404DEFUN (show_ipv6_bgp_filter_list,
8405 show_ipv6_bgp_filter_list_cmd,
8406 "show ipv6 bgp filter-list WORD",
8407 SHOW_STR
8408 IPV6_STR
8409 BGP_STR
8410 "Display routes conforming to the filter-list\n"
8411 "Regular expression access list name\n")
8412{
8413 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8414 bgp_show_type_filter_list);
8415}
8416
8417/* old command */
8418DEFUN (show_ipv6_mbgp_filter_list,
8419 show_ipv6_mbgp_filter_list_cmd,
8420 "show ipv6 mbgp filter-list WORD",
8421 SHOW_STR
8422 IPV6_STR
8423 MBGP_STR
8424 "Display routes conforming to the filter-list\n"
8425 "Regular expression access list name\n")
8426{
8427 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8428 bgp_show_type_filter_list);
8429}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008430
8431DEFUN (show_ip_bgp_dampening_info,
8432 show_ip_bgp_dampening_params_cmd,
8433 "show ip bgp dampening parameters",
8434 SHOW_STR
8435 IP_STR
8436 BGP_STR
8437 "Display detailed information about dampening\n"
8438 "Display detail of configured dampening parameters\n")
8439{
8440 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
8441}
8442
Lou Berger651b4022016-01-12 13:42:07 -05008443DEFUN (show_bgp_ipv4_filter_list,
8444 show_bgp_ipv4_filter_list_cmd,
8445 "show bgp ipv4 filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008446 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008447 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008448 IP_STR
paul718e3742002-12-13 20:15:29 +00008449 "Display routes conforming to the filter-list\n"
8450 "Regular expression access list name\n")
8451{
8452 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8453 bgp_show_type_filter_list);
8454}
8455
Lou Berger651b4022016-01-12 13:42:07 -05008456DEFUN (show_bgp_ipv4_safi_flap_filter_list,
8457 show_bgp_ipv4_safi_flap_filter_list_cmd,
8458 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008459 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008460 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008461 IP_STR
8462 "Address Family modifier\n"
8463 "Address Family modifier\n"
8464 "Address Family modifier\n"
8465 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008466 "Display flap statistics of routes\n"
8467 "Display routes conforming to the filter-list\n"
8468 "Regular expression access list name\n")
8469{
Lou Berger651b4022016-01-12 13:42:07 -05008470 safi_t safi;
8471
8472 if (bgp_parse_safi(argv[0], &safi)) {
8473 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8474 return CMD_WARNING;
8475 }
8476 return bgp_show_filter_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008477 bgp_show_type_flap_filter_list);
8478}
8479
Lou Berger651b4022016-01-12 13:42:07 -05008480ALIAS (show_bgp_ipv4_safi_flap_filter_list,
8481 show_bgp_ipv4_safi_damp_flap_filter_list_cmd,
8482 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics filter-list WORD",
Balaji3921cc52015-05-16 23:12:17 +05308483 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308484 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008485 IP_STR
8486 "Address Family modifier\n"
8487 "Address Family modifier\n"
8488 "Address Family modifier\n"
8489 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308490 "Display detailed information about dampening\n"
8491 "Display flap statistics of routes\n"
8492 "Display routes conforming to the filter-list\n"
8493 "Regular expression access list name\n")
8494
Lou Berger651b4022016-01-12 13:42:07 -05008495DEFUN (show_bgp_ipv6_safi_flap_filter_list,
8496 show_bgp_ipv6_safi_flap_filter_list_cmd,
8497 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008498 SHOW_STR
8499 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008500 IPV6_STR
8501 "Address Family modifier\n"
8502 "Address Family modifier\n"
8503 "Address Family modifier\n"
8504 "Address Family modifier\n"
8505 "Display flap statistics of routes\n"
paul718e3742002-12-13 20:15:29 +00008506 "Display routes conforming to the filter-list\n"
8507 "Regular expression access list name\n")
8508{
Lou Berger651b4022016-01-12 13:42:07 -05008509 safi_t safi;
8510
8511 if (bgp_parse_safi(argv[0], &safi)) {
8512 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8513 return CMD_WARNING;
8514 }
8515 return bgp_show_filter_list (vty, argv[1], AFI_IP6, safi,
8516 bgp_show_type_flap_filter_list);
8517}
8518ALIAS (show_bgp_ipv6_safi_flap_filter_list,
8519 show_bgp_ipv6_safi_damp_flap_filter_list_cmd,
8520 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics filter-list WORD",
8521 SHOW_STR
8522 BGP_STR
8523 IPV6_STR
8524 "Address Family modifier\n"
8525 "Address Family modifier\n"
8526 "Address Family modifier\n"
8527 "Address Family modifier\n"
8528 "Display detailed information about dampening\n"
8529 "Display flap statistics of routes\n"
8530 "Display routes conforming to the filter-list\n"
8531 "Regular expression access list name\n")
Lou Berger651b4022016-01-12 13:42:07 -05008532
8533DEFUN (show_bgp_ipv4_safi_filter_list,
8534 show_bgp_ipv4_safi_filter_list_cmd,
8535 "show bgp ipv4 (encap|multicast|unicast|vpn) filter-list WORD",
8536 SHOW_STR
8537 BGP_STR
8538 "Address Family modifier\n"
8539 "Address Family modifier\n"
8540 "Address Family modifier\n"
8541 "Address Family modifier\n"
8542 "Display routes conforming to the filter-list\n"
8543 "Regular expression access list name\n")
8544{
8545 safi_t safi;
8546
8547 if (bgp_parse_safi(argv[0], &safi)) {
8548 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8549 return CMD_WARNING;
8550 }
8551 return bgp_show_filter_list (vty, argv[1], AFI_IP, safi,
8552 bgp_show_type_filter_list);
8553}
Lou Berger205e6742016-01-12 13:42:11 -05008554
Lou Berger651b4022016-01-12 13:42:07 -05008555DEFUN (show_bgp_ipv6_safi_filter_list,
8556 show_bgp_ipv6_safi_filter_list_cmd,
8557 "show bgp ipv6 (encap|multicast|unicast|vpn) filter-list WORD",
8558 SHOW_STR
8559 BGP_STR
8560 "Address Family modifier\n"
8561 "Address Family modifier\n"
8562 "Address Family modifier\n"
8563 "Address Family modifier\n"
8564 "Display routes conforming to the filter-list\n"
8565 "Regular expression access list name\n")
8566{
8567 safi_t safi;
8568
8569 if (bgp_parse_safi(argv[0], &safi)) {
8570 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8571 return CMD_WARNING;
8572 }
8573 return bgp_show_filter_list (vty, argv[1], AFI_IP6, safi,
8574 bgp_show_type_filter_list);
paul718e3742002-12-13 20:15:29 +00008575}
8576
Lou Bergerf9b6c392016-01-12 13:42:09 -05008577DEFUN (show_bgp_ipv6_filter_list,
paul718e3742002-12-13 20:15:29 +00008578 show_bgp_ipv6_filter_list_cmd,
8579 "show bgp ipv6 filter-list WORD",
8580 SHOW_STR
8581 BGP_STR
8582 "Address family\n"
8583 "Display routes conforming to the filter-list\n"
8584 "Regular expression access list name\n")
paul718e3742002-12-13 20:15:29 +00008585{
8586 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8587 bgp_show_type_filter_list);
8588}
8589
Balaji9c52cae2016-01-20 22:59:26 +05308590
8591DEFUN (show_ip_bgp_ipv4_dampening_parameters,
8592 show_ip_bgp_ipv4_dampening_parameters_cmd,
8593 "show ip bgp ipv4 (unicast|multicast) dampening parameters",
8594 SHOW_STR
8595 IP_STR
8596 BGP_STR
8597 "Address family\n"
8598 "Address Family modifier\n"
8599 "Address Family modifier\n"
8600 "Display detailed information about dampening\n"
8601 "Display detail of configured dampening parameters\n")
8602{
8603 if (strncmp(argv[0], "m", 1) == 0)
8604 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_MULTICAST);
8605
8606 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
8607}
8608
8609
8610DEFUN (show_ip_bgp_ipv4_dampening_flap_stats,
8611 show_ip_bgp_ipv4_dampening_flap_stats_cmd,
8612 "show ip bgp ipv4 (unicast|multicast) dampening flap-statistics",
8613 SHOW_STR
8614 IP_STR
8615 BGP_STR
8616 "Address family\n"
8617 "Address Family modifier\n"
8618 "Address Family modifier\n"
8619 "Display detailed information about dampening\n"
8620 "Display flap statistics of routes\n")
8621{
8622 if (strncmp(argv[0], "m", 1) == 0)
8623 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8624 bgp_show_type_flap_statistics, NULL);
8625
8626 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8627 bgp_show_type_flap_statistics, NULL);
8628}
8629
8630DEFUN (show_ip_bgp_ipv4_dampening_dampd_paths,
8631 show_ip_bgp_ipv4_dampening_dampd_paths_cmd,
8632 "show ip bgp ipv4 (unicast|multicast) dampening dampened-paths",
8633 SHOW_STR
8634 IP_STR
8635 BGP_STR
8636 "Address family\n"
8637 "Address Family modifier\n"
8638 "Address Family modifier\n"
8639 "Display detailed information about dampening\n"
8640 "Display paths suppressed due to dampening\n")
8641{
8642 if (strncmp(argv[0], "m", 1) == 0)
8643 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8644 bgp_show_type_dampend_paths, NULL);
8645
8646 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8647 bgp_show_type_dampend_paths, NULL);
8648}
8649
paul94f2b392005-06-28 12:44:16 +00008650static int
paulfd79ac92004-10-13 05:06:08 +00008651bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008652 safi_t safi, enum bgp_show_type type)
8653{
8654 struct route_map *rmap;
8655
8656 rmap = route_map_lookup_by_name (rmap_str);
8657 if (! rmap)
8658 {
8659 vty_out (vty, "%% %s is not a valid route-map name%s",
8660 rmap_str, VTY_NEWLINE);
8661 return CMD_WARNING;
8662 }
8663
ajs5a646652004-11-05 01:25:55 +00008664 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00008665}
8666
Lou Bergerf9b6c392016-01-12 13:42:09 -05008667DEFUN (show_ip_bgp_route_map,
8668 show_ip_bgp_route_map_cmd,
8669 "show ip bgp route-map WORD",
8670 SHOW_STR
8671 IP_STR
8672 BGP_STR
8673 "Display routes matching the route-map\n"
8674 "A route-map to match on\n")
8675{
8676 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8677 bgp_show_type_route_map);
8678}
8679
8680DEFUN (show_ip_bgp_flap_route_map,
8681 show_ip_bgp_flap_route_map_cmd,
8682 "show ip bgp flap-statistics route-map WORD",
8683 SHOW_STR
8684 IP_STR
8685 BGP_STR
8686 "Display flap statistics of routes\n"
8687 "Display routes matching the route-map\n"
8688 "A route-map to match on\n")
8689{
8690 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8691 bgp_show_type_flap_route_map);
8692}
8693
8694ALIAS (show_ip_bgp_flap_route_map,
8695 show_ip_bgp_damp_flap_route_map_cmd,
8696 "show ip bgp dampening flap-statistics route-map WORD",
8697 SHOW_STR
8698 IP_STR
8699 BGP_STR
8700 "Display detailed information about dampening\n"
8701 "Display flap statistics of routes\n"
8702 "Display routes matching the route-map\n"
8703 "A route-map to match on\n")
8704
8705DEFUN (show_ip_bgp_ipv4_route_map,
8706 show_ip_bgp_ipv4_route_map_cmd,
8707 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
8708 SHOW_STR
8709 IP_STR
8710 BGP_STR
8711 "Address family\n"
8712 "Address Family modifier\n"
8713 "Address Family modifier\n"
8714 "Display routes matching the route-map\n"
8715 "A route-map to match on\n")
8716{
8717 if (strncmp (argv[0], "m", 1) == 0)
8718 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8719 bgp_show_type_route_map);
8720
8721 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
8722 bgp_show_type_route_map);
8723}
8724
8725DEFUN (show_bgp_route_map,
8726 show_bgp_route_map_cmd,
8727 "show bgp route-map WORD",
8728 SHOW_STR
8729 BGP_STR
8730 "Display routes matching the route-map\n"
8731 "A route-map to match on\n")
8732{
8733 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8734 bgp_show_type_route_map);
8735}
8736
8737DEFUN (show_ip_bgp_cidr_only,
8738 show_ip_bgp_cidr_only_cmd,
8739 "show ip bgp cidr-only",
8740 SHOW_STR
8741 IP_STR
8742 BGP_STR
8743 "Display only routes with non-natural netmasks\n")
8744{
8745 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8746 bgp_show_type_cidr_only, NULL);
8747}
8748
8749DEFUN (show_ip_bgp_flap_cidr_only,
8750 show_ip_bgp_flap_cidr_only_cmd,
8751 "show ip bgp flap-statistics cidr-only",
8752 SHOW_STR
8753 IP_STR
8754 BGP_STR
8755 "Display flap statistics of routes\n"
8756 "Display only routes with non-natural netmasks\n")
8757{
8758 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8759 bgp_show_type_flap_cidr_only, NULL);
8760}
8761
8762ALIAS (show_ip_bgp_flap_cidr_only,
8763 show_ip_bgp_damp_flap_cidr_only_cmd,
8764 "show ip bgp dampening flap-statistics cidr-only",
8765 SHOW_STR
8766 IP_STR
8767 BGP_STR
8768 "Display detailed information about dampening\n"
8769 "Display flap statistics of routes\n"
8770 "Display only routes with non-natural netmasks\n")
8771
8772DEFUN (show_ip_bgp_ipv4_cidr_only,
8773 show_ip_bgp_ipv4_cidr_only_cmd,
8774 "show ip bgp ipv4 (unicast|multicast) cidr-only",
8775 SHOW_STR
8776 IP_STR
8777 BGP_STR
8778 "Address family\n"
8779 "Address Family modifier\n"
8780 "Address Family modifier\n"
8781 "Display only routes with non-natural netmasks\n")
8782{
8783 if (strncmp (argv[0], "m", 1) == 0)
8784 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8785 bgp_show_type_cidr_only, NULL);
8786
8787 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8788 bgp_show_type_cidr_only, NULL);
8789}
8790
8791DEFUN (show_ip_bgp_community_all,
8792 show_ip_bgp_community_all_cmd,
8793 "show ip bgp community",
8794 SHOW_STR
8795 IP_STR
8796 BGP_STR
8797 "Display routes matching the communities\n")
8798{
8799 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8800 bgp_show_type_community_all, NULL);
8801}
8802
8803DEFUN (show_ip_bgp_ipv4_community_all,
8804 show_ip_bgp_ipv4_community_all_cmd,
8805 "show ip bgp ipv4 (unicast|multicast) community",
8806 SHOW_STR
8807 IP_STR
8808 BGP_STR
8809 "Address family\n"
8810 "Address Family modifier\n"
8811 "Address Family modifier\n"
8812 "Display routes matching the communities\n")
8813{
8814 if (strncmp (argv[0], "m", 1) == 0)
8815 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8816 bgp_show_type_community_all, NULL);
8817
8818 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8819 bgp_show_type_community_all, NULL);
8820}
8821
Lou Bergerf9b6c392016-01-12 13:42:09 -05008822DEFUN (show_bgp_community_all,
8823 show_bgp_community_all_cmd,
8824 "show bgp community",
8825 SHOW_STR
8826 BGP_STR
8827 "Display routes matching the communities\n")
8828{
8829 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
8830 bgp_show_type_community_all, NULL);
8831}
8832
8833ALIAS (show_bgp_community_all,
8834 show_bgp_ipv6_community_all_cmd,
8835 "show bgp ipv6 community",
8836 SHOW_STR
8837 BGP_STR
8838 "Address family\n"
8839 "Display routes matching the communities\n")
8840
8841/* old command */
8842DEFUN (show_ipv6_bgp_community_all,
8843 show_ipv6_bgp_community_all_cmd,
8844 "show ipv6 bgp community",
8845 SHOW_STR
8846 IPV6_STR
8847 BGP_STR
8848 "Display routes matching the communities\n")
8849{
8850 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
8851 bgp_show_type_community_all, NULL);
8852}
8853
8854/* old command */
8855DEFUN (show_ipv6_mbgp_community_all,
8856 show_ipv6_mbgp_community_all_cmd,
8857 "show ipv6 mbgp community",
8858 SHOW_STR
8859 IPV6_STR
8860 MBGP_STR
8861 "Display routes matching the communities\n")
8862{
8863 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
8864 bgp_show_type_community_all, NULL);
8865}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008866
Lou Berger651b4022016-01-12 13:42:07 -05008867DEFUN (show_bgp_ipv4_route_map,
8868 show_bgp_ipv4_route_map_cmd,
8869 "show bgp ipv4 route-map WORD",
paul718e3742002-12-13 20:15:29 +00008870 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008871 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008872 IP_STR
paul718e3742002-12-13 20:15:29 +00008873 "Display routes matching the route-map\n"
8874 "A route-map to match on\n")
8875{
8876 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8877 bgp_show_type_route_map);
8878}
8879
Lou Berger651b4022016-01-12 13:42:07 -05008880DEFUN (show_bgp_ipv4_safi_flap_route_map,
8881 show_bgp_ipv4_safi_flap_route_map_cmd,
8882 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics route-map WORD",
paul718e3742002-12-13 20:15:29 +00008883 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008884 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008885 IP_STR
8886 "Address Family Modifier\n"
8887 "Address Family Modifier\n"
8888 "Address Family Modifier\n"
8889 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00008890 "Display flap statistics of routes\n"
8891 "Display routes matching the route-map\n"
8892 "A route-map to match on\n")
8893{
Lou Berger651b4022016-01-12 13:42:07 -05008894 safi_t safi;
8895 if (bgp_parse_safi(argv[0], &safi)) {
8896 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8897 return CMD_WARNING;
8898 }
8899 return bgp_show_route_map (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008900 bgp_show_type_flap_route_map);
8901}
8902
Lou Berger651b4022016-01-12 13:42:07 -05008903ALIAS (show_bgp_ipv4_safi_flap_route_map,
8904 show_bgp_ipv4_safi_damp_flap_route_map_cmd,
8905 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics route-map WORD",
Balaji3921cc52015-05-16 23:12:17 +05308906 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308907 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008908 IP_STR
8909 "Address Family Modifier\n"
8910 "Address Family Modifier\n"
8911 "Address Family Modifier\n"
8912 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308913 "Display detailed information about dampening\n"
8914 "Display flap statistics of routes\n"
8915 "Display routes matching the route-map\n"
8916 "A route-map to match on\n")
Lou Berger205e6742016-01-12 13:42:11 -05008917
Lou Berger651b4022016-01-12 13:42:07 -05008918DEFUN (show_bgp_ipv6_safi_flap_route_map,
8919 show_bgp_ipv6_safi_flap_route_map_cmd,
8920 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics route-map WORD",
paul718e3742002-12-13 20:15:29 +00008921 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05008922 BGP_STR
8923 IPV6_STR
8924 "Address Family Modifier\n"
8925 "Address Family Modifier\n"
8926 "Address Family Modifier\n"
8927 "Address Family Modifier\n"
8928 "Display flap statistics of routes\n"
8929 "Display routes matching the route-map\n"
8930 "A route-map to match on\n")
8931{
8932 safi_t safi;
8933 if (bgp_parse_safi(argv[0], &safi)) {
8934 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8935 return CMD_WARNING;
8936 }
8937 return bgp_show_route_map (vty, argv[1], AFI_IP6, safi,
8938 bgp_show_type_flap_route_map);
8939}
8940ALIAS (show_bgp_ipv6_safi_flap_route_map,
8941 show_bgp_ipv6_safi_damp_flap_route_map_cmd,
8942 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics route-map WORD",
8943 SHOW_STR
8944 BGP_STR
8945 IPV6_STR
8946 "Address Family Modifier\n"
8947 "Address Family Modifier\n"
8948 "Address Family Modifier\n"
8949 "Address Family Modifier\n"
8950 "Display detailed information about dampening\n"
8951 "Display flap statistics of routes\n"
8952 "Display routes matching the route-map\n"
8953 "A route-map to match on\n")
Lou Berger651b4022016-01-12 13:42:07 -05008954
8955DEFUN (show_bgp_ipv4_safi_route_map,
8956 show_bgp_ipv4_safi_route_map_cmd,
8957 "show bgp ipv4 (encap|multicast|unicast|vpn) route-map WORD",
8958 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008959 BGP_STR
8960 "Address family\n"
8961 "Address Family modifier\n"
8962 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05008963 "Address Family modifier\n"
8964 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008965 "Display routes matching the route-map\n"
8966 "A route-map to match on\n")
8967{
Lou Berger651b4022016-01-12 13:42:07 -05008968 safi_t safi;
8969 if (bgp_parse_safi(argv[0], &safi)) {
8970 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8971 return CMD_WARNING;
8972 }
8973 return bgp_show_route_map (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008974 bgp_show_type_route_map);
8975}
Lou Berger205e6742016-01-12 13:42:11 -05008976
Lou Berger651b4022016-01-12 13:42:07 -05008977DEFUN (show_bgp_ipv6_safi_route_map,
8978 show_bgp_ipv6_safi_route_map_cmd,
8979 "show bgp ipv6 (encap|multicast|unicast|vpn) route-map WORD",
paul718e3742002-12-13 20:15:29 +00008980 SHOW_STR
8981 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008982 "Address family\n"
8983 "Address Family modifier\n"
8984 "Address Family modifier\n"
8985 "Address Family modifier\n"
8986 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008987 "Display routes matching the route-map\n"
8988 "A route-map to match on\n")
8989{
Lou Berger651b4022016-01-12 13:42:07 -05008990 safi_t safi;
8991 if (bgp_parse_safi(argv[0], &safi)) {
8992 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8993 return CMD_WARNING;
8994 }
8995 return bgp_show_route_map (vty, argv[1], AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00008996 bgp_show_type_route_map);
8997}
8998
Lou Berger651b4022016-01-12 13:42:07 -05008999DEFUN (show_bgp_ipv6_route_map,
paul718e3742002-12-13 20:15:29 +00009000 show_bgp_ipv6_route_map_cmd,
9001 "show bgp ipv6 route-map WORD",
9002 SHOW_STR
9003 BGP_STR
9004 "Address family\n"
9005 "Display routes matching the route-map\n"
9006 "A route-map to match on\n")
Lou Berger651b4022016-01-12 13:42:07 -05009007{
9008 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9009 bgp_show_type_route_map);
9010}
David Lamparter6b0655a2014-06-04 06:53:35 +02009011
Lou Berger651b4022016-01-12 13:42:07 -05009012DEFUN (show_bgp_ipv4_cidr_only,
9013 show_bgp_ipv4_cidr_only_cmd,
9014 "show bgp ipv4 cidr-only",
paul718e3742002-12-13 20:15:29 +00009015 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009016 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009017 IP_STR
paul718e3742002-12-13 20:15:29 +00009018 "Display only routes with non-natural netmasks\n")
9019{
9020 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00009021 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009022}
9023
Lou Berger651b4022016-01-12 13:42:07 -05009024DEFUN (show_bgp_ipv4_safi_flap_cidr_only,
9025 show_bgp_ipv4_safi_flap_cidr_only_cmd,
9026 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics cidr-only",
paul718e3742002-12-13 20:15:29 +00009027 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009028 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009029 "Address Family\n"
9030 "Address Family Modifier\n"
9031 "Address Family Modifier\n"
9032 "Address Family Modifier\n"
9033 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00009034 "Display flap statistics of routes\n"
9035 "Display only routes with non-natural netmasks\n")
9036{
Lou Berger651b4022016-01-12 13:42:07 -05009037 safi_t safi;
9038
9039 if (bgp_parse_safi(argv[0], &safi)) {
9040 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9041 return CMD_WARNING;
9042 }
9043 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009044}
9045
Lou Berger651b4022016-01-12 13:42:07 -05009046ALIAS (show_bgp_ipv4_safi_flap_cidr_only,
9047 show_bgp_ipv4_safi_damp_flap_cidr_only_cmd,
9048 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics cidr-only",
Balaji3921cc52015-05-16 23:12:17 +05309049 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05309050 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009051 "Address Family\n"
9052 "Address Family Modifier\n"
9053 "Address Family Modifier\n"
9054 "Address Family Modifier\n"
9055 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05309056 "Display detailed information about dampening\n"
9057 "Display flap statistics of routes\n"
9058 "Display only routes with non-natural netmasks\n")
9059
Lou Berger651b4022016-01-12 13:42:07 -05009060DEFUN (show_bgp_ipv4_safi_cidr_only,
9061 show_bgp_ipv4_safi_cidr_only_cmd,
9062 "show bgp ipv4 (unicast|multicast) cidr-only",
paul718e3742002-12-13 20:15:29 +00009063 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009064 BGP_STR
9065 "Address family\n"
9066 "Address Family modifier\n"
9067 "Address Family modifier\n"
9068 "Display only routes with non-natural netmasks\n")
9069{
9070 if (strncmp (argv[0], "m", 1) == 0)
9071 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00009072 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009073
9074 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00009075 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009076}
David Lamparter6b0655a2014-06-04 06:53:35 +02009077
Lou Berger651b4022016-01-12 13:42:07 -05009078/* new046 */
9079DEFUN (show_bgp_afi_safi_community_all,
9080 show_bgp_afi_safi_community_all_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009081 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) community",
paul718e3742002-12-13 20:15:29 +00009082 SHOW_STR
9083 BGP_STR
9084 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009085 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009086 "Address Family modifier\n"
9087 "Address Family modifier\n"
9088 "Address Family modifier\n"
9089 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009090 "Display routes matching the communities\n")
Lou Berger651b4022016-01-12 13:42:07 -05009091{
9092 safi_t safi;
9093 afi_t afi;
paul718e3742002-12-13 20:15:29 +00009094
Lou Berger651b4022016-01-12 13:42:07 -05009095 if (bgp_parse_afi(argv[0], &afi)) {
9096 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
9097 return CMD_WARNING;
9098 }
9099 if (bgp_parse_safi(argv[1], &safi)) {
9100 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
9101 return CMD_WARNING;
9102 }
9103
9104 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_all, NULL);
9105}
9106DEFUN (show_bgp_afi_community_all,
9107 show_bgp_afi_community_all_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009108 "show bgp (ipv4|ipv6) community",
paul718e3742002-12-13 20:15:29 +00009109 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009110 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009111 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009112 "Address family\n"
paul718e3742002-12-13 20:15:29 +00009113 "Display routes matching the communities\n")
9114{
Lou Berger651b4022016-01-12 13:42:07 -05009115 afi_t afi;
9116 safi_t safi = SAFI_UNICAST;
paul718e3742002-12-13 20:15:29 +00009117
Lou Berger651b4022016-01-12 13:42:07 -05009118 if (bgp_parse_afi(argv[0], &afi)) {
9119 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
9120 return CMD_WARNING;
9121 }
9122 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00009123}
David Lamparter6b0655a2014-06-04 06:53:35 +02009124
paul94f2b392005-06-28 12:44:16 +00009125static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04009126bgp_show_community (struct vty *vty, const char *view_name, int argc,
9127 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00009128{
9129 struct community *com;
9130 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04009131 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00009132 int i;
9133 char *str;
9134 int first = 0;
9135
Michael Lambert95cbbd22010-07-23 14:43:04 -04009136 /* BGP structure lookup */
9137 if (view_name)
9138 {
9139 bgp = bgp_lookup_by_name (view_name);
9140 if (bgp == NULL)
9141 {
9142 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9143 return CMD_WARNING;
9144 }
9145 }
9146 else
9147 {
9148 bgp = bgp_get_default ();
9149 if (bgp == NULL)
9150 {
9151 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9152 return CMD_WARNING;
9153 }
9154 }
9155
paul718e3742002-12-13 20:15:29 +00009156 b = buffer_new (1024);
9157 for (i = 0; i < argc; i++)
9158 {
9159 if (first)
9160 buffer_putc (b, ' ');
9161 else
9162 {
9163 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9164 continue;
9165 first = 1;
9166 }
9167
9168 buffer_putstr (b, argv[i]);
9169 }
9170 buffer_putc (b, '\0');
9171
9172 str = buffer_getstr (b);
9173 buffer_free (b);
9174
9175 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00009176 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00009177 if (! com)
9178 {
9179 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
9180 return CMD_WARNING;
9181 }
9182
Michael Lambert95cbbd22010-07-23 14:43:04 -04009183 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00009184 (exact ? bgp_show_type_community_exact :
9185 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00009186}
9187
Lou Bergerf9b6c392016-01-12 13:42:09 -05009188DEFUN (show_ip_bgp_community,
9189 show_ip_bgp_community_cmd,
9190 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
9191 SHOW_STR
9192 IP_STR
9193 BGP_STR
9194 "Display routes matching the communities\n"
9195 "community number\n"
9196 "Do not send outside local AS (well-known community)\n"
9197 "Do not advertise to any peer (well-known community)\n"
9198 "Do not export to next AS (well-known community)\n")
9199{
9200 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9201}
9202
9203ALIAS (show_ip_bgp_community,
9204 show_ip_bgp_community2_cmd,
9205 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9206 SHOW_STR
9207 IP_STR
9208 BGP_STR
9209 "Display routes matching the communities\n"
9210 "community number\n"
9211 "Do not send outside local AS (well-known community)\n"
9212 "Do not advertise to any peer (well-known community)\n"
9213 "Do not export to next AS (well-known community)\n"
9214 "community number\n"
9215 "Do not send outside local AS (well-known community)\n"
9216 "Do not advertise to any peer (well-known community)\n"
9217 "Do not export to next AS (well-known community)\n")
9218
9219ALIAS (show_ip_bgp_community,
9220 show_ip_bgp_community3_cmd,
9221 "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)",
9222 SHOW_STR
9223 IP_STR
9224 BGP_STR
9225 "Display routes matching the communities\n"
9226 "community number\n"
9227 "Do not send outside local AS (well-known community)\n"
9228 "Do not advertise to any peer (well-known community)\n"
9229 "Do not export to next AS (well-known community)\n"
9230 "community number\n"
9231 "Do not send outside local AS (well-known community)\n"
9232 "Do not advertise to any peer (well-known community)\n"
9233 "Do not export to next AS (well-known community)\n"
9234 "community number\n"
9235 "Do not send outside local AS (well-known community)\n"
9236 "Do not advertise to any peer (well-known community)\n"
9237 "Do not export to next AS (well-known community)\n")
9238
9239ALIAS (show_ip_bgp_community,
9240 show_ip_bgp_community4_cmd,
9241 "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)",
9242 SHOW_STR
9243 IP_STR
9244 BGP_STR
9245 "Display routes matching the communities\n"
9246 "community number\n"
9247 "Do not send outside local AS (well-known community)\n"
9248 "Do not advertise to any peer (well-known community)\n"
9249 "Do not export to next AS (well-known community)\n"
9250 "community number\n"
9251 "Do not send outside local AS (well-known community)\n"
9252 "Do not advertise to any peer (well-known community)\n"
9253 "Do not export to next AS (well-known community)\n"
9254 "community number\n"
9255 "Do not send outside local AS (well-known community)\n"
9256 "Do not advertise to any peer (well-known community)\n"
9257 "Do not export to next AS (well-known community)\n"
9258 "community number\n"
9259 "Do not send outside local AS (well-known community)\n"
9260 "Do not advertise to any peer (well-known community)\n"
9261 "Do not export to next AS (well-known community)\n")
9262
9263DEFUN (show_ip_bgp_ipv4_community,
9264 show_ip_bgp_ipv4_community_cmd,
9265 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9266 SHOW_STR
9267 IP_STR
9268 BGP_STR
9269 "Address family\n"
9270 "Address Family modifier\n"
9271 "Address Family modifier\n"
9272 "Display routes matching the communities\n"
9273 "community number\n"
9274 "Do not send outside local AS (well-known community)\n"
9275 "Do not advertise to any peer (well-known community)\n"
9276 "Do not export to next AS (well-known community)\n")
9277{
9278 if (strncmp (argv[0], "m", 1) == 0)
9279 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
9280
9281 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9282}
9283
9284ALIAS (show_ip_bgp_ipv4_community,
9285 show_ip_bgp_ipv4_community2_cmd,
9286 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9287 SHOW_STR
9288 IP_STR
9289 BGP_STR
9290 "Address family\n"
9291 "Address Family modifier\n"
9292 "Address Family modifier\n"
9293 "Display routes matching the communities\n"
9294 "community number\n"
9295 "Do not send outside local AS (well-known community)\n"
9296 "Do not advertise to any peer (well-known community)\n"
9297 "Do not export to next AS (well-known community)\n"
9298 "community number\n"
9299 "Do not send outside local AS (well-known community)\n"
9300 "Do not advertise to any peer (well-known community)\n"
9301 "Do not export to next AS (well-known community)\n")
9302
9303ALIAS (show_ip_bgp_ipv4_community,
9304 show_ip_bgp_ipv4_community3_cmd,
9305 "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)",
9306 SHOW_STR
9307 IP_STR
9308 BGP_STR
9309 "Address family\n"
9310 "Address Family modifier\n"
9311 "Address Family modifier\n"
9312 "Display routes matching the communities\n"
9313 "community number\n"
9314 "Do not send outside local AS (well-known community)\n"
9315 "Do not advertise to any peer (well-known community)\n"
9316 "Do not export to next AS (well-known community)\n"
9317 "community number\n"
9318 "Do not send outside local AS (well-known community)\n"
9319 "Do not advertise to any peer (well-known community)\n"
9320 "Do not export to next AS (well-known community)\n"
9321 "community number\n"
9322 "Do not send outside local AS (well-known community)\n"
9323 "Do not advertise to any peer (well-known community)\n"
9324 "Do not export to next AS (well-known community)\n")
9325
9326ALIAS (show_ip_bgp_ipv4_community,
9327 show_ip_bgp_ipv4_community4_cmd,
9328 "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)",
9329 SHOW_STR
9330 IP_STR
9331 BGP_STR
9332 "Address family\n"
9333 "Address Family modifier\n"
9334 "Address Family modifier\n"
9335 "Display routes matching the communities\n"
9336 "community number\n"
9337 "Do not send outside local AS (well-known community)\n"
9338 "Do not advertise to any peer (well-known community)\n"
9339 "Do not export to next AS (well-known community)\n"
9340 "community number\n"
9341 "Do not send outside local AS (well-known community)\n"
9342 "Do not advertise to any peer (well-known community)\n"
9343 "Do not export to next AS (well-known community)\n"
9344 "community number\n"
9345 "Do not send outside local AS (well-known community)\n"
9346 "Do not advertise to any peer (well-known community)\n"
9347 "Do not export to next AS (well-known community)\n"
9348 "community number\n"
9349 "Do not send outside local AS (well-known community)\n"
9350 "Do not advertise to any peer (well-known community)\n"
9351 "Do not export to next AS (well-known community)\n")
9352
9353DEFUN (show_ip_bgp_community_exact,
9354 show_ip_bgp_community_exact_cmd,
9355 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9356 SHOW_STR
9357 IP_STR
9358 BGP_STR
9359 "Display routes matching the communities\n"
9360 "community number\n"
9361 "Do not send outside local AS (well-known community)\n"
9362 "Do not advertise to any peer (well-known community)\n"
9363 "Do not export to next AS (well-known community)\n"
9364 "Exact match of the communities")
9365{
9366 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9367}
9368
9369ALIAS (show_ip_bgp_community_exact,
9370 show_ip_bgp_community2_exact_cmd,
9371 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9372 SHOW_STR
9373 IP_STR
9374 BGP_STR
9375 "Display routes matching the communities\n"
9376 "community number\n"
9377 "Do not send outside local AS (well-known community)\n"
9378 "Do not advertise to any peer (well-known community)\n"
9379 "Do not export to next AS (well-known community)\n"
9380 "community number\n"
9381 "Do not send outside local AS (well-known community)\n"
9382 "Do not advertise to any peer (well-known community)\n"
9383 "Do not export to next AS (well-known community)\n"
9384 "Exact match of the communities")
9385
9386ALIAS (show_ip_bgp_community_exact,
9387 show_ip_bgp_community3_exact_cmd,
9388 "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",
9389 SHOW_STR
9390 IP_STR
9391 BGP_STR
9392 "Display routes matching the communities\n"
9393 "community number\n"
9394 "Do not send outside local AS (well-known community)\n"
9395 "Do not advertise to any peer (well-known community)\n"
9396 "Do not export to next AS (well-known community)\n"
9397 "community number\n"
9398 "Do not send outside local AS (well-known community)\n"
9399 "Do not advertise to any peer (well-known community)\n"
9400 "Do not export to next AS (well-known community)\n"
9401 "community number\n"
9402 "Do not send outside local AS (well-known community)\n"
9403 "Do not advertise to any peer (well-known community)\n"
9404 "Do not export to next AS (well-known community)\n"
9405 "Exact match of the communities")
9406
9407ALIAS (show_ip_bgp_community_exact,
9408 show_ip_bgp_community4_exact_cmd,
9409 "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",
9410 SHOW_STR
9411 IP_STR
9412 BGP_STR
9413 "Display routes matching the communities\n"
9414 "community number\n"
9415 "Do not send outside local AS (well-known community)\n"
9416 "Do not advertise to any peer (well-known community)\n"
9417 "Do not export to next AS (well-known community)\n"
9418 "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 "community number\n"
9423 "Do not send outside local AS (well-known community)\n"
9424 "Do not advertise to any peer (well-known community)\n"
9425 "Do not export to next AS (well-known community)\n"
9426 "community number\n"
9427 "Do not send outside local AS (well-known community)\n"
9428 "Do not advertise to any peer (well-known community)\n"
9429 "Do not export to next AS (well-known community)\n"
9430 "Exact match of the communities")
9431
9432DEFUN (show_ip_bgp_ipv4_community_exact,
9433 show_ip_bgp_ipv4_community_exact_cmd,
9434 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9435 SHOW_STR
9436 IP_STR
9437 BGP_STR
9438 "Address family\n"
9439 "Address Family modifier\n"
9440 "Address Family modifier\n"
9441 "Display routes matching the communities\n"
9442 "community number\n"
9443 "Do not send outside local AS (well-known community)\n"
9444 "Do not advertise to any peer (well-known community)\n"
9445 "Do not export to next AS (well-known community)\n"
9446 "Exact match of the communities")
9447{
9448 if (strncmp (argv[0], "m", 1) == 0)
9449 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
9450
9451 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9452}
9453
9454ALIAS (show_ip_bgp_ipv4_community_exact,
9455 show_ip_bgp_ipv4_community2_exact_cmd,
9456 "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",
9457 SHOW_STR
9458 IP_STR
9459 BGP_STR
9460 "Address family\n"
9461 "Address Family modifier\n"
9462 "Address Family modifier\n"
9463 "Display routes matching the communities\n"
9464 "community number\n"
9465 "Do not send outside local AS (well-known community)\n"
9466 "Do not advertise to any peer (well-known community)\n"
9467 "Do not export to next AS (well-known community)\n"
9468 "community number\n"
9469 "Do not send outside local AS (well-known community)\n"
9470 "Do not advertise to any peer (well-known community)\n"
9471 "Do not export to next AS (well-known community)\n"
9472 "Exact match of the communities")
9473
9474ALIAS (show_ip_bgp_ipv4_community_exact,
9475 show_ip_bgp_ipv4_community3_exact_cmd,
9476 "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",
9477 SHOW_STR
9478 IP_STR
9479 BGP_STR
9480 "Address family\n"
9481 "Address Family modifier\n"
9482 "Address Family modifier\n"
9483 "Display routes matching the communities\n"
9484 "community number\n"
9485 "Do not send outside local AS (well-known community)\n"
9486 "Do not advertise to any peer (well-known community)\n"
9487 "Do not export to next AS (well-known community)\n"
9488 "community number\n"
9489 "Do not send outside local AS (well-known community)\n"
9490 "Do not advertise to any peer (well-known community)\n"
9491 "Do not export to next AS (well-known community)\n"
9492 "community number\n"
9493 "Do not send outside local AS (well-known community)\n"
9494 "Do not advertise to any peer (well-known community)\n"
9495 "Do not export to next AS (well-known community)\n"
9496 "Exact match of the communities")
9497
9498ALIAS (show_ip_bgp_ipv4_community_exact,
9499 show_ip_bgp_ipv4_community4_exact_cmd,
9500 "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",
9501 SHOW_STR
9502 IP_STR
9503 BGP_STR
9504 "Address family\n"
9505 "Address Family modifier\n"
9506 "Address Family modifier\n"
9507 "Display routes matching the communities\n"
9508 "community number\n"
9509 "Do not send outside local AS (well-known community)\n"
9510 "Do not advertise to any peer (well-known community)\n"
9511 "Do not export to next AS (well-known community)\n"
9512 "community number\n"
9513 "Do not send outside local AS (well-known community)\n"
9514 "Do not advertise to any peer (well-known community)\n"
9515 "Do not export to next AS (well-known community)\n"
9516 "community number\n"
9517 "Do not send outside local AS (well-known community)\n"
9518 "Do not advertise to any peer (well-known community)\n"
9519 "Do not export to next AS (well-known community)\n"
9520 "community number\n"
9521 "Do not send outside local AS (well-known community)\n"
9522 "Do not advertise to any peer (well-known community)\n"
9523 "Do not export to next AS (well-known community)\n"
9524 "Exact match of the communities")
9525
Lou Bergerf9b6c392016-01-12 13:42:09 -05009526DEFUN (show_bgp_community,
9527 show_bgp_community_cmd,
9528 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
9529 SHOW_STR
9530 BGP_STR
9531 "Display routes matching the communities\n"
9532 "community number\n"
9533 "Do not send outside local AS (well-known community)\n"
9534 "Do not advertise to any peer (well-known community)\n"
9535 "Do not export to next AS (well-known community)\n")
9536{
9537 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9538}
9539
9540ALIAS (show_bgp_community,
9541 show_bgp_ipv6_community_cmd,
9542 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
9543 SHOW_STR
9544 BGP_STR
9545 "Address family\n"
9546 "Display routes matching the communities\n"
9547 "community number\n"
9548 "Do not send outside local AS (well-known community)\n"
9549 "Do not advertise to any peer (well-known community)\n"
9550 "Do not export to next AS (well-known community)\n")
9551
9552ALIAS (show_bgp_community,
9553 show_bgp_community2_cmd,
9554 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9555 SHOW_STR
9556 BGP_STR
9557 "Display routes matching the communities\n"
9558 "community number\n"
9559 "Do not send outside local AS (well-known community)\n"
9560 "Do not advertise to any peer (well-known community)\n"
9561 "Do not export to next AS (well-known community)\n"
9562 "community number\n"
9563 "Do not send outside local AS (well-known community)\n"
9564 "Do not advertise to any peer (well-known community)\n"
9565 "Do not export to next AS (well-known community)\n")
9566
9567ALIAS (show_bgp_community,
9568 show_bgp_ipv6_community2_cmd,
9569 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9570 SHOW_STR
9571 BGP_STR
9572 "Address family\n"
9573 "Display routes matching the communities\n"
9574 "community number\n"
9575 "Do not send outside local AS (well-known community)\n"
9576 "Do not advertise to any peer (well-known community)\n"
9577 "Do not export to next AS (well-known community)\n"
9578 "community number\n"
9579 "Do not send outside local AS (well-known community)\n"
9580 "Do not advertise to any peer (well-known community)\n"
9581 "Do not export to next AS (well-known community)\n")
9582
9583ALIAS (show_bgp_community,
9584 show_bgp_community3_cmd,
9585 "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)",
9586 SHOW_STR
9587 BGP_STR
9588 "Display routes matching the communities\n"
9589 "community number\n"
9590 "Do not send outside local AS (well-known community)\n"
9591 "Do not advertise to any peer (well-known community)\n"
9592 "Do not export to next AS (well-known community)\n"
9593 "community number\n"
9594 "Do not send outside local AS (well-known community)\n"
9595 "Do not advertise to any peer (well-known community)\n"
9596 "Do not export to next AS (well-known community)\n"
9597 "community number\n"
9598 "Do not send outside local AS (well-known community)\n"
9599 "Do not advertise to any peer (well-known community)\n"
9600 "Do not export to next AS (well-known community)\n")
9601
9602ALIAS (show_bgp_community,
9603 show_bgp_ipv6_community3_cmd,
9604 "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)",
9605 SHOW_STR
9606 BGP_STR
9607 "Address family\n"
9608 "Display routes matching the communities\n"
9609 "community number\n"
9610 "Do not send outside local AS (well-known community)\n"
9611 "Do not advertise to any peer (well-known community)\n"
9612 "Do not export to next AS (well-known community)\n"
9613 "community number\n"
9614 "Do not send outside local AS (well-known community)\n"
9615 "Do not advertise to any peer (well-known community)\n"
9616 "Do not export to next AS (well-known community)\n"
9617 "community number\n"
9618 "Do not send outside local AS (well-known community)\n"
9619 "Do not advertise to any peer (well-known community)\n"
9620 "Do not export to next AS (well-known community)\n")
9621
9622ALIAS (show_bgp_community,
9623 show_bgp_community4_cmd,
9624 "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)",
9625 SHOW_STR
9626 BGP_STR
9627 "Display routes matching the communities\n"
9628 "community number\n"
9629 "Do not send outside local AS (well-known community)\n"
9630 "Do not advertise to any peer (well-known community)\n"
9631 "Do not export to next AS (well-known community)\n"
9632 "community number\n"
9633 "Do not send outside local AS (well-known community)\n"
9634 "Do not advertise to any peer (well-known community)\n"
9635 "Do not export to next AS (well-known community)\n"
9636 "community number\n"
9637 "Do not send outside local AS (well-known community)\n"
9638 "Do not advertise to any peer (well-known community)\n"
9639 "Do not export to next AS (well-known community)\n"
9640 "community number\n"
9641 "Do not send outside local AS (well-known community)\n"
9642 "Do not advertise to any peer (well-known community)\n"
9643 "Do not export to next AS (well-known community)\n")
9644
9645ALIAS (show_bgp_community,
9646 show_bgp_ipv6_community4_cmd,
9647 "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)",
9648 SHOW_STR
9649 BGP_STR
9650 "Address family\n"
9651 "Display routes matching the communities\n"
9652 "community number\n"
9653 "Do not send outside local AS (well-known community)\n"
9654 "Do not advertise to any peer (well-known community)\n"
9655 "Do not export to next AS (well-known community)\n"
9656 "community number\n"
9657 "Do not send outside local AS (well-known community)\n"
9658 "Do not advertise to any peer (well-known community)\n"
9659 "Do not export to next AS (well-known community)\n"
9660 "community number\n"
9661 "Do not send outside local AS (well-known community)\n"
9662 "Do not advertise to any peer (well-known community)\n"
9663 "Do not export to next AS (well-known community)\n"
9664 "community number\n"
9665 "Do not send outside local AS (well-known community)\n"
9666 "Do not advertise to any peer (well-known community)\n"
9667 "Do not export to next AS (well-known community)\n")
9668
9669/* old command */
9670DEFUN (show_ipv6_bgp_community,
9671 show_ipv6_bgp_community_cmd,
9672 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
9673 SHOW_STR
9674 IPV6_STR
9675 BGP_STR
9676 "Display routes matching the communities\n"
9677 "community number\n"
9678 "Do not send outside local AS (well-known community)\n"
9679 "Do not advertise to any peer (well-known community)\n"
9680 "Do not export to next AS (well-known community)\n")
9681{
9682 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9683}
9684
9685/* old command */
9686ALIAS (show_ipv6_bgp_community,
9687 show_ipv6_bgp_community2_cmd,
9688 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9689 SHOW_STR
9690 IPV6_STR
9691 BGP_STR
9692 "Display routes matching the communities\n"
9693 "community number\n"
9694 "Do not send outside local AS (well-known community)\n"
9695 "Do not advertise to any peer (well-known community)\n"
9696 "Do not export to next AS (well-known community)\n"
9697 "community number\n"
9698 "Do not send outside local AS (well-known community)\n"
9699 "Do not advertise to any peer (well-known community)\n"
9700 "Do not export to next AS (well-known community)\n")
9701
9702/* old command */
9703ALIAS (show_ipv6_bgp_community,
9704 show_ipv6_bgp_community3_cmd,
9705 "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)",
9706 SHOW_STR
9707 IPV6_STR
9708 BGP_STR
9709 "Display routes matching the communities\n"
9710 "community number\n"
9711 "Do not send outside local AS (well-known community)\n"
9712 "Do not advertise to any peer (well-known community)\n"
9713 "Do not export to next AS (well-known community)\n"
9714 "community number\n"
9715 "Do not send outside local AS (well-known community)\n"
9716 "Do not advertise to any peer (well-known community)\n"
9717 "Do not export to next AS (well-known community)\n"
9718 "community number\n"
9719 "Do not send outside local AS (well-known community)\n"
9720 "Do not advertise to any peer (well-known community)\n"
9721 "Do not export to next AS (well-known community)\n")
9722
9723/* old command */
9724ALIAS (show_ipv6_bgp_community,
9725 show_ipv6_bgp_community4_cmd,
9726 "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)",
9727 SHOW_STR
9728 IPV6_STR
9729 BGP_STR
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
9748DEFUN (show_bgp_community_exact,
9749 show_bgp_community_exact_cmd,
9750 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9751 SHOW_STR
9752 BGP_STR
9753 "Display routes matching the communities\n"
9754 "community number\n"
9755 "Do not send outside local AS (well-known community)\n"
9756 "Do not advertise to any peer (well-known community)\n"
9757 "Do not export to next AS (well-known community)\n"
9758 "Exact match of the communities")
9759{
9760 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
9761}
9762
9763ALIAS (show_bgp_community_exact,
9764 show_bgp_ipv6_community_exact_cmd,
9765 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
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 "Exact match of the communities")
9775
9776ALIAS (show_bgp_community_exact,
9777 show_bgp_community2_exact_cmd,
9778 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9779 SHOW_STR
9780 BGP_STR
9781 "Display routes matching the communities\n"
9782 "community number\n"
9783 "Do not send outside local AS (well-known community)\n"
9784 "Do not advertise to any peer (well-known community)\n"
9785 "Do not export to next AS (well-known community)\n"
9786 "community number\n"
9787 "Do not send outside local AS (well-known community)\n"
9788 "Do not advertise to any peer (well-known community)\n"
9789 "Do not export to next AS (well-known community)\n"
9790 "Exact match of the communities")
9791
9792ALIAS (show_bgp_community_exact,
9793 show_bgp_ipv6_community2_exact_cmd,
9794 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9795 SHOW_STR
9796 BGP_STR
9797 "Address family\n"
9798 "Display routes matching the communities\n"
9799 "community number\n"
9800 "Do not send outside local AS (well-known community)\n"
9801 "Do not advertise to any peer (well-known community)\n"
9802 "Do not export to next AS (well-known community)\n"
9803 "community number\n"
9804 "Do not send outside local AS (well-known community)\n"
9805 "Do not advertise to any peer (well-known community)\n"
9806 "Do not export to next AS (well-known community)\n"
9807 "Exact match of the communities")
9808
9809ALIAS (show_bgp_community_exact,
9810 show_bgp_community3_exact_cmd,
9811 "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",
9812 SHOW_STR
9813 BGP_STR
9814 "Display routes matching the communities\n"
9815 "community number\n"
9816 "Do not send outside local AS (well-known community)\n"
9817 "Do not advertise to any peer (well-known community)\n"
9818 "Do not export to next AS (well-known community)\n"
9819 "community number\n"
9820 "Do not send outside local AS (well-known community)\n"
9821 "Do not advertise to any peer (well-known community)\n"
9822 "Do not export to next AS (well-known community)\n"
9823 "community number\n"
9824 "Do not send outside local AS (well-known community)\n"
9825 "Do not advertise to any peer (well-known community)\n"
9826 "Do not export to next AS (well-known community)\n"
9827 "Exact match of the communities")
9828
9829ALIAS (show_bgp_community_exact,
9830 show_bgp_ipv6_community3_exact_cmd,
9831 "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",
9832 SHOW_STR
9833 BGP_STR
9834 "Address family\n"
9835 "Display routes matching the communities\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 "community number\n"
9845 "Do not send outside local AS (well-known community)\n"
9846 "Do not advertise to any peer (well-known community)\n"
9847 "Do not export to next AS (well-known community)\n"
9848 "Exact match of the communities")
9849
9850ALIAS (show_bgp_community_exact,
9851 show_bgp_community4_exact_cmd,
9852 "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",
9853 SHOW_STR
9854 BGP_STR
9855 "Display routes matching the communities\n"
9856 "community number\n"
9857 "Do not send outside local AS (well-known community)\n"
9858 "Do not advertise to any peer (well-known community)\n"
9859 "Do not export to next AS (well-known community)\n"
9860 "community number\n"
9861 "Do not send outside local AS (well-known community)\n"
9862 "Do not advertise to any peer (well-known community)\n"
9863 "Do not export to next AS (well-known community)\n"
9864 "community number\n"
9865 "Do not send outside local AS (well-known community)\n"
9866 "Do not advertise to any peer (well-known community)\n"
9867 "Do not export to next AS (well-known community)\n"
9868 "community number\n"
9869 "Do not send outside local AS (well-known community)\n"
9870 "Do not advertise to any peer (well-known community)\n"
9871 "Do not export to next AS (well-known community)\n"
9872 "Exact match of the communities")
9873
9874ALIAS (show_bgp_community_exact,
9875 show_bgp_ipv6_community4_exact_cmd,
9876 "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",
9877 SHOW_STR
9878 BGP_STR
9879 "Address family\n"
9880 "Display routes matching the communities\n"
9881 "community number\n"
9882 "Do not send outside local AS (well-known community)\n"
9883 "Do not advertise to any peer (well-known community)\n"
9884 "Do not export to next AS (well-known community)\n"
9885 "community number\n"
9886 "Do not send outside local AS (well-known community)\n"
9887 "Do not advertise to any peer (well-known community)\n"
9888 "Do not export to next AS (well-known community)\n"
9889 "community number\n"
9890 "Do not send outside local AS (well-known community)\n"
9891 "Do not advertise to any peer (well-known community)\n"
9892 "Do not export to next AS (well-known community)\n"
9893 "community number\n"
9894 "Do not send outside local AS (well-known community)\n"
9895 "Do not advertise to any peer (well-known community)\n"
9896 "Do not export to next AS (well-known community)\n"
9897 "Exact match of the communities")
9898
9899/* old command */
9900DEFUN (show_ipv6_bgp_community_exact,
9901 show_ipv6_bgp_community_exact_cmd,
9902 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9903 SHOW_STR
9904 IPV6_STR
9905 BGP_STR
9906 "Display routes matching the communities\n"
9907 "community number\n"
9908 "Do not send outside local AS (well-known community)\n"
9909 "Do not advertise to any peer (well-known community)\n"
9910 "Do not export to next AS (well-known community)\n"
9911 "Exact match of the communities")
9912{
9913 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
9914}
9915
9916/* old command */
9917ALIAS (show_ipv6_bgp_community_exact,
9918 show_ipv6_bgp_community2_exact_cmd,
9919 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9920 SHOW_STR
9921 IPV6_STR
9922 BGP_STR
9923 "Display routes matching the communities\n"
9924 "community number\n"
9925 "Do not send outside local AS (well-known community)\n"
9926 "Do not advertise to any peer (well-known community)\n"
9927 "Do not export to next AS (well-known community)\n"
9928 "community number\n"
9929 "Do not send outside local AS (well-known community)\n"
9930 "Do not advertise to any peer (well-known community)\n"
9931 "Do not export to next AS (well-known community)\n"
9932 "Exact match of the communities")
9933
9934/* old command */
9935ALIAS (show_ipv6_bgp_community_exact,
9936 show_ipv6_bgp_community3_exact_cmd,
9937 "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",
9938 SHOW_STR
9939 IPV6_STR
9940 BGP_STR
9941 "Display routes matching the communities\n"
9942 "community number\n"
9943 "Do not send outside local AS (well-known community)\n"
9944 "Do not advertise to any peer (well-known community)\n"
9945 "Do not export to next AS (well-known community)\n"
9946 "community number\n"
9947 "Do not send outside local AS (well-known community)\n"
9948 "Do not advertise to any peer (well-known community)\n"
9949 "Do not export to next AS (well-known community)\n"
9950 "community number\n"
9951 "Do not send outside local AS (well-known community)\n"
9952 "Do not advertise to any peer (well-known community)\n"
9953 "Do not export to next AS (well-known community)\n"
9954 "Exact match of the communities")
9955
9956/* old command */
9957ALIAS (show_ipv6_bgp_community_exact,
9958 show_ipv6_bgp_community4_exact_cmd,
9959 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9960 SHOW_STR
9961 IPV6_STR
9962 BGP_STR
9963 "Display routes matching the communities\n"
9964 "community number\n"
9965 "Do not send outside local AS (well-known community)\n"
9966 "Do not advertise to any peer (well-known community)\n"
9967 "Do not export to next AS (well-known community)\n"
9968 "community number\n"
9969 "Do not send outside local AS (well-known community)\n"
9970 "Do not advertise to any peer (well-known community)\n"
9971 "Do not export to next AS (well-known community)\n"
9972 "community number\n"
9973 "Do not send outside local AS (well-known community)\n"
9974 "Do not advertise to any peer (well-known community)\n"
9975 "Do not export to next AS (well-known community)\n"
9976 "community number\n"
9977 "Do not send outside local AS (well-known community)\n"
9978 "Do not advertise to any peer (well-known community)\n"
9979 "Do not export to next AS (well-known community)\n"
9980 "Exact match of the communities")
9981
9982/* old command */
9983DEFUN (show_ipv6_mbgp_community,
9984 show_ipv6_mbgp_community_cmd,
9985 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
9986 SHOW_STR
9987 IPV6_STR
9988 MBGP_STR
9989 "Display routes matching the communities\n"
9990 "community number\n"
9991 "Do not send outside local AS (well-known community)\n"
9992 "Do not advertise to any peer (well-known community)\n"
9993 "Do not export to next AS (well-known community)\n")
9994{
9995 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
9996}
9997
9998/* old command */
9999ALIAS (show_ipv6_mbgp_community,
10000 show_ipv6_mbgp_community2_cmd,
10001 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10002 SHOW_STR
10003 IPV6_STR
10004 MBGP_STR
10005 "Display routes matching the communities\n"
10006 "community number\n"
10007 "Do not send outside local AS (well-known community)\n"
10008 "Do not advertise to any peer (well-known community)\n"
10009 "Do not export to next AS (well-known community)\n"
10010 "community number\n"
10011 "Do not send outside local AS (well-known community)\n"
10012 "Do not advertise to any peer (well-known community)\n"
10013 "Do not export to next AS (well-known community)\n")
10014
10015/* old command */
10016ALIAS (show_ipv6_mbgp_community,
10017 show_ipv6_mbgp_community3_cmd,
10018 "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)",
10019 SHOW_STR
10020 IPV6_STR
10021 MBGP_STR
10022 "Display routes matching the communities\n"
10023 "community number\n"
10024 "Do not send outside local AS (well-known community)\n"
10025 "Do not advertise to any peer (well-known community)\n"
10026 "Do not export to next AS (well-known community)\n"
10027 "community number\n"
10028 "Do not send outside local AS (well-known community)\n"
10029 "Do not advertise to any peer (well-known community)\n"
10030 "Do not export to next AS (well-known community)\n"
10031 "community number\n"
10032 "Do not send outside local AS (well-known community)\n"
10033 "Do not advertise to any peer (well-known community)\n"
10034 "Do not export to next AS (well-known community)\n")
10035
10036/* old command */
10037ALIAS (show_ipv6_mbgp_community,
10038 show_ipv6_mbgp_community4_cmd,
10039 "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)",
10040 SHOW_STR
10041 IPV6_STR
10042 MBGP_STR
10043 "Display routes matching the communities\n"
10044 "community number\n"
10045 "Do not send outside local AS (well-known community)\n"
10046 "Do not advertise to any peer (well-known community)\n"
10047 "Do not export to next AS (well-known community)\n"
10048 "community number\n"
10049 "Do not send outside local AS (well-known community)\n"
10050 "Do not advertise to any peer (well-known community)\n"
10051 "Do not export to next AS (well-known community)\n"
10052 "community number\n"
10053 "Do not send outside local AS (well-known community)\n"
10054 "Do not advertise to any peer (well-known community)\n"
10055 "Do not export to next AS (well-known community)\n"
10056 "community number\n"
10057 "Do not send outside local AS (well-known community)\n"
10058 "Do not advertise to any peer (well-known community)\n"
10059 "Do not export to next AS (well-known community)\n")
10060
10061/* old command */
10062DEFUN (show_ipv6_mbgp_community_exact,
10063 show_ipv6_mbgp_community_exact_cmd,
10064 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10065 SHOW_STR
10066 IPV6_STR
10067 MBGP_STR
10068 "Display routes matching the communities\n"
10069 "community number\n"
10070 "Do not send outside local AS (well-known community)\n"
10071 "Do not advertise to any peer (well-known community)\n"
10072 "Do not export to next AS (well-known community)\n"
10073 "Exact match of the communities")
10074{
10075 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
10076}
10077
10078/* old command */
10079ALIAS (show_ipv6_mbgp_community_exact,
10080 show_ipv6_mbgp_community2_exact_cmd,
10081 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10082 SHOW_STR
10083 IPV6_STR
10084 MBGP_STR
10085 "Display routes matching the communities\n"
10086 "community number\n"
10087 "Do not send outside local AS (well-known community)\n"
10088 "Do not advertise to any peer (well-known community)\n"
10089 "Do not export to next AS (well-known community)\n"
10090 "community number\n"
10091 "Do not send outside local AS (well-known community)\n"
10092 "Do not advertise to any peer (well-known community)\n"
10093 "Do not export to next AS (well-known community)\n"
10094 "Exact match of the communities")
10095
10096/* old command */
10097ALIAS (show_ipv6_mbgp_community_exact,
10098 show_ipv6_mbgp_community3_exact_cmd,
10099 "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",
10100 SHOW_STR
10101 IPV6_STR
10102 MBGP_STR
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 "Exact match of the communities")
10117
10118/* old command */
10119ALIAS (show_ipv6_mbgp_community_exact,
10120 show_ipv6_mbgp_community4_exact_cmd,
10121 "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",
10122 SHOW_STR
10123 IPV6_STR
10124 MBGP_STR
10125 "Display routes matching the communities\n"
10126 "community number\n"
10127 "Do not send outside local AS (well-known community)\n"
10128 "Do not advertise to any peer (well-known community)\n"
10129 "Do not export to next AS (well-known community)\n"
10130 "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 "community number\n"
10135 "Do not send outside local AS (well-known community)\n"
10136 "Do not advertise to any peer (well-known community)\n"
10137 "Do not export to next AS (well-known community)\n"
10138 "community number\n"
10139 "Do not send outside local AS (well-known community)\n"
10140 "Do not advertise to any peer (well-known community)\n"
10141 "Do not export to next AS (well-known community)\n"
10142 "Exact match of the communities")
Lou Bergerf9b6c392016-01-12 13:42:09 -050010143
Lou Berger651b4022016-01-12 13:42:07 -050010144DEFUN (show_bgp_ipv4_community,
10145 show_bgp_ipv4_community_cmd,
10146 "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010147 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010148 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010149 IP_STR
paul718e3742002-12-13 20:15:29 +000010150 "Display routes matching the communities\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{
Michael Lambert95cbbd22010-07-23 14:43:04 -040010156 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010157}
10158
Lou Berger651b4022016-01-12 13:42:07 -050010159ALIAS (show_bgp_ipv4_community,
10160 show_bgp_ipv4_community2_cmd,
10161 "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 +000010162 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010163 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010164 IP_STR
paul718e3742002-12-13 20:15:29 +000010165 "Display routes matching the communities\n"
10166 "community number\n"
10167 "Do not send outside local AS (well-known community)\n"
10168 "Do not advertise to any peer (well-known community)\n"
10169 "Do not export to next AS (well-known community)\n"
10170 "community number\n"
10171 "Do not send outside local AS (well-known community)\n"
10172 "Do not advertise to any peer (well-known community)\n"
10173 "Do not export to next AS (well-known community)\n")
10174
Lou Berger651b4022016-01-12 13:42:07 -050010175ALIAS (show_bgp_ipv4_community,
10176 show_bgp_ipv4_community3_cmd,
10177 "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 +000010178 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010179 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010180 IP_STR
paul718e3742002-12-13 20:15:29 +000010181 "Display routes matching the communities\n"
10182 "community number\n"
10183 "Do not send outside local AS (well-known community)\n"
10184 "Do not advertise to any peer (well-known community)\n"
10185 "Do not export to next AS (well-known community)\n"
10186 "community number\n"
10187 "Do not send outside local AS (well-known community)\n"
10188 "Do not advertise to any peer (well-known community)\n"
10189 "Do not export to next AS (well-known community)\n"
10190 "community number\n"
10191 "Do not send outside local AS (well-known community)\n"
10192 "Do not advertise to any peer (well-known community)\n"
10193 "Do not export to next AS (well-known community)\n")
10194
Lou Berger651b4022016-01-12 13:42:07 -050010195ALIAS (show_bgp_ipv4_community,
10196 show_bgp_ipv4_community4_cmd,
10197 "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 +000010198 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010199 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010200 IP_STR
paul718e3742002-12-13 20:15:29 +000010201 "Display routes matching the communities\n"
10202 "community number\n"
10203 "Do not send outside local AS (well-known community)\n"
10204 "Do not advertise to any peer (well-known community)\n"
10205 "Do not export to next AS (well-known community)\n"
10206 "community number\n"
10207 "Do not send outside local AS (well-known community)\n"
10208 "Do not advertise to any peer (well-known community)\n"
10209 "Do not export to next AS (well-known community)\n"
10210 "community number\n"
10211 "Do not send outside local AS (well-known community)\n"
10212 "Do not advertise to any peer (well-known community)\n"
10213 "Do not export to next AS (well-known community)\n"
10214 "community number\n"
10215 "Do not send outside local AS (well-known community)\n"
10216 "Do not advertise to any peer (well-known community)\n"
10217 "Do not export to next AS (well-known community)\n")
10218
Lou Berger651b4022016-01-12 13:42:07 -050010219DEFUN (show_bgp_ipv4_safi_community,
10220 show_bgp_ipv4_safi_community_cmd,
10221 "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010222 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010223 BGP_STR
10224 "Address family\n"
10225 "Address Family modifier\n"
10226 "Address Family modifier\n"
10227 "Display routes matching the communities\n"
10228 "community number\n"
10229 "Do not send outside local AS (well-known community)\n"
10230 "Do not advertise to any peer (well-known community)\n"
10231 "Do not export to next AS (well-known community)\n")
10232{
10233 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -040010234 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +000010235
Michael Lambert95cbbd22010-07-23 14:43:04 -040010236 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010237}
10238
Lou Berger651b4022016-01-12 13:42:07 -050010239ALIAS (show_bgp_ipv4_safi_community,
10240 show_bgp_ipv4_safi_community2_cmd,
10241 "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 +000010242 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010243 BGP_STR
10244 "Address family\n"
10245 "Address Family modifier\n"
10246 "Address Family modifier\n"
10247 "Display routes matching the communities\n"
10248 "community number\n"
10249 "Do not send outside local AS (well-known community)\n"
10250 "Do not advertise to any peer (well-known community)\n"
10251 "Do not export to next AS (well-known community)\n"
10252 "community number\n"
10253 "Do not send outside local AS (well-known community)\n"
10254 "Do not advertise to any peer (well-known community)\n"
10255 "Do not export to next AS (well-known community)\n")
10256
Lou Berger651b4022016-01-12 13:42:07 -050010257ALIAS (show_bgp_ipv4_safi_community,
10258 show_bgp_ipv4_safi_community3_cmd,
10259 "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 +000010260 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010261 BGP_STR
10262 "Address family\n"
10263 "Address Family modifier\n"
10264 "Address Family modifier\n"
10265 "Display routes matching the communities\n"
10266 "community number\n"
10267 "Do not send outside local AS (well-known community)\n"
10268 "Do not advertise to any peer (well-known community)\n"
10269 "Do not export to next AS (well-known community)\n"
10270 "community number\n"
10271 "Do not send outside local AS (well-known community)\n"
10272 "Do not advertise to any peer (well-known community)\n"
10273 "Do not export to next AS (well-known community)\n"
10274 "community number\n"
10275 "Do not send outside local AS (well-known community)\n"
10276 "Do not advertise to any peer (well-known community)\n"
10277 "Do not export to next AS (well-known community)\n")
10278
Lou Berger651b4022016-01-12 13:42:07 -050010279ALIAS (show_bgp_ipv4_safi_community,
10280 show_bgp_ipv4_safi_community4_cmd,
10281 "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 +000010282 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010283 BGP_STR
10284 "Address family\n"
10285 "Address Family modifier\n"
10286 "Address Family modifier\n"
10287 "Display routes matching the communities\n"
10288 "community number\n"
10289 "Do not send outside local AS (well-known community)\n"
10290 "Do not advertise to any peer (well-known community)\n"
10291 "Do not export to next AS (well-known community)\n"
10292 "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 "community number\n"
10297 "Do not send outside local AS (well-known community)\n"
10298 "Do not advertise to any peer (well-known community)\n"
10299 "Do not export to next AS (well-known community)\n"
10300 "community number\n"
10301 "Do not send outside local AS (well-known community)\n"
10302 "Do not advertise to any peer (well-known community)\n"
10303 "Do not export to next AS (well-known community)\n")
10304
Michael Lambert95cbbd22010-07-23 14:43:04 -040010305DEFUN (show_bgp_view_afi_safi_community_all,
10306 show_bgp_view_afi_safi_community_all_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010307 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Michael Lambert95cbbd22010-07-23 14:43:04 -040010308 SHOW_STR
10309 BGP_STR
10310 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010311 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010312 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010313 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010314 "Address Family modifier\n"
10315 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +000010316 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -040010317{
10318 int afi;
10319 int safi;
10320 struct bgp *bgp;
10321
10322 /* BGP structure lookup. */
10323 bgp = bgp_lookup_by_name (argv[0]);
10324 if (bgp == NULL)
10325 {
10326 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10327 return CMD_WARNING;
10328 }
10329
Michael Lambert95cbbd22010-07-23 14:43:04 -040010330 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10331 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010332 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
10333}
10334
10335DEFUN (show_bgp_view_afi_safi_community,
10336 show_bgp_view_afi_safi_community_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010337 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -040010338 SHOW_STR
10339 BGP_STR
10340 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010341 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010342 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010343 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010344 "Address family modifier\n"
10345 "Address family modifier\n"
10346 "Display routes matching the communities\n"
10347 "community number\n"
10348 "Do not send outside local AS (well-known community)\n"
10349 "Do not advertise to any peer (well-known community)\n"
10350 "Do not export to next AS (well-known community)\n")
10351{
10352 int afi;
10353 int safi;
10354
Michael Lambert95cbbd22010-07-23 14:43:04 -040010355 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10356 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10357 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010358}
10359
10360ALIAS (show_bgp_view_afi_safi_community,
10361 show_bgp_view_afi_safi_community2_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010362 "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 -040010363 SHOW_STR
10364 BGP_STR
10365 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010366 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010367 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010368 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010369 "Address family modifier\n"
10370 "Address family modifier\n"
10371 "Display routes matching the communities\n"
10372 "community number\n"
10373 "Do not send outside local AS (well-known community)\n"
10374 "Do not advertise to any peer (well-known community)\n"
10375 "Do not export to next AS (well-known community)\n"
10376 "community number\n"
10377 "Do not send outside local AS (well-known community)\n"
10378 "Do not advertise to any peer (well-known community)\n"
10379 "Do not export to next AS (well-known community)\n")
10380
10381ALIAS (show_bgp_view_afi_safi_community,
10382 show_bgp_view_afi_safi_community3_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010383 "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 -040010384 SHOW_STR
10385 BGP_STR
10386 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010387 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010388 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010389 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010390 "Address family modifier\n"
10391 "Address family modifier\n"
10392 "Display routes matching the communities\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 "community number\n"
10398 "Do not send outside local AS (well-known community)\n"
10399 "Do not advertise to any peer (well-known community)\n"
10400 "Do not export to next AS (well-known community)\n"
10401 "community number\n"
10402 "Do not send outside local AS (well-known community)\n"
10403 "Do not advertise to any peer (well-known community)\n"
10404 "Do not export to next AS (well-known community)\n")
10405
10406ALIAS (show_bgp_view_afi_safi_community,
10407 show_bgp_view_afi_safi_community4_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010408 "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 -040010409 SHOW_STR
10410 BGP_STR
10411 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010412 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010413 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010414 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010415 "Address family modifier\n"
10416 "Address family modifier\n"
10417 "Display routes matching the communities\n"
10418 "community number\n"
10419 "Do not send outside local AS (well-known community)\n"
10420 "Do not advertise to any peer (well-known community)\n"
10421 "Do not export to next AS (well-known community)\n"
10422 "community number\n"
10423 "Do not send outside local AS (well-known community)\n"
10424 "Do not advertise to any peer (well-known community)\n"
10425 "Do not export to next AS (well-known community)\n"
10426 "community number\n"
10427 "Do not send outside local AS (well-known community)\n"
10428 "Do not advertise to any peer (well-known community)\n"
10429 "Do not export to next AS (well-known community)\n"
10430 "community number\n"
10431 "Do not send outside local AS (well-known community)\n"
10432 "Do not advertise to any peer (well-known community)\n"
10433 "Do not export to next AS (well-known community)\n")
10434
Lou Berger651b4022016-01-12 13:42:07 -050010435DEFUN (show_bgp_ipv4_community_exact,
10436 show_bgp_ipv4_community_exact_cmd,
10437 "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010438 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010439 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010440 IP_STR
paul718e3742002-12-13 20:15:29 +000010441 "Display routes matching the communities\n"
10442 "community number\n"
10443 "Do not send outside local AS (well-known community)\n"
10444 "Do not advertise to any peer (well-known community)\n"
10445 "Do not export to next AS (well-known community)\n"
10446 "Exact match of the communities")
10447{
Michael Lambert95cbbd22010-07-23 14:43:04 -040010448 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010449}
10450
Lou Berger651b4022016-01-12 13:42:07 -050010451ALIAS (show_bgp_ipv4_community_exact,
10452 show_bgp_ipv4_community2_exact_cmd,
10453 "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 +000010454 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010455 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010456 IP_STR
paul718e3742002-12-13 20:15:29 +000010457 "Display routes matching the communities\n"
10458 "community number\n"
10459 "Do not send outside local AS (well-known community)\n"
10460 "Do not advertise to any peer (well-known community)\n"
10461 "Do not export to next AS (well-known community)\n"
10462 "community number\n"
10463 "Do not send outside local AS (well-known community)\n"
10464 "Do not advertise to any peer (well-known community)\n"
10465 "Do not export to next AS (well-known community)\n"
10466 "Exact match of the communities")
10467
Lou Berger651b4022016-01-12 13:42:07 -050010468ALIAS (show_bgp_ipv4_community_exact,
10469 show_bgp_ipv4_community3_exact_cmd,
10470 "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 +000010471 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010472 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010473 IP_STR
paul718e3742002-12-13 20:15:29 +000010474 "Display routes matching the communities\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 "community number\n"
10480 "Do not send outside local AS (well-known community)\n"
10481 "Do not advertise to any peer (well-known community)\n"
10482 "Do not export to next AS (well-known community)\n"
10483 "community number\n"
10484 "Do not send outside local AS (well-known community)\n"
10485 "Do not advertise to any peer (well-known community)\n"
10486 "Do not export to next AS (well-known community)\n"
10487 "Exact match of the communities")
10488
Lou Berger651b4022016-01-12 13:42:07 -050010489ALIAS (show_bgp_ipv4_community_exact,
10490 show_bgp_ipv4_community4_exact_cmd,
10491 "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 +000010492 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010493 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010494 IP_STR
paul718e3742002-12-13 20:15:29 +000010495 "Display routes matching the communities\n"
10496 "community number\n"
10497 "Do not send outside local AS (well-known community)\n"
10498 "Do not advertise to any peer (well-known community)\n"
10499 "Do not export to next AS (well-known community)\n"
10500 "community number\n"
10501 "Do not send outside local AS (well-known community)\n"
10502 "Do not advertise to any peer (well-known community)\n"
10503 "Do not export to next AS (well-known community)\n"
10504 "community number\n"
10505 "Do not send outside local AS (well-known community)\n"
10506 "Do not advertise to any peer (well-known community)\n"
10507 "Do not export to next AS (well-known community)\n"
10508 "community number\n"
10509 "Do not send outside local AS (well-known community)\n"
10510 "Do not advertise to any peer (well-known community)\n"
10511 "Do not export to next AS (well-known community)\n"
10512 "Exact match of the communities")
10513
Lou Berger651b4022016-01-12 13:42:07 -050010514DEFUN (show_bgp_ipv4_safi_community4_exact,
10515 show_bgp_ipv4_safi_community_exact_cmd,
10516 "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010517 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010518 BGP_STR
10519 "Address family\n"
10520 "Address Family modifier\n"
10521 "Address Family modifier\n"
10522 "Display routes matching the communities\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 "Exact match of the communities")
10528{
10529 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -040010530 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +000010531
Michael Lambert95cbbd22010-07-23 14:43:04 -040010532 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010533}
10534
Lou Berger651b4022016-01-12 13:42:07 -050010535ALIAS (show_bgp_ipv4_safi_community4_exact,
10536 show_bgp_ipv4_safi_community2_exact_cmd,
10537 "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 +000010538 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010539 BGP_STR
10540 "Address family\n"
10541 "Address Family modifier\n"
10542 "Address Family modifier\n"
10543 "Display routes matching the communities\n"
10544 "community number\n"
10545 "Do not send outside local AS (well-known community)\n"
10546 "Do not advertise to any peer (well-known community)\n"
10547 "Do not export to next AS (well-known community)\n"
10548 "community number\n"
10549 "Do not send outside local AS (well-known community)\n"
10550 "Do not advertise to any peer (well-known community)\n"
10551 "Do not export to next AS (well-known community)\n"
10552 "Exact match of the communities")
10553
Lou Berger651b4022016-01-12 13:42:07 -050010554ALIAS (show_bgp_ipv4_safi_community4_exact,
10555 show_bgp_ipv4_safi_community3_exact_cmd,
10556 "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 +000010557 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010558 BGP_STR
10559 "Address family\n"
10560 "Address Family modifier\n"
10561 "Address Family modifier\n"
10562 "Display routes matching the communities\n"
10563 "community number\n"
10564 "Do not send outside local AS (well-known community)\n"
10565 "Do not advertise to any peer (well-known community)\n"
10566 "Do not export to next AS (well-known community)\n"
10567 "community number\n"
10568 "Do not send outside local AS (well-known community)\n"
10569 "Do not advertise to any peer (well-known community)\n"
10570 "Do not export to next AS (well-known community)\n"
10571 "community number\n"
10572 "Do not send outside local AS (well-known community)\n"
10573 "Do not advertise to any peer (well-known community)\n"
10574 "Do not export to next AS (well-known community)\n"
10575 "Exact match of the communities")
10576
Lou Berger651b4022016-01-12 13:42:07 -050010577ALIAS (show_bgp_ipv4_safi_community4_exact,
10578 show_bgp_ipv4_safi_community4_exact_cmd,
10579 "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 +000010580 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010581 BGP_STR
10582 "Address family\n"
10583 "Address Family modifier\n"
10584 "Address Family modifier\n"
10585 "Display routes matching the communities\n"
10586 "community number\n"
10587 "Do not send outside local AS (well-known community)\n"
10588 "Do not advertise to any peer (well-known community)\n"
10589 "Do not export to next AS (well-known community)\n"
10590 "community number\n"
10591 "Do not send outside local AS (well-known community)\n"
10592 "Do not advertise to any peer (well-known community)\n"
10593 "Do not export to next AS (well-known community)\n"
10594 "community number\n"
10595 "Do not send outside local AS (well-known community)\n"
10596 "Do not advertise to any peer (well-known community)\n"
10597 "Do not export to next AS (well-known community)\n"
10598 "community number\n"
10599 "Do not send outside local AS (well-known community)\n"
10600 "Do not advertise to any peer (well-known community)\n"
10601 "Do not export to next AS (well-known community)\n"
10602 "Exact match of the communities")
10603
Lou Bergerf9b6c392016-01-12 13:42:09 -050010604DEFUN (show_bgp_ipv6_safi_community,
10605 show_bgp_ipv6_safi_community_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010606 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010607 SHOW_STR
10608 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010609 "Address family\n"
10610 "Address family modifier\n"
10611 "Address family modifier\n"
10612 "Address family modifier\n"
10613 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010614 "Display routes matching the communities\n"
10615 "community number\n"
10616 "Do not send outside local AS (well-known community)\n"
10617 "Do not advertise to any peer (well-known community)\n"
10618 "Do not export to next AS (well-known community)\n")
10619{
Lou Berger651b4022016-01-12 13:42:07 -050010620 safi_t safi;
10621
10622 if (bgp_parse_safi(argv[0], &safi)) {
10623 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10624 return CMD_WARNING;
10625 }
10626 return bgp_show_community (vty, NULL, argc-1, argv+1, 0, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000010627}
10628
Lou Bergerf9b6c392016-01-12 13:42:09 -050010629ALIAS (show_bgp_ipv6_safi_community,
10630 show_bgp_ipv6_safi_community2_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010631 "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 +000010632 SHOW_STR
10633 BGP_STR
10634 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010635 "Address family modifier\n"
10636 "Address family modifier\n"
10637 "Address family modifier\n"
10638 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010639 "Display routes matching the communities\n"
10640 "community number\n"
10641 "Do not send outside local AS (well-known community)\n"
10642 "Do not advertise to any peer (well-known community)\n"
10643 "Do not export to next AS (well-known community)\n"
10644 "community number\n"
10645 "Do not send outside local AS (well-known community)\n"
10646 "Do not advertise to any peer (well-known community)\n"
10647 "Do not export to next AS (well-known community)\n")
10648
Lou Bergerf9b6c392016-01-12 13:42:09 -050010649ALIAS (show_bgp_ipv6_safi_community,
10650 show_bgp_ipv6_safi_community3_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010651 "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 +000010652 SHOW_STR
10653 BGP_STR
10654 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010655 "Address family modifier\n"
10656 "Address family modifier\n"
10657 "Address family modifier\n"
10658 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010659 "Display routes matching the communities\n"
10660 "community number\n"
10661 "Do not send outside local AS (well-known community)\n"
10662 "Do not advertise to any peer (well-known community)\n"
10663 "Do not export to next AS (well-known community)\n"
10664 "community number\n"
10665 "Do not send outside local AS (well-known community)\n"
10666 "Do not advertise to any peer (well-known community)\n"
10667 "Do not export to next AS (well-known community)\n"
10668 "community number\n"
10669 "Do not send outside local AS (well-known community)\n"
10670 "Do not advertise to any peer (well-known community)\n"
10671 "Do not export to next AS (well-known community)\n")
10672
Lou Bergerf9b6c392016-01-12 13:42:09 -050010673ALIAS (show_bgp_ipv6_safi_community,
10674 show_bgp_ipv6_safi_community4_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010675 "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 +000010676 SHOW_STR
10677 BGP_STR
10678 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010679 "Address family modifier\n"
10680 "Address family modifier\n"
10681 "Address family modifier\n"
10682 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010683 "Display routes matching the communities\n"
10684 "community number\n"
10685 "Do not send outside local AS (well-known community)\n"
10686 "Do not advertise to any peer (well-known community)\n"
10687 "Do not export to next AS (well-known community)\n"
10688 "community number\n"
10689 "Do not send outside local AS (well-known community)\n"
10690 "Do not advertise to any peer (well-known community)\n"
10691 "Do not export to next AS (well-known community)\n"
10692 "community number\n"
10693 "Do not send outside local AS (well-known community)\n"
10694 "Do not advertise to any peer (well-known community)\n"
10695 "Do not export to next AS (well-known community)\n"
10696 "community number\n"
10697 "Do not send outside local AS (well-known community)\n"
10698 "Do not advertise to any peer (well-known community)\n"
10699 "Do not export to next AS (well-known community)\n")
10700
paul718e3742002-12-13 20:15:29 +000010701
Lou Bergerf9b6c392016-01-12 13:42:09 -050010702DEFUN (show_bgp_ipv6_safi_community_exact,
10703 show_bgp_ipv6_safi_community_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010704 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010705 SHOW_STR
10706 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010707 "Address family\n"
10708 "Address family modifier\n"
10709 "Address family modifier\n"
10710 "Address family modifier\n"
10711 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010712 "Display routes matching the communities\n"
10713 "community number\n"
10714 "Do not send outside local AS (well-known community)\n"
10715 "Do not advertise to any peer (well-known community)\n"
10716 "Do not export to next AS (well-known community)\n"
10717 "Exact match of the communities")
10718{
Lou Berger651b4022016-01-12 13:42:07 -050010719 safi_t safi;
10720
10721 if (bgp_parse_safi(argv[0], &safi)) {
10722 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10723 return CMD_WARNING;
10724 }
10725 return bgp_show_community (vty, NULL, argc-1, argv+1, 1, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000010726}
10727
paul718e3742002-12-13 20:15:29 +000010728
10729ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010730 show_bgp_ipv6_safi_community2_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010731 "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 +000010732 SHOW_STR
10733 BGP_STR
10734 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010735 "Address family modifier\n"
10736 "Address family modifier\n"
10737 "Address family modifier\n"
10738 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010739 "Display routes matching the communities\n"
10740 "community number\n"
10741 "Do not send outside local AS (well-known community)\n"
10742 "Do not advertise to any peer (well-known community)\n"
10743 "Do not export to next AS (well-known community)\n"
10744 "community number\n"
10745 "Do not send outside local AS (well-known community)\n"
10746 "Do not advertise to any peer (well-known community)\n"
10747 "Do not export to next AS (well-known community)\n"
10748 "Exact match of the communities")
10749
10750ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010751 show_bgp_ipv6_safi_community3_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010752 "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 +000010753 SHOW_STR
10754 BGP_STR
10755 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010756 "Address family modifier\n"
10757 "Address family modifier\n"
10758 "Address family modifier\n"
10759 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010760 "Display routes matching the communities\n"
10761 "community number\n"
10762 "Do not send outside local AS (well-known community)\n"
10763 "Do not advertise to any peer (well-known community)\n"
10764 "Do not export to next AS (well-known community)\n"
10765 "community number\n"
10766 "Do not send outside local AS (well-known community)\n"
10767 "Do not advertise to any peer (well-known community)\n"
10768 "Do not export to next AS (well-known community)\n"
10769 "community number\n"
10770 "Do not send outside local AS (well-known community)\n"
10771 "Do not advertise to any peer (well-known community)\n"
10772 "Do not export to next AS (well-known community)\n"
10773 "Exact match of the communities")
10774
10775ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010776 show_bgp_ipv6_safi_community4_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010777 "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 +000010778 SHOW_STR
10779 BGP_STR
10780 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010781 "Address family modifier\n"
10782 "Address family modifier\n"
10783 "Address family modifier\n"
10784 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010785 "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 "community number\n"
10799 "Do not send outside local AS (well-known community)\n"
10800 "Do not advertise to any peer (well-known community)\n"
10801 "Do not export to next AS (well-known community)\n"
10802 "Exact match of the communities")
10803
paul94f2b392005-06-28 12:44:16 +000010804static int
paulfd79ac92004-10-13 05:06:08 +000010805bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -040010806 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +000010807{
10808 struct community_list *list;
10809
hassofee6e4e2005-02-02 16:29:31 +000010810 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +000010811 if (list == NULL)
10812 {
10813 vty_out (vty, "%% %s is not a valid community-list name%s", com,
10814 VTY_NEWLINE);
10815 return CMD_WARNING;
10816 }
10817
ajs5a646652004-11-05 01:25:55 +000010818 return bgp_show (vty, NULL, afi, safi,
10819 (exact ? bgp_show_type_community_list_exact :
10820 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +000010821}
10822
Lou Bergerf9b6c392016-01-12 13:42:09 -050010823DEFUN (show_ip_bgp_community_list,
10824 show_ip_bgp_community_list_cmd,
10825 "show ip bgp community-list (<1-500>|WORD)",
10826 SHOW_STR
10827 IP_STR
10828 BGP_STR
10829 "Display routes matching the community-list\n"
10830 "community-list number\n"
10831 "community-list name\n")
10832{
10833 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
10834}
10835
10836DEFUN (show_ip_bgp_ipv4_community_list,
10837 show_ip_bgp_ipv4_community_list_cmd,
10838 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
10839 SHOW_STR
10840 IP_STR
10841 BGP_STR
10842 "Address family\n"
10843 "Address Family modifier\n"
10844 "Address Family modifier\n"
10845 "Display routes matching the community-list\n"
10846 "community-list number\n"
10847 "community-list name\n")
10848{
10849 if (strncmp (argv[0], "m", 1) == 0)
10850 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
10851
10852 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
10853}
10854
10855DEFUN (show_ip_bgp_community_list_exact,
10856 show_ip_bgp_community_list_exact_cmd,
10857 "show ip bgp community-list (<1-500>|WORD) exact-match",
10858 SHOW_STR
10859 IP_STR
10860 BGP_STR
10861 "Display routes matching the community-list\n"
10862 "community-list number\n"
10863 "community-list name\n"
10864 "Exact match of the communities\n")
10865{
10866 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
10867}
10868
10869DEFUN (show_ip_bgp_ipv4_community_list_exact,
10870 show_ip_bgp_ipv4_community_list_exact_cmd,
10871 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
10872 SHOW_STR
10873 IP_STR
10874 BGP_STR
10875 "Address family\n"
10876 "Address Family modifier\n"
10877 "Address Family modifier\n"
10878 "Display routes matching the community-list\n"
10879 "community-list number\n"
10880 "community-list name\n"
10881 "Exact match of the communities\n")
10882{
10883 if (strncmp (argv[0], "m", 1) == 0)
10884 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
10885
10886 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
10887}
10888
Lou Bergerf9b6c392016-01-12 13:42:09 -050010889DEFUN (show_bgp_community_list,
10890 show_bgp_community_list_cmd,
10891 "show bgp community-list (<1-500>|WORD)",
10892 SHOW_STR
10893 BGP_STR
10894 "Display routes matching the community-list\n"
10895 "community-list number\n"
10896 "community-list name\n")
10897{
10898 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
10899}
10900
10901ALIAS (show_bgp_community_list,
10902 show_bgp_ipv6_community_list_cmd,
10903 "show bgp ipv6 community-list (<1-500>|WORD)",
10904 SHOW_STR
10905 BGP_STR
10906 "Address family\n"
10907 "Display routes matching the community-list\n"
10908 "community-list number\n"
10909 "community-list name\n")
10910
10911/* old command */
10912DEFUN (show_ipv6_bgp_community_list,
10913 show_ipv6_bgp_community_list_cmd,
10914 "show ipv6 bgp community-list WORD",
10915 SHOW_STR
10916 IPV6_STR
10917 BGP_STR
10918 "Display routes matching the community-list\n"
10919 "community-list name\n")
10920{
10921 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
10922}
10923
10924/* old command */
10925DEFUN (show_ipv6_mbgp_community_list,
10926 show_ipv6_mbgp_community_list_cmd,
10927 "show ipv6 mbgp community-list WORD",
10928 SHOW_STR
10929 IPV6_STR
10930 MBGP_STR
10931 "Display routes matching the community-list\n"
10932 "community-list name\n")
10933{
10934 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
10935}
10936
10937DEFUN (show_bgp_community_list_exact,
10938 show_bgp_community_list_exact_cmd,
10939 "show bgp community-list (<1-500>|WORD) exact-match",
10940 SHOW_STR
10941 BGP_STR
10942 "Display routes matching the community-list\n"
10943 "community-list number\n"
10944 "community-list name\n"
10945 "Exact match of the communities\n")
10946{
10947 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
10948}
10949
10950ALIAS (show_bgp_community_list_exact,
10951 show_bgp_ipv6_community_list_exact_cmd,
10952 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
10953 SHOW_STR
10954 BGP_STR
10955 "Address family\n"
10956 "Display routes matching the community-list\n"
10957 "community-list number\n"
10958 "community-list name\n"
10959 "Exact match of the communities\n")
10960
10961/* old command */
10962DEFUN (show_ipv6_bgp_community_list_exact,
10963 show_ipv6_bgp_community_list_exact_cmd,
10964 "show ipv6 bgp community-list WORD exact-match",
10965 SHOW_STR
10966 IPV6_STR
10967 BGP_STR
10968 "Display routes matching the community-list\n"
10969 "community-list name\n"
10970 "Exact match of the communities\n")
10971{
10972 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
10973}
10974
10975/* old command */
10976DEFUN (show_ipv6_mbgp_community_list_exact,
10977 show_ipv6_mbgp_community_list_exact_cmd,
10978 "show ipv6 mbgp community-list WORD exact-match",
10979 SHOW_STR
10980 IPV6_STR
10981 MBGP_STR
10982 "Display routes matching the community-list\n"
10983 "community-list name\n"
10984 "Exact match of the communities\n")
10985{
10986 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
10987}
Lou Bergerf9b6c392016-01-12 13:42:09 -050010988
Lou Berger651b4022016-01-12 13:42:07 -050010989DEFUN (show_bgp_ipv4_community_list,
10990 show_bgp_ipv4_community_list_cmd,
10991 "show bgp ipv4 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000010992 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010993 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010994 IP_STR
paul718e3742002-12-13 20:15:29 +000010995 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000010996 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000010997 "community-list name\n")
10998{
10999 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
11000}
11001
Lou Berger651b4022016-01-12 13:42:07 -050011002DEFUN (show_bgp_ipv4_safi_community_list,
11003 show_bgp_ipv4_safi_community_list_cmd,
11004 "show bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011005 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011006 BGP_STR
11007 "Address family\n"
11008 "Address Family modifier\n"
11009 "Address Family modifier\n"
11010 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011011 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011012 "community-list name\n")
11013{
11014 if (strncmp (argv[0], "m", 1) == 0)
11015 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
11016
11017 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
11018}
11019
Lou Berger651b4022016-01-12 13:42:07 -050011020DEFUN (show_bgp_ipv4_community_list_exact,
11021 show_bgp_ipv4_community_list_exact_cmd,
11022 "show bgp ipv4 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011023 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011024 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011025 IP_STR
paul718e3742002-12-13 20:15:29 +000011026 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011027 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011028 "community-list name\n"
11029 "Exact match of the communities\n")
11030{
11031 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
11032}
11033
Lou Berger651b4022016-01-12 13:42:07 -050011034DEFUN (show_bgp_ipv4_safi_community_list_exact,
11035 show_bgp_ipv4_safi_community_list_exact_cmd,
11036 "show bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011037 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011038 BGP_STR
11039 "Address family\n"
11040 "Address Family modifier\n"
11041 "Address Family modifier\n"
11042 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011043 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011044 "community-list name\n"
11045 "Exact match of the communities\n")
11046{
11047 if (strncmp (argv[0], "m", 1) == 0)
11048 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
11049
11050 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
11051}
11052
Lou Bergerf9b6c392016-01-12 13:42:09 -050011053DEFUN (show_bgp_ipv6_safi_community_list,
11054 show_bgp_ipv6_safi_community_list_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011055 "show bgp ipv6 (encap|multicast|unicast|vpn) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011056 SHOW_STR
11057 BGP_STR
11058 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050011059 "Address family modifier\n"
11060 "Address family modifier\n"
11061 "Address family modifier\n"
11062 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000011063 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011064 "community-list number\n"
paule8e19462006-01-19 20:16:55 +000011065 "community-list name\n")
paul718e3742002-12-13 20:15:29 +000011066{
Lou Berger651b4022016-01-12 13:42:07 -050011067 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011068
Lou Berger651b4022016-01-12 13:42:07 -050011069 if (bgp_parse_safi(argv[0], &safi)) {
11070 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11071 return CMD_WARNING;
11072 }
11073 return bgp_show_community_list (vty, argv[1], 0, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000011074}
11075
Lou Bergerf9b6c392016-01-12 13:42:09 -050011076DEFUN (show_bgp_ipv6_safi_community_list_exact,
11077 show_bgp_ipv6_safi_community_list_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011078 "show bgp ipv6 (encap|multicast|unicast|vpn) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011079 SHOW_STR
11080 BGP_STR
11081 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050011082 "Address family modifier\n"
11083 "Address family modifier\n"
11084 "Address family modifier\n"
11085 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000011086 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011087 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011088 "community-list name\n"
11089 "Exact match of the communities\n")
paul718e3742002-12-13 20:15:29 +000011090{
Lou Berger651b4022016-01-12 13:42:07 -050011091 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011092
Lou Berger651b4022016-01-12 13:42:07 -050011093 if (bgp_parse_safi(argv[0], &safi)) {
11094 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11095 return CMD_WARNING;
11096 }
11097 return bgp_show_community_list (vty, argv[1], 1, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000011098}
David Lamparter6b0655a2014-06-04 06:53:35 +020011099
paul94f2b392005-06-28 12:44:16 +000011100static int
paulfd79ac92004-10-13 05:06:08 +000011101bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +000011102 safi_t safi, enum bgp_show_type type)
11103{
11104 int ret;
11105 struct prefix *p;
11106
11107 p = prefix_new();
11108
11109 ret = str2prefix (prefix, p);
11110 if (! ret)
11111 {
11112 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
11113 return CMD_WARNING;
11114 }
11115
ajs5a646652004-11-05 01:25:55 +000011116 ret = bgp_show (vty, NULL, afi, safi, type, p);
11117 prefix_free(p);
11118 return ret;
paul718e3742002-12-13 20:15:29 +000011119}
11120
Lou Bergerf9b6c392016-01-12 13:42:09 -050011121DEFUN (show_ip_bgp_prefix_longer,
11122 show_ip_bgp_prefix_longer_cmd,
11123 "show ip bgp A.B.C.D/M longer-prefixes",
11124 SHOW_STR
11125 IP_STR
11126 BGP_STR
11127 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11128 "Display route and more specific routes\n")
11129{
11130 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11131 bgp_show_type_prefix_longer);
11132}
11133
11134DEFUN (show_ip_bgp_flap_prefix_longer,
11135 show_ip_bgp_flap_prefix_longer_cmd,
11136 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
11137 SHOW_STR
11138 IP_STR
11139 BGP_STR
11140 "Display flap statistics of routes\n"
11141 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11142 "Display route and more specific routes\n")
11143{
11144 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11145 bgp_show_type_flap_prefix_longer);
11146}
11147
11148ALIAS (show_ip_bgp_flap_prefix_longer,
11149 show_ip_bgp_damp_flap_prefix_longer_cmd,
11150 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
11151 SHOW_STR
11152 IP_STR
11153 BGP_STR
11154 "Display detailed information about dampening\n"
11155 "Display flap statistics of routes\n"
11156 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11157 "Display route and more specific routes\n")
11158
11159DEFUN (show_ip_bgp_ipv4_prefix_longer,
11160 show_ip_bgp_ipv4_prefix_longer_cmd,
11161 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
11162 SHOW_STR
11163 IP_STR
11164 BGP_STR
11165 "Address family\n"
11166 "Address Family modifier\n"
11167 "Address Family modifier\n"
11168 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11169 "Display route and more specific routes\n")
11170{
11171 if (strncmp (argv[0], "m", 1) == 0)
11172 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
11173 bgp_show_type_prefix_longer);
11174
11175 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
11176 bgp_show_type_prefix_longer);
11177}
11178
11179DEFUN (show_ip_bgp_flap_address,
11180 show_ip_bgp_flap_address_cmd,
11181 "show ip bgp flap-statistics A.B.C.D",
11182 SHOW_STR
11183 IP_STR
11184 BGP_STR
11185 "Display flap statistics of routes\n"
11186 "Network in the BGP routing table to display\n")
11187{
11188 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11189 bgp_show_type_flap_address);
11190}
11191
11192ALIAS (show_ip_bgp_flap_address,
11193 show_ip_bgp_damp_flap_address_cmd,
11194 "show ip bgp dampening flap-statistics A.B.C.D",
11195 SHOW_STR
11196 IP_STR
11197 BGP_STR
11198 "Display detailed information about dampening\n"
11199 "Display flap statistics of routes\n"
11200 "Network in the BGP routing table to display\n")
11201
11202DEFUN (show_ip_bgp_flap_prefix,
11203 show_ip_bgp_flap_prefix_cmd,
11204 "show ip bgp flap-statistics A.B.C.D/M",
11205 SHOW_STR
11206 IP_STR
11207 BGP_STR
11208 "Display flap statistics of routes\n"
11209 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11210{
11211 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11212 bgp_show_type_flap_prefix);
11213}
11214
11215ALIAS (show_ip_bgp_flap_prefix,
11216 show_ip_bgp_damp_flap_prefix_cmd,
11217 "show ip bgp dampening flap-statistics A.B.C.D/M",
11218 SHOW_STR
11219 IP_STR
11220 BGP_STR
11221 "Display detailed information about dampening\n"
11222 "Display flap statistics of routes\n"
11223 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11224
Lou Bergerf9b6c392016-01-12 13:42:09 -050011225DEFUN (show_bgp_prefix_longer,
11226 show_bgp_prefix_longer_cmd,
11227 "show bgp X:X::X:X/M longer-prefixes",
11228 SHOW_STR
11229 BGP_STR
11230 "IPv6 prefix <network>/<length>\n"
11231 "Display route and more specific routes\n")
11232{
11233 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11234 bgp_show_type_prefix_longer);
11235}
11236
11237/* old command */
11238DEFUN (show_ipv6_bgp_prefix_longer,
11239 show_ipv6_bgp_prefix_longer_cmd,
11240 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11241 SHOW_STR
11242 IPV6_STR
11243 BGP_STR
11244 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11245 "Display route and more specific routes\n")
11246{
11247 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11248 bgp_show_type_prefix_longer);
11249}
11250
11251/* old command */
11252DEFUN (show_ipv6_mbgp_prefix_longer,
11253 show_ipv6_mbgp_prefix_longer_cmd,
11254 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11255 SHOW_STR
11256 IPV6_STR
11257 MBGP_STR
11258 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11259 "Display route and more specific routes\n")
11260{
11261 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
11262 bgp_show_type_prefix_longer);
11263}
Lou Bergerf9b6c392016-01-12 13:42:09 -050011264
Lou Berger651b4022016-01-12 13:42:07 -050011265DEFUN (show_bgp_ipv4_prefix_longer,
11266 show_bgp_ipv4_prefix_longer_cmd,
11267 "show bgp ipv4 A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011268 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011269 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011270 IP_STR
paul718e3742002-12-13 20:15:29 +000011271 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11272 "Display route and more specific routes\n")
11273{
11274 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11275 bgp_show_type_prefix_longer);
11276}
11277
Lou Berger651b4022016-01-12 13:42:07 -050011278DEFUN (show_bgp_ipv4_safi_flap_prefix_longer,
11279 show_bgp_ipv4_safi_flap_prefix_longer_cmd,
11280 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011281 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011282 BGP_STR
11283 "Address family\n"
11284 "Address Family modifier\n"
11285 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050011286 "Address Family modifier\n"
11287 "Address Family modifier\n"
11288 "Display flap statistics of routes\n"
paul718e3742002-12-13 20:15:29 +000011289 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11290 "Display route and more specific routes\n")
11291{
Lou Berger651b4022016-01-12 13:42:07 -050011292 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011293
Lou Berger651b4022016-01-12 13:42:07 -050011294 if (bgp_parse_safi(argv[0], &safi)) {
11295 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11296 return CMD_WARNING;
11297 }
11298 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11299 bgp_show_type_flap_prefix_longer);
paul718e3742002-12-13 20:15:29 +000011300}
11301
Lou Berger651b4022016-01-12 13:42:07 -050011302ALIAS (show_bgp_ipv4_safi_flap_prefix_longer,
11303 show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd,
11304 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011305 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011306 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011307 "Address family\n"
11308 "Address Family modifier\n"
11309 "Address Family modifier\n"
11310 "Address Family modifier\n"
11311 "Address Family modifier\n"
11312 "Display detailed information about dampening\n"
11313 "Display flap statistics of routes\n"
11314 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11315 "Display route and more specific routes\n")
11316
Lou Berger651b4022016-01-12 13:42:07 -050011317DEFUN (show_bgp_ipv6_safi_flap_prefix_longer,
11318 show_bgp_ipv6_safi_flap_prefix_longer_cmd,
11319 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics X:X::X:X/M longer-prefixes",
11320 SHOW_STR
11321 BGP_STR
11322 "Address family\n"
11323 "Address Family modifier\n"
11324 "Address Family modifier\n"
11325 "Address Family modifier\n"
11326 "Address Family modifier\n"
11327 "Display flap statistics of routes\n"
11328 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11329 "Display route and more specific routes\n")
11330{
11331 safi_t safi;
11332
11333 if (bgp_parse_safi(argv[0], &safi)) {
11334 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11335 return CMD_WARNING;
11336 }
11337 return bgp_show_prefix_longer (vty, argv[1], AFI_IP6, safi,
11338 bgp_show_type_flap_prefix_longer);
11339}
11340ALIAS (show_bgp_ipv6_safi_flap_prefix_longer,
11341 show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd,
11342 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics X:X::X:X/M longer-prefixes",
11343 SHOW_STR
11344 BGP_STR
11345 "Address family\n"
11346 "Address Family modifier\n"
11347 "Address Family modifier\n"
11348 "Address Family modifier\n"
11349 "Address Family modifier\n"
11350 "Display detailed information about dampening\n"
11351 "Display flap statistics of routes\n"
11352 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11353 "Display route and more specific routes\n")
Lou Berger651b4022016-01-12 13:42:07 -050011354
11355DEFUN (show_bgp_ipv4_safi_prefix_longer,
11356 show_bgp_ipv4_safi_prefix_longer_cmd,
11357 "show bgp ipv4 (encap|multicast|unicast|vpn) A.B.C.D/M longer-prefixes",
11358 SHOW_STR
11359 BGP_STR
11360 "Address family\n"
11361 "Address Family modifier\n"
11362 "Address Family modifier\n"
11363 "Address Family modifier\n"
11364 "Address Family modifier\n"
11365 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11366 "Display route and more specific routes\n")
11367{
11368 safi_t safi;
11369
11370 if (bgp_parse_safi(argv[0], &safi)) {
11371 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11372 return CMD_WARNING;
11373 }
11374
11375 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11376 bgp_show_type_prefix_longer);
11377}
11378
Lou Berger651b4022016-01-12 13:42:07 -050011379DEFUN (show_bgp_ipv6_safi_prefix_longer,
11380 show_bgp_ipv6_safi_prefix_longer_cmd,
11381 "show bgp ipv6 (encap|multicast|unicast|vpn) X:X::X:X/M longer-prefixes",
11382 SHOW_STR
11383 BGP_STR
11384 "Address family\n"
11385 "Address Family modifier\n"
11386 "Address Family modifier\n"
11387 "Address Family modifier\n"
11388 "Address Family modifier\n"
11389 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11390 "Display route and more specific routes\n")
11391{
11392 safi_t safi;
11393
11394 if (bgp_parse_safi(argv[0], &safi)) {
11395 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11396 return CMD_WARNING;
11397 }
11398
11399 return bgp_show_prefix_longer (vty, argv[1], AFI_IP6, safi,
11400 bgp_show_type_prefix_longer);
11401}
Lou Berger651b4022016-01-12 13:42:07 -050011402
11403DEFUN (show_bgp_ipv4_safi_flap_address,
11404 show_bgp_ipv4_safi_flap_address_cmd,
11405 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D",
11406 SHOW_STR
11407 BGP_STR
11408 "Address family\n"
11409 "Address Family modifier\n"
11410 "Address Family modifier\n"
11411 "Address Family modifier\n"
11412 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000011413 "Display flap statistics of routes\n"
11414 "Network in the BGP routing table to display\n")
11415{
Lou Berger651b4022016-01-12 13:42:07 -050011416 safi_t safi;
11417
11418 if (bgp_parse_safi(argv[0], &safi)) {
11419 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11420 return CMD_WARNING;
11421 }
11422 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000011423 bgp_show_type_flap_address);
11424}
Lou Berger651b4022016-01-12 13:42:07 -050011425ALIAS (show_bgp_ipv4_safi_flap_address,
11426 show_bgp_ipv4_safi_damp_flap_address_cmd,
11427 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D",
Balaji3921cc52015-05-16 23:12:17 +053011428 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053011429 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011430 "Address family\n"
11431 "Address Family modifier\n"
11432 "Address Family modifier\n"
11433 "Address Family modifier\n"
11434 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053011435 "Display detailed information about dampening\n"
11436 "Display flap statistics of routes\n"
11437 "Network in the BGP routing table to display\n")
Lou Berger205e6742016-01-12 13:42:11 -050011438
Lou Berger651b4022016-01-12 13:42:07 -050011439DEFUN (show_bgp_ipv6_flap_address,
11440 show_bgp_ipv6_flap_address_cmd,
11441 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D",
paul718e3742002-12-13 20:15:29 +000011442 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011443 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011444 "Address family\n"
11445 "Address Family modifier\n"
11446 "Address Family modifier\n"
11447 "Address Family modifier\n"
11448 "Address Family modifier\n"
11449 "Display flap statistics of routes\n"
11450 "Network in the BGP routing table to display\n")
11451{
11452 safi_t safi;
11453
11454 if (bgp_parse_safi(argv[0], &safi)) {
11455 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11456 return CMD_WARNING;
11457 }
11458 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11459 bgp_show_type_flap_address);
11460}
11461ALIAS (show_bgp_ipv6_flap_address,
11462 show_bgp_ipv6_damp_flap_address_cmd,
11463 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D",
11464 SHOW_STR
11465 BGP_STR
11466 "Address family\n"
11467 "Address Family modifier\n"
11468 "Address Family modifier\n"
11469 "Address Family modifier\n"
11470 "Address Family modifier\n"
11471 "Display detailed information about dampening\n"
11472 "Display flap statistics of routes\n"
11473 "Network in the BGP routing table to display\n")
Lou Berger651b4022016-01-12 13:42:07 -050011474
11475DEFUN (show_bgp_ipv4_safi_flap_prefix,
11476 show_bgp_ipv4_safi_flap_prefix_cmd,
11477 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D/M",
11478 SHOW_STR
11479 BGP_STR
11480 "Address family\n"
11481 "Address Family modifier\n"
11482 "Address Family modifier\n"
11483 "Address Family modifier\n"
11484 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000011485 "Display flap statistics of routes\n"
11486 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11487{
Lou Berger651b4022016-01-12 13:42:07 -050011488 safi_t safi;
11489
11490 if (bgp_parse_safi(argv[0], &safi)) {
11491 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11492 return CMD_WARNING;
11493 }
11494 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000011495 bgp_show_type_flap_prefix);
11496}
Balaji3921cc52015-05-16 23:12:17 +053011497
Lou Berger651b4022016-01-12 13:42:07 -050011498ALIAS (show_bgp_ipv4_safi_flap_prefix,
11499 show_bgp_ipv4_safi_damp_flap_prefix_cmd,
11500 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D/M",
Balaji3921cc52015-05-16 23:12:17 +053011501 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053011502 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011503 "Address family\n"
11504 "Address Family modifier\n"
11505 "Address Family modifier\n"
11506 "Address Family modifier\n"
11507 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053011508 "Display detailed information about dampening\n"
11509 "Display flap statistics of routes\n"
11510 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11511
Lou Berger651b4022016-01-12 13:42:07 -050011512DEFUN (show_bgp_ipv6_safi_flap_prefix,
11513 show_bgp_ipv6_safi_flap_prefix_cmd,
11514 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics X:X::X:X/M",
paul718e3742002-12-13 20:15:29 +000011515 SHOW_STR
11516 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011517 "Address family\n"
11518 "Address Family modifier\n"
11519 "Address Family modifier\n"
11520 "Address Family modifier\n"
11521 "Address Family modifier\n"
11522 "Display flap statistics of routes\n"
11523 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paul718e3742002-12-13 20:15:29 +000011524{
Lou Berger651b4022016-01-12 13:42:07 -050011525 safi_t safi;
11526
11527 if (bgp_parse_safi(argv[0], &safi)) {
11528 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11529 return CMD_WARNING;
11530 }
11531 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, safi,
11532 bgp_show_type_flap_prefix);
paul718e3742002-12-13 20:15:29 +000011533}
11534
Lou Berger651b4022016-01-12 13:42:07 -050011535ALIAS (show_bgp_ipv6_safi_flap_prefix,
11536 show_bgp_ipv6_safi_damp_flap_prefix_cmd,
11537 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics X:X::X:X/M",
11538 SHOW_STR
11539 BGP_STR
11540 "Address family\n"
11541 "Address Family modifier\n"
11542 "Address Family modifier\n"
11543 "Address Family modifier\n"
11544 "Address Family modifier\n"
11545 "Display detailed information about dampening\n"
11546 "Display flap statistics of routes\n"
11547 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11548
11549DEFUN (show_bgp_ipv6_prefix_longer,
paul718e3742002-12-13 20:15:29 +000011550 show_bgp_ipv6_prefix_longer_cmd,
11551 "show bgp ipv6 X:X::X:X/M longer-prefixes",
11552 SHOW_STR
11553 BGP_STR
11554 "Address family\n"
11555 "IPv6 prefix <network>/<length>\n"
11556 "Display route and more specific routes\n")
paul718e3742002-12-13 20:15:29 +000011557{
11558 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11559 bgp_show_type_prefix_longer);
11560}
11561
paul94f2b392005-06-28 12:44:16 +000011562static struct peer *
paulfd79ac92004-10-13 05:06:08 +000011563peer_lookup_in_view (struct vty *vty, const char *view_name,
11564 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +000011565{
11566 int ret;
11567 struct bgp *bgp;
11568 struct peer *peer;
11569 union sockunion su;
11570
11571 /* BGP structure lookup. */
11572 if (view_name)
11573 {
11574 bgp = bgp_lookup_by_name (view_name);
11575 if (! bgp)
11576 {
11577 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11578 return NULL;
11579 }
11580 }
paul5228ad22004-06-04 17:58:18 +000011581 else
paulbb46e942003-10-24 19:02:03 +000011582 {
11583 bgp = bgp_get_default ();
11584 if (! bgp)
11585 {
11586 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11587 return NULL;
11588 }
11589 }
11590
11591 /* Get peer sockunion. */
11592 ret = str2sockunion (ip_str, &su);
11593 if (ret < 0)
11594 {
11595 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
11596 return NULL;
11597 }
11598
11599 /* Peer structure lookup. */
11600 peer = peer_lookup (bgp, &su);
11601 if (! peer)
11602 {
11603 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
11604 return NULL;
11605 }
11606
11607 return peer;
11608}
David Lamparter6b0655a2014-06-04 06:53:35 +020011609
Paul Jakma2815e612006-09-14 02:56:07 +000011610enum bgp_stats
11611{
11612 BGP_STATS_MAXBITLEN = 0,
11613 BGP_STATS_RIB,
11614 BGP_STATS_PREFIXES,
11615 BGP_STATS_TOTPLEN,
11616 BGP_STATS_UNAGGREGATEABLE,
11617 BGP_STATS_MAX_AGGREGATEABLE,
11618 BGP_STATS_AGGREGATES,
11619 BGP_STATS_SPACE,
11620 BGP_STATS_ASPATH_COUNT,
11621 BGP_STATS_ASPATH_MAXHOPS,
11622 BGP_STATS_ASPATH_TOTHOPS,
11623 BGP_STATS_ASPATH_MAXSIZE,
11624 BGP_STATS_ASPATH_TOTSIZE,
11625 BGP_STATS_ASN_HIGHEST,
11626 BGP_STATS_MAX,
11627};
paulbb46e942003-10-24 19:02:03 +000011628
Paul Jakma2815e612006-09-14 02:56:07 +000011629static const char *table_stats_strs[] =
11630{
11631 [BGP_STATS_PREFIXES] = "Total Prefixes",
11632 [BGP_STATS_TOTPLEN] = "Average prefix length",
11633 [BGP_STATS_RIB] = "Total Advertisements",
11634 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11635 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11636 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11637 [BGP_STATS_SPACE] = "Address space advertised",
11638 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11639 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11640 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11641 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11642 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11643 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11644 [BGP_STATS_MAX] = NULL,
11645};
11646
11647struct bgp_table_stats
11648{
11649 struct bgp_table *table;
11650 unsigned long long counts[BGP_STATS_MAX];
11651};
11652
11653#if 0
11654#define TALLY_SIGFIG 100000
11655static unsigned long
11656ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11657{
11658 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11659 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11660 unsigned long ret = newtot / count;
11661
11662 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11663 return ret + 1;
11664 else
11665 return ret;
11666}
11667#endif
11668
11669static int
11670bgp_table_stats_walker (struct thread *t)
11671{
11672 struct bgp_node *rn;
11673 struct bgp_node *top;
11674 struct bgp_table_stats *ts = THREAD_ARG (t);
11675 unsigned int space = 0;
11676
Paul Jakma53d9f672006-10-15 23:41:16 +000011677 if (!(top = bgp_table_top (ts->table)))
11678 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +000011679
11680 switch (top->p.family)
11681 {
11682 case AF_INET:
11683 space = IPV4_MAX_BITLEN;
11684 break;
11685 case AF_INET6:
11686 space = IPV6_MAX_BITLEN;
11687 break;
11688 }
11689
11690 ts->counts[BGP_STATS_MAXBITLEN] = space;
11691
11692 for (rn = top; rn; rn = bgp_route_next (rn))
11693 {
11694 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -070011695 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +000011696 unsigned int rinum = 0;
11697
11698 if (rn == top)
11699 continue;
11700
11701 if (!rn->info)
11702 continue;
11703
11704 ts->counts[BGP_STATS_PREFIXES]++;
11705 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11706
11707#if 0
11708 ts->counts[BGP_STATS_AVGPLEN]
11709 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11710 ts->counts[BGP_STATS_AVGPLEN],
11711 rn->p.prefixlen);
11712#endif
11713
11714 /* check if the prefix is included by any other announcements */
11715 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -070011716 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +000011717
11718 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +000011719 {
11720 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11721 /* announced address space */
11722 if (space)
11723 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11724 }
Paul Jakma2815e612006-09-14 02:56:07 +000011725 else if (prn->info)
11726 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11727
Paul Jakma2815e612006-09-14 02:56:07 +000011728 for (ri = rn->info; ri; ri = ri->next)
11729 {
11730 rinum++;
11731 ts->counts[BGP_STATS_RIB]++;
11732
11733 if (ri->attr &&
11734 (CHECK_FLAG (ri->attr->flag,
11735 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11736 ts->counts[BGP_STATS_AGGREGATES]++;
11737
11738 /* as-path stats */
11739 if (ri->attr && ri->attr->aspath)
11740 {
11741 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11742 unsigned int size = aspath_size (ri->attr->aspath);
11743 as_t highest = aspath_highest (ri->attr->aspath);
11744
11745 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11746
11747 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11748 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11749
11750 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11751 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11752
11753 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11754 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11755#if 0
11756 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11757 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11758 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11759 hops);
11760 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11761 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11762 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11763 size);
11764#endif
11765 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11766 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11767 }
11768 }
11769 }
11770 return 0;
11771}
11772
11773static int
11774bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11775{
11776 struct bgp_table_stats ts;
11777 unsigned int i;
11778
11779 if (!bgp->rib[afi][safi])
11780 {
Donald Sharp3c964042016-01-25 23:38:53 -050011781 vty_out (vty, "%% No RIB exists for the specified AFI(%d)/SAFI(%d) %s",
11782 afi, safi, VTY_NEWLINE);
Paul Jakma2815e612006-09-14 02:56:07 +000011783 return CMD_WARNING;
11784 }
11785
11786 memset (&ts, 0, sizeof (ts));
11787 ts.table = bgp->rib[afi][safi];
11788 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
11789
11790 vty_out (vty, "BGP %s RIB statistics%s%s",
11791 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
11792
11793 for (i = 0; i < BGP_STATS_MAX; i++)
11794 {
11795 if (!table_stats_strs[i])
11796 continue;
11797
11798 switch (i)
11799 {
11800#if 0
11801 case BGP_STATS_ASPATH_AVGHOPS:
11802 case BGP_STATS_ASPATH_AVGSIZE:
11803 case BGP_STATS_AVGPLEN:
11804 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11805 vty_out (vty, "%12.2f",
11806 (float)ts.counts[i] / (float)TALLY_SIGFIG);
11807 break;
11808#endif
11809 case BGP_STATS_ASPATH_TOTHOPS:
11810 case BGP_STATS_ASPATH_TOTSIZE:
11811 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11812 vty_out (vty, "%12.2f",
11813 ts.counts[i] ?
11814 (float)ts.counts[i] /
11815 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
11816 : 0);
11817 break;
11818 case BGP_STATS_TOTPLEN:
11819 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11820 vty_out (vty, "%12.2f",
11821 ts.counts[i] ?
11822 (float)ts.counts[i] /
11823 (float)ts.counts[BGP_STATS_PREFIXES]
11824 : 0);
11825 break;
11826 case BGP_STATS_SPACE:
11827 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11828 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
11829 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
11830 break;
Paul Jakma30a22312008-08-15 14:05:22 +010011831 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +000011832 vty_out (vty, "%12.2f%s",
11833 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +000011834 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +000011835 VTY_NEWLINE);
11836 vty_out (vty, "%30s: ", "/8 equivalent ");
11837 vty_out (vty, "%12.2f%s",
11838 (float)ts.counts[BGP_STATS_SPACE] /
11839 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
11840 VTY_NEWLINE);
11841 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
11842 break;
11843 vty_out (vty, "%30s: ", "/24 equivalent ");
11844 vty_out (vty, "%12.2f",
11845 (float)ts.counts[BGP_STATS_SPACE] /
11846 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
11847 break;
11848 default:
11849 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11850 vty_out (vty, "%12llu", ts.counts[i]);
11851 }
11852
11853 vty_out (vty, "%s", VTY_NEWLINE);
11854 }
11855 return CMD_SUCCESS;
11856}
11857
11858static int
11859bgp_table_stats_vty (struct vty *vty, const char *name,
11860 const char *afi_str, const char *safi_str)
11861{
11862 struct bgp *bgp;
11863 afi_t afi;
11864 safi_t safi;
11865
11866 if (name)
11867 bgp = bgp_lookup_by_name (name);
11868 else
11869 bgp = bgp_get_default ();
11870
11871 if (!bgp)
11872 {
Lou Bergerbf1ae6c2016-01-12 13:42:08 -050011873 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
Paul Jakma2815e612006-09-14 02:56:07 +000011874 return CMD_WARNING;
11875 }
11876 if (strncmp (afi_str, "ipv", 3) == 0)
11877 {
11878 if (strncmp (afi_str, "ipv4", 4) == 0)
11879 afi = AFI_IP;
11880 else if (strncmp (afi_str, "ipv6", 4) == 0)
11881 afi = AFI_IP6;
11882 else
11883 {
11884 vty_out (vty, "%% Invalid address family %s%s",
11885 afi_str, VTY_NEWLINE);
11886 return CMD_WARNING;
11887 }
Lou Berger298cc2f2016-01-12 13:42:02 -050011888 switch (safi_str[0]) {
11889 case 'm':
11890 safi = SAFI_MULTICAST;
11891 break;
11892 case 'u':
11893 safi = SAFI_UNICAST;
11894 break;
11895 case 'v':
Donald Sharp3c964042016-01-25 23:38:53 -050011896 safi = SAFI_MPLS_VPN;
Lou Berger298cc2f2016-01-12 13:42:02 -050011897 break;
11898 case 'e':
11899 safi = SAFI_ENCAP;
11900 break;
11901 default:
11902 vty_out (vty, "%% Invalid subsequent address family %s%s",
Paul Jakma2815e612006-09-14 02:56:07 +000011903 safi_str, VTY_NEWLINE);
Lou Berger298cc2f2016-01-12 13:42:02 -050011904 return CMD_WARNING;
11905 }
Paul Jakma2815e612006-09-14 02:56:07 +000011906 }
11907 else
11908 {
Lou Berger298cc2f2016-01-12 13:42:02 -050011909 vty_out (vty, "%% Invalid address family \"%s\"%s",
Paul Jakma2815e612006-09-14 02:56:07 +000011910 afi_str, VTY_NEWLINE);
11911 return CMD_WARNING;
11912 }
11913
Paul Jakma2815e612006-09-14 02:56:07 +000011914 return bgp_table_stats (vty, bgp, afi, safi);
11915}
11916
11917DEFUN (show_bgp_statistics,
11918 show_bgp_statistics_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -050011919 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000011920 SHOW_STR
11921 BGP_STR
11922 "Address family\n"
11923 "Address family\n"
11924 "Address Family modifier\n"
11925 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -050011926 "Address Family modifier\n"
11927 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +000011928 "BGP RIB advertisement statistics\n")
11929{
11930 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11931}
11932
Lou Bergerf9b6c392016-01-12 13:42:09 -050011933ALIAS (show_bgp_statistics,
11934 show_bgp_statistics_vpnv4_cmd,
11935 "show bgp (ipv4) (vpnv4) statistics",
11936 SHOW_STR
11937 BGP_STR
11938 "Address family\n"
11939 "Address Family modifier\n"
11940 "BGP RIB advertisement statistics\n")
11941
Paul Jakma2815e612006-09-14 02:56:07 +000011942DEFUN (show_bgp_statistics_view,
11943 show_bgp_statistics_view_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -050011944 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000011945 SHOW_STR
11946 BGP_STR
11947 "BGP view\n"
11948 "Address family\n"
11949 "Address family\n"
11950 "Address Family modifier\n"
11951 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -050011952 "Address Family modifier\n"
11953 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +000011954 "BGP RIB advertisement statistics\n")
11955{
11956 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11957}
11958
11959ALIAS (show_bgp_statistics_view,
Lou Bergerf9b6c392016-01-12 13:42:09 -050011960 show_bgp_statistics_view_vpnv4_cmd,
11961 "show bgp view WORD (ipv4) (vpnv4) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000011962 SHOW_STR
11963 BGP_STR
11964 "BGP view\n"
11965 "Address family\n"
11966 "Address Family modifier\n"
11967 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +020011968
Paul Jakmaff7924f2006-09-04 01:10:36 +000011969enum bgp_pcounts
11970{
11971 PCOUNT_ADJ_IN = 0,
11972 PCOUNT_DAMPED,
11973 PCOUNT_REMOVED,
11974 PCOUNT_HISTORY,
11975 PCOUNT_STALE,
11976 PCOUNT_VALID,
11977 PCOUNT_ALL,
11978 PCOUNT_COUNTED,
11979 PCOUNT_PFCNT, /* the figure we display to users */
11980 PCOUNT_MAX,
11981};
11982
11983static const char *pcount_strs[] =
11984{
11985 [PCOUNT_ADJ_IN] = "Adj-in",
11986 [PCOUNT_DAMPED] = "Damped",
11987 [PCOUNT_REMOVED] = "Removed",
11988 [PCOUNT_HISTORY] = "History",
11989 [PCOUNT_STALE] = "Stale",
11990 [PCOUNT_VALID] = "Valid",
11991 [PCOUNT_ALL] = "All RIB",
11992 [PCOUNT_COUNTED] = "PfxCt counted",
11993 [PCOUNT_PFCNT] = "Useable",
11994 [PCOUNT_MAX] = NULL,
11995};
11996
Paul Jakma2815e612006-09-14 02:56:07 +000011997struct peer_pcounts
11998{
11999 unsigned int count[PCOUNT_MAX];
12000 const struct peer *peer;
12001 const struct bgp_table *table;
12002};
12003
Paul Jakmaff7924f2006-09-04 01:10:36 +000012004static int
Paul Jakma2815e612006-09-14 02:56:07 +000012005bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +000012006{
12007 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +000012008 struct peer_pcounts *pc = THREAD_ARG (t);
12009 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012010
Paul Jakma2815e612006-09-14 02:56:07 +000012011 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012012 {
12013 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +000012014 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012015
12016 for (ain = rn->adj_in; ain; ain = ain->next)
12017 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +000012018 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012019
Paul Jakmaff7924f2006-09-04 01:10:36 +000012020 for (ri = rn->info; ri; ri = ri->next)
12021 {
12022 char buf[SU_ADDRSTRLEN];
12023
12024 if (ri->peer != peer)
12025 continue;
12026
Paul Jakma2815e612006-09-14 02:56:07 +000012027 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012028
12029 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +000012030 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012031 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +000012032 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012033 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +000012034 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012035 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +000012036 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012037 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +000012038 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +000012039 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +000012040 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012041
12042 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
12043 {
Paul Jakma2815e612006-09-14 02:56:07 +000012044 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +000012045 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012046 plog_warn (peer->log,
12047 "%s [pcount] %s/%d is counted but flags 0x%x",
12048 peer->host,
12049 inet_ntop(rn->p.family, &rn->p.u.prefix,
12050 buf, SU_ADDRSTRLEN),
12051 rn->p.prefixlen,
12052 ri->flags);
12053 }
12054 else
12055 {
Paul Jakma1a392d42006-09-07 00:24:49 +000012056 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012057 plog_warn (peer->log,
12058 "%s [pcount] %s/%d not counted but flags 0x%x",
12059 peer->host,
12060 inet_ntop(rn->p.family, &rn->p.u.prefix,
12061 buf, SU_ADDRSTRLEN),
12062 rn->p.prefixlen,
12063 ri->flags);
12064 }
12065 }
12066 }
Paul Jakma2815e612006-09-14 02:56:07 +000012067 return 0;
12068}
Paul Jakmaff7924f2006-09-04 01:10:36 +000012069
Paul Jakma2815e612006-09-14 02:56:07 +000012070static int
12071bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
12072{
12073 struct peer_pcounts pcounts = { .peer = peer };
12074 unsigned int i;
12075
12076 if (!peer || !peer->bgp || !peer->afc[afi][safi]
12077 || !peer->bgp->rib[afi][safi])
12078 {
12079 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12080 return CMD_WARNING;
12081 }
12082
12083 memset (&pcounts, 0, sizeof(pcounts));
12084 pcounts.peer = peer;
12085 pcounts.table = peer->bgp->rib[afi][safi];
12086
12087 /* in-place call via thread subsystem so as to record execution time
12088 * stats for the thread-walk (i.e. ensure this can't be blamed on
12089 * on just vty_read()).
12090 */
12091 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
12092
Paul Jakmaff7924f2006-09-04 01:10:36 +000012093 vty_out (vty, "Prefix counts for %s, %s%s",
12094 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
12095 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
12096 vty_out (vty, "%sCounts from RIB table walk:%s%s",
12097 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
12098
12099 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +000012100 vty_out (vty, "%20s: %-10d%s",
12101 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012102
Paul Jakma2815e612006-09-14 02:56:07 +000012103 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +000012104 {
12105 vty_out (vty, "%s [pcount] PfxCt drift!%s",
12106 peer->host, VTY_NEWLINE);
12107 vty_out (vty, "Please report this bug, with the above command output%s",
12108 VTY_NEWLINE);
12109 }
12110
12111 return CMD_SUCCESS;
12112}
12113
Lou Bergerf9b6c392016-01-12 13:42:09 -050012114DEFUN (show_ip_bgp_neighbor_prefix_counts,
12115 show_ip_bgp_neighbor_prefix_counts_cmd,
12116 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12117 SHOW_STR
12118 IP_STR
12119 BGP_STR
12120 "Detailed information on TCP and BGP neighbor connections\n"
12121 "Neighbor to display information about\n"
12122 "Neighbor to display information about\n"
12123 "Display detailed prefix count information\n")
12124{
12125 struct peer *peer;
12126
12127 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12128 if (! peer)
12129 return CMD_WARNING;
12130
12131 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
12132}
12133
Paul Jakmaff7924f2006-09-04 01:10:36 +000012134DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
12135 show_bgp_ipv6_neighbor_prefix_counts_cmd,
12136 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12137 SHOW_STR
12138 BGP_STR
12139 "Address family\n"
12140 "Detailed information on TCP and BGP neighbor connections\n"
12141 "Neighbor to display information about\n"
12142 "Neighbor to display information about\n"
12143 "Display detailed prefix count information\n")
12144{
12145 struct peer *peer;
12146
12147 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12148 if (! peer)
12149 return CMD_WARNING;
12150
12151 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
12152}
Lou Bergerf9b6c392016-01-12 13:42:09 -050012153
12154DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
12155 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
12156 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12157 SHOW_STR
12158 IP_STR
12159 BGP_STR
12160 "Address family\n"
12161 "Address Family modifier\n"
12162 "Address Family modifier\n"
12163 "Detailed information on TCP and BGP neighbor connections\n"
12164 "Neighbor to display information about\n"
12165 "Neighbor to display information about\n"
12166 "Display detailed prefix count information\n")
12167{
12168 struct peer *peer;
12169
12170 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12171 if (! peer)
12172 return CMD_WARNING;
12173
12174 if (strncmp (argv[0], "m", 1) == 0)
12175 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
12176
12177 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
12178}
12179
12180DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
12181 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
12182 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12183 SHOW_STR
12184 IP_STR
12185 BGP_STR
12186 "Address family\n"
12187 "Address Family modifier\n"
12188 "Address Family modifier\n"
12189 "Detailed information on TCP and BGP neighbor connections\n"
12190 "Neighbor to display information about\n"
12191 "Neighbor to display information about\n"
12192 "Display detailed prefix count information\n")
12193{
12194 struct peer *peer;
12195
12196 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12197 if (! peer)
12198 return CMD_WARNING;
12199
12200 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
12201}
Paul Jakmaff7924f2006-09-04 01:10:36 +000012202
Lou Berger651b4022016-01-12 13:42:07 -050012203DEFUN (show_bgp_ipv4_safi_neighbor_prefix_counts,
12204 show_bgp_ipv4_safi_neighbor_prefix_counts_cmd,
12205 "show bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
Paul Jakmaff7924f2006-09-04 01:10:36 +000012206 SHOW_STR
Paul Jakmaff7924f2006-09-04 01:10:36 +000012207 BGP_STR
12208 "Address family\n"
12209 "Address Family modifier\n"
12210 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050012211 "Address Family modifier\n"
12212 "Address Family modifier\n"
Paul Jakmaff7924f2006-09-04 01:10:36 +000012213 "Detailed information on TCP and BGP neighbor connections\n"
12214 "Neighbor to display information about\n"
12215 "Neighbor to display information about\n"
12216 "Display detailed prefix count information\n")
12217{
12218 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050012219 safi_t safi;
12220
12221 if (bgp_parse_safi(argv[0], &safi)) {
12222 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12223 return CMD_WARNING;
12224 }
Paul Jakmaff7924f2006-09-04 01:10:36 +000012225
12226 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12227 if (! peer)
12228 return CMD_WARNING;
12229
Lou Berger651b4022016-01-12 13:42:07 -050012230 return bgp_peer_counts (vty, peer, AFI_IP, safi);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012231}
Lou Berger205e6742016-01-12 13:42:11 -050012232
Lou Berger651b4022016-01-12 13:42:07 -050012233DEFUN (show_bgp_ipv6_safi_neighbor_prefix_counts,
12234 show_bgp_ipv6_safi_neighbor_prefix_counts_cmd,
12235 "show bgp ipv6 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12236 SHOW_STR
12237 BGP_STR
12238 "Address family\n"
12239 "Address Family modifier\n"
12240 "Address Family modifier\n"
12241 "Address Family modifier\n"
12242 "Address Family modifier\n"
12243 "Detailed information on TCP and BGP neighbor connections\n"
12244 "Neighbor to display information about\n"
12245 "Neighbor to display information about\n"
12246 "Display detailed prefix count information\n")
12247{
12248 struct peer *peer;
12249 safi_t safi;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012250
Lou Berger651b4022016-01-12 13:42:07 -050012251 if (bgp_parse_safi(argv[0], &safi)) {
12252 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12253 return CMD_WARNING;
12254 }
12255
12256 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12257 if (! peer)
12258 return CMD_WARNING;
12259
12260 return bgp_peer_counts (vty, peer, AFI_IP6, safi);
12261}
Lou Berger651b4022016-01-12 13:42:07 -050012262
12263DEFUN (show_ip_bgp_encap_neighbor_prefix_counts,
12264 show_ip_bgp_encap_neighbor_prefix_counts_cmd,
12265 "show ip bgp encap all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
Paul Jakmaff7924f2006-09-04 01:10:36 +000012266 SHOW_STR
12267 IP_STR
12268 BGP_STR
12269 "Address family\n"
12270 "Address Family modifier\n"
12271 "Address Family modifier\n"
12272 "Detailed information on TCP and BGP neighbor connections\n"
12273 "Neighbor to display information about\n"
12274 "Neighbor to display information about\n"
12275 "Display detailed prefix count information\n")
12276{
12277 struct peer *peer;
12278
12279 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12280 if (! peer)
12281 return CMD_WARNING;
12282
Lou Berger651b4022016-01-12 13:42:07 -050012283 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_ENCAP);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012284}
12285
12286
paul94f2b392005-06-28 12:44:16 +000012287static void
paul718e3742002-12-13 20:15:29 +000012288show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
12289 int in)
12290{
12291 struct bgp_table *table;
12292 struct bgp_adj_in *ain;
12293 struct bgp_adj_out *adj;
12294 unsigned long output_count;
12295 struct bgp_node *rn;
12296 int header1 = 1;
12297 struct bgp *bgp;
12298 int header2 = 1;
12299
paulbb46e942003-10-24 19:02:03 +000012300 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +000012301
12302 if (! bgp)
12303 return;
12304
12305 table = bgp->rib[afi][safi];
12306
12307 output_count = 0;
12308
12309 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
12310 PEER_STATUS_DEFAULT_ORIGINATE))
12311 {
12312 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 +000012313 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12314 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012315
12316 vty_out (vty, "Originating default network 0.0.0.0%s%s",
12317 VTY_NEWLINE, VTY_NEWLINE);
12318 header1 = 0;
12319 }
12320
12321 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12322 if (in)
12323 {
12324 for (ain = rn->adj_in; ain; ain = ain->next)
12325 if (ain->peer == peer)
12326 {
12327 if (header1)
12328 {
12329 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 +000012330 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12331 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012332 header1 = 0;
12333 }
12334 if (header2)
12335 {
12336 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12337 header2 = 0;
12338 }
12339 if (ain->attr)
12340 {
12341 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
12342 output_count++;
12343 }
12344 }
12345 }
12346 else
12347 {
12348 for (adj = rn->adj_out; adj; adj = adj->next)
12349 if (adj->peer == peer)
12350 {
12351 if (header1)
12352 {
12353 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 +000012354 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12355 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012356 header1 = 0;
12357 }
12358 if (header2)
12359 {
12360 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12361 header2 = 0;
12362 }
12363 if (adj->attr)
12364 {
12365 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
12366 output_count++;
12367 }
12368 }
12369 }
12370
12371 if (output_count != 0)
12372 vty_out (vty, "%sTotal number of prefixes %ld%s",
12373 VTY_NEWLINE, output_count, VTY_NEWLINE);
12374}
12375
paul94f2b392005-06-28 12:44:16 +000012376static int
paulbb46e942003-10-24 19:02:03 +000012377peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
12378{
paul718e3742002-12-13 20:15:29 +000012379 if (! peer || ! peer->afc[afi][safi])
12380 {
12381 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12382 return CMD_WARNING;
12383 }
12384
12385 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12386 {
12387 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
12388 VTY_NEWLINE);
12389 return CMD_WARNING;
12390 }
12391
12392 show_adj_route (vty, peer, afi, safi, in);
12393
12394 return CMD_SUCCESS;
12395}
12396
Lou Bergerf9b6c392016-01-12 13:42:09 -050012397DEFUN (show_ip_bgp_view_neighbor_advertised_route,
12398 show_ip_bgp_view_neighbor_advertised_route_cmd,
12399 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12400 SHOW_STR
12401 IP_STR
12402 BGP_STR
12403 "BGP view\n"
12404 "View name\n"
12405 "Detailed information on TCP and BGP neighbor connections\n"
12406 "Neighbor to display information about\n"
12407 "Neighbor to display information about\n"
12408 "Display the routes advertised to a BGP neighbor\n")
12409{
12410 struct peer *peer;
12411
12412 if (argc == 2)
12413 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12414 else
12415 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12416
12417 if (! peer)
12418 return CMD_WARNING;
12419
12420 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
12421}
12422
12423ALIAS (show_ip_bgp_view_neighbor_advertised_route,
12424 show_ip_bgp_neighbor_advertised_route_cmd,
12425 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12426 SHOW_STR
12427 IP_STR
12428 BGP_STR
12429 "Detailed information on TCP and BGP neighbor connections\n"
12430 "Neighbor to display information about\n"
12431 "Neighbor to display information about\n"
12432 "Display the routes advertised to a BGP neighbor\n")
12433
12434DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
12435 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
12436 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12437 SHOW_STR
12438 IP_STR
12439 BGP_STR
12440 "Address family\n"
12441 "Address Family modifier\n"
12442 "Address Family modifier\n"
12443 "Detailed information on TCP and BGP neighbor connections\n"
12444 "Neighbor to display information about\n"
12445 "Neighbor to display information about\n"
12446 "Display the routes advertised to a BGP neighbor\n")
12447{
12448 struct peer *peer;
12449
12450 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12451 if (! peer)
12452 return CMD_WARNING;
12453
12454 if (strncmp (argv[0], "m", 1) == 0)
12455 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
12456
12457 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
12458}
12459
Lou Bergerf9b6c392016-01-12 13:42:09 -050012460DEFUN (show_bgp_view_neighbor_advertised_route,
12461 show_bgp_view_neighbor_advertised_route_cmd,
12462 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12463 SHOW_STR
12464 BGP_STR
12465 "BGP view\n"
12466 "View name\n"
12467 "Detailed information on TCP and BGP neighbor connections\n"
12468 "Neighbor to display information about\n"
12469 "Neighbor to display information about\n"
12470 "Display the routes advertised to a BGP neighbor\n")
12471{
12472 struct peer *peer;
12473
12474 if (argc == 2)
12475 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12476 else
12477 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12478
12479 if (! peer)
12480 return CMD_WARNING;
12481
12482 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
12483}
12484
12485DEFUN (show_bgp_view_neighbor_received_routes,
12486 show_bgp_view_neighbor_received_routes_cmd,
12487 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
12488 SHOW_STR
12489 BGP_STR
12490 "BGP view\n"
12491 "View name\n"
12492 "Detailed information on TCP and BGP neighbor connections\n"
12493 "Neighbor to display information about\n"
12494 "Neighbor to display information about\n"
12495 "Display the received routes from neighbor\n")
12496{
12497 struct peer *peer;
12498
12499 if (argc == 2)
12500 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12501 else
12502 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12503
12504 if (! peer)
12505 return CMD_WARNING;
12506
12507 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
12508}
12509
12510ALIAS (show_bgp_view_neighbor_advertised_route,
12511 show_bgp_neighbor_advertised_route_cmd,
12512 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12513 SHOW_STR
12514 BGP_STR
12515 "Detailed information on TCP and BGP neighbor connections\n"
12516 "Neighbor to display information about\n"
12517 "Neighbor to display information about\n"
12518 "Display the routes advertised to a BGP neighbor\n")
12519
12520ALIAS (show_bgp_view_neighbor_advertised_route,
12521 show_bgp_ipv6_neighbor_advertised_route_cmd,
12522 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12523 SHOW_STR
12524 BGP_STR
12525 "Address family\n"
12526 "Detailed information on TCP and BGP neighbor connections\n"
12527 "Neighbor to display information about\n"
12528 "Neighbor to display information about\n"
12529 "Display the routes advertised to a BGP neighbor\n")
12530
12531/* old command */
12532ALIAS (show_bgp_view_neighbor_advertised_route,
12533 ipv6_bgp_neighbor_advertised_route_cmd,
12534 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12535 SHOW_STR
12536 IPV6_STR
12537 BGP_STR
12538 "Detailed information on TCP and BGP neighbor connections\n"
12539 "Neighbor to display information about\n"
12540 "Neighbor to display information about\n"
12541 "Display the routes advertised to a BGP neighbor\n")
12542
12543/* old command */
12544DEFUN (ipv6_mbgp_neighbor_advertised_route,
12545 ipv6_mbgp_neighbor_advertised_route_cmd,
12546 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12547 SHOW_STR
12548 IPV6_STR
12549 MBGP_STR
12550 "Detailed information on TCP and BGP neighbor connections\n"
12551 "Neighbor to display information about\n"
12552 "Neighbor to display information about\n"
12553 "Display the routes advertised to a BGP neighbor\n")
12554{
12555 struct peer *peer;
12556
12557 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12558 if (! peer)
12559 return CMD_WARNING;
12560
12561 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
12562}
Lou Bergerf9b6c392016-01-12 13:42:09 -050012563
12564DEFUN (show_ip_bgp_view_neighbor_received_routes,
12565 show_ip_bgp_view_neighbor_received_routes_cmd,
12566 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
12567 SHOW_STR
12568 IP_STR
12569 BGP_STR
12570 "BGP view\n"
12571 "View name\n"
12572 "Detailed information on TCP and BGP neighbor connections\n"
12573 "Neighbor to display information about\n"
12574 "Neighbor to display information about\n"
12575 "Display the received routes from neighbor\n")
12576{
12577 struct peer *peer;
12578
12579 if (argc == 2)
12580 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12581 else
12582 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12583
12584 if (! peer)
12585 return CMD_WARNING;
12586
12587 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
12588}
12589
12590ALIAS (show_ip_bgp_view_neighbor_received_routes,
12591 show_ip_bgp_neighbor_received_routes_cmd,
12592 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12593 SHOW_STR
12594 IP_STR
12595 BGP_STR
12596 "Detailed information on TCP and BGP neighbor connections\n"
12597 "Neighbor to display information about\n"
12598 "Neighbor to display information about\n"
12599 "Display the received routes from neighbor\n")
12600
12601ALIAS (show_bgp_view_neighbor_received_routes,
12602 show_bgp_ipv6_neighbor_received_routes_cmd,
12603 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
12604 SHOW_STR
12605 BGP_STR
12606 "Address family\n"
12607 "Detailed information on TCP and BGP neighbor connections\n"
12608 "Neighbor to display information about\n"
12609 "Neighbor to display information about\n"
12610 "Display the received routes from neighbor\n")
12611
12612DEFUN (show_bgp_neighbor_received_prefix_filter,
12613 show_bgp_neighbor_received_prefix_filter_cmd,
12614 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
12615 SHOW_STR
12616 BGP_STR
12617 "Detailed information on TCP and BGP neighbor connections\n"
12618 "Neighbor to display information about\n"
12619 "Neighbor to display information about\n"
12620 "Display information received from a BGP neighbor\n"
12621 "Display the prefixlist filter\n")
12622{
12623 char name[BUFSIZ];
12624 union sockunion su;
12625 struct peer *peer;
12626 int count, ret;
12627
12628 ret = str2sockunion (argv[0], &su);
12629 if (ret < 0)
12630 {
12631 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
12632 return CMD_WARNING;
12633 }
12634
12635 peer = peer_lookup (NULL, &su);
12636 if (! peer)
12637 return CMD_WARNING;
12638
12639 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12640 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12641 if (count)
12642 {
12643 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12644 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12645 }
12646
12647 return CMD_SUCCESS;
12648}
12649
12650/* old command */
12651ALIAS (show_bgp_view_neighbor_received_routes,
12652 ipv6_bgp_neighbor_received_routes_cmd,
12653 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12654 SHOW_STR
12655 IPV6_STR
12656 BGP_STR
12657 "Detailed information on TCP and BGP neighbor connections\n"
12658 "Neighbor to display information about\n"
12659 "Neighbor to display information about\n"
12660 "Display the received routes from neighbor\n")
12661
12662/* old command */
12663DEFUN (ipv6_mbgp_neighbor_received_routes,
12664 ipv6_mbgp_neighbor_received_routes_cmd,
12665 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12666 SHOW_STR
12667 IPV6_STR
12668 MBGP_STR
12669 "Detailed information on TCP and BGP neighbor connections\n"
12670 "Neighbor to display information about\n"
12671 "Neighbor to display information about\n"
12672 "Display the received routes from neighbor\n")
12673{
12674 struct peer *peer;
12675
12676 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12677 if (! peer)
12678 return CMD_WARNING;
12679
12680 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
12681}
12682
12683DEFUN (show_bgp_view_neighbor_received_prefix_filter,
12684 show_bgp_view_neighbor_received_prefix_filter_cmd,
12685 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
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 information received from a BGP neighbor\n"
12694 "Display the prefixlist filter\n")
12695{
12696 char name[BUFSIZ];
12697 union sockunion su;
12698 struct peer *peer;
12699 struct bgp *bgp;
12700 int count, ret;
12701
12702 /* BGP structure lookup. */
12703 bgp = bgp_lookup_by_name (argv[0]);
12704 if (bgp == NULL)
12705 {
12706 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12707 return CMD_WARNING;
12708 }
12709
12710 ret = str2sockunion (argv[1], &su);
12711 if (ret < 0)
12712 {
12713 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
12714 return CMD_WARNING;
12715 }
12716
12717 peer = peer_lookup (bgp, &su);
12718 if (! peer)
12719 return CMD_WARNING;
12720
12721 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12722 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12723 if (count)
12724 {
12725 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12726 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12727 }
12728
12729 return CMD_SUCCESS;
12730}
12731
12732
12733DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12734 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
12735 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
12736 SHOW_STR
12737 IP_STR
12738 BGP_STR
12739 "Address family\n"
12740 "Address Family modifier\n"
12741 "Address Family modifier\n"
12742 "Detailed information on TCP and BGP neighbor connections\n"
12743 "Neighbor to display information about\n"
12744 "Neighbor to display information about\n"
12745 "Display the received routes from neighbor\n")
12746{
12747 struct peer *peer;
12748
12749 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12750 if (! peer)
12751 return CMD_WARNING;
12752
12753 if (strncmp (argv[0], "m", 1) == 0)
12754 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
12755
12756 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
12757}
12758
Lou Berger651b4022016-01-12 13:42:07 -050012759DEFUN (show_bgp_ipv4_safi_neighbor_advertised_route,
12760 show_bgp_ipv4_safi_neighbor_advertised_route_cmd,
12761 "show bgp ipv4 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012762 SHOW_STR
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012763 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050012764 "Address Family modifier\n"
12765 "Address Family modifier\n"
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012766 "Detailed information on TCP and BGP neighbor connections\n"
12767 "Neighbor to display information about\n"
12768 "Neighbor to display information about\n"
12769 "Display the routes advertised to a BGP neighbor\n")
12770{
12771 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050012772 safi_t safi;
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012773
Lou Berger651b4022016-01-12 13:42:07 -050012774 if (bgp_parse_safi(argv[0], &safi)) {
12775 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012776 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050012777 }
paul718e3742002-12-13 20:15:29 +000012778
paulbb46e942003-10-24 19:02:03 +000012779 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12780 if (! peer)
12781 return CMD_WARNING;
12782
Lou Berger651b4022016-01-12 13:42:07 -050012783 return peer_adj_routes (vty, peer, AFI_IP, safi, 0);
12784}
Lou Berger205e6742016-01-12 13:42:11 -050012785
Lou Berger651b4022016-01-12 13:42:07 -050012786DEFUN (show_bgp_ipv6_safi_neighbor_advertised_route,
12787 show_bgp_ipv6_safi_neighbor_advertised_route_cmd,
12788 "show bgp ipv6 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12789 SHOW_STR
12790 BGP_STR
12791 "Address Family modifier\n"
12792 "Address Family modifier\n"
12793 "Address Family modifier\n"
12794 "Detailed information on TCP and BGP neighbor connections\n"
12795 "Neighbor to display information about\n"
12796 "Neighbor to display information about\n"
12797 "Display the routes advertised to a BGP neighbor\n")
12798{
12799 struct peer *peer;
12800 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000012801
Lou Berger651b4022016-01-12 13:42:07 -050012802 if (bgp_parse_safi(argv[0], &safi)) {
12803 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12804 return CMD_WARNING;
12805 }
12806
12807 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12808 if (! peer)
12809 return CMD_WARNING;
12810
12811 return peer_adj_routes (vty, peer, AFI_IP6, safi, 0);
paul718e3742002-12-13 20:15:29 +000012812}
12813
Lou Bergerf9b6c392016-01-12 13:42:09 -050012814DEFUN (show_bgp_view_ipv6_neighbor_advertised_route,
Lou Berger651b4022016-01-12 13:42:07 -050012815 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
12816 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
paulbb46e942003-10-24 19:02:03 +000012817 SHOW_STR
12818 BGP_STR
12819 "BGP view\n"
12820 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050012821 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000012822 "Detailed information on TCP and BGP neighbor connections\n"
12823 "Neighbor to display information about\n"
12824 "Neighbor to display information about\n"
12825 "Display the routes advertised to a BGP neighbor\n")
12826{
12827 struct peer *peer;
12828
12829 if (argc == 2)
12830 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12831 else
12832 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12833
12834 if (! peer)
12835 return CMD_WARNING;
12836
12837 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
12838}
12839
Lou Bergerf9b6c392016-01-12 13:42:09 -050012840DEFUN (show_bgp_view_ipv6_neighbor_received_routes,
Lou Berger651b4022016-01-12 13:42:07 -050012841 show_bgp_view_ipv6_neighbor_received_routes_cmd,
12842 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
paulbb46e942003-10-24 19:02:03 +000012843 SHOW_STR
12844 BGP_STR
12845 "BGP view\n"
12846 "View name\n"
12847 "Address family\n"
12848 "Detailed information on TCP and BGP neighbor connections\n"
12849 "Neighbor to display information about\n"
12850 "Neighbor to display information about\n"
paulbb46e942003-10-24 19:02:03 +000012851 "Display the received routes from neighbor\n")
12852{
12853 struct peer *peer;
12854
12855 if (argc == 2)
12856 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12857 else
12858 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12859
12860 if (! peer)
12861 return CMD_WARNING;
12862
12863 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
12864}
Lou Berger651b4022016-01-12 13:42:07 -050012865
12866DEFUN (show_bgp_ipv4_safi_neighbor_received_routes,
12867 show_bgp_ipv4_safi_neighbor_received_routes_cmd,
12868 "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 +010012869 SHOW_STR
paul718e3742002-12-13 20:15:29 +000012870 BGP_STR
12871 "Address family\n"
12872 "Address Family modifier\n"
12873 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050012874 "Address Family modifier\n"
12875 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000012876 "Detailed information on TCP and BGP neighbor connections\n"
12877 "Neighbor to display information about\n"
12878 "Neighbor to display information about\n"
12879 "Display the received routes from neighbor\n")
12880{
paulbb46e942003-10-24 19:02:03 +000012881 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050012882 safi_t safi;
12883
12884 if (bgp_parse_safi(argv[0], &safi)) {
12885 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12886 return CMD_WARNING;
12887 }
paul718e3742002-12-13 20:15:29 +000012888
paulbb46e942003-10-24 19:02:03 +000012889 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12890 if (! peer)
12891 return CMD_WARNING;
12892
Lou Berger651b4022016-01-12 13:42:07 -050012893 return peer_adj_routes (vty, peer, AFI_IP, safi, 1);
paul718e3742002-12-13 20:15:29 +000012894}
Lou Berger205e6742016-01-12 13:42:11 -050012895
Lou Berger651b4022016-01-12 13:42:07 -050012896DEFUN (show_bgp_ipv6_safi_neighbor_received_routes,
12897 show_bgp_ipv6_safi_neighbor_received_routes_cmd,
12898 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) received-routes",
12899 SHOW_STR
12900 BGP_STR
12901 "Address family\n"
12902 "Address Family modifier\n"
12903 "Address Family modifier\n"
12904 "Address Family modifier\n"
12905 "Address Family modifier\n"
12906 "Detailed information on TCP and BGP neighbor connections\n"
12907 "Neighbor to display information about\n"
12908 "Neighbor to display information about\n"
12909 "Display the received routes from neighbor\n")
12910{
12911 struct peer *peer;
12912 safi_t safi;
12913
12914 if (bgp_parse_safi(argv[0], &safi)) {
12915 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12916 return CMD_WARNING;
12917 }
12918
12919 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12920 if (! peer)
12921 return CMD_WARNING;
12922
12923 return peer_adj_routes (vty, peer, AFI_IP6, safi, 1);
12924}
paul718e3742002-12-13 20:15:29 +000012925
Michael Lambert95cbbd22010-07-23 14:43:04 -040012926DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
12927 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040012928 "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 -040012929 SHOW_STR
12930 BGP_STR
12931 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000012932 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040012933 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040012934 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040012935 "Address family modifier\n"
12936 "Address family modifier\n"
12937 "Detailed information on TCP and BGP neighbor connections\n"
12938 "Neighbor to display information about\n"
12939 "Neighbor to display information about\n"
12940 "Display the advertised routes to neighbor\n"
12941 "Display the received routes from neighbor\n")
12942{
12943 int afi;
12944 int safi;
12945 int in;
12946 struct peer *peer;
12947
David Lamparter94bad672015-03-03 08:52:22 +010012948 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012949
12950 if (! peer)
12951 return CMD_WARNING;
12952
Michael Lambert95cbbd22010-07-23 14:43:04 -040012953 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
12954 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12955 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040012956
12957 return peer_adj_routes (vty, peer, afi, safi, in);
12958}
12959
Lou Bergerf9b6c392016-01-12 13:42:09 -050012960DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
12961 show_ip_bgp_neighbor_received_prefix_filter_cmd,
12962 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
12963 SHOW_STR
12964 IP_STR
12965 BGP_STR
12966 "Detailed information on TCP and BGP neighbor connections\n"
12967 "Neighbor to display information about\n"
12968 "Neighbor to display information about\n"
12969 "Display information received from a BGP neighbor\n"
12970 "Display the prefixlist filter\n")
12971{
12972 char name[BUFSIZ];
12973 union sockunion su;
12974 struct peer *peer;
12975 int count, ret;
12976
12977 ret = str2sockunion (argv[0], &su);
12978 if (ret < 0)
12979 {
12980 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
12981 return CMD_WARNING;
12982 }
12983
12984 peer = peer_lookup (NULL, &su);
12985 if (! peer)
12986 return CMD_WARNING;
12987
12988 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
12989 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
12990 if (count)
12991 {
12992 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
12993 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
12994 }
12995
12996 return CMD_SUCCESS;
12997}
12998
12999DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
13000 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
13001 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
13002 SHOW_STR
13003 IP_STR
13004 BGP_STR
13005 "Address family\n"
13006 "Address Family modifier\n"
13007 "Address Family modifier\n"
13008 "Detailed information on TCP and BGP neighbor connections\n"
13009 "Neighbor to display information about\n"
13010 "Neighbor to display information about\n"
13011 "Display information received from a BGP neighbor\n"
13012 "Display the prefixlist filter\n")
13013{
13014 char name[BUFSIZ];
13015 union sockunion su;
13016 struct peer *peer;
13017 int count, ret;
13018
13019 ret = str2sockunion (argv[1], &su);
13020 if (ret < 0)
13021 {
13022 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13023 return CMD_WARNING;
13024 }
13025
13026 peer = peer_lookup (NULL, &su);
13027 if (! peer)
13028 return CMD_WARNING;
13029
13030 if (strncmp (argv[0], "m", 1) == 0)
13031 {
13032 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
13033 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13034 if (count)
13035 {
13036 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
13037 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13038 }
13039 }
13040 else
13041 {
13042 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
13043 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13044 if (count)
13045 {
13046 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13047 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13048 }
13049 }
13050
13051 return CMD_SUCCESS;
13052}
13053
13054ALIAS (show_bgp_view_neighbor_received_routes,
13055 show_bgp_neighbor_received_routes_cmd,
13056 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
13057 SHOW_STR
13058 BGP_STR
13059 "Detailed information on TCP and BGP neighbor connections\n"
13060 "Neighbor to display information about\n"
13061 "Neighbor to display information about\n"
13062 "Display the received routes from neighbor\n")
13063
Lou Berger651b4022016-01-12 13:42:07 -050013064DEFUN (show_bgp_ipv4_safi_neighbor_received_prefix_filter,
13065 show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd,
13066 "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 +000013067 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013068 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013069 IP_STR
13070 "Address Family modifier\n"
13071 "Address Family modifier\n"
13072 "Address Family modifier\n"
13073 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000013074 "Detailed information on TCP and BGP neighbor connections\n"
13075 "Neighbor to display information about\n"
13076 "Neighbor to display information about\n"
13077 "Display information received from a BGP neighbor\n"
13078 "Display the prefixlist filter\n")
13079{
13080 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013081 union sockunion su;
paul718e3742002-12-13 20:15:29 +000013082 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013083 int count, ret;
Lou Berger651b4022016-01-12 13:42:07 -050013084 safi_t safi;
paul718e3742002-12-13 20:15:29 +000013085
Lou Berger651b4022016-01-12 13:42:07 -050013086 if (bgp_parse_safi(argv[0], &safi)) {
13087 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000013088 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050013089 }
paul718e3742002-12-13 20:15:29 +000013090
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013091 ret = str2sockunion (argv[1], &su);
13092 if (ret < 0)
13093 {
13094 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13095 return CMD_WARNING;
13096 }
paul718e3742002-12-13 20:15:29 +000013097
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013098 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000013099 if (! peer)
13100 return CMD_WARNING;
13101
Lou Berger651b4022016-01-12 13:42:07 -050013102 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, safi);
13103 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13104 if (count) {
13105 vty_out (vty, "Address family: IPv4 %s%s", safi2str(safi), VTY_NEWLINE);
13106 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13107 }
paul718e3742002-12-13 20:15:29 +000013108
13109 return CMD_SUCCESS;
13110}
Lou Berger205e6742016-01-12 13:42:11 -050013111
Lou Berger651b4022016-01-12 13:42:07 -050013112DEFUN (show_bgp_ipv6_safi_neighbor_received_prefix_filter,
13113 show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd,
13114 "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 +000013115 SHOW_STR
13116 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013117 IP_STR
13118 "Address Family modifier\n"
13119 "Address Family modifier\n"
13120 "Address Family modifier\n"
13121 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000013122 "Detailed information on TCP and BGP neighbor connections\n"
13123 "Neighbor to display information about\n"
13124 "Neighbor to display information about\n"
Lou Berger651b4022016-01-12 13:42:07 -050013125 "Display information received from a BGP neighbor\n"
13126 "Display the prefixlist filter\n")
13127{
13128 char name[BUFSIZ];
13129 union sockunion su;
13130 struct peer *peer;
13131 int count, ret;
13132 safi_t safi;
13133
13134 if (bgp_parse_safi(argv[0], &safi)) {
13135 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13136 return CMD_WARNING;
13137 }
13138
13139 ret = str2sockunion (argv[1], &su);
13140 if (ret < 0)
13141 {
13142 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13143 return CMD_WARNING;
13144 }
13145
13146 peer = peer_lookup (NULL, &su);
13147 if (! peer)
13148 return CMD_WARNING;
13149
13150 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, safi);
13151 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13152 if (count) {
13153 vty_out (vty, "Address family: IPv6 %s%s", safi2str(safi), VTY_NEWLINE);
13154 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13155 }
13156
13157 return CMD_SUCCESS;
13158}
paul718e3742002-12-13 20:15:29 +000013159
Lou Bergerf9b6c392016-01-12 13:42:09 -050013160DEFUN (show_bgp_ipv6_neighbor_received_prefix_filter,
Lou Berger651b4022016-01-12 13:42:07 -050013161 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
13162 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
paul718e3742002-12-13 20:15:29 +000013163 SHOW_STR
13164 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013165 "Address family\n"
paul718e3742002-12-13 20:15:29 +000013166 "Detailed information on TCP and BGP neighbor connections\n"
13167 "Neighbor to display information about\n"
13168 "Neighbor to display information about\n"
13169 "Display information received from a BGP neighbor\n"
13170 "Display the prefixlist filter\n")
13171{
13172 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013173 union sockunion su;
paul718e3742002-12-13 20:15:29 +000013174 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013175 int count, ret;
paul718e3742002-12-13 20:15:29 +000013176
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013177 ret = str2sockunion (argv[0], &su);
13178 if (ret < 0)
13179 {
13180 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
13181 return CMD_WARNING;
13182 }
paul718e3742002-12-13 20:15:29 +000013183
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013184 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000013185 if (! peer)
13186 return CMD_WARNING;
13187
13188 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13189 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13190 if (count)
13191 {
13192 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13193 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13194 }
13195
13196 return CMD_SUCCESS;
13197}
13198
Lou Bergerf9b6c392016-01-12 13:42:09 -050013199DEFUN (show_bgp_view_ipv6_neighbor_received_prefix_filter,
Lou Berger651b4022016-01-12 13:42:07 -050013200 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
13201 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
paulbb46e942003-10-24 19:02:03 +000013202 SHOW_STR
13203 BGP_STR
13204 "BGP view\n"
13205 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050013206 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000013207 "Detailed information on TCP and BGP neighbor connections\n"
13208 "Neighbor to display information about\n"
13209 "Neighbor to display information about\n"
13210 "Display information received from a BGP neighbor\n"
13211 "Display the prefixlist filter\n")
13212{
13213 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013214 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000013215 struct peer *peer;
13216 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013217 int count, ret;
paulbb46e942003-10-24 19:02:03 +000013218
13219 /* BGP structure lookup. */
13220 bgp = bgp_lookup_by_name (argv[0]);
13221 if (bgp == NULL)
13222 {
13223 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13224 return CMD_WARNING;
13225 }
13226
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013227 ret = str2sockunion (argv[1], &su);
13228 if (ret < 0)
13229 {
13230 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13231 return CMD_WARNING;
13232 }
paulbb46e942003-10-24 19:02:03 +000013233
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013234 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000013235 if (! peer)
13236 return CMD_WARNING;
13237
13238 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13239 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13240 if (count)
13241 {
13242 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13243 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13244 }
13245
13246 return CMD_SUCCESS;
13247}
David Lamparter6b0655a2014-06-04 06:53:35 +020013248
paul94f2b392005-06-28 12:44:16 +000013249static int
paulbb46e942003-10-24 19:02:03 +000013250bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000013251 safi_t safi, enum bgp_show_type type)
13252{
paul718e3742002-12-13 20:15:29 +000013253 if (! peer || ! peer->afc[afi][safi])
13254 {
13255 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000013256 return CMD_WARNING;
13257 }
13258
ajs5a646652004-11-05 01:25:55 +000013259 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000013260}
Lou Bergerf9b6c392016-01-12 13:42:09 -050013261DEFUN (show_ip_bgp_neighbor_routes,
13262 show_ip_bgp_neighbor_routes_cmd,
13263 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
13264 SHOW_STR
13265 IP_STR
13266 BGP_STR
13267 "Detailed information on TCP and BGP neighbor connections\n"
13268 "Neighbor to display information about\n"
13269 "Neighbor to display information about\n"
13270 "Display routes learned from neighbor\n")
13271{
13272 struct peer *peer;
13273
13274 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13275 if (! peer)
13276 return CMD_WARNING;
13277
13278 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13279 bgp_show_type_neighbor);
13280}
13281
13282DEFUN (show_ip_bgp_neighbor_flap,
13283 show_ip_bgp_neighbor_flap_cmd,
13284 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
13285 SHOW_STR
13286 IP_STR
13287 BGP_STR
13288 "Detailed information on TCP and BGP neighbor connections\n"
13289 "Neighbor to display information about\n"
13290 "Neighbor to display information about\n"
13291 "Display flap statistics of the routes learned from neighbor\n")
13292{
13293 struct peer *peer;
13294
13295 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13296 if (! peer)
13297 return CMD_WARNING;
13298
13299 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13300 bgp_show_type_flap_neighbor);
13301}
13302
13303DEFUN (show_ip_bgp_neighbor_damp,
13304 show_ip_bgp_neighbor_damp_cmd,
13305 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
13306 SHOW_STR
13307 IP_STR
13308 BGP_STR
13309 "Detailed information on TCP and BGP neighbor connections\n"
13310 "Neighbor to display information about\n"
13311 "Neighbor to display information about\n"
13312 "Display the dampened routes received from neighbor\n")
13313{
13314 struct peer *peer;
13315
13316 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13317 if (! peer)
13318 return CMD_WARNING;
13319
13320 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13321 bgp_show_type_damp_neighbor);
13322}
13323
13324DEFUN (show_ip_bgp_ipv4_neighbor_routes,
13325 show_ip_bgp_ipv4_neighbor_routes_cmd,
13326 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
13327 SHOW_STR
13328 IP_STR
13329 BGP_STR
13330 "Address family\n"
13331 "Address Family modifier\n"
13332 "Address Family modifier\n"
13333 "Detailed information on TCP and BGP neighbor connections\n"
13334 "Neighbor to display information about\n"
13335 "Neighbor to display information about\n"
13336 "Display routes learned from neighbor\n")
13337{
13338 struct peer *peer;
13339
13340 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13341 if (! peer)
13342 return CMD_WARNING;
13343
13344 if (strncmp (argv[0], "m", 1) == 0)
13345 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
13346 bgp_show_type_neighbor);
13347
13348 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13349 bgp_show_type_neighbor);
13350}
13351
13352DEFUN (show_ip_bgp_view_rsclient,
13353 show_ip_bgp_view_rsclient_cmd,
13354 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
13355 SHOW_STR
13356 IP_STR
13357 BGP_STR
13358 "BGP view\n"
13359 "View name\n"
13360 "Information about Route Server Client\n"
13361 NEIGHBOR_ADDR_STR)
13362{
13363 struct bgp_table *table;
13364 struct peer *peer;
13365
13366 if (argc == 2)
13367 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13368 else
13369 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13370
13371 if (! peer)
13372 return CMD_WARNING;
13373
13374 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13375 {
13376 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13377 VTY_NEWLINE);
13378 return CMD_WARNING;
13379 }
13380
13381 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13382 PEER_FLAG_RSERVER_CLIENT))
13383 {
13384 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13385 VTY_NEWLINE);
13386 return CMD_WARNING;
13387 }
13388
13389 table = peer->rib[AFI_IP][SAFI_UNICAST];
13390
13391 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
13392}
13393
13394ALIAS (show_ip_bgp_view_rsclient,
13395 show_ip_bgp_rsclient_cmd,
13396 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
13397 SHOW_STR
13398 IP_STR
13399 BGP_STR
13400 "Information about Route Server Client\n"
13401 NEIGHBOR_ADDR_STR)
13402
13403DEFUN (show_bgp_view_ipv4_safi_rsclient,
13404 show_bgp_view_ipv4_safi_rsclient_cmd,
13405 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
13406 SHOW_STR
13407 BGP_STR
13408 "BGP view\n"
13409 "View name\n"
13410 "Address family\n"
13411 "Address Family modifier\n"
13412 "Address Family modifier\n"
13413 "Information about Route Server Client\n"
13414 NEIGHBOR_ADDR_STR)
13415{
13416 struct bgp_table *table;
13417 struct peer *peer;
13418 safi_t safi;
13419
13420 if (argc == 3) {
13421 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13422 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13423 } else {
13424 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13425 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13426 }
13427
13428 if (! peer)
13429 return CMD_WARNING;
13430
13431 if (! peer->afc[AFI_IP][safi])
13432 {
13433 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13434 VTY_NEWLINE);
13435 return CMD_WARNING;
13436 }
13437
13438 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13439 PEER_FLAG_RSERVER_CLIENT))
13440 {
13441 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13442 VTY_NEWLINE);
13443 return CMD_WARNING;
13444 }
13445
13446 table = peer->rib[AFI_IP][safi];
13447
13448 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
13449}
13450
13451ALIAS (show_bgp_view_ipv4_safi_rsclient,
13452 show_bgp_ipv4_safi_rsclient_cmd,
13453 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
13454 SHOW_STR
13455 BGP_STR
13456 "Address family\n"
13457 "Address Family modifier\n"
13458 "Address Family modifier\n"
13459 "Information about Route Server Client\n"
13460 NEIGHBOR_ADDR_STR)
13461
13462DEFUN (show_ip_bgp_view_rsclient_route,
13463 show_ip_bgp_view_rsclient_route_cmd,
13464 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13465 SHOW_STR
13466 IP_STR
13467 BGP_STR
13468 "BGP view\n"
13469 "View name\n"
13470 "Information about Route Server Client\n"
13471 NEIGHBOR_ADDR_STR
13472 "Network in the BGP routing table to display\n")
13473{
13474 struct bgp *bgp;
13475 struct peer *peer;
13476
13477 /* BGP structure lookup. */
13478 if (argc == 3)
13479 {
13480 bgp = bgp_lookup_by_name (argv[0]);
13481 if (bgp == NULL)
13482 {
13483 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13484 return CMD_WARNING;
13485 }
13486 }
13487 else
13488 {
13489 bgp = bgp_get_default ();
13490 if (bgp == NULL)
13491 {
13492 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13493 return CMD_WARNING;
13494 }
13495 }
13496
13497 if (argc == 3)
13498 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13499 else
13500 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13501
13502 if (! peer)
13503 return CMD_WARNING;
13504
13505 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13506 {
13507 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13508 VTY_NEWLINE);
13509 return CMD_WARNING;
13510}
13511
13512 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13513 PEER_FLAG_RSERVER_CLIENT))
13514 {
13515 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13516 VTY_NEWLINE);
13517 return CMD_WARNING;
13518 }
13519
13520 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
13521 (argc == 3) ? argv[2] : argv[1],
13522 AFI_IP, SAFI_UNICAST, NULL, 0);
13523}
13524
13525ALIAS (show_ip_bgp_view_rsclient_route,
13526 show_ip_bgp_rsclient_route_cmd,
13527 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13528 SHOW_STR
13529 IP_STR
13530 BGP_STR
13531 "Information about Route Server Client\n"
13532 NEIGHBOR_ADDR_STR
13533 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +000013534
Lou Berger651b4022016-01-12 13:42:07 -050013535DEFUN (show_bgp_ipv4_safi_neighbor_flap,
13536 show_bgp_ipv4_safi_neighbor_flap_cmd,
13537 "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paul718e3742002-12-13 20:15:29 +000013538 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013539 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013540 "Address Family Modifier\n"
13541 "Address Family Modifier\n"
13542 "Address Family Modifier\n"
13543 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +000013544 "Detailed information on TCP and BGP neighbor connections\n"
13545 "Neighbor to display information about\n"
13546 "Neighbor to display information about\n"
13547 "Display flap statistics of the routes learned from neighbor\n")
13548{
paulbb46e942003-10-24 19:02:03 +000013549 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013550 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000013551
Lou Berger651b4022016-01-12 13:42:07 -050013552 if (bgp_parse_safi(argv[0], &safi)) {
13553 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13554 return CMD_WARNING;
13555 }
13556
13557 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulbb46e942003-10-24 19:02:03 +000013558 if (! peer)
13559 return CMD_WARNING;
13560
Lou Berger651b4022016-01-12 13:42:07 -050013561 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013562 bgp_show_type_flap_neighbor);
13563}
Lou Berger205e6742016-01-12 13:42:11 -050013564
Lou Berger651b4022016-01-12 13:42:07 -050013565DEFUN (show_bgp_ipv6_safi_neighbor_flap,
13566 show_bgp_ipv6_safi_neighbor_flap_cmd,
13567 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paul718e3742002-12-13 20:15:29 +000013568 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013569 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013570 "Address Family Modifier\n"
13571 "Address Family Modifier\n"
13572 "Address Family Modifier\n"
13573 "Address Family Modifier\n"
13574 "Detailed information on TCP and BGP neighbor connections\n"
13575 "Neighbor to display information about\n"
13576 "Neighbor to display information about\n"
13577 "Display flap statistics of the routes learned from neighbor\n")
13578{
13579 struct peer *peer;
13580 safi_t safi;
13581
13582 if (bgp_parse_safi(argv[0], &safi)) {
13583 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13584 return CMD_WARNING;
13585 }
13586
13587 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13588 if (! peer)
13589 return CMD_WARNING;
13590
13591 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13592 bgp_show_type_flap_neighbor);
13593}
Lou Berger651b4022016-01-12 13:42:07 -050013594
13595DEFUN (show_bgp_ipv4_safi_neighbor_damp,
13596 show_bgp_ipv4_safi_neighbor_damp_cmd,
13597 "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) dampened-routes",
13598 SHOW_STR
13599 BGP_STR
13600 "Address Family Modifier\n"
13601 "Address Family Modifier\n"
13602 "Address Family Modifier\n"
13603 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +000013604 "Detailed information on TCP and BGP neighbor connections\n"
13605 "Neighbor to display information about\n"
13606 "Neighbor to display information about\n"
13607 "Display the dampened routes received from neighbor\n")
13608{
paulbb46e942003-10-24 19:02:03 +000013609 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013610 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000013611
Lou Berger651b4022016-01-12 13:42:07 -050013612 if (bgp_parse_safi(argv[0], &safi)) {
13613 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13614 return CMD_WARNING;
13615 }
13616
13617 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulbb46e942003-10-24 19:02:03 +000013618 if (! peer)
13619 return CMD_WARNING;
13620
Lou Berger651b4022016-01-12 13:42:07 -050013621 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013622 bgp_show_type_damp_neighbor);
13623}
Lou Berger205e6742016-01-12 13:42:11 -050013624
Lou Berger651b4022016-01-12 13:42:07 -050013625DEFUN (show_bgp_ipv6_safi_neighbor_damp,
13626 show_bgp_ipv6_safi_neighbor_damp_cmd,
13627 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) dampened-routes",
paul718e3742002-12-13 20:15:29 +000013628 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -050013629 BGP_STR
13630 "Address Family Modifier\n"
13631 "Address Family Modifier\n"
13632 "Address Family Modifier\n"
13633 "Address Family Modifier\n"
13634 "Detailed information on TCP and BGP neighbor connections\n"
13635 "Neighbor to display information about\n"
13636 "Neighbor to display information about\n"
13637 "Display the dampened routes received from neighbor\n")
13638{
13639 struct peer *peer;
13640 safi_t safi;
13641
13642 if (bgp_parse_safi(argv[0], &safi)) {
13643 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13644 return CMD_WARNING;
13645 }
13646
13647 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13648 if (! peer)
13649 return CMD_WARNING;
13650
13651 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13652 bgp_show_type_damp_neighbor);
13653}
Lou Berger651b4022016-01-12 13:42:07 -050013654
13655DEFUN (show_bgp_ipv4_safi_neighbor_routes,
13656 show_bgp_ipv4_safi_neighbor_routes_cmd,
13657 "show bgp ipv4 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) routes",
13658 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013659 BGP_STR
13660 "Address family\n"
13661 "Address Family modifier\n"
13662 "Address Family modifier\n"
13663 "Detailed information on TCP and BGP neighbor connections\n"
13664 "Neighbor to display information about\n"
13665 "Neighbor to display information about\n"
13666 "Display routes learned from neighbor\n")
13667{
paulbb46e942003-10-24 19:02:03 +000013668 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013669 safi_t safi;
13670
13671 if (bgp_parse_safi(argv[0], &safi)) {
13672 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13673 return CMD_WARNING;
13674 }
paulbb46e942003-10-24 19:02:03 +000013675
13676 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13677 if (! peer)
13678 return CMD_WARNING;
13679
Lou Berger651b4022016-01-12 13:42:07 -050013680 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013681 bgp_show_type_neighbor);
13682}
Lou Berger205e6742016-01-12 13:42:11 -050013683
Lou Berger651b4022016-01-12 13:42:07 -050013684DEFUN (show_bgp_ipv6_safi_neighbor_routes,
13685 show_bgp_ipv6_safi_neighbor_routes_cmd,
13686 "show bgp ipv6 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) routes",
paulfee0f4c2004-09-13 05:12:46 +000013687 SHOW_STR
paulfee0f4c2004-09-13 05:12:46 +000013688 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013689 "Address family\n"
13690 "Address Family modifier\n"
13691 "Address Family modifier\n"
13692 "Detailed information on TCP and BGP neighbor connections\n"
13693 NEIGHBOR_ADDR_STR
13694 NEIGHBOR_ADDR_STR
13695 "Display routes learned from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000013696{
paulfee0f4c2004-09-13 05:12:46 +000013697 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013698 safi_t safi;
paulfee0f4c2004-09-13 05:12:46 +000013699
Lou Berger651b4022016-01-12 13:42:07 -050013700 if (bgp_parse_safi(argv[0], &safi)) {
13701 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13702 return CMD_WARNING;
13703 }
paulfee0f4c2004-09-13 05:12:46 +000013704
Lou Berger651b4022016-01-12 13:42:07 -050013705 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulfee0f4c2004-09-13 05:12:46 +000013706 if (! peer)
13707 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050013708
13709 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13710 bgp_show_type_neighbor);
paulfee0f4c2004-09-13 05:12:46 +000013711}
paulfee0f4c2004-09-13 05:12:46 +000013712
Michael Lambert95cbbd22010-07-23 14:43:04 -040013713DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
13714 show_bgp_view_ipv4_safi_rsclient_route_cmd,
13715 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13716 SHOW_STR
13717 BGP_STR
13718 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000013719 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013720 "Address family\n"
13721 "Address Family modifier\n"
13722 "Address Family modifier\n"
13723 "Information about Route Server Client\n"
13724 NEIGHBOR_ADDR_STR
13725 "Network in the BGP routing table to display\n")
13726{
13727 struct bgp *bgp;
13728 struct peer *peer;
13729 safi_t safi;
13730
13731 /* BGP structure lookup. */
13732 if (argc == 4)
13733 {
13734 bgp = bgp_lookup_by_name (argv[0]);
13735 if (bgp == NULL)
13736 {
13737 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13738 return CMD_WARNING;
13739 }
13740 }
13741 else
13742 {
13743 bgp = bgp_get_default ();
13744 if (bgp == NULL)
13745 {
13746 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13747 return CMD_WARNING;
13748 }
13749 }
13750
13751 if (argc == 4) {
13752 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13753 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13754 } else {
13755 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13756 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13757 }
13758
13759 if (! peer)
13760 return CMD_WARNING;
13761
13762 if (! peer->afc[AFI_IP][safi])
13763 {
13764 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13765 VTY_NEWLINE);
13766 return CMD_WARNING;
13767}
13768
13769 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13770 PEER_FLAG_RSERVER_CLIENT))
13771 {
13772 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13773 VTY_NEWLINE);
13774 return CMD_WARNING;
13775 }
13776
13777 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
13778 (argc == 4) ? argv[3] : argv[2],
13779 AFI_IP, safi, NULL, 0);
13780}
13781
13782ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
13783 show_bgp_ipv4_safi_rsclient_route_cmd,
13784 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13785 SHOW_STR
13786 BGP_STR
13787 "Address family\n"
13788 "Address Family modifier\n"
13789 "Address Family modifier\n"
13790 "Information about Route Server Client\n"
13791 NEIGHBOR_ADDR_STR
13792 "Network in the BGP routing table to display\n")
13793
paulfee0f4c2004-09-13 05:12:46 +000013794
Michael Lambert95cbbd22010-07-23 14:43:04 -040013795DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
13796 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
13797 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
13798 SHOW_STR
13799 BGP_STR
13800 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000013801 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013802 "Address family\n"
13803 "Address Family modifier\n"
13804 "Address Family modifier\n"
13805 "Information about Route Server Client\n"
13806 NEIGHBOR_ADDR_STR
13807 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13808{
13809 struct bgp *bgp;
13810 struct peer *peer;
13811 safi_t safi;
13812
13813 /* BGP structure lookup. */
13814 if (argc == 4)
13815 {
13816 bgp = bgp_lookup_by_name (argv[0]);
13817 if (bgp == NULL)
13818 {
13819 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13820 return CMD_WARNING;
13821 }
13822 }
13823 else
13824 {
13825 bgp = bgp_get_default ();
13826 if (bgp == NULL)
13827 {
13828 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13829 return CMD_WARNING;
13830 }
13831 }
13832
13833 if (argc == 4) {
13834 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13835 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13836 } else {
13837 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13838 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13839 }
13840
13841 if (! peer)
13842 return CMD_WARNING;
13843
13844 if (! peer->afc[AFI_IP][safi])
13845 {
13846 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13847 VTY_NEWLINE);
13848 return CMD_WARNING;
13849}
13850
13851 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13852 PEER_FLAG_RSERVER_CLIENT))
13853{
13854 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13855 VTY_NEWLINE);
13856 return CMD_WARNING;
13857 }
13858
13859 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
13860 (argc == 4) ? argv[3] : argv[2],
13861 AFI_IP, safi, NULL, 1);
13862}
13863
Lou Bergerf9b6c392016-01-12 13:42:09 -050013864DEFUN (show_ip_bgp_view_rsclient_prefix,
13865 show_ip_bgp_view_rsclient_prefix_cmd,
13866 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
13867 SHOW_STR
13868 IP_STR
13869 BGP_STR
13870 "BGP view\n"
13871 "View name\n"
13872 "Information about Route Server Client\n"
13873 NEIGHBOR_ADDR_STR
13874 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13875{
13876 struct bgp *bgp;
13877 struct peer *peer;
13878
13879 /* BGP structure lookup. */
13880 if (argc == 3)
13881 {
13882 bgp = bgp_lookup_by_name (argv[0]);
13883 if (bgp == NULL)
13884 {
13885 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13886 return CMD_WARNING;
13887 }
13888 }
13889 else
13890 {
13891 bgp = bgp_get_default ();
13892 if (bgp == NULL)
13893 {
13894 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13895 return CMD_WARNING;
13896 }
13897 }
13898
13899 if (argc == 3)
13900 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13901 else
13902 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13903
13904 if (! peer)
13905 return CMD_WARNING;
13906
13907 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13908 {
13909 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13910 VTY_NEWLINE);
13911 return CMD_WARNING;
13912}
13913
13914 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13915 PEER_FLAG_RSERVER_CLIENT))
13916{
13917 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13918 VTY_NEWLINE);
13919 return CMD_WARNING;
13920 }
13921
13922 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
13923 (argc == 3) ? argv[2] : argv[1],
13924 AFI_IP, SAFI_UNICAST, NULL, 1);
13925}
13926
13927ALIAS (show_ip_bgp_view_rsclient_prefix,
13928 show_ip_bgp_rsclient_prefix_cmd,
13929 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
13930 SHOW_STR
13931 IP_STR
13932 BGP_STR
13933 "Information about Route Server Client\n"
13934 NEIGHBOR_ADDR_STR
13935 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13936
Michael Lambert95cbbd22010-07-23 14:43:04 -040013937ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
13938 show_bgp_ipv4_safi_rsclient_prefix_cmd,
13939 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
13940 SHOW_STR
13941 BGP_STR
13942 "Address family\n"
13943 "Address Family modifier\n"
13944 "Address Family modifier\n"
13945 "Information about Route Server Client\n"
13946 NEIGHBOR_ADDR_STR
13947 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000013948
Lou Bergerf9b6c392016-01-12 13:42:09 -050013949DEFUN (show_bgp_view_ipv6_neighbor_routes,
Lou Berger651b4022016-01-12 13:42:07 -050013950 show_bgp_view_ipv6_neighbor_routes_cmd,
13951 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
paulbb46e942003-10-24 19:02:03 +000013952 SHOW_STR
13953 BGP_STR
13954 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000013955 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050013956 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000013957 "Detailed information on TCP and BGP neighbor connections\n"
13958 "Neighbor to display information about\n"
13959 "Neighbor to display information about\n"
13960 "Display routes learned from neighbor\n")
13961{
13962 struct peer *peer;
13963
13964 if (argc == 2)
13965 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13966 else
13967 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13968
13969 if (! peer)
13970 return CMD_WARNING;
13971
13972 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13973 bgp_show_type_neighbor);
13974}
13975
Lou Berger651b4022016-01-12 13:42:07 -050013976DEFUN (show_bgp_view_neighbor_damp,
Lou Bergerf9b6c392016-01-12 13:42:09 -050013977 show_bgp_view_neighbor_damp_cmd,
13978 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
13979 SHOW_STR
13980 BGP_STR
13981 "BGP view\n"
13982 "View name\n"
13983 "Detailed information on TCP and BGP neighbor connections\n"
13984 "Neighbor to display information about\n"
13985 "Neighbor to display information about\n"
13986 "Display the dampened routes received from neighbor\n")
13987{
13988 struct peer *peer;
13989
13990 if (argc == 2)
13991 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13992 else
13993 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13994
13995 if (! peer)
13996 return CMD_WARNING;
13997
13998 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13999 bgp_show_type_damp_neighbor);
14000}
14001
14002DEFUN (show_bgp_view_ipv6_neighbor_damp,
Lou Berger651b4022016-01-12 13:42:07 -050014003 show_bgp_view_ipv6_neighbor_damp_cmd,
14004 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
paulbb46e942003-10-24 19:02:03 +000014005 SHOW_STR
14006 BGP_STR
14007 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014008 "View name\n"
paulbb46e942003-10-24 19:02:03 +000014009 "Address family\n"
14010 "Detailed information on TCP and BGP neighbor connections\n"
14011 "Neighbor to display information about\n"
14012 "Neighbor to display information about\n"
paulbb46e942003-10-24 19:02:03 +000014013 "Display the dampened routes received from neighbor\n")
14014{
14015 struct peer *peer;
14016
14017 if (argc == 2)
14018 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14019 else
14020 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14021
14022 if (! peer)
14023 return CMD_WARNING;
14024
14025 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14026 bgp_show_type_damp_neighbor);
14027}
14028
Lou Bergerf9b6c392016-01-12 13:42:09 -050014029DEFUN (show_bgp_view_ipv6_neighbor_flap,
Lou Berger651b4022016-01-12 13:42:07 -050014030 show_bgp_view_ipv6_neighbor_flap_cmd,
14031 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paulbb46e942003-10-24 19:02:03 +000014032 SHOW_STR
14033 BGP_STR
14034 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014035 "View name\n"
paulbb46e942003-10-24 19:02:03 +000014036 "Address family\n"
14037 "Detailed information on TCP and BGP neighbor connections\n"
14038 "Neighbor to display information about\n"
14039 "Neighbor to display information about\n"
14040 "Display the dampened routes received from neighbor\n")
paulbb46e942003-10-24 19:02:03 +000014041{
14042 struct peer *peer;
14043
14044 if (argc == 2)
14045 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14046 else
14047 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14048
14049 if (! peer)
14050 return CMD_WARNING;
14051
14052 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14053 bgp_show_type_flap_neighbor);
14054}
14055
Lou Bergerf9b6c392016-01-12 13:42:09 -050014056DEFUN (show_bgp_view_neighbor_flap,
14057 show_bgp_view_neighbor_flap_cmd,
14058 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14059 SHOW_STR
14060 BGP_STR
14061 "BGP view\n"
14062 "View name\n"
14063 "Detailed information on TCP and BGP neighbor connections\n"
14064 "Neighbor to display information about\n"
14065 "Neighbor to display information about\n"
14066 "Display flap statistics of the routes learned from neighbor\n")
14067{
14068 struct peer *peer;
14069
14070 if (argc == 2)
14071 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14072 else
14073 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14074
14075 if (! peer)
14076 return CMD_WARNING;
14077
14078 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14079 bgp_show_type_flap_neighbor);
14080}
14081
14082ALIAS (show_bgp_view_neighbor_flap,
14083 show_bgp_neighbor_flap_cmd,
14084 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14085 SHOW_STR
14086 BGP_STR
14087 "Detailed information on TCP and BGP neighbor connections\n"
14088 "Neighbor to display information about\n"
14089 "Neighbor to display information about\n"
14090 "Display flap statistics of the routes learned from neighbor\n")
14091
14092ALIAS (show_bgp_view_neighbor_damp,
14093 show_bgp_neighbor_damp_cmd,
14094 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14095 SHOW_STR
14096 BGP_STR
14097 "Detailed information on TCP and BGP neighbor connections\n"
14098 "Neighbor to display information about\n"
14099 "Neighbor to display information about\n"
14100 "Display the dampened routes received from neighbor\n")
14101
14102DEFUN (show_bgp_view_neighbor_routes,
14103 show_bgp_view_neighbor_routes_cmd,
14104 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
14105 SHOW_STR
14106 BGP_STR
14107 "BGP view\n"
14108 "View name\n"
14109 "Detailed information on TCP and BGP neighbor connections\n"
14110 "Neighbor to display information about\n"
14111 "Neighbor to display information about\n"
14112 "Display routes learned from neighbor\n")
14113{
14114 struct peer *peer;
14115
14116 if (argc == 2)
14117 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14118 else
14119 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14120
14121 if (! peer)
14122 return CMD_WARNING;
14123
14124 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14125 bgp_show_type_neighbor);
14126}
14127
14128ALIAS (show_bgp_view_neighbor_routes,
14129 show_bgp_neighbor_routes_cmd,
14130 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
14131 SHOW_STR
14132 BGP_STR
14133 "Detailed information on TCP and BGP neighbor connections\n"
14134 "Neighbor to display information about\n"
14135 "Neighbor to display information about\n"
14136 "Display routes learned from neighbor\n")
14137
paulbb46e942003-10-24 19:02:03 +000014138ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000014139 show_bgp_ipv6_neighbor_routes_cmd,
14140 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
14141 SHOW_STR
14142 BGP_STR
14143 "Address family\n"
14144 "Detailed information on TCP and BGP neighbor connections\n"
14145 "Neighbor to display information about\n"
14146 "Neighbor to display information about\n"
14147 "Display routes learned from neighbor\n")
14148
Lou Bergerf9b6c392016-01-12 13:42:09 -050014149/* old command */
14150ALIAS (show_bgp_view_neighbor_routes,
14151 ipv6_bgp_neighbor_routes_cmd,
14152 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
14153 SHOW_STR
14154 IPV6_STR
14155 BGP_STR
14156 "Detailed information on TCP and BGP neighbor connections\n"
14157 "Neighbor to display information about\n"
14158 "Neighbor to display information about\n"
14159 "Display routes learned from neighbor\n")
14160
14161/* old command */
14162DEFUN (ipv6_mbgp_neighbor_routes,
14163 ipv6_mbgp_neighbor_routes_cmd,
14164 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
14165 SHOW_STR
14166 IPV6_STR
14167 MBGP_STR
14168 "Detailed information on TCP and BGP neighbor connections\n"
14169 "Neighbor to display information about\n"
14170 "Neighbor to display information about\n"
14171 "Display routes learned from neighbor\n")
14172{
14173 struct peer *peer;
14174
14175 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14176 if (! peer)
14177 return CMD_WARNING;
14178
14179 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
14180 bgp_show_type_neighbor);
14181}
14182
paulbb46e942003-10-24 19:02:03 +000014183ALIAS (show_bgp_view_neighbor_flap,
14184 show_bgp_ipv6_neighbor_flap_cmd,
14185 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14186 SHOW_STR
14187 BGP_STR
14188 "Address family\n"
14189 "Detailed information on TCP and BGP neighbor connections\n"
14190 "Neighbor to display information about\n"
14191 "Neighbor to display information about\n"
14192 "Display flap statistics of the routes learned from neighbor\n")
14193
14194ALIAS (show_bgp_view_neighbor_damp,
paulbb46e942003-10-24 19:02:03 +000014195 show_bgp_ipv6_neighbor_damp_cmd,
14196 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14197 SHOW_STR
14198 BGP_STR
14199 "Address family\n"
14200 "Detailed information on TCP and BGP neighbor connections\n"
14201 "Neighbor to display information about\n"
14202 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000014203 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000014204
Lou Bergerf9b6c392016-01-12 13:42:09 -050014205DEFUN (show_bgp_view_rsclient,
14206 show_bgp_view_rsclient_cmd,
14207 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
14208 SHOW_STR
14209 BGP_STR
14210 "BGP view\n"
14211 "View name\n"
14212 "Information about Route Server Client\n"
14213 NEIGHBOR_ADDR_STR)
14214{
14215 struct bgp_table *table;
14216 struct peer *peer;
14217
14218 if (argc == 2)
14219 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14220 else
14221 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14222
14223 if (! peer)
14224 return CMD_WARNING;
14225
14226 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14227 {
14228 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14229 VTY_NEWLINE);
14230 return CMD_WARNING;
14231 }
14232
14233 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14234 PEER_FLAG_RSERVER_CLIENT))
14235 {
14236 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14237 VTY_NEWLINE);
14238 return CMD_WARNING;
14239 }
14240
14241 table = peer->rib[AFI_IP6][SAFI_UNICAST];
14242
14243 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14244}
14245
14246ALIAS (show_bgp_view_rsclient,
14247 show_bgp_rsclient_cmd,
14248 "show bgp rsclient (A.B.C.D|X:X::X:X)",
14249 SHOW_STR
14250 BGP_STR
14251 "Information about Route Server Client\n"
14252 NEIGHBOR_ADDR_STR)
14253
Lou Berger651b4022016-01-12 13:42:07 -050014254DEFUN (show_bgp_view_ipv4_rsclient,
14255 show_bgp_view_ipv4_rsclient_cmd,
14256 "show bgp view WORD ipv4 rsclient (A.B.C.D|X:X::X:X)",
paulfee0f4c2004-09-13 05:12:46 +000014257 SHOW_STR
14258 BGP_STR
14259 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014260 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050014261 "Address Family\n"
paulfee0f4c2004-09-13 05:12:46 +000014262 "Information about Route Server Client\n"
Lou Berger651b4022016-01-12 13:42:07 -050014263 NEIGHBOR_ADDR_STR2)
paulfee0f4c2004-09-13 05:12:46 +000014264{
Lou Berger651b4022016-01-12 13:42:07 -050014265 struct bgp_table *table;
14266 struct peer *peer;
14267
14268 if (argc == 2)
14269 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14270 else
14271 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14272
14273 if (! peer)
14274 return CMD_WARNING;
14275
14276 if (! peer->afc[AFI_IP][SAFI_UNICAST])
14277 {
14278 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14279 VTY_NEWLINE);
14280 return CMD_WARNING;
14281 }
14282
14283 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
14284 PEER_FLAG_RSERVER_CLIENT))
14285 {
14286 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14287 VTY_NEWLINE);
14288 return CMD_WARNING;
14289 }
14290
14291 table = peer->rib[AFI_IP][SAFI_UNICAST];
14292
14293 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14294}
14295DEFUN (show_bgp_view_ipv6_rsclient,
14296 show_bgp_view_ipv6_rsclient_cmd,
14297 "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X)",
14298 SHOW_STR
14299 BGP_STR
14300 "BGP view\n"
14301 "BGP view name\n"
14302 "Address Family\n"
14303 "Information about Route Server Client\n"
14304 NEIGHBOR_ADDR_STR2)
14305{
14306 struct bgp_table *table;
14307 struct peer *peer;
paulfee0f4c2004-09-13 05:12:46 +000014308
14309 if (argc == 2)
14310 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14311 else
14312 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14313
14314 if (! peer)
14315 return CMD_WARNING;
14316
14317 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14318 {
14319 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14320 VTY_NEWLINE);
14321 return CMD_WARNING;
14322 }
14323
14324 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14325 PEER_FLAG_RSERVER_CLIENT))
14326 {
14327 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14328 VTY_NEWLINE);
14329 return CMD_WARNING;
14330 }
14331
14332 table = peer->rib[AFI_IP6][SAFI_UNICAST];
14333
ajs5a646652004-11-05 01:25:55 +000014334 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000014335}
14336
Lou Berger651b4022016-01-12 13:42:07 -050014337ALIAS (show_bgp_view_ipv4_rsclient,
14338 show_bgp_ipv4_rsclient_cmd,
14339 "show bgp ipv4 rsclient (A.B.C.D|X:X::X:X)",
paulfee0f4c2004-09-13 05:12:46 +000014340 SHOW_STR
14341 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050014342 "Address Family\n"
paulfee0f4c2004-09-13 05:12:46 +000014343 "Information about Route Server Client\n"
Lou Berger651b4022016-01-12 13:42:07 -050014344 NEIGHBOR_ADDR_STR2)
14345
Lou Berger651b4022016-01-12 13:42:07 -050014346ALIAS (show_bgp_view_ipv6_rsclient,
14347 show_bgp_ipv6_rsclient_cmd,
14348 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X)",
14349 SHOW_STR
14350 BGP_STR
14351 "Address Family\n"
14352 "Information about Route Server Client\n"
14353 NEIGHBOR_ADDR_STR2)
paulfee0f4c2004-09-13 05:12:46 +000014354
Michael Lambert95cbbd22010-07-23 14:43:04 -040014355DEFUN (show_bgp_view_ipv6_safi_rsclient,
14356 show_bgp_view_ipv6_safi_rsclient_cmd,
14357 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
14358 SHOW_STR
14359 BGP_STR
14360 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014361 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014362 "Address family\n"
14363 "Address Family modifier\n"
14364 "Address Family modifier\n"
14365 "Information about Route Server Client\n"
14366 NEIGHBOR_ADDR_STR)
14367{
14368 struct bgp_table *table;
14369 struct peer *peer;
14370 safi_t safi;
14371
14372 if (argc == 3) {
14373 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14374 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14375 } else {
14376 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14377 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14378 }
14379
14380 if (! peer)
14381 return CMD_WARNING;
14382
14383 if (! peer->afc[AFI_IP6][safi])
14384 {
14385 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14386 VTY_NEWLINE);
14387 return CMD_WARNING;
14388 }
14389
14390 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14391 PEER_FLAG_RSERVER_CLIENT))
14392 {
14393 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14394 VTY_NEWLINE);
14395 return CMD_WARNING;
14396 }
14397
14398 table = peer->rib[AFI_IP6][safi];
14399
14400 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14401}
14402
14403ALIAS (show_bgp_view_ipv6_safi_rsclient,
14404 show_bgp_ipv6_safi_rsclient_cmd,
14405 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
14406 SHOW_STR
14407 BGP_STR
14408 "Address family\n"
14409 "Address Family modifier\n"
14410 "Address Family modifier\n"
14411 "Information about Route Server Client\n"
14412 NEIGHBOR_ADDR_STR)
14413
paulfee0f4c2004-09-13 05:12:46 +000014414DEFUN (show_bgp_view_rsclient_route,
14415 show_bgp_view_rsclient_route_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014416 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14417 SHOW_STR
14418 BGP_STR
14419 "BGP view\n"
14420 "View name\n"
14421 "Information about Route Server Client\n"
14422 NEIGHBOR_ADDR_STR
14423 "Network in the BGP routing table to display\n")
14424{
14425 struct bgp *bgp;
14426 struct peer *peer;
14427
14428 /* BGP structure lookup. */
14429 if (argc == 3)
14430 {
14431 bgp = bgp_lookup_by_name (argv[0]);
14432 if (bgp == NULL)
14433 {
14434 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14435 return CMD_WARNING;
14436 }
14437 }
14438 else
14439 {
14440 bgp = bgp_get_default ();
14441 if (bgp == NULL)
14442 {
14443 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14444 return CMD_WARNING;
14445 }
14446 }
14447
14448 if (argc == 3)
14449 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14450 else
14451 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14452
14453 if (! peer)
14454 return CMD_WARNING;
14455
14456 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14457 {
14458 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14459 VTY_NEWLINE);
14460 return CMD_WARNING;
14461 }
14462
14463 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14464 PEER_FLAG_RSERVER_CLIENT))
14465 {
14466 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14467 VTY_NEWLINE);
14468 return CMD_WARNING;
14469 }
14470
14471 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14472 (argc == 3) ? argv[2] : argv[1],
14473 AFI_IP6, SAFI_UNICAST, NULL, 0);
14474}
14475
14476DEFUN (show_bgp_view_ipv6_rsclient_route,
14477 show_bgp_view_ipv6_rsclient_route_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014478 "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
paulfee0f4c2004-09-13 05:12:46 +000014479 SHOW_STR
14480 BGP_STR
14481 "BGP view\n"
Lou Berger651b4022016-01-12 13:42:07 -050014482 "BGP view name\n"
14483 "IP6_STR"
paulfee0f4c2004-09-13 05:12:46 +000014484 "Information about Route Server Client\n"
14485 NEIGHBOR_ADDR_STR
14486 "Network in the BGP routing table to display\n")
14487{
14488 struct bgp *bgp;
14489 struct peer *peer;
14490
14491 /* BGP structure lookup. */
14492 if (argc == 3)
14493 {
14494 bgp = bgp_lookup_by_name (argv[0]);
14495 if (bgp == NULL)
14496 {
14497 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14498 return CMD_WARNING;
14499 }
14500 }
14501 else
14502 {
14503 bgp = bgp_get_default ();
14504 if (bgp == NULL)
14505 {
14506 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14507 return CMD_WARNING;
14508 }
14509 }
14510
14511 if (argc == 3)
14512 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14513 else
14514 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14515
14516 if (! peer)
14517 return CMD_WARNING;
14518
14519 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14520 {
14521 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14522 VTY_NEWLINE);
14523 return CMD_WARNING;
14524 }
14525
14526 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14527 PEER_FLAG_RSERVER_CLIENT))
14528 {
14529 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14530 VTY_NEWLINE);
14531 return CMD_WARNING;
14532 }
14533
14534 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14535 (argc == 3) ? argv[2] : argv[1],
14536 AFI_IP6, SAFI_UNICAST, NULL, 0);
14537}
14538
Lou Bergerf9b6c392016-01-12 13:42:09 -050014539ALIAS (show_bgp_view_ipv6_rsclient_route,
paulfee0f4c2004-09-13 05:12:46 +000014540 show_bgp_rsclient_route_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014541 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14542 SHOW_STR
14543 BGP_STR
14544 "Information about Route Server Client\n"
14545 NEIGHBOR_ADDR_STR
14546 "Network in the BGP routing table to display\n")
14547
14548ALIAS (show_bgp_view_ipv6_rsclient_route,
14549 show_bgp_ipv6_rsclient_route_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014550 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
paulfee0f4c2004-09-13 05:12:46 +000014551 SHOW_STR
14552 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050014553 IP6_STR
paulfee0f4c2004-09-13 05:12:46 +000014554 "Information about Route Server Client\n"
14555 NEIGHBOR_ADDR_STR
14556 "Network in the BGP routing table to display\n")
14557
Michael Lambert95cbbd22010-07-23 14:43:04 -040014558DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
14559 show_bgp_view_ipv6_safi_rsclient_route_cmd,
14560 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14561 SHOW_STR
14562 BGP_STR
14563 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014564 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014565 "Address family\n"
14566 "Address Family modifier\n"
14567 "Address Family modifier\n"
14568 "Information about Route Server Client\n"
14569 NEIGHBOR_ADDR_STR
14570 "Network in the BGP routing table to display\n")
14571{
14572 struct bgp *bgp;
14573 struct peer *peer;
14574 safi_t safi;
14575
14576 /* BGP structure lookup. */
14577 if (argc == 4)
14578 {
14579 bgp = bgp_lookup_by_name (argv[0]);
14580 if (bgp == NULL)
14581 {
14582 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14583 return CMD_WARNING;
14584 }
14585 }
14586 else
14587 {
14588 bgp = bgp_get_default ();
14589 if (bgp == NULL)
14590 {
14591 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14592 return CMD_WARNING;
14593 }
14594 }
14595
14596 if (argc == 4) {
14597 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14598 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14599 } else {
14600 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14601 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14602 }
14603
14604 if (! peer)
14605 return CMD_WARNING;
14606
14607 if (! peer->afc[AFI_IP6][safi])
14608 {
14609 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14610 VTY_NEWLINE);
14611 return CMD_WARNING;
14612}
14613
14614 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14615 PEER_FLAG_RSERVER_CLIENT))
14616 {
14617 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14618 VTY_NEWLINE);
14619 return CMD_WARNING;
14620 }
14621
14622 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
14623 (argc == 4) ? argv[3] : argv[2],
14624 AFI_IP6, safi, NULL, 0);
14625}
14626
14627ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
14628 show_bgp_ipv6_safi_rsclient_route_cmd,
14629 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14630 SHOW_STR
14631 BGP_STR
14632 "Address family\n"
14633 "Address Family modifier\n"
14634 "Address Family modifier\n"
14635 "Information about Route Server Client\n"
14636 NEIGHBOR_ADDR_STR
14637 "Network in the BGP routing table to display\n")
14638
Lou Berger651b4022016-01-12 13:42:07 -050014639
paulfee0f4c2004-09-13 05:12:46 +000014640DEFUN (show_bgp_view_rsclient_prefix,
14641 show_bgp_view_rsclient_prefix_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014642 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
14643 SHOW_STR
14644 BGP_STR
14645 "BGP view\n"
14646 "View name\n"
14647 "Information about Route Server Client\n"
14648 NEIGHBOR_ADDR_STR
14649 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14650{
14651 struct bgp *bgp;
14652 struct peer *peer;
14653
14654 /* BGP structure lookup. */
14655 if (argc == 3)
14656 {
14657 bgp = bgp_lookup_by_name (argv[0]);
14658 if (bgp == NULL)
14659 {
14660 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14661 return CMD_WARNING;
14662 }
14663 }
14664 else
14665 {
14666 bgp = bgp_get_default ();
14667 if (bgp == NULL)
14668 {
14669 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14670 return CMD_WARNING;
14671 }
14672 }
14673
14674 if (argc == 3)
14675 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14676 else
14677 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14678
14679 if (! peer)
14680 return CMD_WARNING;
14681
14682 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14683 {
14684 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14685 VTY_NEWLINE);
14686 return CMD_WARNING;
14687 }
14688
14689 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14690 PEER_FLAG_RSERVER_CLIENT))
14691 {
14692 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14693 VTY_NEWLINE);
14694 return CMD_WARNING;
14695 }
14696
14697 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14698 (argc == 3) ? argv[2] : argv[1],
14699 AFI_IP6, SAFI_UNICAST, NULL, 1);
14700}
14701
14702DEFUN (show_bgp_view_ipv6_rsclient_prefix,
14703 show_bgp_view_ipv6_rsclient_prefix_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014704 "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 +000014705 SHOW_STR
14706 BGP_STR
14707 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014708 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050014709 IP6_STR
paulfee0f4c2004-09-13 05:12:46 +000014710 "Information about Route Server Client\n"
14711 NEIGHBOR_ADDR_STR
14712 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14713{
14714 struct bgp *bgp;
14715 struct peer *peer;
14716
14717 /* BGP structure lookup. */
14718 if (argc == 3)
14719 {
14720 bgp = bgp_lookup_by_name (argv[0]);
14721 if (bgp == NULL)
14722 {
14723 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14724 return CMD_WARNING;
14725 }
14726 }
14727 else
14728 {
14729 bgp = bgp_get_default ();
14730 if (bgp == NULL)
14731 {
14732 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14733 return CMD_WARNING;
14734 }
14735 }
14736
14737 if (argc == 3)
14738 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14739 else
14740 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14741
14742 if (! peer)
14743 return CMD_WARNING;
14744
14745 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14746 {
14747 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14748 VTY_NEWLINE);
14749 return CMD_WARNING;
14750 }
14751
14752 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14753 PEER_FLAG_RSERVER_CLIENT))
14754 {
14755 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14756 VTY_NEWLINE);
14757 return CMD_WARNING;
14758 }
14759
14760 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14761 (argc == 3) ? argv[2] : argv[1],
14762 AFI_IP6, SAFI_UNICAST, NULL, 1);
14763}
14764
Lou Bergerf9b6c392016-01-12 13:42:09 -050014765ALIAS (show_bgp_view_ipv6_rsclient_prefix,
paulfee0f4c2004-09-13 05:12:46 +000014766 show_bgp_rsclient_prefix_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014767 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
14768 SHOW_STR
14769 BGP_STR
14770 "Information about Route Server Client\n"
14771 NEIGHBOR_ADDR_STR
14772 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14773
14774ALIAS (show_bgp_view_ipv6_rsclient_prefix,
14775 show_bgp_ipv6_rsclient_prefix_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014776 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
paulfee0f4c2004-09-13 05:12:46 +000014777 SHOW_STR
14778 BGP_STR
14779 "Information about Route Server Client\n"
14780 NEIGHBOR_ADDR_STR
14781 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14782
Michael Lambert95cbbd22010-07-23 14:43:04 -040014783DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
14784 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
14785 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
14786 SHOW_STR
14787 BGP_STR
14788 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014789 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014790 "Address family\n"
14791 "Address Family modifier\n"
14792 "Address Family modifier\n"
14793 "Information about Route Server Client\n"
14794 NEIGHBOR_ADDR_STR
14795 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
14796{
14797 struct bgp *bgp;
14798 struct peer *peer;
14799 safi_t safi;
14800
14801 /* BGP structure lookup. */
14802 if (argc == 4)
14803 {
14804 bgp = bgp_lookup_by_name (argv[0]);
14805 if (bgp == NULL)
14806 {
14807 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14808 return CMD_WARNING;
14809 }
14810 }
14811 else
14812 {
14813 bgp = bgp_get_default ();
14814 if (bgp == NULL)
14815 {
14816 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14817 return CMD_WARNING;
14818 }
14819 }
14820
14821 if (argc == 4) {
14822 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14823 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14824 } else {
14825 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14826 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14827 }
14828
14829 if (! peer)
14830 return CMD_WARNING;
14831
14832 if (! peer->afc[AFI_IP6][safi])
14833 {
14834 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14835 VTY_NEWLINE);
14836 return CMD_WARNING;
14837}
14838
14839 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14840 PEER_FLAG_RSERVER_CLIENT))
14841{
14842 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14843 VTY_NEWLINE);
14844 return CMD_WARNING;
14845 }
14846
14847 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
14848 (argc == 4) ? argv[3] : argv[2],
14849 AFI_IP6, safi, NULL, 1);
14850}
14851
14852ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
14853 show_bgp_ipv6_safi_rsclient_prefix_cmd,
14854 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
14855 SHOW_STR
14856 BGP_STR
14857 "Address family\n"
14858 "Address Family modifier\n"
14859 "Address Family modifier\n"
14860 "Information about Route Server Client\n"
14861 NEIGHBOR_ADDR_STR
14862 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
14863
paul718e3742002-12-13 20:15:29 +000014864struct bgp_table *bgp_distance_table;
14865
14866struct bgp_distance
14867{
14868 /* Distance value for the IP source prefix. */
14869 u_char distance;
14870
14871 /* Name of the access-list to be matched. */
14872 char *access_list;
14873};
14874
paul94f2b392005-06-28 12:44:16 +000014875static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080014876bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000014877{
Stephen Hemminger393deb92008-08-18 14:13:29 -070014878 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000014879}
14880
paul94f2b392005-06-28 12:44:16 +000014881static void
paul718e3742002-12-13 20:15:29 +000014882bgp_distance_free (struct bgp_distance *bdistance)
14883{
14884 XFREE (MTYPE_BGP_DISTANCE, bdistance);
14885}
14886
paul94f2b392005-06-28 12:44:16 +000014887static int
paulfd79ac92004-10-13 05:06:08 +000014888bgp_distance_set (struct vty *vty, const char *distance_str,
14889 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000014890{
14891 int ret;
Roman Hoog Antink6184c392014-03-17 14:01:42 +010014892 struct prefix p;
paul718e3742002-12-13 20:15:29 +000014893 u_char distance;
14894 struct bgp_node *rn;
14895 struct bgp_distance *bdistance;
14896
Roman Hoog Antink6184c392014-03-17 14:01:42 +010014897 ret = str2prefix (ip_str, &p);
paul718e3742002-12-13 20:15:29 +000014898 if (ret == 0)
14899 {
14900 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
14901 return CMD_WARNING;
14902 }
14903
14904 distance = atoi (distance_str);
14905
14906 /* Get BGP distance node. */
14907 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
14908 if (rn->info)
14909 {
14910 bdistance = rn->info;
14911 bgp_unlock_node (rn);
14912 }
14913 else
14914 {
14915 bdistance = bgp_distance_new ();
14916 rn->info = bdistance;
14917 }
14918
14919 /* Set distance value. */
14920 bdistance->distance = distance;
14921
14922 /* Reset access-list configuration. */
14923 if (bdistance->access_list)
14924 {
14925 free (bdistance->access_list);
14926 bdistance->access_list = NULL;
14927 }
14928 if (access_list_str)
14929 bdistance->access_list = strdup (access_list_str);
14930
14931 return CMD_SUCCESS;
14932}
14933
paul94f2b392005-06-28 12:44:16 +000014934static int
paulfd79ac92004-10-13 05:06:08 +000014935bgp_distance_unset (struct vty *vty, const char *distance_str,
14936 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000014937{
14938 int ret;
Roman Hoog Antink6184c392014-03-17 14:01:42 +010014939 struct prefix p;
paul718e3742002-12-13 20:15:29 +000014940 u_char distance;
14941 struct bgp_node *rn;
14942 struct bgp_distance *bdistance;
14943
Roman Hoog Antink6184c392014-03-17 14:01:42 +010014944 ret = str2prefix (ip_str, &p);
paul718e3742002-12-13 20:15:29 +000014945 if (ret == 0)
14946 {
14947 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
14948 return CMD_WARNING;
14949 }
14950
14951 distance = atoi (distance_str);
14952
14953 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
14954 if (! rn)
14955 {
14956 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
14957 return CMD_WARNING;
14958 }
14959
14960 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010014961
14962 if (bdistance->distance != distance)
14963 {
14964 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
14965 return CMD_WARNING;
14966 }
14967
paul718e3742002-12-13 20:15:29 +000014968 if (bdistance->access_list)
14969 free (bdistance->access_list);
14970 bgp_distance_free (bdistance);
14971
14972 rn->info = NULL;
14973 bgp_unlock_node (rn);
14974 bgp_unlock_node (rn);
14975
14976 return CMD_SUCCESS;
14977}
14978
paul718e3742002-12-13 20:15:29 +000014979/* Apply BGP information to distance method. */
14980u_char
14981bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
14982{
14983 struct bgp_node *rn;
14984 struct prefix_ipv4 q;
14985 struct peer *peer;
14986 struct bgp_distance *bdistance;
14987 struct access_list *alist;
14988 struct bgp_static *bgp_static;
14989
14990 if (! bgp)
14991 return 0;
14992
14993 if (p->family != AF_INET)
14994 return 0;
14995
14996 peer = rinfo->peer;
14997
14998 if (peer->su.sa.sa_family != AF_INET)
14999 return 0;
15000
15001 memset (&q, 0, sizeof (struct prefix_ipv4));
15002 q.family = AF_INET;
15003 q.prefix = peer->su.sin.sin_addr;
15004 q.prefixlen = IPV4_MAX_BITLEN;
15005
15006 /* Check source address. */
15007 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
15008 if (rn)
15009 {
15010 bdistance = rn->info;
15011 bgp_unlock_node (rn);
15012
15013 if (bdistance->access_list)
15014 {
15015 alist = access_list_lookup (AFI_IP, bdistance->access_list);
15016 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
15017 return bdistance->distance;
15018 }
15019 else
15020 return bdistance->distance;
15021 }
15022
15023 /* Backdoor check. */
15024 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
15025 if (rn)
15026 {
15027 bgp_static = rn->info;
15028 bgp_unlock_node (rn);
15029
15030 if (bgp_static->backdoor)
15031 {
15032 if (bgp->distance_local)
15033 return bgp->distance_local;
15034 else
15035 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15036 }
15037 }
15038
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000015039 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000015040 {
15041 if (bgp->distance_ebgp)
15042 return bgp->distance_ebgp;
15043 return ZEBRA_EBGP_DISTANCE_DEFAULT;
15044 }
15045 else
15046 {
15047 if (bgp->distance_ibgp)
15048 return bgp->distance_ibgp;
15049 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15050 }
15051}
15052
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015053#ifdef HAVE_IPV6
15054/* Apply BGP information to ipv6 distance method. */
15055u_char
15056ipv6_bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
15057{
15058 struct bgp_node *rn;
15059 struct prefix_ipv6 q;
15060 struct peer *peer;
15061 struct bgp_distance *bdistance;
15062 struct access_list *alist;
15063 struct bgp_static *bgp_static;
15064
15065 if (! bgp)
15066 return 0;
15067
15068 if (p->family != AF_INET6)
15069 return 0;
15070
15071 peer = rinfo->peer;
15072
15073 if (peer->su.sa.sa_family != AF_INET6)
15074 return 0;
15075
15076 memset (&q, 0, sizeof (struct prefix_ipv6));
15077 q.family = AF_INET;
15078 q.prefix = peer->su.sin6.sin6_addr;
15079 q.prefixlen = IPV6_MAX_BITLEN;
15080
15081 /* Check source address. */
15082 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
15083 if (rn)
15084 {
15085 bdistance = rn->info;
15086 bgp_unlock_node (rn);
15087
15088 if (bdistance->access_list)
15089 {
15090 alist = access_list_lookup (AFI_IP6, bdistance->access_list);
15091 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
15092 return bdistance->distance;
15093 }
15094 else
15095 return bdistance->distance;
15096 }
15097 /* Backdoor check. */
15098 rn = bgp_node_lookup (bgp->route[AFI_IP6][SAFI_UNICAST], p);
15099 if (rn)
15100 {
15101 bgp_static = rn->info;
15102 bgp_unlock_node (rn);
15103
15104 if (bgp_static->backdoor)
15105 {
15106 if (bgp->ipv6_distance_local)
15107 return bgp->ipv6_distance_local;
15108 else
15109 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15110 }
15111 }
15112
15113 if (peer_sort (peer) == BGP_PEER_EBGP)
15114 {
15115 if (bgp->ipv6_distance_ebgp)
15116 return bgp->ipv6_distance_ebgp;
15117 return ZEBRA_EBGP_DISTANCE_DEFAULT;
15118 }
15119 else
15120 {
15121 if (bgp->ipv6_distance_ibgp)
15122 return bgp->ipv6_distance_ibgp;
15123 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15124 }
15125}
15126#endif /* HAVE_IPV6 */
15127
paul718e3742002-12-13 20:15:29 +000015128DEFUN (bgp_distance,
15129 bgp_distance_cmd,
15130 "distance bgp <1-255> <1-255> <1-255>",
15131 "Define an administrative distance\n"
15132 "BGP distance\n"
15133 "Distance for routes external to the AS\n"
15134 "Distance for routes internal to the AS\n"
15135 "Distance for local routes\n")
15136{
15137 struct bgp *bgp;
15138
15139 bgp = vty->index;
15140
15141 bgp->distance_ebgp = atoi (argv[0]);
15142 bgp->distance_ibgp = atoi (argv[1]);
15143 bgp->distance_local = atoi (argv[2]);
15144 return CMD_SUCCESS;
15145}
15146
15147DEFUN (no_bgp_distance,
15148 no_bgp_distance_cmd,
15149 "no distance bgp <1-255> <1-255> <1-255>",
15150 NO_STR
15151 "Define an administrative distance\n"
15152 "BGP distance\n"
15153 "Distance for routes external to the AS\n"
15154 "Distance for routes internal to the AS\n"
15155 "Distance for local routes\n")
15156{
15157 struct bgp *bgp;
15158
15159 bgp = vty->index;
15160
15161 bgp->distance_ebgp= 0;
15162 bgp->distance_ibgp = 0;
15163 bgp->distance_local = 0;
15164 return CMD_SUCCESS;
15165}
15166
15167ALIAS (no_bgp_distance,
15168 no_bgp_distance2_cmd,
15169 "no distance bgp",
15170 NO_STR
15171 "Define an administrative distance\n"
15172 "BGP distance\n")
15173
15174DEFUN (bgp_distance_source,
15175 bgp_distance_source_cmd,
15176 "distance <1-255> A.B.C.D/M",
15177 "Define an administrative distance\n"
15178 "Administrative distance\n"
15179 "IP source prefix\n")
15180{
15181 bgp_distance_set (vty, argv[0], argv[1], NULL);
15182 return CMD_SUCCESS;
15183}
15184
15185DEFUN (no_bgp_distance_source,
15186 no_bgp_distance_source_cmd,
15187 "no distance <1-255> A.B.C.D/M",
15188 NO_STR
15189 "Define an administrative distance\n"
15190 "Administrative distance\n"
15191 "IP source prefix\n")
15192{
15193 bgp_distance_unset (vty, argv[0], argv[1], NULL);
15194 return CMD_SUCCESS;
15195}
15196
15197DEFUN (bgp_distance_source_access_list,
15198 bgp_distance_source_access_list_cmd,
15199 "distance <1-255> A.B.C.D/M WORD",
15200 "Define an administrative distance\n"
15201 "Administrative distance\n"
15202 "IP source prefix\n"
15203 "Access list name\n")
15204{
15205 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
15206 return CMD_SUCCESS;
15207}
15208
15209DEFUN (no_bgp_distance_source_access_list,
15210 no_bgp_distance_source_access_list_cmd,
15211 "no distance <1-255> A.B.C.D/M WORD",
15212 NO_STR
15213 "Define an administrative distance\n"
15214 "Administrative distance\n"
15215 "IP source prefix\n"
15216 "Access list name\n")
15217{
15218 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
15219 return CMD_SUCCESS;
15220}
David Lamparter6b0655a2014-06-04 06:53:35 +020015221
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015222#ifdef HAVE_IPV6
15223DEFUN (ipv6_bgp_distance,
15224 ipv6_bgp_distance_cmd,
15225 "distance bgp <1-255> <1-255> <1-255>",
15226 "Define an administrative distance\n"
15227 "BGP distance\n"
15228 "Distance for routes external to the AS\n"
15229 "Distance for routes internal to the AS\n"
15230 "Distance for local routes\n")
15231{
15232 struct bgp *bgp;
15233
15234 bgp = vty->index;
15235
15236 bgp->ipv6_distance_ebgp = atoi (argv[0]);
15237 bgp->ipv6_distance_ibgp = atoi (argv[1]);
15238 bgp->ipv6_distance_local = atoi (argv[2]);
15239 return CMD_SUCCESS;
15240}
15241
15242DEFUN (no_ipv6_bgp_distance,
15243 no_ipv6_bgp_distance_cmd,
15244 "no distance bgp <1-255> <1-255> <1-255>",
15245 NO_STR
15246 "Define an administrative distance\n"
15247 "BGP distance\n"
15248 "Distance for routes external to the AS\n"
15249 "Distance for routes internal to the AS\n"
15250 "Distance for local routes\n")
15251{
15252 struct bgp *bgp;
15253
15254 bgp = vty->index;
15255
15256 bgp->ipv6_distance_ebgp= 0;
15257 bgp->ipv6_distance_ibgp = 0;
15258 bgp->ipv6_distance_local = 0;
15259 return CMD_SUCCESS;
15260}
15261
15262ALIAS (no_ipv6_bgp_distance,
15263 no_ipv6_bgp_distance2_cmd,
15264 "no distance bgp",
15265 NO_STR
15266 "Define an administrative distance\n"
15267 "BGP distance\n")
15268
15269DEFUN (ipv6_bgp_distance_source,
15270 ipv6_bgp_distance_source_cmd,
15271 "distance <1-255> X:X::X:X/M",
15272 "Define an administrative distance\n"
15273 "Administrative distance\n"
15274 "IP source prefix\n")
15275{
15276 bgp_distance_set (vty, argv[0], argv[1], NULL);
15277 return CMD_SUCCESS;
15278}
15279
15280DEFUN (no_ipv6_bgp_distance_source,
15281 no_ipv6_bgp_distance_source_cmd,
15282 "no distance <1-255> X:X::X:X/M",
15283 NO_STR
15284 "Define an administrative distance\n"
15285 "Administrative distance\n"
15286 "IP source prefix\n")
15287{
15288 bgp_distance_unset (vty, argv[0], argv[1], NULL);
15289 return CMD_SUCCESS;
15290}
15291
15292DEFUN (ipv6_bgp_distance_source_access_list,
15293 ipv6_bgp_distance_source_access_list_cmd,
15294 "distance <1-255> X:X::X:X/M WORD",
15295 "Define an administrative distance\n"
15296 "Administrative distance\n"
15297 "IP source prefix\n"
15298 "Access list name\n")
15299{
15300 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
15301 return CMD_SUCCESS;
15302}
15303
15304DEFUN (no_ipv6_bgp_distance_source_access_list,
15305 no_ipv6_bgp_distance_source_access_list_cmd,
15306 "no distance <1-255> X:X::X:X/M WORD",
15307 NO_STR
15308 "Define an administrative distance\n"
15309 "Administrative distance\n"
15310 "IP source prefix\n"
15311 "Access list name\n")
15312{
15313 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
15314 return CMD_SUCCESS;
15315}
15316#endif
15317
paul718e3742002-12-13 20:15:29 +000015318DEFUN (bgp_damp_set,
15319 bgp_damp_set_cmd,
15320 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
15321 "BGP Specific commands\n"
15322 "Enable route-flap dampening\n"
15323 "Half-life time for the penalty\n"
15324 "Value to start reusing a route\n"
15325 "Value to start suppressing a route\n"
15326 "Maximum duration to suppress a stable route\n")
15327{
15328 struct bgp *bgp;
15329 int half = DEFAULT_HALF_LIFE * 60;
15330 int reuse = DEFAULT_REUSE;
15331 int suppress = DEFAULT_SUPPRESS;
15332 int max = 4 * half;
15333
15334 if (argc == 4)
15335 {
15336 half = atoi (argv[0]) * 60;
15337 reuse = atoi (argv[1]);
15338 suppress = atoi (argv[2]);
15339 max = atoi (argv[3]) * 60;
15340 }
15341 else if (argc == 1)
15342 {
15343 half = atoi (argv[0]) * 60;
15344 max = 4 * half;
15345 }
15346
15347 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000015348
15349 if (suppress < reuse)
15350 {
15351 vty_out (vty, "Suppress value cannot be less than reuse value %s",
15352 VTY_NEWLINE);
15353 return 0;
15354 }
15355
paul718e3742002-12-13 20:15:29 +000015356 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
15357 half, reuse, suppress, max);
15358}
15359
15360ALIAS (bgp_damp_set,
15361 bgp_damp_set2_cmd,
15362 "bgp dampening <1-45>",
15363 "BGP Specific commands\n"
15364 "Enable route-flap dampening\n"
15365 "Half-life time for the penalty\n")
15366
15367ALIAS (bgp_damp_set,
15368 bgp_damp_set3_cmd,
15369 "bgp dampening",
15370 "BGP Specific commands\n"
15371 "Enable route-flap dampening\n")
15372
15373DEFUN (bgp_damp_unset,
15374 bgp_damp_unset_cmd,
15375 "no bgp dampening",
15376 NO_STR
15377 "BGP Specific commands\n"
15378 "Enable route-flap dampening\n")
15379{
15380 struct bgp *bgp;
15381
15382 bgp = vty->index;
15383 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
15384}
15385
15386ALIAS (bgp_damp_unset,
15387 bgp_damp_unset2_cmd,
15388 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
15389 NO_STR
15390 "BGP Specific commands\n"
15391 "Enable route-flap dampening\n"
15392 "Half-life time for the penalty\n"
15393 "Value to start reusing a route\n"
15394 "Value to start suppressing a route\n"
15395 "Maximum duration to suppress a stable route\n")
15396
Lou Bergerf9b6c392016-01-12 13:42:09 -050015397DEFUN (show_ip_bgp_dampened_paths,
15398 show_ip_bgp_dampened_paths_cmd,
15399 "show ip bgp dampened-paths",
15400 SHOW_STR
15401 IP_STR
15402 BGP_STR
15403 "Display paths suppressed due to dampening\n")
15404{
15405 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
15406 NULL);
15407}
15408
15409ALIAS (show_ip_bgp_dampened_paths,
15410 show_ip_bgp_damp_dampened_paths_cmd,
15411 "show ip bgp dampening dampened-paths",
15412 SHOW_STR
15413 IP_STR
15414 BGP_STR
15415 "Display detailed information about dampening\n"
15416 "Display paths suppressed due to dampening\n")
15417
15418DEFUN (show_ip_bgp_flap_statistics,
15419 show_ip_bgp_flap_statistics_cmd,
15420 "show ip bgp flap-statistics",
15421 SHOW_STR
15422 IP_STR
15423 BGP_STR
15424 "Display flap statistics of routes\n")
15425{
15426 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
15427 bgp_show_type_flap_statistics, NULL);
15428}
15429
15430ALIAS (show_ip_bgp_flap_statistics,
15431 show_ip_bgp_damp_flap_statistics_cmd,
15432 "show ip bgp dampening flap-statistics",
15433 SHOW_STR
15434 IP_STR
15435 BGP_STR
15436 "Display detailed information about dampening\n"
15437 "Display flap statistics of routes\n")
15438
Lou Berger651b4022016-01-12 13:42:07 -050015439DEFUN (show_bgp_ipv4_safi_dampened_paths,
15440 show_bgp_ipv4_safi_dampened_paths_cmd,
15441 "show bgp ipv4 (encap|multicast|unicast|vpn) dampened-paths",
paul718e3742002-12-13 20:15:29 +000015442 SHOW_STR
paul718e3742002-12-13 20:15:29 +000015443 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015444 IP_STR
15445 "Address Family modifier\n"
15446 "Address Family modifier\n"
15447 "Address Family modifier\n"
15448 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000015449 "Display paths suppressed due to dampening\n")
15450{
Lou Berger651b4022016-01-12 13:42:07 -050015451 safi_t safi;
paul718e3742002-12-13 20:15:29 +000015452
Lou Berger651b4022016-01-12 13:42:07 -050015453 if (bgp_parse_safi(argv[0], &safi)) {
15454 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15455 return CMD_WARNING;
15456 }
15457
15458 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_dampend_paths, NULL);
15459}
15460ALIAS (show_bgp_ipv4_safi_dampened_paths,
15461 show_bgp_ipv4_safi_damp_dampened_paths_cmd,
15462 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening dampened-paths",
Balaji3921cc52015-05-16 23:12:17 +053015463 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053015464 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015465 IP_STR
15466 "Address Family modifier\n"
15467 "Address Family modifier\n"
15468 "Address Family modifier\n"
15469 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053015470 "Display detailed information about dampening\n"
15471 "Display paths suppressed due to dampening\n")
Lou Berger205e6742016-01-12 13:42:11 -050015472
Lou Berger651b4022016-01-12 13:42:07 -050015473DEFUN (show_bgp_ipv6_safi_dampened_paths,
15474 show_bgp_ipv6_safi_dampened_paths_cmd,
15475 "show bgp ipv6 (encap|multicast|unicast|vpn) dampened-paths",
paul718e3742002-12-13 20:15:29 +000015476 SHOW_STR
paul718e3742002-12-13 20:15:29 +000015477 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015478 IPV6_STR
15479 "Address Family modifier\n"
15480 "Address Family modifier\n"
15481 "Address Family modifier\n"
15482 "Address Family modifier\n"
15483 "Display paths suppressed due to dampening\n")
15484{
15485 safi_t safi;
15486
15487 if (bgp_parse_safi(argv[0], &safi)) {
15488 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15489 return CMD_WARNING;
15490 }
15491
15492 return bgp_show (vty, NULL, AFI_IP6, safi, bgp_show_type_dampend_paths, NULL);
15493}
15494ALIAS (show_bgp_ipv6_safi_dampened_paths,
15495 show_bgp_ipv6_safi_damp_dampened_paths_cmd,
15496 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening dampened-paths",
15497 SHOW_STR
15498 BGP_STR
15499 IPV6_STR
15500 "Address Family modifier\n"
15501 "Address Family modifier\n"
15502 "Address Family modifier\n"
15503 "Address Family modifier\n"
15504 "Display detailed information about dampening\n"
15505 "Display paths suppressed due to dampening\n")
Lou Berger651b4022016-01-12 13:42:07 -050015506
15507DEFUN (show_bgp_ipv4_safi_flap_statistics,
15508 show_bgp_ipv4_safi_flap_statistics_cmd,
15509 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics",
15510 SHOW_STR
15511 BGP_STR
15512 "Address Family\n"
15513 "Address Family modifier\n"
15514 "Address Family modifier\n"
15515 "Address Family modifier\n"
15516 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000015517 "Display flap statistics of routes\n")
15518{
Lou Berger651b4022016-01-12 13:42:07 -050015519 safi_t safi;
David Lamparter6b0655a2014-06-04 06:53:35 +020015520
Lou Berger651b4022016-01-12 13:42:07 -050015521 if (bgp_parse_safi(argv[0], &safi)) {
15522 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15523 return CMD_WARNING;
15524 }
15525
15526 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_statistics, NULL);
15527}
15528ALIAS (show_bgp_ipv4_safi_flap_statistics,
15529 show_bgp_ipv4_safi_damp_flap_statistics_cmd,
15530 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics",
Balaji3921cc52015-05-16 23:12:17 +053015531 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053015532 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015533 "Address Family\n"
15534 "Address Family modifier\n"
15535 "Address Family modifier\n"
15536 "Address Family modifier\n"
15537 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053015538 "Display detailed information about dampening\n"
15539 "Display flap statistics of routes\n")
Lou Berger205e6742016-01-12 13:42:11 -050015540
Lou Berger651b4022016-01-12 13:42:07 -050015541DEFUN (show_bgp_ipv6_safi_flap_statistics,
15542 show_bgp_ipv6_safi_flap_statistics_cmd,
15543 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics",
15544 SHOW_STR
15545 BGP_STR
15546 "Address Family\n"
15547 "Address Family modifier\n"
15548 "Address Family modifier\n"
15549 "Address Family modifier\n"
15550 "Address Family modifier\n"
15551 "Display flap statistics of routes\n")
15552{
15553 safi_t safi;
15554
15555 if (bgp_parse_safi(argv[0], &safi)) {
15556 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15557 return CMD_WARNING;
15558 }
15559
15560 return bgp_show (vty, NULL, AFI_IP6, safi, bgp_show_type_flap_statistics, NULL);
15561}
15562ALIAS (show_bgp_ipv6_safi_flap_statistics,
15563 show_bgp_ipv6_safi_damp_flap_statistics_cmd,
15564 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics",
15565 SHOW_STR
15566 BGP_STR
15567 "Address Family\n"
15568 "Address Family modifier\n"
15569 "Address Family modifier\n"
15570 "Address Family modifier\n"
15571 "Address Family modifier\n"
15572 "Display detailed information about dampening\n"
15573 "Display flap statistics of routes\n")
Balaji3921cc52015-05-16 23:12:17 +053015574
paul718e3742002-12-13 20:15:29 +000015575/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000015576static int
paulfd79ac92004-10-13 05:06:08 +000015577bgp_clear_damp_route (struct vty *vty, const char *view_name,
15578 const char *ip_str, afi_t afi, safi_t safi,
15579 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000015580{
15581 int ret;
15582 struct prefix match;
15583 struct bgp_node *rn;
15584 struct bgp_node *rm;
15585 struct bgp_info *ri;
15586 struct bgp_info *ri_temp;
15587 struct bgp *bgp;
15588 struct bgp_table *table;
15589
15590 /* BGP structure lookup. */
15591 if (view_name)
15592 {
15593 bgp = bgp_lookup_by_name (view_name);
15594 if (bgp == NULL)
15595 {
15596 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
15597 return CMD_WARNING;
15598 }
15599 }
15600 else
15601 {
15602 bgp = bgp_get_default ();
15603 if (bgp == NULL)
15604 {
15605 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
15606 return CMD_WARNING;
15607 }
15608 }
15609
15610 /* Check IP address argument. */
15611 ret = str2prefix (ip_str, &match);
15612 if (! ret)
15613 {
15614 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
15615 return CMD_WARNING;
15616 }
15617
15618 match.family = afi2family (afi);
15619
Lou Berger298cc2f2016-01-12 13:42:02 -050015620 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000015621 {
Lou Berger298cc2f2016-01-12 13:42:02 -050015622 for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +000015623 {
15624 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
15625 continue;
15626
15627 if ((table = rn->info) != NULL)
15628 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000015629 {
15630 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
15631 {
15632 ri = rm->info;
15633 while (ri)
15634 {
15635 if (ri->extra && ri->extra->damp_info)
15636 {
15637 ri_temp = ri->next;
15638 bgp_damp_info_free (ri->extra->damp_info, 1);
15639 ri = ri_temp;
15640 }
15641 else
15642 ri = ri->next;
15643 }
15644 }
15645
15646 bgp_unlock_node (rm);
15647 }
paul718e3742002-12-13 20:15:29 +000015648 }
15649 }
15650 else
15651 {
15652 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000015653 {
15654 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
15655 {
15656 ri = rn->info;
15657 while (ri)
15658 {
15659 if (ri->extra && ri->extra->damp_info)
15660 {
15661 ri_temp = ri->next;
15662 bgp_damp_info_free (ri->extra->damp_info, 1);
15663 ri = ri_temp;
15664 }
15665 else
15666 ri = ri->next;
15667 }
15668 }
15669
15670 bgp_unlock_node (rn);
15671 }
paul718e3742002-12-13 20:15:29 +000015672 }
15673
15674 return CMD_SUCCESS;
15675}
15676
15677DEFUN (clear_ip_bgp_dampening,
15678 clear_ip_bgp_dampening_cmd,
15679 "clear ip bgp dampening",
15680 CLEAR_STR
15681 IP_STR
15682 BGP_STR
15683 "Clear route flap dampening information\n")
15684{
15685 bgp_damp_info_clean ();
15686 return CMD_SUCCESS;
15687}
15688
15689DEFUN (clear_ip_bgp_dampening_prefix,
15690 clear_ip_bgp_dampening_prefix_cmd,
15691 "clear ip bgp dampening A.B.C.D/M",
15692 CLEAR_STR
15693 IP_STR
15694 BGP_STR
15695 "Clear route flap dampening information\n"
15696 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
15697{
15698 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
15699 SAFI_UNICAST, NULL, 1);
15700}
15701
15702DEFUN (clear_ip_bgp_dampening_address,
15703 clear_ip_bgp_dampening_address_cmd,
15704 "clear ip bgp dampening A.B.C.D",
15705 CLEAR_STR
15706 IP_STR
15707 BGP_STR
15708 "Clear route flap dampening information\n"
15709 "Network to clear damping information\n")
15710{
15711 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
15712 SAFI_UNICAST, NULL, 0);
15713}
15714
15715DEFUN (clear_ip_bgp_dampening_address_mask,
15716 clear_ip_bgp_dampening_address_mask_cmd,
15717 "clear ip bgp dampening A.B.C.D A.B.C.D",
15718 CLEAR_STR
15719 IP_STR
15720 BGP_STR
15721 "Clear route flap dampening information\n"
15722 "Network to clear damping information\n"
15723 "Network mask\n")
15724{
15725 int ret;
15726 char prefix_str[BUFSIZ];
15727
15728 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
15729 if (! ret)
15730 {
15731 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
15732 return CMD_WARNING;
15733 }
15734
15735 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
15736 SAFI_UNICAST, NULL, 0);
15737}
David Lamparter6b0655a2014-06-04 06:53:35 +020015738
Lou Berger298cc2f2016-01-12 13:42:02 -050015739/* also used for encap safi */
paul94f2b392005-06-28 12:44:16 +000015740static int
paul718e3742002-12-13 20:15:29 +000015741bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
15742 afi_t afi, safi_t safi, int *write)
15743{
15744 struct bgp_node *prn;
15745 struct bgp_node *rn;
15746 struct bgp_table *table;
15747 struct prefix *p;
15748 struct prefix_rd *prd;
15749 struct bgp_static *bgp_static;
15750 u_int32_t label;
15751 char buf[SU_ADDRSTRLEN];
15752 char rdbuf[RD_ADDRSTRLEN];
15753
15754 /* Network configuration. */
15755 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
15756 if ((table = prn->info) != NULL)
15757 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
15758 if ((bgp_static = rn->info) != NULL)
15759 {
15760 p = &rn->p;
15761 prd = (struct prefix_rd *) &prn->p;
15762
15763 /* "address-family" display. */
15764 bgp_config_write_family_header (vty, afi, safi, write);
15765
15766 /* "network" configuration display. */
15767 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
15768 label = decode_label (bgp_static->tag);
15769
15770 vty_out (vty, " network %s/%d rd %s tag %d",
15771 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
15772 p->prefixlen,
15773 rdbuf, label);
15774 vty_out (vty, "%s", VTY_NEWLINE);
15775 }
15776 return 0;
15777}
15778
15779/* Configuration of static route announcement and aggregate
15780 information. */
15781int
15782bgp_config_write_network (struct vty *vty, struct bgp *bgp,
15783 afi_t afi, safi_t safi, int *write)
15784{
15785 struct bgp_node *rn;
15786 struct prefix *p;
15787 struct bgp_static *bgp_static;
15788 struct bgp_aggregate *bgp_aggregate;
15789 char buf[SU_ADDRSTRLEN];
15790
Lou Berger298cc2f2016-01-12 13:42:02 -050015791 if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
paul718e3742002-12-13 20:15:29 +000015792 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
15793
15794 /* Network configuration. */
15795 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
15796 if ((bgp_static = rn->info) != NULL)
15797 {
15798 p = &rn->p;
15799
15800 /* "address-family" display. */
15801 bgp_config_write_family_header (vty, afi, safi, write);
15802
15803 /* "network" configuration display. */
15804 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
15805 {
15806 u_int32_t destination;
15807 struct in_addr netmask;
15808
15809 destination = ntohl (p->u.prefix4.s_addr);
15810 masklen2ip (p->prefixlen, &netmask);
15811 vty_out (vty, " network %s",
15812 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
15813
15814 if ((IN_CLASSC (destination) && p->prefixlen == 24)
15815 || (IN_CLASSB (destination) && p->prefixlen == 16)
15816 || (IN_CLASSA (destination) && p->prefixlen == 8)
15817 || p->u.prefix4.s_addr == 0)
15818 {
15819 /* Natural mask is not display. */
15820 }
15821 else
15822 vty_out (vty, " mask %s", inet_ntoa (netmask));
15823 }
15824 else
15825 {
15826 vty_out (vty, " network %s/%d",
15827 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
15828 p->prefixlen);
15829 }
15830
15831 if (bgp_static->rmap.name)
15832 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000015833 else
15834 {
15835 if (bgp_static->backdoor)
15836 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000015837 }
paul718e3742002-12-13 20:15:29 +000015838
15839 vty_out (vty, "%s", VTY_NEWLINE);
15840 }
15841
15842 /* Aggregate-address configuration. */
15843 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
15844 if ((bgp_aggregate = rn->info) != NULL)
15845 {
15846 p = &rn->p;
15847
15848 /* "address-family" display. */
15849 bgp_config_write_family_header (vty, afi, safi, write);
15850
15851 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
15852 {
15853 struct in_addr netmask;
15854
15855 masklen2ip (p->prefixlen, &netmask);
15856 vty_out (vty, " aggregate-address %s %s",
15857 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
15858 inet_ntoa (netmask));
15859 }
15860 else
15861 {
15862 vty_out (vty, " aggregate-address %s/%d",
15863 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
15864 p->prefixlen);
15865 }
15866
15867 if (bgp_aggregate->as_set)
15868 vty_out (vty, " as-set");
15869
15870 if (bgp_aggregate->summary_only)
15871 vty_out (vty, " summary-only");
15872
15873 vty_out (vty, "%s", VTY_NEWLINE);
15874 }
15875
15876 return 0;
15877}
15878
15879int
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015880bgp_config_write_distance (struct vty *vty, struct bgp *bgp,
15881 afi_t afi, safi_t safi, int *write)
paul718e3742002-12-13 20:15:29 +000015882{
15883 struct bgp_node *rn;
15884 struct bgp_distance *bdistance;
15885
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015886 if (afi == AFI_IP && safi == SAFI_UNICAST)
15887 {
15888 /* Distance configuration. */
15889 if (bgp->distance_ebgp
15890 && bgp->distance_ibgp
15891 && bgp->distance_local
15892 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
15893 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
15894 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
15895 vty_out (vty, " distance bgp %d %d %d%s",
15896 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
15897 VTY_NEWLINE);
15898
15899 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
15900 if ((bdistance = rn->info) != NULL)
15901 {
15902 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
15903 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
15904 bdistance->access_list ? bdistance->access_list : "",
15905 VTY_NEWLINE);
15906 }
15907 }
15908
15909#ifdef HAVE_IPV6
15910 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
15911 {
15912 bgp_config_write_family_header (vty, afi, safi, write);
15913 if (bgp->ipv6_distance_ebgp
15914 && bgp->ipv6_distance_ibgp
15915 && bgp->ipv6_distance_local
15916 && (bgp->ipv6_distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
15917 || bgp->ipv6_distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
15918 || bgp->ipv6_distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
15919 vty_out (vty, " distance bgp %d %d %d%s",
15920 bgp->ipv6_distance_ebgp, bgp->ipv6_distance_ibgp, bgp->ipv6_distance_local,
15921 VTY_NEWLINE);
15922
15923 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
15924 if ((bdistance = rn->info) != NULL)
15925 {
15926 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
15927 inet6_ntoa (rn->p.u.prefix6), rn->p.prefixlen,
15928 bdistance->access_list ? bdistance->access_list : "",
15929 VTY_NEWLINE);
15930 }
15931 }
15932#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +000015933
15934 return 0;
15935}
15936
15937/* Allocate routing table structure and install commands. */
15938void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080015939bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000015940{
15941 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000015942 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000015943
15944 /* IPv4 BGP commands. */
15945 install_element (BGP_NODE, &bgp_network_cmd);
15946 install_element (BGP_NODE, &bgp_network_mask_cmd);
15947 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
15948 install_element (BGP_NODE, &bgp_network_route_map_cmd);
15949 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
15950 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
15951 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
15952 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
15953 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
15954 install_element (BGP_NODE, &no_bgp_network_cmd);
15955 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
15956 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
15957 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
15958 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
15959 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
15960 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
15961 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
15962 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
15963
15964 install_element (BGP_NODE, &aggregate_address_cmd);
15965 install_element (BGP_NODE, &aggregate_address_mask_cmd);
15966 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
15967 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
15968 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
15969 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
15970 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
15971 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
15972 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
15973 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
15974 install_element (BGP_NODE, &no_aggregate_address_cmd);
15975 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
15976 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
15977 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
15978 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
15979 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
15980 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
15981 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
15982 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
15983 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
15984
15985 /* IPv4 unicast configuration. */
15986 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
15987 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
15988 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
15989 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
15990 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
15991 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000015992 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000015993 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
15994 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
15995 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
15996 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
15997 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000015998
paul718e3742002-12-13 20:15:29 +000015999 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
16000 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
16001 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
16002 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
16003 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
16004 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
16005 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
16006 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
16007 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
16008 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
16009 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
16010 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
16011 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
16012 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
16013 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
16014 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
16015 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
16016 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
16017 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
16018 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
16019
16020 /* IPv4 multicast configuration. */
16021 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
16022 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
16023 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
16024 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
16025 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
16026 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
16027 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
16028 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
16029 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
16030 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
16031 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
16032 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
16033 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
16034 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
16035 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
16036 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
16037 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
16038 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
16039 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
16040 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
16041 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
16042 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
16043 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
16044 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
16045 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
16046 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
16047 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
16048 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
16049 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
16050 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
16051 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
16052 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
16053
Michael Lambert95cbbd22010-07-23 14:43:04 -040016054 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016055 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016056 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_route_cmd);
16057 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_route_cmd);
16058 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
16059 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
16060 install_element (VIEW_NODE, &show_bgp_ipv4_encap_route_cmd);
16061 install_element (VIEW_NODE, &show_bgp_ipv6_encap_route_cmd);
16062 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
16063 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
16064 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016065 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016066 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
16067 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
16068 install_element (VIEW_NODE, &show_bgp_ipv4_encap_prefix_cmd);
16069 install_element (VIEW_NODE, &show_bgp_ipv6_encap_prefix_cmd);
16070 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
16071 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
16072 install_element (VIEW_NODE, &show_bgp_afi_safi_view_cmd);
16073 install_element (VIEW_NODE, &show_bgp_view_afi_safi_route_cmd);
16074 install_element (VIEW_NODE, &show_bgp_view_afi_safi_prefix_cmd);
16075 install_element (VIEW_NODE, &show_bgp_ipv4_safi_regexp_cmd);
16076 install_element (VIEW_NODE, &show_bgp_ipv6_safi_regexp_cmd);
16077 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_list_cmd);
16078 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_list_cmd);
16079 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_list_cmd);
16080 install_element (VIEW_NODE, &show_bgp_ipv4_filter_list_cmd);
16081 install_element (VIEW_NODE, &show_bgp_ipv4_safi_filter_list_cmd);
16082 install_element (VIEW_NODE, &show_bgp_ipv6_safi_filter_list_cmd);
16083 install_element (VIEW_NODE, &show_bgp_ipv4_route_map_cmd);
16084 install_element (VIEW_NODE, &show_bgp_ipv4_cidr_only_cmd);
16085 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cidr_only_cmd);
16086 install_element (VIEW_NODE, &show_bgp_ipv4_community_cmd);
16087 install_element (VIEW_NODE, &show_bgp_ipv4_community2_cmd);
16088 install_element (VIEW_NODE, &show_bgp_ipv4_community3_cmd);
16089 install_element (VIEW_NODE, &show_bgp_ipv4_community4_cmd);
16090 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_cmd);
16091 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community2_cmd);
16092 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community3_cmd);
16093 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016094 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
16095 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
16096 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
16097 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
16098 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016099 install_element (VIEW_NODE, &show_bgp_ipv4_community_exact_cmd);
16100 install_element (VIEW_NODE, &show_bgp_ipv4_community2_exact_cmd);
16101 install_element (VIEW_NODE, &show_bgp_ipv4_community3_exact_cmd);
16102 install_element (VIEW_NODE, &show_bgp_ipv4_community4_exact_cmd);
16103 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
16104 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
16105 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
16106 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
16107 install_element (VIEW_NODE, &show_bgp_ipv4_community_list_cmd);
16108 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_list_cmd);
16109 install_element (VIEW_NODE, &show_bgp_ipv4_community_list_exact_cmd);
16110 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_list_exact_cmd);
16111 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_longer_cmd);
16112 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_longer_cmd);
16113 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_longer_cmd);
16114 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_advertised_route_cmd);
16115 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_advertised_route_cmd);
16116 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_received_routes_cmd);
16117 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016118 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016119 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_routes_cmd);
16120 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_routes_cmd);
16121 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd);
16122 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd);
16123 install_element (VIEW_NODE, &show_bgp_ipv4_safi_dampened_paths_cmd);
16124 install_element (VIEW_NODE, &show_bgp_ipv6_safi_dampened_paths_cmd);
16125 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_dampened_paths_cmd);
16126 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_dampened_paths_cmd);
16127 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_statistics_cmd);
16128 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_statistics_cmd);
16129 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_statistics_cmd);
16130 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_statistics_cmd);
16131 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_address_cmd);
16132 install_element (VIEW_NODE, &show_bgp_ipv6_flap_address_cmd);
16133 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_address_cmd);
16134 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_cmd);
16135 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_cmd);
16136 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_cmd);
16137 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_cmd);
16138 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_cidr_only_cmd);
16139 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_cidr_only_cmd);
16140 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_regexp_cmd);
16141 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_regexp_cmd);
16142 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_regexp_cmd);
16143 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_regexp_cmd);
16144 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_filter_list_cmd);
16145 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_filter_list_cmd);
16146 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_filter_list_cmd);
16147 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_filter_list_cmd);
16148 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_list_cmd);
16149 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_list_cmd);
16150 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_list_cmd);
16151 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_list_cmd);
16152 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_longer_cmd);
16153 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_longer_cmd);
16154 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd);
16155 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd);
16156 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_route_map_cmd);
16157 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_route_map_cmd);
16158 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_route_map_cmd);
16159 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_route_map_cmd);
16160 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_flap_cmd);
16161 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_flap_cmd);
16162 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_damp_cmd);
16163 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_damp_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016164 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016165 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016166 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016167 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016168 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016169 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016170
16171 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
Michael Lambert95cbbd22010-07-23 14:43:04 -040016172 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016173 install_element (RESTRICTED_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
16174 install_element (RESTRICTED_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
16175 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
16176 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
16177 install_element (RESTRICTED_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016178 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016179 install_element (RESTRICTED_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
16180 install_element (RESTRICTED_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
16181 install_element (RESTRICTED_NODE, &show_bgp_ipv4_encap_prefix_cmd);
16182 install_element (RESTRICTED_NODE, &show_bgp_ipv6_encap_prefix_cmd);
16183 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
16184 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
16185 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_route_cmd);
16186 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_prefix_cmd);
16187 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community_cmd);
16188 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community2_cmd);
16189 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community3_cmd);
16190 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community4_cmd);
16191 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community_cmd);
16192 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community2_cmd);
16193 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community3_cmd);
16194 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016195 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
16196 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
16197 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
16198 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
16199 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016200 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community_exact_cmd);
16201 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community2_exact_cmd);
16202 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community3_exact_cmd);
16203 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community4_exact_cmd);
16204 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
16205 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
16206 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
16207 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016208 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016209 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016210 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016211 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016212
Donald Sharp68b45cc2016-03-11 14:27:13 -050016213 /* BGP dampening clear commands */
paul718e3742002-12-13 20:15:29 +000016214 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
16215 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
16216 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
16217 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
16218
paul718e3742002-12-13 20:15:29 +000016219 /* New config IPv6 BGP commands. */
16220 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
16221 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
16222 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
16223 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
16224
16225 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
16226 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
16227 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
16228 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
16229
G.Balaji73bfe0b2011-09-23 22:36:20 +053016230 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
16231 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
16232
paul718e3742002-12-13 20:15:29 +000016233 /* Old config IPv6 BGP commands. */
16234 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
16235 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
16236
16237 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
16238 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
16239 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
16240 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
16241
Michael Lambert95cbbd22010-07-23 14:43:04 -040016242 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000016243 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016244 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000016245 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016246 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016247 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
paul718e3742002-12-13 20:15:29 +000016248 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000016249 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000016250 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016251 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_cmd);
16252 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community2_cmd);
16253 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community3_cmd);
16254 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community4_cmd);
16255 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_exact_cmd);
16256 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community2_exact_cmd);
16257 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community3_exact_cmd);
16258 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community4_exact_cmd);
paul718e3742002-12-13 20:15:29 +000016259 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
paul718e3742002-12-13 20:15:29 +000016260 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000016261 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
paul718e3742002-12-13 20:15:29 +000016262 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
paul718e3742002-12-13 20:15:29 +000016263 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
paul718e3742002-12-13 20:15:29 +000016264 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000016265 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000016266 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016267 install_element (VIEW_NODE, &show_bgp_ipv4_rsclient_cmd);
16268 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016269 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016270 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016271 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016272 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016273 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000016274 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
paulbb46e942003-10-24 19:02:03 +000016275 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
paulbb46e942003-10-24 19:02:03 +000016276 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000016277 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
paulbb46e942003-10-24 19:02:03 +000016278 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000016279 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000016280 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000016281 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000016282 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016283 install_element (VIEW_NODE, &show_bgp_view_ipv4_rsclient_cmd);
16284 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016285 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016286 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016287 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016288 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016289 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016290
16291 /* Restricted:
16292 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
16293 */
Paul Jakma62687ff2008-08-23 14:27:06 +010016294 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016295 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016296 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016297 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016298 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community_cmd);
16299 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community2_cmd);
16300 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community3_cmd);
16301 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community4_cmd);
16302 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community_exact_cmd);
16303 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community2_exact_cmd);
16304 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community3_exact_cmd);
16305 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community4_exact_cmd);
16306 install_element (RESTRICTED_NODE, &show_bgp_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016307 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016308 install_element (RESTRICTED_NODE, &show_bgp_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016309 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016310 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016311 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016312 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016313 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016314 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016315 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016316 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016317
Paul Jakma2815e612006-09-14 02:56:07 +000016318 /* Statistics */
16319 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016320 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
paul718e3742002-12-13 20:15:29 +000016321
16322 install_element (BGP_NODE, &bgp_distance_cmd);
16323 install_element (BGP_NODE, &no_bgp_distance_cmd);
16324 install_element (BGP_NODE, &no_bgp_distance2_cmd);
16325 install_element (BGP_NODE, &bgp_distance_source_cmd);
16326 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
16327 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
16328 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
Roman Hoog Antink6184c392014-03-17 14:01:42 +010016329#ifdef HAVE_IPV6
16330 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_cmd);
16331 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_cmd);
16332 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance2_cmd);
16333 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_cmd);
16334 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_cmd);
16335 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_access_list_cmd);
16336 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_access_list_cmd);
16337#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +000016338
16339 install_element (BGP_NODE, &bgp_damp_set_cmd);
16340 install_element (BGP_NODE, &bgp_damp_set2_cmd);
16341 install_element (BGP_NODE, &bgp_damp_set3_cmd);
16342 install_element (BGP_NODE, &bgp_damp_unset_cmd);
16343 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
16344 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
16345 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
16346 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
16347 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
16348 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Balaji9145f0e2016-01-20 22:59:27 +053016349
16350 /* IPv4 Multicast Mode */
16351 install_element (BGP_IPV4M_NODE, &bgp_damp_set_cmd);
16352 install_element (BGP_IPV4M_NODE, &bgp_damp_set2_cmd);
16353 install_element (BGP_IPV4M_NODE, &bgp_damp_set3_cmd);
16354 install_element (BGP_IPV4M_NODE, &bgp_damp_unset_cmd);
16355 install_element (BGP_IPV4M_NODE, &bgp_damp_unset2_cmd);
16356
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016357
16358 /* Deprecated AS-Pathlimit commands */
16359 install_element (BGP_NODE, &bgp_network_ttl_cmd);
16360 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
16361 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
16362 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
16363 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16364 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16365
16366 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
16367 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
16368 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16369 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
16370 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16371 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
16372
16373 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
16374 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
16375 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
16376 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
16377 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16378 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16379
16380 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
16381 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
16382 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16383 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
16384 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16385 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
16386
16387 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
16388 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
16389 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
16390 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
16391 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16392 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16393
16394 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
16395 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
16396 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16397 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
16398 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16399 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000016400
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016401 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
16402 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016403
16404 /* old style commands */
16405 install_element (VIEW_NODE, &show_ip_bgp_cmd);
16406 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
16407 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
16408 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
16409 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
16410 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
16411 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
16412 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
16413 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
16414 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
16415 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
16416 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
16417 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
16418 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
16419 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
16420 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
16421 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
16422 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
16423 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
16424 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
16425 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
16426 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
16427 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
16428 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
16429 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
16430 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
16431 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
16432 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
16433 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
16434 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
16435 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
16436 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
16437 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
16438 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
16439 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
16440 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
16441 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
16442 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
16443 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
16444 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
16445 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
16446 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
16447 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
16448 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
16449 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
16450 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
16451 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
16452 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
16453 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
16454 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
16455 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
16456 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
16457 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
16458 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
16459 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
16460 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
Balaji9c52cae2016-01-20 22:59:26 +053016461 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_parameters_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016462 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji9c52cae2016-01-20 22:59:26 +053016463 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_dampd_paths_cmd);
16464 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_flap_stats_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016465 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
16466 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
16467 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
16468 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
16469 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
16470 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
16471 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
16472 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
16473 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
16474 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
16475 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
16476 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
16477 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
16478 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
16479 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
16480 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
16481 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
16482 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
16483 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
16484 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
16485 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
16486 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
16487 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
16488 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
16489 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
16490 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
16491 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016492
Lou Bergerf9b6c392016-01-12 13:42:09 -050016493 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
16494 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
16495 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
16496 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
16497 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
16498 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
16499 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
16500 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
16501 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
16502 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
16503 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
16504 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
16505 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
16506 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
16507 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
16508 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
16509 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
16510 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
16511 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
16512 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
16513 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
16514 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
16515 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
16516 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
16517 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
16518 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
16519 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
16520 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
16521 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016522
16523 install_element (VIEW_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
16524 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
16525 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016526 install_element (VIEW_NODE, &show_bgp_cmd);
16527 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
16528 install_element (VIEW_NODE, &show_bgp_route_cmd);
16529 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
16530 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
16531 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
16532 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
16533 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
16534 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
16535 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
16536 install_element (VIEW_NODE, &show_bgp_community_cmd);
16537 install_element (VIEW_NODE, &show_bgp_community2_cmd);
16538 install_element (VIEW_NODE, &show_bgp_community3_cmd);
16539 install_element (VIEW_NODE, &show_bgp_community4_cmd);
16540 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
16541 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
16542 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
16543 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
16544 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_list_cmd);
16545 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
16546 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_list_exact_cmd);
16547 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
16548 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
16549 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
16550 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
16551 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
16552 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
16553 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
16554 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
16555 install_element (VIEW_NODE, &show_bgp_view_cmd);
16556 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
16557 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
16558 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
16559 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
16560 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
16561 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
16562 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
16563 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
16564 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016565
Lou Bergerf9b6c392016-01-12 13:42:09 -050016566 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
16567 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
16568 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
16569 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
16570 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
16571 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
16572 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
16573 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
16574 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
16575 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
16576 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
16577 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
16578 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016579
Lou Bergerf9b6c392016-01-12 13:42:09 -050016580 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
16581 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016582
Lou Bergerf9b6c392016-01-12 13:42:09 -050016583 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
16584 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
16585 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
16586 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
16587 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
16588 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
16589 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
16590 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
16591 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
16592 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
16593 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
16594 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
16595 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
16596 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
16597 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
16598 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
16599 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
16600 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
16601 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
16602 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
16603 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
16604 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
16605 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
16606 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
16607 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
16608 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
16609 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
16610 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
16611 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
16612 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
16613 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
16614 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
16615 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
16616 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
16617 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
16618 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016619 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016620 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016621 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016622 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016623 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016624 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016625 /* old with name safi collision */
16626 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
16627 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
16628 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
16629 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
16630 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
16631 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
16632 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
16633 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
16634 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
16635 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
16636 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
16637 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
16638 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
16639 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
16640 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
16641 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016642
Lou Bergerf9b6c392016-01-12 13:42:09 -050016643 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
16644 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016645
16646 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
16647 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
16648 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
16649 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016650
16651 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
16652 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
16653 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
16654 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016655}
Chris Caputo228da422009-07-18 05:44:03 +000016656
16657void
16658bgp_route_finish (void)
16659{
16660 bgp_table_unlock (bgp_distance_table);
16661 bgp_distance_table = NULL;
16662}