blob: 48645cf019211c54ecc74622814a4943c6fa12f7 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* BGP routing information
2 Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
23#include "prefix.h"
24#include "linklist.h"
25#include "memory.h"
26#include "command.h"
27#include "stream.h"
28#include "filter.h"
29#include "str.h"
30#include "log.h"
31#include "routemap.h"
32#include "buffer.h"
33#include "sockunion.h"
34#include "plist.h"
35#include "thread.h"
paul200df112005-06-01 11:17:05 +000036#include "workqueue.h"
paul718e3742002-12-13 20:15:29 +000037
38#include "bgpd/bgpd.h"
39#include "bgpd/bgp_table.h"
40#include "bgpd/bgp_route.h"
41#include "bgpd/bgp_attr.h"
42#include "bgpd/bgp_debug.h"
43#include "bgpd/bgp_aspath.h"
44#include "bgpd/bgp_regex.h"
45#include "bgpd/bgp_community.h"
46#include "bgpd/bgp_ecommunity.h"
47#include "bgpd/bgp_clist.h"
48#include "bgpd/bgp_packet.h"
49#include "bgpd/bgp_filter.h"
50#include "bgpd/bgp_fsm.h"
51#include "bgpd/bgp_mplsvpn.h"
52#include "bgpd/bgp_nexthop.h"
53#include "bgpd/bgp_damp.h"
54#include "bgpd/bgp_advertise.h"
55#include "bgpd/bgp_zebra.h"
hasso0a486e52005-02-01 20:57:17 +000056#include "bgpd/bgp_vty.h"
Josh Bailey96450fa2011-07-20 20:45:12 -070057#include "bgpd/bgp_mpath.h"
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -050058#include "bgpd/bgp_nht.c"
paul718e3742002-12-13 20:15:29 +000059
60/* Extern from bgp_dump.c */
Stephen Hemmingerdde72582009-05-08 15:19:07 -070061extern const char *bgp_origin_str[];
62extern const char *bgp_origin_long_str[];
David Lamparter6b0655a2014-06-04 06:53:35 +020063
paul94f2b392005-06-28 12:44:16 +000064static struct bgp_node *
paulfee0f4c2004-09-13 05:12:46 +000065bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
paul718e3742002-12-13 20:15:29 +000066 struct prefix_rd *prd)
67{
68 struct bgp_node *rn;
69 struct bgp_node *prn = NULL;
Paul Jakmada5b30f2006-05-08 14:37:17 +000070
71 assert (table);
72 if (!table)
73 return NULL;
74
Lou Berger298cc2f2016-01-12 13:42:02 -050075 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000076 {
paulfee0f4c2004-09-13 05:12:46 +000077 prn = bgp_node_get (table, (struct prefix *) prd);
paul718e3742002-12-13 20:15:29 +000078
79 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +000080 prn->info = bgp_table_init (afi, safi);
paul718e3742002-12-13 20:15:29 +000081 else
82 bgp_unlock_node (prn);
83 table = prn->info;
84 }
paul718e3742002-12-13 20:15:29 +000085
86 rn = bgp_node_get (table, p);
87
Lou Berger298cc2f2016-01-12 13:42:02 -050088 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000089 rn->prn = prn;
90
91 return rn;
92}
David Lamparter6b0655a2014-06-04 06:53:35 +020093
Paul Jakmafb982c22007-05-04 20:15:47 +000094/* Allocate bgp_info_extra */
95static struct bgp_info_extra *
96bgp_info_extra_new (void)
97{
98 struct bgp_info_extra *new;
99 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
100 return new;
101}
102
103static void
104bgp_info_extra_free (struct bgp_info_extra **extra)
105{
106 if (extra && *extra)
107 {
108 if ((*extra)->damp_info)
109 bgp_damp_info_free ((*extra)->damp_info, 0);
110
111 (*extra)->damp_info = NULL;
112
113 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
114
115 *extra = NULL;
116 }
117}
118
119/* Get bgp_info extra information for the given bgp_info, lazy allocated
120 * if required.
121 */
122struct bgp_info_extra *
123bgp_info_extra_get (struct bgp_info *ri)
124{
125 if (!ri->extra)
126 ri->extra = bgp_info_extra_new();
127 return ri->extra;
128}
129
paul718e3742002-12-13 20:15:29 +0000130/* Free bgp route information. */
paul200df112005-06-01 11:17:05 +0000131static void
paul718e3742002-12-13 20:15:29 +0000132bgp_info_free (struct bgp_info *binfo)
133{
134 if (binfo->attr)
Paul Jakmaf6f434b2010-11-23 21:28:03 +0000135 bgp_attr_unintern (&binfo->attr);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500136
137 bgp_unlink_nexthop(binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +0000138 bgp_info_extra_free (&binfo->extra);
Josh Baileyde8d5df2011-07-20 20:46:01 -0700139 bgp_info_mpath_free (&binfo->mpath);
paul718e3742002-12-13 20:15:29 +0000140
paul200df112005-06-01 11:17:05 +0000141 peer_unlock (binfo->peer); /* bgp_info peer reference */
142
paul718e3742002-12-13 20:15:29 +0000143 XFREE (MTYPE_BGP_ROUTE, binfo);
144}
145
paul200df112005-06-01 11:17:05 +0000146struct bgp_info *
147bgp_info_lock (struct bgp_info *binfo)
148{
149 binfo->lock++;
150 return binfo;
151}
152
153struct bgp_info *
154bgp_info_unlock (struct bgp_info *binfo)
155{
156 assert (binfo && binfo->lock > 0);
157 binfo->lock--;
158
159 if (binfo->lock == 0)
160 {
161#if 0
162 zlog_debug ("%s: unlocked and freeing", __func__);
163 zlog_backtrace (LOG_DEBUG);
164#endif
165 bgp_info_free (binfo);
166 return NULL;
167 }
168
169#if 0
170 if (binfo->lock == 1)
171 {
172 zlog_debug ("%s: unlocked to 1", __func__);
173 zlog_backtrace (LOG_DEBUG);
174 }
175#endif
176
177 return binfo;
178}
179
paul718e3742002-12-13 20:15:29 +0000180void
181bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
182{
183 struct bgp_info *top;
184
185 top = rn->info;
paul200df112005-06-01 11:17:05 +0000186
paul718e3742002-12-13 20:15:29 +0000187 ri->next = rn->info;
188 ri->prev = NULL;
189 if (top)
190 top->prev = ri;
191 rn->info = ri;
paul200df112005-06-01 11:17:05 +0000192
193 bgp_info_lock (ri);
194 bgp_lock_node (rn);
195 peer_lock (ri->peer); /* bgp_info peer reference */
paul718e3742002-12-13 20:15:29 +0000196}
197
paulb40d9392005-08-22 22:34:41 +0000198/* Do the actual removal of info from RIB, for use by bgp_process
199 completion callback *only* */
200static void
201bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
paul718e3742002-12-13 20:15:29 +0000202{
203 if (ri->next)
204 ri->next->prev = ri->prev;
205 if (ri->prev)
206 ri->prev->next = ri->next;
207 else
208 rn->info = ri->next;
paul200df112005-06-01 11:17:05 +0000209
Josh Baileyde8d5df2011-07-20 20:46:01 -0700210 bgp_info_mpath_dequeue (ri);
paul200df112005-06-01 11:17:05 +0000211 bgp_info_unlock (ri);
212 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000213}
214
paulb40d9392005-08-22 22:34:41 +0000215void
216bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
217{
Paul Jakma1a392d42006-09-07 00:24:49 +0000218 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
219 /* set of previous already took care of pcount */
paulb40d9392005-08-22 22:34:41 +0000220 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
221}
222
Andrew J. Schorr8d452102006-11-28 19:50:46 +0000223/* undo the effects of a previous call to bgp_info_delete; typically
224 called when a route is deleted and then quickly re-added before the
225 deletion has been processed */
226static void
227bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
228{
229 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
230 /* unset of previous already took care of pcount */
231 SET_FLAG (ri->flags, BGP_INFO_VALID);
232}
233
Paul Jakma1a392d42006-09-07 00:24:49 +0000234/* Adjust pcount as required */
235static void
236bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
237{
Avneesh Sachdev67174042012-08-17 08:19:49 -0700238 struct bgp_table *table;
239
240 assert (rn && bgp_node_table (rn));
Paul Jakma6f585442006-10-22 19:13:07 +0000241 assert (ri && ri->peer && ri->peer->bgp);
242
Avneesh Sachdev67174042012-08-17 08:19:49 -0700243 table = bgp_node_table (rn);
244
Paul Jakma1a392d42006-09-07 00:24:49 +0000245 /* Ignore 'pcount' for RS-client tables */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700246 if (table->type != BGP_TABLE_MAIN
Paul Jakma1a392d42006-09-07 00:24:49 +0000247 || ri->peer == ri->peer->bgp->peer_self)
248 return;
249
250 if (BGP_INFO_HOLDDOWN (ri)
251 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
252 {
253
254 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
255
256 /* slight hack, but more robust against errors. */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700257 if (ri->peer->pcount[table->afi][table->safi])
258 ri->peer->pcount[table->afi][table->safi]--;
Paul Jakma1a392d42006-09-07 00:24:49 +0000259 else
260 {
261 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
262 __func__, ri->peer->host);
263 zlog_backtrace (LOG_WARNING);
264 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
265 }
266 }
267 else if (!BGP_INFO_HOLDDOWN (ri)
268 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
269 {
270 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
Avneesh Sachdev67174042012-08-17 08:19:49 -0700271 ri->peer->pcount[table->afi][table->safi]++;
Paul Jakma1a392d42006-09-07 00:24:49 +0000272 }
273}
274
275
276/* Set/unset bgp_info flags, adjusting any other state as needed.
277 * This is here primarily to keep prefix-count in check.
278 */
279void
280bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
281{
282 SET_FLAG (ri->flags, flag);
283
284 /* early bath if we know it's not a flag that changes useability state */
285 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
286 return;
287
288 bgp_pcount_adjust (rn, ri);
289}
290
291void
292bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
293{
294 UNSET_FLAG (ri->flags, flag);
295
296 /* early bath if we know it's not a flag that changes useability state */
297 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
298 return;
299
300 bgp_pcount_adjust (rn, ri);
301}
302
paul718e3742002-12-13 20:15:29 +0000303/* Get MED value. If MED value is missing and "bgp bestpath
304 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000305static u_int32_t
paul718e3742002-12-13 20:15:29 +0000306bgp_med_value (struct attr *attr, struct bgp *bgp)
307{
308 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
309 return attr->med;
310 else
311 {
312 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000313 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000314 else
315 return 0;
316 }
317}
318
Paul Jakma6d4742b2015-11-25 17:14:37 +0000319/* Compare two bgp route entity. Return -1 if new is preferred, 1 if exist
320 * is preferred, or 0 if they are the same (usually will only occur if
321 * multipath is enabled */
paul94f2b392005-06-28 12:44:16 +0000322static int
Josh Bailey96450fa2011-07-20 20:45:12 -0700323bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
Paul Jakma6d4742b2015-11-25 17:14:37 +0000324 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +0000325{
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000326 struct attr *newattr, *existattr;
327 struct attr_extra *newattre, *existattre;
328 bgp_peer_sort_t new_sort;
329 bgp_peer_sort_t exist_sort;
paul718e3742002-12-13 20:15:29 +0000330 u_int32_t new_pref;
331 u_int32_t exist_pref;
332 u_int32_t new_med;
333 u_int32_t exist_med;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000334 u_int32_t new_weight;
335 u_int32_t exist_weight;
336 uint32_t newm, existm;
paul718e3742002-12-13 20:15:29 +0000337 struct in_addr new_id;
338 struct in_addr exist_id;
339 int new_cluster;
340 int exist_cluster;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000341 int internal_as_route;
342 int confed_as_route;
paul718e3742002-12-13 20:15:29 +0000343 int ret;
Josh Bailey96450fa2011-07-20 20:45:12 -0700344
paul718e3742002-12-13 20:15:29 +0000345 /* 0. Null check. */
346 if (new == NULL)
paul718e3742002-12-13 20:15:29 +0000347 return 1;
Paul Jakma6d4742b2015-11-25 17:14:37 +0000348 if (exist == NULL)
349 return -1;
paul718e3742002-12-13 20:15:29 +0000350
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000351 newattr = new->attr;
352 existattr = exist->attr;
353 newattre = newattr->extra;
354 existattre = existattr->extra;
355
paul718e3742002-12-13 20:15:29 +0000356 /* 1. Weight check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000357 new_weight = exist_weight = 0;
358
359 if (newattre)
360 new_weight = newattre->weight;
361 if (existattre)
362 exist_weight = existattre->weight;
363
Paul Jakmafb982c22007-05-04 20:15:47 +0000364 if (new_weight > exist_weight)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000365 return -1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000366 if (new_weight < exist_weight)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000367 return 1;
paul718e3742002-12-13 20:15:29 +0000368
369 /* 2. Local preference check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000370 new_pref = exist_pref = bgp->default_local_pref;
paul718e3742002-12-13 20:15:29 +0000371
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000372 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
373 new_pref = newattr->local_pref;
374 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
375 exist_pref = existattr->local_pref;
376
paul718e3742002-12-13 20:15:29 +0000377 if (new_pref > exist_pref)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000378 return -1;
paul718e3742002-12-13 20:15:29 +0000379 if (new_pref < exist_pref)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000380 return 1;
paul718e3742002-12-13 20:15:29 +0000381
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000382 /* 3. Local route check. We prefer:
383 * - BGP_ROUTE_STATIC
384 * - BGP_ROUTE_AGGREGATE
385 * - BGP_ROUTE_REDISTRIBUTE
386 */
387 if (! (new->sub_type == BGP_ROUTE_NORMAL))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000388 return -1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000389 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000390 return 1;
paul718e3742002-12-13 20:15:29 +0000391
392 /* 4. AS path length check. */
393 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
394 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000395 int exist_hops = aspath_count_hops (existattr->aspath);
396 int exist_confeds = aspath_count_confeds (existattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000397
hasso68118452005-04-08 15:40:36 +0000398 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
399 {
paulfe69a502005-09-10 16:55:02 +0000400 int aspath_hops;
401
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000402 aspath_hops = aspath_count_hops (newattr->aspath);
403 aspath_hops += aspath_count_confeds (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000404
405 if ( aspath_hops < (exist_hops + exist_confeds))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000406 return -1;
paulfe69a502005-09-10 16:55:02 +0000407 if ( aspath_hops > (exist_hops + exist_confeds))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000408 return 1;
hasso68118452005-04-08 15:40:36 +0000409 }
410 else
411 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000412 int newhops = aspath_count_hops (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000413
414 if (newhops < exist_hops)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000415 return -1;
paulfe69a502005-09-10 16:55:02 +0000416 if (newhops > exist_hops)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000417 return 1;
hasso68118452005-04-08 15:40:36 +0000418 }
paul718e3742002-12-13 20:15:29 +0000419 }
420
421 /* 5. Origin check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000422 if (newattr->origin < existattr->origin)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000423 return -1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000424 if (newattr->origin > existattr->origin)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000425 return 1;
paul718e3742002-12-13 20:15:29 +0000426
427 /* 6. MED check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000428 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
429 && aspath_count_hops (existattr->aspath) == 0);
430 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
431 && aspath_count_confeds (existattr->aspath) > 0
432 && aspath_count_hops (newattr->aspath) == 0
433 && aspath_count_hops (existattr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000434
435 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
436 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
437 && confed_as_route)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000438 || aspath_cmp_left (newattr->aspath, existattr->aspath)
439 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
paul718e3742002-12-13 20:15:29 +0000440 || internal_as_route)
441 {
442 new_med = bgp_med_value (new->attr, bgp);
443 exist_med = bgp_med_value (exist->attr, bgp);
444
445 if (new_med < exist_med)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000446 return -1;
paul718e3742002-12-13 20:15:29 +0000447 if (new_med > exist_med)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000448 return 1;
paul718e3742002-12-13 20:15:29 +0000449 }
450
451 /* 7. Peer type check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000452 new_sort = new->peer->sort;
453 exist_sort = exist->peer->sort;
454
455 if (new_sort == BGP_PEER_EBGP
456 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000457 return -1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000458 if (exist_sort == BGP_PEER_EBGP
459 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000460 return 1;
paul718e3742002-12-13 20:15:29 +0000461
462 /* 8. IGP metric check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000463 newm = existm = 0;
464
465 if (new->extra)
466 newm = new->extra->igpmetric;
467 if (exist->extra)
468 existm = exist->extra->igpmetric;
469
Josh Bailey96450fa2011-07-20 20:45:12 -0700470 if (newm < existm)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000471 return -1;
Josh Bailey96450fa2011-07-20 20:45:12 -0700472 if (newm > existm)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000473 return 1;
paul718e3742002-12-13 20:15:29 +0000474
475 /* 9. Maximum path check. */
Paul Jakma6d4742b2015-11-25 17:14:37 +0000476 if (bgp_mpath_is_configured (bgp, afi, safi))
Josh Bailey96450fa2011-07-20 20:45:12 -0700477 {
Pradosh Mohapatra2fdd4552013-09-07 07:02:36 +0000478 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
479 {
Paul Jakma6d4742b2015-11-25 17:14:37 +0000480 /*
481 * For the two paths, all comparison steps till IGP metric
482 * have succeeded - including AS_PATH hop count. Since 'bgp
483 * bestpath as-path multipath-relax' knob is on, we don't need
484 * an exact match of AS_PATH. Thus, mark the paths are equal.
485 * That will trigger both these paths to get into the multipath
486 * array.
487 */
488 return 0;
Pradosh Mohapatra2fdd4552013-09-07 07:02:36 +0000489 }
490 else if (new->peer->sort == BGP_PEER_IBGP)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000491 {
492 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
493 return 0;
494 }
Josh Bailey96450fa2011-07-20 20:45:12 -0700495 else if (new->peer->as == exist->peer->as)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000496 return 0;
Josh Bailey96450fa2011-07-20 20:45:12 -0700497 }
paul718e3742002-12-13 20:15:29 +0000498
499 /* 10. If both paths are external, prefer the path that was received
500 first (the oldest one). This step minimizes route-flap, since a
501 newer path won't displace an older one, even if it was the
502 preferred route based on the additional decision criteria below. */
503 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000504 && new_sort == BGP_PEER_EBGP
505 && exist_sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +0000506 {
507 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000508 return -1;
paul718e3742002-12-13 20:15:29 +0000509 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000510 return 1;
paul718e3742002-12-13 20:15:29 +0000511 }
512
vivekbd4b7f12014-09-30 15:54:45 -0700513 /* 11. Router-ID comparision. */
514 /* If one of the paths is "stale", the corresponding peer router-id will
515 * be 0 and would always win over the other path. If originator id is
516 * used for the comparision, it will decide which path is better.
517 */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000518 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
519 new_id.s_addr = newattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000520 else
521 new_id.s_addr = new->peer->remote_id.s_addr;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000522 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
523 exist_id.s_addr = existattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000524 else
525 exist_id.s_addr = exist->peer->remote_id.s_addr;
526
527 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000528 return -1;
paul718e3742002-12-13 20:15:29 +0000529 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000530 return 1;
paul718e3742002-12-13 20:15:29 +0000531
532 /* 12. Cluster length comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000533 new_cluster = exist_cluster = 0;
534
535 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
536 new_cluster = newattre->cluster->length;
537 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
538 exist_cluster = existattre->cluster->length;
paul718e3742002-12-13 20:15:29 +0000539
540 if (new_cluster < exist_cluster)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000541 return -1;
paul718e3742002-12-13 20:15:29 +0000542 if (new_cluster > exist_cluster)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000543 return 1;
paul718e3742002-12-13 20:15:29 +0000544
545 /* 13. Neighbor address comparision. */
vivekbd4b7f12014-09-30 15:54:45 -0700546 /* Do this only if neither path is "stale" as stale paths do not have
547 * valid peer information (as the connection may or may not be up).
548 */
549 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000550 return -1;
vivekbd4b7f12014-09-30 15:54:45 -0700551 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000552 return 1;
Timo Teräs2820a012015-06-24 15:27:21 +0300553 /* locally configured routes to advertise do not have su_remote */
554 if (new->peer->su_remote == NULL)
Timo Teräs2820a012015-06-24 15:27:21 +0300555 return 1;
Paul Jakma6d4742b2015-11-25 17:14:37 +0000556 if (exist->peer->su_remote == NULL)
557 return -1;
Timo Teräs2820a012015-06-24 15:27:21 +0300558
paul718e3742002-12-13 20:15:29 +0000559 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
560
561 if (ret == 1)
paul718e3742002-12-13 20:15:29 +0000562 return 1;
Paul Jakma6d4742b2015-11-25 17:14:37 +0000563 if (ret == -1)
564 return -1;
paul718e3742002-12-13 20:15:29 +0000565
Paul Jakma6d4742b2015-11-25 17:14:37 +0000566 return -1;
paul718e3742002-12-13 20:15:29 +0000567}
568
paul94f2b392005-06-28 12:44:16 +0000569static enum filter_type
paul718e3742002-12-13 20:15:29 +0000570bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
571 afi_t afi, safi_t safi)
572{
573 struct bgp_filter *filter;
574
575 filter = &peer->filter[afi][safi];
576
Paul Jakma650f76c2009-06-25 18:06:31 +0100577#define FILTER_EXIST_WARN(F,f,filter) \
578 if (BGP_DEBUG (update, UPDATE_IN) \
579 && !(F ## _IN (filter))) \
580 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
581 peer->host, #f, F ## _IN_NAME(filter));
582
583 if (DISTRIBUTE_IN_NAME (filter)) {
584 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
585
paul718e3742002-12-13 20:15:29 +0000586 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
587 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100588 }
paul718e3742002-12-13 20:15:29 +0000589
Paul Jakma650f76c2009-06-25 18:06:31 +0100590 if (PREFIX_LIST_IN_NAME (filter)) {
591 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
592
paul718e3742002-12-13 20:15:29 +0000593 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
594 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100595 }
paul718e3742002-12-13 20:15:29 +0000596
Paul Jakma650f76c2009-06-25 18:06:31 +0100597 if (FILTER_LIST_IN_NAME (filter)) {
598 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
599
paul718e3742002-12-13 20:15:29 +0000600 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
601 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100602 }
603
paul718e3742002-12-13 20:15:29 +0000604 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100605#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000606}
607
paul94f2b392005-06-28 12:44:16 +0000608static enum filter_type
paul718e3742002-12-13 20:15:29 +0000609bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
610 afi_t afi, safi_t safi)
611{
612 struct bgp_filter *filter;
613
614 filter = &peer->filter[afi][safi];
615
Paul Jakma650f76c2009-06-25 18:06:31 +0100616#define FILTER_EXIST_WARN(F,f,filter) \
617 if (BGP_DEBUG (update, UPDATE_OUT) \
618 && !(F ## _OUT (filter))) \
619 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
620 peer->host, #f, F ## _OUT_NAME(filter));
621
622 if (DISTRIBUTE_OUT_NAME (filter)) {
623 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
624
paul718e3742002-12-13 20:15:29 +0000625 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
626 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100627 }
paul718e3742002-12-13 20:15:29 +0000628
Paul Jakma650f76c2009-06-25 18:06:31 +0100629 if (PREFIX_LIST_OUT_NAME (filter)) {
630 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
631
paul718e3742002-12-13 20:15:29 +0000632 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
633 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100634 }
paul718e3742002-12-13 20:15:29 +0000635
Paul Jakma650f76c2009-06-25 18:06:31 +0100636 if (FILTER_LIST_OUT_NAME (filter)) {
637 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
638
paul718e3742002-12-13 20:15:29 +0000639 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
640 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100641 }
paul718e3742002-12-13 20:15:29 +0000642
643 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100644#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000645}
646
647/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000648static int
paul718e3742002-12-13 20:15:29 +0000649bgp_community_filter (struct peer *peer, struct attr *attr)
650{
651 if (attr->community)
652 {
653 /* NO_ADVERTISE check. */
654 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
655 return 1;
656
657 /* NO_EXPORT check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000658 if (peer->sort == BGP_PEER_EBGP &&
paul718e3742002-12-13 20:15:29 +0000659 community_include (attr->community, COMMUNITY_NO_EXPORT))
660 return 1;
661
662 /* NO_EXPORT_SUBCONFED check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000663 if (peer->sort == BGP_PEER_EBGP
664 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000665 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
666 return 1;
667 }
668 return 0;
669}
670
671/* Route reflection loop check. */
672static int
673bgp_cluster_filter (struct peer *peer, struct attr *attr)
674{
675 struct in_addr cluster_id;
676
Paul Jakmafb982c22007-05-04 20:15:47 +0000677 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000678 {
679 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
680 cluster_id = peer->bgp->cluster_id;
681 else
682 cluster_id = peer->bgp->router_id;
683
Paul Jakmafb982c22007-05-04 20:15:47 +0000684 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000685 return 1;
686 }
687 return 0;
688}
David Lamparter6b0655a2014-06-04 06:53:35 +0200689
paul94f2b392005-06-28 12:44:16 +0000690static int
paul718e3742002-12-13 20:15:29 +0000691bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
692 afi_t afi, safi_t safi)
693{
694 struct bgp_filter *filter;
695 struct bgp_info info;
696 route_map_result_t ret;
697
698 filter = &peer->filter[afi][safi];
699
700 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000701 if (peer->weight)
702 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000703
704 /* Route map apply. */
705 if (ROUTE_MAP_IN_NAME (filter))
706 {
707 /* Duplicate current value to new strucutre for modification. */
708 info.peer = peer;
709 info.attr = attr;
710
paulac41b2a2003-08-12 05:32:27 +0000711 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
712
paul718e3742002-12-13 20:15:29 +0000713 /* Apply BGP route map to the attribute. */
714 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000715
716 peer->rmap_type = 0;
717
paul718e3742002-12-13 20:15:29 +0000718 if (ret == RMAP_DENYMATCH)
David Lamparterc460e572014-06-04 00:54:58 +0200719 /* caller has multiple error paths with bgp_attr_flush() */
720 return RMAP_DENY;
paul718e3742002-12-13 20:15:29 +0000721 }
722 return RMAP_PERMIT;
723}
David Lamparter6b0655a2014-06-04 06:53:35 +0200724
paul94f2b392005-06-28 12:44:16 +0000725static int
paulfee0f4c2004-09-13 05:12:46 +0000726bgp_export_modifier (struct peer *rsclient, struct peer *peer,
727 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
728{
729 struct bgp_filter *filter;
730 struct bgp_info info;
731 route_map_result_t ret;
732
733 filter = &peer->filter[afi][safi];
734
735 /* Route map apply. */
736 if (ROUTE_MAP_EXPORT_NAME (filter))
737 {
738 /* Duplicate current value to new strucutre for modification. */
739 info.peer = rsclient;
740 info.attr = attr;
741
742 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
743
744 /* Apply BGP route map to the attribute. */
745 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
746
747 rsclient->rmap_type = 0;
748
749 if (ret == RMAP_DENYMATCH)
750 {
751 /* Free newly generated AS path and community by route-map. */
752 bgp_attr_flush (attr);
753 return RMAP_DENY;
754 }
755 }
756 return RMAP_PERMIT;
757}
758
paul94f2b392005-06-28 12:44:16 +0000759static int
paulfee0f4c2004-09-13 05:12:46 +0000760bgp_import_modifier (struct peer *rsclient, struct peer *peer,
761 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
762{
763 struct bgp_filter *filter;
764 struct bgp_info info;
765 route_map_result_t ret;
766
767 filter = &rsclient->filter[afi][safi];
768
769 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000770 if (peer->weight)
771 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000772
773 /* Route map apply. */
774 if (ROUTE_MAP_IMPORT_NAME (filter))
775 {
776 /* Duplicate current value to new strucutre for modification. */
777 info.peer = peer;
778 info.attr = attr;
779
780 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
781
782 /* Apply BGP route map to the attribute. */
783 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
784
785 peer->rmap_type = 0;
786
787 if (ret == RMAP_DENYMATCH)
788 {
789 /* Free newly generated AS path and community by route-map. */
790 bgp_attr_flush (attr);
791 return RMAP_DENY;
792 }
793 }
794 return RMAP_PERMIT;
795}
David Lamparter6b0655a2014-06-04 06:53:35 +0200796
paul94f2b392005-06-28 12:44:16 +0000797static int
paul718e3742002-12-13 20:15:29 +0000798bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
799 struct attr *attr, afi_t afi, safi_t safi)
800{
801 int ret;
802 char buf[SU_ADDRSTRLEN];
803 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000804 struct peer *from;
805 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000806 int transparent;
807 int reflect;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700808 struct attr *riattr;
paul718e3742002-12-13 20:15:29 +0000809
810 from = ri->peer;
811 filter = &peer->filter[afi][safi];
812 bgp = peer->bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700813 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paul718e3742002-12-13 20:15:29 +0000814
Paul Jakma750e8142008-07-22 21:11:48 +0000815 if (DISABLE_BGP_ANNOUNCE)
816 return 0;
paul718e3742002-12-13 20:15:29 +0000817
paulfee0f4c2004-09-13 05:12:46 +0000818 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
819 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
820 return 0;
821
paul718e3742002-12-13 20:15:29 +0000822 /* Do not send back route to sender. */
823 if (from == peer)
824 return 0;
825
826 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000827 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000828 if (! UNSUPPRESS_MAP_NAME (filter))
829 return 0;
830
831 /* Default route check. */
832 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
833 {
834 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
835 return 0;
paul718e3742002-12-13 20:15:29 +0000836 else if (p->family == AF_INET6 && p->prefixlen == 0)
837 return 0;
paul718e3742002-12-13 20:15:29 +0000838 }
839
paul286e1e72003-08-08 00:24:31 +0000840 /* Transparency check. */
841 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
842 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
843 transparent = 1;
844 else
845 transparent = 0;
846
paul718e3742002-12-13 20:15:29 +0000847 /* If community is not disabled check the no-export and local. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700848 if (! transparent && bgp_community_filter (peer, riattr))
paul718e3742002-12-13 20:15:29 +0000849 return 0;
850
851 /* If the attribute has originator-id and it is same as remote
852 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700853 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paul718e3742002-12-13 20:15:29 +0000854 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700855 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000856 {
857 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000858 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000859 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
860 peer->host,
861 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
862 p->prefixlen);
863 return 0;
864 }
865 }
866
867 /* ORF prefix-list filter check */
868 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
869 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
870 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
871 if (peer->orf_plist[afi][safi])
872 {
873 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
874 return 0;
875 }
876
877 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700878 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
paul718e3742002-12-13 20:15:29 +0000879 {
880 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000881 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000882 "%s [Update:SEND] %s/%d is filtered",
883 peer->host,
884 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
885 p->prefixlen);
886 return 0;
887 }
888
889#ifdef BGP_SEND_ASPATH_CHECK
890 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700891 if (aspath_loop_check (riattr->aspath, peer->as))
paul718e3742002-12-13 20:15:29 +0000892 {
893 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000894 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400895 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000896 peer->host, peer->as);
897 return 0;
898 }
899#endif /* BGP_SEND_ASPATH_CHECK */
900
901 /* If we're a CONFED we need to loop check the CONFED ID too */
902 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
903 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700904 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
paul718e3742002-12-13 20:15:29 +0000905 {
906 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000907 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400908 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000909 peer->host,
910 bgp->confed_id);
911 return 0;
912 }
913 }
914
915 /* Route-Reflect check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000916 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +0000917 reflect = 1;
918 else
919 reflect = 0;
920
921 /* IBGP reflection check. */
922 if (reflect)
923 {
924 /* A route from a Client peer. */
925 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
926 {
927 /* Reflect to all the Non-Client peers and also to the
928 Client peers other than the originator. Originator check
929 is already done. So there is noting to do. */
930 /* no bgp client-to-client reflection check. */
931 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
932 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
933 return 0;
934 }
935 else
936 {
937 /* A route from a Non-client peer. Reflect to all other
938 clients. */
939 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
940 return 0;
941 }
942 }
Paul Jakma41367172007-08-06 15:24:51 +0000943
paul718e3742002-12-13 20:15:29 +0000944 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700945 bgp_attr_dup (attr, riattr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000946
paul718e3742002-12-13 20:15:29 +0000947 /* If local-preference is not set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000948 if ((peer->sort == BGP_PEER_IBGP
949 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000950 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
951 {
952 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
953 attr->local_pref = bgp->default_local_pref;
954 }
955
Pradosh Mohapatra689bb662013-09-07 07:13:37 +0000956 /* If originator-id is not set and the route is to be reflected,
957 set the originator id */
958 if (peer && from && peer->sort == BGP_PEER_IBGP &&
959 from->sort == BGP_PEER_IBGP &&
960 (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
961 {
962 attr->extra = bgp_attr_extra_get(attr);
963 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
964 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
965 }
966
paul718e3742002-12-13 20:15:29 +0000967 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000968 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000969 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
970 {
971 if (ri->peer != bgp->peer_self && ! transparent
972 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
973 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
974 }
975
Lou Berger298cc2f2016-01-12 13:42:02 -0500976
977#define NEXTHOP_IS_V4 (\
978 (safi != SAFI_ENCAP && p->family == AF_INET) || \
979 (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 4))
980
Lou Berger298cc2f2016-01-12 13:42:02 -0500981#define NEXTHOP_IS_V6 (\
982 (safi != SAFI_ENCAP && p->family == AF_INET6) || \
983 (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 16))
Lou Berger298cc2f2016-01-12 13:42:02 -0500984
paul718e3742002-12-13 20:15:29 +0000985 /* next-hop-set */
Timo Teräs9e7a53c2014-04-24 10:22:37 +0300986 if (transparent
987 || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
paul718e3742002-12-13 20:15:29 +0000988 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
Lou Berger298cc2f2016-01-12 13:42:02 -0500989 && ((NEXTHOP_IS_V4 && attr->nexthop.s_addr)
Lou Berger298cc2f2016-01-12 13:42:02 -0500990 || (NEXTHOP_IS_V6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000991 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000992 )))
paul718e3742002-12-13 20:15:29 +0000993 {
994 /* NEXT-HOP Unchanged. */
995 }
996 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
Lou Berger298cc2f2016-01-12 13:42:02 -0500997 || (NEXTHOP_IS_V4 && attr->nexthop.s_addr == 0)
Lou Berger298cc2f2016-01-12 13:42:02 -0500998 || (NEXTHOP_IS_V6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000999 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001000 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001001 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
1002 {
1003 /* Set IPv4 nexthop. */
Lou Berger298cc2f2016-01-12 13:42:02 -05001004 if (NEXTHOP_IS_V4)
paul718e3742002-12-13 20:15:29 +00001005 {
Lou Berger298cc2f2016-01-12 13:42:02 -05001006 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00001007 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1008 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +00001009 else
1010 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1011 }
paul718e3742002-12-13 20:15:29 +00001012 /* Set IPv6 nexthop. */
Lou Berger298cc2f2016-01-12 13:42:02 -05001013 if (NEXTHOP_IS_V6)
paul718e3742002-12-13 20:15:29 +00001014 {
1015 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001016 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001017 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001018 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001019 }
paul718e3742002-12-13 20:15:29 +00001020 }
1021
Lou Berger298cc2f2016-01-12 13:42:02 -05001022 if (p->family == AF_INET6 && safi != SAFI_ENCAP)
paul718e3742002-12-13 20:15:29 +00001023 {
paulfee0f4c2004-09-13 05:12:46 +00001024 /* Left nexthop_local unchanged if so configured. */
1025 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1026 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1027 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001028 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1029 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001030 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001031 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001032 }
1033
1034 /* Default nexthop_local treatment for non-RS-Clients */
1035 else
1036 {
paul718e3742002-12-13 20:15:29 +00001037 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001038 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001039
1040 /* Set link-local address for shared network peer. */
1041 if (peer->shared_network
1042 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1043 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001044 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001045 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001046 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001047 }
1048
1049 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1050 address.*/
1051 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001052 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001053
1054 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1055 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001056 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001057 }
paulfee0f4c2004-09-13 05:12:46 +00001058
1059 }
paul718e3742002-12-13 20:15:29 +00001060
1061 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001062 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001063 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1064 && aspath_private_as_check (attr->aspath))
1065 attr->aspath = aspath_empty_get ();
1066
1067 /* Route map & unsuppress-map apply. */
1068 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001069 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001070 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001071 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001072 struct attr dummy_attr;
1073 struct attr_extra dummy_extra;
1074
1075 dummy_attr.extra = &dummy_extra;
1076
paul718e3742002-12-13 20:15:29 +00001077 info.peer = peer;
1078 info.attr = attr;
1079
1080 /* The route reflector is not allowed to modify the attributes
Dinesh Dutt083e5e22015-11-09 20:21:54 -05001081 of the reflected IBGP routes, unless configured to allow it */
1082 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP) &&
1083 !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
paul718e3742002-12-13 20:15:29 +00001084 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001085 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001086 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001087 }
paulac41b2a2003-08-12 05:32:27 +00001088
1089 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1090
Paul Jakmafb982c22007-05-04 20:15:47 +00001091 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001092 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1093 else
1094 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1095
paulac41b2a2003-08-12 05:32:27 +00001096 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001097
paul718e3742002-12-13 20:15:29 +00001098 if (ret == RMAP_DENYMATCH)
1099 {
1100 bgp_attr_flush (attr);
1101 return 0;
1102 }
1103 }
1104 return 1;
1105}
1106
paul94f2b392005-06-28 12:44:16 +00001107static int
paulfee0f4c2004-09-13 05:12:46 +00001108bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1109 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001110{
paulfee0f4c2004-09-13 05:12:46 +00001111 int ret;
1112 char buf[SU_ADDRSTRLEN];
1113 struct bgp_filter *filter;
1114 struct bgp_info info;
1115 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001116 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001117
1118 from = ri->peer;
1119 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001120 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001121
Paul Jakma750e8142008-07-22 21:11:48 +00001122 if (DISABLE_BGP_ANNOUNCE)
1123 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001124
1125 /* Do not send back route to sender. */
1126 if (from == rsclient)
1127 return 0;
1128
1129 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001130 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001131 if (! UNSUPPRESS_MAP_NAME (filter))
1132 return 0;
1133
1134 /* Default route check. */
1135 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1136 PEER_STATUS_DEFAULT_ORIGINATE))
1137 {
1138 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1139 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001140 else if (p->family == AF_INET6 && p->prefixlen == 0)
1141 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001142 }
1143
1144 /* If the attribute has originator-id and it is same as remote
1145 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001146 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001147 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001148 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001149 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001150 {
1151 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001152 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001153 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1154 rsclient->host,
1155 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1156 p->prefixlen);
1157 return 0;
1158 }
1159 }
1160
1161 /* ORF prefix-list filter check */
1162 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1163 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1164 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1165 if (rsclient->orf_plist[afi][safi])
1166 {
1167 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1168 return 0;
1169 }
1170
1171 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001172 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001173 {
1174 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001175 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001176 "%s [Update:SEND] %s/%d is filtered",
1177 rsclient->host,
1178 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1179 p->prefixlen);
1180 return 0;
1181 }
1182
1183#ifdef BGP_SEND_ASPATH_CHECK
1184 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001185 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001186 {
1187 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001188 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001189 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001190 rsclient->host, rsclient->as);
1191 return 0;
1192 }
1193#endif /* BGP_SEND_ASPATH_CHECK */
1194
1195 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001196 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001197
1198 /* next-hop-set */
1199 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
paulfee0f4c2004-09-13 05:12:46 +00001200 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001201 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001202 )
1203 {
1204 /* Set IPv4 nexthop. */
1205 if (p->family == AF_INET)
1206 {
Lou Berger298cc2f2016-01-12 13:42:02 -05001207 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00001208 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001209 IPV4_MAX_BYTELEN);
1210 else
1211 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1212 }
paulfee0f4c2004-09-13 05:12:46 +00001213 /* Set IPv6 nexthop. */
1214 if (p->family == AF_INET6)
1215 {
1216 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001217 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001218 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001219 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001220 }
paulfee0f4c2004-09-13 05:12:46 +00001221 }
1222
paulfee0f4c2004-09-13 05:12:46 +00001223 if (p->family == AF_INET6)
1224 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001225 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001226
paulfee0f4c2004-09-13 05:12:46 +00001227 /* Left nexthop_local unchanged if so configured. */
1228 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1229 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1230 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001231 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1232 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001233 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001234 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001235 }
1236
1237 /* Default nexthop_local treatment for RS-Clients */
1238 else
1239 {
1240 /* Announcer and RS-Client are both in the same network */
1241 if (rsclient->shared_network && from->shared_network &&
1242 (rsclient->ifindex == from->ifindex))
1243 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001244 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1245 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001246 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001247 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001248 }
1249
1250 /* Set link-local address for shared network peer. */
1251 else if (rsclient->shared_network
1252 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1253 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001254 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001255 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001256 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001257 }
1258
1259 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001260 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001261 }
1262
1263 }
paulfee0f4c2004-09-13 05:12:46 +00001264
1265 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001266 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001267 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1268 && aspath_private_as_check (attr->aspath))
1269 attr->aspath = aspath_empty_get ();
1270
1271 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001272 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001273 {
1274 info.peer = rsclient;
1275 info.attr = attr;
1276
1277 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1278
Paul Jakmafb982c22007-05-04 20:15:47 +00001279 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001280 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1281 else
1282 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1283
1284 rsclient->rmap_type = 0;
1285
1286 if (ret == RMAP_DENYMATCH)
1287 {
1288 bgp_attr_flush (attr);
1289 return 0;
1290 }
1291 }
1292
1293 return 1;
1294}
1295
1296struct bgp_info_pair
1297{
1298 struct bgp_info *old;
1299 struct bgp_info *new;
1300};
1301
paul94f2b392005-06-28 12:44:16 +00001302static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001303bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
Paul Jakma6d4742b2015-11-25 17:14:37 +00001304 struct bgp_info_pair *result,
1305 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00001306{
paul718e3742002-12-13 20:15:29 +00001307 struct bgp_info *new_select;
1308 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001309 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001310 struct bgp_info *ri1;
1311 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001312 struct bgp_info *nextri = NULL;
Paul Jakma6d4742b2015-11-25 17:14:37 +00001313 int cmpret, do_mpath;
Josh Bailey96450fa2011-07-20 20:45:12 -07001314 struct list mp_list;
Paul Jakma91b9e852015-12-01 14:32:11 +00001315
1316 result->old = result->new = NULL;
1317
1318 if (rn->info == NULL)
1319 {
1320 char buf[PREFIX_STRLEN];
1321 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1322 __func__,
1323 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1324 return;
1325 }
1326
Josh Bailey96450fa2011-07-20 20:45:12 -07001327 bgp_mp_list_init (&mp_list);
Paul Jakma6d4742b2015-11-25 17:14:37 +00001328 do_mpath = bgp_mpath_is_configured (bgp, afi, safi);
Josh Bailey96450fa2011-07-20 20:45:12 -07001329
paul718e3742002-12-13 20:15:29 +00001330 /* bgp deterministic-med */
1331 new_select = NULL;
1332 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1333 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1334 {
1335 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1336 continue;
1337 if (BGP_INFO_HOLDDOWN (ri1))
1338 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001339 if (ri1->peer && ri1->peer != bgp->peer_self)
1340 if (ri1->peer->status != Established)
1341 continue;
paul718e3742002-12-13 20:15:29 +00001342
1343 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001344 if (do_mpath)
1345 bgp_mp_list_add (&mp_list, ri1);
1346 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001347 if (ri1->next)
1348 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1349 {
1350 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1351 continue;
1352 if (BGP_INFO_HOLDDOWN (ri2))
1353 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001354 if (ri2->peer &&
1355 ri2->peer != bgp->peer_self &&
1356 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1357 if (ri2->peer->status != Established)
1358 continue;
paul718e3742002-12-13 20:15:29 +00001359
1360 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1361 || aspath_cmp_left_confed (ri1->attr->aspath,
1362 ri2->attr->aspath))
1363 {
Josh Bailey6918e742011-07-20 20:48:20 -07001364 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1365 old_select = ri2;
Paul Jakma6d4742b2015-11-25 17:14:37 +00001366 if ((cmpret = bgp_info_cmp (bgp, ri2, new_select, afi, safi))
1367 == -1)
paul718e3742002-12-13 20:15:29 +00001368 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001369 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001370 new_select = ri2;
1371 }
1372
Paul Jakma6d4742b2015-11-25 17:14:37 +00001373 if (do_mpath)
1374 {
1375 if (cmpret != 0)
1376 bgp_mp_list_clear (&mp_list);
1377
1378 if (cmpret == 0 || cmpret == -1)
1379 bgp_mp_list_add (&mp_list, ri2);
1380 }
Josh Bailey6918e742011-07-20 20:48:20 -07001381
Paul Jakma1a392d42006-09-07 00:24:49 +00001382 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001383 }
1384 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001385 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1386 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001387
Paul Jakma6d4742b2015-11-25 17:14:37 +00001388 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, afi, safi);
Josh Bailey6918e742011-07-20 20:48:20 -07001389 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001390 }
1391
1392 /* Check old selected route and new selected route. */
1393 old_select = NULL;
1394 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001395 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001396 {
1397 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1398 old_select = ri;
1399
1400 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001401 {
1402 /* reap REMOVED routes, if needs be
1403 * selected route must stay for a while longer though
1404 */
1405 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1406 && (ri != old_select))
1407 bgp_info_reap (rn, ri);
1408
1409 continue;
1410 }
paul718e3742002-12-13 20:15:29 +00001411
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001412 if (ri->peer &&
1413 ri->peer != bgp->peer_self &&
1414 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1415 if (ri->peer->status != Established)
1416 continue;
1417
paul718e3742002-12-13 20:15:29 +00001418 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1419 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1420 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001421 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001422 continue;
1423 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001424 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1425 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001426
Paul Jakma6d4742b2015-11-25 17:14:37 +00001427 if ((cmpret = bgp_info_cmp (bgp, ri, new_select, afi, safi)) == -1)
Josh Bailey96450fa2011-07-20 20:45:12 -07001428 {
Josh Bailey6918e742011-07-20 20:48:20 -07001429 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1430 bgp_mp_dmed_deselect (new_select);
1431
Josh Bailey96450fa2011-07-20 20:45:12 -07001432 new_select = ri;
Josh Bailey96450fa2011-07-20 20:45:12 -07001433 }
Paul Jakma6d4742b2015-11-25 17:14:37 +00001434 else if (cmpret == 1 && do_mpath
1435 && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
Josh Bailey6918e742011-07-20 20:48:20 -07001436 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001437
Paul Jakma6d4742b2015-11-25 17:14:37 +00001438 if (do_mpath)
1439 {
1440 if (cmpret != 0)
1441 bgp_mp_list_clear (&mp_list);
1442
1443 if (cmpret == 0 || cmpret == -1)
1444 bgp_mp_list_add (&mp_list, ri);
1445 }
paul718e3742002-12-13 20:15:29 +00001446 }
paulfee0f4c2004-09-13 05:12:46 +00001447
Josh Bailey6918e742011-07-20 20:48:20 -07001448 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
Paul Jakma6d4742b2015-11-25 17:14:37 +00001449 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, afi, safi);
Josh Bailey96450fa2011-07-20 20:45:12 -07001450
Josh Bailey0b597ef2011-07-20 20:49:11 -07001451 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001452 bgp_mp_list_clear (&mp_list);
1453
1454 result->old = old_select;
1455 result->new = new_select;
1456
1457 return;
paulfee0f4c2004-09-13 05:12:46 +00001458}
1459
paul94f2b392005-06-28 12:44:16 +00001460static int
paulfee0f4c2004-09-13 05:12:46 +00001461bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001462 struct bgp_node *rn, afi_t afi, safi_t safi)
1463{
paulfee0f4c2004-09-13 05:12:46 +00001464 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001465 struct attr attr;
1466 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001467
Lou Berger050defe2016-01-12 13:41:59 -05001468 memset (&attr, 0, sizeof(struct attr));
1469 memset (&extra, 0, sizeof(struct attr_extra));
1470
paulfee0f4c2004-09-13 05:12:46 +00001471 p = &rn->p;
1472
Paul Jakma9eda90c2007-08-30 13:36:17 +00001473 /* Announce route to Established peer. */
1474 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001475 return 0;
1476
Paul Jakma9eda90c2007-08-30 13:36:17 +00001477 /* Address family configuration check. */
1478 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001479 return 0;
1480
Paul Jakma9eda90c2007-08-30 13:36:17 +00001481 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001482 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1483 PEER_STATUS_ORF_WAIT_REFRESH))
1484 return 0;
1485
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001486 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1487 attr.extra = &extra;
1488
Avneesh Sachdev67174042012-08-17 08:19:49 -07001489 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001490 {
1491 case BGP_TABLE_MAIN:
1492 /* Announcement to peer->conf. If the route is filtered,
1493 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001494 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1495 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001496 else
1497 bgp_adj_out_unset (rn, peer, p, afi, safi);
1498 break;
1499 case BGP_TABLE_RSCLIENT:
1500 /* Announcement to peer->conf. If the route is filtered,
1501 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001502 if (selected &&
1503 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1504 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1505 else
1506 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001507 break;
1508 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001509
Lou Berger050defe2016-01-12 13:41:59 -05001510 bgp_attr_flush (&attr);
paulfee0f4c2004-09-13 05:12:46 +00001511 return 0;
paul200df112005-06-01 11:17:05 +00001512}
paulfee0f4c2004-09-13 05:12:46 +00001513
paul200df112005-06-01 11:17:05 +00001514struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001515{
paul200df112005-06-01 11:17:05 +00001516 struct bgp *bgp;
1517 struct bgp_node *rn;
1518 afi_t afi;
1519 safi_t safi;
1520};
1521
1522static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001523bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001524{
paul0fb58d52005-11-14 14:31:49 +00001525 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001526 struct bgp *bgp = pq->bgp;
1527 struct bgp_node *rn = pq->rn;
1528 afi_t afi = pq->afi;
1529 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001530 struct bgp_info *new_select;
1531 struct bgp_info *old_select;
1532 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001533 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001534 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001535
paulfee0f4c2004-09-13 05:12:46 +00001536 /* Best path selection. */
Paul Jakma6d4742b2015-11-25 17:14:37 +00001537 bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001538 new_select = old_and_new.new;
1539 old_select = old_and_new.old;
1540
paul200df112005-06-01 11:17:05 +00001541 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1542 {
Chris Caputo228da422009-07-18 05:44:03 +00001543 if (rsclient->group)
1544 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1545 {
1546 /* Nothing to do. */
1547 if (old_select && old_select == new_select)
1548 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1549 continue;
paulfee0f4c2004-09-13 05:12:46 +00001550
Chris Caputo228da422009-07-18 05:44:03 +00001551 if (old_select)
1552 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1553 if (new_select)
1554 {
1555 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1556 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001557 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1558 }
paulfee0f4c2004-09-13 05:12:46 +00001559
Chris Caputo228da422009-07-18 05:44:03 +00001560 bgp_process_announce_selected (rsclient, new_select, rn,
1561 afi, safi);
1562 }
paul200df112005-06-01 11:17:05 +00001563 }
1564 else
1565 {
hassob7395792005-08-26 12:58:38 +00001566 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001567 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001568 if (new_select)
1569 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001570 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1571 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001572 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001573 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001574 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001575 }
paulfee0f4c2004-09-13 05:12:46 +00001576
paulb40d9392005-08-22 22:34:41 +00001577 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1578 bgp_info_reap (rn, old_select);
1579
paul200df112005-06-01 11:17:05 +00001580 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1581 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001582}
1583
paul200df112005-06-01 11:17:05 +00001584static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001585bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001586{
paul0fb58d52005-11-14 14:31:49 +00001587 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001588 struct bgp *bgp = pq->bgp;
1589 struct bgp_node *rn = pq->rn;
1590 afi_t afi = pq->afi;
1591 safi_t safi = pq->safi;
1592 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001593 struct bgp_info *new_select;
1594 struct bgp_info *old_select;
1595 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001596 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001597 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001598
paulfee0f4c2004-09-13 05:12:46 +00001599 /* Best path selection. */
Paul Jakma6d4742b2015-11-25 17:14:37 +00001600 bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001601 old_select = old_and_new.old;
1602 new_select = old_and_new.new;
1603
1604 /* Nothing to do. */
Daniel Walton325fcfb2015-05-19 17:58:10 -07001605 if (old_select && old_select == new_select
1606 && !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR))
paulfee0f4c2004-09-13 05:12:46 +00001607 {
1608 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001609 {
Josh Bailey8196f132011-07-20 20:47:07 -07001610 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1611 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001612 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001613
Josh Bailey8196f132011-07-20 20:47:07 -07001614 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001615 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1616 return WQ_SUCCESS;
1617 }
paulfee0f4c2004-09-13 05:12:46 +00001618 }
paul718e3742002-12-13 20:15:29 +00001619
Daniel Walton325fcfb2015-05-19 17:58:10 -07001620 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
1621 UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
1622
hasso338b3422005-02-23 14:27:24 +00001623 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001624 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001625 if (new_select)
1626 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001627 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1628 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001629 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001630 }
1631
1632
paul718e3742002-12-13 20:15:29 +00001633 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001634 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001635 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001636 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001637 }
1638
1639 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001640 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1641 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001642 {
1643 if (new_select
1644 && new_select->type == ZEBRA_ROUTE_BGP
1645 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001646 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001647 else
1648 {
1649 /* Withdraw the route from the kernel. */
1650 if (old_select
1651 && old_select->type == ZEBRA_ROUTE_BGP
1652 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001653 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001654 }
1655 }
paulb40d9392005-08-22 22:34:41 +00001656
Lou Berger050defe2016-01-12 13:41:59 -05001657 /* Reap old select bgp_info, if it has been removed */
paulb40d9392005-08-22 22:34:41 +00001658 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1659 bgp_info_reap (rn, old_select);
1660
paul200df112005-06-01 11:17:05 +00001661 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1662 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001663}
1664
paul200df112005-06-01 11:17:05 +00001665static void
paul0fb58d52005-11-14 14:31:49 +00001666bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001667{
paul0fb58d52005-11-14 14:31:49 +00001668 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001669 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001670
Chris Caputo228da422009-07-18 05:44:03 +00001671 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001672 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001673 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001674 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1675}
1676
1677static void
1678bgp_process_queue_init (void)
1679{
1680 bm->process_main_queue
1681 = work_queue_new (bm->master, "process_main_queue");
1682 bm->process_rsclient_queue
1683 = work_queue_new (bm->master, "process_rsclient_queue");
1684
1685 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1686 {
1687 zlog_err ("%s: Failed to allocate work queue", __func__);
1688 exit (1);
1689 }
1690
1691 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001692 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001693 bm->process_main_queue->spec.max_retries = 0;
1694 bm->process_main_queue->spec.hold = 50;
1695
Paul Jakma838bbde2010-01-08 14:05:32 +00001696 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
David Lamparterd43f8b32015-03-03 08:54:54 +01001697 bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del;
1698 bm->process_rsclient_queue->spec.max_retries = 0;
1699 bm->process_rsclient_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001700}
1701
1702void
paulfee0f4c2004-09-13 05:12:46 +00001703bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1704{
paul200df112005-06-01 11:17:05 +00001705 struct bgp_process_queue *pqnode;
1706
1707 /* already scheduled for processing? */
1708 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1709 return;
1710
Paul Jakma91b9e852015-12-01 14:32:11 +00001711 if (rn->info == NULL)
1712 {
1713 /* XXX: Perhaps remove before next release, after we've flushed out
1714 * any obvious cases
1715 */
1716 assert (rn->info != NULL);
1717 char buf[PREFIX_STRLEN];
1718 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1719 __func__,
1720 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1721 return;
1722 }
1723
paul200df112005-06-01 11:17:05 +00001724 if ( (bm->process_main_queue == NULL) ||
1725 (bm->process_rsclient_queue == NULL) )
1726 bgp_process_queue_init ();
1727
1728 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1729 sizeof (struct bgp_process_queue));
1730 if (!pqnode)
1731 return;
Chris Caputo228da422009-07-18 05:44:03 +00001732
1733 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001734 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001735 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001736 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001737 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001738 pqnode->afi = afi;
1739 pqnode->safi = safi;
1740
Avneesh Sachdev67174042012-08-17 08:19:49 -07001741 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001742 {
paul200df112005-06-01 11:17:05 +00001743 case BGP_TABLE_MAIN:
1744 work_queue_add (bm->process_main_queue, pqnode);
1745 break;
1746 case BGP_TABLE_RSCLIENT:
1747 work_queue_add (bm->process_rsclient_queue, pqnode);
1748 break;
paulfee0f4c2004-09-13 05:12:46 +00001749 }
paul200df112005-06-01 11:17:05 +00001750
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001751 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001752 return;
paulfee0f4c2004-09-13 05:12:46 +00001753}
hasso0a486e52005-02-01 20:57:17 +00001754
paul94f2b392005-06-28 12:44:16 +00001755static int
hasso0a486e52005-02-01 20:57:17 +00001756bgp_maximum_prefix_restart_timer (struct thread *thread)
1757{
1758 struct peer *peer;
1759
1760 peer = THREAD_ARG (thread);
1761 peer->t_pmax_restart = NULL;
1762
1763 if (BGP_DEBUG (events, EVENTS))
1764 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1765 peer->host);
1766
1767 peer_clear (peer);
1768
1769 return 0;
1770}
1771
paulfee0f4c2004-09-13 05:12:46 +00001772int
paul5228ad22004-06-04 17:58:18 +00001773bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1774 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001775{
hassoe0701b72004-05-20 09:19:34 +00001776 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1777 return 0;
1778
1779 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001780 {
hassoe0701b72004-05-20 09:19:34 +00001781 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1782 && ! always)
1783 return 0;
paul718e3742002-12-13 20:15:29 +00001784
hassoe0701b72004-05-20 09:19:34 +00001785 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001786 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1787 "limit %ld", afi_safi_print (afi, safi), peer->host,
1788 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001789 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001790
hassoe0701b72004-05-20 09:19:34 +00001791 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1792 return 0;
paul718e3742002-12-13 20:15:29 +00001793
hassoe0701b72004-05-20 09:19:34 +00001794 {
paul5228ad22004-06-04 17:58:18 +00001795 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001796
1797 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001798 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001799
1800 ndata[0] = (afi >> 8);
1801 ndata[1] = afi;
1802 ndata[2] = safi;
1803 ndata[3] = (peer->pmax[afi][safi] >> 24);
1804 ndata[4] = (peer->pmax[afi][safi] >> 16);
1805 ndata[5] = (peer->pmax[afi][safi] >> 8);
1806 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001807
1808 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1809 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1810 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1811 }
hasso0a486e52005-02-01 20:57:17 +00001812
1813 /* restart timer start */
1814 if (peer->pmax_restart[afi][safi])
1815 {
1816 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1817
1818 if (BGP_DEBUG (events, EVENTS))
1819 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1820 peer->host, peer->v_pmax_restart);
1821
1822 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1823 peer->v_pmax_restart);
1824 }
1825
hassoe0701b72004-05-20 09:19:34 +00001826 return 1;
paul718e3742002-12-13 20:15:29 +00001827 }
hassoe0701b72004-05-20 09:19:34 +00001828 else
1829 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1830
1831 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1832 {
1833 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1834 && ! always)
1835 return 0;
1836
1837 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001838 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1839 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1840 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001841 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1842 }
1843 else
1844 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001845 return 0;
1846}
1847
paulb40d9392005-08-22 22:34:41 +00001848/* Unconditionally remove the route from the RIB, without taking
1849 * damping into consideration (eg, because the session went down)
1850 */
paul94f2b392005-06-28 12:44:16 +00001851static void
paul718e3742002-12-13 20:15:29 +00001852bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1853 afi_t afi, safi_t safi)
1854{
paul902212c2006-02-05 17:51:19 +00001855 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1856
1857 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1858 bgp_info_delete (rn, ri); /* keep historical info */
1859
paulb40d9392005-08-22 22:34:41 +00001860 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001861}
1862
paul94f2b392005-06-28 12:44:16 +00001863static void
paul718e3742002-12-13 20:15:29 +00001864bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
Lou Berger050defe2016-01-12 13:41:59 -05001865 afi_t afi, safi_t safi, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00001866{
paul718e3742002-12-13 20:15:29 +00001867 int status = BGP_DAMP_NONE;
1868
paulb40d9392005-08-22 22:34:41 +00001869 /* apply dampening, if result is suppressed, we'll be retaining
1870 * the bgp_info in the RIB for historical reference.
1871 */
1872 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001873 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001874 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1875 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001876 {
paul902212c2006-02-05 17:51:19 +00001877 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1878 return;
1879 }
1880
1881 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001882}
1883
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05001884static struct bgp_info *
1885info_make (int type, int sub_type, struct peer *peer, struct attr *attr,
1886 struct bgp_node *rn)
1887{
1888 struct bgp_info *new;
1889
1890 /* Make new BGP info. */
1891 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
1892 new->type = type;
1893 new->sub_type = sub_type;
1894 new->peer = peer;
1895 new->attr = attr;
1896 new->uptime = bgp_clock ();
1897 new->net = rn;
1898 return new;
1899}
1900
paul94f2b392005-06-28 12:44:16 +00001901static void
paulfee0f4c2004-09-13 05:12:46 +00001902bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1903 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1904 int sub_type, struct prefix_rd *prd, u_char *tag)
1905{
1906 struct bgp_node *rn;
1907 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001908 struct attr new_attr;
1909 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001910 struct attr *attr_new;
1911 struct attr *attr_new2;
1912 struct bgp_info *ri;
1913 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001914 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001915 char buf[SU_ADDRSTRLEN];
1916
1917 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1918 if (peer == rsclient)
1919 return;
1920
1921 bgp = peer->bgp;
1922 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1923
1924 /* Check previously received route. */
1925 for (ri = rn->info; ri; ri = ri->next)
1926 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1927 break;
1928
1929 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001930 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001931 {
1932 reason = "as-path contains our own AS;";
1933 goto filtered;
1934 }
1935
1936 /* Route reflector originator ID check. */
1937 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001938 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001939 {
1940 reason = "originator is us;";
1941 goto filtered;
1942 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001943
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001944 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001945 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001946
1947 /* Apply export policy. */
1948 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1949 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1950 {
1951 reason = "export-policy;";
1952 goto filtered;
1953 }
1954
1955 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001956
paulfee0f4c2004-09-13 05:12:46 +00001957 /* Apply import policy. */
1958 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1959 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001960 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001961
1962 reason = "import-policy;";
1963 goto filtered;
1964 }
1965
1966 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001967 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001968
1969 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001970 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001971 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001972 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001973 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001974 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001975 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001976 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001977
1978 reason = "martian next-hop;";
1979 goto filtered;
1980 }
1981 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001982
paulfee0f4c2004-09-13 05:12:46 +00001983 /* If the update is implicit withdraw. */
1984 if (ri)
1985 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001986 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001987
1988 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001989 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1990 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001991 {
1992
Paul Jakma1a392d42006-09-07 00:24:49 +00001993 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001994
1995 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001996 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001997 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1998 peer->host,
1999 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2000 p->prefixlen, rsclient->host);
2001
Chris Caputo228da422009-07-18 05:44:03 +00002002 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002003 bgp_attr_unintern (&attr_new);
Lou Berger050defe2016-01-12 13:41:59 -05002004 bgp_attr_flush(&new_attr);
Chris Caputo228da422009-07-18 05:44:03 +00002005 return;
paulfee0f4c2004-09-13 05:12:46 +00002006 }
2007
Paul Jakma16d2e242007-04-10 19:32:10 +00002008 /* Withdraw/Announce before we fully processed the withdraw */
2009 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2010 bgp_info_restore (rn, ri);
2011
paulfee0f4c2004-09-13 05:12:46 +00002012 /* Received Logging. */
2013 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002014 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002015 peer->host,
2016 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2017 p->prefixlen, rsclient->host);
2018
2019 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002020 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00002021
2022 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002023 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00002024 ri->attr = attr_new;
2025
2026 /* Update MPLS tag. */
2027 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002028 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002029
Paul Jakma1a392d42006-09-07 00:24:49 +00002030 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002031
2032 /* Process change. */
2033 bgp_process (bgp, rn, afi, safi);
2034 bgp_unlock_node (rn);
2035
2036 return;
2037 }
2038
2039 /* Received Logging. */
2040 if (BGP_DEBUG (update, UPDATE_IN))
2041 {
ajsd2c1f162004-12-08 21:10:20 +00002042 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002043 peer->host,
2044 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2045 p->prefixlen, rsclient->host);
2046 }
2047
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05002048 new = info_make(type, sub_type, peer, attr_new, rn);
paulfee0f4c2004-09-13 05:12:46 +00002049
2050 /* Update MPLS tag. */
2051 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002052 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002053
Paul Jakma1a392d42006-09-07 00:24:49 +00002054 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002055
2056 /* Register new BGP information. */
2057 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002058
2059 /* route_node_get lock */
2060 bgp_unlock_node (rn);
2061
paulfee0f4c2004-09-13 05:12:46 +00002062 /* Process change. */
2063 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002064
paulfee0f4c2004-09-13 05:12:46 +00002065 return;
2066
2067 filtered:
2068
2069 /* This BGP update is filtered. Log the reason then update BGP entry. */
2070 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002071 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002072 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2073 peer->host,
2074 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2075 p->prefixlen, rsclient->host, reason);
2076
2077 if (ri)
paulb40d9392005-08-22 22:34:41 +00002078 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002079
2080 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002081
paulfee0f4c2004-09-13 05:12:46 +00002082 return;
2083}
2084
paul94f2b392005-06-28 12:44:16 +00002085static void
paulfee0f4c2004-09-13 05:12:46 +00002086bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2087 struct peer *peer, struct prefix *p, int type, int sub_type,
2088 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002089{
paulfee0f4c2004-09-13 05:12:46 +00002090 struct bgp_node *rn;
2091 struct bgp_info *ri;
2092 char buf[SU_ADDRSTRLEN];
2093
2094 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002095 return;
paulfee0f4c2004-09-13 05:12:46 +00002096
2097 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2098
2099 /* Lookup withdrawn route. */
2100 for (ri = rn->info; ri; ri = ri->next)
2101 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2102 break;
2103
2104 /* Withdraw specified route from routing table. */
2105 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Lou Berger050defe2016-01-12 13:41:59 -05002106 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
paulfee0f4c2004-09-13 05:12:46 +00002107 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002108 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002109 "%s Can't find the route %s/%d", peer->host,
2110 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2111 p->prefixlen);
2112
2113 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002114 bgp_unlock_node (rn);
2115}
paulfee0f4c2004-09-13 05:12:46 +00002116
paul94f2b392005-06-28 12:44:16 +00002117static int
paulfee0f4c2004-09-13 05:12:46 +00002118bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002119 afi_t afi, safi_t safi, int type, int sub_type,
2120 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2121{
2122 int ret;
2123 int aspath_loop_count = 0;
2124 struct bgp_node *rn;
2125 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002126 struct attr new_attr;
2127 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002128 struct attr *attr_new;
2129 struct bgp_info *ri;
2130 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002131 const char *reason;
paul718e3742002-12-13 20:15:29 +00002132 char buf[SU_ADDRSTRLEN];
2133
Lou Berger370b7e52016-02-04 21:29:49 -05002134 memset (&new_attr, 0, sizeof(struct attr));
2135 memset (&new_extra, 0, sizeof(struct attr_extra));
2136
paul718e3742002-12-13 20:15:29 +00002137 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002138 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002139
paul718e3742002-12-13 20:15:29 +00002140 /* When peer's soft reconfiguration enabled. Record input packet in
2141 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002142 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2143 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002144 bgp_adj_in_set (rn, peer, attr);
2145
2146 /* Check previously received route. */
2147 for (ri = rn->info; ri; ri = ri->next)
2148 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2149 break;
2150
2151 /* AS path local-as loop check. */
2152 if (peer->change_local_as)
2153 {
2154 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2155 aspath_loop_count = 1;
2156
2157 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2158 {
2159 reason = "as-path contains our own AS;";
2160 goto filtered;
2161 }
2162 }
2163
2164 /* AS path loop check. */
2165 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2166 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2167 && aspath_loop_check(attr->aspath, bgp->confed_id)
2168 > peer->allowas_in[afi][safi]))
2169 {
2170 reason = "as-path contains our own AS;";
2171 goto filtered;
2172 }
2173
2174 /* Route reflector originator ID check. */
2175 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002176 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002177 {
2178 reason = "originator is us;";
2179 goto filtered;
2180 }
2181
2182 /* Route reflector cluster ID check. */
2183 if (bgp_cluster_filter (peer, attr))
2184 {
2185 reason = "reflected from the same cluster;";
2186 goto filtered;
2187 }
2188
2189 /* Apply incoming filter. */
2190 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2191 {
2192 reason = "filter;";
2193 goto filtered;
2194 }
2195
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002196 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002197 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002198
David Lamparterc460e572014-06-04 00:54:58 +02002199 /* Apply incoming route-map.
2200 * NB: new_attr may now contain newly allocated values from route-map "set"
2201 * commands, so we need bgp_attr_flush in the error paths, until we intern
2202 * the attr (which takes over the memory references) */
paul718e3742002-12-13 20:15:29 +00002203 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2204 {
2205 reason = "route-map;";
David Lamparterc460e572014-06-04 00:54:58 +02002206 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002207 goto filtered;
2208 }
2209
2210 /* IPv4 unicast next hop check. */
2211 if (afi == AFI_IP && safi == SAFI_UNICAST)
2212 {
2213 /* If the peer is EBGP and nexthop is not on connected route,
2214 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002215 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002216 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002217 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002218 {
2219 reason = "non-connected next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002220 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002221 goto filtered;
2222 }
2223
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002224 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002225 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002226 if (new_attr.nexthop.s_addr == 0
2227 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2228 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002229 {
2230 reason = "martian next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002231 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002232 goto filtered;
2233 }
2234 }
2235
2236 attr_new = bgp_attr_intern (&new_attr);
2237
2238 /* If the update is implicit withdraw. */
2239 if (ri)
2240 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002241 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002242
2243 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002244 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2245 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002246 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002247 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002248
2249 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002250 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002251 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2252 {
2253 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002254 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002255 peer->host,
2256 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2257 p->prefixlen);
2258
paul902212c2006-02-05 17:51:19 +00002259 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2260 {
2261 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2262 bgp_process (bgp, rn, afi, safi);
2263 }
paul718e3742002-12-13 20:15:29 +00002264 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002265 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002266 {
2267 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002268 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002269 "%s rcvd %s/%d...duplicate ignored",
2270 peer->host,
2271 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2272 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002273
2274 /* graceful restart STALE flag unset. */
2275 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2276 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002277 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002278 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002279 }
paul718e3742002-12-13 20:15:29 +00002280 }
2281
2282 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002283 bgp_attr_unintern (&attr_new);
Lou Berger050defe2016-01-12 13:41:59 -05002284 bgp_attr_flush (&new_attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002285
paul718e3742002-12-13 20:15:29 +00002286 return 0;
2287 }
2288
Paul Jakma16d2e242007-04-10 19:32:10 +00002289 /* Withdraw/Announce before we fully processed the withdraw */
2290 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2291 {
2292 if (BGP_DEBUG (update, UPDATE_IN))
2293 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2294 peer->host,
2295 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2296 p->prefixlen);
2297 bgp_info_restore (rn, ri);
2298 }
2299
paul718e3742002-12-13 20:15:29 +00002300 /* Received Logging. */
2301 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002302 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002303 peer->host,
2304 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2305 p->prefixlen);
2306
hasso93406d82005-02-02 14:40:33 +00002307 /* graceful restart STALE flag unset. */
2308 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002309 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002310
paul718e3742002-12-13 20:15:29 +00002311 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002312 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002313
2314 /* implicit withdraw, decrement aggregate and pcount here.
2315 * only if update is accepted, they'll increment below.
2316 */
paul902212c2006-02-05 17:51:19 +00002317 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2318
paul718e3742002-12-13 20:15:29 +00002319 /* Update bgp route dampening information. */
2320 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002321 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002322 {
2323 /* This is implicit withdraw so we should update dampening
2324 information. */
2325 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2326 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002327 }
2328
paul718e3742002-12-13 20:15:29 +00002329 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002330 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002331 ri->attr = attr_new;
2332
2333 /* Update MPLS tag. */
2334 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002335 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002336
Lou Berger050defe2016-01-12 13:41:59 -05002337 bgp_attr_flush (&new_attr);
2338
paul718e3742002-12-13 20:15:29 +00002339 /* Update bgp route dampening information. */
2340 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002341 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002342 {
2343 /* Now we do normal update dampening. */
2344 ret = bgp_damp_update (ri, rn, afi, safi);
2345 if (ret == BGP_DAMP_SUPPRESSED)
2346 {
2347 bgp_unlock_node (rn);
2348 return 0;
2349 }
2350 }
2351
2352 /* Nexthop reachability check. */
2353 if ((afi == AFI_IP || afi == AFI_IP6)
2354 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002355 && (peer->sort == BGP_PEER_IBGP
2356 || peer->sort == BGP_PEER_CONFED
2357 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002358 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002359 {
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05002360 if (bgp_find_or_add_nexthop (afi, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002361 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002362 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002363 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002364 }
2365 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002366 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002367
Lou Berger050defe2016-01-12 13:41:59 -05002368 bgp_attr_flush (&new_attr);
2369
paul718e3742002-12-13 20:15:29 +00002370 /* Process change. */
2371 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2372
2373 bgp_process (bgp, rn, afi, safi);
2374 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002375
paul718e3742002-12-13 20:15:29 +00002376 return 0;
2377 }
2378
2379 /* Received Logging. */
2380 if (BGP_DEBUG (update, UPDATE_IN))
2381 {
ajsd2c1f162004-12-08 21:10:20 +00002382 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002383 peer->host,
2384 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2385 p->prefixlen);
2386 }
2387
paul718e3742002-12-13 20:15:29 +00002388 /* Make new BGP info. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05002389 new = info_make(type, sub_type, peer, attr_new, rn);
paul718e3742002-12-13 20:15:29 +00002390
2391 /* Update MPLS tag. */
2392 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002393 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002394
2395 /* Nexthop reachability check. */
2396 if ((afi == AFI_IP || afi == AFI_IP6)
2397 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002398 && (peer->sort == BGP_PEER_IBGP
2399 || peer->sort == BGP_PEER_CONFED
2400 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002401 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002402 {
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05002403 if (bgp_find_or_add_nexthop (afi, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002404 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002405 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002406 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002407 }
2408 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002409 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002410
paul902212c2006-02-05 17:51:19 +00002411 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002412 bgp_aggregate_increment (bgp, p, new, afi, safi);
2413
2414 /* Register new BGP information. */
2415 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002416
2417 /* route_node_get lock */
2418 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002419
Lou Berger050defe2016-01-12 13:41:59 -05002420 bgp_attr_flush (&new_attr);
2421
paul718e3742002-12-13 20:15:29 +00002422 /* If maximum prefix count is configured and current prefix
2423 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002424 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2425 return -1;
paul718e3742002-12-13 20:15:29 +00002426
2427 /* Process change. */
2428 bgp_process (bgp, rn, afi, safi);
2429
2430 return 0;
2431
2432 /* This BGP update is filtered. Log the reason then update BGP
2433 entry. */
2434 filtered:
2435 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002436 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002437 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2438 peer->host,
2439 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2440 p->prefixlen, reason);
2441
2442 if (ri)
paulb40d9392005-08-22 22:34:41 +00002443 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002444
2445 bgp_unlock_node (rn);
Lou Berger050defe2016-01-12 13:41:59 -05002446 bgp_attr_flush (&new_attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002447
paul718e3742002-12-13 20:15:29 +00002448 return 0;
2449}
2450
2451int
paulfee0f4c2004-09-13 05:12:46 +00002452bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2453 afi_t afi, safi_t safi, int type, int sub_type,
2454 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2455{
2456 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002457 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002458 struct bgp *bgp;
2459 int ret;
2460
2461 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2462 soft_reconfig);
2463
2464 bgp = peer->bgp;
2465
2466 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002467 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002468 {
2469 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2470 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2471 sub_type, prd, tag);
2472 }
2473
2474 return ret;
2475}
2476
2477int
paul718e3742002-12-13 20:15:29 +00002478bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002479 afi_t afi, safi_t safi, int type, int sub_type,
2480 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002481{
2482 struct bgp *bgp;
2483 char buf[SU_ADDRSTRLEN];
2484 struct bgp_node *rn;
2485 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002486 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002487 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002488
2489 bgp = peer->bgp;
2490
David Lamparter4584c232015-04-13 09:50:00 +02002491 /* Lookup node. */
2492 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2493
2494 /* Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2495 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2496 * the iteration over all RS clients.
2497 * Since we need to remove the entry from adj_in anyway, do that first and
2498 * if there was no entry, we don't need to do anything more. */
2499 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2500 && peer != bgp->peer_self)
2501 if (!bgp_adj_in_unset (rn, peer))
2502 {
2503 if (BGP_DEBUG (update, UPDATE_IN))
2504 zlog (peer->log, LOG_DEBUG, "%s withdrawing route %s/%d "
2505 "not in adj-in", peer->host,
2506 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2507 p->prefixlen);
2508 bgp_unlock_node (rn);
2509 return 0;
2510 }
2511
paulfee0f4c2004-09-13 05:12:46 +00002512 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002513 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002514 {
2515 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2516 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2517 }
2518
paul718e3742002-12-13 20:15:29 +00002519 /* Logging. */
2520 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002521 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002522 peer->host,
2523 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2524 p->prefixlen);
2525
paul718e3742002-12-13 20:15:29 +00002526 /* Lookup withdrawn route. */
2527 for (ri = rn->info; ri; ri = ri->next)
2528 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2529 break;
2530
2531 /* Withdraw specified route from routing table. */
2532 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Lou Berger050defe2016-01-12 13:41:59 -05002533 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
paul718e3742002-12-13 20:15:29 +00002534 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002535 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002536 "%s Can't find the route %s/%d", peer->host,
2537 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2538 p->prefixlen);
2539
2540 /* Unlock bgp_node_get() lock. */
2541 bgp_unlock_node (rn);
2542
2543 return 0;
2544}
David Lamparter6b0655a2014-06-04 06:53:35 +02002545
paul718e3742002-12-13 20:15:29 +00002546void
2547bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2548{
2549 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002550 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002551 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002552 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002553 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002554 struct bgp_node *rn;
2555 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002556 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002557
Paul Jakmab2497022007-06-14 11:17:58 +00002558 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002559 return;
2560
paul718e3742002-12-13 20:15:29 +00002561 bgp = peer->bgp;
2562 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002563
paul718e3742002-12-13 20:15:29 +00002564 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2565 aspath = attr.aspath;
2566 attr.local_pref = bgp->default_local_pref;
2567 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2568
2569 if (afi == AFI_IP)
2570 str2prefix ("0.0.0.0/0", &p);
paul718e3742002-12-13 20:15:29 +00002571 else if (afi == AFI_IP6)
2572 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002573 struct attr_extra *ae = attr.extra;
2574
paul718e3742002-12-13 20:15:29 +00002575 str2prefix ("::/0", &p);
2576
2577 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002578 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002579 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002580 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002581
2582 /* If the peer is on shared nextwork and we have link-local
2583 nexthop set it. */
2584 if (peer->shared_network
2585 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2586 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002587 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002588 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002589 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002590 }
2591 }
paul718e3742002-12-13 20:15:29 +00002592
2593 if (peer->default_rmap[afi][safi].name)
2594 {
paulfee0f4c2004-09-13 05:12:46 +00002595 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002596 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2597 {
2598 for (ri = rn->info; ri; ri = ri->next)
2599 {
2600 struct attr dummy_attr;
2601 struct attr_extra dummy_extra;
2602 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002603
Christian Frankedcab1bb2012-12-07 16:45:52 +00002604 /* Provide dummy so the route-map can't modify the attributes */
2605 dummy_attr.extra = &dummy_extra;
2606 bgp_attr_dup(&dummy_attr, ri->attr);
2607 info.peer = ri->peer;
2608 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002609
Christian Frankedcab1bb2012-12-07 16:45:52 +00002610 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2611 RMAP_BGP, &info);
2612
2613 /* The route map might have set attributes. If we don't flush them
2614 * here, they will be leaked. */
2615 bgp_attr_flush(&dummy_attr);
2616 if (ret != RMAP_DENYMATCH)
2617 break;
2618 }
2619 if (ret != RMAP_DENYMATCH)
2620 break;
2621 }
paulfee0f4c2004-09-13 05:12:46 +00002622 bgp->peer_self->rmap_type = 0;
2623
paul718e3742002-12-13 20:15:29 +00002624 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002625 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002626 }
2627
2628 if (withdraw)
2629 {
2630 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2631 bgp_default_withdraw_send (peer, afi, safi);
2632 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2633 }
2634 else
2635 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002636 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2637 {
2638 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2639 bgp_default_update_send (peer, &attr, afi, safi, from);
2640 }
paul718e3742002-12-13 20:15:29 +00002641 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002642
2643 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002644 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002645}
David Lamparter6b0655a2014-06-04 06:53:35 +02002646
paul718e3742002-12-13 20:15:29 +00002647static void
2648bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002649 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002650{
2651 struct bgp_node *rn;
2652 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002653 struct attr attr;
2654 struct attr_extra extra;
2655
Lou Berger298cc2f2016-01-12 13:42:02 -05002656 memset(&extra, 0, sizeof(extra));
2657
paul718e3742002-12-13 20:15:29 +00002658 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002659 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002660
Lou Berger298cc2f2016-01-12 13:42:02 -05002661 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP)
paul718e3742002-12-13 20:15:29 +00002662 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2663 bgp_default_originate (peer, afi, safi, 0);
2664
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002665 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2666 attr.extra = &extra;
2667
paul718e3742002-12-13 20:15:29 +00002668 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2669 for (ri = rn->info; ri; ri = ri->next)
2670 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2671 {
paulfee0f4c2004-09-13 05:12:46 +00002672 if ( (rsclient) ?
2673 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2674 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002675 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2676 else
2677 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2678 }
Lou Berger298cc2f2016-01-12 13:42:02 -05002679
2680 bgp_attr_flush_encap(&attr);
paul718e3742002-12-13 20:15:29 +00002681}
2682
2683void
2684bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2685{
2686 struct bgp_node *rn;
2687 struct bgp_table *table;
2688
2689 if (peer->status != Established)
2690 return;
2691
2692 if (! peer->afc_nego[afi][safi])
2693 return;
2694
2695 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2696 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2697 return;
2698
Lou Berger298cc2f2016-01-12 13:42:02 -05002699 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
paulfee0f4c2004-09-13 05:12:46 +00002700 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002701 else
2702 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2703 rn = bgp_route_next(rn))
2704 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002705 bgp_announce_table (peer, afi, safi, table, 0);
2706
2707 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2708 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002709}
2710
2711void
2712bgp_announce_route_all (struct peer *peer)
2713{
2714 afi_t afi;
2715 safi_t safi;
2716
2717 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2718 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2719 bgp_announce_route (peer, afi, safi);
2720}
David Lamparter6b0655a2014-06-04 06:53:35 +02002721
paul718e3742002-12-13 20:15:29 +00002722static void
paulfee0f4c2004-09-13 05:12:46 +00002723bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002724 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002725{
2726 struct bgp_node *rn;
2727 struct bgp_adj_in *ain;
2728
2729 if (! table)
2730 table = rsclient->bgp->rib[afi][safi];
2731
2732 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2733 for (ain = rn->adj_in; ain; ain = ain->next)
2734 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002735 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002736 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002737
paulfee0f4c2004-09-13 05:12:46 +00002738 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002739 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002740 }
2741}
2742
2743void
2744bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2745{
2746 struct bgp_table *table;
2747 struct bgp_node *rn;
2748
Lou Berger298cc2f2016-01-12 13:42:02 -05002749 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002750 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002751
2752 else
2753 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2754 rn = bgp_route_next (rn))
2755 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002756 {
2757 struct prefix_rd prd;
2758 prd.family = AF_UNSPEC;
2759 prd.prefixlen = 64;
2760 memcpy(&prd.val, rn->p.u.val, 8);
2761
2762 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2763 }
paulfee0f4c2004-09-13 05:12:46 +00002764}
David Lamparter6b0655a2014-06-04 06:53:35 +02002765
paulfee0f4c2004-09-13 05:12:46 +00002766static void
paul718e3742002-12-13 20:15:29 +00002767bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002768 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002769{
2770 int ret;
2771 struct bgp_node *rn;
2772 struct bgp_adj_in *ain;
2773
2774 if (! table)
2775 table = peer->bgp->rib[afi][safi];
2776
2777 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2778 for (ain = rn->adj_in; ain; ain = ain->next)
2779 {
2780 if (ain->peer == peer)
2781 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002782 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002783 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002784
paul718e3742002-12-13 20:15:29 +00002785 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2786 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002787 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002788
paul718e3742002-12-13 20:15:29 +00002789 if (ret < 0)
2790 {
2791 bgp_unlock_node (rn);
2792 return;
2793 }
2794 continue;
2795 }
2796 }
2797}
2798
2799void
2800bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2801{
2802 struct bgp_node *rn;
2803 struct bgp_table *table;
2804
2805 if (peer->status != Established)
2806 return;
2807
Lou Berger298cc2f2016-01-12 13:42:02 -05002808 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002809 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002810 else
2811 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2812 rn = bgp_route_next (rn))
2813 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002814 {
2815 struct prefix_rd prd;
2816 prd.family = AF_UNSPEC;
2817 prd.prefixlen = 64;
2818 memcpy(&prd.val, rn->p.u.val, 8);
2819
2820 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2821 }
paul718e3742002-12-13 20:15:29 +00002822}
David Lamparter6b0655a2014-06-04 06:53:35 +02002823
Chris Caputo228da422009-07-18 05:44:03 +00002824
2825struct bgp_clear_node_queue
2826{
2827 struct bgp_node *rn;
2828 enum bgp_clear_route_type purpose;
2829};
2830
paul200df112005-06-01 11:17:05 +00002831static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002832bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002833{
Chris Caputo228da422009-07-18 05:44:03 +00002834 struct bgp_clear_node_queue *cnq = data;
2835 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002836 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002837 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002838 afi_t afi = bgp_node_table (rn)->afi;
2839 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002840
Paul Jakma64e580a2006-02-21 01:09:01 +00002841 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002842
Paul Jakma64e580a2006-02-21 01:09:01 +00002843 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002844 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002845 {
2846 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002847 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2848 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002849 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002850 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2851 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002852 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002853 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002854 break;
2855 }
paul200df112005-06-01 11:17:05 +00002856 return WQ_SUCCESS;
2857}
2858
2859static void
paul0fb58d52005-11-14 14:31:49 +00002860bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002861{
Chris Caputo228da422009-07-18 05:44:03 +00002862 struct bgp_clear_node_queue *cnq = data;
2863 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002864 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002865
2866 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002867 bgp_table_unlock (table);
2868 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002869}
2870
2871static void
paul94f2b392005-06-28 12:44:16 +00002872bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002873{
Paul Jakma64e580a2006-02-21 01:09:01 +00002874 struct peer *peer = wq->spec.data;
2875
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002876 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002877 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002878
2879 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002880}
2881
2882static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002883bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002884{
Paul Jakmaa2943652009-07-21 14:02:04 +01002885 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002886
Paul Jakmaa2943652009-07-21 14:02:04 +01002887 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002888#undef CLEAR_QUEUE_NAME_LEN
2889
2890 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002891 {
2892 zlog_err ("%s: Failed to allocate work queue", __func__);
2893 exit (1);
2894 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002895 peer->clear_node_queue->spec.hold = 10;
2896 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2897 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2898 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2899 peer->clear_node_queue->spec.max_retries = 0;
2900
2901 /* we only 'lock' this peer reference when the queue is actually active */
2902 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002903}
2904
paul718e3742002-12-13 20:15:29 +00002905static void
2906bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002907 struct bgp_table *table, struct peer *rsclient,
2908 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002909{
2910 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002911
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002912
paul718e3742002-12-13 20:15:29 +00002913 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002914 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002915
hasso6cf159b2005-03-21 10:28:14 +00002916 /* If still no table => afi/safi isn't configured at all or smth. */
2917 if (! table)
2918 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002919
2920 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2921 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002922 struct bgp_info *ri;
2923 struct bgp_adj_in *ain;
2924 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002925
2926 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2927 * queued for every clearing peer, regardless of whether it is
2928 * relevant to the peer at hand.
2929 *
2930 * Overview: There are 3 different indices which need to be
2931 * scrubbed, potentially, when a peer is removed:
2932 *
2933 * 1 peer's routes visible via the RIB (ie accepted routes)
2934 * 2 peer's routes visible by the (optional) peer's adj-in index
2935 * 3 other routes visible by the peer's adj-out index
2936 *
2937 * 3 there is no hurry in scrubbing, once the struct peer is
2938 * removed from bgp->peer, we could just GC such deleted peer's
2939 * adj-outs at our leisure.
2940 *
2941 * 1 and 2 must be 'scrubbed' in some way, at least made
2942 * invisible via RIB index before peer session is allowed to be
2943 * brought back up. So one needs to know when such a 'search' is
2944 * complete.
2945 *
2946 * Ideally:
2947 *
2948 * - there'd be a single global queue or a single RIB walker
2949 * - rather than tracking which route_nodes still need to be
2950 * examined on a peer basis, we'd track which peers still
2951 * aren't cleared
2952 *
2953 * Given that our per-peer prefix-counts now should be reliable,
2954 * this may actually be achievable. It doesn't seem to be a huge
2955 * problem at this time,
2956 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002957 for (ain = rn->adj_in; ain; ain = ain->next)
2958 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2959 {
2960 bgp_adj_in_remove (rn, ain);
2961 bgp_unlock_node (rn);
2962 break;
2963 }
2964 for (aout = rn->adj_out; aout; aout = aout->next)
2965 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2966 {
2967 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2968 bgp_unlock_node (rn);
2969 break;
2970 }
2971
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002972 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002973 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002974 {
Chris Caputo228da422009-07-18 05:44:03 +00002975 struct bgp_clear_node_queue *cnq;
2976
2977 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002978 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002979 bgp_lock_node (rn);
2980 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2981 sizeof (struct bgp_clear_node_queue));
2982 cnq->rn = rn;
2983 cnq->purpose = purpose;
2984 work_queue_add (peer->clear_node_queue, cnq);
2985 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002986 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002987 }
2988 return;
2989}
2990
2991void
Chris Caputo228da422009-07-18 05:44:03 +00002992bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2993 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002994{
2995 struct bgp_node *rn;
2996 struct bgp_table *table;
2997 struct peer *rsclient;
2998 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002999
Paul Jakma64e580a2006-02-21 01:09:01 +00003000 if (peer->clear_node_queue == NULL)
3001 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00003002
Paul Jakmaca058a32006-09-14 02:58:49 +00003003 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3004 * Idle until it receives a Clearing_Completed event. This protects
3005 * against peers which flap faster than we can we clear, which could
3006 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00003007 *
3008 * a) race with routes from the new session being installed before
3009 * clear_route_node visits the node (to delete the route of that
3010 * peer)
3011 * b) resource exhaustion, clear_route_node likely leads to an entry
3012 * on the process_main queue. Fast-flapping could cause that queue
3013 * to grow and grow.
paul200df112005-06-01 11:17:05 +00003014 */
Donald Sharp7ef42212015-03-30 06:32:52 -07003015
3016 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3017 * the unlock will happen upon work-queue completion; other wise, the
3018 * unlock happens at the end of this function.
3019 */
Paul Jakmaca058a32006-09-14 02:58:49 +00003020 if (!peer->clear_node_queue->thread)
Lou Berger050defe2016-01-12 13:41:59 -05003021 peer_lock (peer); /* bgp_clear_node_complete */
Chris Caputo228da422009-07-18 05:44:03 +00003022 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00003023 {
Chris Caputo228da422009-07-18 05:44:03 +00003024 case BGP_CLEAR_ROUTE_NORMAL:
Lou Berger298cc2f2016-01-12 13:42:02 -05003025 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Chris Caputo228da422009-07-18 05:44:03 +00003026 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
3027 else
3028 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3029 rn = bgp_route_next (rn))
3030 if ((table = rn->info) != NULL)
3031 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3032
3033 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
3034 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
3035 PEER_FLAG_RSERVER_CLIENT))
3036 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3037 break;
3038
3039 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
Lou Berger050defe2016-01-12 13:41:59 -05003040 /*
3041 * gpz 091009: TBD why don't we have special handling for
3042 * SAFI_MPLS_VPN here in the original quagga code?
3043 * (and, by extension, for SAFI_ENCAP)
3044 */
Chris Caputo228da422009-07-18 05:44:03 +00003045 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3046 break;
3047
3048 default:
3049 assert (0);
3050 break;
paulfee0f4c2004-09-13 05:12:46 +00003051 }
Donald Sharp7ef42212015-03-30 06:32:52 -07003052
3053 /* unlock if no nodes got added to the clear-node-queue. */
Paul Jakma65ca75e2006-05-04 08:08:15 +00003054 if (!peer->clear_node_queue->thread)
Donald Sharp7ef42212015-03-30 06:32:52 -07003055 peer_unlock (peer);
3056
paul718e3742002-12-13 20:15:29 +00003057}
3058
3059void
3060bgp_clear_route_all (struct peer *peer)
3061{
3062 afi_t afi;
3063 safi_t safi;
3064
3065 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3066 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003067 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003068}
3069
Lou Berger82dd7072016-01-12 13:41:57 -05003070/*
3071 * Finish freeing things when exiting
3072 */
3073static void
3074bgp_drain_workqueue_immediate (struct work_queue *wq)
3075{
3076 if (!wq)
3077 return;
3078
3079 if (!wq->thread)
3080 {
3081 /*
3082 * no thread implies no queued items
3083 */
3084 assert(!wq->items->count);
3085 return;
3086 }
3087
3088 while (wq->items->count)
3089 {
3090 if (wq->thread)
3091 thread_cancel(wq->thread);
3092 work_queue_run(wq->thread);
3093 }
3094}
3095
3096/*
3097 * Special function to process clear node queue when bgpd is exiting
3098 * and the thread scheduler is no longer running.
3099 */
3100void
3101bgp_peer_clear_node_queue_drain_immediate(struct peer *peer)
3102{
3103 if (!peer)
3104 return;
3105
3106 bgp_drain_workqueue_immediate(peer->clear_node_queue);
3107}
3108
3109/*
3110 * The work queues are not specific to a BGP instance, but the
3111 * items in them refer to BGP instances, so this should be called
3112 * before each BGP instance is deleted.
3113 */
3114void
3115bgp_process_queues_drain_immediate(void)
3116{
3117 bgp_drain_workqueue_immediate(bm->process_main_queue);
3118 bgp_drain_workqueue_immediate(bm->process_rsclient_queue);
3119}
3120
paul718e3742002-12-13 20:15:29 +00003121void
3122bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3123{
3124 struct bgp_table *table;
3125 struct bgp_node *rn;
3126 struct bgp_adj_in *ain;
3127
3128 table = peer->bgp->rib[afi][safi];
3129
3130 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3131 for (ain = rn->adj_in; ain ; ain = ain->next)
3132 if (ain->peer == peer)
3133 {
3134 bgp_adj_in_remove (rn, ain);
3135 bgp_unlock_node (rn);
3136 break;
3137 }
3138}
hasso93406d82005-02-02 14:40:33 +00003139
3140void
3141bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3142{
3143 struct bgp_node *rn;
3144 struct bgp_info *ri;
3145 struct bgp_table *table;
3146
3147 table = peer->bgp->rib[afi][safi];
3148
3149 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3150 {
3151 for (ri = rn->info; ri; ri = ri->next)
3152 if (ri->peer == peer)
3153 {
3154 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3155 bgp_rib_remove (rn, ri, peer, afi, safi);
3156 break;
3157 }
3158 }
3159}
David Lamparter6b0655a2014-06-04 06:53:35 +02003160
Lou Berger82dd7072016-01-12 13:41:57 -05003161static void
3162bgp_cleanup_table(struct bgp_table *table, safi_t safi)
3163{
3164 struct bgp_node *rn;
3165 struct bgp_info *ri;
3166 struct bgp_info *next;
3167
3168 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3169 for (ri = rn->info; ri; ri = next)
3170 {
3171 next = ri->next;
3172 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3173 && ri->type == ZEBRA_ROUTE_BGP
3174 && ri->sub_type == BGP_ROUTE_NORMAL)
3175 bgp_zebra_withdraw (&rn->p, ri, safi);
3176 }
3177}
3178
paul718e3742002-12-13 20:15:29 +00003179/* Delete all kernel routes. */
3180void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003181bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003182{
3183 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003184 struct listnode *node, *nnode;
Lou Berger82dd7072016-01-12 13:41:57 -05003185 afi_t afi;
paul718e3742002-12-13 20:15:29 +00003186
paul1eb8ef22005-04-07 07:30:20 +00003187 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003188 {
Lou Berger82dd7072016-01-12 13:41:57 -05003189 for (afi = AFI_IP; afi < AFI_MAX; ++afi)
3190 {
3191 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00003192
Lou Berger82dd7072016-01-12 13:41:57 -05003193 bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003194
Lou Berger82dd7072016-01-12 13:41:57 -05003195 /*
3196 * VPN and ENCAP tables are two-level (RD is top level)
3197 */
3198 for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn;
3199 rn = bgp_route_next (rn))
Lou Berger298cc2f2016-01-12 13:42:02 -05003200 {
3201 if (rn->info)
Lou Berger82dd7072016-01-12 13:41:57 -05003202 {
Lou Berger298cc2f2016-01-12 13:42:02 -05003203 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN);
3204 bgp_table_finish ((struct bgp_table **)&(rn->info));
3205 rn->info = NULL;
3206 bgp_unlock_node(rn);
Lou Berger82dd7072016-01-12 13:41:57 -05003207 }
Lou Berger298cc2f2016-01-12 13:42:02 -05003208 }
3209
3210 for (rn = bgp_table_top(bgp->rib[afi][SAFI_ENCAP]); rn;
3211 rn = bgp_route_next (rn))
3212 {
3213 if (rn->info)
3214 {
3215 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_ENCAP);
3216 bgp_table_finish ((struct bgp_table **)&(rn->info));
3217 rn->info = NULL;
3218 bgp_unlock_node(rn);
3219 }
3220 }
Lou Berger82dd7072016-01-12 13:41:57 -05003221 }
paul718e3742002-12-13 20:15:29 +00003222 }
3223}
3224
3225void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003226bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003227{
3228 vty_reset ();
3229 bgp_zclient_reset ();
3230 access_list_reset ();
3231 prefix_list_reset ();
3232}
David Lamparter6b0655a2014-06-04 06:53:35 +02003233
paul718e3742002-12-13 20:15:29 +00003234/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3235 value. */
3236int
Paul Jakma518a4b72016-02-04 13:27:04 +00003237bgp_nlri_parse_ip (struct peer *peer, struct attr *attr,
3238 struct bgp_nlri *packet)
paul718e3742002-12-13 20:15:29 +00003239{
3240 u_char *pnt;
3241 u_char *lim;
3242 struct prefix p;
3243 int psize;
3244 int ret;
3245
3246 /* Check peer status. */
3247 if (peer->status != Established)
3248 return 0;
3249
3250 pnt = packet->nlri;
3251 lim = pnt + packet->length;
3252
Paul Jakma405e9e12016-02-04 17:00:18 +00003253 /* RFC4771 6.3 The NLRI field in the UPDATE message is checked for
3254 syntactic validity. If the field is syntactically incorrect,
3255 then the Error Subcode is set to Invalid Network Field. */
paul718e3742002-12-13 20:15:29 +00003256 for (; pnt < lim; pnt += psize)
3257 {
3258 /* Clear prefix structure. */
3259 memset (&p, 0, sizeof (struct prefix));
3260
3261 /* Fetch prefix length. */
3262 p.prefixlen = *pnt++;
Paul Jakma405e9e12016-02-04 17:00:18 +00003263 /* afi/safi validity already verified by caller, bgp_update_receive */
paul718e3742002-12-13 20:15:29 +00003264 p.family = afi2family (packet->afi);
3265
Paul Jakma405e9e12016-02-04 17:00:18 +00003266 /* Prefix length check. */
3267 if (p.prefixlen > prefix_blen (&p) * 8)
3268 {
3269 plog_err (peer->log,
3270 "%s [Error] Update packet error"
3271 " (wrong prefix length %u for afi %u)",
3272 peer->host, p.prefixlen, packet->afi);
3273 return -1;
3274 }
3275
paul718e3742002-12-13 20:15:29 +00003276 /* Packet size overflow check. */
3277 psize = PSIZE (p.prefixlen);
3278
3279 /* When packet overflow occur return immediately. */
3280 if (pnt + psize > lim)
Paul Jakma405e9e12016-02-04 17:00:18 +00003281 {
3282 plog_err (peer->log,
3283 "%s [Error] Update packet error"
3284 " (prefix length %u overflows packet)",
3285 peer->host, p.prefixlen);
3286 return -1;
3287 }
3288
3289 /* Defensive coding, double-check the psize fits in a struct prefix */
3290 if (psize > (ssize_t) sizeof(p.u))
3291 {
3292 plog_err (peer->log,
3293 "%s [Error] Update packet error"
3294 " (prefix length %u too large for prefix storage %zu!?!!",
3295 peer->host, p.prefixlen, sizeof(p.u));
3296 return -1;
3297 }
paul718e3742002-12-13 20:15:29 +00003298
3299 /* Fetch prefix from NLRI packet. */
3300 memcpy (&p.u.prefix, pnt, psize);
3301
3302 /* Check address. */
3303 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3304 {
3305 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3306 {
paulf5ba3872004-07-09 12:11:31 +00003307 /*
Paul Jakma405e9e12016-02-04 17:00:18 +00003308 * From RFC4271 Section 6.3:
3309 *
3310 * If a prefix in the NLRI field is semantically incorrect
3311 * (e.g., an unexpected multicast IP address), an error SHOULD
3312 * be logged locally, and the prefix SHOULD be ignored.
paulf5ba3872004-07-09 12:11:31 +00003313 */
paul718e3742002-12-13 20:15:29 +00003314 zlog (peer->log, LOG_ERR,
Paul Jakma405e9e12016-02-04 17:00:18 +00003315 "%s: IPv4 unicast NLRI is multicast address %s, ignoring",
3316 peer->host, inet_ntoa (p.u.prefix4));
3317 continue;
paul718e3742002-12-13 20:15:29 +00003318 }
3319 }
3320
paul718e3742002-12-13 20:15:29 +00003321 /* Check address. */
3322 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3323 {
3324 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3325 {
3326 char buf[BUFSIZ];
3327
Paul Jakma405e9e12016-02-04 17:00:18 +00003328 zlog (peer->log, LOG_ERR,
3329 "%s: IPv6 unicast NLRI is link-local address %s, ignoring",
3330 peer->host,
paul718e3742002-12-13 20:15:29 +00003331 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00003332 continue;
3333 }
Paul Jakma405e9e12016-02-04 17:00:18 +00003334 if (IN6_IS_ADDR_MULTICAST (&p.u.prefix6))
3335 {
3336 char buf[BUFSIZ];
3337
3338 zlog (peer->log, LOG_ERR,
3339 "%s: IPv6 unicast NLRI is multicast address %s, ignoring",
3340 peer->host,
3341 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3342 continue;
3343 }
3344 }
paul718e3742002-12-13 20:15:29 +00003345
3346 /* Normal process. */
3347 if (attr)
3348 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3349 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3350 else
3351 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3352 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3353
3354 /* Address family configuration mismatch or maximum-prefix count
3355 overflow. */
3356 if (ret < 0)
3357 return -1;
3358 }
3359
3360 /* Packet length consistency check. */
3361 if (pnt != lim)
paul718e3742002-12-13 20:15:29 +00003362 {
3363 plog_err (peer->log,
Paul Jakma405e9e12016-02-04 17:00:18 +00003364 "%s [Error] Update packet error"
3365 " (prefix length mismatch with total length)",
3366 peer->host);
paul718e3742002-12-13 20:15:29 +00003367 return -1;
3368 }
Paul Jakma405e9e12016-02-04 17:00:18 +00003369
paul718e3742002-12-13 20:15:29 +00003370 return 0;
3371}
David Lamparter6b0655a2014-06-04 06:53:35 +02003372
paul94f2b392005-06-28 12:44:16 +00003373static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003374bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003375{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003376 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003377}
3378
paul94f2b392005-06-28 12:44:16 +00003379static void
paul718e3742002-12-13 20:15:29 +00003380bgp_static_free (struct bgp_static *bgp_static)
3381{
3382 if (bgp_static->rmap.name)
3383 free (bgp_static->rmap.name);
3384 XFREE (MTYPE_BGP_STATIC, bgp_static);
3385}
3386
paul94f2b392005-06-28 12:44:16 +00003387static void
paulfee0f4c2004-09-13 05:12:46 +00003388bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3389 struct prefix *p, afi_t afi, safi_t safi)
3390{
3391 struct bgp_node *rn;
3392 struct bgp_info *ri;
3393
3394 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3395
3396 /* Check selected route and self inserted route. */
3397 for (ri = rn->info; ri; ri = ri->next)
3398 if (ri->peer == bgp->peer_self
3399 && ri->type == ZEBRA_ROUTE_BGP
3400 && ri->sub_type == BGP_ROUTE_STATIC)
3401 break;
3402
3403 /* Withdraw static BGP route from routing table. */
3404 if (ri)
3405 {
paulfee0f4c2004-09-13 05:12:46 +00003406 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003407 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003408 }
3409
3410 /* Unlock bgp_node_lookup. */
3411 bgp_unlock_node (rn);
3412}
3413
paul94f2b392005-06-28 12:44:16 +00003414static void
paulfee0f4c2004-09-13 05:12:46 +00003415bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003416 struct bgp_static *bgp_static,
3417 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003418{
3419 struct bgp_node *rn;
3420 struct bgp_info *ri;
3421 struct bgp_info *new;
3422 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003423 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003424 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003425 struct attr new_attr;
3426 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003427 struct bgp *bgp;
3428 int ret;
3429 char buf[SU_ADDRSTRLEN];
3430
3431 bgp = rsclient->bgp;
3432
Paul Jakma06e110f2006-05-12 23:29:22 +00003433 assert (bgp_static);
3434 if (!bgp_static)
3435 return;
3436
paulfee0f4c2004-09-13 05:12:46 +00003437 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3438
3439 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003440
3441 attr.nexthop = bgp_static->igpnexthop;
3442 attr.med = bgp_static->igpmetric;
3443 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003444
Paul Jakma41367172007-08-06 15:24:51 +00003445 if (bgp_static->atomic)
3446 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3447
paulfee0f4c2004-09-13 05:12:46 +00003448 /* Apply network route-map for export to this rsclient. */
3449 if (bgp_static->rmap.name)
3450 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003451 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003452 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003453 info.attr = &attr_tmp;
3454
paulfee0f4c2004-09-13 05:12:46 +00003455 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3456 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3457
3458 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3459
3460 rsclient->rmap_type = 0;
3461
3462 if (ret == RMAP_DENYMATCH)
3463 {
3464 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003465 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003466
3467 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003468 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003469 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003470 bgp_attr_extra_free (&attr);
3471
paulfee0f4c2004-09-13 05:12:46 +00003472 return;
3473 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003474 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003475 }
3476 else
3477 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003478
3479 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003480 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003481
paulfee0f4c2004-09-13 05:12:46 +00003482 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3483
Paul Jakmafb982c22007-05-04 20:15:47 +00003484 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3485 == RMAP_DENY)
3486 {
paulfee0f4c2004-09-13 05:12:46 +00003487 /* This BGP update is filtered. Log the reason then update BGP entry. */
3488 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003489 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003490 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3491 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3492 p->prefixlen, rsclient->host);
3493
3494 bgp->peer_self->rmap_type = 0;
3495
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003496 bgp_attr_unintern (&attr_new);
3497 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003498 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003499
3500 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3501
3502 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003503 }
paulfee0f4c2004-09-13 05:12:46 +00003504
3505 bgp->peer_self->rmap_type = 0;
3506
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003507 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003508 attr_new = bgp_attr_intern (&new_attr);
3509
3510 for (ri = rn->info; ri; ri = ri->next)
3511 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3512 && ri->sub_type == BGP_ROUTE_STATIC)
3513 break;
3514
3515 if (ri)
3516 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003517 if (attrhash_cmp (ri->attr, attr_new) &&
3518 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003519 {
3520 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003521 bgp_attr_unintern (&attr_new);
3522 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003523 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003524 return;
3525 }
3526 else
3527 {
3528 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003529 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003530
3531 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003532 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3533 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003534 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003535 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003536 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003537
3538 /* Process change. */
3539 bgp_process (bgp, rn, afi, safi);
3540 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003541 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003542 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003543 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003544 }
paulfee0f4c2004-09-13 05:12:46 +00003545 }
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003546
paulfee0f4c2004-09-13 05:12:46 +00003547 /* Make new BGP info. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003548 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
3549 attr_new, rn);
paulfee0f4c2004-09-13 05:12:46 +00003550 SET_FLAG (new->flags, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00003551
3552 /* Register new BGP information. */
3553 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003554
3555 /* route_node_get lock */
3556 bgp_unlock_node (rn);
3557
paulfee0f4c2004-09-13 05:12:46 +00003558 /* Process change. */
3559 bgp_process (bgp, rn, afi, safi);
3560
3561 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003562 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003563 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003564}
3565
paul94f2b392005-06-28 12:44:16 +00003566static void
paulfee0f4c2004-09-13 05:12:46 +00003567bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003568 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3569{
3570 struct bgp_node *rn;
3571 struct bgp_info *ri;
3572 struct bgp_info *new;
3573 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003574 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003575 struct attr *attr_new;
3576 int ret;
3577
Paul Jakmadd8103a2006-05-12 23:27:30 +00003578 assert (bgp_static);
3579 if (!bgp_static)
3580 return;
3581
paulfee0f4c2004-09-13 05:12:46 +00003582 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003583
3584 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003585
3586 attr.nexthop = bgp_static->igpnexthop;
3587 attr.med = bgp_static->igpmetric;
3588 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003589
Paul Jakma41367172007-08-06 15:24:51 +00003590 if (bgp_static->atomic)
3591 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3592
paul718e3742002-12-13 20:15:29 +00003593 /* Apply route-map. */
3594 if (bgp_static->rmap.name)
3595 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003596 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003597 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003598 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003599
paulfee0f4c2004-09-13 05:12:46 +00003600 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3601
paul718e3742002-12-13 20:15:29 +00003602 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003603
paulfee0f4c2004-09-13 05:12:46 +00003604 bgp->peer_self->rmap_type = 0;
3605
paul718e3742002-12-13 20:15:29 +00003606 if (ret == RMAP_DENYMATCH)
3607 {
3608 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003609 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003610
3611 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003612 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003613 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003614 bgp_static_withdraw (bgp, p, afi, safi);
3615 return;
3616 }
paul286e1e72003-08-08 00:24:31 +00003617 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003618 }
paul286e1e72003-08-08 00:24:31 +00003619 else
3620 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003621
3622 for (ri = rn->info; ri; ri = ri->next)
3623 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3624 && ri->sub_type == BGP_ROUTE_STATIC)
3625 break;
3626
3627 if (ri)
3628 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003629 if (attrhash_cmp (ri->attr, attr_new) &&
3630 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003631 {
3632 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003633 bgp_attr_unintern (&attr_new);
3634 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003635 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003636 return;
3637 }
3638 else
3639 {
3640 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003641 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003642
3643 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003644 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3645 bgp_info_restore(rn, ri);
3646 else
3647 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003648 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003649 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003650 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003651
3652 /* Process change. */
3653 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3654 bgp_process (bgp, rn, afi, safi);
3655 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003656 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003657 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003658 return;
3659 }
3660 }
3661
3662 /* Make new BGP info. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003663 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self, attr_new,
3664 rn);
paul718e3742002-12-13 20:15:29 +00003665 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00003666
3667 /* Aggregate address increment. */
3668 bgp_aggregate_increment (bgp, p, new, afi, safi);
3669
3670 /* Register new BGP information. */
3671 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003672
3673 /* route_node_get lock */
3674 bgp_unlock_node (rn);
3675
paul718e3742002-12-13 20:15:29 +00003676 /* Process change. */
3677 bgp_process (bgp, rn, afi, safi);
3678
3679 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003680 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003681 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003682}
3683
3684void
paulfee0f4c2004-09-13 05:12:46 +00003685bgp_static_update (struct bgp *bgp, struct prefix *p,
3686 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3687{
3688 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003689 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003690
3691 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3692
paul1eb8ef22005-04-07 07:30:20 +00003693 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003694 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003695 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3696 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003697 }
3698}
3699
paul718e3742002-12-13 20:15:29 +00003700void
3701bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3702 safi_t safi)
3703{
3704 struct bgp_node *rn;
3705 struct bgp_info *ri;
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003706 struct bgp_info *new;
paul718e3742002-12-13 20:15:29 +00003707
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003708 /* Make new BGP info. */
3709 rn = bgp_node_get (bgp->rib[afi][safi], p);
3710 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
3711 bgp_attr_default_intern(BGP_ORIGIN_IGP), rn);
3712
3713 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00003714
3715 /* Check selected route and self inserted route. */
3716 for (ri = rn->info; ri; ri = ri->next)
3717 if (ri->peer == bgp->peer_self
3718 && ri->type == ZEBRA_ROUTE_BGP
3719 && ri->sub_type == BGP_ROUTE_STATIC)
3720 break;
3721
3722 /* Withdraw static BGP route from routing table. */
3723 if (ri)
3724 {
3725 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003726 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003727 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003728 }
3729
3730 /* Unlock bgp_node_lookup. */
3731 bgp_unlock_node (rn);
3732}
3733
3734void
paulfee0f4c2004-09-13 05:12:46 +00003735bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3736{
3737 struct bgp_static *bgp_static;
3738 struct bgp *bgp;
3739 struct bgp_node *rn;
3740 struct prefix *p;
3741
3742 bgp = rsclient->bgp;
3743
3744 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3745 if ((bgp_static = rn->info) != NULL)
3746 {
3747 p = &rn->p;
3748
3749 bgp_static_update_rsclient (rsclient, p, bgp_static,
3750 afi, safi);
3751 }
3752}
3753
Lou Bergera76d9ca2016-01-12 13:41:53 -05003754/*
3755 * Used for SAFI_MPLS_VPN and SAFI_ENCAP
3756 */
paul94f2b392005-06-28 12:44:16 +00003757static void
Lou Bergera76d9ca2016-01-12 13:41:53 -05003758bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
3759 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003760{
3761 struct bgp_node *rn;
3762 struct bgp_info *ri;
3763
paulfee0f4c2004-09-13 05:12:46 +00003764 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003765
3766 /* Check selected route and self inserted route. */
3767 for (ri = rn->info; ri; ri = ri->next)
3768 if (ri->peer == bgp->peer_self
3769 && ri->type == ZEBRA_ROUTE_BGP
3770 && ri->sub_type == BGP_ROUTE_STATIC)
3771 break;
3772
3773 /* Withdraw static BGP route from routing table. */
3774 if (ri)
3775 {
3776 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003777 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003778 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003779 }
3780
3781 /* Unlock bgp_node_lookup. */
3782 bgp_unlock_node (rn);
3783}
3784
Lou Bergera76d9ca2016-01-12 13:41:53 -05003785static void
3786bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
3787 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3788{
3789 struct bgp_node *rn;
3790 struct bgp_info *new;
3791 struct attr *attr_new;
3792 struct attr attr = { 0 };
3793 struct bgp_info *ri;
3794
3795 assert (bgp_static);
3796
3797 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
3798
3799 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3800
3801 attr.nexthop = bgp_static->igpnexthop;
3802 attr.med = bgp_static->igpmetric;
3803 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3804
3805 /* Apply route-map. */
3806 if (bgp_static->rmap.name)
3807 {
3808 struct attr attr_tmp = attr;
3809 struct bgp_info info;
3810 int ret;
3811
3812 info.peer = bgp->peer_self;
3813 info.attr = &attr_tmp;
3814
3815 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3816
3817 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3818
3819 bgp->peer_self->rmap_type = 0;
3820
3821 if (ret == RMAP_DENYMATCH)
3822 {
3823 /* Free uninterned attribute. */
3824 bgp_attr_flush (&attr_tmp);
3825
3826 /* Unintern original. */
3827 aspath_unintern (&attr.aspath);
3828 bgp_attr_extra_free (&attr);
3829 bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
3830 bgp_static->tag);
3831 return;
3832 }
3833
3834 attr_new = bgp_attr_intern (&attr_tmp);
3835 }
3836 else
3837 {
3838 attr_new = bgp_attr_intern (&attr);
3839 }
3840
3841 for (ri = rn->info; ri; ri = ri->next)
3842 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3843 && ri->sub_type == BGP_ROUTE_STATIC)
3844 break;
3845
3846 if (ri)
3847 {
3848 if (attrhash_cmp (ri->attr, attr_new) &&
3849 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3850 {
3851 bgp_unlock_node (rn);
3852 bgp_attr_unintern (&attr_new);
3853 aspath_unintern (&attr.aspath);
3854 bgp_attr_extra_free (&attr);
3855 return;
3856 }
3857 else
3858 {
3859 /* The attribute is changed. */
3860 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3861
3862 /* Rewrite BGP route information. */
3863 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3864 bgp_info_restore(rn, ri);
3865 else
3866 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3867 bgp_attr_unintern (&ri->attr);
3868 ri->attr = attr_new;
3869 ri->uptime = bgp_clock ();
3870
3871 /* Process change. */
3872 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3873 bgp_process (bgp, rn, afi, safi);
3874 bgp_unlock_node (rn);
3875 aspath_unintern (&attr.aspath);
3876 bgp_attr_extra_free (&attr);
3877 return;
3878 }
3879 }
3880
3881
3882 /* Make new BGP info. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003883 new = info_make (ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
3884 attr_new, rn);
Lou Bergera76d9ca2016-01-12 13:41:53 -05003885 SET_FLAG (new->flags, BGP_INFO_VALID);
Lou Bergera76d9ca2016-01-12 13:41:53 -05003886 new->extra = bgp_info_extra_new();
3887 memcpy (new->extra->tag, bgp_static->tag, 3);
3888
3889 /* Aggregate address increment. */
3890 bgp_aggregate_increment (bgp, p, new, afi, safi);
3891
3892 /* Register new BGP information. */
3893 bgp_info_add (rn, new);
3894
3895 /* route_node_get lock */
3896 bgp_unlock_node (rn);
3897
3898 /* Process change. */
3899 bgp_process (bgp, rn, afi, safi);
3900
3901 /* Unintern original. */
3902 aspath_unintern (&attr.aspath);
3903 bgp_attr_extra_free (&attr);
3904}
3905
paul718e3742002-12-13 20:15:29 +00003906/* Configure static BGP network. When user don't run zebra, static
3907 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003908static int
paulfd79ac92004-10-13 05:06:08 +00003909bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003910 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003911{
3912 int ret;
3913 struct prefix p;
3914 struct bgp_static *bgp_static;
3915 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003916 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003917
3918 /* Convert IP prefix string to struct prefix. */
3919 ret = str2prefix (ip_str, &p);
3920 if (! ret)
3921 {
3922 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3923 return CMD_WARNING;
3924 }
paul718e3742002-12-13 20:15:29 +00003925 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3926 {
3927 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3928 VTY_NEWLINE);
3929 return CMD_WARNING;
3930 }
paul718e3742002-12-13 20:15:29 +00003931
3932 apply_mask (&p);
3933
3934 /* Set BGP static route configuration. */
3935 rn = bgp_node_get (bgp->route[afi][safi], &p);
3936
3937 if (rn->info)
3938 {
3939 /* Configuration change. */
3940 bgp_static = rn->info;
3941
3942 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003943 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3944 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003945
paul718e3742002-12-13 20:15:29 +00003946 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003947
paul718e3742002-12-13 20:15:29 +00003948 if (rmap)
3949 {
3950 if (bgp_static->rmap.name)
3951 free (bgp_static->rmap.name);
3952 bgp_static->rmap.name = strdup (rmap);
3953 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3954 }
3955 else
3956 {
3957 if (bgp_static->rmap.name)
3958 free (bgp_static->rmap.name);
3959 bgp_static->rmap.name = NULL;
3960 bgp_static->rmap.map = NULL;
3961 bgp_static->valid = 0;
3962 }
3963 bgp_unlock_node (rn);
3964 }
3965 else
3966 {
3967 /* New configuration. */
3968 bgp_static = bgp_static_new ();
3969 bgp_static->backdoor = backdoor;
3970 bgp_static->valid = 0;
3971 bgp_static->igpmetric = 0;
3972 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003973
paul718e3742002-12-13 20:15:29 +00003974 if (rmap)
3975 {
3976 if (bgp_static->rmap.name)
3977 free (bgp_static->rmap.name);
3978 bgp_static->rmap.name = strdup (rmap);
3979 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3980 }
3981 rn->info = bgp_static;
3982 }
3983
3984 /* If BGP scan is not enabled, we should install this route here. */
3985 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3986 {
3987 bgp_static->valid = 1;
3988
3989 if (need_update)
3990 bgp_static_withdraw (bgp, &p, afi, safi);
3991
3992 if (! bgp_static->backdoor)
3993 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3994 }
3995
3996 return CMD_SUCCESS;
3997}
3998
3999/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00004000static int
paulfd79ac92004-10-13 05:06:08 +00004001bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04004002 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004003{
4004 int ret;
4005 struct prefix p;
4006 struct bgp_static *bgp_static;
4007 struct bgp_node *rn;
4008
4009 /* Convert IP prefix string to struct prefix. */
4010 ret = str2prefix (ip_str, &p);
4011 if (! ret)
4012 {
4013 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4014 return CMD_WARNING;
4015 }
paul718e3742002-12-13 20:15:29 +00004016 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4017 {
4018 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4019 VTY_NEWLINE);
4020 return CMD_WARNING;
4021 }
paul718e3742002-12-13 20:15:29 +00004022
4023 apply_mask (&p);
4024
4025 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4026 if (! rn)
4027 {
4028 vty_out (vty, "%% Can't find specified static route configuration.%s",
4029 VTY_NEWLINE);
4030 return CMD_WARNING;
4031 }
4032
4033 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00004034
paul718e3742002-12-13 20:15:29 +00004035 /* Update BGP RIB. */
4036 if (! bgp_static->backdoor)
4037 bgp_static_withdraw (bgp, &p, afi, safi);
4038
4039 /* Clear configuration. */
4040 bgp_static_free (bgp_static);
4041 rn->info = NULL;
4042 bgp_unlock_node (rn);
4043 bgp_unlock_node (rn);
4044
4045 return CMD_SUCCESS;
4046}
4047
4048/* Called from bgp_delete(). Delete all static routes from the BGP
4049 instance. */
4050void
4051bgp_static_delete (struct bgp *bgp)
4052{
4053 afi_t afi;
4054 safi_t safi;
4055 struct bgp_node *rn;
4056 struct bgp_node *rm;
4057 struct bgp_table *table;
4058 struct bgp_static *bgp_static;
4059
4060 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4061 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4062 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4063 if (rn->info != NULL)
4064 {
Lou Berger298cc2f2016-01-12 13:42:02 -05004065 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004066 {
4067 table = rn->info;
4068
4069 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4070 {
4071 bgp_static = rn->info;
Lou Bergera76d9ca2016-01-12 13:41:53 -05004072 bgp_static_withdraw_safi (bgp, &rm->p,
4073 AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00004074 (struct prefix_rd *)&rn->p,
4075 bgp_static->tag);
4076 bgp_static_free (bgp_static);
4077 rn->info = NULL;
4078 bgp_unlock_node (rn);
4079 }
4080 }
4081 else
4082 {
4083 bgp_static = rn->info;
4084 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4085 bgp_static_free (bgp_static);
4086 rn->info = NULL;
4087 bgp_unlock_node (rn);
4088 }
4089 }
4090}
4091
Lou Bergera76d9ca2016-01-12 13:41:53 -05004092/*
4093 * gpz 110624
4094 * Currently this is used to set static routes for VPN and ENCAP.
4095 * I think it can probably be factored with bgp_static_set.
4096 */
paul718e3742002-12-13 20:15:29 +00004097int
Lou Bergera76d9ca2016-01-12 13:41:53 -05004098bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
4099 const char *rd_str, const char *tag_str,
4100 const char *rmap_str)
paul718e3742002-12-13 20:15:29 +00004101{
4102 int ret;
4103 struct prefix p;
4104 struct prefix_rd prd;
4105 struct bgp *bgp;
4106 struct bgp_node *prn;
4107 struct bgp_node *rn;
4108 struct bgp_table *table;
4109 struct bgp_static *bgp_static;
4110 u_char tag[3];
4111
4112 bgp = vty->index;
4113
4114 ret = str2prefix (ip_str, &p);
4115 if (! ret)
4116 {
4117 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4118 return CMD_WARNING;
4119 }
4120 apply_mask (&p);
4121
4122 ret = str2prefix_rd (rd_str, &prd);
4123 if (! ret)
4124 {
4125 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4126 return CMD_WARNING;
4127 }
4128
4129 ret = str2tag (tag_str, tag);
4130 if (! ret)
4131 {
4132 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4133 return CMD_WARNING;
4134 }
4135
Lou Bergera76d9ca2016-01-12 13:41:53 -05004136 prn = bgp_node_get (bgp->route[AFI_IP][safi],
paul718e3742002-12-13 20:15:29 +00004137 (struct prefix *)&prd);
4138 if (prn->info == NULL)
Lou Bergera76d9ca2016-01-12 13:41:53 -05004139 prn->info = bgp_table_init (AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004140 else
4141 bgp_unlock_node (prn);
4142 table = prn->info;
4143
4144 rn = bgp_node_get (table, &p);
4145
4146 if (rn->info)
4147 {
4148 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4149 bgp_unlock_node (rn);
4150 }
4151 else
4152 {
4153 /* New configuration. */
4154 bgp_static = bgp_static_new ();
Lou Bergera76d9ca2016-01-12 13:41:53 -05004155 bgp_static->backdoor = 0;
4156 bgp_static->valid = 0;
4157 bgp_static->igpmetric = 0;
4158 bgp_static->igpnexthop.s_addr = 0;
4159 memcpy(bgp_static->tag, tag, 3);
4160 bgp_static->prd = prd;
4161
4162 if (rmap_str)
4163 {
4164 if (bgp_static->rmap.name)
4165 free (bgp_static->rmap.name);
4166 bgp_static->rmap.name = strdup (rmap_str);
4167 bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
4168 }
paul718e3742002-12-13 20:15:29 +00004169 rn->info = bgp_static;
4170
Lou Bergera76d9ca2016-01-12 13:41:53 -05004171 bgp_static->valid = 1;
4172 bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004173 }
4174
4175 return CMD_SUCCESS;
4176}
4177
4178/* Configure static BGP network. */
4179int
Lou Bergera76d9ca2016-01-12 13:41:53 -05004180bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
4181 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00004182{
4183 int ret;
4184 struct bgp *bgp;
4185 struct prefix p;
4186 struct prefix_rd prd;
4187 struct bgp_node *prn;
4188 struct bgp_node *rn;
4189 struct bgp_table *table;
4190 struct bgp_static *bgp_static;
4191 u_char tag[3];
4192
4193 bgp = vty->index;
4194
4195 /* Convert IP prefix string to struct prefix. */
4196 ret = str2prefix (ip_str, &p);
4197 if (! ret)
4198 {
4199 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4200 return CMD_WARNING;
4201 }
4202 apply_mask (&p);
4203
4204 ret = str2prefix_rd (rd_str, &prd);
4205 if (! ret)
4206 {
4207 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4208 return CMD_WARNING;
4209 }
4210
4211 ret = str2tag (tag_str, tag);
4212 if (! ret)
4213 {
4214 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4215 return CMD_WARNING;
4216 }
4217
Lou Bergera76d9ca2016-01-12 13:41:53 -05004218 prn = bgp_node_get (bgp->route[AFI_IP][safi],
paul718e3742002-12-13 20:15:29 +00004219 (struct prefix *)&prd);
4220 if (prn->info == NULL)
Lou Bergera76d9ca2016-01-12 13:41:53 -05004221 prn->info = bgp_table_init (AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004222 else
4223 bgp_unlock_node (prn);
4224 table = prn->info;
4225
4226 rn = bgp_node_lookup (table, &p);
4227
4228 if (rn)
4229 {
Lou Bergera76d9ca2016-01-12 13:41:53 -05004230 bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
paul718e3742002-12-13 20:15:29 +00004231
4232 bgp_static = rn->info;
4233 bgp_static_free (bgp_static);
4234 rn->info = NULL;
4235 bgp_unlock_node (rn);
4236 bgp_unlock_node (rn);
4237 }
4238 else
4239 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4240
4241 return CMD_SUCCESS;
4242}
David Lamparter6b0655a2014-06-04 06:53:35 +02004243
paul718e3742002-12-13 20:15:29 +00004244DEFUN (bgp_network,
4245 bgp_network_cmd,
4246 "network A.B.C.D/M",
4247 "Specify a network to announce via BGP\n"
4248 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4249{
4250 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004251 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004252}
4253
4254DEFUN (bgp_network_route_map,
4255 bgp_network_route_map_cmd,
4256 "network A.B.C.D/M route-map WORD",
4257 "Specify a network to announce via BGP\n"
4258 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4259 "Route-map to modify the attributes\n"
4260 "Name of the route map\n")
4261{
4262 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004263 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004264}
4265
4266DEFUN (bgp_network_backdoor,
4267 bgp_network_backdoor_cmd,
4268 "network A.B.C.D/M backdoor",
4269 "Specify a network to announce via BGP\n"
4270 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4271 "Specify a BGP backdoor route\n")
4272{
Paul Jakma41367172007-08-06 15:24:51 +00004273 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004274 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004275}
4276
4277DEFUN (bgp_network_mask,
4278 bgp_network_mask_cmd,
4279 "network A.B.C.D mask A.B.C.D",
4280 "Specify a network to announce via BGP\n"
4281 "Network number\n"
4282 "Network mask\n"
4283 "Network mask\n")
4284{
4285 int ret;
4286 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004287
paul718e3742002-12-13 20:15:29 +00004288 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4289 if (! ret)
4290 {
4291 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4292 return CMD_WARNING;
4293 }
4294
4295 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004296 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004297}
4298
4299DEFUN (bgp_network_mask_route_map,
4300 bgp_network_mask_route_map_cmd,
4301 "network A.B.C.D mask A.B.C.D route-map WORD",
4302 "Specify a network to announce via BGP\n"
4303 "Network number\n"
4304 "Network mask\n"
4305 "Network mask\n"
4306 "Route-map to modify the attributes\n"
4307 "Name of the route map\n")
4308{
4309 int ret;
4310 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004311
paul718e3742002-12-13 20:15:29 +00004312 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4313 if (! ret)
4314 {
4315 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4316 return CMD_WARNING;
4317 }
4318
4319 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004320 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004321}
4322
4323DEFUN (bgp_network_mask_backdoor,
4324 bgp_network_mask_backdoor_cmd,
4325 "network A.B.C.D mask A.B.C.D backdoor",
4326 "Specify a network to announce via BGP\n"
4327 "Network number\n"
4328 "Network mask\n"
4329 "Network mask\n"
4330 "Specify a BGP backdoor route\n")
4331{
4332 int ret;
4333 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004334
paul718e3742002-12-13 20:15:29 +00004335 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4336 if (! ret)
4337 {
4338 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4339 return CMD_WARNING;
4340 }
4341
Paul Jakma41367172007-08-06 15:24:51 +00004342 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004343 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004344}
4345
4346DEFUN (bgp_network_mask_natural,
4347 bgp_network_mask_natural_cmd,
4348 "network A.B.C.D",
4349 "Specify a network to announce via BGP\n"
4350 "Network number\n")
4351{
4352 int ret;
4353 char prefix_str[BUFSIZ];
4354
4355 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4356 if (! ret)
4357 {
4358 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4359 return CMD_WARNING;
4360 }
4361
4362 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004363 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004364}
4365
4366DEFUN (bgp_network_mask_natural_route_map,
4367 bgp_network_mask_natural_route_map_cmd,
4368 "network A.B.C.D route-map WORD",
4369 "Specify a network to announce via BGP\n"
4370 "Network number\n"
4371 "Route-map to modify the attributes\n"
4372 "Name of the route map\n")
4373{
4374 int ret;
4375 char prefix_str[BUFSIZ];
4376
4377 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4378 if (! ret)
4379 {
4380 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4381 return CMD_WARNING;
4382 }
4383
4384 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004385 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004386}
4387
4388DEFUN (bgp_network_mask_natural_backdoor,
4389 bgp_network_mask_natural_backdoor_cmd,
4390 "network A.B.C.D backdoor",
4391 "Specify a network to announce via BGP\n"
4392 "Network number\n"
4393 "Specify a BGP backdoor route\n")
4394{
4395 int ret;
4396 char prefix_str[BUFSIZ];
4397
4398 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4399 if (! ret)
4400 {
4401 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4402 return CMD_WARNING;
4403 }
4404
Paul Jakma41367172007-08-06 15:24:51 +00004405 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004406 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004407}
4408
4409DEFUN (no_bgp_network,
4410 no_bgp_network_cmd,
4411 "no network A.B.C.D/M",
4412 NO_STR
4413 "Specify a network to announce via BGP\n"
4414 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4415{
4416 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4417 bgp_node_safi (vty));
4418}
4419
4420ALIAS (no_bgp_network,
4421 no_bgp_network_route_map_cmd,
4422 "no network A.B.C.D/M route-map WORD",
4423 NO_STR
4424 "Specify a network to announce via BGP\n"
4425 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4426 "Route-map to modify the attributes\n"
4427 "Name of the route map\n")
4428
4429ALIAS (no_bgp_network,
4430 no_bgp_network_backdoor_cmd,
4431 "no network A.B.C.D/M backdoor",
4432 NO_STR
4433 "Specify a network to announce via BGP\n"
4434 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4435 "Specify a BGP backdoor route\n")
4436
4437DEFUN (no_bgp_network_mask,
4438 no_bgp_network_mask_cmd,
4439 "no network A.B.C.D mask A.B.C.D",
4440 NO_STR
4441 "Specify a network to announce via BGP\n"
4442 "Network number\n"
4443 "Network mask\n"
4444 "Network mask\n")
4445{
4446 int ret;
4447 char prefix_str[BUFSIZ];
4448
4449 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4450 if (! ret)
4451 {
4452 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4453 return CMD_WARNING;
4454 }
4455
4456 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4457 bgp_node_safi (vty));
4458}
4459
4460ALIAS (no_bgp_network_mask,
4461 no_bgp_network_mask_route_map_cmd,
4462 "no network A.B.C.D mask A.B.C.D route-map WORD",
4463 NO_STR
4464 "Specify a network to announce via BGP\n"
4465 "Network number\n"
4466 "Network mask\n"
4467 "Network mask\n"
4468 "Route-map to modify the attributes\n"
4469 "Name of the route map\n")
4470
4471ALIAS (no_bgp_network_mask,
4472 no_bgp_network_mask_backdoor_cmd,
4473 "no network A.B.C.D mask A.B.C.D backdoor",
4474 NO_STR
4475 "Specify a network to announce via BGP\n"
4476 "Network number\n"
4477 "Network mask\n"
4478 "Network mask\n"
4479 "Specify a BGP backdoor route\n")
4480
4481DEFUN (no_bgp_network_mask_natural,
4482 no_bgp_network_mask_natural_cmd,
4483 "no network A.B.C.D",
4484 NO_STR
4485 "Specify a network to announce via BGP\n"
4486 "Network number\n")
4487{
4488 int ret;
4489 char prefix_str[BUFSIZ];
4490
4491 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4492 if (! ret)
4493 {
4494 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4495 return CMD_WARNING;
4496 }
4497
4498 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4499 bgp_node_safi (vty));
4500}
4501
4502ALIAS (no_bgp_network_mask_natural,
4503 no_bgp_network_mask_natural_route_map_cmd,
4504 "no network A.B.C.D route-map WORD",
4505 NO_STR
4506 "Specify a network to announce via BGP\n"
4507 "Network number\n"
4508 "Route-map to modify the attributes\n"
4509 "Name of the route map\n")
4510
4511ALIAS (no_bgp_network_mask_natural,
4512 no_bgp_network_mask_natural_backdoor_cmd,
4513 "no network A.B.C.D backdoor",
4514 NO_STR
4515 "Specify a network to announce via BGP\n"
4516 "Network number\n"
4517 "Specify a BGP backdoor route\n")
4518
paul718e3742002-12-13 20:15:29 +00004519DEFUN (ipv6_bgp_network,
4520 ipv6_bgp_network_cmd,
4521 "network X:X::X:X/M",
4522 "Specify a network to announce via BGP\n"
4523 "IPv6 prefix <network>/<length>\n")
4524{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304525 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004526 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004527}
4528
4529DEFUN (ipv6_bgp_network_route_map,
4530 ipv6_bgp_network_route_map_cmd,
4531 "network X:X::X:X/M route-map WORD",
4532 "Specify a network to announce via BGP\n"
4533 "IPv6 prefix <network>/<length>\n"
4534 "Route-map to modify the attributes\n"
4535 "Name of the route map\n")
4536{
4537 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004538 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004539}
4540
4541DEFUN (no_ipv6_bgp_network,
4542 no_ipv6_bgp_network_cmd,
4543 "no network X:X::X:X/M",
4544 NO_STR
4545 "Specify a network to announce via BGP\n"
4546 "IPv6 prefix <network>/<length>\n")
4547{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304548 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004549}
4550
4551ALIAS (no_ipv6_bgp_network,
4552 no_ipv6_bgp_network_route_map_cmd,
4553 "no network X:X::X:X/M route-map WORD",
4554 NO_STR
4555 "Specify a network to announce via BGP\n"
4556 "IPv6 prefix <network>/<length>\n"
4557 "Route-map to modify the attributes\n"
4558 "Name of the route map\n")
4559
4560ALIAS (ipv6_bgp_network,
4561 old_ipv6_bgp_network_cmd,
4562 "ipv6 bgp network X:X::X:X/M",
4563 IPV6_STR
4564 BGP_STR
4565 "Specify a network to announce via BGP\n"
4566 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4567
4568ALIAS (no_ipv6_bgp_network,
4569 old_no_ipv6_bgp_network_cmd,
4570 "no ipv6 bgp network X:X::X:X/M",
4571 NO_STR
4572 IPV6_STR
4573 BGP_STR
4574 "Specify a network to announce via BGP\n"
4575 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004576
4577/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4578ALIAS_DEPRECATED (bgp_network,
4579 bgp_network_ttl_cmd,
4580 "network A.B.C.D/M pathlimit <0-255>",
4581 "Specify a network to announce via BGP\n"
4582 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4583 "AS-Path hopcount limit attribute\n"
4584 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4585ALIAS_DEPRECATED (bgp_network_backdoor,
4586 bgp_network_backdoor_ttl_cmd,
4587 "network A.B.C.D/M backdoor pathlimit <0-255>",
4588 "Specify a network to announce via BGP\n"
4589 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4590 "Specify a BGP backdoor route\n"
4591 "AS-Path hopcount limit attribute\n"
4592 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4593ALIAS_DEPRECATED (bgp_network_mask,
4594 bgp_network_mask_ttl_cmd,
4595 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4596 "Specify a network to announce via BGP\n"
4597 "Network number\n"
4598 "Network mask\n"
4599 "Network mask\n"
4600 "AS-Path hopcount limit attribute\n"
4601 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4602ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4603 bgp_network_mask_backdoor_ttl_cmd,
4604 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4605 "Specify a network to announce via BGP\n"
4606 "Network number\n"
4607 "Network mask\n"
4608 "Network mask\n"
4609 "Specify a BGP backdoor route\n"
4610 "AS-Path hopcount limit attribute\n"
4611 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4612ALIAS_DEPRECATED (bgp_network_mask_natural,
4613 bgp_network_mask_natural_ttl_cmd,
4614 "network A.B.C.D pathlimit <0-255>",
4615 "Specify a network to announce via BGP\n"
4616 "Network number\n"
4617 "AS-Path hopcount limit attribute\n"
4618 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4619ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4620 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004621 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004622 "Specify a network to announce via BGP\n"
4623 "Network number\n"
4624 "Specify a BGP backdoor route\n"
4625 "AS-Path hopcount limit attribute\n"
4626 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4627ALIAS_DEPRECATED (no_bgp_network,
4628 no_bgp_network_ttl_cmd,
4629 "no network A.B.C.D/M pathlimit <0-255>",
4630 NO_STR
4631 "Specify a network to announce via BGP\n"
4632 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4633 "AS-Path hopcount limit attribute\n"
4634 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4635ALIAS_DEPRECATED (no_bgp_network,
4636 no_bgp_network_backdoor_ttl_cmd,
4637 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4638 NO_STR
4639 "Specify a network to announce via BGP\n"
4640 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4641 "Specify a BGP backdoor route\n"
4642 "AS-Path hopcount limit attribute\n"
4643 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4644ALIAS_DEPRECATED (no_bgp_network,
4645 no_bgp_network_mask_ttl_cmd,
4646 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4647 NO_STR
4648 "Specify a network to announce via BGP\n"
4649 "Network number\n"
4650 "Network mask\n"
4651 "Network mask\n"
4652 "AS-Path hopcount limit attribute\n"
4653 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4654ALIAS_DEPRECATED (no_bgp_network_mask,
4655 no_bgp_network_mask_backdoor_ttl_cmd,
4656 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4657 NO_STR
4658 "Specify a network to announce via BGP\n"
4659 "Network number\n"
4660 "Network mask\n"
4661 "Network mask\n"
4662 "Specify a BGP backdoor route\n"
4663 "AS-Path hopcount limit attribute\n"
4664 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4665ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4666 no_bgp_network_mask_natural_ttl_cmd,
4667 "no network A.B.C.D pathlimit <0-255>",
4668 NO_STR
4669 "Specify a network to announce via BGP\n"
4670 "Network number\n"
4671 "AS-Path hopcount limit attribute\n"
4672 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4673ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4674 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4675 "no network A.B.C.D backdoor pathlimit <0-255>",
4676 NO_STR
4677 "Specify a network to announce via BGP\n"
4678 "Network number\n"
4679 "Specify a BGP backdoor route\n"
4680 "AS-Path hopcount limit attribute\n"
4681 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4682ALIAS_DEPRECATED (ipv6_bgp_network,
4683 ipv6_bgp_network_ttl_cmd,
4684 "network X:X::X:X/M pathlimit <0-255>",
4685 "Specify a network to announce via BGP\n"
4686 "IPv6 prefix <network>/<length>\n"
4687 "AS-Path hopcount limit attribute\n"
4688 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4689ALIAS_DEPRECATED (no_ipv6_bgp_network,
4690 no_ipv6_bgp_network_ttl_cmd,
4691 "no network X:X::X:X/M pathlimit <0-255>",
4692 NO_STR
4693 "Specify a network to announce via BGP\n"
4694 "IPv6 prefix <network>/<length>\n"
4695 "AS-Path hopcount limit attribute\n"
4696 "AS-Pathlimit TTL, in number of AS-Path hops\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02004697
paul718e3742002-12-13 20:15:29 +00004698/* Aggreagete address:
4699
4700 advertise-map Set condition to advertise attribute
4701 as-set Generate AS set path information
4702 attribute-map Set attributes of aggregate
4703 route-map Set parameters of aggregate
4704 summary-only Filter more specific routes from updates
4705 suppress-map Conditionally filter more specific routes from updates
4706 <cr>
4707 */
4708struct bgp_aggregate
4709{
4710 /* Summary-only flag. */
4711 u_char summary_only;
4712
4713 /* AS set generation. */
4714 u_char as_set;
4715
4716 /* Route-map for aggregated route. */
4717 struct route_map *map;
4718
4719 /* Suppress-count. */
4720 unsigned long count;
4721
4722 /* SAFI configuration. */
4723 safi_t safi;
4724};
4725
paul94f2b392005-06-28 12:44:16 +00004726static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004727bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004728{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004729 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004730}
4731
paul94f2b392005-06-28 12:44:16 +00004732static void
paul718e3742002-12-13 20:15:29 +00004733bgp_aggregate_free (struct bgp_aggregate *aggregate)
4734{
4735 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4736}
4737
Daniel Walton76a72802015-05-19 17:47:24 -07004738/* Update an aggregate as routes are added/removed from the BGP table */
paul94f2b392005-06-28 12:44:16 +00004739static void
paul718e3742002-12-13 20:15:29 +00004740bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4741 afi_t afi, safi_t safi, struct bgp_info *del,
4742 struct bgp_aggregate *aggregate)
4743{
4744 struct bgp_table *table;
4745 struct bgp_node *top;
4746 struct bgp_node *rn;
4747 u_char origin;
4748 struct aspath *aspath = NULL;
4749 struct aspath *asmerge = NULL;
4750 struct community *community = NULL;
4751 struct community *commerge = NULL;
paul718e3742002-12-13 20:15:29 +00004752 struct bgp_info *ri;
4753 struct bgp_info *new;
4754 int first = 1;
4755 unsigned long match = 0;
4756
paul718e3742002-12-13 20:15:29 +00004757 /* ORIGIN attribute: If at least one route among routes that are
4758 aggregated has ORIGIN with the value INCOMPLETE, then the
4759 aggregated route must have the ORIGIN attribute with the value
4760 INCOMPLETE. Otherwise, if at least one route among routes that
4761 are aggregated has ORIGIN with the value EGP, then the aggregated
4762 route must have the origin attribute with the value EGP. In all
4763 other case the value of the ORIGIN attribute of the aggregated
4764 route is INTERNAL. */
4765 origin = BGP_ORIGIN_IGP;
4766
4767 table = bgp->rib[afi][safi];
4768
4769 top = bgp_node_get (table, p);
4770 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4771 if (rn->p.prefixlen > p->prefixlen)
4772 {
4773 match = 0;
4774
4775 for (ri = rn->info; ri; ri = ri->next)
4776 {
4777 if (BGP_INFO_HOLDDOWN (ri))
4778 continue;
4779
4780 if (del && ri == del)
4781 continue;
4782
4783 if (! rinew && first)
Paul Jakma7aa9dce2014-09-19 14:42:23 +01004784 first = 0;
paul718e3742002-12-13 20:15:29 +00004785
4786#ifdef AGGREGATE_NEXTHOP_CHECK
4787 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4788 || ri->attr->med != med)
4789 {
4790 if (aspath)
4791 aspath_free (aspath);
4792 if (community)
4793 community_free (community);
4794 bgp_unlock_node (rn);
4795 bgp_unlock_node (top);
4796 return;
4797 }
4798#endif /* AGGREGATE_NEXTHOP_CHECK */
4799
4800 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4801 {
4802 if (aggregate->summary_only)
4803 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004804 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004805 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004806 match++;
4807 }
4808
4809 aggregate->count++;
4810
Daniel Walton76a72802015-05-19 17:47:24 -07004811 if (origin < ri->attr->origin)
4812 origin = ri->attr->origin;
4813
paul718e3742002-12-13 20:15:29 +00004814 if (aggregate->as_set)
4815 {
paul718e3742002-12-13 20:15:29 +00004816 if (aspath)
4817 {
4818 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4819 aspath_free (aspath);
4820 aspath = asmerge;
4821 }
4822 else
4823 aspath = aspath_dup (ri->attr->aspath);
4824
4825 if (ri->attr->community)
4826 {
4827 if (community)
4828 {
4829 commerge = community_merge (community,
4830 ri->attr->community);
4831 community = community_uniq_sort (commerge);
4832 community_free (commerge);
4833 }
4834 else
4835 community = community_dup (ri->attr->community);
4836 }
4837 }
4838 }
4839 }
4840 if (match)
4841 bgp_process (bgp, rn, afi, safi);
4842 }
4843 bgp_unlock_node (top);
4844
4845 if (rinew)
4846 {
4847 aggregate->count++;
4848
4849 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004850 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004851
Daniel Walton76a72802015-05-19 17:47:24 -07004852 if (origin < rinew->attr->origin)
4853 origin = rinew->attr->origin;
4854
paul718e3742002-12-13 20:15:29 +00004855 if (aggregate->as_set)
4856 {
paul718e3742002-12-13 20:15:29 +00004857 if (aspath)
4858 {
4859 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4860 aspath_free (aspath);
4861 aspath = asmerge;
4862 }
4863 else
4864 aspath = aspath_dup (rinew->attr->aspath);
4865
4866 if (rinew->attr->community)
4867 {
4868 if (community)
4869 {
4870 commerge = community_merge (community,
4871 rinew->attr->community);
4872 community = community_uniq_sort (commerge);
4873 community_free (commerge);
4874 }
4875 else
4876 community = community_dup (rinew->attr->community);
4877 }
4878 }
4879 }
4880
4881 if (aggregate->count > 0)
4882 {
4883 rn = bgp_node_get (table, p);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05004884 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, bgp->peer_self,
4885 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
4886 aggregate->as_set), rn);
paul718e3742002-12-13 20:15:29 +00004887 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00004888
4889 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004890 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004891 bgp_process (bgp, rn, afi, safi);
4892 }
4893 else
4894 {
4895 if (aspath)
4896 aspath_free (aspath);
4897 if (community)
4898 community_free (community);
4899 }
4900}
4901
4902void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4903 struct bgp_aggregate *);
4904
4905void
4906bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4907 struct bgp_info *ri, afi_t afi, safi_t safi)
4908{
4909 struct bgp_node *child;
4910 struct bgp_node *rn;
4911 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004912 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004913
4914 /* MPLS-VPN aggregation is not yet supported. */
Lou Berger298cc2f2016-01-12 13:42:02 -05004915 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004916 return;
4917
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004918 table = bgp->aggregate[afi][safi];
4919
4920 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004921 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004922 return;
4923
paul718e3742002-12-13 20:15:29 +00004924 if (p->prefixlen == 0)
4925 return;
4926
4927 if (BGP_INFO_HOLDDOWN (ri))
4928 return;
4929
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004930 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004931
4932 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004933 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004934 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4935 {
4936 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004937 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004938 }
4939 bgp_unlock_node (child);
4940}
4941
4942void
4943bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4944 struct bgp_info *del, afi_t afi, safi_t safi)
4945{
4946 struct bgp_node *child;
4947 struct bgp_node *rn;
4948 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004949 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004950
4951 /* MPLS-VPN aggregation is not yet supported. */
Lou Berger298cc2f2016-01-12 13:42:02 -05004952 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004953 return;
4954
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004955 table = bgp->aggregate[afi][safi];
4956
4957 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004958 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004959 return;
4960
paul718e3742002-12-13 20:15:29 +00004961 if (p->prefixlen == 0)
4962 return;
4963
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004964 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004965
4966 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004967 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004968 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4969 {
4970 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004971 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004972 }
4973 bgp_unlock_node (child);
4974}
4975
Daniel Walton76a72802015-05-19 17:47:24 -07004976/* Called via bgp_aggregate_set when the user configures aggregate-address */
paul94f2b392005-06-28 12:44:16 +00004977static void
paul718e3742002-12-13 20:15:29 +00004978bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4979 struct bgp_aggregate *aggregate)
4980{
4981 struct bgp_table *table;
4982 struct bgp_node *top;
4983 struct bgp_node *rn;
4984 struct bgp_info *new;
4985 struct bgp_info *ri;
4986 unsigned long match;
4987 u_char origin = BGP_ORIGIN_IGP;
4988 struct aspath *aspath = NULL;
4989 struct aspath *asmerge = NULL;
4990 struct community *community = NULL;
4991 struct community *commerge = NULL;
4992
4993 table = bgp->rib[afi][safi];
4994
4995 /* Sanity check. */
4996 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4997 return;
4998 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4999 return;
5000
5001 /* If routes exists below this node, generate aggregate routes. */
5002 top = bgp_node_get (table, p);
5003 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5004 if (rn->p.prefixlen > p->prefixlen)
5005 {
5006 match = 0;
5007
5008 for (ri = rn->info; ri; ri = ri->next)
5009 {
5010 if (BGP_INFO_HOLDDOWN (ri))
5011 continue;
5012
5013 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5014 {
5015 /* summary-only aggregate route suppress aggregated
5016 route announcement. */
5017 if (aggregate->summary_only)
5018 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005019 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00005020 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005021 match++;
5022 }
Daniel Walton76a72802015-05-19 17:47:24 -07005023
5024 /* If at least one route among routes that are aggregated has
5025 * ORIGIN with the value INCOMPLETE, then the aggregated route
5026 * MUST have the ORIGIN attribute with the value INCOMPLETE.
5027 * Otherwise, if at least one route among routes that are
5028 * aggregated has ORIGIN with the value EGP, then the aggregated
5029 * route MUST have the ORIGIN attribute with the value EGP.
5030 */
5031 if (origin < ri->attr->origin)
5032 origin = ri->attr->origin;
5033
paul718e3742002-12-13 20:15:29 +00005034 /* as-set aggregate route generate origin, as path,
5035 community aggregation. */
5036 if (aggregate->as_set)
5037 {
paul718e3742002-12-13 20:15:29 +00005038 if (aspath)
5039 {
5040 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5041 aspath_free (aspath);
5042 aspath = asmerge;
5043 }
5044 else
5045 aspath = aspath_dup (ri->attr->aspath);
5046
5047 if (ri->attr->community)
5048 {
5049 if (community)
5050 {
5051 commerge = community_merge (community,
5052 ri->attr->community);
5053 community = community_uniq_sort (commerge);
5054 community_free (commerge);
5055 }
5056 else
5057 community = community_dup (ri->attr->community);
5058 }
5059 }
5060 aggregate->count++;
5061 }
5062 }
5063
5064 /* If this node is suppressed, process the change. */
5065 if (match)
5066 bgp_process (bgp, rn, afi, safi);
5067 }
5068 bgp_unlock_node (top);
5069
5070 /* Add aggregate route to BGP table. */
5071 if (aggregate->count)
5072 {
5073 rn = bgp_node_get (table, p);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05005074 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, bgp->peer_self,
5075 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
5076 aggregate->as_set), rn);
paul718e3742002-12-13 20:15:29 +00005077 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00005078
5079 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00005080 bgp_unlock_node (rn);
5081
paul718e3742002-12-13 20:15:29 +00005082 /* Process change. */
5083 bgp_process (bgp, rn, afi, safi);
5084 }
Denil Virae2a92582015-08-11 13:34:59 -07005085 else
5086 {
5087 if (aspath)
5088 aspath_free (aspath);
5089 if (community)
5090 community_free (community);
5091 }
paul718e3742002-12-13 20:15:29 +00005092}
5093
5094void
5095bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5096 safi_t safi, struct bgp_aggregate *aggregate)
5097{
5098 struct bgp_table *table;
5099 struct bgp_node *top;
5100 struct bgp_node *rn;
5101 struct bgp_info *ri;
5102 unsigned long match;
5103
5104 table = bgp->rib[afi][safi];
5105
5106 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5107 return;
5108 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5109 return;
5110
5111 /* If routes exists below this node, generate aggregate routes. */
5112 top = bgp_node_get (table, p);
5113 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5114 if (rn->p.prefixlen > p->prefixlen)
5115 {
5116 match = 0;
5117
5118 for (ri = rn->info; ri; ri = ri->next)
5119 {
5120 if (BGP_INFO_HOLDDOWN (ri))
5121 continue;
5122
5123 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5124 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005125 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00005126 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005127 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00005128
Paul Jakmafb982c22007-05-04 20:15:47 +00005129 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00005130 {
Paul Jakma1a392d42006-09-07 00:24:49 +00005131 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005132 match++;
5133 }
5134 }
5135 aggregate->count--;
5136 }
5137 }
5138
Paul Jakmafb982c22007-05-04 20:15:47 +00005139 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00005140 if (match)
5141 bgp_process (bgp, rn, afi, safi);
5142 }
5143 bgp_unlock_node (top);
5144
5145 /* Delete aggregate route from BGP table. */
5146 rn = bgp_node_get (table, p);
5147
5148 for (ri = rn->info; ri; ri = ri->next)
5149 if (ri->peer == bgp->peer_self
5150 && ri->type == ZEBRA_ROUTE_BGP
5151 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5152 break;
5153
5154 /* Withdraw static BGP route from routing table. */
5155 if (ri)
5156 {
paul718e3742002-12-13 20:15:29 +00005157 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005158 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00005159 }
5160
5161 /* Unlock bgp_node_lookup. */
5162 bgp_unlock_node (rn);
5163}
5164
5165/* Aggregate route attribute. */
5166#define AGGREGATE_SUMMARY_ONLY 1
5167#define AGGREGATE_AS_SET 1
5168
paul94f2b392005-06-28 12:44:16 +00005169static int
Robert Baysf6269b42010-08-05 10:26:28 -07005170bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5171 afi_t afi, safi_t safi)
5172{
5173 int ret;
5174 struct prefix p;
5175 struct bgp_node *rn;
5176 struct bgp *bgp;
5177 struct bgp_aggregate *aggregate;
5178
5179 /* Convert string to prefix structure. */
5180 ret = str2prefix (prefix_str, &p);
5181 if (!ret)
5182 {
5183 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5184 return CMD_WARNING;
5185 }
5186 apply_mask (&p);
5187
5188 /* Get BGP structure. */
5189 bgp = vty->index;
5190
5191 /* Old configuration check. */
5192 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5193 if (! rn)
5194 {
5195 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5196 VTY_NEWLINE);
5197 return CMD_WARNING;
5198 }
5199
5200 aggregate = rn->info;
5201 if (aggregate->safi & SAFI_UNICAST)
5202 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5203 if (aggregate->safi & SAFI_MULTICAST)
5204 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5205
5206 /* Unlock aggregate address configuration. */
5207 rn->info = NULL;
5208 bgp_aggregate_free (aggregate);
5209 bgp_unlock_node (rn);
5210 bgp_unlock_node (rn);
5211
5212 return CMD_SUCCESS;
5213}
5214
5215static int
5216bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00005217 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00005218 u_char summary_only, u_char as_set)
5219{
5220 int ret;
5221 struct prefix p;
5222 struct bgp_node *rn;
5223 struct bgp *bgp;
5224 struct bgp_aggregate *aggregate;
5225
5226 /* Convert string to prefix structure. */
5227 ret = str2prefix (prefix_str, &p);
5228 if (!ret)
5229 {
5230 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5231 return CMD_WARNING;
5232 }
5233 apply_mask (&p);
5234
5235 /* Get BGP structure. */
5236 bgp = vty->index;
5237
5238 /* Old configuration check. */
5239 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5240
5241 if (rn->info)
5242 {
5243 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005244 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005245 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5246 if (ret)
5247 {
Robert Bays368473f2010-08-05 10:26:29 -07005248 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5249 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005250 return CMD_WARNING;
5251 }
paul718e3742002-12-13 20:15:29 +00005252 }
5253
5254 /* Make aggregate address structure. */
5255 aggregate = bgp_aggregate_new ();
5256 aggregate->summary_only = summary_only;
5257 aggregate->as_set = as_set;
5258 aggregate->safi = safi;
5259 rn->info = aggregate;
5260
5261 /* Aggregate address insert into BGP routing table. */
5262 if (safi & SAFI_UNICAST)
5263 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5264 if (safi & SAFI_MULTICAST)
5265 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5266
5267 return CMD_SUCCESS;
5268}
5269
paul718e3742002-12-13 20:15:29 +00005270DEFUN (aggregate_address,
5271 aggregate_address_cmd,
5272 "aggregate-address A.B.C.D/M",
5273 "Configure BGP aggregate entries\n"
5274 "Aggregate prefix\n")
5275{
5276 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5277}
5278
5279DEFUN (aggregate_address_mask,
5280 aggregate_address_mask_cmd,
5281 "aggregate-address A.B.C.D A.B.C.D",
5282 "Configure BGP aggregate entries\n"
5283 "Aggregate address\n"
5284 "Aggregate mask\n")
5285{
5286 int ret;
5287 char prefix_str[BUFSIZ];
5288
5289 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5290
5291 if (! ret)
5292 {
5293 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5294 return CMD_WARNING;
5295 }
5296
5297 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5298 0, 0);
5299}
5300
5301DEFUN (aggregate_address_summary_only,
5302 aggregate_address_summary_only_cmd,
5303 "aggregate-address A.B.C.D/M summary-only",
5304 "Configure BGP aggregate entries\n"
5305 "Aggregate prefix\n"
5306 "Filter more specific routes from updates\n")
5307{
5308 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5309 AGGREGATE_SUMMARY_ONLY, 0);
5310}
5311
5312DEFUN (aggregate_address_mask_summary_only,
5313 aggregate_address_mask_summary_only_cmd,
5314 "aggregate-address A.B.C.D A.B.C.D summary-only",
5315 "Configure BGP aggregate entries\n"
5316 "Aggregate address\n"
5317 "Aggregate mask\n"
5318 "Filter more specific routes from updates\n")
5319{
5320 int ret;
5321 char prefix_str[BUFSIZ];
5322
5323 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5324
5325 if (! ret)
5326 {
5327 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5328 return CMD_WARNING;
5329 }
5330
5331 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5332 AGGREGATE_SUMMARY_ONLY, 0);
5333}
5334
5335DEFUN (aggregate_address_as_set,
5336 aggregate_address_as_set_cmd,
5337 "aggregate-address A.B.C.D/M as-set",
5338 "Configure BGP aggregate entries\n"
5339 "Aggregate prefix\n"
5340 "Generate AS set path information\n")
5341{
5342 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5343 0, AGGREGATE_AS_SET);
5344}
5345
5346DEFUN (aggregate_address_mask_as_set,
5347 aggregate_address_mask_as_set_cmd,
5348 "aggregate-address A.B.C.D A.B.C.D as-set",
5349 "Configure BGP aggregate entries\n"
5350 "Aggregate address\n"
5351 "Aggregate mask\n"
5352 "Generate AS set path information\n")
5353{
5354 int ret;
5355 char prefix_str[BUFSIZ];
5356
5357 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5358
5359 if (! ret)
5360 {
5361 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5362 return CMD_WARNING;
5363 }
5364
5365 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5366 0, AGGREGATE_AS_SET);
5367}
5368
5369
5370DEFUN (aggregate_address_as_set_summary,
5371 aggregate_address_as_set_summary_cmd,
5372 "aggregate-address A.B.C.D/M as-set summary-only",
5373 "Configure BGP aggregate entries\n"
5374 "Aggregate prefix\n"
5375 "Generate AS set path information\n"
5376 "Filter more specific routes from updates\n")
5377{
5378 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5379 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5380}
5381
5382ALIAS (aggregate_address_as_set_summary,
5383 aggregate_address_summary_as_set_cmd,
5384 "aggregate-address A.B.C.D/M summary-only as-set",
5385 "Configure BGP aggregate entries\n"
5386 "Aggregate prefix\n"
5387 "Filter more specific routes from updates\n"
5388 "Generate AS set path information\n")
5389
5390DEFUN (aggregate_address_mask_as_set_summary,
5391 aggregate_address_mask_as_set_summary_cmd,
5392 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5393 "Configure BGP aggregate entries\n"
5394 "Aggregate address\n"
5395 "Aggregate mask\n"
5396 "Generate AS set path information\n"
5397 "Filter more specific routes from updates\n")
5398{
5399 int ret;
5400 char prefix_str[BUFSIZ];
5401
5402 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5403
5404 if (! ret)
5405 {
5406 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5407 return CMD_WARNING;
5408 }
5409
5410 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5411 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5412}
5413
5414ALIAS (aggregate_address_mask_as_set_summary,
5415 aggregate_address_mask_summary_as_set_cmd,
5416 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5417 "Configure BGP aggregate entries\n"
5418 "Aggregate address\n"
5419 "Aggregate mask\n"
5420 "Filter more specific routes from updates\n"
5421 "Generate AS set path information\n")
5422
5423DEFUN (no_aggregate_address,
5424 no_aggregate_address_cmd,
5425 "no aggregate-address A.B.C.D/M",
5426 NO_STR
5427 "Configure BGP aggregate entries\n"
5428 "Aggregate prefix\n")
5429{
5430 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5431}
5432
5433ALIAS (no_aggregate_address,
5434 no_aggregate_address_summary_only_cmd,
5435 "no aggregate-address A.B.C.D/M summary-only",
5436 NO_STR
5437 "Configure BGP aggregate entries\n"
5438 "Aggregate prefix\n"
5439 "Filter more specific routes from updates\n")
5440
5441ALIAS (no_aggregate_address,
5442 no_aggregate_address_as_set_cmd,
5443 "no aggregate-address A.B.C.D/M as-set",
5444 NO_STR
5445 "Configure BGP aggregate entries\n"
5446 "Aggregate prefix\n"
5447 "Generate AS set path information\n")
5448
5449ALIAS (no_aggregate_address,
5450 no_aggregate_address_as_set_summary_cmd,
5451 "no aggregate-address A.B.C.D/M as-set summary-only",
5452 NO_STR
5453 "Configure BGP aggregate entries\n"
5454 "Aggregate prefix\n"
5455 "Generate AS set path information\n"
5456 "Filter more specific routes from updates\n")
5457
5458ALIAS (no_aggregate_address,
5459 no_aggregate_address_summary_as_set_cmd,
5460 "no aggregate-address A.B.C.D/M summary-only as-set",
5461 NO_STR
5462 "Configure BGP aggregate entries\n"
5463 "Aggregate prefix\n"
5464 "Filter more specific routes from updates\n"
5465 "Generate AS set path information\n")
5466
5467DEFUN (no_aggregate_address_mask,
5468 no_aggregate_address_mask_cmd,
5469 "no aggregate-address A.B.C.D A.B.C.D",
5470 NO_STR
5471 "Configure BGP aggregate entries\n"
5472 "Aggregate address\n"
5473 "Aggregate mask\n")
5474{
5475 int ret;
5476 char prefix_str[BUFSIZ];
5477
5478 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5479
5480 if (! ret)
5481 {
5482 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5483 return CMD_WARNING;
5484 }
5485
5486 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5487}
5488
5489ALIAS (no_aggregate_address_mask,
5490 no_aggregate_address_mask_summary_only_cmd,
5491 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5492 NO_STR
5493 "Configure BGP aggregate entries\n"
5494 "Aggregate address\n"
5495 "Aggregate mask\n"
5496 "Filter more specific routes from updates\n")
5497
5498ALIAS (no_aggregate_address_mask,
5499 no_aggregate_address_mask_as_set_cmd,
5500 "no aggregate-address A.B.C.D A.B.C.D as-set",
5501 NO_STR
5502 "Configure BGP aggregate entries\n"
5503 "Aggregate address\n"
5504 "Aggregate mask\n"
5505 "Generate AS set path information\n")
5506
5507ALIAS (no_aggregate_address_mask,
5508 no_aggregate_address_mask_as_set_summary_cmd,
5509 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5510 NO_STR
5511 "Configure BGP aggregate entries\n"
5512 "Aggregate address\n"
5513 "Aggregate mask\n"
5514 "Generate AS set path information\n"
5515 "Filter more specific routes from updates\n")
5516
5517ALIAS (no_aggregate_address_mask,
5518 no_aggregate_address_mask_summary_as_set_cmd,
5519 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5520 NO_STR
5521 "Configure BGP aggregate entries\n"
5522 "Aggregate address\n"
5523 "Aggregate mask\n"
5524 "Filter more specific routes from updates\n"
5525 "Generate AS set path information\n")
5526
paul718e3742002-12-13 20:15:29 +00005527DEFUN (ipv6_aggregate_address,
5528 ipv6_aggregate_address_cmd,
5529 "aggregate-address X:X::X:X/M",
5530 "Configure BGP aggregate entries\n"
5531 "Aggregate prefix\n")
5532{
5533 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5534}
5535
5536DEFUN (ipv6_aggregate_address_summary_only,
5537 ipv6_aggregate_address_summary_only_cmd,
5538 "aggregate-address X:X::X:X/M summary-only",
5539 "Configure BGP aggregate entries\n"
5540 "Aggregate prefix\n"
5541 "Filter more specific routes from updates\n")
5542{
5543 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5544 AGGREGATE_SUMMARY_ONLY, 0);
5545}
5546
5547DEFUN (no_ipv6_aggregate_address,
5548 no_ipv6_aggregate_address_cmd,
5549 "no aggregate-address X:X::X:X/M",
5550 NO_STR
5551 "Configure BGP aggregate entries\n"
5552 "Aggregate prefix\n")
5553{
5554 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5555}
5556
5557DEFUN (no_ipv6_aggregate_address_summary_only,
5558 no_ipv6_aggregate_address_summary_only_cmd,
5559 "no aggregate-address X:X::X:X/M summary-only",
5560 NO_STR
5561 "Configure BGP aggregate entries\n"
5562 "Aggregate prefix\n"
5563 "Filter more specific routes from updates\n")
5564{
5565 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5566}
5567
5568ALIAS (ipv6_aggregate_address,
5569 old_ipv6_aggregate_address_cmd,
5570 "ipv6 bgp aggregate-address X:X::X:X/M",
5571 IPV6_STR
5572 BGP_STR
5573 "Configure BGP aggregate entries\n"
5574 "Aggregate prefix\n")
5575
5576ALIAS (ipv6_aggregate_address_summary_only,
5577 old_ipv6_aggregate_address_summary_only_cmd,
5578 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5579 IPV6_STR
5580 BGP_STR
5581 "Configure BGP aggregate entries\n"
5582 "Aggregate prefix\n"
5583 "Filter more specific routes from updates\n")
5584
5585ALIAS (no_ipv6_aggregate_address,
5586 old_no_ipv6_aggregate_address_cmd,
5587 "no ipv6 bgp aggregate-address X:X::X:X/M",
5588 NO_STR
5589 IPV6_STR
5590 BGP_STR
5591 "Configure BGP aggregate entries\n"
5592 "Aggregate prefix\n")
5593
5594ALIAS (no_ipv6_aggregate_address_summary_only,
5595 old_no_ipv6_aggregate_address_summary_only_cmd,
5596 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5597 NO_STR
5598 IPV6_STR
5599 BGP_STR
5600 "Configure BGP aggregate entries\n"
5601 "Aggregate prefix\n"
5602 "Filter more specific routes from updates\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02005603
paul718e3742002-12-13 20:15:29 +00005604/* Redistribute route treatment. */
5605void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005606bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5607 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005608 u_int32_t metric, u_char type)
5609{
5610 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005611 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005612 struct bgp_info *new;
5613 struct bgp_info *bi;
5614 struct bgp_info info;
5615 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005616 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005617 struct attr *new_attr;
5618 afi_t afi;
5619 int ret;
5620
5621 /* Make default attribute. */
5622 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5623 if (nexthop)
5624 attr.nexthop = *nexthop;
5625
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005626 if (nexthop6)
5627 {
5628 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5629 extra->mp_nexthop_global = *nexthop6;
5630 extra->mp_nexthop_len = 16;
5631 }
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005632
paul718e3742002-12-13 20:15:29 +00005633 attr.med = metric;
5634 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5635
paul1eb8ef22005-04-07 07:30:20 +00005636 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005637 {
5638 afi = family2afi (p->family);
5639
5640 if (bgp->redist[afi][type])
5641 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005642 struct attr attr_new;
5643 struct attr_extra extra_new;
5644
paul718e3742002-12-13 20:15:29 +00005645 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005646 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005647 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005648
5649 if (bgp->redist_metric_flag[afi][type])
5650 attr_new.med = bgp->redist_metric[afi][type];
5651
5652 /* Apply route-map. */
Daniel Walton1994dc82015-09-17 10:15:59 -04005653 if (bgp->rmap[afi][type].name)
paul718e3742002-12-13 20:15:29 +00005654 {
5655 info.peer = bgp->peer_self;
5656 info.attr = &attr_new;
5657
paulfee0f4c2004-09-13 05:12:46 +00005658 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5659
paul718e3742002-12-13 20:15:29 +00005660 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5661 &info);
paulfee0f4c2004-09-13 05:12:46 +00005662
5663 bgp->peer_self->rmap_type = 0;
5664
paul718e3742002-12-13 20:15:29 +00005665 if (ret == RMAP_DENYMATCH)
5666 {
5667 /* Free uninterned attribute. */
5668 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005669
paul718e3742002-12-13 20:15:29 +00005670 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005671 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005672 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005673 bgp_redistribute_delete (p, type);
5674 return;
5675 }
5676 }
5677
Paul Jakmafb982c22007-05-04 20:15:47 +00005678 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5679 afi, SAFI_UNICAST, p, NULL);
5680
paul718e3742002-12-13 20:15:29 +00005681 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005682
paul718e3742002-12-13 20:15:29 +00005683 for (bi = bn->info; bi; bi = bi->next)
5684 if (bi->peer == bgp->peer_self
5685 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5686 break;
5687
5688 if (bi)
5689 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005690 if (attrhash_cmp (bi->attr, new_attr) &&
5691 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005692 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005693 bgp_attr_unintern (&new_attr);
5694 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005695 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005696 bgp_unlock_node (bn);
5697 return;
5698 }
5699 else
5700 {
5701 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005702 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005703
5704 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005705 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5706 bgp_info_restore(bn, bi);
5707 else
5708 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005709 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005710 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005711 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005712
5713 /* Process change. */
5714 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5715 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5716 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005717 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005718 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005719 return;
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05005720 }
paul718e3742002-12-13 20:15:29 +00005721 }
5722
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05005723 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, bgp->peer_self,
5724 new_attr, bn);
paul718e3742002-12-13 20:15:29 +00005725 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00005726
5727 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5728 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005729 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005730 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5731 }
5732 }
5733
5734 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005735 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005736 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005737}
5738
5739void
5740bgp_redistribute_delete (struct prefix *p, u_char type)
5741{
5742 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005743 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005744 afi_t afi;
5745 struct bgp_node *rn;
5746 struct bgp_info *ri;
5747
paul1eb8ef22005-04-07 07:30:20 +00005748 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005749 {
5750 afi = family2afi (p->family);
5751
5752 if (bgp->redist[afi][type])
5753 {
paulfee0f4c2004-09-13 05:12:46 +00005754 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005755
5756 for (ri = rn->info; ri; ri = ri->next)
5757 if (ri->peer == bgp->peer_self
5758 && ri->type == type)
5759 break;
5760
5761 if (ri)
5762 {
5763 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005764 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005765 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005766 }
5767 bgp_unlock_node (rn);
5768 }
5769 }
5770}
5771
5772/* Withdraw specified route type's route. */
5773void
5774bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5775{
5776 struct bgp_node *rn;
5777 struct bgp_info *ri;
5778 struct bgp_table *table;
5779
5780 table = bgp->rib[afi][SAFI_UNICAST];
5781
5782 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5783 {
5784 for (ri = rn->info; ri; ri = ri->next)
5785 if (ri->peer == bgp->peer_self
5786 && ri->type == type)
5787 break;
5788
5789 if (ri)
5790 {
5791 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005792 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005793 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005794 }
5795 }
5796}
David Lamparter6b0655a2014-06-04 06:53:35 +02005797
paul718e3742002-12-13 20:15:29 +00005798/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005799static void
paul718e3742002-12-13 20:15:29 +00005800route_vty_out_route (struct prefix *p, struct vty *vty)
5801{
5802 int len;
5803 u_int32_t destination;
5804 char buf[BUFSIZ];
5805
5806 if (p->family == AF_INET)
5807 {
5808 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5809 destination = ntohl (p->u.prefix4.s_addr);
5810
5811 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5812 || (IN_CLASSB (destination) && p->prefixlen == 16)
5813 || (IN_CLASSA (destination) && p->prefixlen == 8)
5814 || p->u.prefix4.s_addr == 0)
5815 {
5816 /* When mask is natural, mask is not displayed. */
5817 }
5818 else
5819 len += vty_out (vty, "/%d", p->prefixlen);
5820 }
5821 else
5822 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5823 p->prefixlen);
5824
5825 len = 17 - len;
5826 if (len < 1)
5827 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5828 else
5829 vty_out (vty, "%*s", len, " ");
5830}
5831
paul718e3742002-12-13 20:15:29 +00005832enum bgp_display_type
5833{
5834 normal_list,
5835};
5836
paulb40d9392005-08-22 22:34:41 +00005837/* Print the short form route status for a bgp_info */
5838static void
5839route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005840{
paulb40d9392005-08-22 22:34:41 +00005841 /* Route status display. */
5842 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5843 vty_out (vty, "R");
5844 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005845 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005846 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005847 vty_out (vty, "s");
5848 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5849 vty_out (vty, "*");
5850 else
5851 vty_out (vty, " ");
5852
5853 /* Selected */
5854 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5855 vty_out (vty, "h");
5856 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5857 vty_out (vty, "d");
5858 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5859 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005860 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5861 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005862 else
5863 vty_out (vty, " ");
5864
5865 /* Internal route. */
5866 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5867 vty_out (vty, "i");
5868 else
paulb40d9392005-08-22 22:34:41 +00005869 vty_out (vty, " ");
5870}
5871
5872/* called from terminal list command */
5873void
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005874route_vty_out(
5875 struct vty *vty,
5876 struct prefix *p,
5877 struct bgp_info *binfo,
5878 int display,
5879 safi_t safi)
paulb40d9392005-08-22 22:34:41 +00005880{
5881 struct attr *attr;
5882
5883 /* short status lead text */
5884 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005885
5886 /* print prefix and mask */
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005887 if (!display)
paul718e3742002-12-13 20:15:29 +00005888 route_vty_out_route (p, vty);
5889 else
5890 vty_out (vty, "%*s", 17, " ");
5891
5892 /* Print attribute */
5893 attr = binfo->attr;
5894 if (attr)
5895 {
paul718e3742002-12-13 20:15:29 +00005896
Lou Berger298cc2f2016-01-12 13:42:02 -05005897 /*
5898 * NEXTHOP start
5899 */
5900
5901 /*
5902 * For ENCAP routes, nexthop address family is not
5903 * neccessarily the same as the prefix address family.
5904 * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
5905 */
5906 if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN)) {
5907 if (attr->extra) {
5908 char buf[BUFSIZ];
5909 int af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len);
5910
5911 switch (af) {
5912 case AF_INET:
5913 vty_out (vty, "%s", inet_ntop(af,
5914 &attr->extra->mp_nexthop_global_in, buf, BUFSIZ));
5915 break;
Lou Berger298cc2f2016-01-12 13:42:02 -05005916 case AF_INET6:
5917 vty_out (vty, "%s", inet_ntop(af,
5918 &attr->extra->mp_nexthop_global, buf, BUFSIZ));
5919 break;
Lou Berger298cc2f2016-01-12 13:42:02 -05005920 default:
5921 vty_out(vty, "?");
5922 }
5923 } else {
5924 vty_out(vty, "?");
paul718e3742002-12-13 20:15:29 +00005925 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005926 } else {
5927
5928 if (p->family == AF_INET)
5929 {
5930 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5931 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005932 else if (p->family == AF_INET6)
5933 {
5934 int len;
5935 char buf[BUFSIZ];
5936
5937 len = vty_out (vty, "%s",
5938 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5939 buf, BUFSIZ));
5940 len = 16 - len;
5941 if (len < 1)
5942 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5943 else
5944 vty_out (vty, "%*s", len, " ");
5945 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005946 else
5947 {
5948 vty_out(vty, "?");
5949 }
5950 }
5951
5952 /*
5953 * NEXTHOP end
5954 */
5955
paul718e3742002-12-13 20:15:29 +00005956
5957 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005958 vty_out (vty, "%10u ", attr->med);
paul718e3742002-12-13 20:15:29 +00005959 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005960 vty_out (vty, " ");
paul718e3742002-12-13 20:15:29 +00005961
5962 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005963 vty_out (vty, "%7u ", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005964 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005965 vty_out (vty, " ");
paul718e3742002-12-13 20:15:29 +00005966
Paul Jakmafb982c22007-05-04 20:15:47 +00005967 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005968
Paul Jakmab2518c12006-05-12 23:48:40 +00005969 /* Print aspath */
5970 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005971 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005972
Paul Jakmab2518c12006-05-12 23:48:40 +00005973 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005974 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005975 }
paul718e3742002-12-13 20:15:29 +00005976 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005977}
5978
5979/* called from terminal list command */
5980void
5981route_vty_out_tmp (struct vty *vty, struct prefix *p,
5982 struct attr *attr, safi_t safi)
5983{
5984 /* Route status display. */
5985 vty_out (vty, "*");
5986 vty_out (vty, ">");
5987 vty_out (vty, " ");
5988
5989 /* print prefix and mask */
5990 route_vty_out_route (p, vty);
5991
5992 /* Print attribute */
5993 if (attr)
5994 {
5995 if (p->family == AF_INET)
5996 {
Lou Berger298cc2f2016-01-12 13:42:02 -05005997 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00005998 vty_out (vty, "%-16s",
5999 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00006000 else
6001 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6002 }
paul718e3742002-12-13 20:15:29 +00006003 else if (p->family == AF_INET6)
6004 {
6005 int len;
6006 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006007
6008 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006009
6010 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006011 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6012 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006013 len = 16 - len;
6014 if (len < 1)
6015 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6016 else
6017 vty_out (vty, "%*s", len, " ");
6018 }
paul718e3742002-12-13 20:15:29 +00006019
6020 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006021 vty_out (vty, "%10u ", attr->med);
paul718e3742002-12-13 20:15:29 +00006022 else
6023 vty_out (vty, " ");
6024
6025 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006026 vty_out (vty, "%7u ", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006027 else
6028 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006029
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006030 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00006031
Paul Jakmab2518c12006-05-12 23:48:40 +00006032 /* Print aspath */
6033 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006034 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006035
Paul Jakmab2518c12006-05-12 23:48:40 +00006036 /* Print origin */
paul718e3742002-12-13 20:15:29 +00006037 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00006038 }
paul718e3742002-12-13 20:15:29 +00006039
6040 vty_out (vty, "%s", VTY_NEWLINE);
6041}
6042
ajs5a646652004-11-05 01:25:55 +00006043void
paul718e3742002-12-13 20:15:29 +00006044route_vty_out_tag (struct vty *vty, struct prefix *p,
6045 struct bgp_info *binfo, int display, safi_t safi)
6046{
6047 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006048 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00006049
6050 if (!binfo->extra)
6051 return;
6052
paulb40d9392005-08-22 22:34:41 +00006053 /* short status lead text */
6054 route_vty_short_status_out (vty, binfo);
6055
paul718e3742002-12-13 20:15:29 +00006056 /* print prefix and mask */
6057 if (! display)
6058 route_vty_out_route (p, vty);
6059 else
6060 vty_out (vty, "%*s", 17, " ");
6061
6062 /* Print attribute */
6063 attr = binfo->attr;
6064 if (attr)
6065 {
6066 if (p->family == AF_INET)
6067 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006068 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00006069 vty_out (vty, "%-16s",
6070 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00006071 else
6072 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6073 }
paul718e3742002-12-13 20:15:29 +00006074 else if (p->family == AF_INET6)
6075 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006076 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006077 char buf[BUFSIZ];
6078 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006079 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00006080 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006081 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6082 buf, BUFSIZ));
6083 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006084 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006085 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6086 buf, BUFSIZ),
6087 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6088 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006089
6090 }
paul718e3742002-12-13 20:15:29 +00006091 }
6092
Paul Jakmafb982c22007-05-04 20:15:47 +00006093 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00006094
6095 vty_out (vty, "notag/%d", label);
6096
6097 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006098}
6099
6100/* dampening route */
ajs5a646652004-11-05 01:25:55 +00006101static void
paul718e3742002-12-13 20:15:29 +00006102damp_route_vty_out (struct vty *vty, struct prefix *p,
6103 struct bgp_info *binfo, int display, safi_t safi)
6104{
6105 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006106 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00006107 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00006108
paulb40d9392005-08-22 22:34:41 +00006109 /* short status lead text */
6110 route_vty_short_status_out (vty, binfo);
6111
paul718e3742002-12-13 20:15:29 +00006112 /* print prefix and mask */
6113 if (! display)
6114 route_vty_out_route (p, vty);
6115 else
6116 vty_out (vty, "%*s", 17, " ");
6117
6118 len = vty_out (vty, "%s", binfo->peer->host);
6119 len = 17 - len;
6120 if (len < 1)
6121 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6122 else
6123 vty_out (vty, "%*s", len, " ");
6124
Chris Caputo50aef6f2009-06-23 06:06:49 +00006125 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006126
6127 /* Print attribute */
6128 attr = binfo->attr;
6129 if (attr)
6130 {
6131 /* Print aspath */
6132 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006133 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006134
6135 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006136 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006137 }
6138 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006139}
6140
paul718e3742002-12-13 20:15:29 +00006141/* flap route */
ajs5a646652004-11-05 01:25:55 +00006142static void
paul718e3742002-12-13 20:15:29 +00006143flap_route_vty_out (struct vty *vty, struct prefix *p,
6144 struct bgp_info *binfo, int display, safi_t safi)
6145{
6146 struct attr *attr;
6147 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00006148 char timebuf[BGP_UPTIME_LEN];
6149 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00006150
6151 if (!binfo->extra)
6152 return;
6153
6154 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00006155
paulb40d9392005-08-22 22:34:41 +00006156 /* short status lead text */
6157 route_vty_short_status_out (vty, binfo);
6158
paul718e3742002-12-13 20:15:29 +00006159 /* print prefix and mask */
6160 if (! display)
6161 route_vty_out_route (p, vty);
6162 else
6163 vty_out (vty, "%*s", 17, " ");
6164
6165 len = vty_out (vty, "%s", binfo->peer->host);
6166 len = 16 - len;
6167 if (len < 1)
6168 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6169 else
6170 vty_out (vty, "%*s", len, " ");
6171
6172 len = vty_out (vty, "%d", bdi->flap);
6173 len = 5 - len;
6174 if (len < 1)
6175 vty_out (vty, " ");
6176 else
6177 vty_out (vty, "%*s ", len, " ");
6178
6179 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6180 timebuf, BGP_UPTIME_LEN));
6181
6182 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6183 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00006184 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006185 else
6186 vty_out (vty, "%*s ", 8, " ");
6187
6188 /* Print attribute */
6189 attr = binfo->attr;
6190 if (attr)
6191 {
6192 /* Print aspath */
6193 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006194 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006195
6196 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006197 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006198 }
6199 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006200}
6201
paul94f2b392005-06-28 12:44:16 +00006202static void
paul718e3742002-12-13 20:15:29 +00006203route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6204 struct bgp_info *binfo, afi_t afi, safi_t safi)
6205{
6206 char buf[INET6_ADDRSTRLEN];
6207 char buf1[BUFSIZ];
6208 struct attr *attr;
6209 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03006210#ifdef HAVE_CLOCK_MONOTONIC
6211 time_t tbuf;
6212#endif
paul718e3742002-12-13 20:15:29 +00006213
6214 attr = binfo->attr;
6215
6216 if (attr)
6217 {
6218 /* Line1 display AS-path, Aggregator */
6219 if (attr->aspath)
6220 {
6221 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00006222 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00006223 vty_out (vty, "Local");
6224 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006225 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00006226 }
6227
paulb40d9392005-08-22 22:34:41 +00006228 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6229 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00006230 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6231 vty_out (vty, ", (stale)");
6232 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006233 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006234 attr->extra->aggregator_as,
6235 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006236 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6237 vty_out (vty, ", (Received from a RR-client)");
6238 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6239 vty_out (vty, ", (Received from a RS-client)");
6240 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6241 vty_out (vty, ", (history entry)");
6242 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6243 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006244 vty_out (vty, "%s", VTY_NEWLINE);
6245
6246 /* Line2 display Next-hop, Neighbor, Router-id */
6247 if (p->family == AF_INET)
6248 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006249 vty_out (vty, " %s", ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)) ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006250 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006251 inet_ntoa (attr->nexthop));
6252 }
paul718e3742002-12-13 20:15:29 +00006253 else
6254 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006255 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006256 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006257 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006258 buf, INET6_ADDRSTRLEN));
6259 }
paul718e3742002-12-13 20:15:29 +00006260
6261 if (binfo->peer == bgp->peer_self)
6262 {
6263 vty_out (vty, " from %s ",
6264 p->family == AF_INET ? "0.0.0.0" : "::");
6265 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6266 }
6267 else
6268 {
6269 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6270 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006271 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006272 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006273 if (!sockunion2str (&binfo->peer->su, buf, sizeof(buf))) {
6274 buf[0] = '?';
6275 buf[1] = 0;
6276 }
6277 vty_out (vty, " from %s", buf);
paul718e3742002-12-13 20:15:29 +00006278 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006279 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006280 else
6281 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6282 }
6283 vty_out (vty, "%s", VTY_NEWLINE);
6284
paul718e3742002-12-13 20:15:29 +00006285 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006286 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006287 {
6288 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006289 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006290 buf, INET6_ADDRSTRLEN),
6291 VTY_NEWLINE);
6292 }
paul718e3742002-12-13 20:15:29 +00006293
6294 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6295 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6296
6297 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006298 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006299
6300 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006301 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006302 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006303 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006304
Paul Jakmafb982c22007-05-04 20:15:47 +00006305 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006306 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006307
6308 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6309 vty_out (vty, ", valid");
6310
6311 if (binfo->peer != bgp->peer_self)
6312 {
6313 if (binfo->peer->as == binfo->peer->local_as)
6314 vty_out (vty, ", internal");
6315 else
6316 vty_out (vty, ", %s",
6317 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6318 }
6319 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6320 vty_out (vty, ", aggregated, local");
6321 else if (binfo->type != ZEBRA_ROUTE_BGP)
6322 vty_out (vty, ", sourced");
6323 else
6324 vty_out (vty, ", sourced, local");
6325
6326 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6327 vty_out (vty, ", atomic-aggregate");
6328
Josh Baileyde8d5df2011-07-20 20:46:01 -07006329 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6330 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6331 bgp_info_mpath_count (binfo)))
6332 vty_out (vty, ", multipath");
6333
paul718e3742002-12-13 20:15:29 +00006334 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6335 vty_out (vty, ", best");
6336
6337 vty_out (vty, "%s", VTY_NEWLINE);
6338
6339 /* Line 4 display Community */
6340 if (attr->community)
6341 vty_out (vty, " Community: %s%s", attr->community->str,
6342 VTY_NEWLINE);
6343
6344 /* Line 5 display Extended-community */
6345 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006346 vty_out (vty, " Extended Community: %s%s",
6347 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006348
6349 /* Line 6 display Originator, Cluster-id */
6350 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6351 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6352 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006353 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006354 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006355 vty_out (vty, " Originator: %s",
6356 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006357
6358 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6359 {
6360 int i;
6361 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006362 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6363 vty_out (vty, "%s ",
6364 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006365 }
6366 vty_out (vty, "%s", VTY_NEWLINE);
6367 }
Paul Jakma41367172007-08-06 15:24:51 +00006368
Paul Jakmafb982c22007-05-04 20:15:47 +00006369 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006370 bgp_damp_info_vty (vty, binfo);
6371
6372 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006373#ifdef HAVE_CLOCK_MONOTONIC
6374 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006375 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006376#else
6377 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6378#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006379 }
6380 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006381}
6382
6383#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6384 "h history, * valid, > best, = multipath,%s"\
6385 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006386#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006387#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6388#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6389#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6390
6391enum bgp_show_type
6392{
6393 bgp_show_type_normal,
6394 bgp_show_type_regexp,
6395 bgp_show_type_prefix_list,
6396 bgp_show_type_filter_list,
6397 bgp_show_type_route_map,
6398 bgp_show_type_neighbor,
6399 bgp_show_type_cidr_only,
6400 bgp_show_type_prefix_longer,
6401 bgp_show_type_community_all,
6402 bgp_show_type_community,
6403 bgp_show_type_community_exact,
6404 bgp_show_type_community_list,
6405 bgp_show_type_community_list_exact,
6406 bgp_show_type_flap_statistics,
6407 bgp_show_type_flap_address,
6408 bgp_show_type_flap_prefix,
6409 bgp_show_type_flap_cidr_only,
6410 bgp_show_type_flap_regexp,
6411 bgp_show_type_flap_filter_list,
6412 bgp_show_type_flap_prefix_list,
6413 bgp_show_type_flap_prefix_longer,
6414 bgp_show_type_flap_route_map,
6415 bgp_show_type_flap_neighbor,
6416 bgp_show_type_dampend_paths,
6417 bgp_show_type_damp_neighbor
6418};
6419
ajs5a646652004-11-05 01:25:55 +00006420static int
paulfee0f4c2004-09-13 05:12:46 +00006421bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006422 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006423{
paul718e3742002-12-13 20:15:29 +00006424 struct bgp_info *ri;
6425 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006426 int header = 1;
paul718e3742002-12-13 20:15:29 +00006427 int display;
ajs5a646652004-11-05 01:25:55 +00006428 unsigned long output_count;
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006429 unsigned long total_count;
paul718e3742002-12-13 20:15:29 +00006430
6431 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006432 output_count = 0;
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006433 total_count = 0;
paul718e3742002-12-13 20:15:29 +00006434
paul718e3742002-12-13 20:15:29 +00006435 /* Start processing of routes. */
6436 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6437 if (rn->info != NULL)
6438 {
6439 display = 0;
6440
6441 for (ri = rn->info; ri; ri = ri->next)
6442 {
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006443 total_count++;
ajs5a646652004-11-05 01:25:55 +00006444 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006445 || type == bgp_show_type_flap_address
6446 || type == bgp_show_type_flap_prefix
6447 || type == bgp_show_type_flap_cidr_only
6448 || type == bgp_show_type_flap_regexp
6449 || type == bgp_show_type_flap_filter_list
6450 || type == bgp_show_type_flap_prefix_list
6451 || type == bgp_show_type_flap_prefix_longer
6452 || type == bgp_show_type_flap_route_map
6453 || type == bgp_show_type_flap_neighbor
6454 || type == bgp_show_type_dampend_paths
6455 || type == bgp_show_type_damp_neighbor)
6456 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006457 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006458 continue;
6459 }
6460 if (type == bgp_show_type_regexp
6461 || type == bgp_show_type_flap_regexp)
6462 {
ajs5a646652004-11-05 01:25:55 +00006463 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006464
6465 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6466 continue;
6467 }
6468 if (type == bgp_show_type_prefix_list
6469 || type == bgp_show_type_flap_prefix_list)
6470 {
ajs5a646652004-11-05 01:25:55 +00006471 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006472
6473 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6474 continue;
6475 }
6476 if (type == bgp_show_type_filter_list
6477 || type == bgp_show_type_flap_filter_list)
6478 {
ajs5a646652004-11-05 01:25:55 +00006479 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006480
6481 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6482 continue;
6483 }
6484 if (type == bgp_show_type_route_map
6485 || type == bgp_show_type_flap_route_map)
6486 {
ajs5a646652004-11-05 01:25:55 +00006487 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006488 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006489 struct attr dummy_attr;
6490 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006491 int ret;
6492
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006493 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006494 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006495
paul718e3742002-12-13 20:15:29 +00006496 binfo.peer = ri->peer;
6497 binfo.attr = &dummy_attr;
6498
6499 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006500 if (ret == RMAP_DENYMATCH)
6501 continue;
6502 }
6503 if (type == bgp_show_type_neighbor
6504 || type == bgp_show_type_flap_neighbor
6505 || type == bgp_show_type_damp_neighbor)
6506 {
ajs5a646652004-11-05 01:25:55 +00006507 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006508
6509 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6510 continue;
6511 }
6512 if (type == bgp_show_type_cidr_only
6513 || type == bgp_show_type_flap_cidr_only)
6514 {
6515 u_int32_t destination;
6516
6517 destination = ntohl (rn->p.u.prefix4.s_addr);
6518 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6519 continue;
6520 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6521 continue;
6522 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6523 continue;
6524 }
6525 if (type == bgp_show_type_prefix_longer
6526 || type == bgp_show_type_flap_prefix_longer)
6527 {
ajs5a646652004-11-05 01:25:55 +00006528 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006529
6530 if (! prefix_match (p, &rn->p))
6531 continue;
6532 }
6533 if (type == bgp_show_type_community_all)
6534 {
6535 if (! ri->attr->community)
6536 continue;
6537 }
6538 if (type == bgp_show_type_community)
6539 {
ajs5a646652004-11-05 01:25:55 +00006540 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006541
6542 if (! ri->attr->community ||
6543 ! community_match (ri->attr->community, com))
6544 continue;
6545 }
6546 if (type == bgp_show_type_community_exact)
6547 {
ajs5a646652004-11-05 01:25:55 +00006548 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006549
6550 if (! ri->attr->community ||
6551 ! community_cmp (ri->attr->community, com))
6552 continue;
6553 }
6554 if (type == bgp_show_type_community_list)
6555 {
ajs5a646652004-11-05 01:25:55 +00006556 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006557
6558 if (! community_list_match (ri->attr->community, list))
6559 continue;
6560 }
6561 if (type == bgp_show_type_community_list_exact)
6562 {
ajs5a646652004-11-05 01:25:55 +00006563 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006564
6565 if (! community_list_exact_match (ri->attr->community, list))
6566 continue;
6567 }
6568 if (type == bgp_show_type_flap_address
6569 || type == bgp_show_type_flap_prefix)
6570 {
ajs5a646652004-11-05 01:25:55 +00006571 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006572
6573 if (! prefix_match (&rn->p, p))
6574 continue;
6575
6576 if (type == bgp_show_type_flap_prefix)
6577 if (p->prefixlen != rn->p.prefixlen)
6578 continue;
6579 }
6580 if (type == bgp_show_type_dampend_paths
6581 || type == bgp_show_type_damp_neighbor)
6582 {
6583 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6584 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6585 continue;
6586 }
6587
6588 if (header)
6589 {
hasso93406d82005-02-02 14:40:33 +00006590 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6591 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6592 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006593 if (type == bgp_show_type_dampend_paths
6594 || type == bgp_show_type_damp_neighbor)
6595 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6596 else if (type == bgp_show_type_flap_statistics
6597 || type == bgp_show_type_flap_address
6598 || type == bgp_show_type_flap_prefix
6599 || type == bgp_show_type_flap_cidr_only
6600 || type == bgp_show_type_flap_regexp
6601 || type == bgp_show_type_flap_filter_list
6602 || type == bgp_show_type_flap_prefix_list
6603 || type == bgp_show_type_flap_prefix_longer
6604 || type == bgp_show_type_flap_route_map
6605 || type == bgp_show_type_flap_neighbor)
6606 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6607 else
6608 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006609 header = 0;
6610 }
6611
6612 if (type == bgp_show_type_dampend_paths
6613 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006614 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006615 else if (type == bgp_show_type_flap_statistics
6616 || type == bgp_show_type_flap_address
6617 || type == bgp_show_type_flap_prefix
6618 || type == bgp_show_type_flap_cidr_only
6619 || type == bgp_show_type_flap_regexp
6620 || type == bgp_show_type_flap_filter_list
6621 || type == bgp_show_type_flap_prefix_list
6622 || type == bgp_show_type_flap_prefix_longer
6623 || type == bgp_show_type_flap_route_map
6624 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006625 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006626 else
ajs5a646652004-11-05 01:25:55 +00006627 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006628 display++;
6629 }
6630 if (display)
ajs5a646652004-11-05 01:25:55 +00006631 output_count++;
paul718e3742002-12-13 20:15:29 +00006632 }
6633
6634 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006635 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006636 {
6637 if (type == bgp_show_type_normal)
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006638 vty_out (vty, "No BGP prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006639 }
6640 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006641 vty_out (vty, "%sDisplayed %ld out of %ld total prefixes%s",
6642 VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006643
6644 return CMD_SUCCESS;
6645}
6646
ajs5a646652004-11-05 01:25:55 +00006647static int
paulfee0f4c2004-09-13 05:12:46 +00006648bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006649 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006650{
6651 struct bgp_table *table;
6652
6653 if (bgp == NULL) {
6654 bgp = bgp_get_default ();
6655 }
6656
6657 if (bgp == NULL)
6658 {
6659 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6660 return CMD_WARNING;
6661 }
6662
6663
6664 table = bgp->rib[afi][safi];
6665
ajs5a646652004-11-05 01:25:55 +00006666 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006667}
6668
paul718e3742002-12-13 20:15:29 +00006669/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006670static void
paul718e3742002-12-13 20:15:29 +00006671route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6672 struct bgp_node *rn,
6673 struct prefix_rd *prd, afi_t afi, safi_t safi)
6674{
6675 struct bgp_info *ri;
6676 struct prefix *p;
6677 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006678 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006679 char buf1[INET6_ADDRSTRLEN];
6680 char buf2[INET6_ADDRSTRLEN];
6681 int count = 0;
6682 int best = 0;
6683 int suppress = 0;
6684 int no_export = 0;
6685 int no_advertise = 0;
6686 int local_as = 0;
6687 int first = 0;
Lou Berger298cc2f2016-01-12 13:42:02 -05006688 int printrd = ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP));
paul718e3742002-12-13 20:15:29 +00006689
6690 p = &rn->p;
6691 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
Lou Berger298cc2f2016-01-12 13:42:02 -05006692 (printrd ? prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6693 printrd ? ":" : "",
paul718e3742002-12-13 20:15:29 +00006694 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6695 p->prefixlen, VTY_NEWLINE);
6696
6697 for (ri = rn->info; ri; ri = ri->next)
6698 {
6699 count++;
6700 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6701 {
6702 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006703 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006704 suppress = 1;
6705 if (ri->attr->community != NULL)
6706 {
6707 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6708 no_advertise = 1;
6709 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6710 no_export = 1;
6711 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6712 local_as = 1;
6713 }
6714 }
6715 }
6716
6717 vty_out (vty, "Paths: (%d available", count);
6718 if (best)
6719 {
6720 vty_out (vty, ", best #%d", best);
6721 if (safi == SAFI_UNICAST)
6722 vty_out (vty, ", table Default-IP-Routing-Table");
6723 }
6724 else
6725 vty_out (vty, ", no best path");
6726 if (no_advertise)
6727 vty_out (vty, ", not advertised to any peer");
6728 else if (no_export)
6729 vty_out (vty, ", not advertised to EBGP peer");
6730 else if (local_as)
6731 vty_out (vty, ", not advertised outside local AS");
6732 if (suppress)
6733 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6734 vty_out (vty, ")%s", VTY_NEWLINE);
6735
6736 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006737 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006738 {
6739 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6740 {
6741 if (! first)
6742 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6743 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6744 first = 1;
6745 }
6746 }
6747 if (! first)
6748 vty_out (vty, " Not advertised to any peer");
6749 vty_out (vty, "%s", VTY_NEWLINE);
6750}
6751
6752/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006753static int
paulfee0f4c2004-09-13 05:12:46 +00006754bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006755 struct bgp_table *rib, const char *ip_str,
6756 afi_t afi, safi_t safi, struct prefix_rd *prd,
6757 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006758{
6759 int ret;
6760 int header;
6761 int display = 0;
6762 struct prefix match;
6763 struct bgp_node *rn;
6764 struct bgp_node *rm;
6765 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006766 struct bgp_table *table;
6767
Lou Berger050defe2016-01-12 13:41:59 -05006768 memset (&match, 0, sizeof (struct prefix)); /* keep valgrind happy */
paul718e3742002-12-13 20:15:29 +00006769 /* Check IP address argument. */
6770 ret = str2prefix (ip_str, &match);
6771 if (! ret)
6772 {
6773 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6774 return CMD_WARNING;
6775 }
6776
6777 match.family = afi2family (afi);
6778
Lou Berger298cc2f2016-01-12 13:42:02 -05006779 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00006780 {
paulfee0f4c2004-09-13 05:12:46 +00006781 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006782 {
6783 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6784 continue;
6785
6786 if ((table = rn->info) != NULL)
6787 {
6788 header = 1;
6789
6790 if ((rm = bgp_node_match (table, &match)) != NULL)
6791 {
6792 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006793 {
6794 bgp_unlock_node (rm);
6795 continue;
6796 }
paul718e3742002-12-13 20:15:29 +00006797
6798 for (ri = rm->info; ri; ri = ri->next)
6799 {
6800 if (header)
6801 {
6802 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
Lou Berger298cc2f2016-01-12 13:42:02 -05006803 AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00006804
6805 header = 0;
6806 }
6807 display++;
Lou Berger298cc2f2016-01-12 13:42:02 -05006808 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00006809 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006810
6811 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006812 }
6813 }
6814 }
6815 }
6816 else
6817 {
6818 header = 1;
6819
paulfee0f4c2004-09-13 05:12:46 +00006820 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006821 {
6822 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6823 {
6824 for (ri = rn->info; ri; ri = ri->next)
6825 {
6826 if (header)
6827 {
6828 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6829 header = 0;
6830 }
6831 display++;
6832 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6833 }
6834 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006835
6836 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006837 }
6838 }
6839
6840 if (! display)
6841 {
6842 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6843 return CMD_WARNING;
6844 }
6845
6846 return CMD_SUCCESS;
6847}
6848
paulfee0f4c2004-09-13 05:12:46 +00006849/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006850static int
paulfd79ac92004-10-13 05:06:08 +00006851bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006852 afi_t afi, safi_t safi, struct prefix_rd *prd,
6853 int prefix_check)
6854{
6855 struct bgp *bgp;
6856
6857 /* BGP structure lookup. */
6858 if (view_name)
6859 {
6860 bgp = bgp_lookup_by_name (view_name);
6861 if (bgp == NULL)
6862 {
6863 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6864 return CMD_WARNING;
6865 }
6866 }
6867 else
6868 {
6869 bgp = bgp_get_default ();
6870 if (bgp == NULL)
6871 {
6872 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6873 return CMD_WARNING;
6874 }
6875 }
6876
6877 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6878 afi, safi, prd, prefix_check);
6879}
6880
paul718e3742002-12-13 20:15:29 +00006881/* BGP route print out function. */
Lou Bergerf9b6c392016-01-12 13:42:09 -05006882DEFUN (show_ip_bgp,
6883 show_ip_bgp_cmd,
6884 "show ip bgp",
6885 SHOW_STR
6886 IP_STR
6887 BGP_STR)
6888{
6889 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6890}
6891
6892DEFUN (show_ip_bgp_ipv4,
6893 show_ip_bgp_ipv4_cmd,
6894 "show ip bgp ipv4 (unicast|multicast)",
6895 SHOW_STR
6896 IP_STR
6897 BGP_STR
6898 "Address family\n"
6899 "Address Family modifier\n"
6900 "Address Family modifier\n")
6901{
6902 if (strncmp (argv[0], "m", 1) == 0)
6903 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6904 NULL);
6905
6906 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6907}
6908
6909DEFUN (show_ip_bgp_route,
6910 show_ip_bgp_route_cmd,
6911 "show ip bgp A.B.C.D",
6912 SHOW_STR
6913 IP_STR
6914 BGP_STR
6915 "Network in the BGP routing table to display\n")
6916{
6917 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6918}
6919
6920DEFUN (show_ip_bgp_ipv4_route,
6921 show_ip_bgp_ipv4_route_cmd,
6922 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6923 SHOW_STR
6924 IP_STR
6925 BGP_STR
6926 "Address family\n"
6927 "Address Family modifier\n"
6928 "Address Family modifier\n"
6929 "Network in the BGP routing table to display\n")
6930{
6931 if (strncmp (argv[0], "m", 1) == 0)
6932 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6933
6934 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6935}
6936
6937DEFUN (show_ip_bgp_vpnv4_all_route,
6938 show_ip_bgp_vpnv4_all_route_cmd,
6939 "show ip bgp vpnv4 all A.B.C.D",
6940 SHOW_STR
6941 IP_STR
6942 BGP_STR
6943 "Display VPNv4 NLRI specific information\n"
6944 "Display information about all VPNv4 NLRIs\n"
6945 "Network in the BGP routing table to display\n")
6946{
6947 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6948}
6949
6950DEFUN (show_ip_bgp_vpnv4_rd_route,
6951 show_ip_bgp_vpnv4_rd_route_cmd,
6952 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6953 SHOW_STR
6954 IP_STR
6955 BGP_STR
6956 "Display VPNv4 NLRI specific information\n"
6957 "Display information for a route distinguisher\n"
6958 "VPN Route Distinguisher\n"
6959 "Network in the BGP routing table to display\n")
6960{
6961 int ret;
6962 struct prefix_rd prd;
6963
6964 ret = str2prefix_rd (argv[0], &prd);
6965 if (! ret)
6966 {
6967 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6968 return CMD_WARNING;
6969 }
6970 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6971}
6972
6973DEFUN (show_ip_bgp_prefix,
6974 show_ip_bgp_prefix_cmd,
6975 "show ip bgp A.B.C.D/M",
6976 SHOW_STR
6977 IP_STR
6978 BGP_STR
6979 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6980{
6981 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6982}
6983
6984DEFUN (show_ip_bgp_ipv4_prefix,
6985 show_ip_bgp_ipv4_prefix_cmd,
6986 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6987 SHOW_STR
6988 IP_STR
6989 BGP_STR
6990 "Address family\n"
6991 "Address Family modifier\n"
6992 "Address Family modifier\n"
6993 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6994{
6995 if (strncmp (argv[0], "m", 1) == 0)
6996 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6997
6998 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6999}
7000
7001DEFUN (show_ip_bgp_vpnv4_all_prefix,
7002 show_ip_bgp_vpnv4_all_prefix_cmd,
7003 "show ip bgp vpnv4 all A.B.C.D/M",
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 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7010{
7011 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
7012}
7013
7014DEFUN (show_ip_bgp_vpnv4_rd_prefix,
7015 show_ip_bgp_vpnv4_rd_prefix_cmd,
7016 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7017 SHOW_STR
7018 IP_STR
7019 BGP_STR
7020 "Display VPNv4 NLRI specific information\n"
7021 "Display information for a route distinguisher\n"
7022 "VPN Route Distinguisher\n"
7023 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7024{
7025 int ret;
7026 struct prefix_rd prd;
7027
7028 ret = str2prefix_rd (argv[0], &prd);
7029 if (! ret)
7030 {
7031 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7032 return CMD_WARNING;
7033 }
7034 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
7035}
7036
7037DEFUN (show_ip_bgp_view,
7038 show_ip_bgp_view_cmd,
7039 "show ip bgp view WORD",
7040 SHOW_STR
7041 IP_STR
7042 BGP_STR
7043 "BGP view\n"
7044 "View name\n")
7045{
7046 struct bgp *bgp;
7047
7048 /* BGP structure lookup. */
7049 bgp = bgp_lookup_by_name (argv[0]);
7050 if (bgp == NULL)
7051 {
7052 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7053 return CMD_WARNING;
7054 }
7055
7056 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
7057}
7058
7059DEFUN (show_ip_bgp_view_route,
7060 show_ip_bgp_view_route_cmd,
7061 "show ip bgp view WORD A.B.C.D",
7062 SHOW_STR
7063 IP_STR
7064 BGP_STR
7065 "BGP view\n"
7066 "View name\n"
7067 "Network in the BGP routing table to display\n")
7068{
7069 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
7070}
7071
7072DEFUN (show_ip_bgp_view_prefix,
7073 show_ip_bgp_view_prefix_cmd,
7074 "show ip bgp view WORD A.B.C.D/M",
7075 SHOW_STR
7076 IP_STR
7077 BGP_STR
7078 "BGP view\n"
7079 "View name\n"
7080 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7081{
7082 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
7083}
7084
7085DEFUN (show_bgp,
7086 show_bgp_cmd,
7087 "show bgp",
7088 SHOW_STR
7089 BGP_STR)
7090{
7091 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7092 NULL);
7093}
7094
7095ALIAS (show_bgp,
7096 show_bgp_ipv6_cmd,
7097 "show bgp ipv6",
7098 SHOW_STR
7099 BGP_STR
7100 "Address family\n")
7101
7102/* old command */
7103DEFUN (show_ipv6_bgp,
7104 show_ipv6_bgp_cmd,
7105 "show ipv6 bgp",
7106 SHOW_STR
7107 IP_STR
7108 BGP_STR)
7109{
7110 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7111 NULL);
7112}
7113
7114DEFUN (show_bgp_route,
7115 show_bgp_route_cmd,
7116 "show bgp X:X::X:X",
7117 SHOW_STR
7118 BGP_STR
7119 "Network in the BGP routing table to display\n")
7120{
7121 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7122}
7123
Lou Berger35c36862016-01-12 13:42:06 -05007124DEFUN (show_bgp_ipv4_safi,
7125 show_bgp_ipv4_safi_cmd,
7126 "show bgp ipv4 (unicast|multicast)",
paul718e3742002-12-13 20:15:29 +00007127 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007128 BGP_STR
7129 "Address family\n"
7130 "Address Family modifier\n"
7131 "Address Family modifier\n")
7132{
7133 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00007134 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
7135 NULL);
paul718e3742002-12-13 20:15:29 +00007136
ajs5a646652004-11-05 01:25:55 +00007137 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00007138}
7139
Lou Berger35c36862016-01-12 13:42:06 -05007140DEFUN (show_bgp_ipv4_safi_route,
7141 show_bgp_ipv4_safi_route_cmd,
7142 "show bgp ipv4 (unicast|multicast) A.B.C.D",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007143 SHOW_STR
7144 BGP_STR
7145 "Address family\n"
7146 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00007147 "Address Family modifier\n"
7148 "Network in the BGP routing table to display\n")
7149{
7150 if (strncmp (argv[0], "m", 1) == 0)
7151 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
7152
7153 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
7154}
7155
Lou Berger35c36862016-01-12 13:42:06 -05007156DEFUN (show_bgp_ipv4_vpn_route,
7157 show_bgp_ipv4_vpn_route_cmd,
7158 "show bgp ipv4 vpn A.B.C.D",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007159 SHOW_STR
7160 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007161 "Address Family\n"
7162 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +00007163 "Network in the BGP routing table to display\n")
7164{
7165 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
7166}
7167
Lou Berger35c36862016-01-12 13:42:06 -05007168DEFUN (show_bgp_ipv6_vpn_route,
7169 show_bgp_ipv6_vpn_route_cmd,
7170 "show bgp ipv6 vpn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007171 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007172 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007173 "Address Family\n"
7174 "Display VPN NLRI specific information\n"
7175 "Network in the BGP routing table to display\n")
7176{
7177 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MPLS_VPN, NULL, 0);
7178}
Lou Berger35c36862016-01-12 13:42:06 -05007179
7180DEFUN (show_bgp_ipv4_vpn_rd_route,
7181 show_bgp_ipv4_vpn_rd_route_cmd,
7182 "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn A.B.C.D",
7183 SHOW_STR
7184 BGP_STR
7185 IP_STR
7186 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +00007187 "Display information for a route distinguisher\n"
7188 "VPN Route Distinguisher\n"
7189 "Network in the BGP routing table to display\n")
7190{
7191 int ret;
7192 struct prefix_rd prd;
7193
7194 ret = str2prefix_rd (argv[0], &prd);
7195 if (! ret)
7196 {
7197 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7198 return CMD_WARNING;
7199 }
7200 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
7201}
7202
Lou Berger35c36862016-01-12 13:42:06 -05007203DEFUN (show_bgp_ipv6_vpn_rd_route,
7204 show_bgp_ipv6_vpn_rd_route_cmd,
7205 "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007206 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007207 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007208 "Address Family\n"
7209 "Display VPN NLRI specific information\n"
7210 "Display information for a route distinguisher\n"
7211 "VPN Route Distinguisher\n"
7212 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007213{
Lou Berger35c36862016-01-12 13:42:06 -05007214 int ret;
7215 struct prefix_rd prd;
7216
7217 ret = str2prefix_rd (argv[0], &prd);
7218 if (! ret)
7219 {
7220 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7221 return CMD_WARNING;
7222 }
7223 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MPLS_VPN, &prd, 0);
paul718e3742002-12-13 20:15:29 +00007224}
7225
Lou Berger651b4022016-01-12 13:42:07 -05007226DEFUN (show_bgp_ipv4_encap_route,
7227 show_bgp_ipv4_encap_route_cmd,
7228 "show bgp ipv4 encap A.B.C.D",
paul718e3742002-12-13 20:15:29 +00007229 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007230 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007231 IP_STR
7232 "Display ENCAP NLRI specific information\n"
7233 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007234{
Lou Berger651b4022016-01-12 13:42:07 -05007235 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 0);
paul718e3742002-12-13 20:15:29 +00007236}
7237
Lou Berger651b4022016-01-12 13:42:07 -05007238DEFUN (show_bgp_ipv6_encap_route,
7239 show_bgp_ipv6_encap_route_cmd,
7240 "show bgp ipv6 encap X:X::X:X",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007241 SHOW_STR
7242 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007243 IP6_STR
7244 "Display ENCAP NLRI specific information\n"
7245 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007246{
Lou Berger651b4022016-01-12 13:42:07 -05007247 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 0);
paul718e3742002-12-13 20:15:29 +00007248}
7249
Lou Berger651b4022016-01-12 13:42:07 -05007250DEFUN (show_bgp_ipv4_safi_rd_route,
7251 show_bgp_ipv4_safi_rd_route_cmd,
7252 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D",
paul718e3742002-12-13 20:15:29 +00007253 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007254 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007255 "Address Family\n"
7256 "Address Family Modifier\n"
7257 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00007258 "Display information for a route distinguisher\n"
Lou Berger651b4022016-01-12 13:42:07 -05007259 "ENCAP Route Distinguisher\n"
7260 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007261{
7262 int ret;
7263 struct prefix_rd prd;
Lou Berger651b4022016-01-12 13:42:07 -05007264 safi_t safi;
paul718e3742002-12-13 20:15:29 +00007265
Lou Berger651b4022016-01-12 13:42:07 -05007266 if (bgp_parse_safi(argv[0], &safi)) {
7267 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7268 return CMD_WARNING;
7269 }
7270 ret = str2prefix_rd (argv[1], &prd);
paul718e3742002-12-13 20:15:29 +00007271 if (! ret)
7272 {
7273 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7274 return CMD_WARNING;
7275 }
Lou Berger651b4022016-01-12 13:42:07 -05007276 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 0);
paul718e3742002-12-13 20:15:29 +00007277}
7278
Lou Berger651b4022016-01-12 13:42:07 -05007279DEFUN (show_bgp_ipv6_safi_rd_route,
7280 show_bgp_ipv6_safi_rd_route_cmd,
7281 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007282 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007283 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007284 "Address Family\n"
7285 "Address Family Modifier\n"
7286 "Address Family Modifier\n"
7287 "Display information for a route distinguisher\n"
7288 "ENCAP Route Distinguisher\n"
7289 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007290{
Lou Berger651b4022016-01-12 13:42:07 -05007291 int ret;
7292 struct prefix_rd prd;
7293 safi_t safi;
paulbb46e942003-10-24 19:02:03 +00007294
Lou Berger651b4022016-01-12 13:42:07 -05007295 if (bgp_parse_safi(argv[0], &safi)) {
7296 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7297 return CMD_WARNING;
7298 }
7299 ret = str2prefix_rd (argv[1], &prd);
7300 if (! ret)
7301 {
7302 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7303 return CMD_WARNING;
7304 }
7305 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, SAFI_ENCAP, &prd, 0);
paul718e3742002-12-13 20:15:29 +00007306}
7307
Lou Berger35c36862016-01-12 13:42:06 -05007308DEFUN (show_bgp_ipv4_prefix,
7309 show_bgp_ipv4_prefix_cmd,
7310 "show bgp ipv4 A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007311 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007312 BGP_STR
paul718e3742002-12-13 20:15:29 +00007313 IP_STR
paul718e3742002-12-13 20:15:29 +00007314 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7315{
Lou Berger35c36862016-01-12 13:42:06 -05007316 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
paul718e3742002-12-13 20:15:29 +00007317}
7318
Lou Berger35c36862016-01-12 13:42:06 -05007319DEFUN (show_bgp_ipv4_safi_prefix,
7320 show_bgp_ipv4_safi_prefix_cmd,
7321 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007322 SHOW_STR
7323 BGP_STR
7324 "Address family\n"
7325 "Address Family modifier\n"
Lou Berger35c36862016-01-12 13:42:06 -05007326 "Address Family modifier\n"
7327 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007328{
7329 if (strncmp (argv[0], "m", 1) == 0)
Lou Berger35c36862016-01-12 13:42:06 -05007330 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007331
Lou Berger35c36862016-01-12 13:42:06 -05007332 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007333}
7334
Lou Berger35c36862016-01-12 13:42:06 -05007335DEFUN (show_bgp_ipv4_vpn_prefix,
7336 show_bgp_ipv4_vpn_prefix_cmd,
7337 "show bgp ipv4 vpn A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007338 SHOW_STR
7339 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007340 IP_STR
7341 "Display VPN NLRI specific information\n"
7342 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paul718e3742002-12-13 20:15:29 +00007343{
Lou Berger35c36862016-01-12 13:42:06 -05007344 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
paul718e3742002-12-13 20:15:29 +00007345}
7346
Lou Berger35c36862016-01-12 13:42:06 -05007347DEFUN (show_bgp_ipv6_vpn_prefix,
7348 show_bgp_ipv6_vpn_prefix_cmd,
7349 "show bgp ipv6 vpn X:X::X:X/M",
7350 SHOW_STR
7351 BGP_STR
7352 "Address Family\n"
7353 "Display VPN NLRI specific information\n"
7354 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7355{
7356 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MPLS_VPN, NULL, 1);
7357}
Lou Berger35c36862016-01-12 13:42:06 -05007358
Lou Berger651b4022016-01-12 13:42:07 -05007359DEFUN (show_bgp_ipv4_encap_prefix,
7360 show_bgp_ipv4_encap_prefix_cmd,
7361 "show bgp ipv4 encap A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007362 SHOW_STR
7363 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007364 IP_STR
7365 "Display ENCAP NLRI specific information\n"
7366 "Display information about ENCAP NLRIs\n"
7367 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7368{
7369 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 1);
7370}
paul718e3742002-12-13 20:15:29 +00007371
Lou Berger651b4022016-01-12 13:42:07 -05007372DEFUN (show_bgp_ipv6_encap_prefix,
7373 show_bgp_ipv6_encap_prefix_cmd,
7374 "show bgp ipv6 encap X:X::X:X/M",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007375 SHOW_STR
7376 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007377 IP_STR
7378 "Display ENCAP NLRI specific information\n"
7379 "Display information about ENCAP NLRIs\n"
7380 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7381{
7382 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 1);
7383}
Lou Berger651b4022016-01-12 13:42:07 -05007384
7385DEFUN (show_bgp_ipv4_safi_rd_prefix,
7386 show_bgp_ipv4_safi_rd_prefix_cmd,
7387 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7388 SHOW_STR
7389 BGP_STR
7390 "Address Family\n"
7391 "Address Family Modifier\n"
7392 "Address Family Modifier\n"
7393 "Display information for a route distinguisher\n"
7394 "ENCAP Route Distinguisher\n"
7395 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7396{
7397 int ret;
7398 struct prefix_rd prd;
7399 safi_t safi;
7400
7401 if (bgp_parse_safi(argv[0], &safi)) {
7402 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7403 return CMD_WARNING;
7404 }
7405
7406 ret = str2prefix_rd (argv[1], &prd);
7407 if (! ret)
7408 {
7409 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7410 return CMD_WARNING;
7411 }
7412 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 1);
7413}
7414
Lou Berger651b4022016-01-12 13:42:07 -05007415DEFUN (show_bgp_ipv6_safi_rd_prefix,
7416 show_bgp_ipv6_safi_rd_prefix_cmd,
7417 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X/M",
7418 SHOW_STR
7419 BGP_STR
7420 "Address Family\n"
7421 "Address Family Modifier\n"
7422 "Address Family Modifier\n"
7423 "Display information for a route distinguisher\n"
7424 "ENCAP Route Distinguisher\n"
7425 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7426{
7427 int ret;
7428 struct prefix_rd prd;
7429 safi_t safi;
7430
7431 if (bgp_parse_safi(argv[0], &safi)) {
7432 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7433 return CMD_WARNING;
7434 }
7435
7436 ret = str2prefix_rd (argv[1], &prd);
7437 if (! ret)
7438 {
7439 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7440 return CMD_WARNING;
7441 }
7442 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, safi, &prd, 1);
7443}
Lou Berger651b4022016-01-12 13:42:07 -05007444
7445DEFUN (show_bgp_afi_safi_view,
7446 show_bgp_afi_safi_view_cmd,
7447 "show bgp view WORD (ipv4|ipv6) (encap|mulicast|unicast|vpn)",
7448 SHOW_STR
7449 BGP_STR
7450 "BGP view\n"
7451 "BGP view name\n"
7452 "Address Family\n"
7453 "Address Family\n"
7454 "Address Family Modifier\n"
7455 "Address Family Modifier\n"
7456 "Address Family Modifier\n"
7457 "Address Family Modifier\n"
7458 )
7459{
7460 struct bgp *bgp;
7461 safi_t safi;
7462 afi_t afi;
7463
7464 if (bgp_parse_afi(argv[1], &afi)) {
7465 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7466 return CMD_WARNING;
7467 }
7468 if (bgp_parse_safi(argv[2], &safi)) {
7469 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7470 return CMD_WARNING;
7471 }
7472
7473 /* BGP structure lookup. */
7474 bgp = bgp_lookup_by_name (argv[0]);
7475 if (bgp == NULL)
7476 {
7477 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7478 return CMD_WARNING;
7479 }
7480
7481 return bgp_show (vty, bgp, afi, safi, bgp_show_type_normal, NULL);
7482}
7483
7484DEFUN (show_bgp_view_afi_safi_route,
7485 show_bgp_view_afi_safi_route_cmd,
7486 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) A.B.C.D",
7487 SHOW_STR
7488 BGP_STR
7489 "BGP view\n"
7490 "View name\n"
7491 "Address Family\n"
7492 "Address Family\n"
7493 "Address Family Modifier\n"
7494 "Address Family Modifier\n"
7495 "Address Family Modifier\n"
7496 "Address Family Modifier\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007497 "Network in the BGP routing table to display\n")
7498{
Lou Berger651b4022016-01-12 13:42:07 -05007499 safi_t safi;
7500 afi_t afi;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007501
Lou Berger651b4022016-01-12 13:42:07 -05007502 if (bgp_parse_afi(argv[1], &afi)) {
7503 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7504 return CMD_WARNING;
7505 }
7506 if (bgp_parse_safi(argv[2], &safi)) {
7507 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7508 return CMD_WARNING;
7509 }
7510 return bgp_show_route (vty, argv[0], argv[3], afi, safi, NULL, 0);
7511}
7512
7513DEFUN (show_bgp_view_afi_safi_prefix,
7514 show_bgp_view_afi_safi_prefix_cmd,
7515 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) A.B.C.D/M",
7516 SHOW_STR
7517 BGP_STR
7518 "BGP view\n"
7519 "View name\n"
7520 "Address Family\n"
7521 "Address Family\n"
7522 "Address Family Modifier\n"
7523 "Address Family Modifier\n"
7524 "Address Family Modifier\n"
7525 "Address Family Modifier\n"
7526 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7527{
7528 safi_t safi;
7529 afi_t afi;
7530
7531 if (bgp_parse_afi(argv[1], &afi)) {
7532 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7533 return CMD_WARNING;
7534 }
7535 if (bgp_parse_safi(argv[2], &safi)) {
7536 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7537 return CMD_WARNING;
7538 }
7539 return bgp_show_route (vty, argv[0], argv[3], afi, safi, NULL, 1);
7540}
7541
7542/* new001 */
7543DEFUN (show_bgp_afi,
7544 show_bgp_afi_cmd,
7545 "show bgp (ipv4|ipv6)",
7546 SHOW_STR
7547 BGP_STR
7548 "Address family\n"
7549 "Address family\n")
7550{
7551 afi_t afi;
7552
7553 if (bgp_parse_afi(argv[0], &afi)) {
7554 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7555 return CMD_WARNING;
7556 }
7557 return bgp_show (vty, NULL, afi, SAFI_UNICAST, bgp_show_type_normal,
7558 NULL);
7559}
7560
Lou Berger651b4022016-01-12 13:42:07 -05007561DEFUN (show_bgp_ipv6_safi,
7562 show_bgp_ipv6_safi_cmd,
7563 "show bgp ipv6 (unicast|multicast)",
7564 SHOW_STR
7565 BGP_STR
7566 "Address family\n"
7567 "Address Family modifier\n"
7568 "Address Family modifier\n")
7569{
7570 if (strncmp (argv[0], "m", 1) == 0)
7571 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7572 NULL);
7573
7574 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007575}
7576
Lou Berger35c36862016-01-12 13:42:06 -05007577DEFUN (show_bgp_ipv6_route,
7578 show_bgp_ipv6_route_cmd,
7579 "show bgp ipv6 X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007580 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007581 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007582 "Address family\n"
paul718e3742002-12-13 20:15:29 +00007583 "Network in the BGP routing table to display\n")
7584{
7585 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7586}
7587
Lou Berger35c36862016-01-12 13:42:06 -05007588DEFUN (show_bgp_ipv6_safi_route,
7589 show_bgp_ipv6_safi_route_cmd,
7590 "show bgp ipv6 (unicast|multicast) X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007591 SHOW_STR
7592 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007593 "Address family\n"
7594 "Address Family modifier\n"
7595 "Address Family modifier\n"
7596 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007597{
Lou Berger35c36862016-01-12 13:42:06 -05007598 if (strncmp (argv[0], "m", 1) == 0)
7599 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7600
7601 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
paul718e3742002-12-13 20:15:29 +00007602}
7603
Lou Bergerf9b6c392016-01-12 13:42:09 -05007604/* old command */
7605DEFUN (show_ipv6_bgp_route,
7606 show_ipv6_bgp_route_cmd,
7607 "show ipv6 bgp X:X::X:X",
7608 SHOW_STR
7609 IP_STR
7610 BGP_STR
7611 "Network in the BGP routing table to display\n")
7612{
7613 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7614}
7615
7616DEFUN (show_bgp_prefix,
7617 show_bgp_prefix_cmd,
7618 "show bgp X:X::X:X/M",
7619 SHOW_STR
7620 BGP_STR
7621 "IPv6 prefix <network>/<length>\n")
7622{
7623 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7624}
7625
7626
Lou Berger35c36862016-01-12 13:42:06 -05007627/* new002 */
7628DEFUN (show_bgp_ipv6_prefix,
paul718e3742002-12-13 20:15:29 +00007629 show_bgp_ipv6_prefix_cmd,
7630 "show bgp ipv6 X:X::X:X/M",
7631 SHOW_STR
7632 BGP_STR
7633 "Address family\n"
Lou Berger35c36862016-01-12 13:42:06 -05007634 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7635{
7636 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7637}
Michael Lambert95cbbd22010-07-23 14:43:04 -04007638DEFUN (show_bgp_ipv6_safi_prefix,
7639 show_bgp_ipv6_safi_prefix_cmd,
7640 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
7641 SHOW_STR
7642 BGP_STR
7643 "Address family\n"
7644 "Address Family modifier\n"
7645 "Address Family modifier\n"
7646 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7647{
7648 if (strncmp (argv[0], "m", 1) == 0)
7649 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7650
7651 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7652}
7653
Lou Bergerf9b6c392016-01-12 13:42:09 -05007654/* old command */
7655DEFUN (show_ipv6_bgp_prefix,
7656 show_ipv6_bgp_prefix_cmd,
7657 "show ipv6 bgp X:X::X:X/M",
7658 SHOW_STR
7659 IP_STR
7660 BGP_STR
7661 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7662{
7663 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7664}
7665
paulbb46e942003-10-24 19:02:03 +00007666DEFUN (show_bgp_view,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007667 show_bgp_view_cmd,
7668 "show bgp view WORD",
7669 SHOW_STR
7670 BGP_STR
7671 "BGP view\n"
7672 "View name\n")
7673{
7674 struct bgp *bgp;
7675
7676 /* BGP structure lookup. */
7677 bgp = bgp_lookup_by_name (argv[0]);
7678 if (bgp == NULL)
7679 {
7680 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7681 return CMD_WARNING;
7682 }
7683
7684 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
7685}
7686
7687DEFUN (show_bgp_view_ipv6,
Lou Berger35c36862016-01-12 13:42:06 -05007688 show_bgp_view_ipv6_cmd,
7689 "show bgp view WORD ipv6",
paulbb46e942003-10-24 19:02:03 +00007690 SHOW_STR
Lou Berger35c36862016-01-12 13:42:06 -05007691 BGP_STR
paulbb46e942003-10-24 19:02:03 +00007692 "BGP view\n"
Lou Berger35c36862016-01-12 13:42:06 -05007693 "View name\n"
7694 "Address family\n")
paulbb46e942003-10-24 19:02:03 +00007695{
7696 struct bgp *bgp;
7697
7698 /* BGP structure lookup. */
7699 bgp = bgp_lookup_by_name (argv[0]);
7700 if (bgp == NULL)
7701 {
7702 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7703 return CMD_WARNING;
7704 }
7705
ajs5a646652004-11-05 01:25:55 +00007706 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007707}
paulbb46e942003-10-24 19:02:03 +00007708
7709DEFUN (show_bgp_view_route,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007710 show_bgp_view_route_cmd,
7711 "show bgp view WORD X:X::X:X",
7712 SHOW_STR
7713 BGP_STR
7714 "BGP view\n"
7715 "View name\n"
7716 "Network in the BGP routing table to display\n")
7717{
7718 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7719}
7720
7721DEFUN (show_bgp_view_ipv6_route,
paulbb46e942003-10-24 19:02:03 +00007722 show_bgp_view_ipv6_route_cmd,
7723 "show bgp view WORD ipv6 X:X::X:X",
7724 SHOW_STR
7725 BGP_STR
7726 "BGP view\n"
7727 "View name\n"
7728 "Address family\n"
7729 "Network in the BGP routing table to display\n")
paulbb46e942003-10-24 19:02:03 +00007730{
Lou Berger35c36862016-01-12 13:42:06 -05007731 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
paulbb46e942003-10-24 19:02:03 +00007732}
7733
Lou Bergerf9b6c392016-01-12 13:42:09 -05007734/* old command */
7735DEFUN (show_ipv6_mbgp,
7736 show_ipv6_mbgp_cmd,
7737 "show ipv6 mbgp",
7738 SHOW_STR
7739 IP_STR
7740 MBGP_STR)
7741{
7742 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7743 NULL);
7744}
7745
7746/* old command */
7747DEFUN (show_ipv6_mbgp_route,
7748 show_ipv6_mbgp_route_cmd,
7749 "show ipv6 mbgp X:X::X:X",
7750 SHOW_STR
7751 IP_STR
7752 MBGP_STR
7753 "Network in the MBGP routing table to display\n")
7754{
7755 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7756}
7757
7758/* old command */
7759DEFUN (show_ipv6_mbgp_prefix,
7760 show_ipv6_mbgp_prefix_cmd,
7761 "show ipv6 mbgp X:X::X:X/M",
7762 SHOW_STR
7763 IP_STR
7764 MBGP_STR
7765 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7766{
7767 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7768}
7769
Lou Berger35c36862016-01-12 13:42:06 -05007770DEFUN (show_bgp_view_prefix,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007771 show_bgp_view_prefix_cmd,
7772 "show bgp view WORD X:X::X:X/M",
7773 SHOW_STR
7774 BGP_STR
7775 "BGP view\n"
7776 "View name\n"
7777 "IPv6 prefix <network>/<length>\n")
7778{
7779 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7780}
7781
7782DEFUN (show_bgp_view_ipv6_prefix,
paulbb46e942003-10-24 19:02:03 +00007783 show_bgp_view_ipv6_prefix_cmd,
7784 "show bgp view WORD ipv6 X:X::X:X/M",
7785 SHOW_STR
7786 BGP_STR
7787 "BGP view\n"
7788 "View name\n"
7789 "Address family\n"
7790 "IPv6 prefix <network>/<length>\n")
paul718e3742002-12-13 20:15:29 +00007791{
Lou Berger35c36862016-01-12 13:42:06 -05007792 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
paul718e3742002-12-13 20:15:29 +00007793}
7794
paul94f2b392005-06-28 12:44:16 +00007795static int
paulfd79ac92004-10-13 05:06:08 +00007796bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007797 safi_t safi, enum bgp_show_type type)
7798{
7799 int i;
7800 struct buffer *b;
7801 char *regstr;
7802 int first;
7803 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007804 int rc;
paul718e3742002-12-13 20:15:29 +00007805
7806 first = 0;
7807 b = buffer_new (1024);
7808 for (i = 0; i < argc; i++)
7809 {
7810 if (first)
7811 buffer_putc (b, ' ');
7812 else
7813 {
7814 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7815 continue;
7816 first = 1;
7817 }
7818
7819 buffer_putstr (b, argv[i]);
7820 }
7821 buffer_putc (b, '\0');
7822
7823 regstr = buffer_getstr (b);
7824 buffer_free (b);
7825
7826 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007827 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007828 if (! regex)
7829 {
7830 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7831 VTY_NEWLINE);
7832 return CMD_WARNING;
7833 }
7834
ajs5a646652004-11-05 01:25:55 +00007835 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7836 bgp_regex_free (regex);
7837 return rc;
paul718e3742002-12-13 20:15:29 +00007838}
7839
Lou Bergerf9b6c392016-01-12 13:42:09 -05007840
7841DEFUN (show_ip_bgp_regexp,
7842 show_ip_bgp_regexp_cmd,
7843 "show ip bgp regexp .LINE",
7844 SHOW_STR
7845 IP_STR
7846 BGP_STR
7847 "Display routes matching the AS path regular expression\n"
7848 "A regular-expression to match the BGP AS paths\n")
7849{
7850 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7851 bgp_show_type_regexp);
7852}
7853
7854DEFUN (show_ip_bgp_flap_regexp,
7855 show_ip_bgp_flap_regexp_cmd,
7856 "show ip bgp flap-statistics regexp .LINE",
7857 SHOW_STR
7858 IP_STR
7859 BGP_STR
7860 "Display flap statistics of routes\n"
7861 "Display routes matching the AS path regular expression\n"
7862 "A regular-expression to match the BGP AS paths\n")
7863{
7864 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7865 bgp_show_type_flap_regexp);
7866}
7867
7868ALIAS (show_ip_bgp_flap_regexp,
7869 show_ip_bgp_damp_flap_regexp_cmd,
7870 "show ip bgp dampening flap-statistics regexp .LINE",
7871 SHOW_STR
7872 IP_STR
7873 BGP_STR
7874 "Display detailed information about dampening\n"
7875 "Display flap statistics of routes\n"
7876 "Display routes matching the AS path regular expression\n"
7877 "A regular-expression to match the BGP AS paths\n")
7878
7879DEFUN (show_ip_bgp_ipv4_regexp,
7880 show_ip_bgp_ipv4_regexp_cmd,
7881 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7882 SHOW_STR
7883 IP_STR
7884 BGP_STR
7885 "Address family\n"
7886 "Address Family modifier\n"
7887 "Address Family modifier\n"
7888 "Display routes matching the AS path regular expression\n"
7889 "A regular-expression to match the BGP AS paths\n")
7890{
7891 if (strncmp (argv[0], "m", 1) == 0)
7892 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7893 bgp_show_type_regexp);
7894
7895 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7896 bgp_show_type_regexp);
7897}
7898
Lou Bergerf9b6c392016-01-12 13:42:09 -05007899DEFUN (show_bgp_regexp,
7900 show_bgp_regexp_cmd,
7901 "show bgp regexp .LINE",
7902 SHOW_STR
7903 BGP_STR
7904 "Display routes matching the AS path regular expression\n"
7905 "A regular-expression to match the BGP AS paths\n")
7906{
7907 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7908 bgp_show_type_regexp);
7909}
7910
7911/* old command */
7912DEFUN (show_ipv6_bgp_regexp,
7913 show_ipv6_bgp_regexp_cmd,
7914 "show ipv6 bgp regexp .LINE",
7915 SHOW_STR
7916 IP_STR
7917 BGP_STR
7918 "Display routes matching the AS path regular expression\n"
7919 "A regular-expression to match the BGP AS paths\n")
7920{
7921 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7922 bgp_show_type_regexp);
7923}
7924
7925/* old command */
7926DEFUN (show_ipv6_mbgp_regexp,
7927 show_ipv6_mbgp_regexp_cmd,
7928 "show ipv6 mbgp regexp .LINE",
7929 SHOW_STR
7930 IP_STR
7931 BGP_STR
7932 "Display routes matching the AS path regular expression\n"
7933 "A regular-expression to match the MBGP AS paths\n")
7934{
7935 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7936 bgp_show_type_regexp);
7937}
Lou Bergerf9b6c392016-01-12 13:42:09 -05007938
Lou Berger651b4022016-01-12 13:42:07 -05007939DEFUN (show_bgp_ipv4_safi_flap_regexp,
7940 show_bgp_ipv4_safi_flap_regexp_cmd,
7941 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics regexp .LINE",
paul718e3742002-12-13 20:15:29 +00007942 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007943 BGP_STR
paul718e3742002-12-13 20:15:29 +00007944 IP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007945 "Address Family Modifier\n"
7946 "Address Family Modifier\n"
7947 "Address Family Modifier\n"
7948 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00007949 "Display flap statistics of routes\n"
7950 "Display routes matching the AS path regular expression\n"
7951 "A regular-expression to match the BGP AS paths\n")
7952{
Lou Berger651b4022016-01-12 13:42:07 -05007953 safi_t safi;
7954
7955 if (bgp_parse_safi(argv[0], &safi)) {
7956 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7957 return CMD_WARNING;
7958 }
7959 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP, safi,
7960 bgp_show_type_flap_regexp);
paul718e3742002-12-13 20:15:29 +00007961}
7962
Lou Berger651b4022016-01-12 13:42:07 -05007963ALIAS (show_bgp_ipv4_safi_flap_regexp,
7964 show_bgp_ipv4_safi_damp_flap_regexp_cmd,
7965 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics regexp .LINE",
Balaji3921cc52015-05-16 23:12:17 +05307966 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05307967 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007968 IP_STR
7969 "Address Family Modifier\n"
7970 "Address Family Modifier\n"
7971 "Address Family Modifier\n"
7972 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05307973 "Display detailed information about dampening\n"
7974 "Display flap statistics of routes\n"
7975 "Display routes matching the AS path regular expression\n"
7976 "A regular-expression to match the BGP AS paths\n")
7977
Lou Berger651b4022016-01-12 13:42:07 -05007978DEFUN (show_bgp_ipv6_safi_flap_regexp,
7979 show_bgp_ipv6_safi_flap_regexp_cmd,
7980 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics regexp .LINE",
paul718e3742002-12-13 20:15:29 +00007981 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05007982 BGP_STR
7983 IPV6_STR
7984 "Address Family Modifier\n"
7985 "Address Family Modifier\n"
7986 "Address Family Modifier\n"
7987 "Address Family Modifier\n"
7988 "Display flap statistics of routes\n"
7989 "Display routes matching the AS path regular expression\n"
7990 "A regular-expression to match the BGP AS paths\n")
7991{
7992 safi_t safi;
7993
7994 if (bgp_parse_safi(argv[0], &safi)) {
7995 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7996 return CMD_WARNING;
7997 }
7998 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP6, safi,
7999 bgp_show_type_flap_regexp);
8000}
8001
8002ALIAS (show_bgp_ipv6_safi_flap_regexp,
8003 show_bgp_ipv6_safi_damp_flap_regexp_cmd,
8004 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics regexp .LINE",
8005 SHOW_STR
8006 BGP_STR
8007 IPV6_STR
8008 "Address Family Modifier\n"
8009 "Address Family Modifier\n"
8010 "Address Family Modifier\n"
8011 "Address Family Modifier\n"
8012 "Display detailed information about dampening\n"
8013 "Display flap statistics of routes\n"
8014 "Display routes matching the AS path regular expression\n"
8015 "A regular-expression to match the BGP AS paths\n")
Lou Berger651b4022016-01-12 13:42:07 -05008016
8017DEFUN (show_bgp_ipv4_safi_regexp,
8018 show_bgp_ipv4_safi_regexp_cmd,
8019 "show bgp ipv4 (encap|multicast|unicast|vpn) regexp .LINE",
8020 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008021 BGP_STR
8022 "Address family\n"
8023 "Address Family modifier\n"
8024 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05008025 "Address Family modifier\n"
8026 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008027 "Display routes matching the AS path regular expression\n"
8028 "A regular-expression to match the BGP AS paths\n")
8029{
Lou Berger651b4022016-01-12 13:42:07 -05008030 safi_t safi;
8031 if (bgp_parse_safi(argv[0], &safi)) {
8032 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8033 return CMD_WARNING;
8034 }
paul718e3742002-12-13 20:15:29 +00008035
Lou Berger651b4022016-01-12 13:42:07 -05008036 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008037 bgp_show_type_regexp);
8038}
Lou Berger205e6742016-01-12 13:42:11 -05008039
Lou Berger651b4022016-01-12 13:42:07 -05008040DEFUN (show_bgp_ipv6_safi_regexp,
8041 show_bgp_ipv6_safi_regexp_cmd,
8042 "show bgp ipv6 (encap|multicast|unicast|vpn) regexp .LINE",
paul718e3742002-12-13 20:15:29 +00008043 SHOW_STR
8044 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008045 "Address family\n"
8046 "Address Family modifier\n"
8047 "Address Family modifier\n"
8048 "Address Family modifier\n"
8049 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008050 "Display routes matching the AS path regular expression\n"
8051 "A regular-expression to match the BGP AS paths\n")
8052{
Lou Berger651b4022016-01-12 13:42:07 -05008053 safi_t safi;
8054 if (bgp_parse_safi(argv[0], &safi)) {
8055 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8056 return CMD_WARNING;
8057 }
8058
8059 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00008060 bgp_show_type_regexp);
8061}
8062
Lou Berger651b4022016-01-12 13:42:07 -05008063DEFUN (show_bgp_ipv6_regexp,
paul718e3742002-12-13 20:15:29 +00008064 show_bgp_ipv6_regexp_cmd,
8065 "show bgp ipv6 regexp .LINE",
8066 SHOW_STR
8067 BGP_STR
8068 "Address family\n"
8069 "Display routes matching the AS path regular expression\n"
8070 "A regular-expression to match the BGP AS paths\n")
paul718e3742002-12-13 20:15:29 +00008071{
8072 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8073 bgp_show_type_regexp);
8074}
8075
paul94f2b392005-06-28 12:44:16 +00008076static int
paulfd79ac92004-10-13 05:06:08 +00008077bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008078 safi_t safi, enum bgp_show_type type)
8079{
8080 struct prefix_list *plist;
8081
8082 plist = prefix_list_lookup (afi, prefix_list_str);
8083 if (plist == NULL)
8084 {
8085 vty_out (vty, "%% %s is not a valid prefix-list name%s",
8086 prefix_list_str, VTY_NEWLINE);
8087 return CMD_WARNING;
8088 }
8089
ajs5a646652004-11-05 01:25:55 +00008090 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00008091}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008092DEFUN (show_ip_bgp_prefix_list,
8093 show_ip_bgp_prefix_list_cmd,
8094 "show ip bgp prefix-list WORD",
8095 SHOW_STR
8096 IP_STR
8097 BGP_STR
8098 "Display routes conforming to the prefix-list\n"
8099 "IP prefix-list name\n")
8100{
8101 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8102 bgp_show_type_prefix_list);
8103}
8104
8105DEFUN (show_ip_bgp_flap_prefix_list,
8106 show_ip_bgp_flap_prefix_list_cmd,
8107 "show ip bgp flap-statistics prefix-list WORD",
8108 SHOW_STR
8109 IP_STR
8110 BGP_STR
8111 "Display flap statistics of routes\n"
8112 "Display routes conforming to the prefix-list\n"
8113 "IP prefix-list name\n")
8114{
8115 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8116 bgp_show_type_flap_prefix_list);
8117}
8118
8119ALIAS (show_ip_bgp_flap_prefix_list,
8120 show_ip_bgp_damp_flap_prefix_list_cmd,
8121 "show ip bgp dampening flap-statistics prefix-list WORD",
8122 SHOW_STR
8123 IP_STR
8124 BGP_STR
8125 "Display detailed information about dampening\n"
8126 "Display flap statistics of routes\n"
8127 "Display routes conforming to the prefix-list\n"
8128 "IP prefix-list name\n")
8129
8130DEFUN (show_ip_bgp_ipv4_prefix_list,
8131 show_ip_bgp_ipv4_prefix_list_cmd,
8132 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
8133 SHOW_STR
8134 IP_STR
8135 BGP_STR
8136 "Address family\n"
8137 "Address Family modifier\n"
8138 "Address Family modifier\n"
8139 "Display routes conforming to the prefix-list\n"
8140 "IP prefix-list name\n")
8141{
8142 if (strncmp (argv[0], "m", 1) == 0)
8143 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8144 bgp_show_type_prefix_list);
8145
8146 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8147 bgp_show_type_prefix_list);
8148}
8149
Lou Bergerf9b6c392016-01-12 13:42:09 -05008150DEFUN (show_bgp_prefix_list,
8151 show_bgp_prefix_list_cmd,
8152 "show bgp prefix-list WORD",
8153 SHOW_STR
8154 BGP_STR
8155 "Display routes conforming to the prefix-list\n"
8156 "IPv6 prefix-list name\n")
8157{
8158 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8159 bgp_show_type_prefix_list);
8160}
8161
8162ALIAS (show_bgp_prefix_list,
8163 show_bgp_ipv6_prefix_list_cmd,
8164 "show bgp ipv6 prefix-list WORD",
8165 SHOW_STR
8166 BGP_STR
8167 "Address family\n"
8168 "Display routes conforming to the prefix-list\n"
8169 "IPv6 prefix-list name\n")
8170
8171/* old command */
8172DEFUN (show_ipv6_bgp_prefix_list,
8173 show_ipv6_bgp_prefix_list_cmd,
8174 "show ipv6 bgp prefix-list WORD",
8175 SHOW_STR
8176 IPV6_STR
8177 BGP_STR
8178 "Display routes matching the prefix-list\n"
8179 "IPv6 prefix-list name\n")
8180{
8181 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8182 bgp_show_type_prefix_list);
8183}
8184
8185/* old command */
8186DEFUN (show_ipv6_mbgp_prefix_list,
8187 show_ipv6_mbgp_prefix_list_cmd,
8188 "show ipv6 mbgp prefix-list WORD",
8189 SHOW_STR
8190 IPV6_STR
8191 MBGP_STR
8192 "Display routes matching the prefix-list\n"
8193 "IPv6 prefix-list name\n")
8194{
8195 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8196 bgp_show_type_prefix_list);
8197}
paul718e3742002-12-13 20:15:29 +00008198
Lou Berger35c36862016-01-12 13:42:06 -05008199DEFUN (show_bgp_ipv4_prefix_list,
8200 show_bgp_ipv4_prefix_list_cmd,
8201 "show bgp ipv4 prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008202 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008203 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05008204 IP_STR
paul718e3742002-12-13 20:15:29 +00008205 "Display routes conforming to the prefix-list\n"
8206 "IP prefix-list name\n")
8207{
8208 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8209 bgp_show_type_prefix_list);
8210}
8211
Lou Berger651b4022016-01-12 13:42:07 -05008212DEFUN (show_bgp_ipv4_safi_flap_prefix_list,
8213 show_bgp_ipv4_safi_flap_prefix_list_cmd,
8214 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008215 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008216 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008217 IP_STR
8218 "Address Family Modifier\n"
8219 "Address Family Modifier\n"
8220 "Address Family Modifier\n"
8221 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00008222 "Display flap statistics of routes\n"
8223 "Display routes conforming to the prefix-list\n"
8224 "IP prefix-list name\n")
8225{
Lou Berger651b4022016-01-12 13:42:07 -05008226 safi_t safi;
8227 if (bgp_parse_safi(argv[0], &safi)) {
8228 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8229 return CMD_WARNING;
8230 }
8231 return bgp_show_prefix_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008232 bgp_show_type_flap_prefix_list);
8233}
8234
Lou Berger651b4022016-01-12 13:42:07 -05008235ALIAS (show_bgp_ipv4_safi_flap_prefix_list,
8236 show_bgp_ipv4_safi_damp_flap_prefix_list_cmd,
8237 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics prefix-list WORD",
Balaji3921cc52015-05-16 23:12:17 +05308238 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308239 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008240 IP_STR
8241 "Address Family Modifier\n"
8242 "Address Family Modifier\n"
8243 "Address Family Modifier\n"
8244 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308245 "Display detailed information about dampening\n"
8246 "Display flap statistics of routes\n"
8247 "Display routes conforming to the prefix-list\n"
8248 "IP prefix-list name\n")
8249
Lou Berger651b4022016-01-12 13:42:07 -05008250DEFUN (show_bgp_ipv6_safi_flap_prefix_list,
8251 show_bgp_ipv6_safi_flap_prefix_list_cmd,
8252 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008253 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05008254 BGP_STR
8255 IPV6_STR
8256 "Address Family Modifier\n"
8257 "Address Family Modifier\n"
8258 "Address Family Modifier\n"
8259 "Address Family Modifier\n"
8260 "Display flap statistics of routes\n"
8261 "Display routes conforming to the prefix-list\n"
8262 "IP prefix-list name\n")
8263{
8264 safi_t safi;
8265 if (bgp_parse_safi(argv[0], &safi)) {
8266 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8267 return CMD_WARNING;
8268 }
8269 return bgp_show_prefix_list (vty, argv[1], AFI_IP6, safi,
8270 bgp_show_type_flap_prefix_list);
8271}
8272ALIAS (show_bgp_ipv6_safi_flap_prefix_list,
8273 show_bgp_ipv6_safi_damp_flap_prefix_list_cmd,
8274 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics prefix-list WORD",
8275 SHOW_STR
8276 BGP_STR
8277 IPV6_STR
8278 "Address Family Modifier\n"
8279 "Address Family Modifier\n"
8280 "Address Family Modifier\n"
8281 "Address Family Modifier\n"
8282 "Display detailed information about dampening\n"
8283 "Display flap statistics of routes\n"
8284 "Display routes conforming to the prefix-list\n"
8285 "IP prefix-list name\n")
Lou Berger651b4022016-01-12 13:42:07 -05008286
8287DEFUN (show_bgp_ipv4_safi_prefix_list,
8288 show_bgp_ipv4_safi_prefix_list_cmd,
8289 "show bgp ipv4 (encap|multicast|unicast|vpn) prefix-list WORD",
8290 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008291 BGP_STR
8292 "Address family\n"
8293 "Address Family modifier\n"
8294 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05008295 "Address Family modifier\n"
8296 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008297 "Display routes conforming to the prefix-list\n"
8298 "IP prefix-list name\n")
8299{
Lou Berger651b4022016-01-12 13:42:07 -05008300 safi_t safi;
8301 if (bgp_parse_safi(argv[0], &safi)) {
8302 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8303 return CMD_WARNING;
8304 }
8305 return bgp_show_prefix_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008306 bgp_show_type_prefix_list);
8307}
Lou Berger205e6742016-01-12 13:42:11 -05008308
Lou Berger651b4022016-01-12 13:42:07 -05008309DEFUN (show_bgp_ipv6_safi_prefix_list,
8310 show_bgp_ipv6_safi_prefix_list_cmd,
8311 "show bgp ipv6 (encap|multicast|unicast|vpn) prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008312 SHOW_STR
8313 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008314 "Address family\n"
8315 "Address Family modifier\n"
8316 "Address Family modifier\n"
8317 "Address Family modifier\n"
8318 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008319 "Display routes conforming to the prefix-list\n"
Lou Berger651b4022016-01-12 13:42:07 -05008320 "IP prefix-list name\n")
paul718e3742002-12-13 20:15:29 +00008321{
Lou Berger651b4022016-01-12 13:42:07 -05008322 safi_t safi;
8323 if (bgp_parse_safi(argv[0], &safi)) {
8324 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8325 return CMD_WARNING;
8326 }
8327 return bgp_show_prefix_list (vty, argv[1], AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00008328 bgp_show_type_prefix_list);
8329}
8330
paul94f2b392005-06-28 12:44:16 +00008331static int
paulfd79ac92004-10-13 05:06:08 +00008332bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008333 safi_t safi, enum bgp_show_type type)
8334{
8335 struct as_list *as_list;
8336
8337 as_list = as_list_lookup (filter);
8338 if (as_list == NULL)
8339 {
8340 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
8341 return CMD_WARNING;
8342 }
8343
ajs5a646652004-11-05 01:25:55 +00008344 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00008345}
8346
Lou Bergerf9b6c392016-01-12 13:42:09 -05008347DEFUN (show_ip_bgp_filter_list,
8348 show_ip_bgp_filter_list_cmd,
8349 "show ip bgp filter-list WORD",
8350 SHOW_STR
8351 IP_STR
8352 BGP_STR
8353 "Display routes conforming to the filter-list\n"
8354 "Regular expression access list name\n")
8355{
8356 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8357 bgp_show_type_filter_list);
8358}
8359
8360DEFUN (show_ip_bgp_flap_filter_list,
8361 show_ip_bgp_flap_filter_list_cmd,
8362 "show ip bgp flap-statistics filter-list WORD",
8363 SHOW_STR
8364 IP_STR
8365 BGP_STR
8366 "Display flap statistics of routes\n"
8367 "Display routes conforming to the filter-list\n"
8368 "Regular expression access list name\n")
8369{
8370 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8371 bgp_show_type_flap_filter_list);
8372}
8373
8374ALIAS (show_ip_bgp_flap_filter_list,
8375 show_ip_bgp_damp_flap_filter_list_cmd,
8376 "show ip bgp dampening flap-statistics filter-list WORD",
8377 SHOW_STR
8378 IP_STR
8379 BGP_STR
8380 "Display detailed information about dampening\n"
8381 "Display flap statistics of routes\n"
8382 "Display routes conforming to the filter-list\n"
8383 "Regular expression access list name\n")
8384
8385DEFUN (show_ip_bgp_ipv4_filter_list,
8386 show_ip_bgp_ipv4_filter_list_cmd,
8387 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
8388 SHOW_STR
8389 IP_STR
8390 BGP_STR
8391 "Address family\n"
8392 "Address Family modifier\n"
8393 "Address Family modifier\n"
8394 "Display routes conforming to the filter-list\n"
8395 "Regular expression access list name\n")
8396{
8397 if (strncmp (argv[0], "m", 1) == 0)
8398 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8399 bgp_show_type_filter_list);
8400
8401 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8402 bgp_show_type_filter_list);
8403}
8404
Lou Bergerf9b6c392016-01-12 13:42:09 -05008405DEFUN (show_bgp_filter_list,
8406 show_bgp_filter_list_cmd,
8407 "show bgp filter-list WORD",
8408 SHOW_STR
8409 BGP_STR
8410 "Display routes conforming to the filter-list\n"
8411 "Regular expression access list name\n")
8412{
8413 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8414 bgp_show_type_filter_list);
8415}
8416
8417/* old command */
8418DEFUN (show_ipv6_bgp_filter_list,
8419 show_ipv6_bgp_filter_list_cmd,
8420 "show ipv6 bgp filter-list WORD",
8421 SHOW_STR
8422 IPV6_STR
8423 BGP_STR
8424 "Display routes conforming to the filter-list\n"
8425 "Regular expression access list name\n")
8426{
8427 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8428 bgp_show_type_filter_list);
8429}
8430
8431/* old command */
8432DEFUN (show_ipv6_mbgp_filter_list,
8433 show_ipv6_mbgp_filter_list_cmd,
8434 "show ipv6 mbgp filter-list WORD",
8435 SHOW_STR
8436 IPV6_STR
8437 MBGP_STR
8438 "Display routes conforming to the filter-list\n"
8439 "Regular expression access list name\n")
8440{
8441 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8442 bgp_show_type_filter_list);
8443}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008444
8445DEFUN (show_ip_bgp_dampening_info,
8446 show_ip_bgp_dampening_params_cmd,
8447 "show ip bgp dampening parameters",
8448 SHOW_STR
8449 IP_STR
8450 BGP_STR
8451 "Display detailed information about dampening\n"
8452 "Display detail of configured dampening parameters\n")
8453{
8454 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
8455}
8456
Lou Berger651b4022016-01-12 13:42:07 -05008457DEFUN (show_bgp_ipv4_filter_list,
8458 show_bgp_ipv4_filter_list_cmd,
8459 "show bgp ipv4 filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008460 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008461 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008462 IP_STR
paul718e3742002-12-13 20:15:29 +00008463 "Display routes conforming to the filter-list\n"
8464 "Regular expression access list name\n")
8465{
8466 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8467 bgp_show_type_filter_list);
8468}
8469
Lou Berger651b4022016-01-12 13:42:07 -05008470DEFUN (show_bgp_ipv4_safi_flap_filter_list,
8471 show_bgp_ipv4_safi_flap_filter_list_cmd,
8472 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008473 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008474 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008475 IP_STR
8476 "Address Family modifier\n"
8477 "Address Family modifier\n"
8478 "Address Family modifier\n"
8479 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008480 "Display flap statistics of routes\n"
8481 "Display routes conforming to the filter-list\n"
8482 "Regular expression access list name\n")
8483{
Lou Berger651b4022016-01-12 13:42:07 -05008484 safi_t safi;
8485
8486 if (bgp_parse_safi(argv[0], &safi)) {
8487 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8488 return CMD_WARNING;
8489 }
8490 return bgp_show_filter_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008491 bgp_show_type_flap_filter_list);
8492}
8493
Lou Berger651b4022016-01-12 13:42:07 -05008494ALIAS (show_bgp_ipv4_safi_flap_filter_list,
8495 show_bgp_ipv4_safi_damp_flap_filter_list_cmd,
8496 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics filter-list WORD",
Balaji3921cc52015-05-16 23:12:17 +05308497 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308498 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008499 IP_STR
8500 "Address Family modifier\n"
8501 "Address Family modifier\n"
8502 "Address Family modifier\n"
8503 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308504 "Display detailed information about dampening\n"
8505 "Display flap statistics of routes\n"
8506 "Display routes conforming to the filter-list\n"
8507 "Regular expression access list name\n")
8508
Lou Berger651b4022016-01-12 13:42:07 -05008509DEFUN (show_bgp_ipv6_safi_flap_filter_list,
8510 show_bgp_ipv6_safi_flap_filter_list_cmd,
8511 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008512 SHOW_STR
8513 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008514 IPV6_STR
8515 "Address Family modifier\n"
8516 "Address Family modifier\n"
8517 "Address Family modifier\n"
8518 "Address Family modifier\n"
8519 "Display flap statistics of routes\n"
paul718e3742002-12-13 20:15:29 +00008520 "Display routes conforming to the filter-list\n"
8521 "Regular expression access list name\n")
8522{
Lou Berger651b4022016-01-12 13:42:07 -05008523 safi_t safi;
8524
8525 if (bgp_parse_safi(argv[0], &safi)) {
8526 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8527 return CMD_WARNING;
8528 }
8529 return bgp_show_filter_list (vty, argv[1], AFI_IP6, safi,
8530 bgp_show_type_flap_filter_list);
8531}
8532ALIAS (show_bgp_ipv6_safi_flap_filter_list,
8533 show_bgp_ipv6_safi_damp_flap_filter_list_cmd,
8534 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics filter-list WORD",
8535 SHOW_STR
8536 BGP_STR
8537 IPV6_STR
8538 "Address Family modifier\n"
8539 "Address Family modifier\n"
8540 "Address Family modifier\n"
8541 "Address Family modifier\n"
8542 "Display detailed information about dampening\n"
8543 "Display flap statistics of routes\n"
8544 "Display routes conforming to the filter-list\n"
8545 "Regular expression access list name\n")
Lou Berger651b4022016-01-12 13:42:07 -05008546
8547DEFUN (show_bgp_ipv4_safi_filter_list,
8548 show_bgp_ipv4_safi_filter_list_cmd,
8549 "show bgp ipv4 (encap|multicast|unicast|vpn) filter-list WORD",
8550 SHOW_STR
8551 BGP_STR
8552 "Address Family modifier\n"
8553 "Address Family modifier\n"
8554 "Address Family modifier\n"
8555 "Address Family modifier\n"
8556 "Display routes conforming to the filter-list\n"
8557 "Regular expression access list name\n")
8558{
8559 safi_t safi;
8560
8561 if (bgp_parse_safi(argv[0], &safi)) {
8562 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8563 return CMD_WARNING;
8564 }
8565 return bgp_show_filter_list (vty, argv[1], AFI_IP, safi,
8566 bgp_show_type_filter_list);
8567}
Lou Berger205e6742016-01-12 13:42:11 -05008568
Lou Berger651b4022016-01-12 13:42:07 -05008569DEFUN (show_bgp_ipv6_safi_filter_list,
8570 show_bgp_ipv6_safi_filter_list_cmd,
8571 "show bgp ipv6 (encap|multicast|unicast|vpn) filter-list WORD",
8572 SHOW_STR
8573 BGP_STR
8574 "Address Family modifier\n"
8575 "Address Family modifier\n"
8576 "Address Family modifier\n"
8577 "Address Family modifier\n"
8578 "Display routes conforming to the filter-list\n"
8579 "Regular expression access list name\n")
8580{
8581 safi_t safi;
8582
8583 if (bgp_parse_safi(argv[0], &safi)) {
8584 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8585 return CMD_WARNING;
8586 }
8587 return bgp_show_filter_list (vty, argv[1], AFI_IP6, safi,
8588 bgp_show_type_filter_list);
paul718e3742002-12-13 20:15:29 +00008589}
8590
Lou Bergerf9b6c392016-01-12 13:42:09 -05008591DEFUN (show_bgp_ipv6_filter_list,
paul718e3742002-12-13 20:15:29 +00008592 show_bgp_ipv6_filter_list_cmd,
8593 "show bgp ipv6 filter-list WORD",
8594 SHOW_STR
8595 BGP_STR
8596 "Address family\n"
8597 "Display routes conforming to the filter-list\n"
8598 "Regular expression access list name\n")
paul718e3742002-12-13 20:15:29 +00008599{
8600 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8601 bgp_show_type_filter_list);
8602}
8603
Balaji9c52cae2016-01-20 22:59:26 +05308604
8605DEFUN (show_ip_bgp_ipv4_dampening_parameters,
8606 show_ip_bgp_ipv4_dampening_parameters_cmd,
8607 "show ip bgp ipv4 (unicast|multicast) dampening parameters",
8608 SHOW_STR
8609 IP_STR
8610 BGP_STR
8611 "Address family\n"
8612 "Address Family modifier\n"
8613 "Address Family modifier\n"
8614 "Display detailed information about dampening\n"
8615 "Display detail of configured dampening parameters\n")
8616{
8617 if (strncmp(argv[0], "m", 1) == 0)
8618 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_MULTICAST);
8619
8620 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
8621}
8622
8623
8624DEFUN (show_ip_bgp_ipv4_dampening_flap_stats,
8625 show_ip_bgp_ipv4_dampening_flap_stats_cmd,
8626 "show ip bgp ipv4 (unicast|multicast) dampening flap-statistics",
8627 SHOW_STR
8628 IP_STR
8629 BGP_STR
8630 "Address family\n"
8631 "Address Family modifier\n"
8632 "Address Family modifier\n"
8633 "Display detailed information about dampening\n"
8634 "Display flap statistics of routes\n")
8635{
8636 if (strncmp(argv[0], "m", 1) == 0)
8637 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8638 bgp_show_type_flap_statistics, NULL);
8639
8640 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8641 bgp_show_type_flap_statistics, NULL);
8642}
8643
8644DEFUN (show_ip_bgp_ipv4_dampening_dampd_paths,
8645 show_ip_bgp_ipv4_dampening_dampd_paths_cmd,
8646 "show ip bgp ipv4 (unicast|multicast) dampening dampened-paths",
8647 SHOW_STR
8648 IP_STR
8649 BGP_STR
8650 "Address family\n"
8651 "Address Family modifier\n"
8652 "Address Family modifier\n"
8653 "Display detailed information about dampening\n"
8654 "Display paths suppressed due to dampening\n")
8655{
8656 if (strncmp(argv[0], "m", 1) == 0)
8657 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8658 bgp_show_type_dampend_paths, NULL);
8659
8660 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8661 bgp_show_type_dampend_paths, NULL);
8662}
8663
paul94f2b392005-06-28 12:44:16 +00008664static int
paulfd79ac92004-10-13 05:06:08 +00008665bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008666 safi_t safi, enum bgp_show_type type)
8667{
8668 struct route_map *rmap;
8669
8670 rmap = route_map_lookup_by_name (rmap_str);
8671 if (! rmap)
8672 {
8673 vty_out (vty, "%% %s is not a valid route-map name%s",
8674 rmap_str, VTY_NEWLINE);
8675 return CMD_WARNING;
8676 }
8677
ajs5a646652004-11-05 01:25:55 +00008678 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00008679}
8680
Lou Bergerf9b6c392016-01-12 13:42:09 -05008681DEFUN (show_ip_bgp_route_map,
8682 show_ip_bgp_route_map_cmd,
8683 "show ip bgp route-map WORD",
8684 SHOW_STR
8685 IP_STR
8686 BGP_STR
8687 "Display routes matching the route-map\n"
8688 "A route-map to match on\n")
8689{
8690 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8691 bgp_show_type_route_map);
8692}
8693
8694DEFUN (show_ip_bgp_flap_route_map,
8695 show_ip_bgp_flap_route_map_cmd,
8696 "show ip bgp flap-statistics route-map WORD",
8697 SHOW_STR
8698 IP_STR
8699 BGP_STR
8700 "Display flap statistics of routes\n"
8701 "Display routes matching the route-map\n"
8702 "A route-map to match on\n")
8703{
8704 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8705 bgp_show_type_flap_route_map);
8706}
8707
8708ALIAS (show_ip_bgp_flap_route_map,
8709 show_ip_bgp_damp_flap_route_map_cmd,
8710 "show ip bgp dampening flap-statistics route-map WORD",
8711 SHOW_STR
8712 IP_STR
8713 BGP_STR
8714 "Display detailed information about dampening\n"
8715 "Display flap statistics of routes\n"
8716 "Display routes matching the route-map\n"
8717 "A route-map to match on\n")
8718
8719DEFUN (show_ip_bgp_ipv4_route_map,
8720 show_ip_bgp_ipv4_route_map_cmd,
8721 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
8722 SHOW_STR
8723 IP_STR
8724 BGP_STR
8725 "Address family\n"
8726 "Address Family modifier\n"
8727 "Address Family modifier\n"
8728 "Display routes matching the route-map\n"
8729 "A route-map to match on\n")
8730{
8731 if (strncmp (argv[0], "m", 1) == 0)
8732 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8733 bgp_show_type_route_map);
8734
8735 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
8736 bgp_show_type_route_map);
8737}
8738
8739DEFUN (show_bgp_route_map,
8740 show_bgp_route_map_cmd,
8741 "show bgp route-map WORD",
8742 SHOW_STR
8743 BGP_STR
8744 "Display routes matching the route-map\n"
8745 "A route-map to match on\n")
8746{
8747 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8748 bgp_show_type_route_map);
8749}
8750
8751DEFUN (show_ip_bgp_cidr_only,
8752 show_ip_bgp_cidr_only_cmd,
8753 "show ip bgp cidr-only",
8754 SHOW_STR
8755 IP_STR
8756 BGP_STR
8757 "Display only routes with non-natural netmasks\n")
8758{
8759 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8760 bgp_show_type_cidr_only, NULL);
8761}
8762
8763DEFUN (show_ip_bgp_flap_cidr_only,
8764 show_ip_bgp_flap_cidr_only_cmd,
8765 "show ip bgp flap-statistics cidr-only",
8766 SHOW_STR
8767 IP_STR
8768 BGP_STR
8769 "Display flap statistics of routes\n"
8770 "Display only routes with non-natural netmasks\n")
8771{
8772 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8773 bgp_show_type_flap_cidr_only, NULL);
8774}
8775
8776ALIAS (show_ip_bgp_flap_cidr_only,
8777 show_ip_bgp_damp_flap_cidr_only_cmd,
8778 "show ip bgp dampening flap-statistics cidr-only",
8779 SHOW_STR
8780 IP_STR
8781 BGP_STR
8782 "Display detailed information about dampening\n"
8783 "Display flap statistics of routes\n"
8784 "Display only routes with non-natural netmasks\n")
8785
8786DEFUN (show_ip_bgp_ipv4_cidr_only,
8787 show_ip_bgp_ipv4_cidr_only_cmd,
8788 "show ip bgp ipv4 (unicast|multicast) cidr-only",
8789 SHOW_STR
8790 IP_STR
8791 BGP_STR
8792 "Address family\n"
8793 "Address Family modifier\n"
8794 "Address Family modifier\n"
8795 "Display only routes with non-natural netmasks\n")
8796{
8797 if (strncmp (argv[0], "m", 1) == 0)
8798 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8799 bgp_show_type_cidr_only, NULL);
8800
8801 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8802 bgp_show_type_cidr_only, NULL);
8803}
8804
8805DEFUN (show_ip_bgp_community_all,
8806 show_ip_bgp_community_all_cmd,
8807 "show ip bgp community",
8808 SHOW_STR
8809 IP_STR
8810 BGP_STR
8811 "Display routes matching the communities\n")
8812{
8813 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8814 bgp_show_type_community_all, NULL);
8815}
8816
8817DEFUN (show_ip_bgp_ipv4_community_all,
8818 show_ip_bgp_ipv4_community_all_cmd,
8819 "show ip bgp ipv4 (unicast|multicast) community",
8820 SHOW_STR
8821 IP_STR
8822 BGP_STR
8823 "Address family\n"
8824 "Address Family modifier\n"
8825 "Address Family modifier\n"
8826 "Display routes matching the communities\n")
8827{
8828 if (strncmp (argv[0], "m", 1) == 0)
8829 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8830 bgp_show_type_community_all, NULL);
8831
8832 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8833 bgp_show_type_community_all, NULL);
8834}
8835
Lou Bergerf9b6c392016-01-12 13:42:09 -05008836DEFUN (show_bgp_community_all,
8837 show_bgp_community_all_cmd,
8838 "show bgp community",
8839 SHOW_STR
8840 BGP_STR
8841 "Display routes matching the communities\n")
8842{
8843 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
8844 bgp_show_type_community_all, NULL);
8845}
8846
8847ALIAS (show_bgp_community_all,
8848 show_bgp_ipv6_community_all_cmd,
8849 "show bgp ipv6 community",
8850 SHOW_STR
8851 BGP_STR
8852 "Address family\n"
8853 "Display routes matching the communities\n")
8854
8855/* old command */
8856DEFUN (show_ipv6_bgp_community_all,
8857 show_ipv6_bgp_community_all_cmd,
8858 "show ipv6 bgp community",
8859 SHOW_STR
8860 IPV6_STR
8861 BGP_STR
8862 "Display routes matching the communities\n")
8863{
8864 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
8865 bgp_show_type_community_all, NULL);
8866}
8867
8868/* old command */
8869DEFUN (show_ipv6_mbgp_community_all,
8870 show_ipv6_mbgp_community_all_cmd,
8871 "show ipv6 mbgp community",
8872 SHOW_STR
8873 IPV6_STR
8874 MBGP_STR
8875 "Display routes matching the communities\n")
8876{
8877 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
8878 bgp_show_type_community_all, NULL);
8879}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008880
Lou Berger651b4022016-01-12 13:42:07 -05008881DEFUN (show_bgp_ipv4_route_map,
8882 show_bgp_ipv4_route_map_cmd,
8883 "show bgp ipv4 route-map WORD",
paul718e3742002-12-13 20:15:29 +00008884 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008885 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008886 IP_STR
paul718e3742002-12-13 20:15:29 +00008887 "Display routes matching the route-map\n"
8888 "A route-map to match on\n")
8889{
8890 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8891 bgp_show_type_route_map);
8892}
8893
Lou Berger651b4022016-01-12 13:42:07 -05008894DEFUN (show_bgp_ipv4_safi_flap_route_map,
8895 show_bgp_ipv4_safi_flap_route_map_cmd,
8896 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics route-map WORD",
paul718e3742002-12-13 20:15:29 +00008897 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008898 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008899 IP_STR
8900 "Address Family Modifier\n"
8901 "Address Family Modifier\n"
8902 "Address Family Modifier\n"
8903 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00008904 "Display flap statistics of routes\n"
8905 "Display routes matching the route-map\n"
8906 "A route-map to match on\n")
8907{
Lou Berger651b4022016-01-12 13:42:07 -05008908 safi_t safi;
8909 if (bgp_parse_safi(argv[0], &safi)) {
8910 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8911 return CMD_WARNING;
8912 }
8913 return bgp_show_route_map (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008914 bgp_show_type_flap_route_map);
8915}
8916
Lou Berger651b4022016-01-12 13:42:07 -05008917ALIAS (show_bgp_ipv4_safi_flap_route_map,
8918 show_bgp_ipv4_safi_damp_flap_route_map_cmd,
8919 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics route-map WORD",
Balaji3921cc52015-05-16 23:12:17 +05308920 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308921 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008922 IP_STR
8923 "Address Family Modifier\n"
8924 "Address Family Modifier\n"
8925 "Address Family Modifier\n"
8926 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308927 "Display detailed information about dampening\n"
8928 "Display flap statistics of routes\n"
8929 "Display routes matching the route-map\n"
8930 "A route-map to match on\n")
Lou Berger205e6742016-01-12 13:42:11 -05008931
Lou Berger651b4022016-01-12 13:42:07 -05008932DEFUN (show_bgp_ipv6_safi_flap_route_map,
8933 show_bgp_ipv6_safi_flap_route_map_cmd,
8934 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics route-map WORD",
paul718e3742002-12-13 20:15:29 +00008935 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05008936 BGP_STR
8937 IPV6_STR
8938 "Address Family Modifier\n"
8939 "Address Family Modifier\n"
8940 "Address Family Modifier\n"
8941 "Address Family Modifier\n"
8942 "Display flap statistics of routes\n"
8943 "Display routes matching the route-map\n"
8944 "A route-map to match on\n")
8945{
8946 safi_t safi;
8947 if (bgp_parse_safi(argv[0], &safi)) {
8948 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8949 return CMD_WARNING;
8950 }
8951 return bgp_show_route_map (vty, argv[1], AFI_IP6, safi,
8952 bgp_show_type_flap_route_map);
8953}
8954ALIAS (show_bgp_ipv6_safi_flap_route_map,
8955 show_bgp_ipv6_safi_damp_flap_route_map_cmd,
8956 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics route-map WORD",
8957 SHOW_STR
8958 BGP_STR
8959 IPV6_STR
8960 "Address Family Modifier\n"
8961 "Address Family Modifier\n"
8962 "Address Family Modifier\n"
8963 "Address Family Modifier\n"
8964 "Display detailed information about dampening\n"
8965 "Display flap statistics of routes\n"
8966 "Display routes matching the route-map\n"
8967 "A route-map to match on\n")
Lou Berger651b4022016-01-12 13:42:07 -05008968
8969DEFUN (show_bgp_ipv4_safi_route_map,
8970 show_bgp_ipv4_safi_route_map_cmd,
8971 "show bgp ipv4 (encap|multicast|unicast|vpn) route-map WORD",
8972 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008973 BGP_STR
8974 "Address family\n"
8975 "Address Family modifier\n"
8976 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05008977 "Address Family modifier\n"
8978 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008979 "Display routes matching the route-map\n"
8980 "A route-map to match on\n")
8981{
Lou Berger651b4022016-01-12 13:42:07 -05008982 safi_t safi;
8983 if (bgp_parse_safi(argv[0], &safi)) {
8984 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8985 return CMD_WARNING;
8986 }
8987 return bgp_show_route_map (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008988 bgp_show_type_route_map);
8989}
Lou Berger205e6742016-01-12 13:42:11 -05008990
Lou Berger651b4022016-01-12 13:42:07 -05008991DEFUN (show_bgp_ipv6_safi_route_map,
8992 show_bgp_ipv6_safi_route_map_cmd,
8993 "show bgp ipv6 (encap|multicast|unicast|vpn) route-map WORD",
paul718e3742002-12-13 20:15:29 +00008994 SHOW_STR
8995 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008996 "Address family\n"
8997 "Address Family modifier\n"
8998 "Address Family modifier\n"
8999 "Address Family modifier\n"
9000 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009001 "Display routes matching the route-map\n"
9002 "A route-map to match on\n")
9003{
Lou Berger651b4022016-01-12 13:42:07 -05009004 safi_t safi;
9005 if (bgp_parse_safi(argv[0], &safi)) {
9006 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9007 return CMD_WARNING;
9008 }
9009 return bgp_show_route_map (vty, argv[1], AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00009010 bgp_show_type_route_map);
9011}
9012
Lou Berger651b4022016-01-12 13:42:07 -05009013DEFUN (show_bgp_ipv6_route_map,
paul718e3742002-12-13 20:15:29 +00009014 show_bgp_ipv6_route_map_cmd,
9015 "show bgp ipv6 route-map WORD",
9016 SHOW_STR
9017 BGP_STR
9018 "Address family\n"
9019 "Display routes matching the route-map\n"
9020 "A route-map to match on\n")
Lou Berger651b4022016-01-12 13:42:07 -05009021{
9022 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9023 bgp_show_type_route_map);
9024}
David Lamparter6b0655a2014-06-04 06:53:35 +02009025
Lou Berger651b4022016-01-12 13:42:07 -05009026DEFUN (show_bgp_ipv4_cidr_only,
9027 show_bgp_ipv4_cidr_only_cmd,
9028 "show bgp ipv4 cidr-only",
paul718e3742002-12-13 20:15:29 +00009029 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009030 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009031 IP_STR
paul718e3742002-12-13 20:15:29 +00009032 "Display only routes with non-natural netmasks\n")
9033{
9034 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00009035 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009036}
9037
Lou Berger651b4022016-01-12 13:42:07 -05009038DEFUN (show_bgp_ipv4_safi_flap_cidr_only,
9039 show_bgp_ipv4_safi_flap_cidr_only_cmd,
9040 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics cidr-only",
paul718e3742002-12-13 20:15:29 +00009041 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009042 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009043 "Address Family\n"
9044 "Address Family Modifier\n"
9045 "Address Family Modifier\n"
9046 "Address Family Modifier\n"
9047 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00009048 "Display flap statistics of routes\n"
9049 "Display only routes with non-natural netmasks\n")
9050{
Lou Berger651b4022016-01-12 13:42:07 -05009051 safi_t safi;
9052
9053 if (bgp_parse_safi(argv[0], &safi)) {
9054 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9055 return CMD_WARNING;
9056 }
9057 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009058}
9059
Lou Berger651b4022016-01-12 13:42:07 -05009060ALIAS (show_bgp_ipv4_safi_flap_cidr_only,
9061 show_bgp_ipv4_safi_damp_flap_cidr_only_cmd,
9062 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics cidr-only",
Balaji3921cc52015-05-16 23:12:17 +05309063 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05309064 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009065 "Address Family\n"
9066 "Address Family Modifier\n"
9067 "Address Family Modifier\n"
9068 "Address Family Modifier\n"
9069 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05309070 "Display detailed information about dampening\n"
9071 "Display flap statistics of routes\n"
9072 "Display only routes with non-natural netmasks\n")
9073
Lou Berger651b4022016-01-12 13:42:07 -05009074DEFUN (show_bgp_ipv4_safi_cidr_only,
9075 show_bgp_ipv4_safi_cidr_only_cmd,
9076 "show bgp ipv4 (unicast|multicast) cidr-only",
paul718e3742002-12-13 20:15:29 +00009077 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009078 BGP_STR
9079 "Address family\n"
9080 "Address Family modifier\n"
9081 "Address Family modifier\n"
9082 "Display only routes with non-natural netmasks\n")
9083{
9084 if (strncmp (argv[0], "m", 1) == 0)
9085 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00009086 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009087
9088 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00009089 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009090}
David Lamparter6b0655a2014-06-04 06:53:35 +02009091
Lou Berger651b4022016-01-12 13:42:07 -05009092/* new046 */
9093DEFUN (show_bgp_afi_safi_community_all,
9094 show_bgp_afi_safi_community_all_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009095 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) community",
paul718e3742002-12-13 20:15:29 +00009096 SHOW_STR
9097 BGP_STR
9098 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009099 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009100 "Address Family modifier\n"
9101 "Address Family modifier\n"
9102 "Address Family modifier\n"
9103 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009104 "Display routes matching the communities\n")
Lou Berger651b4022016-01-12 13:42:07 -05009105{
9106 safi_t safi;
9107 afi_t afi;
paul718e3742002-12-13 20:15:29 +00009108
Lou Berger651b4022016-01-12 13:42:07 -05009109 if (bgp_parse_afi(argv[0], &afi)) {
9110 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
9111 return CMD_WARNING;
9112 }
9113 if (bgp_parse_safi(argv[1], &safi)) {
9114 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
9115 return CMD_WARNING;
9116 }
9117
9118 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_all, NULL);
9119}
9120DEFUN (show_bgp_afi_community_all,
9121 show_bgp_afi_community_all_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009122 "show bgp (ipv4|ipv6) community",
paul718e3742002-12-13 20:15:29 +00009123 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009124 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009125 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009126 "Address family\n"
paul718e3742002-12-13 20:15:29 +00009127 "Display routes matching the communities\n")
9128{
Lou Berger651b4022016-01-12 13:42:07 -05009129 afi_t afi;
9130 safi_t safi = SAFI_UNICAST;
paul718e3742002-12-13 20:15:29 +00009131
Lou Berger651b4022016-01-12 13:42:07 -05009132 if (bgp_parse_afi(argv[0], &afi)) {
9133 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
9134 return CMD_WARNING;
9135 }
9136 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00009137}
David Lamparter6b0655a2014-06-04 06:53:35 +02009138
paul94f2b392005-06-28 12:44:16 +00009139static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04009140bgp_show_community (struct vty *vty, const char *view_name, int argc,
9141 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00009142{
9143 struct community *com;
9144 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04009145 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00009146 int i;
9147 char *str;
9148 int first = 0;
9149
Michael Lambert95cbbd22010-07-23 14:43:04 -04009150 /* BGP structure lookup */
9151 if (view_name)
9152 {
9153 bgp = bgp_lookup_by_name (view_name);
9154 if (bgp == NULL)
9155 {
9156 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9157 return CMD_WARNING;
9158 }
9159 }
9160 else
9161 {
9162 bgp = bgp_get_default ();
9163 if (bgp == NULL)
9164 {
9165 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9166 return CMD_WARNING;
9167 }
9168 }
9169
paul718e3742002-12-13 20:15:29 +00009170 b = buffer_new (1024);
9171 for (i = 0; i < argc; i++)
9172 {
9173 if (first)
9174 buffer_putc (b, ' ');
9175 else
9176 {
9177 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9178 continue;
9179 first = 1;
9180 }
9181
9182 buffer_putstr (b, argv[i]);
9183 }
9184 buffer_putc (b, '\0');
9185
9186 str = buffer_getstr (b);
9187 buffer_free (b);
9188
9189 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00009190 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00009191 if (! com)
9192 {
9193 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
9194 return CMD_WARNING;
9195 }
9196
Michael Lambert95cbbd22010-07-23 14:43:04 -04009197 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00009198 (exact ? bgp_show_type_community_exact :
9199 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00009200}
9201
Lou Bergerf9b6c392016-01-12 13:42:09 -05009202DEFUN (show_ip_bgp_community,
9203 show_ip_bgp_community_cmd,
9204 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
9205 SHOW_STR
9206 IP_STR
9207 BGP_STR
9208 "Display routes matching the communities\n"
9209 "community number\n"
9210 "Do not send outside local AS (well-known community)\n"
9211 "Do not advertise to any peer (well-known community)\n"
9212 "Do not export to next AS (well-known community)\n")
9213{
9214 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9215}
9216
9217ALIAS (show_ip_bgp_community,
9218 show_ip_bgp_community2_cmd,
9219 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9220 SHOW_STR
9221 IP_STR
9222 BGP_STR
9223 "Display routes matching the communities\n"
9224 "community number\n"
9225 "Do not send outside local AS (well-known community)\n"
9226 "Do not advertise to any peer (well-known community)\n"
9227 "Do not export to next AS (well-known community)\n"
9228 "community number\n"
9229 "Do not send outside local AS (well-known community)\n"
9230 "Do not advertise to any peer (well-known community)\n"
9231 "Do not export to next AS (well-known community)\n")
9232
9233ALIAS (show_ip_bgp_community,
9234 show_ip_bgp_community3_cmd,
9235 "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)",
9236 SHOW_STR
9237 IP_STR
9238 BGP_STR
9239 "Display routes matching the communities\n"
9240 "community number\n"
9241 "Do not send outside local AS (well-known community)\n"
9242 "Do not advertise to any peer (well-known community)\n"
9243 "Do not export to next AS (well-known community)\n"
9244 "community number\n"
9245 "Do not send outside local AS (well-known community)\n"
9246 "Do not advertise to any peer (well-known community)\n"
9247 "Do not export to next AS (well-known community)\n"
9248 "community number\n"
9249 "Do not send outside local AS (well-known community)\n"
9250 "Do not advertise to any peer (well-known community)\n"
9251 "Do not export to next AS (well-known community)\n")
9252
9253ALIAS (show_ip_bgp_community,
9254 show_ip_bgp_community4_cmd,
9255 "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)",
9256 SHOW_STR
9257 IP_STR
9258 BGP_STR
9259 "Display routes matching the communities\n"
9260 "community number\n"
9261 "Do not send outside local AS (well-known community)\n"
9262 "Do not advertise to any peer (well-known community)\n"
9263 "Do not export to next AS (well-known community)\n"
9264 "community number\n"
9265 "Do not send outside local AS (well-known community)\n"
9266 "Do not advertise to any peer (well-known community)\n"
9267 "Do not export to next AS (well-known community)\n"
9268 "community number\n"
9269 "Do not send outside local AS (well-known community)\n"
9270 "Do not advertise to any peer (well-known community)\n"
9271 "Do not export to next AS (well-known community)\n"
9272 "community number\n"
9273 "Do not send outside local AS (well-known community)\n"
9274 "Do not advertise to any peer (well-known community)\n"
9275 "Do not export to next AS (well-known community)\n")
9276
9277DEFUN (show_ip_bgp_ipv4_community,
9278 show_ip_bgp_ipv4_community_cmd,
9279 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9280 SHOW_STR
9281 IP_STR
9282 BGP_STR
9283 "Address family\n"
9284 "Address Family modifier\n"
9285 "Address Family modifier\n"
9286 "Display routes matching the communities\n"
9287 "community number\n"
9288 "Do not send outside local AS (well-known community)\n"
9289 "Do not advertise to any peer (well-known community)\n"
9290 "Do not export to next AS (well-known community)\n")
9291{
9292 if (strncmp (argv[0], "m", 1) == 0)
9293 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
9294
9295 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9296}
9297
9298ALIAS (show_ip_bgp_ipv4_community,
9299 show_ip_bgp_ipv4_community2_cmd,
9300 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9301 SHOW_STR
9302 IP_STR
9303 BGP_STR
9304 "Address family\n"
9305 "Address Family modifier\n"
9306 "Address Family modifier\n"
9307 "Display routes matching the communities\n"
9308 "community number\n"
9309 "Do not send outside local AS (well-known community)\n"
9310 "Do not advertise to any peer (well-known community)\n"
9311 "Do not export to next AS (well-known community)\n"
9312 "community number\n"
9313 "Do not send outside local AS (well-known community)\n"
9314 "Do not advertise to any peer (well-known community)\n"
9315 "Do not export to next AS (well-known community)\n")
9316
9317ALIAS (show_ip_bgp_ipv4_community,
9318 show_ip_bgp_ipv4_community3_cmd,
9319 "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)",
9320 SHOW_STR
9321 IP_STR
9322 BGP_STR
9323 "Address family\n"
9324 "Address Family modifier\n"
9325 "Address Family modifier\n"
9326 "Display routes matching the communities\n"
9327 "community number\n"
9328 "Do not send outside local AS (well-known community)\n"
9329 "Do not advertise to any peer (well-known community)\n"
9330 "Do not export to next AS (well-known community)\n"
9331 "community number\n"
9332 "Do not send outside local AS (well-known community)\n"
9333 "Do not advertise to any peer (well-known community)\n"
9334 "Do not export to next AS (well-known community)\n"
9335 "community number\n"
9336 "Do not send outside local AS (well-known community)\n"
9337 "Do not advertise to any peer (well-known community)\n"
9338 "Do not export to next AS (well-known community)\n")
9339
9340ALIAS (show_ip_bgp_ipv4_community,
9341 show_ip_bgp_ipv4_community4_cmd,
9342 "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)",
9343 SHOW_STR
9344 IP_STR
9345 BGP_STR
9346 "Address family\n"
9347 "Address Family modifier\n"
9348 "Address Family modifier\n"
9349 "Display routes matching the communities\n"
9350 "community number\n"
9351 "Do not send outside local AS (well-known community)\n"
9352 "Do not advertise to any peer (well-known community)\n"
9353 "Do not export to next AS (well-known community)\n"
9354 "community number\n"
9355 "Do not send outside local AS (well-known community)\n"
9356 "Do not advertise to any peer (well-known community)\n"
9357 "Do not export to next AS (well-known community)\n"
9358 "community number\n"
9359 "Do not send outside local AS (well-known community)\n"
9360 "Do not advertise to any peer (well-known community)\n"
9361 "Do not export to next AS (well-known community)\n"
9362 "community number\n"
9363 "Do not send outside local AS (well-known community)\n"
9364 "Do not advertise to any peer (well-known community)\n"
9365 "Do not export to next AS (well-known community)\n")
9366
9367DEFUN (show_ip_bgp_community_exact,
9368 show_ip_bgp_community_exact_cmd,
9369 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9370 SHOW_STR
9371 IP_STR
9372 BGP_STR
9373 "Display routes matching the communities\n"
9374 "community number\n"
9375 "Do not send outside local AS (well-known community)\n"
9376 "Do not advertise to any peer (well-known community)\n"
9377 "Do not export to next AS (well-known community)\n"
9378 "Exact match of the communities")
9379{
9380 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9381}
9382
9383ALIAS (show_ip_bgp_community_exact,
9384 show_ip_bgp_community2_exact_cmd,
9385 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9386 SHOW_STR
9387 IP_STR
9388 BGP_STR
9389 "Display routes matching the communities\n"
9390 "community number\n"
9391 "Do not send outside local AS (well-known community)\n"
9392 "Do not advertise to any peer (well-known community)\n"
9393 "Do not export to next AS (well-known community)\n"
9394 "community number\n"
9395 "Do not send outside local AS (well-known community)\n"
9396 "Do not advertise to any peer (well-known community)\n"
9397 "Do not export to next AS (well-known community)\n"
9398 "Exact match of the communities")
9399
9400ALIAS (show_ip_bgp_community_exact,
9401 show_ip_bgp_community3_exact_cmd,
9402 "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",
9403 SHOW_STR
9404 IP_STR
9405 BGP_STR
9406 "Display routes matching the communities\n"
9407 "community number\n"
9408 "Do not send outside local AS (well-known community)\n"
9409 "Do not advertise to any peer (well-known community)\n"
9410 "Do not export to next AS (well-known community)\n"
9411 "community number\n"
9412 "Do not send outside local AS (well-known community)\n"
9413 "Do not advertise to any peer (well-known community)\n"
9414 "Do not export to next AS (well-known community)\n"
9415 "community number\n"
9416 "Do not send outside local AS (well-known community)\n"
9417 "Do not advertise to any peer (well-known community)\n"
9418 "Do not export to next AS (well-known community)\n"
9419 "Exact match of the communities")
9420
9421ALIAS (show_ip_bgp_community_exact,
9422 show_ip_bgp_community4_exact_cmd,
9423 "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",
9424 SHOW_STR
9425 IP_STR
9426 BGP_STR
9427 "Display routes matching the communities\n"
9428 "community number\n"
9429 "Do not send outside local AS (well-known community)\n"
9430 "Do not advertise to any peer (well-known community)\n"
9431 "Do not export to next AS (well-known community)\n"
9432 "community number\n"
9433 "Do not send outside local AS (well-known community)\n"
9434 "Do not advertise to any peer (well-known community)\n"
9435 "Do not export to next AS (well-known community)\n"
9436 "community number\n"
9437 "Do not send outside local AS (well-known community)\n"
9438 "Do not advertise to any peer (well-known community)\n"
9439 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
9445
9446DEFUN (show_ip_bgp_ipv4_community_exact,
9447 show_ip_bgp_ipv4_community_exact_cmd,
9448 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9449 SHOW_STR
9450 IP_STR
9451 BGP_STR
9452 "Address family\n"
9453 "Address Family modifier\n"
9454 "Address Family modifier\n"
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 "Exact match of the communities")
9461{
9462 if (strncmp (argv[0], "m", 1) == 0)
9463 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
9464
9465 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9466}
9467
9468ALIAS (show_ip_bgp_ipv4_community_exact,
9469 show_ip_bgp_ipv4_community2_exact_cmd,
9470 "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",
9471 SHOW_STR
9472 IP_STR
9473 BGP_STR
9474 "Address family\n"
9475 "Address Family modifier\n"
9476 "Address Family modifier\n"
9477 "Display routes matching the communities\n"
9478 "community number\n"
9479 "Do not send outside local AS (well-known community)\n"
9480 "Do not advertise to any peer (well-known community)\n"
9481 "Do not export to next AS (well-known community)\n"
9482 "community number\n"
9483 "Do not send outside local AS (well-known community)\n"
9484 "Do not advertise to any peer (well-known community)\n"
9485 "Do not export to next AS (well-known community)\n"
9486 "Exact match of the communities")
9487
9488ALIAS (show_ip_bgp_ipv4_community_exact,
9489 show_ip_bgp_ipv4_community3_exact_cmd,
9490 "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",
9491 SHOW_STR
9492 IP_STR
9493 BGP_STR
9494 "Address family\n"
9495 "Address Family modifier\n"
9496 "Address Family modifier\n"
9497 "Display routes matching the communities\n"
9498 "community number\n"
9499 "Do not send outside local AS (well-known community)\n"
9500 "Do not advertise to any peer (well-known community)\n"
9501 "Do not export to next AS (well-known community)\n"
9502 "community number\n"
9503 "Do not send outside local AS (well-known community)\n"
9504 "Do not advertise to any peer (well-known community)\n"
9505 "Do not export to next AS (well-known community)\n"
9506 "community number\n"
9507 "Do not send outside local AS (well-known community)\n"
9508 "Do not advertise to any peer (well-known community)\n"
9509 "Do not export to next AS (well-known community)\n"
9510 "Exact match of the communities")
9511
9512ALIAS (show_ip_bgp_ipv4_community_exact,
9513 show_ip_bgp_ipv4_community4_exact_cmd,
9514 "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",
9515 SHOW_STR
9516 IP_STR
9517 BGP_STR
9518 "Address family\n"
9519 "Address Family modifier\n"
9520 "Address Family modifier\n"
9521 "Display routes matching the communities\n"
9522 "community number\n"
9523 "Do not send outside local AS (well-known community)\n"
9524 "Do not advertise to any peer (well-known community)\n"
9525 "Do not export to next AS (well-known community)\n"
9526 "community number\n"
9527 "Do not send outside local AS (well-known community)\n"
9528 "Do not advertise to any peer (well-known community)\n"
9529 "Do not export to next AS (well-known community)\n"
9530 "community number\n"
9531 "Do not send outside local AS (well-known community)\n"
9532 "Do not advertise to any peer (well-known community)\n"
9533 "Do not export to next AS (well-known community)\n"
9534 "community number\n"
9535 "Do not send outside local AS (well-known community)\n"
9536 "Do not advertise to any peer (well-known community)\n"
9537 "Do not export to next AS (well-known community)\n"
9538 "Exact match of the communities")
9539
Lou Bergerf9b6c392016-01-12 13:42:09 -05009540DEFUN (show_bgp_community,
9541 show_bgp_community_cmd,
9542 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
9543 SHOW_STR
9544 BGP_STR
9545 "Display routes matching the communities\n"
9546 "community number\n"
9547 "Do not send outside local AS (well-known community)\n"
9548 "Do not advertise to any peer (well-known community)\n"
9549 "Do not export to next AS (well-known community)\n")
9550{
9551 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9552}
9553
9554ALIAS (show_bgp_community,
9555 show_bgp_ipv6_community_cmd,
9556 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
9557 SHOW_STR
9558 BGP_STR
9559 "Address family\n"
9560 "Display routes matching the communities\n"
9561 "community number\n"
9562 "Do not send outside local AS (well-known community)\n"
9563 "Do not advertise to any peer (well-known community)\n"
9564 "Do not export to next AS (well-known community)\n")
9565
9566ALIAS (show_bgp_community,
9567 show_bgp_community2_cmd,
9568 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9569 SHOW_STR
9570 BGP_STR
9571 "Display routes matching the communities\n"
9572 "community number\n"
9573 "Do not send outside local AS (well-known community)\n"
9574 "Do not advertise to any peer (well-known community)\n"
9575 "Do not export to next AS (well-known community)\n"
9576 "community number\n"
9577 "Do not send outside local AS (well-known community)\n"
9578 "Do not advertise to any peer (well-known community)\n"
9579 "Do not export to next AS (well-known community)\n")
9580
9581ALIAS (show_bgp_community,
9582 show_bgp_ipv6_community2_cmd,
9583 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9584 SHOW_STR
9585 BGP_STR
9586 "Address family\n"
9587 "Display routes matching the communities\n"
9588 "community number\n"
9589 "Do not send outside local AS (well-known community)\n"
9590 "Do not advertise to any peer (well-known community)\n"
9591 "Do not export to next AS (well-known community)\n"
9592 "community number\n"
9593 "Do not send outside local AS (well-known community)\n"
9594 "Do not advertise to any peer (well-known community)\n"
9595 "Do not export to next AS (well-known community)\n")
9596
9597ALIAS (show_bgp_community,
9598 show_bgp_community3_cmd,
9599 "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)",
9600 SHOW_STR
9601 BGP_STR
9602 "Display routes matching the communities\n"
9603 "community number\n"
9604 "Do not send outside local AS (well-known community)\n"
9605 "Do not advertise to any peer (well-known community)\n"
9606 "Do not export to next AS (well-known community)\n"
9607 "community number\n"
9608 "Do not send outside local AS (well-known community)\n"
9609 "Do not advertise to any peer (well-known community)\n"
9610 "Do not export to next AS (well-known community)\n"
9611 "community number\n"
9612 "Do not send outside local AS (well-known community)\n"
9613 "Do not advertise to any peer (well-known community)\n"
9614 "Do not export to next AS (well-known community)\n")
9615
9616ALIAS (show_bgp_community,
9617 show_bgp_ipv6_community3_cmd,
9618 "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)",
9619 SHOW_STR
9620 BGP_STR
9621 "Address family\n"
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
9636ALIAS (show_bgp_community,
9637 show_bgp_community4_cmd,
9638 "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)",
9639 SHOW_STR
9640 BGP_STR
9641 "Display routes matching the communities\n"
9642 "community number\n"
9643 "Do not send outside local AS (well-known community)\n"
9644 "Do not advertise to any peer (well-known community)\n"
9645 "Do not export to next AS (well-known community)\n"
9646 "community number\n"
9647 "Do not send outside local AS (well-known community)\n"
9648 "Do not advertise to any peer (well-known community)\n"
9649 "Do not export to next AS (well-known community)\n"
9650 "community number\n"
9651 "Do not send outside local AS (well-known community)\n"
9652 "Do not advertise to any peer (well-known community)\n"
9653 "Do not export to next AS (well-known community)\n"
9654 "community number\n"
9655 "Do not send outside local AS (well-known community)\n"
9656 "Do not advertise to any peer (well-known community)\n"
9657 "Do not export to next AS (well-known community)\n")
9658
9659ALIAS (show_bgp_community,
9660 show_bgp_ipv6_community4_cmd,
9661 "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)",
9662 SHOW_STR
9663 BGP_STR
9664 "Address family\n"
9665 "Display routes matching the communities\n"
9666 "community number\n"
9667 "Do not send outside local AS (well-known community)\n"
9668 "Do not advertise to any peer (well-known community)\n"
9669 "Do not export to next AS (well-known community)\n"
9670 "community number\n"
9671 "Do not send outside local AS (well-known community)\n"
9672 "Do not advertise to any peer (well-known community)\n"
9673 "Do not export to next AS (well-known community)\n"
9674 "community number\n"
9675 "Do not send outside local AS (well-known community)\n"
9676 "Do not advertise to any peer (well-known community)\n"
9677 "Do not export to next AS (well-known community)\n"
9678 "community number\n"
9679 "Do not send outside local AS (well-known community)\n"
9680 "Do not advertise to any peer (well-known community)\n"
9681 "Do not export to next AS (well-known community)\n")
9682
9683/* old command */
9684DEFUN (show_ipv6_bgp_community,
9685 show_ipv6_bgp_community_cmd,
9686 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
9687 SHOW_STR
9688 IPV6_STR
9689 BGP_STR
9690 "Display routes matching the communities\n"
9691 "community number\n"
9692 "Do not send outside local AS (well-known community)\n"
9693 "Do not advertise to any peer (well-known community)\n"
9694 "Do not export to next AS (well-known community)\n")
9695{
9696 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9697}
9698
9699/* old command */
9700ALIAS (show_ipv6_bgp_community,
9701 show_ipv6_bgp_community2_cmd,
9702 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9703 SHOW_STR
9704 IPV6_STR
9705 BGP_STR
9706 "Display routes matching the communities\n"
9707 "community number\n"
9708 "Do not send outside local AS (well-known community)\n"
9709 "Do not advertise to any peer (well-known community)\n"
9710 "Do not export to next AS (well-known community)\n"
9711 "community number\n"
9712 "Do not send outside local AS (well-known community)\n"
9713 "Do not advertise to any peer (well-known community)\n"
9714 "Do not export to next AS (well-known community)\n")
9715
9716/* old command */
9717ALIAS (show_ipv6_bgp_community,
9718 show_ipv6_bgp_community3_cmd,
9719 "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)",
9720 SHOW_STR
9721 IPV6_STR
9722 BGP_STR
9723 "Display routes matching the communities\n"
9724 "community number\n"
9725 "Do not send outside local AS (well-known community)\n"
9726 "Do not advertise to any peer (well-known community)\n"
9727 "Do not export to next AS (well-known community)\n"
9728 "community number\n"
9729 "Do not send outside local AS (well-known community)\n"
9730 "Do not advertise to any peer (well-known community)\n"
9731 "Do not export to next AS (well-known community)\n"
9732 "community number\n"
9733 "Do not send outside local AS (well-known community)\n"
9734 "Do not advertise to any peer (well-known community)\n"
9735 "Do not export to next AS (well-known community)\n")
9736
9737/* old command */
9738ALIAS (show_ipv6_bgp_community,
9739 show_ipv6_bgp_community4_cmd,
9740 "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)",
9741 SHOW_STR
9742 IPV6_STR
9743 BGP_STR
9744 "Display routes matching the communities\n"
9745 "community number\n"
9746 "Do not send outside local AS (well-known community)\n"
9747 "Do not advertise to any peer (well-known community)\n"
9748 "Do not export to next AS (well-known community)\n"
9749 "community number\n"
9750 "Do not send outside local AS (well-known community)\n"
9751 "Do not advertise to any peer (well-known community)\n"
9752 "Do not export to next AS (well-known community)\n"
9753 "community number\n"
9754 "Do not send outside local AS (well-known community)\n"
9755 "Do not advertise to any peer (well-known community)\n"
9756 "Do not export to next AS (well-known community)\n"
9757 "community number\n"
9758 "Do not send outside local AS (well-known community)\n"
9759 "Do not advertise to any peer (well-known community)\n"
9760 "Do not export to next AS (well-known community)\n")
9761
9762DEFUN (show_bgp_community_exact,
9763 show_bgp_community_exact_cmd,
9764 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9765 SHOW_STR
9766 BGP_STR
9767 "Display routes matching the communities\n"
9768 "community number\n"
9769 "Do not send outside local AS (well-known community)\n"
9770 "Do not advertise to any peer (well-known community)\n"
9771 "Do not export to next AS (well-known community)\n"
9772 "Exact match of the communities")
9773{
9774 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
9775}
9776
9777ALIAS (show_bgp_community_exact,
9778 show_bgp_ipv6_community_exact_cmd,
9779 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9780 SHOW_STR
9781 BGP_STR
9782 "Address family\n"
9783 "Display routes matching the communities\n"
9784 "community number\n"
9785 "Do not send outside local AS (well-known community)\n"
9786 "Do not advertise to any peer (well-known community)\n"
9787 "Do not export to next AS (well-known community)\n"
9788 "Exact match of the communities")
9789
9790ALIAS (show_bgp_community_exact,
9791 show_bgp_community2_exact_cmd,
9792 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9793 SHOW_STR
9794 BGP_STR
9795 "Display routes matching the communities\n"
9796 "community number\n"
9797 "Do not send outside local AS (well-known community)\n"
9798 "Do not advertise to any peer (well-known community)\n"
9799 "Do not export to next AS (well-known community)\n"
9800 "community number\n"
9801 "Do not send outside local AS (well-known community)\n"
9802 "Do not advertise to any peer (well-known community)\n"
9803 "Do not export to next AS (well-known community)\n"
9804 "Exact match of the communities")
9805
9806ALIAS (show_bgp_community_exact,
9807 show_bgp_ipv6_community2_exact_cmd,
9808 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9809 SHOW_STR
9810 BGP_STR
9811 "Address family\n"
9812 "Display routes matching the communities\n"
9813 "community number\n"
9814 "Do not send outside local AS (well-known community)\n"
9815 "Do not advertise to any peer (well-known community)\n"
9816 "Do not export to next AS (well-known community)\n"
9817 "community number\n"
9818 "Do not send outside local AS (well-known community)\n"
9819 "Do not advertise to any peer (well-known community)\n"
9820 "Do not export to next AS (well-known community)\n"
9821 "Exact match of the communities")
9822
9823ALIAS (show_bgp_community_exact,
9824 show_bgp_community3_exact_cmd,
9825 "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",
9826 SHOW_STR
9827 BGP_STR
9828 "Display routes matching the communities\n"
9829 "community number\n"
9830 "Do not send outside local AS (well-known community)\n"
9831 "Do not advertise to any peer (well-known community)\n"
9832 "Do not export to next AS (well-known community)\n"
9833 "community number\n"
9834 "Do not send outside local AS (well-known community)\n"
9835 "Do not advertise to any peer (well-known community)\n"
9836 "Do not export to next AS (well-known community)\n"
9837 "community number\n"
9838 "Do not send outside local AS (well-known community)\n"
9839 "Do not advertise to any peer (well-known community)\n"
9840 "Do not export to next AS (well-known community)\n"
9841 "Exact match of the communities")
9842
9843ALIAS (show_bgp_community_exact,
9844 show_bgp_ipv6_community3_exact_cmd,
9845 "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",
9846 SHOW_STR
9847 BGP_STR
9848 "Address family\n"
9849 "Display routes matching the communities\n"
9850 "community number\n"
9851 "Do not send outside local AS (well-known community)\n"
9852 "Do not advertise to any peer (well-known community)\n"
9853 "Do not export to next AS (well-known community)\n"
9854 "community number\n"
9855 "Do not send outside local AS (well-known community)\n"
9856 "Do not advertise to any peer (well-known community)\n"
9857 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
9863
9864ALIAS (show_bgp_community_exact,
9865 show_bgp_community4_exact_cmd,
9866 "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",
9867 SHOW_STR
9868 BGP_STR
9869 "Display routes matching the communities\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 "community number\n"
9875 "Do not send outside local AS (well-known community)\n"
9876 "Do not advertise to any peer (well-known community)\n"
9877 "Do not export to next AS (well-known community)\n"
9878 "community number\n"
9879 "Do not send outside local AS (well-known community)\n"
9880 "Do not advertise to any peer (well-known community)\n"
9881 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
9887
9888ALIAS (show_bgp_community_exact,
9889 show_bgp_ipv6_community4_exact_cmd,
9890 "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",
9891 SHOW_STR
9892 BGP_STR
9893 "Address family\n"
9894 "Display routes matching the communities\n"
9895 "community number\n"
9896 "Do not send outside local AS (well-known community)\n"
9897 "Do not advertise to any peer (well-known community)\n"
9898 "Do not export to next AS (well-known community)\n"
9899 "community number\n"
9900 "Do not send outside local AS (well-known community)\n"
9901 "Do not advertise to any peer (well-known community)\n"
9902 "Do not export to next AS (well-known community)\n"
9903 "community number\n"
9904 "Do not send outside local AS (well-known community)\n"
9905 "Do not advertise to any peer (well-known community)\n"
9906 "Do not export to next AS (well-known community)\n"
9907 "community number\n"
9908 "Do not send outside local AS (well-known community)\n"
9909 "Do not advertise to any peer (well-known community)\n"
9910 "Do not export to next AS (well-known community)\n"
9911 "Exact match of the communities")
9912
9913/* old command */
9914DEFUN (show_ipv6_bgp_community_exact,
9915 show_ipv6_bgp_community_exact_cmd,
9916 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9917 SHOW_STR
9918 IPV6_STR
9919 BGP_STR
9920 "Display routes matching the communities\n"
9921 "community number\n"
9922 "Do not send outside local AS (well-known community)\n"
9923 "Do not advertise to any peer (well-known community)\n"
9924 "Do not export to next AS (well-known community)\n"
9925 "Exact match of the communities")
9926{
9927 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
9928}
9929
9930/* old command */
9931ALIAS (show_ipv6_bgp_community_exact,
9932 show_ipv6_bgp_community2_exact_cmd,
9933 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9934 SHOW_STR
9935 IPV6_STR
9936 BGP_STR
9937 "Display routes matching the communities\n"
9938 "community number\n"
9939 "Do not send outside local AS (well-known community)\n"
9940 "Do not advertise to any peer (well-known community)\n"
9941 "Do not export to next AS (well-known community)\n"
9942 "community number\n"
9943 "Do not send outside local AS (well-known community)\n"
9944 "Do not advertise to any peer (well-known community)\n"
9945 "Do not export to next AS (well-known community)\n"
9946 "Exact match of the communities")
9947
9948/* old command */
9949ALIAS (show_ipv6_bgp_community_exact,
9950 show_ipv6_bgp_community3_exact_cmd,
9951 "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",
9952 SHOW_STR
9953 IPV6_STR
9954 BGP_STR
9955 "Display routes matching the communities\n"
9956 "community number\n"
9957 "Do not send outside local AS (well-known community)\n"
9958 "Do not advertise to any peer (well-known community)\n"
9959 "Do not export to next AS (well-known community)\n"
9960 "community number\n"
9961 "Do not send outside local AS (well-known community)\n"
9962 "Do not advertise to any peer (well-known community)\n"
9963 "Do not export to next AS (well-known community)\n"
9964 "community number\n"
9965 "Do not send outside local AS (well-known community)\n"
9966 "Do not advertise to any peer (well-known community)\n"
9967 "Do not export to next AS (well-known community)\n"
9968 "Exact match of the communities")
9969
9970/* old command */
9971ALIAS (show_ipv6_bgp_community_exact,
9972 show_ipv6_bgp_community4_exact_cmd,
9973 "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",
9974 SHOW_STR
9975 IPV6_STR
9976 BGP_STR
9977 "Display routes matching the communities\n"
9978 "community number\n"
9979 "Do not send outside local AS (well-known community)\n"
9980 "Do not advertise to any peer (well-known community)\n"
9981 "Do not export to next AS (well-known community)\n"
9982 "community number\n"
9983 "Do not send outside local AS (well-known community)\n"
9984 "Do not advertise to any peer (well-known community)\n"
9985 "Do not export to next AS (well-known community)\n"
9986 "community number\n"
9987 "Do not send outside local AS (well-known community)\n"
9988 "Do not advertise to any peer (well-known community)\n"
9989 "Do not export to next AS (well-known community)\n"
9990 "community number\n"
9991 "Do not send outside local AS (well-known community)\n"
9992 "Do not advertise to any peer (well-known community)\n"
9993 "Do not export to next AS (well-known community)\n"
9994 "Exact match of the communities")
9995
9996/* old command */
9997DEFUN (show_ipv6_mbgp_community,
9998 show_ipv6_mbgp_community_cmd,
9999 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
10000 SHOW_STR
10001 IPV6_STR
10002 MBGP_STR
10003 "Display routes matching the communities\n"
10004 "community number\n"
10005 "Do not send outside local AS (well-known community)\n"
10006 "Do not advertise to any peer (well-known community)\n"
10007 "Do not export to next AS (well-known community)\n")
10008{
10009 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
10010}
10011
10012/* old command */
10013ALIAS (show_ipv6_mbgp_community,
10014 show_ipv6_mbgp_community2_cmd,
10015 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10016 SHOW_STR
10017 IPV6_STR
10018 MBGP_STR
10019 "Display routes matching the communities\n"
10020 "community number\n"
10021 "Do not send outside local AS (well-known community)\n"
10022 "Do not advertise to any peer (well-known community)\n"
10023 "Do not export to next AS (well-known community)\n"
10024 "community number\n"
10025 "Do not send outside local AS (well-known community)\n"
10026 "Do not advertise to any peer (well-known community)\n"
10027 "Do not export to next AS (well-known community)\n")
10028
10029/* old command */
10030ALIAS (show_ipv6_mbgp_community,
10031 show_ipv6_mbgp_community3_cmd,
10032 "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)",
10033 SHOW_STR
10034 IPV6_STR
10035 MBGP_STR
10036 "Display routes matching the communities\n"
10037 "community number\n"
10038 "Do not send outside local AS (well-known community)\n"
10039 "Do not advertise to any peer (well-known community)\n"
10040 "Do not export to next AS (well-known community)\n"
10041 "community number\n"
10042 "Do not send outside local AS (well-known community)\n"
10043 "Do not advertise to any peer (well-known community)\n"
10044 "Do not export to next AS (well-known community)\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
10050/* old command */
10051ALIAS (show_ipv6_mbgp_community,
10052 show_ipv6_mbgp_community4_cmd,
10053 "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)",
10054 SHOW_STR
10055 IPV6_STR
10056 MBGP_STR
10057 "Display routes matching the communities\n"
10058 "community number\n"
10059 "Do not send outside local AS (well-known community)\n"
10060 "Do not advertise to any peer (well-known community)\n"
10061 "Do not export to next AS (well-known community)\n"
10062 "community number\n"
10063 "Do not send outside local AS (well-known community)\n"
10064 "Do not advertise to any peer (well-known community)\n"
10065 "Do not export to next AS (well-known community)\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
10075/* old command */
10076DEFUN (show_ipv6_mbgp_community_exact,
10077 show_ipv6_mbgp_community_exact_cmd,
10078 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10079 SHOW_STR
10080 IPV6_STR
10081 MBGP_STR
10082 "Display routes matching the communities\n"
10083 "community number\n"
10084 "Do not send outside local AS (well-known community)\n"
10085 "Do not advertise to any peer (well-known community)\n"
10086 "Do not export to next AS (well-known community)\n"
10087 "Exact match of the communities")
10088{
10089 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
10090}
10091
10092/* old command */
10093ALIAS (show_ipv6_mbgp_community_exact,
10094 show_ipv6_mbgp_community2_exact_cmd,
10095 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10096 SHOW_STR
10097 IPV6_STR
10098 MBGP_STR
10099 "Display routes matching the communities\n"
10100 "community number\n"
10101 "Do not send outside local AS (well-known community)\n"
10102 "Do not advertise to any peer (well-known community)\n"
10103 "Do not export to next AS (well-known community)\n"
10104 "community number\n"
10105 "Do not send outside local AS (well-known community)\n"
10106 "Do not advertise to any peer (well-known community)\n"
10107 "Do not export to next AS (well-known community)\n"
10108 "Exact match of the communities")
10109
10110/* old command */
10111ALIAS (show_ipv6_mbgp_community_exact,
10112 show_ipv6_mbgp_community3_exact_cmd,
10113 "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",
10114 SHOW_STR
10115 IPV6_STR
10116 MBGP_STR
10117 "Display routes matching the communities\n"
10118 "community number\n"
10119 "Do not send outside local AS (well-known community)\n"
10120 "Do not advertise to any peer (well-known community)\n"
10121 "Do not export to next AS (well-known community)\n"
10122 "community number\n"
10123 "Do not send outside local AS (well-known community)\n"
10124 "Do not advertise to any peer (well-known community)\n"
10125 "Do not export to next AS (well-known community)\n"
10126 "community number\n"
10127 "Do not send outside local AS (well-known community)\n"
10128 "Do not advertise to any peer (well-known community)\n"
10129 "Do not export to next AS (well-known community)\n"
10130 "Exact match of the communities")
10131
10132/* old command */
10133ALIAS (show_ipv6_mbgp_community_exact,
10134 show_ipv6_mbgp_community4_exact_cmd,
10135 "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",
10136 SHOW_STR
10137 IPV6_STR
10138 MBGP_STR
10139 "Display routes matching the communities\n"
10140 "community number\n"
10141 "Do not send outside local AS (well-known community)\n"
10142 "Do not advertise to any peer (well-known community)\n"
10143 "Do not export to next AS (well-known community)\n"
10144 "community number\n"
10145 "Do not send outside local AS (well-known community)\n"
10146 "Do not advertise to any peer (well-known community)\n"
10147 "Do not export to next AS (well-known community)\n"
10148 "community number\n"
10149 "Do not send outside local AS (well-known community)\n"
10150 "Do not advertise to any peer (well-known community)\n"
10151 "Do not export to next AS (well-known community)\n"
10152 "community number\n"
10153 "Do not send outside local AS (well-known community)\n"
10154 "Do not advertise to any peer (well-known community)\n"
10155 "Do not export to next AS (well-known community)\n"
10156 "Exact match of the communities")
Lou Bergerf9b6c392016-01-12 13:42:09 -050010157
Lou Berger651b4022016-01-12 13:42:07 -050010158DEFUN (show_bgp_ipv4_community,
10159 show_bgp_ipv4_community_cmd,
10160 "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010161 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010162 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010163 IP_STR
paul718e3742002-12-13 20:15:29 +000010164 "Display routes matching the communities\n"
10165 "community number\n"
10166 "Do not send outside local AS (well-known community)\n"
10167 "Do not advertise to any peer (well-known community)\n"
10168 "Do not export to next AS (well-known community)\n")
10169{
Michael Lambert95cbbd22010-07-23 14:43:04 -040010170 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010171}
10172
Lou Berger651b4022016-01-12 13:42:07 -050010173ALIAS (show_bgp_ipv4_community,
10174 show_bgp_ipv4_community2_cmd,
10175 "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 +000010176 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010177 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010178 IP_STR
paul718e3742002-12-13 20:15:29 +000010179 "Display routes matching the communities\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 "community number\n"
10185 "Do not send outside local AS (well-known community)\n"
10186 "Do not advertise to any peer (well-known community)\n"
10187 "Do not export to next AS (well-known community)\n")
10188
Lou Berger651b4022016-01-12 13:42:07 -050010189ALIAS (show_bgp_ipv4_community,
10190 show_bgp_ipv4_community3_cmd,
10191 "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 +000010192 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010193 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010194 IP_STR
paul718e3742002-12-13 20:15:29 +000010195 "Display routes matching the communities\n"
10196 "community number\n"
10197 "Do not send outside local AS (well-known community)\n"
10198 "Do not advertise to any peer (well-known community)\n"
10199 "Do not export to next AS (well-known community)\n"
10200 "community number\n"
10201 "Do not send outside local AS (well-known community)\n"
10202 "Do not advertise to any peer (well-known community)\n"
10203 "Do not export to next AS (well-known community)\n"
10204 "community number\n"
10205 "Do not send outside local AS (well-known community)\n"
10206 "Do not advertise to any peer (well-known community)\n"
10207 "Do not export to next AS (well-known community)\n")
10208
Lou Berger651b4022016-01-12 13:42:07 -050010209ALIAS (show_bgp_ipv4_community,
10210 show_bgp_ipv4_community4_cmd,
10211 "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 +000010212 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010213 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010214 IP_STR
paul718e3742002-12-13 20:15:29 +000010215 "Display routes matching the communities\n"
10216 "community number\n"
10217 "Do not send outside local AS (well-known community)\n"
10218 "Do not advertise to any peer (well-known community)\n"
10219 "Do not export to next AS (well-known community)\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 "community number\n"
10225 "Do not send outside local AS (well-known community)\n"
10226 "Do not advertise to any peer (well-known community)\n"
10227 "Do not export to next AS (well-known community)\n"
10228 "community number\n"
10229 "Do not send outside local AS (well-known community)\n"
10230 "Do not advertise to any peer (well-known community)\n"
10231 "Do not export to next AS (well-known community)\n")
10232
Lou Berger651b4022016-01-12 13:42:07 -050010233DEFUN (show_bgp_ipv4_safi_community,
10234 show_bgp_ipv4_safi_community_cmd,
10235 "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010236 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010237 BGP_STR
10238 "Address family\n"
10239 "Address Family modifier\n"
10240 "Address Family modifier\n"
10241 "Display routes matching the communities\n"
10242 "community number\n"
10243 "Do not send outside local AS (well-known community)\n"
10244 "Do not advertise to any peer (well-known community)\n"
10245 "Do not export to next AS (well-known community)\n")
10246{
10247 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -040010248 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +000010249
Michael Lambert95cbbd22010-07-23 14:43:04 -040010250 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010251}
10252
Lou Berger651b4022016-01-12 13:42:07 -050010253ALIAS (show_bgp_ipv4_safi_community,
10254 show_bgp_ipv4_safi_community2_cmd,
10255 "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 +000010256 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010257 BGP_STR
10258 "Address family\n"
10259 "Address Family modifier\n"
10260 "Address Family modifier\n"
10261 "Display routes matching the communities\n"
10262 "community number\n"
10263 "Do not send outside local AS (well-known community)\n"
10264 "Do not advertise to any peer (well-known community)\n"
10265 "Do not export to next AS (well-known community)\n"
10266 "community number\n"
10267 "Do not send outside local AS (well-known community)\n"
10268 "Do not advertise to any peer (well-known community)\n"
10269 "Do not export to next AS (well-known community)\n")
10270
Lou Berger651b4022016-01-12 13:42:07 -050010271ALIAS (show_bgp_ipv4_safi_community,
10272 show_bgp_ipv4_safi_community3_cmd,
10273 "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 +000010274 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010275 BGP_STR
10276 "Address family\n"
10277 "Address Family modifier\n"
10278 "Address Family modifier\n"
10279 "Display routes matching the communities\n"
10280 "community number\n"
10281 "Do not send outside local AS (well-known community)\n"
10282 "Do not advertise to any peer (well-known community)\n"
10283 "Do not export to next AS (well-known community)\n"
10284 "community number\n"
10285 "Do not send outside local AS (well-known community)\n"
10286 "Do not advertise to any peer (well-known community)\n"
10287 "Do not export to next AS (well-known community)\n"
10288 "community number\n"
10289 "Do not send outside local AS (well-known community)\n"
10290 "Do not advertise to any peer (well-known community)\n"
10291 "Do not export to next AS (well-known community)\n")
10292
Lou Berger651b4022016-01-12 13:42:07 -050010293ALIAS (show_bgp_ipv4_safi_community,
10294 show_bgp_ipv4_safi_community4_cmd,
10295 "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 +000010296 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010297 BGP_STR
10298 "Address family\n"
10299 "Address Family modifier\n"
10300 "Address Family modifier\n"
10301 "Display routes matching the communities\n"
10302 "community number\n"
10303 "Do not send outside local AS (well-known community)\n"
10304 "Do not advertise to any peer (well-known community)\n"
10305 "Do not export to next AS (well-known community)\n"
10306 "community number\n"
10307 "Do not send outside local AS (well-known community)\n"
10308 "Do not advertise to any peer (well-known community)\n"
10309 "Do not export to next AS (well-known community)\n"
10310 "community number\n"
10311 "Do not send outside local AS (well-known community)\n"
10312 "Do not advertise to any peer (well-known community)\n"
10313 "Do not export to next AS (well-known community)\n"
10314 "community number\n"
10315 "Do not send outside local AS (well-known community)\n"
10316 "Do not advertise to any peer (well-known community)\n"
10317 "Do not export to next AS (well-known community)\n")
10318
Michael Lambert95cbbd22010-07-23 14:43:04 -040010319DEFUN (show_bgp_view_afi_safi_community_all,
10320 show_bgp_view_afi_safi_community_all_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010321 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Michael Lambert95cbbd22010-07-23 14:43:04 -040010322 SHOW_STR
10323 BGP_STR
10324 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010325 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010326 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010327 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010328 "Address Family modifier\n"
10329 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +000010330 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -040010331{
10332 int afi;
10333 int safi;
10334 struct bgp *bgp;
10335
10336 /* BGP structure lookup. */
10337 bgp = bgp_lookup_by_name (argv[0]);
10338 if (bgp == NULL)
10339 {
10340 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10341 return CMD_WARNING;
10342 }
10343
Michael Lambert95cbbd22010-07-23 14:43:04 -040010344 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10345 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010346 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
10347}
10348
10349DEFUN (show_bgp_view_afi_safi_community,
10350 show_bgp_view_afi_safi_community_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010351 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -040010352 SHOW_STR
10353 BGP_STR
10354 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010355 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010356 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010357 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010358 "Address family modifier\n"
10359 "Address family modifier\n"
10360 "Display routes matching the communities\n"
10361 "community number\n"
10362 "Do not send outside local AS (well-known community)\n"
10363 "Do not advertise to any peer (well-known community)\n"
10364 "Do not export to next AS (well-known community)\n")
10365{
10366 int afi;
10367 int safi;
10368
Michael Lambert95cbbd22010-07-23 14:43:04 -040010369 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10370 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10371 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010372}
10373
10374ALIAS (show_bgp_view_afi_safi_community,
10375 show_bgp_view_afi_safi_community2_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010376 "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 -040010377 SHOW_STR
10378 BGP_STR
10379 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010380 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010381 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010382 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010383 "Address family modifier\n"
10384 "Address family modifier\n"
10385 "Display routes matching the communities\n"
10386 "community number\n"
10387 "Do not send outside local AS (well-known community)\n"
10388 "Do not advertise to any peer (well-known community)\n"
10389 "Do not export to next AS (well-known community)\n"
10390 "community number\n"
10391 "Do not send outside local AS (well-known community)\n"
10392 "Do not advertise to any peer (well-known community)\n"
10393 "Do not export to next AS (well-known community)\n")
10394
10395ALIAS (show_bgp_view_afi_safi_community,
10396 show_bgp_view_afi_safi_community3_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010397 "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 -040010398 SHOW_STR
10399 BGP_STR
10400 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010401 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010402 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010403 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010404 "Address family modifier\n"
10405 "Address family modifier\n"
10406 "Display routes matching the communities\n"
10407 "community number\n"
10408 "Do not send outside local AS (well-known community)\n"
10409 "Do not advertise to any peer (well-known community)\n"
10410 "Do not export to next AS (well-known community)\n"
10411 "community number\n"
10412 "Do not send outside local AS (well-known community)\n"
10413 "Do not advertise to any peer (well-known community)\n"
10414 "Do not export to next AS (well-known community)\n"
10415 "community number\n"
10416 "Do not send outside local AS (well-known community)\n"
10417 "Do not advertise to any peer (well-known community)\n"
10418 "Do not export to next AS (well-known community)\n")
10419
10420ALIAS (show_bgp_view_afi_safi_community,
10421 show_bgp_view_afi_safi_community4_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010422 "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 -040010423 SHOW_STR
10424 BGP_STR
10425 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010426 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010427 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010428 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010429 "Address family modifier\n"
10430 "Address family modifier\n"
10431 "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_community_exact,
10450 show_bgp_ipv4_community_exact_cmd,
10451 "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010452 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010453 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010454 IP_STR
paul718e3742002-12-13 20:15:29 +000010455 "Display routes matching the communities\n"
10456 "community number\n"
10457 "Do not send outside local AS (well-known community)\n"
10458 "Do not advertise to any peer (well-known community)\n"
10459 "Do not export to next AS (well-known community)\n"
10460 "Exact match of the communities")
10461{
Michael Lambert95cbbd22010-07-23 14:43:04 -040010462 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010463}
10464
Lou Berger651b4022016-01-12 13:42:07 -050010465ALIAS (show_bgp_ipv4_community_exact,
10466 show_bgp_ipv4_community2_exact_cmd,
10467 "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 +000010468 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010469 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010470 IP_STR
paul718e3742002-12-13 20:15:29 +000010471 "Display routes matching the communities\n"
10472 "community number\n"
10473 "Do not send outside local AS (well-known community)\n"
10474 "Do not advertise to any peer (well-known community)\n"
10475 "Do not export to next AS (well-known community)\n"
10476 "community number\n"
10477 "Do not send outside local AS (well-known community)\n"
10478 "Do not advertise to any peer (well-known community)\n"
10479 "Do not export to next AS (well-known community)\n"
10480 "Exact match of the communities")
10481
Lou Berger651b4022016-01-12 13:42:07 -050010482ALIAS (show_bgp_ipv4_community_exact,
10483 show_bgp_ipv4_community3_exact_cmd,
10484 "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 +000010485 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010486 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010487 IP_STR
paul718e3742002-12-13 20:15:29 +000010488 "Display routes matching the communities\n"
10489 "community number\n"
10490 "Do not send outside local AS (well-known community)\n"
10491 "Do not advertise to any peer (well-known community)\n"
10492 "Do not export to next AS (well-known community)\n"
10493 "community number\n"
10494 "Do not send outside local AS (well-known community)\n"
10495 "Do not advertise to any peer (well-known community)\n"
10496 "Do not export to next AS (well-known community)\n"
10497 "community number\n"
10498 "Do not send outside local AS (well-known community)\n"
10499 "Do not advertise to any peer (well-known community)\n"
10500 "Do not export to next AS (well-known community)\n"
10501 "Exact match of the communities")
10502
Lou Berger651b4022016-01-12 13:42:07 -050010503ALIAS (show_bgp_ipv4_community_exact,
10504 show_bgp_ipv4_community4_exact_cmd,
10505 "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 +000010506 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010507 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010508 IP_STR
paul718e3742002-12-13 20:15:29 +000010509 "Display routes matching the communities\n"
10510 "community number\n"
10511 "Do not send outside local AS (well-known community)\n"
10512 "Do not advertise to any peer (well-known community)\n"
10513 "Do not export to next AS (well-known community)\n"
10514 "community number\n"
10515 "Do not send outside local AS (well-known community)\n"
10516 "Do not advertise to any peer (well-known community)\n"
10517 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
10527
Lou Berger651b4022016-01-12 13:42:07 -050010528DEFUN (show_bgp_ipv4_safi_community4_exact,
10529 show_bgp_ipv4_safi_community_exact_cmd,
10530 "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010531 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010532 BGP_STR
10533 "Address family\n"
10534 "Address Family modifier\n"
10535 "Address Family modifier\n"
10536 "Display routes matching the communities\n"
10537 "community number\n"
10538 "Do not send outside local AS (well-known community)\n"
10539 "Do not advertise to any peer (well-known community)\n"
10540 "Do not export to next AS (well-known community)\n"
10541 "Exact match of the communities")
10542{
10543 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -040010544 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +000010545
Michael Lambert95cbbd22010-07-23 14:43:04 -040010546 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010547}
10548
Lou Berger651b4022016-01-12 13:42:07 -050010549ALIAS (show_bgp_ipv4_safi_community4_exact,
10550 show_bgp_ipv4_safi_community2_exact_cmd,
10551 "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 +000010552 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010553 BGP_STR
10554 "Address family\n"
10555 "Address Family modifier\n"
10556 "Address Family modifier\n"
10557 "Display routes matching the communities\n"
10558 "community number\n"
10559 "Do not send outside local AS (well-known community)\n"
10560 "Do not advertise to any peer (well-known community)\n"
10561 "Do not export to next AS (well-known community)\n"
10562 "community number\n"
10563 "Do not send outside local AS (well-known community)\n"
10564 "Do not advertise to any peer (well-known community)\n"
10565 "Do not export to next AS (well-known community)\n"
10566 "Exact match of the communities")
10567
Lou Berger651b4022016-01-12 13:42:07 -050010568ALIAS (show_bgp_ipv4_safi_community4_exact,
10569 show_bgp_ipv4_safi_community3_exact_cmd,
10570 "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 +000010571 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010572 BGP_STR
10573 "Address family\n"
10574 "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 "community number\n"
10582 "Do not send outside local AS (well-known community)\n"
10583 "Do not advertise to any peer (well-known community)\n"
10584 "Do not export to next AS (well-known community)\n"
10585 "community number\n"
10586 "Do not send outside local AS (well-known community)\n"
10587 "Do not advertise to any peer (well-known community)\n"
10588 "Do not export to next AS (well-known community)\n"
10589 "Exact match of the communities")
10590
Lou Berger651b4022016-01-12 13:42:07 -050010591ALIAS (show_bgp_ipv4_safi_community4_exact,
10592 show_bgp_ipv4_safi_community4_exact_cmd,
10593 "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 +000010594 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010595 BGP_STR
10596 "Address family\n"
10597 "Address Family modifier\n"
10598 "Address Family modifier\n"
10599 "Display routes matching the communities\n"
10600 "community number\n"
10601 "Do not send outside local AS (well-known community)\n"
10602 "Do not advertise to any peer (well-known community)\n"
10603 "Do not export to next AS (well-known community)\n"
10604 "community number\n"
10605 "Do not send outside local AS (well-known community)\n"
10606 "Do not advertise to any peer (well-known community)\n"
10607 "Do not export to next AS (well-known community)\n"
10608 "community number\n"
10609 "Do not send outside local AS (well-known community)\n"
10610 "Do not advertise to any peer (well-known community)\n"
10611 "Do not export to next AS (well-known community)\n"
10612 "community number\n"
10613 "Do not send outside local AS (well-known community)\n"
10614 "Do not advertise to any peer (well-known community)\n"
10615 "Do not export to next AS (well-known community)\n"
10616 "Exact match of the communities")
10617
Lou Bergerf9b6c392016-01-12 13:42:09 -050010618DEFUN (show_bgp_ipv6_safi_community,
10619 show_bgp_ipv6_safi_community_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010620 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010621 SHOW_STR
10622 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010623 "Address family\n"
10624 "Address family modifier\n"
10625 "Address family modifier\n"
10626 "Address family modifier\n"
10627 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010628 "Display routes matching the communities\n"
10629 "community number\n"
10630 "Do not send outside local AS (well-known community)\n"
10631 "Do not advertise to any peer (well-known community)\n"
10632 "Do not export to next AS (well-known community)\n")
10633{
Lou Berger651b4022016-01-12 13:42:07 -050010634 safi_t safi;
10635
10636 if (bgp_parse_safi(argv[0], &safi)) {
10637 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10638 return CMD_WARNING;
10639 }
10640 return bgp_show_community (vty, NULL, argc-1, argv+1, 0, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000010641}
10642
Lou Bergerf9b6c392016-01-12 13:42:09 -050010643ALIAS (show_bgp_ipv6_safi_community,
10644 show_bgp_ipv6_safi_community2_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010645 "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 +000010646 SHOW_STR
10647 BGP_STR
10648 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010649 "Address family modifier\n"
10650 "Address family modifier\n"
10651 "Address family modifier\n"
10652 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010653 "Display routes matching the communities\n"
10654 "community number\n"
10655 "Do not send outside local AS (well-known community)\n"
10656 "Do not advertise to any peer (well-known community)\n"
10657 "Do not export to next AS (well-known community)\n"
10658 "community number\n"
10659 "Do not send outside local AS (well-known community)\n"
10660 "Do not advertise to any peer (well-known community)\n"
10661 "Do not export to next AS (well-known community)\n")
10662
Lou Bergerf9b6c392016-01-12 13:42:09 -050010663ALIAS (show_bgp_ipv6_safi_community,
10664 show_bgp_ipv6_safi_community3_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010665 "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 +000010666 SHOW_STR
10667 BGP_STR
10668 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010669 "Address family modifier\n"
10670 "Address family modifier\n"
10671 "Address family modifier\n"
10672 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010673 "Display routes matching the communities\n"
10674 "community number\n"
10675 "Do not send outside local AS (well-known community)\n"
10676 "Do not advertise to any peer (well-known community)\n"
10677 "Do not export to next AS (well-known community)\n"
10678 "community number\n"
10679 "Do not send outside local AS (well-known community)\n"
10680 "Do not advertise to any peer (well-known community)\n"
10681 "Do not export to next AS (well-known community)\n"
10682 "community number\n"
10683 "Do not send outside local AS (well-known community)\n"
10684 "Do not advertise to any peer (well-known community)\n"
10685 "Do not export to next AS (well-known community)\n")
10686
Lou Bergerf9b6c392016-01-12 13:42:09 -050010687ALIAS (show_bgp_ipv6_safi_community,
10688 show_bgp_ipv6_safi_community4_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010689 "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 +000010690 SHOW_STR
10691 BGP_STR
10692 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010693 "Address family modifier\n"
10694 "Address family modifier\n"
10695 "Address family modifier\n"
10696 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010697 "Display routes matching the communities\n"
10698 "community number\n"
10699 "Do not send outside local AS (well-known community)\n"
10700 "Do not advertise to any peer (well-known community)\n"
10701 "Do not export to next AS (well-known community)\n"
10702 "community number\n"
10703 "Do not send outside local AS (well-known community)\n"
10704 "Do not advertise to any peer (well-known community)\n"
10705 "Do not export to next AS (well-known community)\n"
10706 "community number\n"
10707 "Do not send outside local AS (well-known community)\n"
10708 "Do not advertise to any peer (well-known community)\n"
10709 "Do not export to next AS (well-known community)\n"
10710 "community number\n"
10711 "Do not send outside local AS (well-known community)\n"
10712 "Do not advertise to any peer (well-known community)\n"
10713 "Do not export to next AS (well-known community)\n")
10714
paul718e3742002-12-13 20:15:29 +000010715
Lou Bergerf9b6c392016-01-12 13:42:09 -050010716DEFUN (show_bgp_ipv6_safi_community_exact,
10717 show_bgp_ipv6_safi_community_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010718 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010719 SHOW_STR
10720 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010721 "Address family\n"
10722 "Address family modifier\n"
10723 "Address family modifier\n"
10724 "Address family modifier\n"
10725 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010726 "Display routes matching the communities\n"
10727 "community number\n"
10728 "Do not send outside local AS (well-known community)\n"
10729 "Do not advertise to any peer (well-known community)\n"
10730 "Do not export to next AS (well-known community)\n"
10731 "Exact match of the communities")
10732{
Lou Berger651b4022016-01-12 13:42:07 -050010733 safi_t safi;
10734
10735 if (bgp_parse_safi(argv[0], &safi)) {
10736 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10737 return CMD_WARNING;
10738 }
10739 return bgp_show_community (vty, NULL, argc-1, argv+1, 1, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000010740}
10741
paul718e3742002-12-13 20:15:29 +000010742
10743ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010744 show_bgp_ipv6_safi_community2_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010745 "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 +000010746 SHOW_STR
10747 BGP_STR
10748 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010749 "Address family modifier\n"
10750 "Address family modifier\n"
10751 "Address family modifier\n"
10752 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010753 "Display routes matching the communities\n"
10754 "community number\n"
10755 "Do not send outside local AS (well-known community)\n"
10756 "Do not advertise to any peer (well-known community)\n"
10757 "Do not export to next AS (well-known community)\n"
10758 "community number\n"
10759 "Do not send outside local AS (well-known community)\n"
10760 "Do not advertise to any peer (well-known community)\n"
10761 "Do not export to next AS (well-known community)\n"
10762 "Exact match of the communities")
10763
10764ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010765 show_bgp_ipv6_safi_community3_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010766 "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 +000010767 SHOW_STR
10768 BGP_STR
10769 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010770 "Address family modifier\n"
10771 "Address family modifier\n"
10772 "Address family modifier\n"
10773 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010774 "Display routes matching the communities\n"
10775 "community number\n"
10776 "Do not send outside local AS (well-known community)\n"
10777 "Do not advertise to any peer (well-known community)\n"
10778 "Do not export to next AS (well-known community)\n"
10779 "community number\n"
10780 "Do not send outside local AS (well-known community)\n"
10781 "Do not advertise to any peer (well-known community)\n"
10782 "Do not export to next AS (well-known community)\n"
10783 "community number\n"
10784 "Do not send outside local AS (well-known community)\n"
10785 "Do not advertise to any peer (well-known community)\n"
10786 "Do not export to next AS (well-known community)\n"
10787 "Exact match of the communities")
10788
10789ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010790 show_bgp_ipv6_safi_community4_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010791 "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 +000010792 SHOW_STR
10793 BGP_STR
10794 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010795 "Address family modifier\n"
10796 "Address family modifier\n"
10797 "Address family modifier\n"
10798 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010799 "Display routes matching the communities\n"
10800 "community number\n"
10801 "Do not send outside local AS (well-known community)\n"
10802 "Do not advertise to any peer (well-known community)\n"
10803 "Do not export to next AS (well-known community)\n"
10804 "community number\n"
10805 "Do not send outside local AS (well-known community)\n"
10806 "Do not advertise to any peer (well-known community)\n"
10807 "Do not export to next AS (well-known community)\n"
10808 "community number\n"
10809 "Do not send outside local AS (well-known community)\n"
10810 "Do not advertise to any peer (well-known community)\n"
10811 "Do not export to next AS (well-known community)\n"
10812 "community number\n"
10813 "Do not send outside local AS (well-known community)\n"
10814 "Do not advertise to any peer (well-known community)\n"
10815 "Do not export to next AS (well-known community)\n"
10816 "Exact match of the communities")
10817
paul94f2b392005-06-28 12:44:16 +000010818static int
paulfd79ac92004-10-13 05:06:08 +000010819bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -040010820 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +000010821{
10822 struct community_list *list;
10823
hassofee6e4e2005-02-02 16:29:31 +000010824 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +000010825 if (list == NULL)
10826 {
10827 vty_out (vty, "%% %s is not a valid community-list name%s", com,
10828 VTY_NEWLINE);
10829 return CMD_WARNING;
10830 }
10831
ajs5a646652004-11-05 01:25:55 +000010832 return bgp_show (vty, NULL, afi, safi,
10833 (exact ? bgp_show_type_community_list_exact :
10834 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +000010835}
10836
Lou Bergerf9b6c392016-01-12 13:42:09 -050010837DEFUN (show_ip_bgp_community_list,
10838 show_ip_bgp_community_list_cmd,
10839 "show ip bgp community-list (<1-500>|WORD)",
10840 SHOW_STR
10841 IP_STR
10842 BGP_STR
10843 "Display routes matching the community-list\n"
10844 "community-list number\n"
10845 "community-list name\n")
10846{
10847 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
10848}
10849
10850DEFUN (show_ip_bgp_ipv4_community_list,
10851 show_ip_bgp_ipv4_community_list_cmd,
10852 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
10853 SHOW_STR
10854 IP_STR
10855 BGP_STR
10856 "Address family\n"
10857 "Address Family modifier\n"
10858 "Address Family modifier\n"
10859 "Display routes matching the community-list\n"
10860 "community-list number\n"
10861 "community-list name\n")
10862{
10863 if (strncmp (argv[0], "m", 1) == 0)
10864 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
10865
10866 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
10867}
10868
10869DEFUN (show_ip_bgp_community_list_exact,
10870 show_ip_bgp_community_list_exact_cmd,
10871 "show ip bgp community-list (<1-500>|WORD) exact-match",
10872 SHOW_STR
10873 IP_STR
10874 BGP_STR
10875 "Display routes matching the community-list\n"
10876 "community-list number\n"
10877 "community-list name\n"
10878 "Exact match of the communities\n")
10879{
10880 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
10881}
10882
10883DEFUN (show_ip_bgp_ipv4_community_list_exact,
10884 show_ip_bgp_ipv4_community_list_exact_cmd,
10885 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
10886 SHOW_STR
10887 IP_STR
10888 BGP_STR
10889 "Address family\n"
10890 "Address Family modifier\n"
10891 "Address Family modifier\n"
10892 "Display routes matching the community-list\n"
10893 "community-list number\n"
10894 "community-list name\n"
10895 "Exact match of the communities\n")
10896{
10897 if (strncmp (argv[0], "m", 1) == 0)
10898 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
10899
10900 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
10901}
10902
Lou Bergerf9b6c392016-01-12 13:42:09 -050010903DEFUN (show_bgp_community_list,
10904 show_bgp_community_list_cmd,
10905 "show bgp community-list (<1-500>|WORD)",
10906 SHOW_STR
10907 BGP_STR
10908 "Display routes matching the community-list\n"
10909 "community-list number\n"
10910 "community-list name\n")
10911{
10912 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
10913}
10914
10915ALIAS (show_bgp_community_list,
10916 show_bgp_ipv6_community_list_cmd,
10917 "show bgp ipv6 community-list (<1-500>|WORD)",
10918 SHOW_STR
10919 BGP_STR
10920 "Address family\n"
10921 "Display routes matching the community-list\n"
10922 "community-list number\n"
10923 "community-list name\n")
10924
10925/* old command */
10926DEFUN (show_ipv6_bgp_community_list,
10927 show_ipv6_bgp_community_list_cmd,
10928 "show ipv6 bgp community-list WORD",
10929 SHOW_STR
10930 IPV6_STR
10931 BGP_STR
10932 "Display routes matching the community-list\n"
10933 "community-list name\n")
10934{
10935 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
10936}
10937
10938/* old command */
10939DEFUN (show_ipv6_mbgp_community_list,
10940 show_ipv6_mbgp_community_list_cmd,
10941 "show ipv6 mbgp community-list WORD",
10942 SHOW_STR
10943 IPV6_STR
10944 MBGP_STR
10945 "Display routes matching the community-list\n"
10946 "community-list name\n")
10947{
10948 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
10949}
10950
10951DEFUN (show_bgp_community_list_exact,
10952 show_bgp_community_list_exact_cmd,
10953 "show bgp community-list (<1-500>|WORD) exact-match",
10954 SHOW_STR
10955 BGP_STR
10956 "Display routes matching the community-list\n"
10957 "community-list number\n"
10958 "community-list name\n"
10959 "Exact match of the communities\n")
10960{
10961 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
10962}
10963
10964ALIAS (show_bgp_community_list_exact,
10965 show_bgp_ipv6_community_list_exact_cmd,
10966 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
10967 SHOW_STR
10968 BGP_STR
10969 "Address family\n"
10970 "Display routes matching the community-list\n"
10971 "community-list number\n"
10972 "community-list name\n"
10973 "Exact match of the communities\n")
10974
10975/* old command */
10976DEFUN (show_ipv6_bgp_community_list_exact,
10977 show_ipv6_bgp_community_list_exact_cmd,
10978 "show ipv6 bgp community-list WORD exact-match",
10979 SHOW_STR
10980 IPV6_STR
10981 BGP_STR
10982 "Display routes matching the community-list\n"
10983 "community-list name\n"
10984 "Exact match of the communities\n")
10985{
10986 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
10987}
10988
10989/* old command */
10990DEFUN (show_ipv6_mbgp_community_list_exact,
10991 show_ipv6_mbgp_community_list_exact_cmd,
10992 "show ipv6 mbgp community-list WORD exact-match",
10993 SHOW_STR
10994 IPV6_STR
10995 MBGP_STR
10996 "Display routes matching the community-list\n"
10997 "community-list name\n"
10998 "Exact match of the communities\n")
10999{
11000 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
11001}
Lou Bergerf9b6c392016-01-12 13:42:09 -050011002
Lou Berger651b4022016-01-12 13:42:07 -050011003DEFUN (show_bgp_ipv4_community_list,
11004 show_bgp_ipv4_community_list_cmd,
11005 "show bgp ipv4 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011006 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011007 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011008 IP_STR
paul718e3742002-12-13 20:15:29 +000011009 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011010 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011011 "community-list name\n")
11012{
11013 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
11014}
11015
Lou Berger651b4022016-01-12 13:42:07 -050011016DEFUN (show_bgp_ipv4_safi_community_list,
11017 show_bgp_ipv4_safi_community_list_cmd,
11018 "show bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011019 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011020 BGP_STR
11021 "Address family\n"
11022 "Address Family modifier\n"
11023 "Address Family modifier\n"
11024 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011025 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011026 "community-list name\n")
11027{
11028 if (strncmp (argv[0], "m", 1) == 0)
11029 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
11030
11031 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
11032}
11033
Lou Berger651b4022016-01-12 13:42:07 -050011034DEFUN (show_bgp_ipv4_community_list_exact,
11035 show_bgp_ipv4_community_list_exact_cmd,
11036 "show bgp ipv4 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011037 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011038 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011039 IP_STR
paul718e3742002-12-13 20:15:29 +000011040 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011041 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011042 "community-list name\n"
11043 "Exact match of the communities\n")
11044{
11045 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
11046}
11047
Lou Berger651b4022016-01-12 13:42:07 -050011048DEFUN (show_bgp_ipv4_safi_community_list_exact,
11049 show_bgp_ipv4_safi_community_list_exact_cmd,
11050 "show bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011051 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011052 BGP_STR
11053 "Address family\n"
11054 "Address Family modifier\n"
11055 "Address Family modifier\n"
11056 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011057 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011058 "community-list name\n"
11059 "Exact match of the communities\n")
11060{
11061 if (strncmp (argv[0], "m", 1) == 0)
11062 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
11063
11064 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
11065}
11066
Lou Bergerf9b6c392016-01-12 13:42:09 -050011067DEFUN (show_bgp_ipv6_safi_community_list,
11068 show_bgp_ipv6_safi_community_list_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011069 "show bgp ipv6 (encap|multicast|unicast|vpn) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011070 SHOW_STR
11071 BGP_STR
11072 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050011073 "Address family modifier\n"
11074 "Address family modifier\n"
11075 "Address family modifier\n"
11076 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000011077 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011078 "community-list number\n"
paule8e19462006-01-19 20:16:55 +000011079 "community-list name\n")
paul718e3742002-12-13 20:15:29 +000011080{
Lou Berger651b4022016-01-12 13:42:07 -050011081 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011082
Lou Berger651b4022016-01-12 13:42:07 -050011083 if (bgp_parse_safi(argv[0], &safi)) {
11084 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11085 return CMD_WARNING;
11086 }
11087 return bgp_show_community_list (vty, argv[1], 0, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000011088}
11089
Lou Bergerf9b6c392016-01-12 13:42:09 -050011090DEFUN (show_bgp_ipv6_safi_community_list_exact,
11091 show_bgp_ipv6_safi_community_list_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011092 "show bgp ipv6 (encap|multicast|unicast|vpn) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011093 SHOW_STR
11094 BGP_STR
11095 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050011096 "Address family modifier\n"
11097 "Address family modifier\n"
11098 "Address family modifier\n"
11099 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000011100 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011101 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011102 "community-list name\n"
11103 "Exact match of the communities\n")
paul718e3742002-12-13 20:15:29 +000011104{
Lou Berger651b4022016-01-12 13:42:07 -050011105 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011106
Lou Berger651b4022016-01-12 13:42:07 -050011107 if (bgp_parse_safi(argv[0], &safi)) {
11108 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11109 return CMD_WARNING;
11110 }
11111 return bgp_show_community_list (vty, argv[1], 1, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000011112}
David Lamparter6b0655a2014-06-04 06:53:35 +020011113
paul94f2b392005-06-28 12:44:16 +000011114static int
paulfd79ac92004-10-13 05:06:08 +000011115bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +000011116 safi_t safi, enum bgp_show_type type)
11117{
11118 int ret;
11119 struct prefix *p;
11120
11121 p = prefix_new();
11122
11123 ret = str2prefix (prefix, p);
11124 if (! ret)
11125 {
11126 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
11127 return CMD_WARNING;
11128 }
11129
ajs5a646652004-11-05 01:25:55 +000011130 ret = bgp_show (vty, NULL, afi, safi, type, p);
11131 prefix_free(p);
11132 return ret;
paul718e3742002-12-13 20:15:29 +000011133}
11134
Lou Bergerf9b6c392016-01-12 13:42:09 -050011135DEFUN (show_ip_bgp_prefix_longer,
11136 show_ip_bgp_prefix_longer_cmd,
11137 "show ip bgp A.B.C.D/M longer-prefixes",
11138 SHOW_STR
11139 IP_STR
11140 BGP_STR
11141 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11142 "Display route and more specific routes\n")
11143{
11144 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11145 bgp_show_type_prefix_longer);
11146}
11147
11148DEFUN (show_ip_bgp_flap_prefix_longer,
11149 show_ip_bgp_flap_prefix_longer_cmd,
11150 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
11151 SHOW_STR
11152 IP_STR
11153 BGP_STR
11154 "Display flap statistics of routes\n"
11155 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11156 "Display route and more specific routes\n")
11157{
11158 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11159 bgp_show_type_flap_prefix_longer);
11160}
11161
11162ALIAS (show_ip_bgp_flap_prefix_longer,
11163 show_ip_bgp_damp_flap_prefix_longer_cmd,
11164 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
11165 SHOW_STR
11166 IP_STR
11167 BGP_STR
11168 "Display detailed information about dampening\n"
11169 "Display flap statistics of routes\n"
11170 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11171 "Display route and more specific routes\n")
11172
11173DEFUN (show_ip_bgp_ipv4_prefix_longer,
11174 show_ip_bgp_ipv4_prefix_longer_cmd,
11175 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
11176 SHOW_STR
11177 IP_STR
11178 BGP_STR
11179 "Address family\n"
11180 "Address Family modifier\n"
11181 "Address Family modifier\n"
11182 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11183 "Display route and more specific routes\n")
11184{
11185 if (strncmp (argv[0], "m", 1) == 0)
11186 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
11187 bgp_show_type_prefix_longer);
11188
11189 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
11190 bgp_show_type_prefix_longer);
11191}
11192
11193DEFUN (show_ip_bgp_flap_address,
11194 show_ip_bgp_flap_address_cmd,
11195 "show ip bgp flap-statistics A.B.C.D",
11196 SHOW_STR
11197 IP_STR
11198 BGP_STR
11199 "Display flap statistics of routes\n"
11200 "Network in the BGP routing table to display\n")
11201{
11202 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11203 bgp_show_type_flap_address);
11204}
11205
11206ALIAS (show_ip_bgp_flap_address,
11207 show_ip_bgp_damp_flap_address_cmd,
11208 "show ip bgp dampening flap-statistics A.B.C.D",
11209 SHOW_STR
11210 IP_STR
11211 BGP_STR
11212 "Display detailed information about dampening\n"
11213 "Display flap statistics of routes\n"
11214 "Network in the BGP routing table to display\n")
11215
11216DEFUN (show_ip_bgp_flap_prefix,
11217 show_ip_bgp_flap_prefix_cmd,
11218 "show ip bgp flap-statistics A.B.C.D/M",
11219 SHOW_STR
11220 IP_STR
11221 BGP_STR
11222 "Display flap statistics of routes\n"
11223 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11224{
11225 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11226 bgp_show_type_flap_prefix);
11227}
11228
11229ALIAS (show_ip_bgp_flap_prefix,
11230 show_ip_bgp_damp_flap_prefix_cmd,
11231 "show ip bgp dampening flap-statistics A.B.C.D/M",
11232 SHOW_STR
11233 IP_STR
11234 BGP_STR
11235 "Display detailed information about dampening\n"
11236 "Display flap statistics of routes\n"
11237 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11238
Lou Bergerf9b6c392016-01-12 13:42:09 -050011239DEFUN (show_bgp_prefix_longer,
11240 show_bgp_prefix_longer_cmd,
11241 "show bgp X:X::X:X/M longer-prefixes",
11242 SHOW_STR
11243 BGP_STR
11244 "IPv6 prefix <network>/<length>\n"
11245 "Display route and more specific routes\n")
11246{
11247 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11248 bgp_show_type_prefix_longer);
11249}
11250
11251/* old command */
11252DEFUN (show_ipv6_bgp_prefix_longer,
11253 show_ipv6_bgp_prefix_longer_cmd,
11254 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11255 SHOW_STR
11256 IPV6_STR
11257 BGP_STR
11258 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11259 "Display route and more specific routes\n")
11260{
11261 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11262 bgp_show_type_prefix_longer);
11263}
11264
11265/* old command */
11266DEFUN (show_ipv6_mbgp_prefix_longer,
11267 show_ipv6_mbgp_prefix_longer_cmd,
11268 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11269 SHOW_STR
11270 IPV6_STR
11271 MBGP_STR
11272 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11273 "Display route and more specific routes\n")
11274{
11275 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
11276 bgp_show_type_prefix_longer);
11277}
Lou Bergerf9b6c392016-01-12 13:42:09 -050011278
Lou Berger651b4022016-01-12 13:42:07 -050011279DEFUN (show_bgp_ipv4_prefix_longer,
11280 show_bgp_ipv4_prefix_longer_cmd,
11281 "show bgp ipv4 A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011282 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011283 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011284 IP_STR
paul718e3742002-12-13 20:15:29 +000011285 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11286 "Display route and more specific routes\n")
11287{
11288 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11289 bgp_show_type_prefix_longer);
11290}
11291
Lou Berger651b4022016-01-12 13:42:07 -050011292DEFUN (show_bgp_ipv4_safi_flap_prefix_longer,
11293 show_bgp_ipv4_safi_flap_prefix_longer_cmd,
11294 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011295 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011296 BGP_STR
11297 "Address family\n"
11298 "Address Family modifier\n"
11299 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050011300 "Address Family modifier\n"
11301 "Address Family modifier\n"
11302 "Display flap statistics of routes\n"
paul718e3742002-12-13 20:15:29 +000011303 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11304 "Display route and more specific routes\n")
11305{
Lou Berger651b4022016-01-12 13:42:07 -050011306 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011307
Lou Berger651b4022016-01-12 13:42:07 -050011308 if (bgp_parse_safi(argv[0], &safi)) {
11309 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11310 return CMD_WARNING;
11311 }
11312 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11313 bgp_show_type_flap_prefix_longer);
paul718e3742002-12-13 20:15:29 +000011314}
11315
Lou Berger651b4022016-01-12 13:42:07 -050011316ALIAS (show_bgp_ipv4_safi_flap_prefix_longer,
11317 show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd,
11318 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011319 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011320 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011321 "Address family\n"
11322 "Address Family modifier\n"
11323 "Address Family modifier\n"
11324 "Address Family modifier\n"
11325 "Address Family modifier\n"
11326 "Display detailed information about dampening\n"
11327 "Display flap statistics of routes\n"
11328 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11329 "Display route and more specific routes\n")
11330
Lou Berger651b4022016-01-12 13:42:07 -050011331DEFUN (show_bgp_ipv6_safi_flap_prefix_longer,
11332 show_bgp_ipv6_safi_flap_prefix_longer_cmd,
11333 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics X:X::X:X/M longer-prefixes",
11334 SHOW_STR
11335 BGP_STR
11336 "Address family\n"
11337 "Address Family modifier\n"
11338 "Address Family modifier\n"
11339 "Address Family modifier\n"
11340 "Address Family modifier\n"
11341 "Display flap statistics of routes\n"
11342 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11343 "Display route and more specific routes\n")
11344{
11345 safi_t safi;
11346
11347 if (bgp_parse_safi(argv[0], &safi)) {
11348 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11349 return CMD_WARNING;
11350 }
11351 return bgp_show_prefix_longer (vty, argv[1], AFI_IP6, safi,
11352 bgp_show_type_flap_prefix_longer);
11353}
11354ALIAS (show_bgp_ipv6_safi_flap_prefix_longer,
11355 show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd,
11356 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics X:X::X:X/M longer-prefixes",
11357 SHOW_STR
11358 BGP_STR
11359 "Address family\n"
11360 "Address Family modifier\n"
11361 "Address Family modifier\n"
11362 "Address Family modifier\n"
11363 "Address Family modifier\n"
11364 "Display detailed information about dampening\n"
11365 "Display flap statistics of routes\n"
11366 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11367 "Display route and more specific routes\n")
Lou Berger651b4022016-01-12 13:42:07 -050011368
11369DEFUN (show_bgp_ipv4_safi_prefix_longer,
11370 show_bgp_ipv4_safi_prefix_longer_cmd,
11371 "show bgp ipv4 (encap|multicast|unicast|vpn) A.B.C.D/M longer-prefixes",
11372 SHOW_STR
11373 BGP_STR
11374 "Address family\n"
11375 "Address Family modifier\n"
11376 "Address Family modifier\n"
11377 "Address Family modifier\n"
11378 "Address Family modifier\n"
11379 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11380 "Display route and more specific routes\n")
11381{
11382 safi_t safi;
11383
11384 if (bgp_parse_safi(argv[0], &safi)) {
11385 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11386 return CMD_WARNING;
11387 }
11388
11389 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11390 bgp_show_type_prefix_longer);
11391}
11392
Lou Berger651b4022016-01-12 13:42:07 -050011393DEFUN (show_bgp_ipv6_safi_prefix_longer,
11394 show_bgp_ipv6_safi_prefix_longer_cmd,
11395 "show bgp ipv6 (encap|multicast|unicast|vpn) X:X::X:X/M longer-prefixes",
11396 SHOW_STR
11397 BGP_STR
11398 "Address family\n"
11399 "Address Family modifier\n"
11400 "Address Family modifier\n"
11401 "Address Family modifier\n"
11402 "Address Family modifier\n"
11403 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11404 "Display route and more specific routes\n")
11405{
11406 safi_t safi;
11407
11408 if (bgp_parse_safi(argv[0], &safi)) {
11409 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11410 return CMD_WARNING;
11411 }
11412
11413 return bgp_show_prefix_longer (vty, argv[1], AFI_IP6, safi,
11414 bgp_show_type_prefix_longer);
11415}
Lou Berger651b4022016-01-12 13:42:07 -050011416
11417DEFUN (show_bgp_ipv4_safi_flap_address,
11418 show_bgp_ipv4_safi_flap_address_cmd,
11419 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D",
11420 SHOW_STR
11421 BGP_STR
11422 "Address family\n"
11423 "Address Family modifier\n"
11424 "Address Family modifier\n"
11425 "Address Family modifier\n"
11426 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000011427 "Display flap statistics of routes\n"
11428 "Network in the BGP routing table to display\n")
11429{
Lou Berger651b4022016-01-12 13:42:07 -050011430 safi_t safi;
11431
11432 if (bgp_parse_safi(argv[0], &safi)) {
11433 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11434 return CMD_WARNING;
11435 }
11436 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000011437 bgp_show_type_flap_address);
11438}
Lou Berger651b4022016-01-12 13:42:07 -050011439ALIAS (show_bgp_ipv4_safi_flap_address,
11440 show_bgp_ipv4_safi_damp_flap_address_cmd,
11441 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D",
Balaji3921cc52015-05-16 23:12:17 +053011442 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053011443 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011444 "Address family\n"
11445 "Address Family modifier\n"
11446 "Address Family modifier\n"
11447 "Address Family modifier\n"
11448 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053011449 "Display detailed information about dampening\n"
11450 "Display flap statistics of routes\n"
11451 "Network in the BGP routing table to display\n")
Lou Berger205e6742016-01-12 13:42:11 -050011452
Lou Berger651b4022016-01-12 13:42:07 -050011453DEFUN (show_bgp_ipv6_flap_address,
11454 show_bgp_ipv6_flap_address_cmd,
11455 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D",
paul718e3742002-12-13 20:15:29 +000011456 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011457 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011458 "Address family\n"
11459 "Address Family modifier\n"
11460 "Address Family modifier\n"
11461 "Address Family modifier\n"
11462 "Address Family modifier\n"
11463 "Display flap statistics of routes\n"
11464 "Network in the BGP routing table to display\n")
11465{
11466 safi_t safi;
11467
11468 if (bgp_parse_safi(argv[0], &safi)) {
11469 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11470 return CMD_WARNING;
11471 }
11472 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11473 bgp_show_type_flap_address);
11474}
11475ALIAS (show_bgp_ipv6_flap_address,
11476 show_bgp_ipv6_damp_flap_address_cmd,
11477 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D",
11478 SHOW_STR
11479 BGP_STR
11480 "Address family\n"
11481 "Address Family modifier\n"
11482 "Address Family modifier\n"
11483 "Address Family modifier\n"
11484 "Address Family modifier\n"
11485 "Display detailed information about dampening\n"
11486 "Display flap statistics of routes\n"
11487 "Network in the BGP routing table to display\n")
Lou Berger651b4022016-01-12 13:42:07 -050011488
11489DEFUN (show_bgp_ipv4_safi_flap_prefix,
11490 show_bgp_ipv4_safi_flap_prefix_cmd,
11491 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D/M",
11492 SHOW_STR
11493 BGP_STR
11494 "Address family\n"
11495 "Address Family modifier\n"
11496 "Address Family modifier\n"
11497 "Address Family modifier\n"
11498 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000011499 "Display flap statistics of routes\n"
11500 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11501{
Lou Berger651b4022016-01-12 13:42:07 -050011502 safi_t safi;
11503
11504 if (bgp_parse_safi(argv[0], &safi)) {
11505 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11506 return CMD_WARNING;
11507 }
11508 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000011509 bgp_show_type_flap_prefix);
11510}
Balaji3921cc52015-05-16 23:12:17 +053011511
Lou Berger651b4022016-01-12 13:42:07 -050011512ALIAS (show_bgp_ipv4_safi_flap_prefix,
11513 show_bgp_ipv4_safi_damp_flap_prefix_cmd,
11514 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D/M",
Balaji3921cc52015-05-16 23:12:17 +053011515 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053011516 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011517 "Address family\n"
11518 "Address Family modifier\n"
11519 "Address Family modifier\n"
11520 "Address Family modifier\n"
11521 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053011522 "Display detailed information about dampening\n"
11523 "Display flap statistics of routes\n"
11524 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11525
Lou Berger651b4022016-01-12 13:42:07 -050011526DEFUN (show_bgp_ipv6_safi_flap_prefix,
11527 show_bgp_ipv6_safi_flap_prefix_cmd,
11528 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics X:X::X:X/M",
paul718e3742002-12-13 20:15:29 +000011529 SHOW_STR
11530 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011531 "Address family\n"
11532 "Address Family modifier\n"
11533 "Address Family modifier\n"
11534 "Address Family modifier\n"
11535 "Address Family modifier\n"
11536 "Display flap statistics of routes\n"
11537 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paul718e3742002-12-13 20:15:29 +000011538{
Lou Berger651b4022016-01-12 13:42:07 -050011539 safi_t safi;
11540
11541 if (bgp_parse_safi(argv[0], &safi)) {
11542 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11543 return CMD_WARNING;
11544 }
11545 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, safi,
11546 bgp_show_type_flap_prefix);
paul718e3742002-12-13 20:15:29 +000011547}
11548
Lou Berger651b4022016-01-12 13:42:07 -050011549ALIAS (show_bgp_ipv6_safi_flap_prefix,
11550 show_bgp_ipv6_safi_damp_flap_prefix_cmd,
11551 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics X:X::X:X/M",
11552 SHOW_STR
11553 BGP_STR
11554 "Address family\n"
11555 "Address Family modifier\n"
11556 "Address Family modifier\n"
11557 "Address Family modifier\n"
11558 "Address Family modifier\n"
11559 "Display detailed information about dampening\n"
11560 "Display flap statistics of routes\n"
11561 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11562
11563DEFUN (show_bgp_ipv6_prefix_longer,
paul718e3742002-12-13 20:15:29 +000011564 show_bgp_ipv6_prefix_longer_cmd,
11565 "show bgp ipv6 X:X::X:X/M longer-prefixes",
11566 SHOW_STR
11567 BGP_STR
11568 "Address family\n"
11569 "IPv6 prefix <network>/<length>\n"
11570 "Display route and more specific routes\n")
paul718e3742002-12-13 20:15:29 +000011571{
11572 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11573 bgp_show_type_prefix_longer);
11574}
11575
paul94f2b392005-06-28 12:44:16 +000011576static struct peer *
paulfd79ac92004-10-13 05:06:08 +000011577peer_lookup_in_view (struct vty *vty, const char *view_name,
11578 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +000011579{
11580 int ret;
11581 struct bgp *bgp;
11582 struct peer *peer;
11583 union sockunion su;
11584
11585 /* BGP structure lookup. */
11586 if (view_name)
11587 {
11588 bgp = bgp_lookup_by_name (view_name);
11589 if (! bgp)
11590 {
11591 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11592 return NULL;
11593 }
11594 }
paul5228ad22004-06-04 17:58:18 +000011595 else
paulbb46e942003-10-24 19:02:03 +000011596 {
11597 bgp = bgp_get_default ();
11598 if (! bgp)
11599 {
11600 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11601 return NULL;
11602 }
11603 }
11604
11605 /* Get peer sockunion. */
11606 ret = str2sockunion (ip_str, &su);
11607 if (ret < 0)
11608 {
11609 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
11610 return NULL;
11611 }
11612
11613 /* Peer structure lookup. */
11614 peer = peer_lookup (bgp, &su);
11615 if (! peer)
11616 {
11617 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
11618 return NULL;
11619 }
11620
11621 return peer;
11622}
David Lamparter6b0655a2014-06-04 06:53:35 +020011623
Paul Jakma2815e612006-09-14 02:56:07 +000011624enum bgp_stats
11625{
11626 BGP_STATS_MAXBITLEN = 0,
11627 BGP_STATS_RIB,
11628 BGP_STATS_PREFIXES,
11629 BGP_STATS_TOTPLEN,
11630 BGP_STATS_UNAGGREGATEABLE,
11631 BGP_STATS_MAX_AGGREGATEABLE,
11632 BGP_STATS_AGGREGATES,
11633 BGP_STATS_SPACE,
11634 BGP_STATS_ASPATH_COUNT,
11635 BGP_STATS_ASPATH_MAXHOPS,
11636 BGP_STATS_ASPATH_TOTHOPS,
11637 BGP_STATS_ASPATH_MAXSIZE,
11638 BGP_STATS_ASPATH_TOTSIZE,
11639 BGP_STATS_ASN_HIGHEST,
11640 BGP_STATS_MAX,
11641};
paulbb46e942003-10-24 19:02:03 +000011642
Paul Jakma2815e612006-09-14 02:56:07 +000011643static const char *table_stats_strs[] =
11644{
11645 [BGP_STATS_PREFIXES] = "Total Prefixes",
11646 [BGP_STATS_TOTPLEN] = "Average prefix length",
11647 [BGP_STATS_RIB] = "Total Advertisements",
11648 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11649 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11650 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11651 [BGP_STATS_SPACE] = "Address space advertised",
11652 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11653 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11654 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11655 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11656 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11657 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11658 [BGP_STATS_MAX] = NULL,
11659};
11660
11661struct bgp_table_stats
11662{
11663 struct bgp_table *table;
11664 unsigned long long counts[BGP_STATS_MAX];
11665};
11666
11667#if 0
11668#define TALLY_SIGFIG 100000
11669static unsigned long
11670ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11671{
11672 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11673 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11674 unsigned long ret = newtot / count;
11675
11676 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11677 return ret + 1;
11678 else
11679 return ret;
11680}
11681#endif
11682
11683static int
11684bgp_table_stats_walker (struct thread *t)
11685{
11686 struct bgp_node *rn;
11687 struct bgp_node *top;
11688 struct bgp_table_stats *ts = THREAD_ARG (t);
11689 unsigned int space = 0;
11690
Paul Jakma53d9f672006-10-15 23:41:16 +000011691 if (!(top = bgp_table_top (ts->table)))
11692 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +000011693
11694 switch (top->p.family)
11695 {
11696 case AF_INET:
11697 space = IPV4_MAX_BITLEN;
11698 break;
11699 case AF_INET6:
11700 space = IPV6_MAX_BITLEN;
11701 break;
11702 }
11703
11704 ts->counts[BGP_STATS_MAXBITLEN] = space;
11705
11706 for (rn = top; rn; rn = bgp_route_next (rn))
11707 {
11708 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -070011709 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +000011710 unsigned int rinum = 0;
11711
11712 if (rn == top)
11713 continue;
11714
11715 if (!rn->info)
11716 continue;
11717
11718 ts->counts[BGP_STATS_PREFIXES]++;
11719 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11720
11721#if 0
11722 ts->counts[BGP_STATS_AVGPLEN]
11723 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11724 ts->counts[BGP_STATS_AVGPLEN],
11725 rn->p.prefixlen);
11726#endif
11727
11728 /* check if the prefix is included by any other announcements */
11729 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -070011730 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +000011731
11732 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +000011733 {
11734 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11735 /* announced address space */
11736 if (space)
11737 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11738 }
Paul Jakma2815e612006-09-14 02:56:07 +000011739 else if (prn->info)
11740 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11741
Paul Jakma2815e612006-09-14 02:56:07 +000011742 for (ri = rn->info; ri; ri = ri->next)
11743 {
11744 rinum++;
11745 ts->counts[BGP_STATS_RIB]++;
11746
11747 if (ri->attr &&
11748 (CHECK_FLAG (ri->attr->flag,
11749 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11750 ts->counts[BGP_STATS_AGGREGATES]++;
11751
11752 /* as-path stats */
11753 if (ri->attr && ri->attr->aspath)
11754 {
11755 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11756 unsigned int size = aspath_size (ri->attr->aspath);
11757 as_t highest = aspath_highest (ri->attr->aspath);
11758
11759 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11760
11761 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11762 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11763
11764 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11765 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11766
11767 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11768 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11769#if 0
11770 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11771 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11772 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11773 hops);
11774 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11775 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11776 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11777 size);
11778#endif
11779 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11780 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11781 }
11782 }
11783 }
11784 return 0;
11785}
11786
11787static int
11788bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11789{
11790 struct bgp_table_stats ts;
11791 unsigned int i;
11792
11793 if (!bgp->rib[afi][safi])
11794 {
Donald Sharp3c964042016-01-25 23:38:53 -050011795 vty_out (vty, "%% No RIB exists for the specified AFI(%d)/SAFI(%d) %s",
11796 afi, safi, VTY_NEWLINE);
Paul Jakma2815e612006-09-14 02:56:07 +000011797 return CMD_WARNING;
11798 }
11799
11800 memset (&ts, 0, sizeof (ts));
11801 ts.table = bgp->rib[afi][safi];
11802 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
11803
11804 vty_out (vty, "BGP %s RIB statistics%s%s",
11805 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
11806
11807 for (i = 0; i < BGP_STATS_MAX; i++)
11808 {
11809 if (!table_stats_strs[i])
11810 continue;
11811
11812 switch (i)
11813 {
11814#if 0
11815 case BGP_STATS_ASPATH_AVGHOPS:
11816 case BGP_STATS_ASPATH_AVGSIZE:
11817 case BGP_STATS_AVGPLEN:
11818 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11819 vty_out (vty, "%12.2f",
11820 (float)ts.counts[i] / (float)TALLY_SIGFIG);
11821 break;
11822#endif
11823 case BGP_STATS_ASPATH_TOTHOPS:
11824 case BGP_STATS_ASPATH_TOTSIZE:
11825 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11826 vty_out (vty, "%12.2f",
11827 ts.counts[i] ?
11828 (float)ts.counts[i] /
11829 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
11830 : 0);
11831 break;
11832 case BGP_STATS_TOTPLEN:
11833 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11834 vty_out (vty, "%12.2f",
11835 ts.counts[i] ?
11836 (float)ts.counts[i] /
11837 (float)ts.counts[BGP_STATS_PREFIXES]
11838 : 0);
11839 break;
11840 case BGP_STATS_SPACE:
11841 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11842 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
11843 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
11844 break;
Paul Jakma30a22312008-08-15 14:05:22 +010011845 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +000011846 vty_out (vty, "%12.2f%s",
11847 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +000011848 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +000011849 VTY_NEWLINE);
11850 vty_out (vty, "%30s: ", "/8 equivalent ");
11851 vty_out (vty, "%12.2f%s",
11852 (float)ts.counts[BGP_STATS_SPACE] /
11853 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
11854 VTY_NEWLINE);
11855 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
11856 break;
11857 vty_out (vty, "%30s: ", "/24 equivalent ");
11858 vty_out (vty, "%12.2f",
11859 (float)ts.counts[BGP_STATS_SPACE] /
11860 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
11861 break;
11862 default:
11863 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11864 vty_out (vty, "%12llu", ts.counts[i]);
11865 }
11866
11867 vty_out (vty, "%s", VTY_NEWLINE);
11868 }
11869 return CMD_SUCCESS;
11870}
11871
11872static int
11873bgp_table_stats_vty (struct vty *vty, const char *name,
11874 const char *afi_str, const char *safi_str)
11875{
11876 struct bgp *bgp;
11877 afi_t afi;
11878 safi_t safi;
11879
11880 if (name)
11881 bgp = bgp_lookup_by_name (name);
11882 else
11883 bgp = bgp_get_default ();
11884
11885 if (!bgp)
11886 {
Lou Bergerbf1ae6c2016-01-12 13:42:08 -050011887 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
Paul Jakma2815e612006-09-14 02:56:07 +000011888 return CMD_WARNING;
11889 }
11890 if (strncmp (afi_str, "ipv", 3) == 0)
11891 {
11892 if (strncmp (afi_str, "ipv4", 4) == 0)
11893 afi = AFI_IP;
11894 else if (strncmp (afi_str, "ipv6", 4) == 0)
11895 afi = AFI_IP6;
11896 else
11897 {
11898 vty_out (vty, "%% Invalid address family %s%s",
11899 afi_str, VTY_NEWLINE);
11900 return CMD_WARNING;
11901 }
Lou Berger298cc2f2016-01-12 13:42:02 -050011902 switch (safi_str[0]) {
11903 case 'm':
11904 safi = SAFI_MULTICAST;
11905 break;
11906 case 'u':
11907 safi = SAFI_UNICAST;
11908 break;
11909 case 'v':
Donald Sharp3c964042016-01-25 23:38:53 -050011910 safi = SAFI_MPLS_VPN;
Lou Berger298cc2f2016-01-12 13:42:02 -050011911 break;
11912 case 'e':
11913 safi = SAFI_ENCAP;
11914 break;
11915 default:
11916 vty_out (vty, "%% Invalid subsequent address family %s%s",
Paul Jakma2815e612006-09-14 02:56:07 +000011917 safi_str, VTY_NEWLINE);
Lou Berger298cc2f2016-01-12 13:42:02 -050011918 return CMD_WARNING;
11919 }
Paul Jakma2815e612006-09-14 02:56:07 +000011920 }
11921 else
11922 {
Lou Berger298cc2f2016-01-12 13:42:02 -050011923 vty_out (vty, "%% Invalid address family \"%s\"%s",
Paul Jakma2815e612006-09-14 02:56:07 +000011924 afi_str, VTY_NEWLINE);
11925 return CMD_WARNING;
11926 }
11927
Paul Jakma2815e612006-09-14 02:56:07 +000011928 return bgp_table_stats (vty, bgp, afi, safi);
11929}
11930
11931DEFUN (show_bgp_statistics,
11932 show_bgp_statistics_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -050011933 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000011934 SHOW_STR
11935 BGP_STR
11936 "Address family\n"
11937 "Address family\n"
11938 "Address Family modifier\n"
11939 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -050011940 "Address Family modifier\n"
11941 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +000011942 "BGP RIB advertisement statistics\n")
11943{
11944 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11945}
11946
Lou Bergerf9b6c392016-01-12 13:42:09 -050011947ALIAS (show_bgp_statistics,
11948 show_bgp_statistics_vpnv4_cmd,
11949 "show bgp (ipv4) (vpnv4) statistics",
11950 SHOW_STR
11951 BGP_STR
11952 "Address family\n"
11953 "Address Family modifier\n"
11954 "BGP RIB advertisement statistics\n")
11955
Paul Jakma2815e612006-09-14 02:56:07 +000011956DEFUN (show_bgp_statistics_view,
11957 show_bgp_statistics_view_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -050011958 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000011959 SHOW_STR
11960 BGP_STR
11961 "BGP view\n"
11962 "Address family\n"
11963 "Address family\n"
11964 "Address Family modifier\n"
11965 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -050011966 "Address Family modifier\n"
11967 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +000011968 "BGP RIB advertisement statistics\n")
11969{
11970 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11971}
11972
11973ALIAS (show_bgp_statistics_view,
Lou Bergerf9b6c392016-01-12 13:42:09 -050011974 show_bgp_statistics_view_vpnv4_cmd,
11975 "show bgp view WORD (ipv4) (vpnv4) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000011976 SHOW_STR
11977 BGP_STR
11978 "BGP view\n"
11979 "Address family\n"
11980 "Address Family modifier\n"
11981 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +020011982
Paul Jakmaff7924f2006-09-04 01:10:36 +000011983enum bgp_pcounts
11984{
11985 PCOUNT_ADJ_IN = 0,
11986 PCOUNT_DAMPED,
11987 PCOUNT_REMOVED,
11988 PCOUNT_HISTORY,
11989 PCOUNT_STALE,
11990 PCOUNT_VALID,
11991 PCOUNT_ALL,
11992 PCOUNT_COUNTED,
11993 PCOUNT_PFCNT, /* the figure we display to users */
11994 PCOUNT_MAX,
11995};
11996
11997static const char *pcount_strs[] =
11998{
11999 [PCOUNT_ADJ_IN] = "Adj-in",
12000 [PCOUNT_DAMPED] = "Damped",
12001 [PCOUNT_REMOVED] = "Removed",
12002 [PCOUNT_HISTORY] = "History",
12003 [PCOUNT_STALE] = "Stale",
12004 [PCOUNT_VALID] = "Valid",
12005 [PCOUNT_ALL] = "All RIB",
12006 [PCOUNT_COUNTED] = "PfxCt counted",
12007 [PCOUNT_PFCNT] = "Useable",
12008 [PCOUNT_MAX] = NULL,
12009};
12010
Paul Jakma2815e612006-09-14 02:56:07 +000012011struct peer_pcounts
12012{
12013 unsigned int count[PCOUNT_MAX];
12014 const struct peer *peer;
12015 const struct bgp_table *table;
12016};
12017
Paul Jakmaff7924f2006-09-04 01:10:36 +000012018static int
Paul Jakma2815e612006-09-14 02:56:07 +000012019bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +000012020{
12021 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +000012022 struct peer_pcounts *pc = THREAD_ARG (t);
12023 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012024
Paul Jakma2815e612006-09-14 02:56:07 +000012025 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012026 {
12027 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +000012028 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012029
12030 for (ain = rn->adj_in; ain; ain = ain->next)
12031 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +000012032 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012033
Paul Jakmaff7924f2006-09-04 01:10:36 +000012034 for (ri = rn->info; ri; ri = ri->next)
12035 {
12036 char buf[SU_ADDRSTRLEN];
12037
12038 if (ri->peer != peer)
12039 continue;
12040
Paul Jakma2815e612006-09-14 02:56:07 +000012041 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012042
12043 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +000012044 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012045 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +000012046 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012047 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +000012048 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012049 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +000012050 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012051 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +000012052 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +000012053 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +000012054 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012055
12056 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
12057 {
Paul Jakma2815e612006-09-14 02:56:07 +000012058 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +000012059 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012060 plog_warn (peer->log,
12061 "%s [pcount] %s/%d is counted but flags 0x%x",
12062 peer->host,
12063 inet_ntop(rn->p.family, &rn->p.u.prefix,
12064 buf, SU_ADDRSTRLEN),
12065 rn->p.prefixlen,
12066 ri->flags);
12067 }
12068 else
12069 {
Paul Jakma1a392d42006-09-07 00:24:49 +000012070 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012071 plog_warn (peer->log,
12072 "%s [pcount] %s/%d not counted but flags 0x%x",
12073 peer->host,
12074 inet_ntop(rn->p.family, &rn->p.u.prefix,
12075 buf, SU_ADDRSTRLEN),
12076 rn->p.prefixlen,
12077 ri->flags);
12078 }
12079 }
12080 }
Paul Jakma2815e612006-09-14 02:56:07 +000012081 return 0;
12082}
Paul Jakmaff7924f2006-09-04 01:10:36 +000012083
Paul Jakma2815e612006-09-14 02:56:07 +000012084static int
12085bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
12086{
12087 struct peer_pcounts pcounts = { .peer = peer };
12088 unsigned int i;
12089
12090 if (!peer || !peer->bgp || !peer->afc[afi][safi]
12091 || !peer->bgp->rib[afi][safi])
12092 {
12093 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12094 return CMD_WARNING;
12095 }
12096
12097 memset (&pcounts, 0, sizeof(pcounts));
12098 pcounts.peer = peer;
12099 pcounts.table = peer->bgp->rib[afi][safi];
12100
12101 /* in-place call via thread subsystem so as to record execution time
12102 * stats for the thread-walk (i.e. ensure this can't be blamed on
12103 * on just vty_read()).
12104 */
12105 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
12106
Paul Jakmaff7924f2006-09-04 01:10:36 +000012107 vty_out (vty, "Prefix counts for %s, %s%s",
12108 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
12109 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
12110 vty_out (vty, "%sCounts from RIB table walk:%s%s",
12111 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
12112
12113 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +000012114 vty_out (vty, "%20s: %-10d%s",
12115 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012116
Paul Jakma2815e612006-09-14 02:56:07 +000012117 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +000012118 {
12119 vty_out (vty, "%s [pcount] PfxCt drift!%s",
12120 peer->host, VTY_NEWLINE);
12121 vty_out (vty, "Please report this bug, with the above command output%s",
12122 VTY_NEWLINE);
12123 }
12124
12125 return CMD_SUCCESS;
12126}
12127
Lou Bergerf9b6c392016-01-12 13:42:09 -050012128DEFUN (show_ip_bgp_neighbor_prefix_counts,
12129 show_ip_bgp_neighbor_prefix_counts_cmd,
12130 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12131 SHOW_STR
12132 IP_STR
12133 BGP_STR
12134 "Detailed information on TCP and BGP neighbor connections\n"
12135 "Neighbor to display information about\n"
12136 "Neighbor to display information about\n"
12137 "Display detailed prefix count information\n")
12138{
12139 struct peer *peer;
12140
12141 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12142 if (! peer)
12143 return CMD_WARNING;
12144
12145 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
12146}
12147
Paul Jakmaff7924f2006-09-04 01:10:36 +000012148DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
12149 show_bgp_ipv6_neighbor_prefix_counts_cmd,
12150 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12151 SHOW_STR
12152 BGP_STR
12153 "Address family\n"
12154 "Detailed information on TCP and BGP neighbor connections\n"
12155 "Neighbor to display information about\n"
12156 "Neighbor to display information about\n"
12157 "Display detailed prefix count information\n")
12158{
12159 struct peer *peer;
12160
12161 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12162 if (! peer)
12163 return CMD_WARNING;
12164
12165 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
12166}
Lou Bergerf9b6c392016-01-12 13:42:09 -050012167
12168DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
12169 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
12170 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12171 SHOW_STR
12172 IP_STR
12173 BGP_STR
12174 "Address family\n"
12175 "Address Family modifier\n"
12176 "Address Family modifier\n"
12177 "Detailed information on TCP and BGP neighbor connections\n"
12178 "Neighbor to display information about\n"
12179 "Neighbor to display information about\n"
12180 "Display detailed prefix count information\n")
12181{
12182 struct peer *peer;
12183
12184 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12185 if (! peer)
12186 return CMD_WARNING;
12187
12188 if (strncmp (argv[0], "m", 1) == 0)
12189 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
12190
12191 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
12192}
12193
12194DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
12195 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
12196 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12197 SHOW_STR
12198 IP_STR
12199 BGP_STR
12200 "Address family\n"
12201 "Address Family modifier\n"
12202 "Address Family modifier\n"
12203 "Detailed information on TCP and BGP neighbor connections\n"
12204 "Neighbor to display information about\n"
12205 "Neighbor to display information about\n"
12206 "Display detailed prefix count information\n")
12207{
12208 struct peer *peer;
12209
12210 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12211 if (! peer)
12212 return CMD_WARNING;
12213
12214 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
12215}
Paul Jakmaff7924f2006-09-04 01:10:36 +000012216
Lou Berger651b4022016-01-12 13:42:07 -050012217DEFUN (show_bgp_ipv4_safi_neighbor_prefix_counts,
12218 show_bgp_ipv4_safi_neighbor_prefix_counts_cmd,
12219 "show bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
Paul Jakmaff7924f2006-09-04 01:10:36 +000012220 SHOW_STR
Paul Jakmaff7924f2006-09-04 01:10:36 +000012221 BGP_STR
12222 "Address family\n"
12223 "Address Family modifier\n"
12224 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050012225 "Address Family modifier\n"
12226 "Address Family modifier\n"
Paul Jakmaff7924f2006-09-04 01:10:36 +000012227 "Detailed information on TCP and BGP neighbor connections\n"
12228 "Neighbor to display information about\n"
12229 "Neighbor to display information about\n"
12230 "Display detailed prefix count information\n")
12231{
12232 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050012233 safi_t safi;
12234
12235 if (bgp_parse_safi(argv[0], &safi)) {
12236 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12237 return CMD_WARNING;
12238 }
Paul Jakmaff7924f2006-09-04 01:10:36 +000012239
12240 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12241 if (! peer)
12242 return CMD_WARNING;
12243
Lou Berger651b4022016-01-12 13:42:07 -050012244 return bgp_peer_counts (vty, peer, AFI_IP, safi);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012245}
Lou Berger205e6742016-01-12 13:42:11 -050012246
Lou Berger651b4022016-01-12 13:42:07 -050012247DEFUN (show_bgp_ipv6_safi_neighbor_prefix_counts,
12248 show_bgp_ipv6_safi_neighbor_prefix_counts_cmd,
12249 "show bgp ipv6 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12250 SHOW_STR
12251 BGP_STR
12252 "Address family\n"
12253 "Address Family modifier\n"
12254 "Address Family modifier\n"
12255 "Address Family modifier\n"
12256 "Address Family modifier\n"
12257 "Detailed information on TCP and BGP neighbor connections\n"
12258 "Neighbor to display information about\n"
12259 "Neighbor to display information about\n"
12260 "Display detailed prefix count information\n")
12261{
12262 struct peer *peer;
12263 safi_t safi;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012264
Lou Berger651b4022016-01-12 13:42:07 -050012265 if (bgp_parse_safi(argv[0], &safi)) {
12266 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12267 return CMD_WARNING;
12268 }
12269
12270 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12271 if (! peer)
12272 return CMD_WARNING;
12273
12274 return bgp_peer_counts (vty, peer, AFI_IP6, safi);
12275}
Lou Berger651b4022016-01-12 13:42:07 -050012276
12277DEFUN (show_ip_bgp_encap_neighbor_prefix_counts,
12278 show_ip_bgp_encap_neighbor_prefix_counts_cmd,
12279 "show ip bgp encap all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
Paul Jakmaff7924f2006-09-04 01:10:36 +000012280 SHOW_STR
12281 IP_STR
12282 BGP_STR
12283 "Address family\n"
12284 "Address Family modifier\n"
12285 "Address Family modifier\n"
12286 "Detailed information on TCP and BGP neighbor connections\n"
12287 "Neighbor to display information about\n"
12288 "Neighbor to display information about\n"
12289 "Display detailed prefix count information\n")
12290{
12291 struct peer *peer;
12292
12293 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12294 if (! peer)
12295 return CMD_WARNING;
12296
Lou Berger651b4022016-01-12 13:42:07 -050012297 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_ENCAP);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012298}
12299
12300
paul94f2b392005-06-28 12:44:16 +000012301static void
paul718e3742002-12-13 20:15:29 +000012302show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
12303 int in)
12304{
12305 struct bgp_table *table;
12306 struct bgp_adj_in *ain;
12307 struct bgp_adj_out *adj;
12308 unsigned long output_count;
12309 struct bgp_node *rn;
12310 int header1 = 1;
12311 struct bgp *bgp;
12312 int header2 = 1;
12313
paulbb46e942003-10-24 19:02:03 +000012314 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +000012315
12316 if (! bgp)
12317 return;
12318
12319 table = bgp->rib[afi][safi];
12320
12321 output_count = 0;
12322
12323 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
12324 PEER_STATUS_DEFAULT_ORIGINATE))
12325 {
12326 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 +000012327 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12328 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012329
12330 vty_out (vty, "Originating default network 0.0.0.0%s%s",
12331 VTY_NEWLINE, VTY_NEWLINE);
12332 header1 = 0;
12333 }
12334
12335 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12336 if (in)
12337 {
12338 for (ain = rn->adj_in; ain; ain = ain->next)
12339 if (ain->peer == peer)
12340 {
12341 if (header1)
12342 {
12343 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 +000012344 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12345 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012346 header1 = 0;
12347 }
12348 if (header2)
12349 {
12350 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12351 header2 = 0;
12352 }
12353 if (ain->attr)
12354 {
12355 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
12356 output_count++;
12357 }
12358 }
12359 }
12360 else
12361 {
12362 for (adj = rn->adj_out; adj; adj = adj->next)
12363 if (adj->peer == peer)
12364 {
12365 if (header1)
12366 {
12367 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 +000012368 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12369 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012370 header1 = 0;
12371 }
12372 if (header2)
12373 {
12374 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12375 header2 = 0;
12376 }
12377 if (adj->attr)
12378 {
12379 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
12380 output_count++;
12381 }
12382 }
12383 }
12384
12385 if (output_count != 0)
12386 vty_out (vty, "%sTotal number of prefixes %ld%s",
12387 VTY_NEWLINE, output_count, VTY_NEWLINE);
12388}
12389
paul94f2b392005-06-28 12:44:16 +000012390static int
paulbb46e942003-10-24 19:02:03 +000012391peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
12392{
paul718e3742002-12-13 20:15:29 +000012393 if (! peer || ! peer->afc[afi][safi])
12394 {
12395 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12396 return CMD_WARNING;
12397 }
12398
12399 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12400 {
12401 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
12402 VTY_NEWLINE);
12403 return CMD_WARNING;
12404 }
12405
12406 show_adj_route (vty, peer, afi, safi, in);
12407
12408 return CMD_SUCCESS;
12409}
12410
Lou Bergerf9b6c392016-01-12 13:42:09 -050012411DEFUN (show_ip_bgp_view_neighbor_advertised_route,
12412 show_ip_bgp_view_neighbor_advertised_route_cmd,
12413 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12414 SHOW_STR
12415 IP_STR
12416 BGP_STR
12417 "BGP view\n"
12418 "View name\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 the routes advertised to a BGP neighbor\n")
12423{
12424 struct peer *peer;
12425
12426 if (argc == 2)
12427 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12428 else
12429 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12430
12431 if (! peer)
12432 return CMD_WARNING;
12433
12434 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
12435}
12436
12437ALIAS (show_ip_bgp_view_neighbor_advertised_route,
12438 show_ip_bgp_neighbor_advertised_route_cmd,
12439 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12440 SHOW_STR
12441 IP_STR
12442 BGP_STR
12443 "Detailed information on TCP and BGP neighbor connections\n"
12444 "Neighbor to display information about\n"
12445 "Neighbor to display information about\n"
12446 "Display the routes advertised to a BGP neighbor\n")
12447
12448DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
12449 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
12450 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12451 SHOW_STR
12452 IP_STR
12453 BGP_STR
12454 "Address family\n"
12455 "Address Family modifier\n"
12456 "Address Family modifier\n"
12457 "Detailed information on TCP and BGP neighbor connections\n"
12458 "Neighbor to display information about\n"
12459 "Neighbor to display information about\n"
12460 "Display the routes advertised to a BGP neighbor\n")
12461{
12462 struct peer *peer;
12463
12464 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12465 if (! peer)
12466 return CMD_WARNING;
12467
12468 if (strncmp (argv[0], "m", 1) == 0)
12469 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
12470
12471 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
12472}
12473
Lou Bergerf9b6c392016-01-12 13:42:09 -050012474DEFUN (show_bgp_view_neighbor_advertised_route,
12475 show_bgp_view_neighbor_advertised_route_cmd,
12476 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12477 SHOW_STR
12478 BGP_STR
12479 "BGP view\n"
12480 "View name\n"
12481 "Detailed information on TCP and BGP neighbor connections\n"
12482 "Neighbor to display information about\n"
12483 "Neighbor to display information about\n"
12484 "Display the routes advertised to a BGP neighbor\n")
12485{
12486 struct peer *peer;
12487
12488 if (argc == 2)
12489 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12490 else
12491 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12492
12493 if (! peer)
12494 return CMD_WARNING;
12495
12496 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
12497}
12498
12499DEFUN (show_bgp_view_neighbor_received_routes,
12500 show_bgp_view_neighbor_received_routes_cmd,
12501 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
12502 SHOW_STR
12503 BGP_STR
12504 "BGP view\n"
12505 "View name\n"
12506 "Detailed information on TCP and BGP neighbor connections\n"
12507 "Neighbor to display information about\n"
12508 "Neighbor to display information about\n"
12509 "Display the received routes from neighbor\n")
12510{
12511 struct peer *peer;
12512
12513 if (argc == 2)
12514 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12515 else
12516 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12517
12518 if (! peer)
12519 return CMD_WARNING;
12520
12521 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
12522}
12523
12524ALIAS (show_bgp_view_neighbor_advertised_route,
12525 show_bgp_neighbor_advertised_route_cmd,
12526 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12527 SHOW_STR
12528 BGP_STR
12529 "Detailed information on TCP and BGP neighbor connections\n"
12530 "Neighbor to display information about\n"
12531 "Neighbor to display information about\n"
12532 "Display the routes advertised to a BGP neighbor\n")
12533
12534ALIAS (show_bgp_view_neighbor_advertised_route,
12535 show_bgp_ipv6_neighbor_advertised_route_cmd,
12536 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12537 SHOW_STR
12538 BGP_STR
12539 "Address family\n"
12540 "Detailed information on TCP and BGP neighbor connections\n"
12541 "Neighbor to display information about\n"
12542 "Neighbor to display information about\n"
12543 "Display the routes advertised to a BGP neighbor\n")
12544
12545/* old command */
12546ALIAS (show_bgp_view_neighbor_advertised_route,
12547 ipv6_bgp_neighbor_advertised_route_cmd,
12548 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12549 SHOW_STR
12550 IPV6_STR
12551 BGP_STR
12552 "Detailed information on TCP and BGP neighbor connections\n"
12553 "Neighbor to display information about\n"
12554 "Neighbor to display information about\n"
12555 "Display the routes advertised to a BGP neighbor\n")
12556
12557/* old command */
12558DEFUN (ipv6_mbgp_neighbor_advertised_route,
12559 ipv6_mbgp_neighbor_advertised_route_cmd,
12560 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12561 SHOW_STR
12562 IPV6_STR
12563 MBGP_STR
12564 "Detailed information on TCP and BGP neighbor connections\n"
12565 "Neighbor to display information about\n"
12566 "Neighbor to display information about\n"
12567 "Display the routes advertised to a BGP neighbor\n")
12568{
12569 struct peer *peer;
12570
12571 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12572 if (! peer)
12573 return CMD_WARNING;
12574
12575 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
12576}
Lou Bergerf9b6c392016-01-12 13:42:09 -050012577
12578DEFUN (show_ip_bgp_view_neighbor_received_routes,
12579 show_ip_bgp_view_neighbor_received_routes_cmd,
12580 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
12581 SHOW_STR
12582 IP_STR
12583 BGP_STR
12584 "BGP view\n"
12585 "View name\n"
12586 "Detailed information on TCP and BGP neighbor connections\n"
12587 "Neighbor to display information about\n"
12588 "Neighbor to display information about\n"
12589 "Display the received routes from neighbor\n")
12590{
12591 struct peer *peer;
12592
12593 if (argc == 2)
12594 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12595 else
12596 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12597
12598 if (! peer)
12599 return CMD_WARNING;
12600
12601 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
12602}
12603
12604ALIAS (show_ip_bgp_view_neighbor_received_routes,
12605 show_ip_bgp_neighbor_received_routes_cmd,
12606 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12607 SHOW_STR
12608 IP_STR
12609 BGP_STR
12610 "Detailed information on TCP and BGP neighbor connections\n"
12611 "Neighbor to display information about\n"
12612 "Neighbor to display information about\n"
12613 "Display the received routes from neighbor\n")
12614
12615ALIAS (show_bgp_view_neighbor_received_routes,
12616 show_bgp_ipv6_neighbor_received_routes_cmd,
12617 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
12618 SHOW_STR
12619 BGP_STR
12620 "Address family\n"
12621 "Detailed information on TCP and BGP neighbor connections\n"
12622 "Neighbor to display information about\n"
12623 "Neighbor to display information about\n"
12624 "Display the received routes from neighbor\n")
12625
12626DEFUN (show_bgp_neighbor_received_prefix_filter,
12627 show_bgp_neighbor_received_prefix_filter_cmd,
12628 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
12629 SHOW_STR
12630 BGP_STR
12631 "Detailed information on TCP and BGP neighbor connections\n"
12632 "Neighbor to display information about\n"
12633 "Neighbor to display information about\n"
12634 "Display information received from a BGP neighbor\n"
12635 "Display the prefixlist filter\n")
12636{
12637 char name[BUFSIZ];
12638 union sockunion su;
12639 struct peer *peer;
12640 int count, ret;
12641
12642 ret = str2sockunion (argv[0], &su);
12643 if (ret < 0)
12644 {
12645 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
12646 return CMD_WARNING;
12647 }
12648
12649 peer = peer_lookup (NULL, &su);
12650 if (! peer)
12651 return CMD_WARNING;
12652
12653 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12654 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12655 if (count)
12656 {
12657 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12658 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12659 }
12660
12661 return CMD_SUCCESS;
12662}
12663
12664/* old command */
12665ALIAS (show_bgp_view_neighbor_received_routes,
12666 ipv6_bgp_neighbor_received_routes_cmd,
12667 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12668 SHOW_STR
12669 IPV6_STR
12670 BGP_STR
12671 "Detailed information on TCP and BGP neighbor connections\n"
12672 "Neighbor to display information about\n"
12673 "Neighbor to display information about\n"
12674 "Display the received routes from neighbor\n")
12675
12676/* old command */
12677DEFUN (ipv6_mbgp_neighbor_received_routes,
12678 ipv6_mbgp_neighbor_received_routes_cmd,
12679 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12680 SHOW_STR
12681 IPV6_STR
12682 MBGP_STR
12683 "Detailed information on TCP and BGP neighbor connections\n"
12684 "Neighbor to display information about\n"
12685 "Neighbor to display information about\n"
12686 "Display the received routes from neighbor\n")
12687{
12688 struct peer *peer;
12689
12690 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12691 if (! peer)
12692 return CMD_WARNING;
12693
12694 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
12695}
12696
12697DEFUN (show_bgp_view_neighbor_received_prefix_filter,
12698 show_bgp_view_neighbor_received_prefix_filter_cmd,
12699 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
12700 SHOW_STR
12701 BGP_STR
12702 "BGP view\n"
12703 "View name\n"
12704 "Detailed information on TCP and BGP neighbor connections\n"
12705 "Neighbor to display information about\n"
12706 "Neighbor to display information about\n"
12707 "Display information received from a BGP neighbor\n"
12708 "Display the prefixlist filter\n")
12709{
12710 char name[BUFSIZ];
12711 union sockunion su;
12712 struct peer *peer;
12713 struct bgp *bgp;
12714 int count, ret;
12715
12716 /* BGP structure lookup. */
12717 bgp = bgp_lookup_by_name (argv[0]);
12718 if (bgp == NULL)
12719 {
12720 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12721 return CMD_WARNING;
12722 }
12723
12724 ret = str2sockunion (argv[1], &su);
12725 if (ret < 0)
12726 {
12727 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
12728 return CMD_WARNING;
12729 }
12730
12731 peer = peer_lookup (bgp, &su);
12732 if (! peer)
12733 return CMD_WARNING;
12734
12735 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12736 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12737 if (count)
12738 {
12739 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12740 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12741 }
12742
12743 return CMD_SUCCESS;
12744}
12745
12746
12747DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12748 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
12749 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
12750 SHOW_STR
12751 IP_STR
12752 BGP_STR
12753 "Address family\n"
12754 "Address Family modifier\n"
12755 "Address Family modifier\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 received routes from neighbor\n")
12760{
12761 struct peer *peer;
12762
12763 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12764 if (! peer)
12765 return CMD_WARNING;
12766
12767 if (strncmp (argv[0], "m", 1) == 0)
12768 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
12769
12770 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
12771}
12772
Lou Berger651b4022016-01-12 13:42:07 -050012773DEFUN (show_bgp_ipv4_safi_neighbor_advertised_route,
12774 show_bgp_ipv4_safi_neighbor_advertised_route_cmd,
12775 "show bgp ipv4 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012776 SHOW_STR
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012777 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050012778 "Address Family modifier\n"
12779 "Address Family modifier\n"
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012780 "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;
Lou Berger651b4022016-01-12 13:42:07 -050012786 safi_t safi;
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012787
Lou Berger651b4022016-01-12 13:42:07 -050012788 if (bgp_parse_safi(argv[0], &safi)) {
12789 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012790 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050012791 }
paul718e3742002-12-13 20:15:29 +000012792
paulbb46e942003-10-24 19:02:03 +000012793 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12794 if (! peer)
12795 return CMD_WARNING;
12796
Lou Berger651b4022016-01-12 13:42:07 -050012797 return peer_adj_routes (vty, peer, AFI_IP, safi, 0);
12798}
Lou Berger205e6742016-01-12 13:42:11 -050012799
Lou Berger651b4022016-01-12 13:42:07 -050012800DEFUN (show_bgp_ipv6_safi_neighbor_advertised_route,
12801 show_bgp_ipv6_safi_neighbor_advertised_route_cmd,
12802 "show bgp ipv6 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12803 SHOW_STR
12804 BGP_STR
12805 "Address Family modifier\n"
12806 "Address Family modifier\n"
12807 "Address Family modifier\n"
12808 "Detailed information on TCP and BGP neighbor connections\n"
12809 "Neighbor to display information about\n"
12810 "Neighbor to display information about\n"
12811 "Display the routes advertised to a BGP neighbor\n")
12812{
12813 struct peer *peer;
12814 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000012815
Lou Berger651b4022016-01-12 13:42:07 -050012816 if (bgp_parse_safi(argv[0], &safi)) {
12817 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12818 return CMD_WARNING;
12819 }
12820
12821 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12822 if (! peer)
12823 return CMD_WARNING;
12824
12825 return peer_adj_routes (vty, peer, AFI_IP6, safi, 0);
paul718e3742002-12-13 20:15:29 +000012826}
12827
Lou Bergerf9b6c392016-01-12 13:42:09 -050012828DEFUN (show_bgp_view_ipv6_neighbor_advertised_route,
Lou Berger651b4022016-01-12 13:42:07 -050012829 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
12830 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
paulbb46e942003-10-24 19:02:03 +000012831 SHOW_STR
12832 BGP_STR
12833 "BGP view\n"
12834 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050012835 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000012836 "Detailed information on TCP and BGP neighbor connections\n"
12837 "Neighbor to display information about\n"
12838 "Neighbor to display information about\n"
12839 "Display the routes advertised to a BGP neighbor\n")
12840{
12841 struct peer *peer;
12842
12843 if (argc == 2)
12844 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12845 else
12846 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12847
12848 if (! peer)
12849 return CMD_WARNING;
12850
12851 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
12852}
12853
Lou Bergerf9b6c392016-01-12 13:42:09 -050012854DEFUN (show_bgp_view_ipv6_neighbor_received_routes,
Lou Berger651b4022016-01-12 13:42:07 -050012855 show_bgp_view_ipv6_neighbor_received_routes_cmd,
12856 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
paulbb46e942003-10-24 19:02:03 +000012857 SHOW_STR
12858 BGP_STR
12859 "BGP view\n"
12860 "View name\n"
12861 "Address family\n"
12862 "Detailed information on TCP and BGP neighbor connections\n"
12863 "Neighbor to display information about\n"
12864 "Neighbor to display information about\n"
paulbb46e942003-10-24 19:02:03 +000012865 "Display the received routes from neighbor\n")
12866{
12867 struct peer *peer;
12868
12869 if (argc == 2)
12870 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12871 else
12872 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12873
12874 if (! peer)
12875 return CMD_WARNING;
12876
12877 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
12878}
Lou Berger651b4022016-01-12 13:42:07 -050012879
12880DEFUN (show_bgp_ipv4_safi_neighbor_received_routes,
12881 show_bgp_ipv4_safi_neighbor_received_routes_cmd,
12882 "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 +010012883 SHOW_STR
paul718e3742002-12-13 20:15:29 +000012884 BGP_STR
12885 "Address family\n"
12886 "Address Family modifier\n"
12887 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050012888 "Address Family modifier\n"
12889 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000012890 "Detailed information on TCP and BGP neighbor connections\n"
12891 "Neighbor to display information about\n"
12892 "Neighbor to display information about\n"
12893 "Display the received routes from neighbor\n")
12894{
paulbb46e942003-10-24 19:02:03 +000012895 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050012896 safi_t safi;
12897
12898 if (bgp_parse_safi(argv[0], &safi)) {
12899 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12900 return CMD_WARNING;
12901 }
paul718e3742002-12-13 20:15:29 +000012902
paulbb46e942003-10-24 19:02:03 +000012903 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12904 if (! peer)
12905 return CMD_WARNING;
12906
Lou Berger651b4022016-01-12 13:42:07 -050012907 return peer_adj_routes (vty, peer, AFI_IP, safi, 1);
paul718e3742002-12-13 20:15:29 +000012908}
Lou Berger205e6742016-01-12 13:42:11 -050012909
Lou Berger651b4022016-01-12 13:42:07 -050012910DEFUN (show_bgp_ipv6_safi_neighbor_received_routes,
12911 show_bgp_ipv6_safi_neighbor_received_routes_cmd,
12912 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) received-routes",
12913 SHOW_STR
12914 BGP_STR
12915 "Address family\n"
12916 "Address Family modifier\n"
12917 "Address Family modifier\n"
12918 "Address Family modifier\n"
12919 "Address Family modifier\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 the received routes from neighbor\n")
12924{
12925 struct peer *peer;
12926 safi_t safi;
12927
12928 if (bgp_parse_safi(argv[0], &safi)) {
12929 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12930 return CMD_WARNING;
12931 }
12932
12933 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12934 if (! peer)
12935 return CMD_WARNING;
12936
12937 return peer_adj_routes (vty, peer, AFI_IP6, safi, 1);
12938}
paul718e3742002-12-13 20:15:29 +000012939
Michael Lambert95cbbd22010-07-23 14:43:04 -040012940DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
12941 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040012942 "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 -040012943 SHOW_STR
12944 BGP_STR
12945 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000012946 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040012947 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040012948 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040012949 "Address family modifier\n"
12950 "Address family modifier\n"
12951 "Detailed information on TCP and BGP neighbor connections\n"
12952 "Neighbor to display information about\n"
12953 "Neighbor to display information about\n"
12954 "Display the advertised routes to neighbor\n"
12955 "Display the received routes from neighbor\n")
12956{
12957 int afi;
12958 int safi;
12959 int in;
12960 struct peer *peer;
12961
David Lamparter94bad672015-03-03 08:52:22 +010012962 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012963
12964 if (! peer)
12965 return CMD_WARNING;
12966
Michael Lambert95cbbd22010-07-23 14:43:04 -040012967 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
12968 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12969 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040012970
12971 return peer_adj_routes (vty, peer, afi, safi, in);
12972}
12973
Lou Bergerf9b6c392016-01-12 13:42:09 -050012974DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
12975 show_ip_bgp_neighbor_received_prefix_filter_cmd,
12976 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
12977 SHOW_STR
12978 IP_STR
12979 BGP_STR
12980 "Detailed information on TCP and BGP neighbor connections\n"
12981 "Neighbor to display information about\n"
12982 "Neighbor to display information about\n"
12983 "Display information received from a BGP neighbor\n"
12984 "Display the prefixlist filter\n")
12985{
12986 char name[BUFSIZ];
12987 union sockunion su;
12988 struct peer *peer;
12989 int count, ret;
12990
12991 ret = str2sockunion (argv[0], &su);
12992 if (ret < 0)
12993 {
12994 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
12995 return CMD_WARNING;
12996 }
12997
12998 peer = peer_lookup (NULL, &su);
12999 if (! peer)
13000 return CMD_WARNING;
13001
13002 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
13003 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13004 if (count)
13005 {
13006 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13007 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13008 }
13009
13010 return CMD_SUCCESS;
13011}
13012
13013DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
13014 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
13015 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
13016 SHOW_STR
13017 IP_STR
13018 BGP_STR
13019 "Address family\n"
13020 "Address Family modifier\n"
13021 "Address Family modifier\n"
13022 "Detailed information on TCP and BGP neighbor connections\n"
13023 "Neighbor to display information about\n"
13024 "Neighbor to display information about\n"
13025 "Display information received from a BGP neighbor\n"
13026 "Display the prefixlist filter\n")
13027{
13028 char name[BUFSIZ];
13029 union sockunion su;
13030 struct peer *peer;
13031 int count, ret;
13032
13033 ret = str2sockunion (argv[1], &su);
13034 if (ret < 0)
13035 {
13036 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13037 return CMD_WARNING;
13038 }
13039
13040 peer = peer_lookup (NULL, &su);
13041 if (! peer)
13042 return CMD_WARNING;
13043
13044 if (strncmp (argv[0], "m", 1) == 0)
13045 {
13046 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
13047 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13048 if (count)
13049 {
13050 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
13051 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13052 }
13053 }
13054 else
13055 {
13056 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
13057 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13058 if (count)
13059 {
13060 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13061 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13062 }
13063 }
13064
13065 return CMD_SUCCESS;
13066}
13067
13068ALIAS (show_bgp_view_neighbor_received_routes,
13069 show_bgp_neighbor_received_routes_cmd,
13070 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
13071 SHOW_STR
13072 BGP_STR
13073 "Detailed information on TCP and BGP neighbor connections\n"
13074 "Neighbor to display information about\n"
13075 "Neighbor to display information about\n"
13076 "Display the received routes from neighbor\n")
13077
Lou Berger651b4022016-01-12 13:42:07 -050013078DEFUN (show_bgp_ipv4_safi_neighbor_received_prefix_filter,
13079 show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd,
13080 "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 +000013081 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013082 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013083 IP_STR
13084 "Address Family modifier\n"
13085 "Address Family modifier\n"
13086 "Address Family modifier\n"
13087 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000013088 "Detailed information on TCP and BGP neighbor connections\n"
13089 "Neighbor to display information about\n"
13090 "Neighbor to display information about\n"
13091 "Display information received from a BGP neighbor\n"
13092 "Display the prefixlist filter\n")
13093{
13094 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013095 union sockunion su;
paul718e3742002-12-13 20:15:29 +000013096 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013097 int count, ret;
Lou Berger651b4022016-01-12 13:42:07 -050013098 safi_t safi;
paul718e3742002-12-13 20:15:29 +000013099
Lou Berger651b4022016-01-12 13:42:07 -050013100 if (bgp_parse_safi(argv[0], &safi)) {
13101 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000013102 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050013103 }
paul718e3742002-12-13 20:15:29 +000013104
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013105 ret = str2sockunion (argv[1], &su);
13106 if (ret < 0)
13107 {
13108 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13109 return CMD_WARNING;
13110 }
paul718e3742002-12-13 20:15:29 +000013111
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013112 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000013113 if (! peer)
13114 return CMD_WARNING;
13115
Lou Berger651b4022016-01-12 13:42:07 -050013116 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, safi);
13117 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13118 if (count) {
13119 vty_out (vty, "Address family: IPv4 %s%s", safi2str(safi), VTY_NEWLINE);
13120 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13121 }
paul718e3742002-12-13 20:15:29 +000013122
13123 return CMD_SUCCESS;
13124}
Lou Berger205e6742016-01-12 13:42:11 -050013125
Lou Berger651b4022016-01-12 13:42:07 -050013126DEFUN (show_bgp_ipv6_safi_neighbor_received_prefix_filter,
13127 show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd,
13128 "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 +000013129 SHOW_STR
13130 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013131 IP_STR
13132 "Address Family modifier\n"
13133 "Address Family modifier\n"
13134 "Address Family modifier\n"
13135 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000013136 "Detailed information on TCP and BGP neighbor connections\n"
13137 "Neighbor to display information about\n"
13138 "Neighbor to display information about\n"
Lou Berger651b4022016-01-12 13:42:07 -050013139 "Display information received from a BGP neighbor\n"
13140 "Display the prefixlist filter\n")
13141{
13142 char name[BUFSIZ];
13143 union sockunion su;
13144 struct peer *peer;
13145 int count, ret;
13146 safi_t safi;
13147
13148 if (bgp_parse_safi(argv[0], &safi)) {
13149 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13150 return CMD_WARNING;
13151 }
13152
13153 ret = str2sockunion (argv[1], &su);
13154 if (ret < 0)
13155 {
13156 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13157 return CMD_WARNING;
13158 }
13159
13160 peer = peer_lookup (NULL, &su);
13161 if (! peer)
13162 return CMD_WARNING;
13163
13164 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, safi);
13165 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13166 if (count) {
13167 vty_out (vty, "Address family: IPv6 %s%s", safi2str(safi), VTY_NEWLINE);
13168 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13169 }
13170
13171 return CMD_SUCCESS;
13172}
paul718e3742002-12-13 20:15:29 +000013173
Lou Bergerf9b6c392016-01-12 13:42:09 -050013174DEFUN (show_bgp_ipv6_neighbor_received_prefix_filter,
Lou Berger651b4022016-01-12 13:42:07 -050013175 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
13176 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
paul718e3742002-12-13 20:15:29 +000013177 SHOW_STR
13178 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013179 "Address family\n"
paul718e3742002-12-13 20:15:29 +000013180 "Detailed information on TCP and BGP neighbor connections\n"
13181 "Neighbor to display information about\n"
13182 "Neighbor to display information about\n"
13183 "Display information received from a BGP neighbor\n"
13184 "Display the prefixlist filter\n")
13185{
13186 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013187 union sockunion su;
paul718e3742002-12-13 20:15:29 +000013188 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013189 int count, ret;
paul718e3742002-12-13 20:15:29 +000013190
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013191 ret = str2sockunion (argv[0], &su);
13192 if (ret < 0)
13193 {
13194 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
13195 return CMD_WARNING;
13196 }
paul718e3742002-12-13 20:15:29 +000013197
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013198 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000013199 if (! peer)
13200 return CMD_WARNING;
13201
13202 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13203 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13204 if (count)
13205 {
13206 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13207 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13208 }
13209
13210 return CMD_SUCCESS;
13211}
13212
Lou Bergerf9b6c392016-01-12 13:42:09 -050013213DEFUN (show_bgp_view_ipv6_neighbor_received_prefix_filter,
Lou Berger651b4022016-01-12 13:42:07 -050013214 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
13215 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
paulbb46e942003-10-24 19:02:03 +000013216 SHOW_STR
13217 BGP_STR
13218 "BGP view\n"
13219 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050013220 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000013221 "Detailed information on TCP and BGP neighbor connections\n"
13222 "Neighbor to display information about\n"
13223 "Neighbor to display information about\n"
13224 "Display information received from a BGP neighbor\n"
13225 "Display the prefixlist filter\n")
13226{
13227 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013228 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000013229 struct peer *peer;
13230 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013231 int count, ret;
paulbb46e942003-10-24 19:02:03 +000013232
13233 /* BGP structure lookup. */
13234 bgp = bgp_lookup_by_name (argv[0]);
13235 if (bgp == NULL)
13236 {
13237 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13238 return CMD_WARNING;
13239 }
13240
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013241 ret = str2sockunion (argv[1], &su);
13242 if (ret < 0)
13243 {
13244 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13245 return CMD_WARNING;
13246 }
paulbb46e942003-10-24 19:02:03 +000013247
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013248 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000013249 if (! peer)
13250 return CMD_WARNING;
13251
13252 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13253 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13254 if (count)
13255 {
13256 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13257 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13258 }
13259
13260 return CMD_SUCCESS;
13261}
David Lamparter6b0655a2014-06-04 06:53:35 +020013262
paul94f2b392005-06-28 12:44:16 +000013263static int
paulbb46e942003-10-24 19:02:03 +000013264bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000013265 safi_t safi, enum bgp_show_type type)
13266{
paul718e3742002-12-13 20:15:29 +000013267 if (! peer || ! peer->afc[afi][safi])
13268 {
13269 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000013270 return CMD_WARNING;
13271 }
13272
ajs5a646652004-11-05 01:25:55 +000013273 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000013274}
Lou Bergerf9b6c392016-01-12 13:42:09 -050013275DEFUN (show_ip_bgp_neighbor_routes,
13276 show_ip_bgp_neighbor_routes_cmd,
13277 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
13278 SHOW_STR
13279 IP_STR
13280 BGP_STR
13281 "Detailed information on TCP and BGP neighbor connections\n"
13282 "Neighbor to display information about\n"
13283 "Neighbor to display information about\n"
13284 "Display routes learned from neighbor\n")
13285{
13286 struct peer *peer;
13287
13288 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13289 if (! peer)
13290 return CMD_WARNING;
13291
13292 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13293 bgp_show_type_neighbor);
13294}
13295
13296DEFUN (show_ip_bgp_neighbor_flap,
13297 show_ip_bgp_neighbor_flap_cmd,
13298 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
13299 SHOW_STR
13300 IP_STR
13301 BGP_STR
13302 "Detailed information on TCP and BGP neighbor connections\n"
13303 "Neighbor to display information about\n"
13304 "Neighbor to display information about\n"
13305 "Display flap statistics of the routes learned from neighbor\n")
13306{
13307 struct peer *peer;
13308
13309 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13310 if (! peer)
13311 return CMD_WARNING;
13312
13313 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13314 bgp_show_type_flap_neighbor);
13315}
13316
13317DEFUN (show_ip_bgp_neighbor_damp,
13318 show_ip_bgp_neighbor_damp_cmd,
13319 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
13320 SHOW_STR
13321 IP_STR
13322 BGP_STR
13323 "Detailed information on TCP and BGP neighbor connections\n"
13324 "Neighbor to display information about\n"
13325 "Neighbor to display information about\n"
13326 "Display the dampened routes received from neighbor\n")
13327{
13328 struct peer *peer;
13329
13330 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13331 if (! peer)
13332 return CMD_WARNING;
13333
13334 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13335 bgp_show_type_damp_neighbor);
13336}
13337
13338DEFUN (show_ip_bgp_ipv4_neighbor_routes,
13339 show_ip_bgp_ipv4_neighbor_routes_cmd,
13340 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
13341 SHOW_STR
13342 IP_STR
13343 BGP_STR
13344 "Address family\n"
13345 "Address Family modifier\n"
13346 "Address Family modifier\n"
13347 "Detailed information on TCP and BGP neighbor connections\n"
13348 "Neighbor to display information about\n"
13349 "Neighbor to display information about\n"
13350 "Display routes learned from neighbor\n")
13351{
13352 struct peer *peer;
13353
13354 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13355 if (! peer)
13356 return CMD_WARNING;
13357
13358 if (strncmp (argv[0], "m", 1) == 0)
13359 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
13360 bgp_show_type_neighbor);
13361
13362 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13363 bgp_show_type_neighbor);
13364}
13365
13366DEFUN (show_ip_bgp_view_rsclient,
13367 show_ip_bgp_view_rsclient_cmd,
13368 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
13369 SHOW_STR
13370 IP_STR
13371 BGP_STR
13372 "BGP view\n"
13373 "View name\n"
13374 "Information about Route Server Client\n"
13375 NEIGHBOR_ADDR_STR)
13376{
13377 struct bgp_table *table;
13378 struct peer *peer;
13379
13380 if (argc == 2)
13381 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13382 else
13383 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13384
13385 if (! peer)
13386 return CMD_WARNING;
13387
13388 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13389 {
13390 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13391 VTY_NEWLINE);
13392 return CMD_WARNING;
13393 }
13394
13395 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13396 PEER_FLAG_RSERVER_CLIENT))
13397 {
13398 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13399 VTY_NEWLINE);
13400 return CMD_WARNING;
13401 }
13402
13403 table = peer->rib[AFI_IP][SAFI_UNICAST];
13404
13405 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
13406}
13407
13408ALIAS (show_ip_bgp_view_rsclient,
13409 show_ip_bgp_rsclient_cmd,
13410 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
13411 SHOW_STR
13412 IP_STR
13413 BGP_STR
13414 "Information about Route Server Client\n"
13415 NEIGHBOR_ADDR_STR)
13416
13417DEFUN (show_bgp_view_ipv4_safi_rsclient,
13418 show_bgp_view_ipv4_safi_rsclient_cmd,
13419 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
13420 SHOW_STR
13421 BGP_STR
13422 "BGP view\n"
13423 "View name\n"
13424 "Address family\n"
13425 "Address Family modifier\n"
13426 "Address Family modifier\n"
13427 "Information about Route Server Client\n"
13428 NEIGHBOR_ADDR_STR)
13429{
13430 struct bgp_table *table;
13431 struct peer *peer;
13432 safi_t safi;
13433
13434 if (argc == 3) {
13435 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13436 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13437 } else {
13438 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13439 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13440 }
13441
13442 if (! peer)
13443 return CMD_WARNING;
13444
13445 if (! peer->afc[AFI_IP][safi])
13446 {
13447 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13448 VTY_NEWLINE);
13449 return CMD_WARNING;
13450 }
13451
13452 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13453 PEER_FLAG_RSERVER_CLIENT))
13454 {
13455 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13456 VTY_NEWLINE);
13457 return CMD_WARNING;
13458 }
13459
13460 table = peer->rib[AFI_IP][safi];
13461
13462 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
13463}
13464
13465ALIAS (show_bgp_view_ipv4_safi_rsclient,
13466 show_bgp_ipv4_safi_rsclient_cmd,
13467 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
13468 SHOW_STR
13469 BGP_STR
13470 "Address family\n"
13471 "Address Family modifier\n"
13472 "Address Family modifier\n"
13473 "Information about Route Server Client\n"
13474 NEIGHBOR_ADDR_STR)
13475
13476DEFUN (show_ip_bgp_view_rsclient_route,
13477 show_ip_bgp_view_rsclient_route_cmd,
13478 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13479 SHOW_STR
13480 IP_STR
13481 BGP_STR
13482 "BGP view\n"
13483 "View name\n"
13484 "Information about Route Server Client\n"
13485 NEIGHBOR_ADDR_STR
13486 "Network in the BGP routing table to display\n")
13487{
13488 struct bgp *bgp;
13489 struct peer *peer;
13490
13491 /* BGP structure lookup. */
13492 if (argc == 3)
13493 {
13494 bgp = bgp_lookup_by_name (argv[0]);
13495 if (bgp == NULL)
13496 {
13497 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13498 return CMD_WARNING;
13499 }
13500 }
13501 else
13502 {
13503 bgp = bgp_get_default ();
13504 if (bgp == NULL)
13505 {
13506 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13507 return CMD_WARNING;
13508 }
13509 }
13510
13511 if (argc == 3)
13512 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13513 else
13514 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13515
13516 if (! peer)
13517 return CMD_WARNING;
13518
13519 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13520 {
13521 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13522 VTY_NEWLINE);
13523 return CMD_WARNING;
13524}
13525
13526 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13527 PEER_FLAG_RSERVER_CLIENT))
13528 {
13529 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13530 VTY_NEWLINE);
13531 return CMD_WARNING;
13532 }
13533
13534 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
13535 (argc == 3) ? argv[2] : argv[1],
13536 AFI_IP, SAFI_UNICAST, NULL, 0);
13537}
13538
13539ALIAS (show_ip_bgp_view_rsclient_route,
13540 show_ip_bgp_rsclient_route_cmd,
13541 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13542 SHOW_STR
13543 IP_STR
13544 BGP_STR
13545 "Information about Route Server Client\n"
13546 NEIGHBOR_ADDR_STR
13547 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +000013548
Lou Berger651b4022016-01-12 13:42:07 -050013549DEFUN (show_bgp_ipv4_safi_neighbor_flap,
13550 show_bgp_ipv4_safi_neighbor_flap_cmd,
13551 "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paul718e3742002-12-13 20:15:29 +000013552 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013553 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013554 "Address Family Modifier\n"
13555 "Address Family Modifier\n"
13556 "Address Family Modifier\n"
13557 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +000013558 "Detailed information on TCP and BGP neighbor connections\n"
13559 "Neighbor to display information about\n"
13560 "Neighbor to display information about\n"
13561 "Display flap statistics of the routes learned from neighbor\n")
13562{
paulbb46e942003-10-24 19:02:03 +000013563 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013564 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000013565
Lou Berger651b4022016-01-12 13:42:07 -050013566 if (bgp_parse_safi(argv[0], &safi)) {
13567 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13568 return CMD_WARNING;
13569 }
13570
13571 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulbb46e942003-10-24 19:02:03 +000013572 if (! peer)
13573 return CMD_WARNING;
13574
Lou Berger651b4022016-01-12 13:42:07 -050013575 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013576 bgp_show_type_flap_neighbor);
13577}
Lou Berger205e6742016-01-12 13:42:11 -050013578
Lou Berger651b4022016-01-12 13:42:07 -050013579DEFUN (show_bgp_ipv6_safi_neighbor_flap,
13580 show_bgp_ipv6_safi_neighbor_flap_cmd,
13581 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paul718e3742002-12-13 20:15:29 +000013582 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013583 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013584 "Address Family Modifier\n"
13585 "Address Family Modifier\n"
13586 "Address Family Modifier\n"
13587 "Address Family Modifier\n"
13588 "Detailed information on TCP and BGP neighbor connections\n"
13589 "Neighbor to display information about\n"
13590 "Neighbor to display information about\n"
13591 "Display flap statistics of the routes learned from neighbor\n")
13592{
13593 struct peer *peer;
13594 safi_t safi;
13595
13596 if (bgp_parse_safi(argv[0], &safi)) {
13597 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13598 return CMD_WARNING;
13599 }
13600
13601 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13602 if (! peer)
13603 return CMD_WARNING;
13604
13605 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13606 bgp_show_type_flap_neighbor);
13607}
Lou Berger651b4022016-01-12 13:42:07 -050013608
13609DEFUN (show_bgp_ipv4_safi_neighbor_damp,
13610 show_bgp_ipv4_safi_neighbor_damp_cmd,
13611 "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) dampened-routes",
13612 SHOW_STR
13613 BGP_STR
13614 "Address Family Modifier\n"
13615 "Address Family Modifier\n"
13616 "Address Family Modifier\n"
13617 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +000013618 "Detailed information on TCP and BGP neighbor connections\n"
13619 "Neighbor to display information about\n"
13620 "Neighbor to display information about\n"
13621 "Display the dampened routes received from neighbor\n")
13622{
paulbb46e942003-10-24 19:02:03 +000013623 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013624 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000013625
Lou Berger651b4022016-01-12 13:42:07 -050013626 if (bgp_parse_safi(argv[0], &safi)) {
13627 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13628 return CMD_WARNING;
13629 }
13630
13631 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulbb46e942003-10-24 19:02:03 +000013632 if (! peer)
13633 return CMD_WARNING;
13634
Lou Berger651b4022016-01-12 13:42:07 -050013635 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013636 bgp_show_type_damp_neighbor);
13637}
Lou Berger205e6742016-01-12 13:42:11 -050013638
Lou Berger651b4022016-01-12 13:42:07 -050013639DEFUN (show_bgp_ipv6_safi_neighbor_damp,
13640 show_bgp_ipv6_safi_neighbor_damp_cmd,
13641 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) dampened-routes",
paul718e3742002-12-13 20:15:29 +000013642 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -050013643 BGP_STR
13644 "Address Family Modifier\n"
13645 "Address Family Modifier\n"
13646 "Address Family Modifier\n"
13647 "Address Family Modifier\n"
13648 "Detailed information on TCP and BGP neighbor connections\n"
13649 "Neighbor to display information about\n"
13650 "Neighbor to display information about\n"
13651 "Display the dampened routes received from neighbor\n")
13652{
13653 struct peer *peer;
13654 safi_t safi;
13655
13656 if (bgp_parse_safi(argv[0], &safi)) {
13657 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13658 return CMD_WARNING;
13659 }
13660
13661 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13662 if (! peer)
13663 return CMD_WARNING;
13664
13665 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13666 bgp_show_type_damp_neighbor);
13667}
Lou Berger651b4022016-01-12 13:42:07 -050013668
13669DEFUN (show_bgp_ipv4_safi_neighbor_routes,
13670 show_bgp_ipv4_safi_neighbor_routes_cmd,
13671 "show bgp ipv4 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) routes",
13672 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013673 BGP_STR
13674 "Address family\n"
13675 "Address Family modifier\n"
13676 "Address Family modifier\n"
13677 "Detailed information on TCP and BGP neighbor connections\n"
13678 "Neighbor to display information about\n"
13679 "Neighbor to display information about\n"
13680 "Display routes learned from neighbor\n")
13681{
paulbb46e942003-10-24 19:02:03 +000013682 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013683 safi_t safi;
13684
13685 if (bgp_parse_safi(argv[0], &safi)) {
13686 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13687 return CMD_WARNING;
13688 }
paulbb46e942003-10-24 19:02:03 +000013689
13690 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13691 if (! peer)
13692 return CMD_WARNING;
13693
Lou Berger651b4022016-01-12 13:42:07 -050013694 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013695 bgp_show_type_neighbor);
13696}
Lou Berger205e6742016-01-12 13:42:11 -050013697
Lou Berger651b4022016-01-12 13:42:07 -050013698DEFUN (show_bgp_ipv6_safi_neighbor_routes,
13699 show_bgp_ipv6_safi_neighbor_routes_cmd,
13700 "show bgp ipv6 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) routes",
paulfee0f4c2004-09-13 05:12:46 +000013701 SHOW_STR
paulfee0f4c2004-09-13 05:12:46 +000013702 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013703 "Address family\n"
13704 "Address Family modifier\n"
13705 "Address Family modifier\n"
13706 "Detailed information on TCP and BGP neighbor connections\n"
13707 NEIGHBOR_ADDR_STR
13708 NEIGHBOR_ADDR_STR
13709 "Display routes learned from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000013710{
paulfee0f4c2004-09-13 05:12:46 +000013711 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013712 safi_t safi;
paulfee0f4c2004-09-13 05:12:46 +000013713
Lou Berger651b4022016-01-12 13:42:07 -050013714 if (bgp_parse_safi(argv[0], &safi)) {
13715 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13716 return CMD_WARNING;
13717 }
paulfee0f4c2004-09-13 05:12:46 +000013718
Lou Berger651b4022016-01-12 13:42:07 -050013719 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulfee0f4c2004-09-13 05:12:46 +000013720 if (! peer)
13721 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050013722
13723 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13724 bgp_show_type_neighbor);
paulfee0f4c2004-09-13 05:12:46 +000013725}
paulfee0f4c2004-09-13 05:12:46 +000013726
Michael Lambert95cbbd22010-07-23 14:43:04 -040013727DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
13728 show_bgp_view_ipv4_safi_rsclient_route_cmd,
13729 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13730 SHOW_STR
13731 BGP_STR
13732 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000013733 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013734 "Address family\n"
13735 "Address Family modifier\n"
13736 "Address Family modifier\n"
13737 "Information about Route Server Client\n"
13738 NEIGHBOR_ADDR_STR
13739 "Network in the BGP routing table to display\n")
13740{
13741 struct bgp *bgp;
13742 struct peer *peer;
13743 safi_t safi;
13744
13745 /* BGP structure lookup. */
13746 if (argc == 4)
13747 {
13748 bgp = bgp_lookup_by_name (argv[0]);
13749 if (bgp == NULL)
13750 {
13751 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13752 return CMD_WARNING;
13753 }
13754 }
13755 else
13756 {
13757 bgp = bgp_get_default ();
13758 if (bgp == NULL)
13759 {
13760 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13761 return CMD_WARNING;
13762 }
13763 }
13764
13765 if (argc == 4) {
13766 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13767 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13768 } else {
13769 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13770 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13771 }
13772
13773 if (! peer)
13774 return CMD_WARNING;
13775
13776 if (! peer->afc[AFI_IP][safi])
13777 {
13778 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13779 VTY_NEWLINE);
13780 return CMD_WARNING;
13781}
13782
13783 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13784 PEER_FLAG_RSERVER_CLIENT))
13785 {
13786 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13787 VTY_NEWLINE);
13788 return CMD_WARNING;
13789 }
13790
13791 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
13792 (argc == 4) ? argv[3] : argv[2],
13793 AFI_IP, safi, NULL, 0);
13794}
13795
13796ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
13797 show_bgp_ipv4_safi_rsclient_route_cmd,
13798 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13799 SHOW_STR
13800 BGP_STR
13801 "Address family\n"
13802 "Address Family modifier\n"
13803 "Address Family modifier\n"
13804 "Information about Route Server Client\n"
13805 NEIGHBOR_ADDR_STR
13806 "Network in the BGP routing table to display\n")
13807
paulfee0f4c2004-09-13 05:12:46 +000013808
Michael Lambert95cbbd22010-07-23 14:43:04 -040013809DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
13810 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
13811 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
13812 SHOW_STR
13813 BGP_STR
13814 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000013815 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013816 "Address family\n"
13817 "Address Family modifier\n"
13818 "Address Family modifier\n"
13819 "Information about Route Server Client\n"
13820 NEIGHBOR_ADDR_STR
13821 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13822{
13823 struct bgp *bgp;
13824 struct peer *peer;
13825 safi_t safi;
13826
13827 /* BGP structure lookup. */
13828 if (argc == 4)
13829 {
13830 bgp = bgp_lookup_by_name (argv[0]);
13831 if (bgp == NULL)
13832 {
13833 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13834 return CMD_WARNING;
13835 }
13836 }
13837 else
13838 {
13839 bgp = bgp_get_default ();
13840 if (bgp == NULL)
13841 {
13842 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13843 return CMD_WARNING;
13844 }
13845 }
13846
13847 if (argc == 4) {
13848 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13849 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13850 } else {
13851 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13852 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13853 }
13854
13855 if (! peer)
13856 return CMD_WARNING;
13857
13858 if (! peer->afc[AFI_IP][safi])
13859 {
13860 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13861 VTY_NEWLINE);
13862 return CMD_WARNING;
13863}
13864
13865 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13866 PEER_FLAG_RSERVER_CLIENT))
13867{
13868 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13869 VTY_NEWLINE);
13870 return CMD_WARNING;
13871 }
13872
13873 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
13874 (argc == 4) ? argv[3] : argv[2],
13875 AFI_IP, safi, NULL, 1);
13876}
13877
Lou Bergerf9b6c392016-01-12 13:42:09 -050013878DEFUN (show_ip_bgp_view_rsclient_prefix,
13879 show_ip_bgp_view_rsclient_prefix_cmd,
13880 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
13881 SHOW_STR
13882 IP_STR
13883 BGP_STR
13884 "BGP view\n"
13885 "View name\n"
13886 "Information about Route Server Client\n"
13887 NEIGHBOR_ADDR_STR
13888 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13889{
13890 struct bgp *bgp;
13891 struct peer *peer;
13892
13893 /* BGP structure lookup. */
13894 if (argc == 3)
13895 {
13896 bgp = bgp_lookup_by_name (argv[0]);
13897 if (bgp == NULL)
13898 {
13899 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13900 return CMD_WARNING;
13901 }
13902 }
13903 else
13904 {
13905 bgp = bgp_get_default ();
13906 if (bgp == NULL)
13907 {
13908 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13909 return CMD_WARNING;
13910 }
13911 }
13912
13913 if (argc == 3)
13914 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13915 else
13916 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13917
13918 if (! peer)
13919 return CMD_WARNING;
13920
13921 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13922 {
13923 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13924 VTY_NEWLINE);
13925 return CMD_WARNING;
13926}
13927
13928 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13929 PEER_FLAG_RSERVER_CLIENT))
13930{
13931 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13932 VTY_NEWLINE);
13933 return CMD_WARNING;
13934 }
13935
13936 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
13937 (argc == 3) ? argv[2] : argv[1],
13938 AFI_IP, SAFI_UNICAST, NULL, 1);
13939}
13940
13941ALIAS (show_ip_bgp_view_rsclient_prefix,
13942 show_ip_bgp_rsclient_prefix_cmd,
13943 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
13944 SHOW_STR
13945 IP_STR
13946 BGP_STR
13947 "Information about Route Server Client\n"
13948 NEIGHBOR_ADDR_STR
13949 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13950
Michael Lambert95cbbd22010-07-23 14:43:04 -040013951ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
13952 show_bgp_ipv4_safi_rsclient_prefix_cmd,
13953 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
13954 SHOW_STR
13955 BGP_STR
13956 "Address family\n"
13957 "Address Family modifier\n"
13958 "Address Family modifier\n"
13959 "Information about Route Server Client\n"
13960 NEIGHBOR_ADDR_STR
13961 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000013962
Lou Bergerf9b6c392016-01-12 13:42:09 -050013963DEFUN (show_bgp_view_ipv6_neighbor_routes,
Lou Berger651b4022016-01-12 13:42:07 -050013964 show_bgp_view_ipv6_neighbor_routes_cmd,
13965 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
paulbb46e942003-10-24 19:02:03 +000013966 SHOW_STR
13967 BGP_STR
13968 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000013969 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050013970 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000013971 "Detailed information on TCP and BGP neighbor connections\n"
13972 "Neighbor to display information about\n"
13973 "Neighbor to display information about\n"
13974 "Display routes learned from neighbor\n")
13975{
13976 struct peer *peer;
13977
13978 if (argc == 2)
13979 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13980 else
13981 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13982
13983 if (! peer)
13984 return CMD_WARNING;
13985
13986 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13987 bgp_show_type_neighbor);
13988}
13989
Lou Berger651b4022016-01-12 13:42:07 -050013990DEFUN (show_bgp_view_neighbor_damp,
Lou Bergerf9b6c392016-01-12 13:42:09 -050013991 show_bgp_view_neighbor_damp_cmd,
13992 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
13993 SHOW_STR
13994 BGP_STR
13995 "BGP view\n"
13996 "View name\n"
13997 "Detailed information on TCP and BGP neighbor connections\n"
13998 "Neighbor to display information about\n"
13999 "Neighbor to display information about\n"
14000 "Display the dampened routes received from neighbor\n")
14001{
14002 struct peer *peer;
14003
14004 if (argc == 2)
14005 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14006 else
14007 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14008
14009 if (! peer)
14010 return CMD_WARNING;
14011
14012 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14013 bgp_show_type_damp_neighbor);
14014}
14015
14016DEFUN (show_bgp_view_ipv6_neighbor_damp,
Lou Berger651b4022016-01-12 13:42:07 -050014017 show_bgp_view_ipv6_neighbor_damp_cmd,
14018 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
paulbb46e942003-10-24 19:02:03 +000014019 SHOW_STR
14020 BGP_STR
14021 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014022 "View name\n"
paulbb46e942003-10-24 19:02:03 +000014023 "Address family\n"
14024 "Detailed information on TCP and BGP neighbor connections\n"
14025 "Neighbor to display information about\n"
14026 "Neighbor to display information about\n"
paulbb46e942003-10-24 19:02:03 +000014027 "Display the dampened routes received from neighbor\n")
14028{
14029 struct peer *peer;
14030
14031 if (argc == 2)
14032 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14033 else
14034 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14035
14036 if (! peer)
14037 return CMD_WARNING;
14038
14039 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14040 bgp_show_type_damp_neighbor);
14041}
14042
Lou Bergerf9b6c392016-01-12 13:42:09 -050014043DEFUN (show_bgp_view_ipv6_neighbor_flap,
Lou Berger651b4022016-01-12 13:42:07 -050014044 show_bgp_view_ipv6_neighbor_flap_cmd,
14045 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paulbb46e942003-10-24 19:02:03 +000014046 SHOW_STR
14047 BGP_STR
14048 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014049 "View name\n"
paulbb46e942003-10-24 19:02:03 +000014050 "Address family\n"
14051 "Detailed information on TCP and BGP neighbor connections\n"
14052 "Neighbor to display information about\n"
14053 "Neighbor to display information about\n"
14054 "Display the dampened routes received from neighbor\n")
paulbb46e942003-10-24 19:02:03 +000014055{
14056 struct peer *peer;
14057
14058 if (argc == 2)
14059 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14060 else
14061 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14062
14063 if (! peer)
14064 return CMD_WARNING;
14065
14066 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14067 bgp_show_type_flap_neighbor);
14068}
14069
Lou Bergerf9b6c392016-01-12 13:42:09 -050014070DEFUN (show_bgp_view_neighbor_flap,
14071 show_bgp_view_neighbor_flap_cmd,
14072 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14073 SHOW_STR
14074 BGP_STR
14075 "BGP view\n"
14076 "View name\n"
14077 "Detailed information on TCP and BGP neighbor connections\n"
14078 "Neighbor to display information about\n"
14079 "Neighbor to display information about\n"
14080 "Display flap statistics of the routes learned from neighbor\n")
14081{
14082 struct peer *peer;
14083
14084 if (argc == 2)
14085 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14086 else
14087 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14088
14089 if (! peer)
14090 return CMD_WARNING;
14091
14092 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14093 bgp_show_type_flap_neighbor);
14094}
14095
14096ALIAS (show_bgp_view_neighbor_flap,
14097 show_bgp_neighbor_flap_cmd,
14098 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14099 SHOW_STR
14100 BGP_STR
14101 "Detailed information on TCP and BGP neighbor connections\n"
14102 "Neighbor to display information about\n"
14103 "Neighbor to display information about\n"
14104 "Display flap statistics of the routes learned from neighbor\n")
14105
14106ALIAS (show_bgp_view_neighbor_damp,
14107 show_bgp_neighbor_damp_cmd,
14108 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14109 SHOW_STR
14110 BGP_STR
14111 "Detailed information on TCP and BGP neighbor connections\n"
14112 "Neighbor to display information about\n"
14113 "Neighbor to display information about\n"
14114 "Display the dampened routes received from neighbor\n")
14115
14116DEFUN (show_bgp_view_neighbor_routes,
14117 show_bgp_view_neighbor_routes_cmd,
14118 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
14119 SHOW_STR
14120 BGP_STR
14121 "BGP view\n"
14122 "View name\n"
14123 "Detailed information on TCP and BGP neighbor connections\n"
14124 "Neighbor to display information about\n"
14125 "Neighbor to display information about\n"
14126 "Display routes learned from neighbor\n")
14127{
14128 struct peer *peer;
14129
14130 if (argc == 2)
14131 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14132 else
14133 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14134
14135 if (! peer)
14136 return CMD_WARNING;
14137
14138 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14139 bgp_show_type_neighbor);
14140}
14141
14142ALIAS (show_bgp_view_neighbor_routes,
14143 show_bgp_neighbor_routes_cmd,
14144 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
14145 SHOW_STR
14146 BGP_STR
14147 "Detailed information on TCP and BGP neighbor connections\n"
14148 "Neighbor to display information about\n"
14149 "Neighbor to display information about\n"
14150 "Display routes learned from neighbor\n")
14151
paulbb46e942003-10-24 19:02:03 +000014152ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000014153 show_bgp_ipv6_neighbor_routes_cmd,
14154 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
14155 SHOW_STR
14156 BGP_STR
14157 "Address family\n"
14158 "Detailed information on TCP and BGP neighbor connections\n"
14159 "Neighbor to display information about\n"
14160 "Neighbor to display information about\n"
14161 "Display routes learned from neighbor\n")
14162
Lou Bergerf9b6c392016-01-12 13:42:09 -050014163/* old command */
14164ALIAS (show_bgp_view_neighbor_routes,
14165 ipv6_bgp_neighbor_routes_cmd,
14166 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
14167 SHOW_STR
14168 IPV6_STR
14169 BGP_STR
14170 "Detailed information on TCP and BGP neighbor connections\n"
14171 "Neighbor to display information about\n"
14172 "Neighbor to display information about\n"
14173 "Display routes learned from neighbor\n")
14174
14175/* old command */
14176DEFUN (ipv6_mbgp_neighbor_routes,
14177 ipv6_mbgp_neighbor_routes_cmd,
14178 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
14179 SHOW_STR
14180 IPV6_STR
14181 MBGP_STR
14182 "Detailed information on TCP and BGP neighbor connections\n"
14183 "Neighbor to display information about\n"
14184 "Neighbor to display information about\n"
14185 "Display routes learned from neighbor\n")
14186{
14187 struct peer *peer;
14188
14189 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14190 if (! peer)
14191 return CMD_WARNING;
14192
14193 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
14194 bgp_show_type_neighbor);
14195}
14196
paulbb46e942003-10-24 19:02:03 +000014197ALIAS (show_bgp_view_neighbor_flap,
14198 show_bgp_ipv6_neighbor_flap_cmd,
14199 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14200 SHOW_STR
14201 BGP_STR
14202 "Address family\n"
14203 "Detailed information on TCP and BGP neighbor connections\n"
14204 "Neighbor to display information about\n"
14205 "Neighbor to display information about\n"
14206 "Display flap statistics of the routes learned from neighbor\n")
14207
14208ALIAS (show_bgp_view_neighbor_damp,
paulbb46e942003-10-24 19:02:03 +000014209 show_bgp_ipv6_neighbor_damp_cmd,
14210 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14211 SHOW_STR
14212 BGP_STR
14213 "Address family\n"
14214 "Detailed information on TCP and BGP neighbor connections\n"
14215 "Neighbor to display information about\n"
14216 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000014217 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000014218
Lou Bergerf9b6c392016-01-12 13:42:09 -050014219DEFUN (show_bgp_view_rsclient,
14220 show_bgp_view_rsclient_cmd,
14221 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
14222 SHOW_STR
14223 BGP_STR
14224 "BGP view\n"
14225 "View name\n"
14226 "Information about Route Server Client\n"
14227 NEIGHBOR_ADDR_STR)
14228{
14229 struct bgp_table *table;
14230 struct peer *peer;
14231
14232 if (argc == 2)
14233 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14234 else
14235 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14236
14237 if (! peer)
14238 return CMD_WARNING;
14239
14240 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14241 {
14242 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14243 VTY_NEWLINE);
14244 return CMD_WARNING;
14245 }
14246
14247 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14248 PEER_FLAG_RSERVER_CLIENT))
14249 {
14250 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14251 VTY_NEWLINE);
14252 return CMD_WARNING;
14253 }
14254
14255 table = peer->rib[AFI_IP6][SAFI_UNICAST];
14256
14257 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14258}
14259
14260ALIAS (show_bgp_view_rsclient,
14261 show_bgp_rsclient_cmd,
14262 "show bgp rsclient (A.B.C.D|X:X::X:X)",
14263 SHOW_STR
14264 BGP_STR
14265 "Information about Route Server Client\n"
14266 NEIGHBOR_ADDR_STR)
14267
Lou Berger651b4022016-01-12 13:42:07 -050014268DEFUN (show_bgp_view_ipv4_rsclient,
14269 show_bgp_view_ipv4_rsclient_cmd,
14270 "show bgp view WORD ipv4 rsclient (A.B.C.D|X:X::X:X)",
paulfee0f4c2004-09-13 05:12:46 +000014271 SHOW_STR
14272 BGP_STR
14273 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014274 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050014275 "Address Family\n"
paulfee0f4c2004-09-13 05:12:46 +000014276 "Information about Route Server Client\n"
Lou Berger651b4022016-01-12 13:42:07 -050014277 NEIGHBOR_ADDR_STR2)
paulfee0f4c2004-09-13 05:12:46 +000014278{
Lou Berger651b4022016-01-12 13:42:07 -050014279 struct bgp_table *table;
14280 struct peer *peer;
14281
14282 if (argc == 2)
14283 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14284 else
14285 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14286
14287 if (! peer)
14288 return CMD_WARNING;
14289
14290 if (! peer->afc[AFI_IP][SAFI_UNICAST])
14291 {
14292 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14293 VTY_NEWLINE);
14294 return CMD_WARNING;
14295 }
14296
14297 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
14298 PEER_FLAG_RSERVER_CLIENT))
14299 {
14300 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14301 VTY_NEWLINE);
14302 return CMD_WARNING;
14303 }
14304
14305 table = peer->rib[AFI_IP][SAFI_UNICAST];
14306
14307 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14308}
14309DEFUN (show_bgp_view_ipv6_rsclient,
14310 show_bgp_view_ipv6_rsclient_cmd,
14311 "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X)",
14312 SHOW_STR
14313 BGP_STR
14314 "BGP view\n"
14315 "BGP view name\n"
14316 "Address Family\n"
14317 "Information about Route Server Client\n"
14318 NEIGHBOR_ADDR_STR2)
14319{
14320 struct bgp_table *table;
14321 struct peer *peer;
paulfee0f4c2004-09-13 05:12:46 +000014322
14323 if (argc == 2)
14324 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14325 else
14326 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14327
14328 if (! peer)
14329 return CMD_WARNING;
14330
14331 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14332 {
14333 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14334 VTY_NEWLINE);
14335 return CMD_WARNING;
14336 }
14337
14338 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14339 PEER_FLAG_RSERVER_CLIENT))
14340 {
14341 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14342 VTY_NEWLINE);
14343 return CMD_WARNING;
14344 }
14345
14346 table = peer->rib[AFI_IP6][SAFI_UNICAST];
14347
ajs5a646652004-11-05 01:25:55 +000014348 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000014349}
14350
Lou Berger651b4022016-01-12 13:42:07 -050014351ALIAS (show_bgp_view_ipv4_rsclient,
14352 show_bgp_ipv4_rsclient_cmd,
14353 "show bgp ipv4 rsclient (A.B.C.D|X:X::X:X)",
paulfee0f4c2004-09-13 05:12:46 +000014354 SHOW_STR
14355 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050014356 "Address Family\n"
paulfee0f4c2004-09-13 05:12:46 +000014357 "Information about Route Server Client\n"
Lou Berger651b4022016-01-12 13:42:07 -050014358 NEIGHBOR_ADDR_STR2)
14359
Lou Berger651b4022016-01-12 13:42:07 -050014360ALIAS (show_bgp_view_ipv6_rsclient,
14361 show_bgp_ipv6_rsclient_cmd,
14362 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X)",
14363 SHOW_STR
14364 BGP_STR
14365 "Address Family\n"
14366 "Information about Route Server Client\n"
14367 NEIGHBOR_ADDR_STR2)
paulfee0f4c2004-09-13 05:12:46 +000014368
Michael Lambert95cbbd22010-07-23 14:43:04 -040014369DEFUN (show_bgp_view_ipv6_safi_rsclient,
14370 show_bgp_view_ipv6_safi_rsclient_cmd,
14371 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
14372 SHOW_STR
14373 BGP_STR
14374 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014375 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014376 "Address family\n"
14377 "Address Family modifier\n"
14378 "Address Family modifier\n"
14379 "Information about Route Server Client\n"
14380 NEIGHBOR_ADDR_STR)
14381{
14382 struct bgp_table *table;
14383 struct peer *peer;
14384 safi_t safi;
14385
14386 if (argc == 3) {
14387 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14388 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14389 } else {
14390 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14391 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14392 }
14393
14394 if (! peer)
14395 return CMD_WARNING;
14396
14397 if (! peer->afc[AFI_IP6][safi])
14398 {
14399 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14400 VTY_NEWLINE);
14401 return CMD_WARNING;
14402 }
14403
14404 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14405 PEER_FLAG_RSERVER_CLIENT))
14406 {
14407 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14408 VTY_NEWLINE);
14409 return CMD_WARNING;
14410 }
14411
14412 table = peer->rib[AFI_IP6][safi];
14413
14414 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14415}
14416
14417ALIAS (show_bgp_view_ipv6_safi_rsclient,
14418 show_bgp_ipv6_safi_rsclient_cmd,
14419 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
14420 SHOW_STR
14421 BGP_STR
14422 "Address family\n"
14423 "Address Family modifier\n"
14424 "Address Family modifier\n"
14425 "Information about Route Server Client\n"
14426 NEIGHBOR_ADDR_STR)
14427
paulfee0f4c2004-09-13 05:12:46 +000014428DEFUN (show_bgp_view_rsclient_route,
14429 show_bgp_view_rsclient_route_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014430 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14431 SHOW_STR
14432 BGP_STR
14433 "BGP view\n"
14434 "View name\n"
14435 "Information about Route Server Client\n"
14436 NEIGHBOR_ADDR_STR
14437 "Network in the BGP routing table to display\n")
14438{
14439 struct bgp *bgp;
14440 struct peer *peer;
14441
14442 /* BGP structure lookup. */
14443 if (argc == 3)
14444 {
14445 bgp = bgp_lookup_by_name (argv[0]);
14446 if (bgp == NULL)
14447 {
14448 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14449 return CMD_WARNING;
14450 }
14451 }
14452 else
14453 {
14454 bgp = bgp_get_default ();
14455 if (bgp == NULL)
14456 {
14457 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14458 return CMD_WARNING;
14459 }
14460 }
14461
14462 if (argc == 3)
14463 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14464 else
14465 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14466
14467 if (! peer)
14468 return CMD_WARNING;
14469
14470 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14471 {
14472 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14473 VTY_NEWLINE);
14474 return CMD_WARNING;
14475 }
14476
14477 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14478 PEER_FLAG_RSERVER_CLIENT))
14479 {
14480 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14481 VTY_NEWLINE);
14482 return CMD_WARNING;
14483 }
14484
14485 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14486 (argc == 3) ? argv[2] : argv[1],
14487 AFI_IP6, SAFI_UNICAST, NULL, 0);
14488}
14489
14490DEFUN (show_bgp_view_ipv6_rsclient_route,
14491 show_bgp_view_ipv6_rsclient_route_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014492 "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
paulfee0f4c2004-09-13 05:12:46 +000014493 SHOW_STR
14494 BGP_STR
14495 "BGP view\n"
Lou Berger651b4022016-01-12 13:42:07 -050014496 "BGP view name\n"
14497 "IP6_STR"
paulfee0f4c2004-09-13 05:12:46 +000014498 "Information about Route Server Client\n"
14499 NEIGHBOR_ADDR_STR
14500 "Network in the BGP routing table to display\n")
14501{
14502 struct bgp *bgp;
14503 struct peer *peer;
14504
14505 /* BGP structure lookup. */
14506 if (argc == 3)
14507 {
14508 bgp = bgp_lookup_by_name (argv[0]);
14509 if (bgp == NULL)
14510 {
14511 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14512 return CMD_WARNING;
14513 }
14514 }
14515 else
14516 {
14517 bgp = bgp_get_default ();
14518 if (bgp == NULL)
14519 {
14520 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14521 return CMD_WARNING;
14522 }
14523 }
14524
14525 if (argc == 3)
14526 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14527 else
14528 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14529
14530 if (! peer)
14531 return CMD_WARNING;
14532
14533 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14534 {
14535 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14536 VTY_NEWLINE);
14537 return CMD_WARNING;
14538 }
14539
14540 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14541 PEER_FLAG_RSERVER_CLIENT))
14542 {
14543 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14544 VTY_NEWLINE);
14545 return CMD_WARNING;
14546 }
14547
14548 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14549 (argc == 3) ? argv[2] : argv[1],
14550 AFI_IP6, SAFI_UNICAST, NULL, 0);
14551}
14552
Lou Bergerf9b6c392016-01-12 13:42:09 -050014553ALIAS (show_bgp_view_ipv6_rsclient_route,
paulfee0f4c2004-09-13 05:12:46 +000014554 show_bgp_rsclient_route_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014555 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14556 SHOW_STR
14557 BGP_STR
14558 "Information about Route Server Client\n"
14559 NEIGHBOR_ADDR_STR
14560 "Network in the BGP routing table to display\n")
14561
14562ALIAS (show_bgp_view_ipv6_rsclient_route,
14563 show_bgp_ipv6_rsclient_route_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014564 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
paulfee0f4c2004-09-13 05:12:46 +000014565 SHOW_STR
14566 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050014567 IP6_STR
paulfee0f4c2004-09-13 05:12:46 +000014568 "Information about Route Server Client\n"
14569 NEIGHBOR_ADDR_STR
14570 "Network in the BGP routing table to display\n")
14571
Michael Lambert95cbbd22010-07-23 14:43:04 -040014572DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
14573 show_bgp_view_ipv6_safi_rsclient_route_cmd,
14574 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14575 SHOW_STR
14576 BGP_STR
14577 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014578 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014579 "Address family\n"
14580 "Address Family modifier\n"
14581 "Address Family modifier\n"
14582 "Information about Route Server Client\n"
14583 NEIGHBOR_ADDR_STR
14584 "Network in the BGP routing table to display\n")
14585{
14586 struct bgp *bgp;
14587 struct peer *peer;
14588 safi_t safi;
14589
14590 /* BGP structure lookup. */
14591 if (argc == 4)
14592 {
14593 bgp = bgp_lookup_by_name (argv[0]);
14594 if (bgp == NULL)
14595 {
14596 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14597 return CMD_WARNING;
14598 }
14599 }
14600 else
14601 {
14602 bgp = bgp_get_default ();
14603 if (bgp == NULL)
14604 {
14605 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14606 return CMD_WARNING;
14607 }
14608 }
14609
14610 if (argc == 4) {
14611 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14612 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14613 } else {
14614 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14615 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14616 }
14617
14618 if (! peer)
14619 return CMD_WARNING;
14620
14621 if (! peer->afc[AFI_IP6][safi])
14622 {
14623 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14624 VTY_NEWLINE);
14625 return CMD_WARNING;
14626}
14627
14628 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14629 PEER_FLAG_RSERVER_CLIENT))
14630 {
14631 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14632 VTY_NEWLINE);
14633 return CMD_WARNING;
14634 }
14635
14636 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
14637 (argc == 4) ? argv[3] : argv[2],
14638 AFI_IP6, safi, NULL, 0);
14639}
14640
14641ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
14642 show_bgp_ipv6_safi_rsclient_route_cmd,
14643 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14644 SHOW_STR
14645 BGP_STR
14646 "Address family\n"
14647 "Address Family modifier\n"
14648 "Address Family modifier\n"
14649 "Information about Route Server Client\n"
14650 NEIGHBOR_ADDR_STR
14651 "Network in the BGP routing table to display\n")
14652
Lou Berger651b4022016-01-12 13:42:07 -050014653
paulfee0f4c2004-09-13 05:12:46 +000014654DEFUN (show_bgp_view_rsclient_prefix,
14655 show_bgp_view_rsclient_prefix_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014656 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
14657 SHOW_STR
14658 BGP_STR
14659 "BGP view\n"
14660 "View name\n"
14661 "Information about Route Server Client\n"
14662 NEIGHBOR_ADDR_STR
14663 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14664{
14665 struct bgp *bgp;
14666 struct peer *peer;
14667
14668 /* BGP structure lookup. */
14669 if (argc == 3)
14670 {
14671 bgp = bgp_lookup_by_name (argv[0]);
14672 if (bgp == NULL)
14673 {
14674 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14675 return CMD_WARNING;
14676 }
14677 }
14678 else
14679 {
14680 bgp = bgp_get_default ();
14681 if (bgp == NULL)
14682 {
14683 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14684 return CMD_WARNING;
14685 }
14686 }
14687
14688 if (argc == 3)
14689 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14690 else
14691 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14692
14693 if (! peer)
14694 return CMD_WARNING;
14695
14696 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14697 {
14698 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14699 VTY_NEWLINE);
14700 return CMD_WARNING;
14701 }
14702
14703 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14704 PEER_FLAG_RSERVER_CLIENT))
14705 {
14706 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14707 VTY_NEWLINE);
14708 return CMD_WARNING;
14709 }
14710
14711 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14712 (argc == 3) ? argv[2] : argv[1],
14713 AFI_IP6, SAFI_UNICAST, NULL, 1);
14714}
14715
14716DEFUN (show_bgp_view_ipv6_rsclient_prefix,
14717 show_bgp_view_ipv6_rsclient_prefix_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014718 "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 +000014719 SHOW_STR
14720 BGP_STR
14721 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014722 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050014723 IP6_STR
paulfee0f4c2004-09-13 05:12:46 +000014724 "Information about Route Server Client\n"
14725 NEIGHBOR_ADDR_STR
14726 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14727{
14728 struct bgp *bgp;
14729 struct peer *peer;
14730
14731 /* BGP structure lookup. */
14732 if (argc == 3)
14733 {
14734 bgp = bgp_lookup_by_name (argv[0]);
14735 if (bgp == NULL)
14736 {
14737 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14738 return CMD_WARNING;
14739 }
14740 }
14741 else
14742 {
14743 bgp = bgp_get_default ();
14744 if (bgp == NULL)
14745 {
14746 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14747 return CMD_WARNING;
14748 }
14749 }
14750
14751 if (argc == 3)
14752 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14753 else
14754 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14755
14756 if (! peer)
14757 return CMD_WARNING;
14758
14759 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14760 {
14761 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14762 VTY_NEWLINE);
14763 return CMD_WARNING;
14764 }
14765
14766 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14767 PEER_FLAG_RSERVER_CLIENT))
14768 {
14769 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14770 VTY_NEWLINE);
14771 return CMD_WARNING;
14772 }
14773
14774 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14775 (argc == 3) ? argv[2] : argv[1],
14776 AFI_IP6, SAFI_UNICAST, NULL, 1);
14777}
14778
Lou Bergerf9b6c392016-01-12 13:42:09 -050014779ALIAS (show_bgp_view_ipv6_rsclient_prefix,
paulfee0f4c2004-09-13 05:12:46 +000014780 show_bgp_rsclient_prefix_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014781 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
14782 SHOW_STR
14783 BGP_STR
14784 "Information about Route Server Client\n"
14785 NEIGHBOR_ADDR_STR
14786 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14787
14788ALIAS (show_bgp_view_ipv6_rsclient_prefix,
14789 show_bgp_ipv6_rsclient_prefix_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014790 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
paulfee0f4c2004-09-13 05:12:46 +000014791 SHOW_STR
14792 BGP_STR
14793 "Information about Route Server Client\n"
14794 NEIGHBOR_ADDR_STR
14795 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14796
Michael Lambert95cbbd22010-07-23 14:43:04 -040014797DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
14798 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
14799 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
14800 SHOW_STR
14801 BGP_STR
14802 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014803 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014804 "Address family\n"
14805 "Address Family modifier\n"
14806 "Address Family modifier\n"
14807 "Information about Route Server Client\n"
14808 NEIGHBOR_ADDR_STR
14809 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
14810{
14811 struct bgp *bgp;
14812 struct peer *peer;
14813 safi_t safi;
14814
14815 /* BGP structure lookup. */
14816 if (argc == 4)
14817 {
14818 bgp = bgp_lookup_by_name (argv[0]);
14819 if (bgp == NULL)
14820 {
14821 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14822 return CMD_WARNING;
14823 }
14824 }
14825 else
14826 {
14827 bgp = bgp_get_default ();
14828 if (bgp == NULL)
14829 {
14830 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14831 return CMD_WARNING;
14832 }
14833 }
14834
14835 if (argc == 4) {
14836 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14837 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14838 } else {
14839 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14840 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14841 }
14842
14843 if (! peer)
14844 return CMD_WARNING;
14845
14846 if (! peer->afc[AFI_IP6][safi])
14847 {
14848 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14849 VTY_NEWLINE);
14850 return CMD_WARNING;
14851}
14852
14853 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14854 PEER_FLAG_RSERVER_CLIENT))
14855{
14856 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14857 VTY_NEWLINE);
14858 return CMD_WARNING;
14859 }
14860
14861 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
14862 (argc == 4) ? argv[3] : argv[2],
14863 AFI_IP6, safi, NULL, 1);
14864}
14865
14866ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
14867 show_bgp_ipv6_safi_rsclient_prefix_cmd,
14868 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
14869 SHOW_STR
14870 BGP_STR
14871 "Address family\n"
14872 "Address Family modifier\n"
14873 "Address Family modifier\n"
14874 "Information about Route Server Client\n"
14875 NEIGHBOR_ADDR_STR
14876 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
14877
paul718e3742002-12-13 20:15:29 +000014878struct bgp_table *bgp_distance_table;
14879
14880struct bgp_distance
14881{
14882 /* Distance value for the IP source prefix. */
14883 u_char distance;
14884
14885 /* Name of the access-list to be matched. */
14886 char *access_list;
14887};
14888
paul94f2b392005-06-28 12:44:16 +000014889static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080014890bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000014891{
Stephen Hemminger393deb92008-08-18 14:13:29 -070014892 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000014893}
14894
paul94f2b392005-06-28 12:44:16 +000014895static void
paul718e3742002-12-13 20:15:29 +000014896bgp_distance_free (struct bgp_distance *bdistance)
14897{
14898 XFREE (MTYPE_BGP_DISTANCE, bdistance);
14899}
14900
paul94f2b392005-06-28 12:44:16 +000014901static int
paulfd79ac92004-10-13 05:06:08 +000014902bgp_distance_set (struct vty *vty, const char *distance_str,
14903 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000014904{
14905 int ret;
Roman Hoog Antink6184c392014-03-17 14:01:42 +010014906 struct prefix p;
paul718e3742002-12-13 20:15:29 +000014907 u_char distance;
14908 struct bgp_node *rn;
14909 struct bgp_distance *bdistance;
14910
Roman Hoog Antink6184c392014-03-17 14:01:42 +010014911 ret = str2prefix (ip_str, &p);
paul718e3742002-12-13 20:15:29 +000014912 if (ret == 0)
14913 {
14914 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
14915 return CMD_WARNING;
14916 }
14917
14918 distance = atoi (distance_str);
14919
14920 /* Get BGP distance node. */
14921 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
14922 if (rn->info)
14923 {
14924 bdistance = rn->info;
14925 bgp_unlock_node (rn);
14926 }
14927 else
14928 {
14929 bdistance = bgp_distance_new ();
14930 rn->info = bdistance;
14931 }
14932
14933 /* Set distance value. */
14934 bdistance->distance = distance;
14935
14936 /* Reset access-list configuration. */
14937 if (bdistance->access_list)
14938 {
14939 free (bdistance->access_list);
14940 bdistance->access_list = NULL;
14941 }
14942 if (access_list_str)
14943 bdistance->access_list = strdup (access_list_str);
14944
14945 return CMD_SUCCESS;
14946}
14947
paul94f2b392005-06-28 12:44:16 +000014948static int
paulfd79ac92004-10-13 05:06:08 +000014949bgp_distance_unset (struct vty *vty, const char *distance_str,
14950 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000014951{
14952 int ret;
Roman Hoog Antink6184c392014-03-17 14:01:42 +010014953 struct prefix p;
paul718e3742002-12-13 20:15:29 +000014954 u_char distance;
14955 struct bgp_node *rn;
14956 struct bgp_distance *bdistance;
14957
Roman Hoog Antink6184c392014-03-17 14:01:42 +010014958 ret = str2prefix (ip_str, &p);
paul718e3742002-12-13 20:15:29 +000014959 if (ret == 0)
14960 {
14961 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
14962 return CMD_WARNING;
14963 }
14964
14965 distance = atoi (distance_str);
14966
14967 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
14968 if (! rn)
14969 {
14970 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
14971 return CMD_WARNING;
14972 }
14973
14974 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010014975
14976 if (bdistance->distance != distance)
14977 {
14978 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
14979 return CMD_WARNING;
14980 }
14981
paul718e3742002-12-13 20:15:29 +000014982 if (bdistance->access_list)
14983 free (bdistance->access_list);
14984 bgp_distance_free (bdistance);
14985
14986 rn->info = NULL;
14987 bgp_unlock_node (rn);
14988 bgp_unlock_node (rn);
14989
14990 return CMD_SUCCESS;
14991}
14992
paul718e3742002-12-13 20:15:29 +000014993/* Apply BGP information to distance method. */
14994u_char
14995bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
14996{
14997 struct bgp_node *rn;
14998 struct prefix_ipv4 q;
14999 struct peer *peer;
15000 struct bgp_distance *bdistance;
15001 struct access_list *alist;
15002 struct bgp_static *bgp_static;
15003
15004 if (! bgp)
15005 return 0;
15006
15007 if (p->family != AF_INET)
15008 return 0;
15009
15010 peer = rinfo->peer;
15011
15012 if (peer->su.sa.sa_family != AF_INET)
15013 return 0;
15014
15015 memset (&q, 0, sizeof (struct prefix_ipv4));
15016 q.family = AF_INET;
15017 q.prefix = peer->su.sin.sin_addr;
15018 q.prefixlen = IPV4_MAX_BITLEN;
15019
15020 /* Check source address. */
15021 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
15022 if (rn)
15023 {
15024 bdistance = rn->info;
15025 bgp_unlock_node (rn);
15026
15027 if (bdistance->access_list)
15028 {
15029 alist = access_list_lookup (AFI_IP, bdistance->access_list);
15030 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
15031 return bdistance->distance;
15032 }
15033 else
15034 return bdistance->distance;
15035 }
15036
15037 /* Backdoor check. */
15038 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
15039 if (rn)
15040 {
15041 bgp_static = rn->info;
15042 bgp_unlock_node (rn);
15043
15044 if (bgp_static->backdoor)
15045 {
15046 if (bgp->distance_local)
15047 return bgp->distance_local;
15048 else
15049 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15050 }
15051 }
15052
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000015053 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000015054 {
15055 if (bgp->distance_ebgp)
15056 return bgp->distance_ebgp;
15057 return ZEBRA_EBGP_DISTANCE_DEFAULT;
15058 }
15059 else
15060 {
15061 if (bgp->distance_ibgp)
15062 return bgp->distance_ibgp;
15063 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15064 }
15065}
15066
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015067#ifdef HAVE_IPV6
15068/* Apply BGP information to ipv6 distance method. */
15069u_char
15070ipv6_bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
15071{
15072 struct bgp_node *rn;
15073 struct prefix_ipv6 q;
15074 struct peer *peer;
15075 struct bgp_distance *bdistance;
15076 struct access_list *alist;
15077 struct bgp_static *bgp_static;
15078
15079 if (! bgp)
15080 return 0;
15081
15082 if (p->family != AF_INET6)
15083 return 0;
15084
15085 peer = rinfo->peer;
15086
15087 if (peer->su.sa.sa_family != AF_INET6)
15088 return 0;
15089
15090 memset (&q, 0, sizeof (struct prefix_ipv6));
15091 q.family = AF_INET;
15092 q.prefix = peer->su.sin6.sin6_addr;
15093 q.prefixlen = IPV6_MAX_BITLEN;
15094
15095 /* Check source address. */
15096 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
15097 if (rn)
15098 {
15099 bdistance = rn->info;
15100 bgp_unlock_node (rn);
15101
15102 if (bdistance->access_list)
15103 {
15104 alist = access_list_lookup (AFI_IP6, bdistance->access_list);
15105 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
15106 return bdistance->distance;
15107 }
15108 else
15109 return bdistance->distance;
15110 }
15111 /* Backdoor check. */
15112 rn = bgp_node_lookup (bgp->route[AFI_IP6][SAFI_UNICAST], p);
15113 if (rn)
15114 {
15115 bgp_static = rn->info;
15116 bgp_unlock_node (rn);
15117
15118 if (bgp_static->backdoor)
15119 {
15120 if (bgp->ipv6_distance_local)
15121 return bgp->ipv6_distance_local;
15122 else
15123 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15124 }
15125 }
15126
15127 if (peer_sort (peer) == BGP_PEER_EBGP)
15128 {
15129 if (bgp->ipv6_distance_ebgp)
15130 return bgp->ipv6_distance_ebgp;
15131 return ZEBRA_EBGP_DISTANCE_DEFAULT;
15132 }
15133 else
15134 {
15135 if (bgp->ipv6_distance_ibgp)
15136 return bgp->ipv6_distance_ibgp;
15137 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15138 }
15139}
15140#endif /* HAVE_IPV6 */
15141
paul718e3742002-12-13 20:15:29 +000015142DEFUN (bgp_distance,
15143 bgp_distance_cmd,
15144 "distance bgp <1-255> <1-255> <1-255>",
15145 "Define an administrative distance\n"
15146 "BGP distance\n"
15147 "Distance for routes external to the AS\n"
15148 "Distance for routes internal to the AS\n"
15149 "Distance for local routes\n")
15150{
15151 struct bgp *bgp;
15152
15153 bgp = vty->index;
15154
15155 bgp->distance_ebgp = atoi (argv[0]);
15156 bgp->distance_ibgp = atoi (argv[1]);
15157 bgp->distance_local = atoi (argv[2]);
15158 return CMD_SUCCESS;
15159}
15160
15161DEFUN (no_bgp_distance,
15162 no_bgp_distance_cmd,
15163 "no distance bgp <1-255> <1-255> <1-255>",
15164 NO_STR
15165 "Define an administrative distance\n"
15166 "BGP distance\n"
15167 "Distance for routes external to the AS\n"
15168 "Distance for routes internal to the AS\n"
15169 "Distance for local routes\n")
15170{
15171 struct bgp *bgp;
15172
15173 bgp = vty->index;
15174
15175 bgp->distance_ebgp= 0;
15176 bgp->distance_ibgp = 0;
15177 bgp->distance_local = 0;
15178 return CMD_SUCCESS;
15179}
15180
15181ALIAS (no_bgp_distance,
15182 no_bgp_distance2_cmd,
15183 "no distance bgp",
15184 NO_STR
15185 "Define an administrative distance\n"
15186 "BGP distance\n")
15187
15188DEFUN (bgp_distance_source,
15189 bgp_distance_source_cmd,
15190 "distance <1-255> A.B.C.D/M",
15191 "Define an administrative distance\n"
15192 "Administrative distance\n"
15193 "IP source prefix\n")
15194{
15195 bgp_distance_set (vty, argv[0], argv[1], NULL);
15196 return CMD_SUCCESS;
15197}
15198
15199DEFUN (no_bgp_distance_source,
15200 no_bgp_distance_source_cmd,
15201 "no distance <1-255> A.B.C.D/M",
15202 NO_STR
15203 "Define an administrative distance\n"
15204 "Administrative distance\n"
15205 "IP source prefix\n")
15206{
15207 bgp_distance_unset (vty, argv[0], argv[1], NULL);
15208 return CMD_SUCCESS;
15209}
15210
15211DEFUN (bgp_distance_source_access_list,
15212 bgp_distance_source_access_list_cmd,
15213 "distance <1-255> A.B.C.D/M WORD",
15214 "Define an administrative distance\n"
15215 "Administrative distance\n"
15216 "IP source prefix\n"
15217 "Access list name\n")
15218{
15219 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
15220 return CMD_SUCCESS;
15221}
15222
15223DEFUN (no_bgp_distance_source_access_list,
15224 no_bgp_distance_source_access_list_cmd,
15225 "no distance <1-255> A.B.C.D/M WORD",
15226 NO_STR
15227 "Define an administrative distance\n"
15228 "Administrative distance\n"
15229 "IP source prefix\n"
15230 "Access list name\n")
15231{
15232 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
15233 return CMD_SUCCESS;
15234}
David Lamparter6b0655a2014-06-04 06:53:35 +020015235
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015236#ifdef HAVE_IPV6
15237DEFUN (ipv6_bgp_distance,
15238 ipv6_bgp_distance_cmd,
15239 "distance bgp <1-255> <1-255> <1-255>",
15240 "Define an administrative distance\n"
15241 "BGP distance\n"
15242 "Distance for routes external to the AS\n"
15243 "Distance for routes internal to the AS\n"
15244 "Distance for local routes\n")
15245{
15246 struct bgp *bgp;
15247
15248 bgp = vty->index;
15249
15250 bgp->ipv6_distance_ebgp = atoi (argv[0]);
15251 bgp->ipv6_distance_ibgp = atoi (argv[1]);
15252 bgp->ipv6_distance_local = atoi (argv[2]);
15253 return CMD_SUCCESS;
15254}
15255
15256DEFUN (no_ipv6_bgp_distance,
15257 no_ipv6_bgp_distance_cmd,
15258 "no distance bgp <1-255> <1-255> <1-255>",
15259 NO_STR
15260 "Define an administrative distance\n"
15261 "BGP distance\n"
15262 "Distance for routes external to the AS\n"
15263 "Distance for routes internal to the AS\n"
15264 "Distance for local routes\n")
15265{
15266 struct bgp *bgp;
15267
15268 bgp = vty->index;
15269
15270 bgp->ipv6_distance_ebgp= 0;
15271 bgp->ipv6_distance_ibgp = 0;
15272 bgp->ipv6_distance_local = 0;
15273 return CMD_SUCCESS;
15274}
15275
15276ALIAS (no_ipv6_bgp_distance,
15277 no_ipv6_bgp_distance2_cmd,
15278 "no distance bgp",
15279 NO_STR
15280 "Define an administrative distance\n"
15281 "BGP distance\n")
15282
15283DEFUN (ipv6_bgp_distance_source,
15284 ipv6_bgp_distance_source_cmd,
15285 "distance <1-255> X:X::X:X/M",
15286 "Define an administrative distance\n"
15287 "Administrative distance\n"
15288 "IP source prefix\n")
15289{
15290 bgp_distance_set (vty, argv[0], argv[1], NULL);
15291 return CMD_SUCCESS;
15292}
15293
15294DEFUN (no_ipv6_bgp_distance_source,
15295 no_ipv6_bgp_distance_source_cmd,
15296 "no distance <1-255> X:X::X:X/M",
15297 NO_STR
15298 "Define an administrative distance\n"
15299 "Administrative distance\n"
15300 "IP source prefix\n")
15301{
15302 bgp_distance_unset (vty, argv[0], argv[1], NULL);
15303 return CMD_SUCCESS;
15304}
15305
15306DEFUN (ipv6_bgp_distance_source_access_list,
15307 ipv6_bgp_distance_source_access_list_cmd,
15308 "distance <1-255> X:X::X:X/M WORD",
15309 "Define an administrative distance\n"
15310 "Administrative distance\n"
15311 "IP source prefix\n"
15312 "Access list name\n")
15313{
15314 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
15315 return CMD_SUCCESS;
15316}
15317
15318DEFUN (no_ipv6_bgp_distance_source_access_list,
15319 no_ipv6_bgp_distance_source_access_list_cmd,
15320 "no distance <1-255> X:X::X:X/M WORD",
15321 NO_STR
15322 "Define an administrative distance\n"
15323 "Administrative distance\n"
15324 "IP source prefix\n"
15325 "Access list name\n")
15326{
15327 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
15328 return CMD_SUCCESS;
15329}
15330#endif
15331
paul718e3742002-12-13 20:15:29 +000015332DEFUN (bgp_damp_set,
15333 bgp_damp_set_cmd,
15334 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
15335 "BGP Specific commands\n"
15336 "Enable route-flap dampening\n"
15337 "Half-life time for the penalty\n"
15338 "Value to start reusing a route\n"
15339 "Value to start suppressing a route\n"
15340 "Maximum duration to suppress a stable route\n")
15341{
15342 struct bgp *bgp;
15343 int half = DEFAULT_HALF_LIFE * 60;
15344 int reuse = DEFAULT_REUSE;
15345 int suppress = DEFAULT_SUPPRESS;
15346 int max = 4 * half;
15347
15348 if (argc == 4)
15349 {
15350 half = atoi (argv[0]) * 60;
15351 reuse = atoi (argv[1]);
15352 suppress = atoi (argv[2]);
15353 max = atoi (argv[3]) * 60;
15354 }
15355 else if (argc == 1)
15356 {
15357 half = atoi (argv[0]) * 60;
15358 max = 4 * half;
15359 }
15360
15361 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000015362
15363 if (suppress < reuse)
15364 {
15365 vty_out (vty, "Suppress value cannot be less than reuse value %s",
15366 VTY_NEWLINE);
15367 return 0;
15368 }
15369
paul718e3742002-12-13 20:15:29 +000015370 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
15371 half, reuse, suppress, max);
15372}
15373
15374ALIAS (bgp_damp_set,
15375 bgp_damp_set2_cmd,
15376 "bgp dampening <1-45>",
15377 "BGP Specific commands\n"
15378 "Enable route-flap dampening\n"
15379 "Half-life time for the penalty\n")
15380
15381ALIAS (bgp_damp_set,
15382 bgp_damp_set3_cmd,
15383 "bgp dampening",
15384 "BGP Specific commands\n"
15385 "Enable route-flap dampening\n")
15386
15387DEFUN (bgp_damp_unset,
15388 bgp_damp_unset_cmd,
15389 "no bgp dampening",
15390 NO_STR
15391 "BGP Specific commands\n"
15392 "Enable route-flap dampening\n")
15393{
15394 struct bgp *bgp;
15395
15396 bgp = vty->index;
15397 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
15398}
15399
15400ALIAS (bgp_damp_unset,
15401 bgp_damp_unset2_cmd,
15402 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
15403 NO_STR
15404 "BGP Specific commands\n"
15405 "Enable route-flap dampening\n"
15406 "Half-life time for the penalty\n"
15407 "Value to start reusing a route\n"
15408 "Value to start suppressing a route\n"
15409 "Maximum duration to suppress a stable route\n")
15410
Lou Bergerf9b6c392016-01-12 13:42:09 -050015411DEFUN (show_ip_bgp_dampened_paths,
15412 show_ip_bgp_dampened_paths_cmd,
15413 "show ip bgp dampened-paths",
15414 SHOW_STR
15415 IP_STR
15416 BGP_STR
15417 "Display paths suppressed due to dampening\n")
15418{
15419 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
15420 NULL);
15421}
15422
15423ALIAS (show_ip_bgp_dampened_paths,
15424 show_ip_bgp_damp_dampened_paths_cmd,
15425 "show ip bgp dampening dampened-paths",
15426 SHOW_STR
15427 IP_STR
15428 BGP_STR
15429 "Display detailed information about dampening\n"
15430 "Display paths suppressed due to dampening\n")
15431
15432DEFUN (show_ip_bgp_flap_statistics,
15433 show_ip_bgp_flap_statistics_cmd,
15434 "show ip bgp flap-statistics",
15435 SHOW_STR
15436 IP_STR
15437 BGP_STR
15438 "Display flap statistics of routes\n")
15439{
15440 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
15441 bgp_show_type_flap_statistics, NULL);
15442}
15443
15444ALIAS (show_ip_bgp_flap_statistics,
15445 show_ip_bgp_damp_flap_statistics_cmd,
15446 "show ip bgp dampening flap-statistics",
15447 SHOW_STR
15448 IP_STR
15449 BGP_STR
15450 "Display detailed information about dampening\n"
15451 "Display flap statistics of routes\n")
15452
Lou Berger651b4022016-01-12 13:42:07 -050015453DEFUN (show_bgp_ipv4_safi_dampened_paths,
15454 show_bgp_ipv4_safi_dampened_paths_cmd,
15455 "show bgp ipv4 (encap|multicast|unicast|vpn) dampened-paths",
paul718e3742002-12-13 20:15:29 +000015456 SHOW_STR
paul718e3742002-12-13 20:15:29 +000015457 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015458 IP_STR
15459 "Address Family modifier\n"
15460 "Address Family modifier\n"
15461 "Address Family modifier\n"
15462 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000015463 "Display paths suppressed due to dampening\n")
15464{
Lou Berger651b4022016-01-12 13:42:07 -050015465 safi_t safi;
paul718e3742002-12-13 20:15:29 +000015466
Lou Berger651b4022016-01-12 13:42:07 -050015467 if (bgp_parse_safi(argv[0], &safi)) {
15468 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15469 return CMD_WARNING;
15470 }
15471
15472 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_dampend_paths, NULL);
15473}
15474ALIAS (show_bgp_ipv4_safi_dampened_paths,
15475 show_bgp_ipv4_safi_damp_dampened_paths_cmd,
15476 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening dampened-paths",
Balaji3921cc52015-05-16 23:12:17 +053015477 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053015478 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015479 IP_STR
15480 "Address Family modifier\n"
15481 "Address Family modifier\n"
15482 "Address Family modifier\n"
15483 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053015484 "Display detailed information about dampening\n"
15485 "Display paths suppressed due to dampening\n")
Lou Berger205e6742016-01-12 13:42:11 -050015486
Lou Berger651b4022016-01-12 13:42:07 -050015487DEFUN (show_bgp_ipv6_safi_dampened_paths,
15488 show_bgp_ipv6_safi_dampened_paths_cmd,
15489 "show bgp ipv6 (encap|multicast|unicast|vpn) dampened-paths",
paul718e3742002-12-13 20:15:29 +000015490 SHOW_STR
paul718e3742002-12-13 20:15:29 +000015491 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015492 IPV6_STR
15493 "Address Family modifier\n"
15494 "Address Family modifier\n"
15495 "Address Family modifier\n"
15496 "Address Family modifier\n"
15497 "Display paths suppressed due to dampening\n")
15498{
15499 safi_t safi;
15500
15501 if (bgp_parse_safi(argv[0], &safi)) {
15502 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15503 return CMD_WARNING;
15504 }
15505
15506 return bgp_show (vty, NULL, AFI_IP6, safi, bgp_show_type_dampend_paths, NULL);
15507}
15508ALIAS (show_bgp_ipv6_safi_dampened_paths,
15509 show_bgp_ipv6_safi_damp_dampened_paths_cmd,
15510 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening dampened-paths",
15511 SHOW_STR
15512 BGP_STR
15513 IPV6_STR
15514 "Address Family modifier\n"
15515 "Address Family modifier\n"
15516 "Address Family modifier\n"
15517 "Address Family modifier\n"
15518 "Display detailed information about dampening\n"
15519 "Display paths suppressed due to dampening\n")
Lou Berger651b4022016-01-12 13:42:07 -050015520
15521DEFUN (show_bgp_ipv4_safi_flap_statistics,
15522 show_bgp_ipv4_safi_flap_statistics_cmd,
15523 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics",
15524 SHOW_STR
15525 BGP_STR
15526 "Address Family\n"
15527 "Address Family modifier\n"
15528 "Address Family modifier\n"
15529 "Address Family modifier\n"
15530 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000015531 "Display flap statistics of routes\n")
15532{
Lou Berger651b4022016-01-12 13:42:07 -050015533 safi_t safi;
David Lamparter6b0655a2014-06-04 06:53:35 +020015534
Lou Berger651b4022016-01-12 13:42:07 -050015535 if (bgp_parse_safi(argv[0], &safi)) {
15536 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15537 return CMD_WARNING;
15538 }
15539
15540 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_statistics, NULL);
15541}
15542ALIAS (show_bgp_ipv4_safi_flap_statistics,
15543 show_bgp_ipv4_safi_damp_flap_statistics_cmd,
15544 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics",
Balaji3921cc52015-05-16 23:12:17 +053015545 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053015546 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015547 "Address Family\n"
15548 "Address Family modifier\n"
15549 "Address Family modifier\n"
15550 "Address Family modifier\n"
15551 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053015552 "Display detailed information about dampening\n"
15553 "Display flap statistics of routes\n")
Lou Berger205e6742016-01-12 13:42:11 -050015554
Lou Berger651b4022016-01-12 13:42:07 -050015555DEFUN (show_bgp_ipv6_safi_flap_statistics,
15556 show_bgp_ipv6_safi_flap_statistics_cmd,
15557 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics",
15558 SHOW_STR
15559 BGP_STR
15560 "Address Family\n"
15561 "Address Family modifier\n"
15562 "Address Family modifier\n"
15563 "Address Family modifier\n"
15564 "Address Family modifier\n"
15565 "Display flap statistics of routes\n")
15566{
15567 safi_t safi;
15568
15569 if (bgp_parse_safi(argv[0], &safi)) {
15570 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15571 return CMD_WARNING;
15572 }
15573
15574 return bgp_show (vty, NULL, AFI_IP6, safi, bgp_show_type_flap_statistics, NULL);
15575}
15576ALIAS (show_bgp_ipv6_safi_flap_statistics,
15577 show_bgp_ipv6_safi_damp_flap_statistics_cmd,
15578 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics",
15579 SHOW_STR
15580 BGP_STR
15581 "Address Family\n"
15582 "Address Family modifier\n"
15583 "Address Family modifier\n"
15584 "Address Family modifier\n"
15585 "Address Family modifier\n"
15586 "Display detailed information about dampening\n"
15587 "Display flap statistics of routes\n")
Balaji3921cc52015-05-16 23:12:17 +053015588
paul718e3742002-12-13 20:15:29 +000015589/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000015590static int
paulfd79ac92004-10-13 05:06:08 +000015591bgp_clear_damp_route (struct vty *vty, const char *view_name,
15592 const char *ip_str, afi_t afi, safi_t safi,
15593 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000015594{
15595 int ret;
15596 struct prefix match;
15597 struct bgp_node *rn;
15598 struct bgp_node *rm;
15599 struct bgp_info *ri;
15600 struct bgp_info *ri_temp;
15601 struct bgp *bgp;
15602 struct bgp_table *table;
15603
15604 /* BGP structure lookup. */
15605 if (view_name)
15606 {
15607 bgp = bgp_lookup_by_name (view_name);
15608 if (bgp == NULL)
15609 {
15610 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
15611 return CMD_WARNING;
15612 }
15613 }
15614 else
15615 {
15616 bgp = bgp_get_default ();
15617 if (bgp == NULL)
15618 {
15619 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
15620 return CMD_WARNING;
15621 }
15622 }
15623
15624 /* Check IP address argument. */
15625 ret = str2prefix (ip_str, &match);
15626 if (! ret)
15627 {
15628 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
15629 return CMD_WARNING;
15630 }
15631
15632 match.family = afi2family (afi);
15633
Lou Berger298cc2f2016-01-12 13:42:02 -050015634 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000015635 {
Lou Berger298cc2f2016-01-12 13:42:02 -050015636 for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +000015637 {
15638 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
15639 continue;
15640
15641 if ((table = rn->info) != NULL)
15642 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000015643 {
15644 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
15645 {
15646 ri = rm->info;
15647 while (ri)
15648 {
15649 if (ri->extra && ri->extra->damp_info)
15650 {
15651 ri_temp = ri->next;
15652 bgp_damp_info_free (ri->extra->damp_info, 1);
15653 ri = ri_temp;
15654 }
15655 else
15656 ri = ri->next;
15657 }
15658 }
15659
15660 bgp_unlock_node (rm);
15661 }
paul718e3742002-12-13 20:15:29 +000015662 }
15663 }
15664 else
15665 {
15666 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000015667 {
15668 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
15669 {
15670 ri = rn->info;
15671 while (ri)
15672 {
15673 if (ri->extra && ri->extra->damp_info)
15674 {
15675 ri_temp = ri->next;
15676 bgp_damp_info_free (ri->extra->damp_info, 1);
15677 ri = ri_temp;
15678 }
15679 else
15680 ri = ri->next;
15681 }
15682 }
15683
15684 bgp_unlock_node (rn);
15685 }
paul718e3742002-12-13 20:15:29 +000015686 }
15687
15688 return CMD_SUCCESS;
15689}
15690
15691DEFUN (clear_ip_bgp_dampening,
15692 clear_ip_bgp_dampening_cmd,
15693 "clear ip bgp dampening",
15694 CLEAR_STR
15695 IP_STR
15696 BGP_STR
15697 "Clear route flap dampening information\n")
15698{
15699 bgp_damp_info_clean ();
15700 return CMD_SUCCESS;
15701}
15702
15703DEFUN (clear_ip_bgp_dampening_prefix,
15704 clear_ip_bgp_dampening_prefix_cmd,
15705 "clear ip bgp dampening A.B.C.D/M",
15706 CLEAR_STR
15707 IP_STR
15708 BGP_STR
15709 "Clear route flap dampening information\n"
15710 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
15711{
15712 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
15713 SAFI_UNICAST, NULL, 1);
15714}
15715
15716DEFUN (clear_ip_bgp_dampening_address,
15717 clear_ip_bgp_dampening_address_cmd,
15718 "clear ip bgp dampening A.B.C.D",
15719 CLEAR_STR
15720 IP_STR
15721 BGP_STR
15722 "Clear route flap dampening information\n"
15723 "Network to clear damping information\n")
15724{
15725 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
15726 SAFI_UNICAST, NULL, 0);
15727}
15728
15729DEFUN (clear_ip_bgp_dampening_address_mask,
15730 clear_ip_bgp_dampening_address_mask_cmd,
15731 "clear ip bgp dampening A.B.C.D A.B.C.D",
15732 CLEAR_STR
15733 IP_STR
15734 BGP_STR
15735 "Clear route flap dampening information\n"
15736 "Network to clear damping information\n"
15737 "Network mask\n")
15738{
15739 int ret;
15740 char prefix_str[BUFSIZ];
15741
15742 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
15743 if (! ret)
15744 {
15745 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
15746 return CMD_WARNING;
15747 }
15748
15749 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
15750 SAFI_UNICAST, NULL, 0);
15751}
David Lamparter6b0655a2014-06-04 06:53:35 +020015752
Lou Berger298cc2f2016-01-12 13:42:02 -050015753/* also used for encap safi */
paul94f2b392005-06-28 12:44:16 +000015754static int
paul718e3742002-12-13 20:15:29 +000015755bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
15756 afi_t afi, safi_t safi, int *write)
15757{
15758 struct bgp_node *prn;
15759 struct bgp_node *rn;
15760 struct bgp_table *table;
15761 struct prefix *p;
15762 struct prefix_rd *prd;
15763 struct bgp_static *bgp_static;
15764 u_int32_t label;
15765 char buf[SU_ADDRSTRLEN];
15766 char rdbuf[RD_ADDRSTRLEN];
15767
15768 /* Network configuration. */
15769 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
15770 if ((table = prn->info) != NULL)
15771 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
15772 if ((bgp_static = rn->info) != NULL)
15773 {
15774 p = &rn->p;
15775 prd = (struct prefix_rd *) &prn->p;
15776
15777 /* "address-family" display. */
15778 bgp_config_write_family_header (vty, afi, safi, write);
15779
15780 /* "network" configuration display. */
15781 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
15782 label = decode_label (bgp_static->tag);
15783
15784 vty_out (vty, " network %s/%d rd %s tag %d",
15785 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
15786 p->prefixlen,
15787 rdbuf, label);
15788 vty_out (vty, "%s", VTY_NEWLINE);
15789 }
15790 return 0;
15791}
15792
15793/* Configuration of static route announcement and aggregate
15794 information. */
15795int
15796bgp_config_write_network (struct vty *vty, struct bgp *bgp,
15797 afi_t afi, safi_t safi, int *write)
15798{
15799 struct bgp_node *rn;
15800 struct prefix *p;
15801 struct bgp_static *bgp_static;
15802 struct bgp_aggregate *bgp_aggregate;
15803 char buf[SU_ADDRSTRLEN];
15804
Lou Berger298cc2f2016-01-12 13:42:02 -050015805 if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
paul718e3742002-12-13 20:15:29 +000015806 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
15807
15808 /* Network configuration. */
15809 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
15810 if ((bgp_static = rn->info) != NULL)
15811 {
15812 p = &rn->p;
15813
15814 /* "address-family" display. */
15815 bgp_config_write_family_header (vty, afi, safi, write);
15816
15817 /* "network" configuration display. */
15818 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
15819 {
15820 u_int32_t destination;
15821 struct in_addr netmask;
15822
15823 destination = ntohl (p->u.prefix4.s_addr);
15824 masklen2ip (p->prefixlen, &netmask);
15825 vty_out (vty, " network %s",
15826 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
15827
15828 if ((IN_CLASSC (destination) && p->prefixlen == 24)
15829 || (IN_CLASSB (destination) && p->prefixlen == 16)
15830 || (IN_CLASSA (destination) && p->prefixlen == 8)
15831 || p->u.prefix4.s_addr == 0)
15832 {
15833 /* Natural mask is not display. */
15834 }
15835 else
15836 vty_out (vty, " mask %s", inet_ntoa (netmask));
15837 }
15838 else
15839 {
15840 vty_out (vty, " network %s/%d",
15841 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
15842 p->prefixlen);
15843 }
15844
15845 if (bgp_static->rmap.name)
15846 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000015847 else
15848 {
15849 if (bgp_static->backdoor)
15850 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000015851 }
paul718e3742002-12-13 20:15:29 +000015852
15853 vty_out (vty, "%s", VTY_NEWLINE);
15854 }
15855
15856 /* Aggregate-address configuration. */
15857 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
15858 if ((bgp_aggregate = rn->info) != NULL)
15859 {
15860 p = &rn->p;
15861
15862 /* "address-family" display. */
15863 bgp_config_write_family_header (vty, afi, safi, write);
15864
15865 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
15866 {
15867 struct in_addr netmask;
15868
15869 masklen2ip (p->prefixlen, &netmask);
15870 vty_out (vty, " aggregate-address %s %s",
15871 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
15872 inet_ntoa (netmask));
15873 }
15874 else
15875 {
15876 vty_out (vty, " aggregate-address %s/%d",
15877 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
15878 p->prefixlen);
15879 }
15880
15881 if (bgp_aggregate->as_set)
15882 vty_out (vty, " as-set");
15883
15884 if (bgp_aggregate->summary_only)
15885 vty_out (vty, " summary-only");
15886
15887 vty_out (vty, "%s", VTY_NEWLINE);
15888 }
15889
15890 return 0;
15891}
15892
15893int
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015894bgp_config_write_distance (struct vty *vty, struct bgp *bgp,
15895 afi_t afi, safi_t safi, int *write)
paul718e3742002-12-13 20:15:29 +000015896{
15897 struct bgp_node *rn;
15898 struct bgp_distance *bdistance;
15899
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015900 if (afi == AFI_IP && safi == SAFI_UNICAST)
15901 {
15902 /* Distance configuration. */
15903 if (bgp->distance_ebgp
15904 && bgp->distance_ibgp
15905 && bgp->distance_local
15906 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
15907 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
15908 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
15909 vty_out (vty, " distance bgp %d %d %d%s",
15910 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
15911 VTY_NEWLINE);
15912
15913 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
15914 if ((bdistance = rn->info) != NULL)
15915 {
15916 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
15917 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
15918 bdistance->access_list ? bdistance->access_list : "",
15919 VTY_NEWLINE);
15920 }
15921 }
15922
15923#ifdef HAVE_IPV6
15924 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
15925 {
15926 bgp_config_write_family_header (vty, afi, safi, write);
15927 if (bgp->ipv6_distance_ebgp
15928 && bgp->ipv6_distance_ibgp
15929 && bgp->ipv6_distance_local
15930 && (bgp->ipv6_distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
15931 || bgp->ipv6_distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
15932 || bgp->ipv6_distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
15933 vty_out (vty, " distance bgp %d %d %d%s",
15934 bgp->ipv6_distance_ebgp, bgp->ipv6_distance_ibgp, bgp->ipv6_distance_local,
15935 VTY_NEWLINE);
15936
15937 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
15938 if ((bdistance = rn->info) != NULL)
15939 {
15940 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
15941 inet6_ntoa (rn->p.u.prefix6), rn->p.prefixlen,
15942 bdistance->access_list ? bdistance->access_list : "",
15943 VTY_NEWLINE);
15944 }
15945 }
15946#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +000015947
15948 return 0;
15949}
15950
15951/* Allocate routing table structure and install commands. */
15952void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080015953bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000015954{
15955 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000015956 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000015957
15958 /* IPv4 BGP commands. */
15959 install_element (BGP_NODE, &bgp_network_cmd);
15960 install_element (BGP_NODE, &bgp_network_mask_cmd);
15961 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
15962 install_element (BGP_NODE, &bgp_network_route_map_cmd);
15963 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
15964 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
15965 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
15966 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
15967 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
15968 install_element (BGP_NODE, &no_bgp_network_cmd);
15969 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
15970 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
15971 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
15972 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
15973 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
15974 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
15975 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
15976 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
15977
15978 install_element (BGP_NODE, &aggregate_address_cmd);
15979 install_element (BGP_NODE, &aggregate_address_mask_cmd);
15980 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
15981 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
15982 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
15983 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
15984 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
15985 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
15986 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
15987 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
15988 install_element (BGP_NODE, &no_aggregate_address_cmd);
15989 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
15990 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
15991 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
15992 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
15993 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
15994 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
15995 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
15996 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
15997 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
15998
15999 /* IPv4 unicast configuration. */
16000 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
16001 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
16002 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
16003 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
16004 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
16005 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016006 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000016007 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
16008 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
16009 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
16010 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
16011 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016012
paul718e3742002-12-13 20:15:29 +000016013 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
16014 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
16015 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
16016 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
16017 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
16018 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
16019 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
16020 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
16021 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
16022 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
16023 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
16024 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
16025 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
16026 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
16027 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
16028 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
16029 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
16030 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
16031 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
16032 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
16033
16034 /* IPv4 multicast configuration. */
16035 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
16036 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
16037 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
16038 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
16039 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
16040 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
16041 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
16042 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
16043 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
16044 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
16045 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
16046 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
16047 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
16048 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
16049 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
16050 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
16051 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
16052 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
16053 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
16054 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
16055 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
16056 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
16057 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
16058 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
16059 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
16060 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
16061 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
16062 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
16063 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
16064 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
16065 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
16066 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
16067
Michael Lambert95cbbd22010-07-23 14:43:04 -040016068 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016069 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016070 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_route_cmd);
16071 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_route_cmd);
16072 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
16073 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
16074 install_element (VIEW_NODE, &show_bgp_ipv4_encap_route_cmd);
16075 install_element (VIEW_NODE, &show_bgp_ipv6_encap_route_cmd);
16076 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
16077 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
16078 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016079 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016080 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
16081 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
16082 install_element (VIEW_NODE, &show_bgp_ipv4_encap_prefix_cmd);
16083 install_element (VIEW_NODE, &show_bgp_ipv6_encap_prefix_cmd);
16084 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
16085 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
16086 install_element (VIEW_NODE, &show_bgp_afi_safi_view_cmd);
16087 install_element (VIEW_NODE, &show_bgp_view_afi_safi_route_cmd);
16088 install_element (VIEW_NODE, &show_bgp_view_afi_safi_prefix_cmd);
16089 install_element (VIEW_NODE, &show_bgp_ipv4_safi_regexp_cmd);
16090 install_element (VIEW_NODE, &show_bgp_ipv6_safi_regexp_cmd);
16091 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_list_cmd);
16092 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_list_cmd);
16093 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_list_cmd);
16094 install_element (VIEW_NODE, &show_bgp_ipv4_filter_list_cmd);
16095 install_element (VIEW_NODE, &show_bgp_ipv4_safi_filter_list_cmd);
16096 install_element (VIEW_NODE, &show_bgp_ipv6_safi_filter_list_cmd);
16097 install_element (VIEW_NODE, &show_bgp_ipv4_route_map_cmd);
16098 install_element (VIEW_NODE, &show_bgp_ipv4_cidr_only_cmd);
16099 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cidr_only_cmd);
16100 install_element (VIEW_NODE, &show_bgp_ipv4_community_cmd);
16101 install_element (VIEW_NODE, &show_bgp_ipv4_community2_cmd);
16102 install_element (VIEW_NODE, &show_bgp_ipv4_community3_cmd);
16103 install_element (VIEW_NODE, &show_bgp_ipv4_community4_cmd);
16104 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_cmd);
16105 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community2_cmd);
16106 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community3_cmd);
16107 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016108 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
16109 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
16110 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
16111 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
16112 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016113 install_element (VIEW_NODE, &show_bgp_ipv4_community_exact_cmd);
16114 install_element (VIEW_NODE, &show_bgp_ipv4_community2_exact_cmd);
16115 install_element (VIEW_NODE, &show_bgp_ipv4_community3_exact_cmd);
16116 install_element (VIEW_NODE, &show_bgp_ipv4_community4_exact_cmd);
16117 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
16118 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
16119 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
16120 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
16121 install_element (VIEW_NODE, &show_bgp_ipv4_community_list_cmd);
16122 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_list_cmd);
16123 install_element (VIEW_NODE, &show_bgp_ipv4_community_list_exact_cmd);
16124 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_list_exact_cmd);
16125 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_longer_cmd);
16126 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_longer_cmd);
16127 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_longer_cmd);
16128 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_advertised_route_cmd);
16129 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_advertised_route_cmd);
16130 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_received_routes_cmd);
16131 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016132 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016133 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_routes_cmd);
16134 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_routes_cmd);
16135 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd);
16136 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd);
16137 install_element (VIEW_NODE, &show_bgp_ipv4_safi_dampened_paths_cmd);
16138 install_element (VIEW_NODE, &show_bgp_ipv6_safi_dampened_paths_cmd);
16139 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_dampened_paths_cmd);
16140 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_dampened_paths_cmd);
16141 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_statistics_cmd);
16142 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_statistics_cmd);
16143 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_statistics_cmd);
16144 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_statistics_cmd);
16145 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_address_cmd);
16146 install_element (VIEW_NODE, &show_bgp_ipv6_flap_address_cmd);
16147 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_address_cmd);
16148 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_cmd);
16149 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_cmd);
16150 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_cmd);
16151 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_cmd);
16152 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_cidr_only_cmd);
16153 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_cidr_only_cmd);
16154 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_regexp_cmd);
16155 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_regexp_cmd);
16156 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_regexp_cmd);
16157 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_regexp_cmd);
16158 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_filter_list_cmd);
16159 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_filter_list_cmd);
16160 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_filter_list_cmd);
16161 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_filter_list_cmd);
16162 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_list_cmd);
16163 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_list_cmd);
16164 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_list_cmd);
16165 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_list_cmd);
16166 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_longer_cmd);
16167 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_longer_cmd);
16168 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd);
16169 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd);
16170 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_route_map_cmd);
16171 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_route_map_cmd);
16172 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_route_map_cmd);
16173 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_route_map_cmd);
16174 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_flap_cmd);
16175 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_flap_cmd);
16176 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_damp_cmd);
16177 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_damp_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016178 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016179 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016180 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016181 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016182 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016183 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016184
16185 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
Michael Lambert95cbbd22010-07-23 14:43:04 -040016186 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016187 install_element (RESTRICTED_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
16188 install_element (RESTRICTED_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
16189 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
16190 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
16191 install_element (RESTRICTED_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016192 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016193 install_element (RESTRICTED_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
16194 install_element (RESTRICTED_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
16195 install_element (RESTRICTED_NODE, &show_bgp_ipv4_encap_prefix_cmd);
16196 install_element (RESTRICTED_NODE, &show_bgp_ipv6_encap_prefix_cmd);
16197 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
16198 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
16199 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_route_cmd);
16200 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_prefix_cmd);
16201 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community_cmd);
16202 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community2_cmd);
16203 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community3_cmd);
16204 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community4_cmd);
16205 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community_cmd);
16206 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community2_cmd);
16207 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community3_cmd);
16208 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016209 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
16210 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
16211 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
16212 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
16213 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016214 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community_exact_cmd);
16215 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community2_exact_cmd);
16216 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community3_exact_cmd);
16217 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community4_exact_cmd);
16218 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
16219 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
16220 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
16221 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016222 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016223 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016224 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016225 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016226
Donald Sharp68b45cc2016-03-11 14:27:13 -050016227 /* BGP dampening clear commands */
paul718e3742002-12-13 20:15:29 +000016228 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
16229 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
16230 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
16231 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
16232
paul718e3742002-12-13 20:15:29 +000016233 /* New config IPv6 BGP commands. */
16234 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
16235 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
16236 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
16237 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
16238
16239 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
16240 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
16241 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
16242 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
16243
G.Balaji73bfe0b2011-09-23 22:36:20 +053016244 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
16245 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
16246
paul718e3742002-12-13 20:15:29 +000016247 /* Old config IPv6 BGP commands. */
16248 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
16249 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
16250
16251 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
16252 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
16253 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
16254 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
16255
Michael Lambert95cbbd22010-07-23 14:43:04 -040016256 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000016257 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016258 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000016259 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016260 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016261 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
paul718e3742002-12-13 20:15:29 +000016262 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000016263 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000016264 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016265 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_cmd);
16266 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community2_cmd);
16267 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community3_cmd);
16268 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community4_cmd);
16269 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_exact_cmd);
16270 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community2_exact_cmd);
16271 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community3_exact_cmd);
16272 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community4_exact_cmd);
paul718e3742002-12-13 20:15:29 +000016273 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
paul718e3742002-12-13 20:15:29 +000016274 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000016275 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
paul718e3742002-12-13 20:15:29 +000016276 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
paul718e3742002-12-13 20:15:29 +000016277 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
paul718e3742002-12-13 20:15:29 +000016278 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000016279 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000016280 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016281 install_element (VIEW_NODE, &show_bgp_ipv4_rsclient_cmd);
16282 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016283 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016284 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016285 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016286 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016287 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000016288 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
paulbb46e942003-10-24 19:02:03 +000016289 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
paulbb46e942003-10-24 19:02:03 +000016290 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000016291 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
paulbb46e942003-10-24 19:02:03 +000016292 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000016293 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000016294 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000016295 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000016296 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016297 install_element (VIEW_NODE, &show_bgp_view_ipv4_rsclient_cmd);
16298 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016299 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016300 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016301 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016302 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016303 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016304
16305 /* Restricted:
16306 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
16307 */
Paul Jakma62687ff2008-08-23 14:27:06 +010016308 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016309 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016310 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016311 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016312 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community_cmd);
16313 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community2_cmd);
16314 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community3_cmd);
16315 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community4_cmd);
16316 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community_exact_cmd);
16317 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community2_exact_cmd);
16318 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community3_exact_cmd);
16319 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community4_exact_cmd);
16320 install_element (RESTRICTED_NODE, &show_bgp_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016321 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016322 install_element (RESTRICTED_NODE, &show_bgp_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016323 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016324 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016325 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016326 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016327 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016328 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016329 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016330 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016331
Paul Jakma2815e612006-09-14 02:56:07 +000016332 /* Statistics */
16333 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016334 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
paul718e3742002-12-13 20:15:29 +000016335
16336 install_element (BGP_NODE, &bgp_distance_cmd);
16337 install_element (BGP_NODE, &no_bgp_distance_cmd);
16338 install_element (BGP_NODE, &no_bgp_distance2_cmd);
16339 install_element (BGP_NODE, &bgp_distance_source_cmd);
16340 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
16341 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
16342 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
Roman Hoog Antink6184c392014-03-17 14:01:42 +010016343#ifdef HAVE_IPV6
16344 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_cmd);
16345 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_cmd);
16346 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance2_cmd);
16347 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_cmd);
16348 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_cmd);
16349 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_access_list_cmd);
16350 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_access_list_cmd);
16351#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +000016352
16353 install_element (BGP_NODE, &bgp_damp_set_cmd);
16354 install_element (BGP_NODE, &bgp_damp_set2_cmd);
16355 install_element (BGP_NODE, &bgp_damp_set3_cmd);
16356 install_element (BGP_NODE, &bgp_damp_unset_cmd);
16357 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
16358 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
16359 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
16360 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
16361 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
16362 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Balaji9145f0e2016-01-20 22:59:27 +053016363
16364 /* IPv4 Multicast Mode */
16365 install_element (BGP_IPV4M_NODE, &bgp_damp_set_cmd);
16366 install_element (BGP_IPV4M_NODE, &bgp_damp_set2_cmd);
16367 install_element (BGP_IPV4M_NODE, &bgp_damp_set3_cmd);
16368 install_element (BGP_IPV4M_NODE, &bgp_damp_unset_cmd);
16369 install_element (BGP_IPV4M_NODE, &bgp_damp_unset2_cmd);
16370
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016371
16372 /* Deprecated AS-Pathlimit commands */
16373 install_element (BGP_NODE, &bgp_network_ttl_cmd);
16374 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
16375 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
16376 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
16377 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16378 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16379
16380 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
16381 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
16382 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16383 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
16384 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16385 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
16386
16387 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
16388 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
16389 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
16390 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
16391 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16392 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16393
16394 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
16395 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
16396 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16397 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
16398 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16399 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
16400
16401 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
16402 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
16403 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
16404 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
16405 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16406 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16407
16408 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
16409 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
16410 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16411 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
16412 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16413 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000016414
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016415 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
16416 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016417
16418 /* old style commands */
16419 install_element (VIEW_NODE, &show_ip_bgp_cmd);
16420 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
16421 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
16422 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
16423 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
16424 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
16425 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
16426 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
16427 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
16428 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
16429 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
16430 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
16431 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
16432 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
16433 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
16434 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
16435 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
16436 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
16437 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
16438 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
16439 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
16440 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
16441 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
16442 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
16443 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
16444 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
16445 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
16446 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
16447 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
16448 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
16449 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
16450 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
16451 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
16452 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
16453 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
16454 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
16455 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
16456 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
16457 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
16458 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
16459 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
16460 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
16461 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
16462 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
16463 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
16464 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
16465 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
16466 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
16467 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
16468 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
16469 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
16470 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
16471 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
16472 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
16473 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
16474 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
Balaji9c52cae2016-01-20 22:59:26 +053016475 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_parameters_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016476 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji9c52cae2016-01-20 22:59:26 +053016477 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_dampd_paths_cmd);
16478 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_flap_stats_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016479 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
16480 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
16481 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
16482 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
16483 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
16484 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
16485 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
16486 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
16487 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
16488 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
16489 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
16490 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
16491 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
16492 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
16493 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
16494 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
16495 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
16496 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
16497 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
16498 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
16499 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
16500 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
16501 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
16502 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
16503 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
16504 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
16505 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016506
Lou Bergerf9b6c392016-01-12 13:42:09 -050016507 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
16508 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
16509 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
16510 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
16511 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
16512 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
16513 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
16514 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
16515 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
16516 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
16517 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
16518 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
16519 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
16520 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
16521 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
16522 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
16523 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
16524 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
16525 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
16526 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
16527 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
16528 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
16529 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
16530 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
16531 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
16532 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
16533 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
16534 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
16535 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016536
16537 install_element (VIEW_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
16538 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
16539 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016540 install_element (VIEW_NODE, &show_bgp_cmd);
16541 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
16542 install_element (VIEW_NODE, &show_bgp_route_cmd);
16543 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
16544 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
16545 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
16546 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
16547 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
16548 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
16549 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
16550 install_element (VIEW_NODE, &show_bgp_community_cmd);
16551 install_element (VIEW_NODE, &show_bgp_community2_cmd);
16552 install_element (VIEW_NODE, &show_bgp_community3_cmd);
16553 install_element (VIEW_NODE, &show_bgp_community4_cmd);
16554 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
16555 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
16556 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
16557 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
16558 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_list_cmd);
16559 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
16560 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_list_exact_cmd);
16561 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
16562 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
16563 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
16564 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
16565 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
16566 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
16567 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
16568 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
16569 install_element (VIEW_NODE, &show_bgp_view_cmd);
16570 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
16571 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
16572 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
16573 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
16574 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
16575 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
16576 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
16577 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
16578 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016579
Lou Bergerf9b6c392016-01-12 13:42:09 -050016580 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
16581 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
16582 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
16583 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
16584 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
16585 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
16586 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
16587 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
16588 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
16589 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
16590 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
16591 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
16592 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016593
Lou Bergerf9b6c392016-01-12 13:42:09 -050016594 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
16595 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016596
Lou Bergerf9b6c392016-01-12 13:42:09 -050016597 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
16598 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
16599 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
16600 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
16601 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
16602 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
16603 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
16604 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
16605 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
16606 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
16607 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
16608 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
16609 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
16610 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
16611 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
16612 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
16613 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
16614 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
16615 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
16616 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
16617 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
16618 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
16619 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
16620 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
16621 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
16622 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
16623 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
16624 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
16625 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
16626 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
16627 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
16628 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
16629 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
16630 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
16631 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
16632 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016633 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016634 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016635 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016636 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016637 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016638 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016639 /* old with name safi collision */
16640 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
16641 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
16642 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
16643 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
16644 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
16645 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
16646 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
16647 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
16648 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
16649 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
16650 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
16651 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
16652 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
16653 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
16654 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
16655 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016656
Lou Bergerf9b6c392016-01-12 13:42:09 -050016657 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
16658 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016659
16660 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
16661 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
16662 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
16663 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016664
16665 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
16666 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
16667 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
16668 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016669}
Chris Caputo228da422009-07-18 05:44:03 +000016670
16671void
16672bgp_route_finish (void)
16673{
16674 bgp_table_unlock (bgp_distance_table);
16675 bgp_distance_table = NULL;
16676}