blob: 066637b32e5d9572512710121a1f843774a1a794 [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
Daniel Waltone25a9742015-11-09 20:21:50 -0500250 if (!BGP_INFO_COUNTABLE (ri)
Paul Jakma1a392d42006-09-07 00:24:49 +0000251 && 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 }
Daniel Waltone25a9742015-11-09 20:21:50 -0500267 else if (BGP_INFO_COUNTABLE (ri)
Paul Jakma1a392d42006-09-07 00:24:49 +0000268 && !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
Daniel Waltone25a9742015-11-09 20:21:50 -0500284 /* early bath if we know it's not a flag that changes countability state */
285 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
Paul Jakma1a392d42006-09-07 00:24:49 +0000286 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
Daniel Waltone25a9742015-11-09 20:21:50 -0500296 /* early bath if we know it's not a flag that changes countability state */
297 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED))
Paul Jakma1a392d42006-09-07 00:24:49 +0000298 return;
299
300 bgp_pcount_adjust (rn, ri);
301}
302
paul718e3742002-12-13 20:15:29 +0000303/* Get MED value. If MED value is missing and "bgp bestpath
304 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000305static u_int32_t
paul718e3742002-12-13 20:15:29 +0000306bgp_med_value (struct attr *attr, struct bgp *bgp)
307{
308 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
309 return attr->med;
310 else
311 {
312 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000313 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000314 else
315 return 0;
316 }
317}
318
Paul Jakma6d4742b2015-11-25 17:14:37 +0000319/* Compare two bgp route entity. Return -1 if new is preferred, 1 if exist
320 * is preferred, or 0 if they are the same (usually will only occur if
321 * multipath is enabled */
paul94f2b392005-06-28 12:44:16 +0000322static int
Josh Bailey96450fa2011-07-20 20:45:12 -0700323bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
Paul Jakma6d4742b2015-11-25 17:14:37 +0000324 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +0000325{
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000326 struct attr *newattr, *existattr;
327 struct attr_extra *newattre, *existattre;
328 bgp_peer_sort_t new_sort;
329 bgp_peer_sort_t exist_sort;
paul718e3742002-12-13 20:15:29 +0000330 u_int32_t new_pref;
331 u_int32_t exist_pref;
332 u_int32_t new_med;
333 u_int32_t exist_med;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000334 u_int32_t new_weight;
335 u_int32_t exist_weight;
336 uint32_t newm, existm;
paul718e3742002-12-13 20:15:29 +0000337 struct in_addr new_id;
338 struct in_addr exist_id;
339 int new_cluster;
340 int exist_cluster;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000341 int internal_as_route;
342 int confed_as_route;
paul718e3742002-12-13 20:15:29 +0000343 int ret;
Josh Bailey96450fa2011-07-20 20:45:12 -0700344
paul718e3742002-12-13 20:15:29 +0000345 /* 0. Null check. */
346 if (new == NULL)
paul718e3742002-12-13 20:15:29 +0000347 return 1;
Paul Jakma6d4742b2015-11-25 17:14:37 +0000348 if (exist == NULL)
349 return -1;
paul718e3742002-12-13 20:15:29 +0000350
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000351 newattr = new->attr;
352 existattr = exist->attr;
353 newattre = newattr->extra;
354 existattre = existattr->extra;
355
paul718e3742002-12-13 20:15:29 +0000356 /* 1. Weight check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000357 new_weight = exist_weight = 0;
358
359 if (newattre)
360 new_weight = newattre->weight;
361 if (existattre)
362 exist_weight = existattre->weight;
363
Paul Jakmafb982c22007-05-04 20:15:47 +0000364 if (new_weight > exist_weight)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000365 return -1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000366 if (new_weight < exist_weight)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000367 return 1;
paul718e3742002-12-13 20:15:29 +0000368
369 /* 2. Local preference check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000370 new_pref = exist_pref = bgp->default_local_pref;
paul718e3742002-12-13 20:15:29 +0000371
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000372 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
373 new_pref = newattr->local_pref;
374 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
375 exist_pref = existattr->local_pref;
376
paul718e3742002-12-13 20:15:29 +0000377 if (new_pref > exist_pref)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000378 return -1;
paul718e3742002-12-13 20:15:29 +0000379 if (new_pref < exist_pref)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000380 return 1;
paul718e3742002-12-13 20:15:29 +0000381
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000382 /* 3. Local route check. We prefer:
383 * - BGP_ROUTE_STATIC
384 * - BGP_ROUTE_AGGREGATE
385 * - BGP_ROUTE_REDISTRIBUTE
386 */
387 if (! (new->sub_type == BGP_ROUTE_NORMAL))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000388 return -1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000389 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000390 return 1;
paul718e3742002-12-13 20:15:29 +0000391
392 /* 4. AS path length check. */
393 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
394 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000395 int exist_hops = aspath_count_hops (existattr->aspath);
396 int exist_confeds = aspath_count_confeds (existattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000397
hasso68118452005-04-08 15:40:36 +0000398 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
399 {
paulfe69a502005-09-10 16:55:02 +0000400 int aspath_hops;
401
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000402 aspath_hops = aspath_count_hops (newattr->aspath);
403 aspath_hops += aspath_count_confeds (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000404
405 if ( aspath_hops < (exist_hops + exist_confeds))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000406 return -1;
paulfe69a502005-09-10 16:55:02 +0000407 if ( aspath_hops > (exist_hops + exist_confeds))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000408 return 1;
hasso68118452005-04-08 15:40:36 +0000409 }
410 else
411 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000412 int newhops = aspath_count_hops (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000413
414 if (newhops < exist_hops)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000415 return -1;
paulfe69a502005-09-10 16:55:02 +0000416 if (newhops > exist_hops)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000417 return 1;
hasso68118452005-04-08 15:40:36 +0000418 }
paul718e3742002-12-13 20:15:29 +0000419 }
420
421 /* 5. Origin check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000422 if (newattr->origin < existattr->origin)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000423 return -1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000424 if (newattr->origin > existattr->origin)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000425 return 1;
paul718e3742002-12-13 20:15:29 +0000426
427 /* 6. MED check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000428 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
429 && aspath_count_hops (existattr->aspath) == 0);
430 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
431 && aspath_count_confeds (existattr->aspath) > 0
432 && aspath_count_hops (newattr->aspath) == 0
433 && aspath_count_hops (existattr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000434
435 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
436 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
437 && confed_as_route)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000438 || aspath_cmp_left (newattr->aspath, existattr->aspath)
439 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
paul718e3742002-12-13 20:15:29 +0000440 || internal_as_route)
441 {
442 new_med = bgp_med_value (new->attr, bgp);
443 exist_med = bgp_med_value (exist->attr, bgp);
444
445 if (new_med < exist_med)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000446 return -1;
paul718e3742002-12-13 20:15:29 +0000447 if (new_med > exist_med)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000448 return 1;
paul718e3742002-12-13 20:15:29 +0000449 }
450
451 /* 7. Peer type check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000452 new_sort = new->peer->sort;
453 exist_sort = exist->peer->sort;
454
455 if (new_sort == BGP_PEER_EBGP
456 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000457 return -1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000458 if (exist_sort == BGP_PEER_EBGP
459 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000460 return 1;
paul718e3742002-12-13 20:15:29 +0000461
462 /* 8. IGP metric check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000463 newm = existm = 0;
464
465 if (new->extra)
466 newm = new->extra->igpmetric;
467 if (exist->extra)
468 existm = exist->extra->igpmetric;
469
Josh Bailey96450fa2011-07-20 20:45:12 -0700470 if (newm < existm)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000471 return -1;
Josh Bailey96450fa2011-07-20 20:45:12 -0700472 if (newm > existm)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000473 return 1;
paul718e3742002-12-13 20:15:29 +0000474
475 /* 9. Maximum path check. */
Paul Jakma6d4742b2015-11-25 17:14:37 +0000476 if (bgp_mpath_is_configured (bgp, afi, safi))
Josh Bailey96450fa2011-07-20 20:45:12 -0700477 {
Pradosh Mohapatra2fdd4552013-09-07 07:02:36 +0000478 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
479 {
Paul Jakma6d4742b2015-11-25 17:14:37 +0000480 /*
481 * For the two paths, all comparison steps till IGP metric
482 * have succeeded - including AS_PATH hop count. Since 'bgp
483 * bestpath as-path multipath-relax' knob is on, we don't need
484 * an exact match of AS_PATH. Thus, mark the paths are equal.
485 * That will trigger both these paths to get into the multipath
486 * array.
487 */
488 return 0;
Pradosh Mohapatra2fdd4552013-09-07 07:02:36 +0000489 }
490 else if (new->peer->sort == BGP_PEER_IBGP)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000491 {
492 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
493 return 0;
494 }
Josh Bailey96450fa2011-07-20 20:45:12 -0700495 else if (new->peer->as == exist->peer->as)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000496 return 0;
Josh Bailey96450fa2011-07-20 20:45:12 -0700497 }
paul718e3742002-12-13 20:15:29 +0000498
499 /* 10. If both paths are external, prefer the path that was received
500 first (the oldest one). This step minimizes route-flap, since a
501 newer path won't displace an older one, even if it was the
502 preferred route based on the additional decision criteria below. */
503 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000504 && new_sort == BGP_PEER_EBGP
505 && exist_sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +0000506 {
507 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000508 return -1;
paul718e3742002-12-13 20:15:29 +0000509 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000510 return 1;
paul718e3742002-12-13 20:15:29 +0000511 }
512
vivekbd4b7f12014-09-30 15:54:45 -0700513 /* 11. Router-ID comparision. */
514 /* If one of the paths is "stale", the corresponding peer router-id will
515 * be 0 and would always win over the other path. If originator id is
516 * used for the comparision, it will decide which path is better.
517 */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000518 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
519 new_id.s_addr = newattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000520 else
521 new_id.s_addr = new->peer->remote_id.s_addr;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000522 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
523 exist_id.s_addr = existattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000524 else
525 exist_id.s_addr = exist->peer->remote_id.s_addr;
526
527 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000528 return -1;
paul718e3742002-12-13 20:15:29 +0000529 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000530 return 1;
paul718e3742002-12-13 20:15:29 +0000531
532 /* 12. Cluster length comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000533 new_cluster = exist_cluster = 0;
534
535 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
536 new_cluster = newattre->cluster->length;
537 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
538 exist_cluster = existattre->cluster->length;
paul718e3742002-12-13 20:15:29 +0000539
540 if (new_cluster < exist_cluster)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000541 return -1;
paul718e3742002-12-13 20:15:29 +0000542 if (new_cluster > exist_cluster)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000543 return 1;
paul718e3742002-12-13 20:15:29 +0000544
545 /* 13. Neighbor address comparision. */
vivekbd4b7f12014-09-30 15:54:45 -0700546 /* Do this only if neither path is "stale" as stale paths do not have
547 * valid peer information (as the connection may or may not be up).
548 */
549 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000550 return -1;
vivekbd4b7f12014-09-30 15:54:45 -0700551 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000552 return 1;
Timo Teräs2820a012015-06-24 15:27:21 +0300553 /* locally configured routes to advertise do not have su_remote */
554 if (new->peer->su_remote == NULL)
Timo Teräs2820a012015-06-24 15:27:21 +0300555 return 1;
Paul Jakma6d4742b2015-11-25 17:14:37 +0000556 if (exist->peer->su_remote == NULL)
557 return -1;
Timo Teräs2820a012015-06-24 15:27:21 +0300558
paul718e3742002-12-13 20:15:29 +0000559 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
560
561 if (ret == 1)
paul718e3742002-12-13 20:15:29 +0000562 return 1;
Paul Jakma6d4742b2015-11-25 17:14:37 +0000563 if (ret == -1)
564 return -1;
paul718e3742002-12-13 20:15:29 +0000565
Paul Jakma6d4742b2015-11-25 17:14:37 +0000566 return -1;
paul718e3742002-12-13 20:15:29 +0000567}
568
paul94f2b392005-06-28 12:44:16 +0000569static enum filter_type
paul718e3742002-12-13 20:15:29 +0000570bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
571 afi_t afi, safi_t safi)
572{
573 struct bgp_filter *filter;
574
575 filter = &peer->filter[afi][safi];
576
Paul Jakma650f76c2009-06-25 18:06:31 +0100577#define FILTER_EXIST_WARN(F,f,filter) \
578 if (BGP_DEBUG (update, UPDATE_IN) \
579 && !(F ## _IN (filter))) \
580 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
581 peer->host, #f, F ## _IN_NAME(filter));
582
583 if (DISTRIBUTE_IN_NAME (filter)) {
584 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
585
paul718e3742002-12-13 20:15:29 +0000586 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
587 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100588 }
paul718e3742002-12-13 20:15:29 +0000589
Paul Jakma650f76c2009-06-25 18:06:31 +0100590 if (PREFIX_LIST_IN_NAME (filter)) {
591 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
592
paul718e3742002-12-13 20:15:29 +0000593 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
594 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100595 }
paul718e3742002-12-13 20:15:29 +0000596
Paul Jakma650f76c2009-06-25 18:06:31 +0100597 if (FILTER_LIST_IN_NAME (filter)) {
598 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
599
paul718e3742002-12-13 20:15:29 +0000600 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
601 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100602 }
603
paul718e3742002-12-13 20:15:29 +0000604 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100605#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000606}
607
paul94f2b392005-06-28 12:44:16 +0000608static enum filter_type
paul718e3742002-12-13 20:15:29 +0000609bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
610 afi_t afi, safi_t safi)
611{
612 struct bgp_filter *filter;
613
614 filter = &peer->filter[afi][safi];
615
Paul Jakma650f76c2009-06-25 18:06:31 +0100616#define FILTER_EXIST_WARN(F,f,filter) \
617 if (BGP_DEBUG (update, UPDATE_OUT) \
618 && !(F ## _OUT (filter))) \
619 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
620 peer->host, #f, F ## _OUT_NAME(filter));
621
622 if (DISTRIBUTE_OUT_NAME (filter)) {
623 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
624
paul718e3742002-12-13 20:15:29 +0000625 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
626 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100627 }
paul718e3742002-12-13 20:15:29 +0000628
Paul Jakma650f76c2009-06-25 18:06:31 +0100629 if (PREFIX_LIST_OUT_NAME (filter)) {
630 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
631
paul718e3742002-12-13 20:15:29 +0000632 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
633 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100634 }
paul718e3742002-12-13 20:15:29 +0000635
Paul Jakma650f76c2009-06-25 18:06:31 +0100636 if (FILTER_LIST_OUT_NAME (filter)) {
637 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
638
paul718e3742002-12-13 20:15:29 +0000639 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
640 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100641 }
paul718e3742002-12-13 20:15:29 +0000642
643 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100644#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000645}
646
647/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000648static int
paul718e3742002-12-13 20:15:29 +0000649bgp_community_filter (struct peer *peer, struct attr *attr)
650{
651 if (attr->community)
652 {
653 /* NO_ADVERTISE check. */
654 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
655 return 1;
656
657 /* NO_EXPORT check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000658 if (peer->sort == BGP_PEER_EBGP &&
paul718e3742002-12-13 20:15:29 +0000659 community_include (attr->community, COMMUNITY_NO_EXPORT))
660 return 1;
661
662 /* NO_EXPORT_SUBCONFED check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000663 if (peer->sort == BGP_PEER_EBGP
664 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000665 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
666 return 1;
667 }
668 return 0;
669}
670
671/* Route reflection loop check. */
672static int
673bgp_cluster_filter (struct peer *peer, struct attr *attr)
674{
675 struct in_addr cluster_id;
676
Paul Jakmafb982c22007-05-04 20:15:47 +0000677 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000678 {
679 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
680 cluster_id = peer->bgp->cluster_id;
681 else
682 cluster_id = peer->bgp->router_id;
683
Paul Jakmafb982c22007-05-04 20:15:47 +0000684 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000685 return 1;
686 }
687 return 0;
688}
David Lamparter6b0655a2014-06-04 06:53:35 +0200689
paul94f2b392005-06-28 12:44:16 +0000690static int
paul718e3742002-12-13 20:15:29 +0000691bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
692 afi_t afi, safi_t safi)
693{
694 struct bgp_filter *filter;
695 struct bgp_info info;
696 route_map_result_t ret;
697
698 filter = &peer->filter[afi][safi];
699
700 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000701 if (peer->weight)
702 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000703
704 /* Route map apply. */
705 if (ROUTE_MAP_IN_NAME (filter))
706 {
707 /* Duplicate current value to new strucutre for modification. */
708 info.peer = peer;
709 info.attr = attr;
710
paulac41b2a2003-08-12 05:32:27 +0000711 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
712
paul718e3742002-12-13 20:15:29 +0000713 /* Apply BGP route map to the attribute. */
714 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000715
716 peer->rmap_type = 0;
717
paul718e3742002-12-13 20:15:29 +0000718 if (ret == RMAP_DENYMATCH)
David Lamparterc460e572014-06-04 00:54:58 +0200719 /* caller has multiple error paths with bgp_attr_flush() */
720 return RMAP_DENY;
paul718e3742002-12-13 20:15:29 +0000721 }
722 return RMAP_PERMIT;
723}
David Lamparter6b0655a2014-06-04 06:53:35 +0200724
paul94f2b392005-06-28 12:44:16 +0000725static int
paulfee0f4c2004-09-13 05:12:46 +0000726bgp_export_modifier (struct peer *rsclient, struct peer *peer,
727 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
728{
729 struct bgp_filter *filter;
730 struct bgp_info info;
731 route_map_result_t ret;
732
733 filter = &peer->filter[afi][safi];
734
735 /* Route map apply. */
736 if (ROUTE_MAP_EXPORT_NAME (filter))
737 {
738 /* Duplicate current value to new strucutre for modification. */
739 info.peer = rsclient;
740 info.attr = attr;
741
742 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
743
744 /* Apply BGP route map to the attribute. */
745 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
746
747 rsclient->rmap_type = 0;
748
749 if (ret == RMAP_DENYMATCH)
750 {
751 /* Free newly generated AS path and community by route-map. */
752 bgp_attr_flush (attr);
753 return RMAP_DENY;
754 }
755 }
756 return RMAP_PERMIT;
757}
758
paul94f2b392005-06-28 12:44:16 +0000759static int
paulfee0f4c2004-09-13 05:12:46 +0000760bgp_import_modifier (struct peer *rsclient, struct peer *peer,
761 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
762{
763 struct bgp_filter *filter;
764 struct bgp_info info;
765 route_map_result_t ret;
766
767 filter = &rsclient->filter[afi][safi];
768
769 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000770 if (peer->weight)
771 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000772
773 /* Route map apply. */
774 if (ROUTE_MAP_IMPORT_NAME (filter))
775 {
776 /* Duplicate current value to new strucutre for modification. */
777 info.peer = peer;
778 info.attr = attr;
779
780 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
781
782 /* Apply BGP route map to the attribute. */
783 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
784
785 peer->rmap_type = 0;
786
787 if (ret == RMAP_DENYMATCH)
788 {
789 /* Free newly generated AS path and community by route-map. */
790 bgp_attr_flush (attr);
791 return RMAP_DENY;
792 }
793 }
794 return RMAP_PERMIT;
795}
David Lamparter6b0655a2014-06-04 06:53:35 +0200796
paul94f2b392005-06-28 12:44:16 +0000797static int
paul718e3742002-12-13 20:15:29 +0000798bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
799 struct attr *attr, afi_t afi, safi_t safi)
800{
801 int ret;
802 char buf[SU_ADDRSTRLEN];
803 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000804 struct peer *from;
805 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000806 int transparent;
807 int reflect;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700808 struct attr *riattr;
paul718e3742002-12-13 20:15:29 +0000809
810 from = ri->peer;
811 filter = &peer->filter[afi][safi];
812 bgp = peer->bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700813 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paul718e3742002-12-13 20:15:29 +0000814
Paul Jakma750e8142008-07-22 21:11:48 +0000815 if (DISABLE_BGP_ANNOUNCE)
816 return 0;
paul718e3742002-12-13 20:15:29 +0000817
paulfee0f4c2004-09-13 05:12:46 +0000818 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
819 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
820 return 0;
821
paul718e3742002-12-13 20:15:29 +0000822 /* Do not send back route to sender. */
823 if (from == peer)
824 return 0;
825
826 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000827 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000828 if (! UNSUPPRESS_MAP_NAME (filter))
829 return 0;
830
831 /* Default route check. */
832 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
833 {
834 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
835 return 0;
paul718e3742002-12-13 20:15:29 +0000836 else if (p->family == AF_INET6 && p->prefixlen == 0)
837 return 0;
paul718e3742002-12-13 20:15:29 +0000838 }
839
paul286e1e72003-08-08 00:24:31 +0000840 /* Transparency check. */
841 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
842 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
843 transparent = 1;
844 else
845 transparent = 0;
846
paul718e3742002-12-13 20:15:29 +0000847 /* If community is not disabled check the no-export and local. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700848 if (! transparent && bgp_community_filter (peer, riattr))
paul718e3742002-12-13 20:15:29 +0000849 return 0;
850
851 /* If the attribute has originator-id and it is same as remote
852 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700853 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paul718e3742002-12-13 20:15:29 +0000854 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700855 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000856 {
857 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000858 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000859 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
860 peer->host,
861 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
862 p->prefixlen);
863 return 0;
864 }
865 }
866
867 /* ORF prefix-list filter check */
868 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
869 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
870 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
871 if (peer->orf_plist[afi][safi])
872 {
873 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
874 return 0;
875 }
876
877 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700878 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
paul718e3742002-12-13 20:15:29 +0000879 {
880 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000881 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000882 "%s [Update:SEND] %s/%d is filtered",
883 peer->host,
884 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
885 p->prefixlen);
886 return 0;
887 }
888
889#ifdef BGP_SEND_ASPATH_CHECK
890 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700891 if (aspath_loop_check (riattr->aspath, peer->as))
paul718e3742002-12-13 20:15:29 +0000892 {
893 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000894 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400895 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000896 peer->host, peer->as);
897 return 0;
898 }
899#endif /* BGP_SEND_ASPATH_CHECK */
900
901 /* If we're a CONFED we need to loop check the CONFED ID too */
902 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
903 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700904 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
paul718e3742002-12-13 20:15:29 +0000905 {
906 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000907 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400908 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000909 peer->host,
910 bgp->confed_id);
911 return 0;
912 }
913 }
914
915 /* Route-Reflect check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000916 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +0000917 reflect = 1;
918 else
919 reflect = 0;
920
921 /* IBGP reflection check. */
922 if (reflect)
923 {
924 /* A route from a Client peer. */
925 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
926 {
927 /* Reflect to all the Non-Client peers and also to the
928 Client peers other than the originator. Originator check
929 is already done. So there is noting to do. */
930 /* no bgp client-to-client reflection check. */
931 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
932 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
933 return 0;
934 }
935 else
936 {
937 /* A route from a Non-client peer. Reflect to all other
938 clients. */
939 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
940 return 0;
941 }
942 }
Paul Jakma41367172007-08-06 15:24:51 +0000943
paul718e3742002-12-13 20:15:29 +0000944 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700945 bgp_attr_dup (attr, riattr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000946
paul718e3742002-12-13 20:15:29 +0000947 /* If local-preference is not set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000948 if ((peer->sort == BGP_PEER_IBGP
949 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000950 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
951 {
952 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
953 attr->local_pref = bgp->default_local_pref;
954 }
955
Pradosh Mohapatra689bb662013-09-07 07:13:37 +0000956 /* If originator-id is not set and the route is to be reflected,
957 set the originator id */
958 if (peer && from && peer->sort == BGP_PEER_IBGP &&
959 from->sort == BGP_PEER_IBGP &&
960 (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
961 {
962 attr->extra = bgp_attr_extra_get(attr);
963 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
964 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
965 }
966
paul718e3742002-12-13 20:15:29 +0000967 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000968 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000969 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
970 {
971 if (ri->peer != bgp->peer_self && ! transparent
972 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
973 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
974 }
975
Lou Berger298cc2f2016-01-12 13:42:02 -0500976
977#define NEXTHOP_IS_V4 (\
978 (safi != SAFI_ENCAP && p->family == AF_INET) || \
979 (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 4))
980
Lou Berger298cc2f2016-01-12 13:42:02 -0500981#define NEXTHOP_IS_V6 (\
982 (safi != SAFI_ENCAP && p->family == AF_INET6) || \
983 (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 16))
Lou Berger298cc2f2016-01-12 13:42:02 -0500984
paul718e3742002-12-13 20:15:29 +0000985 /* next-hop-set */
Timo Teräs9e7a53c2014-04-24 10:22:37 +0300986 if (transparent
987 || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
paul718e3742002-12-13 20:15:29 +0000988 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
Lou Berger298cc2f2016-01-12 13:42:02 -0500989 && ((NEXTHOP_IS_V4 && attr->nexthop.s_addr)
Lou Berger298cc2f2016-01-12 13:42:02 -0500990 || (NEXTHOP_IS_V6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000991 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000992 )))
paul718e3742002-12-13 20:15:29 +0000993 {
994 /* NEXT-HOP Unchanged. */
995 }
996 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
Lou Berger298cc2f2016-01-12 13:42:02 -0500997 || (NEXTHOP_IS_V4 && attr->nexthop.s_addr == 0)
Lou Berger298cc2f2016-01-12 13:42:02 -0500998 || (NEXTHOP_IS_V6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000999 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001000 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001001 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
1002 {
1003 /* Set IPv4 nexthop. */
Lou Berger298cc2f2016-01-12 13:42:02 -05001004 if (NEXTHOP_IS_V4)
paul718e3742002-12-13 20:15:29 +00001005 {
Lou Berger298cc2f2016-01-12 13:42:02 -05001006 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00001007 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1008 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +00001009 else
1010 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1011 }
paul718e3742002-12-13 20:15:29 +00001012 /* Set IPv6 nexthop. */
Lou Berger298cc2f2016-01-12 13:42:02 -05001013 if (NEXTHOP_IS_V6)
paul718e3742002-12-13 20:15:29 +00001014 {
1015 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001016 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001017 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001018 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001019 }
paul718e3742002-12-13 20:15:29 +00001020 }
1021
Lou Berger298cc2f2016-01-12 13:42:02 -05001022 if (p->family == AF_INET6 && safi != SAFI_ENCAP)
paul718e3742002-12-13 20:15:29 +00001023 {
paulfee0f4c2004-09-13 05:12:46 +00001024 /* Left nexthop_local unchanged if so configured. */
1025 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1026 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1027 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001028 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1029 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001030 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001031 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001032 }
1033
1034 /* Default nexthop_local treatment for non-RS-Clients */
1035 else
1036 {
paul718e3742002-12-13 20:15:29 +00001037 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001038 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001039
1040 /* Set link-local address for shared network peer. */
1041 if (peer->shared_network
1042 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1043 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001044 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001045 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001046 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001047 }
1048
1049 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1050 address.*/
1051 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001052 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001053
1054 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1055 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001056 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001057 }
paulfee0f4c2004-09-13 05:12:46 +00001058
1059 }
paul718e3742002-12-13 20:15:29 +00001060
1061 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001062 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001063 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1064 && aspath_private_as_check (attr->aspath))
1065 attr->aspath = aspath_empty_get ();
1066
1067 /* Route map & unsuppress-map apply. */
1068 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001069 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001070 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001071 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001072 struct attr dummy_attr;
1073 struct attr_extra dummy_extra;
1074
1075 dummy_attr.extra = &dummy_extra;
1076
paul718e3742002-12-13 20:15:29 +00001077 info.peer = peer;
1078 info.attr = attr;
1079
1080 /* The route reflector is not allowed to modify the attributes
Dinesh Dutt083e5e22015-11-09 20:21:54 -05001081 of the reflected IBGP routes, unless configured to allow it */
1082 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP) &&
1083 !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
paul718e3742002-12-13 20:15:29 +00001084 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001085 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001086 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001087 }
paulac41b2a2003-08-12 05:32:27 +00001088
1089 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1090
Paul Jakmafb982c22007-05-04 20:15:47 +00001091 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001092 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1093 else
1094 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1095
paulac41b2a2003-08-12 05:32:27 +00001096 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001097
paul718e3742002-12-13 20:15:29 +00001098 if (ret == RMAP_DENYMATCH)
1099 {
1100 bgp_attr_flush (attr);
1101 return 0;
1102 }
1103 }
1104 return 1;
1105}
1106
paul94f2b392005-06-28 12:44:16 +00001107static int
paulfee0f4c2004-09-13 05:12:46 +00001108bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1109 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001110{
paulfee0f4c2004-09-13 05:12:46 +00001111 int ret;
1112 char buf[SU_ADDRSTRLEN];
1113 struct bgp_filter *filter;
1114 struct bgp_info info;
1115 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001116 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001117
1118 from = ri->peer;
1119 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001120 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001121
Paul Jakma750e8142008-07-22 21:11:48 +00001122 if (DISABLE_BGP_ANNOUNCE)
1123 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001124
1125 /* Do not send back route to sender. */
1126 if (from == rsclient)
1127 return 0;
1128
1129 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001130 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001131 if (! UNSUPPRESS_MAP_NAME (filter))
1132 return 0;
1133
1134 /* Default route check. */
1135 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1136 PEER_STATUS_DEFAULT_ORIGINATE))
1137 {
1138 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1139 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001140 else if (p->family == AF_INET6 && p->prefixlen == 0)
1141 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001142 }
1143
1144 /* If the attribute has originator-id and it is same as remote
1145 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001146 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001147 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001148 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001149 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001150 {
1151 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001152 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001153 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1154 rsclient->host,
1155 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1156 p->prefixlen);
1157 return 0;
1158 }
1159 }
1160
1161 /* ORF prefix-list filter check */
1162 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1163 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1164 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1165 if (rsclient->orf_plist[afi][safi])
1166 {
1167 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1168 return 0;
1169 }
1170
1171 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001172 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001173 {
1174 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001175 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001176 "%s [Update:SEND] %s/%d is filtered",
1177 rsclient->host,
1178 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1179 p->prefixlen);
1180 return 0;
1181 }
1182
1183#ifdef BGP_SEND_ASPATH_CHECK
1184 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001185 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001186 {
1187 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001188 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001189 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001190 rsclient->host, rsclient->as);
1191 return 0;
1192 }
1193#endif /* BGP_SEND_ASPATH_CHECK */
1194
1195 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001196 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001197
1198 /* next-hop-set */
1199 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
paulfee0f4c2004-09-13 05:12:46 +00001200 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001201 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001202 )
1203 {
1204 /* Set IPv4 nexthop. */
1205 if (p->family == AF_INET)
1206 {
Lou Berger298cc2f2016-01-12 13:42:02 -05001207 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00001208 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001209 IPV4_MAX_BYTELEN);
1210 else
1211 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1212 }
paulfee0f4c2004-09-13 05:12:46 +00001213 /* Set IPv6 nexthop. */
1214 if (p->family == AF_INET6)
1215 {
1216 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001217 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001218 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001219 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001220 }
paulfee0f4c2004-09-13 05:12:46 +00001221 }
1222
paulfee0f4c2004-09-13 05:12:46 +00001223 if (p->family == AF_INET6)
1224 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001225 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001226
paulfee0f4c2004-09-13 05:12:46 +00001227 /* Left nexthop_local unchanged if so configured. */
1228 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1229 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1230 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001231 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1232 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001233 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001234 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001235 }
1236
1237 /* Default nexthop_local treatment for RS-Clients */
1238 else
1239 {
1240 /* Announcer and RS-Client are both in the same network */
1241 if (rsclient->shared_network && from->shared_network &&
1242 (rsclient->ifindex == from->ifindex))
1243 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001244 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1245 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001246 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001247 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001248 }
1249
1250 /* Set link-local address for shared network peer. */
1251 else if (rsclient->shared_network
1252 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1253 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001254 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001255 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001256 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001257 }
1258
1259 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001260 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001261 }
1262
1263 }
paulfee0f4c2004-09-13 05:12:46 +00001264
1265 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001266 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001267 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1268 && aspath_private_as_check (attr->aspath))
1269 attr->aspath = aspath_empty_get ();
1270
1271 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001272 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001273 {
1274 info.peer = rsclient;
1275 info.attr = attr;
1276
1277 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1278
Paul Jakmafb982c22007-05-04 20:15:47 +00001279 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001280 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1281 else
1282 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1283
1284 rsclient->rmap_type = 0;
1285
1286 if (ret == RMAP_DENYMATCH)
1287 {
1288 bgp_attr_flush (attr);
1289 return 0;
1290 }
1291 }
1292
1293 return 1;
1294}
1295
1296struct bgp_info_pair
1297{
1298 struct bgp_info *old;
1299 struct bgp_info *new;
1300};
1301
paul94f2b392005-06-28 12:44:16 +00001302static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001303bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
Paul Jakma6d4742b2015-11-25 17:14:37 +00001304 struct bgp_info_pair *result,
1305 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00001306{
paul718e3742002-12-13 20:15:29 +00001307 struct bgp_info *new_select;
1308 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001309 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001310 struct bgp_info *ri1;
1311 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001312 struct bgp_info *nextri = NULL;
Paul Jakma6d4742b2015-11-25 17:14:37 +00001313 int cmpret, do_mpath;
Josh Bailey96450fa2011-07-20 20:45:12 -07001314 struct list mp_list;
Paul Jakma91b9e852015-12-01 14:32:11 +00001315
1316 result->old = result->new = NULL;
1317
1318 if (rn->info == NULL)
1319 {
1320 char buf[PREFIX_STRLEN];
1321 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1322 __func__,
1323 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1324 return;
1325 }
1326
Josh Bailey96450fa2011-07-20 20:45:12 -07001327 bgp_mp_list_init (&mp_list);
Paul Jakma6d4742b2015-11-25 17:14:37 +00001328 do_mpath = bgp_mpath_is_configured (bgp, afi, safi);
Josh Bailey96450fa2011-07-20 20:45:12 -07001329
paul718e3742002-12-13 20:15:29 +00001330 /* bgp deterministic-med */
1331 new_select = NULL;
1332 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1333 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1334 {
1335 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1336 continue;
1337 if (BGP_INFO_HOLDDOWN (ri1))
1338 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001339 if (ri1->peer && ri1->peer != bgp->peer_self)
1340 if (ri1->peer->status != Established)
1341 continue;
paul718e3742002-12-13 20:15:29 +00001342
1343 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001344 if (do_mpath)
1345 bgp_mp_list_add (&mp_list, ri1);
1346 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001347 if (ri1->next)
1348 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1349 {
1350 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1351 continue;
1352 if (BGP_INFO_HOLDDOWN (ri2))
1353 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001354 if (ri2->peer &&
1355 ri2->peer != bgp->peer_self &&
1356 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1357 if (ri2->peer->status != Established)
1358 continue;
paul718e3742002-12-13 20:15:29 +00001359
1360 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1361 || aspath_cmp_left_confed (ri1->attr->aspath,
1362 ri2->attr->aspath))
1363 {
Josh Bailey6918e742011-07-20 20:48:20 -07001364 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1365 old_select = ri2;
Paul Jakma6d4742b2015-11-25 17:14:37 +00001366 if ((cmpret = bgp_info_cmp (bgp, ri2, new_select, afi, safi))
1367 == -1)
paul718e3742002-12-13 20:15:29 +00001368 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001369 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001370 new_select = ri2;
1371 }
1372
Paul Jakma6d4742b2015-11-25 17:14:37 +00001373 if (do_mpath)
1374 {
1375 if (cmpret != 0)
1376 bgp_mp_list_clear (&mp_list);
1377
1378 if (cmpret == 0 || cmpret == -1)
1379 bgp_mp_list_add (&mp_list, ri2);
1380 }
Josh Bailey6918e742011-07-20 20:48:20 -07001381
Paul Jakma1a392d42006-09-07 00:24:49 +00001382 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001383 }
1384 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001385 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1386 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001387
Paul Jakma6d4742b2015-11-25 17:14:37 +00001388 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, afi, safi);
Josh Bailey6918e742011-07-20 20:48:20 -07001389 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001390 }
1391
1392 /* Check old selected route and new selected route. */
1393 old_select = NULL;
1394 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001395 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001396 {
1397 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1398 old_select = ri;
1399
1400 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001401 {
1402 /* reap REMOVED routes, if needs be
1403 * selected route must stay for a while longer though
1404 */
1405 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1406 && (ri != old_select))
1407 bgp_info_reap (rn, ri);
1408
1409 continue;
1410 }
paul718e3742002-12-13 20:15:29 +00001411
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001412 if (ri->peer &&
1413 ri->peer != bgp->peer_self &&
1414 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1415 if (ri->peer->status != Established)
1416 continue;
1417
paul718e3742002-12-13 20:15:29 +00001418 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1419 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1420 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001421 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001422 continue;
1423 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001424 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1425 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001426
Paul Jakma6d4742b2015-11-25 17:14:37 +00001427 if ((cmpret = bgp_info_cmp (bgp, ri, new_select, afi, safi)) == -1)
Josh Bailey96450fa2011-07-20 20:45:12 -07001428 {
Josh Bailey6918e742011-07-20 20:48:20 -07001429 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1430 bgp_mp_dmed_deselect (new_select);
1431
Josh Bailey96450fa2011-07-20 20:45:12 -07001432 new_select = ri;
Josh Bailey96450fa2011-07-20 20:45:12 -07001433 }
Paul Jakma6d4742b2015-11-25 17:14:37 +00001434 else if (cmpret == 1 && do_mpath
1435 && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
Josh Bailey6918e742011-07-20 20:48:20 -07001436 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001437
Paul Jakma6d4742b2015-11-25 17:14:37 +00001438 if (do_mpath)
1439 {
1440 if (cmpret != 0)
1441 bgp_mp_list_clear (&mp_list);
1442
1443 if (cmpret == 0 || cmpret == -1)
1444 bgp_mp_list_add (&mp_list, ri);
1445 }
paul718e3742002-12-13 20:15:29 +00001446 }
paulfee0f4c2004-09-13 05:12:46 +00001447
Josh Bailey6918e742011-07-20 20:48:20 -07001448 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
Paul Jakma6d4742b2015-11-25 17:14:37 +00001449 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, afi, safi);
Josh Bailey96450fa2011-07-20 20:45:12 -07001450
Josh Bailey0b597ef2011-07-20 20:49:11 -07001451 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001452 bgp_mp_list_clear (&mp_list);
1453
1454 result->old = old_select;
1455 result->new = new_select;
1456
1457 return;
paulfee0f4c2004-09-13 05:12:46 +00001458}
1459
paul94f2b392005-06-28 12:44:16 +00001460static int
paulfee0f4c2004-09-13 05:12:46 +00001461bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001462 struct bgp_node *rn, afi_t afi, safi_t safi)
1463{
paulfee0f4c2004-09-13 05:12:46 +00001464 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001465 struct attr attr;
1466 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001467
Lou Berger050defe2016-01-12 13:41:59 -05001468 memset (&attr, 0, sizeof(struct attr));
1469 memset (&extra, 0, sizeof(struct attr_extra));
1470
paulfee0f4c2004-09-13 05:12:46 +00001471 p = &rn->p;
1472
Paul Jakma9eda90c2007-08-30 13:36:17 +00001473 /* Announce route to Established peer. */
1474 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001475 return 0;
1476
Paul Jakma9eda90c2007-08-30 13:36:17 +00001477 /* Address family configuration check. */
1478 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001479 return 0;
1480
Paul Jakma9eda90c2007-08-30 13:36:17 +00001481 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001482 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1483 PEER_STATUS_ORF_WAIT_REFRESH))
1484 return 0;
1485
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001486 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1487 attr.extra = &extra;
1488
Avneesh Sachdev67174042012-08-17 08:19:49 -07001489 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001490 {
1491 case BGP_TABLE_MAIN:
1492 /* Announcement to peer->conf. If the route is filtered,
1493 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001494 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1495 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001496 else
1497 bgp_adj_out_unset (rn, peer, p, afi, safi);
1498 break;
1499 case BGP_TABLE_RSCLIENT:
1500 /* Announcement to peer->conf. If the route is filtered,
1501 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001502 if (selected &&
1503 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1504 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1505 else
1506 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001507 break;
1508 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001509
Lou Berger050defe2016-01-12 13:41:59 -05001510 bgp_attr_flush (&attr);
paulfee0f4c2004-09-13 05:12:46 +00001511 return 0;
paul200df112005-06-01 11:17:05 +00001512}
paulfee0f4c2004-09-13 05:12:46 +00001513
paul200df112005-06-01 11:17:05 +00001514struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001515{
paul200df112005-06-01 11:17:05 +00001516 struct bgp *bgp;
1517 struct bgp_node *rn;
1518 afi_t afi;
1519 safi_t safi;
1520};
1521
1522static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001523bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001524{
paul0fb58d52005-11-14 14:31:49 +00001525 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001526 struct bgp *bgp = pq->bgp;
1527 struct bgp_node *rn = pq->rn;
1528 afi_t afi = pq->afi;
1529 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001530 struct bgp_info *new_select;
1531 struct bgp_info *old_select;
1532 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001533 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001534 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001535
paulfee0f4c2004-09-13 05:12:46 +00001536 /* Best path selection. */
Paul Jakma6d4742b2015-11-25 17:14:37 +00001537 bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001538 new_select = old_and_new.new;
1539 old_select = old_and_new.old;
1540
paul200df112005-06-01 11:17:05 +00001541 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1542 {
Chris Caputo228da422009-07-18 05:44:03 +00001543 if (rsclient->group)
1544 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1545 {
1546 /* Nothing to do. */
1547 if (old_select && old_select == new_select)
1548 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1549 continue;
paulfee0f4c2004-09-13 05:12:46 +00001550
Chris Caputo228da422009-07-18 05:44:03 +00001551 if (old_select)
1552 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1553 if (new_select)
1554 {
1555 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1556 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001557 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1558 }
paulfee0f4c2004-09-13 05:12:46 +00001559
Chris Caputo228da422009-07-18 05:44:03 +00001560 bgp_process_announce_selected (rsclient, new_select, rn,
1561 afi, safi);
1562 }
paul200df112005-06-01 11:17:05 +00001563 }
1564 else
1565 {
hassob7395792005-08-26 12:58:38 +00001566 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001567 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001568 if (new_select)
1569 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001570 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1571 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001572 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001573 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001574 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001575 }
paulfee0f4c2004-09-13 05:12:46 +00001576
paulb40d9392005-08-22 22:34:41 +00001577 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1578 bgp_info_reap (rn, old_select);
1579
paul200df112005-06-01 11:17:05 +00001580 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1581 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001582}
1583
paul200df112005-06-01 11:17:05 +00001584static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001585bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001586{
paul0fb58d52005-11-14 14:31:49 +00001587 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001588 struct bgp *bgp = pq->bgp;
1589 struct bgp_node *rn = pq->rn;
1590 afi_t afi = pq->afi;
1591 safi_t safi = pq->safi;
1592 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001593 struct bgp_info *new_select;
1594 struct bgp_info *old_select;
1595 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001596 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001597 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001598
paulfee0f4c2004-09-13 05:12:46 +00001599 /* Best path selection. */
Paul Jakma6d4742b2015-11-25 17:14:37 +00001600 bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001601 old_select = old_and_new.old;
1602 new_select = old_and_new.new;
1603
1604 /* Nothing to do. */
Daniel Walton325fcfb2015-05-19 17:58:10 -07001605 if (old_select && old_select == new_select
1606 && !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR))
paulfee0f4c2004-09-13 05:12:46 +00001607 {
1608 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001609 {
Josh Bailey8196f132011-07-20 20:47:07 -07001610 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1611 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001612 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001613
Josh Bailey8196f132011-07-20 20:47:07 -07001614 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001615 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1616 return WQ_SUCCESS;
1617 }
paulfee0f4c2004-09-13 05:12:46 +00001618 }
paul718e3742002-12-13 20:15:29 +00001619
Daniel Walton325fcfb2015-05-19 17:58:10 -07001620 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
1621 UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
1622
hasso338b3422005-02-23 14:27:24 +00001623 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001624 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001625 if (new_select)
1626 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001627 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1628 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001629 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001630 }
1631
1632
paul718e3742002-12-13 20:15:29 +00001633 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001634 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001635 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001636 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001637 }
1638
1639 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001640 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1641 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001642 {
1643 if (new_select
1644 && new_select->type == ZEBRA_ROUTE_BGP
1645 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001646 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001647 else
1648 {
1649 /* Withdraw the route from the kernel. */
1650 if (old_select
1651 && old_select->type == ZEBRA_ROUTE_BGP
1652 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001653 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001654 }
1655 }
paulb40d9392005-08-22 22:34:41 +00001656
Lou Berger050defe2016-01-12 13:41:59 -05001657 /* Reap old select bgp_info, if it has been removed */
paulb40d9392005-08-22 22:34:41 +00001658 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1659 bgp_info_reap (rn, old_select);
1660
paul200df112005-06-01 11:17:05 +00001661 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1662 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001663}
1664
paul200df112005-06-01 11:17:05 +00001665static void
paul0fb58d52005-11-14 14:31:49 +00001666bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001667{
paul0fb58d52005-11-14 14:31:49 +00001668 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001669 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001670
Chris Caputo228da422009-07-18 05:44:03 +00001671 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001672 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001673 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001674 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1675}
1676
1677static void
1678bgp_process_queue_init (void)
1679{
1680 bm->process_main_queue
1681 = work_queue_new (bm->master, "process_main_queue");
1682 bm->process_rsclient_queue
1683 = work_queue_new (bm->master, "process_rsclient_queue");
1684
1685 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1686 {
1687 zlog_err ("%s: Failed to allocate work queue", __func__);
1688 exit (1);
1689 }
1690
1691 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001692 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001693 bm->process_main_queue->spec.max_retries = 0;
1694 bm->process_main_queue->spec.hold = 50;
1695
Paul Jakma838bbde2010-01-08 14:05:32 +00001696 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
David Lamparterd43f8b32015-03-03 08:54:54 +01001697 bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del;
1698 bm->process_rsclient_queue->spec.max_retries = 0;
1699 bm->process_rsclient_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001700}
1701
1702void
paulfee0f4c2004-09-13 05:12:46 +00001703bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1704{
paul200df112005-06-01 11:17:05 +00001705 struct bgp_process_queue *pqnode;
1706
1707 /* already scheduled for processing? */
1708 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1709 return;
1710
Paul Jakma91b9e852015-12-01 14:32:11 +00001711 if (rn->info == NULL)
1712 {
1713 /* XXX: Perhaps remove before next release, after we've flushed out
1714 * any obvious cases
1715 */
1716 assert (rn->info != NULL);
1717 char buf[PREFIX_STRLEN];
1718 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1719 __func__,
1720 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1721 return;
1722 }
1723
paul200df112005-06-01 11:17:05 +00001724 if ( (bm->process_main_queue == NULL) ||
1725 (bm->process_rsclient_queue == NULL) )
1726 bgp_process_queue_init ();
1727
1728 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1729 sizeof (struct bgp_process_queue));
1730 if (!pqnode)
1731 return;
Chris Caputo228da422009-07-18 05:44:03 +00001732
1733 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001734 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001735 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001736 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001737 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001738 pqnode->afi = afi;
1739 pqnode->safi = safi;
1740
Avneesh Sachdev67174042012-08-17 08:19:49 -07001741 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001742 {
paul200df112005-06-01 11:17:05 +00001743 case BGP_TABLE_MAIN:
1744 work_queue_add (bm->process_main_queue, pqnode);
1745 break;
1746 case BGP_TABLE_RSCLIENT:
1747 work_queue_add (bm->process_rsclient_queue, pqnode);
1748 break;
paulfee0f4c2004-09-13 05:12:46 +00001749 }
paul200df112005-06-01 11:17:05 +00001750
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001751 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001752 return;
paulfee0f4c2004-09-13 05:12:46 +00001753}
hasso0a486e52005-02-01 20:57:17 +00001754
paul94f2b392005-06-28 12:44:16 +00001755static int
hasso0a486e52005-02-01 20:57:17 +00001756bgp_maximum_prefix_restart_timer (struct thread *thread)
1757{
1758 struct peer *peer;
1759
1760 peer = THREAD_ARG (thread);
1761 peer->t_pmax_restart = NULL;
1762
1763 if (BGP_DEBUG (events, EVENTS))
1764 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1765 peer->host);
1766
1767 peer_clear (peer);
1768
1769 return 0;
1770}
1771
paulfee0f4c2004-09-13 05:12:46 +00001772int
paul5228ad22004-06-04 17:58:18 +00001773bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1774 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001775{
hassoe0701b72004-05-20 09:19:34 +00001776 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1777 return 0;
1778
1779 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001780 {
hassoe0701b72004-05-20 09:19:34 +00001781 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1782 && ! always)
1783 return 0;
paul718e3742002-12-13 20:15:29 +00001784
hassoe0701b72004-05-20 09:19:34 +00001785 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001786 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1787 "limit %ld", afi_safi_print (afi, safi), peer->host,
1788 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001789 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001790
hassoe0701b72004-05-20 09:19:34 +00001791 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1792 return 0;
paul718e3742002-12-13 20:15:29 +00001793
hassoe0701b72004-05-20 09:19:34 +00001794 {
paul5228ad22004-06-04 17:58:18 +00001795 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001796
1797 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001798 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001799
1800 ndata[0] = (afi >> 8);
1801 ndata[1] = afi;
1802 ndata[2] = safi;
1803 ndata[3] = (peer->pmax[afi][safi] >> 24);
1804 ndata[4] = (peer->pmax[afi][safi] >> 16);
1805 ndata[5] = (peer->pmax[afi][safi] >> 8);
1806 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001807
1808 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1809 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1810 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1811 }
hasso0a486e52005-02-01 20:57:17 +00001812
1813 /* restart timer start */
1814 if (peer->pmax_restart[afi][safi])
1815 {
1816 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1817
1818 if (BGP_DEBUG (events, EVENTS))
1819 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1820 peer->host, peer->v_pmax_restart);
1821
1822 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1823 peer->v_pmax_restart);
1824 }
1825
hassoe0701b72004-05-20 09:19:34 +00001826 return 1;
paul718e3742002-12-13 20:15:29 +00001827 }
hassoe0701b72004-05-20 09:19:34 +00001828 else
1829 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1830
1831 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1832 {
1833 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1834 && ! always)
1835 return 0;
1836
1837 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001838 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1839 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1840 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001841 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1842 }
1843 else
1844 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001845 return 0;
1846}
1847
paulb40d9392005-08-22 22:34:41 +00001848/* Unconditionally remove the route from the RIB, without taking
1849 * damping into consideration (eg, because the session went down)
1850 */
paul94f2b392005-06-28 12:44:16 +00001851static void
paul718e3742002-12-13 20:15:29 +00001852bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1853 afi_t afi, safi_t safi)
1854{
paul902212c2006-02-05 17:51:19 +00001855 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1856
1857 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1858 bgp_info_delete (rn, ri); /* keep historical info */
1859
paulb40d9392005-08-22 22:34:41 +00001860 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001861}
1862
paul94f2b392005-06-28 12:44:16 +00001863static void
paul718e3742002-12-13 20:15:29 +00001864bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
Lou Berger050defe2016-01-12 13:41:59 -05001865 afi_t afi, safi_t safi, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00001866{
paul718e3742002-12-13 20:15:29 +00001867 int status = BGP_DAMP_NONE;
1868
paulb40d9392005-08-22 22:34:41 +00001869 /* apply dampening, if result is suppressed, we'll be retaining
1870 * the bgp_info in the RIB for historical reference.
1871 */
1872 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001873 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001874 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1875 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001876 {
paul902212c2006-02-05 17:51:19 +00001877 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1878 return;
1879 }
1880
1881 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001882}
1883
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05001884static struct bgp_info *
1885info_make (int type, int sub_type, struct peer *peer, struct attr *attr,
1886 struct bgp_node *rn)
1887{
1888 struct bgp_info *new;
1889
1890 /* Make new BGP info. */
1891 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
1892 new->type = type;
1893 new->sub_type = sub_type;
1894 new->peer = peer;
1895 new->attr = attr;
1896 new->uptime = bgp_clock ();
1897 new->net = rn;
1898 return new;
1899}
1900
paul94f2b392005-06-28 12:44:16 +00001901static void
paulfee0f4c2004-09-13 05:12:46 +00001902bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1903 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1904 int sub_type, struct prefix_rd *prd, u_char *tag)
1905{
1906 struct bgp_node *rn;
1907 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001908 struct attr new_attr;
1909 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001910 struct attr *attr_new;
1911 struct attr *attr_new2;
1912 struct bgp_info *ri;
1913 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001914 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001915 char buf[SU_ADDRSTRLEN];
1916
1917 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1918 if (peer == rsclient)
1919 return;
1920
1921 bgp = peer->bgp;
1922 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1923
1924 /* Check previously received route. */
1925 for (ri = rn->info; ri; ri = ri->next)
1926 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1927 break;
1928
1929 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001930 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001931 {
1932 reason = "as-path contains our own AS;";
1933 goto filtered;
1934 }
1935
1936 /* Route reflector originator ID check. */
1937 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001938 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001939 {
1940 reason = "originator is us;";
1941 goto filtered;
1942 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001943
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001944 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001945 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001946
1947 /* Apply export policy. */
1948 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1949 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1950 {
1951 reason = "export-policy;";
1952 goto filtered;
1953 }
1954
1955 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001956
paulfee0f4c2004-09-13 05:12:46 +00001957 /* Apply import policy. */
1958 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1959 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001960 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001961
1962 reason = "import-policy;";
1963 goto filtered;
1964 }
1965
1966 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001967 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001968
1969 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001970 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001971 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001972 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001973 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001974 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001975 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001976 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001977
1978 reason = "martian next-hop;";
1979 goto filtered;
1980 }
1981 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001982
paulfee0f4c2004-09-13 05:12:46 +00001983 /* If the update is implicit withdraw. */
1984 if (ri)
1985 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001986 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001987
1988 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001989 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1990 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001991 {
1992
paulfee0f4c2004-09-13 05:12:46 +00001993
1994 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001995 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001996 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1997 peer->host,
1998 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1999 p->prefixlen, rsclient->host);
2000
Chris Caputo228da422009-07-18 05:44:03 +00002001 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002002 bgp_attr_unintern (&attr_new);
Lou Berger050defe2016-01-12 13:41:59 -05002003 bgp_attr_flush(&new_attr);
Chris Caputo228da422009-07-18 05:44:03 +00002004 return;
paulfee0f4c2004-09-13 05:12:46 +00002005 }
2006
Paul Jakma16d2e242007-04-10 19:32:10 +00002007 /* Withdraw/Announce before we fully processed the withdraw */
2008 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2009 bgp_info_restore (rn, ri);
2010
paulfee0f4c2004-09-13 05:12:46 +00002011 /* Received Logging. */
2012 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002013 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002014 peer->host,
2015 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2016 p->prefixlen, rsclient->host);
2017
2018 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002019 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00002020
2021 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002022 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00002023 ri->attr = attr_new;
2024
2025 /* Update MPLS tag. */
2026 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002027 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002028
Paul Jakma1a392d42006-09-07 00:24:49 +00002029 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002030
2031 /* Process change. */
2032 bgp_process (bgp, rn, afi, safi);
2033 bgp_unlock_node (rn);
2034
2035 return;
2036 }
2037
2038 /* Received Logging. */
2039 if (BGP_DEBUG (update, UPDATE_IN))
2040 {
ajsd2c1f162004-12-08 21:10:20 +00002041 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002042 peer->host,
2043 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2044 p->prefixlen, rsclient->host);
2045 }
2046
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05002047 new = info_make(type, sub_type, peer, attr_new, rn);
paulfee0f4c2004-09-13 05:12:46 +00002048
2049 /* Update MPLS tag. */
2050 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002051 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002052
Paul Jakma1a392d42006-09-07 00:24:49 +00002053 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002054
2055 /* Register new BGP information. */
2056 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002057
2058 /* route_node_get lock */
2059 bgp_unlock_node (rn);
2060
paulfee0f4c2004-09-13 05:12:46 +00002061 /* Process change. */
2062 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002063
paulfee0f4c2004-09-13 05:12:46 +00002064 return;
2065
2066 filtered:
2067
2068 /* This BGP update is filtered. Log the reason then update BGP entry. */
2069 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002070 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002071 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2072 peer->host,
2073 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2074 p->prefixlen, rsclient->host, reason);
2075
2076 if (ri)
paulb40d9392005-08-22 22:34:41 +00002077 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002078
2079 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002080
paulfee0f4c2004-09-13 05:12:46 +00002081 return;
2082}
2083
paul94f2b392005-06-28 12:44:16 +00002084static void
paulfee0f4c2004-09-13 05:12:46 +00002085bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2086 struct peer *peer, struct prefix *p, int type, int sub_type,
2087 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002088{
paulfee0f4c2004-09-13 05:12:46 +00002089 struct bgp_node *rn;
2090 struct bgp_info *ri;
2091 char buf[SU_ADDRSTRLEN];
2092
2093 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002094 return;
paulfee0f4c2004-09-13 05:12:46 +00002095
2096 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2097
2098 /* Lookup withdrawn route. */
2099 for (ri = rn->info; ri; ri = ri->next)
2100 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2101 break;
2102
2103 /* Withdraw specified route from routing table. */
2104 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Lou Berger050defe2016-01-12 13:41:59 -05002105 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
paulfee0f4c2004-09-13 05:12:46 +00002106 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002107 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002108 "%s Can't find the route %s/%d", peer->host,
2109 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2110 p->prefixlen);
2111
2112 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002113 bgp_unlock_node (rn);
2114}
paulfee0f4c2004-09-13 05:12:46 +00002115
paul94f2b392005-06-28 12:44:16 +00002116static int
paulfee0f4c2004-09-13 05:12:46 +00002117bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002118 afi_t afi, safi_t safi, int type, int sub_type,
2119 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2120{
2121 int ret;
2122 int aspath_loop_count = 0;
2123 struct bgp_node *rn;
2124 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002125 struct attr new_attr;
2126 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002127 struct attr *attr_new;
2128 struct bgp_info *ri;
2129 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002130 const char *reason;
paul718e3742002-12-13 20:15:29 +00002131 char buf[SU_ADDRSTRLEN];
2132
Lou Berger370b7e52016-02-04 21:29:49 -05002133 memset (&new_attr, 0, sizeof(struct attr));
2134 memset (&new_extra, 0, sizeof(struct attr_extra));
2135
paul718e3742002-12-13 20:15:29 +00002136 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002137 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002138
paul718e3742002-12-13 20:15:29 +00002139 /* When peer's soft reconfiguration enabled. Record input packet in
2140 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002141 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2142 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002143 bgp_adj_in_set (rn, peer, attr);
2144
2145 /* Check previously received route. */
2146 for (ri = rn->info; ri; ri = ri->next)
2147 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2148 break;
2149
2150 /* AS path local-as loop check. */
2151 if (peer->change_local_as)
2152 {
2153 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2154 aspath_loop_count = 1;
2155
2156 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2157 {
2158 reason = "as-path contains our own AS;";
2159 goto filtered;
2160 }
2161 }
2162
2163 /* AS path loop check. */
2164 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2165 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2166 && aspath_loop_check(attr->aspath, bgp->confed_id)
2167 > peer->allowas_in[afi][safi]))
2168 {
2169 reason = "as-path contains our own AS;";
2170 goto filtered;
2171 }
2172
2173 /* Route reflector originator ID check. */
2174 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002175 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002176 {
2177 reason = "originator is us;";
2178 goto filtered;
2179 }
2180
2181 /* Route reflector cluster ID check. */
2182 if (bgp_cluster_filter (peer, attr))
2183 {
2184 reason = "reflected from the same cluster;";
2185 goto filtered;
2186 }
2187
2188 /* Apply incoming filter. */
2189 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2190 {
2191 reason = "filter;";
2192 goto filtered;
2193 }
2194
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002195 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002196 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002197
David Lamparterc460e572014-06-04 00:54:58 +02002198 /* Apply incoming route-map.
2199 * NB: new_attr may now contain newly allocated values from route-map "set"
2200 * commands, so we need bgp_attr_flush in the error paths, until we intern
2201 * the attr (which takes over the memory references) */
paul718e3742002-12-13 20:15:29 +00002202 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2203 {
2204 reason = "route-map;";
David Lamparterc460e572014-06-04 00:54:58 +02002205 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002206 goto filtered;
2207 }
2208
2209 /* IPv4 unicast next hop check. */
2210 if (afi == AFI_IP && safi == SAFI_UNICAST)
2211 {
2212 /* If the peer is EBGP and nexthop is not on connected route,
2213 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002214 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002215 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002216 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002217 {
2218 reason = "non-connected next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002219 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002220 goto filtered;
2221 }
2222
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002223 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002224 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002225 if (new_attr.nexthop.s_addr == 0
2226 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2227 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002228 {
2229 reason = "martian next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002230 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002231 goto filtered;
2232 }
2233 }
2234
2235 attr_new = bgp_attr_intern (&new_attr);
2236
2237 /* If the update is implicit withdraw. */
2238 if (ri)
2239 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002240 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002241
2242 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002243 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2244 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002245 {
paul718e3742002-12-13 20:15:29 +00002246 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002247 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002248 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2249 {
2250 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002251 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002252 peer->host,
2253 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2254 p->prefixlen);
2255
paul902212c2006-02-05 17:51:19 +00002256 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2257 {
2258 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2259 bgp_process (bgp, rn, afi, safi);
2260 }
paul718e3742002-12-13 20:15:29 +00002261 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002262 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002263 {
2264 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002265 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002266 "%s rcvd %s/%d...duplicate ignored",
2267 peer->host,
2268 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2269 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002270
2271 /* graceful restart STALE flag unset. */
2272 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2273 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002274 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002275 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002276 }
paul718e3742002-12-13 20:15:29 +00002277 }
2278
2279 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002280 bgp_attr_unintern (&attr_new);
Lou Berger050defe2016-01-12 13:41:59 -05002281 bgp_attr_flush (&new_attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002282
paul718e3742002-12-13 20:15:29 +00002283 return 0;
2284 }
2285
Paul Jakma16d2e242007-04-10 19:32:10 +00002286 /* Withdraw/Announce before we fully processed the withdraw */
2287 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2288 {
2289 if (BGP_DEBUG (update, UPDATE_IN))
2290 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2291 peer->host,
2292 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2293 p->prefixlen);
2294 bgp_info_restore (rn, ri);
2295 }
2296
paul718e3742002-12-13 20:15:29 +00002297 /* Received Logging. */
2298 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002299 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002300 peer->host,
2301 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2302 p->prefixlen);
2303
hasso93406d82005-02-02 14:40:33 +00002304 /* graceful restart STALE flag unset. */
2305 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002306 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002307
paul718e3742002-12-13 20:15:29 +00002308 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002309 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002310
2311 /* implicit withdraw, decrement aggregate and pcount here.
2312 * only if update is accepted, they'll increment below.
2313 */
paul902212c2006-02-05 17:51:19 +00002314 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2315
paul718e3742002-12-13 20:15:29 +00002316 /* Update bgp route dampening information. */
2317 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002318 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002319 {
2320 /* This is implicit withdraw so we should update dampening
2321 information. */
2322 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2323 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002324 }
2325
paul718e3742002-12-13 20:15:29 +00002326 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002327 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002328 ri->attr = attr_new;
2329
2330 /* Update MPLS tag. */
2331 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002332 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002333
Lou Berger050defe2016-01-12 13:41:59 -05002334 bgp_attr_flush (&new_attr);
2335
paul718e3742002-12-13 20:15:29 +00002336 /* Update bgp route dampening information. */
2337 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002338 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002339 {
2340 /* Now we do normal update dampening. */
2341 ret = bgp_damp_update (ri, rn, afi, safi);
2342 if (ret == BGP_DAMP_SUPPRESSED)
2343 {
2344 bgp_unlock_node (rn);
2345 return 0;
2346 }
2347 }
2348
2349 /* Nexthop reachability check. */
2350 if ((afi == AFI_IP || afi == AFI_IP6)
2351 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002352 && (peer->sort == BGP_PEER_IBGP
2353 || peer->sort == BGP_PEER_CONFED
2354 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002355 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002356 {
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05002357 if (bgp_find_or_add_nexthop (afi, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002358 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002359 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002360 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002361 }
2362 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002363 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002364
Lou Berger050defe2016-01-12 13:41:59 -05002365 bgp_attr_flush (&new_attr);
2366
paul718e3742002-12-13 20:15:29 +00002367 /* Process change. */
2368 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2369
2370 bgp_process (bgp, rn, afi, safi);
2371 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002372
paul718e3742002-12-13 20:15:29 +00002373 return 0;
2374 }
2375
2376 /* Received Logging. */
2377 if (BGP_DEBUG (update, UPDATE_IN))
2378 {
ajsd2c1f162004-12-08 21:10:20 +00002379 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002380 peer->host,
2381 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2382 p->prefixlen);
2383 }
2384
paul718e3742002-12-13 20:15:29 +00002385 /* Make new BGP info. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05002386 new = info_make(type, sub_type, peer, attr_new, rn);
paul718e3742002-12-13 20:15:29 +00002387
2388 /* Update MPLS tag. */
2389 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002390 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002391
2392 /* Nexthop reachability check. */
2393 if ((afi == AFI_IP || afi == AFI_IP6)
2394 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002395 && (peer->sort == BGP_PEER_IBGP
2396 || peer->sort == BGP_PEER_CONFED
2397 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002398 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002399 {
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05002400 if (bgp_find_or_add_nexthop (afi, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002401 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002402 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002403 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002404 }
2405 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002406 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002407
paul902212c2006-02-05 17:51:19 +00002408 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002409 bgp_aggregate_increment (bgp, p, new, afi, safi);
2410
2411 /* Register new BGP information. */
2412 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002413
2414 /* route_node_get lock */
2415 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002416
Lou Berger050defe2016-01-12 13:41:59 -05002417 bgp_attr_flush (&new_attr);
2418
paul718e3742002-12-13 20:15:29 +00002419 /* If maximum prefix count is configured and current prefix
2420 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002421 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2422 return -1;
paul718e3742002-12-13 20:15:29 +00002423
2424 /* Process change. */
2425 bgp_process (bgp, rn, afi, safi);
2426
2427 return 0;
2428
2429 /* This BGP update is filtered. Log the reason then update BGP
2430 entry. */
2431 filtered:
2432 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002433 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002434 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2435 peer->host,
2436 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2437 p->prefixlen, reason);
2438
2439 if (ri)
paulb40d9392005-08-22 22:34:41 +00002440 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002441
2442 bgp_unlock_node (rn);
Lou Berger050defe2016-01-12 13:41:59 -05002443 bgp_attr_flush (&new_attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002444
paul718e3742002-12-13 20:15:29 +00002445 return 0;
2446}
2447
2448int
paulfee0f4c2004-09-13 05:12:46 +00002449bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2450 afi_t afi, safi_t safi, int type, int sub_type,
2451 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2452{
2453 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002454 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002455 struct bgp *bgp;
2456 int ret;
2457
2458 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2459 soft_reconfig);
2460
2461 bgp = peer->bgp;
2462
2463 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002464 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002465 {
2466 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2467 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2468 sub_type, prd, tag);
2469 }
2470
2471 return ret;
2472}
2473
2474int
paul718e3742002-12-13 20:15:29 +00002475bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002476 afi_t afi, safi_t safi, int type, int sub_type,
2477 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002478{
2479 struct bgp *bgp;
2480 char buf[SU_ADDRSTRLEN];
2481 struct bgp_node *rn;
2482 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002483 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002484 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002485
2486 bgp = peer->bgp;
2487
David Lamparter4584c232015-04-13 09:50:00 +02002488 /* Lookup node. */
2489 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2490
2491 /* Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2492 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2493 * the iteration over all RS clients.
2494 * Since we need to remove the entry from adj_in anyway, do that first and
2495 * if there was no entry, we don't need to do anything more. */
2496 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2497 && peer != bgp->peer_self)
2498 if (!bgp_adj_in_unset (rn, peer))
2499 {
2500 if (BGP_DEBUG (update, UPDATE_IN))
2501 zlog (peer->log, LOG_DEBUG, "%s withdrawing route %s/%d "
2502 "not in adj-in", peer->host,
2503 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2504 p->prefixlen);
2505 bgp_unlock_node (rn);
2506 return 0;
2507 }
2508
paulfee0f4c2004-09-13 05:12:46 +00002509 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002510 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002511 {
2512 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2513 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2514 }
2515
paul718e3742002-12-13 20:15:29 +00002516 /* Logging. */
2517 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002518 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002519 peer->host,
2520 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2521 p->prefixlen);
2522
paul718e3742002-12-13 20:15:29 +00002523 /* Lookup withdrawn route. */
2524 for (ri = rn->info; ri; ri = ri->next)
2525 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2526 break;
2527
2528 /* Withdraw specified route from routing table. */
2529 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Lou Berger050defe2016-01-12 13:41:59 -05002530 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
paul718e3742002-12-13 20:15:29 +00002531 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002532 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002533 "%s Can't find the route %s/%d", peer->host,
2534 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2535 p->prefixlen);
2536
2537 /* Unlock bgp_node_get() lock. */
2538 bgp_unlock_node (rn);
2539
2540 return 0;
2541}
David Lamparter6b0655a2014-06-04 06:53:35 +02002542
paul718e3742002-12-13 20:15:29 +00002543void
2544bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2545{
2546 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002547 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002548 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002549 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002550 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002551 struct bgp_node *rn;
2552 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002553 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002554
Paul Jakmab2497022007-06-14 11:17:58 +00002555 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002556 return;
2557
paul718e3742002-12-13 20:15:29 +00002558 bgp = peer->bgp;
2559 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002560
paul718e3742002-12-13 20:15:29 +00002561 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2562 aspath = attr.aspath;
2563 attr.local_pref = bgp->default_local_pref;
2564 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2565
2566 if (afi == AFI_IP)
2567 str2prefix ("0.0.0.0/0", &p);
paul718e3742002-12-13 20:15:29 +00002568 else if (afi == AFI_IP6)
2569 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002570 struct attr_extra *ae = attr.extra;
2571
paul718e3742002-12-13 20:15:29 +00002572 str2prefix ("::/0", &p);
2573
2574 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002575 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002576 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002577 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002578
2579 /* If the peer is on shared nextwork and we have link-local
2580 nexthop set it. */
2581 if (peer->shared_network
2582 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2583 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002584 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002585 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002586 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002587 }
2588 }
paul718e3742002-12-13 20:15:29 +00002589
2590 if (peer->default_rmap[afi][safi].name)
2591 {
paulfee0f4c2004-09-13 05:12:46 +00002592 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002593 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2594 {
2595 for (ri = rn->info; ri; ri = ri->next)
2596 {
2597 struct attr dummy_attr;
2598 struct attr_extra dummy_extra;
2599 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002600
Christian Frankedcab1bb2012-12-07 16:45:52 +00002601 /* Provide dummy so the route-map can't modify the attributes */
2602 dummy_attr.extra = &dummy_extra;
2603 bgp_attr_dup(&dummy_attr, ri->attr);
2604 info.peer = ri->peer;
2605 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002606
Christian Frankedcab1bb2012-12-07 16:45:52 +00002607 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2608 RMAP_BGP, &info);
2609
2610 /* The route map might have set attributes. If we don't flush them
2611 * here, they will be leaked. */
2612 bgp_attr_flush(&dummy_attr);
2613 if (ret != RMAP_DENYMATCH)
2614 break;
2615 }
2616 if (ret != RMAP_DENYMATCH)
2617 break;
2618 }
paulfee0f4c2004-09-13 05:12:46 +00002619 bgp->peer_self->rmap_type = 0;
2620
paul718e3742002-12-13 20:15:29 +00002621 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002622 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002623 }
2624
2625 if (withdraw)
2626 {
2627 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2628 bgp_default_withdraw_send (peer, afi, safi);
2629 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2630 }
2631 else
2632 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002633 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2634 {
2635 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2636 bgp_default_update_send (peer, &attr, afi, safi, from);
2637 }
paul718e3742002-12-13 20:15:29 +00002638 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002639
2640 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002641 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002642}
David Lamparter6b0655a2014-06-04 06:53:35 +02002643
paul718e3742002-12-13 20:15:29 +00002644static void
2645bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002646 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002647{
2648 struct bgp_node *rn;
2649 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002650 struct attr attr;
2651 struct attr_extra extra;
2652
Lou Berger298cc2f2016-01-12 13:42:02 -05002653 memset(&extra, 0, sizeof(extra));
2654
paul718e3742002-12-13 20:15:29 +00002655 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002656 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002657
Lou Berger298cc2f2016-01-12 13:42:02 -05002658 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP)
paul718e3742002-12-13 20:15:29 +00002659 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2660 bgp_default_originate (peer, afi, safi, 0);
2661
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002662 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2663 attr.extra = &extra;
2664
paul718e3742002-12-13 20:15:29 +00002665 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2666 for (ri = rn->info; ri; ri = ri->next)
2667 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2668 {
paulfee0f4c2004-09-13 05:12:46 +00002669 if ( (rsclient) ?
2670 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2671 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002672 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2673 else
2674 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2675 }
Lou Berger298cc2f2016-01-12 13:42:02 -05002676
2677 bgp_attr_flush_encap(&attr);
paul718e3742002-12-13 20:15:29 +00002678}
2679
2680void
2681bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2682{
2683 struct bgp_node *rn;
2684 struct bgp_table *table;
2685
2686 if (peer->status != Established)
2687 return;
2688
2689 if (! peer->afc_nego[afi][safi])
2690 return;
2691
2692 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2693 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2694 return;
2695
Lou Berger298cc2f2016-01-12 13:42:02 -05002696 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
paulfee0f4c2004-09-13 05:12:46 +00002697 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002698 else
2699 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2700 rn = bgp_route_next(rn))
2701 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002702 bgp_announce_table (peer, afi, safi, table, 0);
2703
2704 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2705 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002706}
2707
2708void
2709bgp_announce_route_all (struct peer *peer)
2710{
2711 afi_t afi;
2712 safi_t safi;
2713
2714 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2715 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2716 bgp_announce_route (peer, afi, safi);
2717}
David Lamparter6b0655a2014-06-04 06:53:35 +02002718
paul718e3742002-12-13 20:15:29 +00002719static void
paulfee0f4c2004-09-13 05:12:46 +00002720bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002721 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002722{
2723 struct bgp_node *rn;
2724 struct bgp_adj_in *ain;
2725
2726 if (! table)
2727 table = rsclient->bgp->rib[afi][safi];
2728
2729 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2730 for (ain = rn->adj_in; ain; ain = ain->next)
2731 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002732 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002733 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002734
paulfee0f4c2004-09-13 05:12:46 +00002735 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002736 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002737 }
2738}
2739
2740void
2741bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2742{
2743 struct bgp_table *table;
2744 struct bgp_node *rn;
2745
Lou Berger298cc2f2016-01-12 13:42:02 -05002746 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002747 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002748
2749 else
2750 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2751 rn = bgp_route_next (rn))
2752 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002753 {
2754 struct prefix_rd prd;
2755 prd.family = AF_UNSPEC;
2756 prd.prefixlen = 64;
2757 memcpy(&prd.val, rn->p.u.val, 8);
2758
2759 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2760 }
paulfee0f4c2004-09-13 05:12:46 +00002761}
David Lamparter6b0655a2014-06-04 06:53:35 +02002762
paulfee0f4c2004-09-13 05:12:46 +00002763static void
paul718e3742002-12-13 20:15:29 +00002764bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002765 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002766{
2767 int ret;
2768 struct bgp_node *rn;
2769 struct bgp_adj_in *ain;
2770
2771 if (! table)
2772 table = peer->bgp->rib[afi][safi];
2773
2774 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2775 for (ain = rn->adj_in; ain; ain = ain->next)
2776 {
2777 if (ain->peer == peer)
2778 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002779 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002780 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002781
paul718e3742002-12-13 20:15:29 +00002782 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2783 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002784 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002785
paul718e3742002-12-13 20:15:29 +00002786 if (ret < 0)
2787 {
2788 bgp_unlock_node (rn);
2789 return;
2790 }
2791 continue;
2792 }
2793 }
2794}
2795
2796void
2797bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2798{
2799 struct bgp_node *rn;
2800 struct bgp_table *table;
2801
2802 if (peer->status != Established)
2803 return;
2804
Lou Berger298cc2f2016-01-12 13:42:02 -05002805 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002806 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002807 else
2808 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2809 rn = bgp_route_next (rn))
2810 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002811 {
2812 struct prefix_rd prd;
2813 prd.family = AF_UNSPEC;
2814 prd.prefixlen = 64;
2815 memcpy(&prd.val, rn->p.u.val, 8);
2816
2817 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2818 }
paul718e3742002-12-13 20:15:29 +00002819}
David Lamparter6b0655a2014-06-04 06:53:35 +02002820
Chris Caputo228da422009-07-18 05:44:03 +00002821
2822struct bgp_clear_node_queue
2823{
2824 struct bgp_node *rn;
2825 enum bgp_clear_route_type purpose;
2826};
2827
paul200df112005-06-01 11:17:05 +00002828static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002829bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002830{
Chris Caputo228da422009-07-18 05:44:03 +00002831 struct bgp_clear_node_queue *cnq = data;
2832 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002833 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002834 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002835 afi_t afi = bgp_node_table (rn)->afi;
2836 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002837
Paul Jakma64e580a2006-02-21 01:09:01 +00002838 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002839
Paul Jakma64e580a2006-02-21 01:09:01 +00002840 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002841 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002842 {
2843 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002844 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2845 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002846 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002847 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2848 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002849 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002850 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002851 break;
2852 }
paul200df112005-06-01 11:17:05 +00002853 return WQ_SUCCESS;
2854}
2855
2856static void
paul0fb58d52005-11-14 14:31:49 +00002857bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002858{
Chris Caputo228da422009-07-18 05:44:03 +00002859 struct bgp_clear_node_queue *cnq = data;
2860 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002861 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002862
2863 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002864 bgp_table_unlock (table);
2865 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002866}
2867
2868static void
paul94f2b392005-06-28 12:44:16 +00002869bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002870{
Paul Jakma64e580a2006-02-21 01:09:01 +00002871 struct peer *peer = wq->spec.data;
2872
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002873 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002874 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002875
2876 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002877}
2878
2879static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002880bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002881{
Paul Jakmaa2943652009-07-21 14:02:04 +01002882 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002883
Paul Jakmaa2943652009-07-21 14:02:04 +01002884 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002885#undef CLEAR_QUEUE_NAME_LEN
2886
2887 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002888 {
2889 zlog_err ("%s: Failed to allocate work queue", __func__);
2890 exit (1);
2891 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002892 peer->clear_node_queue->spec.hold = 10;
2893 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2894 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2895 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2896 peer->clear_node_queue->spec.max_retries = 0;
2897
2898 /* we only 'lock' this peer reference when the queue is actually active */
2899 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002900}
2901
paul718e3742002-12-13 20:15:29 +00002902static void
2903bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002904 struct bgp_table *table, struct peer *rsclient,
2905 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002906{
2907 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002908
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002909
paul718e3742002-12-13 20:15:29 +00002910 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002911 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002912
hasso6cf159b2005-03-21 10:28:14 +00002913 /* If still no table => afi/safi isn't configured at all or smth. */
2914 if (! table)
2915 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002916
2917 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2918 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002919 struct bgp_info *ri;
2920 struct bgp_adj_in *ain;
2921 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002922
2923 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2924 * queued for every clearing peer, regardless of whether it is
2925 * relevant to the peer at hand.
2926 *
2927 * Overview: There are 3 different indices which need to be
2928 * scrubbed, potentially, when a peer is removed:
2929 *
2930 * 1 peer's routes visible via the RIB (ie accepted routes)
2931 * 2 peer's routes visible by the (optional) peer's adj-in index
2932 * 3 other routes visible by the peer's adj-out index
2933 *
2934 * 3 there is no hurry in scrubbing, once the struct peer is
2935 * removed from bgp->peer, we could just GC such deleted peer's
2936 * adj-outs at our leisure.
2937 *
2938 * 1 and 2 must be 'scrubbed' in some way, at least made
2939 * invisible via RIB index before peer session is allowed to be
2940 * brought back up. So one needs to know when such a 'search' is
2941 * complete.
2942 *
2943 * Ideally:
2944 *
2945 * - there'd be a single global queue or a single RIB walker
2946 * - rather than tracking which route_nodes still need to be
2947 * examined on a peer basis, we'd track which peers still
2948 * aren't cleared
2949 *
2950 * Given that our per-peer prefix-counts now should be reliable,
2951 * this may actually be achievable. It doesn't seem to be a huge
2952 * problem at this time,
2953 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002954 for (ain = rn->adj_in; ain; ain = ain->next)
2955 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2956 {
2957 bgp_adj_in_remove (rn, ain);
2958 bgp_unlock_node (rn);
2959 break;
2960 }
2961 for (aout = rn->adj_out; aout; aout = aout->next)
2962 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2963 {
2964 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2965 bgp_unlock_node (rn);
2966 break;
2967 }
2968
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002969 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002970 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002971 {
Chris Caputo228da422009-07-18 05:44:03 +00002972 struct bgp_clear_node_queue *cnq;
2973
2974 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002975 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002976 bgp_lock_node (rn);
2977 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2978 sizeof (struct bgp_clear_node_queue));
2979 cnq->rn = rn;
2980 cnq->purpose = purpose;
2981 work_queue_add (peer->clear_node_queue, cnq);
2982 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002983 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002984 }
2985 return;
2986}
2987
2988void
Chris Caputo228da422009-07-18 05:44:03 +00002989bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2990 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002991{
2992 struct bgp_node *rn;
2993 struct bgp_table *table;
2994 struct peer *rsclient;
2995 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002996
Paul Jakma64e580a2006-02-21 01:09:01 +00002997 if (peer->clear_node_queue == NULL)
2998 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002999
Paul Jakmaca058a32006-09-14 02:58:49 +00003000 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3001 * Idle until it receives a Clearing_Completed event. This protects
3002 * against peers which flap faster than we can we clear, which could
3003 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00003004 *
3005 * a) race with routes from the new session being installed before
3006 * clear_route_node visits the node (to delete the route of that
3007 * peer)
3008 * b) resource exhaustion, clear_route_node likely leads to an entry
3009 * on the process_main queue. Fast-flapping could cause that queue
3010 * to grow and grow.
paul200df112005-06-01 11:17:05 +00003011 */
Donald Sharp7ef42212015-03-30 06:32:52 -07003012
3013 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3014 * the unlock will happen upon work-queue completion; other wise, the
3015 * unlock happens at the end of this function.
3016 */
Paul Jakmaca058a32006-09-14 02:58:49 +00003017 if (!peer->clear_node_queue->thread)
Lou Berger050defe2016-01-12 13:41:59 -05003018 peer_lock (peer); /* bgp_clear_node_complete */
Chris Caputo228da422009-07-18 05:44:03 +00003019 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00003020 {
Chris Caputo228da422009-07-18 05:44:03 +00003021 case BGP_CLEAR_ROUTE_NORMAL:
Lou Berger298cc2f2016-01-12 13:42:02 -05003022 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Chris Caputo228da422009-07-18 05:44:03 +00003023 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
3024 else
3025 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3026 rn = bgp_route_next (rn))
3027 if ((table = rn->info) != NULL)
3028 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3029
3030 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
3031 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
3032 PEER_FLAG_RSERVER_CLIENT))
3033 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3034 break;
3035
3036 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
Lou Berger050defe2016-01-12 13:41:59 -05003037 /*
3038 * gpz 091009: TBD why don't we have special handling for
3039 * SAFI_MPLS_VPN here in the original quagga code?
3040 * (and, by extension, for SAFI_ENCAP)
3041 */
Chris Caputo228da422009-07-18 05:44:03 +00003042 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3043 break;
3044
3045 default:
3046 assert (0);
3047 break;
paulfee0f4c2004-09-13 05:12:46 +00003048 }
Donald Sharp7ef42212015-03-30 06:32:52 -07003049
3050 /* unlock if no nodes got added to the clear-node-queue. */
Paul Jakma65ca75e2006-05-04 08:08:15 +00003051 if (!peer->clear_node_queue->thread)
Donald Sharp7ef42212015-03-30 06:32:52 -07003052 peer_unlock (peer);
3053
paul718e3742002-12-13 20:15:29 +00003054}
3055
3056void
3057bgp_clear_route_all (struct peer *peer)
3058{
3059 afi_t afi;
3060 safi_t safi;
3061
3062 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3063 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003064 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003065}
3066
Lou Berger82dd7072016-01-12 13:41:57 -05003067/*
3068 * Finish freeing things when exiting
3069 */
3070static void
3071bgp_drain_workqueue_immediate (struct work_queue *wq)
3072{
3073 if (!wq)
3074 return;
3075
3076 if (!wq->thread)
3077 {
3078 /*
3079 * no thread implies no queued items
3080 */
3081 assert(!wq->items->count);
3082 return;
3083 }
3084
3085 while (wq->items->count)
3086 {
3087 if (wq->thread)
3088 thread_cancel(wq->thread);
3089 work_queue_run(wq->thread);
3090 }
3091}
3092
3093/*
3094 * Special function to process clear node queue when bgpd is exiting
3095 * and the thread scheduler is no longer running.
3096 */
3097void
3098bgp_peer_clear_node_queue_drain_immediate(struct peer *peer)
3099{
3100 if (!peer)
3101 return;
3102
3103 bgp_drain_workqueue_immediate(peer->clear_node_queue);
3104}
3105
3106/*
3107 * The work queues are not specific to a BGP instance, but the
3108 * items in them refer to BGP instances, so this should be called
3109 * before each BGP instance is deleted.
3110 */
3111void
3112bgp_process_queues_drain_immediate(void)
3113{
3114 bgp_drain_workqueue_immediate(bm->process_main_queue);
3115 bgp_drain_workqueue_immediate(bm->process_rsclient_queue);
3116}
3117
paul718e3742002-12-13 20:15:29 +00003118void
3119bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3120{
3121 struct bgp_table *table;
3122 struct bgp_node *rn;
3123 struct bgp_adj_in *ain;
3124
3125 table = peer->bgp->rib[afi][safi];
3126
3127 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3128 for (ain = rn->adj_in; ain ; ain = ain->next)
3129 if (ain->peer == peer)
3130 {
3131 bgp_adj_in_remove (rn, ain);
3132 bgp_unlock_node (rn);
3133 break;
3134 }
3135}
hasso93406d82005-02-02 14:40:33 +00003136
3137void
3138bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3139{
3140 struct bgp_node *rn;
3141 struct bgp_info *ri;
3142 struct bgp_table *table;
3143
3144 table = peer->bgp->rib[afi][safi];
3145
3146 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3147 {
3148 for (ri = rn->info; ri; ri = ri->next)
3149 if (ri->peer == peer)
3150 {
3151 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3152 bgp_rib_remove (rn, ri, peer, afi, safi);
3153 break;
3154 }
3155 }
3156}
David Lamparter6b0655a2014-06-04 06:53:35 +02003157
Lou Berger82dd7072016-01-12 13:41:57 -05003158static void
3159bgp_cleanup_table(struct bgp_table *table, safi_t safi)
3160{
3161 struct bgp_node *rn;
3162 struct bgp_info *ri;
3163 struct bgp_info *next;
3164
3165 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3166 for (ri = rn->info; ri; ri = next)
3167 {
3168 next = ri->next;
3169 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3170 && ri->type == ZEBRA_ROUTE_BGP
3171 && ri->sub_type == BGP_ROUTE_NORMAL)
3172 bgp_zebra_withdraw (&rn->p, ri, safi);
3173 }
3174}
3175
paul718e3742002-12-13 20:15:29 +00003176/* Delete all kernel routes. */
3177void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003178bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003179{
3180 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003181 struct listnode *node, *nnode;
Lou Berger82dd7072016-01-12 13:41:57 -05003182 afi_t afi;
paul718e3742002-12-13 20:15:29 +00003183
paul1eb8ef22005-04-07 07:30:20 +00003184 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003185 {
Lou Berger82dd7072016-01-12 13:41:57 -05003186 for (afi = AFI_IP; afi < AFI_MAX; ++afi)
3187 {
3188 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00003189
Lou Berger82dd7072016-01-12 13:41:57 -05003190 bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003191
Lou Berger82dd7072016-01-12 13:41:57 -05003192 /*
3193 * VPN and ENCAP tables are two-level (RD is top level)
3194 */
3195 for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn;
3196 rn = bgp_route_next (rn))
Lou Berger298cc2f2016-01-12 13:42:02 -05003197 {
3198 if (rn->info)
Lou Berger82dd7072016-01-12 13:41:57 -05003199 {
Lou Berger298cc2f2016-01-12 13:42:02 -05003200 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN);
3201 bgp_table_finish ((struct bgp_table **)&(rn->info));
3202 rn->info = NULL;
3203 bgp_unlock_node(rn);
Lou Berger82dd7072016-01-12 13:41:57 -05003204 }
Lou Berger298cc2f2016-01-12 13:42:02 -05003205 }
3206
3207 for (rn = bgp_table_top(bgp->rib[afi][SAFI_ENCAP]); rn;
3208 rn = bgp_route_next (rn))
3209 {
3210 if (rn->info)
3211 {
3212 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_ENCAP);
3213 bgp_table_finish ((struct bgp_table **)&(rn->info));
3214 rn->info = NULL;
3215 bgp_unlock_node(rn);
3216 }
3217 }
Lou Berger82dd7072016-01-12 13:41:57 -05003218 }
paul718e3742002-12-13 20:15:29 +00003219 }
3220}
3221
3222void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003223bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003224{
3225 vty_reset ();
3226 bgp_zclient_reset ();
3227 access_list_reset ();
3228 prefix_list_reset ();
3229}
David Lamparter6b0655a2014-06-04 06:53:35 +02003230
paul718e3742002-12-13 20:15:29 +00003231/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3232 value. */
3233int
Paul Jakma518a4b72016-02-04 13:27:04 +00003234bgp_nlri_parse_ip (struct peer *peer, struct attr *attr,
3235 struct bgp_nlri *packet)
paul718e3742002-12-13 20:15:29 +00003236{
3237 u_char *pnt;
3238 u_char *lim;
3239 struct prefix p;
3240 int psize;
3241 int ret;
3242
3243 /* Check peer status. */
3244 if (peer->status != Established)
3245 return 0;
3246
3247 pnt = packet->nlri;
3248 lim = pnt + packet->length;
3249
Paul Jakma405e9e12016-02-04 17:00:18 +00003250 /* RFC4771 6.3 The NLRI field in the UPDATE message is checked for
3251 syntactic validity. If the field is syntactically incorrect,
3252 then the Error Subcode is set to Invalid Network Field. */
paul718e3742002-12-13 20:15:29 +00003253 for (; pnt < lim; pnt += psize)
3254 {
3255 /* Clear prefix structure. */
3256 memset (&p, 0, sizeof (struct prefix));
3257
3258 /* Fetch prefix length. */
3259 p.prefixlen = *pnt++;
Paul Jakma405e9e12016-02-04 17:00:18 +00003260 /* afi/safi validity already verified by caller, bgp_update_receive */
paul718e3742002-12-13 20:15:29 +00003261 p.family = afi2family (packet->afi);
3262
Paul Jakma405e9e12016-02-04 17:00:18 +00003263 /* Prefix length check. */
3264 if (p.prefixlen > prefix_blen (&p) * 8)
3265 {
3266 plog_err (peer->log,
3267 "%s [Error] Update packet error"
3268 " (wrong prefix length %u for afi %u)",
3269 peer->host, p.prefixlen, packet->afi);
3270 return -1;
3271 }
3272
paul718e3742002-12-13 20:15:29 +00003273 /* Packet size overflow check. */
3274 psize = PSIZE (p.prefixlen);
3275
3276 /* When packet overflow occur return immediately. */
3277 if (pnt + psize > lim)
Paul Jakma405e9e12016-02-04 17:00:18 +00003278 {
3279 plog_err (peer->log,
3280 "%s [Error] Update packet error"
3281 " (prefix length %u overflows packet)",
3282 peer->host, p.prefixlen);
3283 return -1;
3284 }
3285
3286 /* Defensive coding, double-check the psize fits in a struct prefix */
3287 if (psize > (ssize_t) sizeof(p.u))
3288 {
3289 plog_err (peer->log,
3290 "%s [Error] Update packet error"
3291 " (prefix length %u too large for prefix storage %zu!?!!",
3292 peer->host, p.prefixlen, sizeof(p.u));
3293 return -1;
3294 }
paul718e3742002-12-13 20:15:29 +00003295
3296 /* Fetch prefix from NLRI packet. */
3297 memcpy (&p.u.prefix, pnt, psize);
3298
3299 /* Check address. */
3300 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3301 {
3302 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3303 {
paulf5ba3872004-07-09 12:11:31 +00003304 /*
Paul Jakma405e9e12016-02-04 17:00:18 +00003305 * From RFC4271 Section 6.3:
3306 *
3307 * If a prefix in the NLRI field is semantically incorrect
3308 * (e.g., an unexpected multicast IP address), an error SHOULD
3309 * be logged locally, and the prefix SHOULD be ignored.
paulf5ba3872004-07-09 12:11:31 +00003310 */
paul718e3742002-12-13 20:15:29 +00003311 zlog (peer->log, LOG_ERR,
Paul Jakma405e9e12016-02-04 17:00:18 +00003312 "%s: IPv4 unicast NLRI is multicast address %s, ignoring",
3313 peer->host, inet_ntoa (p.u.prefix4));
3314 continue;
paul718e3742002-12-13 20:15:29 +00003315 }
3316 }
3317
paul718e3742002-12-13 20:15:29 +00003318 /* Check address. */
3319 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3320 {
3321 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3322 {
3323 char buf[BUFSIZ];
3324
Paul Jakma405e9e12016-02-04 17:00:18 +00003325 zlog (peer->log, LOG_ERR,
3326 "%s: IPv6 unicast NLRI is link-local address %s, ignoring",
3327 peer->host,
paul718e3742002-12-13 20:15:29 +00003328 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00003329 continue;
3330 }
Paul Jakma405e9e12016-02-04 17:00:18 +00003331 if (IN6_IS_ADDR_MULTICAST (&p.u.prefix6))
3332 {
3333 char buf[BUFSIZ];
3334
3335 zlog (peer->log, LOG_ERR,
3336 "%s: IPv6 unicast NLRI is multicast address %s, ignoring",
3337 peer->host,
3338 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3339 continue;
3340 }
3341 }
paul718e3742002-12-13 20:15:29 +00003342
3343 /* Normal process. */
3344 if (attr)
3345 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3346 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3347 else
3348 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3349 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3350
3351 /* Address family configuration mismatch or maximum-prefix count
3352 overflow. */
3353 if (ret < 0)
3354 return -1;
3355 }
3356
3357 /* Packet length consistency check. */
3358 if (pnt != lim)
paul718e3742002-12-13 20:15:29 +00003359 {
3360 plog_err (peer->log,
Paul Jakma405e9e12016-02-04 17:00:18 +00003361 "%s [Error] Update packet error"
3362 " (prefix length mismatch with total length)",
3363 peer->host);
paul718e3742002-12-13 20:15:29 +00003364 return -1;
3365 }
Paul Jakma405e9e12016-02-04 17:00:18 +00003366
paul718e3742002-12-13 20:15:29 +00003367 return 0;
3368}
David Lamparter6b0655a2014-06-04 06:53:35 +02003369
paul94f2b392005-06-28 12:44:16 +00003370static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003371bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003372{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003373 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003374}
3375
paul94f2b392005-06-28 12:44:16 +00003376static void
paul718e3742002-12-13 20:15:29 +00003377bgp_static_free (struct bgp_static *bgp_static)
3378{
3379 if (bgp_static->rmap.name)
3380 free (bgp_static->rmap.name);
3381 XFREE (MTYPE_BGP_STATIC, bgp_static);
3382}
3383
paul94f2b392005-06-28 12:44:16 +00003384static void
paulfee0f4c2004-09-13 05:12:46 +00003385bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3386 struct prefix *p, afi_t afi, safi_t safi)
3387{
3388 struct bgp_node *rn;
3389 struct bgp_info *ri;
3390
3391 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3392
3393 /* Check selected route and self inserted route. */
3394 for (ri = rn->info; ri; ri = ri->next)
3395 if (ri->peer == bgp->peer_self
3396 && ri->type == ZEBRA_ROUTE_BGP
3397 && ri->sub_type == BGP_ROUTE_STATIC)
3398 break;
3399
3400 /* Withdraw static BGP route from routing table. */
3401 if (ri)
3402 {
paulfee0f4c2004-09-13 05:12:46 +00003403 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003404 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003405 }
3406
3407 /* Unlock bgp_node_lookup. */
3408 bgp_unlock_node (rn);
3409}
3410
paul94f2b392005-06-28 12:44:16 +00003411static void
paulfee0f4c2004-09-13 05:12:46 +00003412bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003413 struct bgp_static *bgp_static,
3414 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003415{
3416 struct bgp_node *rn;
3417 struct bgp_info *ri;
3418 struct bgp_info *new;
3419 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003420 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003421 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003422 struct attr new_attr;
3423 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003424 struct bgp *bgp;
3425 int ret;
3426 char buf[SU_ADDRSTRLEN];
3427
3428 bgp = rsclient->bgp;
3429
Paul Jakma06e110f2006-05-12 23:29:22 +00003430 assert (bgp_static);
3431 if (!bgp_static)
3432 return;
3433
paulfee0f4c2004-09-13 05:12:46 +00003434 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3435
3436 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003437
3438 attr.nexthop = bgp_static->igpnexthop;
3439 attr.med = bgp_static->igpmetric;
3440 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003441
Paul Jakma41367172007-08-06 15:24:51 +00003442 if (bgp_static->atomic)
3443 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3444
paulfee0f4c2004-09-13 05:12:46 +00003445 /* Apply network route-map for export to this rsclient. */
3446 if (bgp_static->rmap.name)
3447 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003448 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003449 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003450 info.attr = &attr_tmp;
3451
paulfee0f4c2004-09-13 05:12:46 +00003452 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3453 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3454
3455 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3456
3457 rsclient->rmap_type = 0;
3458
3459 if (ret == RMAP_DENYMATCH)
3460 {
3461 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003462 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003463
3464 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003465 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003466 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003467 bgp_attr_extra_free (&attr);
3468
paulfee0f4c2004-09-13 05:12:46 +00003469 return;
3470 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003471 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003472 }
3473 else
3474 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003475
3476 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003477 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003478
paulfee0f4c2004-09-13 05:12:46 +00003479 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3480
Paul Jakmafb982c22007-05-04 20:15:47 +00003481 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3482 == RMAP_DENY)
3483 {
paulfee0f4c2004-09-13 05:12:46 +00003484 /* This BGP update is filtered. Log the reason then update BGP entry. */
3485 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003486 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003487 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3488 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3489 p->prefixlen, rsclient->host);
3490
3491 bgp->peer_self->rmap_type = 0;
3492
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003493 bgp_attr_unintern (&attr_new);
3494 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003495 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003496
3497 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3498
3499 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003500 }
paulfee0f4c2004-09-13 05:12:46 +00003501
3502 bgp->peer_self->rmap_type = 0;
3503
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003504 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003505 attr_new = bgp_attr_intern (&new_attr);
3506
3507 for (ri = rn->info; ri; ri = ri->next)
3508 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3509 && ri->sub_type == BGP_ROUTE_STATIC)
3510 break;
3511
3512 if (ri)
3513 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003514 if (attrhash_cmp (ri->attr, attr_new) &&
3515 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003516 {
3517 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003518 bgp_attr_unintern (&attr_new);
3519 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003520 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003521 return;
3522 }
3523 else
3524 {
3525 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003526 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003527
3528 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003529 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3530 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003531 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003532 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003533 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003534
3535 /* Process change. */
3536 bgp_process (bgp, rn, afi, safi);
3537 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003538 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003539 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003540 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003541 }
paulfee0f4c2004-09-13 05:12:46 +00003542 }
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003543
paulfee0f4c2004-09-13 05:12:46 +00003544 /* Make new BGP info. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003545 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
3546 attr_new, rn);
paulfee0f4c2004-09-13 05:12:46 +00003547 SET_FLAG (new->flags, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00003548
3549 /* Register new BGP information. */
3550 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003551
3552 /* route_node_get lock */
3553 bgp_unlock_node (rn);
3554
paulfee0f4c2004-09-13 05:12:46 +00003555 /* Process change. */
3556 bgp_process (bgp, rn, afi, safi);
3557
3558 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003559 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003560 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003561}
3562
paul94f2b392005-06-28 12:44:16 +00003563static void
paulfee0f4c2004-09-13 05:12:46 +00003564bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003565 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3566{
3567 struct bgp_node *rn;
3568 struct bgp_info *ri;
3569 struct bgp_info *new;
3570 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003571 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003572 struct attr *attr_new;
3573 int ret;
3574
Paul Jakmadd8103a2006-05-12 23:27:30 +00003575 assert (bgp_static);
3576 if (!bgp_static)
3577 return;
3578
paulfee0f4c2004-09-13 05:12:46 +00003579 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003580
3581 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003582
3583 attr.nexthop = bgp_static->igpnexthop;
3584 attr.med = bgp_static->igpmetric;
3585 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003586
Paul Jakma41367172007-08-06 15:24:51 +00003587 if (bgp_static->atomic)
3588 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3589
paul718e3742002-12-13 20:15:29 +00003590 /* Apply route-map. */
3591 if (bgp_static->rmap.name)
3592 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003593 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003594 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003595 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003596
paulfee0f4c2004-09-13 05:12:46 +00003597 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3598
paul718e3742002-12-13 20:15:29 +00003599 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003600
paulfee0f4c2004-09-13 05:12:46 +00003601 bgp->peer_self->rmap_type = 0;
3602
paul718e3742002-12-13 20:15:29 +00003603 if (ret == RMAP_DENYMATCH)
3604 {
3605 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003606 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003607
3608 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003609 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003610 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003611 bgp_static_withdraw (bgp, p, afi, safi);
3612 return;
3613 }
paul286e1e72003-08-08 00:24:31 +00003614 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003615 }
paul286e1e72003-08-08 00:24:31 +00003616 else
3617 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003618
3619 for (ri = rn->info; ri; ri = ri->next)
3620 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3621 && ri->sub_type == BGP_ROUTE_STATIC)
3622 break;
3623
3624 if (ri)
3625 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003626 if (attrhash_cmp (ri->attr, attr_new) &&
3627 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003628 {
3629 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003630 bgp_attr_unintern (&attr_new);
3631 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003632 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003633 return;
3634 }
3635 else
3636 {
3637 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003638 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003639
3640 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003641 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3642 bgp_info_restore(rn, ri);
3643 else
3644 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003645 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003646 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003647 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003648
3649 /* Process change. */
3650 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3651 bgp_process (bgp, rn, afi, safi);
3652 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003653 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003654 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003655 return;
3656 }
3657 }
3658
3659 /* Make new BGP info. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003660 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self, attr_new,
3661 rn);
paul718e3742002-12-13 20:15:29 +00003662 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00003663
3664 /* Aggregate address increment. */
3665 bgp_aggregate_increment (bgp, p, new, afi, safi);
3666
3667 /* Register new BGP information. */
3668 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003669
3670 /* route_node_get lock */
3671 bgp_unlock_node (rn);
3672
paul718e3742002-12-13 20:15:29 +00003673 /* Process change. */
3674 bgp_process (bgp, rn, afi, safi);
3675
3676 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003677 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003678 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003679}
3680
3681void
paulfee0f4c2004-09-13 05:12:46 +00003682bgp_static_update (struct bgp *bgp, struct prefix *p,
3683 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3684{
3685 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003686 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003687
3688 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3689
paul1eb8ef22005-04-07 07:30:20 +00003690 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003691 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003692 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3693 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003694 }
3695}
3696
paul718e3742002-12-13 20:15:29 +00003697void
3698bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3699 safi_t safi)
3700{
3701 struct bgp_node *rn;
3702 struct bgp_info *ri;
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003703 struct bgp_info *new;
paul718e3742002-12-13 20:15:29 +00003704
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003705 /* Make new BGP info. */
3706 rn = bgp_node_get (bgp->rib[afi][safi], p);
3707 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
3708 bgp_attr_default_intern(BGP_ORIGIN_IGP), rn);
3709
3710 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00003711
3712 /* Check selected route and self inserted route. */
3713 for (ri = rn->info; ri; ri = ri->next)
3714 if (ri->peer == bgp->peer_self
3715 && ri->type == ZEBRA_ROUTE_BGP
3716 && ri->sub_type == BGP_ROUTE_STATIC)
3717 break;
3718
3719 /* Withdraw static BGP route from routing table. */
3720 if (ri)
3721 {
3722 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003723 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003724 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003725 }
3726
3727 /* Unlock bgp_node_lookup. */
3728 bgp_unlock_node (rn);
3729}
3730
3731void
paulfee0f4c2004-09-13 05:12:46 +00003732bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3733{
3734 struct bgp_static *bgp_static;
3735 struct bgp *bgp;
3736 struct bgp_node *rn;
3737 struct prefix *p;
3738
3739 bgp = rsclient->bgp;
3740
3741 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3742 if ((bgp_static = rn->info) != NULL)
3743 {
3744 p = &rn->p;
3745
3746 bgp_static_update_rsclient (rsclient, p, bgp_static,
3747 afi, safi);
3748 }
3749}
3750
Lou Bergera76d9ca2016-01-12 13:41:53 -05003751/*
3752 * Used for SAFI_MPLS_VPN and SAFI_ENCAP
3753 */
paul94f2b392005-06-28 12:44:16 +00003754static void
Lou Bergera76d9ca2016-01-12 13:41:53 -05003755bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
3756 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003757{
3758 struct bgp_node *rn;
3759 struct bgp_info *ri;
3760
paulfee0f4c2004-09-13 05:12:46 +00003761 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003762
3763 /* Check selected route and self inserted route. */
3764 for (ri = rn->info; ri; ri = ri->next)
3765 if (ri->peer == bgp->peer_self
3766 && ri->type == ZEBRA_ROUTE_BGP
3767 && ri->sub_type == BGP_ROUTE_STATIC)
3768 break;
3769
3770 /* Withdraw static BGP route from routing table. */
3771 if (ri)
3772 {
3773 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003774 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003775 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003776 }
3777
3778 /* Unlock bgp_node_lookup. */
3779 bgp_unlock_node (rn);
3780}
3781
Lou Bergera76d9ca2016-01-12 13:41:53 -05003782static void
3783bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
3784 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3785{
3786 struct bgp_node *rn;
3787 struct bgp_info *new;
3788 struct attr *attr_new;
3789 struct attr attr = { 0 };
3790 struct bgp_info *ri;
3791
3792 assert (bgp_static);
3793
3794 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
3795
3796 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3797
3798 attr.nexthop = bgp_static->igpnexthop;
3799 attr.med = bgp_static->igpmetric;
3800 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3801
3802 /* Apply route-map. */
3803 if (bgp_static->rmap.name)
3804 {
3805 struct attr attr_tmp = attr;
3806 struct bgp_info info;
3807 int ret;
3808
3809 info.peer = bgp->peer_self;
3810 info.attr = &attr_tmp;
3811
3812 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3813
3814 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3815
3816 bgp->peer_self->rmap_type = 0;
3817
3818 if (ret == RMAP_DENYMATCH)
3819 {
3820 /* Free uninterned attribute. */
3821 bgp_attr_flush (&attr_tmp);
3822
3823 /* Unintern original. */
3824 aspath_unintern (&attr.aspath);
3825 bgp_attr_extra_free (&attr);
3826 bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
3827 bgp_static->tag);
3828 return;
3829 }
3830
3831 attr_new = bgp_attr_intern (&attr_tmp);
3832 }
3833 else
3834 {
3835 attr_new = bgp_attr_intern (&attr);
3836 }
3837
3838 for (ri = rn->info; ri; ri = ri->next)
3839 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3840 && ri->sub_type == BGP_ROUTE_STATIC)
3841 break;
3842
3843 if (ri)
3844 {
3845 if (attrhash_cmp (ri->attr, attr_new) &&
3846 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3847 {
3848 bgp_unlock_node (rn);
3849 bgp_attr_unintern (&attr_new);
3850 aspath_unintern (&attr.aspath);
3851 bgp_attr_extra_free (&attr);
3852 return;
3853 }
3854 else
3855 {
3856 /* The attribute is changed. */
3857 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3858
3859 /* Rewrite BGP route information. */
3860 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3861 bgp_info_restore(rn, ri);
3862 else
3863 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3864 bgp_attr_unintern (&ri->attr);
3865 ri->attr = attr_new;
3866 ri->uptime = bgp_clock ();
3867
3868 /* Process change. */
3869 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3870 bgp_process (bgp, rn, afi, safi);
3871 bgp_unlock_node (rn);
3872 aspath_unintern (&attr.aspath);
3873 bgp_attr_extra_free (&attr);
3874 return;
3875 }
3876 }
3877
3878
3879 /* Make new BGP info. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003880 new = info_make (ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
3881 attr_new, rn);
Lou Bergera76d9ca2016-01-12 13:41:53 -05003882 SET_FLAG (new->flags, BGP_INFO_VALID);
Lou Bergera76d9ca2016-01-12 13:41:53 -05003883 new->extra = bgp_info_extra_new();
3884 memcpy (new->extra->tag, bgp_static->tag, 3);
3885
3886 /* Aggregate address increment. */
3887 bgp_aggregate_increment (bgp, p, new, afi, safi);
3888
3889 /* Register new BGP information. */
3890 bgp_info_add (rn, new);
3891
3892 /* route_node_get lock */
3893 bgp_unlock_node (rn);
3894
3895 /* Process change. */
3896 bgp_process (bgp, rn, afi, safi);
3897
3898 /* Unintern original. */
3899 aspath_unintern (&attr.aspath);
3900 bgp_attr_extra_free (&attr);
3901}
3902
paul718e3742002-12-13 20:15:29 +00003903/* Configure static BGP network. When user don't run zebra, static
3904 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003905static int
paulfd79ac92004-10-13 05:06:08 +00003906bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003907 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003908{
3909 int ret;
3910 struct prefix p;
3911 struct bgp_static *bgp_static;
3912 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003913 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003914
3915 /* Convert IP prefix string to struct prefix. */
3916 ret = str2prefix (ip_str, &p);
3917 if (! ret)
3918 {
3919 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3920 return CMD_WARNING;
3921 }
paul718e3742002-12-13 20:15:29 +00003922 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3923 {
3924 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3925 VTY_NEWLINE);
3926 return CMD_WARNING;
3927 }
paul718e3742002-12-13 20:15:29 +00003928
3929 apply_mask (&p);
3930
3931 /* Set BGP static route configuration. */
3932 rn = bgp_node_get (bgp->route[afi][safi], &p);
3933
3934 if (rn->info)
3935 {
3936 /* Configuration change. */
3937 bgp_static = rn->info;
3938
3939 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003940 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3941 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003942
paul718e3742002-12-13 20:15:29 +00003943 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003944
paul718e3742002-12-13 20:15:29 +00003945 if (rmap)
3946 {
3947 if (bgp_static->rmap.name)
3948 free (bgp_static->rmap.name);
3949 bgp_static->rmap.name = strdup (rmap);
3950 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3951 }
3952 else
3953 {
3954 if (bgp_static->rmap.name)
3955 free (bgp_static->rmap.name);
3956 bgp_static->rmap.name = NULL;
3957 bgp_static->rmap.map = NULL;
3958 bgp_static->valid = 0;
3959 }
3960 bgp_unlock_node (rn);
3961 }
3962 else
3963 {
3964 /* New configuration. */
3965 bgp_static = bgp_static_new ();
3966 bgp_static->backdoor = backdoor;
3967 bgp_static->valid = 0;
3968 bgp_static->igpmetric = 0;
3969 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003970
paul718e3742002-12-13 20:15:29 +00003971 if (rmap)
3972 {
3973 if (bgp_static->rmap.name)
3974 free (bgp_static->rmap.name);
3975 bgp_static->rmap.name = strdup (rmap);
3976 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3977 }
3978 rn->info = bgp_static;
3979 }
3980
3981 /* If BGP scan is not enabled, we should install this route here. */
3982 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3983 {
3984 bgp_static->valid = 1;
3985
3986 if (need_update)
3987 bgp_static_withdraw (bgp, &p, afi, safi);
3988
3989 if (! bgp_static->backdoor)
3990 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3991 }
3992
3993 return CMD_SUCCESS;
3994}
3995
3996/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003997static int
paulfd79ac92004-10-13 05:06:08 +00003998bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003999 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004000{
4001 int ret;
4002 struct prefix p;
4003 struct bgp_static *bgp_static;
4004 struct bgp_node *rn;
4005
4006 /* Convert IP prefix string to struct prefix. */
4007 ret = str2prefix (ip_str, &p);
4008 if (! ret)
4009 {
4010 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4011 return CMD_WARNING;
4012 }
paul718e3742002-12-13 20:15:29 +00004013 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4014 {
4015 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4016 VTY_NEWLINE);
4017 return CMD_WARNING;
4018 }
paul718e3742002-12-13 20:15:29 +00004019
4020 apply_mask (&p);
4021
4022 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4023 if (! rn)
4024 {
4025 vty_out (vty, "%% Can't find specified static route configuration.%s",
4026 VTY_NEWLINE);
4027 return CMD_WARNING;
4028 }
4029
4030 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00004031
paul718e3742002-12-13 20:15:29 +00004032 /* Update BGP RIB. */
4033 if (! bgp_static->backdoor)
4034 bgp_static_withdraw (bgp, &p, afi, safi);
4035
4036 /* Clear configuration. */
4037 bgp_static_free (bgp_static);
4038 rn->info = NULL;
4039 bgp_unlock_node (rn);
4040 bgp_unlock_node (rn);
4041
4042 return CMD_SUCCESS;
4043}
4044
4045/* Called from bgp_delete(). Delete all static routes from the BGP
4046 instance. */
4047void
4048bgp_static_delete (struct bgp *bgp)
4049{
4050 afi_t afi;
4051 safi_t safi;
4052 struct bgp_node *rn;
4053 struct bgp_node *rm;
4054 struct bgp_table *table;
4055 struct bgp_static *bgp_static;
4056
4057 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4058 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4059 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4060 if (rn->info != NULL)
4061 {
Lou Berger298cc2f2016-01-12 13:42:02 -05004062 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004063 {
4064 table = rn->info;
4065
4066 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4067 {
4068 bgp_static = rn->info;
Lou Bergera76d9ca2016-01-12 13:41:53 -05004069 bgp_static_withdraw_safi (bgp, &rm->p,
4070 AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00004071 (struct prefix_rd *)&rn->p,
4072 bgp_static->tag);
4073 bgp_static_free (bgp_static);
4074 rn->info = NULL;
4075 bgp_unlock_node (rn);
4076 }
4077 }
4078 else
4079 {
4080 bgp_static = rn->info;
4081 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4082 bgp_static_free (bgp_static);
4083 rn->info = NULL;
4084 bgp_unlock_node (rn);
4085 }
4086 }
4087}
4088
Lou Bergera76d9ca2016-01-12 13:41:53 -05004089/*
4090 * gpz 110624
4091 * Currently this is used to set static routes for VPN and ENCAP.
4092 * I think it can probably be factored with bgp_static_set.
4093 */
paul718e3742002-12-13 20:15:29 +00004094int
Lou Bergera76d9ca2016-01-12 13:41:53 -05004095bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
4096 const char *rd_str, const char *tag_str,
4097 const char *rmap_str)
paul718e3742002-12-13 20:15:29 +00004098{
4099 int ret;
4100 struct prefix p;
4101 struct prefix_rd prd;
4102 struct bgp *bgp;
4103 struct bgp_node *prn;
4104 struct bgp_node *rn;
4105 struct bgp_table *table;
4106 struct bgp_static *bgp_static;
4107 u_char tag[3];
4108
4109 bgp = vty->index;
4110
4111 ret = str2prefix (ip_str, &p);
4112 if (! ret)
4113 {
4114 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4115 return CMD_WARNING;
4116 }
4117 apply_mask (&p);
4118
4119 ret = str2prefix_rd (rd_str, &prd);
4120 if (! ret)
4121 {
4122 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4123 return CMD_WARNING;
4124 }
4125
4126 ret = str2tag (tag_str, tag);
4127 if (! ret)
4128 {
4129 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4130 return CMD_WARNING;
4131 }
4132
Lou Bergera76d9ca2016-01-12 13:41:53 -05004133 prn = bgp_node_get (bgp->route[AFI_IP][safi],
paul718e3742002-12-13 20:15:29 +00004134 (struct prefix *)&prd);
4135 if (prn->info == NULL)
Lou Bergera76d9ca2016-01-12 13:41:53 -05004136 prn->info = bgp_table_init (AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004137 else
4138 bgp_unlock_node (prn);
4139 table = prn->info;
4140
4141 rn = bgp_node_get (table, &p);
4142
4143 if (rn->info)
4144 {
4145 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4146 bgp_unlock_node (rn);
4147 }
4148 else
4149 {
4150 /* New configuration. */
4151 bgp_static = bgp_static_new ();
Lou Bergera76d9ca2016-01-12 13:41:53 -05004152 bgp_static->backdoor = 0;
4153 bgp_static->valid = 0;
4154 bgp_static->igpmetric = 0;
4155 bgp_static->igpnexthop.s_addr = 0;
4156 memcpy(bgp_static->tag, tag, 3);
4157 bgp_static->prd = prd;
4158
4159 if (rmap_str)
4160 {
4161 if (bgp_static->rmap.name)
4162 free (bgp_static->rmap.name);
4163 bgp_static->rmap.name = strdup (rmap_str);
4164 bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
4165 }
paul718e3742002-12-13 20:15:29 +00004166 rn->info = bgp_static;
4167
Lou Bergera76d9ca2016-01-12 13:41:53 -05004168 bgp_static->valid = 1;
4169 bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004170 }
4171
4172 return CMD_SUCCESS;
4173}
4174
4175/* Configure static BGP network. */
4176int
Lou Bergera76d9ca2016-01-12 13:41:53 -05004177bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
4178 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00004179{
4180 int ret;
4181 struct bgp *bgp;
4182 struct prefix p;
4183 struct prefix_rd prd;
4184 struct bgp_node *prn;
4185 struct bgp_node *rn;
4186 struct bgp_table *table;
4187 struct bgp_static *bgp_static;
4188 u_char tag[3];
4189
4190 bgp = vty->index;
4191
4192 /* Convert IP prefix string to struct prefix. */
4193 ret = str2prefix (ip_str, &p);
4194 if (! ret)
4195 {
4196 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4197 return CMD_WARNING;
4198 }
4199 apply_mask (&p);
4200
4201 ret = str2prefix_rd (rd_str, &prd);
4202 if (! ret)
4203 {
4204 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4205 return CMD_WARNING;
4206 }
4207
4208 ret = str2tag (tag_str, tag);
4209 if (! ret)
4210 {
4211 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4212 return CMD_WARNING;
4213 }
4214
Lou Bergera76d9ca2016-01-12 13:41:53 -05004215 prn = bgp_node_get (bgp->route[AFI_IP][safi],
paul718e3742002-12-13 20:15:29 +00004216 (struct prefix *)&prd);
4217 if (prn->info == NULL)
Lou Bergera76d9ca2016-01-12 13:41:53 -05004218 prn->info = bgp_table_init (AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004219 else
4220 bgp_unlock_node (prn);
4221 table = prn->info;
4222
4223 rn = bgp_node_lookup (table, &p);
4224
4225 if (rn)
4226 {
Lou Bergera76d9ca2016-01-12 13:41:53 -05004227 bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
paul718e3742002-12-13 20:15:29 +00004228
4229 bgp_static = rn->info;
4230 bgp_static_free (bgp_static);
4231 rn->info = NULL;
4232 bgp_unlock_node (rn);
4233 bgp_unlock_node (rn);
4234 }
4235 else
4236 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4237
4238 return CMD_SUCCESS;
4239}
David Lamparter6b0655a2014-06-04 06:53:35 +02004240
paul718e3742002-12-13 20:15:29 +00004241DEFUN (bgp_network,
4242 bgp_network_cmd,
4243 "network A.B.C.D/M",
4244 "Specify a network to announce via BGP\n"
4245 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4246{
4247 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004248 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004249}
4250
4251DEFUN (bgp_network_route_map,
4252 bgp_network_route_map_cmd,
4253 "network A.B.C.D/M route-map WORD",
4254 "Specify a network to announce via BGP\n"
4255 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4256 "Route-map to modify the attributes\n"
4257 "Name of the route map\n")
4258{
4259 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004260 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004261}
4262
4263DEFUN (bgp_network_backdoor,
4264 bgp_network_backdoor_cmd,
4265 "network A.B.C.D/M backdoor",
4266 "Specify a network to announce via BGP\n"
4267 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4268 "Specify a BGP backdoor route\n")
4269{
Paul Jakma41367172007-08-06 15:24:51 +00004270 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004271 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004272}
4273
4274DEFUN (bgp_network_mask,
4275 bgp_network_mask_cmd,
4276 "network A.B.C.D mask A.B.C.D",
4277 "Specify a network to announce via BGP\n"
4278 "Network number\n"
4279 "Network mask\n"
4280 "Network mask\n")
4281{
4282 int ret;
4283 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004284
paul718e3742002-12-13 20:15:29 +00004285 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4286 if (! ret)
4287 {
4288 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4289 return CMD_WARNING;
4290 }
4291
4292 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004293 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004294}
4295
4296DEFUN (bgp_network_mask_route_map,
4297 bgp_network_mask_route_map_cmd,
4298 "network A.B.C.D mask A.B.C.D route-map WORD",
4299 "Specify a network to announce via BGP\n"
4300 "Network number\n"
4301 "Network mask\n"
4302 "Network mask\n"
4303 "Route-map to modify the attributes\n"
4304 "Name of the route map\n")
4305{
4306 int ret;
4307 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004308
paul718e3742002-12-13 20:15:29 +00004309 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4310 if (! ret)
4311 {
4312 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4313 return CMD_WARNING;
4314 }
4315
4316 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004317 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004318}
4319
4320DEFUN (bgp_network_mask_backdoor,
4321 bgp_network_mask_backdoor_cmd,
4322 "network A.B.C.D mask A.B.C.D backdoor",
4323 "Specify a network to announce via BGP\n"
4324 "Network number\n"
4325 "Network mask\n"
4326 "Network mask\n"
4327 "Specify a BGP backdoor route\n")
4328{
4329 int ret;
4330 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004331
paul718e3742002-12-13 20:15:29 +00004332 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4333 if (! ret)
4334 {
4335 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4336 return CMD_WARNING;
4337 }
4338
Paul Jakma41367172007-08-06 15:24:51 +00004339 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004340 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004341}
4342
4343DEFUN (bgp_network_mask_natural,
4344 bgp_network_mask_natural_cmd,
4345 "network A.B.C.D",
4346 "Specify a network to announce via BGP\n"
4347 "Network number\n")
4348{
4349 int ret;
4350 char prefix_str[BUFSIZ];
4351
4352 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4353 if (! ret)
4354 {
4355 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4356 return CMD_WARNING;
4357 }
4358
4359 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004360 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004361}
4362
4363DEFUN (bgp_network_mask_natural_route_map,
4364 bgp_network_mask_natural_route_map_cmd,
4365 "network A.B.C.D route-map WORD",
4366 "Specify a network to announce via BGP\n"
4367 "Network number\n"
4368 "Route-map to modify the attributes\n"
4369 "Name of the route map\n")
4370{
4371 int ret;
4372 char prefix_str[BUFSIZ];
4373
4374 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4375 if (! ret)
4376 {
4377 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4378 return CMD_WARNING;
4379 }
4380
4381 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004382 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004383}
4384
4385DEFUN (bgp_network_mask_natural_backdoor,
4386 bgp_network_mask_natural_backdoor_cmd,
4387 "network A.B.C.D backdoor",
4388 "Specify a network to announce via BGP\n"
4389 "Network number\n"
4390 "Specify a BGP backdoor route\n")
4391{
4392 int ret;
4393 char prefix_str[BUFSIZ];
4394
4395 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4396 if (! ret)
4397 {
4398 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4399 return CMD_WARNING;
4400 }
4401
Paul Jakma41367172007-08-06 15:24:51 +00004402 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004403 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004404}
4405
4406DEFUN (no_bgp_network,
4407 no_bgp_network_cmd,
4408 "no network A.B.C.D/M",
4409 NO_STR
4410 "Specify a network to announce via BGP\n"
4411 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4412{
4413 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4414 bgp_node_safi (vty));
4415}
4416
4417ALIAS (no_bgp_network,
4418 no_bgp_network_route_map_cmd,
4419 "no network A.B.C.D/M route-map WORD",
4420 NO_STR
4421 "Specify a network to announce via BGP\n"
4422 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4423 "Route-map to modify the attributes\n"
4424 "Name of the route map\n")
4425
4426ALIAS (no_bgp_network,
4427 no_bgp_network_backdoor_cmd,
4428 "no network A.B.C.D/M backdoor",
4429 NO_STR
4430 "Specify a network to announce via BGP\n"
4431 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4432 "Specify a BGP backdoor route\n")
4433
4434DEFUN (no_bgp_network_mask,
4435 no_bgp_network_mask_cmd,
4436 "no network A.B.C.D mask A.B.C.D",
4437 NO_STR
4438 "Specify a network to announce via BGP\n"
4439 "Network number\n"
4440 "Network mask\n"
4441 "Network mask\n")
4442{
4443 int ret;
4444 char prefix_str[BUFSIZ];
4445
4446 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4447 if (! ret)
4448 {
4449 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4450 return CMD_WARNING;
4451 }
4452
4453 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4454 bgp_node_safi (vty));
4455}
4456
4457ALIAS (no_bgp_network_mask,
4458 no_bgp_network_mask_route_map_cmd,
4459 "no network A.B.C.D mask A.B.C.D route-map WORD",
4460 NO_STR
4461 "Specify a network to announce via BGP\n"
4462 "Network number\n"
4463 "Network mask\n"
4464 "Network mask\n"
4465 "Route-map to modify the attributes\n"
4466 "Name of the route map\n")
4467
4468ALIAS (no_bgp_network_mask,
4469 no_bgp_network_mask_backdoor_cmd,
4470 "no network A.B.C.D mask A.B.C.D backdoor",
4471 NO_STR
4472 "Specify a network to announce via BGP\n"
4473 "Network number\n"
4474 "Network mask\n"
4475 "Network mask\n"
4476 "Specify a BGP backdoor route\n")
4477
4478DEFUN (no_bgp_network_mask_natural,
4479 no_bgp_network_mask_natural_cmd,
4480 "no network A.B.C.D",
4481 NO_STR
4482 "Specify a network to announce via BGP\n"
4483 "Network number\n")
4484{
4485 int ret;
4486 char prefix_str[BUFSIZ];
4487
4488 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4489 if (! ret)
4490 {
4491 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4492 return CMD_WARNING;
4493 }
4494
4495 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4496 bgp_node_safi (vty));
4497}
4498
4499ALIAS (no_bgp_network_mask_natural,
4500 no_bgp_network_mask_natural_route_map_cmd,
4501 "no network A.B.C.D route-map WORD",
4502 NO_STR
4503 "Specify a network to announce via BGP\n"
4504 "Network number\n"
4505 "Route-map to modify the attributes\n"
4506 "Name of the route map\n")
4507
4508ALIAS (no_bgp_network_mask_natural,
4509 no_bgp_network_mask_natural_backdoor_cmd,
4510 "no network A.B.C.D backdoor",
4511 NO_STR
4512 "Specify a network to announce via BGP\n"
4513 "Network number\n"
4514 "Specify a BGP backdoor route\n")
4515
paul718e3742002-12-13 20:15:29 +00004516DEFUN (ipv6_bgp_network,
4517 ipv6_bgp_network_cmd,
4518 "network X:X::X:X/M",
4519 "Specify a network to announce via BGP\n"
4520 "IPv6 prefix <network>/<length>\n")
4521{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304522 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004523 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004524}
4525
4526DEFUN (ipv6_bgp_network_route_map,
4527 ipv6_bgp_network_route_map_cmd,
4528 "network X:X::X:X/M route-map WORD",
4529 "Specify a network to announce via BGP\n"
4530 "IPv6 prefix <network>/<length>\n"
4531 "Route-map to modify the attributes\n"
4532 "Name of the route map\n")
4533{
4534 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004535 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004536}
4537
4538DEFUN (no_ipv6_bgp_network,
4539 no_ipv6_bgp_network_cmd,
4540 "no network X:X::X:X/M",
4541 NO_STR
4542 "Specify a network to announce via BGP\n"
4543 "IPv6 prefix <network>/<length>\n")
4544{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304545 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004546}
4547
4548ALIAS (no_ipv6_bgp_network,
4549 no_ipv6_bgp_network_route_map_cmd,
4550 "no network X:X::X:X/M route-map WORD",
4551 NO_STR
4552 "Specify a network to announce via BGP\n"
4553 "IPv6 prefix <network>/<length>\n"
4554 "Route-map to modify the attributes\n"
4555 "Name of the route map\n")
4556
4557ALIAS (ipv6_bgp_network,
4558 old_ipv6_bgp_network_cmd,
4559 "ipv6 bgp network X:X::X:X/M",
4560 IPV6_STR
4561 BGP_STR
4562 "Specify a network to announce via BGP\n"
4563 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4564
4565ALIAS (no_ipv6_bgp_network,
4566 old_no_ipv6_bgp_network_cmd,
4567 "no ipv6 bgp network X:X::X:X/M",
4568 NO_STR
4569 IPV6_STR
4570 BGP_STR
4571 "Specify a network to announce via BGP\n"
4572 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004573
4574/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4575ALIAS_DEPRECATED (bgp_network,
4576 bgp_network_ttl_cmd,
4577 "network A.B.C.D/M pathlimit <0-255>",
4578 "Specify a network to announce via BGP\n"
4579 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4580 "AS-Path hopcount limit attribute\n"
4581 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4582ALIAS_DEPRECATED (bgp_network_backdoor,
4583 bgp_network_backdoor_ttl_cmd,
4584 "network A.B.C.D/M backdoor pathlimit <0-255>",
4585 "Specify a network to announce via BGP\n"
4586 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4587 "Specify a BGP backdoor route\n"
4588 "AS-Path hopcount limit attribute\n"
4589 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4590ALIAS_DEPRECATED (bgp_network_mask,
4591 bgp_network_mask_ttl_cmd,
4592 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4593 "Specify a network to announce via BGP\n"
4594 "Network number\n"
4595 "Network mask\n"
4596 "Network mask\n"
4597 "AS-Path hopcount limit attribute\n"
4598 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4599ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4600 bgp_network_mask_backdoor_ttl_cmd,
4601 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4602 "Specify a network to announce via BGP\n"
4603 "Network number\n"
4604 "Network mask\n"
4605 "Network mask\n"
4606 "Specify a BGP backdoor route\n"
4607 "AS-Path hopcount limit attribute\n"
4608 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4609ALIAS_DEPRECATED (bgp_network_mask_natural,
4610 bgp_network_mask_natural_ttl_cmd,
4611 "network A.B.C.D pathlimit <0-255>",
4612 "Specify a network to announce via BGP\n"
4613 "Network number\n"
4614 "AS-Path hopcount limit attribute\n"
4615 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4616ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4617 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004618 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004619 "Specify a network to announce via BGP\n"
4620 "Network number\n"
4621 "Specify a BGP backdoor route\n"
4622 "AS-Path hopcount limit attribute\n"
4623 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4624ALIAS_DEPRECATED (no_bgp_network,
4625 no_bgp_network_ttl_cmd,
4626 "no network A.B.C.D/M pathlimit <0-255>",
4627 NO_STR
4628 "Specify a network to announce via BGP\n"
4629 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4630 "AS-Path hopcount limit attribute\n"
4631 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4632ALIAS_DEPRECATED (no_bgp_network,
4633 no_bgp_network_backdoor_ttl_cmd,
4634 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4635 NO_STR
4636 "Specify a network to announce via BGP\n"
4637 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4638 "Specify a BGP backdoor route\n"
4639 "AS-Path hopcount limit attribute\n"
4640 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4641ALIAS_DEPRECATED (no_bgp_network,
4642 no_bgp_network_mask_ttl_cmd,
4643 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4644 NO_STR
4645 "Specify a network to announce via BGP\n"
4646 "Network number\n"
4647 "Network mask\n"
4648 "Network mask\n"
4649 "AS-Path hopcount limit attribute\n"
4650 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4651ALIAS_DEPRECATED (no_bgp_network_mask,
4652 no_bgp_network_mask_backdoor_ttl_cmd,
4653 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4654 NO_STR
4655 "Specify a network to announce via BGP\n"
4656 "Network number\n"
4657 "Network mask\n"
4658 "Network mask\n"
4659 "Specify a BGP backdoor route\n"
4660 "AS-Path hopcount limit attribute\n"
4661 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4662ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4663 no_bgp_network_mask_natural_ttl_cmd,
4664 "no network A.B.C.D pathlimit <0-255>",
4665 NO_STR
4666 "Specify a network to announce via BGP\n"
4667 "Network number\n"
4668 "AS-Path hopcount limit attribute\n"
4669 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4670ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4671 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4672 "no network A.B.C.D backdoor pathlimit <0-255>",
4673 NO_STR
4674 "Specify a network to announce via BGP\n"
4675 "Network number\n"
4676 "Specify a BGP backdoor route\n"
4677 "AS-Path hopcount limit attribute\n"
4678 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4679ALIAS_DEPRECATED (ipv6_bgp_network,
4680 ipv6_bgp_network_ttl_cmd,
4681 "network X:X::X:X/M pathlimit <0-255>",
4682 "Specify a network to announce via BGP\n"
4683 "IPv6 prefix <network>/<length>\n"
4684 "AS-Path hopcount limit attribute\n"
4685 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4686ALIAS_DEPRECATED (no_ipv6_bgp_network,
4687 no_ipv6_bgp_network_ttl_cmd,
4688 "no network X:X::X:X/M pathlimit <0-255>",
4689 NO_STR
4690 "Specify a network to announce via BGP\n"
4691 "IPv6 prefix <network>/<length>\n"
4692 "AS-Path hopcount limit attribute\n"
4693 "AS-Pathlimit TTL, in number of AS-Path hops\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02004694
paul718e3742002-12-13 20:15:29 +00004695/* Aggreagete address:
4696
4697 advertise-map Set condition to advertise attribute
4698 as-set Generate AS set path information
4699 attribute-map Set attributes of aggregate
4700 route-map Set parameters of aggregate
4701 summary-only Filter more specific routes from updates
4702 suppress-map Conditionally filter more specific routes from updates
4703 <cr>
4704 */
4705struct bgp_aggregate
4706{
4707 /* Summary-only flag. */
4708 u_char summary_only;
4709
4710 /* AS set generation. */
4711 u_char as_set;
4712
4713 /* Route-map for aggregated route. */
4714 struct route_map *map;
4715
4716 /* Suppress-count. */
4717 unsigned long count;
4718
4719 /* SAFI configuration. */
4720 safi_t safi;
4721};
4722
paul94f2b392005-06-28 12:44:16 +00004723static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004724bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004725{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004726 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004727}
4728
paul94f2b392005-06-28 12:44:16 +00004729static void
paul718e3742002-12-13 20:15:29 +00004730bgp_aggregate_free (struct bgp_aggregate *aggregate)
4731{
4732 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4733}
4734
Daniel Walton76a72802015-05-19 17:47:24 -07004735/* Update an aggregate as routes are added/removed from the BGP table */
paul94f2b392005-06-28 12:44:16 +00004736static void
paul718e3742002-12-13 20:15:29 +00004737bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4738 afi_t afi, safi_t safi, struct bgp_info *del,
4739 struct bgp_aggregate *aggregate)
4740{
4741 struct bgp_table *table;
4742 struct bgp_node *top;
4743 struct bgp_node *rn;
4744 u_char origin;
4745 struct aspath *aspath = NULL;
4746 struct aspath *asmerge = NULL;
4747 struct community *community = NULL;
4748 struct community *commerge = NULL;
paul718e3742002-12-13 20:15:29 +00004749 struct bgp_info *ri;
4750 struct bgp_info *new;
4751 int first = 1;
4752 unsigned long match = 0;
Daniel Waltonf2eb9ca2015-05-19 17:47:21 -07004753 u_char atomic_aggregate = 0;
paul718e3742002-12-13 20:15:29 +00004754
paul718e3742002-12-13 20:15:29 +00004755 /* ORIGIN attribute: If at least one route among routes that are
4756 aggregated has ORIGIN with the value INCOMPLETE, then the
4757 aggregated route must have the ORIGIN attribute with the value
4758 INCOMPLETE. Otherwise, if at least one route among routes that
4759 are aggregated has ORIGIN with the value EGP, then the aggregated
4760 route must have the origin attribute with the value EGP. In all
4761 other case the value of the ORIGIN attribute of the aggregated
4762 route is INTERNAL. */
4763 origin = BGP_ORIGIN_IGP;
4764
4765 table = bgp->rib[afi][safi];
4766
4767 top = bgp_node_get (table, p);
4768 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4769 if (rn->p.prefixlen > p->prefixlen)
4770 {
4771 match = 0;
4772
4773 for (ri = rn->info; ri; ri = ri->next)
4774 {
4775 if (BGP_INFO_HOLDDOWN (ri))
4776 continue;
4777
4778 if (del && ri == del)
4779 continue;
4780
4781 if (! rinew && first)
Paul Jakma7aa9dce2014-09-19 14:42:23 +01004782 first = 0;
paul718e3742002-12-13 20:15:29 +00004783
4784#ifdef AGGREGATE_NEXTHOP_CHECK
4785 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4786 || ri->attr->med != med)
4787 {
4788 if (aspath)
4789 aspath_free (aspath);
4790 if (community)
4791 community_free (community);
4792 bgp_unlock_node (rn);
4793 bgp_unlock_node (top);
4794 return;
4795 }
4796#endif /* AGGREGATE_NEXTHOP_CHECK */
4797
Daniel Waltonf2eb9ca2015-05-19 17:47:21 -07004798 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4799 atomic_aggregate = 1;
4800
paul718e3742002-12-13 20:15:29 +00004801 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4802 {
4803 if (aggregate->summary_only)
4804 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004805 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004806 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004807 match++;
4808 }
4809
4810 aggregate->count++;
4811
Daniel Walton76a72802015-05-19 17:47:24 -07004812 if (origin < ri->attr->origin)
4813 origin = ri->attr->origin;
4814
paul718e3742002-12-13 20:15:29 +00004815 if (aggregate->as_set)
4816 {
paul718e3742002-12-13 20:15:29 +00004817 if (aspath)
4818 {
4819 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4820 aspath_free (aspath);
4821 aspath = asmerge;
4822 }
4823 else
4824 aspath = aspath_dup (ri->attr->aspath);
4825
4826 if (ri->attr->community)
4827 {
4828 if (community)
4829 {
4830 commerge = community_merge (community,
4831 ri->attr->community);
4832 community = community_uniq_sort (commerge);
4833 community_free (commerge);
4834 }
4835 else
4836 community = community_dup (ri->attr->community);
4837 }
4838 }
4839 }
4840 }
4841 if (match)
4842 bgp_process (bgp, rn, afi, safi);
4843 }
4844 bgp_unlock_node (top);
4845
4846 if (rinew)
4847 {
4848 aggregate->count++;
4849
4850 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004851 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004852
Daniel Walton76a72802015-05-19 17:47:24 -07004853 if (origin < rinew->attr->origin)
4854 origin = rinew->attr->origin;
4855
paul718e3742002-12-13 20:15:29 +00004856 if (aggregate->as_set)
4857 {
paul718e3742002-12-13 20:15:29 +00004858 if (aspath)
4859 {
4860 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4861 aspath_free (aspath);
4862 aspath = asmerge;
4863 }
4864 else
4865 aspath = aspath_dup (rinew->attr->aspath);
4866
4867 if (rinew->attr->community)
4868 {
4869 if (community)
4870 {
4871 commerge = community_merge (community,
4872 rinew->attr->community);
4873 community = community_uniq_sort (commerge);
4874 community_free (commerge);
4875 }
4876 else
4877 community = community_dup (rinew->attr->community);
4878 }
4879 }
4880 }
4881
4882 if (aggregate->count > 0)
4883 {
4884 rn = bgp_node_get (table, p);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05004885 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, bgp->peer_self,
4886 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
Daniel Waltonf2eb9ca2015-05-19 17:47:21 -07004887 aggregate->as_set,
4888 atomic_aggregate), rn);
paul718e3742002-12-13 20:15:29 +00004889 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00004890
4891 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004892 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004893 bgp_process (bgp, rn, afi, safi);
4894 }
4895 else
4896 {
4897 if (aspath)
4898 aspath_free (aspath);
4899 if (community)
4900 community_free (community);
4901 }
4902}
4903
4904void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4905 struct bgp_aggregate *);
4906
4907void
4908bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4909 struct bgp_info *ri, afi_t afi, safi_t safi)
4910{
4911 struct bgp_node *child;
4912 struct bgp_node *rn;
4913 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004914 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004915
4916 /* MPLS-VPN aggregation is not yet supported. */
Lou Berger298cc2f2016-01-12 13:42:02 -05004917 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004918 return;
4919
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004920 table = bgp->aggregate[afi][safi];
4921
4922 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004923 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004924 return;
4925
paul718e3742002-12-13 20:15:29 +00004926 if (p->prefixlen == 0)
4927 return;
4928
4929 if (BGP_INFO_HOLDDOWN (ri))
4930 return;
4931
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004932 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004933
4934 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004935 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004936 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4937 {
4938 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004939 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004940 }
4941 bgp_unlock_node (child);
4942}
4943
4944void
4945bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4946 struct bgp_info *del, afi_t afi, safi_t safi)
4947{
4948 struct bgp_node *child;
4949 struct bgp_node *rn;
4950 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004951 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004952
4953 /* MPLS-VPN aggregation is not yet supported. */
Lou Berger298cc2f2016-01-12 13:42:02 -05004954 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004955 return;
4956
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004957 table = bgp->aggregate[afi][safi];
4958
4959 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004960 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004961 return;
4962
paul718e3742002-12-13 20:15:29 +00004963 if (p->prefixlen == 0)
4964 return;
4965
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004966 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004967
4968 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004969 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004970 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4971 {
4972 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004973 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004974 }
4975 bgp_unlock_node (child);
4976}
4977
Daniel Walton76a72802015-05-19 17:47:24 -07004978/* Called via bgp_aggregate_set when the user configures aggregate-address */
paul94f2b392005-06-28 12:44:16 +00004979static void
paul718e3742002-12-13 20:15:29 +00004980bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4981 struct bgp_aggregate *aggregate)
4982{
4983 struct bgp_table *table;
4984 struct bgp_node *top;
4985 struct bgp_node *rn;
4986 struct bgp_info *new;
4987 struct bgp_info *ri;
4988 unsigned long match;
4989 u_char origin = BGP_ORIGIN_IGP;
4990 struct aspath *aspath = NULL;
4991 struct aspath *asmerge = NULL;
4992 struct community *community = NULL;
4993 struct community *commerge = NULL;
Daniel Waltonf2eb9ca2015-05-19 17:47:21 -07004994 u_char atomic_aggregate = 0;
paul718e3742002-12-13 20:15:29 +00004995
4996 table = bgp->rib[afi][safi];
4997
4998 /* Sanity check. */
4999 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5000 return;
5001 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5002 return;
5003
5004 /* If routes exists below this node, generate aggregate routes. */
5005 top = bgp_node_get (table, p);
5006 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5007 if (rn->p.prefixlen > p->prefixlen)
5008 {
5009 match = 0;
5010
5011 for (ri = rn->info; ri; ri = ri->next)
5012 {
5013 if (BGP_INFO_HOLDDOWN (ri))
5014 continue;
5015
Daniel Waltonf2eb9ca2015-05-19 17:47:21 -07005016 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5017 atomic_aggregate = 1;
5018
paul718e3742002-12-13 20:15:29 +00005019 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5020 {
5021 /* summary-only aggregate route suppress aggregated
5022 route announcement. */
5023 if (aggregate->summary_only)
5024 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005025 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00005026 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005027 match++;
5028 }
Daniel Walton76a72802015-05-19 17:47:24 -07005029
5030 /* If at least one route among routes that are aggregated has
5031 * ORIGIN with the value INCOMPLETE, then the aggregated route
5032 * MUST have the ORIGIN attribute with the value INCOMPLETE.
5033 * Otherwise, if at least one route among routes that are
5034 * aggregated has ORIGIN with the value EGP, then the aggregated
5035 * route MUST have the ORIGIN attribute with the value EGP.
5036 */
5037 if (origin < ri->attr->origin)
5038 origin = ri->attr->origin;
5039
paul718e3742002-12-13 20:15:29 +00005040 /* as-set aggregate route generate origin, as path,
5041 community aggregation. */
5042 if (aggregate->as_set)
5043 {
paul718e3742002-12-13 20:15:29 +00005044 if (aspath)
5045 {
5046 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5047 aspath_free (aspath);
5048 aspath = asmerge;
5049 }
5050 else
5051 aspath = aspath_dup (ri->attr->aspath);
5052
5053 if (ri->attr->community)
5054 {
5055 if (community)
5056 {
5057 commerge = community_merge (community,
5058 ri->attr->community);
5059 community = community_uniq_sort (commerge);
5060 community_free (commerge);
5061 }
5062 else
5063 community = community_dup (ri->attr->community);
5064 }
5065 }
5066 aggregate->count++;
5067 }
5068 }
5069
5070 /* If this node is suppressed, process the change. */
5071 if (match)
5072 bgp_process (bgp, rn, afi, safi);
5073 }
5074 bgp_unlock_node (top);
5075
5076 /* Add aggregate route to BGP table. */
5077 if (aggregate->count)
5078 {
5079 rn = bgp_node_get (table, p);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05005080 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, bgp->peer_self,
5081 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
Daniel Waltonf2eb9ca2015-05-19 17:47:21 -07005082 aggregate->as_set,
5083 atomic_aggregate), rn);
paul718e3742002-12-13 20:15:29 +00005084 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00005085
5086 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00005087 bgp_unlock_node (rn);
5088
paul718e3742002-12-13 20:15:29 +00005089 /* Process change. */
5090 bgp_process (bgp, rn, afi, safi);
5091 }
Denil Virae2a92582015-08-11 13:34:59 -07005092 else
5093 {
5094 if (aspath)
5095 aspath_free (aspath);
5096 if (community)
5097 community_free (community);
5098 }
paul718e3742002-12-13 20:15:29 +00005099}
5100
5101void
5102bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5103 safi_t safi, struct bgp_aggregate *aggregate)
5104{
5105 struct bgp_table *table;
5106 struct bgp_node *top;
5107 struct bgp_node *rn;
5108 struct bgp_info *ri;
5109 unsigned long match;
5110
5111 table = bgp->rib[afi][safi];
5112
5113 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5114 return;
5115 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5116 return;
5117
5118 /* If routes exists below this node, generate aggregate routes. */
5119 top = bgp_node_get (table, p);
5120 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5121 if (rn->p.prefixlen > p->prefixlen)
5122 {
5123 match = 0;
5124
5125 for (ri = rn->info; ri; ri = ri->next)
5126 {
5127 if (BGP_INFO_HOLDDOWN (ri))
5128 continue;
5129
5130 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5131 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005132 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00005133 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005134 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00005135
Paul Jakmafb982c22007-05-04 20:15:47 +00005136 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00005137 {
Paul Jakma1a392d42006-09-07 00:24:49 +00005138 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005139 match++;
5140 }
5141 }
5142 aggregate->count--;
5143 }
5144 }
5145
Paul Jakmafb982c22007-05-04 20:15:47 +00005146 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00005147 if (match)
5148 bgp_process (bgp, rn, afi, safi);
5149 }
5150 bgp_unlock_node (top);
5151
5152 /* Delete aggregate route from BGP table. */
5153 rn = bgp_node_get (table, p);
5154
5155 for (ri = rn->info; ri; ri = ri->next)
5156 if (ri->peer == bgp->peer_self
5157 && ri->type == ZEBRA_ROUTE_BGP
5158 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5159 break;
5160
5161 /* Withdraw static BGP route from routing table. */
5162 if (ri)
5163 {
paul718e3742002-12-13 20:15:29 +00005164 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005165 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00005166 }
5167
5168 /* Unlock bgp_node_lookup. */
5169 bgp_unlock_node (rn);
5170}
5171
5172/* Aggregate route attribute. */
5173#define AGGREGATE_SUMMARY_ONLY 1
5174#define AGGREGATE_AS_SET 1
5175
paul94f2b392005-06-28 12:44:16 +00005176static int
Robert Baysf6269b42010-08-05 10:26:28 -07005177bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5178 afi_t afi, safi_t safi)
5179{
5180 int ret;
5181 struct prefix p;
5182 struct bgp_node *rn;
5183 struct bgp *bgp;
5184 struct bgp_aggregate *aggregate;
5185
5186 /* Convert string to prefix structure. */
5187 ret = str2prefix (prefix_str, &p);
5188 if (!ret)
5189 {
5190 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5191 return CMD_WARNING;
5192 }
5193 apply_mask (&p);
5194
5195 /* Get BGP structure. */
5196 bgp = vty->index;
5197
5198 /* Old configuration check. */
5199 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5200 if (! rn)
5201 {
5202 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5203 VTY_NEWLINE);
5204 return CMD_WARNING;
5205 }
5206
5207 aggregate = rn->info;
5208 if (aggregate->safi & SAFI_UNICAST)
5209 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5210 if (aggregate->safi & SAFI_MULTICAST)
5211 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5212
5213 /* Unlock aggregate address configuration. */
5214 rn->info = NULL;
5215 bgp_aggregate_free (aggregate);
5216 bgp_unlock_node (rn);
5217 bgp_unlock_node (rn);
5218
5219 return CMD_SUCCESS;
5220}
5221
5222static int
5223bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00005224 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00005225 u_char summary_only, u_char as_set)
5226{
5227 int ret;
5228 struct prefix p;
5229 struct bgp_node *rn;
5230 struct bgp *bgp;
5231 struct bgp_aggregate *aggregate;
5232
5233 /* Convert string to prefix structure. */
5234 ret = str2prefix (prefix_str, &p);
5235 if (!ret)
5236 {
5237 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5238 return CMD_WARNING;
5239 }
5240 apply_mask (&p);
5241
5242 /* Get BGP structure. */
5243 bgp = vty->index;
5244
5245 /* Old configuration check. */
5246 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5247
5248 if (rn->info)
5249 {
5250 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005251 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005252 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5253 if (ret)
5254 {
Robert Bays368473f2010-08-05 10:26:29 -07005255 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5256 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005257 return CMD_WARNING;
5258 }
paul718e3742002-12-13 20:15:29 +00005259 }
5260
5261 /* Make aggregate address structure. */
5262 aggregate = bgp_aggregate_new ();
5263 aggregate->summary_only = summary_only;
5264 aggregate->as_set = as_set;
5265 aggregate->safi = safi;
5266 rn->info = aggregate;
5267
5268 /* Aggregate address insert into BGP routing table. */
5269 if (safi & SAFI_UNICAST)
5270 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5271 if (safi & SAFI_MULTICAST)
5272 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5273
5274 return CMD_SUCCESS;
5275}
5276
paul718e3742002-12-13 20:15:29 +00005277DEFUN (aggregate_address,
5278 aggregate_address_cmd,
5279 "aggregate-address A.B.C.D/M",
5280 "Configure BGP aggregate entries\n"
5281 "Aggregate prefix\n")
5282{
5283 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5284}
5285
5286DEFUN (aggregate_address_mask,
5287 aggregate_address_mask_cmd,
5288 "aggregate-address A.B.C.D A.B.C.D",
5289 "Configure BGP aggregate entries\n"
5290 "Aggregate address\n"
5291 "Aggregate mask\n")
5292{
5293 int ret;
5294 char prefix_str[BUFSIZ];
5295
5296 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5297
5298 if (! ret)
5299 {
5300 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5301 return CMD_WARNING;
5302 }
5303
5304 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5305 0, 0);
5306}
5307
5308DEFUN (aggregate_address_summary_only,
5309 aggregate_address_summary_only_cmd,
5310 "aggregate-address A.B.C.D/M summary-only",
5311 "Configure BGP aggregate entries\n"
5312 "Aggregate prefix\n"
5313 "Filter more specific routes from updates\n")
5314{
5315 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5316 AGGREGATE_SUMMARY_ONLY, 0);
5317}
5318
5319DEFUN (aggregate_address_mask_summary_only,
5320 aggregate_address_mask_summary_only_cmd,
5321 "aggregate-address A.B.C.D A.B.C.D summary-only",
5322 "Configure BGP aggregate entries\n"
5323 "Aggregate address\n"
5324 "Aggregate mask\n"
5325 "Filter more specific routes from updates\n")
5326{
5327 int ret;
5328 char prefix_str[BUFSIZ];
5329
5330 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5331
5332 if (! ret)
5333 {
5334 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5335 return CMD_WARNING;
5336 }
5337
5338 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5339 AGGREGATE_SUMMARY_ONLY, 0);
5340}
5341
5342DEFUN (aggregate_address_as_set,
5343 aggregate_address_as_set_cmd,
5344 "aggregate-address A.B.C.D/M as-set",
5345 "Configure BGP aggregate entries\n"
5346 "Aggregate prefix\n"
5347 "Generate AS set path information\n")
5348{
5349 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5350 0, AGGREGATE_AS_SET);
5351}
5352
5353DEFUN (aggregate_address_mask_as_set,
5354 aggregate_address_mask_as_set_cmd,
5355 "aggregate-address A.B.C.D A.B.C.D as-set",
5356 "Configure BGP aggregate entries\n"
5357 "Aggregate address\n"
5358 "Aggregate mask\n"
5359 "Generate AS set path information\n")
5360{
5361 int ret;
5362 char prefix_str[BUFSIZ];
5363
5364 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5365
5366 if (! ret)
5367 {
5368 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5369 return CMD_WARNING;
5370 }
5371
5372 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5373 0, AGGREGATE_AS_SET);
5374}
5375
5376
5377DEFUN (aggregate_address_as_set_summary,
5378 aggregate_address_as_set_summary_cmd,
5379 "aggregate-address A.B.C.D/M as-set summary-only",
5380 "Configure BGP aggregate entries\n"
5381 "Aggregate prefix\n"
5382 "Generate AS set path information\n"
5383 "Filter more specific routes from updates\n")
5384{
5385 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5386 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5387}
5388
5389ALIAS (aggregate_address_as_set_summary,
5390 aggregate_address_summary_as_set_cmd,
5391 "aggregate-address A.B.C.D/M summary-only as-set",
5392 "Configure BGP aggregate entries\n"
5393 "Aggregate prefix\n"
5394 "Filter more specific routes from updates\n"
5395 "Generate AS set path information\n")
5396
5397DEFUN (aggregate_address_mask_as_set_summary,
5398 aggregate_address_mask_as_set_summary_cmd,
5399 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5400 "Configure BGP aggregate entries\n"
5401 "Aggregate address\n"
5402 "Aggregate mask\n"
5403 "Generate AS set path information\n"
5404 "Filter more specific routes from updates\n")
5405{
5406 int ret;
5407 char prefix_str[BUFSIZ];
5408
5409 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5410
5411 if (! ret)
5412 {
5413 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5414 return CMD_WARNING;
5415 }
5416
5417 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5418 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5419}
5420
5421ALIAS (aggregate_address_mask_as_set_summary,
5422 aggregate_address_mask_summary_as_set_cmd,
5423 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5424 "Configure BGP aggregate entries\n"
5425 "Aggregate address\n"
5426 "Aggregate mask\n"
5427 "Filter more specific routes from updates\n"
5428 "Generate AS set path information\n")
5429
5430DEFUN (no_aggregate_address,
5431 no_aggregate_address_cmd,
5432 "no aggregate-address A.B.C.D/M",
5433 NO_STR
5434 "Configure BGP aggregate entries\n"
5435 "Aggregate prefix\n")
5436{
5437 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5438}
5439
5440ALIAS (no_aggregate_address,
5441 no_aggregate_address_summary_only_cmd,
5442 "no aggregate-address A.B.C.D/M summary-only",
5443 NO_STR
5444 "Configure BGP aggregate entries\n"
5445 "Aggregate prefix\n"
5446 "Filter more specific routes from updates\n")
5447
5448ALIAS (no_aggregate_address,
5449 no_aggregate_address_as_set_cmd,
5450 "no aggregate-address A.B.C.D/M as-set",
5451 NO_STR
5452 "Configure BGP aggregate entries\n"
5453 "Aggregate prefix\n"
5454 "Generate AS set path information\n")
5455
5456ALIAS (no_aggregate_address,
5457 no_aggregate_address_as_set_summary_cmd,
5458 "no aggregate-address A.B.C.D/M as-set summary-only",
5459 NO_STR
5460 "Configure BGP aggregate entries\n"
5461 "Aggregate prefix\n"
5462 "Generate AS set path information\n"
5463 "Filter more specific routes from updates\n")
5464
5465ALIAS (no_aggregate_address,
5466 no_aggregate_address_summary_as_set_cmd,
5467 "no aggregate-address A.B.C.D/M summary-only as-set",
5468 NO_STR
5469 "Configure BGP aggregate entries\n"
5470 "Aggregate prefix\n"
5471 "Filter more specific routes from updates\n"
5472 "Generate AS set path information\n")
5473
5474DEFUN (no_aggregate_address_mask,
5475 no_aggregate_address_mask_cmd,
5476 "no aggregate-address A.B.C.D A.B.C.D",
5477 NO_STR
5478 "Configure BGP aggregate entries\n"
5479 "Aggregate address\n"
5480 "Aggregate mask\n")
5481{
5482 int ret;
5483 char prefix_str[BUFSIZ];
5484
5485 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5486
5487 if (! ret)
5488 {
5489 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5490 return CMD_WARNING;
5491 }
5492
5493 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5494}
5495
5496ALIAS (no_aggregate_address_mask,
5497 no_aggregate_address_mask_summary_only_cmd,
5498 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5499 NO_STR
5500 "Configure BGP aggregate entries\n"
5501 "Aggregate address\n"
5502 "Aggregate mask\n"
5503 "Filter more specific routes from updates\n")
5504
5505ALIAS (no_aggregate_address_mask,
5506 no_aggregate_address_mask_as_set_cmd,
5507 "no aggregate-address A.B.C.D A.B.C.D as-set",
5508 NO_STR
5509 "Configure BGP aggregate entries\n"
5510 "Aggregate address\n"
5511 "Aggregate mask\n"
5512 "Generate AS set path information\n")
5513
5514ALIAS (no_aggregate_address_mask,
5515 no_aggregate_address_mask_as_set_summary_cmd,
5516 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5517 NO_STR
5518 "Configure BGP aggregate entries\n"
5519 "Aggregate address\n"
5520 "Aggregate mask\n"
5521 "Generate AS set path information\n"
5522 "Filter more specific routes from updates\n")
5523
5524ALIAS (no_aggregate_address_mask,
5525 no_aggregate_address_mask_summary_as_set_cmd,
5526 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5527 NO_STR
5528 "Configure BGP aggregate entries\n"
5529 "Aggregate address\n"
5530 "Aggregate mask\n"
5531 "Filter more specific routes from updates\n"
5532 "Generate AS set path information\n")
5533
paul718e3742002-12-13 20:15:29 +00005534DEFUN (ipv6_aggregate_address,
5535 ipv6_aggregate_address_cmd,
5536 "aggregate-address X:X::X:X/M",
5537 "Configure BGP aggregate entries\n"
5538 "Aggregate prefix\n")
5539{
5540 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5541}
5542
5543DEFUN (ipv6_aggregate_address_summary_only,
5544 ipv6_aggregate_address_summary_only_cmd,
5545 "aggregate-address X:X::X:X/M summary-only",
5546 "Configure BGP aggregate entries\n"
5547 "Aggregate prefix\n"
5548 "Filter more specific routes from updates\n")
5549{
5550 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5551 AGGREGATE_SUMMARY_ONLY, 0);
5552}
5553
5554DEFUN (no_ipv6_aggregate_address,
5555 no_ipv6_aggregate_address_cmd,
5556 "no aggregate-address X:X::X:X/M",
5557 NO_STR
5558 "Configure BGP aggregate entries\n"
5559 "Aggregate prefix\n")
5560{
5561 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5562}
5563
5564DEFUN (no_ipv6_aggregate_address_summary_only,
5565 no_ipv6_aggregate_address_summary_only_cmd,
5566 "no aggregate-address X:X::X:X/M summary-only",
5567 NO_STR
5568 "Configure BGP aggregate entries\n"
5569 "Aggregate prefix\n"
5570 "Filter more specific routes from updates\n")
5571{
5572 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5573}
5574
5575ALIAS (ipv6_aggregate_address,
5576 old_ipv6_aggregate_address_cmd,
5577 "ipv6 bgp aggregate-address X:X::X:X/M",
5578 IPV6_STR
5579 BGP_STR
5580 "Configure BGP aggregate entries\n"
5581 "Aggregate prefix\n")
5582
5583ALIAS (ipv6_aggregate_address_summary_only,
5584 old_ipv6_aggregate_address_summary_only_cmd,
5585 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5586 IPV6_STR
5587 BGP_STR
5588 "Configure BGP aggregate entries\n"
5589 "Aggregate prefix\n"
5590 "Filter more specific routes from updates\n")
5591
5592ALIAS (no_ipv6_aggregate_address,
5593 old_no_ipv6_aggregate_address_cmd,
5594 "no ipv6 bgp aggregate-address X:X::X:X/M",
5595 NO_STR
5596 IPV6_STR
5597 BGP_STR
5598 "Configure BGP aggregate entries\n"
5599 "Aggregate prefix\n")
5600
5601ALIAS (no_ipv6_aggregate_address_summary_only,
5602 old_no_ipv6_aggregate_address_summary_only_cmd,
5603 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5604 NO_STR
5605 IPV6_STR
5606 BGP_STR
5607 "Configure BGP aggregate entries\n"
5608 "Aggregate prefix\n"
5609 "Filter more specific routes from updates\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02005610
paul718e3742002-12-13 20:15:29 +00005611/* Redistribute route treatment. */
5612void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005613bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5614 const struct in6_addr *nexthop6,
Paul Jakma96d10602016-07-01 14:23:45 +01005615 u_int32_t metric, u_char type, route_tag_t tag)
paul718e3742002-12-13 20:15:29 +00005616{
5617 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005618 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005619 struct bgp_info *new;
5620 struct bgp_info *bi;
5621 struct bgp_info info;
5622 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005623 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005624 struct attr *new_attr;
5625 afi_t afi;
5626 int ret;
5627
5628 /* Make default attribute. */
5629 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5630 if (nexthop)
5631 attr.nexthop = *nexthop;
5632
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005633 if (nexthop6)
5634 {
5635 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5636 extra->mp_nexthop_global = *nexthop6;
5637 extra->mp_nexthop_len = 16;
5638 }
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005639
paul718e3742002-12-13 20:15:29 +00005640 attr.med = metric;
5641 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Piotr Chytła605aa332015-12-01 10:03:54 -05005642 attr.extra->tag = tag;
paul718e3742002-12-13 20:15:29 +00005643
paul1eb8ef22005-04-07 07:30:20 +00005644 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005645 {
5646 afi = family2afi (p->family);
5647
5648 if (bgp->redist[afi][type])
5649 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005650 struct attr attr_new;
5651 struct attr_extra extra_new;
5652
paul718e3742002-12-13 20:15:29 +00005653 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005654 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005655 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005656
5657 if (bgp->redist_metric_flag[afi][type])
5658 attr_new.med = bgp->redist_metric[afi][type];
5659
5660 /* Apply route-map. */
Daniel Walton1994dc82015-09-17 10:15:59 -04005661 if (bgp->rmap[afi][type].name)
paul718e3742002-12-13 20:15:29 +00005662 {
5663 info.peer = bgp->peer_self;
5664 info.attr = &attr_new;
5665
paulfee0f4c2004-09-13 05:12:46 +00005666 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5667
paul718e3742002-12-13 20:15:29 +00005668 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5669 &info);
paulfee0f4c2004-09-13 05:12:46 +00005670
5671 bgp->peer_self->rmap_type = 0;
5672
paul718e3742002-12-13 20:15:29 +00005673 if (ret == RMAP_DENYMATCH)
5674 {
5675 /* Free uninterned attribute. */
5676 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005677
paul718e3742002-12-13 20:15:29 +00005678 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005679 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005680 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005681 bgp_redistribute_delete (p, type);
5682 return;
5683 }
5684 }
5685
Paul Jakmafb982c22007-05-04 20:15:47 +00005686 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5687 afi, SAFI_UNICAST, p, NULL);
5688
paul718e3742002-12-13 20:15:29 +00005689 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005690
paul718e3742002-12-13 20:15:29 +00005691 for (bi = bn->info; bi; bi = bi->next)
5692 if (bi->peer == bgp->peer_self
5693 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5694 break;
5695
5696 if (bi)
5697 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005698 if (attrhash_cmp (bi->attr, new_attr) &&
5699 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005700 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005701 bgp_attr_unintern (&new_attr);
5702 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005703 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005704 bgp_unlock_node (bn);
5705 return;
5706 }
5707 else
5708 {
5709 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005710 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005711
5712 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005713 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5714 bgp_info_restore(bn, bi);
5715 else
5716 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005717 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005718 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005719 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005720
5721 /* Process change. */
5722 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5723 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5724 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005725 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005726 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005727 return;
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05005728 }
paul718e3742002-12-13 20:15:29 +00005729 }
5730
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05005731 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, bgp->peer_self,
5732 new_attr, bn);
paul718e3742002-12-13 20:15:29 +00005733 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00005734
5735 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5736 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005737 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005738 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5739 }
5740 }
5741
5742 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005743 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005744 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005745}
5746
5747void
5748bgp_redistribute_delete (struct prefix *p, u_char type)
5749{
5750 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005751 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005752 afi_t afi;
5753 struct bgp_node *rn;
5754 struct bgp_info *ri;
5755
paul1eb8ef22005-04-07 07:30:20 +00005756 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005757 {
5758 afi = family2afi (p->family);
5759
5760 if (bgp->redist[afi][type])
5761 {
paulfee0f4c2004-09-13 05:12:46 +00005762 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005763
5764 for (ri = rn->info; ri; ri = ri->next)
5765 if (ri->peer == bgp->peer_self
5766 && ri->type == type)
5767 break;
5768
5769 if (ri)
5770 {
5771 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005772 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005773 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005774 }
5775 bgp_unlock_node (rn);
5776 }
5777 }
5778}
5779
5780/* Withdraw specified route type's route. */
5781void
5782bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5783{
5784 struct bgp_node *rn;
5785 struct bgp_info *ri;
5786 struct bgp_table *table;
5787
5788 table = bgp->rib[afi][SAFI_UNICAST];
5789
5790 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5791 {
5792 for (ri = rn->info; ri; ri = ri->next)
5793 if (ri->peer == bgp->peer_self
5794 && ri->type == type)
5795 break;
5796
5797 if (ri)
5798 {
5799 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005800 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005801 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005802 }
5803 }
5804}
David Lamparter6b0655a2014-06-04 06:53:35 +02005805
paul718e3742002-12-13 20:15:29 +00005806/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005807static void
paul718e3742002-12-13 20:15:29 +00005808route_vty_out_route (struct prefix *p, struct vty *vty)
5809{
5810 int len;
5811 u_int32_t destination;
5812 char buf[BUFSIZ];
5813
5814 if (p->family == AF_INET)
5815 {
5816 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5817 destination = ntohl (p->u.prefix4.s_addr);
5818
5819 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5820 || (IN_CLASSB (destination) && p->prefixlen == 16)
5821 || (IN_CLASSA (destination) && p->prefixlen == 8)
5822 || p->u.prefix4.s_addr == 0)
5823 {
5824 /* When mask is natural, mask is not displayed. */
5825 }
5826 else
5827 len += vty_out (vty, "/%d", p->prefixlen);
5828 }
5829 else
5830 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5831 p->prefixlen);
5832
5833 len = 17 - len;
5834 if (len < 1)
5835 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5836 else
5837 vty_out (vty, "%*s", len, " ");
5838}
5839
paul718e3742002-12-13 20:15:29 +00005840enum bgp_display_type
5841{
5842 normal_list,
5843};
5844
paulb40d9392005-08-22 22:34:41 +00005845/* Print the short form route status for a bgp_info */
5846static void
5847route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005848{
paulb40d9392005-08-22 22:34:41 +00005849 /* Route status display. */
5850 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5851 vty_out (vty, "R");
5852 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005853 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005854 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005855 vty_out (vty, "s");
Daniel Waltone2a0ebf2015-05-19 18:03:43 -07005856 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
5857 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
paul718e3742002-12-13 20:15:29 +00005858 vty_out (vty, "*");
5859 else
5860 vty_out (vty, " ");
5861
5862 /* Selected */
5863 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5864 vty_out (vty, "h");
5865 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5866 vty_out (vty, "d");
5867 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5868 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005869 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5870 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005871 else
5872 vty_out (vty, " ");
5873
5874 /* Internal route. */
5875 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5876 vty_out (vty, "i");
5877 else
paulb40d9392005-08-22 22:34:41 +00005878 vty_out (vty, " ");
5879}
5880
5881/* called from terminal list command */
5882void
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005883route_vty_out(
5884 struct vty *vty,
5885 struct prefix *p,
5886 struct bgp_info *binfo,
5887 int display,
5888 safi_t safi)
paulb40d9392005-08-22 22:34:41 +00005889{
5890 struct attr *attr;
5891
5892 /* short status lead text */
5893 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005894
5895 /* print prefix and mask */
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005896 if (!display)
paul718e3742002-12-13 20:15:29 +00005897 route_vty_out_route (p, vty);
5898 else
5899 vty_out (vty, "%*s", 17, " ");
5900
5901 /* Print attribute */
5902 attr = binfo->attr;
5903 if (attr)
5904 {
paul718e3742002-12-13 20:15:29 +00005905
Lou Berger298cc2f2016-01-12 13:42:02 -05005906 /*
5907 * NEXTHOP start
5908 */
5909
5910 /*
5911 * For ENCAP routes, nexthop address family is not
5912 * neccessarily the same as the prefix address family.
5913 * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
5914 */
5915 if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN)) {
5916 if (attr->extra) {
5917 char buf[BUFSIZ];
5918 int af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len);
5919
5920 switch (af) {
5921 case AF_INET:
5922 vty_out (vty, "%s", inet_ntop(af,
5923 &attr->extra->mp_nexthop_global_in, buf, BUFSIZ));
5924 break;
Lou Berger298cc2f2016-01-12 13:42:02 -05005925 case AF_INET6:
5926 vty_out (vty, "%s", inet_ntop(af,
5927 &attr->extra->mp_nexthop_global, buf, BUFSIZ));
5928 break;
Lou Berger298cc2f2016-01-12 13:42:02 -05005929 default:
5930 vty_out(vty, "?");
5931 }
5932 } else {
5933 vty_out(vty, "?");
paul718e3742002-12-13 20:15:29 +00005934 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005935 } else {
5936
5937 if (p->family == AF_INET)
5938 {
5939 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5940 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005941 else if (p->family == AF_INET6)
5942 {
5943 int len;
5944 char buf[BUFSIZ];
5945
5946 len = vty_out (vty, "%s",
5947 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5948 buf, BUFSIZ));
5949 len = 16 - len;
5950 if (len < 1)
5951 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5952 else
5953 vty_out (vty, "%*s", len, " ");
5954 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005955 else
5956 {
5957 vty_out(vty, "?");
5958 }
5959 }
5960
5961 /*
5962 * NEXTHOP end
5963 */
5964
paul718e3742002-12-13 20:15:29 +00005965
5966 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005967 vty_out (vty, "%10u ", attr->med);
paul718e3742002-12-13 20:15:29 +00005968 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005969 vty_out (vty, " ");
paul718e3742002-12-13 20:15:29 +00005970
5971 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005972 vty_out (vty, "%7u ", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005973 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005974 vty_out (vty, " ");
paul718e3742002-12-13 20:15:29 +00005975
Paul Jakmafb982c22007-05-04 20:15:47 +00005976 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005977
Paul Jakmab2518c12006-05-12 23:48:40 +00005978 /* Print aspath */
5979 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005980 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005981
Paul Jakmab2518c12006-05-12 23:48:40 +00005982 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005983 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005984 }
paul718e3742002-12-13 20:15:29 +00005985 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005986}
5987
5988/* called from terminal list command */
5989void
5990route_vty_out_tmp (struct vty *vty, struct prefix *p,
5991 struct attr *attr, safi_t safi)
5992{
5993 /* Route status display. */
5994 vty_out (vty, "*");
5995 vty_out (vty, ">");
5996 vty_out (vty, " ");
5997
5998 /* print prefix and mask */
5999 route_vty_out_route (p, vty);
6000
6001 /* Print attribute */
6002 if (attr)
6003 {
6004 if (p->family == AF_INET)
6005 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006006 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00006007 vty_out (vty, "%-16s",
6008 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00006009 else
6010 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6011 }
paul718e3742002-12-13 20:15:29 +00006012 else if (p->family == AF_INET6)
6013 {
6014 int len;
6015 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006016
6017 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006018
6019 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006020 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6021 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006022 len = 16 - len;
6023 if (len < 1)
6024 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6025 else
6026 vty_out (vty, "%*s", len, " ");
6027 }
paul718e3742002-12-13 20:15:29 +00006028
6029 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006030 vty_out (vty, "%10u ", attr->med);
paul718e3742002-12-13 20:15:29 +00006031 else
6032 vty_out (vty, " ");
6033
6034 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006035 vty_out (vty, "%7u ", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006036 else
6037 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006038
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006039 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00006040
Paul Jakmab2518c12006-05-12 23:48:40 +00006041 /* Print aspath */
6042 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006043 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006044
Paul Jakmab2518c12006-05-12 23:48:40 +00006045 /* Print origin */
paul718e3742002-12-13 20:15:29 +00006046 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00006047 }
paul718e3742002-12-13 20:15:29 +00006048
6049 vty_out (vty, "%s", VTY_NEWLINE);
6050}
6051
ajs5a646652004-11-05 01:25:55 +00006052void
paul718e3742002-12-13 20:15:29 +00006053route_vty_out_tag (struct vty *vty, struct prefix *p,
6054 struct bgp_info *binfo, int display, safi_t safi)
6055{
6056 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006057 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00006058
6059 if (!binfo->extra)
6060 return;
6061
paulb40d9392005-08-22 22:34:41 +00006062 /* short status lead text */
6063 route_vty_short_status_out (vty, binfo);
6064
paul718e3742002-12-13 20:15:29 +00006065 /* print prefix and mask */
6066 if (! display)
6067 route_vty_out_route (p, vty);
6068 else
6069 vty_out (vty, "%*s", 17, " ");
6070
6071 /* Print attribute */
6072 attr = binfo->attr;
6073 if (attr)
6074 {
6075 if (p->family == AF_INET)
6076 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006077 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00006078 vty_out (vty, "%-16s",
6079 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00006080 else
6081 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6082 }
paul718e3742002-12-13 20:15:29 +00006083 else if (p->family == AF_INET6)
6084 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006085 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006086 char buf[BUFSIZ];
6087 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006088 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00006089 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006090 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6091 buf, BUFSIZ));
6092 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006093 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006094 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6095 buf, BUFSIZ),
6096 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6097 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006098
6099 }
paul718e3742002-12-13 20:15:29 +00006100 }
6101
Paul Jakmafb982c22007-05-04 20:15:47 +00006102 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00006103
6104 vty_out (vty, "notag/%d", label);
6105
6106 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006107}
6108
6109/* dampening route */
ajs5a646652004-11-05 01:25:55 +00006110static void
paul718e3742002-12-13 20:15:29 +00006111damp_route_vty_out (struct vty *vty, struct prefix *p,
6112 struct bgp_info *binfo, int display, safi_t safi)
6113{
6114 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006115 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00006116 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00006117
paulb40d9392005-08-22 22:34:41 +00006118 /* short status lead text */
6119 route_vty_short_status_out (vty, binfo);
6120
paul718e3742002-12-13 20:15:29 +00006121 /* print prefix and mask */
6122 if (! display)
6123 route_vty_out_route (p, vty);
6124 else
6125 vty_out (vty, "%*s", 17, " ");
6126
6127 len = vty_out (vty, "%s", binfo->peer->host);
6128 len = 17 - len;
6129 if (len < 1)
6130 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6131 else
6132 vty_out (vty, "%*s", len, " ");
6133
Chris Caputo50aef6f2009-06-23 06:06:49 +00006134 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006135
6136 /* Print attribute */
6137 attr = binfo->attr;
6138 if (attr)
6139 {
6140 /* Print aspath */
6141 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006142 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006143
6144 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006145 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006146 }
6147 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006148}
6149
paul718e3742002-12-13 20:15:29 +00006150/* flap route */
ajs5a646652004-11-05 01:25:55 +00006151static void
paul718e3742002-12-13 20:15:29 +00006152flap_route_vty_out (struct vty *vty, struct prefix *p,
6153 struct bgp_info *binfo, int display, safi_t safi)
6154{
6155 struct attr *attr;
6156 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00006157 char timebuf[BGP_UPTIME_LEN];
6158 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00006159
6160 if (!binfo->extra)
6161 return;
6162
6163 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00006164
paulb40d9392005-08-22 22:34:41 +00006165 /* short status lead text */
6166 route_vty_short_status_out (vty, binfo);
6167
paul718e3742002-12-13 20:15:29 +00006168 /* print prefix and mask */
6169 if (! display)
6170 route_vty_out_route (p, vty);
6171 else
6172 vty_out (vty, "%*s", 17, " ");
6173
6174 len = vty_out (vty, "%s", binfo->peer->host);
6175 len = 16 - len;
6176 if (len < 1)
6177 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6178 else
6179 vty_out (vty, "%*s", len, " ");
6180
6181 len = vty_out (vty, "%d", bdi->flap);
6182 len = 5 - len;
6183 if (len < 1)
6184 vty_out (vty, " ");
6185 else
6186 vty_out (vty, "%*s ", len, " ");
6187
6188 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6189 timebuf, BGP_UPTIME_LEN));
6190
6191 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6192 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00006193 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006194 else
6195 vty_out (vty, "%*s ", 8, " ");
6196
6197 /* Print attribute */
6198 attr = binfo->attr;
6199 if (attr)
6200 {
6201 /* Print aspath */
6202 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006203 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006204
6205 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006206 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006207 }
6208 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006209}
6210
paul94f2b392005-06-28 12:44:16 +00006211static void
paul718e3742002-12-13 20:15:29 +00006212route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6213 struct bgp_info *binfo, afi_t afi, safi_t safi)
6214{
6215 char buf[INET6_ADDRSTRLEN];
6216 char buf1[BUFSIZ];
6217 struct attr *attr;
6218 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03006219#ifdef HAVE_CLOCK_MONOTONIC
6220 time_t tbuf;
6221#endif
paul718e3742002-12-13 20:15:29 +00006222
6223 attr = binfo->attr;
6224
6225 if (attr)
6226 {
6227 /* Line1 display AS-path, Aggregator */
6228 if (attr->aspath)
6229 {
6230 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00006231 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00006232 vty_out (vty, "Local");
6233 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006234 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00006235 }
6236
paulb40d9392005-08-22 22:34:41 +00006237 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6238 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00006239 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6240 vty_out (vty, ", (stale)");
6241 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006242 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006243 attr->extra->aggregator_as,
6244 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006245 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6246 vty_out (vty, ", (Received from a RR-client)");
6247 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6248 vty_out (vty, ", (Received from a RS-client)");
6249 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6250 vty_out (vty, ", (history entry)");
6251 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6252 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006253 vty_out (vty, "%s", VTY_NEWLINE);
6254
6255 /* Line2 display Next-hop, Neighbor, Router-id */
6256 if (p->family == AF_INET)
6257 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006258 vty_out (vty, " %s", ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)) ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006259 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006260 inet_ntoa (attr->nexthop));
6261 }
paul718e3742002-12-13 20:15:29 +00006262 else
6263 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006264 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006265 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006266 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006267 buf, INET6_ADDRSTRLEN));
6268 }
paul718e3742002-12-13 20:15:29 +00006269
6270 if (binfo->peer == bgp->peer_self)
6271 {
6272 vty_out (vty, " from %s ",
6273 p->family == AF_INET ? "0.0.0.0" : "::");
6274 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6275 }
6276 else
6277 {
6278 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6279 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006280 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006281 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006282 if (!sockunion2str (&binfo->peer->su, buf, sizeof(buf))) {
6283 buf[0] = '?';
6284 buf[1] = 0;
6285 }
6286 vty_out (vty, " from %s", buf);
paul718e3742002-12-13 20:15:29 +00006287 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006288 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006289 else
6290 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6291 }
6292 vty_out (vty, "%s", VTY_NEWLINE);
6293
paul718e3742002-12-13 20:15:29 +00006294 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006295 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006296 {
6297 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006298 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006299 buf, INET6_ADDRSTRLEN),
6300 VTY_NEWLINE);
6301 }
paul718e3742002-12-13 20:15:29 +00006302
Piotr Chytła605aa332015-12-01 10:03:54 -05006303 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
paul718e3742002-12-13 20:15:29 +00006304 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6305
6306 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006307 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006308
6309 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006310 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006311 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006312 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006313
Paul Jakmafb982c22007-05-04 20:15:47 +00006314 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006315 vty_out (vty, ", weight %u", attr->extra->weight);
Piotr Chytła605aa332015-12-01 10:03:54 -05006316
6317 if (attr->extra && attr->extra->tag != 0)
6318 vty_out (vty, ", tag %d", attr->extra->tag);
paul718e3742002-12-13 20:15:29 +00006319
Daniel Waltone2a0ebf2015-05-19 18:03:43 -07006320 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6321 vty_out (vty, ", invalid");
6322 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
paul718e3742002-12-13 20:15:29 +00006323 vty_out (vty, ", valid");
6324
6325 if (binfo->peer != bgp->peer_self)
6326 {
6327 if (binfo->peer->as == binfo->peer->local_as)
6328 vty_out (vty, ", internal");
6329 else
6330 vty_out (vty, ", %s",
6331 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6332 }
6333 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6334 vty_out (vty, ", aggregated, local");
6335 else if (binfo->type != ZEBRA_ROUTE_BGP)
6336 vty_out (vty, ", sourced");
6337 else
6338 vty_out (vty, ", sourced, local");
6339
6340 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6341 vty_out (vty, ", atomic-aggregate");
6342
Josh Baileyde8d5df2011-07-20 20:46:01 -07006343 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6344 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6345 bgp_info_mpath_count (binfo)))
6346 vty_out (vty, ", multipath");
6347
paul718e3742002-12-13 20:15:29 +00006348 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6349 vty_out (vty, ", best");
6350
6351 vty_out (vty, "%s", VTY_NEWLINE);
6352
6353 /* Line 4 display Community */
6354 if (attr->community)
6355 vty_out (vty, " Community: %s%s", attr->community->str,
6356 VTY_NEWLINE);
6357
6358 /* Line 5 display Extended-community */
6359 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006360 vty_out (vty, " Extended Community: %s%s",
6361 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006362
6363 /* Line 6 display Originator, Cluster-id */
6364 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6365 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6366 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006367 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006368 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006369 vty_out (vty, " Originator: %s",
6370 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006371
6372 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6373 {
6374 int i;
6375 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006376 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6377 vty_out (vty, "%s ",
6378 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006379 }
6380 vty_out (vty, "%s", VTY_NEWLINE);
6381 }
Paul Jakma41367172007-08-06 15:24:51 +00006382
Paul Jakmafb982c22007-05-04 20:15:47 +00006383 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006384 bgp_damp_info_vty (vty, binfo);
6385
6386 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006387#ifdef HAVE_CLOCK_MONOTONIC
6388 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006389 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006390#else
6391 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6392#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006393 }
6394 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006395}
6396
6397#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6398 "h history, * valid, > best, = multipath,%s"\
6399 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006400#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006401#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6402#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6403#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6404
6405enum bgp_show_type
6406{
6407 bgp_show_type_normal,
6408 bgp_show_type_regexp,
6409 bgp_show_type_prefix_list,
6410 bgp_show_type_filter_list,
6411 bgp_show_type_route_map,
6412 bgp_show_type_neighbor,
6413 bgp_show_type_cidr_only,
6414 bgp_show_type_prefix_longer,
6415 bgp_show_type_community_all,
6416 bgp_show_type_community,
6417 bgp_show_type_community_exact,
6418 bgp_show_type_community_list,
6419 bgp_show_type_community_list_exact,
6420 bgp_show_type_flap_statistics,
6421 bgp_show_type_flap_address,
6422 bgp_show_type_flap_prefix,
6423 bgp_show_type_flap_cidr_only,
6424 bgp_show_type_flap_regexp,
6425 bgp_show_type_flap_filter_list,
6426 bgp_show_type_flap_prefix_list,
6427 bgp_show_type_flap_prefix_longer,
6428 bgp_show_type_flap_route_map,
6429 bgp_show_type_flap_neighbor,
6430 bgp_show_type_dampend_paths,
6431 bgp_show_type_damp_neighbor
6432};
6433
ajs5a646652004-11-05 01:25:55 +00006434static int
paulfee0f4c2004-09-13 05:12:46 +00006435bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006436 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006437{
paul718e3742002-12-13 20:15:29 +00006438 struct bgp_info *ri;
6439 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006440 int header = 1;
paul718e3742002-12-13 20:15:29 +00006441 int display;
ajs5a646652004-11-05 01:25:55 +00006442 unsigned long output_count;
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006443 unsigned long total_count;
paul718e3742002-12-13 20:15:29 +00006444
6445 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006446 output_count = 0;
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006447 total_count = 0;
paul718e3742002-12-13 20:15:29 +00006448
paul718e3742002-12-13 20:15:29 +00006449 /* Start processing of routes. */
6450 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6451 if (rn->info != NULL)
6452 {
6453 display = 0;
6454
6455 for (ri = rn->info; ri; ri = ri->next)
6456 {
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006457 total_count++;
ajs5a646652004-11-05 01:25:55 +00006458 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006459 || type == bgp_show_type_flap_address
6460 || type == bgp_show_type_flap_prefix
6461 || type == bgp_show_type_flap_cidr_only
6462 || type == bgp_show_type_flap_regexp
6463 || type == bgp_show_type_flap_filter_list
6464 || type == bgp_show_type_flap_prefix_list
6465 || type == bgp_show_type_flap_prefix_longer
6466 || type == bgp_show_type_flap_route_map
6467 || type == bgp_show_type_flap_neighbor
6468 || type == bgp_show_type_dampend_paths
6469 || type == bgp_show_type_damp_neighbor)
6470 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006471 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006472 continue;
6473 }
6474 if (type == bgp_show_type_regexp
6475 || type == bgp_show_type_flap_regexp)
6476 {
ajs5a646652004-11-05 01:25:55 +00006477 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006478
6479 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6480 continue;
6481 }
6482 if (type == bgp_show_type_prefix_list
6483 || type == bgp_show_type_flap_prefix_list)
6484 {
ajs5a646652004-11-05 01:25:55 +00006485 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006486
6487 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6488 continue;
6489 }
6490 if (type == bgp_show_type_filter_list
6491 || type == bgp_show_type_flap_filter_list)
6492 {
ajs5a646652004-11-05 01:25:55 +00006493 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006494
6495 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6496 continue;
6497 }
6498 if (type == bgp_show_type_route_map
6499 || type == bgp_show_type_flap_route_map)
6500 {
ajs5a646652004-11-05 01:25:55 +00006501 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006502 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006503 struct attr dummy_attr;
6504 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006505 int ret;
6506
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006507 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006508 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006509
paul718e3742002-12-13 20:15:29 +00006510 binfo.peer = ri->peer;
6511 binfo.attr = &dummy_attr;
6512
6513 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006514 if (ret == RMAP_DENYMATCH)
6515 continue;
6516 }
6517 if (type == bgp_show_type_neighbor
6518 || type == bgp_show_type_flap_neighbor
6519 || type == bgp_show_type_damp_neighbor)
6520 {
ajs5a646652004-11-05 01:25:55 +00006521 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006522
6523 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6524 continue;
6525 }
6526 if (type == bgp_show_type_cidr_only
6527 || type == bgp_show_type_flap_cidr_only)
6528 {
6529 u_int32_t destination;
6530
6531 destination = ntohl (rn->p.u.prefix4.s_addr);
6532 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6533 continue;
6534 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6535 continue;
6536 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6537 continue;
6538 }
6539 if (type == bgp_show_type_prefix_longer
6540 || type == bgp_show_type_flap_prefix_longer)
6541 {
ajs5a646652004-11-05 01:25:55 +00006542 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006543
6544 if (! prefix_match (p, &rn->p))
6545 continue;
6546 }
6547 if (type == bgp_show_type_community_all)
6548 {
6549 if (! ri->attr->community)
6550 continue;
6551 }
6552 if (type == bgp_show_type_community)
6553 {
ajs5a646652004-11-05 01:25:55 +00006554 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006555
6556 if (! ri->attr->community ||
6557 ! community_match (ri->attr->community, com))
6558 continue;
6559 }
6560 if (type == bgp_show_type_community_exact)
6561 {
ajs5a646652004-11-05 01:25:55 +00006562 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006563
6564 if (! ri->attr->community ||
6565 ! community_cmp (ri->attr->community, com))
6566 continue;
6567 }
6568 if (type == bgp_show_type_community_list)
6569 {
ajs5a646652004-11-05 01:25:55 +00006570 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006571
6572 if (! community_list_match (ri->attr->community, list))
6573 continue;
6574 }
6575 if (type == bgp_show_type_community_list_exact)
6576 {
ajs5a646652004-11-05 01:25:55 +00006577 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006578
6579 if (! community_list_exact_match (ri->attr->community, list))
6580 continue;
6581 }
6582 if (type == bgp_show_type_flap_address
6583 || type == bgp_show_type_flap_prefix)
6584 {
ajs5a646652004-11-05 01:25:55 +00006585 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006586
6587 if (! prefix_match (&rn->p, p))
6588 continue;
6589
6590 if (type == bgp_show_type_flap_prefix)
6591 if (p->prefixlen != rn->p.prefixlen)
6592 continue;
6593 }
6594 if (type == bgp_show_type_dampend_paths
6595 || type == bgp_show_type_damp_neighbor)
6596 {
6597 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6598 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6599 continue;
6600 }
6601
6602 if (header)
6603 {
hasso93406d82005-02-02 14:40:33 +00006604 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6605 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6606 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006607 if (type == bgp_show_type_dampend_paths
6608 || type == bgp_show_type_damp_neighbor)
6609 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6610 else if (type == bgp_show_type_flap_statistics
6611 || type == bgp_show_type_flap_address
6612 || type == bgp_show_type_flap_prefix
6613 || type == bgp_show_type_flap_cidr_only
6614 || type == bgp_show_type_flap_regexp
6615 || type == bgp_show_type_flap_filter_list
6616 || type == bgp_show_type_flap_prefix_list
6617 || type == bgp_show_type_flap_prefix_longer
6618 || type == bgp_show_type_flap_route_map
6619 || type == bgp_show_type_flap_neighbor)
6620 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6621 else
6622 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006623 header = 0;
6624 }
6625
6626 if (type == bgp_show_type_dampend_paths
6627 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006628 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006629 else if (type == bgp_show_type_flap_statistics
6630 || type == bgp_show_type_flap_address
6631 || type == bgp_show_type_flap_prefix
6632 || type == bgp_show_type_flap_cidr_only
6633 || type == bgp_show_type_flap_regexp
6634 || type == bgp_show_type_flap_filter_list
6635 || type == bgp_show_type_flap_prefix_list
6636 || type == bgp_show_type_flap_prefix_longer
6637 || type == bgp_show_type_flap_route_map
6638 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006639 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006640 else
ajs5a646652004-11-05 01:25:55 +00006641 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006642 display++;
6643 }
6644 if (display)
ajs5a646652004-11-05 01:25:55 +00006645 output_count++;
paul718e3742002-12-13 20:15:29 +00006646 }
6647
6648 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006649 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006650 {
6651 if (type == bgp_show_type_normal)
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006652 vty_out (vty, "No BGP prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006653 }
6654 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006655 vty_out (vty, "%sDisplayed %ld out of %ld total prefixes%s",
6656 VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006657
6658 return CMD_SUCCESS;
6659}
6660
ajs5a646652004-11-05 01:25:55 +00006661static int
paulfee0f4c2004-09-13 05:12:46 +00006662bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006663 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006664{
6665 struct bgp_table *table;
6666
6667 if (bgp == NULL) {
6668 bgp = bgp_get_default ();
6669 }
6670
6671 if (bgp == NULL)
6672 {
6673 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6674 return CMD_WARNING;
6675 }
6676
6677
6678 table = bgp->rib[afi][safi];
6679
ajs5a646652004-11-05 01:25:55 +00006680 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006681}
6682
paul718e3742002-12-13 20:15:29 +00006683/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006684static void
paul718e3742002-12-13 20:15:29 +00006685route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6686 struct bgp_node *rn,
6687 struct prefix_rd *prd, afi_t afi, safi_t safi)
6688{
6689 struct bgp_info *ri;
6690 struct prefix *p;
6691 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006692 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006693 char buf1[INET6_ADDRSTRLEN];
6694 char buf2[INET6_ADDRSTRLEN];
6695 int count = 0;
6696 int best = 0;
6697 int suppress = 0;
6698 int no_export = 0;
6699 int no_advertise = 0;
6700 int local_as = 0;
6701 int first = 0;
Lou Berger298cc2f2016-01-12 13:42:02 -05006702 int printrd = ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP));
paul718e3742002-12-13 20:15:29 +00006703
6704 p = &rn->p;
6705 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
Lou Berger298cc2f2016-01-12 13:42:02 -05006706 (printrd ? prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6707 printrd ? ":" : "",
paul718e3742002-12-13 20:15:29 +00006708 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6709 p->prefixlen, VTY_NEWLINE);
6710
6711 for (ri = rn->info; ri; ri = ri->next)
6712 {
6713 count++;
6714 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6715 {
6716 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006717 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006718 suppress = 1;
6719 if (ri->attr->community != NULL)
6720 {
6721 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6722 no_advertise = 1;
6723 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6724 no_export = 1;
6725 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6726 local_as = 1;
6727 }
6728 }
6729 }
6730
6731 vty_out (vty, "Paths: (%d available", count);
6732 if (best)
6733 {
6734 vty_out (vty, ", best #%d", best);
6735 if (safi == SAFI_UNICAST)
6736 vty_out (vty, ", table Default-IP-Routing-Table");
6737 }
6738 else
6739 vty_out (vty, ", no best path");
6740 if (no_advertise)
6741 vty_out (vty, ", not advertised to any peer");
6742 else if (no_export)
6743 vty_out (vty, ", not advertised to EBGP peer");
6744 else if (local_as)
6745 vty_out (vty, ", not advertised outside local AS");
6746 if (suppress)
6747 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6748 vty_out (vty, ")%s", VTY_NEWLINE);
6749
6750 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006751 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006752 {
6753 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6754 {
6755 if (! first)
6756 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6757 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6758 first = 1;
6759 }
6760 }
6761 if (! first)
6762 vty_out (vty, " Not advertised to any peer");
6763 vty_out (vty, "%s", VTY_NEWLINE);
6764}
6765
6766/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006767static int
paulfee0f4c2004-09-13 05:12:46 +00006768bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006769 struct bgp_table *rib, const char *ip_str,
6770 afi_t afi, safi_t safi, struct prefix_rd *prd,
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006771 int prefix_check, enum bgp_path_type pathtype)
paul718e3742002-12-13 20:15:29 +00006772{
6773 int ret;
6774 int header;
6775 int display = 0;
6776 struct prefix match;
6777 struct bgp_node *rn;
6778 struct bgp_node *rm;
6779 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006780 struct bgp_table *table;
6781
Lou Berger050defe2016-01-12 13:41:59 -05006782 memset (&match, 0, sizeof (struct prefix)); /* keep valgrind happy */
paul718e3742002-12-13 20:15:29 +00006783 /* Check IP address argument. */
6784 ret = str2prefix (ip_str, &match);
6785 if (! ret)
6786 {
6787 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6788 return CMD_WARNING;
6789 }
6790
6791 match.family = afi2family (afi);
6792
Lou Berger298cc2f2016-01-12 13:42:02 -05006793 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00006794 {
paulfee0f4c2004-09-13 05:12:46 +00006795 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006796 {
6797 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6798 continue;
6799
6800 if ((table = rn->info) != NULL)
6801 {
6802 header = 1;
6803
6804 if ((rm = bgp_node_match (table, &match)) != NULL)
6805 {
6806 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006807 {
6808 bgp_unlock_node (rm);
6809 continue;
6810 }
paul718e3742002-12-13 20:15:29 +00006811
6812 for (ri = rm->info; ri; ri = ri->next)
6813 {
6814 if (header)
6815 {
6816 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
Lou Berger298cc2f2016-01-12 13:42:02 -05006817 AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00006818
6819 header = 0;
6820 }
6821 display++;
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006822
6823 if (pathtype == BGP_PATH_ALL ||
6824 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
6825 (pathtype == BGP_PATH_MULTIPATH &&
6826 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
6827 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00006828 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006829
6830 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006831 }
6832 }
6833 }
6834 }
6835 else
6836 {
6837 header = 1;
6838
paulfee0f4c2004-09-13 05:12:46 +00006839 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006840 {
6841 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6842 {
6843 for (ri = rn->info; ri; ri = ri->next)
6844 {
6845 if (header)
6846 {
6847 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6848 header = 0;
6849 }
6850 display++;
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006851
6852 if (pathtype == BGP_PATH_ALL ||
6853 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
6854 (pathtype == BGP_PATH_MULTIPATH &&
6855 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
6856 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00006857 }
6858 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006859
6860 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006861 }
6862 }
6863
6864 if (! display)
6865 {
6866 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6867 return CMD_WARNING;
6868 }
6869
6870 return CMD_SUCCESS;
6871}
6872
paulfee0f4c2004-09-13 05:12:46 +00006873/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006874static int
paulfd79ac92004-10-13 05:06:08 +00006875bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006876 afi_t afi, safi_t safi, struct prefix_rd *prd,
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006877 int prefix_check, enum bgp_path_type pathtype)
paulfee0f4c2004-09-13 05:12:46 +00006878{
6879 struct bgp *bgp;
6880
6881 /* BGP structure lookup. */
6882 if (view_name)
6883 {
6884 bgp = bgp_lookup_by_name (view_name);
6885 if (bgp == NULL)
6886 {
6887 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6888 return CMD_WARNING;
6889 }
6890 }
6891 else
6892 {
6893 bgp = bgp_get_default ();
6894 if (bgp == NULL)
6895 {
6896 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6897 return CMD_WARNING;
6898 }
6899 }
6900
6901 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006902 afi, safi, prd, prefix_check, pathtype);
paulfee0f4c2004-09-13 05:12:46 +00006903}
6904
paul718e3742002-12-13 20:15:29 +00006905/* BGP route print out function. */
Lou Bergerf9b6c392016-01-12 13:42:09 -05006906DEFUN (show_ip_bgp,
6907 show_ip_bgp_cmd,
6908 "show ip bgp",
6909 SHOW_STR
6910 IP_STR
6911 BGP_STR)
6912{
6913 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6914}
6915
6916DEFUN (show_ip_bgp_ipv4,
6917 show_ip_bgp_ipv4_cmd,
6918 "show ip bgp ipv4 (unicast|multicast)",
6919 SHOW_STR
6920 IP_STR
6921 BGP_STR
6922 "Address family\n"
6923 "Address Family modifier\n"
6924 "Address Family modifier\n")
6925{
6926 if (strncmp (argv[0], "m", 1) == 0)
6927 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6928 NULL);
6929
6930 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6931}
6932
6933DEFUN (show_ip_bgp_route,
6934 show_ip_bgp_route_cmd,
6935 "show ip bgp A.B.C.D",
6936 SHOW_STR
6937 IP_STR
6938 BGP_STR
6939 "Network in the BGP routing table to display\n")
6940{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006941 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
6942}
6943
6944DEFUN (show_ip_bgp_route_pathtype,
6945 show_ip_bgp_route_pathtype_cmd,
6946 "show ip bgp A.B.C.D (bestpath|multipath)",
6947 SHOW_STR
6948 IP_STR
6949 BGP_STR
6950 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
6951 "Display only the bestpath\n"
6952 "Display only multipaths\n")
6953{
6954 if (strncmp (argv[1], "b", 1) == 0)
6955 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
6956 else
6957 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
6958}
6959
6960DEFUN (show_bgp_ipv4_safi_route_pathtype,
6961 show_bgp_ipv4_safi_route_pathtype_cmd,
6962 "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath)",
6963 SHOW_STR
6964 BGP_STR
6965 "Address family\n"
6966 "Address Family modifier\n"
6967 "Address Family modifier\n"
6968 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
6969 "Display only the bestpath\n"
6970 "Display only multipaths\n")
6971{
6972 if (strncmp (argv[0], "m", 1) == 0)
6973 if (strncmp (argv[2], "b", 1) == 0)
6974 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH);
6975 else
6976 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH);
6977 else
6978 if (strncmp (argv[2], "b", 1) == 0)
6979 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
6980 else
6981 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
Lou Bergerf9b6c392016-01-12 13:42:09 -05006982}
6983
6984DEFUN (show_ip_bgp_ipv4_route,
6985 show_ip_bgp_ipv4_route_cmd,
6986 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6987 SHOW_STR
6988 IP_STR
6989 BGP_STR
6990 "Address family\n"
6991 "Address Family modifier\n"
6992 "Address Family modifier\n"
6993 "Network in the BGP routing table to display\n")
6994{
6995 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006996 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05006997
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006998 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05006999}
7000
7001DEFUN (show_ip_bgp_vpnv4_all_route,
7002 show_ip_bgp_vpnv4_all_route_cmd,
7003 "show ip bgp vpnv4 all A.B.C.D",
7004 SHOW_STR
7005 IP_STR
7006 BGP_STR
7007 "Display VPNv4 NLRI specific information\n"
7008 "Display information about all VPNv4 NLRIs\n"
7009 "Network in the BGP routing table to display\n")
7010{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007011 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007012}
7013
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007014
Lou Bergerf9b6c392016-01-12 13:42:09 -05007015DEFUN (show_ip_bgp_vpnv4_rd_route,
7016 show_ip_bgp_vpnv4_rd_route_cmd,
7017 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
7018 SHOW_STR
7019 IP_STR
7020 BGP_STR
7021 "Display VPNv4 NLRI specific information\n"
7022 "Display information for a route distinguisher\n"
7023 "VPN Route Distinguisher\n"
7024 "Network in the BGP routing table to display\n")
7025{
7026 int ret;
7027 struct prefix_rd prd;
7028
7029 ret = str2prefix_rd (argv[0], &prd);
7030 if (! ret)
7031 {
7032 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7033 return CMD_WARNING;
7034 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007035 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007036}
7037
7038DEFUN (show_ip_bgp_prefix,
7039 show_ip_bgp_prefix_cmd,
7040 "show ip bgp A.B.C.D/M",
7041 SHOW_STR
7042 IP_STR
7043 BGP_STR
7044 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7045{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007046 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7047}
7048
7049DEFUN (show_ip_bgp_prefix_pathtype,
7050 show_ip_bgp_prefix_pathtype_cmd,
7051 "show ip bgp A.B.C.D/M (bestpath|multipath)",
7052 SHOW_STR
7053 IP_STR
7054 BGP_STR
7055 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7056 "Display only the bestpath\n"
7057 "Display only multipaths\n")
7058{
7059 if (strncmp (argv[1], "b", 1) == 0)
7060 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7061 else
7062 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007063}
7064
7065DEFUN (show_ip_bgp_ipv4_prefix,
7066 show_ip_bgp_ipv4_prefix_cmd,
7067 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
7068 SHOW_STR
7069 IP_STR
7070 BGP_STR
7071 "Address family\n"
7072 "Address Family modifier\n"
7073 "Address Family modifier\n"
7074 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7075{
7076 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007077 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007078
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007079 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007080}
7081
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007082DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
7083 show_ip_bgp_ipv4_prefix_pathtype_cmd,
7084 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath)",
7085 SHOW_STR
7086 IP_STR
7087 BGP_STR
7088 "Address family\n"
7089 "Address Family modifier\n"
7090 "Address Family modifier\n"
7091 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7092 "Display only the bestpath\n"
7093 "Display only multipaths\n")
7094{
7095 if (strncmp (argv[0], "m", 1) == 0)
7096 if (strncmp (argv[2], "b", 1) == 0)
7097 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH);
7098 else
7099 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH);
7100 else
7101 if (strncmp (argv[2], "b", 1) == 0)
7102 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7103 else
7104 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
7105}
7106
7107ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
7108 show_bgp_ipv4_safi_prefix_pathtype_cmd,
7109 "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath)",
7110 SHOW_STR
7111 BGP_STR
7112 "Address family\n"
7113 "Address Family modifier\n"
7114 "Address Family modifier\n"
7115 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7116 "Display only the bestpath\n"
7117 "Display only multipaths\n")
7118
Lou Bergerf9b6c392016-01-12 13:42:09 -05007119DEFUN (show_ip_bgp_vpnv4_all_prefix,
7120 show_ip_bgp_vpnv4_all_prefix_cmd,
7121 "show ip bgp vpnv4 all A.B.C.D/M",
7122 SHOW_STR
7123 IP_STR
7124 BGP_STR
7125 "Display VPNv4 NLRI specific information\n"
7126 "Display information about all VPNv4 NLRIs\n"
7127 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7128{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007129 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007130}
7131
7132DEFUN (show_ip_bgp_vpnv4_rd_prefix,
7133 show_ip_bgp_vpnv4_rd_prefix_cmd,
7134 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7135 SHOW_STR
7136 IP_STR
7137 BGP_STR
7138 "Display VPNv4 NLRI specific information\n"
7139 "Display information for a route distinguisher\n"
7140 "VPN Route Distinguisher\n"
7141 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7142{
7143 int ret;
7144 struct prefix_rd prd;
7145
7146 ret = str2prefix_rd (argv[0], &prd);
7147 if (! ret)
7148 {
7149 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7150 return CMD_WARNING;
7151 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007152 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007153}
7154
7155DEFUN (show_ip_bgp_view,
7156 show_ip_bgp_view_cmd,
7157 "show ip bgp view WORD",
7158 SHOW_STR
7159 IP_STR
7160 BGP_STR
7161 "BGP view\n"
7162 "View name\n")
7163{
7164 struct bgp *bgp;
7165
7166 /* BGP structure lookup. */
7167 bgp = bgp_lookup_by_name (argv[0]);
7168 if (bgp == NULL)
7169 {
7170 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7171 return CMD_WARNING;
7172 }
7173
7174 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
7175}
7176
7177DEFUN (show_ip_bgp_view_route,
7178 show_ip_bgp_view_route_cmd,
7179 "show ip bgp view WORD A.B.C.D",
7180 SHOW_STR
7181 IP_STR
7182 BGP_STR
7183 "BGP view\n"
7184 "View name\n"
7185 "Network in the BGP routing table to display\n")
7186{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007187 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007188}
7189
7190DEFUN (show_ip_bgp_view_prefix,
7191 show_ip_bgp_view_prefix_cmd,
7192 "show ip bgp view WORD A.B.C.D/M",
7193 SHOW_STR
7194 IP_STR
7195 BGP_STR
7196 "BGP view\n"
7197 "View name\n"
7198 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7199{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007200 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007201}
7202
7203DEFUN (show_bgp,
7204 show_bgp_cmd,
7205 "show bgp",
7206 SHOW_STR
7207 BGP_STR)
7208{
7209 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7210 NULL);
7211}
7212
7213ALIAS (show_bgp,
7214 show_bgp_ipv6_cmd,
7215 "show bgp ipv6",
7216 SHOW_STR
7217 BGP_STR
7218 "Address family\n")
7219
7220/* old command */
7221DEFUN (show_ipv6_bgp,
7222 show_ipv6_bgp_cmd,
7223 "show ipv6 bgp",
7224 SHOW_STR
7225 IP_STR
7226 BGP_STR)
7227{
7228 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7229 NULL);
7230}
7231
7232DEFUN (show_bgp_route,
7233 show_bgp_route_cmd,
7234 "show bgp X:X::X:X",
7235 SHOW_STR
7236 BGP_STR
7237 "Network in the BGP routing table to display\n")
7238{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007239 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007240}
7241
Lou Berger35c36862016-01-12 13:42:06 -05007242DEFUN (show_bgp_ipv4_safi,
7243 show_bgp_ipv4_safi_cmd,
7244 "show bgp ipv4 (unicast|multicast)",
paul718e3742002-12-13 20:15:29 +00007245 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007246 BGP_STR
7247 "Address family\n"
7248 "Address Family modifier\n"
7249 "Address Family modifier\n")
7250{
7251 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00007252 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
7253 NULL);
paul718e3742002-12-13 20:15:29 +00007254
ajs5a646652004-11-05 01:25:55 +00007255 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00007256}
7257
Lou Berger35c36862016-01-12 13:42:06 -05007258DEFUN (show_bgp_ipv4_safi_route,
7259 show_bgp_ipv4_safi_route_cmd,
7260 "show bgp ipv4 (unicast|multicast) A.B.C.D",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007261 SHOW_STR
7262 BGP_STR
7263 "Address family\n"
7264 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00007265 "Address Family modifier\n"
7266 "Network in the BGP routing table to display\n")
7267{
7268 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007269 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007270
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007271 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7272}
7273
7274DEFUN (show_bgp_route_pathtype,
7275 show_bgp_route_pathtype_cmd,
7276 "show bgp X:X::X:X (bestpath|multipath)",
7277 SHOW_STR
7278 BGP_STR
7279 "Network in the BGP routing table to display\n"
7280 "Display only the bestpath\n"
7281 "Display only multipaths\n")
7282{
7283 if (strncmp (argv[1], "b", 1) == 0)
7284 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
7285 else
7286 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
7287}
7288
7289ALIAS (show_bgp_route_pathtype,
7290 show_bgp_ipv6_route_pathtype_cmd,
7291 "show bgp ipv6 X:X::X:X (bestpath|multipath)",
7292 SHOW_STR
7293 BGP_STR
7294 "Address family\n"
7295 "Network in the BGP routing table to display\n"
7296 "Display only the bestpath\n"
7297 "Display only multipaths\n")
7298
7299DEFUN (show_bgp_ipv6_safi_route_pathtype,
7300 show_bgp_ipv6_safi_route_pathtype_cmd,
7301 "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath)",
7302 SHOW_STR
7303 BGP_STR
7304 "Address family\n"
7305 "Address Family modifier\n"
7306 "Address Family modifier\n"
7307 "Network in the BGP routing table to display\n"
7308 "Display only the bestpath\n"
7309 "Display only multipaths\n")
7310{
7311 if (strncmp (argv[0], "m", 1) == 0)
7312 if (strncmp (argv[2], "b", 1) == 0)
7313 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH);
7314 else
7315 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH);
7316 else
7317 if (strncmp (argv[2], "b", 1) == 0)
7318 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
7319 else
7320 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
paul718e3742002-12-13 20:15:29 +00007321}
7322
Lou Berger35c36862016-01-12 13:42:06 -05007323DEFUN (show_bgp_ipv4_vpn_route,
7324 show_bgp_ipv4_vpn_route_cmd,
7325 "show bgp ipv4 vpn A.B.C.D",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007326 SHOW_STR
7327 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007328 "Address Family\n"
7329 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +00007330 "Network in the BGP routing table to display\n")
7331{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007332 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007333}
7334
Lou Berger35c36862016-01-12 13:42:06 -05007335DEFUN (show_bgp_ipv6_vpn_route,
7336 show_bgp_ipv6_vpn_route_cmd,
7337 "show bgp ipv6 vpn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007338 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007339 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007340 "Address Family\n"
7341 "Display VPN NLRI specific information\n"
7342 "Network in the BGP routing table to display\n")
7343{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007344 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL);
Lou Berger35c36862016-01-12 13:42:06 -05007345}
Lou Berger35c36862016-01-12 13:42:06 -05007346
7347DEFUN (show_bgp_ipv4_vpn_rd_route,
7348 show_bgp_ipv4_vpn_rd_route_cmd,
7349 "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn A.B.C.D",
7350 SHOW_STR
7351 BGP_STR
7352 IP_STR
7353 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +00007354 "Display information for a route distinguisher\n"
7355 "VPN Route Distinguisher\n"
7356 "Network in the BGP routing table to display\n")
7357{
7358 int ret;
7359 struct prefix_rd prd;
7360
7361 ret = str2prefix_rd (argv[0], &prd);
7362 if (! ret)
7363 {
7364 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7365 return CMD_WARNING;
7366 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007367 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007368}
7369
Lou Berger35c36862016-01-12 13:42:06 -05007370DEFUN (show_bgp_ipv6_vpn_rd_route,
7371 show_bgp_ipv6_vpn_rd_route_cmd,
7372 "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007373 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007374 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007375 "Address Family\n"
7376 "Display VPN NLRI specific information\n"
7377 "Display information for a route distinguisher\n"
7378 "VPN Route Distinguisher\n"
7379 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007380{
Lou Berger35c36862016-01-12 13:42:06 -05007381 int ret;
7382 struct prefix_rd prd;
7383
7384 ret = str2prefix_rd (argv[0], &prd);
7385 if (! ret)
7386 {
7387 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7388 return CMD_WARNING;
7389 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007390 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL);
7391}
7392
7393DEFUN (show_bgp_prefix_pathtype,
7394 show_bgp_prefix_pathtype_cmd,
7395 "show bgp X:X::X:X/M (bestpath|multipath)",
7396 SHOW_STR
7397 BGP_STR
7398 "IPv6 prefix <network>/<length>\n"
7399 "Display only the bestpath\n"
7400 "Display only multipaths\n")
7401{
7402 if (strncmp (argv[1], "b", 1) == 0)
7403 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7404 else
7405 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
7406}
7407
7408ALIAS (show_bgp_prefix_pathtype,
7409 show_bgp_ipv6_prefix_pathtype_cmd,
7410 "show bgp ipv6 X:X::X:X/M (bestpath|multipath)",
7411 SHOW_STR
7412 BGP_STR
7413 "Address family\n"
7414 "IPv6 prefix <network>/<length>\n"
7415 "Display only the bestpath\n"
7416 "Display only multipaths\n")
7417
7418DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
7419 show_bgp_ipv6_safi_prefix_pathtype_cmd,
7420 "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath)",
7421 SHOW_STR
7422 BGP_STR
7423 "Address family\n"
7424 "Address Family modifier\n"
7425 "Address Family modifier\n"
7426 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
7427 "Display only the bestpath\n"
7428 "Display only multipaths\n")
7429{
7430 if (strncmp (argv[0], "m", 1) == 0)
7431 if (strncmp (argv[2], "b", 1) == 0)
7432 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH);
7433 else
7434 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH);
7435 else
7436 if (strncmp (argv[2], "b", 1) == 0)
7437 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7438 else
7439 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
paul718e3742002-12-13 20:15:29 +00007440}
7441
Lou Berger651b4022016-01-12 13:42:07 -05007442DEFUN (show_bgp_ipv4_encap_route,
7443 show_bgp_ipv4_encap_route_cmd,
7444 "show bgp ipv4 encap A.B.C.D",
paul718e3742002-12-13 20:15:29 +00007445 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007446 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007447 IP_STR
7448 "Display ENCAP NLRI specific information\n"
7449 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007450{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007451 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007452}
7453
Lou Berger651b4022016-01-12 13:42:07 -05007454DEFUN (show_bgp_ipv6_encap_route,
7455 show_bgp_ipv6_encap_route_cmd,
7456 "show bgp ipv6 encap X:X::X:X",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007457 SHOW_STR
7458 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007459 IP6_STR
7460 "Display ENCAP NLRI specific information\n"
7461 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007462{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007463 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007464}
7465
Lou Berger651b4022016-01-12 13:42:07 -05007466DEFUN (show_bgp_ipv4_safi_rd_route,
7467 show_bgp_ipv4_safi_rd_route_cmd,
7468 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D",
paul718e3742002-12-13 20:15:29 +00007469 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007470 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007471 "Address Family\n"
7472 "Address Family Modifier\n"
7473 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00007474 "Display information for a route distinguisher\n"
Lou Berger651b4022016-01-12 13:42:07 -05007475 "ENCAP Route Distinguisher\n"
7476 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007477{
7478 int ret;
7479 struct prefix_rd prd;
Lou Berger651b4022016-01-12 13:42:07 -05007480 safi_t safi;
paul718e3742002-12-13 20:15:29 +00007481
Lou Berger651b4022016-01-12 13:42:07 -05007482 if (bgp_parse_safi(argv[0], &safi)) {
7483 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7484 return CMD_WARNING;
7485 }
7486 ret = str2prefix_rd (argv[1], &prd);
paul718e3742002-12-13 20:15:29 +00007487 if (! ret)
7488 {
7489 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7490 return CMD_WARNING;
7491 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007492 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007493}
7494
Lou Berger651b4022016-01-12 13:42:07 -05007495DEFUN (show_bgp_ipv6_safi_rd_route,
7496 show_bgp_ipv6_safi_rd_route_cmd,
7497 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007498 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007499 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007500 "Address Family\n"
7501 "Address Family Modifier\n"
7502 "Address Family Modifier\n"
7503 "Display information for a route distinguisher\n"
7504 "ENCAP Route Distinguisher\n"
7505 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007506{
Lou Berger651b4022016-01-12 13:42:07 -05007507 int ret;
7508 struct prefix_rd prd;
7509 safi_t safi;
paulbb46e942003-10-24 19:02:03 +00007510
Lou Berger651b4022016-01-12 13:42:07 -05007511 if (bgp_parse_safi(argv[0], &safi)) {
7512 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7513 return CMD_WARNING;
7514 }
7515 ret = str2prefix_rd (argv[1], &prd);
7516 if (! ret)
7517 {
7518 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7519 return CMD_WARNING;
7520 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007521 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, SAFI_ENCAP, &prd, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007522}
7523
Lou Berger35c36862016-01-12 13:42:06 -05007524DEFUN (show_bgp_ipv4_prefix,
7525 show_bgp_ipv4_prefix_cmd,
7526 "show bgp ipv4 A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007527 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007528 BGP_STR
paul718e3742002-12-13 20:15:29 +00007529 IP_STR
paul718e3742002-12-13 20:15:29 +00007530 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7531{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007532 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007533}
7534
Lou Berger35c36862016-01-12 13:42:06 -05007535DEFUN (show_bgp_ipv4_safi_prefix,
7536 show_bgp_ipv4_safi_prefix_cmd,
7537 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007538 SHOW_STR
7539 BGP_STR
7540 "Address family\n"
7541 "Address Family modifier\n"
Lou Berger35c36862016-01-12 13:42:06 -05007542 "Address Family modifier\n"
7543 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007544{
7545 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007546 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007547
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007548 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007549}
7550
Lou Berger35c36862016-01-12 13:42:06 -05007551DEFUN (show_bgp_ipv4_vpn_prefix,
7552 show_bgp_ipv4_vpn_prefix_cmd,
7553 "show bgp ipv4 vpn A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007554 SHOW_STR
7555 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007556 IP_STR
7557 "Display VPN NLRI specific information\n"
7558 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paul718e3742002-12-13 20:15:29 +00007559{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007560 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007561}
7562
Lou Berger35c36862016-01-12 13:42:06 -05007563DEFUN (show_bgp_ipv6_vpn_prefix,
7564 show_bgp_ipv6_vpn_prefix_cmd,
7565 "show bgp ipv6 vpn X:X::X:X/M",
7566 SHOW_STR
7567 BGP_STR
7568 "Address Family\n"
7569 "Display VPN NLRI specific information\n"
7570 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7571{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007572 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL);
Lou Berger35c36862016-01-12 13:42:06 -05007573}
Lou Berger35c36862016-01-12 13:42:06 -05007574
Lou Berger651b4022016-01-12 13:42:07 -05007575DEFUN (show_bgp_ipv4_encap_prefix,
7576 show_bgp_ipv4_encap_prefix_cmd,
7577 "show bgp ipv4 encap A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007578 SHOW_STR
7579 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007580 IP_STR
7581 "Display ENCAP NLRI specific information\n"
7582 "Display information about ENCAP NLRIs\n"
7583 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7584{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007585 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007586}
paul718e3742002-12-13 20:15:29 +00007587
Lou Berger651b4022016-01-12 13:42:07 -05007588DEFUN (show_bgp_ipv6_encap_prefix,
7589 show_bgp_ipv6_encap_prefix_cmd,
7590 "show bgp ipv6 encap X:X::X:X/M",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007591 SHOW_STR
7592 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007593 IP_STR
7594 "Display ENCAP NLRI specific information\n"
7595 "Display information about ENCAP NLRIs\n"
7596 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7597{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007598 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007599}
Lou Berger651b4022016-01-12 13:42:07 -05007600
7601DEFUN (show_bgp_ipv4_safi_rd_prefix,
7602 show_bgp_ipv4_safi_rd_prefix_cmd,
7603 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7604 SHOW_STR
7605 BGP_STR
7606 "Address Family\n"
7607 "Address Family Modifier\n"
7608 "Address Family Modifier\n"
7609 "Display information for a route distinguisher\n"
7610 "ENCAP Route Distinguisher\n"
7611 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7612{
7613 int ret;
7614 struct prefix_rd prd;
7615 safi_t safi;
7616
7617 if (bgp_parse_safi(argv[0], &safi)) {
7618 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7619 return CMD_WARNING;
7620 }
7621
7622 ret = str2prefix_rd (argv[1], &prd);
7623 if (! ret)
7624 {
7625 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7626 return CMD_WARNING;
7627 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007628 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007629}
7630
Lou Berger651b4022016-01-12 13:42:07 -05007631DEFUN (show_bgp_ipv6_safi_rd_prefix,
7632 show_bgp_ipv6_safi_rd_prefix_cmd,
7633 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X/M",
7634 SHOW_STR
7635 BGP_STR
7636 "Address Family\n"
7637 "Address Family Modifier\n"
7638 "Address Family Modifier\n"
7639 "Display information for a route distinguisher\n"
7640 "ENCAP Route Distinguisher\n"
7641 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7642{
7643 int ret;
7644 struct prefix_rd prd;
7645 safi_t safi;
7646
7647 if (bgp_parse_safi(argv[0], &safi)) {
7648 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7649 return CMD_WARNING;
7650 }
7651
7652 ret = str2prefix_rd (argv[1], &prd);
7653 if (! ret)
7654 {
7655 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7656 return CMD_WARNING;
7657 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007658 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, safi, &prd, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007659}
Lou Berger651b4022016-01-12 13:42:07 -05007660
7661DEFUN (show_bgp_afi_safi_view,
7662 show_bgp_afi_safi_view_cmd,
7663 "show bgp view WORD (ipv4|ipv6) (encap|mulicast|unicast|vpn)",
7664 SHOW_STR
7665 BGP_STR
7666 "BGP view\n"
7667 "BGP view name\n"
7668 "Address Family\n"
7669 "Address Family\n"
7670 "Address Family Modifier\n"
7671 "Address Family Modifier\n"
7672 "Address Family Modifier\n"
7673 "Address Family Modifier\n"
7674 )
7675{
7676 struct bgp *bgp;
7677 safi_t safi;
7678 afi_t afi;
7679
7680 if (bgp_parse_afi(argv[1], &afi)) {
7681 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7682 return CMD_WARNING;
7683 }
7684 if (bgp_parse_safi(argv[2], &safi)) {
7685 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7686 return CMD_WARNING;
7687 }
7688
7689 /* BGP structure lookup. */
7690 bgp = bgp_lookup_by_name (argv[0]);
7691 if (bgp == NULL)
7692 {
7693 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7694 return CMD_WARNING;
7695 }
7696
7697 return bgp_show (vty, bgp, afi, safi, bgp_show_type_normal, NULL);
7698}
7699
7700DEFUN (show_bgp_view_afi_safi_route,
7701 show_bgp_view_afi_safi_route_cmd,
7702 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) A.B.C.D",
7703 SHOW_STR
7704 BGP_STR
7705 "BGP view\n"
7706 "View name\n"
7707 "Address Family\n"
7708 "Address Family\n"
7709 "Address Family Modifier\n"
7710 "Address Family Modifier\n"
7711 "Address Family Modifier\n"
7712 "Address Family Modifier\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007713 "Network in the BGP routing table to display\n")
7714{
Lou Berger651b4022016-01-12 13:42:07 -05007715 safi_t safi;
7716 afi_t afi;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007717
Lou Berger651b4022016-01-12 13:42:07 -05007718 if (bgp_parse_afi(argv[1], &afi)) {
7719 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7720 return CMD_WARNING;
7721 }
7722 if (bgp_parse_safi(argv[2], &safi)) {
7723 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7724 return CMD_WARNING;
7725 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007726 return bgp_show_route (vty, argv[0], argv[3], afi, safi, NULL, 0, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007727}
7728
7729DEFUN (show_bgp_view_afi_safi_prefix,
7730 show_bgp_view_afi_safi_prefix_cmd,
7731 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) A.B.C.D/M",
7732 SHOW_STR
7733 BGP_STR
7734 "BGP view\n"
7735 "View name\n"
7736 "Address Family\n"
7737 "Address Family\n"
7738 "Address Family Modifier\n"
7739 "Address Family Modifier\n"
7740 "Address Family Modifier\n"
7741 "Address Family Modifier\n"
7742 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7743{
7744 safi_t safi;
7745 afi_t afi;
7746
7747 if (bgp_parse_afi(argv[1], &afi)) {
7748 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7749 return CMD_WARNING;
7750 }
7751 if (bgp_parse_safi(argv[2], &safi)) {
7752 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7753 return CMD_WARNING;
7754 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007755 return bgp_show_route (vty, argv[0], argv[3], afi, safi, NULL, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007756}
7757
7758/* new001 */
7759DEFUN (show_bgp_afi,
7760 show_bgp_afi_cmd,
7761 "show bgp (ipv4|ipv6)",
7762 SHOW_STR
7763 BGP_STR
7764 "Address family\n"
7765 "Address family\n")
7766{
7767 afi_t afi;
7768
7769 if (bgp_parse_afi(argv[0], &afi)) {
7770 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7771 return CMD_WARNING;
7772 }
7773 return bgp_show (vty, NULL, afi, SAFI_UNICAST, bgp_show_type_normal,
7774 NULL);
7775}
7776
Lou Berger651b4022016-01-12 13:42:07 -05007777DEFUN (show_bgp_ipv6_safi,
7778 show_bgp_ipv6_safi_cmd,
7779 "show bgp ipv6 (unicast|multicast)",
7780 SHOW_STR
7781 BGP_STR
7782 "Address family\n"
7783 "Address Family modifier\n"
7784 "Address Family modifier\n")
7785{
7786 if (strncmp (argv[0], "m", 1) == 0)
7787 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7788 NULL);
7789
7790 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007791}
7792
Lou Berger35c36862016-01-12 13:42:06 -05007793DEFUN (show_bgp_ipv6_route,
7794 show_bgp_ipv6_route_cmd,
7795 "show bgp ipv6 X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007796 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007797 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007798 "Address family\n"
paul718e3742002-12-13 20:15:29 +00007799 "Network in the BGP routing table to display\n")
7800{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007801 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007802}
7803
Lou Berger35c36862016-01-12 13:42:06 -05007804DEFUN (show_bgp_ipv6_safi_route,
7805 show_bgp_ipv6_safi_route_cmd,
7806 "show bgp ipv6 (unicast|multicast) X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007807 SHOW_STR
7808 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007809 "Address family\n"
7810 "Address Family modifier\n"
7811 "Address Family modifier\n"
7812 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007813{
Lou Berger35c36862016-01-12 13:42:06 -05007814 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007815 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
Lou Berger35c36862016-01-12 13:42:06 -05007816
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007817 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007818}
7819
Lou Bergerf9b6c392016-01-12 13:42:09 -05007820/* old command */
7821DEFUN (show_ipv6_bgp_route,
7822 show_ipv6_bgp_route_cmd,
7823 "show ipv6 bgp X:X::X:X",
7824 SHOW_STR
7825 IP_STR
7826 BGP_STR
7827 "Network in the BGP routing table to display\n")
7828{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007829 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007830}
7831
7832DEFUN (show_bgp_prefix,
7833 show_bgp_prefix_cmd,
7834 "show bgp X:X::X:X/M",
7835 SHOW_STR
7836 BGP_STR
7837 "IPv6 prefix <network>/<length>\n")
7838{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007839 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007840}
7841
7842
Lou Berger35c36862016-01-12 13:42:06 -05007843/* new002 */
7844DEFUN (show_bgp_ipv6_prefix,
paul718e3742002-12-13 20:15:29 +00007845 show_bgp_ipv6_prefix_cmd,
7846 "show bgp ipv6 X:X::X:X/M",
7847 SHOW_STR
7848 BGP_STR
7849 "Address family\n"
Lou Berger35c36862016-01-12 13:42:06 -05007850 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7851{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007852 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Berger35c36862016-01-12 13:42:06 -05007853}
Michael Lambert95cbbd22010-07-23 14:43:04 -04007854DEFUN (show_bgp_ipv6_safi_prefix,
7855 show_bgp_ipv6_safi_prefix_cmd,
7856 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
7857 SHOW_STR
7858 BGP_STR
7859 "Address family\n"
7860 "Address Family modifier\n"
7861 "Address Family modifier\n"
7862 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7863{
7864 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007865 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007866
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007867 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007868}
7869
Lou Bergerf9b6c392016-01-12 13:42:09 -05007870/* old command */
7871DEFUN (show_ipv6_bgp_prefix,
7872 show_ipv6_bgp_prefix_cmd,
7873 "show ipv6 bgp X:X::X:X/M",
7874 SHOW_STR
7875 IP_STR
7876 BGP_STR
7877 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7878{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007879 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007880}
7881
paulbb46e942003-10-24 19:02:03 +00007882DEFUN (show_bgp_view,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007883 show_bgp_view_cmd,
7884 "show bgp view WORD",
7885 SHOW_STR
7886 BGP_STR
7887 "BGP view\n"
7888 "View name\n")
7889{
7890 struct bgp *bgp;
7891
7892 /* BGP structure lookup. */
7893 bgp = bgp_lookup_by_name (argv[0]);
7894 if (bgp == NULL)
7895 {
7896 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7897 return CMD_WARNING;
7898 }
7899
7900 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
7901}
7902
7903DEFUN (show_bgp_view_ipv6,
Lou Berger35c36862016-01-12 13:42:06 -05007904 show_bgp_view_ipv6_cmd,
7905 "show bgp view WORD ipv6",
paulbb46e942003-10-24 19:02:03 +00007906 SHOW_STR
Lou Berger35c36862016-01-12 13:42:06 -05007907 BGP_STR
paulbb46e942003-10-24 19:02:03 +00007908 "BGP view\n"
Lou Berger35c36862016-01-12 13:42:06 -05007909 "View name\n"
7910 "Address family\n")
paulbb46e942003-10-24 19:02:03 +00007911{
7912 struct bgp *bgp;
7913
7914 /* BGP structure lookup. */
7915 bgp = bgp_lookup_by_name (argv[0]);
7916 if (bgp == NULL)
7917 {
7918 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7919 return CMD_WARNING;
7920 }
7921
ajs5a646652004-11-05 01:25:55 +00007922 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007923}
paulbb46e942003-10-24 19:02:03 +00007924
7925DEFUN (show_bgp_view_route,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007926 show_bgp_view_route_cmd,
7927 "show bgp view WORD X:X::X:X",
7928 SHOW_STR
7929 BGP_STR
7930 "BGP view\n"
7931 "View name\n"
7932 "Network in the BGP routing table to display\n")
7933{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007934 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007935}
7936
7937DEFUN (show_bgp_view_ipv6_route,
paulbb46e942003-10-24 19:02:03 +00007938 show_bgp_view_ipv6_route_cmd,
7939 "show bgp view WORD ipv6 X:X::X:X",
7940 SHOW_STR
7941 BGP_STR
7942 "BGP view\n"
7943 "View name\n"
7944 "Address family\n"
7945 "Network in the BGP routing table to display\n")
paulbb46e942003-10-24 19:02:03 +00007946{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007947 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
paulbb46e942003-10-24 19:02:03 +00007948}
7949
Lou Bergerf9b6c392016-01-12 13:42:09 -05007950/* old command */
7951DEFUN (show_ipv6_mbgp,
7952 show_ipv6_mbgp_cmd,
7953 "show ipv6 mbgp",
7954 SHOW_STR
7955 IP_STR
7956 MBGP_STR)
7957{
7958 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7959 NULL);
7960}
7961
7962/* old command */
7963DEFUN (show_ipv6_mbgp_route,
7964 show_ipv6_mbgp_route_cmd,
7965 "show ipv6 mbgp X:X::X:X",
7966 SHOW_STR
7967 IP_STR
7968 MBGP_STR
7969 "Network in the MBGP routing table to display\n")
7970{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007971 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007972}
7973
7974/* old command */
7975DEFUN (show_ipv6_mbgp_prefix,
7976 show_ipv6_mbgp_prefix_cmd,
7977 "show ipv6 mbgp X:X::X:X/M",
7978 SHOW_STR
7979 IP_STR
7980 MBGP_STR
7981 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7982{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007983 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007984}
7985
Lou Berger35c36862016-01-12 13:42:06 -05007986DEFUN (show_bgp_view_prefix,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007987 show_bgp_view_prefix_cmd,
7988 "show bgp view WORD X:X::X:X/M",
7989 SHOW_STR
7990 BGP_STR
7991 "BGP view\n"
7992 "View name\n"
7993 "IPv6 prefix <network>/<length>\n")
7994{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007995 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007996}
7997
7998DEFUN (show_bgp_view_ipv6_prefix,
paulbb46e942003-10-24 19:02:03 +00007999 show_bgp_view_ipv6_prefix_cmd,
8000 "show bgp view WORD ipv6 X:X::X:X/M",
8001 SHOW_STR
8002 BGP_STR
8003 "BGP view\n"
8004 "View name\n"
8005 "Address family\n"
8006 "IPv6 prefix <network>/<length>\n")
paul718e3742002-12-13 20:15:29 +00008007{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07008008 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00008009}
8010
paul94f2b392005-06-28 12:44:16 +00008011static int
paulfd79ac92004-10-13 05:06:08 +00008012bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008013 safi_t safi, enum bgp_show_type type)
8014{
8015 int i;
8016 struct buffer *b;
8017 char *regstr;
8018 int first;
8019 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00008020 int rc;
paul718e3742002-12-13 20:15:29 +00008021
8022 first = 0;
8023 b = buffer_new (1024);
8024 for (i = 0; i < argc; i++)
8025 {
8026 if (first)
8027 buffer_putc (b, ' ');
8028 else
8029 {
8030 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8031 continue;
8032 first = 1;
8033 }
8034
8035 buffer_putstr (b, argv[i]);
8036 }
8037 buffer_putc (b, '\0');
8038
8039 regstr = buffer_getstr (b);
8040 buffer_free (b);
8041
8042 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00008043 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00008044 if (! regex)
8045 {
8046 vty_out (vty, "Can't compile regexp %s%s", argv[0],
8047 VTY_NEWLINE);
8048 return CMD_WARNING;
8049 }
8050
ajs5a646652004-11-05 01:25:55 +00008051 rc = bgp_show (vty, NULL, afi, safi, type, regex);
8052 bgp_regex_free (regex);
8053 return rc;
paul718e3742002-12-13 20:15:29 +00008054}
8055
Lou Bergerf9b6c392016-01-12 13:42:09 -05008056
8057DEFUN (show_ip_bgp_regexp,
8058 show_ip_bgp_regexp_cmd,
8059 "show ip bgp regexp .LINE",
8060 SHOW_STR
8061 IP_STR
8062 BGP_STR
8063 "Display routes matching the AS path regular expression\n"
8064 "A regular-expression to match the BGP AS paths\n")
8065{
8066 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8067 bgp_show_type_regexp);
8068}
8069
8070DEFUN (show_ip_bgp_flap_regexp,
8071 show_ip_bgp_flap_regexp_cmd,
8072 "show ip bgp flap-statistics regexp .LINE",
8073 SHOW_STR
8074 IP_STR
8075 BGP_STR
8076 "Display flap statistics of routes\n"
8077 "Display routes matching the AS path regular expression\n"
8078 "A regular-expression to match the BGP AS paths\n")
8079{
8080 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8081 bgp_show_type_flap_regexp);
8082}
8083
8084ALIAS (show_ip_bgp_flap_regexp,
8085 show_ip_bgp_damp_flap_regexp_cmd,
8086 "show ip bgp dampening flap-statistics regexp .LINE",
8087 SHOW_STR
8088 IP_STR
8089 BGP_STR
8090 "Display detailed information about dampening\n"
8091 "Display flap statistics of routes\n"
8092 "Display routes matching the AS path regular expression\n"
8093 "A regular-expression to match the BGP AS paths\n")
8094
8095DEFUN (show_ip_bgp_ipv4_regexp,
8096 show_ip_bgp_ipv4_regexp_cmd,
8097 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
8098 SHOW_STR
8099 IP_STR
8100 BGP_STR
8101 "Address family\n"
8102 "Address Family modifier\n"
8103 "Address Family modifier\n"
8104 "Display routes matching the AS path regular expression\n"
8105 "A regular-expression to match the BGP AS paths\n")
8106{
8107 if (strncmp (argv[0], "m", 1) == 0)
8108 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
8109 bgp_show_type_regexp);
8110
8111 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8112 bgp_show_type_regexp);
8113}
8114
Lou Bergerf9b6c392016-01-12 13:42:09 -05008115DEFUN (show_bgp_regexp,
8116 show_bgp_regexp_cmd,
8117 "show bgp regexp .LINE",
8118 SHOW_STR
8119 BGP_STR
8120 "Display routes matching the AS path regular expression\n"
8121 "A regular-expression to match the BGP AS paths\n")
8122{
8123 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8124 bgp_show_type_regexp);
8125}
8126
8127/* old command */
8128DEFUN (show_ipv6_bgp_regexp,
8129 show_ipv6_bgp_regexp_cmd,
8130 "show ipv6 bgp regexp .LINE",
8131 SHOW_STR
8132 IP_STR
8133 BGP_STR
8134 "Display routes matching the AS path regular expression\n"
8135 "A regular-expression to match the BGP AS paths\n")
8136{
8137 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8138 bgp_show_type_regexp);
8139}
8140
8141/* old command */
8142DEFUN (show_ipv6_mbgp_regexp,
8143 show_ipv6_mbgp_regexp_cmd,
8144 "show ipv6 mbgp regexp .LINE",
8145 SHOW_STR
8146 IP_STR
8147 BGP_STR
8148 "Display routes matching the AS path regular expression\n"
8149 "A regular-expression to match the MBGP AS paths\n")
8150{
8151 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
8152 bgp_show_type_regexp);
8153}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008154
Lou Berger651b4022016-01-12 13:42:07 -05008155DEFUN (show_bgp_ipv4_safi_flap_regexp,
8156 show_bgp_ipv4_safi_flap_regexp_cmd,
8157 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics regexp .LINE",
paul718e3742002-12-13 20:15:29 +00008158 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008159 BGP_STR
paul718e3742002-12-13 20:15:29 +00008160 IP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008161 "Address Family Modifier\n"
8162 "Address Family Modifier\n"
8163 "Address Family Modifier\n"
8164 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00008165 "Display flap statistics of routes\n"
8166 "Display routes matching the AS path regular expression\n"
8167 "A regular-expression to match the BGP AS paths\n")
8168{
Lou Berger651b4022016-01-12 13:42:07 -05008169 safi_t safi;
8170
8171 if (bgp_parse_safi(argv[0], &safi)) {
8172 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
8173 return CMD_WARNING;
8174 }
8175 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP, safi,
8176 bgp_show_type_flap_regexp);
paul718e3742002-12-13 20:15:29 +00008177}
8178
Lou Berger651b4022016-01-12 13:42:07 -05008179ALIAS (show_bgp_ipv4_safi_flap_regexp,
8180 show_bgp_ipv4_safi_damp_flap_regexp_cmd,
8181 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics regexp .LINE",
Balaji3921cc52015-05-16 23:12:17 +05308182 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308183 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008184 IP_STR
8185 "Address Family Modifier\n"
8186 "Address Family Modifier\n"
8187 "Address Family Modifier\n"
8188 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308189 "Display detailed information about dampening\n"
8190 "Display flap statistics of routes\n"
8191 "Display routes matching the AS path regular expression\n"
8192 "A regular-expression to match the BGP AS paths\n")
8193
Lou Berger651b4022016-01-12 13:42:07 -05008194DEFUN (show_bgp_ipv6_safi_flap_regexp,
8195 show_bgp_ipv6_safi_flap_regexp_cmd,
8196 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics regexp .LINE",
paul718e3742002-12-13 20:15:29 +00008197 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05008198 BGP_STR
8199 IPV6_STR
8200 "Address Family Modifier\n"
8201 "Address Family Modifier\n"
8202 "Address Family Modifier\n"
8203 "Address Family Modifier\n"
8204 "Display flap statistics of routes\n"
8205 "Display routes matching the AS path regular expression\n"
8206 "A regular-expression to match the BGP AS paths\n")
8207{
8208 safi_t safi;
8209
8210 if (bgp_parse_safi(argv[0], &safi)) {
8211 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
8212 return CMD_WARNING;
8213 }
8214 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP6, safi,
8215 bgp_show_type_flap_regexp);
8216}
8217
8218ALIAS (show_bgp_ipv6_safi_flap_regexp,
8219 show_bgp_ipv6_safi_damp_flap_regexp_cmd,
8220 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics regexp .LINE",
8221 SHOW_STR
8222 BGP_STR
8223 IPV6_STR
8224 "Address Family Modifier\n"
8225 "Address Family Modifier\n"
8226 "Address Family Modifier\n"
8227 "Address Family Modifier\n"
8228 "Display detailed information about dampening\n"
8229 "Display flap statistics of routes\n"
8230 "Display routes matching the AS path regular expression\n"
8231 "A regular-expression to match the BGP AS paths\n")
Lou Berger651b4022016-01-12 13:42:07 -05008232
8233DEFUN (show_bgp_ipv4_safi_regexp,
8234 show_bgp_ipv4_safi_regexp_cmd,
8235 "show bgp ipv4 (encap|multicast|unicast|vpn) regexp .LINE",
8236 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008237 BGP_STR
8238 "Address family\n"
8239 "Address Family modifier\n"
8240 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05008241 "Address Family modifier\n"
8242 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008243 "Display routes matching the AS path regular expression\n"
8244 "A regular-expression to match the BGP AS paths\n")
8245{
Lou Berger651b4022016-01-12 13:42:07 -05008246 safi_t safi;
8247 if (bgp_parse_safi(argv[0], &safi)) {
8248 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8249 return CMD_WARNING;
8250 }
paul718e3742002-12-13 20:15:29 +00008251
Lou Berger651b4022016-01-12 13:42:07 -05008252 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008253 bgp_show_type_regexp);
8254}
Lou Berger205e6742016-01-12 13:42:11 -05008255
Lou Berger651b4022016-01-12 13:42:07 -05008256DEFUN (show_bgp_ipv6_safi_regexp,
8257 show_bgp_ipv6_safi_regexp_cmd,
8258 "show bgp ipv6 (encap|multicast|unicast|vpn) regexp .LINE",
paul718e3742002-12-13 20:15:29 +00008259 SHOW_STR
8260 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008261 "Address family\n"
8262 "Address Family modifier\n"
8263 "Address Family modifier\n"
8264 "Address Family modifier\n"
8265 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008266 "Display routes matching the AS path regular expression\n"
8267 "A regular-expression to match the BGP AS paths\n")
8268{
Lou Berger651b4022016-01-12 13:42:07 -05008269 safi_t safi;
8270 if (bgp_parse_safi(argv[0], &safi)) {
8271 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8272 return CMD_WARNING;
8273 }
8274
8275 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00008276 bgp_show_type_regexp);
8277}
8278
Lou Berger651b4022016-01-12 13:42:07 -05008279DEFUN (show_bgp_ipv6_regexp,
paul718e3742002-12-13 20:15:29 +00008280 show_bgp_ipv6_regexp_cmd,
8281 "show bgp ipv6 regexp .LINE",
8282 SHOW_STR
8283 BGP_STR
8284 "Address family\n"
8285 "Display routes matching the AS path regular expression\n"
8286 "A regular-expression to match the BGP AS paths\n")
paul718e3742002-12-13 20:15:29 +00008287{
8288 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8289 bgp_show_type_regexp);
8290}
8291
paul94f2b392005-06-28 12:44:16 +00008292static int
paulfd79ac92004-10-13 05:06:08 +00008293bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008294 safi_t safi, enum bgp_show_type type)
8295{
8296 struct prefix_list *plist;
8297
8298 plist = prefix_list_lookup (afi, prefix_list_str);
8299 if (plist == NULL)
8300 {
8301 vty_out (vty, "%% %s is not a valid prefix-list name%s",
8302 prefix_list_str, VTY_NEWLINE);
8303 return CMD_WARNING;
8304 }
8305
ajs5a646652004-11-05 01:25:55 +00008306 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00008307}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008308DEFUN (show_ip_bgp_prefix_list,
8309 show_ip_bgp_prefix_list_cmd,
8310 "show ip bgp prefix-list WORD",
8311 SHOW_STR
8312 IP_STR
8313 BGP_STR
8314 "Display routes conforming to the prefix-list\n"
8315 "IP prefix-list name\n")
8316{
8317 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8318 bgp_show_type_prefix_list);
8319}
8320
8321DEFUN (show_ip_bgp_flap_prefix_list,
8322 show_ip_bgp_flap_prefix_list_cmd,
8323 "show ip bgp flap-statistics prefix-list WORD",
8324 SHOW_STR
8325 IP_STR
8326 BGP_STR
8327 "Display flap statistics of routes\n"
8328 "Display routes conforming to the prefix-list\n"
8329 "IP prefix-list name\n")
8330{
8331 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8332 bgp_show_type_flap_prefix_list);
8333}
8334
8335ALIAS (show_ip_bgp_flap_prefix_list,
8336 show_ip_bgp_damp_flap_prefix_list_cmd,
8337 "show ip bgp dampening flap-statistics prefix-list WORD",
8338 SHOW_STR
8339 IP_STR
8340 BGP_STR
8341 "Display detailed information about dampening\n"
8342 "Display flap statistics of routes\n"
8343 "Display routes conforming to the prefix-list\n"
8344 "IP prefix-list name\n")
8345
8346DEFUN (show_ip_bgp_ipv4_prefix_list,
8347 show_ip_bgp_ipv4_prefix_list_cmd,
8348 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
8349 SHOW_STR
8350 IP_STR
8351 BGP_STR
8352 "Address family\n"
8353 "Address Family modifier\n"
8354 "Address Family modifier\n"
8355 "Display routes conforming to the prefix-list\n"
8356 "IP prefix-list name\n")
8357{
8358 if (strncmp (argv[0], "m", 1) == 0)
8359 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8360 bgp_show_type_prefix_list);
8361
8362 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8363 bgp_show_type_prefix_list);
8364}
8365
Lou Bergerf9b6c392016-01-12 13:42:09 -05008366DEFUN (show_bgp_prefix_list,
8367 show_bgp_prefix_list_cmd,
8368 "show bgp prefix-list WORD",
8369 SHOW_STR
8370 BGP_STR
8371 "Display routes conforming to the prefix-list\n"
8372 "IPv6 prefix-list name\n")
8373{
8374 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8375 bgp_show_type_prefix_list);
8376}
8377
8378ALIAS (show_bgp_prefix_list,
8379 show_bgp_ipv6_prefix_list_cmd,
8380 "show bgp ipv6 prefix-list WORD",
8381 SHOW_STR
8382 BGP_STR
8383 "Address family\n"
8384 "Display routes conforming to the prefix-list\n"
8385 "IPv6 prefix-list name\n")
8386
8387/* old command */
8388DEFUN (show_ipv6_bgp_prefix_list,
8389 show_ipv6_bgp_prefix_list_cmd,
8390 "show ipv6 bgp prefix-list WORD",
8391 SHOW_STR
8392 IPV6_STR
8393 BGP_STR
8394 "Display routes matching the prefix-list\n"
8395 "IPv6 prefix-list name\n")
8396{
8397 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8398 bgp_show_type_prefix_list);
8399}
8400
8401/* old command */
8402DEFUN (show_ipv6_mbgp_prefix_list,
8403 show_ipv6_mbgp_prefix_list_cmd,
8404 "show ipv6 mbgp prefix-list WORD",
8405 SHOW_STR
8406 IPV6_STR
8407 MBGP_STR
8408 "Display routes matching the prefix-list\n"
8409 "IPv6 prefix-list name\n")
8410{
8411 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8412 bgp_show_type_prefix_list);
8413}
paul718e3742002-12-13 20:15:29 +00008414
Lou Berger35c36862016-01-12 13:42:06 -05008415DEFUN (show_bgp_ipv4_prefix_list,
8416 show_bgp_ipv4_prefix_list_cmd,
8417 "show bgp ipv4 prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008418 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008419 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05008420 IP_STR
paul718e3742002-12-13 20:15:29 +00008421 "Display routes conforming to the prefix-list\n"
8422 "IP prefix-list name\n")
8423{
8424 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8425 bgp_show_type_prefix_list);
8426}
8427
Lou Berger651b4022016-01-12 13:42:07 -05008428DEFUN (show_bgp_ipv4_safi_flap_prefix_list,
8429 show_bgp_ipv4_safi_flap_prefix_list_cmd,
8430 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008431 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008432 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008433 IP_STR
8434 "Address Family Modifier\n"
8435 "Address Family Modifier\n"
8436 "Address Family Modifier\n"
8437 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00008438 "Display flap statistics of routes\n"
8439 "Display routes conforming to the prefix-list\n"
8440 "IP prefix-list name\n")
8441{
Lou Berger651b4022016-01-12 13:42:07 -05008442 safi_t safi;
8443 if (bgp_parse_safi(argv[0], &safi)) {
8444 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8445 return CMD_WARNING;
8446 }
8447 return bgp_show_prefix_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008448 bgp_show_type_flap_prefix_list);
8449}
8450
Lou Berger651b4022016-01-12 13:42:07 -05008451ALIAS (show_bgp_ipv4_safi_flap_prefix_list,
8452 show_bgp_ipv4_safi_damp_flap_prefix_list_cmd,
8453 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics prefix-list WORD",
Balaji3921cc52015-05-16 23:12:17 +05308454 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308455 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008456 IP_STR
8457 "Address Family Modifier\n"
8458 "Address Family Modifier\n"
8459 "Address Family Modifier\n"
8460 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308461 "Display detailed information about dampening\n"
8462 "Display flap statistics of routes\n"
8463 "Display routes conforming to the prefix-list\n"
8464 "IP prefix-list name\n")
8465
Lou Berger651b4022016-01-12 13:42:07 -05008466DEFUN (show_bgp_ipv6_safi_flap_prefix_list,
8467 show_bgp_ipv6_safi_flap_prefix_list_cmd,
8468 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008469 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05008470 BGP_STR
8471 IPV6_STR
8472 "Address Family Modifier\n"
8473 "Address Family Modifier\n"
8474 "Address Family Modifier\n"
8475 "Address Family Modifier\n"
8476 "Display flap statistics of routes\n"
8477 "Display routes conforming to the prefix-list\n"
8478 "IP prefix-list name\n")
8479{
8480 safi_t safi;
8481 if (bgp_parse_safi(argv[0], &safi)) {
8482 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8483 return CMD_WARNING;
8484 }
8485 return bgp_show_prefix_list (vty, argv[1], AFI_IP6, safi,
8486 bgp_show_type_flap_prefix_list);
8487}
8488ALIAS (show_bgp_ipv6_safi_flap_prefix_list,
8489 show_bgp_ipv6_safi_damp_flap_prefix_list_cmd,
8490 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics prefix-list WORD",
8491 SHOW_STR
8492 BGP_STR
8493 IPV6_STR
8494 "Address Family Modifier\n"
8495 "Address Family Modifier\n"
8496 "Address Family Modifier\n"
8497 "Address Family Modifier\n"
8498 "Display detailed information about dampening\n"
8499 "Display flap statistics of routes\n"
8500 "Display routes conforming to the prefix-list\n"
8501 "IP prefix-list name\n")
Lou Berger651b4022016-01-12 13:42:07 -05008502
8503DEFUN (show_bgp_ipv4_safi_prefix_list,
8504 show_bgp_ipv4_safi_prefix_list_cmd,
8505 "show bgp ipv4 (encap|multicast|unicast|vpn) prefix-list WORD",
8506 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008507 BGP_STR
8508 "Address family\n"
8509 "Address Family modifier\n"
8510 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05008511 "Address Family modifier\n"
8512 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008513 "Display routes conforming to the prefix-list\n"
8514 "IP prefix-list name\n")
8515{
Lou Berger651b4022016-01-12 13:42:07 -05008516 safi_t safi;
8517 if (bgp_parse_safi(argv[0], &safi)) {
8518 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8519 return CMD_WARNING;
8520 }
8521 return bgp_show_prefix_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008522 bgp_show_type_prefix_list);
8523}
Lou Berger205e6742016-01-12 13:42:11 -05008524
Lou Berger651b4022016-01-12 13:42:07 -05008525DEFUN (show_bgp_ipv6_safi_prefix_list,
8526 show_bgp_ipv6_safi_prefix_list_cmd,
8527 "show bgp ipv6 (encap|multicast|unicast|vpn) prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008528 SHOW_STR
8529 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008530 "Address family\n"
8531 "Address Family modifier\n"
8532 "Address Family modifier\n"
8533 "Address Family modifier\n"
8534 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008535 "Display routes conforming to the prefix-list\n"
Lou Berger651b4022016-01-12 13:42:07 -05008536 "IP prefix-list name\n")
paul718e3742002-12-13 20:15:29 +00008537{
Lou Berger651b4022016-01-12 13:42:07 -05008538 safi_t safi;
8539 if (bgp_parse_safi(argv[0], &safi)) {
8540 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8541 return CMD_WARNING;
8542 }
8543 return bgp_show_prefix_list (vty, argv[1], AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00008544 bgp_show_type_prefix_list);
8545}
8546
paul94f2b392005-06-28 12:44:16 +00008547static int
paulfd79ac92004-10-13 05:06:08 +00008548bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008549 safi_t safi, enum bgp_show_type type)
8550{
8551 struct as_list *as_list;
8552
8553 as_list = as_list_lookup (filter);
8554 if (as_list == NULL)
8555 {
8556 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
8557 return CMD_WARNING;
8558 }
8559
ajs5a646652004-11-05 01:25:55 +00008560 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00008561}
8562
Lou Bergerf9b6c392016-01-12 13:42:09 -05008563DEFUN (show_ip_bgp_filter_list,
8564 show_ip_bgp_filter_list_cmd,
8565 "show ip bgp filter-list WORD",
8566 SHOW_STR
8567 IP_STR
8568 BGP_STR
8569 "Display routes conforming to the filter-list\n"
8570 "Regular expression access list name\n")
8571{
8572 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8573 bgp_show_type_filter_list);
8574}
8575
8576DEFUN (show_ip_bgp_flap_filter_list,
8577 show_ip_bgp_flap_filter_list_cmd,
8578 "show ip bgp flap-statistics filter-list WORD",
8579 SHOW_STR
8580 IP_STR
8581 BGP_STR
8582 "Display flap statistics of routes\n"
8583 "Display routes conforming to the filter-list\n"
8584 "Regular expression access list name\n")
8585{
8586 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8587 bgp_show_type_flap_filter_list);
8588}
8589
8590ALIAS (show_ip_bgp_flap_filter_list,
8591 show_ip_bgp_damp_flap_filter_list_cmd,
8592 "show ip bgp dampening flap-statistics filter-list WORD",
8593 SHOW_STR
8594 IP_STR
8595 BGP_STR
8596 "Display detailed information about dampening\n"
8597 "Display flap statistics of routes\n"
8598 "Display routes conforming to the filter-list\n"
8599 "Regular expression access list name\n")
8600
8601DEFUN (show_ip_bgp_ipv4_filter_list,
8602 show_ip_bgp_ipv4_filter_list_cmd,
8603 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
8604 SHOW_STR
8605 IP_STR
8606 BGP_STR
8607 "Address family\n"
8608 "Address Family modifier\n"
8609 "Address Family modifier\n"
8610 "Display routes conforming to the filter-list\n"
8611 "Regular expression access list name\n")
8612{
8613 if (strncmp (argv[0], "m", 1) == 0)
8614 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8615 bgp_show_type_filter_list);
8616
8617 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8618 bgp_show_type_filter_list);
8619}
8620
Lou Bergerf9b6c392016-01-12 13:42:09 -05008621DEFUN (show_bgp_filter_list,
8622 show_bgp_filter_list_cmd,
8623 "show bgp filter-list WORD",
8624 SHOW_STR
8625 BGP_STR
8626 "Display routes conforming to the filter-list\n"
8627 "Regular expression access list name\n")
8628{
8629 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8630 bgp_show_type_filter_list);
8631}
8632
8633/* old command */
8634DEFUN (show_ipv6_bgp_filter_list,
8635 show_ipv6_bgp_filter_list_cmd,
8636 "show ipv6 bgp filter-list WORD",
8637 SHOW_STR
8638 IPV6_STR
8639 BGP_STR
8640 "Display routes conforming to the filter-list\n"
8641 "Regular expression access list name\n")
8642{
8643 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8644 bgp_show_type_filter_list);
8645}
8646
8647/* old command */
8648DEFUN (show_ipv6_mbgp_filter_list,
8649 show_ipv6_mbgp_filter_list_cmd,
8650 "show ipv6 mbgp filter-list WORD",
8651 SHOW_STR
8652 IPV6_STR
8653 MBGP_STR
8654 "Display routes conforming to the filter-list\n"
8655 "Regular expression access list name\n")
8656{
8657 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8658 bgp_show_type_filter_list);
8659}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008660
8661DEFUN (show_ip_bgp_dampening_info,
8662 show_ip_bgp_dampening_params_cmd,
8663 "show ip bgp dampening parameters",
8664 SHOW_STR
8665 IP_STR
8666 BGP_STR
8667 "Display detailed information about dampening\n"
8668 "Display detail of configured dampening parameters\n")
8669{
8670 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
8671}
8672
Lou Berger651b4022016-01-12 13:42:07 -05008673DEFUN (show_bgp_ipv4_filter_list,
8674 show_bgp_ipv4_filter_list_cmd,
8675 "show bgp ipv4 filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008676 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008677 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008678 IP_STR
paul718e3742002-12-13 20:15:29 +00008679 "Display routes conforming to the filter-list\n"
8680 "Regular expression access list name\n")
8681{
8682 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8683 bgp_show_type_filter_list);
8684}
8685
Lou Berger651b4022016-01-12 13:42:07 -05008686DEFUN (show_bgp_ipv4_safi_flap_filter_list,
8687 show_bgp_ipv4_safi_flap_filter_list_cmd,
8688 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008689 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008690 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008691 IP_STR
8692 "Address Family modifier\n"
8693 "Address Family modifier\n"
8694 "Address Family modifier\n"
8695 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008696 "Display flap statistics of routes\n"
8697 "Display routes conforming to the filter-list\n"
8698 "Regular expression access list name\n")
8699{
Lou Berger651b4022016-01-12 13:42:07 -05008700 safi_t safi;
8701
8702 if (bgp_parse_safi(argv[0], &safi)) {
8703 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8704 return CMD_WARNING;
8705 }
8706 return bgp_show_filter_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008707 bgp_show_type_flap_filter_list);
8708}
8709
Lou Berger651b4022016-01-12 13:42:07 -05008710ALIAS (show_bgp_ipv4_safi_flap_filter_list,
8711 show_bgp_ipv4_safi_damp_flap_filter_list_cmd,
8712 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics filter-list WORD",
Balaji3921cc52015-05-16 23:12:17 +05308713 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308714 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008715 IP_STR
8716 "Address Family modifier\n"
8717 "Address Family modifier\n"
8718 "Address Family modifier\n"
8719 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308720 "Display detailed information about dampening\n"
8721 "Display flap statistics of routes\n"
8722 "Display routes conforming to the filter-list\n"
8723 "Regular expression access list name\n")
8724
Lou Berger651b4022016-01-12 13:42:07 -05008725DEFUN (show_bgp_ipv6_safi_flap_filter_list,
8726 show_bgp_ipv6_safi_flap_filter_list_cmd,
8727 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008728 SHOW_STR
8729 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008730 IPV6_STR
8731 "Address Family modifier\n"
8732 "Address Family modifier\n"
8733 "Address Family modifier\n"
8734 "Address Family modifier\n"
8735 "Display flap statistics of routes\n"
paul718e3742002-12-13 20:15:29 +00008736 "Display routes conforming to the filter-list\n"
8737 "Regular expression access list name\n")
8738{
Lou Berger651b4022016-01-12 13:42:07 -05008739 safi_t safi;
8740
8741 if (bgp_parse_safi(argv[0], &safi)) {
8742 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8743 return CMD_WARNING;
8744 }
8745 return bgp_show_filter_list (vty, argv[1], AFI_IP6, safi,
8746 bgp_show_type_flap_filter_list);
8747}
8748ALIAS (show_bgp_ipv6_safi_flap_filter_list,
8749 show_bgp_ipv6_safi_damp_flap_filter_list_cmd,
8750 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics filter-list WORD",
8751 SHOW_STR
8752 BGP_STR
8753 IPV6_STR
8754 "Address Family modifier\n"
8755 "Address Family modifier\n"
8756 "Address Family modifier\n"
8757 "Address Family modifier\n"
8758 "Display detailed information about dampening\n"
8759 "Display flap statistics of routes\n"
8760 "Display routes conforming to the filter-list\n"
8761 "Regular expression access list name\n")
Lou Berger651b4022016-01-12 13:42:07 -05008762
8763DEFUN (show_bgp_ipv4_safi_filter_list,
8764 show_bgp_ipv4_safi_filter_list_cmd,
8765 "show bgp ipv4 (encap|multicast|unicast|vpn) filter-list WORD",
8766 SHOW_STR
8767 BGP_STR
8768 "Address Family modifier\n"
8769 "Address Family modifier\n"
8770 "Address Family modifier\n"
8771 "Address Family modifier\n"
8772 "Display routes conforming to the filter-list\n"
8773 "Regular expression access list name\n")
8774{
8775 safi_t safi;
8776
8777 if (bgp_parse_safi(argv[0], &safi)) {
8778 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8779 return CMD_WARNING;
8780 }
8781 return bgp_show_filter_list (vty, argv[1], AFI_IP, safi,
8782 bgp_show_type_filter_list);
8783}
Lou Berger205e6742016-01-12 13:42:11 -05008784
Lou Berger651b4022016-01-12 13:42:07 -05008785DEFUN (show_bgp_ipv6_safi_filter_list,
8786 show_bgp_ipv6_safi_filter_list_cmd,
8787 "show bgp ipv6 (encap|multicast|unicast|vpn) filter-list WORD",
8788 SHOW_STR
8789 BGP_STR
8790 "Address Family modifier\n"
8791 "Address Family modifier\n"
8792 "Address Family modifier\n"
8793 "Address Family modifier\n"
8794 "Display routes conforming to the filter-list\n"
8795 "Regular expression access list name\n")
8796{
8797 safi_t safi;
8798
8799 if (bgp_parse_safi(argv[0], &safi)) {
8800 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8801 return CMD_WARNING;
8802 }
8803 return bgp_show_filter_list (vty, argv[1], AFI_IP6, safi,
8804 bgp_show_type_filter_list);
paul718e3742002-12-13 20:15:29 +00008805}
8806
Lou Bergerf9b6c392016-01-12 13:42:09 -05008807DEFUN (show_bgp_ipv6_filter_list,
paul718e3742002-12-13 20:15:29 +00008808 show_bgp_ipv6_filter_list_cmd,
8809 "show bgp ipv6 filter-list WORD",
8810 SHOW_STR
8811 BGP_STR
8812 "Address family\n"
8813 "Display routes conforming to the filter-list\n"
8814 "Regular expression access list name\n")
paul718e3742002-12-13 20:15:29 +00008815{
8816 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8817 bgp_show_type_filter_list);
8818}
8819
Balaji9c52cae2016-01-20 22:59:26 +05308820
8821DEFUN (show_ip_bgp_ipv4_dampening_parameters,
8822 show_ip_bgp_ipv4_dampening_parameters_cmd,
8823 "show ip bgp ipv4 (unicast|multicast) dampening parameters",
8824 SHOW_STR
8825 IP_STR
8826 BGP_STR
8827 "Address family\n"
8828 "Address Family modifier\n"
8829 "Address Family modifier\n"
8830 "Display detailed information about dampening\n"
8831 "Display detail of configured dampening parameters\n")
8832{
8833 if (strncmp(argv[0], "m", 1) == 0)
8834 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_MULTICAST);
8835
8836 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
8837}
8838
8839
8840DEFUN (show_ip_bgp_ipv4_dampening_flap_stats,
8841 show_ip_bgp_ipv4_dampening_flap_stats_cmd,
8842 "show ip bgp ipv4 (unicast|multicast) dampening flap-statistics",
8843 SHOW_STR
8844 IP_STR
8845 BGP_STR
8846 "Address family\n"
8847 "Address Family modifier\n"
8848 "Address Family modifier\n"
8849 "Display detailed information about dampening\n"
8850 "Display flap statistics of routes\n")
8851{
8852 if (strncmp(argv[0], "m", 1) == 0)
8853 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8854 bgp_show_type_flap_statistics, NULL);
8855
8856 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8857 bgp_show_type_flap_statistics, NULL);
8858}
8859
8860DEFUN (show_ip_bgp_ipv4_dampening_dampd_paths,
8861 show_ip_bgp_ipv4_dampening_dampd_paths_cmd,
8862 "show ip bgp ipv4 (unicast|multicast) dampening dampened-paths",
8863 SHOW_STR
8864 IP_STR
8865 BGP_STR
8866 "Address family\n"
8867 "Address Family modifier\n"
8868 "Address Family modifier\n"
8869 "Display detailed information about dampening\n"
8870 "Display paths suppressed due to dampening\n")
8871{
8872 if (strncmp(argv[0], "m", 1) == 0)
8873 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8874 bgp_show_type_dampend_paths, NULL);
8875
8876 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8877 bgp_show_type_dampend_paths, NULL);
8878}
8879
paul94f2b392005-06-28 12:44:16 +00008880static int
paulfd79ac92004-10-13 05:06:08 +00008881bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008882 safi_t safi, enum bgp_show_type type)
8883{
8884 struct route_map *rmap;
8885
8886 rmap = route_map_lookup_by_name (rmap_str);
8887 if (! rmap)
8888 {
8889 vty_out (vty, "%% %s is not a valid route-map name%s",
8890 rmap_str, VTY_NEWLINE);
8891 return CMD_WARNING;
8892 }
8893
ajs5a646652004-11-05 01:25:55 +00008894 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00008895}
8896
Lou Bergerf9b6c392016-01-12 13:42:09 -05008897DEFUN (show_ip_bgp_route_map,
8898 show_ip_bgp_route_map_cmd,
8899 "show ip bgp route-map WORD",
8900 SHOW_STR
8901 IP_STR
8902 BGP_STR
8903 "Display routes matching the route-map\n"
8904 "A route-map to match on\n")
8905{
8906 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8907 bgp_show_type_route_map);
8908}
8909
8910DEFUN (show_ip_bgp_flap_route_map,
8911 show_ip_bgp_flap_route_map_cmd,
8912 "show ip bgp flap-statistics route-map WORD",
8913 SHOW_STR
8914 IP_STR
8915 BGP_STR
8916 "Display flap statistics of routes\n"
8917 "Display routes matching the route-map\n"
8918 "A route-map to match on\n")
8919{
8920 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8921 bgp_show_type_flap_route_map);
8922}
8923
8924ALIAS (show_ip_bgp_flap_route_map,
8925 show_ip_bgp_damp_flap_route_map_cmd,
8926 "show ip bgp dampening flap-statistics route-map WORD",
8927 SHOW_STR
8928 IP_STR
8929 BGP_STR
8930 "Display detailed information about dampening\n"
8931 "Display flap statistics of routes\n"
8932 "Display routes matching the route-map\n"
8933 "A route-map to match on\n")
8934
8935DEFUN (show_ip_bgp_ipv4_route_map,
8936 show_ip_bgp_ipv4_route_map_cmd,
8937 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
8938 SHOW_STR
8939 IP_STR
8940 BGP_STR
8941 "Address family\n"
8942 "Address Family modifier\n"
8943 "Address Family modifier\n"
8944 "Display routes matching the route-map\n"
8945 "A route-map to match on\n")
8946{
8947 if (strncmp (argv[0], "m", 1) == 0)
8948 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8949 bgp_show_type_route_map);
8950
8951 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
8952 bgp_show_type_route_map);
8953}
8954
8955DEFUN (show_bgp_route_map,
8956 show_bgp_route_map_cmd,
8957 "show bgp route-map WORD",
8958 SHOW_STR
8959 BGP_STR
8960 "Display routes matching the route-map\n"
8961 "A route-map to match on\n")
8962{
8963 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8964 bgp_show_type_route_map);
8965}
8966
8967DEFUN (show_ip_bgp_cidr_only,
8968 show_ip_bgp_cidr_only_cmd,
8969 "show ip bgp cidr-only",
8970 SHOW_STR
8971 IP_STR
8972 BGP_STR
8973 "Display only routes with non-natural netmasks\n")
8974{
8975 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8976 bgp_show_type_cidr_only, NULL);
8977}
8978
8979DEFUN (show_ip_bgp_flap_cidr_only,
8980 show_ip_bgp_flap_cidr_only_cmd,
8981 "show ip bgp flap-statistics cidr-only",
8982 SHOW_STR
8983 IP_STR
8984 BGP_STR
8985 "Display flap statistics of routes\n"
8986 "Display only routes with non-natural netmasks\n")
8987{
8988 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8989 bgp_show_type_flap_cidr_only, NULL);
8990}
8991
8992ALIAS (show_ip_bgp_flap_cidr_only,
8993 show_ip_bgp_damp_flap_cidr_only_cmd,
8994 "show ip bgp dampening flap-statistics cidr-only",
8995 SHOW_STR
8996 IP_STR
8997 BGP_STR
8998 "Display detailed information about dampening\n"
8999 "Display flap statistics of routes\n"
9000 "Display only routes with non-natural netmasks\n")
9001
9002DEFUN (show_ip_bgp_ipv4_cidr_only,
9003 show_ip_bgp_ipv4_cidr_only_cmd,
9004 "show ip bgp ipv4 (unicast|multicast) cidr-only",
9005 SHOW_STR
9006 IP_STR
9007 BGP_STR
9008 "Address family\n"
9009 "Address Family modifier\n"
9010 "Address Family modifier\n"
9011 "Display only routes with non-natural netmasks\n")
9012{
9013 if (strncmp (argv[0], "m", 1) == 0)
9014 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9015 bgp_show_type_cidr_only, NULL);
9016
9017 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9018 bgp_show_type_cidr_only, NULL);
9019}
9020
9021DEFUN (show_ip_bgp_community_all,
9022 show_ip_bgp_community_all_cmd,
9023 "show ip bgp community",
9024 SHOW_STR
9025 IP_STR
9026 BGP_STR
9027 "Display routes matching the communities\n")
9028{
9029 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9030 bgp_show_type_community_all, NULL);
9031}
9032
9033DEFUN (show_ip_bgp_ipv4_community_all,
9034 show_ip_bgp_ipv4_community_all_cmd,
9035 "show ip bgp ipv4 (unicast|multicast) community",
9036 SHOW_STR
9037 IP_STR
9038 BGP_STR
9039 "Address family\n"
9040 "Address Family modifier\n"
9041 "Address Family modifier\n"
9042 "Display routes matching the communities\n")
9043{
9044 if (strncmp (argv[0], "m", 1) == 0)
9045 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9046 bgp_show_type_community_all, NULL);
9047
9048 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9049 bgp_show_type_community_all, NULL);
9050}
9051
Lou Bergerf9b6c392016-01-12 13:42:09 -05009052DEFUN (show_bgp_community_all,
9053 show_bgp_community_all_cmd,
9054 "show bgp community",
9055 SHOW_STR
9056 BGP_STR
9057 "Display routes matching the communities\n")
9058{
9059 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9060 bgp_show_type_community_all, NULL);
9061}
9062
9063ALIAS (show_bgp_community_all,
9064 show_bgp_ipv6_community_all_cmd,
9065 "show bgp ipv6 community",
9066 SHOW_STR
9067 BGP_STR
9068 "Address family\n"
9069 "Display routes matching the communities\n")
9070
9071/* old command */
9072DEFUN (show_ipv6_bgp_community_all,
9073 show_ipv6_bgp_community_all_cmd,
9074 "show ipv6 bgp community",
9075 SHOW_STR
9076 IPV6_STR
9077 BGP_STR
9078 "Display routes matching the communities\n")
9079{
9080 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9081 bgp_show_type_community_all, NULL);
9082}
9083
9084/* old command */
9085DEFUN (show_ipv6_mbgp_community_all,
9086 show_ipv6_mbgp_community_all_cmd,
9087 "show ipv6 mbgp community",
9088 SHOW_STR
9089 IPV6_STR
9090 MBGP_STR
9091 "Display routes matching the communities\n")
9092{
9093 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
9094 bgp_show_type_community_all, NULL);
9095}
Lou Bergerf9b6c392016-01-12 13:42:09 -05009096
Lou Berger651b4022016-01-12 13:42:07 -05009097DEFUN (show_bgp_ipv4_route_map,
9098 show_bgp_ipv4_route_map_cmd,
9099 "show bgp ipv4 route-map WORD",
paul718e3742002-12-13 20:15:29 +00009100 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009101 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009102 IP_STR
paul718e3742002-12-13 20:15:29 +00009103 "Display routes matching the route-map\n"
9104 "A route-map to match on\n")
9105{
9106 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
9107 bgp_show_type_route_map);
9108}
9109
Lou Berger651b4022016-01-12 13:42:07 -05009110DEFUN (show_bgp_ipv4_safi_flap_route_map,
9111 show_bgp_ipv4_safi_flap_route_map_cmd,
9112 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics route-map WORD",
paul718e3742002-12-13 20:15:29 +00009113 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009114 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009115 IP_STR
9116 "Address Family Modifier\n"
9117 "Address Family Modifier\n"
9118 "Address Family Modifier\n"
9119 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00009120 "Display flap statistics of routes\n"
9121 "Display routes matching the route-map\n"
9122 "A route-map to match on\n")
9123{
Lou Berger651b4022016-01-12 13:42:07 -05009124 safi_t safi;
9125 if (bgp_parse_safi(argv[0], &safi)) {
9126 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9127 return CMD_WARNING;
9128 }
9129 return bgp_show_route_map (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00009130 bgp_show_type_flap_route_map);
9131}
9132
Lou Berger651b4022016-01-12 13:42:07 -05009133ALIAS (show_bgp_ipv4_safi_flap_route_map,
9134 show_bgp_ipv4_safi_damp_flap_route_map_cmd,
9135 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics route-map WORD",
Balaji3921cc52015-05-16 23:12:17 +05309136 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05309137 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009138 IP_STR
9139 "Address Family Modifier\n"
9140 "Address Family Modifier\n"
9141 "Address Family Modifier\n"
9142 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05309143 "Display detailed information about dampening\n"
9144 "Display flap statistics of routes\n"
9145 "Display routes matching the route-map\n"
9146 "A route-map to match on\n")
Lou Berger205e6742016-01-12 13:42:11 -05009147
Lou Berger651b4022016-01-12 13:42:07 -05009148DEFUN (show_bgp_ipv6_safi_flap_route_map,
9149 show_bgp_ipv6_safi_flap_route_map_cmd,
9150 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics route-map WORD",
paul718e3742002-12-13 20:15:29 +00009151 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05009152 BGP_STR
9153 IPV6_STR
9154 "Address Family Modifier\n"
9155 "Address Family Modifier\n"
9156 "Address Family Modifier\n"
9157 "Address Family Modifier\n"
9158 "Display flap statistics of routes\n"
9159 "Display routes matching the route-map\n"
9160 "A route-map to match on\n")
9161{
9162 safi_t safi;
9163 if (bgp_parse_safi(argv[0], &safi)) {
9164 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9165 return CMD_WARNING;
9166 }
9167 return bgp_show_route_map (vty, argv[1], AFI_IP6, safi,
9168 bgp_show_type_flap_route_map);
9169}
9170ALIAS (show_bgp_ipv6_safi_flap_route_map,
9171 show_bgp_ipv6_safi_damp_flap_route_map_cmd,
9172 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics route-map WORD",
9173 SHOW_STR
9174 BGP_STR
9175 IPV6_STR
9176 "Address Family Modifier\n"
9177 "Address Family Modifier\n"
9178 "Address Family Modifier\n"
9179 "Address Family Modifier\n"
9180 "Display detailed information about dampening\n"
9181 "Display flap statistics of routes\n"
9182 "Display routes matching the route-map\n"
9183 "A route-map to match on\n")
Lou Berger651b4022016-01-12 13:42:07 -05009184
9185DEFUN (show_bgp_ipv4_safi_route_map,
9186 show_bgp_ipv4_safi_route_map_cmd,
9187 "show bgp ipv4 (encap|multicast|unicast|vpn) route-map WORD",
9188 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009189 BGP_STR
9190 "Address family\n"
9191 "Address Family modifier\n"
9192 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05009193 "Address Family modifier\n"
9194 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009195 "Display routes matching the route-map\n"
9196 "A route-map to match on\n")
9197{
Lou Berger651b4022016-01-12 13:42:07 -05009198 safi_t safi;
9199 if (bgp_parse_safi(argv[0], &safi)) {
9200 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9201 return CMD_WARNING;
9202 }
9203 return bgp_show_route_map (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00009204 bgp_show_type_route_map);
9205}
Lou Berger205e6742016-01-12 13:42:11 -05009206
Lou Berger651b4022016-01-12 13:42:07 -05009207DEFUN (show_bgp_ipv6_safi_route_map,
9208 show_bgp_ipv6_safi_route_map_cmd,
9209 "show bgp ipv6 (encap|multicast|unicast|vpn) route-map WORD",
paul718e3742002-12-13 20:15:29 +00009210 SHOW_STR
9211 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009212 "Address family\n"
9213 "Address Family modifier\n"
9214 "Address Family modifier\n"
9215 "Address Family modifier\n"
9216 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009217 "Display routes matching the route-map\n"
9218 "A route-map to match on\n")
9219{
Lou Berger651b4022016-01-12 13:42:07 -05009220 safi_t safi;
9221 if (bgp_parse_safi(argv[0], &safi)) {
9222 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9223 return CMD_WARNING;
9224 }
9225 return bgp_show_route_map (vty, argv[1], AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00009226 bgp_show_type_route_map);
9227}
9228
Lou Berger651b4022016-01-12 13:42:07 -05009229DEFUN (show_bgp_ipv6_route_map,
paul718e3742002-12-13 20:15:29 +00009230 show_bgp_ipv6_route_map_cmd,
9231 "show bgp ipv6 route-map WORD",
9232 SHOW_STR
9233 BGP_STR
9234 "Address family\n"
9235 "Display routes matching the route-map\n"
9236 "A route-map to match on\n")
Lou Berger651b4022016-01-12 13:42:07 -05009237{
9238 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9239 bgp_show_type_route_map);
9240}
David Lamparter6b0655a2014-06-04 06:53:35 +02009241
Lou Berger651b4022016-01-12 13:42:07 -05009242DEFUN (show_bgp_ipv4_cidr_only,
9243 show_bgp_ipv4_cidr_only_cmd,
9244 "show bgp ipv4 cidr-only",
paul718e3742002-12-13 20:15:29 +00009245 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009246 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009247 IP_STR
paul718e3742002-12-13 20:15:29 +00009248 "Display only routes with non-natural netmasks\n")
9249{
9250 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00009251 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009252}
9253
Lou Berger651b4022016-01-12 13:42:07 -05009254DEFUN (show_bgp_ipv4_safi_flap_cidr_only,
9255 show_bgp_ipv4_safi_flap_cidr_only_cmd,
9256 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics cidr-only",
paul718e3742002-12-13 20:15:29 +00009257 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009258 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009259 "Address Family\n"
9260 "Address Family Modifier\n"
9261 "Address Family Modifier\n"
9262 "Address Family Modifier\n"
9263 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00009264 "Display flap statistics of routes\n"
9265 "Display only routes with non-natural netmasks\n")
9266{
Lou Berger651b4022016-01-12 13:42:07 -05009267 safi_t safi;
9268
9269 if (bgp_parse_safi(argv[0], &safi)) {
9270 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9271 return CMD_WARNING;
9272 }
9273 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009274}
9275
Lou Berger651b4022016-01-12 13:42:07 -05009276ALIAS (show_bgp_ipv4_safi_flap_cidr_only,
9277 show_bgp_ipv4_safi_damp_flap_cidr_only_cmd,
9278 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics cidr-only",
Balaji3921cc52015-05-16 23:12:17 +05309279 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05309280 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009281 "Address Family\n"
9282 "Address Family Modifier\n"
9283 "Address Family Modifier\n"
9284 "Address Family Modifier\n"
9285 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05309286 "Display detailed information about dampening\n"
9287 "Display flap statistics of routes\n"
9288 "Display only routes with non-natural netmasks\n")
9289
Lou Berger651b4022016-01-12 13:42:07 -05009290DEFUN (show_bgp_ipv4_safi_cidr_only,
9291 show_bgp_ipv4_safi_cidr_only_cmd,
9292 "show bgp ipv4 (unicast|multicast) cidr-only",
paul718e3742002-12-13 20:15:29 +00009293 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009294 BGP_STR
9295 "Address family\n"
9296 "Address Family modifier\n"
9297 "Address Family modifier\n"
9298 "Display only routes with non-natural netmasks\n")
9299{
9300 if (strncmp (argv[0], "m", 1) == 0)
9301 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00009302 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009303
9304 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00009305 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009306}
David Lamparter6b0655a2014-06-04 06:53:35 +02009307
Lou Berger651b4022016-01-12 13:42:07 -05009308/* new046 */
9309DEFUN (show_bgp_afi_safi_community_all,
9310 show_bgp_afi_safi_community_all_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009311 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) community",
paul718e3742002-12-13 20:15:29 +00009312 SHOW_STR
9313 BGP_STR
9314 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009315 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009316 "Address Family modifier\n"
9317 "Address Family modifier\n"
9318 "Address Family modifier\n"
9319 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009320 "Display routes matching the communities\n")
Lou Berger651b4022016-01-12 13:42:07 -05009321{
9322 safi_t safi;
9323 afi_t afi;
paul718e3742002-12-13 20:15:29 +00009324
Lou Berger651b4022016-01-12 13:42:07 -05009325 if (bgp_parse_afi(argv[0], &afi)) {
9326 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
9327 return CMD_WARNING;
9328 }
9329 if (bgp_parse_safi(argv[1], &safi)) {
9330 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
9331 return CMD_WARNING;
9332 }
9333
9334 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_all, NULL);
9335}
9336DEFUN (show_bgp_afi_community_all,
9337 show_bgp_afi_community_all_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009338 "show bgp (ipv4|ipv6) community",
paul718e3742002-12-13 20:15:29 +00009339 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009340 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009341 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009342 "Address family\n"
paul718e3742002-12-13 20:15:29 +00009343 "Display routes matching the communities\n")
9344{
Lou Berger651b4022016-01-12 13:42:07 -05009345 afi_t afi;
9346 safi_t safi = SAFI_UNICAST;
paul718e3742002-12-13 20:15:29 +00009347
Lou Berger651b4022016-01-12 13:42:07 -05009348 if (bgp_parse_afi(argv[0], &afi)) {
9349 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
9350 return CMD_WARNING;
9351 }
9352 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00009353}
David Lamparter6b0655a2014-06-04 06:53:35 +02009354
paul94f2b392005-06-28 12:44:16 +00009355static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04009356bgp_show_community (struct vty *vty, const char *view_name, int argc,
9357 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00009358{
9359 struct community *com;
9360 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04009361 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00009362 int i;
9363 char *str;
9364 int first = 0;
9365
Michael Lambert95cbbd22010-07-23 14:43:04 -04009366 /* BGP structure lookup */
9367 if (view_name)
9368 {
9369 bgp = bgp_lookup_by_name (view_name);
9370 if (bgp == NULL)
9371 {
9372 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9373 return CMD_WARNING;
9374 }
9375 }
9376 else
9377 {
9378 bgp = bgp_get_default ();
9379 if (bgp == NULL)
9380 {
9381 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9382 return CMD_WARNING;
9383 }
9384 }
9385
paul718e3742002-12-13 20:15:29 +00009386 b = buffer_new (1024);
9387 for (i = 0; i < argc; i++)
9388 {
9389 if (first)
9390 buffer_putc (b, ' ');
9391 else
9392 {
9393 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9394 continue;
9395 first = 1;
9396 }
9397
9398 buffer_putstr (b, argv[i]);
9399 }
9400 buffer_putc (b, '\0');
9401
9402 str = buffer_getstr (b);
9403 buffer_free (b);
9404
9405 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00009406 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00009407 if (! com)
9408 {
9409 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
9410 return CMD_WARNING;
9411 }
9412
Michael Lambert95cbbd22010-07-23 14:43:04 -04009413 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00009414 (exact ? bgp_show_type_community_exact :
9415 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00009416}
9417
Lou Bergerf9b6c392016-01-12 13:42:09 -05009418DEFUN (show_ip_bgp_community,
9419 show_ip_bgp_community_cmd,
9420 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
9421 SHOW_STR
9422 IP_STR
9423 BGP_STR
9424 "Display routes matching the communities\n"
9425 "community number\n"
9426 "Do not send outside local AS (well-known community)\n"
9427 "Do not advertise to any peer (well-known community)\n"
9428 "Do not export to next AS (well-known community)\n")
9429{
9430 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9431}
9432
9433ALIAS (show_ip_bgp_community,
9434 show_ip_bgp_community2_cmd,
9435 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9436 SHOW_STR
9437 IP_STR
9438 BGP_STR
9439 "Display routes matching the communities\n"
9440 "community number\n"
9441 "Do not send outside local AS (well-known community)\n"
9442 "Do not advertise to any peer (well-known community)\n"
9443 "Do not export to next AS (well-known community)\n"
9444 "community number\n"
9445 "Do not send outside local AS (well-known community)\n"
9446 "Do not advertise to any peer (well-known community)\n"
9447 "Do not export to next AS (well-known community)\n")
9448
9449ALIAS (show_ip_bgp_community,
9450 show_ip_bgp_community3_cmd,
9451 "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)",
9452 SHOW_STR
9453 IP_STR
9454 BGP_STR
9455 "Display routes matching the communities\n"
9456 "community number\n"
9457 "Do not send outside local AS (well-known community)\n"
9458 "Do not advertise to any peer (well-known community)\n"
9459 "Do not export to next AS (well-known community)\n"
9460 "community number\n"
9461 "Do not send outside local AS (well-known community)\n"
9462 "Do not advertise to any peer (well-known community)\n"
9463 "Do not export to next AS (well-known community)\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
9469ALIAS (show_ip_bgp_community,
9470 show_ip_bgp_community4_cmd,
9471 "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)",
9472 SHOW_STR
9473 IP_STR
9474 BGP_STR
9475 "Display routes matching the communities\n"
9476 "community number\n"
9477 "Do not send outside local AS (well-known community)\n"
9478 "Do not advertise to any peer (well-known community)\n"
9479 "Do not export to next AS (well-known community)\n"
9480 "community number\n"
9481 "Do not send outside local AS (well-known community)\n"
9482 "Do not advertise to any peer (well-known community)\n"
9483 "Do not export to next AS (well-known community)\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
9493DEFUN (show_ip_bgp_ipv4_community,
9494 show_ip_bgp_ipv4_community_cmd,
9495 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9496 SHOW_STR
9497 IP_STR
9498 BGP_STR
9499 "Address family\n"
9500 "Address Family modifier\n"
9501 "Address Family modifier\n"
9502 "Display routes matching the communities\n"
9503 "community number\n"
9504 "Do not send outside local AS (well-known community)\n"
9505 "Do not advertise to any peer (well-known community)\n"
9506 "Do not export to next AS (well-known community)\n")
9507{
9508 if (strncmp (argv[0], "m", 1) == 0)
9509 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
9510
9511 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9512}
9513
9514ALIAS (show_ip_bgp_ipv4_community,
9515 show_ip_bgp_ipv4_community2_cmd,
9516 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9517 SHOW_STR
9518 IP_STR
9519 BGP_STR
9520 "Address family\n"
9521 "Address Family modifier\n"
9522 "Address Family modifier\n"
9523 "Display routes matching the communities\n"
9524 "community number\n"
9525 "Do not send outside local AS (well-known community)\n"
9526 "Do not advertise to any peer (well-known community)\n"
9527 "Do not export to next AS (well-known community)\n"
9528 "community number\n"
9529 "Do not send outside local AS (well-known community)\n"
9530 "Do not advertise to any peer (well-known community)\n"
9531 "Do not export to next AS (well-known community)\n")
9532
9533ALIAS (show_ip_bgp_ipv4_community,
9534 show_ip_bgp_ipv4_community3_cmd,
9535 "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)",
9536 SHOW_STR
9537 IP_STR
9538 BGP_STR
9539 "Address family\n"
9540 "Address Family modifier\n"
9541 "Address Family modifier\n"
9542 "Display routes matching the communities\n"
9543 "community number\n"
9544 "Do not send outside local AS (well-known community)\n"
9545 "Do not advertise to any peer (well-known community)\n"
9546 "Do not export to next AS (well-known community)\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 "community number\n"
9552 "Do not send outside local AS (well-known community)\n"
9553 "Do not advertise to any peer (well-known community)\n"
9554 "Do not export to next AS (well-known community)\n")
9555
9556ALIAS (show_ip_bgp_ipv4_community,
9557 show_ip_bgp_ipv4_community4_cmd,
9558 "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)",
9559 SHOW_STR
9560 IP_STR
9561 BGP_STR
9562 "Address family\n"
9563 "Address Family modifier\n"
9564 "Address Family modifier\n"
9565 "Display routes matching the communities\n"
9566 "community number\n"
9567 "Do not send outside local AS (well-known community)\n"
9568 "Do not advertise to any peer (well-known community)\n"
9569 "Do not export to next AS (well-known community)\n"
9570 "community number\n"
9571 "Do not send outside local AS (well-known community)\n"
9572 "Do not advertise to any peer (well-known community)\n"
9573 "Do not export to next AS (well-known community)\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
9583DEFUN (show_ip_bgp_community_exact,
9584 show_ip_bgp_community_exact_cmd,
9585 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9586 SHOW_STR
9587 IP_STR
9588 BGP_STR
9589 "Display routes matching the communities\n"
9590 "community number\n"
9591 "Do not send outside local AS (well-known community)\n"
9592 "Do not advertise to any peer (well-known community)\n"
9593 "Do not export to next AS (well-known community)\n"
9594 "Exact match of the communities")
9595{
9596 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9597}
9598
9599ALIAS (show_ip_bgp_community_exact,
9600 show_ip_bgp_community2_exact_cmd,
9601 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9602 SHOW_STR
9603 IP_STR
9604 BGP_STR
9605 "Display routes matching the communities\n"
9606 "community number\n"
9607 "Do not send outside local AS (well-known community)\n"
9608 "Do not advertise to any peer (well-known community)\n"
9609 "Do not export to next AS (well-known community)\n"
9610 "community number\n"
9611 "Do not send outside local AS (well-known community)\n"
9612 "Do not advertise to any peer (well-known community)\n"
9613 "Do not export to next AS (well-known community)\n"
9614 "Exact match of the communities")
9615
9616ALIAS (show_ip_bgp_community_exact,
9617 show_ip_bgp_community3_exact_cmd,
9618 "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",
9619 SHOW_STR
9620 IP_STR
9621 BGP_STR
9622 "Display routes matching the communities\n"
9623 "community number\n"
9624 "Do not send outside local AS (well-known community)\n"
9625 "Do not advertise to any peer (well-known community)\n"
9626 "Do not export to next AS (well-known community)\n"
9627 "community number\n"
9628 "Do not send outside local AS (well-known community)\n"
9629 "Do not advertise to any peer (well-known community)\n"
9630 "Do not export to next AS (well-known community)\n"
9631 "community number\n"
9632 "Do not send outside local AS (well-known community)\n"
9633 "Do not advertise to any peer (well-known community)\n"
9634 "Do not export to next AS (well-known community)\n"
9635 "Exact match of the communities")
9636
9637ALIAS (show_ip_bgp_community_exact,
9638 show_ip_bgp_community4_exact_cmd,
9639 "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",
9640 SHOW_STR
9641 IP_STR
9642 BGP_STR
9643 "Display routes matching the communities\n"
9644 "community number\n"
9645 "Do not send outside local AS (well-known community)\n"
9646 "Do not advertise to any peer (well-known community)\n"
9647 "Do not export to next AS (well-known community)\n"
9648 "community number\n"
9649 "Do not send outside local AS (well-known community)\n"
9650 "Do not advertise to any peer (well-known community)\n"
9651 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
9661
9662DEFUN (show_ip_bgp_ipv4_community_exact,
9663 show_ip_bgp_ipv4_community_exact_cmd,
9664 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9665 SHOW_STR
9666 IP_STR
9667 BGP_STR
9668 "Address family\n"
9669 "Address Family modifier\n"
9670 "Address Family modifier\n"
9671 "Display routes matching the communities\n"
9672 "community number\n"
9673 "Do not send outside local AS (well-known community)\n"
9674 "Do not advertise to any peer (well-known community)\n"
9675 "Do not export to next AS (well-known community)\n"
9676 "Exact match of the communities")
9677{
9678 if (strncmp (argv[0], "m", 1) == 0)
9679 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
9680
9681 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9682}
9683
9684ALIAS (show_ip_bgp_ipv4_community_exact,
9685 show_ip_bgp_ipv4_community2_exact_cmd,
9686 "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",
9687 SHOW_STR
9688 IP_STR
9689 BGP_STR
9690 "Address family\n"
9691 "Address Family modifier\n"
9692 "Address Family modifier\n"
9693 "Display routes matching the communities\n"
9694 "community number\n"
9695 "Do not send outside local AS (well-known community)\n"
9696 "Do not advertise to any peer (well-known community)\n"
9697 "Do not export to next AS (well-known community)\n"
9698 "community number\n"
9699 "Do not send outside local AS (well-known community)\n"
9700 "Do not advertise to any peer (well-known community)\n"
9701 "Do not export to next AS (well-known community)\n"
9702 "Exact match of the communities")
9703
9704ALIAS (show_ip_bgp_ipv4_community_exact,
9705 show_ip_bgp_ipv4_community3_exact_cmd,
9706 "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",
9707 SHOW_STR
9708 IP_STR
9709 BGP_STR
9710 "Address family\n"
9711 "Address Family modifier\n"
9712 "Address Family modifier\n"
9713 "Display routes matching the communities\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 "community number\n"
9723 "Do not send outside local AS (well-known community)\n"
9724 "Do not advertise to any peer (well-known community)\n"
9725 "Do not export to next AS (well-known community)\n"
9726 "Exact match of the communities")
9727
9728ALIAS (show_ip_bgp_ipv4_community_exact,
9729 show_ip_bgp_ipv4_community4_exact_cmd,
9730 "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",
9731 SHOW_STR
9732 IP_STR
9733 BGP_STR
9734 "Address family\n"
9735 "Address Family modifier\n"
9736 "Address Family modifier\n"
9737 "Display routes matching the communities\n"
9738 "community number\n"
9739 "Do not send outside local AS (well-known community)\n"
9740 "Do not advertise to any peer (well-known community)\n"
9741 "Do not export to next AS (well-known community)\n"
9742 "community number\n"
9743 "Do not send outside local AS (well-known community)\n"
9744 "Do not advertise to any peer (well-known community)\n"
9745 "Do not export to next AS (well-known community)\n"
9746 "community number\n"
9747 "Do not send outside local AS (well-known community)\n"
9748 "Do not advertise to any peer (well-known community)\n"
9749 "Do not export to next AS (well-known community)\n"
9750 "community number\n"
9751 "Do not send outside local AS (well-known community)\n"
9752 "Do not advertise to any peer (well-known community)\n"
9753 "Do not export to next AS (well-known community)\n"
9754 "Exact match of the communities")
9755
Lou Bergerf9b6c392016-01-12 13:42:09 -05009756DEFUN (show_bgp_community,
9757 show_bgp_community_cmd,
9758 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
9759 SHOW_STR
9760 BGP_STR
9761 "Display routes matching the communities\n"
9762 "community number\n"
9763 "Do not send outside local AS (well-known community)\n"
9764 "Do not advertise to any peer (well-known community)\n"
9765 "Do not export to next AS (well-known community)\n")
9766{
9767 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9768}
9769
9770ALIAS (show_bgp_community,
9771 show_bgp_ipv6_community_cmd,
9772 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
9773 SHOW_STR
9774 BGP_STR
9775 "Address family\n"
9776 "Display routes matching the communities\n"
9777 "community number\n"
9778 "Do not send outside local AS (well-known community)\n"
9779 "Do not advertise to any peer (well-known community)\n"
9780 "Do not export to next AS (well-known community)\n")
9781
9782ALIAS (show_bgp_community,
9783 show_bgp_community2_cmd,
9784 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9785 SHOW_STR
9786 BGP_STR
9787 "Display routes matching the communities\n"
9788 "community number\n"
9789 "Do not send outside local AS (well-known community)\n"
9790 "Do not advertise to any peer (well-known community)\n"
9791 "Do not export to next AS (well-known community)\n"
9792 "community number\n"
9793 "Do not send outside local AS (well-known community)\n"
9794 "Do not advertise to any peer (well-known community)\n"
9795 "Do not export to next AS (well-known community)\n")
9796
9797ALIAS (show_bgp_community,
9798 show_bgp_ipv6_community2_cmd,
9799 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9800 SHOW_STR
9801 BGP_STR
9802 "Address family\n"
9803 "Display routes matching the communities\n"
9804 "community number\n"
9805 "Do not send outside local AS (well-known community)\n"
9806 "Do not advertise to any peer (well-known community)\n"
9807 "Do not export to next AS (well-known community)\n"
9808 "community number\n"
9809 "Do not send outside local AS (well-known community)\n"
9810 "Do not advertise to any peer (well-known community)\n"
9811 "Do not export to next AS (well-known community)\n")
9812
9813ALIAS (show_bgp_community,
9814 show_bgp_community3_cmd,
9815 "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)",
9816 SHOW_STR
9817 BGP_STR
9818 "Display routes matching the communities\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 "community number\n"
9828 "Do not send outside local AS (well-known community)\n"
9829 "Do not advertise to any peer (well-known community)\n"
9830 "Do not export to next AS (well-known community)\n")
9831
9832ALIAS (show_bgp_community,
9833 show_bgp_ipv6_community3_cmd,
9834 "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)",
9835 SHOW_STR
9836 BGP_STR
9837 "Address family\n"
9838 "Display routes matching the communities\n"
9839 "community number\n"
9840 "Do not send outside local AS (well-known community)\n"
9841 "Do not advertise to any peer (well-known community)\n"
9842 "Do not export to next AS (well-known community)\n"
9843 "community number\n"
9844 "Do not send outside local AS (well-known community)\n"
9845 "Do not advertise to any peer (well-known community)\n"
9846 "Do not export to next AS (well-known community)\n"
9847 "community number\n"
9848 "Do not send outside local AS (well-known community)\n"
9849 "Do not advertise to any peer (well-known community)\n"
9850 "Do not export to next AS (well-known community)\n")
9851
9852ALIAS (show_bgp_community,
9853 show_bgp_community4_cmd,
9854 "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)",
9855 SHOW_STR
9856 BGP_STR
9857 "Display routes matching the communities\n"
9858 "community number\n"
9859 "Do not send outside local AS (well-known community)\n"
9860 "Do not advertise to any peer (well-known community)\n"
9861 "Do not export to next AS (well-known community)\n"
9862 "community number\n"
9863 "Do not send outside local AS (well-known community)\n"
9864 "Do not advertise to any peer (well-known community)\n"
9865 "Do not export to next AS (well-known community)\n"
9866 "community number\n"
9867 "Do not send outside local AS (well-known community)\n"
9868 "Do not advertise to any peer (well-known community)\n"
9869 "Do not export to next AS (well-known community)\n"
9870 "community number\n"
9871 "Do not send outside local AS (well-known community)\n"
9872 "Do not advertise to any peer (well-known community)\n"
9873 "Do not export to next AS (well-known community)\n")
9874
9875ALIAS (show_bgp_community,
9876 show_bgp_ipv6_community4_cmd,
9877 "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)",
9878 SHOW_STR
9879 BGP_STR
9880 "Address family\n"
9881 "Display routes matching the communities\n"
9882 "community number\n"
9883 "Do not send outside local AS (well-known community)\n"
9884 "Do not advertise to any peer (well-known community)\n"
9885 "Do not export to next AS (well-known community)\n"
9886 "community number\n"
9887 "Do not send outside local AS (well-known community)\n"
9888 "Do not advertise to any peer (well-known community)\n"
9889 "Do not export to next AS (well-known community)\n"
9890 "community number\n"
9891 "Do not send outside local AS (well-known community)\n"
9892 "Do not advertise to any peer (well-known community)\n"
9893 "Do not export to next AS (well-known community)\n"
9894 "community number\n"
9895 "Do not send outside local AS (well-known community)\n"
9896 "Do not advertise to any peer (well-known community)\n"
9897 "Do not export to next AS (well-known community)\n")
9898
9899/* old command */
9900DEFUN (show_ipv6_bgp_community,
9901 show_ipv6_bgp_community_cmd,
9902 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
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{
9912 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9913}
9914
9915/* old command */
9916ALIAS (show_ipv6_bgp_community,
9917 show_ipv6_bgp_community2_cmd,
9918 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9919 SHOW_STR
9920 IPV6_STR
9921 BGP_STR
9922 "Display routes matching the communities\n"
9923 "community number\n"
9924 "Do not send outside local AS (well-known community)\n"
9925 "Do not advertise to any peer (well-known community)\n"
9926 "Do not export to next AS (well-known community)\n"
9927 "community number\n"
9928 "Do not send outside local AS (well-known community)\n"
9929 "Do not advertise to any peer (well-known community)\n"
9930 "Do not export to next AS (well-known community)\n")
9931
9932/* old command */
9933ALIAS (show_ipv6_bgp_community,
9934 show_ipv6_bgp_community3_cmd,
9935 "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)",
9936 SHOW_STR
9937 IPV6_STR
9938 BGP_STR
9939 "Display routes matching the communities\n"
9940 "community number\n"
9941 "Do not send outside local AS (well-known community)\n"
9942 "Do not advertise to any peer (well-known community)\n"
9943 "Do not export to next AS (well-known community)\n"
9944 "community number\n"
9945 "Do not send outside local AS (well-known community)\n"
9946 "Do not advertise to any peer (well-known community)\n"
9947 "Do not export to next AS (well-known community)\n"
9948 "community number\n"
9949 "Do not send outside local AS (well-known community)\n"
9950 "Do not advertise to any peer (well-known community)\n"
9951 "Do not export to next AS (well-known community)\n")
9952
9953/* old command */
9954ALIAS (show_ipv6_bgp_community,
9955 show_ipv6_bgp_community4_cmd,
9956 "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)",
9957 SHOW_STR
9958 IPV6_STR
9959 BGP_STR
9960 "Display routes matching the communities\n"
9961 "community number\n"
9962 "Do not send outside local AS (well-known community)\n"
9963 "Do not advertise to any peer (well-known community)\n"
9964 "Do not export to next AS (well-known community)\n"
9965 "community number\n"
9966 "Do not send outside local AS (well-known community)\n"
9967 "Do not advertise to any peer (well-known community)\n"
9968 "Do not export to next AS (well-known community)\n"
9969 "community number\n"
9970 "Do not send outside local AS (well-known community)\n"
9971 "Do not advertise to any peer (well-known community)\n"
9972 "Do not export to next AS (well-known community)\n"
9973 "community number\n"
9974 "Do not send outside local AS (well-known community)\n"
9975 "Do not advertise to any peer (well-known community)\n"
9976 "Do not export to next AS (well-known community)\n")
9977
9978DEFUN (show_bgp_community_exact,
9979 show_bgp_community_exact_cmd,
9980 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9981 SHOW_STR
9982 BGP_STR
9983 "Display routes matching the communities\n"
9984 "community number\n"
9985 "Do not send outside local AS (well-known community)\n"
9986 "Do not advertise to any peer (well-known community)\n"
9987 "Do not export to next AS (well-known community)\n"
9988 "Exact match of the communities")
9989{
9990 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
9991}
9992
9993ALIAS (show_bgp_community_exact,
9994 show_bgp_ipv6_community_exact_cmd,
9995 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9996 SHOW_STR
9997 BGP_STR
9998 "Address family\n"
9999 "Display routes matching the communities\n"
10000 "community number\n"
10001 "Do not send outside local AS (well-known community)\n"
10002 "Do not advertise to any peer (well-known community)\n"
10003 "Do not export to next AS (well-known community)\n"
10004 "Exact match of the communities")
10005
10006ALIAS (show_bgp_community_exact,
10007 show_bgp_community2_exact_cmd,
10008 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10009 SHOW_STR
10010 BGP_STR
10011 "Display routes matching the communities\n"
10012 "community number\n"
10013 "Do not send outside local AS (well-known community)\n"
10014 "Do not advertise to any peer (well-known community)\n"
10015 "Do not export to next AS (well-known community)\n"
10016 "community number\n"
10017 "Do not send outside local AS (well-known community)\n"
10018 "Do not advertise to any peer (well-known community)\n"
10019 "Do not export to next AS (well-known community)\n"
10020 "Exact match of the communities")
10021
10022ALIAS (show_bgp_community_exact,
10023 show_bgp_ipv6_community2_exact_cmd,
10024 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10025 SHOW_STR
10026 BGP_STR
10027 "Address family\n"
10028 "Display routes matching the communities\n"
10029 "community number\n"
10030 "Do not send outside local AS (well-known community)\n"
10031 "Do not advertise to any peer (well-known community)\n"
10032 "Do not export to next AS (well-known community)\n"
10033 "community number\n"
10034 "Do not send outside local AS (well-known community)\n"
10035 "Do not advertise to any peer (well-known community)\n"
10036 "Do not export to next AS (well-known community)\n"
10037 "Exact match of the communities")
10038
10039ALIAS (show_bgp_community_exact,
10040 show_bgp_community3_exact_cmd,
10041 "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",
10042 SHOW_STR
10043 BGP_STR
10044 "Display routes matching the communities\n"
10045 "community number\n"
10046 "Do not send outside local AS (well-known community)\n"
10047 "Do not advertise to any peer (well-known community)\n"
10048 "Do not export to next AS (well-known community)\n"
10049 "community number\n"
10050 "Do not send outside local AS (well-known community)\n"
10051 "Do not advertise to any peer (well-known community)\n"
10052 "Do not export to next AS (well-known community)\n"
10053 "community number\n"
10054 "Do not send outside local AS (well-known community)\n"
10055 "Do not advertise to any peer (well-known community)\n"
10056 "Do not export to next AS (well-known community)\n"
10057 "Exact match of the communities")
10058
10059ALIAS (show_bgp_community_exact,
10060 show_bgp_ipv6_community3_exact_cmd,
10061 "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",
10062 SHOW_STR
10063 BGP_STR
10064 "Address family\n"
10065 "Display routes matching the communities\n"
10066 "community number\n"
10067 "Do not send outside local AS (well-known community)\n"
10068 "Do not advertise to any peer (well-known community)\n"
10069 "Do not export to next AS (well-known community)\n"
10070 "community number\n"
10071 "Do not send outside local AS (well-known community)\n"
10072 "Do not advertise to any peer (well-known community)\n"
10073 "Do not export to next AS (well-known community)\n"
10074 "community number\n"
10075 "Do not send outside local AS (well-known community)\n"
10076 "Do not advertise to any peer (well-known community)\n"
10077 "Do not export to next AS (well-known community)\n"
10078 "Exact match of the communities")
10079
10080ALIAS (show_bgp_community_exact,
10081 show_bgp_community4_exact_cmd,
10082 "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",
10083 SHOW_STR
10084 BGP_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 "community number\n"
10095 "Do not send outside local AS (well-known community)\n"
10096 "Do not advertise to any peer (well-known community)\n"
10097 "Do not export to next AS (well-known community)\n"
10098 "community number\n"
10099 "Do not send outside local AS (well-known community)\n"
10100 "Do not advertise to any peer (well-known community)\n"
10101 "Do not export to next AS (well-known community)\n"
10102 "Exact match of the communities")
10103
10104ALIAS (show_bgp_community_exact,
10105 show_bgp_ipv6_community4_exact_cmd,
10106 "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",
10107 SHOW_STR
10108 BGP_STR
10109 "Address family\n"
10110 "Display routes matching the communities\n"
10111 "community number\n"
10112 "Do not send outside local AS (well-known community)\n"
10113 "Do not advertise to any peer (well-known community)\n"
10114 "Do not export to next AS (well-known community)\n"
10115 "community number\n"
10116 "Do not send outside local AS (well-known community)\n"
10117 "Do not advertise to any peer (well-known community)\n"
10118 "Do not export to next AS (well-known community)\n"
10119 "community number\n"
10120 "Do not send outside local AS (well-known community)\n"
10121 "Do not advertise to any peer (well-known community)\n"
10122 "Do not export to next AS (well-known community)\n"
10123 "community number\n"
10124 "Do not send outside local AS (well-known community)\n"
10125 "Do not advertise to any peer (well-known community)\n"
10126 "Do not export to next AS (well-known community)\n"
10127 "Exact match of the communities")
10128
10129/* old command */
10130DEFUN (show_ipv6_bgp_community_exact,
10131 show_ipv6_bgp_community_exact_cmd,
10132 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10133 SHOW_STR
10134 IPV6_STR
10135 BGP_STR
10136 "Display routes matching the communities\n"
10137 "community number\n"
10138 "Do not send outside local AS (well-known community)\n"
10139 "Do not advertise to any peer (well-known community)\n"
10140 "Do not export to next AS (well-known community)\n"
10141 "Exact match of the communities")
10142{
10143 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10144}
10145
10146/* old command */
10147ALIAS (show_ipv6_bgp_community_exact,
10148 show_ipv6_bgp_community2_exact_cmd,
10149 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10150 SHOW_STR
10151 IPV6_STR
10152 BGP_STR
10153 "Display routes matching the communities\n"
10154 "community number\n"
10155 "Do not send outside local AS (well-known community)\n"
10156 "Do not advertise to any peer (well-known community)\n"
10157 "Do not export to next AS (well-known community)\n"
10158 "community number\n"
10159 "Do not send outside local AS (well-known community)\n"
10160 "Do not advertise to any peer (well-known community)\n"
10161 "Do not export to next AS (well-known community)\n"
10162 "Exact match of the communities")
10163
10164/* old command */
10165ALIAS (show_ipv6_bgp_community_exact,
10166 show_ipv6_bgp_community3_exact_cmd,
10167 "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",
10168 SHOW_STR
10169 IPV6_STR
10170 BGP_STR
10171 "Display routes matching the communities\n"
10172 "community number\n"
10173 "Do not send outside local AS (well-known community)\n"
10174 "Do not advertise to any peer (well-known community)\n"
10175 "Do not export to next AS (well-known community)\n"
10176 "community number\n"
10177 "Do not send outside local AS (well-known community)\n"
10178 "Do not advertise to any peer (well-known community)\n"
10179 "Do not export to next AS (well-known community)\n"
10180 "community number\n"
10181 "Do not send outside local AS (well-known community)\n"
10182 "Do not advertise to any peer (well-known community)\n"
10183 "Do not export to next AS (well-known community)\n"
10184 "Exact match of the communities")
10185
10186/* old command */
10187ALIAS (show_ipv6_bgp_community_exact,
10188 show_ipv6_bgp_community4_exact_cmd,
10189 "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",
10190 SHOW_STR
10191 IPV6_STR
10192 BGP_STR
10193 "Display routes matching the communities\n"
10194 "community number\n"
10195 "Do not send outside local AS (well-known community)\n"
10196 "Do not advertise to any peer (well-known community)\n"
10197 "Do not export to next AS (well-known community)\n"
10198 "community number\n"
10199 "Do not send outside local AS (well-known community)\n"
10200 "Do not advertise to any peer (well-known community)\n"
10201 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
10211
10212/* old command */
10213DEFUN (show_ipv6_mbgp_community,
10214 show_ipv6_mbgp_community_cmd,
10215 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
10216 SHOW_STR
10217 IPV6_STR
10218 MBGP_STR
10219 "Display routes matching the communities\n"
10220 "community number\n"
10221 "Do not send outside local AS (well-known community)\n"
10222 "Do not advertise to any peer (well-known community)\n"
10223 "Do not export to next AS (well-known community)\n")
10224{
10225 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
10226}
10227
10228/* old command */
10229ALIAS (show_ipv6_mbgp_community,
10230 show_ipv6_mbgp_community2_cmd,
10231 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10232 SHOW_STR
10233 IPV6_STR
10234 MBGP_STR
10235 "Display routes matching the communities\n"
10236 "community number\n"
10237 "Do not send outside local AS (well-known community)\n"
10238 "Do not advertise to any peer (well-known community)\n"
10239 "Do not export to next AS (well-known community)\n"
10240 "community number\n"
10241 "Do not send outside local AS (well-known community)\n"
10242 "Do not advertise to any peer (well-known community)\n"
10243 "Do not export to next AS (well-known community)\n")
10244
10245/* old command */
10246ALIAS (show_ipv6_mbgp_community,
10247 show_ipv6_mbgp_community3_cmd,
10248 "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)",
10249 SHOW_STR
10250 IPV6_STR
10251 MBGP_STR
10252 "Display routes matching the communities\n"
10253 "community number\n"
10254 "Do not send outside local AS (well-known community)\n"
10255 "Do not advertise to any peer (well-known community)\n"
10256 "Do not export to next AS (well-known community)\n"
10257 "community number\n"
10258 "Do not send outside local AS (well-known community)\n"
10259 "Do not advertise to any peer (well-known community)\n"
10260 "Do not export to next AS (well-known community)\n"
10261 "community number\n"
10262 "Do not send outside local AS (well-known community)\n"
10263 "Do not advertise to any peer (well-known community)\n"
10264 "Do not export to next AS (well-known community)\n")
10265
10266/* old command */
10267ALIAS (show_ipv6_mbgp_community,
10268 show_ipv6_mbgp_community4_cmd,
10269 "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)",
10270 SHOW_STR
10271 IPV6_STR
10272 MBGP_STR
10273 "Display routes matching the communities\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 "community number\n"
10279 "Do not send outside local AS (well-known community)\n"
10280 "Do not advertise to any peer (well-known community)\n"
10281 "Do not export to next AS (well-known community)\n"
10282 "community number\n"
10283 "Do not send outside local AS (well-known community)\n"
10284 "Do not advertise to any peer (well-known community)\n"
10285 "Do not export to next AS (well-known community)\n"
10286 "community number\n"
10287 "Do not send outside local AS (well-known community)\n"
10288 "Do not advertise to any peer (well-known community)\n"
10289 "Do not export to next AS (well-known community)\n")
10290
10291/* old command */
10292DEFUN (show_ipv6_mbgp_community_exact,
10293 show_ipv6_mbgp_community_exact_cmd,
10294 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10295 SHOW_STR
10296 IPV6_STR
10297 MBGP_STR
10298 "Display routes matching the communities\n"
10299 "community number\n"
10300 "Do not send outside local AS (well-known community)\n"
10301 "Do not advertise to any peer (well-known community)\n"
10302 "Do not export to next AS (well-known community)\n"
10303 "Exact match of the communities")
10304{
10305 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
10306}
10307
10308/* old command */
10309ALIAS (show_ipv6_mbgp_community_exact,
10310 show_ipv6_mbgp_community2_exact_cmd,
10311 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10312 SHOW_STR
10313 IPV6_STR
10314 MBGP_STR
10315 "Display routes matching the communities\n"
10316 "community number\n"
10317 "Do not send outside local AS (well-known community)\n"
10318 "Do not advertise to any peer (well-known community)\n"
10319 "Do not export to next AS (well-known community)\n"
10320 "community number\n"
10321 "Do not send outside local AS (well-known community)\n"
10322 "Do not advertise to any peer (well-known community)\n"
10323 "Do not export to next AS (well-known community)\n"
10324 "Exact match of the communities")
10325
10326/* old command */
10327ALIAS (show_ipv6_mbgp_community_exact,
10328 show_ipv6_mbgp_community3_exact_cmd,
10329 "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",
10330 SHOW_STR
10331 IPV6_STR
10332 MBGP_STR
10333 "Display routes matching the communities\n"
10334 "community number\n"
10335 "Do not send outside local AS (well-known community)\n"
10336 "Do not advertise to any peer (well-known community)\n"
10337 "Do not export to next AS (well-known community)\n"
10338 "community number\n"
10339 "Do not send outside local AS (well-known community)\n"
10340 "Do not advertise to any peer (well-known community)\n"
10341 "Do not export to next AS (well-known community)\n"
10342 "community number\n"
10343 "Do not send outside local AS (well-known community)\n"
10344 "Do not advertise to any peer (well-known community)\n"
10345 "Do not export to next AS (well-known community)\n"
10346 "Exact match of the communities")
10347
10348/* old command */
10349ALIAS (show_ipv6_mbgp_community_exact,
10350 show_ipv6_mbgp_community4_exact_cmd,
10351 "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",
10352 SHOW_STR
10353 IPV6_STR
10354 MBGP_STR
10355 "Display routes matching the communities\n"
10356 "community number\n"
10357 "Do not send outside local AS (well-known community)\n"
10358 "Do not advertise to any peer (well-known community)\n"
10359 "Do not export to next AS (well-known community)\n"
10360 "community number\n"
10361 "Do not send outside local AS (well-known community)\n"
10362 "Do not advertise to any peer (well-known community)\n"
10363 "Do not export to next AS (well-known community)\n"
10364 "community number\n"
10365 "Do not send outside local AS (well-known community)\n"
10366 "Do not advertise to any peer (well-known community)\n"
10367 "Do not export to next AS (well-known community)\n"
10368 "community number\n"
10369 "Do not send outside local AS (well-known community)\n"
10370 "Do not advertise to any peer (well-known community)\n"
10371 "Do not export to next AS (well-known community)\n"
10372 "Exact match of the communities")
Lou Bergerf9b6c392016-01-12 13:42:09 -050010373
Lou Berger651b4022016-01-12 13:42:07 -050010374DEFUN (show_bgp_ipv4_community,
10375 show_bgp_ipv4_community_cmd,
10376 "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010377 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010378 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010379 IP_STR
paul718e3742002-12-13 20:15:29 +000010380 "Display routes matching the communities\n"
10381 "community number\n"
10382 "Do not send outside local AS (well-known community)\n"
10383 "Do not advertise to any peer (well-known community)\n"
10384 "Do not export to next AS (well-known community)\n")
10385{
Michael Lambert95cbbd22010-07-23 14:43:04 -040010386 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010387}
10388
Lou Berger651b4022016-01-12 13:42:07 -050010389ALIAS (show_bgp_ipv4_community,
10390 show_bgp_ipv4_community2_cmd,
10391 "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 +000010392 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010393 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010394 IP_STR
paul718e3742002-12-13 20:15:29 +000010395 "Display routes matching the communities\n"
10396 "community number\n"
10397 "Do not send outside local AS (well-known community)\n"
10398 "Do not advertise to any peer (well-known community)\n"
10399 "Do not export to next AS (well-known community)\n"
10400 "community number\n"
10401 "Do not send outside local AS (well-known community)\n"
10402 "Do not advertise to any peer (well-known community)\n"
10403 "Do not export to next AS (well-known community)\n")
10404
Lou Berger651b4022016-01-12 13:42:07 -050010405ALIAS (show_bgp_ipv4_community,
10406 show_bgp_ipv4_community3_cmd,
10407 "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 +000010408 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010409 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010410 IP_STR
paul718e3742002-12-13 20:15:29 +000010411 "Display routes matching the communities\n"
10412 "community number\n"
10413 "Do not send outside local AS (well-known community)\n"
10414 "Do not advertise to any peer (well-known community)\n"
10415 "Do not export to next AS (well-known community)\n"
10416 "community number\n"
10417 "Do not send outside local AS (well-known community)\n"
10418 "Do not advertise to any peer (well-known community)\n"
10419 "Do not export to next AS (well-known community)\n"
10420 "community number\n"
10421 "Do not send outside local AS (well-known community)\n"
10422 "Do not advertise to any peer (well-known community)\n"
10423 "Do not export to next AS (well-known community)\n")
10424
Lou Berger651b4022016-01-12 13:42:07 -050010425ALIAS (show_bgp_ipv4_community,
10426 show_bgp_ipv4_community4_cmd,
10427 "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 +000010428 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010429 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010430 IP_STR
paul718e3742002-12-13 20:15:29 +000010431 "Display routes matching the communities\n"
10432 "community number\n"
10433 "Do not send outside local AS (well-known community)\n"
10434 "Do not advertise to any peer (well-known community)\n"
10435 "Do not export to next AS (well-known community)\n"
10436 "community number\n"
10437 "Do not send outside local AS (well-known community)\n"
10438 "Do not advertise to any peer (well-known community)\n"
10439 "Do not export to next AS (well-known community)\n"
10440 "community number\n"
10441 "Do not send outside local AS (well-known community)\n"
10442 "Do not advertise to any peer (well-known community)\n"
10443 "Do not export to next AS (well-known community)\n"
10444 "community number\n"
10445 "Do not send outside local AS (well-known community)\n"
10446 "Do not advertise to any peer (well-known community)\n"
10447 "Do not export to next AS (well-known community)\n")
10448
Lou Berger651b4022016-01-12 13:42:07 -050010449DEFUN (show_bgp_ipv4_safi_community,
10450 show_bgp_ipv4_safi_community_cmd,
10451 "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010452 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010453 BGP_STR
10454 "Address family\n"
10455 "Address Family modifier\n"
10456 "Address Family modifier\n"
10457 "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{
10463 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -040010464 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +000010465
Michael Lambert95cbbd22010-07-23 14:43:04 -040010466 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010467}
10468
Lou Berger651b4022016-01-12 13:42:07 -050010469ALIAS (show_bgp_ipv4_safi_community,
10470 show_bgp_ipv4_safi_community2_cmd,
10471 "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 +000010472 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010473 BGP_STR
10474 "Address family\n"
10475 "Address Family modifier\n"
10476 "Address Family modifier\n"
10477 "Display routes matching the communities\n"
10478 "community number\n"
10479 "Do not send outside local AS (well-known community)\n"
10480 "Do not advertise to any peer (well-known community)\n"
10481 "Do not export to next AS (well-known community)\n"
10482 "community number\n"
10483 "Do not send outside local AS (well-known community)\n"
10484 "Do not advertise to any peer (well-known community)\n"
10485 "Do not export to next AS (well-known community)\n")
10486
Lou Berger651b4022016-01-12 13:42:07 -050010487ALIAS (show_bgp_ipv4_safi_community,
10488 show_bgp_ipv4_safi_community3_cmd,
10489 "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 +000010490 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010491 BGP_STR
10492 "Address family\n"
10493 "Address Family modifier\n"
10494 "Address Family modifier\n"
10495 "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
Lou Berger651b4022016-01-12 13:42:07 -050010509ALIAS (show_bgp_ipv4_safi_community,
10510 show_bgp_ipv4_safi_community4_cmd,
10511 "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 +000010512 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010513 BGP_STR
10514 "Address family\n"
10515 "Address Family modifier\n"
10516 "Address Family modifier\n"
10517 "Display routes matching the communities\n"
10518 "community number\n"
10519 "Do not send outside local AS (well-known community)\n"
10520 "Do not advertise to any peer (well-known community)\n"
10521 "Do not export to next AS (well-known community)\n"
10522 "community number\n"
10523 "Do not send outside local AS (well-known community)\n"
10524 "Do not advertise to any peer (well-known community)\n"
10525 "Do not export to next AS (well-known community)\n"
10526 "community number\n"
10527 "Do not send outside local AS (well-known community)\n"
10528 "Do not advertise to any peer (well-known community)\n"
10529 "Do not export to next AS (well-known community)\n"
10530 "community number\n"
10531 "Do not send outside local AS (well-known community)\n"
10532 "Do not advertise to any peer (well-known community)\n"
10533 "Do not export to next AS (well-known community)\n")
10534
Michael Lambert95cbbd22010-07-23 14:43:04 -040010535DEFUN (show_bgp_view_afi_safi_community_all,
10536 show_bgp_view_afi_safi_community_all_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010537 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Michael Lambert95cbbd22010-07-23 14:43:04 -040010538 SHOW_STR
10539 BGP_STR
10540 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010541 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010542 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010543 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010544 "Address Family modifier\n"
10545 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +000010546 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -040010547{
10548 int afi;
10549 int safi;
10550 struct bgp *bgp;
10551
10552 /* BGP structure lookup. */
10553 bgp = bgp_lookup_by_name (argv[0]);
10554 if (bgp == NULL)
10555 {
10556 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10557 return CMD_WARNING;
10558 }
10559
Michael Lambert95cbbd22010-07-23 14:43:04 -040010560 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10561 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010562 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
10563}
10564
10565DEFUN (show_bgp_view_afi_safi_community,
10566 show_bgp_view_afi_safi_community_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010567 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -040010568 SHOW_STR
10569 BGP_STR
10570 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010571 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010572 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010573 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010574 "Address family modifier\n"
10575 "Address family modifier\n"
10576 "Display routes matching the communities\n"
10577 "community number\n"
10578 "Do not send outside local AS (well-known community)\n"
10579 "Do not advertise to any peer (well-known community)\n"
10580 "Do not export to next AS (well-known community)\n")
10581{
10582 int afi;
10583 int safi;
10584
Michael Lambert95cbbd22010-07-23 14:43:04 -040010585 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10586 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10587 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010588}
10589
10590ALIAS (show_bgp_view_afi_safi_community,
10591 show_bgp_view_afi_safi_community2_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010592 "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 -040010593 SHOW_STR
10594 BGP_STR
10595 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010596 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010597 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010598 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010599 "Address family modifier\n"
10600 "Address family modifier\n"
10601 "Display routes matching the communities\n"
10602 "community number\n"
10603 "Do not send outside local AS (well-known community)\n"
10604 "Do not advertise to any peer (well-known community)\n"
10605 "Do not export to next AS (well-known community)\n"
10606 "community number\n"
10607 "Do not send outside local AS (well-known community)\n"
10608 "Do not advertise to any peer (well-known community)\n"
10609 "Do not export to next AS (well-known community)\n")
10610
10611ALIAS (show_bgp_view_afi_safi_community,
10612 show_bgp_view_afi_safi_community3_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010613 "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 -040010614 SHOW_STR
10615 BGP_STR
10616 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010617 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010618 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010619 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010620 "Address family modifier\n"
10621 "Address family modifier\n"
10622 "Display routes matching the communities\n"
10623 "community number\n"
10624 "Do not send outside local AS (well-known community)\n"
10625 "Do not advertise to any peer (well-known community)\n"
10626 "Do not export to next AS (well-known community)\n"
10627 "community number\n"
10628 "Do not send outside local AS (well-known community)\n"
10629 "Do not advertise to any peer (well-known community)\n"
10630 "Do not export to next AS (well-known community)\n"
10631 "community number\n"
10632 "Do not send outside local AS (well-known community)\n"
10633 "Do not advertise to any peer (well-known community)\n"
10634 "Do not export to next AS (well-known community)\n")
10635
10636ALIAS (show_bgp_view_afi_safi_community,
10637 show_bgp_view_afi_safi_community4_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010638 "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 -040010639 SHOW_STR
10640 BGP_STR
10641 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010642 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010643 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010644 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010645 "Address family modifier\n"
10646 "Address family modifier\n"
10647 "Display routes matching the communities\n"
10648 "community number\n"
10649 "Do not send outside local AS (well-known community)\n"
10650 "Do not advertise to any peer (well-known community)\n"
10651 "Do not export to next AS (well-known community)\n"
10652 "community number\n"
10653 "Do not send outside local AS (well-known community)\n"
10654 "Do not advertise to any peer (well-known community)\n"
10655 "Do not export to next AS (well-known community)\n"
10656 "community number\n"
10657 "Do not send outside local AS (well-known community)\n"
10658 "Do not advertise to any peer (well-known community)\n"
10659 "Do not export to next AS (well-known community)\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
Lou Berger651b4022016-01-12 13:42:07 -050010665DEFUN (show_bgp_ipv4_community_exact,
10666 show_bgp_ipv4_community_exact_cmd,
10667 "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010668 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010669 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010670 IP_STR
paul718e3742002-12-13 20:15:29 +000010671 "Display routes matching the communities\n"
10672 "community number\n"
10673 "Do not send outside local AS (well-known community)\n"
10674 "Do not advertise to any peer (well-known community)\n"
10675 "Do not export to next AS (well-known community)\n"
10676 "Exact match of the communities")
10677{
Michael Lambert95cbbd22010-07-23 14:43:04 -040010678 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010679}
10680
Lou Berger651b4022016-01-12 13:42:07 -050010681ALIAS (show_bgp_ipv4_community_exact,
10682 show_bgp_ipv4_community2_exact_cmd,
10683 "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 +000010684 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010685 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010686 IP_STR
paul718e3742002-12-13 20:15:29 +000010687 "Display routes matching the communities\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 "Exact match of the communities")
10697
Lou Berger651b4022016-01-12 13:42:07 -050010698ALIAS (show_bgp_ipv4_community_exact,
10699 show_bgp_ipv4_community3_exact_cmd,
10700 "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 +000010701 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010702 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010703 IP_STR
paul718e3742002-12-13 20:15:29 +000010704 "Display routes matching the communities\n"
10705 "community number\n"
10706 "Do not send outside local AS (well-known community)\n"
10707 "Do not advertise to any peer (well-known community)\n"
10708 "Do not export to next AS (well-known community)\n"
10709 "community number\n"
10710 "Do not send outside local AS (well-known community)\n"
10711 "Do not advertise to any peer (well-known community)\n"
10712 "Do not export to next AS (well-known community)\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 -050010719ALIAS (show_bgp_ipv4_community_exact,
10720 show_bgp_ipv4_community4_exact_cmd,
10721 "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 +000010722 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010723 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010724 IP_STR
paul718e3742002-12-13 20:15:29 +000010725 "Display routes matching the communities\n"
10726 "community number\n"
10727 "Do not send outside local AS (well-known community)\n"
10728 "Do not advertise to any peer (well-known community)\n"
10729 "Do not export to next AS (well-known community)\n"
10730 "community number\n"
10731 "Do not send outside local AS (well-known community)\n"
10732 "Do not advertise to any peer (well-known community)\n"
10733 "Do not export to next AS (well-known community)\n"
10734 "community number\n"
10735 "Do not send outside local AS (well-known community)\n"
10736 "Do not advertise to any peer (well-known community)\n"
10737 "Do not export to next AS (well-known community)\n"
10738 "community number\n"
10739 "Do not send outside local AS (well-known community)\n"
10740 "Do not advertise to any peer (well-known community)\n"
10741 "Do not export to next AS (well-known community)\n"
10742 "Exact match of the communities")
10743
Lou Berger651b4022016-01-12 13:42:07 -050010744DEFUN (show_bgp_ipv4_safi_community4_exact,
10745 show_bgp_ipv4_safi_community_exact_cmd,
10746 "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010747 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010748 BGP_STR
10749 "Address family\n"
10750 "Address Family modifier\n"
10751 "Address Family modifier\n"
10752 "Display routes matching the communities\n"
10753 "community number\n"
10754 "Do not send outside local AS (well-known community)\n"
10755 "Do not advertise to any peer (well-known community)\n"
10756 "Do not export to next AS (well-known community)\n"
10757 "Exact match of the communities")
10758{
10759 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -040010760 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +000010761
Michael Lambert95cbbd22010-07-23 14:43:04 -040010762 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010763}
10764
Lou Berger651b4022016-01-12 13:42:07 -050010765ALIAS (show_bgp_ipv4_safi_community4_exact,
10766 show_bgp_ipv4_safi_community2_exact_cmd,
10767 "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 +000010768 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010769 BGP_STR
10770 "Address family\n"
10771 "Address Family modifier\n"
10772 "Address Family modifier\n"
10773 "Display routes matching the communities\n"
10774 "community number\n"
10775 "Do not send outside local AS (well-known community)\n"
10776 "Do not advertise to any peer (well-known community)\n"
10777 "Do not export to next AS (well-known community)\n"
10778 "community number\n"
10779 "Do not send outside local AS (well-known community)\n"
10780 "Do not advertise to any peer (well-known community)\n"
10781 "Do not export to next AS (well-known community)\n"
10782 "Exact match of the communities")
10783
Lou Berger651b4022016-01-12 13:42:07 -050010784ALIAS (show_bgp_ipv4_safi_community4_exact,
10785 show_bgp_ipv4_safi_community3_exact_cmd,
10786 "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 +000010787 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010788 BGP_STR
10789 "Address family\n"
10790 "Address Family modifier\n"
10791 "Address Family modifier\n"
10792 "Display routes matching the communities\n"
10793 "community number\n"
10794 "Do not send outside local AS (well-known community)\n"
10795 "Do not advertise to any peer (well-known community)\n"
10796 "Do not export to next AS (well-known community)\n"
10797 "community number\n"
10798 "Do not send outside local AS (well-known community)\n"
10799 "Do not advertise to any peer (well-known community)\n"
10800 "Do not export to next AS (well-known community)\n"
10801 "community number\n"
10802 "Do not send outside local AS (well-known community)\n"
10803 "Do not advertise to any peer (well-known community)\n"
10804 "Do not export to next AS (well-known community)\n"
10805 "Exact match of the communities")
10806
Lou Berger651b4022016-01-12 13:42:07 -050010807ALIAS (show_bgp_ipv4_safi_community4_exact,
10808 show_bgp_ipv4_safi_community4_exact_cmd,
10809 "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 +000010810 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010811 BGP_STR
10812 "Address family\n"
10813 "Address Family modifier\n"
10814 "Address Family modifier\n"
10815 "Display routes matching the communities\n"
10816 "community number\n"
10817 "Do not send outside local AS (well-known community)\n"
10818 "Do not advertise to any peer (well-known community)\n"
10819 "Do not export to next AS (well-known community)\n"
10820 "community number\n"
10821 "Do not send outside local AS (well-known community)\n"
10822 "Do not advertise to any peer (well-known community)\n"
10823 "Do not export to next AS (well-known community)\n"
10824 "community number\n"
10825 "Do not send outside local AS (well-known community)\n"
10826 "Do not advertise to any peer (well-known community)\n"
10827 "Do not export to next AS (well-known community)\n"
10828 "community number\n"
10829 "Do not send outside local AS (well-known community)\n"
10830 "Do not advertise to any peer (well-known community)\n"
10831 "Do not export to next AS (well-known community)\n"
10832 "Exact match of the communities")
10833
Lou Bergerf9b6c392016-01-12 13:42:09 -050010834DEFUN (show_bgp_ipv6_safi_community,
10835 show_bgp_ipv6_safi_community_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010836 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010837 SHOW_STR
10838 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010839 "Address family\n"
10840 "Address family modifier\n"
10841 "Address family modifier\n"
10842 "Address family modifier\n"
10843 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010844 "Display routes matching the communities\n"
10845 "community number\n"
10846 "Do not send outside local AS (well-known community)\n"
10847 "Do not advertise to any peer (well-known community)\n"
10848 "Do not export to next AS (well-known community)\n")
10849{
Lou Berger651b4022016-01-12 13:42:07 -050010850 safi_t safi;
10851
10852 if (bgp_parse_safi(argv[0], &safi)) {
10853 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10854 return CMD_WARNING;
10855 }
10856 return bgp_show_community (vty, NULL, argc-1, argv+1, 0, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000010857}
10858
Lou Bergerf9b6c392016-01-12 13:42:09 -050010859ALIAS (show_bgp_ipv6_safi_community,
10860 show_bgp_ipv6_safi_community2_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010861 "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 +000010862 SHOW_STR
10863 BGP_STR
10864 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010865 "Address family modifier\n"
10866 "Address family modifier\n"
10867 "Address family modifier\n"
10868 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010869 "Display routes matching the communities\n"
10870 "community number\n"
10871 "Do not send outside local AS (well-known community)\n"
10872 "Do not advertise to any peer (well-known community)\n"
10873 "Do not export to next AS (well-known community)\n"
10874 "community number\n"
10875 "Do not send outside local AS (well-known community)\n"
10876 "Do not advertise to any peer (well-known community)\n"
10877 "Do not export to next AS (well-known community)\n")
10878
Lou Bergerf9b6c392016-01-12 13:42:09 -050010879ALIAS (show_bgp_ipv6_safi_community,
10880 show_bgp_ipv6_safi_community3_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010881 "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 +000010882 SHOW_STR
10883 BGP_STR
10884 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010885 "Address family modifier\n"
10886 "Address family modifier\n"
10887 "Address family modifier\n"
10888 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010889 "Display routes matching the communities\n"
10890 "community number\n"
10891 "Do not send outside local AS (well-known community)\n"
10892 "Do not advertise to any peer (well-known community)\n"
10893 "Do not export to next AS (well-known community)\n"
10894 "community number\n"
10895 "Do not send outside local AS (well-known community)\n"
10896 "Do not advertise to any peer (well-known community)\n"
10897 "Do not export to next AS (well-known community)\n"
10898 "community number\n"
10899 "Do not send outside local AS (well-known community)\n"
10900 "Do not advertise to any peer (well-known community)\n"
10901 "Do not export to next AS (well-known community)\n")
10902
Lou Bergerf9b6c392016-01-12 13:42:09 -050010903ALIAS (show_bgp_ipv6_safi_community,
10904 show_bgp_ipv6_safi_community4_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010905 "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 +000010906 SHOW_STR
10907 BGP_STR
10908 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010909 "Address family modifier\n"
10910 "Address family modifier\n"
10911 "Address family modifier\n"
10912 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010913 "Display routes matching the communities\n"
10914 "community number\n"
10915 "Do not send outside local AS (well-known community)\n"
10916 "Do not advertise to any peer (well-known community)\n"
10917 "Do not export to next AS (well-known community)\n"
10918 "community number\n"
10919 "Do not send outside local AS (well-known community)\n"
10920 "Do not advertise to any peer (well-known community)\n"
10921 "Do not export to next AS (well-known community)\n"
10922 "community number\n"
10923 "Do not send outside local AS (well-known community)\n"
10924 "Do not advertise to any peer (well-known community)\n"
10925 "Do not export to next AS (well-known community)\n"
10926 "community number\n"
10927 "Do not send outside local AS (well-known community)\n"
10928 "Do not advertise to any peer (well-known community)\n"
10929 "Do not export to next AS (well-known community)\n")
10930
paul718e3742002-12-13 20:15:29 +000010931
Lou Bergerf9b6c392016-01-12 13:42:09 -050010932DEFUN (show_bgp_ipv6_safi_community_exact,
10933 show_bgp_ipv6_safi_community_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010934 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010935 SHOW_STR
10936 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010937 "Address family\n"
10938 "Address family modifier\n"
10939 "Address family modifier\n"
10940 "Address family modifier\n"
10941 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010942 "Display routes matching the communities\n"
10943 "community number\n"
10944 "Do not send outside local AS (well-known community)\n"
10945 "Do not advertise to any peer (well-known community)\n"
10946 "Do not export to next AS (well-known community)\n"
10947 "Exact match of the communities")
10948{
Lou Berger651b4022016-01-12 13:42:07 -050010949 safi_t safi;
10950
10951 if (bgp_parse_safi(argv[0], &safi)) {
10952 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10953 return CMD_WARNING;
10954 }
10955 return bgp_show_community (vty, NULL, argc-1, argv+1, 1, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000010956}
10957
paul718e3742002-12-13 20:15:29 +000010958
10959ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010960 show_bgp_ipv6_safi_community2_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010961 "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 +000010962 SHOW_STR
10963 BGP_STR
10964 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010965 "Address family modifier\n"
10966 "Address family modifier\n"
10967 "Address family modifier\n"
10968 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010969 "Display routes matching the communities\n"
10970 "community number\n"
10971 "Do not send outside local AS (well-known community)\n"
10972 "Do not advertise to any peer (well-known community)\n"
10973 "Do not export to next AS (well-known community)\n"
10974 "community number\n"
10975 "Do not send outside local AS (well-known community)\n"
10976 "Do not advertise to any peer (well-known community)\n"
10977 "Do not export to next AS (well-known community)\n"
10978 "Exact match of the communities")
10979
10980ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010981 show_bgp_ipv6_safi_community3_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010982 "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 +000010983 SHOW_STR
10984 BGP_STR
10985 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010986 "Address family modifier\n"
10987 "Address family modifier\n"
10988 "Address family modifier\n"
10989 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010990 "Display routes matching the communities\n"
10991 "community number\n"
10992 "Do not send outside local AS (well-known community)\n"
10993 "Do not advertise to any peer (well-known community)\n"
10994 "Do not export to next AS (well-known community)\n"
10995 "community number\n"
10996 "Do not send outside local AS (well-known community)\n"
10997 "Do not advertise to any peer (well-known community)\n"
10998 "Do not export to next AS (well-known community)\n"
10999 "community number\n"
11000 "Do not send outside local AS (well-known community)\n"
11001 "Do not advertise to any peer (well-known community)\n"
11002 "Do not export to next AS (well-known community)\n"
11003 "Exact match of the communities")
11004
11005ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050011006 show_bgp_ipv6_safi_community4_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011007 "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 +000011008 SHOW_STR
11009 BGP_STR
11010 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050011011 "Address family modifier\n"
11012 "Address family modifier\n"
11013 "Address family modifier\n"
11014 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000011015 "Display routes matching the communities\n"
11016 "community number\n"
11017 "Do not send outside local AS (well-known community)\n"
11018 "Do not advertise to any peer (well-known community)\n"
11019 "Do not export to next AS (well-known community)\n"
11020 "community number\n"
11021 "Do not send outside local AS (well-known community)\n"
11022 "Do not advertise to any peer (well-known community)\n"
11023 "Do not export to next AS (well-known community)\n"
11024 "community number\n"
11025 "Do not send outside local AS (well-known community)\n"
11026 "Do not advertise to any peer (well-known community)\n"
11027 "Do not export to next AS (well-known community)\n"
11028 "community number\n"
11029 "Do not send outside local AS (well-known community)\n"
11030 "Do not advertise to any peer (well-known community)\n"
11031 "Do not export to next AS (well-known community)\n"
11032 "Exact match of the communities")
11033
paul94f2b392005-06-28 12:44:16 +000011034static int
paulfd79ac92004-10-13 05:06:08 +000011035bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -040011036 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +000011037{
11038 struct community_list *list;
11039
hassofee6e4e2005-02-02 16:29:31 +000011040 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +000011041 if (list == NULL)
11042 {
11043 vty_out (vty, "%% %s is not a valid community-list name%s", com,
11044 VTY_NEWLINE);
11045 return CMD_WARNING;
11046 }
11047
ajs5a646652004-11-05 01:25:55 +000011048 return bgp_show (vty, NULL, afi, safi,
11049 (exact ? bgp_show_type_community_list_exact :
11050 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +000011051}
11052
Lou Bergerf9b6c392016-01-12 13:42:09 -050011053DEFUN (show_ip_bgp_community_list,
11054 show_ip_bgp_community_list_cmd,
11055 "show ip bgp community-list (<1-500>|WORD)",
11056 SHOW_STR
11057 IP_STR
11058 BGP_STR
11059 "Display routes matching the community-list\n"
11060 "community-list number\n"
11061 "community-list name\n")
11062{
11063 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
11064}
11065
11066DEFUN (show_ip_bgp_ipv4_community_list,
11067 show_ip_bgp_ipv4_community_list_cmd,
11068 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
11069 SHOW_STR
11070 IP_STR
11071 BGP_STR
11072 "Address family\n"
11073 "Address Family modifier\n"
11074 "Address Family modifier\n"
11075 "Display routes matching the community-list\n"
11076 "community-list number\n"
11077 "community-list name\n")
11078{
11079 if (strncmp (argv[0], "m", 1) == 0)
11080 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
11081
11082 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
11083}
11084
11085DEFUN (show_ip_bgp_community_list_exact,
11086 show_ip_bgp_community_list_exact_cmd,
11087 "show ip bgp community-list (<1-500>|WORD) exact-match",
11088 SHOW_STR
11089 IP_STR
11090 BGP_STR
11091 "Display routes matching the community-list\n"
11092 "community-list number\n"
11093 "community-list name\n"
11094 "Exact match of the communities\n")
11095{
11096 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
11097}
11098
11099DEFUN (show_ip_bgp_ipv4_community_list_exact,
11100 show_ip_bgp_ipv4_community_list_exact_cmd,
11101 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
11102 SHOW_STR
11103 IP_STR
11104 BGP_STR
11105 "Address family\n"
11106 "Address Family modifier\n"
11107 "Address Family modifier\n"
11108 "Display routes matching the community-list\n"
11109 "community-list number\n"
11110 "community-list name\n"
11111 "Exact match of the communities\n")
11112{
11113 if (strncmp (argv[0], "m", 1) == 0)
11114 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
11115
11116 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
11117}
11118
Lou Bergerf9b6c392016-01-12 13:42:09 -050011119DEFUN (show_bgp_community_list,
11120 show_bgp_community_list_cmd,
11121 "show bgp community-list (<1-500>|WORD)",
11122 SHOW_STR
11123 BGP_STR
11124 "Display routes matching the community-list\n"
11125 "community-list number\n"
11126 "community-list name\n")
11127{
11128 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11129}
11130
11131ALIAS (show_bgp_community_list,
11132 show_bgp_ipv6_community_list_cmd,
11133 "show bgp ipv6 community-list (<1-500>|WORD)",
11134 SHOW_STR
11135 BGP_STR
11136 "Address family\n"
11137 "Display routes matching the community-list\n"
11138 "community-list number\n"
11139 "community-list name\n")
11140
11141/* old command */
11142DEFUN (show_ipv6_bgp_community_list,
11143 show_ipv6_bgp_community_list_cmd,
11144 "show ipv6 bgp community-list WORD",
11145 SHOW_STR
11146 IPV6_STR
11147 BGP_STR
11148 "Display routes matching the community-list\n"
11149 "community-list name\n")
11150{
11151 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11152}
11153
11154/* old command */
11155DEFUN (show_ipv6_mbgp_community_list,
11156 show_ipv6_mbgp_community_list_cmd,
11157 "show ipv6 mbgp community-list WORD",
11158 SHOW_STR
11159 IPV6_STR
11160 MBGP_STR
11161 "Display routes matching the community-list\n"
11162 "community-list name\n")
11163{
11164 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
11165}
11166
11167DEFUN (show_bgp_community_list_exact,
11168 show_bgp_community_list_exact_cmd,
11169 "show bgp community-list (<1-500>|WORD) exact-match",
11170 SHOW_STR
11171 BGP_STR
11172 "Display routes matching the community-list\n"
11173 "community-list number\n"
11174 "community-list name\n"
11175 "Exact match of the communities\n")
11176{
11177 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11178}
11179
11180ALIAS (show_bgp_community_list_exact,
11181 show_bgp_ipv6_community_list_exact_cmd,
11182 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
11183 SHOW_STR
11184 BGP_STR
11185 "Address family\n"
11186 "Display routes matching the community-list\n"
11187 "community-list number\n"
11188 "community-list name\n"
11189 "Exact match of the communities\n")
11190
11191/* old command */
11192DEFUN (show_ipv6_bgp_community_list_exact,
11193 show_ipv6_bgp_community_list_exact_cmd,
11194 "show ipv6 bgp community-list WORD exact-match",
11195 SHOW_STR
11196 IPV6_STR
11197 BGP_STR
11198 "Display routes matching the community-list\n"
11199 "community-list name\n"
11200 "Exact match of the communities\n")
11201{
11202 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11203}
11204
11205/* old command */
11206DEFUN (show_ipv6_mbgp_community_list_exact,
11207 show_ipv6_mbgp_community_list_exact_cmd,
11208 "show ipv6 mbgp community-list WORD exact-match",
11209 SHOW_STR
11210 IPV6_STR
11211 MBGP_STR
11212 "Display routes matching the community-list\n"
11213 "community-list name\n"
11214 "Exact match of the communities\n")
11215{
11216 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
11217}
Lou Bergerf9b6c392016-01-12 13:42:09 -050011218
Lou Berger651b4022016-01-12 13:42:07 -050011219DEFUN (show_bgp_ipv4_community_list,
11220 show_bgp_ipv4_community_list_cmd,
11221 "show bgp ipv4 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011222 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011223 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011224 IP_STR
paul718e3742002-12-13 20:15:29 +000011225 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011226 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011227 "community-list name\n")
11228{
11229 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
11230}
11231
Lou Berger651b4022016-01-12 13:42:07 -050011232DEFUN (show_bgp_ipv4_safi_community_list,
11233 show_bgp_ipv4_safi_community_list_cmd,
11234 "show bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011235 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011236 BGP_STR
11237 "Address family\n"
11238 "Address Family modifier\n"
11239 "Address Family modifier\n"
11240 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011241 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011242 "community-list name\n")
11243{
11244 if (strncmp (argv[0], "m", 1) == 0)
11245 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
11246
11247 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
11248}
11249
Lou Berger651b4022016-01-12 13:42:07 -050011250DEFUN (show_bgp_ipv4_community_list_exact,
11251 show_bgp_ipv4_community_list_exact_cmd,
11252 "show bgp ipv4 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011253 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011254 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011255 IP_STR
paul718e3742002-12-13 20:15:29 +000011256 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011257 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011258 "community-list name\n"
11259 "Exact match of the communities\n")
11260{
11261 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
11262}
11263
Lou Berger651b4022016-01-12 13:42:07 -050011264DEFUN (show_bgp_ipv4_safi_community_list_exact,
11265 show_bgp_ipv4_safi_community_list_exact_cmd,
11266 "show bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011267 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011268 BGP_STR
11269 "Address family\n"
11270 "Address Family modifier\n"
11271 "Address Family modifier\n"
11272 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011273 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011274 "community-list name\n"
11275 "Exact match of the communities\n")
11276{
11277 if (strncmp (argv[0], "m", 1) == 0)
11278 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
11279
11280 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
11281}
11282
Lou Bergerf9b6c392016-01-12 13:42:09 -050011283DEFUN (show_bgp_ipv6_safi_community_list,
11284 show_bgp_ipv6_safi_community_list_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011285 "show bgp ipv6 (encap|multicast|unicast|vpn) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011286 SHOW_STR
11287 BGP_STR
11288 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050011289 "Address family modifier\n"
11290 "Address family modifier\n"
11291 "Address family modifier\n"
11292 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000011293 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011294 "community-list number\n"
paule8e19462006-01-19 20:16:55 +000011295 "community-list name\n")
paul718e3742002-12-13 20:15:29 +000011296{
Lou Berger651b4022016-01-12 13:42:07 -050011297 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011298
Lou Berger651b4022016-01-12 13:42:07 -050011299 if (bgp_parse_safi(argv[0], &safi)) {
11300 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11301 return CMD_WARNING;
11302 }
11303 return bgp_show_community_list (vty, argv[1], 0, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000011304}
11305
Lou Bergerf9b6c392016-01-12 13:42:09 -050011306DEFUN (show_bgp_ipv6_safi_community_list_exact,
11307 show_bgp_ipv6_safi_community_list_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011308 "show bgp ipv6 (encap|multicast|unicast|vpn) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011309 SHOW_STR
11310 BGP_STR
11311 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050011312 "Address family modifier\n"
11313 "Address family modifier\n"
11314 "Address family modifier\n"
11315 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000011316 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011317 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011318 "community-list name\n"
11319 "Exact match of the communities\n")
paul718e3742002-12-13 20:15:29 +000011320{
Lou Berger651b4022016-01-12 13:42:07 -050011321 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011322
Lou Berger651b4022016-01-12 13:42:07 -050011323 if (bgp_parse_safi(argv[0], &safi)) {
11324 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11325 return CMD_WARNING;
11326 }
11327 return bgp_show_community_list (vty, argv[1], 1, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000011328}
David Lamparter6b0655a2014-06-04 06:53:35 +020011329
paul94f2b392005-06-28 12:44:16 +000011330static int
paulfd79ac92004-10-13 05:06:08 +000011331bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +000011332 safi_t safi, enum bgp_show_type type)
11333{
11334 int ret;
11335 struct prefix *p;
11336
11337 p = prefix_new();
11338
11339 ret = str2prefix (prefix, p);
11340 if (! ret)
11341 {
11342 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
11343 return CMD_WARNING;
11344 }
11345
ajs5a646652004-11-05 01:25:55 +000011346 ret = bgp_show (vty, NULL, afi, safi, type, p);
11347 prefix_free(p);
11348 return ret;
paul718e3742002-12-13 20:15:29 +000011349}
11350
Lou Bergerf9b6c392016-01-12 13:42:09 -050011351DEFUN (show_ip_bgp_prefix_longer,
11352 show_ip_bgp_prefix_longer_cmd,
11353 "show ip bgp A.B.C.D/M longer-prefixes",
11354 SHOW_STR
11355 IP_STR
11356 BGP_STR
11357 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11358 "Display route and more specific routes\n")
11359{
11360 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11361 bgp_show_type_prefix_longer);
11362}
11363
11364DEFUN (show_ip_bgp_flap_prefix_longer,
11365 show_ip_bgp_flap_prefix_longer_cmd,
11366 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
11367 SHOW_STR
11368 IP_STR
11369 BGP_STR
11370 "Display flap statistics of routes\n"
11371 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11372 "Display route and more specific routes\n")
11373{
11374 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11375 bgp_show_type_flap_prefix_longer);
11376}
11377
11378ALIAS (show_ip_bgp_flap_prefix_longer,
11379 show_ip_bgp_damp_flap_prefix_longer_cmd,
11380 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
11381 SHOW_STR
11382 IP_STR
11383 BGP_STR
11384 "Display detailed information about dampening\n"
11385 "Display flap statistics of routes\n"
11386 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11387 "Display route and more specific routes\n")
11388
11389DEFUN (show_ip_bgp_ipv4_prefix_longer,
11390 show_ip_bgp_ipv4_prefix_longer_cmd,
11391 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
11392 SHOW_STR
11393 IP_STR
11394 BGP_STR
11395 "Address family\n"
11396 "Address Family modifier\n"
11397 "Address Family modifier\n"
11398 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11399 "Display route and more specific routes\n")
11400{
11401 if (strncmp (argv[0], "m", 1) == 0)
11402 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
11403 bgp_show_type_prefix_longer);
11404
11405 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
11406 bgp_show_type_prefix_longer);
11407}
11408
11409DEFUN (show_ip_bgp_flap_address,
11410 show_ip_bgp_flap_address_cmd,
11411 "show ip bgp flap-statistics A.B.C.D",
11412 SHOW_STR
11413 IP_STR
11414 BGP_STR
11415 "Display flap statistics of routes\n"
11416 "Network in the BGP routing table to display\n")
11417{
11418 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11419 bgp_show_type_flap_address);
11420}
11421
11422ALIAS (show_ip_bgp_flap_address,
11423 show_ip_bgp_damp_flap_address_cmd,
11424 "show ip bgp dampening flap-statistics A.B.C.D",
11425 SHOW_STR
11426 IP_STR
11427 BGP_STR
11428 "Display detailed information about dampening\n"
11429 "Display flap statistics of routes\n"
11430 "Network in the BGP routing table to display\n")
11431
11432DEFUN (show_ip_bgp_flap_prefix,
11433 show_ip_bgp_flap_prefix_cmd,
11434 "show ip bgp flap-statistics A.B.C.D/M",
11435 SHOW_STR
11436 IP_STR
11437 BGP_STR
11438 "Display flap statistics of routes\n"
11439 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11440{
11441 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11442 bgp_show_type_flap_prefix);
11443}
11444
11445ALIAS (show_ip_bgp_flap_prefix,
11446 show_ip_bgp_damp_flap_prefix_cmd,
11447 "show ip bgp dampening flap-statistics A.B.C.D/M",
11448 SHOW_STR
11449 IP_STR
11450 BGP_STR
11451 "Display detailed information about dampening\n"
11452 "Display flap statistics of routes\n"
11453 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11454
Lou Bergerf9b6c392016-01-12 13:42:09 -050011455DEFUN (show_bgp_prefix_longer,
11456 show_bgp_prefix_longer_cmd,
11457 "show bgp X:X::X:X/M longer-prefixes",
11458 SHOW_STR
11459 BGP_STR
11460 "IPv6 prefix <network>/<length>\n"
11461 "Display route and more specific routes\n")
11462{
11463 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11464 bgp_show_type_prefix_longer);
11465}
11466
11467/* old command */
11468DEFUN (show_ipv6_bgp_prefix_longer,
11469 show_ipv6_bgp_prefix_longer_cmd,
11470 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11471 SHOW_STR
11472 IPV6_STR
11473 BGP_STR
11474 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11475 "Display route and more specific routes\n")
11476{
11477 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11478 bgp_show_type_prefix_longer);
11479}
11480
11481/* old command */
11482DEFUN (show_ipv6_mbgp_prefix_longer,
11483 show_ipv6_mbgp_prefix_longer_cmd,
11484 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11485 SHOW_STR
11486 IPV6_STR
11487 MBGP_STR
11488 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11489 "Display route and more specific routes\n")
11490{
11491 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
11492 bgp_show_type_prefix_longer);
11493}
Lou Bergerf9b6c392016-01-12 13:42:09 -050011494
Lou Berger651b4022016-01-12 13:42:07 -050011495DEFUN (show_bgp_ipv4_prefix_longer,
11496 show_bgp_ipv4_prefix_longer_cmd,
11497 "show bgp ipv4 A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011498 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011499 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011500 IP_STR
paul718e3742002-12-13 20:15:29 +000011501 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11502 "Display route and more specific routes\n")
11503{
11504 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11505 bgp_show_type_prefix_longer);
11506}
11507
Lou Berger651b4022016-01-12 13:42:07 -050011508DEFUN (show_bgp_ipv4_safi_flap_prefix_longer,
11509 show_bgp_ipv4_safi_flap_prefix_longer_cmd,
11510 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011511 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011512 BGP_STR
11513 "Address family\n"
11514 "Address Family modifier\n"
11515 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050011516 "Address Family modifier\n"
11517 "Address Family modifier\n"
11518 "Display flap statistics of routes\n"
paul718e3742002-12-13 20:15:29 +000011519 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11520 "Display route and more specific routes\n")
11521{
Lou Berger651b4022016-01-12 13:42:07 -050011522 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011523
Lou Berger651b4022016-01-12 13:42:07 -050011524 if (bgp_parse_safi(argv[0], &safi)) {
11525 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11526 return CMD_WARNING;
11527 }
11528 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11529 bgp_show_type_flap_prefix_longer);
paul718e3742002-12-13 20:15:29 +000011530}
11531
Lou Berger651b4022016-01-12 13:42:07 -050011532ALIAS (show_bgp_ipv4_safi_flap_prefix_longer,
11533 show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd,
11534 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011535 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011536 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011537 "Address family\n"
11538 "Address Family modifier\n"
11539 "Address Family modifier\n"
11540 "Address Family modifier\n"
11541 "Address Family modifier\n"
11542 "Display detailed information about dampening\n"
11543 "Display flap statistics of routes\n"
11544 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11545 "Display route and more specific routes\n")
11546
Lou Berger651b4022016-01-12 13:42:07 -050011547DEFUN (show_bgp_ipv6_safi_flap_prefix_longer,
11548 show_bgp_ipv6_safi_flap_prefix_longer_cmd,
11549 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics X:X::X:X/M longer-prefixes",
11550 SHOW_STR
11551 BGP_STR
11552 "Address family\n"
11553 "Address Family modifier\n"
11554 "Address Family modifier\n"
11555 "Address Family modifier\n"
11556 "Address Family modifier\n"
11557 "Display flap statistics of routes\n"
11558 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11559 "Display route and more specific routes\n")
11560{
11561 safi_t safi;
11562
11563 if (bgp_parse_safi(argv[0], &safi)) {
11564 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11565 return CMD_WARNING;
11566 }
11567 return bgp_show_prefix_longer (vty, argv[1], AFI_IP6, safi,
11568 bgp_show_type_flap_prefix_longer);
11569}
11570ALIAS (show_bgp_ipv6_safi_flap_prefix_longer,
11571 show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd,
11572 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics X:X::X:X/M longer-prefixes",
11573 SHOW_STR
11574 BGP_STR
11575 "Address family\n"
11576 "Address Family modifier\n"
11577 "Address Family modifier\n"
11578 "Address Family modifier\n"
11579 "Address Family modifier\n"
11580 "Display detailed information about dampening\n"
11581 "Display flap statistics of routes\n"
11582 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11583 "Display route and more specific routes\n")
Lou Berger651b4022016-01-12 13:42:07 -050011584
11585DEFUN (show_bgp_ipv4_safi_prefix_longer,
11586 show_bgp_ipv4_safi_prefix_longer_cmd,
11587 "show bgp ipv4 (encap|multicast|unicast|vpn) A.B.C.D/M longer-prefixes",
11588 SHOW_STR
11589 BGP_STR
11590 "Address family\n"
11591 "Address Family modifier\n"
11592 "Address Family modifier\n"
11593 "Address Family modifier\n"
11594 "Address Family modifier\n"
11595 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11596 "Display route and more specific routes\n")
11597{
11598 safi_t safi;
11599
11600 if (bgp_parse_safi(argv[0], &safi)) {
11601 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11602 return CMD_WARNING;
11603 }
11604
11605 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11606 bgp_show_type_prefix_longer);
11607}
11608
Lou Berger651b4022016-01-12 13:42:07 -050011609DEFUN (show_bgp_ipv6_safi_prefix_longer,
11610 show_bgp_ipv6_safi_prefix_longer_cmd,
11611 "show bgp ipv6 (encap|multicast|unicast|vpn) X:X::X:X/M longer-prefixes",
11612 SHOW_STR
11613 BGP_STR
11614 "Address family\n"
11615 "Address Family modifier\n"
11616 "Address Family modifier\n"
11617 "Address Family modifier\n"
11618 "Address Family modifier\n"
11619 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11620 "Display route and more specific routes\n")
11621{
11622 safi_t safi;
11623
11624 if (bgp_parse_safi(argv[0], &safi)) {
11625 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11626 return CMD_WARNING;
11627 }
11628
11629 return bgp_show_prefix_longer (vty, argv[1], AFI_IP6, safi,
11630 bgp_show_type_prefix_longer);
11631}
Lou Berger651b4022016-01-12 13:42:07 -050011632
11633DEFUN (show_bgp_ipv4_safi_flap_address,
11634 show_bgp_ipv4_safi_flap_address_cmd,
11635 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D",
11636 SHOW_STR
11637 BGP_STR
11638 "Address family\n"
11639 "Address Family modifier\n"
11640 "Address Family modifier\n"
11641 "Address Family modifier\n"
11642 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000011643 "Display flap statistics of routes\n"
11644 "Network in the BGP routing table to display\n")
11645{
Lou Berger651b4022016-01-12 13:42:07 -050011646 safi_t safi;
11647
11648 if (bgp_parse_safi(argv[0], &safi)) {
11649 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11650 return CMD_WARNING;
11651 }
11652 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000011653 bgp_show_type_flap_address);
11654}
Lou Berger651b4022016-01-12 13:42:07 -050011655ALIAS (show_bgp_ipv4_safi_flap_address,
11656 show_bgp_ipv4_safi_damp_flap_address_cmd,
11657 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D",
Balaji3921cc52015-05-16 23:12:17 +053011658 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053011659 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011660 "Address family\n"
11661 "Address Family modifier\n"
11662 "Address Family modifier\n"
11663 "Address Family modifier\n"
11664 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053011665 "Display detailed information about dampening\n"
11666 "Display flap statistics of routes\n"
11667 "Network in the BGP routing table to display\n")
Lou Berger205e6742016-01-12 13:42:11 -050011668
Lou Berger651b4022016-01-12 13:42:07 -050011669DEFUN (show_bgp_ipv6_flap_address,
11670 show_bgp_ipv6_flap_address_cmd,
11671 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D",
paul718e3742002-12-13 20:15:29 +000011672 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011673 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011674 "Address family\n"
11675 "Address Family modifier\n"
11676 "Address Family modifier\n"
11677 "Address Family modifier\n"
11678 "Address Family modifier\n"
11679 "Display flap statistics of routes\n"
11680 "Network in the BGP routing table to display\n")
11681{
11682 safi_t safi;
11683
11684 if (bgp_parse_safi(argv[0], &safi)) {
11685 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11686 return CMD_WARNING;
11687 }
11688 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11689 bgp_show_type_flap_address);
11690}
11691ALIAS (show_bgp_ipv6_flap_address,
11692 show_bgp_ipv6_damp_flap_address_cmd,
11693 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D",
11694 SHOW_STR
11695 BGP_STR
11696 "Address family\n"
11697 "Address Family modifier\n"
11698 "Address Family modifier\n"
11699 "Address Family modifier\n"
11700 "Address Family modifier\n"
11701 "Display detailed information about dampening\n"
11702 "Display flap statistics of routes\n"
11703 "Network in the BGP routing table to display\n")
Lou Berger651b4022016-01-12 13:42:07 -050011704
11705DEFUN (show_bgp_ipv4_safi_flap_prefix,
11706 show_bgp_ipv4_safi_flap_prefix_cmd,
11707 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D/M",
11708 SHOW_STR
11709 BGP_STR
11710 "Address family\n"
11711 "Address Family modifier\n"
11712 "Address Family modifier\n"
11713 "Address Family modifier\n"
11714 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000011715 "Display flap statistics of routes\n"
11716 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11717{
Lou Berger651b4022016-01-12 13:42:07 -050011718 safi_t safi;
11719
11720 if (bgp_parse_safi(argv[0], &safi)) {
11721 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11722 return CMD_WARNING;
11723 }
11724 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000011725 bgp_show_type_flap_prefix);
11726}
Balaji3921cc52015-05-16 23:12:17 +053011727
Lou Berger651b4022016-01-12 13:42:07 -050011728ALIAS (show_bgp_ipv4_safi_flap_prefix,
11729 show_bgp_ipv4_safi_damp_flap_prefix_cmd,
11730 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D/M",
Balaji3921cc52015-05-16 23:12:17 +053011731 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053011732 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011733 "Address family\n"
11734 "Address Family modifier\n"
11735 "Address Family modifier\n"
11736 "Address Family modifier\n"
11737 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053011738 "Display detailed information about dampening\n"
11739 "Display flap statistics of routes\n"
11740 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11741
Lou Berger651b4022016-01-12 13:42:07 -050011742DEFUN (show_bgp_ipv6_safi_flap_prefix,
11743 show_bgp_ipv6_safi_flap_prefix_cmd,
11744 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics X:X::X:X/M",
paul718e3742002-12-13 20:15:29 +000011745 SHOW_STR
11746 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011747 "Address family\n"
11748 "Address Family modifier\n"
11749 "Address Family modifier\n"
11750 "Address Family modifier\n"
11751 "Address Family modifier\n"
11752 "Display flap statistics of routes\n"
11753 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paul718e3742002-12-13 20:15:29 +000011754{
Lou Berger651b4022016-01-12 13:42:07 -050011755 safi_t safi;
11756
11757 if (bgp_parse_safi(argv[0], &safi)) {
11758 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11759 return CMD_WARNING;
11760 }
11761 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, safi,
11762 bgp_show_type_flap_prefix);
paul718e3742002-12-13 20:15:29 +000011763}
11764
Lou Berger651b4022016-01-12 13:42:07 -050011765ALIAS (show_bgp_ipv6_safi_flap_prefix,
11766 show_bgp_ipv6_safi_damp_flap_prefix_cmd,
11767 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics X:X::X:X/M",
11768 SHOW_STR
11769 BGP_STR
11770 "Address family\n"
11771 "Address Family modifier\n"
11772 "Address Family modifier\n"
11773 "Address Family modifier\n"
11774 "Address Family modifier\n"
11775 "Display detailed information about dampening\n"
11776 "Display flap statistics of routes\n"
11777 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11778
11779DEFUN (show_bgp_ipv6_prefix_longer,
paul718e3742002-12-13 20:15:29 +000011780 show_bgp_ipv6_prefix_longer_cmd,
11781 "show bgp ipv6 X:X::X:X/M longer-prefixes",
11782 SHOW_STR
11783 BGP_STR
11784 "Address family\n"
11785 "IPv6 prefix <network>/<length>\n"
11786 "Display route and more specific routes\n")
paul718e3742002-12-13 20:15:29 +000011787{
11788 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11789 bgp_show_type_prefix_longer);
11790}
11791
paul94f2b392005-06-28 12:44:16 +000011792static struct peer *
paulfd79ac92004-10-13 05:06:08 +000011793peer_lookup_in_view (struct vty *vty, const char *view_name,
11794 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +000011795{
11796 int ret;
11797 struct bgp *bgp;
11798 struct peer *peer;
11799 union sockunion su;
11800
11801 /* BGP structure lookup. */
11802 if (view_name)
11803 {
11804 bgp = bgp_lookup_by_name (view_name);
11805 if (! bgp)
11806 {
11807 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11808 return NULL;
11809 }
11810 }
paul5228ad22004-06-04 17:58:18 +000011811 else
paulbb46e942003-10-24 19:02:03 +000011812 {
11813 bgp = bgp_get_default ();
11814 if (! bgp)
11815 {
11816 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11817 return NULL;
11818 }
11819 }
11820
11821 /* Get peer sockunion. */
11822 ret = str2sockunion (ip_str, &su);
11823 if (ret < 0)
11824 {
11825 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
11826 return NULL;
11827 }
11828
11829 /* Peer structure lookup. */
11830 peer = peer_lookup (bgp, &su);
11831 if (! peer)
11832 {
11833 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
11834 return NULL;
11835 }
11836
11837 return peer;
11838}
David Lamparter6b0655a2014-06-04 06:53:35 +020011839
Paul Jakma2815e612006-09-14 02:56:07 +000011840enum bgp_stats
11841{
11842 BGP_STATS_MAXBITLEN = 0,
11843 BGP_STATS_RIB,
11844 BGP_STATS_PREFIXES,
11845 BGP_STATS_TOTPLEN,
11846 BGP_STATS_UNAGGREGATEABLE,
11847 BGP_STATS_MAX_AGGREGATEABLE,
11848 BGP_STATS_AGGREGATES,
11849 BGP_STATS_SPACE,
11850 BGP_STATS_ASPATH_COUNT,
11851 BGP_STATS_ASPATH_MAXHOPS,
11852 BGP_STATS_ASPATH_TOTHOPS,
11853 BGP_STATS_ASPATH_MAXSIZE,
11854 BGP_STATS_ASPATH_TOTSIZE,
11855 BGP_STATS_ASN_HIGHEST,
11856 BGP_STATS_MAX,
11857};
paulbb46e942003-10-24 19:02:03 +000011858
Paul Jakma2815e612006-09-14 02:56:07 +000011859static const char *table_stats_strs[] =
11860{
11861 [BGP_STATS_PREFIXES] = "Total Prefixes",
11862 [BGP_STATS_TOTPLEN] = "Average prefix length",
11863 [BGP_STATS_RIB] = "Total Advertisements",
11864 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11865 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11866 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11867 [BGP_STATS_SPACE] = "Address space advertised",
11868 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11869 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11870 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11871 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11872 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11873 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11874 [BGP_STATS_MAX] = NULL,
11875};
11876
11877struct bgp_table_stats
11878{
11879 struct bgp_table *table;
11880 unsigned long long counts[BGP_STATS_MAX];
11881};
11882
11883#if 0
11884#define TALLY_SIGFIG 100000
11885static unsigned long
11886ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11887{
11888 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11889 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11890 unsigned long ret = newtot / count;
11891
11892 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11893 return ret + 1;
11894 else
11895 return ret;
11896}
11897#endif
11898
11899static int
11900bgp_table_stats_walker (struct thread *t)
11901{
11902 struct bgp_node *rn;
11903 struct bgp_node *top;
11904 struct bgp_table_stats *ts = THREAD_ARG (t);
11905 unsigned int space = 0;
11906
Paul Jakma53d9f672006-10-15 23:41:16 +000011907 if (!(top = bgp_table_top (ts->table)))
11908 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +000011909
11910 switch (top->p.family)
11911 {
11912 case AF_INET:
11913 space = IPV4_MAX_BITLEN;
11914 break;
11915 case AF_INET6:
11916 space = IPV6_MAX_BITLEN;
11917 break;
11918 }
11919
11920 ts->counts[BGP_STATS_MAXBITLEN] = space;
11921
11922 for (rn = top; rn; rn = bgp_route_next (rn))
11923 {
11924 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -070011925 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +000011926 unsigned int rinum = 0;
11927
11928 if (rn == top)
11929 continue;
11930
11931 if (!rn->info)
11932 continue;
11933
11934 ts->counts[BGP_STATS_PREFIXES]++;
11935 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11936
11937#if 0
11938 ts->counts[BGP_STATS_AVGPLEN]
11939 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11940 ts->counts[BGP_STATS_AVGPLEN],
11941 rn->p.prefixlen);
11942#endif
11943
11944 /* check if the prefix is included by any other announcements */
11945 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -070011946 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +000011947
11948 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +000011949 {
11950 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11951 /* announced address space */
11952 if (space)
11953 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11954 }
Paul Jakma2815e612006-09-14 02:56:07 +000011955 else if (prn->info)
11956 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11957
Paul Jakma2815e612006-09-14 02:56:07 +000011958 for (ri = rn->info; ri; ri = ri->next)
11959 {
11960 rinum++;
11961 ts->counts[BGP_STATS_RIB]++;
11962
11963 if (ri->attr &&
11964 (CHECK_FLAG (ri->attr->flag,
11965 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11966 ts->counts[BGP_STATS_AGGREGATES]++;
11967
11968 /* as-path stats */
11969 if (ri->attr && ri->attr->aspath)
11970 {
11971 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11972 unsigned int size = aspath_size (ri->attr->aspath);
11973 as_t highest = aspath_highest (ri->attr->aspath);
11974
11975 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11976
11977 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11978 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11979
11980 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11981 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11982
11983 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11984 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11985#if 0
11986 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11987 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11988 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11989 hops);
11990 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11991 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11992 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11993 size);
11994#endif
11995 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11996 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11997 }
11998 }
11999 }
12000 return 0;
12001}
12002
12003static int
12004bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
12005{
12006 struct bgp_table_stats ts;
12007 unsigned int i;
12008
12009 if (!bgp->rib[afi][safi])
12010 {
Donald Sharp3c964042016-01-25 23:38:53 -050012011 vty_out (vty, "%% No RIB exists for the specified AFI(%d)/SAFI(%d) %s",
12012 afi, safi, VTY_NEWLINE);
Paul Jakma2815e612006-09-14 02:56:07 +000012013 return CMD_WARNING;
12014 }
12015
12016 memset (&ts, 0, sizeof (ts));
12017 ts.table = bgp->rib[afi][safi];
12018 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
12019
12020 vty_out (vty, "BGP %s RIB statistics%s%s",
12021 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
12022
12023 for (i = 0; i < BGP_STATS_MAX; i++)
12024 {
12025 if (!table_stats_strs[i])
12026 continue;
12027
12028 switch (i)
12029 {
12030#if 0
12031 case BGP_STATS_ASPATH_AVGHOPS:
12032 case BGP_STATS_ASPATH_AVGSIZE:
12033 case BGP_STATS_AVGPLEN:
12034 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12035 vty_out (vty, "%12.2f",
12036 (float)ts.counts[i] / (float)TALLY_SIGFIG);
12037 break;
12038#endif
12039 case BGP_STATS_ASPATH_TOTHOPS:
12040 case BGP_STATS_ASPATH_TOTSIZE:
12041 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12042 vty_out (vty, "%12.2f",
12043 ts.counts[i] ?
12044 (float)ts.counts[i] /
12045 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
12046 : 0);
12047 break;
12048 case BGP_STATS_TOTPLEN:
12049 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12050 vty_out (vty, "%12.2f",
12051 ts.counts[i] ?
12052 (float)ts.counts[i] /
12053 (float)ts.counts[BGP_STATS_PREFIXES]
12054 : 0);
12055 break;
12056 case BGP_STATS_SPACE:
12057 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12058 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
12059 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
12060 break;
Paul Jakma30a22312008-08-15 14:05:22 +010012061 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +000012062 vty_out (vty, "%12.2f%s",
12063 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +000012064 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +000012065 VTY_NEWLINE);
12066 vty_out (vty, "%30s: ", "/8 equivalent ");
12067 vty_out (vty, "%12.2f%s",
12068 (float)ts.counts[BGP_STATS_SPACE] /
12069 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
12070 VTY_NEWLINE);
12071 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
12072 break;
12073 vty_out (vty, "%30s: ", "/24 equivalent ");
12074 vty_out (vty, "%12.2f",
12075 (float)ts.counts[BGP_STATS_SPACE] /
12076 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
12077 break;
12078 default:
12079 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12080 vty_out (vty, "%12llu", ts.counts[i]);
12081 }
12082
12083 vty_out (vty, "%s", VTY_NEWLINE);
12084 }
12085 return CMD_SUCCESS;
12086}
12087
12088static int
12089bgp_table_stats_vty (struct vty *vty, const char *name,
12090 const char *afi_str, const char *safi_str)
12091{
12092 struct bgp *bgp;
12093 afi_t afi;
12094 safi_t safi;
12095
12096 if (name)
12097 bgp = bgp_lookup_by_name (name);
12098 else
12099 bgp = bgp_get_default ();
12100
12101 if (!bgp)
12102 {
Lou Bergerbf1ae6c2016-01-12 13:42:08 -050012103 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
Paul Jakma2815e612006-09-14 02:56:07 +000012104 return CMD_WARNING;
12105 }
12106 if (strncmp (afi_str, "ipv", 3) == 0)
12107 {
12108 if (strncmp (afi_str, "ipv4", 4) == 0)
12109 afi = AFI_IP;
12110 else if (strncmp (afi_str, "ipv6", 4) == 0)
12111 afi = AFI_IP6;
12112 else
12113 {
12114 vty_out (vty, "%% Invalid address family %s%s",
12115 afi_str, VTY_NEWLINE);
12116 return CMD_WARNING;
12117 }
Lou Berger298cc2f2016-01-12 13:42:02 -050012118 switch (safi_str[0]) {
12119 case 'm':
12120 safi = SAFI_MULTICAST;
12121 break;
12122 case 'u':
12123 safi = SAFI_UNICAST;
12124 break;
12125 case 'v':
Donald Sharp3c964042016-01-25 23:38:53 -050012126 safi = SAFI_MPLS_VPN;
Lou Berger298cc2f2016-01-12 13:42:02 -050012127 break;
12128 case 'e':
12129 safi = SAFI_ENCAP;
12130 break;
12131 default:
12132 vty_out (vty, "%% Invalid subsequent address family %s%s",
Paul Jakma2815e612006-09-14 02:56:07 +000012133 safi_str, VTY_NEWLINE);
Lou Berger298cc2f2016-01-12 13:42:02 -050012134 return CMD_WARNING;
12135 }
Paul Jakma2815e612006-09-14 02:56:07 +000012136 }
12137 else
12138 {
Lou Berger298cc2f2016-01-12 13:42:02 -050012139 vty_out (vty, "%% Invalid address family \"%s\"%s",
Paul Jakma2815e612006-09-14 02:56:07 +000012140 afi_str, VTY_NEWLINE);
12141 return CMD_WARNING;
12142 }
12143
Paul Jakma2815e612006-09-14 02:56:07 +000012144 return bgp_table_stats (vty, bgp, afi, safi);
12145}
12146
12147DEFUN (show_bgp_statistics,
12148 show_bgp_statistics_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -050012149 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000012150 SHOW_STR
12151 BGP_STR
12152 "Address family\n"
12153 "Address family\n"
12154 "Address Family modifier\n"
12155 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -050012156 "Address Family modifier\n"
12157 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +000012158 "BGP RIB advertisement statistics\n")
12159{
12160 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
12161}
12162
Lou Bergerf9b6c392016-01-12 13:42:09 -050012163ALIAS (show_bgp_statistics,
12164 show_bgp_statistics_vpnv4_cmd,
12165 "show bgp (ipv4) (vpnv4) statistics",
12166 SHOW_STR
12167 BGP_STR
12168 "Address family\n"
12169 "Address Family modifier\n"
12170 "BGP RIB advertisement statistics\n")
12171
Paul Jakma2815e612006-09-14 02:56:07 +000012172DEFUN (show_bgp_statistics_view,
12173 show_bgp_statistics_view_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -050012174 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000012175 SHOW_STR
12176 BGP_STR
12177 "BGP view\n"
12178 "Address family\n"
12179 "Address family\n"
12180 "Address Family modifier\n"
12181 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -050012182 "Address Family modifier\n"
12183 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +000012184 "BGP RIB advertisement statistics\n")
12185{
12186 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
12187}
12188
12189ALIAS (show_bgp_statistics_view,
Lou Bergerf9b6c392016-01-12 13:42:09 -050012190 show_bgp_statistics_view_vpnv4_cmd,
12191 "show bgp view WORD (ipv4) (vpnv4) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000012192 SHOW_STR
12193 BGP_STR
12194 "BGP view\n"
12195 "Address family\n"
12196 "Address Family modifier\n"
12197 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +020012198
Paul Jakmaff7924f2006-09-04 01:10:36 +000012199enum bgp_pcounts
12200{
12201 PCOUNT_ADJ_IN = 0,
12202 PCOUNT_DAMPED,
12203 PCOUNT_REMOVED,
12204 PCOUNT_HISTORY,
12205 PCOUNT_STALE,
12206 PCOUNT_VALID,
12207 PCOUNT_ALL,
12208 PCOUNT_COUNTED,
12209 PCOUNT_PFCNT, /* the figure we display to users */
12210 PCOUNT_MAX,
12211};
12212
12213static const char *pcount_strs[] =
12214{
12215 [PCOUNT_ADJ_IN] = "Adj-in",
12216 [PCOUNT_DAMPED] = "Damped",
12217 [PCOUNT_REMOVED] = "Removed",
12218 [PCOUNT_HISTORY] = "History",
12219 [PCOUNT_STALE] = "Stale",
12220 [PCOUNT_VALID] = "Valid",
12221 [PCOUNT_ALL] = "All RIB",
12222 [PCOUNT_COUNTED] = "PfxCt counted",
12223 [PCOUNT_PFCNT] = "Useable",
12224 [PCOUNT_MAX] = NULL,
12225};
12226
Paul Jakma2815e612006-09-14 02:56:07 +000012227struct peer_pcounts
12228{
12229 unsigned int count[PCOUNT_MAX];
12230 const struct peer *peer;
12231 const struct bgp_table *table;
12232};
12233
Paul Jakmaff7924f2006-09-04 01:10:36 +000012234static int
Paul Jakma2815e612006-09-14 02:56:07 +000012235bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +000012236{
12237 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +000012238 struct peer_pcounts *pc = THREAD_ARG (t);
12239 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012240
Paul Jakma2815e612006-09-14 02:56:07 +000012241 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012242 {
12243 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +000012244 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012245
12246 for (ain = rn->adj_in; ain; ain = ain->next)
12247 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +000012248 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012249
Paul Jakmaff7924f2006-09-04 01:10:36 +000012250 for (ri = rn->info; ri; ri = ri->next)
12251 {
12252 char buf[SU_ADDRSTRLEN];
12253
12254 if (ri->peer != peer)
12255 continue;
12256
Paul Jakma2815e612006-09-14 02:56:07 +000012257 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012258
12259 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +000012260 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012261 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +000012262 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012263 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +000012264 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012265 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +000012266 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012267 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +000012268 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +000012269 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +000012270 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012271
12272 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
12273 {
Paul Jakma2815e612006-09-14 02:56:07 +000012274 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +000012275 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012276 plog_warn (peer->log,
12277 "%s [pcount] %s/%d is counted but flags 0x%x",
12278 peer->host,
12279 inet_ntop(rn->p.family, &rn->p.u.prefix,
12280 buf, SU_ADDRSTRLEN),
12281 rn->p.prefixlen,
12282 ri->flags);
12283 }
12284 else
12285 {
Paul Jakma1a392d42006-09-07 00:24:49 +000012286 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012287 plog_warn (peer->log,
12288 "%s [pcount] %s/%d not counted but flags 0x%x",
12289 peer->host,
12290 inet_ntop(rn->p.family, &rn->p.u.prefix,
12291 buf, SU_ADDRSTRLEN),
12292 rn->p.prefixlen,
12293 ri->flags);
12294 }
12295 }
12296 }
Paul Jakma2815e612006-09-14 02:56:07 +000012297 return 0;
12298}
Paul Jakmaff7924f2006-09-04 01:10:36 +000012299
Paul Jakma2815e612006-09-14 02:56:07 +000012300static int
12301bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
12302{
12303 struct peer_pcounts pcounts = { .peer = peer };
12304 unsigned int i;
12305
12306 if (!peer || !peer->bgp || !peer->afc[afi][safi]
12307 || !peer->bgp->rib[afi][safi])
12308 {
12309 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12310 return CMD_WARNING;
12311 }
12312
12313 memset (&pcounts, 0, sizeof(pcounts));
12314 pcounts.peer = peer;
12315 pcounts.table = peer->bgp->rib[afi][safi];
12316
12317 /* in-place call via thread subsystem so as to record execution time
12318 * stats for the thread-walk (i.e. ensure this can't be blamed on
12319 * on just vty_read()).
12320 */
12321 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
12322
Paul Jakmaff7924f2006-09-04 01:10:36 +000012323 vty_out (vty, "Prefix counts for %s, %s%s",
12324 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
12325 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
12326 vty_out (vty, "%sCounts from RIB table walk:%s%s",
12327 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
12328
12329 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +000012330 vty_out (vty, "%20s: %-10d%s",
12331 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012332
Paul Jakma2815e612006-09-14 02:56:07 +000012333 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +000012334 {
12335 vty_out (vty, "%s [pcount] PfxCt drift!%s",
12336 peer->host, VTY_NEWLINE);
12337 vty_out (vty, "Please report this bug, with the above command output%s",
12338 VTY_NEWLINE);
12339 }
12340
12341 return CMD_SUCCESS;
12342}
12343
Lou Bergerf9b6c392016-01-12 13:42:09 -050012344DEFUN (show_ip_bgp_neighbor_prefix_counts,
12345 show_ip_bgp_neighbor_prefix_counts_cmd,
12346 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12347 SHOW_STR
12348 IP_STR
12349 BGP_STR
12350 "Detailed information on TCP and BGP neighbor connections\n"
12351 "Neighbor to display information about\n"
12352 "Neighbor to display information about\n"
12353 "Display detailed prefix count information\n")
12354{
12355 struct peer *peer;
12356
12357 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12358 if (! peer)
12359 return CMD_WARNING;
12360
12361 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
12362}
12363
Paul Jakmaff7924f2006-09-04 01:10:36 +000012364DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
12365 show_bgp_ipv6_neighbor_prefix_counts_cmd,
12366 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12367 SHOW_STR
12368 BGP_STR
12369 "Address family\n"
12370 "Detailed information on TCP and BGP neighbor connections\n"
12371 "Neighbor to display information about\n"
12372 "Neighbor to display information about\n"
12373 "Display detailed prefix count information\n")
12374{
12375 struct peer *peer;
12376
12377 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12378 if (! peer)
12379 return CMD_WARNING;
12380
12381 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
12382}
Lou Bergerf9b6c392016-01-12 13:42:09 -050012383
12384DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
12385 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
12386 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12387 SHOW_STR
12388 IP_STR
12389 BGP_STR
12390 "Address family\n"
12391 "Address Family modifier\n"
12392 "Address Family modifier\n"
12393 "Detailed information on TCP and BGP neighbor connections\n"
12394 "Neighbor to display information about\n"
12395 "Neighbor to display information about\n"
12396 "Display detailed prefix count information\n")
12397{
12398 struct peer *peer;
12399
12400 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12401 if (! peer)
12402 return CMD_WARNING;
12403
12404 if (strncmp (argv[0], "m", 1) == 0)
12405 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
12406
12407 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
12408}
12409
12410DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
12411 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
12412 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12413 SHOW_STR
12414 IP_STR
12415 BGP_STR
12416 "Address family\n"
12417 "Address Family modifier\n"
12418 "Address Family modifier\n"
12419 "Detailed information on TCP and BGP neighbor connections\n"
12420 "Neighbor to display information about\n"
12421 "Neighbor to display information about\n"
12422 "Display detailed prefix count information\n")
12423{
12424 struct peer *peer;
12425
12426 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12427 if (! peer)
12428 return CMD_WARNING;
12429
12430 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
12431}
Paul Jakmaff7924f2006-09-04 01:10:36 +000012432
Lou Berger651b4022016-01-12 13:42:07 -050012433DEFUN (show_bgp_ipv4_safi_neighbor_prefix_counts,
12434 show_bgp_ipv4_safi_neighbor_prefix_counts_cmd,
12435 "show bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
Paul Jakmaff7924f2006-09-04 01:10:36 +000012436 SHOW_STR
Paul Jakmaff7924f2006-09-04 01:10:36 +000012437 BGP_STR
12438 "Address family\n"
12439 "Address Family modifier\n"
12440 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050012441 "Address Family modifier\n"
12442 "Address Family modifier\n"
Paul Jakmaff7924f2006-09-04 01:10:36 +000012443 "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 detailed prefix count information\n")
12447{
12448 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050012449 safi_t safi;
12450
12451 if (bgp_parse_safi(argv[0], &safi)) {
12452 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12453 return CMD_WARNING;
12454 }
Paul Jakmaff7924f2006-09-04 01:10:36 +000012455
12456 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12457 if (! peer)
12458 return CMD_WARNING;
12459
Lou Berger651b4022016-01-12 13:42:07 -050012460 return bgp_peer_counts (vty, peer, AFI_IP, safi);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012461}
Lou Berger205e6742016-01-12 13:42:11 -050012462
Lou Berger651b4022016-01-12 13:42:07 -050012463DEFUN (show_bgp_ipv6_safi_neighbor_prefix_counts,
12464 show_bgp_ipv6_safi_neighbor_prefix_counts_cmd,
12465 "show bgp ipv6 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12466 SHOW_STR
12467 BGP_STR
12468 "Address family\n"
12469 "Address Family modifier\n"
12470 "Address Family modifier\n"
12471 "Address Family modifier\n"
12472 "Address Family modifier\n"
12473 "Detailed information on TCP and BGP neighbor connections\n"
12474 "Neighbor to display information about\n"
12475 "Neighbor to display information about\n"
12476 "Display detailed prefix count information\n")
12477{
12478 struct peer *peer;
12479 safi_t safi;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012480
Lou Berger651b4022016-01-12 13:42:07 -050012481 if (bgp_parse_safi(argv[0], &safi)) {
12482 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12483 return CMD_WARNING;
12484 }
12485
12486 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12487 if (! peer)
12488 return CMD_WARNING;
12489
12490 return bgp_peer_counts (vty, peer, AFI_IP6, safi);
12491}
Lou Berger651b4022016-01-12 13:42:07 -050012492
12493DEFUN (show_ip_bgp_encap_neighbor_prefix_counts,
12494 show_ip_bgp_encap_neighbor_prefix_counts_cmd,
12495 "show ip bgp encap all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
Paul Jakmaff7924f2006-09-04 01:10:36 +000012496 SHOW_STR
12497 IP_STR
12498 BGP_STR
12499 "Address family\n"
12500 "Address Family modifier\n"
12501 "Address Family modifier\n"
12502 "Detailed information on TCP and BGP neighbor connections\n"
12503 "Neighbor to display information about\n"
12504 "Neighbor to display information about\n"
12505 "Display detailed prefix count information\n")
12506{
12507 struct peer *peer;
12508
12509 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12510 if (! peer)
12511 return CMD_WARNING;
12512
Lou Berger651b4022016-01-12 13:42:07 -050012513 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_ENCAP);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012514}
12515
12516
paul94f2b392005-06-28 12:44:16 +000012517static void
paul718e3742002-12-13 20:15:29 +000012518show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
12519 int in)
12520{
12521 struct bgp_table *table;
12522 struct bgp_adj_in *ain;
12523 struct bgp_adj_out *adj;
12524 unsigned long output_count;
12525 struct bgp_node *rn;
12526 int header1 = 1;
12527 struct bgp *bgp;
12528 int header2 = 1;
12529
paulbb46e942003-10-24 19:02:03 +000012530 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +000012531
12532 if (! bgp)
12533 return;
12534
12535 table = bgp->rib[afi][safi];
12536
12537 output_count = 0;
12538
12539 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
12540 PEER_STATUS_DEFAULT_ORIGINATE))
12541 {
12542 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 +000012543 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12544 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012545
12546 vty_out (vty, "Originating default network 0.0.0.0%s%s",
12547 VTY_NEWLINE, VTY_NEWLINE);
12548 header1 = 0;
12549 }
12550
12551 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12552 if (in)
12553 {
12554 for (ain = rn->adj_in; ain; ain = ain->next)
12555 if (ain->peer == peer)
12556 {
12557 if (header1)
12558 {
12559 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 +000012560 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12561 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012562 header1 = 0;
12563 }
12564 if (header2)
12565 {
12566 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12567 header2 = 0;
12568 }
12569 if (ain->attr)
12570 {
12571 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
12572 output_count++;
12573 }
12574 }
12575 }
12576 else
12577 {
12578 for (adj = rn->adj_out; adj; adj = adj->next)
12579 if (adj->peer == peer)
12580 {
12581 if (header1)
12582 {
12583 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 +000012584 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12585 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012586 header1 = 0;
12587 }
12588 if (header2)
12589 {
12590 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12591 header2 = 0;
12592 }
12593 if (adj->attr)
12594 {
12595 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
12596 output_count++;
12597 }
12598 }
12599 }
12600
12601 if (output_count != 0)
12602 vty_out (vty, "%sTotal number of prefixes %ld%s",
12603 VTY_NEWLINE, output_count, VTY_NEWLINE);
12604}
12605
paul94f2b392005-06-28 12:44:16 +000012606static int
paulbb46e942003-10-24 19:02:03 +000012607peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
12608{
paul718e3742002-12-13 20:15:29 +000012609 if (! peer || ! peer->afc[afi][safi])
12610 {
12611 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12612 return CMD_WARNING;
12613 }
12614
12615 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12616 {
12617 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
12618 VTY_NEWLINE);
12619 return CMD_WARNING;
12620 }
12621
12622 show_adj_route (vty, peer, afi, safi, in);
12623
12624 return CMD_SUCCESS;
12625}
12626
Lou Bergerf9b6c392016-01-12 13:42:09 -050012627DEFUN (show_ip_bgp_view_neighbor_advertised_route,
12628 show_ip_bgp_view_neighbor_advertised_route_cmd,
12629 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12630 SHOW_STR
12631 IP_STR
12632 BGP_STR
12633 "BGP view\n"
12634 "View name\n"
12635 "Detailed information on TCP and BGP neighbor connections\n"
12636 "Neighbor to display information about\n"
12637 "Neighbor to display information about\n"
12638 "Display the routes advertised to a BGP neighbor\n")
12639{
12640 struct peer *peer;
12641
12642 if (argc == 2)
12643 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12644 else
12645 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12646
12647 if (! peer)
12648 return CMD_WARNING;
12649
12650 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
12651}
12652
12653ALIAS (show_ip_bgp_view_neighbor_advertised_route,
12654 show_ip_bgp_neighbor_advertised_route_cmd,
12655 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12656 SHOW_STR
12657 IP_STR
12658 BGP_STR
12659 "Detailed information on TCP and BGP neighbor connections\n"
12660 "Neighbor to display information about\n"
12661 "Neighbor to display information about\n"
12662 "Display the routes advertised to a BGP neighbor\n")
12663
12664DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
12665 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
12666 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12667 SHOW_STR
12668 IP_STR
12669 BGP_STR
12670 "Address family\n"
12671 "Address Family modifier\n"
12672 "Address Family modifier\n"
12673 "Detailed information on TCP and BGP neighbor connections\n"
12674 "Neighbor to display information about\n"
12675 "Neighbor to display information about\n"
12676 "Display the routes advertised to a BGP neighbor\n")
12677{
12678 struct peer *peer;
12679
12680 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12681 if (! peer)
12682 return CMD_WARNING;
12683
12684 if (strncmp (argv[0], "m", 1) == 0)
12685 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
12686
12687 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
12688}
12689
Lou Bergerf9b6c392016-01-12 13:42:09 -050012690DEFUN (show_bgp_view_neighbor_advertised_route,
12691 show_bgp_view_neighbor_advertised_route_cmd,
12692 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12693 SHOW_STR
12694 BGP_STR
12695 "BGP view\n"
12696 "View name\n"
12697 "Detailed information on TCP and BGP neighbor connections\n"
12698 "Neighbor to display information about\n"
12699 "Neighbor to display information about\n"
12700 "Display the routes advertised to a BGP neighbor\n")
12701{
12702 struct peer *peer;
12703
12704 if (argc == 2)
12705 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12706 else
12707 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12708
12709 if (! peer)
12710 return CMD_WARNING;
12711
12712 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
12713}
12714
12715DEFUN (show_bgp_view_neighbor_received_routes,
12716 show_bgp_view_neighbor_received_routes_cmd,
12717 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
12718 SHOW_STR
12719 BGP_STR
12720 "BGP view\n"
12721 "View name\n"
12722 "Detailed information on TCP and BGP neighbor connections\n"
12723 "Neighbor to display information about\n"
12724 "Neighbor to display information about\n"
12725 "Display the received routes from neighbor\n")
12726{
12727 struct peer *peer;
12728
12729 if (argc == 2)
12730 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12731 else
12732 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12733
12734 if (! peer)
12735 return CMD_WARNING;
12736
12737 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
12738}
12739
12740ALIAS (show_bgp_view_neighbor_advertised_route,
12741 show_bgp_neighbor_advertised_route_cmd,
12742 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12743 SHOW_STR
12744 BGP_STR
12745 "Detailed information on TCP and BGP neighbor connections\n"
12746 "Neighbor to display information about\n"
12747 "Neighbor to display information about\n"
12748 "Display the routes advertised to a BGP neighbor\n")
12749
12750ALIAS (show_bgp_view_neighbor_advertised_route,
12751 show_bgp_ipv6_neighbor_advertised_route_cmd,
12752 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12753 SHOW_STR
12754 BGP_STR
12755 "Address family\n"
12756 "Detailed information on TCP and BGP neighbor connections\n"
12757 "Neighbor to display information about\n"
12758 "Neighbor to display information about\n"
12759 "Display the routes advertised to a BGP neighbor\n")
12760
12761/* old command */
12762ALIAS (show_bgp_view_neighbor_advertised_route,
12763 ipv6_bgp_neighbor_advertised_route_cmd,
12764 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12765 SHOW_STR
12766 IPV6_STR
12767 BGP_STR
12768 "Detailed information on TCP and BGP neighbor connections\n"
12769 "Neighbor to display information about\n"
12770 "Neighbor to display information about\n"
12771 "Display the routes advertised to a BGP neighbor\n")
12772
12773/* old command */
12774DEFUN (ipv6_mbgp_neighbor_advertised_route,
12775 ipv6_mbgp_neighbor_advertised_route_cmd,
12776 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12777 SHOW_STR
12778 IPV6_STR
12779 MBGP_STR
12780 "Detailed information on TCP and BGP neighbor connections\n"
12781 "Neighbor to display information about\n"
12782 "Neighbor to display information about\n"
12783 "Display the routes advertised to a BGP neighbor\n")
12784{
12785 struct peer *peer;
12786
12787 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12788 if (! peer)
12789 return CMD_WARNING;
12790
12791 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
12792}
Lou Bergerf9b6c392016-01-12 13:42:09 -050012793
12794DEFUN (show_ip_bgp_view_neighbor_received_routes,
12795 show_ip_bgp_view_neighbor_received_routes_cmd,
12796 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
12797 SHOW_STR
12798 IP_STR
12799 BGP_STR
12800 "BGP view\n"
12801 "View name\n"
12802 "Detailed information on TCP and BGP neighbor connections\n"
12803 "Neighbor to display information about\n"
12804 "Neighbor to display information about\n"
12805 "Display the received routes from neighbor\n")
12806{
12807 struct peer *peer;
12808
12809 if (argc == 2)
12810 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12811 else
12812 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12813
12814 if (! peer)
12815 return CMD_WARNING;
12816
12817 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
12818}
12819
12820ALIAS (show_ip_bgp_view_neighbor_received_routes,
12821 show_ip_bgp_neighbor_received_routes_cmd,
12822 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12823 SHOW_STR
12824 IP_STR
12825 BGP_STR
12826 "Detailed information on TCP and BGP neighbor connections\n"
12827 "Neighbor to display information about\n"
12828 "Neighbor to display information about\n"
12829 "Display the received routes from neighbor\n")
12830
12831ALIAS (show_bgp_view_neighbor_received_routes,
12832 show_bgp_ipv6_neighbor_received_routes_cmd,
12833 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
12834 SHOW_STR
12835 BGP_STR
12836 "Address family\n"
12837 "Detailed information on TCP and BGP neighbor connections\n"
12838 "Neighbor to display information about\n"
12839 "Neighbor to display information about\n"
12840 "Display the received routes from neighbor\n")
12841
12842DEFUN (show_bgp_neighbor_received_prefix_filter,
12843 show_bgp_neighbor_received_prefix_filter_cmd,
12844 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
12845 SHOW_STR
12846 BGP_STR
12847 "Detailed information on TCP and BGP neighbor connections\n"
12848 "Neighbor to display information about\n"
12849 "Neighbor to display information about\n"
12850 "Display information received from a BGP neighbor\n"
12851 "Display the prefixlist filter\n")
12852{
12853 char name[BUFSIZ];
12854 union sockunion su;
12855 struct peer *peer;
12856 int count, ret;
12857
12858 ret = str2sockunion (argv[0], &su);
12859 if (ret < 0)
12860 {
12861 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
12862 return CMD_WARNING;
12863 }
12864
12865 peer = peer_lookup (NULL, &su);
12866 if (! peer)
12867 return CMD_WARNING;
12868
12869 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12870 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12871 if (count)
12872 {
12873 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12874 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12875 }
12876
12877 return CMD_SUCCESS;
12878}
12879
12880/* old command */
12881ALIAS (show_bgp_view_neighbor_received_routes,
12882 ipv6_bgp_neighbor_received_routes_cmd,
12883 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12884 SHOW_STR
12885 IPV6_STR
12886 BGP_STR
12887 "Detailed information on TCP and BGP neighbor connections\n"
12888 "Neighbor to display information about\n"
12889 "Neighbor to display information about\n"
12890 "Display the received routes from neighbor\n")
12891
12892/* old command */
12893DEFUN (ipv6_mbgp_neighbor_received_routes,
12894 ipv6_mbgp_neighbor_received_routes_cmd,
12895 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12896 SHOW_STR
12897 IPV6_STR
12898 MBGP_STR
12899 "Detailed information on TCP and BGP neighbor connections\n"
12900 "Neighbor to display information about\n"
12901 "Neighbor to display information about\n"
12902 "Display the received routes from neighbor\n")
12903{
12904 struct peer *peer;
12905
12906 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12907 if (! peer)
12908 return CMD_WARNING;
12909
12910 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
12911}
12912
12913DEFUN (show_bgp_view_neighbor_received_prefix_filter,
12914 show_bgp_view_neighbor_received_prefix_filter_cmd,
12915 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
12916 SHOW_STR
12917 BGP_STR
12918 "BGP view\n"
12919 "View name\n"
12920 "Detailed information on TCP and BGP neighbor connections\n"
12921 "Neighbor to display information about\n"
12922 "Neighbor to display information about\n"
12923 "Display information received from a BGP neighbor\n"
12924 "Display the prefixlist filter\n")
12925{
12926 char name[BUFSIZ];
12927 union sockunion su;
12928 struct peer *peer;
12929 struct bgp *bgp;
12930 int count, ret;
12931
12932 /* BGP structure lookup. */
12933 bgp = bgp_lookup_by_name (argv[0]);
12934 if (bgp == NULL)
12935 {
12936 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12937 return CMD_WARNING;
12938 }
12939
12940 ret = str2sockunion (argv[1], &su);
12941 if (ret < 0)
12942 {
12943 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
12944 return CMD_WARNING;
12945 }
12946
12947 peer = peer_lookup (bgp, &su);
12948 if (! peer)
12949 return CMD_WARNING;
12950
12951 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12952 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12953 if (count)
12954 {
12955 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12956 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12957 }
12958
12959 return CMD_SUCCESS;
12960}
12961
12962
12963DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12964 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
12965 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
12966 SHOW_STR
12967 IP_STR
12968 BGP_STR
12969 "Address family\n"
12970 "Address Family modifier\n"
12971 "Address Family modifier\n"
12972 "Detailed information on TCP and BGP neighbor connections\n"
12973 "Neighbor to display information about\n"
12974 "Neighbor to display information about\n"
12975 "Display the received routes from neighbor\n")
12976{
12977 struct peer *peer;
12978
12979 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12980 if (! peer)
12981 return CMD_WARNING;
12982
12983 if (strncmp (argv[0], "m", 1) == 0)
12984 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
12985
12986 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
12987}
12988
Lou Berger651b4022016-01-12 13:42:07 -050012989DEFUN (show_bgp_ipv4_safi_neighbor_advertised_route,
12990 show_bgp_ipv4_safi_neighbor_advertised_route_cmd,
12991 "show bgp ipv4 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012992 SHOW_STR
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012993 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050012994 "Address Family modifier\n"
12995 "Address Family modifier\n"
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012996 "Detailed information on TCP and BGP neighbor connections\n"
12997 "Neighbor to display information about\n"
12998 "Neighbor to display information about\n"
12999 "Display the routes advertised to a BGP neighbor\n")
13000{
13001 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013002 safi_t safi;
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010013003
Lou Berger651b4022016-01-12 13:42:07 -050013004 if (bgp_parse_safi(argv[0], &safi)) {
13005 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010013006 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050013007 }
paul718e3742002-12-13 20:15:29 +000013008
paulbb46e942003-10-24 19:02:03 +000013009 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13010 if (! peer)
13011 return CMD_WARNING;
13012
Lou Berger651b4022016-01-12 13:42:07 -050013013 return peer_adj_routes (vty, peer, AFI_IP, safi, 0);
13014}
Lou Berger205e6742016-01-12 13:42:11 -050013015
Lou Berger651b4022016-01-12 13:42:07 -050013016DEFUN (show_bgp_ipv6_safi_neighbor_advertised_route,
13017 show_bgp_ipv6_safi_neighbor_advertised_route_cmd,
13018 "show bgp ipv6 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
13019 SHOW_STR
13020 BGP_STR
13021 "Address Family modifier\n"
13022 "Address Family modifier\n"
13023 "Address Family modifier\n"
13024 "Detailed information on TCP and BGP neighbor connections\n"
13025 "Neighbor to display information about\n"
13026 "Neighbor to display information about\n"
13027 "Display the routes advertised to a BGP neighbor\n")
13028{
13029 struct peer *peer;
13030 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000013031
Lou Berger651b4022016-01-12 13:42:07 -050013032 if (bgp_parse_safi(argv[0], &safi)) {
13033 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13034 return CMD_WARNING;
13035 }
13036
13037 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13038 if (! peer)
13039 return CMD_WARNING;
13040
13041 return peer_adj_routes (vty, peer, AFI_IP6, safi, 0);
paul718e3742002-12-13 20:15:29 +000013042}
13043
Lou Bergerf9b6c392016-01-12 13:42:09 -050013044DEFUN (show_bgp_view_ipv6_neighbor_advertised_route,
Lou Berger651b4022016-01-12 13:42:07 -050013045 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
13046 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
paulbb46e942003-10-24 19:02:03 +000013047 SHOW_STR
13048 BGP_STR
13049 "BGP view\n"
13050 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050013051 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000013052 "Detailed information on TCP and BGP neighbor connections\n"
13053 "Neighbor to display information about\n"
13054 "Neighbor to display information about\n"
13055 "Display the routes advertised to a BGP neighbor\n")
13056{
13057 struct peer *peer;
13058
13059 if (argc == 2)
13060 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13061 else
13062 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13063
13064 if (! peer)
13065 return CMD_WARNING;
13066
13067 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
13068}
13069
Lou Bergerf9b6c392016-01-12 13:42:09 -050013070DEFUN (show_bgp_view_ipv6_neighbor_received_routes,
Lou Berger651b4022016-01-12 13:42:07 -050013071 show_bgp_view_ipv6_neighbor_received_routes_cmd,
13072 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
paulbb46e942003-10-24 19:02:03 +000013073 SHOW_STR
13074 BGP_STR
13075 "BGP view\n"
13076 "View name\n"
13077 "Address family\n"
13078 "Detailed information on TCP and BGP neighbor connections\n"
13079 "Neighbor to display information about\n"
13080 "Neighbor to display information about\n"
paulbb46e942003-10-24 19:02:03 +000013081 "Display the received routes from neighbor\n")
13082{
13083 struct peer *peer;
13084
13085 if (argc == 2)
13086 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13087 else
13088 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13089
13090 if (! peer)
13091 return CMD_WARNING;
13092
13093 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
13094}
Lou Berger651b4022016-01-12 13:42:07 -050013095
13096DEFUN (show_bgp_ipv4_safi_neighbor_received_routes,
13097 show_bgp_ipv4_safi_neighbor_received_routes_cmd,
13098 "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 +010013099 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013100 BGP_STR
13101 "Address family\n"
13102 "Address Family modifier\n"
13103 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050013104 "Address Family modifier\n"
13105 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000013106 "Detailed information on TCP and BGP neighbor connections\n"
13107 "Neighbor to display information about\n"
13108 "Neighbor to display information about\n"
13109 "Display the received routes from neighbor\n")
13110{
paulbb46e942003-10-24 19:02:03 +000013111 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013112 safi_t safi;
13113
13114 if (bgp_parse_safi(argv[0], &safi)) {
13115 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13116 return CMD_WARNING;
13117 }
paul718e3742002-12-13 20:15:29 +000013118
paulbb46e942003-10-24 19:02:03 +000013119 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13120 if (! peer)
13121 return CMD_WARNING;
13122
Lou Berger651b4022016-01-12 13:42:07 -050013123 return peer_adj_routes (vty, peer, AFI_IP, safi, 1);
paul718e3742002-12-13 20:15:29 +000013124}
Lou Berger205e6742016-01-12 13:42:11 -050013125
Lou Berger651b4022016-01-12 13:42:07 -050013126DEFUN (show_bgp_ipv6_safi_neighbor_received_routes,
13127 show_bgp_ipv6_safi_neighbor_received_routes_cmd,
13128 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) received-routes",
13129 SHOW_STR
13130 BGP_STR
13131 "Address family\n"
13132 "Address Family modifier\n"
13133 "Address Family modifier\n"
13134 "Address Family modifier\n"
13135 "Address Family modifier\n"
13136 "Detailed information on TCP and BGP neighbor connections\n"
13137 "Neighbor to display information about\n"
13138 "Neighbor to display information about\n"
13139 "Display the received routes from neighbor\n")
13140{
13141 struct peer *peer;
13142 safi_t safi;
13143
13144 if (bgp_parse_safi(argv[0], &safi)) {
13145 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13146 return CMD_WARNING;
13147 }
13148
13149 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13150 if (! peer)
13151 return CMD_WARNING;
13152
13153 return peer_adj_routes (vty, peer, AFI_IP6, safi, 1);
13154}
paul718e3742002-12-13 20:15:29 +000013155
Michael Lambert95cbbd22010-07-23 14:43:04 -040013156DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
13157 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040013158 "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 -040013159 SHOW_STR
13160 BGP_STR
13161 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000013162 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013163 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013164 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013165 "Address family modifier\n"
13166 "Address family modifier\n"
13167 "Detailed information on TCP and BGP neighbor connections\n"
13168 "Neighbor to display information about\n"
13169 "Neighbor to display information about\n"
13170 "Display the advertised routes to neighbor\n"
13171 "Display the received routes from neighbor\n")
13172{
13173 int afi;
13174 int safi;
13175 int in;
13176 struct peer *peer;
13177
David Lamparter94bad672015-03-03 08:52:22 +010013178 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013179
13180 if (! peer)
13181 return CMD_WARNING;
13182
Michael Lambert95cbbd22010-07-23 14:43:04 -040013183 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
13184 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13185 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040013186
13187 return peer_adj_routes (vty, peer, afi, safi, in);
13188}
13189
Lou Bergerf9b6c392016-01-12 13:42:09 -050013190DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
13191 show_ip_bgp_neighbor_received_prefix_filter_cmd,
13192 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
13193 SHOW_STR
13194 IP_STR
13195 BGP_STR
13196 "Detailed information on TCP and BGP neighbor connections\n"
13197 "Neighbor to display information about\n"
13198 "Neighbor to display information about\n"
13199 "Display information received from a BGP neighbor\n"
13200 "Display the prefixlist filter\n")
13201{
13202 char name[BUFSIZ];
13203 union sockunion su;
13204 struct peer *peer;
13205 int count, ret;
13206
13207 ret = str2sockunion (argv[0], &su);
13208 if (ret < 0)
13209 {
13210 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
13211 return CMD_WARNING;
13212 }
13213
13214 peer = peer_lookup (NULL, &su);
13215 if (! peer)
13216 return CMD_WARNING;
13217
13218 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
13219 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13220 if (count)
13221 {
13222 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13223 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13224 }
13225
13226 return CMD_SUCCESS;
13227}
13228
13229DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
13230 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
13231 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
13232 SHOW_STR
13233 IP_STR
13234 BGP_STR
13235 "Address family\n"
13236 "Address Family modifier\n"
13237 "Address Family modifier\n"
13238 "Detailed information on TCP and BGP neighbor connections\n"
13239 "Neighbor to display information about\n"
13240 "Neighbor to display information about\n"
13241 "Display information received from a BGP neighbor\n"
13242 "Display the prefixlist filter\n")
13243{
13244 char name[BUFSIZ];
13245 union sockunion su;
13246 struct peer *peer;
13247 int count, ret;
13248
13249 ret = str2sockunion (argv[1], &su);
13250 if (ret < 0)
13251 {
13252 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13253 return CMD_WARNING;
13254 }
13255
13256 peer = peer_lookup (NULL, &su);
13257 if (! peer)
13258 return CMD_WARNING;
13259
13260 if (strncmp (argv[0], "m", 1) == 0)
13261 {
13262 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
13263 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13264 if (count)
13265 {
13266 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
13267 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13268 }
13269 }
13270 else
13271 {
13272 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
13273 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13274 if (count)
13275 {
13276 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13277 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13278 }
13279 }
13280
13281 return CMD_SUCCESS;
13282}
13283
13284ALIAS (show_bgp_view_neighbor_received_routes,
13285 show_bgp_neighbor_received_routes_cmd,
13286 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
13287 SHOW_STR
13288 BGP_STR
13289 "Detailed information on TCP and BGP neighbor connections\n"
13290 "Neighbor to display information about\n"
13291 "Neighbor to display information about\n"
13292 "Display the received routes from neighbor\n")
13293
Lou Berger651b4022016-01-12 13:42:07 -050013294DEFUN (show_bgp_ipv4_safi_neighbor_received_prefix_filter,
13295 show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd,
13296 "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 +000013297 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013298 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013299 IP_STR
13300 "Address Family modifier\n"
13301 "Address Family modifier\n"
13302 "Address Family modifier\n"
13303 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000013304 "Detailed information on TCP and BGP neighbor connections\n"
13305 "Neighbor to display information about\n"
13306 "Neighbor to display information about\n"
13307 "Display information received from a BGP neighbor\n"
13308 "Display the prefixlist filter\n")
13309{
13310 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013311 union sockunion su;
paul718e3742002-12-13 20:15:29 +000013312 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013313 int count, ret;
Lou Berger651b4022016-01-12 13:42:07 -050013314 safi_t safi;
paul718e3742002-12-13 20:15:29 +000013315
Lou Berger651b4022016-01-12 13:42:07 -050013316 if (bgp_parse_safi(argv[0], &safi)) {
13317 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000013318 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050013319 }
paul718e3742002-12-13 20:15:29 +000013320
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013321 ret = str2sockunion (argv[1], &su);
13322 if (ret < 0)
13323 {
13324 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13325 return CMD_WARNING;
13326 }
paul718e3742002-12-13 20:15:29 +000013327
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013328 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000013329 if (! peer)
13330 return CMD_WARNING;
13331
Lou Berger651b4022016-01-12 13:42:07 -050013332 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, safi);
13333 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13334 if (count) {
13335 vty_out (vty, "Address family: IPv4 %s%s", safi2str(safi), VTY_NEWLINE);
13336 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13337 }
paul718e3742002-12-13 20:15:29 +000013338
13339 return CMD_SUCCESS;
13340}
Lou Berger205e6742016-01-12 13:42:11 -050013341
Lou Berger651b4022016-01-12 13:42:07 -050013342DEFUN (show_bgp_ipv6_safi_neighbor_received_prefix_filter,
13343 show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd,
13344 "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 +000013345 SHOW_STR
13346 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013347 IP_STR
13348 "Address Family modifier\n"
13349 "Address Family modifier\n"
13350 "Address Family modifier\n"
13351 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000013352 "Detailed information on TCP and BGP neighbor connections\n"
13353 "Neighbor to display information about\n"
13354 "Neighbor to display information about\n"
Lou Berger651b4022016-01-12 13:42:07 -050013355 "Display information received from a BGP neighbor\n"
13356 "Display the prefixlist filter\n")
13357{
13358 char name[BUFSIZ];
13359 union sockunion su;
13360 struct peer *peer;
13361 int count, ret;
13362 safi_t safi;
13363
13364 if (bgp_parse_safi(argv[0], &safi)) {
13365 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13366 return CMD_WARNING;
13367 }
13368
13369 ret = str2sockunion (argv[1], &su);
13370 if (ret < 0)
13371 {
13372 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13373 return CMD_WARNING;
13374 }
13375
13376 peer = peer_lookup (NULL, &su);
13377 if (! peer)
13378 return CMD_WARNING;
13379
13380 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, safi);
13381 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13382 if (count) {
13383 vty_out (vty, "Address family: IPv6 %s%s", safi2str(safi), VTY_NEWLINE);
13384 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13385 }
13386
13387 return CMD_SUCCESS;
13388}
paul718e3742002-12-13 20:15:29 +000013389
Lou Bergerf9b6c392016-01-12 13:42:09 -050013390DEFUN (show_bgp_ipv6_neighbor_received_prefix_filter,
Lou Berger651b4022016-01-12 13:42:07 -050013391 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
13392 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
paul718e3742002-12-13 20:15:29 +000013393 SHOW_STR
13394 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013395 "Address family\n"
paul718e3742002-12-13 20:15:29 +000013396 "Detailed information on TCP and BGP neighbor connections\n"
13397 "Neighbor to display information about\n"
13398 "Neighbor to display information about\n"
13399 "Display information received from a BGP neighbor\n"
13400 "Display the prefixlist filter\n")
13401{
13402 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013403 union sockunion su;
paul718e3742002-12-13 20:15:29 +000013404 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013405 int count, ret;
paul718e3742002-12-13 20:15:29 +000013406
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013407 ret = str2sockunion (argv[0], &su);
13408 if (ret < 0)
13409 {
13410 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
13411 return CMD_WARNING;
13412 }
paul718e3742002-12-13 20:15:29 +000013413
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013414 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000013415 if (! peer)
13416 return CMD_WARNING;
13417
13418 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13419 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13420 if (count)
13421 {
13422 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13423 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13424 }
13425
13426 return CMD_SUCCESS;
13427}
13428
Lou Bergerf9b6c392016-01-12 13:42:09 -050013429DEFUN (show_bgp_view_ipv6_neighbor_received_prefix_filter,
Lou Berger651b4022016-01-12 13:42:07 -050013430 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
13431 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
paulbb46e942003-10-24 19:02:03 +000013432 SHOW_STR
13433 BGP_STR
13434 "BGP view\n"
13435 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050013436 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000013437 "Detailed information on TCP and BGP neighbor connections\n"
13438 "Neighbor to display information about\n"
13439 "Neighbor to display information about\n"
13440 "Display information received from a BGP neighbor\n"
13441 "Display the prefixlist filter\n")
13442{
13443 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013444 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000013445 struct peer *peer;
13446 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013447 int count, ret;
paulbb46e942003-10-24 19:02:03 +000013448
13449 /* BGP structure lookup. */
13450 bgp = bgp_lookup_by_name (argv[0]);
13451 if (bgp == NULL)
13452 {
13453 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13454 return CMD_WARNING;
13455 }
13456
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013457 ret = str2sockunion (argv[1], &su);
13458 if (ret < 0)
13459 {
13460 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13461 return CMD_WARNING;
13462 }
paulbb46e942003-10-24 19:02:03 +000013463
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013464 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000013465 if (! peer)
13466 return CMD_WARNING;
13467
13468 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13469 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13470 if (count)
13471 {
13472 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13473 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13474 }
13475
13476 return CMD_SUCCESS;
13477}
David Lamparter6b0655a2014-06-04 06:53:35 +020013478
paul94f2b392005-06-28 12:44:16 +000013479static int
paulbb46e942003-10-24 19:02:03 +000013480bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000013481 safi_t safi, enum bgp_show_type type)
13482{
paul718e3742002-12-13 20:15:29 +000013483 if (! peer || ! peer->afc[afi][safi])
13484 {
13485 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000013486 return CMD_WARNING;
13487 }
13488
ajs5a646652004-11-05 01:25:55 +000013489 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000013490}
Lou Bergerf9b6c392016-01-12 13:42:09 -050013491DEFUN (show_ip_bgp_neighbor_routes,
13492 show_ip_bgp_neighbor_routes_cmd,
13493 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
13494 SHOW_STR
13495 IP_STR
13496 BGP_STR
13497 "Detailed information on TCP and BGP neighbor connections\n"
13498 "Neighbor to display information about\n"
13499 "Neighbor to display information about\n"
13500 "Display routes learned from neighbor\n")
13501{
13502 struct peer *peer;
13503
13504 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13505 if (! peer)
13506 return CMD_WARNING;
13507
13508 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13509 bgp_show_type_neighbor);
13510}
13511
13512DEFUN (show_ip_bgp_neighbor_flap,
13513 show_ip_bgp_neighbor_flap_cmd,
13514 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
13515 SHOW_STR
13516 IP_STR
13517 BGP_STR
13518 "Detailed information on TCP and BGP neighbor connections\n"
13519 "Neighbor to display information about\n"
13520 "Neighbor to display information about\n"
13521 "Display flap statistics of the routes learned from neighbor\n")
13522{
13523 struct peer *peer;
13524
13525 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13526 if (! peer)
13527 return CMD_WARNING;
13528
13529 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13530 bgp_show_type_flap_neighbor);
13531}
13532
13533DEFUN (show_ip_bgp_neighbor_damp,
13534 show_ip_bgp_neighbor_damp_cmd,
13535 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
13536 SHOW_STR
13537 IP_STR
13538 BGP_STR
13539 "Detailed information on TCP and BGP neighbor connections\n"
13540 "Neighbor to display information about\n"
13541 "Neighbor to display information about\n"
13542 "Display the dampened routes received from neighbor\n")
13543{
13544 struct peer *peer;
13545
13546 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13547 if (! peer)
13548 return CMD_WARNING;
13549
13550 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13551 bgp_show_type_damp_neighbor);
13552}
13553
13554DEFUN (show_ip_bgp_ipv4_neighbor_routes,
13555 show_ip_bgp_ipv4_neighbor_routes_cmd,
13556 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
13557 SHOW_STR
13558 IP_STR
13559 BGP_STR
13560 "Address family\n"
13561 "Address Family modifier\n"
13562 "Address Family modifier\n"
13563 "Detailed information on TCP and BGP neighbor connections\n"
13564 "Neighbor to display information about\n"
13565 "Neighbor to display information about\n"
13566 "Display routes learned from neighbor\n")
13567{
13568 struct peer *peer;
13569
13570 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13571 if (! peer)
13572 return CMD_WARNING;
13573
13574 if (strncmp (argv[0], "m", 1) == 0)
13575 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
13576 bgp_show_type_neighbor);
13577
13578 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13579 bgp_show_type_neighbor);
13580}
13581
13582DEFUN (show_ip_bgp_view_rsclient,
13583 show_ip_bgp_view_rsclient_cmd,
13584 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
13585 SHOW_STR
13586 IP_STR
13587 BGP_STR
13588 "BGP view\n"
13589 "View name\n"
13590 "Information about Route Server Client\n"
13591 NEIGHBOR_ADDR_STR)
13592{
13593 struct bgp_table *table;
13594 struct peer *peer;
13595
13596 if (argc == 2)
13597 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13598 else
13599 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13600
13601 if (! peer)
13602 return CMD_WARNING;
13603
13604 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13605 {
13606 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13607 VTY_NEWLINE);
13608 return CMD_WARNING;
13609 }
13610
13611 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13612 PEER_FLAG_RSERVER_CLIENT))
13613 {
13614 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13615 VTY_NEWLINE);
13616 return CMD_WARNING;
13617 }
13618
13619 table = peer->rib[AFI_IP][SAFI_UNICAST];
13620
13621 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
13622}
13623
13624ALIAS (show_ip_bgp_view_rsclient,
13625 show_ip_bgp_rsclient_cmd,
13626 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
13627 SHOW_STR
13628 IP_STR
13629 BGP_STR
13630 "Information about Route Server Client\n"
13631 NEIGHBOR_ADDR_STR)
13632
13633DEFUN (show_bgp_view_ipv4_safi_rsclient,
13634 show_bgp_view_ipv4_safi_rsclient_cmd,
13635 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
13636 SHOW_STR
13637 BGP_STR
13638 "BGP view\n"
13639 "View name\n"
13640 "Address family\n"
13641 "Address Family modifier\n"
13642 "Address Family modifier\n"
13643 "Information about Route Server Client\n"
13644 NEIGHBOR_ADDR_STR)
13645{
13646 struct bgp_table *table;
13647 struct peer *peer;
13648 safi_t safi;
13649
13650 if (argc == 3) {
13651 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13652 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13653 } else {
13654 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13655 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13656 }
13657
13658 if (! peer)
13659 return CMD_WARNING;
13660
13661 if (! peer->afc[AFI_IP][safi])
13662 {
13663 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13664 VTY_NEWLINE);
13665 return CMD_WARNING;
13666 }
13667
13668 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13669 PEER_FLAG_RSERVER_CLIENT))
13670 {
13671 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13672 VTY_NEWLINE);
13673 return CMD_WARNING;
13674 }
13675
13676 table = peer->rib[AFI_IP][safi];
13677
13678 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
13679}
13680
13681ALIAS (show_bgp_view_ipv4_safi_rsclient,
13682 show_bgp_ipv4_safi_rsclient_cmd,
13683 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
13684 SHOW_STR
13685 BGP_STR
13686 "Address family\n"
13687 "Address Family modifier\n"
13688 "Address Family modifier\n"
13689 "Information about Route Server Client\n"
13690 NEIGHBOR_ADDR_STR)
13691
13692DEFUN (show_ip_bgp_view_rsclient_route,
13693 show_ip_bgp_view_rsclient_route_cmd,
13694 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13695 SHOW_STR
13696 IP_STR
13697 BGP_STR
13698 "BGP view\n"
13699 "View name\n"
13700 "Information about Route Server Client\n"
13701 NEIGHBOR_ADDR_STR
13702 "Network in the BGP routing table to display\n")
13703{
13704 struct bgp *bgp;
13705 struct peer *peer;
13706
13707 /* BGP structure lookup. */
13708 if (argc == 3)
13709 {
13710 bgp = bgp_lookup_by_name (argv[0]);
13711 if (bgp == NULL)
13712 {
13713 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13714 return CMD_WARNING;
13715 }
13716 }
13717 else
13718 {
13719 bgp = bgp_get_default ();
13720 if (bgp == NULL)
13721 {
13722 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13723 return CMD_WARNING;
13724 }
13725 }
13726
13727 if (argc == 3)
13728 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13729 else
13730 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13731
13732 if (! peer)
13733 return CMD_WARNING;
13734
13735 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13736 {
13737 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13738 VTY_NEWLINE);
13739 return CMD_WARNING;
13740}
13741
13742 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13743 PEER_FLAG_RSERVER_CLIENT))
13744 {
13745 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13746 VTY_NEWLINE);
13747 return CMD_WARNING;
13748 }
13749
13750 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
13751 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070013752 AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -050013753}
13754
13755ALIAS (show_ip_bgp_view_rsclient_route,
13756 show_ip_bgp_rsclient_route_cmd,
13757 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13758 SHOW_STR
13759 IP_STR
13760 BGP_STR
13761 "Information about Route Server Client\n"
13762 NEIGHBOR_ADDR_STR
13763 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +000013764
Lou Berger651b4022016-01-12 13:42:07 -050013765DEFUN (show_bgp_ipv4_safi_neighbor_flap,
13766 show_bgp_ipv4_safi_neighbor_flap_cmd,
13767 "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paul718e3742002-12-13 20:15:29 +000013768 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013769 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013770 "Address Family Modifier\n"
13771 "Address Family Modifier\n"
13772 "Address Family Modifier\n"
13773 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +000013774 "Detailed information on TCP and BGP neighbor connections\n"
13775 "Neighbor to display information about\n"
13776 "Neighbor to display information about\n"
13777 "Display flap statistics of the routes learned from neighbor\n")
13778{
paulbb46e942003-10-24 19:02:03 +000013779 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013780 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000013781
Lou Berger651b4022016-01-12 13:42:07 -050013782 if (bgp_parse_safi(argv[0], &safi)) {
13783 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13784 return CMD_WARNING;
13785 }
13786
13787 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulbb46e942003-10-24 19:02:03 +000013788 if (! peer)
13789 return CMD_WARNING;
13790
Lou Berger651b4022016-01-12 13:42:07 -050013791 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013792 bgp_show_type_flap_neighbor);
13793}
Lou Berger205e6742016-01-12 13:42:11 -050013794
Lou Berger651b4022016-01-12 13:42:07 -050013795DEFUN (show_bgp_ipv6_safi_neighbor_flap,
13796 show_bgp_ipv6_safi_neighbor_flap_cmd,
13797 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paul718e3742002-12-13 20:15:29 +000013798 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013799 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013800 "Address Family Modifier\n"
13801 "Address Family Modifier\n"
13802 "Address Family Modifier\n"
13803 "Address Family Modifier\n"
13804 "Detailed information on TCP and BGP neighbor connections\n"
13805 "Neighbor to display information about\n"
13806 "Neighbor to display information about\n"
13807 "Display flap statistics of the routes learned from neighbor\n")
13808{
13809 struct peer *peer;
13810 safi_t safi;
13811
13812 if (bgp_parse_safi(argv[0], &safi)) {
13813 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13814 return CMD_WARNING;
13815 }
13816
13817 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13818 if (! peer)
13819 return CMD_WARNING;
13820
13821 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13822 bgp_show_type_flap_neighbor);
13823}
Lou Berger651b4022016-01-12 13:42:07 -050013824
13825DEFUN (show_bgp_ipv4_safi_neighbor_damp,
13826 show_bgp_ipv4_safi_neighbor_damp_cmd,
13827 "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) dampened-routes",
13828 SHOW_STR
13829 BGP_STR
13830 "Address Family Modifier\n"
13831 "Address Family Modifier\n"
13832 "Address Family Modifier\n"
13833 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +000013834 "Detailed information on TCP and BGP neighbor connections\n"
13835 "Neighbor to display information about\n"
13836 "Neighbor to display information about\n"
13837 "Display the dampened routes received from neighbor\n")
13838{
paulbb46e942003-10-24 19:02:03 +000013839 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013840 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000013841
Lou Berger651b4022016-01-12 13:42:07 -050013842 if (bgp_parse_safi(argv[0], &safi)) {
13843 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13844 return CMD_WARNING;
13845 }
13846
13847 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulbb46e942003-10-24 19:02:03 +000013848 if (! peer)
13849 return CMD_WARNING;
13850
Lou Berger651b4022016-01-12 13:42:07 -050013851 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013852 bgp_show_type_damp_neighbor);
13853}
Lou Berger205e6742016-01-12 13:42:11 -050013854
Lou Berger651b4022016-01-12 13:42:07 -050013855DEFUN (show_bgp_ipv6_safi_neighbor_damp,
13856 show_bgp_ipv6_safi_neighbor_damp_cmd,
13857 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) dampened-routes",
paul718e3742002-12-13 20:15:29 +000013858 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -050013859 BGP_STR
13860 "Address Family Modifier\n"
13861 "Address Family Modifier\n"
13862 "Address Family Modifier\n"
13863 "Address Family Modifier\n"
13864 "Detailed information on TCP and BGP neighbor connections\n"
13865 "Neighbor to display information about\n"
13866 "Neighbor to display information about\n"
13867 "Display the dampened routes received from neighbor\n")
13868{
13869 struct peer *peer;
13870 safi_t safi;
13871
13872 if (bgp_parse_safi(argv[0], &safi)) {
13873 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13874 return CMD_WARNING;
13875 }
13876
13877 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13878 if (! peer)
13879 return CMD_WARNING;
13880
13881 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13882 bgp_show_type_damp_neighbor);
13883}
Lou Berger651b4022016-01-12 13:42:07 -050013884
13885DEFUN (show_bgp_ipv4_safi_neighbor_routes,
13886 show_bgp_ipv4_safi_neighbor_routes_cmd,
13887 "show bgp ipv4 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) routes",
13888 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013889 BGP_STR
13890 "Address family\n"
13891 "Address Family modifier\n"
13892 "Address Family modifier\n"
13893 "Detailed information on TCP and BGP neighbor connections\n"
13894 "Neighbor to display information about\n"
13895 "Neighbor to display information about\n"
13896 "Display routes learned from neighbor\n")
13897{
paulbb46e942003-10-24 19:02:03 +000013898 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013899 safi_t safi;
13900
13901 if (bgp_parse_safi(argv[0], &safi)) {
13902 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13903 return CMD_WARNING;
13904 }
paulbb46e942003-10-24 19:02:03 +000013905
13906 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13907 if (! peer)
13908 return CMD_WARNING;
13909
Lou Berger651b4022016-01-12 13:42:07 -050013910 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013911 bgp_show_type_neighbor);
13912}
Lou Berger205e6742016-01-12 13:42:11 -050013913
Lou Berger651b4022016-01-12 13:42:07 -050013914DEFUN (show_bgp_ipv6_safi_neighbor_routes,
13915 show_bgp_ipv6_safi_neighbor_routes_cmd,
13916 "show bgp ipv6 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) routes",
paulfee0f4c2004-09-13 05:12:46 +000013917 SHOW_STR
paulfee0f4c2004-09-13 05:12:46 +000013918 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013919 "Address family\n"
13920 "Address Family modifier\n"
13921 "Address Family modifier\n"
13922 "Detailed information on TCP and BGP neighbor connections\n"
13923 NEIGHBOR_ADDR_STR
13924 NEIGHBOR_ADDR_STR
13925 "Display routes learned from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000013926{
paulfee0f4c2004-09-13 05:12:46 +000013927 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013928 safi_t safi;
paulfee0f4c2004-09-13 05:12:46 +000013929
Lou Berger651b4022016-01-12 13:42:07 -050013930 if (bgp_parse_safi(argv[0], &safi)) {
13931 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13932 return CMD_WARNING;
13933 }
paulfee0f4c2004-09-13 05:12:46 +000013934
Lou Berger651b4022016-01-12 13:42:07 -050013935 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulfee0f4c2004-09-13 05:12:46 +000013936 if (! peer)
13937 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050013938
13939 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13940 bgp_show_type_neighbor);
paulfee0f4c2004-09-13 05:12:46 +000013941}
paulfee0f4c2004-09-13 05:12:46 +000013942
Michael Lambert95cbbd22010-07-23 14:43:04 -040013943DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
13944 show_bgp_view_ipv4_safi_rsclient_route_cmd,
13945 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13946 SHOW_STR
13947 BGP_STR
13948 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000013949 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013950 "Address family\n"
13951 "Address Family modifier\n"
13952 "Address Family modifier\n"
13953 "Information about Route Server Client\n"
13954 NEIGHBOR_ADDR_STR
13955 "Network in the BGP routing table to display\n")
13956{
13957 struct bgp *bgp;
13958 struct peer *peer;
13959 safi_t safi;
13960
13961 /* BGP structure lookup. */
13962 if (argc == 4)
13963 {
13964 bgp = bgp_lookup_by_name (argv[0]);
13965 if (bgp == NULL)
13966 {
13967 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13968 return CMD_WARNING;
13969 }
13970 }
13971 else
13972 {
13973 bgp = bgp_get_default ();
13974 if (bgp == NULL)
13975 {
13976 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13977 return CMD_WARNING;
13978 }
13979 }
13980
13981 if (argc == 4) {
13982 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13983 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13984 } else {
13985 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13986 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13987 }
13988
13989 if (! peer)
13990 return CMD_WARNING;
13991
13992 if (! peer->afc[AFI_IP][safi])
13993 {
13994 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13995 VTY_NEWLINE);
13996 return CMD_WARNING;
13997}
13998
13999 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
14000 PEER_FLAG_RSERVER_CLIENT))
14001 {
14002 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14003 VTY_NEWLINE);
14004 return CMD_WARNING;
14005 }
14006
14007 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
14008 (argc == 4) ? argv[3] : argv[2],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014009 AFI_IP, safi, NULL, 0, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -040014010}
14011
14012ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
14013 show_bgp_ipv4_safi_rsclient_route_cmd,
14014 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
14015 SHOW_STR
14016 BGP_STR
14017 "Address family\n"
14018 "Address Family modifier\n"
14019 "Address Family modifier\n"
14020 "Information about Route Server Client\n"
14021 NEIGHBOR_ADDR_STR
14022 "Network in the BGP routing table to display\n")
14023
paulfee0f4c2004-09-13 05:12:46 +000014024
Michael Lambert95cbbd22010-07-23 14:43:04 -040014025DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
14026 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
14027 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
14028 SHOW_STR
14029 BGP_STR
14030 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014031 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014032 "Address family\n"
14033 "Address Family modifier\n"
14034 "Address Family modifier\n"
14035 "Information about Route Server Client\n"
14036 NEIGHBOR_ADDR_STR
14037 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14038{
14039 struct bgp *bgp;
14040 struct peer *peer;
14041 safi_t safi;
14042
14043 /* BGP structure lookup. */
14044 if (argc == 4)
14045 {
14046 bgp = bgp_lookup_by_name (argv[0]);
14047 if (bgp == NULL)
14048 {
14049 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14050 return CMD_WARNING;
14051 }
14052 }
14053 else
14054 {
14055 bgp = bgp_get_default ();
14056 if (bgp == NULL)
14057 {
14058 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14059 return CMD_WARNING;
14060 }
14061 }
14062
14063 if (argc == 4) {
14064 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14065 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14066 } else {
14067 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14068 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14069 }
14070
14071 if (! peer)
14072 return CMD_WARNING;
14073
14074 if (! peer->afc[AFI_IP][safi])
14075 {
14076 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14077 VTY_NEWLINE);
14078 return CMD_WARNING;
14079}
14080
14081 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
14082 PEER_FLAG_RSERVER_CLIENT))
14083{
14084 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14085 VTY_NEWLINE);
14086 return CMD_WARNING;
14087 }
14088
14089 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
14090 (argc == 4) ? argv[3] : argv[2],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014091 AFI_IP, safi, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -040014092}
14093
Lou Bergerf9b6c392016-01-12 13:42:09 -050014094DEFUN (show_ip_bgp_view_rsclient_prefix,
14095 show_ip_bgp_view_rsclient_prefix_cmd,
14096 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
14097 SHOW_STR
14098 IP_STR
14099 BGP_STR
14100 "BGP view\n"
14101 "View name\n"
14102 "Information about Route Server Client\n"
14103 NEIGHBOR_ADDR_STR
14104 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14105{
14106 struct bgp *bgp;
14107 struct peer *peer;
14108
14109 /* BGP structure lookup. */
14110 if (argc == 3)
14111 {
14112 bgp = bgp_lookup_by_name (argv[0]);
14113 if (bgp == NULL)
14114 {
14115 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14116 return CMD_WARNING;
14117 }
14118 }
14119 else
14120 {
14121 bgp = bgp_get_default ();
14122 if (bgp == NULL)
14123 {
14124 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14125 return CMD_WARNING;
14126 }
14127 }
14128
14129 if (argc == 3)
14130 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14131 else
14132 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14133
14134 if (! peer)
14135 return CMD_WARNING;
14136
14137 if (! peer->afc[AFI_IP][SAFI_UNICAST])
14138 {
14139 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14140 VTY_NEWLINE);
14141 return CMD_WARNING;
14142}
14143
14144 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
14145 PEER_FLAG_RSERVER_CLIENT))
14146{
14147 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14148 VTY_NEWLINE);
14149 return CMD_WARNING;
14150 }
14151
14152 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
14153 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014154 AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -050014155}
14156
14157ALIAS (show_ip_bgp_view_rsclient_prefix,
14158 show_ip_bgp_rsclient_prefix_cmd,
14159 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
14160 SHOW_STR
14161 IP_STR
14162 BGP_STR
14163 "Information about Route Server Client\n"
14164 NEIGHBOR_ADDR_STR
14165 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14166
Michael Lambert95cbbd22010-07-23 14:43:04 -040014167ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
14168 show_bgp_ipv4_safi_rsclient_prefix_cmd,
14169 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
14170 SHOW_STR
14171 BGP_STR
14172 "Address family\n"
14173 "Address Family modifier\n"
14174 "Address Family modifier\n"
14175 "Information about Route Server Client\n"
14176 NEIGHBOR_ADDR_STR
14177 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000014178
Lou Bergerf9b6c392016-01-12 13:42:09 -050014179DEFUN (show_bgp_view_ipv6_neighbor_routes,
Lou Berger651b4022016-01-12 13:42:07 -050014180 show_bgp_view_ipv6_neighbor_routes_cmd,
14181 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
paulbb46e942003-10-24 19:02:03 +000014182 SHOW_STR
14183 BGP_STR
14184 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014185 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050014186 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000014187 "Detailed information on TCP and BGP neighbor connections\n"
14188 "Neighbor to display information about\n"
14189 "Neighbor to display information about\n"
14190 "Display routes learned from neighbor\n")
14191{
14192 struct peer *peer;
14193
14194 if (argc == 2)
14195 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14196 else
14197 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14198
14199 if (! peer)
14200 return CMD_WARNING;
14201
14202 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14203 bgp_show_type_neighbor);
14204}
14205
Lou Berger651b4022016-01-12 13:42:07 -050014206DEFUN (show_bgp_view_neighbor_damp,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014207 show_bgp_view_neighbor_damp_cmd,
14208 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14209 SHOW_STR
14210 BGP_STR
14211 "BGP view\n"
14212 "View name\n"
14213 "Detailed information on TCP and BGP neighbor connections\n"
14214 "Neighbor to display information about\n"
14215 "Neighbor to display information about\n"
14216 "Display the dampened routes received from neighbor\n")
14217{
14218 struct peer *peer;
14219
14220 if (argc == 2)
14221 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14222 else
14223 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14224
14225 if (! peer)
14226 return CMD_WARNING;
14227
14228 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14229 bgp_show_type_damp_neighbor);
14230}
14231
14232DEFUN (show_bgp_view_ipv6_neighbor_damp,
Lou Berger651b4022016-01-12 13:42:07 -050014233 show_bgp_view_ipv6_neighbor_damp_cmd,
14234 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
paulbb46e942003-10-24 19:02:03 +000014235 SHOW_STR
14236 BGP_STR
14237 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014238 "View name\n"
paulbb46e942003-10-24 19:02:03 +000014239 "Address family\n"
14240 "Detailed information on TCP and BGP neighbor connections\n"
14241 "Neighbor to display information about\n"
14242 "Neighbor to display information about\n"
paulbb46e942003-10-24 19:02:03 +000014243 "Display the dampened routes received from neighbor\n")
14244{
14245 struct peer *peer;
14246
14247 if (argc == 2)
14248 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14249 else
14250 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14251
14252 if (! peer)
14253 return CMD_WARNING;
14254
14255 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14256 bgp_show_type_damp_neighbor);
14257}
14258
Lou Bergerf9b6c392016-01-12 13:42:09 -050014259DEFUN (show_bgp_view_ipv6_neighbor_flap,
Lou Berger651b4022016-01-12 13:42:07 -050014260 show_bgp_view_ipv6_neighbor_flap_cmd,
14261 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paulbb46e942003-10-24 19:02:03 +000014262 SHOW_STR
14263 BGP_STR
14264 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014265 "View name\n"
paulbb46e942003-10-24 19:02:03 +000014266 "Address family\n"
14267 "Detailed information on TCP and BGP neighbor connections\n"
14268 "Neighbor to display information about\n"
14269 "Neighbor to display information about\n"
14270 "Display the dampened routes received from neighbor\n")
paulbb46e942003-10-24 19:02:03 +000014271{
14272 struct peer *peer;
14273
14274 if (argc == 2)
14275 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14276 else
14277 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14278
14279 if (! peer)
14280 return CMD_WARNING;
14281
14282 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14283 bgp_show_type_flap_neighbor);
14284}
14285
Lou Bergerf9b6c392016-01-12 13:42:09 -050014286DEFUN (show_bgp_view_neighbor_flap,
14287 show_bgp_view_neighbor_flap_cmd,
14288 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14289 SHOW_STR
14290 BGP_STR
14291 "BGP view\n"
14292 "View name\n"
14293 "Detailed information on TCP and BGP neighbor connections\n"
14294 "Neighbor to display information about\n"
14295 "Neighbor to display information about\n"
14296 "Display flap statistics of the routes learned from neighbor\n")
14297{
14298 struct peer *peer;
14299
14300 if (argc == 2)
14301 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14302 else
14303 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14304
14305 if (! peer)
14306 return CMD_WARNING;
14307
14308 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14309 bgp_show_type_flap_neighbor);
14310}
14311
14312ALIAS (show_bgp_view_neighbor_flap,
14313 show_bgp_neighbor_flap_cmd,
14314 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14315 SHOW_STR
14316 BGP_STR
14317 "Detailed information on TCP and BGP neighbor connections\n"
14318 "Neighbor to display information about\n"
14319 "Neighbor to display information about\n"
14320 "Display flap statistics of the routes learned from neighbor\n")
14321
14322ALIAS (show_bgp_view_neighbor_damp,
14323 show_bgp_neighbor_damp_cmd,
14324 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14325 SHOW_STR
14326 BGP_STR
14327 "Detailed information on TCP and BGP neighbor connections\n"
14328 "Neighbor to display information about\n"
14329 "Neighbor to display information about\n"
14330 "Display the dampened routes received from neighbor\n")
14331
14332DEFUN (show_bgp_view_neighbor_routes,
14333 show_bgp_view_neighbor_routes_cmd,
14334 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
14335 SHOW_STR
14336 BGP_STR
14337 "BGP view\n"
14338 "View name\n"
14339 "Detailed information on TCP and BGP neighbor connections\n"
14340 "Neighbor to display information about\n"
14341 "Neighbor to display information about\n"
14342 "Display routes learned from neighbor\n")
14343{
14344 struct peer *peer;
14345
14346 if (argc == 2)
14347 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14348 else
14349 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14350
14351 if (! peer)
14352 return CMD_WARNING;
14353
14354 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14355 bgp_show_type_neighbor);
14356}
14357
14358ALIAS (show_bgp_view_neighbor_routes,
14359 show_bgp_neighbor_routes_cmd,
14360 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
14361 SHOW_STR
14362 BGP_STR
14363 "Detailed information on TCP and BGP neighbor connections\n"
14364 "Neighbor to display information about\n"
14365 "Neighbor to display information about\n"
14366 "Display routes learned from neighbor\n")
14367
paulbb46e942003-10-24 19:02:03 +000014368ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000014369 show_bgp_ipv6_neighbor_routes_cmd,
14370 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
14371 SHOW_STR
14372 BGP_STR
14373 "Address family\n"
14374 "Detailed information on TCP and BGP neighbor connections\n"
14375 "Neighbor to display information about\n"
14376 "Neighbor to display information about\n"
14377 "Display routes learned from neighbor\n")
14378
Lou Bergerf9b6c392016-01-12 13:42:09 -050014379/* old command */
14380ALIAS (show_bgp_view_neighbor_routes,
14381 ipv6_bgp_neighbor_routes_cmd,
14382 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
14383 SHOW_STR
14384 IPV6_STR
14385 BGP_STR
14386 "Detailed information on TCP and BGP neighbor connections\n"
14387 "Neighbor to display information about\n"
14388 "Neighbor to display information about\n"
14389 "Display routes learned from neighbor\n")
14390
14391/* old command */
14392DEFUN (ipv6_mbgp_neighbor_routes,
14393 ipv6_mbgp_neighbor_routes_cmd,
14394 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
14395 SHOW_STR
14396 IPV6_STR
14397 MBGP_STR
14398 "Detailed information on TCP and BGP neighbor connections\n"
14399 "Neighbor to display information about\n"
14400 "Neighbor to display information about\n"
14401 "Display routes learned from neighbor\n")
14402{
14403 struct peer *peer;
14404
14405 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14406 if (! peer)
14407 return CMD_WARNING;
14408
14409 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
14410 bgp_show_type_neighbor);
14411}
14412
paulbb46e942003-10-24 19:02:03 +000014413ALIAS (show_bgp_view_neighbor_flap,
14414 show_bgp_ipv6_neighbor_flap_cmd,
14415 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14416 SHOW_STR
14417 BGP_STR
14418 "Address family\n"
14419 "Detailed information on TCP and BGP neighbor connections\n"
14420 "Neighbor to display information about\n"
14421 "Neighbor to display information about\n"
14422 "Display flap statistics of the routes learned from neighbor\n")
14423
14424ALIAS (show_bgp_view_neighbor_damp,
paulbb46e942003-10-24 19:02:03 +000014425 show_bgp_ipv6_neighbor_damp_cmd,
14426 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14427 SHOW_STR
14428 BGP_STR
14429 "Address family\n"
14430 "Detailed information on TCP and BGP neighbor connections\n"
14431 "Neighbor to display information about\n"
14432 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000014433 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000014434
Lou Bergerf9b6c392016-01-12 13:42:09 -050014435DEFUN (show_bgp_view_rsclient,
14436 show_bgp_view_rsclient_cmd,
14437 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
14438 SHOW_STR
14439 BGP_STR
14440 "BGP view\n"
14441 "View name\n"
14442 "Information about Route Server Client\n"
14443 NEIGHBOR_ADDR_STR)
14444{
14445 struct bgp_table *table;
14446 struct peer *peer;
14447
14448 if (argc == 2)
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 table = peer->rib[AFI_IP6][SAFI_UNICAST];
14472
14473 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14474}
14475
14476ALIAS (show_bgp_view_rsclient,
14477 show_bgp_rsclient_cmd,
14478 "show bgp rsclient (A.B.C.D|X:X::X:X)",
14479 SHOW_STR
14480 BGP_STR
14481 "Information about Route Server Client\n"
14482 NEIGHBOR_ADDR_STR)
14483
Lou Berger651b4022016-01-12 13:42:07 -050014484DEFUN (show_bgp_view_ipv4_rsclient,
14485 show_bgp_view_ipv4_rsclient_cmd,
14486 "show bgp view WORD ipv4 rsclient (A.B.C.D|X:X::X:X)",
paulfee0f4c2004-09-13 05:12:46 +000014487 SHOW_STR
14488 BGP_STR
14489 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014490 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050014491 "Address Family\n"
paulfee0f4c2004-09-13 05:12:46 +000014492 "Information about Route Server Client\n"
Lou Berger651b4022016-01-12 13:42:07 -050014493 NEIGHBOR_ADDR_STR2)
paulfee0f4c2004-09-13 05:12:46 +000014494{
Lou Berger651b4022016-01-12 13:42:07 -050014495 struct bgp_table *table;
14496 struct peer *peer;
14497
14498 if (argc == 2)
14499 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14500 else
14501 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14502
14503 if (! peer)
14504 return CMD_WARNING;
14505
14506 if (! peer->afc[AFI_IP][SAFI_UNICAST])
14507 {
14508 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14509 VTY_NEWLINE);
14510 return CMD_WARNING;
14511 }
14512
14513 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
14514 PEER_FLAG_RSERVER_CLIENT))
14515 {
14516 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14517 VTY_NEWLINE);
14518 return CMD_WARNING;
14519 }
14520
14521 table = peer->rib[AFI_IP][SAFI_UNICAST];
14522
14523 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14524}
14525DEFUN (show_bgp_view_ipv6_rsclient,
14526 show_bgp_view_ipv6_rsclient_cmd,
14527 "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X)",
14528 SHOW_STR
14529 BGP_STR
14530 "BGP view\n"
14531 "BGP view name\n"
14532 "Address Family\n"
14533 "Information about Route Server Client\n"
14534 NEIGHBOR_ADDR_STR2)
14535{
14536 struct bgp_table *table;
14537 struct peer *peer;
paulfee0f4c2004-09-13 05:12:46 +000014538
14539 if (argc == 2)
14540 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14541 else
14542 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14543
14544 if (! peer)
14545 return CMD_WARNING;
14546
14547 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14548 {
14549 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14550 VTY_NEWLINE);
14551 return CMD_WARNING;
14552 }
14553
14554 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14555 PEER_FLAG_RSERVER_CLIENT))
14556 {
14557 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14558 VTY_NEWLINE);
14559 return CMD_WARNING;
14560 }
14561
14562 table = peer->rib[AFI_IP6][SAFI_UNICAST];
14563
ajs5a646652004-11-05 01:25:55 +000014564 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000014565}
14566
Lou Berger651b4022016-01-12 13:42:07 -050014567ALIAS (show_bgp_view_ipv4_rsclient,
14568 show_bgp_ipv4_rsclient_cmd,
14569 "show bgp ipv4 rsclient (A.B.C.D|X:X::X:X)",
paulfee0f4c2004-09-13 05:12:46 +000014570 SHOW_STR
14571 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050014572 "Address Family\n"
paulfee0f4c2004-09-13 05:12:46 +000014573 "Information about Route Server Client\n"
Lou Berger651b4022016-01-12 13:42:07 -050014574 NEIGHBOR_ADDR_STR2)
14575
Lou Berger651b4022016-01-12 13:42:07 -050014576ALIAS (show_bgp_view_ipv6_rsclient,
14577 show_bgp_ipv6_rsclient_cmd,
14578 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X)",
14579 SHOW_STR
14580 BGP_STR
14581 "Address Family\n"
14582 "Information about Route Server Client\n"
14583 NEIGHBOR_ADDR_STR2)
paulfee0f4c2004-09-13 05:12:46 +000014584
Michael Lambert95cbbd22010-07-23 14:43:04 -040014585DEFUN (show_bgp_view_ipv6_safi_rsclient,
14586 show_bgp_view_ipv6_safi_rsclient_cmd,
14587 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
14588 SHOW_STR
14589 BGP_STR
14590 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014591 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014592 "Address family\n"
14593 "Address Family modifier\n"
14594 "Address Family modifier\n"
14595 "Information about Route Server Client\n"
14596 NEIGHBOR_ADDR_STR)
14597{
14598 struct bgp_table *table;
14599 struct peer *peer;
14600 safi_t safi;
14601
14602 if (argc == 3) {
14603 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14604 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14605 } else {
14606 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14607 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14608 }
14609
14610 if (! peer)
14611 return CMD_WARNING;
14612
14613 if (! peer->afc[AFI_IP6][safi])
14614 {
14615 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14616 VTY_NEWLINE);
14617 return CMD_WARNING;
14618 }
14619
14620 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14621 PEER_FLAG_RSERVER_CLIENT))
14622 {
14623 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14624 VTY_NEWLINE);
14625 return CMD_WARNING;
14626 }
14627
14628 table = peer->rib[AFI_IP6][safi];
14629
14630 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14631}
14632
14633ALIAS (show_bgp_view_ipv6_safi_rsclient,
14634 show_bgp_ipv6_safi_rsclient_cmd,
14635 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
14636 SHOW_STR
14637 BGP_STR
14638 "Address family\n"
14639 "Address Family modifier\n"
14640 "Address Family modifier\n"
14641 "Information about Route Server Client\n"
14642 NEIGHBOR_ADDR_STR)
14643
paulfee0f4c2004-09-13 05:12:46 +000014644DEFUN (show_bgp_view_rsclient_route,
14645 show_bgp_view_rsclient_route_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014646 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14647 SHOW_STR
14648 BGP_STR
14649 "BGP view\n"
14650 "View name\n"
14651 "Information about Route Server Client\n"
14652 NEIGHBOR_ADDR_STR
14653 "Network in the BGP routing table to display\n")
14654{
14655 struct bgp *bgp;
14656 struct peer *peer;
14657
14658 /* BGP structure lookup. */
14659 if (argc == 3)
14660 {
14661 bgp = bgp_lookup_by_name (argv[0]);
14662 if (bgp == NULL)
14663 {
14664 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14665 return CMD_WARNING;
14666 }
14667 }
14668 else
14669 {
14670 bgp = bgp_get_default ();
14671 if (bgp == NULL)
14672 {
14673 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14674 return CMD_WARNING;
14675 }
14676 }
14677
14678 if (argc == 3)
14679 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14680 else
14681 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14682
14683 if (! peer)
14684 return CMD_WARNING;
14685
14686 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14687 {
14688 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14689 VTY_NEWLINE);
14690 return CMD_WARNING;
14691 }
14692
14693 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14694 PEER_FLAG_RSERVER_CLIENT))
14695 {
14696 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14697 VTY_NEWLINE);
14698 return CMD_WARNING;
14699 }
14700
14701 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14702 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014703 AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -050014704}
14705
14706DEFUN (show_bgp_view_ipv6_rsclient_route,
14707 show_bgp_view_ipv6_rsclient_route_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014708 "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
paulfee0f4c2004-09-13 05:12:46 +000014709 SHOW_STR
14710 BGP_STR
14711 "BGP view\n"
Lou Berger651b4022016-01-12 13:42:07 -050014712 "BGP view name\n"
14713 "IP6_STR"
paulfee0f4c2004-09-13 05:12:46 +000014714 "Information about Route Server Client\n"
14715 NEIGHBOR_ADDR_STR
14716 "Network in the BGP routing table to display\n")
14717{
14718 struct bgp *bgp;
14719 struct peer *peer;
14720
14721 /* BGP structure lookup. */
14722 if (argc == 3)
14723 {
14724 bgp = bgp_lookup_by_name (argv[0]);
14725 if (bgp == NULL)
14726 {
14727 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14728 return CMD_WARNING;
14729 }
14730 }
14731 else
14732 {
14733 bgp = bgp_get_default ();
14734 if (bgp == NULL)
14735 {
14736 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14737 return CMD_WARNING;
14738 }
14739 }
14740
14741 if (argc == 3)
14742 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14743 else
14744 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14745
14746 if (! peer)
14747 return CMD_WARNING;
14748
14749 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14750 {
14751 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14752 VTY_NEWLINE);
14753 return CMD_WARNING;
14754 }
14755
14756 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14757 PEER_FLAG_RSERVER_CLIENT))
14758 {
14759 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14760 VTY_NEWLINE);
14761 return CMD_WARNING;
14762 }
14763
14764 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14765 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014766 AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
paulfee0f4c2004-09-13 05:12:46 +000014767}
14768
Lou Bergerf9b6c392016-01-12 13:42:09 -050014769ALIAS (show_bgp_view_ipv6_rsclient_route,
paulfee0f4c2004-09-13 05:12:46 +000014770 show_bgp_rsclient_route_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014771 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14772 SHOW_STR
14773 BGP_STR
14774 "Information about Route Server Client\n"
14775 NEIGHBOR_ADDR_STR
14776 "Network in the BGP routing table to display\n")
14777
14778ALIAS (show_bgp_view_ipv6_rsclient_route,
14779 show_bgp_ipv6_rsclient_route_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014780 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
paulfee0f4c2004-09-13 05:12:46 +000014781 SHOW_STR
14782 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050014783 IP6_STR
paulfee0f4c2004-09-13 05:12:46 +000014784 "Information about Route Server Client\n"
14785 NEIGHBOR_ADDR_STR
14786 "Network in the BGP routing table to display\n")
14787
Michael Lambert95cbbd22010-07-23 14:43:04 -040014788DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
14789 show_bgp_view_ipv6_safi_rsclient_route_cmd,
14790 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14791 SHOW_STR
14792 BGP_STR
14793 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014794 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014795 "Address family\n"
14796 "Address Family modifier\n"
14797 "Address Family modifier\n"
14798 "Information about Route Server Client\n"
14799 NEIGHBOR_ADDR_STR
14800 "Network in the BGP routing table to display\n")
14801{
14802 struct bgp *bgp;
14803 struct peer *peer;
14804 safi_t safi;
14805
14806 /* BGP structure lookup. */
14807 if (argc == 4)
14808 {
14809 bgp = bgp_lookup_by_name (argv[0]);
14810 if (bgp == NULL)
14811 {
14812 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14813 return CMD_WARNING;
14814 }
14815 }
14816 else
14817 {
14818 bgp = bgp_get_default ();
14819 if (bgp == NULL)
14820 {
14821 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14822 return CMD_WARNING;
14823 }
14824 }
14825
14826 if (argc == 4) {
14827 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14828 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14829 } else {
14830 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14831 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14832 }
14833
14834 if (! peer)
14835 return CMD_WARNING;
14836
14837 if (! peer->afc[AFI_IP6][safi])
14838 {
14839 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14840 VTY_NEWLINE);
14841 return CMD_WARNING;
14842}
14843
14844 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14845 PEER_FLAG_RSERVER_CLIENT))
14846 {
14847 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14848 VTY_NEWLINE);
14849 return CMD_WARNING;
14850 }
14851
14852 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
14853 (argc == 4) ? argv[3] : argv[2],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014854 AFI_IP6, safi, NULL, 0, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -040014855}
14856
14857ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
14858 show_bgp_ipv6_safi_rsclient_route_cmd,
14859 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14860 SHOW_STR
14861 BGP_STR
14862 "Address family\n"
14863 "Address Family modifier\n"
14864 "Address Family modifier\n"
14865 "Information about Route Server Client\n"
14866 NEIGHBOR_ADDR_STR
14867 "Network in the BGP routing table to display\n")
14868
Lou Berger651b4022016-01-12 13:42:07 -050014869
paulfee0f4c2004-09-13 05:12:46 +000014870DEFUN (show_bgp_view_rsclient_prefix,
14871 show_bgp_view_rsclient_prefix_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014872 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
14873 SHOW_STR
14874 BGP_STR
14875 "BGP view\n"
14876 "View name\n"
14877 "Information about Route Server Client\n"
14878 NEIGHBOR_ADDR_STR
14879 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14880{
14881 struct bgp *bgp;
14882 struct peer *peer;
14883
14884 /* BGP structure lookup. */
14885 if (argc == 3)
14886 {
14887 bgp = bgp_lookup_by_name (argv[0]);
14888 if (bgp == NULL)
14889 {
14890 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14891 return CMD_WARNING;
14892 }
14893 }
14894 else
14895 {
14896 bgp = bgp_get_default ();
14897 if (bgp == NULL)
14898 {
14899 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14900 return CMD_WARNING;
14901 }
14902 }
14903
14904 if (argc == 3)
14905 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14906 else
14907 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14908
14909 if (! peer)
14910 return CMD_WARNING;
14911
14912 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14913 {
14914 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14915 VTY_NEWLINE);
14916 return CMD_WARNING;
14917 }
14918
14919 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14920 PEER_FLAG_RSERVER_CLIENT))
14921 {
14922 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14923 VTY_NEWLINE);
14924 return CMD_WARNING;
14925 }
14926
14927 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14928 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014929 AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -050014930}
14931
14932DEFUN (show_bgp_view_ipv6_rsclient_prefix,
14933 show_bgp_view_ipv6_rsclient_prefix_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014934 "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 +000014935 SHOW_STR
14936 BGP_STR
14937 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014938 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050014939 IP6_STR
paulfee0f4c2004-09-13 05:12:46 +000014940 "Information about Route Server Client\n"
14941 NEIGHBOR_ADDR_STR
14942 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14943{
14944 struct bgp *bgp;
14945 struct peer *peer;
14946
14947 /* BGP structure lookup. */
14948 if (argc == 3)
14949 {
14950 bgp = bgp_lookup_by_name (argv[0]);
14951 if (bgp == NULL)
14952 {
14953 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14954 return CMD_WARNING;
14955 }
14956 }
14957 else
14958 {
14959 bgp = bgp_get_default ();
14960 if (bgp == NULL)
14961 {
14962 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14963 return CMD_WARNING;
14964 }
14965 }
14966
14967 if (argc == 3)
14968 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14969 else
14970 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14971
14972 if (! peer)
14973 return CMD_WARNING;
14974
14975 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14976 {
14977 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14978 VTY_NEWLINE);
14979 return CMD_WARNING;
14980 }
14981
14982 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14983 PEER_FLAG_RSERVER_CLIENT))
14984 {
14985 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14986 VTY_NEWLINE);
14987 return CMD_WARNING;
14988 }
14989
14990 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14991 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014992 AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
paulfee0f4c2004-09-13 05:12:46 +000014993}
14994
Lou Bergerf9b6c392016-01-12 13:42:09 -050014995ALIAS (show_bgp_view_ipv6_rsclient_prefix,
paulfee0f4c2004-09-13 05:12:46 +000014996 show_bgp_rsclient_prefix_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014997 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
14998 SHOW_STR
14999 BGP_STR
15000 "Information about Route Server Client\n"
15001 NEIGHBOR_ADDR_STR
15002 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
15003
15004ALIAS (show_bgp_view_ipv6_rsclient_prefix,
15005 show_bgp_ipv6_rsclient_prefix_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050015006 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
paulfee0f4c2004-09-13 05:12:46 +000015007 SHOW_STR
15008 BGP_STR
15009 "Information about Route Server Client\n"
15010 NEIGHBOR_ADDR_STR
15011 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
15012
Michael Lambert95cbbd22010-07-23 14:43:04 -040015013DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
15014 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
15015 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
15016 SHOW_STR
15017 BGP_STR
15018 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000015019 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040015020 "Address family\n"
15021 "Address Family modifier\n"
15022 "Address Family modifier\n"
15023 "Information about Route Server Client\n"
15024 NEIGHBOR_ADDR_STR
15025 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
15026{
15027 struct bgp *bgp;
15028 struct peer *peer;
15029 safi_t safi;
15030
15031 /* BGP structure lookup. */
15032 if (argc == 4)
15033 {
15034 bgp = bgp_lookup_by_name (argv[0]);
15035 if (bgp == NULL)
15036 {
15037 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
15038 return CMD_WARNING;
15039 }
15040 }
15041 else
15042 {
15043 bgp = bgp_get_default ();
15044 if (bgp == NULL)
15045 {
15046 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
15047 return CMD_WARNING;
15048 }
15049 }
15050
15051 if (argc == 4) {
15052 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
15053 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
15054 } else {
15055 peer = peer_lookup_in_view (vty, NULL, argv[1]);
15056 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
15057 }
15058
15059 if (! peer)
15060 return CMD_WARNING;
15061
15062 if (! peer->afc[AFI_IP6][safi])
15063 {
15064 vty_out (vty, "%% Activate the neighbor for the address family first%s",
15065 VTY_NEWLINE);
15066 return CMD_WARNING;
15067}
15068
15069 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
15070 PEER_FLAG_RSERVER_CLIENT))
15071{
15072 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
15073 VTY_NEWLINE);
15074 return CMD_WARNING;
15075 }
15076
15077 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
15078 (argc == 4) ? argv[3] : argv[2],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070015079 AFI_IP6, safi, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -040015080}
15081
15082ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
15083 show_bgp_ipv6_safi_rsclient_prefix_cmd,
15084 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
15085 SHOW_STR
15086 BGP_STR
15087 "Address family\n"
15088 "Address Family modifier\n"
15089 "Address Family modifier\n"
15090 "Information about Route Server Client\n"
15091 NEIGHBOR_ADDR_STR
15092 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
15093
paul718e3742002-12-13 20:15:29 +000015094struct bgp_table *bgp_distance_table;
15095
15096struct bgp_distance
15097{
15098 /* Distance value for the IP source prefix. */
15099 u_char distance;
15100
15101 /* Name of the access-list to be matched. */
15102 char *access_list;
15103};
15104
paul94f2b392005-06-28 12:44:16 +000015105static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080015106bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000015107{
Stephen Hemminger393deb92008-08-18 14:13:29 -070015108 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000015109}
15110
paul94f2b392005-06-28 12:44:16 +000015111static void
paul718e3742002-12-13 20:15:29 +000015112bgp_distance_free (struct bgp_distance *bdistance)
15113{
15114 XFREE (MTYPE_BGP_DISTANCE, bdistance);
15115}
15116
paul94f2b392005-06-28 12:44:16 +000015117static int
paulfd79ac92004-10-13 05:06:08 +000015118bgp_distance_set (struct vty *vty, const char *distance_str,
15119 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000015120{
15121 int ret;
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015122 struct prefix p;
paul718e3742002-12-13 20:15:29 +000015123 u_char distance;
15124 struct bgp_node *rn;
15125 struct bgp_distance *bdistance;
15126
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015127 ret = str2prefix (ip_str, &p);
paul718e3742002-12-13 20:15:29 +000015128 if (ret == 0)
15129 {
15130 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
15131 return CMD_WARNING;
15132 }
15133
15134 distance = atoi (distance_str);
15135
15136 /* Get BGP distance node. */
15137 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
15138 if (rn->info)
15139 {
15140 bdistance = rn->info;
15141 bgp_unlock_node (rn);
15142 }
15143 else
15144 {
15145 bdistance = bgp_distance_new ();
15146 rn->info = bdistance;
15147 }
15148
15149 /* Set distance value. */
15150 bdistance->distance = distance;
15151
15152 /* Reset access-list configuration. */
15153 if (bdistance->access_list)
15154 {
15155 free (bdistance->access_list);
15156 bdistance->access_list = NULL;
15157 }
15158 if (access_list_str)
15159 bdistance->access_list = strdup (access_list_str);
15160
15161 return CMD_SUCCESS;
15162}
15163
paul94f2b392005-06-28 12:44:16 +000015164static int
paulfd79ac92004-10-13 05:06:08 +000015165bgp_distance_unset (struct vty *vty, const char *distance_str,
15166 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000015167{
15168 int ret;
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015169 struct prefix p;
paul718e3742002-12-13 20:15:29 +000015170 u_char distance;
15171 struct bgp_node *rn;
15172 struct bgp_distance *bdistance;
15173
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015174 ret = str2prefix (ip_str, &p);
paul718e3742002-12-13 20:15:29 +000015175 if (ret == 0)
15176 {
15177 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
15178 return CMD_WARNING;
15179 }
15180
15181 distance = atoi (distance_str);
15182
15183 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
15184 if (! rn)
15185 {
15186 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
15187 return CMD_WARNING;
15188 }
15189
15190 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010015191
15192 if (bdistance->distance != distance)
15193 {
15194 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
15195 return CMD_WARNING;
15196 }
15197
paul718e3742002-12-13 20:15:29 +000015198 if (bdistance->access_list)
15199 free (bdistance->access_list);
15200 bgp_distance_free (bdistance);
15201
15202 rn->info = NULL;
15203 bgp_unlock_node (rn);
15204 bgp_unlock_node (rn);
15205
15206 return CMD_SUCCESS;
15207}
15208
paul718e3742002-12-13 20:15:29 +000015209/* Apply BGP information to distance method. */
15210u_char
15211bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
15212{
15213 struct bgp_node *rn;
15214 struct prefix_ipv4 q;
15215 struct peer *peer;
15216 struct bgp_distance *bdistance;
15217 struct access_list *alist;
15218 struct bgp_static *bgp_static;
15219
15220 if (! bgp)
15221 return 0;
15222
15223 if (p->family != AF_INET)
15224 return 0;
15225
15226 peer = rinfo->peer;
15227
15228 if (peer->su.sa.sa_family != AF_INET)
15229 return 0;
15230
15231 memset (&q, 0, sizeof (struct prefix_ipv4));
15232 q.family = AF_INET;
15233 q.prefix = peer->su.sin.sin_addr;
15234 q.prefixlen = IPV4_MAX_BITLEN;
15235
15236 /* Check source address. */
15237 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
15238 if (rn)
15239 {
15240 bdistance = rn->info;
15241 bgp_unlock_node (rn);
15242
15243 if (bdistance->access_list)
15244 {
15245 alist = access_list_lookup (AFI_IP, bdistance->access_list);
15246 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
15247 return bdistance->distance;
15248 }
15249 else
15250 return bdistance->distance;
15251 }
15252
15253 /* Backdoor check. */
15254 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
15255 if (rn)
15256 {
15257 bgp_static = rn->info;
15258 bgp_unlock_node (rn);
15259
15260 if (bgp_static->backdoor)
15261 {
15262 if (bgp->distance_local)
15263 return bgp->distance_local;
15264 else
15265 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15266 }
15267 }
15268
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000015269 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000015270 {
15271 if (bgp->distance_ebgp)
15272 return bgp->distance_ebgp;
15273 return ZEBRA_EBGP_DISTANCE_DEFAULT;
15274 }
15275 else
15276 {
15277 if (bgp->distance_ibgp)
15278 return bgp->distance_ibgp;
15279 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15280 }
15281}
15282
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015283#ifdef HAVE_IPV6
15284/* Apply BGP information to ipv6 distance method. */
15285u_char
15286ipv6_bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
15287{
15288 struct bgp_node *rn;
15289 struct prefix_ipv6 q;
15290 struct peer *peer;
15291 struct bgp_distance *bdistance;
15292 struct access_list *alist;
15293 struct bgp_static *bgp_static;
15294
15295 if (! bgp)
15296 return 0;
15297
15298 if (p->family != AF_INET6)
15299 return 0;
15300
15301 peer = rinfo->peer;
15302
15303 if (peer->su.sa.sa_family != AF_INET6)
15304 return 0;
15305
15306 memset (&q, 0, sizeof (struct prefix_ipv6));
15307 q.family = AF_INET;
15308 q.prefix = peer->su.sin6.sin6_addr;
15309 q.prefixlen = IPV6_MAX_BITLEN;
15310
15311 /* Check source address. */
15312 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
15313 if (rn)
15314 {
15315 bdistance = rn->info;
15316 bgp_unlock_node (rn);
15317
15318 if (bdistance->access_list)
15319 {
15320 alist = access_list_lookup (AFI_IP6, bdistance->access_list);
15321 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
15322 return bdistance->distance;
15323 }
15324 else
15325 return bdistance->distance;
15326 }
15327 /* Backdoor check. */
15328 rn = bgp_node_lookup (bgp->route[AFI_IP6][SAFI_UNICAST], p);
15329 if (rn)
15330 {
15331 bgp_static = rn->info;
15332 bgp_unlock_node (rn);
15333
15334 if (bgp_static->backdoor)
15335 {
15336 if (bgp->ipv6_distance_local)
15337 return bgp->ipv6_distance_local;
15338 else
15339 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15340 }
15341 }
15342
15343 if (peer_sort (peer) == BGP_PEER_EBGP)
15344 {
15345 if (bgp->ipv6_distance_ebgp)
15346 return bgp->ipv6_distance_ebgp;
15347 return ZEBRA_EBGP_DISTANCE_DEFAULT;
15348 }
15349 else
15350 {
15351 if (bgp->ipv6_distance_ibgp)
15352 return bgp->ipv6_distance_ibgp;
15353 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15354 }
15355}
15356#endif /* HAVE_IPV6 */
15357
paul718e3742002-12-13 20:15:29 +000015358DEFUN (bgp_distance,
15359 bgp_distance_cmd,
15360 "distance bgp <1-255> <1-255> <1-255>",
15361 "Define an administrative distance\n"
15362 "BGP distance\n"
15363 "Distance for routes external to the AS\n"
15364 "Distance for routes internal to the AS\n"
15365 "Distance for local routes\n")
15366{
15367 struct bgp *bgp;
15368
15369 bgp = vty->index;
15370
15371 bgp->distance_ebgp = atoi (argv[0]);
15372 bgp->distance_ibgp = atoi (argv[1]);
15373 bgp->distance_local = atoi (argv[2]);
15374 return CMD_SUCCESS;
15375}
15376
15377DEFUN (no_bgp_distance,
15378 no_bgp_distance_cmd,
15379 "no distance bgp <1-255> <1-255> <1-255>",
15380 NO_STR
15381 "Define an administrative distance\n"
15382 "BGP distance\n"
15383 "Distance for routes external to the AS\n"
15384 "Distance for routes internal to the AS\n"
15385 "Distance for local routes\n")
15386{
15387 struct bgp *bgp;
15388
15389 bgp = vty->index;
15390
15391 bgp->distance_ebgp= 0;
15392 bgp->distance_ibgp = 0;
15393 bgp->distance_local = 0;
15394 return CMD_SUCCESS;
15395}
15396
15397ALIAS (no_bgp_distance,
15398 no_bgp_distance2_cmd,
15399 "no distance bgp",
15400 NO_STR
15401 "Define an administrative distance\n"
15402 "BGP distance\n")
15403
15404DEFUN (bgp_distance_source,
15405 bgp_distance_source_cmd,
15406 "distance <1-255> A.B.C.D/M",
15407 "Define an administrative distance\n"
15408 "Administrative distance\n"
15409 "IP source prefix\n")
15410{
15411 bgp_distance_set (vty, argv[0], argv[1], NULL);
15412 return CMD_SUCCESS;
15413}
15414
15415DEFUN (no_bgp_distance_source,
15416 no_bgp_distance_source_cmd,
15417 "no distance <1-255> A.B.C.D/M",
15418 NO_STR
15419 "Define an administrative distance\n"
15420 "Administrative distance\n"
15421 "IP source prefix\n")
15422{
15423 bgp_distance_unset (vty, argv[0], argv[1], NULL);
15424 return CMD_SUCCESS;
15425}
15426
15427DEFUN (bgp_distance_source_access_list,
15428 bgp_distance_source_access_list_cmd,
15429 "distance <1-255> A.B.C.D/M WORD",
15430 "Define an administrative distance\n"
15431 "Administrative distance\n"
15432 "IP source prefix\n"
15433 "Access list name\n")
15434{
15435 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
15436 return CMD_SUCCESS;
15437}
15438
15439DEFUN (no_bgp_distance_source_access_list,
15440 no_bgp_distance_source_access_list_cmd,
15441 "no distance <1-255> A.B.C.D/M WORD",
15442 NO_STR
15443 "Define an administrative distance\n"
15444 "Administrative distance\n"
15445 "IP source prefix\n"
15446 "Access list name\n")
15447{
15448 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
15449 return CMD_SUCCESS;
15450}
David Lamparter6b0655a2014-06-04 06:53:35 +020015451
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015452#ifdef HAVE_IPV6
15453DEFUN (ipv6_bgp_distance,
15454 ipv6_bgp_distance_cmd,
15455 "distance bgp <1-255> <1-255> <1-255>",
15456 "Define an administrative distance\n"
15457 "BGP distance\n"
15458 "Distance for routes external to the AS\n"
15459 "Distance for routes internal to the AS\n"
15460 "Distance for local routes\n")
15461{
15462 struct bgp *bgp;
15463
15464 bgp = vty->index;
15465
15466 bgp->ipv6_distance_ebgp = atoi (argv[0]);
15467 bgp->ipv6_distance_ibgp = atoi (argv[1]);
15468 bgp->ipv6_distance_local = atoi (argv[2]);
15469 return CMD_SUCCESS;
15470}
15471
15472DEFUN (no_ipv6_bgp_distance,
15473 no_ipv6_bgp_distance_cmd,
15474 "no distance bgp <1-255> <1-255> <1-255>",
15475 NO_STR
15476 "Define an administrative distance\n"
15477 "BGP distance\n"
15478 "Distance for routes external to the AS\n"
15479 "Distance for routes internal to the AS\n"
15480 "Distance for local routes\n")
15481{
15482 struct bgp *bgp;
15483
15484 bgp = vty->index;
15485
15486 bgp->ipv6_distance_ebgp= 0;
15487 bgp->ipv6_distance_ibgp = 0;
15488 bgp->ipv6_distance_local = 0;
15489 return CMD_SUCCESS;
15490}
15491
15492ALIAS (no_ipv6_bgp_distance,
15493 no_ipv6_bgp_distance2_cmd,
15494 "no distance bgp",
15495 NO_STR
15496 "Define an administrative distance\n"
15497 "BGP distance\n")
15498
15499DEFUN (ipv6_bgp_distance_source,
15500 ipv6_bgp_distance_source_cmd,
15501 "distance <1-255> X:X::X:X/M",
15502 "Define an administrative distance\n"
15503 "Administrative distance\n"
15504 "IP source prefix\n")
15505{
15506 bgp_distance_set (vty, argv[0], argv[1], NULL);
15507 return CMD_SUCCESS;
15508}
15509
15510DEFUN (no_ipv6_bgp_distance_source,
15511 no_ipv6_bgp_distance_source_cmd,
15512 "no distance <1-255> X:X::X:X/M",
15513 NO_STR
15514 "Define an administrative distance\n"
15515 "Administrative distance\n"
15516 "IP source prefix\n")
15517{
15518 bgp_distance_unset (vty, argv[0], argv[1], NULL);
15519 return CMD_SUCCESS;
15520}
15521
15522DEFUN (ipv6_bgp_distance_source_access_list,
15523 ipv6_bgp_distance_source_access_list_cmd,
15524 "distance <1-255> X:X::X:X/M WORD",
15525 "Define an administrative distance\n"
15526 "Administrative distance\n"
15527 "IP source prefix\n"
15528 "Access list name\n")
15529{
15530 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
15531 return CMD_SUCCESS;
15532}
15533
15534DEFUN (no_ipv6_bgp_distance_source_access_list,
15535 no_ipv6_bgp_distance_source_access_list_cmd,
15536 "no distance <1-255> X:X::X:X/M WORD",
15537 NO_STR
15538 "Define an administrative distance\n"
15539 "Administrative distance\n"
15540 "IP source prefix\n"
15541 "Access list name\n")
15542{
15543 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
15544 return CMD_SUCCESS;
15545}
15546#endif
15547
paul718e3742002-12-13 20:15:29 +000015548DEFUN (bgp_damp_set,
15549 bgp_damp_set_cmd,
15550 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
15551 "BGP Specific commands\n"
15552 "Enable route-flap dampening\n"
15553 "Half-life time for the penalty\n"
15554 "Value to start reusing a route\n"
15555 "Value to start suppressing a route\n"
15556 "Maximum duration to suppress a stable route\n")
15557{
15558 struct bgp *bgp;
15559 int half = DEFAULT_HALF_LIFE * 60;
15560 int reuse = DEFAULT_REUSE;
15561 int suppress = DEFAULT_SUPPRESS;
15562 int max = 4 * half;
15563
15564 if (argc == 4)
15565 {
15566 half = atoi (argv[0]) * 60;
15567 reuse = atoi (argv[1]);
15568 suppress = atoi (argv[2]);
15569 max = atoi (argv[3]) * 60;
15570 }
15571 else if (argc == 1)
15572 {
15573 half = atoi (argv[0]) * 60;
15574 max = 4 * half;
15575 }
15576
15577 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000015578
15579 if (suppress < reuse)
15580 {
15581 vty_out (vty, "Suppress value cannot be less than reuse value %s",
15582 VTY_NEWLINE);
15583 return 0;
15584 }
15585
paul718e3742002-12-13 20:15:29 +000015586 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
15587 half, reuse, suppress, max);
15588}
15589
15590ALIAS (bgp_damp_set,
15591 bgp_damp_set2_cmd,
15592 "bgp dampening <1-45>",
15593 "BGP Specific commands\n"
15594 "Enable route-flap dampening\n"
15595 "Half-life time for the penalty\n")
15596
15597ALIAS (bgp_damp_set,
15598 bgp_damp_set3_cmd,
15599 "bgp dampening",
15600 "BGP Specific commands\n"
15601 "Enable route-flap dampening\n")
15602
15603DEFUN (bgp_damp_unset,
15604 bgp_damp_unset_cmd,
15605 "no bgp dampening",
15606 NO_STR
15607 "BGP Specific commands\n"
15608 "Enable route-flap dampening\n")
15609{
15610 struct bgp *bgp;
15611
15612 bgp = vty->index;
15613 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
15614}
15615
15616ALIAS (bgp_damp_unset,
15617 bgp_damp_unset2_cmd,
15618 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
15619 NO_STR
15620 "BGP Specific commands\n"
15621 "Enable route-flap dampening\n"
15622 "Half-life time for the penalty\n"
15623 "Value to start reusing a route\n"
15624 "Value to start suppressing a route\n"
15625 "Maximum duration to suppress a stable route\n")
15626
Lou Bergerf9b6c392016-01-12 13:42:09 -050015627DEFUN (show_ip_bgp_dampened_paths,
15628 show_ip_bgp_dampened_paths_cmd,
15629 "show ip bgp dampened-paths",
15630 SHOW_STR
15631 IP_STR
15632 BGP_STR
15633 "Display paths suppressed due to dampening\n")
15634{
15635 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
15636 NULL);
15637}
15638
15639ALIAS (show_ip_bgp_dampened_paths,
15640 show_ip_bgp_damp_dampened_paths_cmd,
15641 "show ip bgp dampening dampened-paths",
15642 SHOW_STR
15643 IP_STR
15644 BGP_STR
15645 "Display detailed information about dampening\n"
15646 "Display paths suppressed due to dampening\n")
15647
15648DEFUN (show_ip_bgp_flap_statistics,
15649 show_ip_bgp_flap_statistics_cmd,
15650 "show ip bgp flap-statistics",
15651 SHOW_STR
15652 IP_STR
15653 BGP_STR
15654 "Display flap statistics of routes\n")
15655{
15656 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
15657 bgp_show_type_flap_statistics, NULL);
15658}
15659
15660ALIAS (show_ip_bgp_flap_statistics,
15661 show_ip_bgp_damp_flap_statistics_cmd,
15662 "show ip bgp dampening flap-statistics",
15663 SHOW_STR
15664 IP_STR
15665 BGP_STR
15666 "Display detailed information about dampening\n"
15667 "Display flap statistics of routes\n")
15668
Lou Berger651b4022016-01-12 13:42:07 -050015669DEFUN (show_bgp_ipv4_safi_dampened_paths,
15670 show_bgp_ipv4_safi_dampened_paths_cmd,
15671 "show bgp ipv4 (encap|multicast|unicast|vpn) dampened-paths",
paul718e3742002-12-13 20:15:29 +000015672 SHOW_STR
paul718e3742002-12-13 20:15:29 +000015673 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015674 IP_STR
15675 "Address Family modifier\n"
15676 "Address Family modifier\n"
15677 "Address Family modifier\n"
15678 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000015679 "Display paths suppressed due to dampening\n")
15680{
Lou Berger651b4022016-01-12 13:42:07 -050015681 safi_t safi;
paul718e3742002-12-13 20:15:29 +000015682
Lou Berger651b4022016-01-12 13:42:07 -050015683 if (bgp_parse_safi(argv[0], &safi)) {
15684 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15685 return CMD_WARNING;
15686 }
15687
15688 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_dampend_paths, NULL);
15689}
15690ALIAS (show_bgp_ipv4_safi_dampened_paths,
15691 show_bgp_ipv4_safi_damp_dampened_paths_cmd,
15692 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening dampened-paths",
Balaji3921cc52015-05-16 23:12:17 +053015693 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053015694 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015695 IP_STR
15696 "Address Family modifier\n"
15697 "Address Family modifier\n"
15698 "Address Family modifier\n"
15699 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053015700 "Display detailed information about dampening\n"
15701 "Display paths suppressed due to dampening\n")
Lou Berger205e6742016-01-12 13:42:11 -050015702
Lou Berger651b4022016-01-12 13:42:07 -050015703DEFUN (show_bgp_ipv6_safi_dampened_paths,
15704 show_bgp_ipv6_safi_dampened_paths_cmd,
15705 "show bgp ipv6 (encap|multicast|unicast|vpn) dampened-paths",
paul718e3742002-12-13 20:15:29 +000015706 SHOW_STR
paul718e3742002-12-13 20:15:29 +000015707 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015708 IPV6_STR
15709 "Address Family modifier\n"
15710 "Address Family modifier\n"
15711 "Address Family modifier\n"
15712 "Address Family modifier\n"
15713 "Display paths suppressed due to dampening\n")
15714{
15715 safi_t safi;
15716
15717 if (bgp_parse_safi(argv[0], &safi)) {
15718 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15719 return CMD_WARNING;
15720 }
15721
15722 return bgp_show (vty, NULL, AFI_IP6, safi, bgp_show_type_dampend_paths, NULL);
15723}
15724ALIAS (show_bgp_ipv6_safi_dampened_paths,
15725 show_bgp_ipv6_safi_damp_dampened_paths_cmd,
15726 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening dampened-paths",
15727 SHOW_STR
15728 BGP_STR
15729 IPV6_STR
15730 "Address Family modifier\n"
15731 "Address Family modifier\n"
15732 "Address Family modifier\n"
15733 "Address Family modifier\n"
15734 "Display detailed information about dampening\n"
15735 "Display paths suppressed due to dampening\n")
Lou Berger651b4022016-01-12 13:42:07 -050015736
15737DEFUN (show_bgp_ipv4_safi_flap_statistics,
15738 show_bgp_ipv4_safi_flap_statistics_cmd,
15739 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics",
15740 SHOW_STR
15741 BGP_STR
15742 "Address Family\n"
15743 "Address Family modifier\n"
15744 "Address Family modifier\n"
15745 "Address Family modifier\n"
15746 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000015747 "Display flap statistics of routes\n")
15748{
Lou Berger651b4022016-01-12 13:42:07 -050015749 safi_t safi;
David Lamparter6b0655a2014-06-04 06:53:35 +020015750
Lou Berger651b4022016-01-12 13:42:07 -050015751 if (bgp_parse_safi(argv[0], &safi)) {
15752 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15753 return CMD_WARNING;
15754 }
15755
15756 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_statistics, NULL);
15757}
15758ALIAS (show_bgp_ipv4_safi_flap_statistics,
15759 show_bgp_ipv4_safi_damp_flap_statistics_cmd,
15760 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics",
Balaji3921cc52015-05-16 23:12:17 +053015761 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053015762 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015763 "Address Family\n"
15764 "Address Family modifier\n"
15765 "Address Family modifier\n"
15766 "Address Family modifier\n"
15767 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053015768 "Display detailed information about dampening\n"
15769 "Display flap statistics of routes\n")
Lou Berger205e6742016-01-12 13:42:11 -050015770
Lou Berger651b4022016-01-12 13:42:07 -050015771DEFUN (show_bgp_ipv6_safi_flap_statistics,
15772 show_bgp_ipv6_safi_flap_statistics_cmd,
15773 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics",
15774 SHOW_STR
15775 BGP_STR
15776 "Address Family\n"
15777 "Address Family modifier\n"
15778 "Address Family modifier\n"
15779 "Address Family modifier\n"
15780 "Address Family modifier\n"
15781 "Display flap statistics of routes\n")
15782{
15783 safi_t safi;
15784
15785 if (bgp_parse_safi(argv[0], &safi)) {
15786 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15787 return CMD_WARNING;
15788 }
15789
15790 return bgp_show (vty, NULL, AFI_IP6, safi, bgp_show_type_flap_statistics, NULL);
15791}
15792ALIAS (show_bgp_ipv6_safi_flap_statistics,
15793 show_bgp_ipv6_safi_damp_flap_statistics_cmd,
15794 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics",
15795 SHOW_STR
15796 BGP_STR
15797 "Address Family\n"
15798 "Address Family modifier\n"
15799 "Address Family modifier\n"
15800 "Address Family modifier\n"
15801 "Address Family modifier\n"
15802 "Display detailed information about dampening\n"
15803 "Display flap statistics of routes\n")
Balaji3921cc52015-05-16 23:12:17 +053015804
paul718e3742002-12-13 20:15:29 +000015805/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000015806static int
paulfd79ac92004-10-13 05:06:08 +000015807bgp_clear_damp_route (struct vty *vty, const char *view_name,
15808 const char *ip_str, afi_t afi, safi_t safi,
15809 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000015810{
15811 int ret;
15812 struct prefix match;
15813 struct bgp_node *rn;
15814 struct bgp_node *rm;
15815 struct bgp_info *ri;
15816 struct bgp_info *ri_temp;
15817 struct bgp *bgp;
15818 struct bgp_table *table;
15819
15820 /* BGP structure lookup. */
15821 if (view_name)
15822 {
15823 bgp = bgp_lookup_by_name (view_name);
15824 if (bgp == NULL)
15825 {
15826 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
15827 return CMD_WARNING;
15828 }
15829 }
15830 else
15831 {
15832 bgp = bgp_get_default ();
15833 if (bgp == NULL)
15834 {
15835 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
15836 return CMD_WARNING;
15837 }
15838 }
15839
15840 /* Check IP address argument. */
15841 ret = str2prefix (ip_str, &match);
15842 if (! ret)
15843 {
15844 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
15845 return CMD_WARNING;
15846 }
15847
15848 match.family = afi2family (afi);
15849
Lou Berger298cc2f2016-01-12 13:42:02 -050015850 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000015851 {
Lou Berger298cc2f2016-01-12 13:42:02 -050015852 for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +000015853 {
15854 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
15855 continue;
15856
15857 if ((table = rn->info) != NULL)
15858 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000015859 {
15860 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
15861 {
15862 ri = rm->info;
15863 while (ri)
15864 {
15865 if (ri->extra && ri->extra->damp_info)
15866 {
15867 ri_temp = ri->next;
15868 bgp_damp_info_free (ri->extra->damp_info, 1);
15869 ri = ri_temp;
15870 }
15871 else
15872 ri = ri->next;
15873 }
15874 }
15875
15876 bgp_unlock_node (rm);
15877 }
paul718e3742002-12-13 20:15:29 +000015878 }
15879 }
15880 else
15881 {
15882 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000015883 {
15884 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
15885 {
15886 ri = rn->info;
15887 while (ri)
15888 {
15889 if (ri->extra && ri->extra->damp_info)
15890 {
15891 ri_temp = ri->next;
15892 bgp_damp_info_free (ri->extra->damp_info, 1);
15893 ri = ri_temp;
15894 }
15895 else
15896 ri = ri->next;
15897 }
15898 }
15899
15900 bgp_unlock_node (rn);
15901 }
paul718e3742002-12-13 20:15:29 +000015902 }
15903
15904 return CMD_SUCCESS;
15905}
15906
15907DEFUN (clear_ip_bgp_dampening,
15908 clear_ip_bgp_dampening_cmd,
15909 "clear ip bgp dampening",
15910 CLEAR_STR
15911 IP_STR
15912 BGP_STR
15913 "Clear route flap dampening information\n")
15914{
15915 bgp_damp_info_clean ();
15916 return CMD_SUCCESS;
15917}
15918
15919DEFUN (clear_ip_bgp_dampening_prefix,
15920 clear_ip_bgp_dampening_prefix_cmd,
15921 "clear ip bgp dampening A.B.C.D/M",
15922 CLEAR_STR
15923 IP_STR
15924 BGP_STR
15925 "Clear route flap dampening information\n"
15926 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
15927{
15928 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
15929 SAFI_UNICAST, NULL, 1);
15930}
15931
15932DEFUN (clear_ip_bgp_dampening_address,
15933 clear_ip_bgp_dampening_address_cmd,
15934 "clear ip bgp dampening A.B.C.D",
15935 CLEAR_STR
15936 IP_STR
15937 BGP_STR
15938 "Clear route flap dampening information\n"
15939 "Network to clear damping information\n")
15940{
15941 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
15942 SAFI_UNICAST, NULL, 0);
15943}
15944
15945DEFUN (clear_ip_bgp_dampening_address_mask,
15946 clear_ip_bgp_dampening_address_mask_cmd,
15947 "clear ip bgp dampening A.B.C.D A.B.C.D",
15948 CLEAR_STR
15949 IP_STR
15950 BGP_STR
15951 "Clear route flap dampening information\n"
15952 "Network to clear damping information\n"
15953 "Network mask\n")
15954{
15955 int ret;
15956 char prefix_str[BUFSIZ];
15957
15958 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
15959 if (! ret)
15960 {
15961 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
15962 return CMD_WARNING;
15963 }
15964
15965 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
15966 SAFI_UNICAST, NULL, 0);
15967}
David Lamparter6b0655a2014-06-04 06:53:35 +020015968
Lou Berger298cc2f2016-01-12 13:42:02 -050015969/* also used for encap safi */
paul94f2b392005-06-28 12:44:16 +000015970static int
paul718e3742002-12-13 20:15:29 +000015971bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
15972 afi_t afi, safi_t safi, int *write)
15973{
15974 struct bgp_node *prn;
15975 struct bgp_node *rn;
15976 struct bgp_table *table;
15977 struct prefix *p;
15978 struct prefix_rd *prd;
15979 struct bgp_static *bgp_static;
15980 u_int32_t label;
15981 char buf[SU_ADDRSTRLEN];
15982 char rdbuf[RD_ADDRSTRLEN];
15983
15984 /* Network configuration. */
15985 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
15986 if ((table = prn->info) != NULL)
15987 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
15988 if ((bgp_static = rn->info) != NULL)
15989 {
15990 p = &rn->p;
15991 prd = (struct prefix_rd *) &prn->p;
15992
15993 /* "address-family" display. */
15994 bgp_config_write_family_header (vty, afi, safi, write);
15995
15996 /* "network" configuration display. */
15997 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
15998 label = decode_label (bgp_static->tag);
15999
16000 vty_out (vty, " network %s/%d rd %s tag %d",
16001 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
16002 p->prefixlen,
16003 rdbuf, label);
16004 vty_out (vty, "%s", VTY_NEWLINE);
16005 }
16006 return 0;
16007}
16008
16009/* Configuration of static route announcement and aggregate
16010 information. */
16011int
16012bgp_config_write_network (struct vty *vty, struct bgp *bgp,
16013 afi_t afi, safi_t safi, int *write)
16014{
16015 struct bgp_node *rn;
16016 struct prefix *p;
16017 struct bgp_static *bgp_static;
16018 struct bgp_aggregate *bgp_aggregate;
16019 char buf[SU_ADDRSTRLEN];
16020
Lou Berger298cc2f2016-01-12 13:42:02 -050016021 if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
paul718e3742002-12-13 20:15:29 +000016022 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
16023
16024 /* Network configuration. */
16025 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
16026 if ((bgp_static = rn->info) != NULL)
16027 {
16028 p = &rn->p;
16029
16030 /* "address-family" display. */
16031 bgp_config_write_family_header (vty, afi, safi, write);
16032
16033 /* "network" configuration display. */
16034 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
16035 {
16036 u_int32_t destination;
16037 struct in_addr netmask;
16038
16039 destination = ntohl (p->u.prefix4.s_addr);
16040 masklen2ip (p->prefixlen, &netmask);
16041 vty_out (vty, " network %s",
16042 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
16043
16044 if ((IN_CLASSC (destination) && p->prefixlen == 24)
16045 || (IN_CLASSB (destination) && p->prefixlen == 16)
16046 || (IN_CLASSA (destination) && p->prefixlen == 8)
16047 || p->u.prefix4.s_addr == 0)
16048 {
16049 /* Natural mask is not display. */
16050 }
16051 else
16052 vty_out (vty, " mask %s", inet_ntoa (netmask));
16053 }
16054 else
16055 {
16056 vty_out (vty, " network %s/%d",
16057 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
16058 p->prefixlen);
16059 }
16060
16061 if (bgp_static->rmap.name)
16062 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000016063 else
16064 {
16065 if (bgp_static->backdoor)
16066 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000016067 }
paul718e3742002-12-13 20:15:29 +000016068
16069 vty_out (vty, "%s", VTY_NEWLINE);
16070 }
16071
16072 /* Aggregate-address configuration. */
16073 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
16074 if ((bgp_aggregate = rn->info) != NULL)
16075 {
16076 p = &rn->p;
16077
16078 /* "address-family" display. */
16079 bgp_config_write_family_header (vty, afi, safi, write);
16080
16081 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
16082 {
16083 struct in_addr netmask;
16084
16085 masklen2ip (p->prefixlen, &netmask);
16086 vty_out (vty, " aggregate-address %s %s",
16087 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
16088 inet_ntoa (netmask));
16089 }
16090 else
16091 {
16092 vty_out (vty, " aggregate-address %s/%d",
16093 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
16094 p->prefixlen);
16095 }
16096
16097 if (bgp_aggregate->as_set)
16098 vty_out (vty, " as-set");
16099
16100 if (bgp_aggregate->summary_only)
16101 vty_out (vty, " summary-only");
16102
16103 vty_out (vty, "%s", VTY_NEWLINE);
16104 }
16105
16106 return 0;
16107}
16108
16109int
Roman Hoog Antink6184c392014-03-17 14:01:42 +010016110bgp_config_write_distance (struct vty *vty, struct bgp *bgp,
16111 afi_t afi, safi_t safi, int *write)
paul718e3742002-12-13 20:15:29 +000016112{
16113 struct bgp_node *rn;
16114 struct bgp_distance *bdistance;
16115
Roman Hoog Antink6184c392014-03-17 14:01:42 +010016116 if (afi == AFI_IP && safi == SAFI_UNICAST)
16117 {
16118 /* Distance configuration. */
16119 if (bgp->distance_ebgp
16120 && bgp->distance_ibgp
16121 && bgp->distance_local
16122 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
16123 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
16124 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
16125 vty_out (vty, " distance bgp %d %d %d%s",
16126 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
16127 VTY_NEWLINE);
16128
16129 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
16130 if ((bdistance = rn->info) != NULL)
16131 {
16132 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
16133 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
16134 bdistance->access_list ? bdistance->access_list : "",
16135 VTY_NEWLINE);
16136 }
16137 }
16138
16139#ifdef HAVE_IPV6
16140 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
16141 {
16142 bgp_config_write_family_header (vty, afi, safi, write);
16143 if (bgp->ipv6_distance_ebgp
16144 && bgp->ipv6_distance_ibgp
16145 && bgp->ipv6_distance_local
16146 && (bgp->ipv6_distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
16147 || bgp->ipv6_distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
16148 || bgp->ipv6_distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
16149 vty_out (vty, " distance bgp %d %d %d%s",
16150 bgp->ipv6_distance_ebgp, bgp->ipv6_distance_ibgp, bgp->ipv6_distance_local,
16151 VTY_NEWLINE);
16152
16153 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
16154 if ((bdistance = rn->info) != NULL)
16155 {
16156 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
16157 inet6_ntoa (rn->p.u.prefix6), rn->p.prefixlen,
16158 bdistance->access_list ? bdistance->access_list : "",
16159 VTY_NEWLINE);
16160 }
16161 }
16162#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +000016163
16164 return 0;
16165}
16166
16167/* Allocate routing table structure and install commands. */
16168void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080016169bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000016170{
16171 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000016172 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000016173
16174 /* IPv4 BGP commands. */
16175 install_element (BGP_NODE, &bgp_network_cmd);
16176 install_element (BGP_NODE, &bgp_network_mask_cmd);
16177 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
16178 install_element (BGP_NODE, &bgp_network_route_map_cmd);
16179 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
16180 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
16181 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
16182 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
16183 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
16184 install_element (BGP_NODE, &no_bgp_network_cmd);
16185 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
16186 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
16187 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
16188 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
16189 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
16190 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
16191 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
16192 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
16193
16194 install_element (BGP_NODE, &aggregate_address_cmd);
16195 install_element (BGP_NODE, &aggregate_address_mask_cmd);
16196 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
16197 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
16198 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
16199 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
16200 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
16201 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
16202 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
16203 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
16204 install_element (BGP_NODE, &no_aggregate_address_cmd);
16205 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
16206 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
16207 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
16208 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
16209 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
16210 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
16211 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
16212 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
16213 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
16214
16215 /* IPv4 unicast configuration. */
16216 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
16217 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
16218 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
16219 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
16220 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
16221 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016222 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000016223 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
16224 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
16225 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
16226 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
16227 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016228
paul718e3742002-12-13 20:15:29 +000016229 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
16230 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
16231 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
16232 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
16233 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
16234 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
16235 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
16236 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
16237 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
16238 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
16239 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
16240 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
16241 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
16242 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
16243 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
16244 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
16245 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
16246 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
16247 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
16248 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
16249
16250 /* IPv4 multicast configuration. */
16251 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
16252 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
16253 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
16254 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
16255 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
16256 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
16257 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
16258 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
16259 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
16260 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
16261 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
16262 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
16263 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
16264 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
16265 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
16266 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
16267 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
16268 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
16269 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
16270 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
16271 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
16272 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
16273 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
16274 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
16275 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
16276 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
16277 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
16278 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
16279 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
16280 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
16281 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
16282 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
16283
Michael Lambert95cbbd22010-07-23 14:43:04 -040016284 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016285 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016286 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_route_cmd);
16287 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_route_cmd);
16288 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
16289 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
16290 install_element (VIEW_NODE, &show_bgp_ipv4_encap_route_cmd);
16291 install_element (VIEW_NODE, &show_bgp_ipv6_encap_route_cmd);
16292 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
16293 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
16294 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016295 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016296 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
16297 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
16298 install_element (VIEW_NODE, &show_bgp_ipv4_encap_prefix_cmd);
16299 install_element (VIEW_NODE, &show_bgp_ipv6_encap_prefix_cmd);
16300 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
16301 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
16302 install_element (VIEW_NODE, &show_bgp_afi_safi_view_cmd);
16303 install_element (VIEW_NODE, &show_bgp_view_afi_safi_route_cmd);
16304 install_element (VIEW_NODE, &show_bgp_view_afi_safi_prefix_cmd);
16305 install_element (VIEW_NODE, &show_bgp_ipv4_safi_regexp_cmd);
16306 install_element (VIEW_NODE, &show_bgp_ipv6_safi_regexp_cmd);
16307 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_list_cmd);
16308 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_list_cmd);
16309 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_list_cmd);
16310 install_element (VIEW_NODE, &show_bgp_ipv4_filter_list_cmd);
16311 install_element (VIEW_NODE, &show_bgp_ipv4_safi_filter_list_cmd);
16312 install_element (VIEW_NODE, &show_bgp_ipv6_safi_filter_list_cmd);
16313 install_element (VIEW_NODE, &show_bgp_ipv4_route_map_cmd);
16314 install_element (VIEW_NODE, &show_bgp_ipv4_cidr_only_cmd);
16315 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cidr_only_cmd);
16316 install_element (VIEW_NODE, &show_bgp_ipv4_community_cmd);
16317 install_element (VIEW_NODE, &show_bgp_ipv4_community2_cmd);
16318 install_element (VIEW_NODE, &show_bgp_ipv4_community3_cmd);
16319 install_element (VIEW_NODE, &show_bgp_ipv4_community4_cmd);
16320 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_cmd);
16321 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community2_cmd);
16322 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community3_cmd);
16323 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016324 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
16325 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
16326 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
16327 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
16328 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016329 install_element (VIEW_NODE, &show_bgp_ipv4_community_exact_cmd);
16330 install_element (VIEW_NODE, &show_bgp_ipv4_community2_exact_cmd);
16331 install_element (VIEW_NODE, &show_bgp_ipv4_community3_exact_cmd);
16332 install_element (VIEW_NODE, &show_bgp_ipv4_community4_exact_cmd);
16333 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
16334 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
16335 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
16336 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
16337 install_element (VIEW_NODE, &show_bgp_ipv4_community_list_cmd);
16338 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_list_cmd);
16339 install_element (VIEW_NODE, &show_bgp_ipv4_community_list_exact_cmd);
16340 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_list_exact_cmd);
16341 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_longer_cmd);
16342 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_longer_cmd);
16343 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_longer_cmd);
16344 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_advertised_route_cmd);
16345 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_advertised_route_cmd);
16346 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_received_routes_cmd);
16347 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016348 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016349 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_routes_cmd);
16350 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_routes_cmd);
16351 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd);
16352 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd);
16353 install_element (VIEW_NODE, &show_bgp_ipv4_safi_dampened_paths_cmd);
16354 install_element (VIEW_NODE, &show_bgp_ipv6_safi_dampened_paths_cmd);
16355 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_dampened_paths_cmd);
16356 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_dampened_paths_cmd);
16357 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_statistics_cmd);
16358 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_statistics_cmd);
16359 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_statistics_cmd);
16360 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_statistics_cmd);
16361 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_address_cmd);
16362 install_element (VIEW_NODE, &show_bgp_ipv6_flap_address_cmd);
16363 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_address_cmd);
16364 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_cmd);
16365 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_cmd);
16366 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_cmd);
16367 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_cmd);
16368 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_cidr_only_cmd);
16369 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_cidr_only_cmd);
16370 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_regexp_cmd);
16371 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_regexp_cmd);
16372 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_regexp_cmd);
16373 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_regexp_cmd);
16374 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_filter_list_cmd);
16375 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_filter_list_cmd);
16376 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_filter_list_cmd);
16377 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_filter_list_cmd);
16378 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_list_cmd);
16379 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_list_cmd);
16380 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_list_cmd);
16381 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_list_cmd);
16382 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_longer_cmd);
16383 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_longer_cmd);
16384 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd);
16385 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd);
16386 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_route_map_cmd);
16387 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_route_map_cmd);
16388 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_route_map_cmd);
16389 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_route_map_cmd);
16390 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_flap_cmd);
16391 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_flap_cmd);
16392 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_damp_cmd);
16393 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_damp_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016394 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016395 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016396 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016397 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016398 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016399 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016400
16401 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
Michael Lambert95cbbd22010-07-23 14:43:04 -040016402 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016403 install_element (RESTRICTED_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
16404 install_element (RESTRICTED_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
16405 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
16406 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
16407 install_element (RESTRICTED_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016408 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016409 install_element (RESTRICTED_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
16410 install_element (RESTRICTED_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
16411 install_element (RESTRICTED_NODE, &show_bgp_ipv4_encap_prefix_cmd);
16412 install_element (RESTRICTED_NODE, &show_bgp_ipv6_encap_prefix_cmd);
16413 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
16414 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
16415 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_route_cmd);
16416 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_prefix_cmd);
16417 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community_cmd);
16418 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community2_cmd);
16419 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community3_cmd);
16420 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community4_cmd);
16421 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community_cmd);
16422 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community2_cmd);
16423 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community3_cmd);
16424 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016425 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
16426 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
16427 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
16428 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
16429 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016430 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community_exact_cmd);
16431 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community2_exact_cmd);
16432 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community3_exact_cmd);
16433 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community4_exact_cmd);
16434 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
16435 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
16436 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
16437 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016438 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016439 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016440 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016441 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016442
Donald Sharp68b45cc2016-03-11 14:27:13 -050016443 /* BGP dampening clear commands */
paul718e3742002-12-13 20:15:29 +000016444 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
16445 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
16446 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
16447 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
16448
paul718e3742002-12-13 20:15:29 +000016449 /* New config IPv6 BGP commands. */
16450 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
16451 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
16452 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
16453 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
16454
16455 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
16456 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
16457 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
16458 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
16459
G.Balaji73bfe0b2011-09-23 22:36:20 +053016460 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
16461 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
16462
paul718e3742002-12-13 20:15:29 +000016463 /* Old config IPv6 BGP commands. */
16464 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
16465 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
16466
16467 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
16468 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
16469 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
16470 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
16471
Michael Lambert95cbbd22010-07-23 14:43:04 -040016472 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000016473 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016474 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000016475 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016476 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016477 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
paul718e3742002-12-13 20:15:29 +000016478 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000016479 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000016480 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016481 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_cmd);
16482 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community2_cmd);
16483 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community3_cmd);
16484 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community4_cmd);
16485 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_exact_cmd);
16486 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community2_exact_cmd);
16487 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community3_exact_cmd);
16488 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community4_exact_cmd);
paul718e3742002-12-13 20:15:29 +000016489 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
paul718e3742002-12-13 20:15:29 +000016490 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000016491 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
paul718e3742002-12-13 20:15:29 +000016492 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
paul718e3742002-12-13 20:15:29 +000016493 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
paul718e3742002-12-13 20:15:29 +000016494 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000016495 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000016496 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016497 install_element (VIEW_NODE, &show_bgp_ipv4_rsclient_cmd);
16498 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016499 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016500 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016501 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016502 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016503 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000016504 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
paulbb46e942003-10-24 19:02:03 +000016505 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
paulbb46e942003-10-24 19:02:03 +000016506 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000016507 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
paulbb46e942003-10-24 19:02:03 +000016508 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000016509 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000016510 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000016511 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000016512 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016513 install_element (VIEW_NODE, &show_bgp_view_ipv4_rsclient_cmd);
16514 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016515 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016516 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016517 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016518 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016519 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016520
16521 /* Restricted:
16522 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
16523 */
Paul Jakma62687ff2008-08-23 14:27:06 +010016524 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016525 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016526 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016527 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016528 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community_cmd);
16529 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community2_cmd);
16530 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community3_cmd);
16531 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community4_cmd);
16532 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community_exact_cmd);
16533 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community2_exact_cmd);
16534 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community3_exact_cmd);
16535 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community4_exact_cmd);
16536 install_element (RESTRICTED_NODE, &show_bgp_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016537 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016538 install_element (RESTRICTED_NODE, &show_bgp_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016539 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016540 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016541 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016542 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016543 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016544 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016545 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016546 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016547
Paul Jakma2815e612006-09-14 02:56:07 +000016548 /* Statistics */
16549 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016550 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
paul718e3742002-12-13 20:15:29 +000016551
16552 install_element (BGP_NODE, &bgp_distance_cmd);
16553 install_element (BGP_NODE, &no_bgp_distance_cmd);
16554 install_element (BGP_NODE, &no_bgp_distance2_cmd);
16555 install_element (BGP_NODE, &bgp_distance_source_cmd);
16556 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
16557 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
16558 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
Roman Hoog Antink6184c392014-03-17 14:01:42 +010016559#ifdef HAVE_IPV6
16560 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_cmd);
16561 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_cmd);
16562 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance2_cmd);
16563 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_cmd);
16564 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_cmd);
16565 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_access_list_cmd);
16566 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_access_list_cmd);
16567#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +000016568
16569 install_element (BGP_NODE, &bgp_damp_set_cmd);
16570 install_element (BGP_NODE, &bgp_damp_set2_cmd);
16571 install_element (BGP_NODE, &bgp_damp_set3_cmd);
16572 install_element (BGP_NODE, &bgp_damp_unset_cmd);
16573 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
16574 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
16575 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
16576 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
16577 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
16578 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Balaji9145f0e2016-01-20 22:59:27 +053016579
16580 /* IPv4 Multicast Mode */
16581 install_element (BGP_IPV4M_NODE, &bgp_damp_set_cmd);
16582 install_element (BGP_IPV4M_NODE, &bgp_damp_set2_cmd);
16583 install_element (BGP_IPV4M_NODE, &bgp_damp_set3_cmd);
16584 install_element (BGP_IPV4M_NODE, &bgp_damp_unset_cmd);
16585 install_element (BGP_IPV4M_NODE, &bgp_damp_unset2_cmd);
16586
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016587
16588 /* Deprecated AS-Pathlimit commands */
16589 install_element (BGP_NODE, &bgp_network_ttl_cmd);
16590 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
16591 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
16592 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
16593 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16594 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16595
16596 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
16597 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
16598 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16599 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
16600 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16601 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
16602
16603 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
16604 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
16605 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
16606 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
16607 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16608 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16609
16610 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
16611 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
16612 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16613 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
16614 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16615 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
16616
16617 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
16618 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
16619 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
16620 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
16621 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16622 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16623
16624 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
16625 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
16626 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16627 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
16628 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16629 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000016630
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016631 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
16632 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016633
16634 /* old style commands */
16635 install_element (VIEW_NODE, &show_ip_bgp_cmd);
16636 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
16637 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016638 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
16639 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016640 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
16641 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
16642 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
16643 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
16644 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016645 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
16646 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
16647 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016648 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
16649 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
16650 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
16651 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
16652 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
16653 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
16654 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
16655 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
16656 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
16657 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
16658 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
16659 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
16660 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
16661 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
16662 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
16663 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
16664 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
16665 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
16666 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
16667 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
16668 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
16669 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
16670 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
16671 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
16672 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
16673 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
16674 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
16675 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
16676 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
16677 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
16678 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
16679 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
16680 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
16681 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
16682 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
16683 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
16684 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
16685 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
16686 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
16687 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
16688 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
16689 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
16690 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
16691 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
16692 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
16693 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
16694 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
16695 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
Balaji9c52cae2016-01-20 22:59:26 +053016696 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_parameters_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016697 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji9c52cae2016-01-20 22:59:26 +053016698 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_dampd_paths_cmd);
16699 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_flap_stats_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016700 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
16701 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
16702 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
16703 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
16704 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
16705 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
16706 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
16707 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
16708 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
16709 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
16710 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
16711 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
16712 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
16713 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
16714 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
16715 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
16716 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
16717 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
16718 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
16719 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
16720 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
16721 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
16722 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
16723 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
16724 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
16725 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
16726 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016727
Lou Bergerf9b6c392016-01-12 13:42:09 -050016728 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016729 install_element (RESTRICTED_NODE, &show_ip_bgp_route_pathtype_cmd);
16730 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016731 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
16732 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
16733 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
16734 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016735 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
16736 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
16737 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016738 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
16739 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
16740 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
16741 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
16742 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
16743 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
16744 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
16745 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
16746 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
16747 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
16748 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
16749 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
16750 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
16751 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
16752 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
16753 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
16754 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
16755 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
16756 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
16757 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
16758 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
16759 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
16760 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
16761 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016762
16763 install_element (VIEW_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
16764 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
16765 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016766
Lou Bergerf9b6c392016-01-12 13:42:09 -050016767 install_element (VIEW_NODE, &show_bgp_cmd);
16768 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
16769 install_element (VIEW_NODE, &show_bgp_route_cmd);
16770 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016771 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
16772 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
16773 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
16774 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
16775 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
16776 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016777 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
16778 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
16779 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
16780 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
16781 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
16782 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
16783 install_element (VIEW_NODE, &show_bgp_community_cmd);
16784 install_element (VIEW_NODE, &show_bgp_community2_cmd);
16785 install_element (VIEW_NODE, &show_bgp_community3_cmd);
16786 install_element (VIEW_NODE, &show_bgp_community4_cmd);
16787 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
16788 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
16789 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
16790 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
16791 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_list_cmd);
16792 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
16793 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_list_exact_cmd);
16794 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
16795 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
16796 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
16797 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
16798 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
16799 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
16800 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
16801 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
16802 install_element (VIEW_NODE, &show_bgp_view_cmd);
16803 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
16804 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
16805 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
16806 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
16807 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
16808 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
16809 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
16810 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
16811 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016812
Lou Bergerf9b6c392016-01-12 13:42:09 -050016813 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
16814 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016815 install_element (RESTRICTED_NODE, &show_bgp_route_pathtype_cmd);
16816 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_pathtype_cmd);
16817 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
16818 install_element (RESTRICTED_NODE, &show_bgp_prefix_pathtype_cmd);
16819 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
16820 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016821 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
16822 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
16823 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
16824 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
16825 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
16826 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
16827 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
16828 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
16829 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
16830 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
16831 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016832
Lou Bergerf9b6c392016-01-12 13:42:09 -050016833 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
16834 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016835
Lou Bergerf9b6c392016-01-12 13:42:09 -050016836 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
16837 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
16838 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
16839 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
16840 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
16841 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
16842 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
16843 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
16844 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
16845 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
16846 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
16847 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
16848 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
16849 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
16850 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
16851 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
16852 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
16853 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
16854 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
16855 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
16856 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
16857 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
16858 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
16859 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
16860 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
16861 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
16862 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
16863 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
16864 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
16865 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
16866 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
16867 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
16868 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
16869 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
16870 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
16871 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016872 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016873 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016874 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016875 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016876 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016877 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016878 /* old with name safi collision */
16879 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
16880 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
16881 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
16882 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
16883 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
16884 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
16885 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
16886 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
16887 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
16888 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
16889 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
16890 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
16891 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
16892 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
16893 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
16894 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016895
Lou Bergerf9b6c392016-01-12 13:42:09 -050016896 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
16897 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016898
16899 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
16900 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
16901 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
16902 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016903
16904 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
16905 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
16906 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
16907 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016908}
Chris Caputo228da422009-07-18 05:44:03 +000016909
16910void
16911bgp_route_finish (void)
16912{
16913 bgp_table_unlock (bgp_distance_table);
16914 bgp_distance_table = NULL;
16915}