blob: 17b87f49a8c48a60d4bd49ad42c9bbf529217274 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* BGP routing information
2 Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
23#include "prefix.h"
24#include "linklist.h"
25#include "memory.h"
26#include "command.h"
27#include "stream.h"
28#include "filter.h"
29#include "str.h"
30#include "log.h"
31#include "routemap.h"
32#include "buffer.h"
33#include "sockunion.h"
34#include "plist.h"
35#include "thread.h"
paul200df112005-06-01 11:17:05 +000036#include "workqueue.h"
paul718e3742002-12-13 20:15:29 +000037
38#include "bgpd/bgpd.h"
39#include "bgpd/bgp_table.h"
40#include "bgpd/bgp_route.h"
41#include "bgpd/bgp_attr.h"
42#include "bgpd/bgp_debug.h"
43#include "bgpd/bgp_aspath.h"
44#include "bgpd/bgp_regex.h"
45#include "bgpd/bgp_community.h"
46#include "bgpd/bgp_ecommunity.h"
47#include "bgpd/bgp_clist.h"
48#include "bgpd/bgp_packet.h"
49#include "bgpd/bgp_filter.h"
50#include "bgpd/bgp_fsm.h"
51#include "bgpd/bgp_mplsvpn.h"
52#include "bgpd/bgp_nexthop.h"
53#include "bgpd/bgp_damp.h"
54#include "bgpd/bgp_advertise.h"
55#include "bgpd/bgp_zebra.h"
hasso0a486e52005-02-01 20:57:17 +000056#include "bgpd/bgp_vty.h"
Josh Bailey96450fa2011-07-20 20:45:12 -070057#include "bgpd/bgp_mpath.h"
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -050058#include "bgpd/bgp_nht.c"
paul718e3742002-12-13 20:15:29 +000059
60/* Extern from bgp_dump.c */
Stephen Hemmingerdde72582009-05-08 15:19:07 -070061extern const char *bgp_origin_str[];
62extern const char *bgp_origin_long_str[];
David Lamparter6b0655a2014-06-04 06:53:35 +020063
paul94f2b392005-06-28 12:44:16 +000064static struct bgp_node *
paulfee0f4c2004-09-13 05:12:46 +000065bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
paul718e3742002-12-13 20:15:29 +000066 struct prefix_rd *prd)
67{
68 struct bgp_node *rn;
69 struct bgp_node *prn = NULL;
Paul Jakmada5b30f2006-05-08 14:37:17 +000070
71 assert (table);
72 if (!table)
73 return NULL;
74
Lou Berger298cc2f2016-01-12 13:42:02 -050075 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000076 {
paulfee0f4c2004-09-13 05:12:46 +000077 prn = bgp_node_get (table, (struct prefix *) prd);
paul718e3742002-12-13 20:15:29 +000078
79 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +000080 prn->info = bgp_table_init (afi, safi);
paul718e3742002-12-13 20:15:29 +000081 else
82 bgp_unlock_node (prn);
83 table = prn->info;
84 }
paul718e3742002-12-13 20:15:29 +000085
86 rn = bgp_node_get (table, p);
87
Lou Berger298cc2f2016-01-12 13:42:02 -050088 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000089 rn->prn = prn;
90
91 return rn;
92}
David Lamparter6b0655a2014-06-04 06:53:35 +020093
Paul Jakmafb982c22007-05-04 20:15:47 +000094/* Allocate bgp_info_extra */
95static struct bgp_info_extra *
96bgp_info_extra_new (void)
97{
98 struct bgp_info_extra *new;
99 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
100 return new;
101}
102
103static void
104bgp_info_extra_free (struct bgp_info_extra **extra)
105{
106 if (extra && *extra)
107 {
108 if ((*extra)->damp_info)
109 bgp_damp_info_free ((*extra)->damp_info, 0);
110
111 (*extra)->damp_info = NULL;
112
113 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
114
115 *extra = NULL;
116 }
117}
118
119/* Get bgp_info extra information for the given bgp_info, lazy allocated
120 * if required.
121 */
122struct bgp_info_extra *
123bgp_info_extra_get (struct bgp_info *ri)
124{
125 if (!ri->extra)
126 ri->extra = bgp_info_extra_new();
127 return ri->extra;
128}
129
paul718e3742002-12-13 20:15:29 +0000130/* Free bgp route information. */
paul200df112005-06-01 11:17:05 +0000131static void
paul718e3742002-12-13 20:15:29 +0000132bgp_info_free (struct bgp_info *binfo)
133{
134 if (binfo->attr)
Paul Jakmaf6f434b2010-11-23 21:28:03 +0000135 bgp_attr_unintern (&binfo->attr);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500136
137 bgp_unlink_nexthop(binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +0000138 bgp_info_extra_free (&binfo->extra);
Josh Baileyde8d5df2011-07-20 20:46:01 -0700139 bgp_info_mpath_free (&binfo->mpath);
paul718e3742002-12-13 20:15:29 +0000140
paul200df112005-06-01 11:17:05 +0000141 peer_unlock (binfo->peer); /* bgp_info peer reference */
142
paul718e3742002-12-13 20:15:29 +0000143 XFREE (MTYPE_BGP_ROUTE, binfo);
144}
145
paul200df112005-06-01 11:17:05 +0000146struct bgp_info *
147bgp_info_lock (struct bgp_info *binfo)
148{
149 binfo->lock++;
150 return binfo;
151}
152
153struct bgp_info *
154bgp_info_unlock (struct bgp_info *binfo)
155{
156 assert (binfo && binfo->lock > 0);
157 binfo->lock--;
158
159 if (binfo->lock == 0)
160 {
161#if 0
162 zlog_debug ("%s: unlocked and freeing", __func__);
163 zlog_backtrace (LOG_DEBUG);
164#endif
165 bgp_info_free (binfo);
166 return NULL;
167 }
168
169#if 0
170 if (binfo->lock == 1)
171 {
172 zlog_debug ("%s: unlocked to 1", __func__);
173 zlog_backtrace (LOG_DEBUG);
174 }
175#endif
176
177 return binfo;
178}
179
paul718e3742002-12-13 20:15:29 +0000180void
181bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
182{
183 struct bgp_info *top;
184
185 top = rn->info;
paul200df112005-06-01 11:17:05 +0000186
paul718e3742002-12-13 20:15:29 +0000187 ri->next = rn->info;
188 ri->prev = NULL;
189 if (top)
190 top->prev = ri;
191 rn->info = ri;
paul200df112005-06-01 11:17:05 +0000192
193 bgp_info_lock (ri);
194 bgp_lock_node (rn);
195 peer_lock (ri->peer); /* bgp_info peer reference */
paul718e3742002-12-13 20:15:29 +0000196}
197
paulb40d9392005-08-22 22:34:41 +0000198/* Do the actual removal of info from RIB, for use by bgp_process
199 completion callback *only* */
200static void
201bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
paul718e3742002-12-13 20:15:29 +0000202{
203 if (ri->next)
204 ri->next->prev = ri->prev;
205 if (ri->prev)
206 ri->prev->next = ri->next;
207 else
208 rn->info = ri->next;
paul200df112005-06-01 11:17:05 +0000209
Josh Baileyde8d5df2011-07-20 20:46:01 -0700210 bgp_info_mpath_dequeue (ri);
paul200df112005-06-01 11:17:05 +0000211 bgp_info_unlock (ri);
212 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000213}
214
paulb40d9392005-08-22 22:34:41 +0000215void
216bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
217{
Paul Jakma1a392d42006-09-07 00:24:49 +0000218 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
219 /* set of previous already took care of pcount */
paulb40d9392005-08-22 22:34:41 +0000220 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
221}
222
Andrew J. Schorr8d452102006-11-28 19:50:46 +0000223/* undo the effects of a previous call to bgp_info_delete; typically
224 called when a route is deleted and then quickly re-added before the
225 deletion has been processed */
226static void
227bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
228{
229 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
230 /* unset of previous already took care of pcount */
231 SET_FLAG (ri->flags, BGP_INFO_VALID);
232}
233
Paul Jakma1a392d42006-09-07 00:24:49 +0000234/* Adjust pcount as required */
235static void
236bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
237{
Avneesh Sachdev67174042012-08-17 08:19:49 -0700238 struct bgp_table *table;
239
240 assert (rn && bgp_node_table (rn));
Paul Jakma6f585442006-10-22 19:13:07 +0000241 assert (ri && ri->peer && ri->peer->bgp);
242
Avneesh Sachdev67174042012-08-17 08:19:49 -0700243 table = bgp_node_table (rn);
244
Paul Jakma1a392d42006-09-07 00:24:49 +0000245 /* Ignore 'pcount' for RS-client tables */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700246 if (table->type != BGP_TABLE_MAIN
Paul Jakma1a392d42006-09-07 00:24:49 +0000247 || ri->peer == ri->peer->bgp->peer_self)
248 return;
249
250 if (BGP_INFO_HOLDDOWN (ri)
251 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
252 {
253
254 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
255
256 /* slight hack, but more robust against errors. */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700257 if (ri->peer->pcount[table->afi][table->safi])
258 ri->peer->pcount[table->afi][table->safi]--;
Paul Jakma1a392d42006-09-07 00:24:49 +0000259 else
260 {
261 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
262 __func__, ri->peer->host);
263 zlog_backtrace (LOG_WARNING);
264 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
265 }
266 }
267 else if (!BGP_INFO_HOLDDOWN (ri)
268 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
269 {
270 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
Avneesh Sachdev67174042012-08-17 08:19:49 -0700271 ri->peer->pcount[table->afi][table->safi]++;
Paul Jakma1a392d42006-09-07 00:24:49 +0000272 }
273}
274
275
276/* Set/unset bgp_info flags, adjusting any other state as needed.
277 * This is here primarily to keep prefix-count in check.
278 */
279void
280bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
281{
282 SET_FLAG (ri->flags, flag);
283
284 /* early bath if we know it's not a flag that changes useability state */
285 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
286 return;
287
288 bgp_pcount_adjust (rn, ri);
289}
290
291void
292bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
293{
294 UNSET_FLAG (ri->flags, flag);
295
296 /* early bath if we know it's not a flag that changes useability state */
297 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
298 return;
299
300 bgp_pcount_adjust (rn, ri);
301}
302
paul718e3742002-12-13 20:15:29 +0000303/* Get MED value. If MED value is missing and "bgp bestpath
304 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000305static u_int32_t
paul718e3742002-12-13 20:15:29 +0000306bgp_med_value (struct attr *attr, struct bgp *bgp)
307{
308 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
309 return attr->med;
310 else
311 {
312 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000313 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000314 else
315 return 0;
316 }
317}
318
Paul Jakma6d4742b2015-11-25 17:14:37 +0000319/* Compare two bgp route entity. Return -1 if new is preferred, 1 if exist
320 * is preferred, or 0 if they are the same (usually will only occur if
321 * multipath is enabled */
paul94f2b392005-06-28 12:44:16 +0000322static int
Josh Bailey96450fa2011-07-20 20:45:12 -0700323bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
Paul Jakma6d4742b2015-11-25 17:14:37 +0000324 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +0000325{
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000326 struct attr *newattr, *existattr;
327 struct attr_extra *newattre, *existattre;
328 bgp_peer_sort_t new_sort;
329 bgp_peer_sort_t exist_sort;
paul718e3742002-12-13 20:15:29 +0000330 u_int32_t new_pref;
331 u_int32_t exist_pref;
332 u_int32_t new_med;
333 u_int32_t exist_med;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000334 u_int32_t new_weight;
335 u_int32_t exist_weight;
336 uint32_t newm, existm;
paul718e3742002-12-13 20:15:29 +0000337 struct in_addr new_id;
338 struct in_addr exist_id;
339 int new_cluster;
340 int exist_cluster;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000341 int internal_as_route;
342 int confed_as_route;
paul718e3742002-12-13 20:15:29 +0000343 int ret;
Josh Bailey96450fa2011-07-20 20:45:12 -0700344
paul718e3742002-12-13 20:15:29 +0000345 /* 0. Null check. */
346 if (new == NULL)
paul718e3742002-12-13 20:15:29 +0000347 return 1;
Paul Jakma6d4742b2015-11-25 17:14:37 +0000348 if (exist == NULL)
349 return -1;
paul718e3742002-12-13 20:15:29 +0000350
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000351 newattr = new->attr;
352 existattr = exist->attr;
353 newattre = newattr->extra;
354 existattre = existattr->extra;
355
paul718e3742002-12-13 20:15:29 +0000356 /* 1. Weight check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000357 new_weight = exist_weight = 0;
358
359 if (newattre)
360 new_weight = newattre->weight;
361 if (existattre)
362 exist_weight = existattre->weight;
363
Paul Jakmafb982c22007-05-04 20:15:47 +0000364 if (new_weight > exist_weight)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000365 return -1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000366 if (new_weight < exist_weight)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000367 return 1;
paul718e3742002-12-13 20:15:29 +0000368
369 /* 2. Local preference check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000370 new_pref = exist_pref = bgp->default_local_pref;
paul718e3742002-12-13 20:15:29 +0000371
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000372 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
373 new_pref = newattr->local_pref;
374 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
375 exist_pref = existattr->local_pref;
376
paul718e3742002-12-13 20:15:29 +0000377 if (new_pref > exist_pref)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000378 return -1;
paul718e3742002-12-13 20:15:29 +0000379 if (new_pref < exist_pref)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000380 return 1;
paul718e3742002-12-13 20:15:29 +0000381
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000382 /* 3. Local route check. We prefer:
383 * - BGP_ROUTE_STATIC
384 * - BGP_ROUTE_AGGREGATE
385 * - BGP_ROUTE_REDISTRIBUTE
386 */
387 if (! (new->sub_type == BGP_ROUTE_NORMAL))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000388 return -1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000389 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000390 return 1;
paul718e3742002-12-13 20:15:29 +0000391
392 /* 4. AS path length check. */
393 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
394 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000395 int exist_hops = aspath_count_hops (existattr->aspath);
396 int exist_confeds = aspath_count_confeds (existattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000397
hasso68118452005-04-08 15:40:36 +0000398 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
399 {
paulfe69a502005-09-10 16:55:02 +0000400 int aspath_hops;
401
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000402 aspath_hops = aspath_count_hops (newattr->aspath);
403 aspath_hops += aspath_count_confeds (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000404
405 if ( aspath_hops < (exist_hops + exist_confeds))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000406 return -1;
paulfe69a502005-09-10 16:55:02 +0000407 if ( aspath_hops > (exist_hops + exist_confeds))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000408 return 1;
hasso68118452005-04-08 15:40:36 +0000409 }
410 else
411 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000412 int newhops = aspath_count_hops (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000413
414 if (newhops < exist_hops)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000415 return -1;
paulfe69a502005-09-10 16:55:02 +0000416 if (newhops > exist_hops)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000417 return 1;
hasso68118452005-04-08 15:40:36 +0000418 }
paul718e3742002-12-13 20:15:29 +0000419 }
420
421 /* 5. Origin check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000422 if (newattr->origin < existattr->origin)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000423 return -1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000424 if (newattr->origin > existattr->origin)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000425 return 1;
paul718e3742002-12-13 20:15:29 +0000426
427 /* 6. MED check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000428 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
429 && aspath_count_hops (existattr->aspath) == 0);
430 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
431 && aspath_count_confeds (existattr->aspath) > 0
432 && aspath_count_hops (newattr->aspath) == 0
433 && aspath_count_hops (existattr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000434
435 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
436 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
437 && confed_as_route)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000438 || aspath_cmp_left (newattr->aspath, existattr->aspath)
439 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
paul718e3742002-12-13 20:15:29 +0000440 || internal_as_route)
441 {
442 new_med = bgp_med_value (new->attr, bgp);
443 exist_med = bgp_med_value (exist->attr, bgp);
444
445 if (new_med < exist_med)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000446 return -1;
paul718e3742002-12-13 20:15:29 +0000447 if (new_med > exist_med)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000448 return 1;
paul718e3742002-12-13 20:15:29 +0000449 }
450
451 /* 7. Peer type check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000452 new_sort = new->peer->sort;
453 exist_sort = exist->peer->sort;
454
455 if (new_sort == BGP_PEER_EBGP
456 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000457 return -1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000458 if (exist_sort == BGP_PEER_EBGP
459 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000460 return 1;
paul718e3742002-12-13 20:15:29 +0000461
462 /* 8. IGP metric check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000463 newm = existm = 0;
464
465 if (new->extra)
466 newm = new->extra->igpmetric;
467 if (exist->extra)
468 existm = exist->extra->igpmetric;
469
Josh Bailey96450fa2011-07-20 20:45:12 -0700470 if (newm < existm)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000471 return -1;
Josh Bailey96450fa2011-07-20 20:45:12 -0700472 if (newm > existm)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000473 return 1;
paul718e3742002-12-13 20:15:29 +0000474
475 /* 9. Maximum path check. */
Paul Jakma6d4742b2015-11-25 17:14:37 +0000476 if (bgp_mpath_is_configured (bgp, afi, safi))
Josh Bailey96450fa2011-07-20 20:45:12 -0700477 {
Pradosh Mohapatra2fdd4552013-09-07 07:02:36 +0000478 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
479 {
Paul Jakma6d4742b2015-11-25 17:14:37 +0000480 /*
481 * For the two paths, all comparison steps till IGP metric
482 * have succeeded - including AS_PATH hop count. Since 'bgp
483 * bestpath as-path multipath-relax' knob is on, we don't need
484 * an exact match of AS_PATH. Thus, mark the paths are equal.
485 * That will trigger both these paths to get into the multipath
486 * array.
487 */
488 return 0;
Pradosh Mohapatra2fdd4552013-09-07 07:02:36 +0000489 }
490 else if (new->peer->sort == BGP_PEER_IBGP)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000491 {
492 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
493 return 0;
494 }
Josh Bailey96450fa2011-07-20 20:45:12 -0700495 else if (new->peer->as == exist->peer->as)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000496 return 0;
Josh Bailey96450fa2011-07-20 20:45:12 -0700497 }
paul718e3742002-12-13 20:15:29 +0000498
499 /* 10. If both paths are external, prefer the path that was received
500 first (the oldest one). This step minimizes route-flap, since a
501 newer path won't displace an older one, even if it was the
502 preferred route based on the additional decision criteria below. */
503 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000504 && new_sort == BGP_PEER_EBGP
505 && exist_sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +0000506 {
507 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000508 return -1;
paul718e3742002-12-13 20:15:29 +0000509 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000510 return 1;
paul718e3742002-12-13 20:15:29 +0000511 }
512
vivekbd4b7f12014-09-30 15:54:45 -0700513 /* 11. Router-ID comparision. */
514 /* If one of the paths is "stale", the corresponding peer router-id will
515 * be 0 and would always win over the other path. If originator id is
516 * used for the comparision, it will decide which path is better.
517 */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000518 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
519 new_id.s_addr = newattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000520 else
521 new_id.s_addr = new->peer->remote_id.s_addr;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000522 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
523 exist_id.s_addr = existattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000524 else
525 exist_id.s_addr = exist->peer->remote_id.s_addr;
526
527 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000528 return -1;
paul718e3742002-12-13 20:15:29 +0000529 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000530 return 1;
paul718e3742002-12-13 20:15:29 +0000531
532 /* 12. Cluster length comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000533 new_cluster = exist_cluster = 0;
534
535 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
536 new_cluster = newattre->cluster->length;
537 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
538 exist_cluster = existattre->cluster->length;
paul718e3742002-12-13 20:15:29 +0000539
540 if (new_cluster < exist_cluster)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000541 return -1;
paul718e3742002-12-13 20:15:29 +0000542 if (new_cluster > exist_cluster)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000543 return 1;
paul718e3742002-12-13 20:15:29 +0000544
545 /* 13. Neighbor address comparision. */
vivekbd4b7f12014-09-30 15:54:45 -0700546 /* Do this only if neither path is "stale" as stale paths do not have
547 * valid peer information (as the connection may or may not be up).
548 */
549 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000550 return -1;
vivekbd4b7f12014-09-30 15:54:45 -0700551 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000552 return 1;
Timo Teräs2820a012015-06-24 15:27:21 +0300553 /* locally configured routes to advertise do not have su_remote */
554 if (new->peer->su_remote == NULL)
Timo Teräs2820a012015-06-24 15:27:21 +0300555 return 1;
Paul Jakma6d4742b2015-11-25 17:14:37 +0000556 if (exist->peer->su_remote == NULL)
557 return -1;
Timo Teräs2820a012015-06-24 15:27:21 +0300558
paul718e3742002-12-13 20:15:29 +0000559 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
560
561 if (ret == 1)
paul718e3742002-12-13 20:15:29 +0000562 return 1;
Paul Jakma6d4742b2015-11-25 17:14:37 +0000563 if (ret == -1)
564 return -1;
paul718e3742002-12-13 20:15:29 +0000565
Paul Jakma6d4742b2015-11-25 17:14:37 +0000566 return -1;
paul718e3742002-12-13 20:15:29 +0000567}
568
paul94f2b392005-06-28 12:44:16 +0000569static enum filter_type
paul718e3742002-12-13 20:15:29 +0000570bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
571 afi_t afi, safi_t safi)
572{
573 struct bgp_filter *filter;
574
575 filter = &peer->filter[afi][safi];
576
Paul Jakma650f76c2009-06-25 18:06:31 +0100577#define FILTER_EXIST_WARN(F,f,filter) \
578 if (BGP_DEBUG (update, UPDATE_IN) \
579 && !(F ## _IN (filter))) \
580 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
581 peer->host, #f, F ## _IN_NAME(filter));
582
583 if (DISTRIBUTE_IN_NAME (filter)) {
584 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
585
paul718e3742002-12-13 20:15:29 +0000586 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
587 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100588 }
paul718e3742002-12-13 20:15:29 +0000589
Paul Jakma650f76c2009-06-25 18:06:31 +0100590 if (PREFIX_LIST_IN_NAME (filter)) {
591 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
592
paul718e3742002-12-13 20:15:29 +0000593 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
594 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100595 }
paul718e3742002-12-13 20:15:29 +0000596
Paul Jakma650f76c2009-06-25 18:06:31 +0100597 if (FILTER_LIST_IN_NAME (filter)) {
598 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
599
paul718e3742002-12-13 20:15:29 +0000600 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
601 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100602 }
603
paul718e3742002-12-13 20:15:29 +0000604 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100605#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000606}
607
paul94f2b392005-06-28 12:44:16 +0000608static enum filter_type
paul718e3742002-12-13 20:15:29 +0000609bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
610 afi_t afi, safi_t safi)
611{
612 struct bgp_filter *filter;
613
614 filter = &peer->filter[afi][safi];
615
Paul Jakma650f76c2009-06-25 18:06:31 +0100616#define FILTER_EXIST_WARN(F,f,filter) \
617 if (BGP_DEBUG (update, UPDATE_OUT) \
618 && !(F ## _OUT (filter))) \
619 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
620 peer->host, #f, F ## _OUT_NAME(filter));
621
622 if (DISTRIBUTE_OUT_NAME (filter)) {
623 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
624
paul718e3742002-12-13 20:15:29 +0000625 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
626 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100627 }
paul718e3742002-12-13 20:15:29 +0000628
Paul Jakma650f76c2009-06-25 18:06:31 +0100629 if (PREFIX_LIST_OUT_NAME (filter)) {
630 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
631
paul718e3742002-12-13 20:15:29 +0000632 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
633 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100634 }
paul718e3742002-12-13 20:15:29 +0000635
Paul Jakma650f76c2009-06-25 18:06:31 +0100636 if (FILTER_LIST_OUT_NAME (filter)) {
637 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
638
paul718e3742002-12-13 20:15:29 +0000639 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
640 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100641 }
paul718e3742002-12-13 20:15:29 +0000642
643 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100644#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000645}
646
647/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000648static int
paul718e3742002-12-13 20:15:29 +0000649bgp_community_filter (struct peer *peer, struct attr *attr)
650{
651 if (attr->community)
652 {
653 /* NO_ADVERTISE check. */
654 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
655 return 1;
656
657 /* NO_EXPORT check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000658 if (peer->sort == BGP_PEER_EBGP &&
paul718e3742002-12-13 20:15:29 +0000659 community_include (attr->community, COMMUNITY_NO_EXPORT))
660 return 1;
661
662 /* NO_EXPORT_SUBCONFED check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000663 if (peer->sort == BGP_PEER_EBGP
664 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000665 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
666 return 1;
667 }
668 return 0;
669}
670
671/* Route reflection loop check. */
672static int
673bgp_cluster_filter (struct peer *peer, struct attr *attr)
674{
675 struct in_addr cluster_id;
676
Paul Jakmafb982c22007-05-04 20:15:47 +0000677 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000678 {
679 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
680 cluster_id = peer->bgp->cluster_id;
681 else
682 cluster_id = peer->bgp->router_id;
683
Paul Jakmafb982c22007-05-04 20:15:47 +0000684 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000685 return 1;
686 }
687 return 0;
688}
David Lamparter6b0655a2014-06-04 06:53:35 +0200689
paul94f2b392005-06-28 12:44:16 +0000690static int
paul718e3742002-12-13 20:15:29 +0000691bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
692 afi_t afi, safi_t safi)
693{
694 struct bgp_filter *filter;
695 struct bgp_info info;
696 route_map_result_t ret;
697
698 filter = &peer->filter[afi][safi];
699
700 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000701 if (peer->weight)
702 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000703
704 /* Route map apply. */
705 if (ROUTE_MAP_IN_NAME (filter))
706 {
707 /* Duplicate current value to new strucutre for modification. */
708 info.peer = peer;
709 info.attr = attr;
710
paulac41b2a2003-08-12 05:32:27 +0000711 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
712
paul718e3742002-12-13 20:15:29 +0000713 /* Apply BGP route map to the attribute. */
714 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000715
716 peer->rmap_type = 0;
717
paul718e3742002-12-13 20:15:29 +0000718 if (ret == RMAP_DENYMATCH)
David Lamparterc460e572014-06-04 00:54:58 +0200719 /* caller has multiple error paths with bgp_attr_flush() */
720 return RMAP_DENY;
paul718e3742002-12-13 20:15:29 +0000721 }
722 return RMAP_PERMIT;
723}
David Lamparter6b0655a2014-06-04 06:53:35 +0200724
paul94f2b392005-06-28 12:44:16 +0000725static int
paulfee0f4c2004-09-13 05:12:46 +0000726bgp_export_modifier (struct peer *rsclient, struct peer *peer,
727 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
728{
729 struct bgp_filter *filter;
730 struct bgp_info info;
731 route_map_result_t ret;
732
733 filter = &peer->filter[afi][safi];
734
735 /* Route map apply. */
736 if (ROUTE_MAP_EXPORT_NAME (filter))
737 {
738 /* Duplicate current value to new strucutre for modification. */
739 info.peer = rsclient;
740 info.attr = attr;
741
742 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
743
744 /* Apply BGP route map to the attribute. */
745 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
746
747 rsclient->rmap_type = 0;
748
749 if (ret == RMAP_DENYMATCH)
750 {
751 /* Free newly generated AS path and community by route-map. */
752 bgp_attr_flush (attr);
753 return RMAP_DENY;
754 }
755 }
756 return RMAP_PERMIT;
757}
758
paul94f2b392005-06-28 12:44:16 +0000759static int
paulfee0f4c2004-09-13 05:12:46 +0000760bgp_import_modifier (struct peer *rsclient, struct peer *peer,
761 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
762{
763 struct bgp_filter *filter;
764 struct bgp_info info;
765 route_map_result_t ret;
766
767 filter = &rsclient->filter[afi][safi];
768
769 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000770 if (peer->weight)
771 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000772
773 /* Route map apply. */
774 if (ROUTE_MAP_IMPORT_NAME (filter))
775 {
776 /* Duplicate current value to new strucutre for modification. */
777 info.peer = peer;
778 info.attr = attr;
779
780 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
781
782 /* Apply BGP route map to the attribute. */
783 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
784
785 peer->rmap_type = 0;
786
787 if (ret == RMAP_DENYMATCH)
788 {
789 /* Free newly generated AS path and community by route-map. */
790 bgp_attr_flush (attr);
791 return RMAP_DENY;
792 }
793 }
794 return RMAP_PERMIT;
795}
David Lamparter6b0655a2014-06-04 06:53:35 +0200796
paul94f2b392005-06-28 12:44:16 +0000797static int
paul718e3742002-12-13 20:15:29 +0000798bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
799 struct attr *attr, afi_t afi, safi_t safi)
800{
801 int ret;
802 char buf[SU_ADDRSTRLEN];
803 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000804 struct peer *from;
805 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000806 int transparent;
807 int reflect;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700808 struct attr *riattr;
paul718e3742002-12-13 20:15:29 +0000809
810 from = ri->peer;
811 filter = &peer->filter[afi][safi];
812 bgp = peer->bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700813 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paul718e3742002-12-13 20:15:29 +0000814
Paul Jakma750e8142008-07-22 21:11:48 +0000815 if (DISABLE_BGP_ANNOUNCE)
816 return 0;
paul718e3742002-12-13 20:15:29 +0000817
paulfee0f4c2004-09-13 05:12:46 +0000818 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
819 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
820 return 0;
821
paul718e3742002-12-13 20:15:29 +0000822 /* Do not send back route to sender. */
823 if (from == peer)
824 return 0;
825
826 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000827 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000828 if (! UNSUPPRESS_MAP_NAME (filter))
829 return 0;
830
831 /* Default route check. */
832 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
833 {
834 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
835 return 0;
paul718e3742002-12-13 20:15:29 +0000836 else if (p->family == AF_INET6 && p->prefixlen == 0)
837 return 0;
paul718e3742002-12-13 20:15:29 +0000838 }
839
paul286e1e72003-08-08 00:24:31 +0000840 /* Transparency check. */
841 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
842 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
843 transparent = 1;
844 else
845 transparent = 0;
846
paul718e3742002-12-13 20:15:29 +0000847 /* If community is not disabled check the no-export and local. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700848 if (! transparent && bgp_community_filter (peer, riattr))
paul718e3742002-12-13 20:15:29 +0000849 return 0;
850
851 /* If the attribute has originator-id and it is same as remote
852 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700853 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paul718e3742002-12-13 20:15:29 +0000854 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700855 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000856 {
857 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000858 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000859 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
860 peer->host,
861 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
862 p->prefixlen);
863 return 0;
864 }
865 }
866
867 /* ORF prefix-list filter check */
868 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
869 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
870 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
871 if (peer->orf_plist[afi][safi])
872 {
873 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
874 return 0;
875 }
876
877 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700878 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
paul718e3742002-12-13 20:15:29 +0000879 {
880 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000881 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000882 "%s [Update:SEND] %s/%d is filtered",
883 peer->host,
884 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
885 p->prefixlen);
886 return 0;
887 }
888
889#ifdef BGP_SEND_ASPATH_CHECK
890 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700891 if (aspath_loop_check (riattr->aspath, peer->as))
paul718e3742002-12-13 20:15:29 +0000892 {
893 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000894 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400895 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000896 peer->host, peer->as);
897 return 0;
898 }
899#endif /* BGP_SEND_ASPATH_CHECK */
900
901 /* If we're a CONFED we need to loop check the CONFED ID too */
902 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
903 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700904 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
paul718e3742002-12-13 20:15:29 +0000905 {
906 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000907 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400908 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000909 peer->host,
910 bgp->confed_id);
911 return 0;
912 }
913 }
914
915 /* Route-Reflect check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000916 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +0000917 reflect = 1;
918 else
919 reflect = 0;
920
921 /* IBGP reflection check. */
922 if (reflect)
923 {
924 /* A route from a Client peer. */
925 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
926 {
927 /* Reflect to all the Non-Client peers and also to the
928 Client peers other than the originator. Originator check
929 is already done. So there is noting to do. */
930 /* no bgp client-to-client reflection check. */
931 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
932 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
933 return 0;
934 }
935 else
936 {
937 /* A route from a Non-client peer. Reflect to all other
938 clients. */
939 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
940 return 0;
941 }
942 }
Paul Jakma41367172007-08-06 15:24:51 +0000943
paul718e3742002-12-13 20:15:29 +0000944 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700945 bgp_attr_dup (attr, riattr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000946
paul718e3742002-12-13 20:15:29 +0000947 /* If local-preference is not set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000948 if ((peer->sort == BGP_PEER_IBGP
949 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000950 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
951 {
952 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
953 attr->local_pref = bgp->default_local_pref;
954 }
955
Pradosh Mohapatra689bb662013-09-07 07:13:37 +0000956 /* If originator-id is not set and the route is to be reflected,
957 set the originator id */
958 if (peer && from && peer->sort == BGP_PEER_IBGP &&
959 from->sort == BGP_PEER_IBGP &&
960 (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
961 {
962 attr->extra = bgp_attr_extra_get(attr);
963 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
964 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
965 }
966
paul718e3742002-12-13 20:15:29 +0000967 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000968 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000969 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
970 {
971 if (ri->peer != bgp->peer_self && ! transparent
972 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
973 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
974 }
975
Lou Berger298cc2f2016-01-12 13:42:02 -0500976
977#define NEXTHOP_IS_V4 (\
978 (safi != SAFI_ENCAP && p->family == AF_INET) || \
979 (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 4))
980
Lou Berger298cc2f2016-01-12 13:42:02 -0500981#define NEXTHOP_IS_V6 (\
982 (safi != SAFI_ENCAP && p->family == AF_INET6) || \
983 (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 16))
Lou Berger298cc2f2016-01-12 13:42:02 -0500984
paul718e3742002-12-13 20:15:29 +0000985 /* next-hop-set */
Timo Teräs9e7a53c2014-04-24 10:22:37 +0300986 if (transparent
987 || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
paul718e3742002-12-13 20:15:29 +0000988 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
Lou Berger298cc2f2016-01-12 13:42:02 -0500989 && ((NEXTHOP_IS_V4 && attr->nexthop.s_addr)
Lou Berger298cc2f2016-01-12 13:42:02 -0500990 || (NEXTHOP_IS_V6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000991 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000992 )))
paul718e3742002-12-13 20:15:29 +0000993 {
994 /* NEXT-HOP Unchanged. */
995 }
996 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
Lou Berger298cc2f2016-01-12 13:42:02 -0500997 || (NEXTHOP_IS_V4 && attr->nexthop.s_addr == 0)
Lou Berger298cc2f2016-01-12 13:42:02 -0500998 || (NEXTHOP_IS_V6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000999 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001000 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001001 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
1002 {
1003 /* Set IPv4 nexthop. */
Lou Berger298cc2f2016-01-12 13:42:02 -05001004 if (NEXTHOP_IS_V4)
paul718e3742002-12-13 20:15:29 +00001005 {
Lou Berger298cc2f2016-01-12 13:42:02 -05001006 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00001007 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1008 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +00001009 else
1010 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1011 }
paul718e3742002-12-13 20:15:29 +00001012 /* Set IPv6 nexthop. */
Lou Berger298cc2f2016-01-12 13:42:02 -05001013 if (NEXTHOP_IS_V6)
paul718e3742002-12-13 20:15:29 +00001014 {
1015 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001016 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001017 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001018 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001019 }
paul718e3742002-12-13 20:15:29 +00001020 }
1021
Lou Berger298cc2f2016-01-12 13:42:02 -05001022 if (p->family == AF_INET6 && safi != SAFI_ENCAP)
paul718e3742002-12-13 20:15:29 +00001023 {
paulfee0f4c2004-09-13 05:12:46 +00001024 /* Left nexthop_local unchanged if so configured. */
1025 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1026 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1027 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001028 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1029 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001030 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001031 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001032 }
1033
1034 /* Default nexthop_local treatment for non-RS-Clients */
1035 else
1036 {
paul718e3742002-12-13 20:15:29 +00001037 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001038 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001039
1040 /* Set link-local address for shared network peer. */
1041 if (peer->shared_network
1042 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1043 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001044 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001045 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001046 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001047 }
1048
1049 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1050 address.*/
1051 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001052 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001053
1054 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1055 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001056 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001057 }
paulfee0f4c2004-09-13 05:12:46 +00001058
1059 }
paul718e3742002-12-13 20:15:29 +00001060
1061 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001062 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001063 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1064 && aspath_private_as_check (attr->aspath))
1065 attr->aspath = aspath_empty_get ();
1066
1067 /* Route map & unsuppress-map apply. */
1068 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001069 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001070 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001071 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001072 struct attr dummy_attr;
1073 struct attr_extra dummy_extra;
1074
1075 dummy_attr.extra = &dummy_extra;
1076
paul718e3742002-12-13 20:15:29 +00001077 info.peer = peer;
1078 info.attr = attr;
1079
1080 /* The route reflector is not allowed to modify the attributes
Dinesh Dutt083e5e22015-11-09 20:21:54 -05001081 of the reflected IBGP routes, unless configured to allow it */
1082 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP) &&
1083 !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
paul718e3742002-12-13 20:15:29 +00001084 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001085 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001086 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001087 }
paulac41b2a2003-08-12 05:32:27 +00001088
1089 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1090
Paul Jakmafb982c22007-05-04 20:15:47 +00001091 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001092 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1093 else
1094 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1095
paulac41b2a2003-08-12 05:32:27 +00001096 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001097
paul718e3742002-12-13 20:15:29 +00001098 if (ret == RMAP_DENYMATCH)
1099 {
1100 bgp_attr_flush (attr);
1101 return 0;
1102 }
1103 }
1104 return 1;
1105}
1106
paul94f2b392005-06-28 12:44:16 +00001107static int
paulfee0f4c2004-09-13 05:12:46 +00001108bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1109 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001110{
paulfee0f4c2004-09-13 05:12:46 +00001111 int ret;
1112 char buf[SU_ADDRSTRLEN];
1113 struct bgp_filter *filter;
1114 struct bgp_info info;
1115 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001116 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001117
1118 from = ri->peer;
1119 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001120 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001121
Paul Jakma750e8142008-07-22 21:11:48 +00001122 if (DISABLE_BGP_ANNOUNCE)
1123 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001124
1125 /* Do not send back route to sender. */
1126 if (from == rsclient)
1127 return 0;
1128
1129 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001130 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001131 if (! UNSUPPRESS_MAP_NAME (filter))
1132 return 0;
1133
1134 /* Default route check. */
1135 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1136 PEER_STATUS_DEFAULT_ORIGINATE))
1137 {
1138 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1139 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001140 else if (p->family == AF_INET6 && p->prefixlen == 0)
1141 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001142 }
1143
1144 /* If the attribute has originator-id and it is same as remote
1145 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001146 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001147 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001148 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001149 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001150 {
1151 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001152 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001153 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1154 rsclient->host,
1155 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1156 p->prefixlen);
1157 return 0;
1158 }
1159 }
1160
1161 /* ORF prefix-list filter check */
1162 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1163 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1164 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1165 if (rsclient->orf_plist[afi][safi])
1166 {
1167 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1168 return 0;
1169 }
1170
1171 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001172 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001173 {
1174 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001175 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001176 "%s [Update:SEND] %s/%d is filtered",
1177 rsclient->host,
1178 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1179 p->prefixlen);
1180 return 0;
1181 }
1182
1183#ifdef BGP_SEND_ASPATH_CHECK
1184 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001185 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001186 {
1187 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001188 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001189 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001190 rsclient->host, rsclient->as);
1191 return 0;
1192 }
1193#endif /* BGP_SEND_ASPATH_CHECK */
1194
1195 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001196 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001197
1198 /* next-hop-set */
1199 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
paulfee0f4c2004-09-13 05:12:46 +00001200 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001201 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001202 )
1203 {
1204 /* Set IPv4 nexthop. */
1205 if (p->family == AF_INET)
1206 {
Lou Berger298cc2f2016-01-12 13:42:02 -05001207 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00001208 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001209 IPV4_MAX_BYTELEN);
1210 else
1211 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1212 }
paulfee0f4c2004-09-13 05:12:46 +00001213 /* Set IPv6 nexthop. */
1214 if (p->family == AF_INET6)
1215 {
1216 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001217 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001218 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001219 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001220 }
paulfee0f4c2004-09-13 05:12:46 +00001221 }
1222
paulfee0f4c2004-09-13 05:12:46 +00001223 if (p->family == AF_INET6)
1224 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001225 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001226
paulfee0f4c2004-09-13 05:12:46 +00001227 /* Left nexthop_local unchanged if so configured. */
1228 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1229 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1230 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001231 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1232 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001233 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001234 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001235 }
1236
1237 /* Default nexthop_local treatment for RS-Clients */
1238 else
1239 {
1240 /* Announcer and RS-Client are both in the same network */
1241 if (rsclient->shared_network && from->shared_network &&
1242 (rsclient->ifindex == from->ifindex))
1243 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001244 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1245 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001246 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001247 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001248 }
1249
1250 /* Set link-local address for shared network peer. */
1251 else if (rsclient->shared_network
1252 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1253 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001254 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001255 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001256 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001257 }
1258
1259 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001260 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001261 }
1262
1263 }
paulfee0f4c2004-09-13 05:12:46 +00001264
1265 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001266 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001267 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1268 && aspath_private_as_check (attr->aspath))
1269 attr->aspath = aspath_empty_get ();
1270
1271 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001272 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001273 {
1274 info.peer = rsclient;
1275 info.attr = attr;
1276
1277 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1278
Paul Jakmafb982c22007-05-04 20:15:47 +00001279 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001280 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1281 else
1282 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1283
1284 rsclient->rmap_type = 0;
1285
1286 if (ret == RMAP_DENYMATCH)
1287 {
1288 bgp_attr_flush (attr);
1289 return 0;
1290 }
1291 }
1292
1293 return 1;
1294}
1295
1296struct bgp_info_pair
1297{
1298 struct bgp_info *old;
1299 struct bgp_info *new;
1300};
1301
paul94f2b392005-06-28 12:44:16 +00001302static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001303bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
Paul Jakma6d4742b2015-11-25 17:14:37 +00001304 struct bgp_info_pair *result,
1305 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00001306{
paul718e3742002-12-13 20:15:29 +00001307 struct bgp_info *new_select;
1308 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001309 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001310 struct bgp_info *ri1;
1311 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001312 struct bgp_info *nextri = NULL;
Paul Jakma6d4742b2015-11-25 17:14:37 +00001313 int cmpret, do_mpath;
Josh Bailey96450fa2011-07-20 20:45:12 -07001314 struct list mp_list;
Paul Jakma91b9e852015-12-01 14:32:11 +00001315
1316 result->old = result->new = NULL;
1317
1318 if (rn->info == NULL)
1319 {
1320 char buf[PREFIX_STRLEN];
1321 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1322 __func__,
1323 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1324 return;
1325 }
1326
Josh Bailey96450fa2011-07-20 20:45:12 -07001327 bgp_mp_list_init (&mp_list);
Paul Jakma6d4742b2015-11-25 17:14:37 +00001328 do_mpath = bgp_mpath_is_configured (bgp, afi, safi);
Josh Bailey96450fa2011-07-20 20:45:12 -07001329
paul718e3742002-12-13 20:15:29 +00001330 /* bgp deterministic-med */
1331 new_select = NULL;
1332 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1333 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1334 {
1335 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1336 continue;
1337 if (BGP_INFO_HOLDDOWN (ri1))
1338 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001339 if (ri1->peer && ri1->peer != bgp->peer_self)
1340 if (ri1->peer->status != Established)
1341 continue;
paul718e3742002-12-13 20:15:29 +00001342
1343 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001344 if (do_mpath)
1345 bgp_mp_list_add (&mp_list, ri1);
1346 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001347 if (ri1->next)
1348 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1349 {
1350 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1351 continue;
1352 if (BGP_INFO_HOLDDOWN (ri2))
1353 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001354 if (ri2->peer &&
1355 ri2->peer != bgp->peer_self &&
1356 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1357 if (ri2->peer->status != Established)
1358 continue;
paul718e3742002-12-13 20:15:29 +00001359
1360 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1361 || aspath_cmp_left_confed (ri1->attr->aspath,
1362 ri2->attr->aspath))
1363 {
Josh Bailey6918e742011-07-20 20:48:20 -07001364 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1365 old_select = ri2;
Paul Jakma6d4742b2015-11-25 17:14:37 +00001366 if ((cmpret = bgp_info_cmp (bgp, ri2, new_select, afi, safi))
1367 == -1)
paul718e3742002-12-13 20:15:29 +00001368 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001369 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001370 new_select = ri2;
1371 }
1372
Paul Jakma6d4742b2015-11-25 17:14:37 +00001373 if (do_mpath)
1374 {
1375 if (cmpret != 0)
1376 bgp_mp_list_clear (&mp_list);
1377
1378 if (cmpret == 0 || cmpret == -1)
1379 bgp_mp_list_add (&mp_list, ri2);
1380 }
Josh Bailey6918e742011-07-20 20:48:20 -07001381
Paul Jakma1a392d42006-09-07 00:24:49 +00001382 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001383 }
1384 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001385 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1386 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001387
Paul Jakma6d4742b2015-11-25 17:14:37 +00001388 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, afi, safi);
Josh Bailey6918e742011-07-20 20:48:20 -07001389 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001390 }
1391
1392 /* Check old selected route and new selected route. */
1393 old_select = NULL;
1394 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001395 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001396 {
1397 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1398 old_select = ri;
1399
1400 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001401 {
1402 /* reap REMOVED routes, if needs be
1403 * selected route must stay for a while longer though
1404 */
1405 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1406 && (ri != old_select))
1407 bgp_info_reap (rn, ri);
1408
1409 continue;
1410 }
paul718e3742002-12-13 20:15:29 +00001411
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001412 if (ri->peer &&
1413 ri->peer != bgp->peer_self &&
1414 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1415 if (ri->peer->status != Established)
1416 continue;
1417
paul718e3742002-12-13 20:15:29 +00001418 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1419 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1420 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001421 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001422 continue;
1423 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001424 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1425 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001426
Paul Jakma6d4742b2015-11-25 17:14:37 +00001427 if ((cmpret = bgp_info_cmp (bgp, ri, new_select, afi, safi)) == -1)
Josh Bailey96450fa2011-07-20 20:45:12 -07001428 {
Josh Bailey6918e742011-07-20 20:48:20 -07001429 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1430 bgp_mp_dmed_deselect (new_select);
1431
Josh Bailey96450fa2011-07-20 20:45:12 -07001432 new_select = ri;
Josh Bailey96450fa2011-07-20 20:45:12 -07001433 }
Paul Jakma6d4742b2015-11-25 17:14:37 +00001434 else if (cmpret == 1 && do_mpath
1435 && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
Josh Bailey6918e742011-07-20 20:48:20 -07001436 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001437
Paul Jakma6d4742b2015-11-25 17:14:37 +00001438 if (do_mpath)
1439 {
1440 if (cmpret != 0)
1441 bgp_mp_list_clear (&mp_list);
1442
1443 if (cmpret == 0 || cmpret == -1)
1444 bgp_mp_list_add (&mp_list, ri);
1445 }
paul718e3742002-12-13 20:15:29 +00001446 }
paulfee0f4c2004-09-13 05:12:46 +00001447
Josh Bailey6918e742011-07-20 20:48:20 -07001448 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
Paul Jakma6d4742b2015-11-25 17:14:37 +00001449 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, afi, safi);
Josh Bailey96450fa2011-07-20 20:45:12 -07001450
Josh Bailey0b597ef2011-07-20 20:49:11 -07001451 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001452 bgp_mp_list_clear (&mp_list);
1453
1454 result->old = old_select;
1455 result->new = new_select;
1456
1457 return;
paulfee0f4c2004-09-13 05:12:46 +00001458}
1459
paul94f2b392005-06-28 12:44:16 +00001460static int
paulfee0f4c2004-09-13 05:12:46 +00001461bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001462 struct bgp_node *rn, afi_t afi, safi_t safi)
1463{
paulfee0f4c2004-09-13 05:12:46 +00001464 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001465 struct attr attr;
1466 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001467
Lou Berger050defe2016-01-12 13:41:59 -05001468 memset (&attr, 0, sizeof(struct attr));
1469 memset (&extra, 0, sizeof(struct attr_extra));
1470
paulfee0f4c2004-09-13 05:12:46 +00001471 p = &rn->p;
1472
Paul Jakma9eda90c2007-08-30 13:36:17 +00001473 /* Announce route to Established peer. */
1474 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001475 return 0;
1476
Paul Jakma9eda90c2007-08-30 13:36:17 +00001477 /* Address family configuration check. */
1478 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001479 return 0;
1480
Paul Jakma9eda90c2007-08-30 13:36:17 +00001481 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001482 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1483 PEER_STATUS_ORF_WAIT_REFRESH))
1484 return 0;
1485
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001486 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1487 attr.extra = &extra;
1488
Avneesh Sachdev67174042012-08-17 08:19:49 -07001489 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001490 {
1491 case BGP_TABLE_MAIN:
1492 /* Announcement to peer->conf. If the route is filtered,
1493 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001494 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1495 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001496 else
1497 bgp_adj_out_unset (rn, peer, p, afi, safi);
1498 break;
1499 case BGP_TABLE_RSCLIENT:
1500 /* Announcement to peer->conf. If the route is filtered,
1501 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001502 if (selected &&
1503 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1504 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1505 else
1506 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001507 break;
1508 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001509
Lou Berger050defe2016-01-12 13:41:59 -05001510 bgp_attr_flush (&attr);
paulfee0f4c2004-09-13 05:12:46 +00001511 return 0;
paul200df112005-06-01 11:17:05 +00001512}
paulfee0f4c2004-09-13 05:12:46 +00001513
paul200df112005-06-01 11:17:05 +00001514struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001515{
paul200df112005-06-01 11:17:05 +00001516 struct bgp *bgp;
1517 struct bgp_node *rn;
1518 afi_t afi;
1519 safi_t safi;
1520};
1521
1522static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001523bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001524{
paul0fb58d52005-11-14 14:31:49 +00001525 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001526 struct bgp *bgp = pq->bgp;
1527 struct bgp_node *rn = pq->rn;
1528 afi_t afi = pq->afi;
1529 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001530 struct bgp_info *new_select;
1531 struct bgp_info *old_select;
1532 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001533 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001534 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001535
paulfee0f4c2004-09-13 05:12:46 +00001536 /* Best path selection. */
Paul Jakma6d4742b2015-11-25 17:14:37 +00001537 bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001538 new_select = old_and_new.new;
1539 old_select = old_and_new.old;
1540
paul200df112005-06-01 11:17:05 +00001541 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1542 {
Chris Caputo228da422009-07-18 05:44:03 +00001543 if (rsclient->group)
1544 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1545 {
1546 /* Nothing to do. */
1547 if (old_select && old_select == new_select)
1548 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1549 continue;
paulfee0f4c2004-09-13 05:12:46 +00001550
Chris Caputo228da422009-07-18 05:44:03 +00001551 if (old_select)
1552 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1553 if (new_select)
1554 {
1555 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1556 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001557 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1558 }
paulfee0f4c2004-09-13 05:12:46 +00001559
Chris Caputo228da422009-07-18 05:44:03 +00001560 bgp_process_announce_selected (rsclient, new_select, rn,
1561 afi, safi);
1562 }
paul200df112005-06-01 11:17:05 +00001563 }
1564 else
1565 {
hassob7395792005-08-26 12:58:38 +00001566 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001567 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001568 if (new_select)
1569 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001570 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1571 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001572 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001573 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001574 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001575 }
paulfee0f4c2004-09-13 05:12:46 +00001576
paulb40d9392005-08-22 22:34:41 +00001577 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1578 bgp_info_reap (rn, old_select);
1579
paul200df112005-06-01 11:17:05 +00001580 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1581 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001582}
1583
paul200df112005-06-01 11:17:05 +00001584static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001585bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001586{
paul0fb58d52005-11-14 14:31:49 +00001587 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001588 struct bgp *bgp = pq->bgp;
1589 struct bgp_node *rn = pq->rn;
1590 afi_t afi = pq->afi;
1591 safi_t safi = pq->safi;
1592 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001593 struct bgp_info *new_select;
1594 struct bgp_info *old_select;
1595 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001596 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001597 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001598
paulfee0f4c2004-09-13 05:12:46 +00001599 /* Best path selection. */
Paul Jakma6d4742b2015-11-25 17:14:37 +00001600 bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001601 old_select = old_and_new.old;
1602 new_select = old_and_new.new;
1603
1604 /* Nothing to do. */
1605 if (old_select && old_select == new_select)
1606 {
1607 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001608 {
Josh Bailey8196f132011-07-20 20:47:07 -07001609 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1610 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001611 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001612
Josh Bailey8196f132011-07-20 20:47:07 -07001613 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001614 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1615 return WQ_SUCCESS;
1616 }
paulfee0f4c2004-09-13 05:12:46 +00001617 }
paul718e3742002-12-13 20:15:29 +00001618
hasso338b3422005-02-23 14:27:24 +00001619 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001620 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001621 if (new_select)
1622 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001623 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1624 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001625 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001626 }
1627
1628
paul718e3742002-12-13 20:15:29 +00001629 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001630 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001631 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001632 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001633 }
1634
1635 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001636 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1637 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001638 {
1639 if (new_select
1640 && new_select->type == ZEBRA_ROUTE_BGP
1641 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001642 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001643 else
1644 {
1645 /* Withdraw the route from the kernel. */
1646 if (old_select
1647 && old_select->type == ZEBRA_ROUTE_BGP
1648 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001649 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001650 }
1651 }
paulb40d9392005-08-22 22:34:41 +00001652
Lou Berger050defe2016-01-12 13:41:59 -05001653 /* Reap old select bgp_info, if it has been removed */
paulb40d9392005-08-22 22:34:41 +00001654 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1655 bgp_info_reap (rn, old_select);
1656
paul200df112005-06-01 11:17:05 +00001657 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1658 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001659}
1660
paul200df112005-06-01 11:17:05 +00001661static void
paul0fb58d52005-11-14 14:31:49 +00001662bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001663{
paul0fb58d52005-11-14 14:31:49 +00001664 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001665 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001666
Chris Caputo228da422009-07-18 05:44:03 +00001667 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001668 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001669 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001670 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1671}
1672
1673static void
1674bgp_process_queue_init (void)
1675{
1676 bm->process_main_queue
1677 = work_queue_new (bm->master, "process_main_queue");
1678 bm->process_rsclient_queue
1679 = work_queue_new (bm->master, "process_rsclient_queue");
1680
1681 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1682 {
1683 zlog_err ("%s: Failed to allocate work queue", __func__);
1684 exit (1);
1685 }
1686
1687 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001688 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001689 bm->process_main_queue->spec.max_retries = 0;
1690 bm->process_main_queue->spec.hold = 50;
1691
Paul Jakma838bbde2010-01-08 14:05:32 +00001692 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
David Lamparterd43f8b32015-03-03 08:54:54 +01001693 bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del;
1694 bm->process_rsclient_queue->spec.max_retries = 0;
1695 bm->process_rsclient_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001696}
1697
1698void
paulfee0f4c2004-09-13 05:12:46 +00001699bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1700{
paul200df112005-06-01 11:17:05 +00001701 struct bgp_process_queue *pqnode;
1702
1703 /* already scheduled for processing? */
1704 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1705 return;
1706
Paul Jakma91b9e852015-12-01 14:32:11 +00001707 if (rn->info == NULL)
1708 {
1709 /* XXX: Perhaps remove before next release, after we've flushed out
1710 * any obvious cases
1711 */
1712 assert (rn->info != NULL);
1713 char buf[PREFIX_STRLEN];
1714 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1715 __func__,
1716 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1717 return;
1718 }
1719
paul200df112005-06-01 11:17:05 +00001720 if ( (bm->process_main_queue == NULL) ||
1721 (bm->process_rsclient_queue == NULL) )
1722 bgp_process_queue_init ();
1723
1724 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1725 sizeof (struct bgp_process_queue));
1726 if (!pqnode)
1727 return;
Chris Caputo228da422009-07-18 05:44:03 +00001728
1729 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001730 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001731 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001732 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001733 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001734 pqnode->afi = afi;
1735 pqnode->safi = safi;
1736
Avneesh Sachdev67174042012-08-17 08:19:49 -07001737 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001738 {
paul200df112005-06-01 11:17:05 +00001739 case BGP_TABLE_MAIN:
1740 work_queue_add (bm->process_main_queue, pqnode);
1741 break;
1742 case BGP_TABLE_RSCLIENT:
1743 work_queue_add (bm->process_rsclient_queue, pqnode);
1744 break;
paulfee0f4c2004-09-13 05:12:46 +00001745 }
paul200df112005-06-01 11:17:05 +00001746
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001747 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001748 return;
paulfee0f4c2004-09-13 05:12:46 +00001749}
hasso0a486e52005-02-01 20:57:17 +00001750
paul94f2b392005-06-28 12:44:16 +00001751static int
hasso0a486e52005-02-01 20:57:17 +00001752bgp_maximum_prefix_restart_timer (struct thread *thread)
1753{
1754 struct peer *peer;
1755
1756 peer = THREAD_ARG (thread);
1757 peer->t_pmax_restart = NULL;
1758
1759 if (BGP_DEBUG (events, EVENTS))
1760 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1761 peer->host);
1762
1763 peer_clear (peer);
1764
1765 return 0;
1766}
1767
paulfee0f4c2004-09-13 05:12:46 +00001768int
paul5228ad22004-06-04 17:58:18 +00001769bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1770 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001771{
hassoe0701b72004-05-20 09:19:34 +00001772 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1773 return 0;
1774
1775 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001776 {
hassoe0701b72004-05-20 09:19:34 +00001777 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1778 && ! always)
1779 return 0;
paul718e3742002-12-13 20:15:29 +00001780
hassoe0701b72004-05-20 09:19:34 +00001781 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001782 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1783 "limit %ld", afi_safi_print (afi, safi), peer->host,
1784 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001785 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001786
hassoe0701b72004-05-20 09:19:34 +00001787 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1788 return 0;
paul718e3742002-12-13 20:15:29 +00001789
hassoe0701b72004-05-20 09:19:34 +00001790 {
paul5228ad22004-06-04 17:58:18 +00001791 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001792
1793 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001794 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001795
1796 ndata[0] = (afi >> 8);
1797 ndata[1] = afi;
1798 ndata[2] = safi;
1799 ndata[3] = (peer->pmax[afi][safi] >> 24);
1800 ndata[4] = (peer->pmax[afi][safi] >> 16);
1801 ndata[5] = (peer->pmax[afi][safi] >> 8);
1802 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001803
1804 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1805 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1806 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1807 }
hasso0a486e52005-02-01 20:57:17 +00001808
1809 /* restart timer start */
1810 if (peer->pmax_restart[afi][safi])
1811 {
1812 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1813
1814 if (BGP_DEBUG (events, EVENTS))
1815 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1816 peer->host, peer->v_pmax_restart);
1817
1818 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1819 peer->v_pmax_restart);
1820 }
1821
hassoe0701b72004-05-20 09:19:34 +00001822 return 1;
paul718e3742002-12-13 20:15:29 +00001823 }
hassoe0701b72004-05-20 09:19:34 +00001824 else
1825 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1826
1827 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1828 {
1829 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1830 && ! always)
1831 return 0;
1832
1833 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001834 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1835 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1836 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001837 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1838 }
1839 else
1840 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001841 return 0;
1842}
1843
paulb40d9392005-08-22 22:34:41 +00001844/* Unconditionally remove the route from the RIB, without taking
1845 * damping into consideration (eg, because the session went down)
1846 */
paul94f2b392005-06-28 12:44:16 +00001847static void
paul718e3742002-12-13 20:15:29 +00001848bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1849 afi_t afi, safi_t safi)
1850{
paul902212c2006-02-05 17:51:19 +00001851 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1852
1853 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1854 bgp_info_delete (rn, ri); /* keep historical info */
1855
paulb40d9392005-08-22 22:34:41 +00001856 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001857}
1858
paul94f2b392005-06-28 12:44:16 +00001859static void
paul718e3742002-12-13 20:15:29 +00001860bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
Lou Berger050defe2016-01-12 13:41:59 -05001861 afi_t afi, safi_t safi, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00001862{
paul718e3742002-12-13 20:15:29 +00001863 int status = BGP_DAMP_NONE;
1864
paulb40d9392005-08-22 22:34:41 +00001865 /* apply dampening, if result is suppressed, we'll be retaining
1866 * the bgp_info in the RIB for historical reference.
1867 */
1868 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001869 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001870 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1871 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001872 {
paul902212c2006-02-05 17:51:19 +00001873 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1874 return;
1875 }
1876
1877 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001878}
1879
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05001880static struct bgp_info *
1881info_make (int type, int sub_type, struct peer *peer, struct attr *attr,
1882 struct bgp_node *rn)
1883{
1884 struct bgp_info *new;
1885
1886 /* Make new BGP info. */
1887 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
1888 new->type = type;
1889 new->sub_type = sub_type;
1890 new->peer = peer;
1891 new->attr = attr;
1892 new->uptime = bgp_clock ();
1893 new->net = rn;
1894 return new;
1895}
1896
paul94f2b392005-06-28 12:44:16 +00001897static void
paulfee0f4c2004-09-13 05:12:46 +00001898bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1899 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1900 int sub_type, struct prefix_rd *prd, u_char *tag)
1901{
1902 struct bgp_node *rn;
1903 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001904 struct attr new_attr;
1905 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001906 struct attr *attr_new;
1907 struct attr *attr_new2;
1908 struct bgp_info *ri;
1909 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001910 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001911 char buf[SU_ADDRSTRLEN];
1912
1913 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1914 if (peer == rsclient)
1915 return;
1916
1917 bgp = peer->bgp;
1918 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1919
1920 /* Check previously received route. */
1921 for (ri = rn->info; ri; ri = ri->next)
1922 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1923 break;
1924
1925 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001926 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001927 {
1928 reason = "as-path contains our own AS;";
1929 goto filtered;
1930 }
1931
1932 /* Route reflector originator ID check. */
1933 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001934 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001935 {
1936 reason = "originator is us;";
1937 goto filtered;
1938 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001939
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001940 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001941 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001942
1943 /* Apply export policy. */
1944 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1945 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1946 {
1947 reason = "export-policy;";
1948 goto filtered;
1949 }
1950
1951 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001952
paulfee0f4c2004-09-13 05:12:46 +00001953 /* Apply import policy. */
1954 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1955 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001956 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001957
1958 reason = "import-policy;";
1959 goto filtered;
1960 }
1961
1962 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001963 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001964
1965 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001966 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001967 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001968 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001969 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001970 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001971 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001972 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001973
1974 reason = "martian next-hop;";
1975 goto filtered;
1976 }
1977 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001978
paulfee0f4c2004-09-13 05:12:46 +00001979 /* If the update is implicit withdraw. */
1980 if (ri)
1981 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001982 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001983
1984 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001985 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1986 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001987 {
1988
Paul Jakma1a392d42006-09-07 00:24:49 +00001989 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001990
1991 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001992 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001993 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1994 peer->host,
1995 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1996 p->prefixlen, rsclient->host);
1997
Chris Caputo228da422009-07-18 05:44:03 +00001998 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001999 bgp_attr_unintern (&attr_new);
Lou Berger050defe2016-01-12 13:41:59 -05002000 bgp_attr_flush(&new_attr);
Chris Caputo228da422009-07-18 05:44:03 +00002001 return;
paulfee0f4c2004-09-13 05:12:46 +00002002 }
2003
Paul Jakma16d2e242007-04-10 19:32:10 +00002004 /* Withdraw/Announce before we fully processed the withdraw */
2005 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2006 bgp_info_restore (rn, ri);
2007
paulfee0f4c2004-09-13 05:12:46 +00002008 /* Received Logging. */
2009 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002010 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002011 peer->host,
2012 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2013 p->prefixlen, rsclient->host);
2014
2015 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002016 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00002017
2018 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002019 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00002020 ri->attr = attr_new;
2021
2022 /* Update MPLS tag. */
2023 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002024 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002025
Paul Jakma1a392d42006-09-07 00:24:49 +00002026 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002027
2028 /* Process change. */
2029 bgp_process (bgp, rn, afi, safi);
2030 bgp_unlock_node (rn);
2031
2032 return;
2033 }
2034
2035 /* Received Logging. */
2036 if (BGP_DEBUG (update, UPDATE_IN))
2037 {
ajsd2c1f162004-12-08 21:10:20 +00002038 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002039 peer->host,
2040 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2041 p->prefixlen, rsclient->host);
2042 }
2043
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05002044 new = info_make(type, sub_type, peer, attr_new, rn);
paulfee0f4c2004-09-13 05:12:46 +00002045
2046 /* Update MPLS tag. */
2047 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002048 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002049
Paul Jakma1a392d42006-09-07 00:24:49 +00002050 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002051
2052 /* Register new BGP information. */
2053 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002054
2055 /* route_node_get lock */
2056 bgp_unlock_node (rn);
2057
paulfee0f4c2004-09-13 05:12:46 +00002058 /* Process change. */
2059 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002060
paulfee0f4c2004-09-13 05:12:46 +00002061 return;
2062
2063 filtered:
2064
2065 /* This BGP update is filtered. Log the reason then update BGP entry. */
2066 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002067 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002068 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2069 peer->host,
2070 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2071 p->prefixlen, rsclient->host, reason);
2072
2073 if (ri)
paulb40d9392005-08-22 22:34:41 +00002074 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002075
2076 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002077
paulfee0f4c2004-09-13 05:12:46 +00002078 return;
2079}
2080
paul94f2b392005-06-28 12:44:16 +00002081static void
paulfee0f4c2004-09-13 05:12:46 +00002082bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2083 struct peer *peer, struct prefix *p, int type, int sub_type,
2084 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002085{
paulfee0f4c2004-09-13 05:12:46 +00002086 struct bgp_node *rn;
2087 struct bgp_info *ri;
2088 char buf[SU_ADDRSTRLEN];
2089
2090 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002091 return;
paulfee0f4c2004-09-13 05:12:46 +00002092
2093 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2094
2095 /* Lookup withdrawn route. */
2096 for (ri = rn->info; ri; ri = ri->next)
2097 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2098 break;
2099
2100 /* Withdraw specified route from routing table. */
2101 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Lou Berger050defe2016-01-12 13:41:59 -05002102 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
paulfee0f4c2004-09-13 05:12:46 +00002103 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002104 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002105 "%s Can't find the route %s/%d", peer->host,
2106 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2107 p->prefixlen);
2108
2109 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002110 bgp_unlock_node (rn);
2111}
paulfee0f4c2004-09-13 05:12:46 +00002112
paul94f2b392005-06-28 12:44:16 +00002113static int
paulfee0f4c2004-09-13 05:12:46 +00002114bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002115 afi_t afi, safi_t safi, int type, int sub_type,
2116 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2117{
2118 int ret;
2119 int aspath_loop_count = 0;
2120 struct bgp_node *rn;
2121 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002122 struct attr new_attr;
2123 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002124 struct attr *attr_new;
2125 struct bgp_info *ri;
2126 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002127 const char *reason;
paul718e3742002-12-13 20:15:29 +00002128 char buf[SU_ADDRSTRLEN];
2129
Lou Berger370b7e52016-02-04 21:29:49 -05002130 memset (&new_attr, 0, sizeof(struct attr));
2131 memset (&new_extra, 0, sizeof(struct attr_extra));
2132
paul718e3742002-12-13 20:15:29 +00002133 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002134 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002135
paul718e3742002-12-13 20:15:29 +00002136 /* When peer's soft reconfiguration enabled. Record input packet in
2137 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002138 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2139 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002140 bgp_adj_in_set (rn, peer, attr);
2141
2142 /* Check previously received route. */
2143 for (ri = rn->info; ri; ri = ri->next)
2144 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2145 break;
2146
2147 /* AS path local-as loop check. */
2148 if (peer->change_local_as)
2149 {
2150 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2151 aspath_loop_count = 1;
2152
2153 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2154 {
2155 reason = "as-path contains our own AS;";
2156 goto filtered;
2157 }
2158 }
2159
2160 /* AS path loop check. */
2161 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2162 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2163 && aspath_loop_check(attr->aspath, bgp->confed_id)
2164 > peer->allowas_in[afi][safi]))
2165 {
2166 reason = "as-path contains our own AS;";
2167 goto filtered;
2168 }
2169
2170 /* Route reflector originator ID check. */
2171 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002172 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002173 {
2174 reason = "originator is us;";
2175 goto filtered;
2176 }
2177
2178 /* Route reflector cluster ID check. */
2179 if (bgp_cluster_filter (peer, attr))
2180 {
2181 reason = "reflected from the same cluster;";
2182 goto filtered;
2183 }
2184
2185 /* Apply incoming filter. */
2186 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2187 {
2188 reason = "filter;";
2189 goto filtered;
2190 }
2191
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002192 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002193 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002194
David Lamparterc460e572014-06-04 00:54:58 +02002195 /* Apply incoming route-map.
2196 * NB: new_attr may now contain newly allocated values from route-map "set"
2197 * commands, so we need bgp_attr_flush in the error paths, until we intern
2198 * the attr (which takes over the memory references) */
paul718e3742002-12-13 20:15:29 +00002199 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2200 {
2201 reason = "route-map;";
David Lamparterc460e572014-06-04 00:54:58 +02002202 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002203 goto filtered;
2204 }
2205
2206 /* IPv4 unicast next hop check. */
2207 if (afi == AFI_IP && safi == SAFI_UNICAST)
2208 {
2209 /* If the peer is EBGP and nexthop is not on connected route,
2210 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002211 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002212 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002213 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002214 {
2215 reason = "non-connected next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002216 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002217 goto filtered;
2218 }
2219
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002220 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002221 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002222 if (new_attr.nexthop.s_addr == 0
2223 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2224 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002225 {
2226 reason = "martian next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002227 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002228 goto filtered;
2229 }
2230 }
2231
2232 attr_new = bgp_attr_intern (&new_attr);
2233
2234 /* If the update is implicit withdraw. */
2235 if (ri)
2236 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002237 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002238
2239 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002240 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2241 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002242 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002243 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002244
2245 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002246 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002247 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2248 {
2249 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002250 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002251 peer->host,
2252 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2253 p->prefixlen);
2254
paul902212c2006-02-05 17:51:19 +00002255 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2256 {
2257 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2258 bgp_process (bgp, rn, afi, safi);
2259 }
paul718e3742002-12-13 20:15:29 +00002260 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002261 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002262 {
2263 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002264 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002265 "%s rcvd %s/%d...duplicate ignored",
2266 peer->host,
2267 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2268 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002269
2270 /* graceful restart STALE flag unset. */
2271 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2272 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002273 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002274 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002275 }
paul718e3742002-12-13 20:15:29 +00002276 }
2277
2278 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002279 bgp_attr_unintern (&attr_new);
Lou Berger050defe2016-01-12 13:41:59 -05002280 bgp_attr_flush (&new_attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002281
paul718e3742002-12-13 20:15:29 +00002282 return 0;
2283 }
2284
Paul Jakma16d2e242007-04-10 19:32:10 +00002285 /* Withdraw/Announce before we fully processed the withdraw */
2286 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2287 {
2288 if (BGP_DEBUG (update, UPDATE_IN))
2289 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2290 peer->host,
2291 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2292 p->prefixlen);
2293 bgp_info_restore (rn, ri);
2294 }
2295
paul718e3742002-12-13 20:15:29 +00002296 /* Received Logging. */
2297 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002298 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002299 peer->host,
2300 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2301 p->prefixlen);
2302
hasso93406d82005-02-02 14:40:33 +00002303 /* graceful restart STALE flag unset. */
2304 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002305 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002306
paul718e3742002-12-13 20:15:29 +00002307 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002308 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002309
2310 /* implicit withdraw, decrement aggregate and pcount here.
2311 * only if update is accepted, they'll increment below.
2312 */
paul902212c2006-02-05 17:51:19 +00002313 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2314
paul718e3742002-12-13 20:15:29 +00002315 /* Update bgp route dampening information. */
2316 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002317 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002318 {
2319 /* This is implicit withdraw so we should update dampening
2320 information. */
2321 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2322 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002323 }
2324
paul718e3742002-12-13 20:15:29 +00002325 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002326 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002327 ri->attr = attr_new;
2328
2329 /* Update MPLS tag. */
2330 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002331 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002332
Lou Berger050defe2016-01-12 13:41:59 -05002333 bgp_attr_flush (&new_attr);
2334
paul718e3742002-12-13 20:15:29 +00002335 /* Update bgp route dampening information. */
2336 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002337 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002338 {
2339 /* Now we do normal update dampening. */
2340 ret = bgp_damp_update (ri, rn, afi, safi);
2341 if (ret == BGP_DAMP_SUPPRESSED)
2342 {
2343 bgp_unlock_node (rn);
2344 return 0;
2345 }
2346 }
2347
2348 /* Nexthop reachability check. */
2349 if ((afi == AFI_IP || afi == AFI_IP6)
2350 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002351 && (peer->sort == BGP_PEER_IBGP
2352 || peer->sort == BGP_PEER_CONFED
2353 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002354 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002355 {
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05002356 if (bgp_find_or_add_nexthop (afi, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002357 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002358 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002359 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002360 }
2361 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002362 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002363
Lou Berger050defe2016-01-12 13:41:59 -05002364 bgp_attr_flush (&new_attr);
2365
paul718e3742002-12-13 20:15:29 +00002366 /* Process change. */
2367 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2368
2369 bgp_process (bgp, rn, afi, safi);
2370 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002371
paul718e3742002-12-13 20:15:29 +00002372 return 0;
2373 }
2374
2375 /* Received Logging. */
2376 if (BGP_DEBUG (update, UPDATE_IN))
2377 {
ajsd2c1f162004-12-08 21:10:20 +00002378 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002379 peer->host,
2380 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2381 p->prefixlen);
2382 }
2383
paul718e3742002-12-13 20:15:29 +00002384 /* Make new BGP info. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05002385 new = info_make(type, sub_type, peer, attr_new, rn);
paul718e3742002-12-13 20:15:29 +00002386
2387 /* Update MPLS tag. */
2388 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002389 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002390
2391 /* Nexthop reachability check. */
2392 if ((afi == AFI_IP || afi == AFI_IP6)
2393 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002394 && (peer->sort == BGP_PEER_IBGP
2395 || peer->sort == BGP_PEER_CONFED
2396 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002397 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002398 {
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05002399 if (bgp_find_or_add_nexthop (afi, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002400 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002401 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002402 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002403 }
2404 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002405 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002406
paul902212c2006-02-05 17:51:19 +00002407 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002408 bgp_aggregate_increment (bgp, p, new, afi, safi);
2409
2410 /* Register new BGP information. */
2411 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002412
2413 /* route_node_get lock */
2414 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002415
Lou Berger050defe2016-01-12 13:41:59 -05002416 bgp_attr_flush (&new_attr);
2417
paul718e3742002-12-13 20:15:29 +00002418 /* If maximum prefix count is configured and current prefix
2419 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002420 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2421 return -1;
paul718e3742002-12-13 20:15:29 +00002422
2423 /* Process change. */
2424 bgp_process (bgp, rn, afi, safi);
2425
2426 return 0;
2427
2428 /* This BGP update is filtered. Log the reason then update BGP
2429 entry. */
2430 filtered:
2431 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002432 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002433 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2434 peer->host,
2435 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2436 p->prefixlen, reason);
2437
2438 if (ri)
paulb40d9392005-08-22 22:34:41 +00002439 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002440
2441 bgp_unlock_node (rn);
Lou Berger050defe2016-01-12 13:41:59 -05002442 bgp_attr_flush (&new_attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002443
paul718e3742002-12-13 20:15:29 +00002444 return 0;
2445}
2446
2447int
paulfee0f4c2004-09-13 05:12:46 +00002448bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2449 afi_t afi, safi_t safi, int type, int sub_type,
2450 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2451{
2452 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002453 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002454 struct bgp *bgp;
2455 int ret;
2456
2457 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2458 soft_reconfig);
2459
2460 bgp = peer->bgp;
2461
2462 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002463 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002464 {
2465 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2466 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2467 sub_type, prd, tag);
2468 }
2469
2470 return ret;
2471}
2472
2473int
paul718e3742002-12-13 20:15:29 +00002474bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002475 afi_t afi, safi_t safi, int type, int sub_type,
2476 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002477{
2478 struct bgp *bgp;
2479 char buf[SU_ADDRSTRLEN];
2480 struct bgp_node *rn;
2481 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002482 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002483 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002484
2485 bgp = peer->bgp;
2486
David Lamparter4584c232015-04-13 09:50:00 +02002487 /* Lookup node. */
2488 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2489
2490 /* Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2491 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2492 * the iteration over all RS clients.
2493 * Since we need to remove the entry from adj_in anyway, do that first and
2494 * if there was no entry, we don't need to do anything more. */
2495 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2496 && peer != bgp->peer_self)
2497 if (!bgp_adj_in_unset (rn, peer))
2498 {
2499 if (BGP_DEBUG (update, UPDATE_IN))
2500 zlog (peer->log, LOG_DEBUG, "%s withdrawing route %s/%d "
2501 "not in adj-in", peer->host,
2502 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2503 p->prefixlen);
2504 bgp_unlock_node (rn);
2505 return 0;
2506 }
2507
paulfee0f4c2004-09-13 05:12:46 +00002508 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002509 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002510 {
2511 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2512 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2513 }
2514
paul718e3742002-12-13 20:15:29 +00002515 /* Logging. */
2516 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002517 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002518 peer->host,
2519 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2520 p->prefixlen);
2521
paul718e3742002-12-13 20:15:29 +00002522 /* Lookup withdrawn route. */
2523 for (ri = rn->info; ri; ri = ri->next)
2524 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2525 break;
2526
2527 /* Withdraw specified route from routing table. */
2528 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Lou Berger050defe2016-01-12 13:41:59 -05002529 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
paul718e3742002-12-13 20:15:29 +00002530 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002531 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002532 "%s Can't find the route %s/%d", peer->host,
2533 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2534 p->prefixlen);
2535
2536 /* Unlock bgp_node_get() lock. */
2537 bgp_unlock_node (rn);
2538
2539 return 0;
2540}
David Lamparter6b0655a2014-06-04 06:53:35 +02002541
paul718e3742002-12-13 20:15:29 +00002542void
2543bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2544{
2545 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002546 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002547 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002548 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002549 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002550 struct bgp_node *rn;
2551 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002552 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002553
Paul Jakmab2497022007-06-14 11:17:58 +00002554 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002555 return;
2556
paul718e3742002-12-13 20:15:29 +00002557 bgp = peer->bgp;
2558 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002559
paul718e3742002-12-13 20:15:29 +00002560 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2561 aspath = attr.aspath;
2562 attr.local_pref = bgp->default_local_pref;
2563 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2564
2565 if (afi == AFI_IP)
2566 str2prefix ("0.0.0.0/0", &p);
paul718e3742002-12-13 20:15:29 +00002567 else if (afi == AFI_IP6)
2568 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002569 struct attr_extra *ae = attr.extra;
2570
paul718e3742002-12-13 20:15:29 +00002571 str2prefix ("::/0", &p);
2572
2573 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002574 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002575 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002576 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002577
2578 /* If the peer is on shared nextwork and we have link-local
2579 nexthop set it. */
2580 if (peer->shared_network
2581 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2582 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002583 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002584 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002585 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002586 }
2587 }
paul718e3742002-12-13 20:15:29 +00002588
2589 if (peer->default_rmap[afi][safi].name)
2590 {
paulfee0f4c2004-09-13 05:12:46 +00002591 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002592 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2593 {
2594 for (ri = rn->info; ri; ri = ri->next)
2595 {
2596 struct attr dummy_attr;
2597 struct attr_extra dummy_extra;
2598 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002599
Christian Frankedcab1bb2012-12-07 16:45:52 +00002600 /* Provide dummy so the route-map can't modify the attributes */
2601 dummy_attr.extra = &dummy_extra;
2602 bgp_attr_dup(&dummy_attr, ri->attr);
2603 info.peer = ri->peer;
2604 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002605
Christian Frankedcab1bb2012-12-07 16:45:52 +00002606 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2607 RMAP_BGP, &info);
2608
2609 /* The route map might have set attributes. If we don't flush them
2610 * here, they will be leaked. */
2611 bgp_attr_flush(&dummy_attr);
2612 if (ret != RMAP_DENYMATCH)
2613 break;
2614 }
2615 if (ret != RMAP_DENYMATCH)
2616 break;
2617 }
paulfee0f4c2004-09-13 05:12:46 +00002618 bgp->peer_self->rmap_type = 0;
2619
paul718e3742002-12-13 20:15:29 +00002620 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002621 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002622 }
2623
2624 if (withdraw)
2625 {
2626 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2627 bgp_default_withdraw_send (peer, afi, safi);
2628 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2629 }
2630 else
2631 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002632 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2633 {
2634 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2635 bgp_default_update_send (peer, &attr, afi, safi, from);
2636 }
paul718e3742002-12-13 20:15:29 +00002637 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002638
2639 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002640 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002641}
David Lamparter6b0655a2014-06-04 06:53:35 +02002642
paul718e3742002-12-13 20:15:29 +00002643static void
2644bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002645 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002646{
2647 struct bgp_node *rn;
2648 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002649 struct attr attr;
2650 struct attr_extra extra;
2651
Lou Berger298cc2f2016-01-12 13:42:02 -05002652 memset(&extra, 0, sizeof(extra));
2653
paul718e3742002-12-13 20:15:29 +00002654 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002655 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002656
Lou Berger298cc2f2016-01-12 13:42:02 -05002657 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP)
paul718e3742002-12-13 20:15:29 +00002658 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2659 bgp_default_originate (peer, afi, safi, 0);
2660
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002661 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2662 attr.extra = &extra;
2663
paul718e3742002-12-13 20:15:29 +00002664 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2665 for (ri = rn->info; ri; ri = ri->next)
2666 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2667 {
paulfee0f4c2004-09-13 05:12:46 +00002668 if ( (rsclient) ?
2669 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2670 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002671 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2672 else
2673 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2674 }
Lou Berger298cc2f2016-01-12 13:42:02 -05002675
2676 bgp_attr_flush_encap(&attr);
paul718e3742002-12-13 20:15:29 +00002677}
2678
2679void
2680bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2681{
2682 struct bgp_node *rn;
2683 struct bgp_table *table;
2684
2685 if (peer->status != Established)
2686 return;
2687
2688 if (! peer->afc_nego[afi][safi])
2689 return;
2690
2691 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2692 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2693 return;
2694
Lou Berger298cc2f2016-01-12 13:42:02 -05002695 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
paulfee0f4c2004-09-13 05:12:46 +00002696 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002697 else
2698 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2699 rn = bgp_route_next(rn))
2700 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002701 bgp_announce_table (peer, afi, safi, table, 0);
2702
2703 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2704 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002705}
2706
2707void
2708bgp_announce_route_all (struct peer *peer)
2709{
2710 afi_t afi;
2711 safi_t safi;
2712
2713 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2714 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2715 bgp_announce_route (peer, afi, safi);
2716}
David Lamparter6b0655a2014-06-04 06:53:35 +02002717
paul718e3742002-12-13 20:15:29 +00002718static void
paulfee0f4c2004-09-13 05:12:46 +00002719bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002720 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002721{
2722 struct bgp_node *rn;
2723 struct bgp_adj_in *ain;
2724
2725 if (! table)
2726 table = rsclient->bgp->rib[afi][safi];
2727
2728 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2729 for (ain = rn->adj_in; ain; ain = ain->next)
2730 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002731 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002732 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002733
paulfee0f4c2004-09-13 05:12:46 +00002734 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002735 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002736 }
2737}
2738
2739void
2740bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2741{
2742 struct bgp_table *table;
2743 struct bgp_node *rn;
2744
Lou Berger298cc2f2016-01-12 13:42:02 -05002745 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002746 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002747
2748 else
2749 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2750 rn = bgp_route_next (rn))
2751 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002752 {
2753 struct prefix_rd prd;
2754 prd.family = AF_UNSPEC;
2755 prd.prefixlen = 64;
2756 memcpy(&prd.val, rn->p.u.val, 8);
2757
2758 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2759 }
paulfee0f4c2004-09-13 05:12:46 +00002760}
David Lamparter6b0655a2014-06-04 06:53:35 +02002761
paulfee0f4c2004-09-13 05:12:46 +00002762static void
paul718e3742002-12-13 20:15:29 +00002763bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002764 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002765{
2766 int ret;
2767 struct bgp_node *rn;
2768 struct bgp_adj_in *ain;
2769
2770 if (! table)
2771 table = peer->bgp->rib[afi][safi];
2772
2773 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2774 for (ain = rn->adj_in; ain; ain = ain->next)
2775 {
2776 if (ain->peer == peer)
2777 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002778 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002779 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002780
paul718e3742002-12-13 20:15:29 +00002781 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2782 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002783 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002784
paul718e3742002-12-13 20:15:29 +00002785 if (ret < 0)
2786 {
2787 bgp_unlock_node (rn);
2788 return;
2789 }
2790 continue;
2791 }
2792 }
2793}
2794
2795void
2796bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2797{
2798 struct bgp_node *rn;
2799 struct bgp_table *table;
2800
2801 if (peer->status != Established)
2802 return;
2803
Lou Berger298cc2f2016-01-12 13:42:02 -05002804 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002805 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002806 else
2807 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2808 rn = bgp_route_next (rn))
2809 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002810 {
2811 struct prefix_rd prd;
2812 prd.family = AF_UNSPEC;
2813 prd.prefixlen = 64;
2814 memcpy(&prd.val, rn->p.u.val, 8);
2815
2816 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2817 }
paul718e3742002-12-13 20:15:29 +00002818}
David Lamparter6b0655a2014-06-04 06:53:35 +02002819
Chris Caputo228da422009-07-18 05:44:03 +00002820
2821struct bgp_clear_node_queue
2822{
2823 struct bgp_node *rn;
2824 enum bgp_clear_route_type purpose;
2825};
2826
paul200df112005-06-01 11:17:05 +00002827static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002828bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002829{
Chris Caputo228da422009-07-18 05:44:03 +00002830 struct bgp_clear_node_queue *cnq = data;
2831 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002832 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002833 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002834 afi_t afi = bgp_node_table (rn)->afi;
2835 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002836
Paul Jakma64e580a2006-02-21 01:09:01 +00002837 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002838
Paul Jakma64e580a2006-02-21 01:09:01 +00002839 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002840 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002841 {
2842 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002843 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2844 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002845 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002846 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2847 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002848 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002849 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002850 break;
2851 }
paul200df112005-06-01 11:17:05 +00002852 return WQ_SUCCESS;
2853}
2854
2855static void
paul0fb58d52005-11-14 14:31:49 +00002856bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002857{
Chris Caputo228da422009-07-18 05:44:03 +00002858 struct bgp_clear_node_queue *cnq = data;
2859 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002860 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002861
2862 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002863 bgp_table_unlock (table);
2864 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002865}
2866
2867static void
paul94f2b392005-06-28 12:44:16 +00002868bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002869{
Paul Jakma64e580a2006-02-21 01:09:01 +00002870 struct peer *peer = wq->spec.data;
2871
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002872 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002873 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002874
2875 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002876}
2877
2878static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002879bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002880{
Paul Jakmaa2943652009-07-21 14:02:04 +01002881 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002882
Paul Jakmaa2943652009-07-21 14:02:04 +01002883 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002884#undef CLEAR_QUEUE_NAME_LEN
2885
2886 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002887 {
2888 zlog_err ("%s: Failed to allocate work queue", __func__);
2889 exit (1);
2890 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002891 peer->clear_node_queue->spec.hold = 10;
2892 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2893 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2894 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2895 peer->clear_node_queue->spec.max_retries = 0;
2896
2897 /* we only 'lock' this peer reference when the queue is actually active */
2898 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002899}
2900
paul718e3742002-12-13 20:15:29 +00002901static void
2902bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002903 struct bgp_table *table, struct peer *rsclient,
2904 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002905{
2906 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002907
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002908
paul718e3742002-12-13 20:15:29 +00002909 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002910 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002911
hasso6cf159b2005-03-21 10:28:14 +00002912 /* If still no table => afi/safi isn't configured at all or smth. */
2913 if (! table)
2914 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002915
2916 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2917 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002918 struct bgp_info *ri;
2919 struct bgp_adj_in *ain;
2920 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002921
2922 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2923 * queued for every clearing peer, regardless of whether it is
2924 * relevant to the peer at hand.
2925 *
2926 * Overview: There are 3 different indices which need to be
2927 * scrubbed, potentially, when a peer is removed:
2928 *
2929 * 1 peer's routes visible via the RIB (ie accepted routes)
2930 * 2 peer's routes visible by the (optional) peer's adj-in index
2931 * 3 other routes visible by the peer's adj-out index
2932 *
2933 * 3 there is no hurry in scrubbing, once the struct peer is
2934 * removed from bgp->peer, we could just GC such deleted peer's
2935 * adj-outs at our leisure.
2936 *
2937 * 1 and 2 must be 'scrubbed' in some way, at least made
2938 * invisible via RIB index before peer session is allowed to be
2939 * brought back up. So one needs to know when such a 'search' is
2940 * complete.
2941 *
2942 * Ideally:
2943 *
2944 * - there'd be a single global queue or a single RIB walker
2945 * - rather than tracking which route_nodes still need to be
2946 * examined on a peer basis, we'd track which peers still
2947 * aren't cleared
2948 *
2949 * Given that our per-peer prefix-counts now should be reliable,
2950 * this may actually be achievable. It doesn't seem to be a huge
2951 * problem at this time,
2952 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002953 for (ain = rn->adj_in; ain; ain = ain->next)
2954 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2955 {
2956 bgp_adj_in_remove (rn, ain);
2957 bgp_unlock_node (rn);
2958 break;
2959 }
2960 for (aout = rn->adj_out; aout; aout = aout->next)
2961 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2962 {
2963 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2964 bgp_unlock_node (rn);
2965 break;
2966 }
2967
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002968 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002969 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002970 {
Chris Caputo228da422009-07-18 05:44:03 +00002971 struct bgp_clear_node_queue *cnq;
2972
2973 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002974 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002975 bgp_lock_node (rn);
2976 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2977 sizeof (struct bgp_clear_node_queue));
2978 cnq->rn = rn;
2979 cnq->purpose = purpose;
2980 work_queue_add (peer->clear_node_queue, cnq);
2981 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002982 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002983 }
2984 return;
2985}
2986
2987void
Chris Caputo228da422009-07-18 05:44:03 +00002988bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2989 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002990{
2991 struct bgp_node *rn;
2992 struct bgp_table *table;
2993 struct peer *rsclient;
2994 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002995
Paul Jakma64e580a2006-02-21 01:09:01 +00002996 if (peer->clear_node_queue == NULL)
2997 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002998
Paul Jakmaca058a32006-09-14 02:58:49 +00002999 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3000 * Idle until it receives a Clearing_Completed event. This protects
3001 * against peers which flap faster than we can we clear, which could
3002 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00003003 *
3004 * a) race with routes from the new session being installed before
3005 * clear_route_node visits the node (to delete the route of that
3006 * peer)
3007 * b) resource exhaustion, clear_route_node likely leads to an entry
3008 * on the process_main queue. Fast-flapping could cause that queue
3009 * to grow and grow.
paul200df112005-06-01 11:17:05 +00003010 */
Donald Sharp7ef42212015-03-30 06:32:52 -07003011
3012 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3013 * the unlock will happen upon work-queue completion; other wise, the
3014 * unlock happens at the end of this function.
3015 */
Paul Jakmaca058a32006-09-14 02:58:49 +00003016 if (!peer->clear_node_queue->thread)
Lou Berger050defe2016-01-12 13:41:59 -05003017 peer_lock (peer); /* bgp_clear_node_complete */
Chris Caputo228da422009-07-18 05:44:03 +00003018 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00003019 {
Chris Caputo228da422009-07-18 05:44:03 +00003020 case BGP_CLEAR_ROUTE_NORMAL:
Lou Berger298cc2f2016-01-12 13:42:02 -05003021 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Chris Caputo228da422009-07-18 05:44:03 +00003022 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
3023 else
3024 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3025 rn = bgp_route_next (rn))
3026 if ((table = rn->info) != NULL)
3027 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3028
3029 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
3030 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
3031 PEER_FLAG_RSERVER_CLIENT))
3032 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3033 break;
3034
3035 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
Lou Berger050defe2016-01-12 13:41:59 -05003036 /*
3037 * gpz 091009: TBD why don't we have special handling for
3038 * SAFI_MPLS_VPN here in the original quagga code?
3039 * (and, by extension, for SAFI_ENCAP)
3040 */
Chris Caputo228da422009-07-18 05:44:03 +00003041 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3042 break;
3043
3044 default:
3045 assert (0);
3046 break;
paulfee0f4c2004-09-13 05:12:46 +00003047 }
Donald Sharp7ef42212015-03-30 06:32:52 -07003048
3049 /* unlock if no nodes got added to the clear-node-queue. */
Paul Jakma65ca75e2006-05-04 08:08:15 +00003050 if (!peer->clear_node_queue->thread)
Donald Sharp7ef42212015-03-30 06:32:52 -07003051 peer_unlock (peer);
3052
paul718e3742002-12-13 20:15:29 +00003053}
3054
3055void
3056bgp_clear_route_all (struct peer *peer)
3057{
3058 afi_t afi;
3059 safi_t safi;
3060
3061 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3062 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003063 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003064}
3065
Lou Berger82dd7072016-01-12 13:41:57 -05003066/*
3067 * Finish freeing things when exiting
3068 */
3069static void
3070bgp_drain_workqueue_immediate (struct work_queue *wq)
3071{
3072 if (!wq)
3073 return;
3074
3075 if (!wq->thread)
3076 {
3077 /*
3078 * no thread implies no queued items
3079 */
3080 assert(!wq->items->count);
3081 return;
3082 }
3083
3084 while (wq->items->count)
3085 {
3086 if (wq->thread)
3087 thread_cancel(wq->thread);
3088 work_queue_run(wq->thread);
3089 }
3090}
3091
3092/*
3093 * Special function to process clear node queue when bgpd is exiting
3094 * and the thread scheduler is no longer running.
3095 */
3096void
3097bgp_peer_clear_node_queue_drain_immediate(struct peer *peer)
3098{
3099 if (!peer)
3100 return;
3101
3102 bgp_drain_workqueue_immediate(peer->clear_node_queue);
3103}
3104
3105/*
3106 * The work queues are not specific to a BGP instance, but the
3107 * items in them refer to BGP instances, so this should be called
3108 * before each BGP instance is deleted.
3109 */
3110void
3111bgp_process_queues_drain_immediate(void)
3112{
3113 bgp_drain_workqueue_immediate(bm->process_main_queue);
3114 bgp_drain_workqueue_immediate(bm->process_rsclient_queue);
3115}
3116
paul718e3742002-12-13 20:15:29 +00003117void
3118bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3119{
3120 struct bgp_table *table;
3121 struct bgp_node *rn;
3122 struct bgp_adj_in *ain;
3123
3124 table = peer->bgp->rib[afi][safi];
3125
3126 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3127 for (ain = rn->adj_in; ain ; ain = ain->next)
3128 if (ain->peer == peer)
3129 {
3130 bgp_adj_in_remove (rn, ain);
3131 bgp_unlock_node (rn);
3132 break;
3133 }
3134}
hasso93406d82005-02-02 14:40:33 +00003135
3136void
3137bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3138{
3139 struct bgp_node *rn;
3140 struct bgp_info *ri;
3141 struct bgp_table *table;
3142
3143 table = peer->bgp->rib[afi][safi];
3144
3145 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3146 {
3147 for (ri = rn->info; ri; ri = ri->next)
3148 if (ri->peer == peer)
3149 {
3150 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3151 bgp_rib_remove (rn, ri, peer, afi, safi);
3152 break;
3153 }
3154 }
3155}
David Lamparter6b0655a2014-06-04 06:53:35 +02003156
Lou Berger82dd7072016-01-12 13:41:57 -05003157static void
3158bgp_cleanup_table(struct bgp_table *table, safi_t safi)
3159{
3160 struct bgp_node *rn;
3161 struct bgp_info *ri;
3162 struct bgp_info *next;
3163
3164 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3165 for (ri = rn->info; ri; ri = next)
3166 {
3167 next = ri->next;
3168 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3169 && ri->type == ZEBRA_ROUTE_BGP
3170 && ri->sub_type == BGP_ROUTE_NORMAL)
3171 bgp_zebra_withdraw (&rn->p, ri, safi);
3172 }
3173}
3174
paul718e3742002-12-13 20:15:29 +00003175/* Delete all kernel routes. */
3176void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003177bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003178{
3179 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003180 struct listnode *node, *nnode;
Lou Berger82dd7072016-01-12 13:41:57 -05003181 afi_t afi;
paul718e3742002-12-13 20:15:29 +00003182
paul1eb8ef22005-04-07 07:30:20 +00003183 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003184 {
Lou Berger82dd7072016-01-12 13:41:57 -05003185 for (afi = AFI_IP; afi < AFI_MAX; ++afi)
3186 {
3187 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00003188
Lou Berger82dd7072016-01-12 13:41:57 -05003189 bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003190
Lou Berger82dd7072016-01-12 13:41:57 -05003191 /*
3192 * VPN and ENCAP tables are two-level (RD is top level)
3193 */
3194 for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn;
3195 rn = bgp_route_next (rn))
Lou Berger298cc2f2016-01-12 13:42:02 -05003196 {
3197 if (rn->info)
Lou Berger82dd7072016-01-12 13:41:57 -05003198 {
Lou Berger298cc2f2016-01-12 13:42:02 -05003199 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN);
3200 bgp_table_finish ((struct bgp_table **)&(rn->info));
3201 rn->info = NULL;
3202 bgp_unlock_node(rn);
Lou Berger82dd7072016-01-12 13:41:57 -05003203 }
Lou Berger298cc2f2016-01-12 13:42:02 -05003204 }
3205
3206 for (rn = bgp_table_top(bgp->rib[afi][SAFI_ENCAP]); rn;
3207 rn = bgp_route_next (rn))
3208 {
3209 if (rn->info)
3210 {
3211 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_ENCAP);
3212 bgp_table_finish ((struct bgp_table **)&(rn->info));
3213 rn->info = NULL;
3214 bgp_unlock_node(rn);
3215 }
3216 }
Lou Berger82dd7072016-01-12 13:41:57 -05003217 }
paul718e3742002-12-13 20:15:29 +00003218 }
3219}
3220
3221void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003222bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003223{
3224 vty_reset ();
3225 bgp_zclient_reset ();
3226 access_list_reset ();
3227 prefix_list_reset ();
3228}
David Lamparter6b0655a2014-06-04 06:53:35 +02003229
paul718e3742002-12-13 20:15:29 +00003230/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3231 value. */
3232int
Paul Jakma518a4b72016-02-04 13:27:04 +00003233bgp_nlri_parse_ip (struct peer *peer, struct attr *attr,
3234 struct bgp_nlri *packet)
paul718e3742002-12-13 20:15:29 +00003235{
3236 u_char *pnt;
3237 u_char *lim;
3238 struct prefix p;
3239 int psize;
3240 int ret;
3241
3242 /* Check peer status. */
3243 if (peer->status != Established)
3244 return 0;
3245
3246 pnt = packet->nlri;
3247 lim = pnt + packet->length;
3248
Paul Jakma405e9e12016-02-04 17:00:18 +00003249 /* RFC4771 6.3 The NLRI field in the UPDATE message is checked for
3250 syntactic validity. If the field is syntactically incorrect,
3251 then the Error Subcode is set to Invalid Network Field. */
paul718e3742002-12-13 20:15:29 +00003252 for (; pnt < lim; pnt += psize)
3253 {
3254 /* Clear prefix structure. */
3255 memset (&p, 0, sizeof (struct prefix));
3256
3257 /* Fetch prefix length. */
3258 p.prefixlen = *pnt++;
Paul Jakma405e9e12016-02-04 17:00:18 +00003259 /* afi/safi validity already verified by caller, bgp_update_receive */
paul718e3742002-12-13 20:15:29 +00003260 p.family = afi2family (packet->afi);
3261
Paul Jakma405e9e12016-02-04 17:00:18 +00003262 /* Prefix length check. */
3263 if (p.prefixlen > prefix_blen (&p) * 8)
3264 {
3265 plog_err (peer->log,
3266 "%s [Error] Update packet error"
3267 " (wrong prefix length %u for afi %u)",
3268 peer->host, p.prefixlen, packet->afi);
3269 return -1;
3270 }
3271
paul718e3742002-12-13 20:15:29 +00003272 /* Packet size overflow check. */
3273 psize = PSIZE (p.prefixlen);
3274
3275 /* When packet overflow occur return immediately. */
3276 if (pnt + psize > lim)
Paul Jakma405e9e12016-02-04 17:00:18 +00003277 {
3278 plog_err (peer->log,
3279 "%s [Error] Update packet error"
3280 " (prefix length %u overflows packet)",
3281 peer->host, p.prefixlen);
3282 return -1;
3283 }
3284
3285 /* Defensive coding, double-check the psize fits in a struct prefix */
3286 if (psize > (ssize_t) sizeof(p.u))
3287 {
3288 plog_err (peer->log,
3289 "%s [Error] Update packet error"
3290 " (prefix length %u too large for prefix storage %zu!?!!",
3291 peer->host, p.prefixlen, sizeof(p.u));
3292 return -1;
3293 }
paul718e3742002-12-13 20:15:29 +00003294
3295 /* Fetch prefix from NLRI packet. */
3296 memcpy (&p.u.prefix, pnt, psize);
3297
3298 /* Check address. */
3299 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3300 {
3301 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3302 {
paulf5ba3872004-07-09 12:11:31 +00003303 /*
Paul Jakma405e9e12016-02-04 17:00:18 +00003304 * From RFC4271 Section 6.3:
3305 *
3306 * If a prefix in the NLRI field is semantically incorrect
3307 * (e.g., an unexpected multicast IP address), an error SHOULD
3308 * be logged locally, and the prefix SHOULD be ignored.
paulf5ba3872004-07-09 12:11:31 +00003309 */
paul718e3742002-12-13 20:15:29 +00003310 zlog (peer->log, LOG_ERR,
Paul Jakma405e9e12016-02-04 17:00:18 +00003311 "%s: IPv4 unicast NLRI is multicast address %s, ignoring",
3312 peer->host, inet_ntoa (p.u.prefix4));
3313 continue;
paul718e3742002-12-13 20:15:29 +00003314 }
3315 }
3316
paul718e3742002-12-13 20:15:29 +00003317 /* Check address. */
3318 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3319 {
3320 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3321 {
3322 char buf[BUFSIZ];
3323
Paul Jakma405e9e12016-02-04 17:00:18 +00003324 zlog (peer->log, LOG_ERR,
3325 "%s: IPv6 unicast NLRI is link-local address %s, ignoring",
3326 peer->host,
paul718e3742002-12-13 20:15:29 +00003327 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00003328 continue;
3329 }
Paul Jakma405e9e12016-02-04 17:00:18 +00003330 if (IN6_IS_ADDR_MULTICAST (&p.u.prefix6))
3331 {
3332 char buf[BUFSIZ];
3333
3334 zlog (peer->log, LOG_ERR,
3335 "%s: IPv6 unicast NLRI is multicast address %s, ignoring",
3336 peer->host,
3337 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3338 continue;
3339 }
3340 }
paul718e3742002-12-13 20:15:29 +00003341
3342 /* Normal process. */
3343 if (attr)
3344 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3345 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3346 else
3347 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3348 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3349
3350 /* Address family configuration mismatch or maximum-prefix count
3351 overflow. */
3352 if (ret < 0)
3353 return -1;
3354 }
3355
3356 /* Packet length consistency check. */
3357 if (pnt != lim)
paul718e3742002-12-13 20:15:29 +00003358 {
3359 plog_err (peer->log,
Paul Jakma405e9e12016-02-04 17:00:18 +00003360 "%s [Error] Update packet error"
3361 " (prefix length mismatch with total length)",
3362 peer->host);
paul718e3742002-12-13 20:15:29 +00003363 return -1;
3364 }
Paul Jakma405e9e12016-02-04 17:00:18 +00003365
paul718e3742002-12-13 20:15:29 +00003366 return 0;
3367}
David Lamparter6b0655a2014-06-04 06:53:35 +02003368
paul94f2b392005-06-28 12:44:16 +00003369static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003370bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003371{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003372 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003373}
3374
paul94f2b392005-06-28 12:44:16 +00003375static void
paul718e3742002-12-13 20:15:29 +00003376bgp_static_free (struct bgp_static *bgp_static)
3377{
3378 if (bgp_static->rmap.name)
3379 free (bgp_static->rmap.name);
3380 XFREE (MTYPE_BGP_STATIC, bgp_static);
3381}
3382
paul94f2b392005-06-28 12:44:16 +00003383static void
paulfee0f4c2004-09-13 05:12:46 +00003384bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3385 struct prefix *p, afi_t afi, safi_t safi)
3386{
3387 struct bgp_node *rn;
3388 struct bgp_info *ri;
3389
3390 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3391
3392 /* Check selected route and self inserted route. */
3393 for (ri = rn->info; ri; ri = ri->next)
3394 if (ri->peer == bgp->peer_self
3395 && ri->type == ZEBRA_ROUTE_BGP
3396 && ri->sub_type == BGP_ROUTE_STATIC)
3397 break;
3398
3399 /* Withdraw static BGP route from routing table. */
3400 if (ri)
3401 {
paulfee0f4c2004-09-13 05:12:46 +00003402 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003403 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003404 }
3405
3406 /* Unlock bgp_node_lookup. */
3407 bgp_unlock_node (rn);
3408}
3409
paul94f2b392005-06-28 12:44:16 +00003410static void
paulfee0f4c2004-09-13 05:12:46 +00003411bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003412 struct bgp_static *bgp_static,
3413 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003414{
3415 struct bgp_node *rn;
3416 struct bgp_info *ri;
3417 struct bgp_info *new;
3418 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003419 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003420 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003421 struct attr new_attr;
3422 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003423 struct bgp *bgp;
3424 int ret;
3425 char buf[SU_ADDRSTRLEN];
3426
3427 bgp = rsclient->bgp;
3428
Paul Jakma06e110f2006-05-12 23:29:22 +00003429 assert (bgp_static);
3430 if (!bgp_static)
3431 return;
3432
paulfee0f4c2004-09-13 05:12:46 +00003433 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3434
3435 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003436
3437 attr.nexthop = bgp_static->igpnexthop;
3438 attr.med = bgp_static->igpmetric;
3439 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003440
Paul Jakma41367172007-08-06 15:24:51 +00003441 if (bgp_static->atomic)
3442 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3443
paulfee0f4c2004-09-13 05:12:46 +00003444 /* Apply network route-map for export to this rsclient. */
3445 if (bgp_static->rmap.name)
3446 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003447 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003448 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003449 info.attr = &attr_tmp;
3450
paulfee0f4c2004-09-13 05:12:46 +00003451 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3452 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3453
3454 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3455
3456 rsclient->rmap_type = 0;
3457
3458 if (ret == RMAP_DENYMATCH)
3459 {
3460 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003461 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003462
3463 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003464 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003465 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003466 bgp_attr_extra_free (&attr);
3467
paulfee0f4c2004-09-13 05:12:46 +00003468 return;
3469 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003470 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003471 }
3472 else
3473 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003474
3475 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003476 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003477
paulfee0f4c2004-09-13 05:12:46 +00003478 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3479
Paul Jakmafb982c22007-05-04 20:15:47 +00003480 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3481 == RMAP_DENY)
3482 {
paulfee0f4c2004-09-13 05:12:46 +00003483 /* This BGP update is filtered. Log the reason then update BGP entry. */
3484 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003485 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003486 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3487 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3488 p->prefixlen, rsclient->host);
3489
3490 bgp->peer_self->rmap_type = 0;
3491
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003492 bgp_attr_unintern (&attr_new);
3493 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003494 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003495
3496 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3497
3498 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003499 }
paulfee0f4c2004-09-13 05:12:46 +00003500
3501 bgp->peer_self->rmap_type = 0;
3502
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003503 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003504 attr_new = bgp_attr_intern (&new_attr);
3505
3506 for (ri = rn->info; ri; ri = ri->next)
3507 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3508 && ri->sub_type == BGP_ROUTE_STATIC)
3509 break;
3510
3511 if (ri)
3512 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003513 if (attrhash_cmp (ri->attr, attr_new) &&
3514 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003515 {
3516 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003517 bgp_attr_unintern (&attr_new);
3518 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003519 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003520 return;
3521 }
3522 else
3523 {
3524 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003525 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003526
3527 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003528 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3529 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003530 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003531 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003532 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003533
3534 /* Process change. */
3535 bgp_process (bgp, rn, afi, safi);
3536 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003537 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003538 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003539 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003540 }
paulfee0f4c2004-09-13 05:12:46 +00003541 }
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003542
paulfee0f4c2004-09-13 05:12:46 +00003543 /* Make new BGP info. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003544 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
3545 attr_new, rn);
paulfee0f4c2004-09-13 05:12:46 +00003546 SET_FLAG (new->flags, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00003547
3548 /* Register new BGP information. */
3549 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003550
3551 /* route_node_get lock */
3552 bgp_unlock_node (rn);
3553
paulfee0f4c2004-09-13 05:12:46 +00003554 /* Process change. */
3555 bgp_process (bgp, rn, afi, safi);
3556
3557 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003558 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003559 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003560}
3561
paul94f2b392005-06-28 12:44:16 +00003562static void
paulfee0f4c2004-09-13 05:12:46 +00003563bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003564 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3565{
3566 struct bgp_node *rn;
3567 struct bgp_info *ri;
3568 struct bgp_info *new;
3569 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003570 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003571 struct attr *attr_new;
3572 int ret;
3573
Paul Jakmadd8103a2006-05-12 23:27:30 +00003574 assert (bgp_static);
3575 if (!bgp_static)
3576 return;
3577
paulfee0f4c2004-09-13 05:12:46 +00003578 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003579
3580 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003581
3582 attr.nexthop = bgp_static->igpnexthop;
3583 attr.med = bgp_static->igpmetric;
3584 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003585
Paul Jakma41367172007-08-06 15:24:51 +00003586 if (bgp_static->atomic)
3587 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3588
paul718e3742002-12-13 20:15:29 +00003589 /* Apply route-map. */
3590 if (bgp_static->rmap.name)
3591 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003592 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003593 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003594 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003595
paulfee0f4c2004-09-13 05:12:46 +00003596 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3597
paul718e3742002-12-13 20:15:29 +00003598 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003599
paulfee0f4c2004-09-13 05:12:46 +00003600 bgp->peer_self->rmap_type = 0;
3601
paul718e3742002-12-13 20:15:29 +00003602 if (ret == RMAP_DENYMATCH)
3603 {
3604 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003605 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003606
3607 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003608 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003609 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003610 bgp_static_withdraw (bgp, p, afi, safi);
3611 return;
3612 }
paul286e1e72003-08-08 00:24:31 +00003613 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003614 }
paul286e1e72003-08-08 00:24:31 +00003615 else
3616 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003617
3618 for (ri = rn->info; ri; ri = ri->next)
3619 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3620 && ri->sub_type == BGP_ROUTE_STATIC)
3621 break;
3622
3623 if (ri)
3624 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003625 if (attrhash_cmp (ri->attr, attr_new) &&
3626 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003627 {
3628 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003629 bgp_attr_unintern (&attr_new);
3630 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003631 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003632 return;
3633 }
3634 else
3635 {
3636 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003637 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003638
3639 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003640 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3641 bgp_info_restore(rn, ri);
3642 else
3643 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003644 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003645 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003646 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003647
3648 /* Process change. */
3649 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3650 bgp_process (bgp, rn, afi, safi);
3651 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003652 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003653 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003654 return;
3655 }
3656 }
3657
3658 /* Make new BGP info. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003659 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self, attr_new,
3660 rn);
paul718e3742002-12-13 20:15:29 +00003661 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00003662
3663 /* Aggregate address increment. */
3664 bgp_aggregate_increment (bgp, p, new, afi, safi);
3665
3666 /* Register new BGP information. */
3667 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003668
3669 /* route_node_get lock */
3670 bgp_unlock_node (rn);
3671
paul718e3742002-12-13 20:15:29 +00003672 /* Process change. */
3673 bgp_process (bgp, rn, afi, safi);
3674
3675 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003676 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003677 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003678}
3679
3680void
paulfee0f4c2004-09-13 05:12:46 +00003681bgp_static_update (struct bgp *bgp, struct prefix *p,
3682 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3683{
3684 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003685 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003686
3687 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3688
paul1eb8ef22005-04-07 07:30:20 +00003689 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003690 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003691 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3692 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003693 }
3694}
3695
paul718e3742002-12-13 20:15:29 +00003696void
3697bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3698 safi_t safi)
3699{
3700 struct bgp_node *rn;
3701 struct bgp_info *ri;
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003702 struct bgp_info *new;
paul718e3742002-12-13 20:15:29 +00003703
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003704 /* Make new BGP info. */
3705 rn = bgp_node_get (bgp->rib[afi][safi], p);
3706 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
3707 bgp_attr_default_intern(BGP_ORIGIN_IGP), rn);
3708
3709 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00003710
3711 /* Check selected route and self inserted route. */
3712 for (ri = rn->info; ri; ri = ri->next)
3713 if (ri->peer == bgp->peer_self
3714 && ri->type == ZEBRA_ROUTE_BGP
3715 && ri->sub_type == BGP_ROUTE_STATIC)
3716 break;
3717
3718 /* Withdraw static BGP route from routing table. */
3719 if (ri)
3720 {
3721 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003722 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003723 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003724 }
3725
3726 /* Unlock bgp_node_lookup. */
3727 bgp_unlock_node (rn);
3728}
3729
3730void
paulfee0f4c2004-09-13 05:12:46 +00003731bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3732{
3733 struct bgp_static *bgp_static;
3734 struct bgp *bgp;
3735 struct bgp_node *rn;
3736 struct prefix *p;
3737
3738 bgp = rsclient->bgp;
3739
3740 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3741 if ((bgp_static = rn->info) != NULL)
3742 {
3743 p = &rn->p;
3744
3745 bgp_static_update_rsclient (rsclient, p, bgp_static,
3746 afi, safi);
3747 }
3748}
3749
Lou Bergera76d9ca2016-01-12 13:41:53 -05003750/*
3751 * Used for SAFI_MPLS_VPN and SAFI_ENCAP
3752 */
paul94f2b392005-06-28 12:44:16 +00003753static void
Lou Bergera76d9ca2016-01-12 13:41:53 -05003754bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
3755 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003756{
3757 struct bgp_node *rn;
3758 struct bgp_info *ri;
3759
paulfee0f4c2004-09-13 05:12:46 +00003760 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003761
3762 /* Check selected route and self inserted route. */
3763 for (ri = rn->info; ri; ri = ri->next)
3764 if (ri->peer == bgp->peer_self
3765 && ri->type == ZEBRA_ROUTE_BGP
3766 && ri->sub_type == BGP_ROUTE_STATIC)
3767 break;
3768
3769 /* Withdraw static BGP route from routing table. */
3770 if (ri)
3771 {
3772 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003773 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003774 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003775 }
3776
3777 /* Unlock bgp_node_lookup. */
3778 bgp_unlock_node (rn);
3779}
3780
Lou Bergera76d9ca2016-01-12 13:41:53 -05003781static void
3782bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
3783 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3784{
3785 struct bgp_node *rn;
3786 struct bgp_info *new;
3787 struct attr *attr_new;
3788 struct attr attr = { 0 };
3789 struct bgp_info *ri;
3790
3791 assert (bgp_static);
3792
3793 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
3794
3795 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3796
3797 attr.nexthop = bgp_static->igpnexthop;
3798 attr.med = bgp_static->igpmetric;
3799 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3800
3801 /* Apply route-map. */
3802 if (bgp_static->rmap.name)
3803 {
3804 struct attr attr_tmp = attr;
3805 struct bgp_info info;
3806 int ret;
3807
3808 info.peer = bgp->peer_self;
3809 info.attr = &attr_tmp;
3810
3811 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3812
3813 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3814
3815 bgp->peer_self->rmap_type = 0;
3816
3817 if (ret == RMAP_DENYMATCH)
3818 {
3819 /* Free uninterned attribute. */
3820 bgp_attr_flush (&attr_tmp);
3821
3822 /* Unintern original. */
3823 aspath_unintern (&attr.aspath);
3824 bgp_attr_extra_free (&attr);
3825 bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
3826 bgp_static->tag);
3827 return;
3828 }
3829
3830 attr_new = bgp_attr_intern (&attr_tmp);
3831 }
3832 else
3833 {
3834 attr_new = bgp_attr_intern (&attr);
3835 }
3836
3837 for (ri = rn->info; ri; ri = ri->next)
3838 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3839 && ri->sub_type == BGP_ROUTE_STATIC)
3840 break;
3841
3842 if (ri)
3843 {
3844 if (attrhash_cmp (ri->attr, attr_new) &&
3845 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3846 {
3847 bgp_unlock_node (rn);
3848 bgp_attr_unintern (&attr_new);
3849 aspath_unintern (&attr.aspath);
3850 bgp_attr_extra_free (&attr);
3851 return;
3852 }
3853 else
3854 {
3855 /* The attribute is changed. */
3856 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3857
3858 /* Rewrite BGP route information. */
3859 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3860 bgp_info_restore(rn, ri);
3861 else
3862 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3863 bgp_attr_unintern (&ri->attr);
3864 ri->attr = attr_new;
3865 ri->uptime = bgp_clock ();
3866
3867 /* Process change. */
3868 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3869 bgp_process (bgp, rn, afi, safi);
3870 bgp_unlock_node (rn);
3871 aspath_unintern (&attr.aspath);
3872 bgp_attr_extra_free (&attr);
3873 return;
3874 }
3875 }
3876
3877
3878 /* Make new BGP info. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003879 new = info_make (ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
3880 attr_new, rn);
Lou Bergera76d9ca2016-01-12 13:41:53 -05003881 SET_FLAG (new->flags, BGP_INFO_VALID);
Lou Bergera76d9ca2016-01-12 13:41:53 -05003882 new->extra = bgp_info_extra_new();
3883 memcpy (new->extra->tag, bgp_static->tag, 3);
3884
3885 /* Aggregate address increment. */
3886 bgp_aggregate_increment (bgp, p, new, afi, safi);
3887
3888 /* Register new BGP information. */
3889 bgp_info_add (rn, new);
3890
3891 /* route_node_get lock */
3892 bgp_unlock_node (rn);
3893
3894 /* Process change. */
3895 bgp_process (bgp, rn, afi, safi);
3896
3897 /* Unintern original. */
3898 aspath_unintern (&attr.aspath);
3899 bgp_attr_extra_free (&attr);
3900}
3901
paul718e3742002-12-13 20:15:29 +00003902/* Configure static BGP network. When user don't run zebra, static
3903 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003904static int
paulfd79ac92004-10-13 05:06:08 +00003905bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003906 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003907{
3908 int ret;
3909 struct prefix p;
3910 struct bgp_static *bgp_static;
3911 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003912 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003913
3914 /* Convert IP prefix string to struct prefix. */
3915 ret = str2prefix (ip_str, &p);
3916 if (! ret)
3917 {
3918 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3919 return CMD_WARNING;
3920 }
paul718e3742002-12-13 20:15:29 +00003921 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3922 {
3923 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3924 VTY_NEWLINE);
3925 return CMD_WARNING;
3926 }
paul718e3742002-12-13 20:15:29 +00003927
3928 apply_mask (&p);
3929
3930 /* Set BGP static route configuration. */
3931 rn = bgp_node_get (bgp->route[afi][safi], &p);
3932
3933 if (rn->info)
3934 {
3935 /* Configuration change. */
3936 bgp_static = rn->info;
3937
3938 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003939 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3940 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003941
paul718e3742002-12-13 20:15:29 +00003942 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003943
paul718e3742002-12-13 20:15:29 +00003944 if (rmap)
3945 {
3946 if (bgp_static->rmap.name)
3947 free (bgp_static->rmap.name);
3948 bgp_static->rmap.name = strdup (rmap);
3949 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3950 }
3951 else
3952 {
3953 if (bgp_static->rmap.name)
3954 free (bgp_static->rmap.name);
3955 bgp_static->rmap.name = NULL;
3956 bgp_static->rmap.map = NULL;
3957 bgp_static->valid = 0;
3958 }
3959 bgp_unlock_node (rn);
3960 }
3961 else
3962 {
3963 /* New configuration. */
3964 bgp_static = bgp_static_new ();
3965 bgp_static->backdoor = backdoor;
3966 bgp_static->valid = 0;
3967 bgp_static->igpmetric = 0;
3968 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003969
paul718e3742002-12-13 20:15:29 +00003970 if (rmap)
3971 {
3972 if (bgp_static->rmap.name)
3973 free (bgp_static->rmap.name);
3974 bgp_static->rmap.name = strdup (rmap);
3975 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3976 }
3977 rn->info = bgp_static;
3978 }
3979
3980 /* If BGP scan is not enabled, we should install this route here. */
3981 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3982 {
3983 bgp_static->valid = 1;
3984
3985 if (need_update)
3986 bgp_static_withdraw (bgp, &p, afi, safi);
3987
3988 if (! bgp_static->backdoor)
3989 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3990 }
3991
3992 return CMD_SUCCESS;
3993}
3994
3995/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003996static int
paulfd79ac92004-10-13 05:06:08 +00003997bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003998 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003999{
4000 int ret;
4001 struct prefix p;
4002 struct bgp_static *bgp_static;
4003 struct bgp_node *rn;
4004
4005 /* Convert IP prefix string to struct prefix. */
4006 ret = str2prefix (ip_str, &p);
4007 if (! ret)
4008 {
4009 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4010 return CMD_WARNING;
4011 }
paul718e3742002-12-13 20:15:29 +00004012 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4013 {
4014 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4015 VTY_NEWLINE);
4016 return CMD_WARNING;
4017 }
paul718e3742002-12-13 20:15:29 +00004018
4019 apply_mask (&p);
4020
4021 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4022 if (! rn)
4023 {
4024 vty_out (vty, "%% Can't find specified static route configuration.%s",
4025 VTY_NEWLINE);
4026 return CMD_WARNING;
4027 }
4028
4029 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00004030
paul718e3742002-12-13 20:15:29 +00004031 /* Update BGP RIB. */
4032 if (! bgp_static->backdoor)
4033 bgp_static_withdraw (bgp, &p, afi, safi);
4034
4035 /* Clear configuration. */
4036 bgp_static_free (bgp_static);
4037 rn->info = NULL;
4038 bgp_unlock_node (rn);
4039 bgp_unlock_node (rn);
4040
4041 return CMD_SUCCESS;
4042}
4043
4044/* Called from bgp_delete(). Delete all static routes from the BGP
4045 instance. */
4046void
4047bgp_static_delete (struct bgp *bgp)
4048{
4049 afi_t afi;
4050 safi_t safi;
4051 struct bgp_node *rn;
4052 struct bgp_node *rm;
4053 struct bgp_table *table;
4054 struct bgp_static *bgp_static;
4055
4056 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4057 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4058 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4059 if (rn->info != NULL)
4060 {
Lou Berger298cc2f2016-01-12 13:42:02 -05004061 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004062 {
4063 table = rn->info;
4064
4065 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4066 {
4067 bgp_static = rn->info;
Lou Bergera76d9ca2016-01-12 13:41:53 -05004068 bgp_static_withdraw_safi (bgp, &rm->p,
4069 AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00004070 (struct prefix_rd *)&rn->p,
4071 bgp_static->tag);
4072 bgp_static_free (bgp_static);
4073 rn->info = NULL;
4074 bgp_unlock_node (rn);
4075 }
4076 }
4077 else
4078 {
4079 bgp_static = rn->info;
4080 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4081 bgp_static_free (bgp_static);
4082 rn->info = NULL;
4083 bgp_unlock_node (rn);
4084 }
4085 }
4086}
4087
Lou Bergera76d9ca2016-01-12 13:41:53 -05004088/*
4089 * gpz 110624
4090 * Currently this is used to set static routes for VPN and ENCAP.
4091 * I think it can probably be factored with bgp_static_set.
4092 */
paul718e3742002-12-13 20:15:29 +00004093int
Lou Bergera76d9ca2016-01-12 13:41:53 -05004094bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
4095 const char *rd_str, const char *tag_str,
4096 const char *rmap_str)
paul718e3742002-12-13 20:15:29 +00004097{
4098 int ret;
4099 struct prefix p;
4100 struct prefix_rd prd;
4101 struct bgp *bgp;
4102 struct bgp_node *prn;
4103 struct bgp_node *rn;
4104 struct bgp_table *table;
4105 struct bgp_static *bgp_static;
4106 u_char tag[3];
4107
4108 bgp = vty->index;
4109
4110 ret = str2prefix (ip_str, &p);
4111 if (! ret)
4112 {
4113 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4114 return CMD_WARNING;
4115 }
4116 apply_mask (&p);
4117
4118 ret = str2prefix_rd (rd_str, &prd);
4119 if (! ret)
4120 {
4121 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4122 return CMD_WARNING;
4123 }
4124
4125 ret = str2tag (tag_str, tag);
4126 if (! ret)
4127 {
4128 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4129 return CMD_WARNING;
4130 }
4131
Lou Bergera76d9ca2016-01-12 13:41:53 -05004132 prn = bgp_node_get (bgp->route[AFI_IP][safi],
paul718e3742002-12-13 20:15:29 +00004133 (struct prefix *)&prd);
4134 if (prn->info == NULL)
Lou Bergera76d9ca2016-01-12 13:41:53 -05004135 prn->info = bgp_table_init (AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004136 else
4137 bgp_unlock_node (prn);
4138 table = prn->info;
4139
4140 rn = bgp_node_get (table, &p);
4141
4142 if (rn->info)
4143 {
4144 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4145 bgp_unlock_node (rn);
4146 }
4147 else
4148 {
4149 /* New configuration. */
4150 bgp_static = bgp_static_new ();
Lou Bergera76d9ca2016-01-12 13:41:53 -05004151 bgp_static->backdoor = 0;
4152 bgp_static->valid = 0;
4153 bgp_static->igpmetric = 0;
4154 bgp_static->igpnexthop.s_addr = 0;
4155 memcpy(bgp_static->tag, tag, 3);
4156 bgp_static->prd = prd;
4157
4158 if (rmap_str)
4159 {
4160 if (bgp_static->rmap.name)
4161 free (bgp_static->rmap.name);
4162 bgp_static->rmap.name = strdup (rmap_str);
4163 bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
4164 }
paul718e3742002-12-13 20:15:29 +00004165 rn->info = bgp_static;
4166
Lou Bergera76d9ca2016-01-12 13:41:53 -05004167 bgp_static->valid = 1;
4168 bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004169 }
4170
4171 return CMD_SUCCESS;
4172}
4173
4174/* Configure static BGP network. */
4175int
Lou Bergera76d9ca2016-01-12 13:41:53 -05004176bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
4177 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00004178{
4179 int ret;
4180 struct bgp *bgp;
4181 struct prefix p;
4182 struct prefix_rd prd;
4183 struct bgp_node *prn;
4184 struct bgp_node *rn;
4185 struct bgp_table *table;
4186 struct bgp_static *bgp_static;
4187 u_char tag[3];
4188
4189 bgp = vty->index;
4190
4191 /* Convert IP prefix string to struct prefix. */
4192 ret = str2prefix (ip_str, &p);
4193 if (! ret)
4194 {
4195 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4196 return CMD_WARNING;
4197 }
4198 apply_mask (&p);
4199
4200 ret = str2prefix_rd (rd_str, &prd);
4201 if (! ret)
4202 {
4203 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4204 return CMD_WARNING;
4205 }
4206
4207 ret = str2tag (tag_str, tag);
4208 if (! ret)
4209 {
4210 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4211 return CMD_WARNING;
4212 }
4213
Lou Bergera76d9ca2016-01-12 13:41:53 -05004214 prn = bgp_node_get (bgp->route[AFI_IP][safi],
paul718e3742002-12-13 20:15:29 +00004215 (struct prefix *)&prd);
4216 if (prn->info == NULL)
Lou Bergera76d9ca2016-01-12 13:41:53 -05004217 prn->info = bgp_table_init (AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004218 else
4219 bgp_unlock_node (prn);
4220 table = prn->info;
4221
4222 rn = bgp_node_lookup (table, &p);
4223
4224 if (rn)
4225 {
Lou Bergera76d9ca2016-01-12 13:41:53 -05004226 bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
paul718e3742002-12-13 20:15:29 +00004227
4228 bgp_static = rn->info;
4229 bgp_static_free (bgp_static);
4230 rn->info = NULL;
4231 bgp_unlock_node (rn);
4232 bgp_unlock_node (rn);
4233 }
4234 else
4235 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4236
4237 return CMD_SUCCESS;
4238}
David Lamparter6b0655a2014-06-04 06:53:35 +02004239
paul718e3742002-12-13 20:15:29 +00004240DEFUN (bgp_network,
4241 bgp_network_cmd,
4242 "network A.B.C.D/M",
4243 "Specify a network to announce via BGP\n"
4244 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4245{
4246 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004247 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004248}
4249
4250DEFUN (bgp_network_route_map,
4251 bgp_network_route_map_cmd,
4252 "network A.B.C.D/M route-map WORD",
4253 "Specify a network to announce via BGP\n"
4254 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4255 "Route-map to modify the attributes\n"
4256 "Name of the route map\n")
4257{
4258 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004259 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004260}
4261
4262DEFUN (bgp_network_backdoor,
4263 bgp_network_backdoor_cmd,
4264 "network A.B.C.D/M backdoor",
4265 "Specify a network to announce via BGP\n"
4266 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4267 "Specify a BGP backdoor route\n")
4268{
Paul Jakma41367172007-08-06 15:24:51 +00004269 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004270 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004271}
4272
4273DEFUN (bgp_network_mask,
4274 bgp_network_mask_cmd,
4275 "network A.B.C.D mask A.B.C.D",
4276 "Specify a network to announce via BGP\n"
4277 "Network number\n"
4278 "Network mask\n"
4279 "Network mask\n")
4280{
4281 int ret;
4282 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004283
paul718e3742002-12-13 20:15:29 +00004284 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4285 if (! ret)
4286 {
4287 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4288 return CMD_WARNING;
4289 }
4290
4291 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004292 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004293}
4294
4295DEFUN (bgp_network_mask_route_map,
4296 bgp_network_mask_route_map_cmd,
4297 "network A.B.C.D mask A.B.C.D route-map WORD",
4298 "Specify a network to announce via BGP\n"
4299 "Network number\n"
4300 "Network mask\n"
4301 "Network mask\n"
4302 "Route-map to modify the attributes\n"
4303 "Name of the route map\n")
4304{
4305 int ret;
4306 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004307
paul718e3742002-12-13 20:15:29 +00004308 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4309 if (! ret)
4310 {
4311 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4312 return CMD_WARNING;
4313 }
4314
4315 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004316 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004317}
4318
4319DEFUN (bgp_network_mask_backdoor,
4320 bgp_network_mask_backdoor_cmd,
4321 "network A.B.C.D mask A.B.C.D backdoor",
4322 "Specify a network to announce via BGP\n"
4323 "Network number\n"
4324 "Network mask\n"
4325 "Network mask\n"
4326 "Specify a BGP backdoor route\n")
4327{
4328 int ret;
4329 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004330
paul718e3742002-12-13 20:15:29 +00004331 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4332 if (! ret)
4333 {
4334 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4335 return CMD_WARNING;
4336 }
4337
Paul Jakma41367172007-08-06 15:24:51 +00004338 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004339 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004340}
4341
4342DEFUN (bgp_network_mask_natural,
4343 bgp_network_mask_natural_cmd,
4344 "network A.B.C.D",
4345 "Specify a network to announce via BGP\n"
4346 "Network number\n")
4347{
4348 int ret;
4349 char prefix_str[BUFSIZ];
4350
4351 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4352 if (! ret)
4353 {
4354 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4355 return CMD_WARNING;
4356 }
4357
4358 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004359 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004360}
4361
4362DEFUN (bgp_network_mask_natural_route_map,
4363 bgp_network_mask_natural_route_map_cmd,
4364 "network A.B.C.D route-map WORD",
4365 "Specify a network to announce via BGP\n"
4366 "Network number\n"
4367 "Route-map to modify the attributes\n"
4368 "Name of the route map\n")
4369{
4370 int ret;
4371 char prefix_str[BUFSIZ];
4372
4373 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4374 if (! ret)
4375 {
4376 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4377 return CMD_WARNING;
4378 }
4379
4380 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004381 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004382}
4383
4384DEFUN (bgp_network_mask_natural_backdoor,
4385 bgp_network_mask_natural_backdoor_cmd,
4386 "network A.B.C.D backdoor",
4387 "Specify a network to announce via BGP\n"
4388 "Network number\n"
4389 "Specify a BGP backdoor route\n")
4390{
4391 int ret;
4392 char prefix_str[BUFSIZ];
4393
4394 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4395 if (! ret)
4396 {
4397 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4398 return CMD_WARNING;
4399 }
4400
Paul Jakma41367172007-08-06 15:24:51 +00004401 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004402 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004403}
4404
4405DEFUN (no_bgp_network,
4406 no_bgp_network_cmd,
4407 "no network A.B.C.D/M",
4408 NO_STR
4409 "Specify a network to announce via BGP\n"
4410 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4411{
4412 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4413 bgp_node_safi (vty));
4414}
4415
4416ALIAS (no_bgp_network,
4417 no_bgp_network_route_map_cmd,
4418 "no network A.B.C.D/M route-map WORD",
4419 NO_STR
4420 "Specify a network to announce via BGP\n"
4421 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4422 "Route-map to modify the attributes\n"
4423 "Name of the route map\n")
4424
4425ALIAS (no_bgp_network,
4426 no_bgp_network_backdoor_cmd,
4427 "no network A.B.C.D/M backdoor",
4428 NO_STR
4429 "Specify a network to announce via BGP\n"
4430 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4431 "Specify a BGP backdoor route\n")
4432
4433DEFUN (no_bgp_network_mask,
4434 no_bgp_network_mask_cmd,
4435 "no network A.B.C.D mask A.B.C.D",
4436 NO_STR
4437 "Specify a network to announce via BGP\n"
4438 "Network number\n"
4439 "Network mask\n"
4440 "Network mask\n")
4441{
4442 int ret;
4443 char prefix_str[BUFSIZ];
4444
4445 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4446 if (! ret)
4447 {
4448 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4449 return CMD_WARNING;
4450 }
4451
4452 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4453 bgp_node_safi (vty));
4454}
4455
4456ALIAS (no_bgp_network_mask,
4457 no_bgp_network_mask_route_map_cmd,
4458 "no network A.B.C.D mask A.B.C.D route-map WORD",
4459 NO_STR
4460 "Specify a network to announce via BGP\n"
4461 "Network number\n"
4462 "Network mask\n"
4463 "Network mask\n"
4464 "Route-map to modify the attributes\n"
4465 "Name of the route map\n")
4466
4467ALIAS (no_bgp_network_mask,
4468 no_bgp_network_mask_backdoor_cmd,
4469 "no network A.B.C.D mask A.B.C.D backdoor",
4470 NO_STR
4471 "Specify a network to announce via BGP\n"
4472 "Network number\n"
4473 "Network mask\n"
4474 "Network mask\n"
4475 "Specify a BGP backdoor route\n")
4476
4477DEFUN (no_bgp_network_mask_natural,
4478 no_bgp_network_mask_natural_cmd,
4479 "no network A.B.C.D",
4480 NO_STR
4481 "Specify a network to announce via BGP\n"
4482 "Network number\n")
4483{
4484 int ret;
4485 char prefix_str[BUFSIZ];
4486
4487 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4488 if (! ret)
4489 {
4490 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4491 return CMD_WARNING;
4492 }
4493
4494 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4495 bgp_node_safi (vty));
4496}
4497
4498ALIAS (no_bgp_network_mask_natural,
4499 no_bgp_network_mask_natural_route_map_cmd,
4500 "no network A.B.C.D route-map WORD",
4501 NO_STR
4502 "Specify a network to announce via BGP\n"
4503 "Network number\n"
4504 "Route-map to modify the attributes\n"
4505 "Name of the route map\n")
4506
4507ALIAS (no_bgp_network_mask_natural,
4508 no_bgp_network_mask_natural_backdoor_cmd,
4509 "no network A.B.C.D backdoor",
4510 NO_STR
4511 "Specify a network to announce via BGP\n"
4512 "Network number\n"
4513 "Specify a BGP backdoor route\n")
4514
paul718e3742002-12-13 20:15:29 +00004515DEFUN (ipv6_bgp_network,
4516 ipv6_bgp_network_cmd,
4517 "network X:X::X:X/M",
4518 "Specify a network to announce via BGP\n"
4519 "IPv6 prefix <network>/<length>\n")
4520{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304521 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004522 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004523}
4524
4525DEFUN (ipv6_bgp_network_route_map,
4526 ipv6_bgp_network_route_map_cmd,
4527 "network X:X::X:X/M route-map WORD",
4528 "Specify a network to announce via BGP\n"
4529 "IPv6 prefix <network>/<length>\n"
4530 "Route-map to modify the attributes\n"
4531 "Name of the route map\n")
4532{
4533 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004534 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004535}
4536
4537DEFUN (no_ipv6_bgp_network,
4538 no_ipv6_bgp_network_cmd,
4539 "no network X:X::X:X/M",
4540 NO_STR
4541 "Specify a network to announce via BGP\n"
4542 "IPv6 prefix <network>/<length>\n")
4543{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304544 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004545}
4546
4547ALIAS (no_ipv6_bgp_network,
4548 no_ipv6_bgp_network_route_map_cmd,
4549 "no network X:X::X:X/M route-map WORD",
4550 NO_STR
4551 "Specify a network to announce via BGP\n"
4552 "IPv6 prefix <network>/<length>\n"
4553 "Route-map to modify the attributes\n"
4554 "Name of the route map\n")
4555
4556ALIAS (ipv6_bgp_network,
4557 old_ipv6_bgp_network_cmd,
4558 "ipv6 bgp network X:X::X:X/M",
4559 IPV6_STR
4560 BGP_STR
4561 "Specify a network to announce via BGP\n"
4562 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4563
4564ALIAS (no_ipv6_bgp_network,
4565 old_no_ipv6_bgp_network_cmd,
4566 "no ipv6 bgp network X:X::X:X/M",
4567 NO_STR
4568 IPV6_STR
4569 BGP_STR
4570 "Specify a network to announce via BGP\n"
4571 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004572
4573/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4574ALIAS_DEPRECATED (bgp_network,
4575 bgp_network_ttl_cmd,
4576 "network A.B.C.D/M pathlimit <0-255>",
4577 "Specify a network to announce via BGP\n"
4578 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4579 "AS-Path hopcount limit attribute\n"
4580 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4581ALIAS_DEPRECATED (bgp_network_backdoor,
4582 bgp_network_backdoor_ttl_cmd,
4583 "network A.B.C.D/M backdoor pathlimit <0-255>",
4584 "Specify a network to announce via BGP\n"
4585 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4586 "Specify a BGP backdoor route\n"
4587 "AS-Path hopcount limit attribute\n"
4588 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4589ALIAS_DEPRECATED (bgp_network_mask,
4590 bgp_network_mask_ttl_cmd,
4591 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4592 "Specify a network to announce via BGP\n"
4593 "Network number\n"
4594 "Network mask\n"
4595 "Network mask\n"
4596 "AS-Path hopcount limit attribute\n"
4597 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4598ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4599 bgp_network_mask_backdoor_ttl_cmd,
4600 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4601 "Specify a network to announce via BGP\n"
4602 "Network number\n"
4603 "Network mask\n"
4604 "Network mask\n"
4605 "Specify a BGP backdoor route\n"
4606 "AS-Path hopcount limit attribute\n"
4607 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4608ALIAS_DEPRECATED (bgp_network_mask_natural,
4609 bgp_network_mask_natural_ttl_cmd,
4610 "network A.B.C.D pathlimit <0-255>",
4611 "Specify a network to announce via BGP\n"
4612 "Network number\n"
4613 "AS-Path hopcount limit attribute\n"
4614 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4615ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4616 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004617 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004618 "Specify a network to announce via BGP\n"
4619 "Network number\n"
4620 "Specify a BGP backdoor route\n"
4621 "AS-Path hopcount limit attribute\n"
4622 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4623ALIAS_DEPRECATED (no_bgp_network,
4624 no_bgp_network_ttl_cmd,
4625 "no network A.B.C.D/M pathlimit <0-255>",
4626 NO_STR
4627 "Specify a network to announce via BGP\n"
4628 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4629 "AS-Path hopcount limit attribute\n"
4630 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4631ALIAS_DEPRECATED (no_bgp_network,
4632 no_bgp_network_backdoor_ttl_cmd,
4633 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4634 NO_STR
4635 "Specify a network to announce via BGP\n"
4636 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4637 "Specify a BGP backdoor route\n"
4638 "AS-Path hopcount limit attribute\n"
4639 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4640ALIAS_DEPRECATED (no_bgp_network,
4641 no_bgp_network_mask_ttl_cmd,
4642 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4643 NO_STR
4644 "Specify a network to announce via BGP\n"
4645 "Network number\n"
4646 "Network mask\n"
4647 "Network mask\n"
4648 "AS-Path hopcount limit attribute\n"
4649 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4650ALIAS_DEPRECATED (no_bgp_network_mask,
4651 no_bgp_network_mask_backdoor_ttl_cmd,
4652 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4653 NO_STR
4654 "Specify a network to announce via BGP\n"
4655 "Network number\n"
4656 "Network mask\n"
4657 "Network mask\n"
4658 "Specify a BGP backdoor route\n"
4659 "AS-Path hopcount limit attribute\n"
4660 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4661ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4662 no_bgp_network_mask_natural_ttl_cmd,
4663 "no network A.B.C.D pathlimit <0-255>",
4664 NO_STR
4665 "Specify a network to announce via BGP\n"
4666 "Network number\n"
4667 "AS-Path hopcount limit attribute\n"
4668 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4669ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4670 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4671 "no network A.B.C.D backdoor pathlimit <0-255>",
4672 NO_STR
4673 "Specify a network to announce via BGP\n"
4674 "Network number\n"
4675 "Specify a BGP backdoor route\n"
4676 "AS-Path hopcount limit attribute\n"
4677 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4678ALIAS_DEPRECATED (ipv6_bgp_network,
4679 ipv6_bgp_network_ttl_cmd,
4680 "network X:X::X:X/M pathlimit <0-255>",
4681 "Specify a network to announce via BGP\n"
4682 "IPv6 prefix <network>/<length>\n"
4683 "AS-Path hopcount limit attribute\n"
4684 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4685ALIAS_DEPRECATED (no_ipv6_bgp_network,
4686 no_ipv6_bgp_network_ttl_cmd,
4687 "no network X:X::X:X/M pathlimit <0-255>",
4688 NO_STR
4689 "Specify a network to announce via BGP\n"
4690 "IPv6 prefix <network>/<length>\n"
4691 "AS-Path hopcount limit attribute\n"
4692 "AS-Pathlimit TTL, in number of AS-Path hops\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02004693
paul718e3742002-12-13 20:15:29 +00004694/* Aggreagete address:
4695
4696 advertise-map Set condition to advertise attribute
4697 as-set Generate AS set path information
4698 attribute-map Set attributes of aggregate
4699 route-map Set parameters of aggregate
4700 summary-only Filter more specific routes from updates
4701 suppress-map Conditionally filter more specific routes from updates
4702 <cr>
4703 */
4704struct bgp_aggregate
4705{
4706 /* Summary-only flag. */
4707 u_char summary_only;
4708
4709 /* AS set generation. */
4710 u_char as_set;
4711
4712 /* Route-map for aggregated route. */
4713 struct route_map *map;
4714
4715 /* Suppress-count. */
4716 unsigned long count;
4717
4718 /* SAFI configuration. */
4719 safi_t safi;
4720};
4721
paul94f2b392005-06-28 12:44:16 +00004722static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004723bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004724{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004725 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004726}
4727
paul94f2b392005-06-28 12:44:16 +00004728static void
paul718e3742002-12-13 20:15:29 +00004729bgp_aggregate_free (struct bgp_aggregate *aggregate)
4730{
4731 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4732}
4733
Daniel Walton76a72802015-05-19 17:47:24 -07004734/* Update an aggregate as routes are added/removed from the BGP table */
paul94f2b392005-06-28 12:44:16 +00004735static void
paul718e3742002-12-13 20:15:29 +00004736bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4737 afi_t afi, safi_t safi, struct bgp_info *del,
4738 struct bgp_aggregate *aggregate)
4739{
4740 struct bgp_table *table;
4741 struct bgp_node *top;
4742 struct bgp_node *rn;
4743 u_char origin;
4744 struct aspath *aspath = NULL;
4745 struct aspath *asmerge = NULL;
4746 struct community *community = NULL;
4747 struct community *commerge = NULL;
paul718e3742002-12-13 20:15:29 +00004748 struct bgp_info *ri;
4749 struct bgp_info *new;
4750 int first = 1;
4751 unsigned long match = 0;
4752
paul718e3742002-12-13 20:15:29 +00004753 /* ORIGIN attribute: If at least one route among routes that are
4754 aggregated has ORIGIN with the value INCOMPLETE, then the
4755 aggregated route must have the ORIGIN attribute with the value
4756 INCOMPLETE. Otherwise, if at least one route among routes that
4757 are aggregated has ORIGIN with the value EGP, then the aggregated
4758 route must have the origin attribute with the value EGP. In all
4759 other case the value of the ORIGIN attribute of the aggregated
4760 route is INTERNAL. */
4761 origin = BGP_ORIGIN_IGP;
4762
4763 table = bgp->rib[afi][safi];
4764
4765 top = bgp_node_get (table, p);
4766 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4767 if (rn->p.prefixlen > p->prefixlen)
4768 {
4769 match = 0;
4770
4771 for (ri = rn->info; ri; ri = ri->next)
4772 {
4773 if (BGP_INFO_HOLDDOWN (ri))
4774 continue;
4775
4776 if (del && ri == del)
4777 continue;
4778
4779 if (! rinew && first)
Paul Jakma7aa9dce2014-09-19 14:42:23 +01004780 first = 0;
paul718e3742002-12-13 20:15:29 +00004781
4782#ifdef AGGREGATE_NEXTHOP_CHECK
4783 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4784 || ri->attr->med != med)
4785 {
4786 if (aspath)
4787 aspath_free (aspath);
4788 if (community)
4789 community_free (community);
4790 bgp_unlock_node (rn);
4791 bgp_unlock_node (top);
4792 return;
4793 }
4794#endif /* AGGREGATE_NEXTHOP_CHECK */
4795
4796 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4797 {
4798 if (aggregate->summary_only)
4799 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004800 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004801 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004802 match++;
4803 }
4804
4805 aggregate->count++;
4806
Daniel Walton76a72802015-05-19 17:47:24 -07004807 if (origin < ri->attr->origin)
4808 origin = ri->attr->origin;
4809
paul718e3742002-12-13 20:15:29 +00004810 if (aggregate->as_set)
4811 {
paul718e3742002-12-13 20:15:29 +00004812 if (aspath)
4813 {
4814 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4815 aspath_free (aspath);
4816 aspath = asmerge;
4817 }
4818 else
4819 aspath = aspath_dup (ri->attr->aspath);
4820
4821 if (ri->attr->community)
4822 {
4823 if (community)
4824 {
4825 commerge = community_merge (community,
4826 ri->attr->community);
4827 community = community_uniq_sort (commerge);
4828 community_free (commerge);
4829 }
4830 else
4831 community = community_dup (ri->attr->community);
4832 }
4833 }
4834 }
4835 }
4836 if (match)
4837 bgp_process (bgp, rn, afi, safi);
4838 }
4839 bgp_unlock_node (top);
4840
4841 if (rinew)
4842 {
4843 aggregate->count++;
4844
4845 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004846 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004847
Daniel Walton76a72802015-05-19 17:47:24 -07004848 if (origin < rinew->attr->origin)
4849 origin = rinew->attr->origin;
4850
paul718e3742002-12-13 20:15:29 +00004851 if (aggregate->as_set)
4852 {
paul718e3742002-12-13 20:15:29 +00004853 if (aspath)
4854 {
4855 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4856 aspath_free (aspath);
4857 aspath = asmerge;
4858 }
4859 else
4860 aspath = aspath_dup (rinew->attr->aspath);
4861
4862 if (rinew->attr->community)
4863 {
4864 if (community)
4865 {
4866 commerge = community_merge (community,
4867 rinew->attr->community);
4868 community = community_uniq_sort (commerge);
4869 community_free (commerge);
4870 }
4871 else
4872 community = community_dup (rinew->attr->community);
4873 }
4874 }
4875 }
4876
4877 if (aggregate->count > 0)
4878 {
4879 rn = bgp_node_get (table, p);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05004880 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, bgp->peer_self,
4881 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
4882 aggregate->as_set), rn);
paul718e3742002-12-13 20:15:29 +00004883 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00004884
4885 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004886 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004887 bgp_process (bgp, rn, afi, safi);
4888 }
4889 else
4890 {
4891 if (aspath)
4892 aspath_free (aspath);
4893 if (community)
4894 community_free (community);
4895 }
4896}
4897
4898void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4899 struct bgp_aggregate *);
4900
4901void
4902bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4903 struct bgp_info *ri, afi_t afi, safi_t safi)
4904{
4905 struct bgp_node *child;
4906 struct bgp_node *rn;
4907 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004908 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004909
4910 /* MPLS-VPN aggregation is not yet supported. */
Lou Berger298cc2f2016-01-12 13:42:02 -05004911 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004912 return;
4913
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004914 table = bgp->aggregate[afi][safi];
4915
4916 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004917 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004918 return;
4919
paul718e3742002-12-13 20:15:29 +00004920 if (p->prefixlen == 0)
4921 return;
4922
4923 if (BGP_INFO_HOLDDOWN (ri))
4924 return;
4925
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004926 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004927
4928 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004929 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004930 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4931 {
4932 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004933 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004934 }
4935 bgp_unlock_node (child);
4936}
4937
4938void
4939bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4940 struct bgp_info *del, afi_t afi, safi_t safi)
4941{
4942 struct bgp_node *child;
4943 struct bgp_node *rn;
4944 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004945 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004946
4947 /* MPLS-VPN aggregation is not yet supported. */
Lou Berger298cc2f2016-01-12 13:42:02 -05004948 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004949 return;
4950
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004951 table = bgp->aggregate[afi][safi];
4952
4953 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004954 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004955 return;
4956
paul718e3742002-12-13 20:15:29 +00004957 if (p->prefixlen == 0)
4958 return;
4959
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004960 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004961
4962 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004963 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004964 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4965 {
4966 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004967 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004968 }
4969 bgp_unlock_node (child);
4970}
4971
Daniel Walton76a72802015-05-19 17:47:24 -07004972/* Called via bgp_aggregate_set when the user configures aggregate-address */
paul94f2b392005-06-28 12:44:16 +00004973static void
paul718e3742002-12-13 20:15:29 +00004974bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4975 struct bgp_aggregate *aggregate)
4976{
4977 struct bgp_table *table;
4978 struct bgp_node *top;
4979 struct bgp_node *rn;
4980 struct bgp_info *new;
4981 struct bgp_info *ri;
4982 unsigned long match;
4983 u_char origin = BGP_ORIGIN_IGP;
4984 struct aspath *aspath = NULL;
4985 struct aspath *asmerge = NULL;
4986 struct community *community = NULL;
4987 struct community *commerge = NULL;
4988
4989 table = bgp->rib[afi][safi];
4990
4991 /* Sanity check. */
4992 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4993 return;
4994 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4995 return;
4996
4997 /* If routes exists below this node, generate aggregate routes. */
4998 top = bgp_node_get (table, p);
4999 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5000 if (rn->p.prefixlen > p->prefixlen)
5001 {
5002 match = 0;
5003
5004 for (ri = rn->info; ri; ri = ri->next)
5005 {
5006 if (BGP_INFO_HOLDDOWN (ri))
5007 continue;
5008
5009 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5010 {
5011 /* summary-only aggregate route suppress aggregated
5012 route announcement. */
5013 if (aggregate->summary_only)
5014 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005015 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00005016 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005017 match++;
5018 }
Daniel Walton76a72802015-05-19 17:47:24 -07005019
5020 /* If at least one route among routes that are aggregated has
5021 * ORIGIN with the value INCOMPLETE, then the aggregated route
5022 * MUST have the ORIGIN attribute with the value INCOMPLETE.
5023 * Otherwise, if at least one route among routes that are
5024 * aggregated has ORIGIN with the value EGP, then the aggregated
5025 * route MUST have the ORIGIN attribute with the value EGP.
5026 */
5027 if (origin < ri->attr->origin)
5028 origin = ri->attr->origin;
5029
paul718e3742002-12-13 20:15:29 +00005030 /* as-set aggregate route generate origin, as path,
5031 community aggregation. */
5032 if (aggregate->as_set)
5033 {
paul718e3742002-12-13 20:15:29 +00005034 if (aspath)
5035 {
5036 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5037 aspath_free (aspath);
5038 aspath = asmerge;
5039 }
5040 else
5041 aspath = aspath_dup (ri->attr->aspath);
5042
5043 if (ri->attr->community)
5044 {
5045 if (community)
5046 {
5047 commerge = community_merge (community,
5048 ri->attr->community);
5049 community = community_uniq_sort (commerge);
5050 community_free (commerge);
5051 }
5052 else
5053 community = community_dup (ri->attr->community);
5054 }
5055 }
5056 aggregate->count++;
5057 }
5058 }
5059
5060 /* If this node is suppressed, process the change. */
5061 if (match)
5062 bgp_process (bgp, rn, afi, safi);
5063 }
5064 bgp_unlock_node (top);
5065
5066 /* Add aggregate route to BGP table. */
5067 if (aggregate->count)
5068 {
5069 rn = bgp_node_get (table, p);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05005070 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, bgp->peer_self,
5071 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
5072 aggregate->as_set), rn);
paul718e3742002-12-13 20:15:29 +00005073 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00005074
5075 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00005076 bgp_unlock_node (rn);
5077
paul718e3742002-12-13 20:15:29 +00005078 /* Process change. */
5079 bgp_process (bgp, rn, afi, safi);
5080 }
Denil Virae2a92582015-08-11 13:34:59 -07005081 else
5082 {
5083 if (aspath)
5084 aspath_free (aspath);
5085 if (community)
5086 community_free (community);
5087 }
paul718e3742002-12-13 20:15:29 +00005088}
5089
5090void
5091bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5092 safi_t safi, struct bgp_aggregate *aggregate)
5093{
5094 struct bgp_table *table;
5095 struct bgp_node *top;
5096 struct bgp_node *rn;
5097 struct bgp_info *ri;
5098 unsigned long match;
5099
5100 table = bgp->rib[afi][safi];
5101
5102 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5103 return;
5104 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5105 return;
5106
5107 /* If routes exists below this node, generate aggregate routes. */
5108 top = bgp_node_get (table, p);
5109 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5110 if (rn->p.prefixlen > p->prefixlen)
5111 {
5112 match = 0;
5113
5114 for (ri = rn->info; ri; ri = ri->next)
5115 {
5116 if (BGP_INFO_HOLDDOWN (ri))
5117 continue;
5118
5119 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5120 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005121 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00005122 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005123 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00005124
Paul Jakmafb982c22007-05-04 20:15:47 +00005125 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00005126 {
Paul Jakma1a392d42006-09-07 00:24:49 +00005127 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005128 match++;
5129 }
5130 }
5131 aggregate->count--;
5132 }
5133 }
5134
Paul Jakmafb982c22007-05-04 20:15:47 +00005135 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00005136 if (match)
5137 bgp_process (bgp, rn, afi, safi);
5138 }
5139 bgp_unlock_node (top);
5140
5141 /* Delete aggregate route from BGP table. */
5142 rn = bgp_node_get (table, p);
5143
5144 for (ri = rn->info; ri; ri = ri->next)
5145 if (ri->peer == bgp->peer_self
5146 && ri->type == ZEBRA_ROUTE_BGP
5147 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5148 break;
5149
5150 /* Withdraw static BGP route from routing table. */
5151 if (ri)
5152 {
paul718e3742002-12-13 20:15:29 +00005153 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005154 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00005155 }
5156
5157 /* Unlock bgp_node_lookup. */
5158 bgp_unlock_node (rn);
5159}
5160
5161/* Aggregate route attribute. */
5162#define AGGREGATE_SUMMARY_ONLY 1
5163#define AGGREGATE_AS_SET 1
5164
paul94f2b392005-06-28 12:44:16 +00005165static int
Robert Baysf6269b42010-08-05 10:26:28 -07005166bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5167 afi_t afi, safi_t safi)
5168{
5169 int ret;
5170 struct prefix p;
5171 struct bgp_node *rn;
5172 struct bgp *bgp;
5173 struct bgp_aggregate *aggregate;
5174
5175 /* Convert string to prefix structure. */
5176 ret = str2prefix (prefix_str, &p);
5177 if (!ret)
5178 {
5179 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5180 return CMD_WARNING;
5181 }
5182 apply_mask (&p);
5183
5184 /* Get BGP structure. */
5185 bgp = vty->index;
5186
5187 /* Old configuration check. */
5188 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5189 if (! rn)
5190 {
5191 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5192 VTY_NEWLINE);
5193 return CMD_WARNING;
5194 }
5195
5196 aggregate = rn->info;
5197 if (aggregate->safi & SAFI_UNICAST)
5198 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5199 if (aggregate->safi & SAFI_MULTICAST)
5200 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5201
5202 /* Unlock aggregate address configuration. */
5203 rn->info = NULL;
5204 bgp_aggregate_free (aggregate);
5205 bgp_unlock_node (rn);
5206 bgp_unlock_node (rn);
5207
5208 return CMD_SUCCESS;
5209}
5210
5211static int
5212bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00005213 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00005214 u_char summary_only, u_char as_set)
5215{
5216 int ret;
5217 struct prefix p;
5218 struct bgp_node *rn;
5219 struct bgp *bgp;
5220 struct bgp_aggregate *aggregate;
5221
5222 /* Convert string to prefix structure. */
5223 ret = str2prefix (prefix_str, &p);
5224 if (!ret)
5225 {
5226 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5227 return CMD_WARNING;
5228 }
5229 apply_mask (&p);
5230
5231 /* Get BGP structure. */
5232 bgp = vty->index;
5233
5234 /* Old configuration check. */
5235 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5236
5237 if (rn->info)
5238 {
5239 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005240 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005241 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5242 if (ret)
5243 {
Robert Bays368473f2010-08-05 10:26:29 -07005244 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5245 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005246 return CMD_WARNING;
5247 }
paul718e3742002-12-13 20:15:29 +00005248 }
5249
5250 /* Make aggregate address structure. */
5251 aggregate = bgp_aggregate_new ();
5252 aggregate->summary_only = summary_only;
5253 aggregate->as_set = as_set;
5254 aggregate->safi = safi;
5255 rn->info = aggregate;
5256
5257 /* Aggregate address insert into BGP routing table. */
5258 if (safi & SAFI_UNICAST)
5259 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5260 if (safi & SAFI_MULTICAST)
5261 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5262
5263 return CMD_SUCCESS;
5264}
5265
paul718e3742002-12-13 20:15:29 +00005266DEFUN (aggregate_address,
5267 aggregate_address_cmd,
5268 "aggregate-address A.B.C.D/M",
5269 "Configure BGP aggregate entries\n"
5270 "Aggregate prefix\n")
5271{
5272 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5273}
5274
5275DEFUN (aggregate_address_mask,
5276 aggregate_address_mask_cmd,
5277 "aggregate-address A.B.C.D A.B.C.D",
5278 "Configure BGP aggregate entries\n"
5279 "Aggregate address\n"
5280 "Aggregate mask\n")
5281{
5282 int ret;
5283 char prefix_str[BUFSIZ];
5284
5285 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5286
5287 if (! ret)
5288 {
5289 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5290 return CMD_WARNING;
5291 }
5292
5293 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5294 0, 0);
5295}
5296
5297DEFUN (aggregate_address_summary_only,
5298 aggregate_address_summary_only_cmd,
5299 "aggregate-address A.B.C.D/M summary-only",
5300 "Configure BGP aggregate entries\n"
5301 "Aggregate prefix\n"
5302 "Filter more specific routes from updates\n")
5303{
5304 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5305 AGGREGATE_SUMMARY_ONLY, 0);
5306}
5307
5308DEFUN (aggregate_address_mask_summary_only,
5309 aggregate_address_mask_summary_only_cmd,
5310 "aggregate-address A.B.C.D A.B.C.D summary-only",
5311 "Configure BGP aggregate entries\n"
5312 "Aggregate address\n"
5313 "Aggregate mask\n"
5314 "Filter more specific routes from updates\n")
5315{
5316 int ret;
5317 char prefix_str[BUFSIZ];
5318
5319 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5320
5321 if (! ret)
5322 {
5323 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5324 return CMD_WARNING;
5325 }
5326
5327 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5328 AGGREGATE_SUMMARY_ONLY, 0);
5329}
5330
5331DEFUN (aggregate_address_as_set,
5332 aggregate_address_as_set_cmd,
5333 "aggregate-address A.B.C.D/M as-set",
5334 "Configure BGP aggregate entries\n"
5335 "Aggregate prefix\n"
5336 "Generate AS set path information\n")
5337{
5338 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5339 0, AGGREGATE_AS_SET);
5340}
5341
5342DEFUN (aggregate_address_mask_as_set,
5343 aggregate_address_mask_as_set_cmd,
5344 "aggregate-address A.B.C.D A.B.C.D as-set",
5345 "Configure BGP aggregate entries\n"
5346 "Aggregate address\n"
5347 "Aggregate mask\n"
5348 "Generate AS set path information\n")
5349{
5350 int ret;
5351 char prefix_str[BUFSIZ];
5352
5353 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5354
5355 if (! ret)
5356 {
5357 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5358 return CMD_WARNING;
5359 }
5360
5361 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5362 0, AGGREGATE_AS_SET);
5363}
5364
5365
5366DEFUN (aggregate_address_as_set_summary,
5367 aggregate_address_as_set_summary_cmd,
5368 "aggregate-address A.B.C.D/M as-set summary-only",
5369 "Configure BGP aggregate entries\n"
5370 "Aggregate prefix\n"
5371 "Generate AS set path information\n"
5372 "Filter more specific routes from updates\n")
5373{
5374 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5375 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5376}
5377
5378ALIAS (aggregate_address_as_set_summary,
5379 aggregate_address_summary_as_set_cmd,
5380 "aggregate-address A.B.C.D/M summary-only as-set",
5381 "Configure BGP aggregate entries\n"
5382 "Aggregate prefix\n"
5383 "Filter more specific routes from updates\n"
5384 "Generate AS set path information\n")
5385
5386DEFUN (aggregate_address_mask_as_set_summary,
5387 aggregate_address_mask_as_set_summary_cmd,
5388 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5389 "Configure BGP aggregate entries\n"
5390 "Aggregate address\n"
5391 "Aggregate mask\n"
5392 "Generate AS set path information\n"
5393 "Filter more specific routes from updates\n")
5394{
5395 int ret;
5396 char prefix_str[BUFSIZ];
5397
5398 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5399
5400 if (! ret)
5401 {
5402 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5403 return CMD_WARNING;
5404 }
5405
5406 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5407 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5408}
5409
5410ALIAS (aggregate_address_mask_as_set_summary,
5411 aggregate_address_mask_summary_as_set_cmd,
5412 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5413 "Configure BGP aggregate entries\n"
5414 "Aggregate address\n"
5415 "Aggregate mask\n"
5416 "Filter more specific routes from updates\n"
5417 "Generate AS set path information\n")
5418
5419DEFUN (no_aggregate_address,
5420 no_aggregate_address_cmd,
5421 "no aggregate-address A.B.C.D/M",
5422 NO_STR
5423 "Configure BGP aggregate entries\n"
5424 "Aggregate prefix\n")
5425{
5426 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5427}
5428
5429ALIAS (no_aggregate_address,
5430 no_aggregate_address_summary_only_cmd,
5431 "no aggregate-address A.B.C.D/M summary-only",
5432 NO_STR
5433 "Configure BGP aggregate entries\n"
5434 "Aggregate prefix\n"
5435 "Filter more specific routes from updates\n")
5436
5437ALIAS (no_aggregate_address,
5438 no_aggregate_address_as_set_cmd,
5439 "no aggregate-address A.B.C.D/M as-set",
5440 NO_STR
5441 "Configure BGP aggregate entries\n"
5442 "Aggregate prefix\n"
5443 "Generate AS set path information\n")
5444
5445ALIAS (no_aggregate_address,
5446 no_aggregate_address_as_set_summary_cmd,
5447 "no aggregate-address A.B.C.D/M as-set summary-only",
5448 NO_STR
5449 "Configure BGP aggregate entries\n"
5450 "Aggregate prefix\n"
5451 "Generate AS set path information\n"
5452 "Filter more specific routes from updates\n")
5453
5454ALIAS (no_aggregate_address,
5455 no_aggregate_address_summary_as_set_cmd,
5456 "no aggregate-address A.B.C.D/M summary-only as-set",
5457 NO_STR
5458 "Configure BGP aggregate entries\n"
5459 "Aggregate prefix\n"
5460 "Filter more specific routes from updates\n"
5461 "Generate AS set path information\n")
5462
5463DEFUN (no_aggregate_address_mask,
5464 no_aggregate_address_mask_cmd,
5465 "no aggregate-address A.B.C.D A.B.C.D",
5466 NO_STR
5467 "Configure BGP aggregate entries\n"
5468 "Aggregate address\n"
5469 "Aggregate mask\n")
5470{
5471 int ret;
5472 char prefix_str[BUFSIZ];
5473
5474 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5475
5476 if (! ret)
5477 {
5478 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5479 return CMD_WARNING;
5480 }
5481
5482 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5483}
5484
5485ALIAS (no_aggregate_address_mask,
5486 no_aggregate_address_mask_summary_only_cmd,
5487 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5488 NO_STR
5489 "Configure BGP aggregate entries\n"
5490 "Aggregate address\n"
5491 "Aggregate mask\n"
5492 "Filter more specific routes from updates\n")
5493
5494ALIAS (no_aggregate_address_mask,
5495 no_aggregate_address_mask_as_set_cmd,
5496 "no aggregate-address A.B.C.D A.B.C.D as-set",
5497 NO_STR
5498 "Configure BGP aggregate entries\n"
5499 "Aggregate address\n"
5500 "Aggregate mask\n"
5501 "Generate AS set path information\n")
5502
5503ALIAS (no_aggregate_address_mask,
5504 no_aggregate_address_mask_as_set_summary_cmd,
5505 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5506 NO_STR
5507 "Configure BGP aggregate entries\n"
5508 "Aggregate address\n"
5509 "Aggregate mask\n"
5510 "Generate AS set path information\n"
5511 "Filter more specific routes from updates\n")
5512
5513ALIAS (no_aggregate_address_mask,
5514 no_aggregate_address_mask_summary_as_set_cmd,
5515 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5516 NO_STR
5517 "Configure BGP aggregate entries\n"
5518 "Aggregate address\n"
5519 "Aggregate mask\n"
5520 "Filter more specific routes from updates\n"
5521 "Generate AS set path information\n")
5522
paul718e3742002-12-13 20:15:29 +00005523DEFUN (ipv6_aggregate_address,
5524 ipv6_aggregate_address_cmd,
5525 "aggregate-address X:X::X:X/M",
5526 "Configure BGP aggregate entries\n"
5527 "Aggregate prefix\n")
5528{
5529 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5530}
5531
5532DEFUN (ipv6_aggregate_address_summary_only,
5533 ipv6_aggregate_address_summary_only_cmd,
5534 "aggregate-address X:X::X:X/M summary-only",
5535 "Configure BGP aggregate entries\n"
5536 "Aggregate prefix\n"
5537 "Filter more specific routes from updates\n")
5538{
5539 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5540 AGGREGATE_SUMMARY_ONLY, 0);
5541}
5542
5543DEFUN (no_ipv6_aggregate_address,
5544 no_ipv6_aggregate_address_cmd,
5545 "no aggregate-address X:X::X:X/M",
5546 NO_STR
5547 "Configure BGP aggregate entries\n"
5548 "Aggregate prefix\n")
5549{
5550 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5551}
5552
5553DEFUN (no_ipv6_aggregate_address_summary_only,
5554 no_ipv6_aggregate_address_summary_only_cmd,
5555 "no aggregate-address X:X::X:X/M summary-only",
5556 NO_STR
5557 "Configure BGP aggregate entries\n"
5558 "Aggregate prefix\n"
5559 "Filter more specific routes from updates\n")
5560{
5561 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5562}
5563
5564ALIAS (ipv6_aggregate_address,
5565 old_ipv6_aggregate_address_cmd,
5566 "ipv6 bgp aggregate-address X:X::X:X/M",
5567 IPV6_STR
5568 BGP_STR
5569 "Configure BGP aggregate entries\n"
5570 "Aggregate prefix\n")
5571
5572ALIAS (ipv6_aggregate_address_summary_only,
5573 old_ipv6_aggregate_address_summary_only_cmd,
5574 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5575 IPV6_STR
5576 BGP_STR
5577 "Configure BGP aggregate entries\n"
5578 "Aggregate prefix\n"
5579 "Filter more specific routes from updates\n")
5580
5581ALIAS (no_ipv6_aggregate_address,
5582 old_no_ipv6_aggregate_address_cmd,
5583 "no ipv6 bgp aggregate-address X:X::X:X/M",
5584 NO_STR
5585 IPV6_STR
5586 BGP_STR
5587 "Configure BGP aggregate entries\n"
5588 "Aggregate prefix\n")
5589
5590ALIAS (no_ipv6_aggregate_address_summary_only,
5591 old_no_ipv6_aggregate_address_summary_only_cmd,
5592 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5593 NO_STR
5594 IPV6_STR
5595 BGP_STR
5596 "Configure BGP aggregate entries\n"
5597 "Aggregate prefix\n"
5598 "Filter more specific routes from updates\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02005599
paul718e3742002-12-13 20:15:29 +00005600/* Redistribute route treatment. */
5601void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005602bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5603 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005604 u_int32_t metric, u_char type)
5605{
5606 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005607 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005608 struct bgp_info *new;
5609 struct bgp_info *bi;
5610 struct bgp_info info;
5611 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005612 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005613 struct attr *new_attr;
5614 afi_t afi;
5615 int ret;
5616
5617 /* Make default attribute. */
5618 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5619 if (nexthop)
5620 attr.nexthop = *nexthop;
5621
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005622 if (nexthop6)
5623 {
5624 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5625 extra->mp_nexthop_global = *nexthop6;
5626 extra->mp_nexthop_len = 16;
5627 }
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005628
paul718e3742002-12-13 20:15:29 +00005629 attr.med = metric;
5630 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5631
paul1eb8ef22005-04-07 07:30:20 +00005632 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005633 {
5634 afi = family2afi (p->family);
5635
5636 if (bgp->redist[afi][type])
5637 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005638 struct attr attr_new;
5639 struct attr_extra extra_new;
5640
paul718e3742002-12-13 20:15:29 +00005641 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005642 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005643 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005644
5645 if (bgp->redist_metric_flag[afi][type])
5646 attr_new.med = bgp->redist_metric[afi][type];
5647
5648 /* Apply route-map. */
Daniel Walton1994dc82015-09-17 10:15:59 -04005649 if (bgp->rmap[afi][type].name)
paul718e3742002-12-13 20:15:29 +00005650 {
5651 info.peer = bgp->peer_self;
5652 info.attr = &attr_new;
5653
paulfee0f4c2004-09-13 05:12:46 +00005654 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5655
paul718e3742002-12-13 20:15:29 +00005656 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5657 &info);
paulfee0f4c2004-09-13 05:12:46 +00005658
5659 bgp->peer_self->rmap_type = 0;
5660
paul718e3742002-12-13 20:15:29 +00005661 if (ret == RMAP_DENYMATCH)
5662 {
5663 /* Free uninterned attribute. */
5664 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005665
paul718e3742002-12-13 20:15:29 +00005666 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005667 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005668 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005669 bgp_redistribute_delete (p, type);
5670 return;
5671 }
5672 }
5673
Paul Jakmafb982c22007-05-04 20:15:47 +00005674 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5675 afi, SAFI_UNICAST, p, NULL);
5676
paul718e3742002-12-13 20:15:29 +00005677 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005678
paul718e3742002-12-13 20:15:29 +00005679 for (bi = bn->info; bi; bi = bi->next)
5680 if (bi->peer == bgp->peer_self
5681 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5682 break;
5683
5684 if (bi)
5685 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005686 if (attrhash_cmp (bi->attr, new_attr) &&
5687 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005688 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005689 bgp_attr_unintern (&new_attr);
5690 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005691 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005692 bgp_unlock_node (bn);
5693 return;
5694 }
5695 else
5696 {
5697 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005698 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005699
5700 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005701 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5702 bgp_info_restore(bn, bi);
5703 else
5704 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005705 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005706 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005707 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005708
5709 /* Process change. */
5710 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5711 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5712 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005713 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005714 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005715 return;
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05005716 }
paul718e3742002-12-13 20:15:29 +00005717 }
5718
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05005719 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, bgp->peer_self,
5720 new_attr, bn);
paul718e3742002-12-13 20:15:29 +00005721 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00005722
5723 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5724 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005725 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005726 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5727 }
5728 }
5729
5730 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005731 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005732 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005733}
5734
5735void
5736bgp_redistribute_delete (struct prefix *p, u_char type)
5737{
5738 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005739 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005740 afi_t afi;
5741 struct bgp_node *rn;
5742 struct bgp_info *ri;
5743
paul1eb8ef22005-04-07 07:30:20 +00005744 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005745 {
5746 afi = family2afi (p->family);
5747
5748 if (bgp->redist[afi][type])
5749 {
paulfee0f4c2004-09-13 05:12:46 +00005750 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005751
5752 for (ri = rn->info; ri; ri = ri->next)
5753 if (ri->peer == bgp->peer_self
5754 && ri->type == type)
5755 break;
5756
5757 if (ri)
5758 {
5759 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005760 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005761 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005762 }
5763 bgp_unlock_node (rn);
5764 }
5765 }
5766}
5767
5768/* Withdraw specified route type's route. */
5769void
5770bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5771{
5772 struct bgp_node *rn;
5773 struct bgp_info *ri;
5774 struct bgp_table *table;
5775
5776 table = bgp->rib[afi][SAFI_UNICAST];
5777
5778 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5779 {
5780 for (ri = rn->info; ri; ri = ri->next)
5781 if (ri->peer == bgp->peer_self
5782 && ri->type == type)
5783 break;
5784
5785 if (ri)
5786 {
5787 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005788 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005789 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005790 }
5791 }
5792}
David Lamparter6b0655a2014-06-04 06:53:35 +02005793
paul718e3742002-12-13 20:15:29 +00005794/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005795static void
paul718e3742002-12-13 20:15:29 +00005796route_vty_out_route (struct prefix *p, struct vty *vty)
5797{
5798 int len;
5799 u_int32_t destination;
5800 char buf[BUFSIZ];
5801
5802 if (p->family == AF_INET)
5803 {
5804 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5805 destination = ntohl (p->u.prefix4.s_addr);
5806
5807 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5808 || (IN_CLASSB (destination) && p->prefixlen == 16)
5809 || (IN_CLASSA (destination) && p->prefixlen == 8)
5810 || p->u.prefix4.s_addr == 0)
5811 {
5812 /* When mask is natural, mask is not displayed. */
5813 }
5814 else
5815 len += vty_out (vty, "/%d", p->prefixlen);
5816 }
5817 else
5818 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5819 p->prefixlen);
5820
5821 len = 17 - len;
5822 if (len < 1)
5823 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5824 else
5825 vty_out (vty, "%*s", len, " ");
5826}
5827
paul718e3742002-12-13 20:15:29 +00005828enum bgp_display_type
5829{
5830 normal_list,
5831};
5832
paulb40d9392005-08-22 22:34:41 +00005833/* Print the short form route status for a bgp_info */
5834static void
5835route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005836{
paulb40d9392005-08-22 22:34:41 +00005837 /* Route status display. */
5838 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5839 vty_out (vty, "R");
5840 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005841 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005842 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005843 vty_out (vty, "s");
5844 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5845 vty_out (vty, "*");
5846 else
5847 vty_out (vty, " ");
5848
5849 /* Selected */
5850 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5851 vty_out (vty, "h");
5852 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5853 vty_out (vty, "d");
5854 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5855 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005856 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5857 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005858 else
5859 vty_out (vty, " ");
5860
5861 /* Internal route. */
5862 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5863 vty_out (vty, "i");
5864 else
paulb40d9392005-08-22 22:34:41 +00005865 vty_out (vty, " ");
5866}
5867
5868/* called from terminal list command */
5869void
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005870route_vty_out(
5871 struct vty *vty,
5872 struct prefix *p,
5873 struct bgp_info *binfo,
5874 int display,
5875 safi_t safi)
paulb40d9392005-08-22 22:34:41 +00005876{
5877 struct attr *attr;
5878
5879 /* short status lead text */
5880 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005881
5882 /* print prefix and mask */
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005883 if (!display)
paul718e3742002-12-13 20:15:29 +00005884 route_vty_out_route (p, vty);
5885 else
5886 vty_out (vty, "%*s", 17, " ");
5887
5888 /* Print attribute */
5889 attr = binfo->attr;
5890 if (attr)
5891 {
paul718e3742002-12-13 20:15:29 +00005892
Lou Berger298cc2f2016-01-12 13:42:02 -05005893 /*
5894 * NEXTHOP start
5895 */
5896
5897 /*
5898 * For ENCAP routes, nexthop address family is not
5899 * neccessarily the same as the prefix address family.
5900 * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
5901 */
5902 if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN)) {
5903 if (attr->extra) {
5904 char buf[BUFSIZ];
5905 int af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len);
5906
5907 switch (af) {
5908 case AF_INET:
5909 vty_out (vty, "%s", inet_ntop(af,
5910 &attr->extra->mp_nexthop_global_in, buf, BUFSIZ));
5911 break;
Lou Berger298cc2f2016-01-12 13:42:02 -05005912 case AF_INET6:
5913 vty_out (vty, "%s", inet_ntop(af,
5914 &attr->extra->mp_nexthop_global, buf, BUFSIZ));
5915 break;
Lou Berger298cc2f2016-01-12 13:42:02 -05005916 default:
5917 vty_out(vty, "?");
5918 }
5919 } else {
5920 vty_out(vty, "?");
paul718e3742002-12-13 20:15:29 +00005921 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005922 } else {
5923
5924 if (p->family == AF_INET)
5925 {
5926 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5927 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005928 else if (p->family == AF_INET6)
5929 {
5930 int len;
5931 char buf[BUFSIZ];
5932
5933 len = vty_out (vty, "%s",
5934 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5935 buf, BUFSIZ));
5936 len = 16 - len;
5937 if (len < 1)
5938 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5939 else
5940 vty_out (vty, "%*s", len, " ");
5941 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005942 else
5943 {
5944 vty_out(vty, "?");
5945 }
5946 }
5947
5948 /*
5949 * NEXTHOP end
5950 */
5951
paul718e3742002-12-13 20:15:29 +00005952
5953 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005954 vty_out (vty, "%10u ", attr->med);
paul718e3742002-12-13 20:15:29 +00005955 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005956 vty_out (vty, " ");
paul718e3742002-12-13 20:15:29 +00005957
5958 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005959 vty_out (vty, "%7u ", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005960 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005961 vty_out (vty, " ");
paul718e3742002-12-13 20:15:29 +00005962
Paul Jakmafb982c22007-05-04 20:15:47 +00005963 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005964
Paul Jakmab2518c12006-05-12 23:48:40 +00005965 /* Print aspath */
5966 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005967 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005968
Paul Jakmab2518c12006-05-12 23:48:40 +00005969 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005970 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005971 }
paul718e3742002-12-13 20:15:29 +00005972 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005973}
5974
5975/* called from terminal list command */
5976void
5977route_vty_out_tmp (struct vty *vty, struct prefix *p,
5978 struct attr *attr, safi_t safi)
5979{
5980 /* Route status display. */
5981 vty_out (vty, "*");
5982 vty_out (vty, ">");
5983 vty_out (vty, " ");
5984
5985 /* print prefix and mask */
5986 route_vty_out_route (p, vty);
5987
5988 /* Print attribute */
5989 if (attr)
5990 {
5991 if (p->family == AF_INET)
5992 {
Lou Berger298cc2f2016-01-12 13:42:02 -05005993 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00005994 vty_out (vty, "%-16s",
5995 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005996 else
5997 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5998 }
paul718e3742002-12-13 20:15:29 +00005999 else if (p->family == AF_INET6)
6000 {
6001 int len;
6002 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006003
6004 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006005
6006 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006007 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6008 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006009 len = 16 - len;
6010 if (len < 1)
6011 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6012 else
6013 vty_out (vty, "%*s", len, " ");
6014 }
paul718e3742002-12-13 20:15:29 +00006015
6016 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006017 vty_out (vty, "%10u ", attr->med);
paul718e3742002-12-13 20:15:29 +00006018 else
6019 vty_out (vty, " ");
6020
6021 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006022 vty_out (vty, "%7u ", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006023 else
6024 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006025
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006026 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00006027
Paul Jakmab2518c12006-05-12 23:48:40 +00006028 /* Print aspath */
6029 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006030 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006031
Paul Jakmab2518c12006-05-12 23:48:40 +00006032 /* Print origin */
paul718e3742002-12-13 20:15:29 +00006033 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00006034 }
paul718e3742002-12-13 20:15:29 +00006035
6036 vty_out (vty, "%s", VTY_NEWLINE);
6037}
6038
ajs5a646652004-11-05 01:25:55 +00006039void
paul718e3742002-12-13 20:15:29 +00006040route_vty_out_tag (struct vty *vty, struct prefix *p,
6041 struct bgp_info *binfo, int display, safi_t safi)
6042{
6043 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006044 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00006045
6046 if (!binfo->extra)
6047 return;
6048
paulb40d9392005-08-22 22:34:41 +00006049 /* short status lead text */
6050 route_vty_short_status_out (vty, binfo);
6051
paul718e3742002-12-13 20:15:29 +00006052 /* print prefix and mask */
6053 if (! display)
6054 route_vty_out_route (p, vty);
6055 else
6056 vty_out (vty, "%*s", 17, " ");
6057
6058 /* Print attribute */
6059 attr = binfo->attr;
6060 if (attr)
6061 {
6062 if (p->family == AF_INET)
6063 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006064 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00006065 vty_out (vty, "%-16s",
6066 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00006067 else
6068 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6069 }
paul718e3742002-12-13 20:15:29 +00006070 else if (p->family == AF_INET6)
6071 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006072 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006073 char buf[BUFSIZ];
6074 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006075 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00006076 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006077 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6078 buf, BUFSIZ));
6079 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006080 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006081 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6082 buf, BUFSIZ),
6083 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6084 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006085
6086 }
paul718e3742002-12-13 20:15:29 +00006087 }
6088
Paul Jakmafb982c22007-05-04 20:15:47 +00006089 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00006090
6091 vty_out (vty, "notag/%d", label);
6092
6093 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006094}
6095
6096/* dampening route */
ajs5a646652004-11-05 01:25:55 +00006097static void
paul718e3742002-12-13 20:15:29 +00006098damp_route_vty_out (struct vty *vty, struct prefix *p,
6099 struct bgp_info *binfo, int display, safi_t safi)
6100{
6101 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006102 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00006103 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00006104
paulb40d9392005-08-22 22:34:41 +00006105 /* short status lead text */
6106 route_vty_short_status_out (vty, binfo);
6107
paul718e3742002-12-13 20:15:29 +00006108 /* print prefix and mask */
6109 if (! display)
6110 route_vty_out_route (p, vty);
6111 else
6112 vty_out (vty, "%*s", 17, " ");
6113
6114 len = vty_out (vty, "%s", binfo->peer->host);
6115 len = 17 - len;
6116 if (len < 1)
6117 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6118 else
6119 vty_out (vty, "%*s", len, " ");
6120
Chris Caputo50aef6f2009-06-23 06:06:49 +00006121 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006122
6123 /* Print attribute */
6124 attr = binfo->attr;
6125 if (attr)
6126 {
6127 /* Print aspath */
6128 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006129 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006130
6131 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006132 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006133 }
6134 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006135}
6136
paul718e3742002-12-13 20:15:29 +00006137/* flap route */
ajs5a646652004-11-05 01:25:55 +00006138static void
paul718e3742002-12-13 20:15:29 +00006139flap_route_vty_out (struct vty *vty, struct prefix *p,
6140 struct bgp_info *binfo, int display, safi_t safi)
6141{
6142 struct attr *attr;
6143 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00006144 char timebuf[BGP_UPTIME_LEN];
6145 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00006146
6147 if (!binfo->extra)
6148 return;
6149
6150 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00006151
paulb40d9392005-08-22 22:34:41 +00006152 /* short status lead text */
6153 route_vty_short_status_out (vty, binfo);
6154
paul718e3742002-12-13 20:15:29 +00006155 /* print prefix and mask */
6156 if (! display)
6157 route_vty_out_route (p, vty);
6158 else
6159 vty_out (vty, "%*s", 17, " ");
6160
6161 len = vty_out (vty, "%s", binfo->peer->host);
6162 len = 16 - len;
6163 if (len < 1)
6164 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6165 else
6166 vty_out (vty, "%*s", len, " ");
6167
6168 len = vty_out (vty, "%d", bdi->flap);
6169 len = 5 - len;
6170 if (len < 1)
6171 vty_out (vty, " ");
6172 else
6173 vty_out (vty, "%*s ", len, " ");
6174
6175 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6176 timebuf, BGP_UPTIME_LEN));
6177
6178 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6179 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00006180 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006181 else
6182 vty_out (vty, "%*s ", 8, " ");
6183
6184 /* Print attribute */
6185 attr = binfo->attr;
6186 if (attr)
6187 {
6188 /* Print aspath */
6189 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006190 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006191
6192 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006193 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006194 }
6195 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006196}
6197
paul94f2b392005-06-28 12:44:16 +00006198static void
paul718e3742002-12-13 20:15:29 +00006199route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6200 struct bgp_info *binfo, afi_t afi, safi_t safi)
6201{
6202 char buf[INET6_ADDRSTRLEN];
6203 char buf1[BUFSIZ];
6204 struct attr *attr;
6205 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03006206#ifdef HAVE_CLOCK_MONOTONIC
6207 time_t tbuf;
6208#endif
paul718e3742002-12-13 20:15:29 +00006209
6210 attr = binfo->attr;
6211
6212 if (attr)
6213 {
6214 /* Line1 display AS-path, Aggregator */
6215 if (attr->aspath)
6216 {
6217 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00006218 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00006219 vty_out (vty, "Local");
6220 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006221 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00006222 }
6223
paulb40d9392005-08-22 22:34:41 +00006224 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6225 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00006226 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6227 vty_out (vty, ", (stale)");
6228 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006229 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006230 attr->extra->aggregator_as,
6231 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006232 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6233 vty_out (vty, ", (Received from a RR-client)");
6234 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6235 vty_out (vty, ", (Received from a RS-client)");
6236 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6237 vty_out (vty, ", (history entry)");
6238 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6239 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006240 vty_out (vty, "%s", VTY_NEWLINE);
6241
6242 /* Line2 display Next-hop, Neighbor, Router-id */
6243 if (p->family == AF_INET)
6244 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006245 vty_out (vty, " %s", ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)) ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006246 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006247 inet_ntoa (attr->nexthop));
6248 }
paul718e3742002-12-13 20:15:29 +00006249 else
6250 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006251 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006252 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006253 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006254 buf, INET6_ADDRSTRLEN));
6255 }
paul718e3742002-12-13 20:15:29 +00006256
6257 if (binfo->peer == bgp->peer_self)
6258 {
6259 vty_out (vty, " from %s ",
6260 p->family == AF_INET ? "0.0.0.0" : "::");
6261 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6262 }
6263 else
6264 {
6265 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6266 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006267 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006268 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006269 if (!sockunion2str (&binfo->peer->su, buf, sizeof(buf))) {
6270 buf[0] = '?';
6271 buf[1] = 0;
6272 }
6273 vty_out (vty, " from %s", buf);
paul718e3742002-12-13 20:15:29 +00006274 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006275 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006276 else
6277 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6278 }
6279 vty_out (vty, "%s", VTY_NEWLINE);
6280
paul718e3742002-12-13 20:15:29 +00006281 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006282 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006283 {
6284 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006285 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006286 buf, INET6_ADDRSTRLEN),
6287 VTY_NEWLINE);
6288 }
paul718e3742002-12-13 20:15:29 +00006289
6290 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6291 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6292
6293 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006294 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006295
6296 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006297 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006298 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006299 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006300
Paul Jakmafb982c22007-05-04 20:15:47 +00006301 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006302 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006303
6304 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6305 vty_out (vty, ", valid");
6306
6307 if (binfo->peer != bgp->peer_self)
6308 {
6309 if (binfo->peer->as == binfo->peer->local_as)
6310 vty_out (vty, ", internal");
6311 else
6312 vty_out (vty, ", %s",
6313 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6314 }
6315 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6316 vty_out (vty, ", aggregated, local");
6317 else if (binfo->type != ZEBRA_ROUTE_BGP)
6318 vty_out (vty, ", sourced");
6319 else
6320 vty_out (vty, ", sourced, local");
6321
6322 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6323 vty_out (vty, ", atomic-aggregate");
6324
Josh Baileyde8d5df2011-07-20 20:46:01 -07006325 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6326 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6327 bgp_info_mpath_count (binfo)))
6328 vty_out (vty, ", multipath");
6329
paul718e3742002-12-13 20:15:29 +00006330 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6331 vty_out (vty, ", best");
6332
6333 vty_out (vty, "%s", VTY_NEWLINE);
6334
6335 /* Line 4 display Community */
6336 if (attr->community)
6337 vty_out (vty, " Community: %s%s", attr->community->str,
6338 VTY_NEWLINE);
6339
6340 /* Line 5 display Extended-community */
6341 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006342 vty_out (vty, " Extended Community: %s%s",
6343 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006344
6345 /* Line 6 display Originator, Cluster-id */
6346 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6347 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6348 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006349 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006350 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006351 vty_out (vty, " Originator: %s",
6352 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006353
6354 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6355 {
6356 int i;
6357 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006358 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6359 vty_out (vty, "%s ",
6360 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006361 }
6362 vty_out (vty, "%s", VTY_NEWLINE);
6363 }
Paul Jakma41367172007-08-06 15:24:51 +00006364
Paul Jakmafb982c22007-05-04 20:15:47 +00006365 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006366 bgp_damp_info_vty (vty, binfo);
6367
6368 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006369#ifdef HAVE_CLOCK_MONOTONIC
6370 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006371 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006372#else
6373 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6374#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006375 }
6376 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006377}
6378
6379#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6380 "h history, * valid, > best, = multipath,%s"\
6381 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006382#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006383#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6384#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6385#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6386
6387enum bgp_show_type
6388{
6389 bgp_show_type_normal,
6390 bgp_show_type_regexp,
6391 bgp_show_type_prefix_list,
6392 bgp_show_type_filter_list,
6393 bgp_show_type_route_map,
6394 bgp_show_type_neighbor,
6395 bgp_show_type_cidr_only,
6396 bgp_show_type_prefix_longer,
6397 bgp_show_type_community_all,
6398 bgp_show_type_community,
6399 bgp_show_type_community_exact,
6400 bgp_show_type_community_list,
6401 bgp_show_type_community_list_exact,
6402 bgp_show_type_flap_statistics,
6403 bgp_show_type_flap_address,
6404 bgp_show_type_flap_prefix,
6405 bgp_show_type_flap_cidr_only,
6406 bgp_show_type_flap_regexp,
6407 bgp_show_type_flap_filter_list,
6408 bgp_show_type_flap_prefix_list,
6409 bgp_show_type_flap_prefix_longer,
6410 bgp_show_type_flap_route_map,
6411 bgp_show_type_flap_neighbor,
6412 bgp_show_type_dampend_paths,
6413 bgp_show_type_damp_neighbor
6414};
6415
ajs5a646652004-11-05 01:25:55 +00006416static int
paulfee0f4c2004-09-13 05:12:46 +00006417bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006418 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006419{
paul718e3742002-12-13 20:15:29 +00006420 struct bgp_info *ri;
6421 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006422 int header = 1;
paul718e3742002-12-13 20:15:29 +00006423 int display;
ajs5a646652004-11-05 01:25:55 +00006424 unsigned long output_count;
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006425 unsigned long total_count;
paul718e3742002-12-13 20:15:29 +00006426
6427 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006428 output_count = 0;
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006429 total_count = 0;
paul718e3742002-12-13 20:15:29 +00006430
paul718e3742002-12-13 20:15:29 +00006431 /* Start processing of routes. */
6432 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6433 if (rn->info != NULL)
6434 {
6435 display = 0;
6436
6437 for (ri = rn->info; ri; ri = ri->next)
6438 {
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006439 total_count++;
ajs5a646652004-11-05 01:25:55 +00006440 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006441 || type == bgp_show_type_flap_address
6442 || type == bgp_show_type_flap_prefix
6443 || type == bgp_show_type_flap_cidr_only
6444 || type == bgp_show_type_flap_regexp
6445 || type == bgp_show_type_flap_filter_list
6446 || type == bgp_show_type_flap_prefix_list
6447 || type == bgp_show_type_flap_prefix_longer
6448 || type == bgp_show_type_flap_route_map
6449 || type == bgp_show_type_flap_neighbor
6450 || type == bgp_show_type_dampend_paths
6451 || type == bgp_show_type_damp_neighbor)
6452 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006453 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006454 continue;
6455 }
6456 if (type == bgp_show_type_regexp
6457 || type == bgp_show_type_flap_regexp)
6458 {
ajs5a646652004-11-05 01:25:55 +00006459 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006460
6461 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6462 continue;
6463 }
6464 if (type == bgp_show_type_prefix_list
6465 || type == bgp_show_type_flap_prefix_list)
6466 {
ajs5a646652004-11-05 01:25:55 +00006467 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006468
6469 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6470 continue;
6471 }
6472 if (type == bgp_show_type_filter_list
6473 || type == bgp_show_type_flap_filter_list)
6474 {
ajs5a646652004-11-05 01:25:55 +00006475 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006476
6477 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6478 continue;
6479 }
6480 if (type == bgp_show_type_route_map
6481 || type == bgp_show_type_flap_route_map)
6482 {
ajs5a646652004-11-05 01:25:55 +00006483 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006484 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006485 struct attr dummy_attr;
6486 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006487 int ret;
6488
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006489 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006490 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006491
paul718e3742002-12-13 20:15:29 +00006492 binfo.peer = ri->peer;
6493 binfo.attr = &dummy_attr;
6494
6495 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006496 if (ret == RMAP_DENYMATCH)
6497 continue;
6498 }
6499 if (type == bgp_show_type_neighbor
6500 || type == bgp_show_type_flap_neighbor
6501 || type == bgp_show_type_damp_neighbor)
6502 {
ajs5a646652004-11-05 01:25:55 +00006503 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006504
6505 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6506 continue;
6507 }
6508 if (type == bgp_show_type_cidr_only
6509 || type == bgp_show_type_flap_cidr_only)
6510 {
6511 u_int32_t destination;
6512
6513 destination = ntohl (rn->p.u.prefix4.s_addr);
6514 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6515 continue;
6516 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6517 continue;
6518 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6519 continue;
6520 }
6521 if (type == bgp_show_type_prefix_longer
6522 || type == bgp_show_type_flap_prefix_longer)
6523 {
ajs5a646652004-11-05 01:25:55 +00006524 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006525
6526 if (! prefix_match (p, &rn->p))
6527 continue;
6528 }
6529 if (type == bgp_show_type_community_all)
6530 {
6531 if (! ri->attr->community)
6532 continue;
6533 }
6534 if (type == bgp_show_type_community)
6535 {
ajs5a646652004-11-05 01:25:55 +00006536 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006537
6538 if (! ri->attr->community ||
6539 ! community_match (ri->attr->community, com))
6540 continue;
6541 }
6542 if (type == bgp_show_type_community_exact)
6543 {
ajs5a646652004-11-05 01:25:55 +00006544 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006545
6546 if (! ri->attr->community ||
6547 ! community_cmp (ri->attr->community, com))
6548 continue;
6549 }
6550 if (type == bgp_show_type_community_list)
6551 {
ajs5a646652004-11-05 01:25:55 +00006552 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006553
6554 if (! community_list_match (ri->attr->community, list))
6555 continue;
6556 }
6557 if (type == bgp_show_type_community_list_exact)
6558 {
ajs5a646652004-11-05 01:25:55 +00006559 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006560
6561 if (! community_list_exact_match (ri->attr->community, list))
6562 continue;
6563 }
6564 if (type == bgp_show_type_flap_address
6565 || type == bgp_show_type_flap_prefix)
6566 {
ajs5a646652004-11-05 01:25:55 +00006567 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006568
6569 if (! prefix_match (&rn->p, p))
6570 continue;
6571
6572 if (type == bgp_show_type_flap_prefix)
6573 if (p->prefixlen != rn->p.prefixlen)
6574 continue;
6575 }
6576 if (type == bgp_show_type_dampend_paths
6577 || type == bgp_show_type_damp_neighbor)
6578 {
6579 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6580 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6581 continue;
6582 }
6583
6584 if (header)
6585 {
hasso93406d82005-02-02 14:40:33 +00006586 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6587 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6588 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006589 if (type == bgp_show_type_dampend_paths
6590 || type == bgp_show_type_damp_neighbor)
6591 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6592 else if (type == bgp_show_type_flap_statistics
6593 || type == bgp_show_type_flap_address
6594 || type == bgp_show_type_flap_prefix
6595 || type == bgp_show_type_flap_cidr_only
6596 || type == bgp_show_type_flap_regexp
6597 || type == bgp_show_type_flap_filter_list
6598 || type == bgp_show_type_flap_prefix_list
6599 || type == bgp_show_type_flap_prefix_longer
6600 || type == bgp_show_type_flap_route_map
6601 || type == bgp_show_type_flap_neighbor)
6602 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6603 else
6604 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006605 header = 0;
6606 }
6607
6608 if (type == bgp_show_type_dampend_paths
6609 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006610 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006611 else if (type == bgp_show_type_flap_statistics
6612 || type == bgp_show_type_flap_address
6613 || type == bgp_show_type_flap_prefix
6614 || type == bgp_show_type_flap_cidr_only
6615 || type == bgp_show_type_flap_regexp
6616 || type == bgp_show_type_flap_filter_list
6617 || type == bgp_show_type_flap_prefix_list
6618 || type == bgp_show_type_flap_prefix_longer
6619 || type == bgp_show_type_flap_route_map
6620 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006621 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006622 else
ajs5a646652004-11-05 01:25:55 +00006623 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006624 display++;
6625 }
6626 if (display)
ajs5a646652004-11-05 01:25:55 +00006627 output_count++;
paul718e3742002-12-13 20:15:29 +00006628 }
6629
6630 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006631 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006632 {
6633 if (type == bgp_show_type_normal)
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006634 vty_out (vty, "No BGP prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006635 }
6636 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006637 vty_out (vty, "%sDisplayed %ld out of %ld total prefixes%s",
6638 VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006639
6640 return CMD_SUCCESS;
6641}
6642
ajs5a646652004-11-05 01:25:55 +00006643static int
paulfee0f4c2004-09-13 05:12:46 +00006644bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006645 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006646{
6647 struct bgp_table *table;
6648
6649 if (bgp == NULL) {
6650 bgp = bgp_get_default ();
6651 }
6652
6653 if (bgp == NULL)
6654 {
6655 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6656 return CMD_WARNING;
6657 }
6658
6659
6660 table = bgp->rib[afi][safi];
6661
ajs5a646652004-11-05 01:25:55 +00006662 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006663}
6664
paul718e3742002-12-13 20:15:29 +00006665/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006666static void
paul718e3742002-12-13 20:15:29 +00006667route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6668 struct bgp_node *rn,
6669 struct prefix_rd *prd, afi_t afi, safi_t safi)
6670{
6671 struct bgp_info *ri;
6672 struct prefix *p;
6673 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006674 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006675 char buf1[INET6_ADDRSTRLEN];
6676 char buf2[INET6_ADDRSTRLEN];
6677 int count = 0;
6678 int best = 0;
6679 int suppress = 0;
6680 int no_export = 0;
6681 int no_advertise = 0;
6682 int local_as = 0;
6683 int first = 0;
Lou Berger298cc2f2016-01-12 13:42:02 -05006684 int printrd = ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP));
paul718e3742002-12-13 20:15:29 +00006685
6686 p = &rn->p;
6687 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
Lou Berger298cc2f2016-01-12 13:42:02 -05006688 (printrd ? prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6689 printrd ? ":" : "",
paul718e3742002-12-13 20:15:29 +00006690 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6691 p->prefixlen, VTY_NEWLINE);
6692
6693 for (ri = rn->info; ri; ri = ri->next)
6694 {
6695 count++;
6696 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6697 {
6698 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006699 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006700 suppress = 1;
6701 if (ri->attr->community != NULL)
6702 {
6703 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6704 no_advertise = 1;
6705 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6706 no_export = 1;
6707 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6708 local_as = 1;
6709 }
6710 }
6711 }
6712
6713 vty_out (vty, "Paths: (%d available", count);
6714 if (best)
6715 {
6716 vty_out (vty, ", best #%d", best);
6717 if (safi == SAFI_UNICAST)
6718 vty_out (vty, ", table Default-IP-Routing-Table");
6719 }
6720 else
6721 vty_out (vty, ", no best path");
6722 if (no_advertise)
6723 vty_out (vty, ", not advertised to any peer");
6724 else if (no_export)
6725 vty_out (vty, ", not advertised to EBGP peer");
6726 else if (local_as)
6727 vty_out (vty, ", not advertised outside local AS");
6728 if (suppress)
6729 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6730 vty_out (vty, ")%s", VTY_NEWLINE);
6731
6732 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006733 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006734 {
6735 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6736 {
6737 if (! first)
6738 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6739 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6740 first = 1;
6741 }
6742 }
6743 if (! first)
6744 vty_out (vty, " Not advertised to any peer");
6745 vty_out (vty, "%s", VTY_NEWLINE);
6746}
6747
6748/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006749static int
paulfee0f4c2004-09-13 05:12:46 +00006750bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006751 struct bgp_table *rib, const char *ip_str,
6752 afi_t afi, safi_t safi, struct prefix_rd *prd,
6753 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006754{
6755 int ret;
6756 int header;
6757 int display = 0;
6758 struct prefix match;
6759 struct bgp_node *rn;
6760 struct bgp_node *rm;
6761 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006762 struct bgp_table *table;
6763
Lou Berger050defe2016-01-12 13:41:59 -05006764 memset (&match, 0, sizeof (struct prefix)); /* keep valgrind happy */
paul718e3742002-12-13 20:15:29 +00006765 /* Check IP address argument. */
6766 ret = str2prefix (ip_str, &match);
6767 if (! ret)
6768 {
6769 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6770 return CMD_WARNING;
6771 }
6772
6773 match.family = afi2family (afi);
6774
Lou Berger298cc2f2016-01-12 13:42:02 -05006775 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00006776 {
paulfee0f4c2004-09-13 05:12:46 +00006777 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006778 {
6779 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6780 continue;
6781
6782 if ((table = rn->info) != NULL)
6783 {
6784 header = 1;
6785
6786 if ((rm = bgp_node_match (table, &match)) != NULL)
6787 {
6788 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006789 {
6790 bgp_unlock_node (rm);
6791 continue;
6792 }
paul718e3742002-12-13 20:15:29 +00006793
6794 for (ri = rm->info; ri; ri = ri->next)
6795 {
6796 if (header)
6797 {
6798 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
Lou Berger298cc2f2016-01-12 13:42:02 -05006799 AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00006800
6801 header = 0;
6802 }
6803 display++;
Lou Berger298cc2f2016-01-12 13:42:02 -05006804 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00006805 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006806
6807 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006808 }
6809 }
6810 }
6811 }
6812 else
6813 {
6814 header = 1;
6815
paulfee0f4c2004-09-13 05:12:46 +00006816 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006817 {
6818 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6819 {
6820 for (ri = rn->info; ri; ri = ri->next)
6821 {
6822 if (header)
6823 {
6824 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6825 header = 0;
6826 }
6827 display++;
6828 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6829 }
6830 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006831
6832 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006833 }
6834 }
6835
6836 if (! display)
6837 {
6838 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6839 return CMD_WARNING;
6840 }
6841
6842 return CMD_SUCCESS;
6843}
6844
paulfee0f4c2004-09-13 05:12:46 +00006845/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006846static int
paulfd79ac92004-10-13 05:06:08 +00006847bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006848 afi_t afi, safi_t safi, struct prefix_rd *prd,
6849 int prefix_check)
6850{
6851 struct bgp *bgp;
6852
6853 /* BGP structure lookup. */
6854 if (view_name)
6855 {
6856 bgp = bgp_lookup_by_name (view_name);
6857 if (bgp == NULL)
6858 {
6859 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6860 return CMD_WARNING;
6861 }
6862 }
6863 else
6864 {
6865 bgp = bgp_get_default ();
6866 if (bgp == NULL)
6867 {
6868 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6869 return CMD_WARNING;
6870 }
6871 }
6872
6873 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6874 afi, safi, prd, prefix_check);
6875}
6876
paul718e3742002-12-13 20:15:29 +00006877/* BGP route print out function. */
Lou Bergerf9b6c392016-01-12 13:42:09 -05006878DEFUN (show_ip_bgp,
6879 show_ip_bgp_cmd,
6880 "show ip bgp",
6881 SHOW_STR
6882 IP_STR
6883 BGP_STR)
6884{
6885 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6886}
6887
6888DEFUN (show_ip_bgp_ipv4,
6889 show_ip_bgp_ipv4_cmd,
6890 "show ip bgp ipv4 (unicast|multicast)",
6891 SHOW_STR
6892 IP_STR
6893 BGP_STR
6894 "Address family\n"
6895 "Address Family modifier\n"
6896 "Address Family modifier\n")
6897{
6898 if (strncmp (argv[0], "m", 1) == 0)
6899 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6900 NULL);
6901
6902 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6903}
6904
6905DEFUN (show_ip_bgp_route,
6906 show_ip_bgp_route_cmd,
6907 "show ip bgp A.B.C.D",
6908 SHOW_STR
6909 IP_STR
6910 BGP_STR
6911 "Network in the BGP routing table to display\n")
6912{
6913 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6914}
6915
6916DEFUN (show_ip_bgp_ipv4_route,
6917 show_ip_bgp_ipv4_route_cmd,
6918 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6919 SHOW_STR
6920 IP_STR
6921 BGP_STR
6922 "Address family\n"
6923 "Address Family modifier\n"
6924 "Address Family modifier\n"
6925 "Network in the BGP routing table to display\n")
6926{
6927 if (strncmp (argv[0], "m", 1) == 0)
6928 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6929
6930 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6931}
6932
6933DEFUN (show_ip_bgp_vpnv4_all_route,
6934 show_ip_bgp_vpnv4_all_route_cmd,
6935 "show ip bgp vpnv4 all A.B.C.D",
6936 SHOW_STR
6937 IP_STR
6938 BGP_STR
6939 "Display VPNv4 NLRI specific information\n"
6940 "Display information about all VPNv4 NLRIs\n"
6941 "Network in the BGP routing table to display\n")
6942{
6943 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6944}
6945
6946DEFUN (show_ip_bgp_vpnv4_rd_route,
6947 show_ip_bgp_vpnv4_rd_route_cmd,
6948 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6949 SHOW_STR
6950 IP_STR
6951 BGP_STR
6952 "Display VPNv4 NLRI specific information\n"
6953 "Display information for a route distinguisher\n"
6954 "VPN Route Distinguisher\n"
6955 "Network in the BGP routing table to display\n")
6956{
6957 int ret;
6958 struct prefix_rd prd;
6959
6960 ret = str2prefix_rd (argv[0], &prd);
6961 if (! ret)
6962 {
6963 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6964 return CMD_WARNING;
6965 }
6966 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6967}
6968
6969DEFUN (show_ip_bgp_prefix,
6970 show_ip_bgp_prefix_cmd,
6971 "show ip bgp A.B.C.D/M",
6972 SHOW_STR
6973 IP_STR
6974 BGP_STR
6975 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6976{
6977 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6978}
6979
6980DEFUN (show_ip_bgp_ipv4_prefix,
6981 show_ip_bgp_ipv4_prefix_cmd,
6982 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6983 SHOW_STR
6984 IP_STR
6985 BGP_STR
6986 "Address family\n"
6987 "Address Family modifier\n"
6988 "Address Family modifier\n"
6989 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6990{
6991 if (strncmp (argv[0], "m", 1) == 0)
6992 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6993
6994 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6995}
6996
6997DEFUN (show_ip_bgp_vpnv4_all_prefix,
6998 show_ip_bgp_vpnv4_all_prefix_cmd,
6999 "show ip bgp vpnv4 all A.B.C.D/M",
7000 SHOW_STR
7001 IP_STR
7002 BGP_STR
7003 "Display VPNv4 NLRI specific information\n"
7004 "Display information about all VPNv4 NLRIs\n"
7005 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7006{
7007 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
7008}
7009
7010DEFUN (show_ip_bgp_vpnv4_rd_prefix,
7011 show_ip_bgp_vpnv4_rd_prefix_cmd,
7012 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7013 SHOW_STR
7014 IP_STR
7015 BGP_STR
7016 "Display VPNv4 NLRI specific information\n"
7017 "Display information for a route distinguisher\n"
7018 "VPN Route Distinguisher\n"
7019 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7020{
7021 int ret;
7022 struct prefix_rd prd;
7023
7024 ret = str2prefix_rd (argv[0], &prd);
7025 if (! ret)
7026 {
7027 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7028 return CMD_WARNING;
7029 }
7030 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
7031}
7032
7033DEFUN (show_ip_bgp_view,
7034 show_ip_bgp_view_cmd,
7035 "show ip bgp view WORD",
7036 SHOW_STR
7037 IP_STR
7038 BGP_STR
7039 "BGP view\n"
7040 "View name\n")
7041{
7042 struct bgp *bgp;
7043
7044 /* BGP structure lookup. */
7045 bgp = bgp_lookup_by_name (argv[0]);
7046 if (bgp == NULL)
7047 {
7048 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7049 return CMD_WARNING;
7050 }
7051
7052 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
7053}
7054
7055DEFUN (show_ip_bgp_view_route,
7056 show_ip_bgp_view_route_cmd,
7057 "show ip bgp view WORD A.B.C.D",
7058 SHOW_STR
7059 IP_STR
7060 BGP_STR
7061 "BGP view\n"
7062 "View name\n"
7063 "Network in the BGP routing table to display\n")
7064{
7065 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
7066}
7067
7068DEFUN (show_ip_bgp_view_prefix,
7069 show_ip_bgp_view_prefix_cmd,
7070 "show ip bgp view WORD A.B.C.D/M",
7071 SHOW_STR
7072 IP_STR
7073 BGP_STR
7074 "BGP view\n"
7075 "View name\n"
7076 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7077{
7078 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
7079}
7080
7081DEFUN (show_bgp,
7082 show_bgp_cmd,
7083 "show bgp",
7084 SHOW_STR
7085 BGP_STR)
7086{
7087 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7088 NULL);
7089}
7090
7091ALIAS (show_bgp,
7092 show_bgp_ipv6_cmd,
7093 "show bgp ipv6",
7094 SHOW_STR
7095 BGP_STR
7096 "Address family\n")
7097
7098/* old command */
7099DEFUN (show_ipv6_bgp,
7100 show_ipv6_bgp_cmd,
7101 "show ipv6 bgp",
7102 SHOW_STR
7103 IP_STR
7104 BGP_STR)
7105{
7106 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7107 NULL);
7108}
7109
7110DEFUN (show_bgp_route,
7111 show_bgp_route_cmd,
7112 "show bgp X:X::X:X",
7113 SHOW_STR
7114 BGP_STR
7115 "Network in the BGP routing table to display\n")
7116{
7117 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7118}
7119
Lou Berger35c36862016-01-12 13:42:06 -05007120DEFUN (show_bgp_ipv4_safi,
7121 show_bgp_ipv4_safi_cmd,
7122 "show bgp ipv4 (unicast|multicast)",
paul718e3742002-12-13 20:15:29 +00007123 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007124 BGP_STR
7125 "Address family\n"
7126 "Address Family modifier\n"
7127 "Address Family modifier\n")
7128{
7129 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00007130 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
7131 NULL);
paul718e3742002-12-13 20:15:29 +00007132
ajs5a646652004-11-05 01:25:55 +00007133 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00007134}
7135
Lou Berger35c36862016-01-12 13:42:06 -05007136DEFUN (show_bgp_ipv4_safi_route,
7137 show_bgp_ipv4_safi_route_cmd,
7138 "show bgp ipv4 (unicast|multicast) A.B.C.D",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007139 SHOW_STR
7140 BGP_STR
7141 "Address family\n"
7142 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00007143 "Address Family modifier\n"
7144 "Network in the BGP routing table to display\n")
7145{
7146 if (strncmp (argv[0], "m", 1) == 0)
7147 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
7148
7149 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
7150}
7151
Lou Berger35c36862016-01-12 13:42:06 -05007152DEFUN (show_bgp_ipv4_vpn_route,
7153 show_bgp_ipv4_vpn_route_cmd,
7154 "show bgp ipv4 vpn A.B.C.D",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007155 SHOW_STR
7156 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007157 "Address Family\n"
7158 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +00007159 "Network in the BGP routing table to display\n")
7160{
7161 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
7162}
7163
Lou Berger35c36862016-01-12 13:42:06 -05007164DEFUN (show_bgp_ipv6_vpn_route,
7165 show_bgp_ipv6_vpn_route_cmd,
7166 "show bgp ipv6 vpn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007167 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007168 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007169 "Address Family\n"
7170 "Display VPN NLRI specific information\n"
7171 "Network in the BGP routing table to display\n")
7172{
7173 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MPLS_VPN, NULL, 0);
7174}
Lou Berger35c36862016-01-12 13:42:06 -05007175
7176DEFUN (show_bgp_ipv4_vpn_rd_route,
7177 show_bgp_ipv4_vpn_rd_route_cmd,
7178 "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn A.B.C.D",
7179 SHOW_STR
7180 BGP_STR
7181 IP_STR
7182 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +00007183 "Display information for a route distinguisher\n"
7184 "VPN Route Distinguisher\n"
7185 "Network in the BGP routing table to display\n")
7186{
7187 int ret;
7188 struct prefix_rd prd;
7189
7190 ret = str2prefix_rd (argv[0], &prd);
7191 if (! ret)
7192 {
7193 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7194 return CMD_WARNING;
7195 }
7196 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
7197}
7198
Lou Berger35c36862016-01-12 13:42:06 -05007199DEFUN (show_bgp_ipv6_vpn_rd_route,
7200 show_bgp_ipv6_vpn_rd_route_cmd,
7201 "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007202 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007203 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007204 "Address Family\n"
7205 "Display VPN NLRI specific information\n"
7206 "Display information for a route distinguisher\n"
7207 "VPN Route Distinguisher\n"
7208 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007209{
Lou Berger35c36862016-01-12 13:42:06 -05007210 int ret;
7211 struct prefix_rd prd;
7212
7213 ret = str2prefix_rd (argv[0], &prd);
7214 if (! ret)
7215 {
7216 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7217 return CMD_WARNING;
7218 }
7219 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MPLS_VPN, &prd, 0);
paul718e3742002-12-13 20:15:29 +00007220}
7221
Lou Berger651b4022016-01-12 13:42:07 -05007222DEFUN (show_bgp_ipv4_encap_route,
7223 show_bgp_ipv4_encap_route_cmd,
7224 "show bgp ipv4 encap A.B.C.D",
paul718e3742002-12-13 20:15:29 +00007225 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007226 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007227 IP_STR
7228 "Display ENCAP NLRI specific information\n"
7229 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007230{
Lou Berger651b4022016-01-12 13:42:07 -05007231 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 0);
paul718e3742002-12-13 20:15:29 +00007232}
7233
Lou Berger651b4022016-01-12 13:42:07 -05007234DEFUN (show_bgp_ipv6_encap_route,
7235 show_bgp_ipv6_encap_route_cmd,
7236 "show bgp ipv6 encap X:X::X:X",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007237 SHOW_STR
7238 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007239 IP6_STR
7240 "Display ENCAP NLRI specific information\n"
7241 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007242{
Lou Berger651b4022016-01-12 13:42:07 -05007243 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 0);
paul718e3742002-12-13 20:15:29 +00007244}
7245
Lou Berger651b4022016-01-12 13:42:07 -05007246DEFUN (show_bgp_ipv4_safi_rd_route,
7247 show_bgp_ipv4_safi_rd_route_cmd,
7248 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D",
paul718e3742002-12-13 20:15:29 +00007249 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007250 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007251 "Address Family\n"
7252 "Address Family Modifier\n"
7253 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00007254 "Display information for a route distinguisher\n"
Lou Berger651b4022016-01-12 13:42:07 -05007255 "ENCAP Route Distinguisher\n"
7256 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007257{
7258 int ret;
7259 struct prefix_rd prd;
Lou Berger651b4022016-01-12 13:42:07 -05007260 safi_t safi;
paul718e3742002-12-13 20:15:29 +00007261
Lou Berger651b4022016-01-12 13:42:07 -05007262 if (bgp_parse_safi(argv[0], &safi)) {
7263 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7264 return CMD_WARNING;
7265 }
7266 ret = str2prefix_rd (argv[1], &prd);
paul718e3742002-12-13 20:15:29 +00007267 if (! ret)
7268 {
7269 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7270 return CMD_WARNING;
7271 }
Lou Berger651b4022016-01-12 13:42:07 -05007272 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 0);
paul718e3742002-12-13 20:15:29 +00007273}
7274
Lou Berger651b4022016-01-12 13:42:07 -05007275DEFUN (show_bgp_ipv6_safi_rd_route,
7276 show_bgp_ipv6_safi_rd_route_cmd,
7277 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007278 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007279 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007280 "Address Family\n"
7281 "Address Family Modifier\n"
7282 "Address Family Modifier\n"
7283 "Display information for a route distinguisher\n"
7284 "ENCAP Route Distinguisher\n"
7285 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007286{
Lou Berger651b4022016-01-12 13:42:07 -05007287 int ret;
7288 struct prefix_rd prd;
7289 safi_t safi;
paulbb46e942003-10-24 19:02:03 +00007290
Lou Berger651b4022016-01-12 13:42:07 -05007291 if (bgp_parse_safi(argv[0], &safi)) {
7292 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7293 return CMD_WARNING;
7294 }
7295 ret = str2prefix_rd (argv[1], &prd);
7296 if (! ret)
7297 {
7298 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7299 return CMD_WARNING;
7300 }
7301 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, SAFI_ENCAP, &prd, 0);
paul718e3742002-12-13 20:15:29 +00007302}
7303
Lou Berger35c36862016-01-12 13:42:06 -05007304DEFUN (show_bgp_ipv4_prefix,
7305 show_bgp_ipv4_prefix_cmd,
7306 "show bgp ipv4 A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007307 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007308 BGP_STR
paul718e3742002-12-13 20:15:29 +00007309 IP_STR
paul718e3742002-12-13 20:15:29 +00007310 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7311{
Lou Berger35c36862016-01-12 13:42:06 -05007312 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
paul718e3742002-12-13 20:15:29 +00007313}
7314
Lou Berger35c36862016-01-12 13:42:06 -05007315DEFUN (show_bgp_ipv4_safi_prefix,
7316 show_bgp_ipv4_safi_prefix_cmd,
7317 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007318 SHOW_STR
7319 BGP_STR
7320 "Address family\n"
7321 "Address Family modifier\n"
Lou Berger35c36862016-01-12 13:42:06 -05007322 "Address Family modifier\n"
7323 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007324{
7325 if (strncmp (argv[0], "m", 1) == 0)
Lou Berger35c36862016-01-12 13:42:06 -05007326 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007327
Lou Berger35c36862016-01-12 13:42:06 -05007328 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007329}
7330
Lou Berger35c36862016-01-12 13:42:06 -05007331DEFUN (show_bgp_ipv4_vpn_prefix,
7332 show_bgp_ipv4_vpn_prefix_cmd,
7333 "show bgp ipv4 vpn A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007334 SHOW_STR
7335 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007336 IP_STR
7337 "Display VPN NLRI specific information\n"
7338 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paul718e3742002-12-13 20:15:29 +00007339{
Lou Berger35c36862016-01-12 13:42:06 -05007340 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
paul718e3742002-12-13 20:15:29 +00007341}
7342
Lou Berger35c36862016-01-12 13:42:06 -05007343DEFUN (show_bgp_ipv6_vpn_prefix,
7344 show_bgp_ipv6_vpn_prefix_cmd,
7345 "show bgp ipv6 vpn X:X::X:X/M",
7346 SHOW_STR
7347 BGP_STR
7348 "Address Family\n"
7349 "Display VPN NLRI specific information\n"
7350 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7351{
7352 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MPLS_VPN, NULL, 1);
7353}
Lou Berger35c36862016-01-12 13:42:06 -05007354
Lou Berger651b4022016-01-12 13:42:07 -05007355DEFUN (show_bgp_ipv4_encap_prefix,
7356 show_bgp_ipv4_encap_prefix_cmd,
7357 "show bgp ipv4 encap A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007358 SHOW_STR
7359 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007360 IP_STR
7361 "Display ENCAP NLRI specific information\n"
7362 "Display information about ENCAP NLRIs\n"
7363 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7364{
7365 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 1);
7366}
paul718e3742002-12-13 20:15:29 +00007367
Lou Berger651b4022016-01-12 13:42:07 -05007368DEFUN (show_bgp_ipv6_encap_prefix,
7369 show_bgp_ipv6_encap_prefix_cmd,
7370 "show bgp ipv6 encap X:X::X:X/M",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007371 SHOW_STR
7372 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007373 IP_STR
7374 "Display ENCAP NLRI specific information\n"
7375 "Display information about ENCAP NLRIs\n"
7376 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7377{
7378 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 1);
7379}
Lou Berger651b4022016-01-12 13:42:07 -05007380
7381DEFUN (show_bgp_ipv4_safi_rd_prefix,
7382 show_bgp_ipv4_safi_rd_prefix_cmd,
7383 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7384 SHOW_STR
7385 BGP_STR
7386 "Address Family\n"
7387 "Address Family Modifier\n"
7388 "Address Family Modifier\n"
7389 "Display information for a route distinguisher\n"
7390 "ENCAP Route Distinguisher\n"
7391 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7392{
7393 int ret;
7394 struct prefix_rd prd;
7395 safi_t safi;
7396
7397 if (bgp_parse_safi(argv[0], &safi)) {
7398 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7399 return CMD_WARNING;
7400 }
7401
7402 ret = str2prefix_rd (argv[1], &prd);
7403 if (! ret)
7404 {
7405 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7406 return CMD_WARNING;
7407 }
7408 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 1);
7409}
7410
Lou Berger651b4022016-01-12 13:42:07 -05007411DEFUN (show_bgp_ipv6_safi_rd_prefix,
7412 show_bgp_ipv6_safi_rd_prefix_cmd,
7413 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X/M",
7414 SHOW_STR
7415 BGP_STR
7416 "Address Family\n"
7417 "Address Family Modifier\n"
7418 "Address Family Modifier\n"
7419 "Display information for a route distinguisher\n"
7420 "ENCAP Route Distinguisher\n"
7421 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7422{
7423 int ret;
7424 struct prefix_rd prd;
7425 safi_t safi;
7426
7427 if (bgp_parse_safi(argv[0], &safi)) {
7428 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7429 return CMD_WARNING;
7430 }
7431
7432 ret = str2prefix_rd (argv[1], &prd);
7433 if (! ret)
7434 {
7435 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7436 return CMD_WARNING;
7437 }
7438 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, safi, &prd, 1);
7439}
Lou Berger651b4022016-01-12 13:42:07 -05007440
7441DEFUN (show_bgp_afi_safi_view,
7442 show_bgp_afi_safi_view_cmd,
7443 "show bgp view WORD (ipv4|ipv6) (encap|mulicast|unicast|vpn)",
7444 SHOW_STR
7445 BGP_STR
7446 "BGP view\n"
7447 "BGP view name\n"
7448 "Address Family\n"
7449 "Address Family\n"
7450 "Address Family Modifier\n"
7451 "Address Family Modifier\n"
7452 "Address Family Modifier\n"
7453 "Address Family Modifier\n"
7454 )
7455{
7456 struct bgp *bgp;
7457 safi_t safi;
7458 afi_t afi;
7459
7460 if (bgp_parse_afi(argv[1], &afi)) {
7461 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7462 return CMD_WARNING;
7463 }
7464 if (bgp_parse_safi(argv[2], &safi)) {
7465 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7466 return CMD_WARNING;
7467 }
7468
7469 /* BGP structure lookup. */
7470 bgp = bgp_lookup_by_name (argv[0]);
7471 if (bgp == NULL)
7472 {
7473 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7474 return CMD_WARNING;
7475 }
7476
7477 return bgp_show (vty, bgp, afi, safi, bgp_show_type_normal, NULL);
7478}
7479
7480DEFUN (show_bgp_view_afi_safi_route,
7481 show_bgp_view_afi_safi_route_cmd,
7482 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) A.B.C.D",
7483 SHOW_STR
7484 BGP_STR
7485 "BGP view\n"
7486 "View name\n"
7487 "Address Family\n"
7488 "Address Family\n"
7489 "Address Family Modifier\n"
7490 "Address Family Modifier\n"
7491 "Address Family Modifier\n"
7492 "Address Family Modifier\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007493 "Network in the BGP routing table to display\n")
7494{
Lou Berger651b4022016-01-12 13:42:07 -05007495 safi_t safi;
7496 afi_t afi;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007497
Lou Berger651b4022016-01-12 13:42:07 -05007498 if (bgp_parse_afi(argv[1], &afi)) {
7499 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7500 return CMD_WARNING;
7501 }
7502 if (bgp_parse_safi(argv[2], &safi)) {
7503 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7504 return CMD_WARNING;
7505 }
7506 return bgp_show_route (vty, argv[0], argv[3], afi, safi, NULL, 0);
7507}
7508
7509DEFUN (show_bgp_view_afi_safi_prefix,
7510 show_bgp_view_afi_safi_prefix_cmd,
7511 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) A.B.C.D/M",
7512 SHOW_STR
7513 BGP_STR
7514 "BGP view\n"
7515 "View name\n"
7516 "Address Family\n"
7517 "Address Family\n"
7518 "Address Family Modifier\n"
7519 "Address Family Modifier\n"
7520 "Address Family Modifier\n"
7521 "Address Family Modifier\n"
7522 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7523{
7524 safi_t safi;
7525 afi_t afi;
7526
7527 if (bgp_parse_afi(argv[1], &afi)) {
7528 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7529 return CMD_WARNING;
7530 }
7531 if (bgp_parse_safi(argv[2], &safi)) {
7532 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7533 return CMD_WARNING;
7534 }
7535 return bgp_show_route (vty, argv[0], argv[3], afi, safi, NULL, 1);
7536}
7537
7538/* new001 */
7539DEFUN (show_bgp_afi,
7540 show_bgp_afi_cmd,
7541 "show bgp (ipv4|ipv6)",
7542 SHOW_STR
7543 BGP_STR
7544 "Address family\n"
7545 "Address family\n")
7546{
7547 afi_t afi;
7548
7549 if (bgp_parse_afi(argv[0], &afi)) {
7550 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7551 return CMD_WARNING;
7552 }
7553 return bgp_show (vty, NULL, afi, SAFI_UNICAST, bgp_show_type_normal,
7554 NULL);
7555}
7556
Lou Berger651b4022016-01-12 13:42:07 -05007557DEFUN (show_bgp_ipv6_safi,
7558 show_bgp_ipv6_safi_cmd,
7559 "show bgp ipv6 (unicast|multicast)",
7560 SHOW_STR
7561 BGP_STR
7562 "Address family\n"
7563 "Address Family modifier\n"
7564 "Address Family modifier\n")
7565{
7566 if (strncmp (argv[0], "m", 1) == 0)
7567 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7568 NULL);
7569
7570 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007571}
7572
Lou Berger35c36862016-01-12 13:42:06 -05007573DEFUN (show_bgp_ipv6_route,
7574 show_bgp_ipv6_route_cmd,
7575 "show bgp ipv6 X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007576 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007577 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007578 "Address family\n"
paul718e3742002-12-13 20:15:29 +00007579 "Network in the BGP routing table to display\n")
7580{
7581 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7582}
7583
Lou Berger35c36862016-01-12 13:42:06 -05007584DEFUN (show_bgp_ipv6_safi_route,
7585 show_bgp_ipv6_safi_route_cmd,
7586 "show bgp ipv6 (unicast|multicast) X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007587 SHOW_STR
7588 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007589 "Address family\n"
7590 "Address Family modifier\n"
7591 "Address Family modifier\n"
7592 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007593{
Lou Berger35c36862016-01-12 13:42:06 -05007594 if (strncmp (argv[0], "m", 1) == 0)
7595 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7596
7597 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
paul718e3742002-12-13 20:15:29 +00007598}
7599
Lou Bergerf9b6c392016-01-12 13:42:09 -05007600/* old command */
7601DEFUN (show_ipv6_bgp_route,
7602 show_ipv6_bgp_route_cmd,
7603 "show ipv6 bgp X:X::X:X",
7604 SHOW_STR
7605 IP_STR
7606 BGP_STR
7607 "Network in the BGP routing table to display\n")
7608{
7609 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7610}
7611
7612DEFUN (show_bgp_prefix,
7613 show_bgp_prefix_cmd,
7614 "show bgp X:X::X:X/M",
7615 SHOW_STR
7616 BGP_STR
7617 "IPv6 prefix <network>/<length>\n")
7618{
7619 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7620}
7621
7622
Lou Berger35c36862016-01-12 13:42:06 -05007623/* new002 */
7624DEFUN (show_bgp_ipv6_prefix,
paul718e3742002-12-13 20:15:29 +00007625 show_bgp_ipv6_prefix_cmd,
7626 "show bgp ipv6 X:X::X:X/M",
7627 SHOW_STR
7628 BGP_STR
7629 "Address family\n"
Lou Berger35c36862016-01-12 13:42:06 -05007630 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7631{
7632 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7633}
Michael Lambert95cbbd22010-07-23 14:43:04 -04007634DEFUN (show_bgp_ipv6_safi_prefix,
7635 show_bgp_ipv6_safi_prefix_cmd,
7636 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
7637 SHOW_STR
7638 BGP_STR
7639 "Address family\n"
7640 "Address Family modifier\n"
7641 "Address Family modifier\n"
7642 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7643{
7644 if (strncmp (argv[0], "m", 1) == 0)
7645 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7646
7647 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7648}
7649
Lou Bergerf9b6c392016-01-12 13:42:09 -05007650/* old command */
7651DEFUN (show_ipv6_bgp_prefix,
7652 show_ipv6_bgp_prefix_cmd,
7653 "show ipv6 bgp X:X::X:X/M",
7654 SHOW_STR
7655 IP_STR
7656 BGP_STR
7657 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7658{
7659 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7660}
7661
paulbb46e942003-10-24 19:02:03 +00007662DEFUN (show_bgp_view,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007663 show_bgp_view_cmd,
7664 "show bgp view WORD",
7665 SHOW_STR
7666 BGP_STR
7667 "BGP view\n"
7668 "View name\n")
7669{
7670 struct bgp *bgp;
7671
7672 /* BGP structure lookup. */
7673 bgp = bgp_lookup_by_name (argv[0]);
7674 if (bgp == NULL)
7675 {
7676 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7677 return CMD_WARNING;
7678 }
7679
7680 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
7681}
7682
7683DEFUN (show_bgp_view_ipv6,
Lou Berger35c36862016-01-12 13:42:06 -05007684 show_bgp_view_ipv6_cmd,
7685 "show bgp view WORD ipv6",
paulbb46e942003-10-24 19:02:03 +00007686 SHOW_STR
Lou Berger35c36862016-01-12 13:42:06 -05007687 BGP_STR
paulbb46e942003-10-24 19:02:03 +00007688 "BGP view\n"
Lou Berger35c36862016-01-12 13:42:06 -05007689 "View name\n"
7690 "Address family\n")
paulbb46e942003-10-24 19:02:03 +00007691{
7692 struct bgp *bgp;
7693
7694 /* BGP structure lookup. */
7695 bgp = bgp_lookup_by_name (argv[0]);
7696 if (bgp == NULL)
7697 {
7698 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7699 return CMD_WARNING;
7700 }
7701
ajs5a646652004-11-05 01:25:55 +00007702 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007703}
paulbb46e942003-10-24 19:02:03 +00007704
7705DEFUN (show_bgp_view_route,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007706 show_bgp_view_route_cmd,
7707 "show bgp view WORD X:X::X:X",
7708 SHOW_STR
7709 BGP_STR
7710 "BGP view\n"
7711 "View name\n"
7712 "Network in the BGP routing table to display\n")
7713{
7714 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7715}
7716
7717DEFUN (show_bgp_view_ipv6_route,
paulbb46e942003-10-24 19:02:03 +00007718 show_bgp_view_ipv6_route_cmd,
7719 "show bgp view WORD ipv6 X:X::X:X",
7720 SHOW_STR
7721 BGP_STR
7722 "BGP view\n"
7723 "View name\n"
7724 "Address family\n"
7725 "Network in the BGP routing table to display\n")
paulbb46e942003-10-24 19:02:03 +00007726{
Lou Berger35c36862016-01-12 13:42:06 -05007727 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
paulbb46e942003-10-24 19:02:03 +00007728}
7729
Lou Bergerf9b6c392016-01-12 13:42:09 -05007730/* old command */
7731DEFUN (show_ipv6_mbgp,
7732 show_ipv6_mbgp_cmd,
7733 "show ipv6 mbgp",
7734 SHOW_STR
7735 IP_STR
7736 MBGP_STR)
7737{
7738 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7739 NULL);
7740}
7741
7742/* old command */
7743DEFUN (show_ipv6_mbgp_route,
7744 show_ipv6_mbgp_route_cmd,
7745 "show ipv6 mbgp X:X::X:X",
7746 SHOW_STR
7747 IP_STR
7748 MBGP_STR
7749 "Network in the MBGP routing table to display\n")
7750{
7751 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7752}
7753
7754/* old command */
7755DEFUN (show_ipv6_mbgp_prefix,
7756 show_ipv6_mbgp_prefix_cmd,
7757 "show ipv6 mbgp X:X::X:X/M",
7758 SHOW_STR
7759 IP_STR
7760 MBGP_STR
7761 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7762{
7763 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7764}
7765
Lou Berger35c36862016-01-12 13:42:06 -05007766DEFUN (show_bgp_view_prefix,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007767 show_bgp_view_prefix_cmd,
7768 "show bgp view WORD X:X::X:X/M",
7769 SHOW_STR
7770 BGP_STR
7771 "BGP view\n"
7772 "View name\n"
7773 "IPv6 prefix <network>/<length>\n")
7774{
7775 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7776}
7777
7778DEFUN (show_bgp_view_ipv6_prefix,
paulbb46e942003-10-24 19:02:03 +00007779 show_bgp_view_ipv6_prefix_cmd,
7780 "show bgp view WORD ipv6 X:X::X:X/M",
7781 SHOW_STR
7782 BGP_STR
7783 "BGP view\n"
7784 "View name\n"
7785 "Address family\n"
7786 "IPv6 prefix <network>/<length>\n")
paul718e3742002-12-13 20:15:29 +00007787{
Lou Berger35c36862016-01-12 13:42:06 -05007788 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
paul718e3742002-12-13 20:15:29 +00007789}
7790
paul94f2b392005-06-28 12:44:16 +00007791static int
paulfd79ac92004-10-13 05:06:08 +00007792bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007793 safi_t safi, enum bgp_show_type type)
7794{
7795 int i;
7796 struct buffer *b;
7797 char *regstr;
7798 int first;
7799 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007800 int rc;
paul718e3742002-12-13 20:15:29 +00007801
7802 first = 0;
7803 b = buffer_new (1024);
7804 for (i = 0; i < argc; i++)
7805 {
7806 if (first)
7807 buffer_putc (b, ' ');
7808 else
7809 {
7810 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7811 continue;
7812 first = 1;
7813 }
7814
7815 buffer_putstr (b, argv[i]);
7816 }
7817 buffer_putc (b, '\0');
7818
7819 regstr = buffer_getstr (b);
7820 buffer_free (b);
7821
7822 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007823 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007824 if (! regex)
7825 {
7826 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7827 VTY_NEWLINE);
7828 return CMD_WARNING;
7829 }
7830
ajs5a646652004-11-05 01:25:55 +00007831 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7832 bgp_regex_free (regex);
7833 return rc;
paul718e3742002-12-13 20:15:29 +00007834}
7835
Lou Bergerf9b6c392016-01-12 13:42:09 -05007836
7837DEFUN (show_ip_bgp_regexp,
7838 show_ip_bgp_regexp_cmd,
7839 "show ip bgp regexp .LINE",
7840 SHOW_STR
7841 IP_STR
7842 BGP_STR
7843 "Display routes matching the AS path regular expression\n"
7844 "A regular-expression to match the BGP AS paths\n")
7845{
7846 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7847 bgp_show_type_regexp);
7848}
7849
7850DEFUN (show_ip_bgp_flap_regexp,
7851 show_ip_bgp_flap_regexp_cmd,
7852 "show ip bgp flap-statistics regexp .LINE",
7853 SHOW_STR
7854 IP_STR
7855 BGP_STR
7856 "Display flap statistics of routes\n"
7857 "Display routes matching the AS path regular expression\n"
7858 "A regular-expression to match the BGP AS paths\n")
7859{
7860 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7861 bgp_show_type_flap_regexp);
7862}
7863
7864ALIAS (show_ip_bgp_flap_regexp,
7865 show_ip_bgp_damp_flap_regexp_cmd,
7866 "show ip bgp dampening flap-statistics regexp .LINE",
7867 SHOW_STR
7868 IP_STR
7869 BGP_STR
7870 "Display detailed information about dampening\n"
7871 "Display flap statistics of routes\n"
7872 "Display routes matching the AS path regular expression\n"
7873 "A regular-expression to match the BGP AS paths\n")
7874
7875DEFUN (show_ip_bgp_ipv4_regexp,
7876 show_ip_bgp_ipv4_regexp_cmd,
7877 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7878 SHOW_STR
7879 IP_STR
7880 BGP_STR
7881 "Address family\n"
7882 "Address Family modifier\n"
7883 "Address Family modifier\n"
7884 "Display routes matching the AS path regular expression\n"
7885 "A regular-expression to match the BGP AS paths\n")
7886{
7887 if (strncmp (argv[0], "m", 1) == 0)
7888 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7889 bgp_show_type_regexp);
7890
7891 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7892 bgp_show_type_regexp);
7893}
7894
Lou Bergerf9b6c392016-01-12 13:42:09 -05007895DEFUN (show_bgp_regexp,
7896 show_bgp_regexp_cmd,
7897 "show bgp regexp .LINE",
7898 SHOW_STR
7899 BGP_STR
7900 "Display routes matching the AS path regular expression\n"
7901 "A regular-expression to match the BGP AS paths\n")
7902{
7903 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7904 bgp_show_type_regexp);
7905}
7906
7907/* old command */
7908DEFUN (show_ipv6_bgp_regexp,
7909 show_ipv6_bgp_regexp_cmd,
7910 "show ipv6 bgp regexp .LINE",
7911 SHOW_STR
7912 IP_STR
7913 BGP_STR
7914 "Display routes matching the AS path regular expression\n"
7915 "A regular-expression to match the BGP AS paths\n")
7916{
7917 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7918 bgp_show_type_regexp);
7919}
7920
7921/* old command */
7922DEFUN (show_ipv6_mbgp_regexp,
7923 show_ipv6_mbgp_regexp_cmd,
7924 "show ipv6 mbgp regexp .LINE",
7925 SHOW_STR
7926 IP_STR
7927 BGP_STR
7928 "Display routes matching the AS path regular expression\n"
7929 "A regular-expression to match the MBGP AS paths\n")
7930{
7931 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7932 bgp_show_type_regexp);
7933}
Lou Bergerf9b6c392016-01-12 13:42:09 -05007934
Lou Berger651b4022016-01-12 13:42:07 -05007935DEFUN (show_bgp_ipv4_safi_flap_regexp,
7936 show_bgp_ipv4_safi_flap_regexp_cmd,
7937 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics regexp .LINE",
paul718e3742002-12-13 20:15:29 +00007938 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007939 BGP_STR
paul718e3742002-12-13 20:15:29 +00007940 IP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007941 "Address Family Modifier\n"
7942 "Address Family Modifier\n"
7943 "Address Family Modifier\n"
7944 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00007945 "Display flap statistics of routes\n"
7946 "Display routes matching the AS path regular expression\n"
7947 "A regular-expression to match the BGP AS paths\n")
7948{
Lou Berger651b4022016-01-12 13:42:07 -05007949 safi_t safi;
7950
7951 if (bgp_parse_safi(argv[0], &safi)) {
7952 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7953 return CMD_WARNING;
7954 }
7955 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP, safi,
7956 bgp_show_type_flap_regexp);
paul718e3742002-12-13 20:15:29 +00007957}
7958
Lou Berger651b4022016-01-12 13:42:07 -05007959ALIAS (show_bgp_ipv4_safi_flap_regexp,
7960 show_bgp_ipv4_safi_damp_flap_regexp_cmd,
7961 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics regexp .LINE",
Balaji3921cc52015-05-16 23:12:17 +05307962 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05307963 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007964 IP_STR
7965 "Address Family Modifier\n"
7966 "Address Family Modifier\n"
7967 "Address Family Modifier\n"
7968 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05307969 "Display detailed information about dampening\n"
7970 "Display flap statistics of routes\n"
7971 "Display routes matching the AS path regular expression\n"
7972 "A regular-expression to match the BGP AS paths\n")
7973
Lou Berger651b4022016-01-12 13:42:07 -05007974DEFUN (show_bgp_ipv6_safi_flap_regexp,
7975 show_bgp_ipv6_safi_flap_regexp_cmd,
7976 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics regexp .LINE",
paul718e3742002-12-13 20:15:29 +00007977 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05007978 BGP_STR
7979 IPV6_STR
7980 "Address Family Modifier\n"
7981 "Address Family Modifier\n"
7982 "Address Family Modifier\n"
7983 "Address Family Modifier\n"
7984 "Display flap statistics of routes\n"
7985 "Display routes matching the AS path regular expression\n"
7986 "A regular-expression to match the BGP AS paths\n")
7987{
7988 safi_t safi;
7989
7990 if (bgp_parse_safi(argv[0], &safi)) {
7991 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7992 return CMD_WARNING;
7993 }
7994 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP6, safi,
7995 bgp_show_type_flap_regexp);
7996}
7997
7998ALIAS (show_bgp_ipv6_safi_flap_regexp,
7999 show_bgp_ipv6_safi_damp_flap_regexp_cmd,
8000 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics regexp .LINE",
8001 SHOW_STR
8002 BGP_STR
8003 IPV6_STR
8004 "Address Family Modifier\n"
8005 "Address Family Modifier\n"
8006 "Address Family Modifier\n"
8007 "Address Family Modifier\n"
8008 "Display detailed information about dampening\n"
8009 "Display flap statistics of routes\n"
8010 "Display routes matching the AS path regular expression\n"
8011 "A regular-expression to match the BGP AS paths\n")
Lou Berger651b4022016-01-12 13:42:07 -05008012
8013DEFUN (show_bgp_ipv4_safi_regexp,
8014 show_bgp_ipv4_safi_regexp_cmd,
8015 "show bgp ipv4 (encap|multicast|unicast|vpn) regexp .LINE",
8016 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008017 BGP_STR
8018 "Address family\n"
8019 "Address Family modifier\n"
8020 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05008021 "Address Family modifier\n"
8022 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008023 "Display routes matching the AS path regular expression\n"
8024 "A regular-expression to match the BGP AS paths\n")
8025{
Lou Berger651b4022016-01-12 13:42:07 -05008026 safi_t safi;
8027 if (bgp_parse_safi(argv[0], &safi)) {
8028 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8029 return CMD_WARNING;
8030 }
paul718e3742002-12-13 20:15:29 +00008031
Lou Berger651b4022016-01-12 13:42:07 -05008032 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008033 bgp_show_type_regexp);
8034}
Lou Berger205e6742016-01-12 13:42:11 -05008035
Lou Berger651b4022016-01-12 13:42:07 -05008036DEFUN (show_bgp_ipv6_safi_regexp,
8037 show_bgp_ipv6_safi_regexp_cmd,
8038 "show bgp ipv6 (encap|multicast|unicast|vpn) regexp .LINE",
paul718e3742002-12-13 20:15:29 +00008039 SHOW_STR
8040 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008041 "Address family\n"
8042 "Address Family modifier\n"
8043 "Address Family modifier\n"
8044 "Address Family modifier\n"
8045 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008046 "Display routes matching the AS path regular expression\n"
8047 "A regular-expression to match the BGP AS paths\n")
8048{
Lou Berger651b4022016-01-12 13:42:07 -05008049 safi_t safi;
8050 if (bgp_parse_safi(argv[0], &safi)) {
8051 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8052 return CMD_WARNING;
8053 }
8054
8055 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00008056 bgp_show_type_regexp);
8057}
8058
Lou Berger651b4022016-01-12 13:42:07 -05008059DEFUN (show_bgp_ipv6_regexp,
paul718e3742002-12-13 20:15:29 +00008060 show_bgp_ipv6_regexp_cmd,
8061 "show bgp ipv6 regexp .LINE",
8062 SHOW_STR
8063 BGP_STR
8064 "Address family\n"
8065 "Display routes matching the AS path regular expression\n"
8066 "A regular-expression to match the BGP AS paths\n")
paul718e3742002-12-13 20:15:29 +00008067{
8068 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8069 bgp_show_type_regexp);
8070}
8071
paul94f2b392005-06-28 12:44:16 +00008072static int
paulfd79ac92004-10-13 05:06:08 +00008073bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008074 safi_t safi, enum bgp_show_type type)
8075{
8076 struct prefix_list *plist;
8077
8078 plist = prefix_list_lookup (afi, prefix_list_str);
8079 if (plist == NULL)
8080 {
8081 vty_out (vty, "%% %s is not a valid prefix-list name%s",
8082 prefix_list_str, VTY_NEWLINE);
8083 return CMD_WARNING;
8084 }
8085
ajs5a646652004-11-05 01:25:55 +00008086 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00008087}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008088DEFUN (show_ip_bgp_prefix_list,
8089 show_ip_bgp_prefix_list_cmd,
8090 "show ip bgp prefix-list WORD",
8091 SHOW_STR
8092 IP_STR
8093 BGP_STR
8094 "Display routes conforming to the prefix-list\n"
8095 "IP prefix-list name\n")
8096{
8097 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8098 bgp_show_type_prefix_list);
8099}
8100
8101DEFUN (show_ip_bgp_flap_prefix_list,
8102 show_ip_bgp_flap_prefix_list_cmd,
8103 "show ip bgp flap-statistics prefix-list WORD",
8104 SHOW_STR
8105 IP_STR
8106 BGP_STR
8107 "Display flap statistics of routes\n"
8108 "Display routes conforming to the prefix-list\n"
8109 "IP prefix-list name\n")
8110{
8111 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8112 bgp_show_type_flap_prefix_list);
8113}
8114
8115ALIAS (show_ip_bgp_flap_prefix_list,
8116 show_ip_bgp_damp_flap_prefix_list_cmd,
8117 "show ip bgp dampening flap-statistics prefix-list WORD",
8118 SHOW_STR
8119 IP_STR
8120 BGP_STR
8121 "Display detailed information about dampening\n"
8122 "Display flap statistics of routes\n"
8123 "Display routes conforming to the prefix-list\n"
8124 "IP prefix-list name\n")
8125
8126DEFUN (show_ip_bgp_ipv4_prefix_list,
8127 show_ip_bgp_ipv4_prefix_list_cmd,
8128 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
8129 SHOW_STR
8130 IP_STR
8131 BGP_STR
8132 "Address family\n"
8133 "Address Family modifier\n"
8134 "Address Family modifier\n"
8135 "Display routes conforming to the prefix-list\n"
8136 "IP prefix-list name\n")
8137{
8138 if (strncmp (argv[0], "m", 1) == 0)
8139 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8140 bgp_show_type_prefix_list);
8141
8142 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8143 bgp_show_type_prefix_list);
8144}
8145
Lou Bergerf9b6c392016-01-12 13:42:09 -05008146DEFUN (show_bgp_prefix_list,
8147 show_bgp_prefix_list_cmd,
8148 "show bgp prefix-list WORD",
8149 SHOW_STR
8150 BGP_STR
8151 "Display routes conforming to the prefix-list\n"
8152 "IPv6 prefix-list name\n")
8153{
8154 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8155 bgp_show_type_prefix_list);
8156}
8157
8158ALIAS (show_bgp_prefix_list,
8159 show_bgp_ipv6_prefix_list_cmd,
8160 "show bgp ipv6 prefix-list WORD",
8161 SHOW_STR
8162 BGP_STR
8163 "Address family\n"
8164 "Display routes conforming to the prefix-list\n"
8165 "IPv6 prefix-list name\n")
8166
8167/* old command */
8168DEFUN (show_ipv6_bgp_prefix_list,
8169 show_ipv6_bgp_prefix_list_cmd,
8170 "show ipv6 bgp prefix-list WORD",
8171 SHOW_STR
8172 IPV6_STR
8173 BGP_STR
8174 "Display routes matching the prefix-list\n"
8175 "IPv6 prefix-list name\n")
8176{
8177 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8178 bgp_show_type_prefix_list);
8179}
8180
8181/* old command */
8182DEFUN (show_ipv6_mbgp_prefix_list,
8183 show_ipv6_mbgp_prefix_list_cmd,
8184 "show ipv6 mbgp prefix-list WORD",
8185 SHOW_STR
8186 IPV6_STR
8187 MBGP_STR
8188 "Display routes matching the prefix-list\n"
8189 "IPv6 prefix-list name\n")
8190{
8191 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8192 bgp_show_type_prefix_list);
8193}
paul718e3742002-12-13 20:15:29 +00008194
Lou Berger35c36862016-01-12 13:42:06 -05008195DEFUN (show_bgp_ipv4_prefix_list,
8196 show_bgp_ipv4_prefix_list_cmd,
8197 "show bgp ipv4 prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008198 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008199 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05008200 IP_STR
paul718e3742002-12-13 20:15:29 +00008201 "Display routes conforming to the prefix-list\n"
8202 "IP prefix-list name\n")
8203{
8204 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8205 bgp_show_type_prefix_list);
8206}
8207
Lou Berger651b4022016-01-12 13:42:07 -05008208DEFUN (show_bgp_ipv4_safi_flap_prefix_list,
8209 show_bgp_ipv4_safi_flap_prefix_list_cmd,
8210 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008211 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008212 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008213 IP_STR
8214 "Address Family Modifier\n"
8215 "Address Family Modifier\n"
8216 "Address Family Modifier\n"
8217 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00008218 "Display flap statistics of routes\n"
8219 "Display routes conforming to the prefix-list\n"
8220 "IP prefix-list name\n")
8221{
Lou Berger651b4022016-01-12 13:42:07 -05008222 safi_t safi;
8223 if (bgp_parse_safi(argv[0], &safi)) {
8224 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8225 return CMD_WARNING;
8226 }
8227 return bgp_show_prefix_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008228 bgp_show_type_flap_prefix_list);
8229}
8230
Lou Berger651b4022016-01-12 13:42:07 -05008231ALIAS (show_bgp_ipv4_safi_flap_prefix_list,
8232 show_bgp_ipv4_safi_damp_flap_prefix_list_cmd,
8233 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics prefix-list WORD",
Balaji3921cc52015-05-16 23:12:17 +05308234 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308235 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008236 IP_STR
8237 "Address Family Modifier\n"
8238 "Address Family Modifier\n"
8239 "Address Family Modifier\n"
8240 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308241 "Display detailed information about dampening\n"
8242 "Display flap statistics of routes\n"
8243 "Display routes conforming to the prefix-list\n"
8244 "IP prefix-list name\n")
8245
Lou Berger651b4022016-01-12 13:42:07 -05008246DEFUN (show_bgp_ipv6_safi_flap_prefix_list,
8247 show_bgp_ipv6_safi_flap_prefix_list_cmd,
8248 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008249 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05008250 BGP_STR
8251 IPV6_STR
8252 "Address Family Modifier\n"
8253 "Address Family Modifier\n"
8254 "Address Family Modifier\n"
8255 "Address Family Modifier\n"
8256 "Display flap statistics of routes\n"
8257 "Display routes conforming to the prefix-list\n"
8258 "IP prefix-list name\n")
8259{
8260 safi_t safi;
8261 if (bgp_parse_safi(argv[0], &safi)) {
8262 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8263 return CMD_WARNING;
8264 }
8265 return bgp_show_prefix_list (vty, argv[1], AFI_IP6, safi,
8266 bgp_show_type_flap_prefix_list);
8267}
8268ALIAS (show_bgp_ipv6_safi_flap_prefix_list,
8269 show_bgp_ipv6_safi_damp_flap_prefix_list_cmd,
8270 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics prefix-list WORD",
8271 SHOW_STR
8272 BGP_STR
8273 IPV6_STR
8274 "Address Family Modifier\n"
8275 "Address Family Modifier\n"
8276 "Address Family Modifier\n"
8277 "Address Family Modifier\n"
8278 "Display detailed information about dampening\n"
8279 "Display flap statistics of routes\n"
8280 "Display routes conforming to the prefix-list\n"
8281 "IP prefix-list name\n")
Lou Berger651b4022016-01-12 13:42:07 -05008282
8283DEFUN (show_bgp_ipv4_safi_prefix_list,
8284 show_bgp_ipv4_safi_prefix_list_cmd,
8285 "show bgp ipv4 (encap|multicast|unicast|vpn) prefix-list WORD",
8286 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008287 BGP_STR
8288 "Address family\n"
8289 "Address Family modifier\n"
8290 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05008291 "Address Family modifier\n"
8292 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008293 "Display routes conforming to the prefix-list\n"
8294 "IP prefix-list name\n")
8295{
Lou Berger651b4022016-01-12 13:42:07 -05008296 safi_t safi;
8297 if (bgp_parse_safi(argv[0], &safi)) {
8298 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8299 return CMD_WARNING;
8300 }
8301 return bgp_show_prefix_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008302 bgp_show_type_prefix_list);
8303}
Lou Berger205e6742016-01-12 13:42:11 -05008304
Lou Berger651b4022016-01-12 13:42:07 -05008305DEFUN (show_bgp_ipv6_safi_prefix_list,
8306 show_bgp_ipv6_safi_prefix_list_cmd,
8307 "show bgp ipv6 (encap|multicast|unicast|vpn) prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008308 SHOW_STR
8309 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008310 "Address family\n"
8311 "Address Family modifier\n"
8312 "Address Family modifier\n"
8313 "Address Family modifier\n"
8314 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008315 "Display routes conforming to the prefix-list\n"
Lou Berger651b4022016-01-12 13:42:07 -05008316 "IP prefix-list name\n")
paul718e3742002-12-13 20:15:29 +00008317{
Lou Berger651b4022016-01-12 13:42:07 -05008318 safi_t safi;
8319 if (bgp_parse_safi(argv[0], &safi)) {
8320 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8321 return CMD_WARNING;
8322 }
8323 return bgp_show_prefix_list (vty, argv[1], AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00008324 bgp_show_type_prefix_list);
8325}
8326
paul94f2b392005-06-28 12:44:16 +00008327static int
paulfd79ac92004-10-13 05:06:08 +00008328bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008329 safi_t safi, enum bgp_show_type type)
8330{
8331 struct as_list *as_list;
8332
8333 as_list = as_list_lookup (filter);
8334 if (as_list == NULL)
8335 {
8336 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
8337 return CMD_WARNING;
8338 }
8339
ajs5a646652004-11-05 01:25:55 +00008340 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00008341}
8342
Lou Bergerf9b6c392016-01-12 13:42:09 -05008343DEFUN (show_ip_bgp_filter_list,
8344 show_ip_bgp_filter_list_cmd,
8345 "show ip bgp filter-list WORD",
8346 SHOW_STR
8347 IP_STR
8348 BGP_STR
8349 "Display routes conforming to the filter-list\n"
8350 "Regular expression access list name\n")
8351{
8352 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8353 bgp_show_type_filter_list);
8354}
8355
8356DEFUN (show_ip_bgp_flap_filter_list,
8357 show_ip_bgp_flap_filter_list_cmd,
8358 "show ip bgp flap-statistics filter-list WORD",
8359 SHOW_STR
8360 IP_STR
8361 BGP_STR
8362 "Display flap statistics of routes\n"
8363 "Display routes conforming to the filter-list\n"
8364 "Regular expression access list name\n")
8365{
8366 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8367 bgp_show_type_flap_filter_list);
8368}
8369
8370ALIAS (show_ip_bgp_flap_filter_list,
8371 show_ip_bgp_damp_flap_filter_list_cmd,
8372 "show ip bgp dampening flap-statistics filter-list WORD",
8373 SHOW_STR
8374 IP_STR
8375 BGP_STR
8376 "Display detailed information about dampening\n"
8377 "Display flap statistics of routes\n"
8378 "Display routes conforming to the filter-list\n"
8379 "Regular expression access list name\n")
8380
8381DEFUN (show_ip_bgp_ipv4_filter_list,
8382 show_ip_bgp_ipv4_filter_list_cmd,
8383 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
8384 SHOW_STR
8385 IP_STR
8386 BGP_STR
8387 "Address family\n"
8388 "Address Family modifier\n"
8389 "Address Family modifier\n"
8390 "Display routes conforming to the filter-list\n"
8391 "Regular expression access list name\n")
8392{
8393 if (strncmp (argv[0], "m", 1) == 0)
8394 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8395 bgp_show_type_filter_list);
8396
8397 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8398 bgp_show_type_filter_list);
8399}
8400
Lou Bergerf9b6c392016-01-12 13:42:09 -05008401DEFUN (show_bgp_filter_list,
8402 show_bgp_filter_list_cmd,
8403 "show bgp filter-list WORD",
8404 SHOW_STR
8405 BGP_STR
8406 "Display routes conforming to the filter-list\n"
8407 "Regular expression access list name\n")
8408{
8409 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8410 bgp_show_type_filter_list);
8411}
8412
8413/* old command */
8414DEFUN (show_ipv6_bgp_filter_list,
8415 show_ipv6_bgp_filter_list_cmd,
8416 "show ipv6 bgp filter-list WORD",
8417 SHOW_STR
8418 IPV6_STR
8419 BGP_STR
8420 "Display routes conforming to the filter-list\n"
8421 "Regular expression access list name\n")
8422{
8423 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8424 bgp_show_type_filter_list);
8425}
8426
8427/* old command */
8428DEFUN (show_ipv6_mbgp_filter_list,
8429 show_ipv6_mbgp_filter_list_cmd,
8430 "show ipv6 mbgp filter-list WORD",
8431 SHOW_STR
8432 IPV6_STR
8433 MBGP_STR
8434 "Display routes conforming to the filter-list\n"
8435 "Regular expression access list name\n")
8436{
8437 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8438 bgp_show_type_filter_list);
8439}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008440
8441DEFUN (show_ip_bgp_dampening_info,
8442 show_ip_bgp_dampening_params_cmd,
8443 "show ip bgp dampening parameters",
8444 SHOW_STR
8445 IP_STR
8446 BGP_STR
8447 "Display detailed information about dampening\n"
8448 "Display detail of configured dampening parameters\n")
8449{
8450 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
8451}
8452
Lou Berger651b4022016-01-12 13:42:07 -05008453DEFUN (show_bgp_ipv4_filter_list,
8454 show_bgp_ipv4_filter_list_cmd,
8455 "show bgp ipv4 filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008456 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008457 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008458 IP_STR
paul718e3742002-12-13 20:15:29 +00008459 "Display routes conforming to the filter-list\n"
8460 "Regular expression access list name\n")
8461{
8462 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8463 bgp_show_type_filter_list);
8464}
8465
Lou Berger651b4022016-01-12 13:42:07 -05008466DEFUN (show_bgp_ipv4_safi_flap_filter_list,
8467 show_bgp_ipv4_safi_flap_filter_list_cmd,
8468 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008469 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008470 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008471 IP_STR
8472 "Address Family modifier\n"
8473 "Address Family modifier\n"
8474 "Address Family modifier\n"
8475 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008476 "Display flap statistics of routes\n"
8477 "Display routes conforming to the filter-list\n"
8478 "Regular expression access list name\n")
8479{
Lou Berger651b4022016-01-12 13:42:07 -05008480 safi_t safi;
8481
8482 if (bgp_parse_safi(argv[0], &safi)) {
8483 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8484 return CMD_WARNING;
8485 }
8486 return bgp_show_filter_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008487 bgp_show_type_flap_filter_list);
8488}
8489
Lou Berger651b4022016-01-12 13:42:07 -05008490ALIAS (show_bgp_ipv4_safi_flap_filter_list,
8491 show_bgp_ipv4_safi_damp_flap_filter_list_cmd,
8492 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics filter-list WORD",
Balaji3921cc52015-05-16 23:12:17 +05308493 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308494 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008495 IP_STR
8496 "Address Family modifier\n"
8497 "Address Family modifier\n"
8498 "Address Family modifier\n"
8499 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308500 "Display detailed information about dampening\n"
8501 "Display flap statistics of routes\n"
8502 "Display routes conforming to the filter-list\n"
8503 "Regular expression access list name\n")
8504
Lou Berger651b4022016-01-12 13:42:07 -05008505DEFUN (show_bgp_ipv6_safi_flap_filter_list,
8506 show_bgp_ipv6_safi_flap_filter_list_cmd,
8507 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008508 SHOW_STR
8509 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008510 IPV6_STR
8511 "Address Family modifier\n"
8512 "Address Family modifier\n"
8513 "Address Family modifier\n"
8514 "Address Family modifier\n"
8515 "Display flap statistics of routes\n"
paul718e3742002-12-13 20:15:29 +00008516 "Display routes conforming to the filter-list\n"
8517 "Regular expression access list name\n")
8518{
Lou Berger651b4022016-01-12 13:42:07 -05008519 safi_t safi;
8520
8521 if (bgp_parse_safi(argv[0], &safi)) {
8522 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8523 return CMD_WARNING;
8524 }
8525 return bgp_show_filter_list (vty, argv[1], AFI_IP6, safi,
8526 bgp_show_type_flap_filter_list);
8527}
8528ALIAS (show_bgp_ipv6_safi_flap_filter_list,
8529 show_bgp_ipv6_safi_damp_flap_filter_list_cmd,
8530 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics filter-list WORD",
8531 SHOW_STR
8532 BGP_STR
8533 IPV6_STR
8534 "Address Family modifier\n"
8535 "Address Family modifier\n"
8536 "Address Family modifier\n"
8537 "Address Family modifier\n"
8538 "Display detailed information about dampening\n"
8539 "Display flap statistics of routes\n"
8540 "Display routes conforming to the filter-list\n"
8541 "Regular expression access list name\n")
Lou Berger651b4022016-01-12 13:42:07 -05008542
8543DEFUN (show_bgp_ipv4_safi_filter_list,
8544 show_bgp_ipv4_safi_filter_list_cmd,
8545 "show bgp ipv4 (encap|multicast|unicast|vpn) filter-list WORD",
8546 SHOW_STR
8547 BGP_STR
8548 "Address Family modifier\n"
8549 "Address Family modifier\n"
8550 "Address Family modifier\n"
8551 "Address Family modifier\n"
8552 "Display routes conforming to the filter-list\n"
8553 "Regular expression access list name\n")
8554{
8555 safi_t safi;
8556
8557 if (bgp_parse_safi(argv[0], &safi)) {
8558 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8559 return CMD_WARNING;
8560 }
8561 return bgp_show_filter_list (vty, argv[1], AFI_IP, safi,
8562 bgp_show_type_filter_list);
8563}
Lou Berger205e6742016-01-12 13:42:11 -05008564
Lou Berger651b4022016-01-12 13:42:07 -05008565DEFUN (show_bgp_ipv6_safi_filter_list,
8566 show_bgp_ipv6_safi_filter_list_cmd,
8567 "show bgp ipv6 (encap|multicast|unicast|vpn) filter-list WORD",
8568 SHOW_STR
8569 BGP_STR
8570 "Address Family modifier\n"
8571 "Address Family modifier\n"
8572 "Address Family modifier\n"
8573 "Address Family modifier\n"
8574 "Display routes conforming to the filter-list\n"
8575 "Regular expression access list name\n")
8576{
8577 safi_t safi;
8578
8579 if (bgp_parse_safi(argv[0], &safi)) {
8580 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8581 return CMD_WARNING;
8582 }
8583 return bgp_show_filter_list (vty, argv[1], AFI_IP6, safi,
8584 bgp_show_type_filter_list);
paul718e3742002-12-13 20:15:29 +00008585}
8586
Lou Bergerf9b6c392016-01-12 13:42:09 -05008587DEFUN (show_bgp_ipv6_filter_list,
paul718e3742002-12-13 20:15:29 +00008588 show_bgp_ipv6_filter_list_cmd,
8589 "show bgp ipv6 filter-list WORD",
8590 SHOW_STR
8591 BGP_STR
8592 "Address family\n"
8593 "Display routes conforming to the filter-list\n"
8594 "Regular expression access list name\n")
paul718e3742002-12-13 20:15:29 +00008595{
8596 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8597 bgp_show_type_filter_list);
8598}
8599
Balaji9c52cae2016-01-20 22:59:26 +05308600
8601DEFUN (show_ip_bgp_ipv4_dampening_parameters,
8602 show_ip_bgp_ipv4_dampening_parameters_cmd,
8603 "show ip bgp ipv4 (unicast|multicast) dampening parameters",
8604 SHOW_STR
8605 IP_STR
8606 BGP_STR
8607 "Address family\n"
8608 "Address Family modifier\n"
8609 "Address Family modifier\n"
8610 "Display detailed information about dampening\n"
8611 "Display detail of configured dampening parameters\n")
8612{
8613 if (strncmp(argv[0], "m", 1) == 0)
8614 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_MULTICAST);
8615
8616 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
8617}
8618
8619
8620DEFUN (show_ip_bgp_ipv4_dampening_flap_stats,
8621 show_ip_bgp_ipv4_dampening_flap_stats_cmd,
8622 "show ip bgp ipv4 (unicast|multicast) dampening flap-statistics",
8623 SHOW_STR
8624 IP_STR
8625 BGP_STR
8626 "Address family\n"
8627 "Address Family modifier\n"
8628 "Address Family modifier\n"
8629 "Display detailed information about dampening\n"
8630 "Display flap statistics of routes\n")
8631{
8632 if (strncmp(argv[0], "m", 1) == 0)
8633 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8634 bgp_show_type_flap_statistics, NULL);
8635
8636 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8637 bgp_show_type_flap_statistics, NULL);
8638}
8639
8640DEFUN (show_ip_bgp_ipv4_dampening_dampd_paths,
8641 show_ip_bgp_ipv4_dampening_dampd_paths_cmd,
8642 "show ip bgp ipv4 (unicast|multicast) dampening dampened-paths",
8643 SHOW_STR
8644 IP_STR
8645 BGP_STR
8646 "Address family\n"
8647 "Address Family modifier\n"
8648 "Address Family modifier\n"
8649 "Display detailed information about dampening\n"
8650 "Display paths suppressed due to dampening\n")
8651{
8652 if (strncmp(argv[0], "m", 1) == 0)
8653 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8654 bgp_show_type_dampend_paths, NULL);
8655
8656 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8657 bgp_show_type_dampend_paths, NULL);
8658}
8659
paul94f2b392005-06-28 12:44:16 +00008660static int
paulfd79ac92004-10-13 05:06:08 +00008661bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008662 safi_t safi, enum bgp_show_type type)
8663{
8664 struct route_map *rmap;
8665
8666 rmap = route_map_lookup_by_name (rmap_str);
8667 if (! rmap)
8668 {
8669 vty_out (vty, "%% %s is not a valid route-map name%s",
8670 rmap_str, VTY_NEWLINE);
8671 return CMD_WARNING;
8672 }
8673
ajs5a646652004-11-05 01:25:55 +00008674 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00008675}
8676
Lou Bergerf9b6c392016-01-12 13:42:09 -05008677DEFUN (show_ip_bgp_route_map,
8678 show_ip_bgp_route_map_cmd,
8679 "show ip bgp route-map WORD",
8680 SHOW_STR
8681 IP_STR
8682 BGP_STR
8683 "Display routes matching the route-map\n"
8684 "A route-map to match on\n")
8685{
8686 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8687 bgp_show_type_route_map);
8688}
8689
8690DEFUN (show_ip_bgp_flap_route_map,
8691 show_ip_bgp_flap_route_map_cmd,
8692 "show ip bgp flap-statistics route-map WORD",
8693 SHOW_STR
8694 IP_STR
8695 BGP_STR
8696 "Display flap statistics of routes\n"
8697 "Display routes matching the route-map\n"
8698 "A route-map to match on\n")
8699{
8700 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8701 bgp_show_type_flap_route_map);
8702}
8703
8704ALIAS (show_ip_bgp_flap_route_map,
8705 show_ip_bgp_damp_flap_route_map_cmd,
8706 "show ip bgp dampening flap-statistics route-map WORD",
8707 SHOW_STR
8708 IP_STR
8709 BGP_STR
8710 "Display detailed information about dampening\n"
8711 "Display flap statistics of routes\n"
8712 "Display routes matching the route-map\n"
8713 "A route-map to match on\n")
8714
8715DEFUN (show_ip_bgp_ipv4_route_map,
8716 show_ip_bgp_ipv4_route_map_cmd,
8717 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
8718 SHOW_STR
8719 IP_STR
8720 BGP_STR
8721 "Address family\n"
8722 "Address Family modifier\n"
8723 "Address Family modifier\n"
8724 "Display routes matching the route-map\n"
8725 "A route-map to match on\n")
8726{
8727 if (strncmp (argv[0], "m", 1) == 0)
8728 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8729 bgp_show_type_route_map);
8730
8731 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
8732 bgp_show_type_route_map);
8733}
8734
8735DEFUN (show_bgp_route_map,
8736 show_bgp_route_map_cmd,
8737 "show bgp route-map WORD",
8738 SHOW_STR
8739 BGP_STR
8740 "Display routes matching the route-map\n"
8741 "A route-map to match on\n")
8742{
8743 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8744 bgp_show_type_route_map);
8745}
8746
8747DEFUN (show_ip_bgp_cidr_only,
8748 show_ip_bgp_cidr_only_cmd,
8749 "show ip bgp cidr-only",
8750 SHOW_STR
8751 IP_STR
8752 BGP_STR
8753 "Display only routes with non-natural netmasks\n")
8754{
8755 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8756 bgp_show_type_cidr_only, NULL);
8757}
8758
8759DEFUN (show_ip_bgp_flap_cidr_only,
8760 show_ip_bgp_flap_cidr_only_cmd,
8761 "show ip bgp flap-statistics cidr-only",
8762 SHOW_STR
8763 IP_STR
8764 BGP_STR
8765 "Display flap statistics of routes\n"
8766 "Display only routes with non-natural netmasks\n")
8767{
8768 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8769 bgp_show_type_flap_cidr_only, NULL);
8770}
8771
8772ALIAS (show_ip_bgp_flap_cidr_only,
8773 show_ip_bgp_damp_flap_cidr_only_cmd,
8774 "show ip bgp dampening flap-statistics cidr-only",
8775 SHOW_STR
8776 IP_STR
8777 BGP_STR
8778 "Display detailed information about dampening\n"
8779 "Display flap statistics of routes\n"
8780 "Display only routes with non-natural netmasks\n")
8781
8782DEFUN (show_ip_bgp_ipv4_cidr_only,
8783 show_ip_bgp_ipv4_cidr_only_cmd,
8784 "show ip bgp ipv4 (unicast|multicast) cidr-only",
8785 SHOW_STR
8786 IP_STR
8787 BGP_STR
8788 "Address family\n"
8789 "Address Family modifier\n"
8790 "Address Family modifier\n"
8791 "Display only routes with non-natural netmasks\n")
8792{
8793 if (strncmp (argv[0], "m", 1) == 0)
8794 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8795 bgp_show_type_cidr_only, NULL);
8796
8797 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8798 bgp_show_type_cidr_only, NULL);
8799}
8800
8801DEFUN (show_ip_bgp_community_all,
8802 show_ip_bgp_community_all_cmd,
8803 "show ip bgp community",
8804 SHOW_STR
8805 IP_STR
8806 BGP_STR
8807 "Display routes matching the communities\n")
8808{
8809 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8810 bgp_show_type_community_all, NULL);
8811}
8812
8813DEFUN (show_ip_bgp_ipv4_community_all,
8814 show_ip_bgp_ipv4_community_all_cmd,
8815 "show ip bgp ipv4 (unicast|multicast) community",
8816 SHOW_STR
8817 IP_STR
8818 BGP_STR
8819 "Address family\n"
8820 "Address Family modifier\n"
8821 "Address Family modifier\n"
8822 "Display routes matching the communities\n")
8823{
8824 if (strncmp (argv[0], "m", 1) == 0)
8825 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8826 bgp_show_type_community_all, NULL);
8827
8828 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8829 bgp_show_type_community_all, NULL);
8830}
8831
Lou Bergerf9b6c392016-01-12 13:42:09 -05008832DEFUN (show_bgp_community_all,
8833 show_bgp_community_all_cmd,
8834 "show bgp community",
8835 SHOW_STR
8836 BGP_STR
8837 "Display routes matching the communities\n")
8838{
8839 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
8840 bgp_show_type_community_all, NULL);
8841}
8842
8843ALIAS (show_bgp_community_all,
8844 show_bgp_ipv6_community_all_cmd,
8845 "show bgp ipv6 community",
8846 SHOW_STR
8847 BGP_STR
8848 "Address family\n"
8849 "Display routes matching the communities\n")
8850
8851/* old command */
8852DEFUN (show_ipv6_bgp_community_all,
8853 show_ipv6_bgp_community_all_cmd,
8854 "show ipv6 bgp community",
8855 SHOW_STR
8856 IPV6_STR
8857 BGP_STR
8858 "Display routes matching the communities\n")
8859{
8860 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
8861 bgp_show_type_community_all, NULL);
8862}
8863
8864/* old command */
8865DEFUN (show_ipv6_mbgp_community_all,
8866 show_ipv6_mbgp_community_all_cmd,
8867 "show ipv6 mbgp community",
8868 SHOW_STR
8869 IPV6_STR
8870 MBGP_STR
8871 "Display routes matching the communities\n")
8872{
8873 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
8874 bgp_show_type_community_all, NULL);
8875}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008876
Lou Berger651b4022016-01-12 13:42:07 -05008877DEFUN (show_bgp_ipv4_route_map,
8878 show_bgp_ipv4_route_map_cmd,
8879 "show bgp ipv4 route-map WORD",
paul718e3742002-12-13 20:15:29 +00008880 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008881 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008882 IP_STR
paul718e3742002-12-13 20:15:29 +00008883 "Display routes matching the route-map\n"
8884 "A route-map to match on\n")
8885{
8886 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8887 bgp_show_type_route_map);
8888}
8889
Lou Berger651b4022016-01-12 13:42:07 -05008890DEFUN (show_bgp_ipv4_safi_flap_route_map,
8891 show_bgp_ipv4_safi_flap_route_map_cmd,
8892 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics route-map WORD",
paul718e3742002-12-13 20:15:29 +00008893 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008894 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008895 IP_STR
8896 "Address Family Modifier\n"
8897 "Address Family Modifier\n"
8898 "Address Family Modifier\n"
8899 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00008900 "Display flap statistics of routes\n"
8901 "Display routes matching the route-map\n"
8902 "A route-map to match on\n")
8903{
Lou Berger651b4022016-01-12 13:42:07 -05008904 safi_t safi;
8905 if (bgp_parse_safi(argv[0], &safi)) {
8906 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8907 return CMD_WARNING;
8908 }
8909 return bgp_show_route_map (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008910 bgp_show_type_flap_route_map);
8911}
8912
Lou Berger651b4022016-01-12 13:42:07 -05008913ALIAS (show_bgp_ipv4_safi_flap_route_map,
8914 show_bgp_ipv4_safi_damp_flap_route_map_cmd,
8915 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics route-map WORD",
Balaji3921cc52015-05-16 23:12:17 +05308916 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308917 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008918 IP_STR
8919 "Address Family Modifier\n"
8920 "Address Family Modifier\n"
8921 "Address Family Modifier\n"
8922 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308923 "Display detailed information about dampening\n"
8924 "Display flap statistics of routes\n"
8925 "Display routes matching the route-map\n"
8926 "A route-map to match on\n")
Lou Berger205e6742016-01-12 13:42:11 -05008927
Lou Berger651b4022016-01-12 13:42:07 -05008928DEFUN (show_bgp_ipv6_safi_flap_route_map,
8929 show_bgp_ipv6_safi_flap_route_map_cmd,
8930 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics route-map WORD",
paul718e3742002-12-13 20:15:29 +00008931 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05008932 BGP_STR
8933 IPV6_STR
8934 "Address Family Modifier\n"
8935 "Address Family Modifier\n"
8936 "Address Family Modifier\n"
8937 "Address Family Modifier\n"
8938 "Display flap statistics of routes\n"
8939 "Display routes matching the route-map\n"
8940 "A route-map to match on\n")
8941{
8942 safi_t safi;
8943 if (bgp_parse_safi(argv[0], &safi)) {
8944 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8945 return CMD_WARNING;
8946 }
8947 return bgp_show_route_map (vty, argv[1], AFI_IP6, safi,
8948 bgp_show_type_flap_route_map);
8949}
8950ALIAS (show_bgp_ipv6_safi_flap_route_map,
8951 show_bgp_ipv6_safi_damp_flap_route_map_cmd,
8952 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics route-map WORD",
8953 SHOW_STR
8954 BGP_STR
8955 IPV6_STR
8956 "Address Family Modifier\n"
8957 "Address Family Modifier\n"
8958 "Address Family Modifier\n"
8959 "Address Family Modifier\n"
8960 "Display detailed information about dampening\n"
8961 "Display flap statistics of routes\n"
8962 "Display routes matching the route-map\n"
8963 "A route-map to match on\n")
Lou Berger651b4022016-01-12 13:42:07 -05008964
8965DEFUN (show_bgp_ipv4_safi_route_map,
8966 show_bgp_ipv4_safi_route_map_cmd,
8967 "show bgp ipv4 (encap|multicast|unicast|vpn) route-map WORD",
8968 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008969 BGP_STR
8970 "Address family\n"
8971 "Address Family modifier\n"
8972 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05008973 "Address Family modifier\n"
8974 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008975 "Display routes matching the route-map\n"
8976 "A route-map to match on\n")
8977{
Lou Berger651b4022016-01-12 13:42:07 -05008978 safi_t safi;
8979 if (bgp_parse_safi(argv[0], &safi)) {
8980 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8981 return CMD_WARNING;
8982 }
8983 return bgp_show_route_map (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008984 bgp_show_type_route_map);
8985}
Lou Berger205e6742016-01-12 13:42:11 -05008986
Lou Berger651b4022016-01-12 13:42:07 -05008987DEFUN (show_bgp_ipv6_safi_route_map,
8988 show_bgp_ipv6_safi_route_map_cmd,
8989 "show bgp ipv6 (encap|multicast|unicast|vpn) route-map WORD",
paul718e3742002-12-13 20:15:29 +00008990 SHOW_STR
8991 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008992 "Address family\n"
8993 "Address Family modifier\n"
8994 "Address Family modifier\n"
8995 "Address Family modifier\n"
8996 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008997 "Display routes matching the route-map\n"
8998 "A route-map to match on\n")
8999{
Lou Berger651b4022016-01-12 13:42:07 -05009000 safi_t safi;
9001 if (bgp_parse_safi(argv[0], &safi)) {
9002 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9003 return CMD_WARNING;
9004 }
9005 return bgp_show_route_map (vty, argv[1], AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00009006 bgp_show_type_route_map);
9007}
9008
Lou Berger651b4022016-01-12 13:42:07 -05009009DEFUN (show_bgp_ipv6_route_map,
paul718e3742002-12-13 20:15:29 +00009010 show_bgp_ipv6_route_map_cmd,
9011 "show bgp ipv6 route-map WORD",
9012 SHOW_STR
9013 BGP_STR
9014 "Address family\n"
9015 "Display routes matching the route-map\n"
9016 "A route-map to match on\n")
Lou Berger651b4022016-01-12 13:42:07 -05009017{
9018 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9019 bgp_show_type_route_map);
9020}
David Lamparter6b0655a2014-06-04 06:53:35 +02009021
Lou Berger651b4022016-01-12 13:42:07 -05009022DEFUN (show_bgp_ipv4_cidr_only,
9023 show_bgp_ipv4_cidr_only_cmd,
9024 "show bgp ipv4 cidr-only",
paul718e3742002-12-13 20:15:29 +00009025 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009026 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009027 IP_STR
paul718e3742002-12-13 20:15:29 +00009028 "Display only routes with non-natural netmasks\n")
9029{
9030 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00009031 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009032}
9033
Lou Berger651b4022016-01-12 13:42:07 -05009034DEFUN (show_bgp_ipv4_safi_flap_cidr_only,
9035 show_bgp_ipv4_safi_flap_cidr_only_cmd,
9036 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics cidr-only",
paul718e3742002-12-13 20:15:29 +00009037 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009038 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009039 "Address Family\n"
9040 "Address Family Modifier\n"
9041 "Address Family Modifier\n"
9042 "Address Family Modifier\n"
9043 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00009044 "Display flap statistics of routes\n"
9045 "Display only routes with non-natural netmasks\n")
9046{
Lou Berger651b4022016-01-12 13:42:07 -05009047 safi_t safi;
9048
9049 if (bgp_parse_safi(argv[0], &safi)) {
9050 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9051 return CMD_WARNING;
9052 }
9053 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009054}
9055
Lou Berger651b4022016-01-12 13:42:07 -05009056ALIAS (show_bgp_ipv4_safi_flap_cidr_only,
9057 show_bgp_ipv4_safi_damp_flap_cidr_only_cmd,
9058 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics cidr-only",
Balaji3921cc52015-05-16 23:12:17 +05309059 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05309060 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009061 "Address Family\n"
9062 "Address Family Modifier\n"
9063 "Address Family Modifier\n"
9064 "Address Family Modifier\n"
9065 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05309066 "Display detailed information about dampening\n"
9067 "Display flap statistics of routes\n"
9068 "Display only routes with non-natural netmasks\n")
9069
Lou Berger651b4022016-01-12 13:42:07 -05009070DEFUN (show_bgp_ipv4_safi_cidr_only,
9071 show_bgp_ipv4_safi_cidr_only_cmd,
9072 "show bgp ipv4 (unicast|multicast) cidr-only",
paul718e3742002-12-13 20:15:29 +00009073 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009074 BGP_STR
9075 "Address family\n"
9076 "Address Family modifier\n"
9077 "Address Family modifier\n"
9078 "Display only routes with non-natural netmasks\n")
9079{
9080 if (strncmp (argv[0], "m", 1) == 0)
9081 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00009082 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009083
9084 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00009085 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009086}
David Lamparter6b0655a2014-06-04 06:53:35 +02009087
Lou Berger651b4022016-01-12 13:42:07 -05009088/* new046 */
9089DEFUN (show_bgp_afi_safi_community_all,
9090 show_bgp_afi_safi_community_all_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009091 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) community",
paul718e3742002-12-13 20:15:29 +00009092 SHOW_STR
9093 BGP_STR
9094 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009095 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009096 "Address Family modifier\n"
9097 "Address Family modifier\n"
9098 "Address Family modifier\n"
9099 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009100 "Display routes matching the communities\n")
Lou Berger651b4022016-01-12 13:42:07 -05009101{
9102 safi_t safi;
9103 afi_t afi;
paul718e3742002-12-13 20:15:29 +00009104
Lou Berger651b4022016-01-12 13:42:07 -05009105 if (bgp_parse_afi(argv[0], &afi)) {
9106 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
9107 return CMD_WARNING;
9108 }
9109 if (bgp_parse_safi(argv[1], &safi)) {
9110 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
9111 return CMD_WARNING;
9112 }
9113
9114 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_all, NULL);
9115}
9116DEFUN (show_bgp_afi_community_all,
9117 show_bgp_afi_community_all_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009118 "show bgp (ipv4|ipv6) community",
paul718e3742002-12-13 20:15:29 +00009119 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009120 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009121 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009122 "Address family\n"
paul718e3742002-12-13 20:15:29 +00009123 "Display routes matching the communities\n")
9124{
Lou Berger651b4022016-01-12 13:42:07 -05009125 afi_t afi;
9126 safi_t safi = SAFI_UNICAST;
paul718e3742002-12-13 20:15:29 +00009127
Lou Berger651b4022016-01-12 13:42:07 -05009128 if (bgp_parse_afi(argv[0], &afi)) {
9129 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
9130 return CMD_WARNING;
9131 }
9132 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00009133}
David Lamparter6b0655a2014-06-04 06:53:35 +02009134
paul94f2b392005-06-28 12:44:16 +00009135static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04009136bgp_show_community (struct vty *vty, const char *view_name, int argc,
9137 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00009138{
9139 struct community *com;
9140 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04009141 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00009142 int i;
9143 char *str;
9144 int first = 0;
9145
Michael Lambert95cbbd22010-07-23 14:43:04 -04009146 /* BGP structure lookup */
9147 if (view_name)
9148 {
9149 bgp = bgp_lookup_by_name (view_name);
9150 if (bgp == NULL)
9151 {
9152 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9153 return CMD_WARNING;
9154 }
9155 }
9156 else
9157 {
9158 bgp = bgp_get_default ();
9159 if (bgp == NULL)
9160 {
9161 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9162 return CMD_WARNING;
9163 }
9164 }
9165
paul718e3742002-12-13 20:15:29 +00009166 b = buffer_new (1024);
9167 for (i = 0; i < argc; i++)
9168 {
9169 if (first)
9170 buffer_putc (b, ' ');
9171 else
9172 {
9173 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9174 continue;
9175 first = 1;
9176 }
9177
9178 buffer_putstr (b, argv[i]);
9179 }
9180 buffer_putc (b, '\0');
9181
9182 str = buffer_getstr (b);
9183 buffer_free (b);
9184
9185 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00009186 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00009187 if (! com)
9188 {
9189 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
9190 return CMD_WARNING;
9191 }
9192
Michael Lambert95cbbd22010-07-23 14:43:04 -04009193 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00009194 (exact ? bgp_show_type_community_exact :
9195 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00009196}
9197
Lou Bergerf9b6c392016-01-12 13:42:09 -05009198DEFUN (show_ip_bgp_community,
9199 show_ip_bgp_community_cmd,
9200 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
9201 SHOW_STR
9202 IP_STR
9203 BGP_STR
9204 "Display routes matching the communities\n"
9205 "community number\n"
9206 "Do not send outside local AS (well-known community)\n"
9207 "Do not advertise to any peer (well-known community)\n"
9208 "Do not export to next AS (well-known community)\n")
9209{
9210 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9211}
9212
9213ALIAS (show_ip_bgp_community,
9214 show_ip_bgp_community2_cmd,
9215 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9216 SHOW_STR
9217 IP_STR
9218 BGP_STR
9219 "Display routes matching the communities\n"
9220 "community number\n"
9221 "Do not send outside local AS (well-known community)\n"
9222 "Do not advertise to any peer (well-known community)\n"
9223 "Do not export to next AS (well-known community)\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
9229ALIAS (show_ip_bgp_community,
9230 show_ip_bgp_community3_cmd,
9231 "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)",
9232 SHOW_STR
9233 IP_STR
9234 BGP_STR
9235 "Display routes matching the communities\n"
9236 "community number\n"
9237 "Do not send outside local AS (well-known community)\n"
9238 "Do not advertise to any peer (well-known community)\n"
9239 "Do not export to next AS (well-known community)\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
9249ALIAS (show_ip_bgp_community,
9250 show_ip_bgp_community4_cmd,
9251 "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)",
9252 SHOW_STR
9253 IP_STR
9254 BGP_STR
9255 "Display routes matching the communities\n"
9256 "community number\n"
9257 "Do not send outside local AS (well-known community)\n"
9258 "Do not advertise to any peer (well-known community)\n"
9259 "Do not export to next AS (well-known community)\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
9273DEFUN (show_ip_bgp_ipv4_community,
9274 show_ip_bgp_ipv4_community_cmd,
9275 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9276 SHOW_STR
9277 IP_STR
9278 BGP_STR
9279 "Address family\n"
9280 "Address Family modifier\n"
9281 "Address Family modifier\n"
9282 "Display routes matching the communities\n"
9283 "community number\n"
9284 "Do not send outside local AS (well-known community)\n"
9285 "Do not advertise to any peer (well-known community)\n"
9286 "Do not export to next AS (well-known community)\n")
9287{
9288 if (strncmp (argv[0], "m", 1) == 0)
9289 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
9290
9291 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9292}
9293
9294ALIAS (show_ip_bgp_ipv4_community,
9295 show_ip_bgp_ipv4_community2_cmd,
9296 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9297 SHOW_STR
9298 IP_STR
9299 BGP_STR
9300 "Address family\n"
9301 "Address Family modifier\n"
9302 "Address Family modifier\n"
9303 "Display routes matching the communities\n"
9304 "community number\n"
9305 "Do not send outside local AS (well-known community)\n"
9306 "Do not advertise to any peer (well-known community)\n"
9307 "Do not export to next AS (well-known community)\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
9313ALIAS (show_ip_bgp_ipv4_community,
9314 show_ip_bgp_ipv4_community3_cmd,
9315 "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)",
9316 SHOW_STR
9317 IP_STR
9318 BGP_STR
9319 "Address family\n"
9320 "Address Family modifier\n"
9321 "Address Family modifier\n"
9322 "Display routes matching the communities\n"
9323 "community number\n"
9324 "Do not send outside local AS (well-known community)\n"
9325 "Do not advertise to any peer (well-known community)\n"
9326 "Do not export to next AS (well-known community)\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
9336ALIAS (show_ip_bgp_ipv4_community,
9337 show_ip_bgp_ipv4_community4_cmd,
9338 "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)",
9339 SHOW_STR
9340 IP_STR
9341 BGP_STR
9342 "Address family\n"
9343 "Address Family modifier\n"
9344 "Address Family modifier\n"
9345 "Display routes matching the communities\n"
9346 "community number\n"
9347 "Do not send outside local AS (well-known community)\n"
9348 "Do not advertise to any peer (well-known community)\n"
9349 "Do not export to next AS (well-known community)\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
9363DEFUN (show_ip_bgp_community_exact,
9364 show_ip_bgp_community_exact_cmd,
9365 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9366 SHOW_STR
9367 IP_STR
9368 BGP_STR
9369 "Display routes matching the communities\n"
9370 "community number\n"
9371 "Do not send outside local AS (well-known community)\n"
9372 "Do not advertise to any peer (well-known community)\n"
9373 "Do not export to next AS (well-known community)\n"
9374 "Exact match of the communities")
9375{
9376 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9377}
9378
9379ALIAS (show_ip_bgp_community_exact,
9380 show_ip_bgp_community2_exact_cmd,
9381 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9382 SHOW_STR
9383 IP_STR
9384 BGP_STR
9385 "Display routes matching the communities\n"
9386 "community number\n"
9387 "Do not send outside local AS (well-known community)\n"
9388 "Do not advertise to any peer (well-known community)\n"
9389 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
9395
9396ALIAS (show_ip_bgp_community_exact,
9397 show_ip_bgp_community3_exact_cmd,
9398 "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",
9399 SHOW_STR
9400 IP_STR
9401 BGP_STR
9402 "Display routes matching the communities\n"
9403 "community number\n"
9404 "Do not send outside local AS (well-known community)\n"
9405 "Do not advertise to any peer (well-known community)\n"
9406 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
9416
9417ALIAS (show_ip_bgp_community_exact,
9418 show_ip_bgp_community4_exact_cmd,
9419 "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",
9420 SHOW_STR
9421 IP_STR
9422 BGP_STR
9423 "Display routes matching the communities\n"
9424 "community number\n"
9425 "Do not send outside local AS (well-known community)\n"
9426 "Do not advertise to any peer (well-known community)\n"
9427 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
9441
9442DEFUN (show_ip_bgp_ipv4_community_exact,
9443 show_ip_bgp_ipv4_community_exact_cmd,
9444 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9445 SHOW_STR
9446 IP_STR
9447 BGP_STR
9448 "Address family\n"
9449 "Address Family modifier\n"
9450 "Address Family modifier\n"
9451 "Display routes matching the communities\n"
9452 "community number\n"
9453 "Do not send outside local AS (well-known community)\n"
9454 "Do not advertise to any peer (well-known community)\n"
9455 "Do not export to next AS (well-known community)\n"
9456 "Exact match of the communities")
9457{
9458 if (strncmp (argv[0], "m", 1) == 0)
9459 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
9460
9461 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9462}
9463
9464ALIAS (show_ip_bgp_ipv4_community_exact,
9465 show_ip_bgp_ipv4_community2_exact_cmd,
9466 "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",
9467 SHOW_STR
9468 IP_STR
9469 BGP_STR
9470 "Address family\n"
9471 "Address Family modifier\n"
9472 "Address Family modifier\n"
9473 "Display routes matching the communities\n"
9474 "community number\n"
9475 "Do not send outside local AS (well-known community)\n"
9476 "Do not advertise to any peer (well-known community)\n"
9477 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
9483
9484ALIAS (show_ip_bgp_ipv4_community_exact,
9485 show_ip_bgp_ipv4_community3_exact_cmd,
9486 "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",
9487 SHOW_STR
9488 IP_STR
9489 BGP_STR
9490 "Address family\n"
9491 "Address Family modifier\n"
9492 "Address Family modifier\n"
9493 "Display routes matching the communities\n"
9494 "community number\n"
9495 "Do not send outside local AS (well-known community)\n"
9496 "Do not advertise to any peer (well-known community)\n"
9497 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
9507
9508ALIAS (show_ip_bgp_ipv4_community_exact,
9509 show_ip_bgp_ipv4_community4_exact_cmd,
9510 "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",
9511 SHOW_STR
9512 IP_STR
9513 BGP_STR
9514 "Address family\n"
9515 "Address Family modifier\n"
9516 "Address Family modifier\n"
9517 "Display routes matching the communities\n"
9518 "community number\n"
9519 "Do not send outside local AS (well-known community)\n"
9520 "Do not advertise to any peer (well-known community)\n"
9521 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
9535
Lou Bergerf9b6c392016-01-12 13:42:09 -05009536DEFUN (show_bgp_community,
9537 show_bgp_community_cmd,
9538 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
9539 SHOW_STR
9540 BGP_STR
9541 "Display routes matching the communities\n"
9542 "community number\n"
9543 "Do not send outside local AS (well-known community)\n"
9544 "Do not advertise to any peer (well-known community)\n"
9545 "Do not export to next AS (well-known community)\n")
9546{
9547 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9548}
9549
9550ALIAS (show_bgp_community,
9551 show_bgp_ipv6_community_cmd,
9552 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
9553 SHOW_STR
9554 BGP_STR
9555 "Address family\n"
9556 "Display routes matching the communities\n"
9557 "community number\n"
9558 "Do not send outside local AS (well-known community)\n"
9559 "Do not advertise to any peer (well-known community)\n"
9560 "Do not export to next AS (well-known community)\n")
9561
9562ALIAS (show_bgp_community,
9563 show_bgp_community2_cmd,
9564 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9565 SHOW_STR
9566 BGP_STR
9567 "Display routes matching the communities\n"
9568 "community number\n"
9569 "Do not send outside local AS (well-known community)\n"
9570 "Do not advertise to any peer (well-known community)\n"
9571 "Do not export to next AS (well-known community)\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
9577ALIAS (show_bgp_community,
9578 show_bgp_ipv6_community2_cmd,
9579 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9580 SHOW_STR
9581 BGP_STR
9582 "Address family\n"
9583 "Display routes matching the communities\n"
9584 "community number\n"
9585 "Do not send outside local AS (well-known community)\n"
9586 "Do not advertise to any peer (well-known community)\n"
9587 "Do not export to next AS (well-known community)\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
9593ALIAS (show_bgp_community,
9594 show_bgp_community3_cmd,
9595 "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)",
9596 SHOW_STR
9597 BGP_STR
9598 "Display routes matching the communities\n"
9599 "community number\n"
9600 "Do not send outside local AS (well-known community)\n"
9601 "Do not advertise to any peer (well-known community)\n"
9602 "Do not export to next AS (well-known community)\n"
9603 "community number\n"
9604 "Do not send outside local AS (well-known community)\n"
9605 "Do not advertise to any peer (well-known community)\n"
9606 "Do not export to next AS (well-known community)\n"
9607 "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
9612ALIAS (show_bgp_community,
9613 show_bgp_ipv6_community3_cmd,
9614 "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)",
9615 SHOW_STR
9616 BGP_STR
9617 "Address family\n"
9618 "Display routes matching the communities\n"
9619 "community number\n"
9620 "Do not send outside local AS (well-known community)\n"
9621 "Do not advertise to any peer (well-known community)\n"
9622 "Do not export to next AS (well-known community)\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
9632ALIAS (show_bgp_community,
9633 show_bgp_community4_cmd,
9634 "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)",
9635 SHOW_STR
9636 BGP_STR
9637 "Display routes matching the communities\n"
9638 "community number\n"
9639 "Do not send outside local AS (well-known community)\n"
9640 "Do not advertise to any peer (well-known community)\n"
9641 "Do not export to next AS (well-known community)\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
9655ALIAS (show_bgp_community,
9656 show_bgp_ipv6_community4_cmd,
9657 "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)",
9658 SHOW_STR
9659 BGP_STR
9660 "Address family\n"
9661 "Display routes matching the communities\n"
9662 "community number\n"
9663 "Do not send outside local AS (well-known community)\n"
9664 "Do not advertise to any peer (well-known community)\n"
9665 "Do not export to next AS (well-known community)\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
9679/* old command */
9680DEFUN (show_ipv6_bgp_community,
9681 show_ipv6_bgp_community_cmd,
9682 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
9683 SHOW_STR
9684 IPV6_STR
9685 BGP_STR
9686 "Display routes matching the communities\n"
9687 "community number\n"
9688 "Do not send outside local AS (well-known community)\n"
9689 "Do not advertise to any peer (well-known community)\n"
9690 "Do not export to next AS (well-known community)\n")
9691{
9692 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9693}
9694
9695/* old command */
9696ALIAS (show_ipv6_bgp_community,
9697 show_ipv6_bgp_community2_cmd,
9698 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9699 SHOW_STR
9700 IPV6_STR
9701 BGP_STR
9702 "Display routes matching the communities\n"
9703 "community number\n"
9704 "Do not send outside local AS (well-known community)\n"
9705 "Do not advertise to any peer (well-known community)\n"
9706 "Do not export to next AS (well-known community)\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
9712/* old command */
9713ALIAS (show_ipv6_bgp_community,
9714 show_ipv6_bgp_community3_cmd,
9715 "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)",
9716 SHOW_STR
9717 IPV6_STR
9718 BGP_STR
9719 "Display routes matching the communities\n"
9720 "community number\n"
9721 "Do not send outside local AS (well-known community)\n"
9722 "Do not advertise to any peer (well-known community)\n"
9723 "Do not export to next AS (well-known community)\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
9733/* old command */
9734ALIAS (show_ipv6_bgp_community,
9735 show_ipv6_bgp_community4_cmd,
9736 "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)",
9737 SHOW_STR
9738 IPV6_STR
9739 BGP_STR
9740 "Display routes matching the communities\n"
9741 "community number\n"
9742 "Do not send outside local AS (well-known community)\n"
9743 "Do not advertise to any peer (well-known community)\n"
9744 "Do not export to next AS (well-known community)\n"
9745 "community number\n"
9746 "Do not send outside local AS (well-known community)\n"
9747 "Do not advertise to any peer (well-known community)\n"
9748 "Do not export to next AS (well-known community)\n"
9749 "community number\n"
9750 "Do not send outside local AS (well-known community)\n"
9751 "Do not advertise to any peer (well-known community)\n"
9752 "Do not export to next AS (well-known community)\n"
9753 "community number\n"
9754 "Do not send outside local AS (well-known community)\n"
9755 "Do not advertise to any peer (well-known community)\n"
9756 "Do not export to next AS (well-known community)\n")
9757
9758DEFUN (show_bgp_community_exact,
9759 show_bgp_community_exact_cmd,
9760 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9761 SHOW_STR
9762 BGP_STR
9763 "Display routes matching the communities\n"
9764 "community number\n"
9765 "Do not send outside local AS (well-known community)\n"
9766 "Do not advertise to any peer (well-known community)\n"
9767 "Do not export to next AS (well-known community)\n"
9768 "Exact match of the communities")
9769{
9770 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
9771}
9772
9773ALIAS (show_bgp_community_exact,
9774 show_bgp_ipv6_community_exact_cmd,
9775 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9776 SHOW_STR
9777 BGP_STR
9778 "Address family\n"
9779 "Display routes matching the communities\n"
9780 "community number\n"
9781 "Do not send outside local AS (well-known community)\n"
9782 "Do not advertise to any peer (well-known community)\n"
9783 "Do not export to next AS (well-known community)\n"
9784 "Exact match of the communities")
9785
9786ALIAS (show_bgp_community_exact,
9787 show_bgp_community2_exact_cmd,
9788 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9789 SHOW_STR
9790 BGP_STR
9791 "Display routes matching the communities\n"
9792 "community number\n"
9793 "Do not send outside local AS (well-known community)\n"
9794 "Do not advertise to any peer (well-known community)\n"
9795 "Do not export to next AS (well-known community)\n"
9796 "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 "Exact match of the communities")
9801
9802ALIAS (show_bgp_community_exact,
9803 show_bgp_ipv6_community2_exact_cmd,
9804 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9805 SHOW_STR
9806 BGP_STR
9807 "Address family\n"
9808 "Display routes matching the communities\n"
9809 "community number\n"
9810 "Do not send outside local AS (well-known community)\n"
9811 "Do not advertise to any peer (well-known community)\n"
9812 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
9818
9819ALIAS (show_bgp_community_exact,
9820 show_bgp_community3_exact_cmd,
9821 "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",
9822 SHOW_STR
9823 BGP_STR
9824 "Display routes matching the communities\n"
9825 "community number\n"
9826 "Do not send outside local AS (well-known community)\n"
9827 "Do not advertise to any peer (well-known community)\n"
9828 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
9838
9839ALIAS (show_bgp_community_exact,
9840 show_bgp_ipv6_community3_exact_cmd,
9841 "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",
9842 SHOW_STR
9843 BGP_STR
9844 "Address family\n"
9845 "Display routes matching the communities\n"
9846 "community number\n"
9847 "Do not send outside local AS (well-known community)\n"
9848 "Do not advertise to any peer (well-known community)\n"
9849 "Do not export to next AS (well-known community)\n"
9850 "community number\n"
9851 "Do not send outside local AS (well-known community)\n"
9852 "Do not advertise to any peer (well-known community)\n"
9853 "Do not export to next AS (well-known community)\n"
9854 "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 "Exact match of the communities")
9859
9860ALIAS (show_bgp_community_exact,
9861 show_bgp_community4_exact_cmd,
9862 "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",
9863 SHOW_STR
9864 BGP_STR
9865 "Display routes matching the communities\n"
9866 "community number\n"
9867 "Do not send outside local AS (well-known community)\n"
9868 "Do not advertise to any peer (well-known community)\n"
9869 "Do not export to next AS (well-known community)\n"
9870 "community number\n"
9871 "Do not send outside local AS (well-known community)\n"
9872 "Do not advertise to any peer (well-known community)\n"
9873 "Do not export to next AS (well-known community)\n"
9874 "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 "Exact match of the communities")
9883
9884ALIAS (show_bgp_community_exact,
9885 show_bgp_ipv6_community4_exact_cmd,
9886 "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",
9887 SHOW_STR
9888 BGP_STR
9889 "Address family\n"
9890 "Display routes matching the communities\n"
9891 "community number\n"
9892 "Do not send outside local AS (well-known community)\n"
9893 "Do not advertise to any peer (well-known community)\n"
9894 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
9908
9909/* old command */
9910DEFUN (show_ipv6_bgp_community_exact,
9911 show_ipv6_bgp_community_exact_cmd,
9912 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9913 SHOW_STR
9914 IPV6_STR
9915 BGP_STR
9916 "Display routes matching the communities\n"
9917 "community number\n"
9918 "Do not send outside local AS (well-known community)\n"
9919 "Do not advertise to any peer (well-known community)\n"
9920 "Do not export to next AS (well-known community)\n"
9921 "Exact match of the communities")
9922{
9923 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
9924}
9925
9926/* old command */
9927ALIAS (show_ipv6_bgp_community_exact,
9928 show_ipv6_bgp_community2_exact_cmd,
9929 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9930 SHOW_STR
9931 IPV6_STR
9932 BGP_STR
9933 "Display routes matching the communities\n"
9934 "community number\n"
9935 "Do not send outside local AS (well-known community)\n"
9936 "Do not advertise to any peer (well-known community)\n"
9937 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
9943
9944/* old command */
9945ALIAS (show_ipv6_bgp_community_exact,
9946 show_ipv6_bgp_community3_exact_cmd,
9947 "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",
9948 SHOW_STR
9949 IPV6_STR
9950 BGP_STR
9951 "Display routes matching the communities\n"
9952 "community number\n"
9953 "Do not send outside local AS (well-known community)\n"
9954 "Do not advertise to any peer (well-known community)\n"
9955 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
9965
9966/* old command */
9967ALIAS (show_ipv6_bgp_community_exact,
9968 show_ipv6_bgp_community4_exact_cmd,
9969 "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",
9970 SHOW_STR
9971 IPV6_STR
9972 BGP_STR
9973 "Display routes matching the communities\n"
9974 "community number\n"
9975 "Do not send outside local AS (well-known community)\n"
9976 "Do not advertise to any peer (well-known community)\n"
9977 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
9991
9992/* old command */
9993DEFUN (show_ipv6_mbgp_community,
9994 show_ipv6_mbgp_community_cmd,
9995 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
9996 SHOW_STR
9997 IPV6_STR
9998 MBGP_STR
9999 "Display routes matching the communities\n"
10000 "community number\n"
10001 "Do not send outside local AS (well-known community)\n"
10002 "Do not advertise to any peer (well-known community)\n"
10003 "Do not export to next AS (well-known community)\n")
10004{
10005 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
10006}
10007
10008/* old command */
10009ALIAS (show_ipv6_mbgp_community,
10010 show_ipv6_mbgp_community2_cmd,
10011 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10012 SHOW_STR
10013 IPV6_STR
10014 MBGP_STR
10015 "Display routes matching the communities\n"
10016 "community number\n"
10017 "Do not send outside local AS (well-known community)\n"
10018 "Do not advertise to any peer (well-known community)\n"
10019 "Do not export to next AS (well-known community)\n"
10020 "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
10025/* old command */
10026ALIAS (show_ipv6_mbgp_community,
10027 show_ipv6_mbgp_community3_cmd,
10028 "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)",
10029 SHOW_STR
10030 IPV6_STR
10031 MBGP_STR
10032 "Display routes matching the communities\n"
10033 "community number\n"
10034 "Do not send outside local AS (well-known community)\n"
10035 "Do not advertise to any peer (well-known community)\n"
10036 "Do not export to next AS (well-known community)\n"
10037 "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
10046/* old command */
10047ALIAS (show_ipv6_mbgp_community,
10048 show_ipv6_mbgp_community4_cmd,
10049 "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)",
10050 SHOW_STR
10051 IPV6_STR
10052 MBGP_STR
10053 "Display routes matching the communities\n"
10054 "community number\n"
10055 "Do not send outside local AS (well-known community)\n"
10056 "Do not advertise to any peer (well-known community)\n"
10057 "Do not export to next AS (well-known community)\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
10071/* old command */
10072DEFUN (show_ipv6_mbgp_community_exact,
10073 show_ipv6_mbgp_community_exact_cmd,
10074 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10075 SHOW_STR
10076 IPV6_STR
10077 MBGP_STR
10078 "Display routes matching the communities\n"
10079 "community number\n"
10080 "Do not send outside local AS (well-known community)\n"
10081 "Do not advertise to any peer (well-known community)\n"
10082 "Do not export to next AS (well-known community)\n"
10083 "Exact match of the communities")
10084{
10085 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
10086}
10087
10088/* old command */
10089ALIAS (show_ipv6_mbgp_community_exact,
10090 show_ipv6_mbgp_community2_exact_cmd,
10091 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10092 SHOW_STR
10093 IPV6_STR
10094 MBGP_STR
10095 "Display routes matching the communities\n"
10096 "community number\n"
10097 "Do not send outside local AS (well-known community)\n"
10098 "Do not advertise to any peer (well-known community)\n"
10099 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
10105
10106/* old command */
10107ALIAS (show_ipv6_mbgp_community_exact,
10108 show_ipv6_mbgp_community3_exact_cmd,
10109 "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",
10110 SHOW_STR
10111 IPV6_STR
10112 MBGP_STR
10113 "Display routes matching the communities\n"
10114 "community number\n"
10115 "Do not send outside local AS (well-known community)\n"
10116 "Do not advertise to any peer (well-known community)\n"
10117 "Do not export to next AS (well-known community)\n"
10118 "community number\n"
10119 "Do not send outside local AS (well-known community)\n"
10120 "Do not advertise to any peer (well-known community)\n"
10121 "Do not export to next AS (well-known community)\n"
10122 "community number\n"
10123 "Do not send outside local AS (well-known community)\n"
10124 "Do not advertise to any peer (well-known community)\n"
10125 "Do not export to next AS (well-known community)\n"
10126 "Exact match of the communities")
10127
10128/* old command */
10129ALIAS (show_ipv6_mbgp_community_exact,
10130 show_ipv6_mbgp_community4_exact_cmd,
10131 "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",
10132 SHOW_STR
10133 IPV6_STR
10134 MBGP_STR
10135 "Display routes matching the communities\n"
10136 "community number\n"
10137 "Do not send outside local AS (well-known community)\n"
10138 "Do not advertise to any peer (well-known community)\n"
10139 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
Lou Bergerf9b6c392016-01-12 13:42:09 -050010153
Lou Berger651b4022016-01-12 13:42:07 -050010154DEFUN (show_bgp_ipv4_community,
10155 show_bgp_ipv4_community_cmd,
10156 "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010157 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010158 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010159 IP_STR
paul718e3742002-12-13 20:15:29 +000010160 "Display routes matching the communities\n"
10161 "community number\n"
10162 "Do not send outside local AS (well-known community)\n"
10163 "Do not advertise to any peer (well-known community)\n"
10164 "Do not export to next AS (well-known community)\n")
10165{
Michael Lambert95cbbd22010-07-23 14:43:04 -040010166 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010167}
10168
Lou Berger651b4022016-01-12 13:42:07 -050010169ALIAS (show_bgp_ipv4_community,
10170 show_bgp_ipv4_community2_cmd,
10171 "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 +000010172 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010173 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010174 IP_STR
paul718e3742002-12-13 20:15:29 +000010175 "Display routes matching the communities\n"
10176 "community number\n"
10177 "Do not send outside local AS (well-known community)\n"
10178 "Do not advertise to any peer (well-known community)\n"
10179 "Do not export to next AS (well-known community)\n"
10180 "community number\n"
10181 "Do not send outside local AS (well-known community)\n"
10182 "Do not advertise to any peer (well-known community)\n"
10183 "Do not export to next AS (well-known community)\n")
10184
Lou Berger651b4022016-01-12 13:42:07 -050010185ALIAS (show_bgp_ipv4_community,
10186 show_bgp_ipv4_community3_cmd,
10187 "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 +000010188 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010189 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010190 IP_STR
paul718e3742002-12-13 20:15:29 +000010191 "Display routes matching the communities\n"
10192 "community number\n"
10193 "Do not send outside local AS (well-known community)\n"
10194 "Do not advertise to any peer (well-known community)\n"
10195 "Do not export to next AS (well-known community)\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
Lou Berger651b4022016-01-12 13:42:07 -050010205ALIAS (show_bgp_ipv4_community,
10206 show_bgp_ipv4_community4_cmd,
10207 "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 +000010208 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010209 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010210 IP_STR
paul718e3742002-12-13 20:15:29 +000010211 "Display routes matching the communities\n"
10212 "community number\n"
10213 "Do not send outside local AS (well-known community)\n"
10214 "Do not advertise to any peer (well-known community)\n"
10215 "Do not export to next AS (well-known community)\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
Lou Berger651b4022016-01-12 13:42:07 -050010229DEFUN (show_bgp_ipv4_safi_community,
10230 show_bgp_ipv4_safi_community_cmd,
10231 "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010232 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010233 BGP_STR
10234 "Address family\n"
10235 "Address Family modifier\n"
10236 "Address Family modifier\n"
10237 "Display routes matching the communities\n"
10238 "community number\n"
10239 "Do not send outside local AS (well-known community)\n"
10240 "Do not advertise to any peer (well-known community)\n"
10241 "Do not export to next AS (well-known community)\n")
10242{
10243 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -040010244 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +000010245
Michael Lambert95cbbd22010-07-23 14:43:04 -040010246 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010247}
10248
Lou Berger651b4022016-01-12 13:42:07 -050010249ALIAS (show_bgp_ipv4_safi_community,
10250 show_bgp_ipv4_safi_community2_cmd,
10251 "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 +000010252 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010253 BGP_STR
10254 "Address family\n"
10255 "Address Family modifier\n"
10256 "Address Family modifier\n"
10257 "Display routes matching the communities\n"
10258 "community number\n"
10259 "Do not send outside local AS (well-known community)\n"
10260 "Do not advertise to any peer (well-known community)\n"
10261 "Do not export to next AS (well-known community)\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
Lou Berger651b4022016-01-12 13:42:07 -050010267ALIAS (show_bgp_ipv4_safi_community,
10268 show_bgp_ipv4_safi_community3_cmd,
10269 "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 +000010270 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010271 BGP_STR
10272 "Address family\n"
10273 "Address Family modifier\n"
10274 "Address Family modifier\n"
10275 "Display routes matching the communities\n"
10276 "community number\n"
10277 "Do not send outside local AS (well-known community)\n"
10278 "Do not advertise to any peer (well-known community)\n"
10279 "Do not export to next AS (well-known community)\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
Lou Berger651b4022016-01-12 13:42:07 -050010289ALIAS (show_bgp_ipv4_safi_community,
10290 show_bgp_ipv4_safi_community4_cmd,
10291 "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 +000010292 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010293 BGP_STR
10294 "Address family\n"
10295 "Address Family modifier\n"
10296 "Address Family modifier\n"
10297 "Display routes matching the communities\n"
10298 "community number\n"
10299 "Do not send outside local AS (well-known community)\n"
10300 "Do not advertise to any peer (well-known community)\n"
10301 "Do not export to next AS (well-known community)\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
Michael Lambert95cbbd22010-07-23 14:43:04 -040010315DEFUN (show_bgp_view_afi_safi_community_all,
10316 show_bgp_view_afi_safi_community_all_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010317 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Michael Lambert95cbbd22010-07-23 14:43:04 -040010318 SHOW_STR
10319 BGP_STR
10320 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010321 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010322 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010323 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010324 "Address Family modifier\n"
10325 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +000010326 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -040010327{
10328 int afi;
10329 int safi;
10330 struct bgp *bgp;
10331
10332 /* BGP structure lookup. */
10333 bgp = bgp_lookup_by_name (argv[0]);
10334 if (bgp == NULL)
10335 {
10336 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10337 return CMD_WARNING;
10338 }
10339
Michael Lambert95cbbd22010-07-23 14:43:04 -040010340 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10341 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010342 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
10343}
10344
10345DEFUN (show_bgp_view_afi_safi_community,
10346 show_bgp_view_afi_safi_community_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010347 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -040010348 SHOW_STR
10349 BGP_STR
10350 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010351 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010352 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010353 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010354 "Address family modifier\n"
10355 "Address family modifier\n"
10356 "Display routes matching the communities\n"
10357 "community number\n"
10358 "Do not send outside local AS (well-known community)\n"
10359 "Do not advertise to any peer (well-known community)\n"
10360 "Do not export to next AS (well-known community)\n")
10361{
10362 int afi;
10363 int safi;
10364
Michael Lambert95cbbd22010-07-23 14:43:04 -040010365 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10366 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10367 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010368}
10369
10370ALIAS (show_bgp_view_afi_safi_community,
10371 show_bgp_view_afi_safi_community2_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010372 "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 -040010373 SHOW_STR
10374 BGP_STR
10375 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010376 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010377 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010378 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010379 "Address family modifier\n"
10380 "Address family modifier\n"
10381 "Display routes matching the communities\n"
10382 "community number\n"
10383 "Do not send outside local AS (well-known community)\n"
10384 "Do not advertise to any peer (well-known community)\n"
10385 "Do not export to next AS (well-known community)\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
10391ALIAS (show_bgp_view_afi_safi_community,
10392 show_bgp_view_afi_safi_community3_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010393 "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 -040010394 SHOW_STR
10395 BGP_STR
10396 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010397 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010398 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010399 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010400 "Address family modifier\n"
10401 "Address family modifier\n"
10402 "Display routes matching the communities\n"
10403 "community number\n"
10404 "Do not send outside local AS (well-known community)\n"
10405 "Do not advertise to any peer (well-known community)\n"
10406 "Do not export to next AS (well-known community)\n"
10407 "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
10416ALIAS (show_bgp_view_afi_safi_community,
10417 show_bgp_view_afi_safi_community4_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010418 "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 -040010419 SHOW_STR
10420 BGP_STR
10421 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010422 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010423 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010424 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010425 "Address family modifier\n"
10426 "Address family modifier\n"
10427 "Display routes matching the communities\n"
10428 "community number\n"
10429 "Do not send outside local AS (well-known community)\n"
10430 "Do not advertise to any peer (well-known community)\n"
10431 "Do not export to next AS (well-known community)\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
Lou Berger651b4022016-01-12 13:42:07 -050010445DEFUN (show_bgp_ipv4_community_exact,
10446 show_bgp_ipv4_community_exact_cmd,
10447 "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010448 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010449 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010450 IP_STR
paul718e3742002-12-13 20:15:29 +000010451 "Display routes matching the communities\n"
10452 "community number\n"
10453 "Do not send outside local AS (well-known community)\n"
10454 "Do not advertise to any peer (well-known community)\n"
10455 "Do not export to next AS (well-known community)\n"
10456 "Exact match of the communities")
10457{
Michael Lambert95cbbd22010-07-23 14:43:04 -040010458 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010459}
10460
Lou Berger651b4022016-01-12 13:42:07 -050010461ALIAS (show_bgp_ipv4_community_exact,
10462 show_bgp_ipv4_community2_exact_cmd,
10463 "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 +000010464 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010465 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010466 IP_STR
paul718e3742002-12-13 20:15:29 +000010467 "Display routes matching the communities\n"
10468 "community number\n"
10469 "Do not send outside local AS (well-known community)\n"
10470 "Do not advertise to any peer (well-known community)\n"
10471 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
10477
Lou Berger651b4022016-01-12 13:42:07 -050010478ALIAS (show_bgp_ipv4_community_exact,
10479 show_bgp_ipv4_community3_exact_cmd,
10480 "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 +000010481 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010482 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010483 IP_STR
paul718e3742002-12-13 20:15:29 +000010484 "Display routes matching the communities\n"
10485 "community number\n"
10486 "Do not send outside local AS (well-known community)\n"
10487 "Do not advertise to any peer (well-known community)\n"
10488 "Do not export to next AS (well-known community)\n"
10489 "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 "Exact match of the communities")
10498
Lou Berger651b4022016-01-12 13:42:07 -050010499ALIAS (show_bgp_ipv4_community_exact,
10500 show_bgp_ipv4_community4_exact_cmd,
10501 "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 +000010502 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010503 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010504 IP_STR
paul718e3742002-12-13 20:15:29 +000010505 "Display routes matching the communities\n"
10506 "community number\n"
10507 "Do not send outside local AS (well-known community)\n"
10508 "Do not advertise to any peer (well-known community)\n"
10509 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
10523
Lou Berger651b4022016-01-12 13:42:07 -050010524DEFUN (show_bgp_ipv4_safi_community4_exact,
10525 show_bgp_ipv4_safi_community_exact_cmd,
10526 "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010527 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010528 BGP_STR
10529 "Address family\n"
10530 "Address Family modifier\n"
10531 "Address Family modifier\n"
10532 "Display routes matching the communities\n"
10533 "community number\n"
10534 "Do not send outside local AS (well-known community)\n"
10535 "Do not advertise to any peer (well-known community)\n"
10536 "Do not export to next AS (well-known community)\n"
10537 "Exact match of the communities")
10538{
10539 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -040010540 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +000010541
Michael Lambert95cbbd22010-07-23 14:43:04 -040010542 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010543}
10544
Lou Berger651b4022016-01-12 13:42:07 -050010545ALIAS (show_bgp_ipv4_safi_community4_exact,
10546 show_bgp_ipv4_safi_community2_exact_cmd,
10547 "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 +000010548 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010549 BGP_STR
10550 "Address family\n"
10551 "Address Family modifier\n"
10552 "Address Family modifier\n"
10553 "Display routes matching the communities\n"
10554 "community number\n"
10555 "Do not send outside local AS (well-known community)\n"
10556 "Do not advertise to any peer (well-known community)\n"
10557 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
10563
Lou Berger651b4022016-01-12 13:42:07 -050010564ALIAS (show_bgp_ipv4_safi_community4_exact,
10565 show_bgp_ipv4_safi_community3_exact_cmd,
10566 "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 +000010567 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010568 BGP_STR
10569 "Address family\n"
10570 "Address Family modifier\n"
10571 "Address Family modifier\n"
10572 "Display routes matching the communities\n"
10573 "community number\n"
10574 "Do not send outside local AS (well-known community)\n"
10575 "Do not advertise to any peer (well-known community)\n"
10576 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
10586
Lou Berger651b4022016-01-12 13:42:07 -050010587ALIAS (show_bgp_ipv4_safi_community4_exact,
10588 show_bgp_ipv4_safi_community4_exact_cmd,
10589 "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 +000010590 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010591 BGP_STR
10592 "Address family\n"
10593 "Address Family modifier\n"
10594 "Address Family modifier\n"
10595 "Display routes matching the communities\n"
10596 "community number\n"
10597 "Do not send outside local AS (well-known community)\n"
10598 "Do not advertise to any peer (well-known community)\n"
10599 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
10613
Lou Bergerf9b6c392016-01-12 13:42:09 -050010614DEFUN (show_bgp_ipv6_safi_community,
10615 show_bgp_ipv6_safi_community_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010616 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010617 SHOW_STR
10618 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010619 "Address family\n"
10620 "Address family modifier\n"
10621 "Address family modifier\n"
10622 "Address family modifier\n"
10623 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010624 "Display routes matching the communities\n"
10625 "community number\n"
10626 "Do not send outside local AS (well-known community)\n"
10627 "Do not advertise to any peer (well-known community)\n"
10628 "Do not export to next AS (well-known community)\n")
10629{
Lou Berger651b4022016-01-12 13:42:07 -050010630 safi_t safi;
10631
10632 if (bgp_parse_safi(argv[0], &safi)) {
10633 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10634 return CMD_WARNING;
10635 }
10636 return bgp_show_community (vty, NULL, argc-1, argv+1, 0, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000010637}
10638
Lou Bergerf9b6c392016-01-12 13:42:09 -050010639ALIAS (show_bgp_ipv6_safi_community,
10640 show_bgp_ipv6_safi_community2_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010641 "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 +000010642 SHOW_STR
10643 BGP_STR
10644 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010645 "Address family modifier\n"
10646 "Address family modifier\n"
10647 "Address family modifier\n"
10648 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010649 "Display routes matching the communities\n"
10650 "community number\n"
10651 "Do not send outside local AS (well-known community)\n"
10652 "Do not advertise to any peer (well-known community)\n"
10653 "Do not export to next AS (well-known community)\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
Lou Bergerf9b6c392016-01-12 13:42:09 -050010659ALIAS (show_bgp_ipv6_safi_community,
10660 show_bgp_ipv6_safi_community3_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010661 "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 +000010662 SHOW_STR
10663 BGP_STR
10664 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010665 "Address family modifier\n"
10666 "Address family modifier\n"
10667 "Address family modifier\n"
10668 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010669 "Display routes matching the communities\n"
10670 "community number\n"
10671 "Do not send outside local AS (well-known community)\n"
10672 "Do not advertise to any peer (well-known community)\n"
10673 "Do not export to next AS (well-known community)\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
Lou Bergerf9b6c392016-01-12 13:42:09 -050010683ALIAS (show_bgp_ipv6_safi_community,
10684 show_bgp_ipv6_safi_community4_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010685 "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 +000010686 SHOW_STR
10687 BGP_STR
10688 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010689 "Address family modifier\n"
10690 "Address family modifier\n"
10691 "Address family modifier\n"
10692 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010693 "Display routes matching the communities\n"
10694 "community number\n"
10695 "Do not send outside local AS (well-known community)\n"
10696 "Do not advertise to any peer (well-known community)\n"
10697 "Do not export to next AS (well-known community)\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
paul718e3742002-12-13 20:15:29 +000010711
Lou Bergerf9b6c392016-01-12 13:42:09 -050010712DEFUN (show_bgp_ipv6_safi_community_exact,
10713 show_bgp_ipv6_safi_community_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010714 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010715 SHOW_STR
10716 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010717 "Address family\n"
10718 "Address family modifier\n"
10719 "Address family modifier\n"
10720 "Address family modifier\n"
10721 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010722 "Display routes matching the communities\n"
10723 "community number\n"
10724 "Do not send outside local AS (well-known community)\n"
10725 "Do not advertise to any peer (well-known community)\n"
10726 "Do not export to next AS (well-known community)\n"
10727 "Exact match of the communities")
10728{
Lou Berger651b4022016-01-12 13:42:07 -050010729 safi_t safi;
10730
10731 if (bgp_parse_safi(argv[0], &safi)) {
10732 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10733 return CMD_WARNING;
10734 }
10735 return bgp_show_community (vty, NULL, argc-1, argv+1, 1, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000010736}
10737
paul718e3742002-12-13 20:15:29 +000010738
10739ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010740 show_bgp_ipv6_safi_community2_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010741 "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 +000010742 SHOW_STR
10743 BGP_STR
10744 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010745 "Address family modifier\n"
10746 "Address family modifier\n"
10747 "Address family modifier\n"
10748 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010749 "Display routes matching the communities\n"
10750 "community number\n"
10751 "Do not send outside local AS (well-known community)\n"
10752 "Do not advertise to any peer (well-known community)\n"
10753 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
10759
10760ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010761 show_bgp_ipv6_safi_community3_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010762 "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 +000010763 SHOW_STR
10764 BGP_STR
10765 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010766 "Address family modifier\n"
10767 "Address family modifier\n"
10768 "Address family modifier\n"
10769 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010770 "Display routes matching the communities\n"
10771 "community number\n"
10772 "Do not send outside local AS (well-known community)\n"
10773 "Do not advertise to any peer (well-known community)\n"
10774 "Do not export to next AS (well-known community)\n"
10775 "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 "Exact match of the communities")
10784
10785ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010786 show_bgp_ipv6_safi_community4_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010787 "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 +000010788 SHOW_STR
10789 BGP_STR
10790 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010791 "Address family modifier\n"
10792 "Address family modifier\n"
10793 "Address family modifier\n"
10794 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010795 "Display routes matching the communities\n"
10796 "community number\n"
10797 "Do not send outside local AS (well-known community)\n"
10798 "Do not advertise to any peer (well-known community)\n"
10799 "Do not export to next AS (well-known community)\n"
10800 "community number\n"
10801 "Do not send outside local AS (well-known community)\n"
10802 "Do not advertise to any peer (well-known community)\n"
10803 "Do not export to next AS (well-known community)\n"
10804 "community number\n"
10805 "Do not send outside local AS (well-known community)\n"
10806 "Do not advertise to any peer (well-known community)\n"
10807 "Do not export to next AS (well-known community)\n"
10808 "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 "Exact match of the communities")
10813
paul94f2b392005-06-28 12:44:16 +000010814static int
paulfd79ac92004-10-13 05:06:08 +000010815bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -040010816 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +000010817{
10818 struct community_list *list;
10819
hassofee6e4e2005-02-02 16:29:31 +000010820 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +000010821 if (list == NULL)
10822 {
10823 vty_out (vty, "%% %s is not a valid community-list name%s", com,
10824 VTY_NEWLINE);
10825 return CMD_WARNING;
10826 }
10827
ajs5a646652004-11-05 01:25:55 +000010828 return bgp_show (vty, NULL, afi, safi,
10829 (exact ? bgp_show_type_community_list_exact :
10830 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +000010831}
10832
Lou Bergerf9b6c392016-01-12 13:42:09 -050010833DEFUN (show_ip_bgp_community_list,
10834 show_ip_bgp_community_list_cmd,
10835 "show ip bgp community-list (<1-500>|WORD)",
10836 SHOW_STR
10837 IP_STR
10838 BGP_STR
10839 "Display routes matching the community-list\n"
10840 "community-list number\n"
10841 "community-list name\n")
10842{
10843 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
10844}
10845
10846DEFUN (show_ip_bgp_ipv4_community_list,
10847 show_ip_bgp_ipv4_community_list_cmd,
10848 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
10849 SHOW_STR
10850 IP_STR
10851 BGP_STR
10852 "Address family\n"
10853 "Address Family modifier\n"
10854 "Address Family modifier\n"
10855 "Display routes matching the community-list\n"
10856 "community-list number\n"
10857 "community-list name\n")
10858{
10859 if (strncmp (argv[0], "m", 1) == 0)
10860 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
10861
10862 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
10863}
10864
10865DEFUN (show_ip_bgp_community_list_exact,
10866 show_ip_bgp_community_list_exact_cmd,
10867 "show ip bgp community-list (<1-500>|WORD) exact-match",
10868 SHOW_STR
10869 IP_STR
10870 BGP_STR
10871 "Display routes matching the community-list\n"
10872 "community-list number\n"
10873 "community-list name\n"
10874 "Exact match of the communities\n")
10875{
10876 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
10877}
10878
10879DEFUN (show_ip_bgp_ipv4_community_list_exact,
10880 show_ip_bgp_ipv4_community_list_exact_cmd,
10881 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
10882 SHOW_STR
10883 IP_STR
10884 BGP_STR
10885 "Address family\n"
10886 "Address Family modifier\n"
10887 "Address Family modifier\n"
10888 "Display routes matching the community-list\n"
10889 "community-list number\n"
10890 "community-list name\n"
10891 "Exact match of the communities\n")
10892{
10893 if (strncmp (argv[0], "m", 1) == 0)
10894 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
10895
10896 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
10897}
10898
Lou Bergerf9b6c392016-01-12 13:42:09 -050010899DEFUN (show_bgp_community_list,
10900 show_bgp_community_list_cmd,
10901 "show bgp community-list (<1-500>|WORD)",
10902 SHOW_STR
10903 BGP_STR
10904 "Display routes matching the community-list\n"
10905 "community-list number\n"
10906 "community-list name\n")
10907{
10908 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
10909}
10910
10911ALIAS (show_bgp_community_list,
10912 show_bgp_ipv6_community_list_cmd,
10913 "show bgp ipv6 community-list (<1-500>|WORD)",
10914 SHOW_STR
10915 BGP_STR
10916 "Address family\n"
10917 "Display routes matching the community-list\n"
10918 "community-list number\n"
10919 "community-list name\n")
10920
10921/* old command */
10922DEFUN (show_ipv6_bgp_community_list,
10923 show_ipv6_bgp_community_list_cmd,
10924 "show ipv6 bgp community-list WORD",
10925 SHOW_STR
10926 IPV6_STR
10927 BGP_STR
10928 "Display routes matching the community-list\n"
10929 "community-list name\n")
10930{
10931 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
10932}
10933
10934/* old command */
10935DEFUN (show_ipv6_mbgp_community_list,
10936 show_ipv6_mbgp_community_list_cmd,
10937 "show ipv6 mbgp community-list WORD",
10938 SHOW_STR
10939 IPV6_STR
10940 MBGP_STR
10941 "Display routes matching the community-list\n"
10942 "community-list name\n")
10943{
10944 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
10945}
10946
10947DEFUN (show_bgp_community_list_exact,
10948 show_bgp_community_list_exact_cmd,
10949 "show bgp community-list (<1-500>|WORD) exact-match",
10950 SHOW_STR
10951 BGP_STR
10952 "Display routes matching the community-list\n"
10953 "community-list number\n"
10954 "community-list name\n"
10955 "Exact match of the communities\n")
10956{
10957 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
10958}
10959
10960ALIAS (show_bgp_community_list_exact,
10961 show_bgp_ipv6_community_list_exact_cmd,
10962 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
10963 SHOW_STR
10964 BGP_STR
10965 "Address family\n"
10966 "Display routes matching the community-list\n"
10967 "community-list number\n"
10968 "community-list name\n"
10969 "Exact match of the communities\n")
10970
10971/* old command */
10972DEFUN (show_ipv6_bgp_community_list_exact,
10973 show_ipv6_bgp_community_list_exact_cmd,
10974 "show ipv6 bgp community-list WORD exact-match",
10975 SHOW_STR
10976 IPV6_STR
10977 BGP_STR
10978 "Display routes matching the community-list\n"
10979 "community-list name\n"
10980 "Exact match of the communities\n")
10981{
10982 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
10983}
10984
10985/* old command */
10986DEFUN (show_ipv6_mbgp_community_list_exact,
10987 show_ipv6_mbgp_community_list_exact_cmd,
10988 "show ipv6 mbgp community-list WORD exact-match",
10989 SHOW_STR
10990 IPV6_STR
10991 MBGP_STR
10992 "Display routes matching the community-list\n"
10993 "community-list name\n"
10994 "Exact match of the communities\n")
10995{
10996 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
10997}
Lou Bergerf9b6c392016-01-12 13:42:09 -050010998
Lou Berger651b4022016-01-12 13:42:07 -050010999DEFUN (show_bgp_ipv4_community_list,
11000 show_bgp_ipv4_community_list_cmd,
11001 "show bgp ipv4 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011002 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011003 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011004 IP_STR
paul718e3742002-12-13 20:15:29 +000011005 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011006 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011007 "community-list name\n")
11008{
11009 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
11010}
11011
Lou Berger651b4022016-01-12 13:42:07 -050011012DEFUN (show_bgp_ipv4_safi_community_list,
11013 show_bgp_ipv4_safi_community_list_cmd,
11014 "show bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011015 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011016 BGP_STR
11017 "Address family\n"
11018 "Address Family modifier\n"
11019 "Address Family modifier\n"
11020 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011021 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011022 "community-list name\n")
11023{
11024 if (strncmp (argv[0], "m", 1) == 0)
11025 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
11026
11027 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
11028}
11029
Lou Berger651b4022016-01-12 13:42:07 -050011030DEFUN (show_bgp_ipv4_community_list_exact,
11031 show_bgp_ipv4_community_list_exact_cmd,
11032 "show bgp ipv4 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011033 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011034 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011035 IP_STR
paul718e3742002-12-13 20:15:29 +000011036 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011037 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011038 "community-list name\n"
11039 "Exact match of the communities\n")
11040{
11041 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
11042}
11043
Lou Berger651b4022016-01-12 13:42:07 -050011044DEFUN (show_bgp_ipv4_safi_community_list_exact,
11045 show_bgp_ipv4_safi_community_list_exact_cmd,
11046 "show bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011047 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011048 BGP_STR
11049 "Address family\n"
11050 "Address Family modifier\n"
11051 "Address Family modifier\n"
11052 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011053 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011054 "community-list name\n"
11055 "Exact match of the communities\n")
11056{
11057 if (strncmp (argv[0], "m", 1) == 0)
11058 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
11059
11060 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
11061}
11062
Lou Bergerf9b6c392016-01-12 13:42:09 -050011063DEFUN (show_bgp_ipv6_safi_community_list,
11064 show_bgp_ipv6_safi_community_list_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011065 "show bgp ipv6 (encap|multicast|unicast|vpn) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011066 SHOW_STR
11067 BGP_STR
11068 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050011069 "Address family modifier\n"
11070 "Address family modifier\n"
11071 "Address family modifier\n"
11072 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000011073 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011074 "community-list number\n"
paule8e19462006-01-19 20:16:55 +000011075 "community-list name\n")
paul718e3742002-12-13 20:15:29 +000011076{
Lou Berger651b4022016-01-12 13:42:07 -050011077 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011078
Lou Berger651b4022016-01-12 13:42:07 -050011079 if (bgp_parse_safi(argv[0], &safi)) {
11080 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11081 return CMD_WARNING;
11082 }
11083 return bgp_show_community_list (vty, argv[1], 0, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000011084}
11085
Lou Bergerf9b6c392016-01-12 13:42:09 -050011086DEFUN (show_bgp_ipv6_safi_community_list_exact,
11087 show_bgp_ipv6_safi_community_list_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011088 "show bgp ipv6 (encap|multicast|unicast|vpn) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011089 SHOW_STR
11090 BGP_STR
11091 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050011092 "Address family modifier\n"
11093 "Address family modifier\n"
11094 "Address family modifier\n"
11095 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000011096 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011097 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011098 "community-list name\n"
11099 "Exact match of the communities\n")
paul718e3742002-12-13 20:15:29 +000011100{
Lou Berger651b4022016-01-12 13:42:07 -050011101 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011102
Lou Berger651b4022016-01-12 13:42:07 -050011103 if (bgp_parse_safi(argv[0], &safi)) {
11104 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11105 return CMD_WARNING;
11106 }
11107 return bgp_show_community_list (vty, argv[1], 1, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000011108}
David Lamparter6b0655a2014-06-04 06:53:35 +020011109
paul94f2b392005-06-28 12:44:16 +000011110static int
paulfd79ac92004-10-13 05:06:08 +000011111bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +000011112 safi_t safi, enum bgp_show_type type)
11113{
11114 int ret;
11115 struct prefix *p;
11116
11117 p = prefix_new();
11118
11119 ret = str2prefix (prefix, p);
11120 if (! ret)
11121 {
11122 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
11123 return CMD_WARNING;
11124 }
11125
ajs5a646652004-11-05 01:25:55 +000011126 ret = bgp_show (vty, NULL, afi, safi, type, p);
11127 prefix_free(p);
11128 return ret;
paul718e3742002-12-13 20:15:29 +000011129}
11130
Lou Bergerf9b6c392016-01-12 13:42:09 -050011131DEFUN (show_ip_bgp_prefix_longer,
11132 show_ip_bgp_prefix_longer_cmd,
11133 "show ip bgp A.B.C.D/M longer-prefixes",
11134 SHOW_STR
11135 IP_STR
11136 BGP_STR
11137 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11138 "Display route and more specific routes\n")
11139{
11140 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11141 bgp_show_type_prefix_longer);
11142}
11143
11144DEFUN (show_ip_bgp_flap_prefix_longer,
11145 show_ip_bgp_flap_prefix_longer_cmd,
11146 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
11147 SHOW_STR
11148 IP_STR
11149 BGP_STR
11150 "Display flap statistics of routes\n"
11151 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11152 "Display route and more specific routes\n")
11153{
11154 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11155 bgp_show_type_flap_prefix_longer);
11156}
11157
11158ALIAS (show_ip_bgp_flap_prefix_longer,
11159 show_ip_bgp_damp_flap_prefix_longer_cmd,
11160 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
11161 SHOW_STR
11162 IP_STR
11163 BGP_STR
11164 "Display detailed information about dampening\n"
11165 "Display flap statistics of routes\n"
11166 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11167 "Display route and more specific routes\n")
11168
11169DEFUN (show_ip_bgp_ipv4_prefix_longer,
11170 show_ip_bgp_ipv4_prefix_longer_cmd,
11171 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
11172 SHOW_STR
11173 IP_STR
11174 BGP_STR
11175 "Address family\n"
11176 "Address Family modifier\n"
11177 "Address Family modifier\n"
11178 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11179 "Display route and more specific routes\n")
11180{
11181 if (strncmp (argv[0], "m", 1) == 0)
11182 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
11183 bgp_show_type_prefix_longer);
11184
11185 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
11186 bgp_show_type_prefix_longer);
11187}
11188
11189DEFUN (show_ip_bgp_flap_address,
11190 show_ip_bgp_flap_address_cmd,
11191 "show ip bgp flap-statistics A.B.C.D",
11192 SHOW_STR
11193 IP_STR
11194 BGP_STR
11195 "Display flap statistics of routes\n"
11196 "Network in the BGP routing table to display\n")
11197{
11198 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11199 bgp_show_type_flap_address);
11200}
11201
11202ALIAS (show_ip_bgp_flap_address,
11203 show_ip_bgp_damp_flap_address_cmd,
11204 "show ip bgp dampening flap-statistics A.B.C.D",
11205 SHOW_STR
11206 IP_STR
11207 BGP_STR
11208 "Display detailed information about dampening\n"
11209 "Display flap statistics of routes\n"
11210 "Network in the BGP routing table to display\n")
11211
11212DEFUN (show_ip_bgp_flap_prefix,
11213 show_ip_bgp_flap_prefix_cmd,
11214 "show ip bgp flap-statistics A.B.C.D/M",
11215 SHOW_STR
11216 IP_STR
11217 BGP_STR
11218 "Display flap statistics of routes\n"
11219 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11220{
11221 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11222 bgp_show_type_flap_prefix);
11223}
11224
11225ALIAS (show_ip_bgp_flap_prefix,
11226 show_ip_bgp_damp_flap_prefix_cmd,
11227 "show ip bgp dampening flap-statistics A.B.C.D/M",
11228 SHOW_STR
11229 IP_STR
11230 BGP_STR
11231 "Display detailed information about dampening\n"
11232 "Display flap statistics of routes\n"
11233 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11234
Lou Bergerf9b6c392016-01-12 13:42:09 -050011235DEFUN (show_bgp_prefix_longer,
11236 show_bgp_prefix_longer_cmd,
11237 "show bgp X:X::X:X/M longer-prefixes",
11238 SHOW_STR
11239 BGP_STR
11240 "IPv6 prefix <network>/<length>\n"
11241 "Display route and more specific routes\n")
11242{
11243 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11244 bgp_show_type_prefix_longer);
11245}
11246
11247/* old command */
11248DEFUN (show_ipv6_bgp_prefix_longer,
11249 show_ipv6_bgp_prefix_longer_cmd,
11250 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11251 SHOW_STR
11252 IPV6_STR
11253 BGP_STR
11254 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11255 "Display route and more specific routes\n")
11256{
11257 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11258 bgp_show_type_prefix_longer);
11259}
11260
11261/* old command */
11262DEFUN (show_ipv6_mbgp_prefix_longer,
11263 show_ipv6_mbgp_prefix_longer_cmd,
11264 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11265 SHOW_STR
11266 IPV6_STR
11267 MBGP_STR
11268 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11269 "Display route and more specific routes\n")
11270{
11271 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
11272 bgp_show_type_prefix_longer);
11273}
Lou Bergerf9b6c392016-01-12 13:42:09 -050011274
Lou Berger651b4022016-01-12 13:42:07 -050011275DEFUN (show_bgp_ipv4_prefix_longer,
11276 show_bgp_ipv4_prefix_longer_cmd,
11277 "show bgp ipv4 A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011278 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011279 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011280 IP_STR
paul718e3742002-12-13 20:15:29 +000011281 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11282 "Display route and more specific routes\n")
11283{
11284 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11285 bgp_show_type_prefix_longer);
11286}
11287
Lou Berger651b4022016-01-12 13:42:07 -050011288DEFUN (show_bgp_ipv4_safi_flap_prefix_longer,
11289 show_bgp_ipv4_safi_flap_prefix_longer_cmd,
11290 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011291 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011292 BGP_STR
11293 "Address family\n"
11294 "Address Family modifier\n"
11295 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050011296 "Address Family modifier\n"
11297 "Address Family modifier\n"
11298 "Display flap statistics of routes\n"
paul718e3742002-12-13 20:15:29 +000011299 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11300 "Display route and more specific routes\n")
11301{
Lou Berger651b4022016-01-12 13:42:07 -050011302 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011303
Lou Berger651b4022016-01-12 13:42:07 -050011304 if (bgp_parse_safi(argv[0], &safi)) {
11305 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11306 return CMD_WARNING;
11307 }
11308 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11309 bgp_show_type_flap_prefix_longer);
paul718e3742002-12-13 20:15:29 +000011310}
11311
Lou Berger651b4022016-01-12 13:42:07 -050011312ALIAS (show_bgp_ipv4_safi_flap_prefix_longer,
11313 show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd,
11314 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011315 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011316 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011317 "Address family\n"
11318 "Address Family modifier\n"
11319 "Address Family modifier\n"
11320 "Address Family modifier\n"
11321 "Address Family modifier\n"
11322 "Display detailed information about dampening\n"
11323 "Display flap statistics of routes\n"
11324 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11325 "Display route and more specific routes\n")
11326
Lou Berger651b4022016-01-12 13:42:07 -050011327DEFUN (show_bgp_ipv6_safi_flap_prefix_longer,
11328 show_bgp_ipv6_safi_flap_prefix_longer_cmd,
11329 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics X:X::X:X/M longer-prefixes",
11330 SHOW_STR
11331 BGP_STR
11332 "Address family\n"
11333 "Address Family modifier\n"
11334 "Address Family modifier\n"
11335 "Address Family modifier\n"
11336 "Address Family modifier\n"
11337 "Display flap statistics of routes\n"
11338 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11339 "Display route and more specific routes\n")
11340{
11341 safi_t safi;
11342
11343 if (bgp_parse_safi(argv[0], &safi)) {
11344 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11345 return CMD_WARNING;
11346 }
11347 return bgp_show_prefix_longer (vty, argv[1], AFI_IP6, safi,
11348 bgp_show_type_flap_prefix_longer);
11349}
11350ALIAS (show_bgp_ipv6_safi_flap_prefix_longer,
11351 show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd,
11352 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics X:X::X:X/M longer-prefixes",
11353 SHOW_STR
11354 BGP_STR
11355 "Address family\n"
11356 "Address Family modifier\n"
11357 "Address Family modifier\n"
11358 "Address Family modifier\n"
11359 "Address Family modifier\n"
11360 "Display detailed information about dampening\n"
11361 "Display flap statistics of routes\n"
11362 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11363 "Display route and more specific routes\n")
Lou Berger651b4022016-01-12 13:42:07 -050011364
11365DEFUN (show_bgp_ipv4_safi_prefix_longer,
11366 show_bgp_ipv4_safi_prefix_longer_cmd,
11367 "show bgp ipv4 (encap|multicast|unicast|vpn) A.B.C.D/M longer-prefixes",
11368 SHOW_STR
11369 BGP_STR
11370 "Address family\n"
11371 "Address Family modifier\n"
11372 "Address Family modifier\n"
11373 "Address Family modifier\n"
11374 "Address Family modifier\n"
11375 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11376 "Display route and more specific routes\n")
11377{
11378 safi_t safi;
11379
11380 if (bgp_parse_safi(argv[0], &safi)) {
11381 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11382 return CMD_WARNING;
11383 }
11384
11385 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11386 bgp_show_type_prefix_longer);
11387}
11388
Lou Berger651b4022016-01-12 13:42:07 -050011389DEFUN (show_bgp_ipv6_safi_prefix_longer,
11390 show_bgp_ipv6_safi_prefix_longer_cmd,
11391 "show bgp ipv6 (encap|multicast|unicast|vpn) X:X::X:X/M longer-prefixes",
11392 SHOW_STR
11393 BGP_STR
11394 "Address family\n"
11395 "Address Family modifier\n"
11396 "Address Family modifier\n"
11397 "Address Family modifier\n"
11398 "Address Family modifier\n"
11399 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11400 "Display route and more specific routes\n")
11401{
11402 safi_t safi;
11403
11404 if (bgp_parse_safi(argv[0], &safi)) {
11405 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11406 return CMD_WARNING;
11407 }
11408
11409 return bgp_show_prefix_longer (vty, argv[1], AFI_IP6, safi,
11410 bgp_show_type_prefix_longer);
11411}
Lou Berger651b4022016-01-12 13:42:07 -050011412
11413DEFUN (show_bgp_ipv4_safi_flap_address,
11414 show_bgp_ipv4_safi_flap_address_cmd,
11415 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D",
11416 SHOW_STR
11417 BGP_STR
11418 "Address family\n"
11419 "Address Family modifier\n"
11420 "Address Family modifier\n"
11421 "Address Family modifier\n"
11422 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000011423 "Display flap statistics of routes\n"
11424 "Network in the BGP routing table to display\n")
11425{
Lou Berger651b4022016-01-12 13:42:07 -050011426 safi_t safi;
11427
11428 if (bgp_parse_safi(argv[0], &safi)) {
11429 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11430 return CMD_WARNING;
11431 }
11432 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000011433 bgp_show_type_flap_address);
11434}
Lou Berger651b4022016-01-12 13:42:07 -050011435ALIAS (show_bgp_ipv4_safi_flap_address,
11436 show_bgp_ipv4_safi_damp_flap_address_cmd,
11437 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D",
Balaji3921cc52015-05-16 23:12:17 +053011438 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053011439 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011440 "Address family\n"
11441 "Address Family modifier\n"
11442 "Address Family modifier\n"
11443 "Address Family modifier\n"
11444 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053011445 "Display detailed information about dampening\n"
11446 "Display flap statistics of routes\n"
11447 "Network in the BGP routing table to display\n")
Lou Berger205e6742016-01-12 13:42:11 -050011448
Lou Berger651b4022016-01-12 13:42:07 -050011449DEFUN (show_bgp_ipv6_flap_address,
11450 show_bgp_ipv6_flap_address_cmd,
11451 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D",
paul718e3742002-12-13 20:15:29 +000011452 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011453 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011454 "Address family\n"
11455 "Address Family modifier\n"
11456 "Address Family modifier\n"
11457 "Address Family modifier\n"
11458 "Address Family modifier\n"
11459 "Display flap statistics of routes\n"
11460 "Network in the BGP routing table to display\n")
11461{
11462 safi_t safi;
11463
11464 if (bgp_parse_safi(argv[0], &safi)) {
11465 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11466 return CMD_WARNING;
11467 }
11468 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11469 bgp_show_type_flap_address);
11470}
11471ALIAS (show_bgp_ipv6_flap_address,
11472 show_bgp_ipv6_damp_flap_address_cmd,
11473 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D",
11474 SHOW_STR
11475 BGP_STR
11476 "Address family\n"
11477 "Address Family modifier\n"
11478 "Address Family modifier\n"
11479 "Address Family modifier\n"
11480 "Address Family modifier\n"
11481 "Display detailed information about dampening\n"
11482 "Display flap statistics of routes\n"
11483 "Network in the BGP routing table to display\n")
Lou Berger651b4022016-01-12 13:42:07 -050011484
11485DEFUN (show_bgp_ipv4_safi_flap_prefix,
11486 show_bgp_ipv4_safi_flap_prefix_cmd,
11487 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D/M",
11488 SHOW_STR
11489 BGP_STR
11490 "Address family\n"
11491 "Address Family modifier\n"
11492 "Address Family modifier\n"
11493 "Address Family modifier\n"
11494 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000011495 "Display flap statistics of routes\n"
11496 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11497{
Lou Berger651b4022016-01-12 13:42:07 -050011498 safi_t safi;
11499
11500 if (bgp_parse_safi(argv[0], &safi)) {
11501 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11502 return CMD_WARNING;
11503 }
11504 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000011505 bgp_show_type_flap_prefix);
11506}
Balaji3921cc52015-05-16 23:12:17 +053011507
Lou Berger651b4022016-01-12 13:42:07 -050011508ALIAS (show_bgp_ipv4_safi_flap_prefix,
11509 show_bgp_ipv4_safi_damp_flap_prefix_cmd,
11510 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D/M",
Balaji3921cc52015-05-16 23:12:17 +053011511 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053011512 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011513 "Address family\n"
11514 "Address Family modifier\n"
11515 "Address Family modifier\n"
11516 "Address Family modifier\n"
11517 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053011518 "Display detailed information about dampening\n"
11519 "Display flap statistics of routes\n"
11520 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11521
Lou Berger651b4022016-01-12 13:42:07 -050011522DEFUN (show_bgp_ipv6_safi_flap_prefix,
11523 show_bgp_ipv6_safi_flap_prefix_cmd,
11524 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics X:X::X:X/M",
paul718e3742002-12-13 20:15:29 +000011525 SHOW_STR
11526 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011527 "Address family\n"
11528 "Address Family modifier\n"
11529 "Address Family modifier\n"
11530 "Address Family modifier\n"
11531 "Address Family modifier\n"
11532 "Display flap statistics of routes\n"
11533 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paul718e3742002-12-13 20:15:29 +000011534{
Lou Berger651b4022016-01-12 13:42:07 -050011535 safi_t safi;
11536
11537 if (bgp_parse_safi(argv[0], &safi)) {
11538 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11539 return CMD_WARNING;
11540 }
11541 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, safi,
11542 bgp_show_type_flap_prefix);
paul718e3742002-12-13 20:15:29 +000011543}
11544
Lou Berger651b4022016-01-12 13:42:07 -050011545ALIAS (show_bgp_ipv6_safi_flap_prefix,
11546 show_bgp_ipv6_safi_damp_flap_prefix_cmd,
11547 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics X:X::X:X/M",
11548 SHOW_STR
11549 BGP_STR
11550 "Address family\n"
11551 "Address Family modifier\n"
11552 "Address Family modifier\n"
11553 "Address Family modifier\n"
11554 "Address Family modifier\n"
11555 "Display detailed information about dampening\n"
11556 "Display flap statistics of routes\n"
11557 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11558
11559DEFUN (show_bgp_ipv6_prefix_longer,
paul718e3742002-12-13 20:15:29 +000011560 show_bgp_ipv6_prefix_longer_cmd,
11561 "show bgp ipv6 X:X::X:X/M longer-prefixes",
11562 SHOW_STR
11563 BGP_STR
11564 "Address family\n"
11565 "IPv6 prefix <network>/<length>\n"
11566 "Display route and more specific routes\n")
paul718e3742002-12-13 20:15:29 +000011567{
11568 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11569 bgp_show_type_prefix_longer);
11570}
11571
paul94f2b392005-06-28 12:44:16 +000011572static struct peer *
paulfd79ac92004-10-13 05:06:08 +000011573peer_lookup_in_view (struct vty *vty, const char *view_name,
11574 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +000011575{
11576 int ret;
11577 struct bgp *bgp;
11578 struct peer *peer;
11579 union sockunion su;
11580
11581 /* BGP structure lookup. */
11582 if (view_name)
11583 {
11584 bgp = bgp_lookup_by_name (view_name);
11585 if (! bgp)
11586 {
11587 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11588 return NULL;
11589 }
11590 }
paul5228ad22004-06-04 17:58:18 +000011591 else
paulbb46e942003-10-24 19:02:03 +000011592 {
11593 bgp = bgp_get_default ();
11594 if (! bgp)
11595 {
11596 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11597 return NULL;
11598 }
11599 }
11600
11601 /* Get peer sockunion. */
11602 ret = str2sockunion (ip_str, &su);
11603 if (ret < 0)
11604 {
11605 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
11606 return NULL;
11607 }
11608
11609 /* Peer structure lookup. */
11610 peer = peer_lookup (bgp, &su);
11611 if (! peer)
11612 {
11613 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
11614 return NULL;
11615 }
11616
11617 return peer;
11618}
David Lamparter6b0655a2014-06-04 06:53:35 +020011619
Paul Jakma2815e612006-09-14 02:56:07 +000011620enum bgp_stats
11621{
11622 BGP_STATS_MAXBITLEN = 0,
11623 BGP_STATS_RIB,
11624 BGP_STATS_PREFIXES,
11625 BGP_STATS_TOTPLEN,
11626 BGP_STATS_UNAGGREGATEABLE,
11627 BGP_STATS_MAX_AGGREGATEABLE,
11628 BGP_STATS_AGGREGATES,
11629 BGP_STATS_SPACE,
11630 BGP_STATS_ASPATH_COUNT,
11631 BGP_STATS_ASPATH_MAXHOPS,
11632 BGP_STATS_ASPATH_TOTHOPS,
11633 BGP_STATS_ASPATH_MAXSIZE,
11634 BGP_STATS_ASPATH_TOTSIZE,
11635 BGP_STATS_ASN_HIGHEST,
11636 BGP_STATS_MAX,
11637};
paulbb46e942003-10-24 19:02:03 +000011638
Paul Jakma2815e612006-09-14 02:56:07 +000011639static const char *table_stats_strs[] =
11640{
11641 [BGP_STATS_PREFIXES] = "Total Prefixes",
11642 [BGP_STATS_TOTPLEN] = "Average prefix length",
11643 [BGP_STATS_RIB] = "Total Advertisements",
11644 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11645 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11646 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11647 [BGP_STATS_SPACE] = "Address space advertised",
11648 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11649 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11650 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11651 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11652 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11653 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11654 [BGP_STATS_MAX] = NULL,
11655};
11656
11657struct bgp_table_stats
11658{
11659 struct bgp_table *table;
11660 unsigned long long counts[BGP_STATS_MAX];
11661};
11662
11663#if 0
11664#define TALLY_SIGFIG 100000
11665static unsigned long
11666ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11667{
11668 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11669 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11670 unsigned long ret = newtot / count;
11671
11672 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11673 return ret + 1;
11674 else
11675 return ret;
11676}
11677#endif
11678
11679static int
11680bgp_table_stats_walker (struct thread *t)
11681{
11682 struct bgp_node *rn;
11683 struct bgp_node *top;
11684 struct bgp_table_stats *ts = THREAD_ARG (t);
11685 unsigned int space = 0;
11686
Paul Jakma53d9f672006-10-15 23:41:16 +000011687 if (!(top = bgp_table_top (ts->table)))
11688 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +000011689
11690 switch (top->p.family)
11691 {
11692 case AF_INET:
11693 space = IPV4_MAX_BITLEN;
11694 break;
11695 case AF_INET6:
11696 space = IPV6_MAX_BITLEN;
11697 break;
11698 }
11699
11700 ts->counts[BGP_STATS_MAXBITLEN] = space;
11701
11702 for (rn = top; rn; rn = bgp_route_next (rn))
11703 {
11704 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -070011705 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +000011706 unsigned int rinum = 0;
11707
11708 if (rn == top)
11709 continue;
11710
11711 if (!rn->info)
11712 continue;
11713
11714 ts->counts[BGP_STATS_PREFIXES]++;
11715 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11716
11717#if 0
11718 ts->counts[BGP_STATS_AVGPLEN]
11719 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11720 ts->counts[BGP_STATS_AVGPLEN],
11721 rn->p.prefixlen);
11722#endif
11723
11724 /* check if the prefix is included by any other announcements */
11725 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -070011726 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +000011727
11728 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +000011729 {
11730 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11731 /* announced address space */
11732 if (space)
11733 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11734 }
Paul Jakma2815e612006-09-14 02:56:07 +000011735 else if (prn->info)
11736 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11737
Paul Jakma2815e612006-09-14 02:56:07 +000011738 for (ri = rn->info; ri; ri = ri->next)
11739 {
11740 rinum++;
11741 ts->counts[BGP_STATS_RIB]++;
11742
11743 if (ri->attr &&
11744 (CHECK_FLAG (ri->attr->flag,
11745 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11746 ts->counts[BGP_STATS_AGGREGATES]++;
11747
11748 /* as-path stats */
11749 if (ri->attr && ri->attr->aspath)
11750 {
11751 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11752 unsigned int size = aspath_size (ri->attr->aspath);
11753 as_t highest = aspath_highest (ri->attr->aspath);
11754
11755 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11756
11757 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11758 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11759
11760 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11761 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11762
11763 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11764 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11765#if 0
11766 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11767 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11768 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11769 hops);
11770 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11771 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11772 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11773 size);
11774#endif
11775 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11776 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11777 }
11778 }
11779 }
11780 return 0;
11781}
11782
11783static int
11784bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11785{
11786 struct bgp_table_stats ts;
11787 unsigned int i;
11788
11789 if (!bgp->rib[afi][safi])
11790 {
Donald Sharp3c964042016-01-25 23:38:53 -050011791 vty_out (vty, "%% No RIB exists for the specified AFI(%d)/SAFI(%d) %s",
11792 afi, safi, VTY_NEWLINE);
Paul Jakma2815e612006-09-14 02:56:07 +000011793 return CMD_WARNING;
11794 }
11795
11796 memset (&ts, 0, sizeof (ts));
11797 ts.table = bgp->rib[afi][safi];
11798 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
11799
11800 vty_out (vty, "BGP %s RIB statistics%s%s",
11801 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
11802
11803 for (i = 0; i < BGP_STATS_MAX; i++)
11804 {
11805 if (!table_stats_strs[i])
11806 continue;
11807
11808 switch (i)
11809 {
11810#if 0
11811 case BGP_STATS_ASPATH_AVGHOPS:
11812 case BGP_STATS_ASPATH_AVGSIZE:
11813 case BGP_STATS_AVGPLEN:
11814 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11815 vty_out (vty, "%12.2f",
11816 (float)ts.counts[i] / (float)TALLY_SIGFIG);
11817 break;
11818#endif
11819 case BGP_STATS_ASPATH_TOTHOPS:
11820 case BGP_STATS_ASPATH_TOTSIZE:
11821 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11822 vty_out (vty, "%12.2f",
11823 ts.counts[i] ?
11824 (float)ts.counts[i] /
11825 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
11826 : 0);
11827 break;
11828 case BGP_STATS_TOTPLEN:
11829 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11830 vty_out (vty, "%12.2f",
11831 ts.counts[i] ?
11832 (float)ts.counts[i] /
11833 (float)ts.counts[BGP_STATS_PREFIXES]
11834 : 0);
11835 break;
11836 case BGP_STATS_SPACE:
11837 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11838 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
11839 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
11840 break;
Paul Jakma30a22312008-08-15 14:05:22 +010011841 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +000011842 vty_out (vty, "%12.2f%s",
11843 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +000011844 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +000011845 VTY_NEWLINE);
11846 vty_out (vty, "%30s: ", "/8 equivalent ");
11847 vty_out (vty, "%12.2f%s",
11848 (float)ts.counts[BGP_STATS_SPACE] /
11849 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
11850 VTY_NEWLINE);
11851 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
11852 break;
11853 vty_out (vty, "%30s: ", "/24 equivalent ");
11854 vty_out (vty, "%12.2f",
11855 (float)ts.counts[BGP_STATS_SPACE] /
11856 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
11857 break;
11858 default:
11859 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11860 vty_out (vty, "%12llu", ts.counts[i]);
11861 }
11862
11863 vty_out (vty, "%s", VTY_NEWLINE);
11864 }
11865 return CMD_SUCCESS;
11866}
11867
11868static int
11869bgp_table_stats_vty (struct vty *vty, const char *name,
11870 const char *afi_str, const char *safi_str)
11871{
11872 struct bgp *bgp;
11873 afi_t afi;
11874 safi_t safi;
11875
11876 if (name)
11877 bgp = bgp_lookup_by_name (name);
11878 else
11879 bgp = bgp_get_default ();
11880
11881 if (!bgp)
11882 {
Lou Bergerbf1ae6c2016-01-12 13:42:08 -050011883 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
Paul Jakma2815e612006-09-14 02:56:07 +000011884 return CMD_WARNING;
11885 }
11886 if (strncmp (afi_str, "ipv", 3) == 0)
11887 {
11888 if (strncmp (afi_str, "ipv4", 4) == 0)
11889 afi = AFI_IP;
11890 else if (strncmp (afi_str, "ipv6", 4) == 0)
11891 afi = AFI_IP6;
11892 else
11893 {
11894 vty_out (vty, "%% Invalid address family %s%s",
11895 afi_str, VTY_NEWLINE);
11896 return CMD_WARNING;
11897 }
Lou Berger298cc2f2016-01-12 13:42:02 -050011898 switch (safi_str[0]) {
11899 case 'm':
11900 safi = SAFI_MULTICAST;
11901 break;
11902 case 'u':
11903 safi = SAFI_UNICAST;
11904 break;
11905 case 'v':
Donald Sharp3c964042016-01-25 23:38:53 -050011906 safi = SAFI_MPLS_VPN;
Lou Berger298cc2f2016-01-12 13:42:02 -050011907 break;
11908 case 'e':
11909 safi = SAFI_ENCAP;
11910 break;
11911 default:
11912 vty_out (vty, "%% Invalid subsequent address family %s%s",
Paul Jakma2815e612006-09-14 02:56:07 +000011913 safi_str, VTY_NEWLINE);
Lou Berger298cc2f2016-01-12 13:42:02 -050011914 return CMD_WARNING;
11915 }
Paul Jakma2815e612006-09-14 02:56:07 +000011916 }
11917 else
11918 {
Lou Berger298cc2f2016-01-12 13:42:02 -050011919 vty_out (vty, "%% Invalid address family \"%s\"%s",
Paul Jakma2815e612006-09-14 02:56:07 +000011920 afi_str, VTY_NEWLINE);
11921 return CMD_WARNING;
11922 }
11923
Paul Jakma2815e612006-09-14 02:56:07 +000011924 return bgp_table_stats (vty, bgp, afi, safi);
11925}
11926
11927DEFUN (show_bgp_statistics,
11928 show_bgp_statistics_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -050011929 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000011930 SHOW_STR
11931 BGP_STR
11932 "Address family\n"
11933 "Address family\n"
11934 "Address Family modifier\n"
11935 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -050011936 "Address Family modifier\n"
11937 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +000011938 "BGP RIB advertisement statistics\n")
11939{
11940 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11941}
11942
Lou Bergerf9b6c392016-01-12 13:42:09 -050011943ALIAS (show_bgp_statistics,
11944 show_bgp_statistics_vpnv4_cmd,
11945 "show bgp (ipv4) (vpnv4) statistics",
11946 SHOW_STR
11947 BGP_STR
11948 "Address family\n"
11949 "Address Family modifier\n"
11950 "BGP RIB advertisement statistics\n")
11951
Paul Jakma2815e612006-09-14 02:56:07 +000011952DEFUN (show_bgp_statistics_view,
11953 show_bgp_statistics_view_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -050011954 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000011955 SHOW_STR
11956 BGP_STR
11957 "BGP view\n"
11958 "Address family\n"
11959 "Address family\n"
11960 "Address Family modifier\n"
11961 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -050011962 "Address Family modifier\n"
11963 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +000011964 "BGP RIB advertisement statistics\n")
11965{
11966 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
11967}
11968
11969ALIAS (show_bgp_statistics_view,
Lou Bergerf9b6c392016-01-12 13:42:09 -050011970 show_bgp_statistics_view_vpnv4_cmd,
11971 "show bgp view WORD (ipv4) (vpnv4) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000011972 SHOW_STR
11973 BGP_STR
11974 "BGP view\n"
11975 "Address family\n"
11976 "Address Family modifier\n"
11977 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +020011978
Paul Jakmaff7924f2006-09-04 01:10:36 +000011979enum bgp_pcounts
11980{
11981 PCOUNT_ADJ_IN = 0,
11982 PCOUNT_DAMPED,
11983 PCOUNT_REMOVED,
11984 PCOUNT_HISTORY,
11985 PCOUNT_STALE,
11986 PCOUNT_VALID,
11987 PCOUNT_ALL,
11988 PCOUNT_COUNTED,
11989 PCOUNT_PFCNT, /* the figure we display to users */
11990 PCOUNT_MAX,
11991};
11992
11993static const char *pcount_strs[] =
11994{
11995 [PCOUNT_ADJ_IN] = "Adj-in",
11996 [PCOUNT_DAMPED] = "Damped",
11997 [PCOUNT_REMOVED] = "Removed",
11998 [PCOUNT_HISTORY] = "History",
11999 [PCOUNT_STALE] = "Stale",
12000 [PCOUNT_VALID] = "Valid",
12001 [PCOUNT_ALL] = "All RIB",
12002 [PCOUNT_COUNTED] = "PfxCt counted",
12003 [PCOUNT_PFCNT] = "Useable",
12004 [PCOUNT_MAX] = NULL,
12005};
12006
Paul Jakma2815e612006-09-14 02:56:07 +000012007struct peer_pcounts
12008{
12009 unsigned int count[PCOUNT_MAX];
12010 const struct peer *peer;
12011 const struct bgp_table *table;
12012};
12013
Paul Jakmaff7924f2006-09-04 01:10:36 +000012014static int
Paul Jakma2815e612006-09-14 02:56:07 +000012015bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +000012016{
12017 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +000012018 struct peer_pcounts *pc = THREAD_ARG (t);
12019 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012020
Paul Jakma2815e612006-09-14 02:56:07 +000012021 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012022 {
12023 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +000012024 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012025
12026 for (ain = rn->adj_in; ain; ain = ain->next)
12027 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +000012028 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012029
Paul Jakmaff7924f2006-09-04 01:10:36 +000012030 for (ri = rn->info; ri; ri = ri->next)
12031 {
12032 char buf[SU_ADDRSTRLEN];
12033
12034 if (ri->peer != peer)
12035 continue;
12036
Paul Jakma2815e612006-09-14 02:56:07 +000012037 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012038
12039 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +000012040 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012041 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +000012042 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012043 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +000012044 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012045 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +000012046 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012047 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +000012048 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +000012049 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +000012050 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012051
12052 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
12053 {
Paul Jakma2815e612006-09-14 02:56:07 +000012054 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +000012055 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012056 plog_warn (peer->log,
12057 "%s [pcount] %s/%d is counted but flags 0x%x",
12058 peer->host,
12059 inet_ntop(rn->p.family, &rn->p.u.prefix,
12060 buf, SU_ADDRSTRLEN),
12061 rn->p.prefixlen,
12062 ri->flags);
12063 }
12064 else
12065 {
Paul Jakma1a392d42006-09-07 00:24:49 +000012066 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012067 plog_warn (peer->log,
12068 "%s [pcount] %s/%d not counted but flags 0x%x",
12069 peer->host,
12070 inet_ntop(rn->p.family, &rn->p.u.prefix,
12071 buf, SU_ADDRSTRLEN),
12072 rn->p.prefixlen,
12073 ri->flags);
12074 }
12075 }
12076 }
Paul Jakma2815e612006-09-14 02:56:07 +000012077 return 0;
12078}
Paul Jakmaff7924f2006-09-04 01:10:36 +000012079
Paul Jakma2815e612006-09-14 02:56:07 +000012080static int
12081bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
12082{
12083 struct peer_pcounts pcounts = { .peer = peer };
12084 unsigned int i;
12085
12086 if (!peer || !peer->bgp || !peer->afc[afi][safi]
12087 || !peer->bgp->rib[afi][safi])
12088 {
12089 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12090 return CMD_WARNING;
12091 }
12092
12093 memset (&pcounts, 0, sizeof(pcounts));
12094 pcounts.peer = peer;
12095 pcounts.table = peer->bgp->rib[afi][safi];
12096
12097 /* in-place call via thread subsystem so as to record execution time
12098 * stats for the thread-walk (i.e. ensure this can't be blamed on
12099 * on just vty_read()).
12100 */
12101 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
12102
Paul Jakmaff7924f2006-09-04 01:10:36 +000012103 vty_out (vty, "Prefix counts for %s, %s%s",
12104 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
12105 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
12106 vty_out (vty, "%sCounts from RIB table walk:%s%s",
12107 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
12108
12109 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +000012110 vty_out (vty, "%20s: %-10d%s",
12111 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012112
Paul Jakma2815e612006-09-14 02:56:07 +000012113 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +000012114 {
12115 vty_out (vty, "%s [pcount] PfxCt drift!%s",
12116 peer->host, VTY_NEWLINE);
12117 vty_out (vty, "Please report this bug, with the above command output%s",
12118 VTY_NEWLINE);
12119 }
12120
12121 return CMD_SUCCESS;
12122}
12123
Lou Bergerf9b6c392016-01-12 13:42:09 -050012124DEFUN (show_ip_bgp_neighbor_prefix_counts,
12125 show_ip_bgp_neighbor_prefix_counts_cmd,
12126 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12127 SHOW_STR
12128 IP_STR
12129 BGP_STR
12130 "Detailed information on TCP and BGP neighbor connections\n"
12131 "Neighbor to display information about\n"
12132 "Neighbor to display information about\n"
12133 "Display detailed prefix count information\n")
12134{
12135 struct peer *peer;
12136
12137 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12138 if (! peer)
12139 return CMD_WARNING;
12140
12141 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
12142}
12143
Paul Jakmaff7924f2006-09-04 01:10:36 +000012144DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
12145 show_bgp_ipv6_neighbor_prefix_counts_cmd,
12146 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12147 SHOW_STR
12148 BGP_STR
12149 "Address family\n"
12150 "Detailed information on TCP and BGP neighbor connections\n"
12151 "Neighbor to display information about\n"
12152 "Neighbor to display information about\n"
12153 "Display detailed prefix count information\n")
12154{
12155 struct peer *peer;
12156
12157 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12158 if (! peer)
12159 return CMD_WARNING;
12160
12161 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
12162}
Lou Bergerf9b6c392016-01-12 13:42:09 -050012163
12164DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
12165 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
12166 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12167 SHOW_STR
12168 IP_STR
12169 BGP_STR
12170 "Address family\n"
12171 "Address Family modifier\n"
12172 "Address Family modifier\n"
12173 "Detailed information on TCP and BGP neighbor connections\n"
12174 "Neighbor to display information about\n"
12175 "Neighbor to display information about\n"
12176 "Display detailed prefix count information\n")
12177{
12178 struct peer *peer;
12179
12180 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12181 if (! peer)
12182 return CMD_WARNING;
12183
12184 if (strncmp (argv[0], "m", 1) == 0)
12185 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
12186
12187 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
12188}
12189
12190DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
12191 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
12192 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12193 SHOW_STR
12194 IP_STR
12195 BGP_STR
12196 "Address family\n"
12197 "Address Family modifier\n"
12198 "Address Family modifier\n"
12199 "Detailed information on TCP and BGP neighbor connections\n"
12200 "Neighbor to display information about\n"
12201 "Neighbor to display information about\n"
12202 "Display detailed prefix count information\n")
12203{
12204 struct peer *peer;
12205
12206 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12207 if (! peer)
12208 return CMD_WARNING;
12209
12210 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
12211}
Paul Jakmaff7924f2006-09-04 01:10:36 +000012212
Lou Berger651b4022016-01-12 13:42:07 -050012213DEFUN (show_bgp_ipv4_safi_neighbor_prefix_counts,
12214 show_bgp_ipv4_safi_neighbor_prefix_counts_cmd,
12215 "show bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
Paul Jakmaff7924f2006-09-04 01:10:36 +000012216 SHOW_STR
Paul Jakmaff7924f2006-09-04 01:10:36 +000012217 BGP_STR
12218 "Address family\n"
12219 "Address Family modifier\n"
12220 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050012221 "Address Family modifier\n"
12222 "Address Family modifier\n"
Paul Jakmaff7924f2006-09-04 01:10:36 +000012223 "Detailed information on TCP and BGP neighbor connections\n"
12224 "Neighbor to display information about\n"
12225 "Neighbor to display information about\n"
12226 "Display detailed prefix count information\n")
12227{
12228 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050012229 safi_t safi;
12230
12231 if (bgp_parse_safi(argv[0], &safi)) {
12232 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12233 return CMD_WARNING;
12234 }
Paul Jakmaff7924f2006-09-04 01:10:36 +000012235
12236 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12237 if (! peer)
12238 return CMD_WARNING;
12239
Lou Berger651b4022016-01-12 13:42:07 -050012240 return bgp_peer_counts (vty, peer, AFI_IP, safi);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012241}
Lou Berger205e6742016-01-12 13:42:11 -050012242
Lou Berger651b4022016-01-12 13:42:07 -050012243DEFUN (show_bgp_ipv6_safi_neighbor_prefix_counts,
12244 show_bgp_ipv6_safi_neighbor_prefix_counts_cmd,
12245 "show bgp ipv6 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12246 SHOW_STR
12247 BGP_STR
12248 "Address family\n"
12249 "Address Family modifier\n"
12250 "Address Family modifier\n"
12251 "Address Family modifier\n"
12252 "Address Family modifier\n"
12253 "Detailed information on TCP and BGP neighbor connections\n"
12254 "Neighbor to display information about\n"
12255 "Neighbor to display information about\n"
12256 "Display detailed prefix count information\n")
12257{
12258 struct peer *peer;
12259 safi_t safi;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012260
Lou Berger651b4022016-01-12 13:42:07 -050012261 if (bgp_parse_safi(argv[0], &safi)) {
12262 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12263 return CMD_WARNING;
12264 }
12265
12266 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12267 if (! peer)
12268 return CMD_WARNING;
12269
12270 return bgp_peer_counts (vty, peer, AFI_IP6, safi);
12271}
Lou Berger651b4022016-01-12 13:42:07 -050012272
12273DEFUN (show_ip_bgp_encap_neighbor_prefix_counts,
12274 show_ip_bgp_encap_neighbor_prefix_counts_cmd,
12275 "show ip bgp encap all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
Paul Jakmaff7924f2006-09-04 01:10:36 +000012276 SHOW_STR
12277 IP_STR
12278 BGP_STR
12279 "Address family\n"
12280 "Address Family modifier\n"
12281 "Address Family modifier\n"
12282 "Detailed information on TCP and BGP neighbor connections\n"
12283 "Neighbor to display information about\n"
12284 "Neighbor to display information about\n"
12285 "Display detailed prefix count information\n")
12286{
12287 struct peer *peer;
12288
12289 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12290 if (! peer)
12291 return CMD_WARNING;
12292
Lou Berger651b4022016-01-12 13:42:07 -050012293 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_ENCAP);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012294}
12295
12296
paul94f2b392005-06-28 12:44:16 +000012297static void
paul718e3742002-12-13 20:15:29 +000012298show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
12299 int in)
12300{
12301 struct bgp_table *table;
12302 struct bgp_adj_in *ain;
12303 struct bgp_adj_out *adj;
12304 unsigned long output_count;
12305 struct bgp_node *rn;
12306 int header1 = 1;
12307 struct bgp *bgp;
12308 int header2 = 1;
12309
paulbb46e942003-10-24 19:02:03 +000012310 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +000012311
12312 if (! bgp)
12313 return;
12314
12315 table = bgp->rib[afi][safi];
12316
12317 output_count = 0;
12318
12319 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
12320 PEER_STATUS_DEFAULT_ORIGINATE))
12321 {
12322 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 +000012323 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12324 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012325
12326 vty_out (vty, "Originating default network 0.0.0.0%s%s",
12327 VTY_NEWLINE, VTY_NEWLINE);
12328 header1 = 0;
12329 }
12330
12331 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12332 if (in)
12333 {
12334 for (ain = rn->adj_in; ain; ain = ain->next)
12335 if (ain->peer == peer)
12336 {
12337 if (header1)
12338 {
12339 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 +000012340 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12341 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012342 header1 = 0;
12343 }
12344 if (header2)
12345 {
12346 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12347 header2 = 0;
12348 }
12349 if (ain->attr)
12350 {
12351 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
12352 output_count++;
12353 }
12354 }
12355 }
12356 else
12357 {
12358 for (adj = rn->adj_out; adj; adj = adj->next)
12359 if (adj->peer == peer)
12360 {
12361 if (header1)
12362 {
12363 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 +000012364 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12365 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012366 header1 = 0;
12367 }
12368 if (header2)
12369 {
12370 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12371 header2 = 0;
12372 }
12373 if (adj->attr)
12374 {
12375 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
12376 output_count++;
12377 }
12378 }
12379 }
12380
12381 if (output_count != 0)
12382 vty_out (vty, "%sTotal number of prefixes %ld%s",
12383 VTY_NEWLINE, output_count, VTY_NEWLINE);
12384}
12385
paul94f2b392005-06-28 12:44:16 +000012386static int
paulbb46e942003-10-24 19:02:03 +000012387peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
12388{
paul718e3742002-12-13 20:15:29 +000012389 if (! peer || ! peer->afc[afi][safi])
12390 {
12391 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12392 return CMD_WARNING;
12393 }
12394
12395 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12396 {
12397 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
12398 VTY_NEWLINE);
12399 return CMD_WARNING;
12400 }
12401
12402 show_adj_route (vty, peer, afi, safi, in);
12403
12404 return CMD_SUCCESS;
12405}
12406
Lou Bergerf9b6c392016-01-12 13:42:09 -050012407DEFUN (show_ip_bgp_view_neighbor_advertised_route,
12408 show_ip_bgp_view_neighbor_advertised_route_cmd,
12409 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12410 SHOW_STR
12411 IP_STR
12412 BGP_STR
12413 "BGP view\n"
12414 "View name\n"
12415 "Detailed information on TCP and BGP neighbor connections\n"
12416 "Neighbor to display information about\n"
12417 "Neighbor to display information about\n"
12418 "Display the routes advertised to a BGP neighbor\n")
12419{
12420 struct peer *peer;
12421
12422 if (argc == 2)
12423 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12424 else
12425 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12426
12427 if (! peer)
12428 return CMD_WARNING;
12429
12430 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
12431}
12432
12433ALIAS (show_ip_bgp_view_neighbor_advertised_route,
12434 show_ip_bgp_neighbor_advertised_route_cmd,
12435 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12436 SHOW_STR
12437 IP_STR
12438 BGP_STR
12439 "Detailed information on TCP and BGP neighbor connections\n"
12440 "Neighbor to display information about\n"
12441 "Neighbor to display information about\n"
12442 "Display the routes advertised to a BGP neighbor\n")
12443
12444DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
12445 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
12446 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12447 SHOW_STR
12448 IP_STR
12449 BGP_STR
12450 "Address family\n"
12451 "Address Family modifier\n"
12452 "Address Family modifier\n"
12453 "Detailed information on TCP and BGP neighbor connections\n"
12454 "Neighbor to display information about\n"
12455 "Neighbor to display information about\n"
12456 "Display the routes advertised to a BGP neighbor\n")
12457{
12458 struct peer *peer;
12459
12460 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12461 if (! peer)
12462 return CMD_WARNING;
12463
12464 if (strncmp (argv[0], "m", 1) == 0)
12465 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
12466
12467 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
12468}
12469
Lou Bergerf9b6c392016-01-12 13:42:09 -050012470DEFUN (show_bgp_view_neighbor_advertised_route,
12471 show_bgp_view_neighbor_advertised_route_cmd,
12472 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12473 SHOW_STR
12474 BGP_STR
12475 "BGP view\n"
12476 "View name\n"
12477 "Detailed information on TCP and BGP neighbor connections\n"
12478 "Neighbor to display information about\n"
12479 "Neighbor to display information about\n"
12480 "Display the routes advertised to a BGP neighbor\n")
12481{
12482 struct peer *peer;
12483
12484 if (argc == 2)
12485 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12486 else
12487 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12488
12489 if (! peer)
12490 return CMD_WARNING;
12491
12492 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
12493}
12494
12495DEFUN (show_bgp_view_neighbor_received_routes,
12496 show_bgp_view_neighbor_received_routes_cmd,
12497 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
12498 SHOW_STR
12499 BGP_STR
12500 "BGP view\n"
12501 "View name\n"
12502 "Detailed information on TCP and BGP neighbor connections\n"
12503 "Neighbor to display information about\n"
12504 "Neighbor to display information about\n"
12505 "Display the received routes from neighbor\n")
12506{
12507 struct peer *peer;
12508
12509 if (argc == 2)
12510 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12511 else
12512 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12513
12514 if (! peer)
12515 return CMD_WARNING;
12516
12517 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
12518}
12519
12520ALIAS (show_bgp_view_neighbor_advertised_route,
12521 show_bgp_neighbor_advertised_route_cmd,
12522 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12523 SHOW_STR
12524 BGP_STR
12525 "Detailed information on TCP and BGP neighbor connections\n"
12526 "Neighbor to display information about\n"
12527 "Neighbor to display information about\n"
12528 "Display the routes advertised to a BGP neighbor\n")
12529
12530ALIAS (show_bgp_view_neighbor_advertised_route,
12531 show_bgp_ipv6_neighbor_advertised_route_cmd,
12532 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12533 SHOW_STR
12534 BGP_STR
12535 "Address family\n"
12536 "Detailed information on TCP and BGP neighbor connections\n"
12537 "Neighbor to display information about\n"
12538 "Neighbor to display information about\n"
12539 "Display the routes advertised to a BGP neighbor\n")
12540
12541/* old command */
12542ALIAS (show_bgp_view_neighbor_advertised_route,
12543 ipv6_bgp_neighbor_advertised_route_cmd,
12544 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12545 SHOW_STR
12546 IPV6_STR
12547 BGP_STR
12548 "Detailed information on TCP and BGP neighbor connections\n"
12549 "Neighbor to display information about\n"
12550 "Neighbor to display information about\n"
12551 "Display the routes advertised to a BGP neighbor\n")
12552
12553/* old command */
12554DEFUN (ipv6_mbgp_neighbor_advertised_route,
12555 ipv6_mbgp_neighbor_advertised_route_cmd,
12556 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12557 SHOW_STR
12558 IPV6_STR
12559 MBGP_STR
12560 "Detailed information on TCP and BGP neighbor connections\n"
12561 "Neighbor to display information about\n"
12562 "Neighbor to display information about\n"
12563 "Display the routes advertised to a BGP neighbor\n")
12564{
12565 struct peer *peer;
12566
12567 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12568 if (! peer)
12569 return CMD_WARNING;
12570
12571 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
12572}
Lou Bergerf9b6c392016-01-12 13:42:09 -050012573
12574DEFUN (show_ip_bgp_view_neighbor_received_routes,
12575 show_ip_bgp_view_neighbor_received_routes_cmd,
12576 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
12577 SHOW_STR
12578 IP_STR
12579 BGP_STR
12580 "BGP view\n"
12581 "View name\n"
12582 "Detailed information on TCP and BGP neighbor connections\n"
12583 "Neighbor to display information about\n"
12584 "Neighbor to display information about\n"
12585 "Display the received routes from neighbor\n")
12586{
12587 struct peer *peer;
12588
12589 if (argc == 2)
12590 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12591 else
12592 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12593
12594 if (! peer)
12595 return CMD_WARNING;
12596
12597 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
12598}
12599
12600ALIAS (show_ip_bgp_view_neighbor_received_routes,
12601 show_ip_bgp_neighbor_received_routes_cmd,
12602 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12603 SHOW_STR
12604 IP_STR
12605 BGP_STR
12606 "Detailed information on TCP and BGP neighbor connections\n"
12607 "Neighbor to display information about\n"
12608 "Neighbor to display information about\n"
12609 "Display the received routes from neighbor\n")
12610
12611ALIAS (show_bgp_view_neighbor_received_routes,
12612 show_bgp_ipv6_neighbor_received_routes_cmd,
12613 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
12614 SHOW_STR
12615 BGP_STR
12616 "Address family\n"
12617 "Detailed information on TCP and BGP neighbor connections\n"
12618 "Neighbor to display information about\n"
12619 "Neighbor to display information about\n"
12620 "Display the received routes from neighbor\n")
12621
12622DEFUN (show_bgp_neighbor_received_prefix_filter,
12623 show_bgp_neighbor_received_prefix_filter_cmd,
12624 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
12625 SHOW_STR
12626 BGP_STR
12627 "Detailed information on TCP and BGP neighbor connections\n"
12628 "Neighbor to display information about\n"
12629 "Neighbor to display information about\n"
12630 "Display information received from a BGP neighbor\n"
12631 "Display the prefixlist filter\n")
12632{
12633 char name[BUFSIZ];
12634 union sockunion su;
12635 struct peer *peer;
12636 int count, ret;
12637
12638 ret = str2sockunion (argv[0], &su);
12639 if (ret < 0)
12640 {
12641 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
12642 return CMD_WARNING;
12643 }
12644
12645 peer = peer_lookup (NULL, &su);
12646 if (! peer)
12647 return CMD_WARNING;
12648
12649 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12650 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12651 if (count)
12652 {
12653 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12654 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12655 }
12656
12657 return CMD_SUCCESS;
12658}
12659
12660/* old command */
12661ALIAS (show_bgp_view_neighbor_received_routes,
12662 ipv6_bgp_neighbor_received_routes_cmd,
12663 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12664 SHOW_STR
12665 IPV6_STR
12666 BGP_STR
12667 "Detailed information on TCP and BGP neighbor connections\n"
12668 "Neighbor to display information about\n"
12669 "Neighbor to display information about\n"
12670 "Display the received routes from neighbor\n")
12671
12672/* old command */
12673DEFUN (ipv6_mbgp_neighbor_received_routes,
12674 ipv6_mbgp_neighbor_received_routes_cmd,
12675 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12676 SHOW_STR
12677 IPV6_STR
12678 MBGP_STR
12679 "Detailed information on TCP and BGP neighbor connections\n"
12680 "Neighbor to display information about\n"
12681 "Neighbor to display information about\n"
12682 "Display the received routes from neighbor\n")
12683{
12684 struct peer *peer;
12685
12686 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12687 if (! peer)
12688 return CMD_WARNING;
12689
12690 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
12691}
12692
12693DEFUN (show_bgp_view_neighbor_received_prefix_filter,
12694 show_bgp_view_neighbor_received_prefix_filter_cmd,
12695 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
12696 SHOW_STR
12697 BGP_STR
12698 "BGP view\n"
12699 "View name\n"
12700 "Detailed information on TCP and BGP neighbor connections\n"
12701 "Neighbor to display information about\n"
12702 "Neighbor to display information about\n"
12703 "Display information received from a BGP neighbor\n"
12704 "Display the prefixlist filter\n")
12705{
12706 char name[BUFSIZ];
12707 union sockunion su;
12708 struct peer *peer;
12709 struct bgp *bgp;
12710 int count, ret;
12711
12712 /* BGP structure lookup. */
12713 bgp = bgp_lookup_by_name (argv[0]);
12714 if (bgp == NULL)
12715 {
12716 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12717 return CMD_WARNING;
12718 }
12719
12720 ret = str2sockunion (argv[1], &su);
12721 if (ret < 0)
12722 {
12723 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
12724 return CMD_WARNING;
12725 }
12726
12727 peer = peer_lookup (bgp, &su);
12728 if (! peer)
12729 return CMD_WARNING;
12730
12731 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12732 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12733 if (count)
12734 {
12735 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12736 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12737 }
12738
12739 return CMD_SUCCESS;
12740}
12741
12742
12743DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12744 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
12745 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
12746 SHOW_STR
12747 IP_STR
12748 BGP_STR
12749 "Address family\n"
12750 "Address Family modifier\n"
12751 "Address Family modifier\n"
12752 "Detailed information on TCP and BGP neighbor connections\n"
12753 "Neighbor to display information about\n"
12754 "Neighbor to display information about\n"
12755 "Display the received routes from neighbor\n")
12756{
12757 struct peer *peer;
12758
12759 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12760 if (! peer)
12761 return CMD_WARNING;
12762
12763 if (strncmp (argv[0], "m", 1) == 0)
12764 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
12765
12766 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
12767}
12768
Lou Berger651b4022016-01-12 13:42:07 -050012769DEFUN (show_bgp_ipv4_safi_neighbor_advertised_route,
12770 show_bgp_ipv4_safi_neighbor_advertised_route_cmd,
12771 "show bgp ipv4 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012772 SHOW_STR
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012773 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050012774 "Address Family modifier\n"
12775 "Address Family modifier\n"
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012776 "Detailed information on TCP and BGP neighbor connections\n"
12777 "Neighbor to display information about\n"
12778 "Neighbor to display information about\n"
12779 "Display the routes advertised to a BGP neighbor\n")
12780{
12781 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050012782 safi_t safi;
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012783
Lou Berger651b4022016-01-12 13:42:07 -050012784 if (bgp_parse_safi(argv[0], &safi)) {
12785 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012786 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050012787 }
paul718e3742002-12-13 20:15:29 +000012788
paulbb46e942003-10-24 19:02:03 +000012789 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12790 if (! peer)
12791 return CMD_WARNING;
12792
Lou Berger651b4022016-01-12 13:42:07 -050012793 return peer_adj_routes (vty, peer, AFI_IP, safi, 0);
12794}
Lou Berger205e6742016-01-12 13:42:11 -050012795
Lou Berger651b4022016-01-12 13:42:07 -050012796DEFUN (show_bgp_ipv6_safi_neighbor_advertised_route,
12797 show_bgp_ipv6_safi_neighbor_advertised_route_cmd,
12798 "show bgp ipv6 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12799 SHOW_STR
12800 BGP_STR
12801 "Address Family modifier\n"
12802 "Address Family modifier\n"
12803 "Address Family modifier\n"
12804 "Detailed information on TCP and BGP neighbor connections\n"
12805 "Neighbor to display information about\n"
12806 "Neighbor to display information about\n"
12807 "Display the routes advertised to a BGP neighbor\n")
12808{
12809 struct peer *peer;
12810 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000012811
Lou Berger651b4022016-01-12 13:42:07 -050012812 if (bgp_parse_safi(argv[0], &safi)) {
12813 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12814 return CMD_WARNING;
12815 }
12816
12817 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12818 if (! peer)
12819 return CMD_WARNING;
12820
12821 return peer_adj_routes (vty, peer, AFI_IP6, safi, 0);
paul718e3742002-12-13 20:15:29 +000012822}
12823
Lou Bergerf9b6c392016-01-12 13:42:09 -050012824DEFUN (show_bgp_view_ipv6_neighbor_advertised_route,
Lou Berger651b4022016-01-12 13:42:07 -050012825 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
12826 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
paulbb46e942003-10-24 19:02:03 +000012827 SHOW_STR
12828 BGP_STR
12829 "BGP view\n"
12830 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050012831 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000012832 "Detailed information on TCP and BGP neighbor connections\n"
12833 "Neighbor to display information about\n"
12834 "Neighbor to display information about\n"
12835 "Display the routes advertised to a BGP neighbor\n")
12836{
12837 struct peer *peer;
12838
12839 if (argc == 2)
12840 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12841 else
12842 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12843
12844 if (! peer)
12845 return CMD_WARNING;
12846
12847 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
12848}
12849
Lou Bergerf9b6c392016-01-12 13:42:09 -050012850DEFUN (show_bgp_view_ipv6_neighbor_received_routes,
Lou Berger651b4022016-01-12 13:42:07 -050012851 show_bgp_view_ipv6_neighbor_received_routes_cmd,
12852 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
paulbb46e942003-10-24 19:02:03 +000012853 SHOW_STR
12854 BGP_STR
12855 "BGP view\n"
12856 "View name\n"
12857 "Address family\n"
12858 "Detailed information on TCP and BGP neighbor connections\n"
12859 "Neighbor to display information about\n"
12860 "Neighbor to display information about\n"
paulbb46e942003-10-24 19:02:03 +000012861 "Display the received routes from neighbor\n")
12862{
12863 struct peer *peer;
12864
12865 if (argc == 2)
12866 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12867 else
12868 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12869
12870 if (! peer)
12871 return CMD_WARNING;
12872
12873 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
12874}
Lou Berger651b4022016-01-12 13:42:07 -050012875
12876DEFUN (show_bgp_ipv4_safi_neighbor_received_routes,
12877 show_bgp_ipv4_safi_neighbor_received_routes_cmd,
12878 "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 +010012879 SHOW_STR
paul718e3742002-12-13 20:15:29 +000012880 BGP_STR
12881 "Address family\n"
12882 "Address Family modifier\n"
12883 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050012884 "Address Family modifier\n"
12885 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000012886 "Detailed information on TCP and BGP neighbor connections\n"
12887 "Neighbor to display information about\n"
12888 "Neighbor to display information about\n"
12889 "Display the received routes from neighbor\n")
12890{
paulbb46e942003-10-24 19:02:03 +000012891 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050012892 safi_t safi;
12893
12894 if (bgp_parse_safi(argv[0], &safi)) {
12895 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12896 return CMD_WARNING;
12897 }
paul718e3742002-12-13 20:15:29 +000012898
paulbb46e942003-10-24 19:02:03 +000012899 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12900 if (! peer)
12901 return CMD_WARNING;
12902
Lou Berger651b4022016-01-12 13:42:07 -050012903 return peer_adj_routes (vty, peer, AFI_IP, safi, 1);
paul718e3742002-12-13 20:15:29 +000012904}
Lou Berger205e6742016-01-12 13:42:11 -050012905
Lou Berger651b4022016-01-12 13:42:07 -050012906DEFUN (show_bgp_ipv6_safi_neighbor_received_routes,
12907 show_bgp_ipv6_safi_neighbor_received_routes_cmd,
12908 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) received-routes",
12909 SHOW_STR
12910 BGP_STR
12911 "Address family\n"
12912 "Address Family modifier\n"
12913 "Address Family modifier\n"
12914 "Address Family modifier\n"
12915 "Address Family modifier\n"
12916 "Detailed information on TCP and BGP neighbor connections\n"
12917 "Neighbor to display information about\n"
12918 "Neighbor to display information about\n"
12919 "Display the received routes from neighbor\n")
12920{
12921 struct peer *peer;
12922 safi_t safi;
12923
12924 if (bgp_parse_safi(argv[0], &safi)) {
12925 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12926 return CMD_WARNING;
12927 }
12928
12929 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12930 if (! peer)
12931 return CMD_WARNING;
12932
12933 return peer_adj_routes (vty, peer, AFI_IP6, safi, 1);
12934}
paul718e3742002-12-13 20:15:29 +000012935
Michael Lambert95cbbd22010-07-23 14:43:04 -040012936DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
12937 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040012938 "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 -040012939 SHOW_STR
12940 BGP_STR
12941 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000012942 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040012943 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040012944 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040012945 "Address family modifier\n"
12946 "Address family modifier\n"
12947 "Detailed information on TCP and BGP neighbor connections\n"
12948 "Neighbor to display information about\n"
12949 "Neighbor to display information about\n"
12950 "Display the advertised routes to neighbor\n"
12951 "Display the received routes from neighbor\n")
12952{
12953 int afi;
12954 int safi;
12955 int in;
12956 struct peer *peer;
12957
David Lamparter94bad672015-03-03 08:52:22 +010012958 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012959
12960 if (! peer)
12961 return CMD_WARNING;
12962
Michael Lambert95cbbd22010-07-23 14:43:04 -040012963 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
12964 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12965 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040012966
12967 return peer_adj_routes (vty, peer, afi, safi, in);
12968}
12969
Lou Bergerf9b6c392016-01-12 13:42:09 -050012970DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
12971 show_ip_bgp_neighbor_received_prefix_filter_cmd,
12972 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
12973 SHOW_STR
12974 IP_STR
12975 BGP_STR
12976 "Detailed information on TCP and BGP neighbor connections\n"
12977 "Neighbor to display information about\n"
12978 "Neighbor to display information about\n"
12979 "Display information received from a BGP neighbor\n"
12980 "Display the prefixlist filter\n")
12981{
12982 char name[BUFSIZ];
12983 union sockunion su;
12984 struct peer *peer;
12985 int count, ret;
12986
12987 ret = str2sockunion (argv[0], &su);
12988 if (ret < 0)
12989 {
12990 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
12991 return CMD_WARNING;
12992 }
12993
12994 peer = peer_lookup (NULL, &su);
12995 if (! peer)
12996 return CMD_WARNING;
12997
12998 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
12999 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13000 if (count)
13001 {
13002 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13003 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13004 }
13005
13006 return CMD_SUCCESS;
13007}
13008
13009DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
13010 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
13011 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
13012 SHOW_STR
13013 IP_STR
13014 BGP_STR
13015 "Address family\n"
13016 "Address Family modifier\n"
13017 "Address Family modifier\n"
13018 "Detailed information on TCP and BGP neighbor connections\n"
13019 "Neighbor to display information about\n"
13020 "Neighbor to display information about\n"
13021 "Display information received from a BGP neighbor\n"
13022 "Display the prefixlist filter\n")
13023{
13024 char name[BUFSIZ];
13025 union sockunion su;
13026 struct peer *peer;
13027 int count, ret;
13028
13029 ret = str2sockunion (argv[1], &su);
13030 if (ret < 0)
13031 {
13032 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13033 return CMD_WARNING;
13034 }
13035
13036 peer = peer_lookup (NULL, &su);
13037 if (! peer)
13038 return CMD_WARNING;
13039
13040 if (strncmp (argv[0], "m", 1) == 0)
13041 {
13042 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
13043 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13044 if (count)
13045 {
13046 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
13047 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13048 }
13049 }
13050 else
13051 {
13052 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
13053 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13054 if (count)
13055 {
13056 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13057 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13058 }
13059 }
13060
13061 return CMD_SUCCESS;
13062}
13063
13064ALIAS (show_bgp_view_neighbor_received_routes,
13065 show_bgp_neighbor_received_routes_cmd,
13066 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
13067 SHOW_STR
13068 BGP_STR
13069 "Detailed information on TCP and BGP neighbor connections\n"
13070 "Neighbor to display information about\n"
13071 "Neighbor to display information about\n"
13072 "Display the received routes from neighbor\n")
13073
Lou Berger651b4022016-01-12 13:42:07 -050013074DEFUN (show_bgp_ipv4_safi_neighbor_received_prefix_filter,
13075 show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd,
13076 "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 +000013077 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013078 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013079 IP_STR
13080 "Address Family modifier\n"
13081 "Address Family modifier\n"
13082 "Address Family modifier\n"
13083 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000013084 "Detailed information on TCP and BGP neighbor connections\n"
13085 "Neighbor to display information about\n"
13086 "Neighbor to display information about\n"
13087 "Display information received from a BGP neighbor\n"
13088 "Display the prefixlist filter\n")
13089{
13090 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013091 union sockunion su;
paul718e3742002-12-13 20:15:29 +000013092 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013093 int count, ret;
Lou Berger651b4022016-01-12 13:42:07 -050013094 safi_t safi;
paul718e3742002-12-13 20:15:29 +000013095
Lou Berger651b4022016-01-12 13:42:07 -050013096 if (bgp_parse_safi(argv[0], &safi)) {
13097 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000013098 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050013099 }
paul718e3742002-12-13 20:15:29 +000013100
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013101 ret = str2sockunion (argv[1], &su);
13102 if (ret < 0)
13103 {
13104 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13105 return CMD_WARNING;
13106 }
paul718e3742002-12-13 20:15:29 +000013107
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013108 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000013109 if (! peer)
13110 return CMD_WARNING;
13111
Lou Berger651b4022016-01-12 13:42:07 -050013112 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, safi);
13113 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13114 if (count) {
13115 vty_out (vty, "Address family: IPv4 %s%s", safi2str(safi), VTY_NEWLINE);
13116 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13117 }
paul718e3742002-12-13 20:15:29 +000013118
13119 return CMD_SUCCESS;
13120}
Lou Berger205e6742016-01-12 13:42:11 -050013121
Lou Berger651b4022016-01-12 13:42:07 -050013122DEFUN (show_bgp_ipv6_safi_neighbor_received_prefix_filter,
13123 show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd,
13124 "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 +000013125 SHOW_STR
13126 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013127 IP_STR
13128 "Address Family modifier\n"
13129 "Address Family modifier\n"
13130 "Address Family modifier\n"
13131 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000013132 "Detailed information on TCP and BGP neighbor connections\n"
13133 "Neighbor to display information about\n"
13134 "Neighbor to display information about\n"
Lou Berger651b4022016-01-12 13:42:07 -050013135 "Display information received from a BGP neighbor\n"
13136 "Display the prefixlist filter\n")
13137{
13138 char name[BUFSIZ];
13139 union sockunion su;
13140 struct peer *peer;
13141 int count, ret;
13142 safi_t safi;
13143
13144 if (bgp_parse_safi(argv[0], &safi)) {
13145 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13146 return CMD_WARNING;
13147 }
13148
13149 ret = str2sockunion (argv[1], &su);
13150 if (ret < 0)
13151 {
13152 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13153 return CMD_WARNING;
13154 }
13155
13156 peer = peer_lookup (NULL, &su);
13157 if (! peer)
13158 return CMD_WARNING;
13159
13160 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, safi);
13161 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13162 if (count) {
13163 vty_out (vty, "Address family: IPv6 %s%s", safi2str(safi), VTY_NEWLINE);
13164 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13165 }
13166
13167 return CMD_SUCCESS;
13168}
paul718e3742002-12-13 20:15:29 +000013169
Lou Bergerf9b6c392016-01-12 13:42:09 -050013170DEFUN (show_bgp_ipv6_neighbor_received_prefix_filter,
Lou Berger651b4022016-01-12 13:42:07 -050013171 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
13172 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
paul718e3742002-12-13 20:15:29 +000013173 SHOW_STR
13174 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013175 "Address family\n"
paul718e3742002-12-13 20:15:29 +000013176 "Detailed information on TCP and BGP neighbor connections\n"
13177 "Neighbor to display information about\n"
13178 "Neighbor to display information about\n"
13179 "Display information received from a BGP neighbor\n"
13180 "Display the prefixlist filter\n")
13181{
13182 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013183 union sockunion su;
paul718e3742002-12-13 20:15:29 +000013184 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013185 int count, ret;
paul718e3742002-12-13 20:15:29 +000013186
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013187 ret = str2sockunion (argv[0], &su);
13188 if (ret < 0)
13189 {
13190 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
13191 return CMD_WARNING;
13192 }
paul718e3742002-12-13 20:15:29 +000013193
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013194 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000013195 if (! peer)
13196 return CMD_WARNING;
13197
13198 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13199 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13200 if (count)
13201 {
13202 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13203 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13204 }
13205
13206 return CMD_SUCCESS;
13207}
13208
Lou Bergerf9b6c392016-01-12 13:42:09 -050013209DEFUN (show_bgp_view_ipv6_neighbor_received_prefix_filter,
Lou Berger651b4022016-01-12 13:42:07 -050013210 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
13211 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
paulbb46e942003-10-24 19:02:03 +000013212 SHOW_STR
13213 BGP_STR
13214 "BGP view\n"
13215 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050013216 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000013217 "Detailed information on TCP and BGP neighbor connections\n"
13218 "Neighbor to display information about\n"
13219 "Neighbor to display information about\n"
13220 "Display information received from a BGP neighbor\n"
13221 "Display the prefixlist filter\n")
13222{
13223 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013224 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000013225 struct peer *peer;
13226 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013227 int count, ret;
paulbb46e942003-10-24 19:02:03 +000013228
13229 /* BGP structure lookup. */
13230 bgp = bgp_lookup_by_name (argv[0]);
13231 if (bgp == NULL)
13232 {
13233 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13234 return CMD_WARNING;
13235 }
13236
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013237 ret = str2sockunion (argv[1], &su);
13238 if (ret < 0)
13239 {
13240 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13241 return CMD_WARNING;
13242 }
paulbb46e942003-10-24 19:02:03 +000013243
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013244 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000013245 if (! peer)
13246 return CMD_WARNING;
13247
13248 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13249 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13250 if (count)
13251 {
13252 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13253 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13254 }
13255
13256 return CMD_SUCCESS;
13257}
David Lamparter6b0655a2014-06-04 06:53:35 +020013258
paul94f2b392005-06-28 12:44:16 +000013259static int
paulbb46e942003-10-24 19:02:03 +000013260bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000013261 safi_t safi, enum bgp_show_type type)
13262{
paul718e3742002-12-13 20:15:29 +000013263 if (! peer || ! peer->afc[afi][safi])
13264 {
13265 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000013266 return CMD_WARNING;
13267 }
13268
ajs5a646652004-11-05 01:25:55 +000013269 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000013270}
Lou Bergerf9b6c392016-01-12 13:42:09 -050013271DEFUN (show_ip_bgp_neighbor_routes,
13272 show_ip_bgp_neighbor_routes_cmd,
13273 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
13274 SHOW_STR
13275 IP_STR
13276 BGP_STR
13277 "Detailed information on TCP and BGP neighbor connections\n"
13278 "Neighbor to display information about\n"
13279 "Neighbor to display information about\n"
13280 "Display routes learned from neighbor\n")
13281{
13282 struct peer *peer;
13283
13284 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13285 if (! peer)
13286 return CMD_WARNING;
13287
13288 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13289 bgp_show_type_neighbor);
13290}
13291
13292DEFUN (show_ip_bgp_neighbor_flap,
13293 show_ip_bgp_neighbor_flap_cmd,
13294 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
13295 SHOW_STR
13296 IP_STR
13297 BGP_STR
13298 "Detailed information on TCP and BGP neighbor connections\n"
13299 "Neighbor to display information about\n"
13300 "Neighbor to display information about\n"
13301 "Display flap statistics of the routes learned from neighbor\n")
13302{
13303 struct peer *peer;
13304
13305 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13306 if (! peer)
13307 return CMD_WARNING;
13308
13309 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13310 bgp_show_type_flap_neighbor);
13311}
13312
13313DEFUN (show_ip_bgp_neighbor_damp,
13314 show_ip_bgp_neighbor_damp_cmd,
13315 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
13316 SHOW_STR
13317 IP_STR
13318 BGP_STR
13319 "Detailed information on TCP and BGP neighbor connections\n"
13320 "Neighbor to display information about\n"
13321 "Neighbor to display information about\n"
13322 "Display the dampened routes received from neighbor\n")
13323{
13324 struct peer *peer;
13325
13326 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13327 if (! peer)
13328 return CMD_WARNING;
13329
13330 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13331 bgp_show_type_damp_neighbor);
13332}
13333
13334DEFUN (show_ip_bgp_ipv4_neighbor_routes,
13335 show_ip_bgp_ipv4_neighbor_routes_cmd,
13336 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
13337 SHOW_STR
13338 IP_STR
13339 BGP_STR
13340 "Address family\n"
13341 "Address Family modifier\n"
13342 "Address Family modifier\n"
13343 "Detailed information on TCP and BGP neighbor connections\n"
13344 "Neighbor to display information about\n"
13345 "Neighbor to display information about\n"
13346 "Display routes learned from neighbor\n")
13347{
13348 struct peer *peer;
13349
13350 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13351 if (! peer)
13352 return CMD_WARNING;
13353
13354 if (strncmp (argv[0], "m", 1) == 0)
13355 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
13356 bgp_show_type_neighbor);
13357
13358 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13359 bgp_show_type_neighbor);
13360}
13361
13362DEFUN (show_ip_bgp_view_rsclient,
13363 show_ip_bgp_view_rsclient_cmd,
13364 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
13365 SHOW_STR
13366 IP_STR
13367 BGP_STR
13368 "BGP view\n"
13369 "View name\n"
13370 "Information about Route Server Client\n"
13371 NEIGHBOR_ADDR_STR)
13372{
13373 struct bgp_table *table;
13374 struct peer *peer;
13375
13376 if (argc == 2)
13377 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13378 else
13379 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13380
13381 if (! peer)
13382 return CMD_WARNING;
13383
13384 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13385 {
13386 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13387 VTY_NEWLINE);
13388 return CMD_WARNING;
13389 }
13390
13391 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13392 PEER_FLAG_RSERVER_CLIENT))
13393 {
13394 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13395 VTY_NEWLINE);
13396 return CMD_WARNING;
13397 }
13398
13399 table = peer->rib[AFI_IP][SAFI_UNICAST];
13400
13401 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
13402}
13403
13404ALIAS (show_ip_bgp_view_rsclient,
13405 show_ip_bgp_rsclient_cmd,
13406 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
13407 SHOW_STR
13408 IP_STR
13409 BGP_STR
13410 "Information about Route Server Client\n"
13411 NEIGHBOR_ADDR_STR)
13412
13413DEFUN (show_bgp_view_ipv4_safi_rsclient,
13414 show_bgp_view_ipv4_safi_rsclient_cmd,
13415 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
13416 SHOW_STR
13417 BGP_STR
13418 "BGP view\n"
13419 "View name\n"
13420 "Address family\n"
13421 "Address Family modifier\n"
13422 "Address Family modifier\n"
13423 "Information about Route Server Client\n"
13424 NEIGHBOR_ADDR_STR)
13425{
13426 struct bgp_table *table;
13427 struct peer *peer;
13428 safi_t safi;
13429
13430 if (argc == 3) {
13431 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13432 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13433 } else {
13434 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13435 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13436 }
13437
13438 if (! peer)
13439 return CMD_WARNING;
13440
13441 if (! peer->afc[AFI_IP][safi])
13442 {
13443 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13444 VTY_NEWLINE);
13445 return CMD_WARNING;
13446 }
13447
13448 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13449 PEER_FLAG_RSERVER_CLIENT))
13450 {
13451 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13452 VTY_NEWLINE);
13453 return CMD_WARNING;
13454 }
13455
13456 table = peer->rib[AFI_IP][safi];
13457
13458 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
13459}
13460
13461ALIAS (show_bgp_view_ipv4_safi_rsclient,
13462 show_bgp_ipv4_safi_rsclient_cmd,
13463 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
13464 SHOW_STR
13465 BGP_STR
13466 "Address family\n"
13467 "Address Family modifier\n"
13468 "Address Family modifier\n"
13469 "Information about Route Server Client\n"
13470 NEIGHBOR_ADDR_STR)
13471
13472DEFUN (show_ip_bgp_view_rsclient_route,
13473 show_ip_bgp_view_rsclient_route_cmd,
13474 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13475 SHOW_STR
13476 IP_STR
13477 BGP_STR
13478 "BGP view\n"
13479 "View name\n"
13480 "Information about Route Server Client\n"
13481 NEIGHBOR_ADDR_STR
13482 "Network in the BGP routing table to display\n")
13483{
13484 struct bgp *bgp;
13485 struct peer *peer;
13486
13487 /* BGP structure lookup. */
13488 if (argc == 3)
13489 {
13490 bgp = bgp_lookup_by_name (argv[0]);
13491 if (bgp == NULL)
13492 {
13493 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13494 return CMD_WARNING;
13495 }
13496 }
13497 else
13498 {
13499 bgp = bgp_get_default ();
13500 if (bgp == NULL)
13501 {
13502 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13503 return CMD_WARNING;
13504 }
13505 }
13506
13507 if (argc == 3)
13508 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13509 else
13510 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13511
13512 if (! peer)
13513 return CMD_WARNING;
13514
13515 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13516 {
13517 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13518 VTY_NEWLINE);
13519 return CMD_WARNING;
13520}
13521
13522 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13523 PEER_FLAG_RSERVER_CLIENT))
13524 {
13525 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13526 VTY_NEWLINE);
13527 return CMD_WARNING;
13528 }
13529
13530 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
13531 (argc == 3) ? argv[2] : argv[1],
13532 AFI_IP, SAFI_UNICAST, NULL, 0);
13533}
13534
13535ALIAS (show_ip_bgp_view_rsclient_route,
13536 show_ip_bgp_rsclient_route_cmd,
13537 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13538 SHOW_STR
13539 IP_STR
13540 BGP_STR
13541 "Information about Route Server Client\n"
13542 NEIGHBOR_ADDR_STR
13543 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +000013544
Lou Berger651b4022016-01-12 13:42:07 -050013545DEFUN (show_bgp_ipv4_safi_neighbor_flap,
13546 show_bgp_ipv4_safi_neighbor_flap_cmd,
13547 "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paul718e3742002-12-13 20:15:29 +000013548 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013549 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013550 "Address Family Modifier\n"
13551 "Address Family Modifier\n"
13552 "Address Family Modifier\n"
13553 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +000013554 "Detailed information on TCP and BGP neighbor connections\n"
13555 "Neighbor to display information about\n"
13556 "Neighbor to display information about\n"
13557 "Display flap statistics of the routes learned from neighbor\n")
13558{
paulbb46e942003-10-24 19:02:03 +000013559 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013560 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000013561
Lou Berger651b4022016-01-12 13:42:07 -050013562 if (bgp_parse_safi(argv[0], &safi)) {
13563 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13564 return CMD_WARNING;
13565 }
13566
13567 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulbb46e942003-10-24 19:02:03 +000013568 if (! peer)
13569 return CMD_WARNING;
13570
Lou Berger651b4022016-01-12 13:42:07 -050013571 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013572 bgp_show_type_flap_neighbor);
13573}
Lou Berger205e6742016-01-12 13:42:11 -050013574
Lou Berger651b4022016-01-12 13:42:07 -050013575DEFUN (show_bgp_ipv6_safi_neighbor_flap,
13576 show_bgp_ipv6_safi_neighbor_flap_cmd,
13577 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paul718e3742002-12-13 20:15:29 +000013578 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013579 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013580 "Address Family Modifier\n"
13581 "Address Family Modifier\n"
13582 "Address Family Modifier\n"
13583 "Address Family Modifier\n"
13584 "Detailed information on TCP and BGP neighbor connections\n"
13585 "Neighbor to display information about\n"
13586 "Neighbor to display information about\n"
13587 "Display flap statistics of the routes learned from neighbor\n")
13588{
13589 struct peer *peer;
13590 safi_t safi;
13591
13592 if (bgp_parse_safi(argv[0], &safi)) {
13593 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13594 return CMD_WARNING;
13595 }
13596
13597 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13598 if (! peer)
13599 return CMD_WARNING;
13600
13601 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13602 bgp_show_type_flap_neighbor);
13603}
Lou Berger651b4022016-01-12 13:42:07 -050013604
13605DEFUN (show_bgp_ipv4_safi_neighbor_damp,
13606 show_bgp_ipv4_safi_neighbor_damp_cmd,
13607 "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) dampened-routes",
13608 SHOW_STR
13609 BGP_STR
13610 "Address Family Modifier\n"
13611 "Address Family Modifier\n"
13612 "Address Family Modifier\n"
13613 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +000013614 "Detailed information on TCP and BGP neighbor connections\n"
13615 "Neighbor to display information about\n"
13616 "Neighbor to display information about\n"
13617 "Display the dampened routes received from neighbor\n")
13618{
paulbb46e942003-10-24 19:02:03 +000013619 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013620 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000013621
Lou Berger651b4022016-01-12 13:42:07 -050013622 if (bgp_parse_safi(argv[0], &safi)) {
13623 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13624 return CMD_WARNING;
13625 }
13626
13627 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulbb46e942003-10-24 19:02:03 +000013628 if (! peer)
13629 return CMD_WARNING;
13630
Lou Berger651b4022016-01-12 13:42:07 -050013631 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013632 bgp_show_type_damp_neighbor);
13633}
Lou Berger205e6742016-01-12 13:42:11 -050013634
Lou Berger651b4022016-01-12 13:42:07 -050013635DEFUN (show_bgp_ipv6_safi_neighbor_damp,
13636 show_bgp_ipv6_safi_neighbor_damp_cmd,
13637 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) dampened-routes",
paul718e3742002-12-13 20:15:29 +000013638 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -050013639 BGP_STR
13640 "Address Family Modifier\n"
13641 "Address Family Modifier\n"
13642 "Address Family Modifier\n"
13643 "Address Family Modifier\n"
13644 "Detailed information on TCP and BGP neighbor connections\n"
13645 "Neighbor to display information about\n"
13646 "Neighbor to display information about\n"
13647 "Display the dampened routes received from neighbor\n")
13648{
13649 struct peer *peer;
13650 safi_t safi;
13651
13652 if (bgp_parse_safi(argv[0], &safi)) {
13653 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13654 return CMD_WARNING;
13655 }
13656
13657 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13658 if (! peer)
13659 return CMD_WARNING;
13660
13661 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13662 bgp_show_type_damp_neighbor);
13663}
Lou Berger651b4022016-01-12 13:42:07 -050013664
13665DEFUN (show_bgp_ipv4_safi_neighbor_routes,
13666 show_bgp_ipv4_safi_neighbor_routes_cmd,
13667 "show bgp ipv4 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) routes",
13668 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013669 BGP_STR
13670 "Address family\n"
13671 "Address Family modifier\n"
13672 "Address Family modifier\n"
13673 "Detailed information on TCP and BGP neighbor connections\n"
13674 "Neighbor to display information about\n"
13675 "Neighbor to display information about\n"
13676 "Display routes learned from neighbor\n")
13677{
paulbb46e942003-10-24 19:02:03 +000013678 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013679 safi_t safi;
13680
13681 if (bgp_parse_safi(argv[0], &safi)) {
13682 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13683 return CMD_WARNING;
13684 }
paulbb46e942003-10-24 19:02:03 +000013685
13686 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13687 if (! peer)
13688 return CMD_WARNING;
13689
Lou Berger651b4022016-01-12 13:42:07 -050013690 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013691 bgp_show_type_neighbor);
13692}
Lou Berger205e6742016-01-12 13:42:11 -050013693
Lou Berger651b4022016-01-12 13:42:07 -050013694DEFUN (show_bgp_ipv6_safi_neighbor_routes,
13695 show_bgp_ipv6_safi_neighbor_routes_cmd,
13696 "show bgp ipv6 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) routes",
paulfee0f4c2004-09-13 05:12:46 +000013697 SHOW_STR
paulfee0f4c2004-09-13 05:12:46 +000013698 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013699 "Address family\n"
13700 "Address Family modifier\n"
13701 "Address Family modifier\n"
13702 "Detailed information on TCP and BGP neighbor connections\n"
13703 NEIGHBOR_ADDR_STR
13704 NEIGHBOR_ADDR_STR
13705 "Display routes learned from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000013706{
paulfee0f4c2004-09-13 05:12:46 +000013707 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013708 safi_t safi;
paulfee0f4c2004-09-13 05:12:46 +000013709
Lou Berger651b4022016-01-12 13:42:07 -050013710 if (bgp_parse_safi(argv[0], &safi)) {
13711 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13712 return CMD_WARNING;
13713 }
paulfee0f4c2004-09-13 05:12:46 +000013714
Lou Berger651b4022016-01-12 13:42:07 -050013715 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulfee0f4c2004-09-13 05:12:46 +000013716 if (! peer)
13717 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050013718
13719 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13720 bgp_show_type_neighbor);
paulfee0f4c2004-09-13 05:12:46 +000013721}
paulfee0f4c2004-09-13 05:12:46 +000013722
Michael Lambert95cbbd22010-07-23 14:43:04 -040013723DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
13724 show_bgp_view_ipv4_safi_rsclient_route_cmd,
13725 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13726 SHOW_STR
13727 BGP_STR
13728 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000013729 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013730 "Address family\n"
13731 "Address Family modifier\n"
13732 "Address Family modifier\n"
13733 "Information about Route Server Client\n"
13734 NEIGHBOR_ADDR_STR
13735 "Network in the BGP routing table to display\n")
13736{
13737 struct bgp *bgp;
13738 struct peer *peer;
13739 safi_t safi;
13740
13741 /* BGP structure lookup. */
13742 if (argc == 4)
13743 {
13744 bgp = bgp_lookup_by_name (argv[0]);
13745 if (bgp == NULL)
13746 {
13747 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13748 return CMD_WARNING;
13749 }
13750 }
13751 else
13752 {
13753 bgp = bgp_get_default ();
13754 if (bgp == NULL)
13755 {
13756 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13757 return CMD_WARNING;
13758 }
13759 }
13760
13761 if (argc == 4) {
13762 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13763 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13764 } else {
13765 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13766 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13767 }
13768
13769 if (! peer)
13770 return CMD_WARNING;
13771
13772 if (! peer->afc[AFI_IP][safi])
13773 {
13774 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13775 VTY_NEWLINE);
13776 return CMD_WARNING;
13777}
13778
13779 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13780 PEER_FLAG_RSERVER_CLIENT))
13781 {
13782 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13783 VTY_NEWLINE);
13784 return CMD_WARNING;
13785 }
13786
13787 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
13788 (argc == 4) ? argv[3] : argv[2],
13789 AFI_IP, safi, NULL, 0);
13790}
13791
13792ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
13793 show_bgp_ipv4_safi_rsclient_route_cmd,
13794 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13795 SHOW_STR
13796 BGP_STR
13797 "Address family\n"
13798 "Address Family modifier\n"
13799 "Address Family modifier\n"
13800 "Information about Route Server Client\n"
13801 NEIGHBOR_ADDR_STR
13802 "Network in the BGP routing table to display\n")
13803
paulfee0f4c2004-09-13 05:12:46 +000013804
Michael Lambert95cbbd22010-07-23 14:43:04 -040013805DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
13806 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
13807 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
13808 SHOW_STR
13809 BGP_STR
13810 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000013811 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013812 "Address family\n"
13813 "Address Family modifier\n"
13814 "Address Family modifier\n"
13815 "Information about Route Server Client\n"
13816 NEIGHBOR_ADDR_STR
13817 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13818{
13819 struct bgp *bgp;
13820 struct peer *peer;
13821 safi_t safi;
13822
13823 /* BGP structure lookup. */
13824 if (argc == 4)
13825 {
13826 bgp = bgp_lookup_by_name (argv[0]);
13827 if (bgp == NULL)
13828 {
13829 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13830 return CMD_WARNING;
13831 }
13832 }
13833 else
13834 {
13835 bgp = bgp_get_default ();
13836 if (bgp == NULL)
13837 {
13838 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13839 return CMD_WARNING;
13840 }
13841 }
13842
13843 if (argc == 4) {
13844 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13845 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13846 } else {
13847 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13848 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13849 }
13850
13851 if (! peer)
13852 return CMD_WARNING;
13853
13854 if (! peer->afc[AFI_IP][safi])
13855 {
13856 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13857 VTY_NEWLINE);
13858 return CMD_WARNING;
13859}
13860
13861 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13862 PEER_FLAG_RSERVER_CLIENT))
13863{
13864 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13865 VTY_NEWLINE);
13866 return CMD_WARNING;
13867 }
13868
13869 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
13870 (argc == 4) ? argv[3] : argv[2],
13871 AFI_IP, safi, NULL, 1);
13872}
13873
Lou Bergerf9b6c392016-01-12 13:42:09 -050013874DEFUN (show_ip_bgp_view_rsclient_prefix,
13875 show_ip_bgp_view_rsclient_prefix_cmd,
13876 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
13877 SHOW_STR
13878 IP_STR
13879 BGP_STR
13880 "BGP view\n"
13881 "View name\n"
13882 "Information about Route Server Client\n"
13883 NEIGHBOR_ADDR_STR
13884 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13885{
13886 struct bgp *bgp;
13887 struct peer *peer;
13888
13889 /* BGP structure lookup. */
13890 if (argc == 3)
13891 {
13892 bgp = bgp_lookup_by_name (argv[0]);
13893 if (bgp == NULL)
13894 {
13895 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13896 return CMD_WARNING;
13897 }
13898 }
13899 else
13900 {
13901 bgp = bgp_get_default ();
13902 if (bgp == NULL)
13903 {
13904 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13905 return CMD_WARNING;
13906 }
13907 }
13908
13909 if (argc == 3)
13910 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13911 else
13912 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13913
13914 if (! peer)
13915 return CMD_WARNING;
13916
13917 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13918 {
13919 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13920 VTY_NEWLINE);
13921 return CMD_WARNING;
13922}
13923
13924 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13925 PEER_FLAG_RSERVER_CLIENT))
13926{
13927 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13928 VTY_NEWLINE);
13929 return CMD_WARNING;
13930 }
13931
13932 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
13933 (argc == 3) ? argv[2] : argv[1],
13934 AFI_IP, SAFI_UNICAST, NULL, 1);
13935}
13936
13937ALIAS (show_ip_bgp_view_rsclient_prefix,
13938 show_ip_bgp_rsclient_prefix_cmd,
13939 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
13940 SHOW_STR
13941 IP_STR
13942 BGP_STR
13943 "Information about Route Server Client\n"
13944 NEIGHBOR_ADDR_STR
13945 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13946
Michael Lambert95cbbd22010-07-23 14:43:04 -040013947ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
13948 show_bgp_ipv4_safi_rsclient_prefix_cmd,
13949 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
13950 SHOW_STR
13951 BGP_STR
13952 "Address family\n"
13953 "Address Family modifier\n"
13954 "Address Family modifier\n"
13955 "Information about Route Server Client\n"
13956 NEIGHBOR_ADDR_STR
13957 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000013958
Lou Bergerf9b6c392016-01-12 13:42:09 -050013959DEFUN (show_bgp_view_ipv6_neighbor_routes,
Lou Berger651b4022016-01-12 13:42:07 -050013960 show_bgp_view_ipv6_neighbor_routes_cmd,
13961 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
paulbb46e942003-10-24 19:02:03 +000013962 SHOW_STR
13963 BGP_STR
13964 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000013965 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050013966 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000013967 "Detailed information on TCP and BGP neighbor connections\n"
13968 "Neighbor to display information about\n"
13969 "Neighbor to display information about\n"
13970 "Display routes learned from neighbor\n")
13971{
13972 struct peer *peer;
13973
13974 if (argc == 2)
13975 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13976 else
13977 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13978
13979 if (! peer)
13980 return CMD_WARNING;
13981
13982 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
13983 bgp_show_type_neighbor);
13984}
13985
Lou Berger651b4022016-01-12 13:42:07 -050013986DEFUN (show_bgp_view_neighbor_damp,
Lou Bergerf9b6c392016-01-12 13:42:09 -050013987 show_bgp_view_neighbor_damp_cmd,
13988 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
13989 SHOW_STR
13990 BGP_STR
13991 "BGP view\n"
13992 "View name\n"
13993 "Detailed information on TCP and BGP neighbor connections\n"
13994 "Neighbor to display information about\n"
13995 "Neighbor to display information about\n"
13996 "Display the dampened routes received from neighbor\n")
13997{
13998 struct peer *peer;
13999
14000 if (argc == 2)
14001 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14002 else
14003 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14004
14005 if (! peer)
14006 return CMD_WARNING;
14007
14008 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14009 bgp_show_type_damp_neighbor);
14010}
14011
14012DEFUN (show_bgp_view_ipv6_neighbor_damp,
Lou Berger651b4022016-01-12 13:42:07 -050014013 show_bgp_view_ipv6_neighbor_damp_cmd,
14014 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
paulbb46e942003-10-24 19:02:03 +000014015 SHOW_STR
14016 BGP_STR
14017 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014018 "View name\n"
paulbb46e942003-10-24 19:02:03 +000014019 "Address family\n"
14020 "Detailed information on TCP and BGP neighbor connections\n"
14021 "Neighbor to display information about\n"
14022 "Neighbor to display information about\n"
paulbb46e942003-10-24 19:02:03 +000014023 "Display the dampened routes received from neighbor\n")
14024{
14025 struct peer *peer;
14026
14027 if (argc == 2)
14028 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14029 else
14030 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14031
14032 if (! peer)
14033 return CMD_WARNING;
14034
14035 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14036 bgp_show_type_damp_neighbor);
14037}
14038
Lou Bergerf9b6c392016-01-12 13:42:09 -050014039DEFUN (show_bgp_view_ipv6_neighbor_flap,
Lou Berger651b4022016-01-12 13:42:07 -050014040 show_bgp_view_ipv6_neighbor_flap_cmd,
14041 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paulbb46e942003-10-24 19:02:03 +000014042 SHOW_STR
14043 BGP_STR
14044 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014045 "View name\n"
paulbb46e942003-10-24 19:02:03 +000014046 "Address family\n"
14047 "Detailed information on TCP and BGP neighbor connections\n"
14048 "Neighbor to display information about\n"
14049 "Neighbor to display information about\n"
14050 "Display the dampened routes received from neighbor\n")
paulbb46e942003-10-24 19:02:03 +000014051{
14052 struct peer *peer;
14053
14054 if (argc == 2)
14055 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14056 else
14057 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14058
14059 if (! peer)
14060 return CMD_WARNING;
14061
14062 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14063 bgp_show_type_flap_neighbor);
14064}
14065
Lou Bergerf9b6c392016-01-12 13:42:09 -050014066DEFUN (show_bgp_view_neighbor_flap,
14067 show_bgp_view_neighbor_flap_cmd,
14068 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14069 SHOW_STR
14070 BGP_STR
14071 "BGP view\n"
14072 "View name\n"
14073 "Detailed information on TCP and BGP neighbor connections\n"
14074 "Neighbor to display information about\n"
14075 "Neighbor to display information about\n"
14076 "Display flap statistics of the routes learned from neighbor\n")
14077{
14078 struct peer *peer;
14079
14080 if (argc == 2)
14081 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14082 else
14083 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14084
14085 if (! peer)
14086 return CMD_WARNING;
14087
14088 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14089 bgp_show_type_flap_neighbor);
14090}
14091
14092ALIAS (show_bgp_view_neighbor_flap,
14093 show_bgp_neighbor_flap_cmd,
14094 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14095 SHOW_STR
14096 BGP_STR
14097 "Detailed information on TCP and BGP neighbor connections\n"
14098 "Neighbor to display information about\n"
14099 "Neighbor to display information about\n"
14100 "Display flap statistics of the routes learned from neighbor\n")
14101
14102ALIAS (show_bgp_view_neighbor_damp,
14103 show_bgp_neighbor_damp_cmd,
14104 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14105 SHOW_STR
14106 BGP_STR
14107 "Detailed information on TCP and BGP neighbor connections\n"
14108 "Neighbor to display information about\n"
14109 "Neighbor to display information about\n"
14110 "Display the dampened routes received from neighbor\n")
14111
14112DEFUN (show_bgp_view_neighbor_routes,
14113 show_bgp_view_neighbor_routes_cmd,
14114 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
14115 SHOW_STR
14116 BGP_STR
14117 "BGP view\n"
14118 "View name\n"
14119 "Detailed information on TCP and BGP neighbor connections\n"
14120 "Neighbor to display information about\n"
14121 "Neighbor to display information about\n"
14122 "Display routes learned from neighbor\n")
14123{
14124 struct peer *peer;
14125
14126 if (argc == 2)
14127 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14128 else
14129 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14130
14131 if (! peer)
14132 return CMD_WARNING;
14133
14134 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14135 bgp_show_type_neighbor);
14136}
14137
14138ALIAS (show_bgp_view_neighbor_routes,
14139 show_bgp_neighbor_routes_cmd,
14140 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
14141 SHOW_STR
14142 BGP_STR
14143 "Detailed information on TCP and BGP neighbor connections\n"
14144 "Neighbor to display information about\n"
14145 "Neighbor to display information about\n"
14146 "Display routes learned from neighbor\n")
14147
paulbb46e942003-10-24 19:02:03 +000014148ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000014149 show_bgp_ipv6_neighbor_routes_cmd,
14150 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
14151 SHOW_STR
14152 BGP_STR
14153 "Address family\n"
14154 "Detailed information on TCP and BGP neighbor connections\n"
14155 "Neighbor to display information about\n"
14156 "Neighbor to display information about\n"
14157 "Display routes learned from neighbor\n")
14158
Lou Bergerf9b6c392016-01-12 13:42:09 -050014159/* old command */
14160ALIAS (show_bgp_view_neighbor_routes,
14161 ipv6_bgp_neighbor_routes_cmd,
14162 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
14163 SHOW_STR
14164 IPV6_STR
14165 BGP_STR
14166 "Detailed information on TCP and BGP neighbor connections\n"
14167 "Neighbor to display information about\n"
14168 "Neighbor to display information about\n"
14169 "Display routes learned from neighbor\n")
14170
14171/* old command */
14172DEFUN (ipv6_mbgp_neighbor_routes,
14173 ipv6_mbgp_neighbor_routes_cmd,
14174 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
14175 SHOW_STR
14176 IPV6_STR
14177 MBGP_STR
14178 "Detailed information on TCP and BGP neighbor connections\n"
14179 "Neighbor to display information about\n"
14180 "Neighbor to display information about\n"
14181 "Display routes learned from neighbor\n")
14182{
14183 struct peer *peer;
14184
14185 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14186 if (! peer)
14187 return CMD_WARNING;
14188
14189 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
14190 bgp_show_type_neighbor);
14191}
14192
paulbb46e942003-10-24 19:02:03 +000014193ALIAS (show_bgp_view_neighbor_flap,
14194 show_bgp_ipv6_neighbor_flap_cmd,
14195 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14196 SHOW_STR
14197 BGP_STR
14198 "Address family\n"
14199 "Detailed information on TCP and BGP neighbor connections\n"
14200 "Neighbor to display information about\n"
14201 "Neighbor to display information about\n"
14202 "Display flap statistics of the routes learned from neighbor\n")
14203
14204ALIAS (show_bgp_view_neighbor_damp,
paulbb46e942003-10-24 19:02:03 +000014205 show_bgp_ipv6_neighbor_damp_cmd,
14206 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14207 SHOW_STR
14208 BGP_STR
14209 "Address family\n"
14210 "Detailed information on TCP and BGP neighbor connections\n"
14211 "Neighbor to display information about\n"
14212 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000014213 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000014214
Lou Bergerf9b6c392016-01-12 13:42:09 -050014215DEFUN (show_bgp_view_rsclient,
14216 show_bgp_view_rsclient_cmd,
14217 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
14218 SHOW_STR
14219 BGP_STR
14220 "BGP view\n"
14221 "View name\n"
14222 "Information about Route Server Client\n"
14223 NEIGHBOR_ADDR_STR)
14224{
14225 struct bgp_table *table;
14226 struct peer *peer;
14227
14228 if (argc == 2)
14229 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14230 else
14231 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14232
14233 if (! peer)
14234 return CMD_WARNING;
14235
14236 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14237 {
14238 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14239 VTY_NEWLINE);
14240 return CMD_WARNING;
14241 }
14242
14243 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14244 PEER_FLAG_RSERVER_CLIENT))
14245 {
14246 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14247 VTY_NEWLINE);
14248 return CMD_WARNING;
14249 }
14250
14251 table = peer->rib[AFI_IP6][SAFI_UNICAST];
14252
14253 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14254}
14255
14256ALIAS (show_bgp_view_rsclient,
14257 show_bgp_rsclient_cmd,
14258 "show bgp rsclient (A.B.C.D|X:X::X:X)",
14259 SHOW_STR
14260 BGP_STR
14261 "Information about Route Server Client\n"
14262 NEIGHBOR_ADDR_STR)
14263
Lou Berger651b4022016-01-12 13:42:07 -050014264DEFUN (show_bgp_view_ipv4_rsclient,
14265 show_bgp_view_ipv4_rsclient_cmd,
14266 "show bgp view WORD ipv4 rsclient (A.B.C.D|X:X::X:X)",
paulfee0f4c2004-09-13 05:12:46 +000014267 SHOW_STR
14268 BGP_STR
14269 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014270 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050014271 "Address Family\n"
paulfee0f4c2004-09-13 05:12:46 +000014272 "Information about Route Server Client\n"
Lou Berger651b4022016-01-12 13:42:07 -050014273 NEIGHBOR_ADDR_STR2)
paulfee0f4c2004-09-13 05:12:46 +000014274{
Lou Berger651b4022016-01-12 13:42:07 -050014275 struct bgp_table *table;
14276 struct peer *peer;
14277
14278 if (argc == 2)
14279 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14280 else
14281 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14282
14283 if (! peer)
14284 return CMD_WARNING;
14285
14286 if (! peer->afc[AFI_IP][SAFI_UNICAST])
14287 {
14288 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14289 VTY_NEWLINE);
14290 return CMD_WARNING;
14291 }
14292
14293 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
14294 PEER_FLAG_RSERVER_CLIENT))
14295 {
14296 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14297 VTY_NEWLINE);
14298 return CMD_WARNING;
14299 }
14300
14301 table = peer->rib[AFI_IP][SAFI_UNICAST];
14302
14303 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14304}
14305DEFUN (show_bgp_view_ipv6_rsclient,
14306 show_bgp_view_ipv6_rsclient_cmd,
14307 "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X)",
14308 SHOW_STR
14309 BGP_STR
14310 "BGP view\n"
14311 "BGP view name\n"
14312 "Address Family\n"
14313 "Information about Route Server Client\n"
14314 NEIGHBOR_ADDR_STR2)
14315{
14316 struct bgp_table *table;
14317 struct peer *peer;
paulfee0f4c2004-09-13 05:12:46 +000014318
14319 if (argc == 2)
14320 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14321 else
14322 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14323
14324 if (! peer)
14325 return CMD_WARNING;
14326
14327 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14328 {
14329 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14330 VTY_NEWLINE);
14331 return CMD_WARNING;
14332 }
14333
14334 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14335 PEER_FLAG_RSERVER_CLIENT))
14336 {
14337 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14338 VTY_NEWLINE);
14339 return CMD_WARNING;
14340 }
14341
14342 table = peer->rib[AFI_IP6][SAFI_UNICAST];
14343
ajs5a646652004-11-05 01:25:55 +000014344 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000014345}
14346
Lou Berger651b4022016-01-12 13:42:07 -050014347ALIAS (show_bgp_view_ipv4_rsclient,
14348 show_bgp_ipv4_rsclient_cmd,
14349 "show bgp ipv4 rsclient (A.B.C.D|X:X::X:X)",
paulfee0f4c2004-09-13 05:12:46 +000014350 SHOW_STR
14351 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050014352 "Address Family\n"
paulfee0f4c2004-09-13 05:12:46 +000014353 "Information about Route Server Client\n"
Lou Berger651b4022016-01-12 13:42:07 -050014354 NEIGHBOR_ADDR_STR2)
14355
Lou Berger651b4022016-01-12 13:42:07 -050014356ALIAS (show_bgp_view_ipv6_rsclient,
14357 show_bgp_ipv6_rsclient_cmd,
14358 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X)",
14359 SHOW_STR
14360 BGP_STR
14361 "Address Family\n"
14362 "Information about Route Server Client\n"
14363 NEIGHBOR_ADDR_STR2)
paulfee0f4c2004-09-13 05:12:46 +000014364
Michael Lambert95cbbd22010-07-23 14:43:04 -040014365DEFUN (show_bgp_view_ipv6_safi_rsclient,
14366 show_bgp_view_ipv6_safi_rsclient_cmd,
14367 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
14368 SHOW_STR
14369 BGP_STR
14370 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014371 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014372 "Address family\n"
14373 "Address Family modifier\n"
14374 "Address Family modifier\n"
14375 "Information about Route Server Client\n"
14376 NEIGHBOR_ADDR_STR)
14377{
14378 struct bgp_table *table;
14379 struct peer *peer;
14380 safi_t safi;
14381
14382 if (argc == 3) {
14383 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14384 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14385 } else {
14386 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14387 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14388 }
14389
14390 if (! peer)
14391 return CMD_WARNING;
14392
14393 if (! peer->afc[AFI_IP6][safi])
14394 {
14395 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14396 VTY_NEWLINE);
14397 return CMD_WARNING;
14398 }
14399
14400 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14401 PEER_FLAG_RSERVER_CLIENT))
14402 {
14403 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14404 VTY_NEWLINE);
14405 return CMD_WARNING;
14406 }
14407
14408 table = peer->rib[AFI_IP6][safi];
14409
14410 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14411}
14412
14413ALIAS (show_bgp_view_ipv6_safi_rsclient,
14414 show_bgp_ipv6_safi_rsclient_cmd,
14415 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
14416 SHOW_STR
14417 BGP_STR
14418 "Address family\n"
14419 "Address Family modifier\n"
14420 "Address Family modifier\n"
14421 "Information about Route Server Client\n"
14422 NEIGHBOR_ADDR_STR)
14423
paulfee0f4c2004-09-13 05:12:46 +000014424DEFUN (show_bgp_view_rsclient_route,
14425 show_bgp_view_rsclient_route_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014426 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14427 SHOW_STR
14428 BGP_STR
14429 "BGP view\n"
14430 "View name\n"
14431 "Information about Route Server Client\n"
14432 NEIGHBOR_ADDR_STR
14433 "Network in the BGP routing table to display\n")
14434{
14435 struct bgp *bgp;
14436 struct peer *peer;
14437
14438 /* BGP structure lookup. */
14439 if (argc == 3)
14440 {
14441 bgp = bgp_lookup_by_name (argv[0]);
14442 if (bgp == NULL)
14443 {
14444 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14445 return CMD_WARNING;
14446 }
14447 }
14448 else
14449 {
14450 bgp = bgp_get_default ();
14451 if (bgp == NULL)
14452 {
14453 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14454 return CMD_WARNING;
14455 }
14456 }
14457
14458 if (argc == 3)
14459 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14460 else
14461 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14462
14463 if (! peer)
14464 return CMD_WARNING;
14465
14466 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14467 {
14468 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14469 VTY_NEWLINE);
14470 return CMD_WARNING;
14471 }
14472
14473 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14474 PEER_FLAG_RSERVER_CLIENT))
14475 {
14476 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14477 VTY_NEWLINE);
14478 return CMD_WARNING;
14479 }
14480
14481 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14482 (argc == 3) ? argv[2] : argv[1],
14483 AFI_IP6, SAFI_UNICAST, NULL, 0);
14484}
14485
14486DEFUN (show_bgp_view_ipv6_rsclient_route,
14487 show_bgp_view_ipv6_rsclient_route_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014488 "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
paulfee0f4c2004-09-13 05:12:46 +000014489 SHOW_STR
14490 BGP_STR
14491 "BGP view\n"
Lou Berger651b4022016-01-12 13:42:07 -050014492 "BGP view name\n"
14493 "IP6_STR"
paulfee0f4c2004-09-13 05:12:46 +000014494 "Information about Route Server Client\n"
14495 NEIGHBOR_ADDR_STR
14496 "Network in the BGP routing table to display\n")
14497{
14498 struct bgp *bgp;
14499 struct peer *peer;
14500
14501 /* BGP structure lookup. */
14502 if (argc == 3)
14503 {
14504 bgp = bgp_lookup_by_name (argv[0]);
14505 if (bgp == NULL)
14506 {
14507 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14508 return CMD_WARNING;
14509 }
14510 }
14511 else
14512 {
14513 bgp = bgp_get_default ();
14514 if (bgp == NULL)
14515 {
14516 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14517 return CMD_WARNING;
14518 }
14519 }
14520
14521 if (argc == 3)
14522 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14523 else
14524 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14525
14526 if (! peer)
14527 return CMD_WARNING;
14528
14529 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14530 {
14531 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14532 VTY_NEWLINE);
14533 return CMD_WARNING;
14534 }
14535
14536 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14537 PEER_FLAG_RSERVER_CLIENT))
14538 {
14539 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14540 VTY_NEWLINE);
14541 return CMD_WARNING;
14542 }
14543
14544 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14545 (argc == 3) ? argv[2] : argv[1],
14546 AFI_IP6, SAFI_UNICAST, NULL, 0);
14547}
14548
Lou Bergerf9b6c392016-01-12 13:42:09 -050014549ALIAS (show_bgp_view_ipv6_rsclient_route,
paulfee0f4c2004-09-13 05:12:46 +000014550 show_bgp_rsclient_route_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014551 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14552 SHOW_STR
14553 BGP_STR
14554 "Information about Route Server Client\n"
14555 NEIGHBOR_ADDR_STR
14556 "Network in the BGP routing table to display\n")
14557
14558ALIAS (show_bgp_view_ipv6_rsclient_route,
14559 show_bgp_ipv6_rsclient_route_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014560 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
paulfee0f4c2004-09-13 05:12:46 +000014561 SHOW_STR
14562 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050014563 IP6_STR
paulfee0f4c2004-09-13 05:12:46 +000014564 "Information about Route Server Client\n"
14565 NEIGHBOR_ADDR_STR
14566 "Network in the BGP routing table to display\n")
14567
Michael Lambert95cbbd22010-07-23 14:43:04 -040014568DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
14569 show_bgp_view_ipv6_safi_rsclient_route_cmd,
14570 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14571 SHOW_STR
14572 BGP_STR
14573 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014574 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014575 "Address family\n"
14576 "Address Family modifier\n"
14577 "Address Family modifier\n"
14578 "Information about Route Server Client\n"
14579 NEIGHBOR_ADDR_STR
14580 "Network in the BGP routing table to display\n")
14581{
14582 struct bgp *bgp;
14583 struct peer *peer;
14584 safi_t safi;
14585
14586 /* BGP structure lookup. */
14587 if (argc == 4)
14588 {
14589 bgp = bgp_lookup_by_name (argv[0]);
14590 if (bgp == NULL)
14591 {
14592 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14593 return CMD_WARNING;
14594 }
14595 }
14596 else
14597 {
14598 bgp = bgp_get_default ();
14599 if (bgp == NULL)
14600 {
14601 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14602 return CMD_WARNING;
14603 }
14604 }
14605
14606 if (argc == 4) {
14607 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14608 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14609 } else {
14610 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14611 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14612 }
14613
14614 if (! peer)
14615 return CMD_WARNING;
14616
14617 if (! peer->afc[AFI_IP6][safi])
14618 {
14619 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14620 VTY_NEWLINE);
14621 return CMD_WARNING;
14622}
14623
14624 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14625 PEER_FLAG_RSERVER_CLIENT))
14626 {
14627 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14628 VTY_NEWLINE);
14629 return CMD_WARNING;
14630 }
14631
14632 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
14633 (argc == 4) ? argv[3] : argv[2],
14634 AFI_IP6, safi, NULL, 0);
14635}
14636
14637ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
14638 show_bgp_ipv6_safi_rsclient_route_cmd,
14639 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14640 SHOW_STR
14641 BGP_STR
14642 "Address family\n"
14643 "Address Family modifier\n"
14644 "Address Family modifier\n"
14645 "Information about Route Server Client\n"
14646 NEIGHBOR_ADDR_STR
14647 "Network in the BGP routing table to display\n")
14648
Lou Berger651b4022016-01-12 13:42:07 -050014649
paulfee0f4c2004-09-13 05:12:46 +000014650DEFUN (show_bgp_view_rsclient_prefix,
14651 show_bgp_view_rsclient_prefix_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014652 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
14653 SHOW_STR
14654 BGP_STR
14655 "BGP view\n"
14656 "View name\n"
14657 "Information about Route Server Client\n"
14658 NEIGHBOR_ADDR_STR
14659 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14660{
14661 struct bgp *bgp;
14662 struct peer *peer;
14663
14664 /* BGP structure lookup. */
14665 if (argc == 3)
14666 {
14667 bgp = bgp_lookup_by_name (argv[0]);
14668 if (bgp == NULL)
14669 {
14670 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14671 return CMD_WARNING;
14672 }
14673 }
14674 else
14675 {
14676 bgp = bgp_get_default ();
14677 if (bgp == NULL)
14678 {
14679 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14680 return CMD_WARNING;
14681 }
14682 }
14683
14684 if (argc == 3)
14685 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14686 else
14687 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14688
14689 if (! peer)
14690 return CMD_WARNING;
14691
14692 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14693 {
14694 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14695 VTY_NEWLINE);
14696 return CMD_WARNING;
14697 }
14698
14699 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14700 PEER_FLAG_RSERVER_CLIENT))
14701 {
14702 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14703 VTY_NEWLINE);
14704 return CMD_WARNING;
14705 }
14706
14707 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14708 (argc == 3) ? argv[2] : argv[1],
14709 AFI_IP6, SAFI_UNICAST, NULL, 1);
14710}
14711
14712DEFUN (show_bgp_view_ipv6_rsclient_prefix,
14713 show_bgp_view_ipv6_rsclient_prefix_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014714 "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 +000014715 SHOW_STR
14716 BGP_STR
14717 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014718 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050014719 IP6_STR
paulfee0f4c2004-09-13 05:12:46 +000014720 "Information about Route Server Client\n"
14721 NEIGHBOR_ADDR_STR
14722 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14723{
14724 struct bgp *bgp;
14725 struct peer *peer;
14726
14727 /* BGP structure lookup. */
14728 if (argc == 3)
14729 {
14730 bgp = bgp_lookup_by_name (argv[0]);
14731 if (bgp == NULL)
14732 {
14733 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14734 return CMD_WARNING;
14735 }
14736 }
14737 else
14738 {
14739 bgp = bgp_get_default ();
14740 if (bgp == NULL)
14741 {
14742 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14743 return CMD_WARNING;
14744 }
14745 }
14746
14747 if (argc == 3)
14748 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14749 else
14750 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14751
14752 if (! peer)
14753 return CMD_WARNING;
14754
14755 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14756 {
14757 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14758 VTY_NEWLINE);
14759 return CMD_WARNING;
14760 }
14761
14762 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14763 PEER_FLAG_RSERVER_CLIENT))
14764 {
14765 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14766 VTY_NEWLINE);
14767 return CMD_WARNING;
14768 }
14769
14770 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14771 (argc == 3) ? argv[2] : argv[1],
14772 AFI_IP6, SAFI_UNICAST, NULL, 1);
14773}
14774
Lou Bergerf9b6c392016-01-12 13:42:09 -050014775ALIAS (show_bgp_view_ipv6_rsclient_prefix,
paulfee0f4c2004-09-13 05:12:46 +000014776 show_bgp_rsclient_prefix_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014777 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
14778 SHOW_STR
14779 BGP_STR
14780 "Information about Route Server Client\n"
14781 NEIGHBOR_ADDR_STR
14782 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14783
14784ALIAS (show_bgp_view_ipv6_rsclient_prefix,
14785 show_bgp_ipv6_rsclient_prefix_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014786 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
paulfee0f4c2004-09-13 05:12:46 +000014787 SHOW_STR
14788 BGP_STR
14789 "Information about Route Server Client\n"
14790 NEIGHBOR_ADDR_STR
14791 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14792
Michael Lambert95cbbd22010-07-23 14:43:04 -040014793DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
14794 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
14795 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
14796 SHOW_STR
14797 BGP_STR
14798 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014799 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014800 "Address family\n"
14801 "Address Family modifier\n"
14802 "Address Family modifier\n"
14803 "Information about Route Server Client\n"
14804 NEIGHBOR_ADDR_STR
14805 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
14806{
14807 struct bgp *bgp;
14808 struct peer *peer;
14809 safi_t safi;
14810
14811 /* BGP structure lookup. */
14812 if (argc == 4)
14813 {
14814 bgp = bgp_lookup_by_name (argv[0]);
14815 if (bgp == NULL)
14816 {
14817 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14818 return CMD_WARNING;
14819 }
14820 }
14821 else
14822 {
14823 bgp = bgp_get_default ();
14824 if (bgp == NULL)
14825 {
14826 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14827 return CMD_WARNING;
14828 }
14829 }
14830
14831 if (argc == 4) {
14832 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14833 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14834 } else {
14835 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14836 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14837 }
14838
14839 if (! peer)
14840 return CMD_WARNING;
14841
14842 if (! peer->afc[AFI_IP6][safi])
14843 {
14844 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14845 VTY_NEWLINE);
14846 return CMD_WARNING;
14847}
14848
14849 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14850 PEER_FLAG_RSERVER_CLIENT))
14851{
14852 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14853 VTY_NEWLINE);
14854 return CMD_WARNING;
14855 }
14856
14857 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
14858 (argc == 4) ? argv[3] : argv[2],
14859 AFI_IP6, safi, NULL, 1);
14860}
14861
14862ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
14863 show_bgp_ipv6_safi_rsclient_prefix_cmd,
14864 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
14865 SHOW_STR
14866 BGP_STR
14867 "Address family\n"
14868 "Address Family modifier\n"
14869 "Address Family modifier\n"
14870 "Information about Route Server Client\n"
14871 NEIGHBOR_ADDR_STR
14872 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
14873
paul718e3742002-12-13 20:15:29 +000014874struct bgp_table *bgp_distance_table;
14875
14876struct bgp_distance
14877{
14878 /* Distance value for the IP source prefix. */
14879 u_char distance;
14880
14881 /* Name of the access-list to be matched. */
14882 char *access_list;
14883};
14884
paul94f2b392005-06-28 12:44:16 +000014885static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080014886bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000014887{
Stephen Hemminger393deb92008-08-18 14:13:29 -070014888 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000014889}
14890
paul94f2b392005-06-28 12:44:16 +000014891static void
paul718e3742002-12-13 20:15:29 +000014892bgp_distance_free (struct bgp_distance *bdistance)
14893{
14894 XFREE (MTYPE_BGP_DISTANCE, bdistance);
14895}
14896
paul94f2b392005-06-28 12:44:16 +000014897static int
paulfd79ac92004-10-13 05:06:08 +000014898bgp_distance_set (struct vty *vty, const char *distance_str,
14899 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000014900{
14901 int ret;
Roman Hoog Antink6184c392014-03-17 14:01:42 +010014902 struct prefix p;
paul718e3742002-12-13 20:15:29 +000014903 u_char distance;
14904 struct bgp_node *rn;
14905 struct bgp_distance *bdistance;
14906
Roman Hoog Antink6184c392014-03-17 14:01:42 +010014907 ret = str2prefix (ip_str, &p);
paul718e3742002-12-13 20:15:29 +000014908 if (ret == 0)
14909 {
14910 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
14911 return CMD_WARNING;
14912 }
14913
14914 distance = atoi (distance_str);
14915
14916 /* Get BGP distance node. */
14917 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
14918 if (rn->info)
14919 {
14920 bdistance = rn->info;
14921 bgp_unlock_node (rn);
14922 }
14923 else
14924 {
14925 bdistance = bgp_distance_new ();
14926 rn->info = bdistance;
14927 }
14928
14929 /* Set distance value. */
14930 bdistance->distance = distance;
14931
14932 /* Reset access-list configuration. */
14933 if (bdistance->access_list)
14934 {
14935 free (bdistance->access_list);
14936 bdistance->access_list = NULL;
14937 }
14938 if (access_list_str)
14939 bdistance->access_list = strdup (access_list_str);
14940
14941 return CMD_SUCCESS;
14942}
14943
paul94f2b392005-06-28 12:44:16 +000014944static int
paulfd79ac92004-10-13 05:06:08 +000014945bgp_distance_unset (struct vty *vty, const char *distance_str,
14946 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000014947{
14948 int ret;
Roman Hoog Antink6184c392014-03-17 14:01:42 +010014949 struct prefix p;
paul718e3742002-12-13 20:15:29 +000014950 u_char distance;
14951 struct bgp_node *rn;
14952 struct bgp_distance *bdistance;
14953
Roman Hoog Antink6184c392014-03-17 14:01:42 +010014954 ret = str2prefix (ip_str, &p);
paul718e3742002-12-13 20:15:29 +000014955 if (ret == 0)
14956 {
14957 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
14958 return CMD_WARNING;
14959 }
14960
14961 distance = atoi (distance_str);
14962
14963 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
14964 if (! rn)
14965 {
14966 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
14967 return CMD_WARNING;
14968 }
14969
14970 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010014971
14972 if (bdistance->distance != distance)
14973 {
14974 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
14975 return CMD_WARNING;
14976 }
14977
paul718e3742002-12-13 20:15:29 +000014978 if (bdistance->access_list)
14979 free (bdistance->access_list);
14980 bgp_distance_free (bdistance);
14981
14982 rn->info = NULL;
14983 bgp_unlock_node (rn);
14984 bgp_unlock_node (rn);
14985
14986 return CMD_SUCCESS;
14987}
14988
paul718e3742002-12-13 20:15:29 +000014989/* Apply BGP information to distance method. */
14990u_char
14991bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
14992{
14993 struct bgp_node *rn;
14994 struct prefix_ipv4 q;
14995 struct peer *peer;
14996 struct bgp_distance *bdistance;
14997 struct access_list *alist;
14998 struct bgp_static *bgp_static;
14999
15000 if (! bgp)
15001 return 0;
15002
15003 if (p->family != AF_INET)
15004 return 0;
15005
15006 peer = rinfo->peer;
15007
15008 if (peer->su.sa.sa_family != AF_INET)
15009 return 0;
15010
15011 memset (&q, 0, sizeof (struct prefix_ipv4));
15012 q.family = AF_INET;
15013 q.prefix = peer->su.sin.sin_addr;
15014 q.prefixlen = IPV4_MAX_BITLEN;
15015
15016 /* Check source address. */
15017 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
15018 if (rn)
15019 {
15020 bdistance = rn->info;
15021 bgp_unlock_node (rn);
15022
15023 if (bdistance->access_list)
15024 {
15025 alist = access_list_lookup (AFI_IP, bdistance->access_list);
15026 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
15027 return bdistance->distance;
15028 }
15029 else
15030 return bdistance->distance;
15031 }
15032
15033 /* Backdoor check. */
15034 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
15035 if (rn)
15036 {
15037 bgp_static = rn->info;
15038 bgp_unlock_node (rn);
15039
15040 if (bgp_static->backdoor)
15041 {
15042 if (bgp->distance_local)
15043 return bgp->distance_local;
15044 else
15045 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15046 }
15047 }
15048
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000015049 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000015050 {
15051 if (bgp->distance_ebgp)
15052 return bgp->distance_ebgp;
15053 return ZEBRA_EBGP_DISTANCE_DEFAULT;
15054 }
15055 else
15056 {
15057 if (bgp->distance_ibgp)
15058 return bgp->distance_ibgp;
15059 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15060 }
15061}
15062
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015063#ifdef HAVE_IPV6
15064/* Apply BGP information to ipv6 distance method. */
15065u_char
15066ipv6_bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
15067{
15068 struct bgp_node *rn;
15069 struct prefix_ipv6 q;
15070 struct peer *peer;
15071 struct bgp_distance *bdistance;
15072 struct access_list *alist;
15073 struct bgp_static *bgp_static;
15074
15075 if (! bgp)
15076 return 0;
15077
15078 if (p->family != AF_INET6)
15079 return 0;
15080
15081 peer = rinfo->peer;
15082
15083 if (peer->su.sa.sa_family != AF_INET6)
15084 return 0;
15085
15086 memset (&q, 0, sizeof (struct prefix_ipv6));
15087 q.family = AF_INET;
15088 q.prefix = peer->su.sin6.sin6_addr;
15089 q.prefixlen = IPV6_MAX_BITLEN;
15090
15091 /* Check source address. */
15092 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
15093 if (rn)
15094 {
15095 bdistance = rn->info;
15096 bgp_unlock_node (rn);
15097
15098 if (bdistance->access_list)
15099 {
15100 alist = access_list_lookup (AFI_IP6, bdistance->access_list);
15101 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
15102 return bdistance->distance;
15103 }
15104 else
15105 return bdistance->distance;
15106 }
15107 /* Backdoor check. */
15108 rn = bgp_node_lookup (bgp->route[AFI_IP6][SAFI_UNICAST], p);
15109 if (rn)
15110 {
15111 bgp_static = rn->info;
15112 bgp_unlock_node (rn);
15113
15114 if (bgp_static->backdoor)
15115 {
15116 if (bgp->ipv6_distance_local)
15117 return bgp->ipv6_distance_local;
15118 else
15119 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15120 }
15121 }
15122
15123 if (peer_sort (peer) == BGP_PEER_EBGP)
15124 {
15125 if (bgp->ipv6_distance_ebgp)
15126 return bgp->ipv6_distance_ebgp;
15127 return ZEBRA_EBGP_DISTANCE_DEFAULT;
15128 }
15129 else
15130 {
15131 if (bgp->ipv6_distance_ibgp)
15132 return bgp->ipv6_distance_ibgp;
15133 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15134 }
15135}
15136#endif /* HAVE_IPV6 */
15137
paul718e3742002-12-13 20:15:29 +000015138DEFUN (bgp_distance,
15139 bgp_distance_cmd,
15140 "distance bgp <1-255> <1-255> <1-255>",
15141 "Define an administrative distance\n"
15142 "BGP distance\n"
15143 "Distance for routes external to the AS\n"
15144 "Distance for routes internal to the AS\n"
15145 "Distance for local routes\n")
15146{
15147 struct bgp *bgp;
15148
15149 bgp = vty->index;
15150
15151 bgp->distance_ebgp = atoi (argv[0]);
15152 bgp->distance_ibgp = atoi (argv[1]);
15153 bgp->distance_local = atoi (argv[2]);
15154 return CMD_SUCCESS;
15155}
15156
15157DEFUN (no_bgp_distance,
15158 no_bgp_distance_cmd,
15159 "no distance bgp <1-255> <1-255> <1-255>",
15160 NO_STR
15161 "Define an administrative distance\n"
15162 "BGP distance\n"
15163 "Distance for routes external to the AS\n"
15164 "Distance for routes internal to the AS\n"
15165 "Distance for local routes\n")
15166{
15167 struct bgp *bgp;
15168
15169 bgp = vty->index;
15170
15171 bgp->distance_ebgp= 0;
15172 bgp->distance_ibgp = 0;
15173 bgp->distance_local = 0;
15174 return CMD_SUCCESS;
15175}
15176
15177ALIAS (no_bgp_distance,
15178 no_bgp_distance2_cmd,
15179 "no distance bgp",
15180 NO_STR
15181 "Define an administrative distance\n"
15182 "BGP distance\n")
15183
15184DEFUN (bgp_distance_source,
15185 bgp_distance_source_cmd,
15186 "distance <1-255> A.B.C.D/M",
15187 "Define an administrative distance\n"
15188 "Administrative distance\n"
15189 "IP source prefix\n")
15190{
15191 bgp_distance_set (vty, argv[0], argv[1], NULL);
15192 return CMD_SUCCESS;
15193}
15194
15195DEFUN (no_bgp_distance_source,
15196 no_bgp_distance_source_cmd,
15197 "no distance <1-255> A.B.C.D/M",
15198 NO_STR
15199 "Define an administrative distance\n"
15200 "Administrative distance\n"
15201 "IP source prefix\n")
15202{
15203 bgp_distance_unset (vty, argv[0], argv[1], NULL);
15204 return CMD_SUCCESS;
15205}
15206
15207DEFUN (bgp_distance_source_access_list,
15208 bgp_distance_source_access_list_cmd,
15209 "distance <1-255> A.B.C.D/M WORD",
15210 "Define an administrative distance\n"
15211 "Administrative distance\n"
15212 "IP source prefix\n"
15213 "Access list name\n")
15214{
15215 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
15216 return CMD_SUCCESS;
15217}
15218
15219DEFUN (no_bgp_distance_source_access_list,
15220 no_bgp_distance_source_access_list_cmd,
15221 "no distance <1-255> A.B.C.D/M WORD",
15222 NO_STR
15223 "Define an administrative distance\n"
15224 "Administrative distance\n"
15225 "IP source prefix\n"
15226 "Access list name\n")
15227{
15228 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
15229 return CMD_SUCCESS;
15230}
David Lamparter6b0655a2014-06-04 06:53:35 +020015231
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015232#ifdef HAVE_IPV6
15233DEFUN (ipv6_bgp_distance,
15234 ipv6_bgp_distance_cmd,
15235 "distance bgp <1-255> <1-255> <1-255>",
15236 "Define an administrative distance\n"
15237 "BGP distance\n"
15238 "Distance for routes external to the AS\n"
15239 "Distance for routes internal to the AS\n"
15240 "Distance for local routes\n")
15241{
15242 struct bgp *bgp;
15243
15244 bgp = vty->index;
15245
15246 bgp->ipv6_distance_ebgp = atoi (argv[0]);
15247 bgp->ipv6_distance_ibgp = atoi (argv[1]);
15248 bgp->ipv6_distance_local = atoi (argv[2]);
15249 return CMD_SUCCESS;
15250}
15251
15252DEFUN (no_ipv6_bgp_distance,
15253 no_ipv6_bgp_distance_cmd,
15254 "no distance bgp <1-255> <1-255> <1-255>",
15255 NO_STR
15256 "Define an administrative distance\n"
15257 "BGP distance\n"
15258 "Distance for routes external to the AS\n"
15259 "Distance for routes internal to the AS\n"
15260 "Distance for local routes\n")
15261{
15262 struct bgp *bgp;
15263
15264 bgp = vty->index;
15265
15266 bgp->ipv6_distance_ebgp= 0;
15267 bgp->ipv6_distance_ibgp = 0;
15268 bgp->ipv6_distance_local = 0;
15269 return CMD_SUCCESS;
15270}
15271
15272ALIAS (no_ipv6_bgp_distance,
15273 no_ipv6_bgp_distance2_cmd,
15274 "no distance bgp",
15275 NO_STR
15276 "Define an administrative distance\n"
15277 "BGP distance\n")
15278
15279DEFUN (ipv6_bgp_distance_source,
15280 ipv6_bgp_distance_source_cmd,
15281 "distance <1-255> X:X::X:X/M",
15282 "Define an administrative distance\n"
15283 "Administrative distance\n"
15284 "IP source prefix\n")
15285{
15286 bgp_distance_set (vty, argv[0], argv[1], NULL);
15287 return CMD_SUCCESS;
15288}
15289
15290DEFUN (no_ipv6_bgp_distance_source,
15291 no_ipv6_bgp_distance_source_cmd,
15292 "no distance <1-255> X:X::X:X/M",
15293 NO_STR
15294 "Define an administrative distance\n"
15295 "Administrative distance\n"
15296 "IP source prefix\n")
15297{
15298 bgp_distance_unset (vty, argv[0], argv[1], NULL);
15299 return CMD_SUCCESS;
15300}
15301
15302DEFUN (ipv6_bgp_distance_source_access_list,
15303 ipv6_bgp_distance_source_access_list_cmd,
15304 "distance <1-255> X:X::X:X/M WORD",
15305 "Define an administrative distance\n"
15306 "Administrative distance\n"
15307 "IP source prefix\n"
15308 "Access list name\n")
15309{
15310 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
15311 return CMD_SUCCESS;
15312}
15313
15314DEFUN (no_ipv6_bgp_distance_source_access_list,
15315 no_ipv6_bgp_distance_source_access_list_cmd,
15316 "no distance <1-255> X:X::X:X/M WORD",
15317 NO_STR
15318 "Define an administrative distance\n"
15319 "Administrative distance\n"
15320 "IP source prefix\n"
15321 "Access list name\n")
15322{
15323 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
15324 return CMD_SUCCESS;
15325}
15326#endif
15327
paul718e3742002-12-13 20:15:29 +000015328DEFUN (bgp_damp_set,
15329 bgp_damp_set_cmd,
15330 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
15331 "BGP Specific commands\n"
15332 "Enable route-flap dampening\n"
15333 "Half-life time for the penalty\n"
15334 "Value to start reusing a route\n"
15335 "Value to start suppressing a route\n"
15336 "Maximum duration to suppress a stable route\n")
15337{
15338 struct bgp *bgp;
15339 int half = DEFAULT_HALF_LIFE * 60;
15340 int reuse = DEFAULT_REUSE;
15341 int suppress = DEFAULT_SUPPRESS;
15342 int max = 4 * half;
15343
15344 if (argc == 4)
15345 {
15346 half = atoi (argv[0]) * 60;
15347 reuse = atoi (argv[1]);
15348 suppress = atoi (argv[2]);
15349 max = atoi (argv[3]) * 60;
15350 }
15351 else if (argc == 1)
15352 {
15353 half = atoi (argv[0]) * 60;
15354 max = 4 * half;
15355 }
15356
15357 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000015358
15359 if (suppress < reuse)
15360 {
15361 vty_out (vty, "Suppress value cannot be less than reuse value %s",
15362 VTY_NEWLINE);
15363 return 0;
15364 }
15365
paul718e3742002-12-13 20:15:29 +000015366 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
15367 half, reuse, suppress, max);
15368}
15369
15370ALIAS (bgp_damp_set,
15371 bgp_damp_set2_cmd,
15372 "bgp dampening <1-45>",
15373 "BGP Specific commands\n"
15374 "Enable route-flap dampening\n"
15375 "Half-life time for the penalty\n")
15376
15377ALIAS (bgp_damp_set,
15378 bgp_damp_set3_cmd,
15379 "bgp dampening",
15380 "BGP Specific commands\n"
15381 "Enable route-flap dampening\n")
15382
15383DEFUN (bgp_damp_unset,
15384 bgp_damp_unset_cmd,
15385 "no bgp dampening",
15386 NO_STR
15387 "BGP Specific commands\n"
15388 "Enable route-flap dampening\n")
15389{
15390 struct bgp *bgp;
15391
15392 bgp = vty->index;
15393 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
15394}
15395
15396ALIAS (bgp_damp_unset,
15397 bgp_damp_unset2_cmd,
15398 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
15399 NO_STR
15400 "BGP Specific commands\n"
15401 "Enable route-flap dampening\n"
15402 "Half-life time for the penalty\n"
15403 "Value to start reusing a route\n"
15404 "Value to start suppressing a route\n"
15405 "Maximum duration to suppress a stable route\n")
15406
Lou Bergerf9b6c392016-01-12 13:42:09 -050015407DEFUN (show_ip_bgp_dampened_paths,
15408 show_ip_bgp_dampened_paths_cmd,
15409 "show ip bgp dampened-paths",
15410 SHOW_STR
15411 IP_STR
15412 BGP_STR
15413 "Display paths suppressed due to dampening\n")
15414{
15415 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
15416 NULL);
15417}
15418
15419ALIAS (show_ip_bgp_dampened_paths,
15420 show_ip_bgp_damp_dampened_paths_cmd,
15421 "show ip bgp dampening dampened-paths",
15422 SHOW_STR
15423 IP_STR
15424 BGP_STR
15425 "Display detailed information about dampening\n"
15426 "Display paths suppressed due to dampening\n")
15427
15428DEFUN (show_ip_bgp_flap_statistics,
15429 show_ip_bgp_flap_statistics_cmd,
15430 "show ip bgp flap-statistics",
15431 SHOW_STR
15432 IP_STR
15433 BGP_STR
15434 "Display flap statistics of routes\n")
15435{
15436 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
15437 bgp_show_type_flap_statistics, NULL);
15438}
15439
15440ALIAS (show_ip_bgp_flap_statistics,
15441 show_ip_bgp_damp_flap_statistics_cmd,
15442 "show ip bgp dampening flap-statistics",
15443 SHOW_STR
15444 IP_STR
15445 BGP_STR
15446 "Display detailed information about dampening\n"
15447 "Display flap statistics of routes\n")
15448
Lou Berger651b4022016-01-12 13:42:07 -050015449DEFUN (show_bgp_ipv4_safi_dampened_paths,
15450 show_bgp_ipv4_safi_dampened_paths_cmd,
15451 "show bgp ipv4 (encap|multicast|unicast|vpn) dampened-paths",
paul718e3742002-12-13 20:15:29 +000015452 SHOW_STR
paul718e3742002-12-13 20:15:29 +000015453 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015454 IP_STR
15455 "Address Family modifier\n"
15456 "Address Family modifier\n"
15457 "Address Family modifier\n"
15458 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000015459 "Display paths suppressed due to dampening\n")
15460{
Lou Berger651b4022016-01-12 13:42:07 -050015461 safi_t safi;
paul718e3742002-12-13 20:15:29 +000015462
Lou Berger651b4022016-01-12 13:42:07 -050015463 if (bgp_parse_safi(argv[0], &safi)) {
15464 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15465 return CMD_WARNING;
15466 }
15467
15468 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_dampend_paths, NULL);
15469}
15470ALIAS (show_bgp_ipv4_safi_dampened_paths,
15471 show_bgp_ipv4_safi_damp_dampened_paths_cmd,
15472 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening dampened-paths",
Balaji3921cc52015-05-16 23:12:17 +053015473 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053015474 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015475 IP_STR
15476 "Address Family modifier\n"
15477 "Address Family modifier\n"
15478 "Address Family modifier\n"
15479 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053015480 "Display detailed information about dampening\n"
15481 "Display paths suppressed due to dampening\n")
Lou Berger205e6742016-01-12 13:42:11 -050015482
Lou Berger651b4022016-01-12 13:42:07 -050015483DEFUN (show_bgp_ipv6_safi_dampened_paths,
15484 show_bgp_ipv6_safi_dampened_paths_cmd,
15485 "show bgp ipv6 (encap|multicast|unicast|vpn) dampened-paths",
paul718e3742002-12-13 20:15:29 +000015486 SHOW_STR
paul718e3742002-12-13 20:15:29 +000015487 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015488 IPV6_STR
15489 "Address Family modifier\n"
15490 "Address Family modifier\n"
15491 "Address Family modifier\n"
15492 "Address Family modifier\n"
15493 "Display paths suppressed due to dampening\n")
15494{
15495 safi_t safi;
15496
15497 if (bgp_parse_safi(argv[0], &safi)) {
15498 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15499 return CMD_WARNING;
15500 }
15501
15502 return bgp_show (vty, NULL, AFI_IP6, safi, bgp_show_type_dampend_paths, NULL);
15503}
15504ALIAS (show_bgp_ipv6_safi_dampened_paths,
15505 show_bgp_ipv6_safi_damp_dampened_paths_cmd,
15506 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening dampened-paths",
15507 SHOW_STR
15508 BGP_STR
15509 IPV6_STR
15510 "Address Family modifier\n"
15511 "Address Family modifier\n"
15512 "Address Family modifier\n"
15513 "Address Family modifier\n"
15514 "Display detailed information about dampening\n"
15515 "Display paths suppressed due to dampening\n")
Lou Berger651b4022016-01-12 13:42:07 -050015516
15517DEFUN (show_bgp_ipv4_safi_flap_statistics,
15518 show_bgp_ipv4_safi_flap_statistics_cmd,
15519 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics",
15520 SHOW_STR
15521 BGP_STR
15522 "Address Family\n"
15523 "Address Family modifier\n"
15524 "Address Family modifier\n"
15525 "Address Family modifier\n"
15526 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000015527 "Display flap statistics of routes\n")
15528{
Lou Berger651b4022016-01-12 13:42:07 -050015529 safi_t safi;
David Lamparter6b0655a2014-06-04 06:53:35 +020015530
Lou Berger651b4022016-01-12 13:42:07 -050015531 if (bgp_parse_safi(argv[0], &safi)) {
15532 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15533 return CMD_WARNING;
15534 }
15535
15536 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_statistics, NULL);
15537}
15538ALIAS (show_bgp_ipv4_safi_flap_statistics,
15539 show_bgp_ipv4_safi_damp_flap_statistics_cmd,
15540 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics",
Balaji3921cc52015-05-16 23:12:17 +053015541 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053015542 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015543 "Address Family\n"
15544 "Address Family modifier\n"
15545 "Address Family modifier\n"
15546 "Address Family modifier\n"
15547 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053015548 "Display detailed information about dampening\n"
15549 "Display flap statistics of routes\n")
Lou Berger205e6742016-01-12 13:42:11 -050015550
Lou Berger651b4022016-01-12 13:42:07 -050015551DEFUN (show_bgp_ipv6_safi_flap_statistics,
15552 show_bgp_ipv6_safi_flap_statistics_cmd,
15553 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics",
15554 SHOW_STR
15555 BGP_STR
15556 "Address Family\n"
15557 "Address Family modifier\n"
15558 "Address Family modifier\n"
15559 "Address Family modifier\n"
15560 "Address Family modifier\n"
15561 "Display flap statistics of routes\n")
15562{
15563 safi_t safi;
15564
15565 if (bgp_parse_safi(argv[0], &safi)) {
15566 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15567 return CMD_WARNING;
15568 }
15569
15570 return bgp_show (vty, NULL, AFI_IP6, safi, bgp_show_type_flap_statistics, NULL);
15571}
15572ALIAS (show_bgp_ipv6_safi_flap_statistics,
15573 show_bgp_ipv6_safi_damp_flap_statistics_cmd,
15574 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics",
15575 SHOW_STR
15576 BGP_STR
15577 "Address Family\n"
15578 "Address Family modifier\n"
15579 "Address Family modifier\n"
15580 "Address Family modifier\n"
15581 "Address Family modifier\n"
15582 "Display detailed information about dampening\n"
15583 "Display flap statistics of routes\n")
Balaji3921cc52015-05-16 23:12:17 +053015584
paul718e3742002-12-13 20:15:29 +000015585/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000015586static int
paulfd79ac92004-10-13 05:06:08 +000015587bgp_clear_damp_route (struct vty *vty, const char *view_name,
15588 const char *ip_str, afi_t afi, safi_t safi,
15589 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000015590{
15591 int ret;
15592 struct prefix match;
15593 struct bgp_node *rn;
15594 struct bgp_node *rm;
15595 struct bgp_info *ri;
15596 struct bgp_info *ri_temp;
15597 struct bgp *bgp;
15598 struct bgp_table *table;
15599
15600 /* BGP structure lookup. */
15601 if (view_name)
15602 {
15603 bgp = bgp_lookup_by_name (view_name);
15604 if (bgp == NULL)
15605 {
15606 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
15607 return CMD_WARNING;
15608 }
15609 }
15610 else
15611 {
15612 bgp = bgp_get_default ();
15613 if (bgp == NULL)
15614 {
15615 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
15616 return CMD_WARNING;
15617 }
15618 }
15619
15620 /* Check IP address argument. */
15621 ret = str2prefix (ip_str, &match);
15622 if (! ret)
15623 {
15624 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
15625 return CMD_WARNING;
15626 }
15627
15628 match.family = afi2family (afi);
15629
Lou Berger298cc2f2016-01-12 13:42:02 -050015630 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000015631 {
Lou Berger298cc2f2016-01-12 13:42:02 -050015632 for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +000015633 {
15634 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
15635 continue;
15636
15637 if ((table = rn->info) != NULL)
15638 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000015639 {
15640 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
15641 {
15642 ri = rm->info;
15643 while (ri)
15644 {
15645 if (ri->extra && ri->extra->damp_info)
15646 {
15647 ri_temp = ri->next;
15648 bgp_damp_info_free (ri->extra->damp_info, 1);
15649 ri = ri_temp;
15650 }
15651 else
15652 ri = ri->next;
15653 }
15654 }
15655
15656 bgp_unlock_node (rm);
15657 }
paul718e3742002-12-13 20:15:29 +000015658 }
15659 }
15660 else
15661 {
15662 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000015663 {
15664 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
15665 {
15666 ri = rn->info;
15667 while (ri)
15668 {
15669 if (ri->extra && ri->extra->damp_info)
15670 {
15671 ri_temp = ri->next;
15672 bgp_damp_info_free (ri->extra->damp_info, 1);
15673 ri = ri_temp;
15674 }
15675 else
15676 ri = ri->next;
15677 }
15678 }
15679
15680 bgp_unlock_node (rn);
15681 }
paul718e3742002-12-13 20:15:29 +000015682 }
15683
15684 return CMD_SUCCESS;
15685}
15686
15687DEFUN (clear_ip_bgp_dampening,
15688 clear_ip_bgp_dampening_cmd,
15689 "clear ip bgp dampening",
15690 CLEAR_STR
15691 IP_STR
15692 BGP_STR
15693 "Clear route flap dampening information\n")
15694{
15695 bgp_damp_info_clean ();
15696 return CMD_SUCCESS;
15697}
15698
15699DEFUN (clear_ip_bgp_dampening_prefix,
15700 clear_ip_bgp_dampening_prefix_cmd,
15701 "clear ip bgp dampening A.B.C.D/M",
15702 CLEAR_STR
15703 IP_STR
15704 BGP_STR
15705 "Clear route flap dampening information\n"
15706 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
15707{
15708 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
15709 SAFI_UNICAST, NULL, 1);
15710}
15711
15712DEFUN (clear_ip_bgp_dampening_address,
15713 clear_ip_bgp_dampening_address_cmd,
15714 "clear ip bgp dampening A.B.C.D",
15715 CLEAR_STR
15716 IP_STR
15717 BGP_STR
15718 "Clear route flap dampening information\n"
15719 "Network to clear damping information\n")
15720{
15721 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
15722 SAFI_UNICAST, NULL, 0);
15723}
15724
15725DEFUN (clear_ip_bgp_dampening_address_mask,
15726 clear_ip_bgp_dampening_address_mask_cmd,
15727 "clear ip bgp dampening A.B.C.D A.B.C.D",
15728 CLEAR_STR
15729 IP_STR
15730 BGP_STR
15731 "Clear route flap dampening information\n"
15732 "Network to clear damping information\n"
15733 "Network mask\n")
15734{
15735 int ret;
15736 char prefix_str[BUFSIZ];
15737
15738 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
15739 if (! ret)
15740 {
15741 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
15742 return CMD_WARNING;
15743 }
15744
15745 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
15746 SAFI_UNICAST, NULL, 0);
15747}
David Lamparter6b0655a2014-06-04 06:53:35 +020015748
Lou Berger298cc2f2016-01-12 13:42:02 -050015749/* also used for encap safi */
paul94f2b392005-06-28 12:44:16 +000015750static int
paul718e3742002-12-13 20:15:29 +000015751bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
15752 afi_t afi, safi_t safi, int *write)
15753{
15754 struct bgp_node *prn;
15755 struct bgp_node *rn;
15756 struct bgp_table *table;
15757 struct prefix *p;
15758 struct prefix_rd *prd;
15759 struct bgp_static *bgp_static;
15760 u_int32_t label;
15761 char buf[SU_ADDRSTRLEN];
15762 char rdbuf[RD_ADDRSTRLEN];
15763
15764 /* Network configuration. */
15765 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
15766 if ((table = prn->info) != NULL)
15767 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
15768 if ((bgp_static = rn->info) != NULL)
15769 {
15770 p = &rn->p;
15771 prd = (struct prefix_rd *) &prn->p;
15772
15773 /* "address-family" display. */
15774 bgp_config_write_family_header (vty, afi, safi, write);
15775
15776 /* "network" configuration display. */
15777 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
15778 label = decode_label (bgp_static->tag);
15779
15780 vty_out (vty, " network %s/%d rd %s tag %d",
15781 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
15782 p->prefixlen,
15783 rdbuf, label);
15784 vty_out (vty, "%s", VTY_NEWLINE);
15785 }
15786 return 0;
15787}
15788
15789/* Configuration of static route announcement and aggregate
15790 information. */
15791int
15792bgp_config_write_network (struct vty *vty, struct bgp *bgp,
15793 afi_t afi, safi_t safi, int *write)
15794{
15795 struct bgp_node *rn;
15796 struct prefix *p;
15797 struct bgp_static *bgp_static;
15798 struct bgp_aggregate *bgp_aggregate;
15799 char buf[SU_ADDRSTRLEN];
15800
Lou Berger298cc2f2016-01-12 13:42:02 -050015801 if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
paul718e3742002-12-13 20:15:29 +000015802 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
15803
15804 /* Network configuration. */
15805 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
15806 if ((bgp_static = rn->info) != NULL)
15807 {
15808 p = &rn->p;
15809
15810 /* "address-family" display. */
15811 bgp_config_write_family_header (vty, afi, safi, write);
15812
15813 /* "network" configuration display. */
15814 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
15815 {
15816 u_int32_t destination;
15817 struct in_addr netmask;
15818
15819 destination = ntohl (p->u.prefix4.s_addr);
15820 masklen2ip (p->prefixlen, &netmask);
15821 vty_out (vty, " network %s",
15822 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
15823
15824 if ((IN_CLASSC (destination) && p->prefixlen == 24)
15825 || (IN_CLASSB (destination) && p->prefixlen == 16)
15826 || (IN_CLASSA (destination) && p->prefixlen == 8)
15827 || p->u.prefix4.s_addr == 0)
15828 {
15829 /* Natural mask is not display. */
15830 }
15831 else
15832 vty_out (vty, " mask %s", inet_ntoa (netmask));
15833 }
15834 else
15835 {
15836 vty_out (vty, " network %s/%d",
15837 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
15838 p->prefixlen);
15839 }
15840
15841 if (bgp_static->rmap.name)
15842 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000015843 else
15844 {
15845 if (bgp_static->backdoor)
15846 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000015847 }
paul718e3742002-12-13 20:15:29 +000015848
15849 vty_out (vty, "%s", VTY_NEWLINE);
15850 }
15851
15852 /* Aggregate-address configuration. */
15853 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
15854 if ((bgp_aggregate = rn->info) != NULL)
15855 {
15856 p = &rn->p;
15857
15858 /* "address-family" display. */
15859 bgp_config_write_family_header (vty, afi, safi, write);
15860
15861 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
15862 {
15863 struct in_addr netmask;
15864
15865 masklen2ip (p->prefixlen, &netmask);
15866 vty_out (vty, " aggregate-address %s %s",
15867 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
15868 inet_ntoa (netmask));
15869 }
15870 else
15871 {
15872 vty_out (vty, " aggregate-address %s/%d",
15873 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
15874 p->prefixlen);
15875 }
15876
15877 if (bgp_aggregate->as_set)
15878 vty_out (vty, " as-set");
15879
15880 if (bgp_aggregate->summary_only)
15881 vty_out (vty, " summary-only");
15882
15883 vty_out (vty, "%s", VTY_NEWLINE);
15884 }
15885
15886 return 0;
15887}
15888
15889int
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015890bgp_config_write_distance (struct vty *vty, struct bgp *bgp,
15891 afi_t afi, safi_t safi, int *write)
paul718e3742002-12-13 20:15:29 +000015892{
15893 struct bgp_node *rn;
15894 struct bgp_distance *bdistance;
15895
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015896 if (afi == AFI_IP && safi == SAFI_UNICAST)
15897 {
15898 /* Distance configuration. */
15899 if (bgp->distance_ebgp
15900 && bgp->distance_ibgp
15901 && bgp->distance_local
15902 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
15903 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
15904 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
15905 vty_out (vty, " distance bgp %d %d %d%s",
15906 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
15907 VTY_NEWLINE);
15908
15909 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
15910 if ((bdistance = rn->info) != NULL)
15911 {
15912 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
15913 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
15914 bdistance->access_list ? bdistance->access_list : "",
15915 VTY_NEWLINE);
15916 }
15917 }
15918
15919#ifdef HAVE_IPV6
15920 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
15921 {
15922 bgp_config_write_family_header (vty, afi, safi, write);
15923 if (bgp->ipv6_distance_ebgp
15924 && bgp->ipv6_distance_ibgp
15925 && bgp->ipv6_distance_local
15926 && (bgp->ipv6_distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
15927 || bgp->ipv6_distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
15928 || bgp->ipv6_distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
15929 vty_out (vty, " distance bgp %d %d %d%s",
15930 bgp->ipv6_distance_ebgp, bgp->ipv6_distance_ibgp, bgp->ipv6_distance_local,
15931 VTY_NEWLINE);
15932
15933 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
15934 if ((bdistance = rn->info) != NULL)
15935 {
15936 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
15937 inet6_ntoa (rn->p.u.prefix6), rn->p.prefixlen,
15938 bdistance->access_list ? bdistance->access_list : "",
15939 VTY_NEWLINE);
15940 }
15941 }
15942#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +000015943
15944 return 0;
15945}
15946
15947/* Allocate routing table structure and install commands. */
15948void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080015949bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000015950{
15951 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000015952 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000015953
15954 /* IPv4 BGP commands. */
15955 install_element (BGP_NODE, &bgp_network_cmd);
15956 install_element (BGP_NODE, &bgp_network_mask_cmd);
15957 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
15958 install_element (BGP_NODE, &bgp_network_route_map_cmd);
15959 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
15960 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
15961 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
15962 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
15963 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
15964 install_element (BGP_NODE, &no_bgp_network_cmd);
15965 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
15966 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
15967 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
15968 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
15969 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
15970 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
15971 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
15972 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
15973
15974 install_element (BGP_NODE, &aggregate_address_cmd);
15975 install_element (BGP_NODE, &aggregate_address_mask_cmd);
15976 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
15977 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
15978 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
15979 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
15980 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
15981 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
15982 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
15983 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
15984 install_element (BGP_NODE, &no_aggregate_address_cmd);
15985 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
15986 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
15987 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
15988 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
15989 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
15990 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
15991 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
15992 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
15993 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
15994
15995 /* IPv4 unicast configuration. */
15996 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
15997 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
15998 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
15999 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
16000 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
16001 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016002 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000016003 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
16004 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
16005 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
16006 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
16007 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016008
paul718e3742002-12-13 20:15:29 +000016009 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
16010 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
16011 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
16012 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
16013 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
16014 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
16015 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
16016 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
16017 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
16018 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
16019 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
16020 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
16021 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
16022 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
16023 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
16024 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
16025 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
16026 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
16027 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
16028 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
16029
16030 /* IPv4 multicast configuration. */
16031 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
16032 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
16033 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
16034 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
16035 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
16036 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
16037 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
16038 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
16039 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
16040 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
16041 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
16042 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
16043 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
16044 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
16045 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
16046 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
16047 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
16048 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
16049 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
16050 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
16051 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
16052 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
16053 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
16054 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
16055 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
16056 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
16057 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
16058 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
16059 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
16060 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
16061 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
16062 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
16063
Michael Lambert95cbbd22010-07-23 14:43:04 -040016064 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016065 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016066 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_route_cmd);
16067 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_route_cmd);
16068 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
16069 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
16070 install_element (VIEW_NODE, &show_bgp_ipv4_encap_route_cmd);
16071 install_element (VIEW_NODE, &show_bgp_ipv6_encap_route_cmd);
16072 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
16073 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
16074 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016075 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016076 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
16077 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
16078 install_element (VIEW_NODE, &show_bgp_ipv4_encap_prefix_cmd);
16079 install_element (VIEW_NODE, &show_bgp_ipv6_encap_prefix_cmd);
16080 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
16081 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
16082 install_element (VIEW_NODE, &show_bgp_afi_safi_view_cmd);
16083 install_element (VIEW_NODE, &show_bgp_view_afi_safi_route_cmd);
16084 install_element (VIEW_NODE, &show_bgp_view_afi_safi_prefix_cmd);
16085 install_element (VIEW_NODE, &show_bgp_ipv4_safi_regexp_cmd);
16086 install_element (VIEW_NODE, &show_bgp_ipv6_safi_regexp_cmd);
16087 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_list_cmd);
16088 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_list_cmd);
16089 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_list_cmd);
16090 install_element (VIEW_NODE, &show_bgp_ipv4_filter_list_cmd);
16091 install_element (VIEW_NODE, &show_bgp_ipv4_safi_filter_list_cmd);
16092 install_element (VIEW_NODE, &show_bgp_ipv6_safi_filter_list_cmd);
16093 install_element (VIEW_NODE, &show_bgp_ipv4_route_map_cmd);
16094 install_element (VIEW_NODE, &show_bgp_ipv4_cidr_only_cmd);
16095 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cidr_only_cmd);
16096 install_element (VIEW_NODE, &show_bgp_ipv4_community_cmd);
16097 install_element (VIEW_NODE, &show_bgp_ipv4_community2_cmd);
16098 install_element (VIEW_NODE, &show_bgp_ipv4_community3_cmd);
16099 install_element (VIEW_NODE, &show_bgp_ipv4_community4_cmd);
16100 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_cmd);
16101 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community2_cmd);
16102 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community3_cmd);
16103 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016104 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
16105 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
16106 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
16107 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
16108 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016109 install_element (VIEW_NODE, &show_bgp_ipv4_community_exact_cmd);
16110 install_element (VIEW_NODE, &show_bgp_ipv4_community2_exact_cmd);
16111 install_element (VIEW_NODE, &show_bgp_ipv4_community3_exact_cmd);
16112 install_element (VIEW_NODE, &show_bgp_ipv4_community4_exact_cmd);
16113 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
16114 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
16115 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
16116 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
16117 install_element (VIEW_NODE, &show_bgp_ipv4_community_list_cmd);
16118 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_list_cmd);
16119 install_element (VIEW_NODE, &show_bgp_ipv4_community_list_exact_cmd);
16120 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_list_exact_cmd);
16121 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_longer_cmd);
16122 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_longer_cmd);
16123 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_longer_cmd);
16124 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_advertised_route_cmd);
16125 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_advertised_route_cmd);
16126 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_received_routes_cmd);
16127 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016128 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016129 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_routes_cmd);
16130 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_routes_cmd);
16131 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd);
16132 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd);
16133 install_element (VIEW_NODE, &show_bgp_ipv4_safi_dampened_paths_cmd);
16134 install_element (VIEW_NODE, &show_bgp_ipv6_safi_dampened_paths_cmd);
16135 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_dampened_paths_cmd);
16136 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_dampened_paths_cmd);
16137 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_statistics_cmd);
16138 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_statistics_cmd);
16139 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_statistics_cmd);
16140 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_statistics_cmd);
16141 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_address_cmd);
16142 install_element (VIEW_NODE, &show_bgp_ipv6_flap_address_cmd);
16143 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_address_cmd);
16144 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_cmd);
16145 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_cmd);
16146 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_cmd);
16147 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_cmd);
16148 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_cidr_only_cmd);
16149 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_cidr_only_cmd);
16150 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_regexp_cmd);
16151 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_regexp_cmd);
16152 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_regexp_cmd);
16153 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_regexp_cmd);
16154 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_filter_list_cmd);
16155 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_filter_list_cmd);
16156 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_filter_list_cmd);
16157 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_filter_list_cmd);
16158 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_list_cmd);
16159 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_list_cmd);
16160 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_list_cmd);
16161 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_list_cmd);
16162 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_longer_cmd);
16163 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_longer_cmd);
16164 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd);
16165 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd);
16166 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_route_map_cmd);
16167 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_route_map_cmd);
16168 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_route_map_cmd);
16169 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_route_map_cmd);
16170 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_flap_cmd);
16171 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_flap_cmd);
16172 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_damp_cmd);
16173 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_damp_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016174 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016175 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016176 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016177 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016178 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016179 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016180
16181 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
Michael Lambert95cbbd22010-07-23 14:43:04 -040016182 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016183 install_element (RESTRICTED_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
16184 install_element (RESTRICTED_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
16185 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
16186 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
16187 install_element (RESTRICTED_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016188 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016189 install_element (RESTRICTED_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
16190 install_element (RESTRICTED_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
16191 install_element (RESTRICTED_NODE, &show_bgp_ipv4_encap_prefix_cmd);
16192 install_element (RESTRICTED_NODE, &show_bgp_ipv6_encap_prefix_cmd);
16193 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
16194 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
16195 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_route_cmd);
16196 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_prefix_cmd);
16197 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community_cmd);
16198 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community2_cmd);
16199 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community3_cmd);
16200 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community4_cmd);
16201 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community_cmd);
16202 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community2_cmd);
16203 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community3_cmd);
16204 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016205 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
16206 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
16207 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
16208 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
16209 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016210 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community_exact_cmd);
16211 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community2_exact_cmd);
16212 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community3_exact_cmd);
16213 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community4_exact_cmd);
16214 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
16215 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
16216 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
16217 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016218 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016219 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016220 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016221 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016222
Donald Sharp68b45cc2016-03-11 14:27:13 -050016223 /* BGP dampening clear commands */
paul718e3742002-12-13 20:15:29 +000016224 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
16225 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
16226 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
16227 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
16228
paul718e3742002-12-13 20:15:29 +000016229 /* New config IPv6 BGP commands. */
16230 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
16231 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
16232 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
16233 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
16234
16235 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
16236 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
16237 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
16238 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
16239
G.Balaji73bfe0b2011-09-23 22:36:20 +053016240 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
16241 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
16242
paul718e3742002-12-13 20:15:29 +000016243 /* Old config IPv6 BGP commands. */
16244 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
16245 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
16246
16247 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
16248 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
16249 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
16250 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
16251
Michael Lambert95cbbd22010-07-23 14:43:04 -040016252 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000016253 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016254 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000016255 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016256 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016257 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
paul718e3742002-12-13 20:15:29 +000016258 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000016259 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000016260 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016261 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_cmd);
16262 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community2_cmd);
16263 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community3_cmd);
16264 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community4_cmd);
16265 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_exact_cmd);
16266 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community2_exact_cmd);
16267 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community3_exact_cmd);
16268 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community4_exact_cmd);
paul718e3742002-12-13 20:15:29 +000016269 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
paul718e3742002-12-13 20:15:29 +000016270 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000016271 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
paul718e3742002-12-13 20:15:29 +000016272 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
paul718e3742002-12-13 20:15:29 +000016273 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
paul718e3742002-12-13 20:15:29 +000016274 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000016275 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000016276 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016277 install_element (VIEW_NODE, &show_bgp_ipv4_rsclient_cmd);
16278 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016279 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016280 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016281 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016282 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016283 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000016284 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
paulbb46e942003-10-24 19:02:03 +000016285 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
paulbb46e942003-10-24 19:02:03 +000016286 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000016287 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
paulbb46e942003-10-24 19:02:03 +000016288 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000016289 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000016290 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000016291 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000016292 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016293 install_element (VIEW_NODE, &show_bgp_view_ipv4_rsclient_cmd);
16294 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016295 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016296 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016297 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016298 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016299 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016300
16301 /* Restricted:
16302 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
16303 */
Paul Jakma62687ff2008-08-23 14:27:06 +010016304 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016305 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016306 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016307 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016308 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community_cmd);
16309 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community2_cmd);
16310 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community3_cmd);
16311 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community4_cmd);
16312 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community_exact_cmd);
16313 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community2_exact_cmd);
16314 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community3_exact_cmd);
16315 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community4_exact_cmd);
16316 install_element (RESTRICTED_NODE, &show_bgp_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016317 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016318 install_element (RESTRICTED_NODE, &show_bgp_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016319 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016320 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016321 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016322 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016323 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016324 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016325 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016326 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016327
Paul Jakma2815e612006-09-14 02:56:07 +000016328 /* Statistics */
16329 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016330 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
paul718e3742002-12-13 20:15:29 +000016331
16332 install_element (BGP_NODE, &bgp_distance_cmd);
16333 install_element (BGP_NODE, &no_bgp_distance_cmd);
16334 install_element (BGP_NODE, &no_bgp_distance2_cmd);
16335 install_element (BGP_NODE, &bgp_distance_source_cmd);
16336 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
16337 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
16338 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
Roman Hoog Antink6184c392014-03-17 14:01:42 +010016339#ifdef HAVE_IPV6
16340 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_cmd);
16341 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_cmd);
16342 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance2_cmd);
16343 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_cmd);
16344 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_cmd);
16345 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_access_list_cmd);
16346 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_access_list_cmd);
16347#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +000016348
16349 install_element (BGP_NODE, &bgp_damp_set_cmd);
16350 install_element (BGP_NODE, &bgp_damp_set2_cmd);
16351 install_element (BGP_NODE, &bgp_damp_set3_cmd);
16352 install_element (BGP_NODE, &bgp_damp_unset_cmd);
16353 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
16354 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
16355 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
16356 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
16357 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
16358 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Balaji9145f0e2016-01-20 22:59:27 +053016359
16360 /* IPv4 Multicast Mode */
16361 install_element (BGP_IPV4M_NODE, &bgp_damp_set_cmd);
16362 install_element (BGP_IPV4M_NODE, &bgp_damp_set2_cmd);
16363 install_element (BGP_IPV4M_NODE, &bgp_damp_set3_cmd);
16364 install_element (BGP_IPV4M_NODE, &bgp_damp_unset_cmd);
16365 install_element (BGP_IPV4M_NODE, &bgp_damp_unset2_cmd);
16366
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016367
16368 /* Deprecated AS-Pathlimit commands */
16369 install_element (BGP_NODE, &bgp_network_ttl_cmd);
16370 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
16371 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
16372 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
16373 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16374 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16375
16376 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
16377 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
16378 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16379 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
16380 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16381 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
16382
16383 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
16384 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
16385 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
16386 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
16387 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16388 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16389
16390 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
16391 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
16392 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16393 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
16394 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16395 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
16396
16397 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
16398 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
16399 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
16400 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
16401 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16402 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16403
16404 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
16405 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
16406 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16407 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
16408 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16409 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000016410
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016411 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
16412 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016413
16414 /* old style commands */
16415 install_element (VIEW_NODE, &show_ip_bgp_cmd);
16416 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
16417 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
16418 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
16419 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
16420 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
16421 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
16422 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
16423 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
16424 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
16425 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
16426 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
16427 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
16428 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
16429 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
16430 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
16431 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
16432 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
16433 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
16434 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
16435 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
16436 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
16437 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
16438 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
16439 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
16440 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
16441 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
16442 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
16443 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
16444 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
16445 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
16446 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
16447 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
16448 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
16449 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
16450 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
16451 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
16452 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
16453 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
16454 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
16455 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
16456 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
16457 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
16458 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
16459 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
16460 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
16461 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
16462 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
16463 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
16464 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
16465 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
16466 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
16467 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
16468 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
16469 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
16470 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
Balaji9c52cae2016-01-20 22:59:26 +053016471 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_parameters_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016472 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji9c52cae2016-01-20 22:59:26 +053016473 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_dampd_paths_cmd);
16474 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_flap_stats_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016475 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
16476 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
16477 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
16478 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
16479 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
16480 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
16481 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
16482 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
16483 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
16484 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
16485 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
16486 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
16487 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
16488 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
16489 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
16490 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
16491 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
16492 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
16493 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
16494 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
16495 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
16496 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
16497 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
16498 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
16499 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
16500 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
16501 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016502
Lou Bergerf9b6c392016-01-12 13:42:09 -050016503 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
16504 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
16505 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
16506 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
16507 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
16508 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
16509 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
16510 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
16511 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
16512 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
16513 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
16514 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
16515 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
16516 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
16517 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
16518 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
16519 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
16520 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
16521 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
16522 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
16523 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
16524 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
16525 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
16526 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
16527 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
16528 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
16529 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
16530 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
16531 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016532
16533 install_element (VIEW_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
16534 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
16535 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016536 install_element (VIEW_NODE, &show_bgp_cmd);
16537 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
16538 install_element (VIEW_NODE, &show_bgp_route_cmd);
16539 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
16540 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
16541 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
16542 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
16543 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
16544 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
16545 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
16546 install_element (VIEW_NODE, &show_bgp_community_cmd);
16547 install_element (VIEW_NODE, &show_bgp_community2_cmd);
16548 install_element (VIEW_NODE, &show_bgp_community3_cmd);
16549 install_element (VIEW_NODE, &show_bgp_community4_cmd);
16550 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
16551 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
16552 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
16553 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
16554 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_list_cmd);
16555 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
16556 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_list_exact_cmd);
16557 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
16558 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
16559 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
16560 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
16561 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
16562 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
16563 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
16564 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
16565 install_element (VIEW_NODE, &show_bgp_view_cmd);
16566 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
16567 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
16568 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
16569 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
16570 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
16571 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
16572 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
16573 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
16574 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016575
Lou Bergerf9b6c392016-01-12 13:42:09 -050016576 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
16577 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
16578 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
16579 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
16580 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
16581 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
16582 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
16583 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
16584 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
16585 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
16586 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
16587 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
16588 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016589
Lou Bergerf9b6c392016-01-12 13:42:09 -050016590 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
16591 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016592
Lou Bergerf9b6c392016-01-12 13:42:09 -050016593 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
16594 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
16595 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
16596 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
16597 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
16598 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
16599 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
16600 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
16601 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
16602 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
16603 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
16604 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
16605 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
16606 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
16607 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
16608 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
16609 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
16610 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
16611 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
16612 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
16613 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
16614 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
16615 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
16616 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
16617 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
16618 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
16619 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
16620 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
16621 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
16622 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
16623 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
16624 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
16625 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
16626 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
16627 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
16628 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016629 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016630 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016631 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016632 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016633 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016634 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016635 /* old with name safi collision */
16636 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
16637 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
16638 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
16639 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
16640 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
16641 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
16642 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
16643 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
16644 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
16645 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
16646 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
16647 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
16648 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
16649 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
16650 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
16651 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016652
Lou Bergerf9b6c392016-01-12 13:42:09 -050016653 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
16654 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016655
16656 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
16657 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
16658 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
16659 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016660
16661 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
16662 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
16663 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
16664 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016665}
Chris Caputo228da422009-07-18 05:44:03 +000016666
16667void
16668bgp_route_finish (void)
16669{
16670 bgp_table_unlock (bgp_distance_table);
16671 bgp_distance_table = NULL;
16672}