blob: 0ea7ced8654a572a4bd72e35117a1c80d39fdd90 [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"
paul718e3742002-12-13 20:15:29 +000058
59/* Extern from bgp_dump.c */
Stephen Hemmingerdde72582009-05-08 15:19:07 -070060extern const char *bgp_origin_str[];
61extern const char *bgp_origin_long_str[];
David Lamparter6b0655a2014-06-04 06:53:35 +020062
paul94f2b392005-06-28 12:44:16 +000063static struct bgp_node *
paulfee0f4c2004-09-13 05:12:46 +000064bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
paul718e3742002-12-13 20:15:29 +000065 struct prefix_rd *prd)
66{
67 struct bgp_node *rn;
68 struct bgp_node *prn = NULL;
Paul Jakmada5b30f2006-05-08 14:37:17 +000069
70 assert (table);
71 if (!table)
72 return NULL;
73
Lou Berger298cc2f2016-01-12 13:42:02 -050074 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000075 {
paulfee0f4c2004-09-13 05:12:46 +000076 prn = bgp_node_get (table, (struct prefix *) prd);
paul718e3742002-12-13 20:15:29 +000077
78 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +000079 prn->info = bgp_table_init (afi, safi);
paul718e3742002-12-13 20:15:29 +000080 else
81 bgp_unlock_node (prn);
82 table = prn->info;
83 }
paul718e3742002-12-13 20:15:29 +000084
85 rn = bgp_node_get (table, p);
86
Lou Berger298cc2f2016-01-12 13:42:02 -050087 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000088 rn->prn = prn;
89
90 return rn;
91}
David Lamparter6b0655a2014-06-04 06:53:35 +020092
Paul Jakmafb982c22007-05-04 20:15:47 +000093/* Allocate bgp_info_extra */
94static struct bgp_info_extra *
95bgp_info_extra_new (void)
96{
97 struct bgp_info_extra *new;
98 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
99 return new;
100}
101
102static void
103bgp_info_extra_free (struct bgp_info_extra **extra)
104{
105 if (extra && *extra)
106 {
107 if ((*extra)->damp_info)
108 bgp_damp_info_free ((*extra)->damp_info, 0);
109
110 (*extra)->damp_info = NULL;
111
112 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
113
114 *extra = NULL;
115 }
116}
117
118/* Get bgp_info extra information for the given bgp_info, lazy allocated
119 * if required.
120 */
121struct bgp_info_extra *
122bgp_info_extra_get (struct bgp_info *ri)
123{
124 if (!ri->extra)
125 ri->extra = bgp_info_extra_new();
126 return ri->extra;
127}
128
paul718e3742002-12-13 20:15:29 +0000129/* Allocate new bgp info structure. */
paul200df112005-06-01 11:17:05 +0000130static struct bgp_info *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -0800131bgp_info_new (void)
paul718e3742002-12-13 20:15:29 +0000132{
Stephen Hemminger393deb92008-08-18 14:13:29 -0700133 return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
paul718e3742002-12-13 20:15:29 +0000134}
135
136/* Free bgp route information. */
paul200df112005-06-01 11:17:05 +0000137static void
paul718e3742002-12-13 20:15:29 +0000138bgp_info_free (struct bgp_info *binfo)
139{
140 if (binfo->attr)
Paul Jakmaf6f434b2010-11-23 21:28:03 +0000141 bgp_attr_unintern (&binfo->attr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000142
143 bgp_info_extra_free (&binfo->extra);
Josh Baileyde8d5df2011-07-20 20:46:01 -0700144 bgp_info_mpath_free (&binfo->mpath);
paul718e3742002-12-13 20:15:29 +0000145
paul200df112005-06-01 11:17:05 +0000146 peer_unlock (binfo->peer); /* bgp_info peer reference */
147
paul718e3742002-12-13 20:15:29 +0000148 XFREE (MTYPE_BGP_ROUTE, binfo);
149}
150
paul200df112005-06-01 11:17:05 +0000151struct bgp_info *
152bgp_info_lock (struct bgp_info *binfo)
153{
154 binfo->lock++;
155 return binfo;
156}
157
158struct bgp_info *
159bgp_info_unlock (struct bgp_info *binfo)
160{
161 assert (binfo && binfo->lock > 0);
162 binfo->lock--;
163
164 if (binfo->lock == 0)
165 {
166#if 0
167 zlog_debug ("%s: unlocked and freeing", __func__);
168 zlog_backtrace (LOG_DEBUG);
169#endif
170 bgp_info_free (binfo);
171 return NULL;
172 }
173
174#if 0
175 if (binfo->lock == 1)
176 {
177 zlog_debug ("%s: unlocked to 1", __func__);
178 zlog_backtrace (LOG_DEBUG);
179 }
180#endif
181
182 return binfo;
183}
184
paul718e3742002-12-13 20:15:29 +0000185void
186bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
187{
188 struct bgp_info *top;
189
190 top = rn->info;
paul200df112005-06-01 11:17:05 +0000191
paul718e3742002-12-13 20:15:29 +0000192 ri->next = rn->info;
193 ri->prev = NULL;
194 if (top)
195 top->prev = ri;
196 rn->info = ri;
paul200df112005-06-01 11:17:05 +0000197
198 bgp_info_lock (ri);
199 bgp_lock_node (rn);
200 peer_lock (ri->peer); /* bgp_info peer reference */
paul718e3742002-12-13 20:15:29 +0000201}
202
paulb40d9392005-08-22 22:34:41 +0000203/* Do the actual removal of info from RIB, for use by bgp_process
204 completion callback *only* */
205static void
206bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
paul718e3742002-12-13 20:15:29 +0000207{
208 if (ri->next)
209 ri->next->prev = ri->prev;
210 if (ri->prev)
211 ri->prev->next = ri->next;
212 else
213 rn->info = ri->next;
paul200df112005-06-01 11:17:05 +0000214
Josh Baileyde8d5df2011-07-20 20:46:01 -0700215 bgp_info_mpath_dequeue (ri);
paul200df112005-06-01 11:17:05 +0000216 bgp_info_unlock (ri);
217 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000218}
219
paulb40d9392005-08-22 22:34:41 +0000220void
221bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
222{
Paul Jakma1a392d42006-09-07 00:24:49 +0000223 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
224 /* set of previous already took care of pcount */
paulb40d9392005-08-22 22:34:41 +0000225 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
226}
227
Andrew J. Schorr8d452102006-11-28 19:50:46 +0000228/* undo the effects of a previous call to bgp_info_delete; typically
229 called when a route is deleted and then quickly re-added before the
230 deletion has been processed */
231static void
232bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
233{
234 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
235 /* unset of previous already took care of pcount */
236 SET_FLAG (ri->flags, BGP_INFO_VALID);
237}
238
Paul Jakma1a392d42006-09-07 00:24:49 +0000239/* Adjust pcount as required */
240static void
241bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
242{
Avneesh Sachdev67174042012-08-17 08:19:49 -0700243 struct bgp_table *table;
244
245 assert (rn && bgp_node_table (rn));
Paul Jakma6f585442006-10-22 19:13:07 +0000246 assert (ri && ri->peer && ri->peer->bgp);
247
Avneesh Sachdev67174042012-08-17 08:19:49 -0700248 table = bgp_node_table (rn);
249
Paul Jakma1a392d42006-09-07 00:24:49 +0000250 /* Ignore 'pcount' for RS-client tables */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700251 if (table->type != BGP_TABLE_MAIN
Paul Jakma1a392d42006-09-07 00:24:49 +0000252 || ri->peer == ri->peer->bgp->peer_self)
253 return;
254
255 if (BGP_INFO_HOLDDOWN (ri)
256 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
257 {
258
259 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
260
261 /* slight hack, but more robust against errors. */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700262 if (ri->peer->pcount[table->afi][table->safi])
263 ri->peer->pcount[table->afi][table->safi]--;
Paul Jakma1a392d42006-09-07 00:24:49 +0000264 else
265 {
266 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
267 __func__, ri->peer->host);
268 zlog_backtrace (LOG_WARNING);
269 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
270 }
271 }
272 else if (!BGP_INFO_HOLDDOWN (ri)
273 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
274 {
275 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
Avneesh Sachdev67174042012-08-17 08:19:49 -0700276 ri->peer->pcount[table->afi][table->safi]++;
Paul Jakma1a392d42006-09-07 00:24:49 +0000277 }
278}
279
280
281/* Set/unset bgp_info flags, adjusting any other state as needed.
282 * This is here primarily to keep prefix-count in check.
283 */
284void
285bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
286{
287 SET_FLAG (ri->flags, flag);
288
289 /* early bath if we know it's not a flag that changes useability state */
290 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
291 return;
292
293 bgp_pcount_adjust (rn, ri);
294}
295
296void
297bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
298{
299 UNSET_FLAG (ri->flags, flag);
300
301 /* early bath if we know it's not a flag that changes useability state */
302 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
303 return;
304
305 bgp_pcount_adjust (rn, ri);
306}
307
paul718e3742002-12-13 20:15:29 +0000308/* Get MED value. If MED value is missing and "bgp bestpath
309 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000310static u_int32_t
paul718e3742002-12-13 20:15:29 +0000311bgp_med_value (struct attr *attr, struct bgp *bgp)
312{
313 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
314 return attr->med;
315 else
316 {
317 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000318 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000319 else
320 return 0;
321 }
322}
323
Paul Jakma6d4742b2015-11-25 17:14:37 +0000324/* Compare two bgp route entity. Return -1 if new is preferred, 1 if exist
325 * is preferred, or 0 if they are the same (usually will only occur if
326 * multipath is enabled */
paul94f2b392005-06-28 12:44:16 +0000327static int
Josh Bailey96450fa2011-07-20 20:45:12 -0700328bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
Paul Jakma6d4742b2015-11-25 17:14:37 +0000329 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +0000330{
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000331 struct attr *newattr, *existattr;
332 struct attr_extra *newattre, *existattre;
333 bgp_peer_sort_t new_sort;
334 bgp_peer_sort_t exist_sort;
paul718e3742002-12-13 20:15:29 +0000335 u_int32_t new_pref;
336 u_int32_t exist_pref;
337 u_int32_t new_med;
338 u_int32_t exist_med;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000339 u_int32_t new_weight;
340 u_int32_t exist_weight;
341 uint32_t newm, existm;
paul718e3742002-12-13 20:15:29 +0000342 struct in_addr new_id;
343 struct in_addr exist_id;
344 int new_cluster;
345 int exist_cluster;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000346 int internal_as_route;
347 int confed_as_route;
paul718e3742002-12-13 20:15:29 +0000348 int ret;
Josh Bailey96450fa2011-07-20 20:45:12 -0700349
paul718e3742002-12-13 20:15:29 +0000350 /* 0. Null check. */
351 if (new == NULL)
paul718e3742002-12-13 20:15:29 +0000352 return 1;
Paul Jakma6d4742b2015-11-25 17:14:37 +0000353 if (exist == NULL)
354 return -1;
paul718e3742002-12-13 20:15:29 +0000355
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000356 newattr = new->attr;
357 existattr = exist->attr;
358 newattre = newattr->extra;
359 existattre = existattr->extra;
360
paul718e3742002-12-13 20:15:29 +0000361 /* 1. Weight check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000362 new_weight = exist_weight = 0;
363
364 if (newattre)
365 new_weight = newattre->weight;
366 if (existattre)
367 exist_weight = existattre->weight;
368
Paul Jakmafb982c22007-05-04 20:15:47 +0000369 if (new_weight > exist_weight)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000370 return -1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000371 if (new_weight < exist_weight)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000372 return 1;
paul718e3742002-12-13 20:15:29 +0000373
374 /* 2. Local preference check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000375 new_pref = exist_pref = bgp->default_local_pref;
paul718e3742002-12-13 20:15:29 +0000376
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000377 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
378 new_pref = newattr->local_pref;
379 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
380 exist_pref = existattr->local_pref;
381
paul718e3742002-12-13 20:15:29 +0000382 if (new_pref > exist_pref)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000383 return -1;
paul718e3742002-12-13 20:15:29 +0000384 if (new_pref < exist_pref)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000385 return 1;
paul718e3742002-12-13 20:15:29 +0000386
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000387 /* 3. Local route check. We prefer:
388 * - BGP_ROUTE_STATIC
389 * - BGP_ROUTE_AGGREGATE
390 * - BGP_ROUTE_REDISTRIBUTE
391 */
392 if (! (new->sub_type == BGP_ROUTE_NORMAL))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000393 return -1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000394 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000395 return 1;
paul718e3742002-12-13 20:15:29 +0000396
397 /* 4. AS path length check. */
398 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
399 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000400 int exist_hops = aspath_count_hops (existattr->aspath);
401 int exist_confeds = aspath_count_confeds (existattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000402
hasso68118452005-04-08 15:40:36 +0000403 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
404 {
paulfe69a502005-09-10 16:55:02 +0000405 int aspath_hops;
406
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000407 aspath_hops = aspath_count_hops (newattr->aspath);
408 aspath_hops += aspath_count_confeds (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000409
410 if ( aspath_hops < (exist_hops + exist_confeds))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000411 return -1;
paulfe69a502005-09-10 16:55:02 +0000412 if ( aspath_hops > (exist_hops + exist_confeds))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000413 return 1;
hasso68118452005-04-08 15:40:36 +0000414 }
415 else
416 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000417 int newhops = aspath_count_hops (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000418
419 if (newhops < exist_hops)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000420 return -1;
paulfe69a502005-09-10 16:55:02 +0000421 if (newhops > exist_hops)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000422 return 1;
hasso68118452005-04-08 15:40:36 +0000423 }
paul718e3742002-12-13 20:15:29 +0000424 }
425
426 /* 5. Origin check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000427 if (newattr->origin < existattr->origin)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000428 return -1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000429 if (newattr->origin > existattr->origin)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000430 return 1;
paul718e3742002-12-13 20:15:29 +0000431
432 /* 6. MED check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000433 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
434 && aspath_count_hops (existattr->aspath) == 0);
435 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
436 && aspath_count_confeds (existattr->aspath) > 0
437 && aspath_count_hops (newattr->aspath) == 0
438 && aspath_count_hops (existattr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000439
440 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
441 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
442 && confed_as_route)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000443 || aspath_cmp_left (newattr->aspath, existattr->aspath)
444 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
paul718e3742002-12-13 20:15:29 +0000445 || internal_as_route)
446 {
447 new_med = bgp_med_value (new->attr, bgp);
448 exist_med = bgp_med_value (exist->attr, bgp);
449
450 if (new_med < exist_med)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000451 return -1;
paul718e3742002-12-13 20:15:29 +0000452 if (new_med > exist_med)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000453 return 1;
paul718e3742002-12-13 20:15:29 +0000454 }
455
456 /* 7. Peer type check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000457 new_sort = new->peer->sort;
458 exist_sort = exist->peer->sort;
459
460 if (new_sort == BGP_PEER_EBGP
461 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000462 return -1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000463 if (exist_sort == BGP_PEER_EBGP
464 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000465 return 1;
paul718e3742002-12-13 20:15:29 +0000466
467 /* 8. IGP metric check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000468 newm = existm = 0;
469
470 if (new->extra)
471 newm = new->extra->igpmetric;
472 if (exist->extra)
473 existm = exist->extra->igpmetric;
474
Josh Bailey96450fa2011-07-20 20:45:12 -0700475 if (newm < existm)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000476 return -1;
Josh Bailey96450fa2011-07-20 20:45:12 -0700477 if (newm > existm)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000478 return 1;
paul718e3742002-12-13 20:15:29 +0000479
480 /* 9. Maximum path check. */
Paul Jakma6d4742b2015-11-25 17:14:37 +0000481 if (bgp_mpath_is_configured (bgp, afi, safi))
Josh Bailey96450fa2011-07-20 20:45:12 -0700482 {
Pradosh Mohapatra2fdd4552013-09-07 07:02:36 +0000483 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
484 {
Paul Jakma6d4742b2015-11-25 17:14:37 +0000485 /*
486 * For the two paths, all comparison steps till IGP metric
487 * have succeeded - including AS_PATH hop count. Since 'bgp
488 * bestpath as-path multipath-relax' knob is on, we don't need
489 * an exact match of AS_PATH. Thus, mark the paths are equal.
490 * That will trigger both these paths to get into the multipath
491 * array.
492 */
493 return 0;
Pradosh Mohapatra2fdd4552013-09-07 07:02:36 +0000494 }
495 else if (new->peer->sort == BGP_PEER_IBGP)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000496 {
497 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
498 return 0;
499 }
Josh Bailey96450fa2011-07-20 20:45:12 -0700500 else if (new->peer->as == exist->peer->as)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000501 return 0;
Josh Bailey96450fa2011-07-20 20:45:12 -0700502 }
paul718e3742002-12-13 20:15:29 +0000503
504 /* 10. If both paths are external, prefer the path that was received
505 first (the oldest one). This step minimizes route-flap, since a
506 newer path won't displace an older one, even if it was the
507 preferred route based on the additional decision criteria below. */
508 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000509 && new_sort == BGP_PEER_EBGP
510 && exist_sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +0000511 {
512 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000513 return -1;
paul718e3742002-12-13 20:15:29 +0000514 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000515 return 1;
paul718e3742002-12-13 20:15:29 +0000516 }
517
vivekbd4b7f12014-09-30 15:54:45 -0700518 /* 11. Router-ID comparision. */
519 /* If one of the paths is "stale", the corresponding peer router-id will
520 * be 0 and would always win over the other path. If originator id is
521 * used for the comparision, it will decide which path is better.
522 */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000523 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
524 new_id.s_addr = newattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000525 else
526 new_id.s_addr = new->peer->remote_id.s_addr;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000527 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
528 exist_id.s_addr = existattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000529 else
530 exist_id.s_addr = exist->peer->remote_id.s_addr;
531
532 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000533 return -1;
paul718e3742002-12-13 20:15:29 +0000534 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000535 return 1;
paul718e3742002-12-13 20:15:29 +0000536
537 /* 12. Cluster length comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000538 new_cluster = exist_cluster = 0;
539
540 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
541 new_cluster = newattre->cluster->length;
542 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
543 exist_cluster = existattre->cluster->length;
paul718e3742002-12-13 20:15:29 +0000544
545 if (new_cluster < exist_cluster)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000546 return -1;
paul718e3742002-12-13 20:15:29 +0000547 if (new_cluster > exist_cluster)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000548 return 1;
paul718e3742002-12-13 20:15:29 +0000549
550 /* 13. Neighbor address comparision. */
vivekbd4b7f12014-09-30 15:54:45 -0700551 /* Do this only if neither path is "stale" as stale paths do not have
552 * valid peer information (as the connection may or may not be up).
553 */
554 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000555 return -1;
vivekbd4b7f12014-09-30 15:54:45 -0700556 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000557 return 1;
Timo Teräs2820a012015-06-24 15:27:21 +0300558 /* locally configured routes to advertise do not have su_remote */
559 if (new->peer->su_remote == NULL)
Timo Teräs2820a012015-06-24 15:27:21 +0300560 return 1;
Paul Jakma6d4742b2015-11-25 17:14:37 +0000561 if (exist->peer->su_remote == NULL)
562 return -1;
Timo Teräs2820a012015-06-24 15:27:21 +0300563
paul718e3742002-12-13 20:15:29 +0000564 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
565
566 if (ret == 1)
paul718e3742002-12-13 20:15:29 +0000567 return 1;
Paul Jakma6d4742b2015-11-25 17:14:37 +0000568 if (ret == -1)
569 return -1;
paul718e3742002-12-13 20:15:29 +0000570
Paul Jakma6d4742b2015-11-25 17:14:37 +0000571 return -1;
paul718e3742002-12-13 20:15:29 +0000572}
573
paul94f2b392005-06-28 12:44:16 +0000574static enum filter_type
paul718e3742002-12-13 20:15:29 +0000575bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
576 afi_t afi, safi_t safi)
577{
578 struct bgp_filter *filter;
579
580 filter = &peer->filter[afi][safi];
581
Paul Jakma650f76c2009-06-25 18:06:31 +0100582#define FILTER_EXIST_WARN(F,f,filter) \
583 if (BGP_DEBUG (update, UPDATE_IN) \
584 && !(F ## _IN (filter))) \
585 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
586 peer->host, #f, F ## _IN_NAME(filter));
587
588 if (DISTRIBUTE_IN_NAME (filter)) {
589 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
590
paul718e3742002-12-13 20:15:29 +0000591 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
592 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100593 }
paul718e3742002-12-13 20:15:29 +0000594
Paul Jakma650f76c2009-06-25 18:06:31 +0100595 if (PREFIX_LIST_IN_NAME (filter)) {
596 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
597
paul718e3742002-12-13 20:15:29 +0000598 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
599 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100600 }
paul718e3742002-12-13 20:15:29 +0000601
Paul Jakma650f76c2009-06-25 18:06:31 +0100602 if (FILTER_LIST_IN_NAME (filter)) {
603 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
604
paul718e3742002-12-13 20:15:29 +0000605 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
606 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100607 }
608
paul718e3742002-12-13 20:15:29 +0000609 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100610#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000611}
612
paul94f2b392005-06-28 12:44:16 +0000613static enum filter_type
paul718e3742002-12-13 20:15:29 +0000614bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
615 afi_t afi, safi_t safi)
616{
617 struct bgp_filter *filter;
618
619 filter = &peer->filter[afi][safi];
620
Paul Jakma650f76c2009-06-25 18:06:31 +0100621#define FILTER_EXIST_WARN(F,f,filter) \
622 if (BGP_DEBUG (update, UPDATE_OUT) \
623 && !(F ## _OUT (filter))) \
624 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
625 peer->host, #f, F ## _OUT_NAME(filter));
626
627 if (DISTRIBUTE_OUT_NAME (filter)) {
628 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
629
paul718e3742002-12-13 20:15:29 +0000630 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
631 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100632 }
paul718e3742002-12-13 20:15:29 +0000633
Paul Jakma650f76c2009-06-25 18:06:31 +0100634 if (PREFIX_LIST_OUT_NAME (filter)) {
635 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
636
paul718e3742002-12-13 20:15:29 +0000637 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
638 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100639 }
paul718e3742002-12-13 20:15:29 +0000640
Paul Jakma650f76c2009-06-25 18:06:31 +0100641 if (FILTER_LIST_OUT_NAME (filter)) {
642 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
643
paul718e3742002-12-13 20:15:29 +0000644 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
645 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100646 }
paul718e3742002-12-13 20:15:29 +0000647
648 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100649#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000650}
651
652/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000653static int
paul718e3742002-12-13 20:15:29 +0000654bgp_community_filter (struct peer *peer, struct attr *attr)
655{
656 if (attr->community)
657 {
658 /* NO_ADVERTISE check. */
659 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
660 return 1;
661
662 /* NO_EXPORT check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000663 if (peer->sort == BGP_PEER_EBGP &&
paul718e3742002-12-13 20:15:29 +0000664 community_include (attr->community, COMMUNITY_NO_EXPORT))
665 return 1;
666
667 /* NO_EXPORT_SUBCONFED check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000668 if (peer->sort == BGP_PEER_EBGP
669 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000670 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
671 return 1;
672 }
673 return 0;
674}
675
676/* Route reflection loop check. */
677static int
678bgp_cluster_filter (struct peer *peer, struct attr *attr)
679{
680 struct in_addr cluster_id;
681
Paul Jakmafb982c22007-05-04 20:15:47 +0000682 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000683 {
684 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
685 cluster_id = peer->bgp->cluster_id;
686 else
687 cluster_id = peer->bgp->router_id;
688
Paul Jakmafb982c22007-05-04 20:15:47 +0000689 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000690 return 1;
691 }
692 return 0;
693}
David Lamparter6b0655a2014-06-04 06:53:35 +0200694
paul94f2b392005-06-28 12:44:16 +0000695static int
paul718e3742002-12-13 20:15:29 +0000696bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
697 afi_t afi, safi_t safi)
698{
699 struct bgp_filter *filter;
700 struct bgp_info info;
701 route_map_result_t ret;
702
703 filter = &peer->filter[afi][safi];
704
705 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000706 if (peer->weight)
707 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000708
709 /* Route map apply. */
710 if (ROUTE_MAP_IN_NAME (filter))
711 {
712 /* Duplicate current value to new strucutre for modification. */
713 info.peer = peer;
714 info.attr = attr;
715
paulac41b2a2003-08-12 05:32:27 +0000716 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
717
paul718e3742002-12-13 20:15:29 +0000718 /* Apply BGP route map to the attribute. */
719 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000720
721 peer->rmap_type = 0;
722
paul718e3742002-12-13 20:15:29 +0000723 if (ret == RMAP_DENYMATCH)
David Lamparterc460e572014-06-04 00:54:58 +0200724 /* caller has multiple error paths with bgp_attr_flush() */
725 return RMAP_DENY;
paul718e3742002-12-13 20:15:29 +0000726 }
727 return RMAP_PERMIT;
728}
David Lamparter6b0655a2014-06-04 06:53:35 +0200729
paul94f2b392005-06-28 12:44:16 +0000730static int
paulfee0f4c2004-09-13 05:12:46 +0000731bgp_export_modifier (struct peer *rsclient, struct peer *peer,
732 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
733{
734 struct bgp_filter *filter;
735 struct bgp_info info;
736 route_map_result_t ret;
737
738 filter = &peer->filter[afi][safi];
739
740 /* Route map apply. */
741 if (ROUTE_MAP_EXPORT_NAME (filter))
742 {
743 /* Duplicate current value to new strucutre for modification. */
744 info.peer = rsclient;
745 info.attr = attr;
746
747 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
748
749 /* Apply BGP route map to the attribute. */
750 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
751
752 rsclient->rmap_type = 0;
753
754 if (ret == RMAP_DENYMATCH)
755 {
756 /* Free newly generated AS path and community by route-map. */
757 bgp_attr_flush (attr);
758 return RMAP_DENY;
759 }
760 }
761 return RMAP_PERMIT;
762}
763
paul94f2b392005-06-28 12:44:16 +0000764static int
paulfee0f4c2004-09-13 05:12:46 +0000765bgp_import_modifier (struct peer *rsclient, struct peer *peer,
766 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
767{
768 struct bgp_filter *filter;
769 struct bgp_info info;
770 route_map_result_t ret;
771
772 filter = &rsclient->filter[afi][safi];
773
774 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000775 if (peer->weight)
776 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000777
778 /* Route map apply. */
779 if (ROUTE_MAP_IMPORT_NAME (filter))
780 {
781 /* Duplicate current value to new strucutre for modification. */
782 info.peer = peer;
783 info.attr = attr;
784
785 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
786
787 /* Apply BGP route map to the attribute. */
788 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
789
790 peer->rmap_type = 0;
791
792 if (ret == RMAP_DENYMATCH)
793 {
794 /* Free newly generated AS path and community by route-map. */
795 bgp_attr_flush (attr);
796 return RMAP_DENY;
797 }
798 }
799 return RMAP_PERMIT;
800}
David Lamparter6b0655a2014-06-04 06:53:35 +0200801
paul94f2b392005-06-28 12:44:16 +0000802static int
paul718e3742002-12-13 20:15:29 +0000803bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
804 struct attr *attr, afi_t afi, safi_t safi)
805{
806 int ret;
807 char buf[SU_ADDRSTRLEN];
808 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000809 struct peer *from;
810 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000811 int transparent;
812 int reflect;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700813 struct attr *riattr;
paul718e3742002-12-13 20:15:29 +0000814
815 from = ri->peer;
816 filter = &peer->filter[afi][safi];
817 bgp = peer->bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700818 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paul718e3742002-12-13 20:15:29 +0000819
Paul Jakma750e8142008-07-22 21:11:48 +0000820 if (DISABLE_BGP_ANNOUNCE)
821 return 0;
paul718e3742002-12-13 20:15:29 +0000822
paulfee0f4c2004-09-13 05:12:46 +0000823 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
824 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
825 return 0;
826
paul718e3742002-12-13 20:15:29 +0000827 /* Do not send back route to sender. */
828 if (from == peer)
829 return 0;
830
831 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000832 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000833 if (! UNSUPPRESS_MAP_NAME (filter))
834 return 0;
835
836 /* Default route check. */
837 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
838 {
839 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
840 return 0;
841#ifdef HAVE_IPV6
842 else if (p->family == AF_INET6 && p->prefixlen == 0)
843 return 0;
844#endif /* HAVE_IPV6 */
845 }
846
paul286e1e72003-08-08 00:24:31 +0000847 /* Transparency check. */
848 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
849 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
850 transparent = 1;
851 else
852 transparent = 0;
853
paul718e3742002-12-13 20:15:29 +0000854 /* If community is not disabled check the no-export and local. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700855 if (! transparent && bgp_community_filter (peer, riattr))
paul718e3742002-12-13 20:15:29 +0000856 return 0;
857
858 /* If the attribute has originator-id and it is same as remote
859 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700860 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paul718e3742002-12-13 20:15:29 +0000861 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700862 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000863 {
864 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000865 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000866 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
867 peer->host,
868 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
869 p->prefixlen);
870 return 0;
871 }
872 }
873
874 /* ORF prefix-list filter check */
875 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
876 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
877 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
878 if (peer->orf_plist[afi][safi])
879 {
880 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
881 return 0;
882 }
883
884 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700885 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
paul718e3742002-12-13 20:15:29 +0000886 {
887 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000888 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000889 "%s [Update:SEND] %s/%d is filtered",
890 peer->host,
891 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
892 p->prefixlen);
893 return 0;
894 }
895
896#ifdef BGP_SEND_ASPATH_CHECK
897 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700898 if (aspath_loop_check (riattr->aspath, peer->as))
paul718e3742002-12-13 20:15:29 +0000899 {
900 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000901 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400902 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000903 peer->host, peer->as);
904 return 0;
905 }
906#endif /* BGP_SEND_ASPATH_CHECK */
907
908 /* If we're a CONFED we need to loop check the CONFED ID too */
909 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
910 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700911 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
paul718e3742002-12-13 20:15:29 +0000912 {
913 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000914 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400915 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000916 peer->host,
917 bgp->confed_id);
918 return 0;
919 }
920 }
921
922 /* Route-Reflect check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000923 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +0000924 reflect = 1;
925 else
926 reflect = 0;
927
928 /* IBGP reflection check. */
929 if (reflect)
930 {
931 /* A route from a Client peer. */
932 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
933 {
934 /* Reflect to all the Non-Client peers and also to the
935 Client peers other than the originator. Originator check
936 is already done. So there is noting to do. */
937 /* no bgp client-to-client reflection check. */
938 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
939 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
940 return 0;
941 }
942 else
943 {
944 /* A route from a Non-client peer. Reflect to all other
945 clients. */
946 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
947 return 0;
948 }
949 }
Paul Jakma41367172007-08-06 15:24:51 +0000950
paul718e3742002-12-13 20:15:29 +0000951 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700952 bgp_attr_dup (attr, riattr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000953
paul718e3742002-12-13 20:15:29 +0000954 /* If local-preference is not set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000955 if ((peer->sort == BGP_PEER_IBGP
956 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000957 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
958 {
959 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
960 attr->local_pref = bgp->default_local_pref;
961 }
962
Pradosh Mohapatra689bb662013-09-07 07:13:37 +0000963 /* If originator-id is not set and the route is to be reflected,
964 set the originator id */
965 if (peer && from && peer->sort == BGP_PEER_IBGP &&
966 from->sort == BGP_PEER_IBGP &&
967 (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
968 {
969 attr->extra = bgp_attr_extra_get(attr);
970 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
971 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
972 }
973
paul718e3742002-12-13 20:15:29 +0000974 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000975 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000976 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
977 {
978 if (ri->peer != bgp->peer_self && ! transparent
979 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
980 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
981 }
982
Lou Berger298cc2f2016-01-12 13:42:02 -0500983
984#define NEXTHOP_IS_V4 (\
985 (safi != SAFI_ENCAP && p->family == AF_INET) || \
986 (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 4))
987
988#ifdef HAVE_IPV6
989#define NEXTHOP_IS_V6 (\
990 (safi != SAFI_ENCAP && p->family == AF_INET6) || \
991 (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 16))
992#endif
993
paul718e3742002-12-13 20:15:29 +0000994 /* next-hop-set */
Timo Teräs9e7a53c2014-04-24 10:22:37 +0300995 if (transparent
996 || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
paul718e3742002-12-13 20:15:29 +0000997 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
Lou Berger298cc2f2016-01-12 13:42:02 -0500998 && ((NEXTHOP_IS_V4 && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000999#ifdef HAVE_IPV6
Lou Berger298cc2f2016-01-12 13:42:02 -05001000 || (NEXTHOP_IS_V6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001001 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +00001002#endif /* HAVE_IPV6 */
1003 )))
paul718e3742002-12-13 20:15:29 +00001004 {
1005 /* NEXT-HOP Unchanged. */
1006 }
1007 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
Lou Berger298cc2f2016-01-12 13:42:02 -05001008 || (NEXTHOP_IS_V4 && attr->nexthop.s_addr == 0)
paul718e3742002-12-13 20:15:29 +00001009#ifdef HAVE_IPV6
Lou Berger298cc2f2016-01-12 13:42:02 -05001010 || (NEXTHOP_IS_V6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001011 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +00001012#endif /* HAVE_IPV6 */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001013 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001014 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
1015 {
1016 /* Set IPv4 nexthop. */
Lou Berger298cc2f2016-01-12 13:42:02 -05001017 if (NEXTHOP_IS_V4)
paul718e3742002-12-13 20:15:29 +00001018 {
Lou Berger298cc2f2016-01-12 13:42:02 -05001019 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00001020 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1021 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +00001022 else
1023 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1024 }
1025#ifdef HAVE_IPV6
1026 /* Set IPv6 nexthop. */
Lou Berger298cc2f2016-01-12 13:42:02 -05001027 if (NEXTHOP_IS_V6)
paul718e3742002-12-13 20:15:29 +00001028 {
1029 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001030 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001031 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001032 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001033 }
1034#endif /* HAVE_IPV6 */
1035 }
1036
1037#ifdef HAVE_IPV6
Lou Berger298cc2f2016-01-12 13:42:02 -05001038 if (p->family == AF_INET6 && safi != SAFI_ENCAP)
paul718e3742002-12-13 20:15:29 +00001039 {
paulfee0f4c2004-09-13 05:12:46 +00001040 /* Left nexthop_local unchanged if so configured. */
1041 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1042 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1043 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001044 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1045 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001046 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001047 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001048 }
1049
1050 /* Default nexthop_local treatment for non-RS-Clients */
1051 else
1052 {
paul718e3742002-12-13 20:15:29 +00001053 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001054 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001055
1056 /* Set link-local address for shared network peer. */
1057 if (peer->shared_network
1058 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1059 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001060 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001061 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001062 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001063 }
1064
1065 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1066 address.*/
1067 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001068 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001069
1070 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1071 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001072 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001073 }
paulfee0f4c2004-09-13 05:12:46 +00001074
1075 }
paul718e3742002-12-13 20:15:29 +00001076#endif /* HAVE_IPV6 */
1077
1078 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001079 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001080 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1081 && aspath_private_as_check (attr->aspath))
1082 attr->aspath = aspath_empty_get ();
1083
1084 /* Route map & unsuppress-map apply. */
1085 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001086 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001087 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001088 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001089 struct attr dummy_attr;
1090 struct attr_extra dummy_extra;
1091
1092 dummy_attr.extra = &dummy_extra;
1093
paul718e3742002-12-13 20:15:29 +00001094 info.peer = peer;
1095 info.attr = attr;
1096
1097 /* The route reflector is not allowed to modify the attributes
1098 of the reflected IBGP routes. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001099 if (from->sort == BGP_PEER_IBGP
1100 && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +00001101 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001102 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001103 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001104 }
paulac41b2a2003-08-12 05:32:27 +00001105
1106 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1107
Paul Jakmafb982c22007-05-04 20:15:47 +00001108 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001109 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1110 else
1111 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1112
paulac41b2a2003-08-12 05:32:27 +00001113 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001114
paul718e3742002-12-13 20:15:29 +00001115 if (ret == RMAP_DENYMATCH)
1116 {
1117 bgp_attr_flush (attr);
1118 return 0;
1119 }
1120 }
1121 return 1;
1122}
1123
paul94f2b392005-06-28 12:44:16 +00001124static int
paulfee0f4c2004-09-13 05:12:46 +00001125bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1126 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001127{
paulfee0f4c2004-09-13 05:12:46 +00001128 int ret;
1129 char buf[SU_ADDRSTRLEN];
1130 struct bgp_filter *filter;
1131 struct bgp_info info;
1132 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001133 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001134
1135 from = ri->peer;
1136 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001137 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001138
Paul Jakma750e8142008-07-22 21:11:48 +00001139 if (DISABLE_BGP_ANNOUNCE)
1140 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001141
1142 /* Do not send back route to sender. */
1143 if (from == rsclient)
1144 return 0;
1145
1146 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001147 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001148 if (! UNSUPPRESS_MAP_NAME (filter))
1149 return 0;
1150
1151 /* Default route check. */
1152 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1153 PEER_STATUS_DEFAULT_ORIGINATE))
1154 {
1155 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1156 return 0;
1157#ifdef HAVE_IPV6
1158 else if (p->family == AF_INET6 && p->prefixlen == 0)
1159 return 0;
1160#endif /* HAVE_IPV6 */
1161 }
1162
1163 /* If the attribute has originator-id and it is same as remote
1164 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001165 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001166 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001167 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001168 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001169 {
1170 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001171 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001172 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1173 rsclient->host,
1174 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1175 p->prefixlen);
1176 return 0;
1177 }
1178 }
1179
1180 /* ORF prefix-list filter check */
1181 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1182 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1183 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1184 if (rsclient->orf_plist[afi][safi])
1185 {
1186 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1187 return 0;
1188 }
1189
1190 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001191 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001192 {
1193 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001194 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001195 "%s [Update:SEND] %s/%d is filtered",
1196 rsclient->host,
1197 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1198 p->prefixlen);
1199 return 0;
1200 }
1201
1202#ifdef BGP_SEND_ASPATH_CHECK
1203 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001204 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001205 {
1206 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001207 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001208 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001209 rsclient->host, rsclient->as);
1210 return 0;
1211 }
1212#endif /* BGP_SEND_ASPATH_CHECK */
1213
1214 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001215 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001216
1217 /* next-hop-set */
1218 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1219#ifdef HAVE_IPV6
1220 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001221 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001222#endif /* HAVE_IPV6 */
1223 )
1224 {
1225 /* Set IPv4 nexthop. */
1226 if (p->family == AF_INET)
1227 {
Lou Berger298cc2f2016-01-12 13:42:02 -05001228 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00001229 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001230 IPV4_MAX_BYTELEN);
1231 else
1232 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1233 }
1234#ifdef HAVE_IPV6
1235 /* Set IPv6 nexthop. */
1236 if (p->family == AF_INET6)
1237 {
1238 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001239 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001240 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001241 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001242 }
1243#endif /* HAVE_IPV6 */
1244 }
1245
1246#ifdef HAVE_IPV6
1247 if (p->family == AF_INET6)
1248 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001249 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001250
paulfee0f4c2004-09-13 05:12:46 +00001251 /* Left nexthop_local unchanged if so configured. */
1252 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1253 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1254 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001255 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1256 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001257 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001258 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001259 }
1260
1261 /* Default nexthop_local treatment for RS-Clients */
1262 else
1263 {
1264 /* Announcer and RS-Client are both in the same network */
1265 if (rsclient->shared_network && from->shared_network &&
1266 (rsclient->ifindex == from->ifindex))
1267 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001268 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1269 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001270 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001271 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001272 }
1273
1274 /* Set link-local address for shared network peer. */
1275 else if (rsclient->shared_network
1276 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1277 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001278 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001279 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001280 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001281 }
1282
1283 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001284 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001285 }
1286
1287 }
1288#endif /* HAVE_IPV6 */
1289
1290
1291 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001292 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001293 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1294 && aspath_private_as_check (attr->aspath))
1295 attr->aspath = aspath_empty_get ();
1296
1297 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001298 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001299 {
1300 info.peer = rsclient;
1301 info.attr = attr;
1302
1303 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1304
Paul Jakmafb982c22007-05-04 20:15:47 +00001305 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001306 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1307 else
1308 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1309
1310 rsclient->rmap_type = 0;
1311
1312 if (ret == RMAP_DENYMATCH)
1313 {
1314 bgp_attr_flush (attr);
1315 return 0;
1316 }
1317 }
1318
1319 return 1;
1320}
1321
1322struct bgp_info_pair
1323{
1324 struct bgp_info *old;
1325 struct bgp_info *new;
1326};
1327
paul94f2b392005-06-28 12:44:16 +00001328static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001329bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
Paul Jakma6d4742b2015-11-25 17:14:37 +00001330 struct bgp_info_pair *result,
1331 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00001332{
paul718e3742002-12-13 20:15:29 +00001333 struct bgp_info *new_select;
1334 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001335 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001336 struct bgp_info *ri1;
1337 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001338 struct bgp_info *nextri = NULL;
Paul Jakma6d4742b2015-11-25 17:14:37 +00001339 int cmpret, do_mpath;
Josh Bailey96450fa2011-07-20 20:45:12 -07001340 struct list mp_list;
Paul Jakma91b9e852015-12-01 14:32:11 +00001341
1342 result->old = result->new = NULL;
1343
1344 if (rn->info == NULL)
1345 {
1346 char buf[PREFIX_STRLEN];
1347 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1348 __func__,
1349 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1350 return;
1351 }
1352
Josh Bailey96450fa2011-07-20 20:45:12 -07001353 bgp_mp_list_init (&mp_list);
Paul Jakma6d4742b2015-11-25 17:14:37 +00001354 do_mpath = bgp_mpath_is_configured (bgp, afi, safi);
Josh Bailey96450fa2011-07-20 20:45:12 -07001355
paul718e3742002-12-13 20:15:29 +00001356 /* bgp deterministic-med */
1357 new_select = NULL;
1358 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1359 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1360 {
1361 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1362 continue;
1363 if (BGP_INFO_HOLDDOWN (ri1))
1364 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001365 if (ri1->peer && ri1->peer != bgp->peer_self)
1366 if (ri1->peer->status != Established)
1367 continue;
paul718e3742002-12-13 20:15:29 +00001368
1369 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001370 if (do_mpath)
1371 bgp_mp_list_add (&mp_list, ri1);
1372 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001373 if (ri1->next)
1374 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1375 {
1376 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1377 continue;
1378 if (BGP_INFO_HOLDDOWN (ri2))
1379 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001380 if (ri2->peer &&
1381 ri2->peer != bgp->peer_self &&
1382 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1383 if (ri2->peer->status != Established)
1384 continue;
paul718e3742002-12-13 20:15:29 +00001385
1386 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1387 || aspath_cmp_left_confed (ri1->attr->aspath,
1388 ri2->attr->aspath))
1389 {
Josh Bailey6918e742011-07-20 20:48:20 -07001390 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1391 old_select = ri2;
Paul Jakma6d4742b2015-11-25 17:14:37 +00001392 if ((cmpret = bgp_info_cmp (bgp, ri2, new_select, afi, safi))
1393 == -1)
paul718e3742002-12-13 20:15:29 +00001394 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001395 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001396 new_select = ri2;
1397 }
1398
Paul Jakma6d4742b2015-11-25 17:14:37 +00001399 if (do_mpath)
1400 {
1401 if (cmpret != 0)
1402 bgp_mp_list_clear (&mp_list);
1403
1404 if (cmpret == 0 || cmpret == -1)
1405 bgp_mp_list_add (&mp_list, ri2);
1406 }
Josh Bailey6918e742011-07-20 20:48:20 -07001407
Paul Jakma1a392d42006-09-07 00:24:49 +00001408 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001409 }
1410 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001411 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1412 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001413
Paul Jakma6d4742b2015-11-25 17:14:37 +00001414 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, afi, safi);
Josh Bailey6918e742011-07-20 20:48:20 -07001415 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001416 }
1417
1418 /* Check old selected route and new selected route. */
1419 old_select = NULL;
1420 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001421 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001422 {
1423 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1424 old_select = ri;
1425
1426 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001427 {
1428 /* reap REMOVED routes, if needs be
1429 * selected route must stay for a while longer though
1430 */
1431 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1432 && (ri != old_select))
1433 bgp_info_reap (rn, ri);
1434
1435 continue;
1436 }
paul718e3742002-12-13 20:15:29 +00001437
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001438 if (ri->peer &&
1439 ri->peer != bgp->peer_self &&
1440 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1441 if (ri->peer->status != Established)
1442 continue;
1443
paul718e3742002-12-13 20:15:29 +00001444 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1445 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1446 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001447 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001448 continue;
1449 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001450 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1451 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001452
Paul Jakma6d4742b2015-11-25 17:14:37 +00001453 if ((cmpret = bgp_info_cmp (bgp, ri, new_select, afi, safi)) == -1)
Josh Bailey96450fa2011-07-20 20:45:12 -07001454 {
Josh Bailey6918e742011-07-20 20:48:20 -07001455 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1456 bgp_mp_dmed_deselect (new_select);
1457
Josh Bailey96450fa2011-07-20 20:45:12 -07001458 new_select = ri;
Josh Bailey96450fa2011-07-20 20:45:12 -07001459 }
Paul Jakma6d4742b2015-11-25 17:14:37 +00001460 else if (cmpret == 1 && do_mpath
1461 && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
Josh Bailey6918e742011-07-20 20:48:20 -07001462 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001463
Paul Jakma6d4742b2015-11-25 17:14:37 +00001464 if (do_mpath)
1465 {
1466 if (cmpret != 0)
1467 bgp_mp_list_clear (&mp_list);
1468
1469 if (cmpret == 0 || cmpret == -1)
1470 bgp_mp_list_add (&mp_list, ri);
1471 }
paul718e3742002-12-13 20:15:29 +00001472 }
paulfee0f4c2004-09-13 05:12:46 +00001473
Josh Bailey6918e742011-07-20 20:48:20 -07001474 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
Paul Jakma6d4742b2015-11-25 17:14:37 +00001475 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, afi, safi);
Josh Bailey96450fa2011-07-20 20:45:12 -07001476
Josh Bailey0b597ef2011-07-20 20:49:11 -07001477 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001478 bgp_mp_list_clear (&mp_list);
1479
1480 result->old = old_select;
1481 result->new = new_select;
1482
1483 return;
paulfee0f4c2004-09-13 05:12:46 +00001484}
1485
paul94f2b392005-06-28 12:44:16 +00001486static int
paulfee0f4c2004-09-13 05:12:46 +00001487bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001488 struct bgp_node *rn, afi_t afi, safi_t safi)
1489{
paulfee0f4c2004-09-13 05:12:46 +00001490 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001491 struct attr attr;
1492 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001493
Lou Berger050defe2016-01-12 13:41:59 -05001494 memset (&attr, 0, sizeof(struct attr));
1495 memset (&extra, 0, sizeof(struct attr_extra));
1496
paulfee0f4c2004-09-13 05:12:46 +00001497 p = &rn->p;
1498
Paul Jakma9eda90c2007-08-30 13:36:17 +00001499 /* Announce route to Established peer. */
1500 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001501 return 0;
1502
Paul Jakma9eda90c2007-08-30 13:36:17 +00001503 /* Address family configuration check. */
1504 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001505 return 0;
1506
Paul Jakma9eda90c2007-08-30 13:36:17 +00001507 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001508 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1509 PEER_STATUS_ORF_WAIT_REFRESH))
1510 return 0;
1511
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001512 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1513 attr.extra = &extra;
1514
Avneesh Sachdev67174042012-08-17 08:19:49 -07001515 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001516 {
1517 case BGP_TABLE_MAIN:
1518 /* Announcement to peer->conf. If the route is filtered,
1519 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001520 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1521 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001522 else
1523 bgp_adj_out_unset (rn, peer, p, afi, safi);
1524 break;
1525 case BGP_TABLE_RSCLIENT:
1526 /* Announcement to peer->conf. If the route is filtered,
1527 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001528 if (selected &&
1529 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1530 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1531 else
1532 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001533 break;
1534 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001535
Lou Berger050defe2016-01-12 13:41:59 -05001536 bgp_attr_flush (&attr);
paulfee0f4c2004-09-13 05:12:46 +00001537 return 0;
paul200df112005-06-01 11:17:05 +00001538}
paulfee0f4c2004-09-13 05:12:46 +00001539
paul200df112005-06-01 11:17:05 +00001540struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001541{
paul200df112005-06-01 11:17:05 +00001542 struct bgp *bgp;
1543 struct bgp_node *rn;
1544 afi_t afi;
1545 safi_t safi;
1546};
1547
1548static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001549bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001550{
paul0fb58d52005-11-14 14:31:49 +00001551 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001552 struct bgp *bgp = pq->bgp;
1553 struct bgp_node *rn = pq->rn;
1554 afi_t afi = pq->afi;
1555 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001556 struct bgp_info *new_select;
1557 struct bgp_info *old_select;
1558 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001559 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001560 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001561
paulfee0f4c2004-09-13 05:12:46 +00001562 /* Best path selection. */
Paul Jakma6d4742b2015-11-25 17:14:37 +00001563 bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001564 new_select = old_and_new.new;
1565 old_select = old_and_new.old;
1566
paul200df112005-06-01 11:17:05 +00001567 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1568 {
Chris Caputo228da422009-07-18 05:44:03 +00001569 if (rsclient->group)
1570 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1571 {
1572 /* Nothing to do. */
1573 if (old_select && old_select == new_select)
1574 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1575 continue;
paulfee0f4c2004-09-13 05:12:46 +00001576
Chris Caputo228da422009-07-18 05:44:03 +00001577 if (old_select)
1578 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1579 if (new_select)
1580 {
1581 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1582 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001583 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1584 }
paulfee0f4c2004-09-13 05:12:46 +00001585
Chris Caputo228da422009-07-18 05:44:03 +00001586 bgp_process_announce_selected (rsclient, new_select, rn,
1587 afi, safi);
1588 }
paul200df112005-06-01 11:17:05 +00001589 }
1590 else
1591 {
hassob7395792005-08-26 12:58:38 +00001592 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001593 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001594 if (new_select)
1595 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001596 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1597 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001598 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001599 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001600 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001601 }
paulfee0f4c2004-09-13 05:12:46 +00001602
paulb40d9392005-08-22 22:34:41 +00001603 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1604 bgp_info_reap (rn, old_select);
1605
paul200df112005-06-01 11:17:05 +00001606 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1607 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001608}
1609
paul200df112005-06-01 11:17:05 +00001610static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001611bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001612{
paul0fb58d52005-11-14 14:31:49 +00001613 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001614 struct bgp *bgp = pq->bgp;
1615 struct bgp_node *rn = pq->rn;
1616 afi_t afi = pq->afi;
1617 safi_t safi = pq->safi;
1618 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001619 struct bgp_info *new_select;
1620 struct bgp_info *old_select;
1621 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001622 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001623 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001624
paulfee0f4c2004-09-13 05:12:46 +00001625 /* Best path selection. */
Paul Jakma6d4742b2015-11-25 17:14:37 +00001626 bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001627 old_select = old_and_new.old;
1628 new_select = old_and_new.new;
1629
1630 /* Nothing to do. */
1631 if (old_select && old_select == new_select)
1632 {
1633 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001634 {
Josh Bailey8196f132011-07-20 20:47:07 -07001635 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1636 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001637 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001638
Josh Bailey8196f132011-07-20 20:47:07 -07001639 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001640 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1641 return WQ_SUCCESS;
1642 }
paulfee0f4c2004-09-13 05:12:46 +00001643 }
paul718e3742002-12-13 20:15:29 +00001644
hasso338b3422005-02-23 14:27:24 +00001645 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001646 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001647 if (new_select)
1648 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001649 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1650 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001651 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001652 }
1653
1654
paul718e3742002-12-13 20:15:29 +00001655 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001656 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001657 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001658 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001659 }
1660
1661 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001662 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1663 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001664 {
1665 if (new_select
1666 && new_select->type == ZEBRA_ROUTE_BGP
1667 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001668 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001669 else
1670 {
1671 /* Withdraw the route from the kernel. */
1672 if (old_select
1673 && old_select->type == ZEBRA_ROUTE_BGP
1674 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001675 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001676 }
1677 }
paulb40d9392005-08-22 22:34:41 +00001678
Lou Berger050defe2016-01-12 13:41:59 -05001679 /* Reap old select bgp_info, if it has been removed */
paulb40d9392005-08-22 22:34:41 +00001680 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1681 bgp_info_reap (rn, old_select);
1682
paul200df112005-06-01 11:17:05 +00001683 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1684 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001685}
1686
paul200df112005-06-01 11:17:05 +00001687static void
paul0fb58d52005-11-14 14:31:49 +00001688bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001689{
paul0fb58d52005-11-14 14:31:49 +00001690 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001691 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001692
Chris Caputo228da422009-07-18 05:44:03 +00001693 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001694 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001695 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001696 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1697}
1698
1699static void
1700bgp_process_queue_init (void)
1701{
1702 bm->process_main_queue
1703 = work_queue_new (bm->master, "process_main_queue");
1704 bm->process_rsclient_queue
1705 = work_queue_new (bm->master, "process_rsclient_queue");
1706
1707 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1708 {
1709 zlog_err ("%s: Failed to allocate work queue", __func__);
1710 exit (1);
1711 }
1712
1713 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001714 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001715 bm->process_main_queue->spec.max_retries = 0;
1716 bm->process_main_queue->spec.hold = 50;
1717
Paul Jakma838bbde2010-01-08 14:05:32 +00001718 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
David Lamparterd43f8b32015-03-03 08:54:54 +01001719 bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del;
1720 bm->process_rsclient_queue->spec.max_retries = 0;
1721 bm->process_rsclient_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001722}
1723
1724void
paulfee0f4c2004-09-13 05:12:46 +00001725bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1726{
paul200df112005-06-01 11:17:05 +00001727 struct bgp_process_queue *pqnode;
1728
1729 /* already scheduled for processing? */
1730 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1731 return;
1732
Paul Jakma91b9e852015-12-01 14:32:11 +00001733 if (rn->info == NULL)
1734 {
1735 /* XXX: Perhaps remove before next release, after we've flushed out
1736 * any obvious cases
1737 */
1738 assert (rn->info != NULL);
1739 char buf[PREFIX_STRLEN];
1740 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1741 __func__,
1742 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1743 return;
1744 }
1745
paul200df112005-06-01 11:17:05 +00001746 if ( (bm->process_main_queue == NULL) ||
1747 (bm->process_rsclient_queue == NULL) )
1748 bgp_process_queue_init ();
1749
1750 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1751 sizeof (struct bgp_process_queue));
1752 if (!pqnode)
1753 return;
Chris Caputo228da422009-07-18 05:44:03 +00001754
1755 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001756 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001757 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001758 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001759 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001760 pqnode->afi = afi;
1761 pqnode->safi = safi;
1762
Avneesh Sachdev67174042012-08-17 08:19:49 -07001763 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001764 {
paul200df112005-06-01 11:17:05 +00001765 case BGP_TABLE_MAIN:
1766 work_queue_add (bm->process_main_queue, pqnode);
1767 break;
1768 case BGP_TABLE_RSCLIENT:
1769 work_queue_add (bm->process_rsclient_queue, pqnode);
1770 break;
paulfee0f4c2004-09-13 05:12:46 +00001771 }
paul200df112005-06-01 11:17:05 +00001772
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001773 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001774 return;
paulfee0f4c2004-09-13 05:12:46 +00001775}
hasso0a486e52005-02-01 20:57:17 +00001776
paul94f2b392005-06-28 12:44:16 +00001777static int
hasso0a486e52005-02-01 20:57:17 +00001778bgp_maximum_prefix_restart_timer (struct thread *thread)
1779{
1780 struct peer *peer;
1781
1782 peer = THREAD_ARG (thread);
1783 peer->t_pmax_restart = NULL;
1784
1785 if (BGP_DEBUG (events, EVENTS))
1786 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1787 peer->host);
1788
1789 peer_clear (peer);
1790
1791 return 0;
1792}
1793
paulfee0f4c2004-09-13 05:12:46 +00001794int
paul5228ad22004-06-04 17:58:18 +00001795bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1796 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001797{
hassoe0701b72004-05-20 09:19:34 +00001798 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1799 return 0;
1800
1801 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001802 {
hassoe0701b72004-05-20 09:19:34 +00001803 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1804 && ! always)
1805 return 0;
paul718e3742002-12-13 20:15:29 +00001806
hassoe0701b72004-05-20 09:19:34 +00001807 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001808 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1809 "limit %ld", afi_safi_print (afi, safi), peer->host,
1810 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001811 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001812
hassoe0701b72004-05-20 09:19:34 +00001813 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1814 return 0;
paul718e3742002-12-13 20:15:29 +00001815
hassoe0701b72004-05-20 09:19:34 +00001816 {
paul5228ad22004-06-04 17:58:18 +00001817 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001818
1819 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001820 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001821
1822 ndata[0] = (afi >> 8);
1823 ndata[1] = afi;
1824 ndata[2] = safi;
1825 ndata[3] = (peer->pmax[afi][safi] >> 24);
1826 ndata[4] = (peer->pmax[afi][safi] >> 16);
1827 ndata[5] = (peer->pmax[afi][safi] >> 8);
1828 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001829
1830 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1831 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1832 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1833 }
hasso0a486e52005-02-01 20:57:17 +00001834
1835 /* restart timer start */
1836 if (peer->pmax_restart[afi][safi])
1837 {
1838 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1839
1840 if (BGP_DEBUG (events, EVENTS))
1841 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1842 peer->host, peer->v_pmax_restart);
1843
1844 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1845 peer->v_pmax_restart);
1846 }
1847
hassoe0701b72004-05-20 09:19:34 +00001848 return 1;
paul718e3742002-12-13 20:15:29 +00001849 }
hassoe0701b72004-05-20 09:19:34 +00001850 else
1851 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1852
1853 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1854 {
1855 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1856 && ! always)
1857 return 0;
1858
1859 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001860 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1861 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1862 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001863 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1864 }
1865 else
1866 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001867 return 0;
1868}
1869
paulb40d9392005-08-22 22:34:41 +00001870/* Unconditionally remove the route from the RIB, without taking
1871 * damping into consideration (eg, because the session went down)
1872 */
paul94f2b392005-06-28 12:44:16 +00001873static void
paul718e3742002-12-13 20:15:29 +00001874bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1875 afi_t afi, safi_t safi)
1876{
paul902212c2006-02-05 17:51:19 +00001877 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1878
1879 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1880 bgp_info_delete (rn, ri); /* keep historical info */
1881
paulb40d9392005-08-22 22:34:41 +00001882 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001883}
1884
paul94f2b392005-06-28 12:44:16 +00001885static void
paul718e3742002-12-13 20:15:29 +00001886bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
Lou Berger050defe2016-01-12 13:41:59 -05001887 afi_t afi, safi_t safi, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00001888{
paul718e3742002-12-13 20:15:29 +00001889 int status = BGP_DAMP_NONE;
1890
paulb40d9392005-08-22 22:34:41 +00001891 /* apply dampening, if result is suppressed, we'll be retaining
1892 * the bgp_info in the RIB for historical reference.
1893 */
1894 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001895 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001896 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1897 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001898 {
paul902212c2006-02-05 17:51:19 +00001899 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1900 return;
1901 }
1902
1903 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001904}
1905
paul94f2b392005-06-28 12:44:16 +00001906static void
paulfee0f4c2004-09-13 05:12:46 +00001907bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1908 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1909 int sub_type, struct prefix_rd *prd, u_char *tag)
1910{
1911 struct bgp_node *rn;
1912 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001913 struct attr new_attr;
1914 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001915 struct attr *attr_new;
1916 struct attr *attr_new2;
1917 struct bgp_info *ri;
1918 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001919 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001920 char buf[SU_ADDRSTRLEN];
1921
1922 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1923 if (peer == rsclient)
1924 return;
1925
1926 bgp = peer->bgp;
1927 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1928
1929 /* Check previously received route. */
1930 for (ri = rn->info; ri; ri = ri->next)
1931 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1932 break;
1933
1934 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001935 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001936 {
1937 reason = "as-path contains our own AS;";
1938 goto filtered;
1939 }
1940
1941 /* Route reflector originator ID check. */
1942 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001943 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001944 {
1945 reason = "originator is us;";
1946 goto filtered;
1947 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001948
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001949 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001950 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001951
1952 /* Apply export policy. */
1953 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1954 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1955 {
1956 reason = "export-policy;";
1957 goto filtered;
1958 }
1959
1960 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001961
paulfee0f4c2004-09-13 05:12:46 +00001962 /* Apply import policy. */
1963 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1964 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001965 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001966
1967 reason = "import-policy;";
1968 goto filtered;
1969 }
1970
1971 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001972 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001973
1974 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001975 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001976 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001977 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001978 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001979 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001980 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001981 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001982
1983 reason = "martian next-hop;";
1984 goto filtered;
1985 }
1986 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001987
paulfee0f4c2004-09-13 05:12:46 +00001988 /* If the update is implicit withdraw. */
1989 if (ri)
1990 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001991 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001992
1993 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001994 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1995 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001996 {
1997
Paul Jakma1a392d42006-09-07 00:24:49 +00001998 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001999
2000 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002001 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002002 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
2003 peer->host,
2004 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2005 p->prefixlen, rsclient->host);
2006
Chris Caputo228da422009-07-18 05:44:03 +00002007 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002008 bgp_attr_unintern (&attr_new);
Lou Berger050defe2016-01-12 13:41:59 -05002009 bgp_attr_flush(&new_attr);
Chris Caputo228da422009-07-18 05:44:03 +00002010 return;
paulfee0f4c2004-09-13 05:12:46 +00002011 }
2012
Paul Jakma16d2e242007-04-10 19:32:10 +00002013 /* Withdraw/Announce before we fully processed the withdraw */
2014 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2015 bgp_info_restore (rn, ri);
2016
paulfee0f4c2004-09-13 05:12:46 +00002017 /* Received Logging. */
2018 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002019 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002020 peer->host,
2021 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2022 p->prefixlen, rsclient->host);
2023
2024 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002025 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00002026
2027 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002028 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00002029 ri->attr = attr_new;
2030
2031 /* Update MPLS tag. */
2032 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002033 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002034
Paul Jakma1a392d42006-09-07 00:24:49 +00002035 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002036
2037 /* Process change. */
2038 bgp_process (bgp, rn, afi, safi);
2039 bgp_unlock_node (rn);
2040
2041 return;
2042 }
2043
2044 /* Received Logging. */
2045 if (BGP_DEBUG (update, UPDATE_IN))
2046 {
ajsd2c1f162004-12-08 21:10:20 +00002047 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002048 peer->host,
2049 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2050 p->prefixlen, rsclient->host);
2051 }
2052
2053 /* Make new BGP info. */
2054 new = bgp_info_new ();
2055 new->type = type;
2056 new->sub_type = sub_type;
2057 new->peer = peer;
2058 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002059 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00002060
2061 /* Update MPLS tag. */
2062 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002063 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002064
Paul Jakma1a392d42006-09-07 00:24:49 +00002065 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002066
2067 /* Register new BGP information. */
2068 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002069
2070 /* route_node_get lock */
2071 bgp_unlock_node (rn);
2072
paulfee0f4c2004-09-13 05:12:46 +00002073 /* Process change. */
2074 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002075
paulfee0f4c2004-09-13 05:12:46 +00002076 return;
2077
2078 filtered:
2079
2080 /* This BGP update is filtered. Log the reason then update BGP entry. */
2081 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002082 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002083 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2084 peer->host,
2085 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2086 p->prefixlen, rsclient->host, reason);
2087
2088 if (ri)
paulb40d9392005-08-22 22:34:41 +00002089 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002090
2091 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002092
paulfee0f4c2004-09-13 05:12:46 +00002093 return;
2094}
2095
paul94f2b392005-06-28 12:44:16 +00002096static void
paulfee0f4c2004-09-13 05:12:46 +00002097bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2098 struct peer *peer, struct prefix *p, int type, int sub_type,
2099 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002100{
paulfee0f4c2004-09-13 05:12:46 +00002101 struct bgp_node *rn;
2102 struct bgp_info *ri;
2103 char buf[SU_ADDRSTRLEN];
2104
2105 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002106 return;
paulfee0f4c2004-09-13 05:12:46 +00002107
2108 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2109
2110 /* Lookup withdrawn route. */
2111 for (ri = rn->info; ri; ri = ri->next)
2112 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2113 break;
2114
2115 /* Withdraw specified route from routing table. */
2116 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Lou Berger050defe2016-01-12 13:41:59 -05002117 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
paulfee0f4c2004-09-13 05:12:46 +00002118 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002119 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002120 "%s Can't find the route %s/%d", peer->host,
2121 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2122 p->prefixlen);
2123
2124 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002125 bgp_unlock_node (rn);
2126}
paulfee0f4c2004-09-13 05:12:46 +00002127
paul94f2b392005-06-28 12:44:16 +00002128static int
paulfee0f4c2004-09-13 05:12:46 +00002129bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002130 afi_t afi, safi_t safi, int type, int sub_type,
2131 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2132{
2133 int ret;
2134 int aspath_loop_count = 0;
2135 struct bgp_node *rn;
2136 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002137 struct attr new_attr;
2138 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002139 struct attr *attr_new;
2140 struct bgp_info *ri;
2141 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002142 const char *reason;
paul718e3742002-12-13 20:15:29 +00002143 char buf[SU_ADDRSTRLEN];
2144
2145 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002146 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002147
paul718e3742002-12-13 20:15:29 +00002148 /* When peer's soft reconfiguration enabled. Record input packet in
2149 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002150 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2151 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002152 bgp_adj_in_set (rn, peer, attr);
2153
2154 /* Check previously received route. */
2155 for (ri = rn->info; ri; ri = ri->next)
2156 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2157 break;
2158
2159 /* AS path local-as loop check. */
2160 if (peer->change_local_as)
2161 {
2162 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2163 aspath_loop_count = 1;
2164
2165 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2166 {
2167 reason = "as-path contains our own AS;";
2168 goto filtered;
2169 }
2170 }
2171
2172 /* AS path loop check. */
2173 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2174 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2175 && aspath_loop_check(attr->aspath, bgp->confed_id)
2176 > peer->allowas_in[afi][safi]))
2177 {
2178 reason = "as-path contains our own AS;";
2179 goto filtered;
2180 }
2181
2182 /* Route reflector originator ID check. */
2183 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002184 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002185 {
2186 reason = "originator is us;";
2187 goto filtered;
2188 }
2189
2190 /* Route reflector cluster ID check. */
2191 if (bgp_cluster_filter (peer, attr))
2192 {
2193 reason = "reflected from the same cluster;";
2194 goto filtered;
2195 }
2196
2197 /* Apply incoming filter. */
2198 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2199 {
2200 reason = "filter;";
2201 goto filtered;
2202 }
2203
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002204 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002205 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002206
David Lamparterc460e572014-06-04 00:54:58 +02002207 /* Apply incoming route-map.
2208 * NB: new_attr may now contain newly allocated values from route-map "set"
2209 * commands, so we need bgp_attr_flush in the error paths, until we intern
2210 * the attr (which takes over the memory references) */
paul718e3742002-12-13 20:15:29 +00002211 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2212 {
2213 reason = "route-map;";
David Lamparterc460e572014-06-04 00:54:58 +02002214 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002215 goto filtered;
2216 }
2217
2218 /* IPv4 unicast next hop check. */
2219 if (afi == AFI_IP && safi == SAFI_UNICAST)
2220 {
2221 /* If the peer is EBGP and nexthop is not on connected route,
2222 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002223 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002224 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002225 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002226 {
2227 reason = "non-connected next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002228 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002229 goto filtered;
2230 }
2231
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002232 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002233 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002234 if (new_attr.nexthop.s_addr == 0
2235 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2236 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002237 {
2238 reason = "martian next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002239 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002240 goto filtered;
2241 }
2242 }
2243
2244 attr_new = bgp_attr_intern (&new_attr);
2245
2246 /* If the update is implicit withdraw. */
2247 if (ri)
2248 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002249 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002250
2251 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002252 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2253 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002254 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002255 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002256
2257 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002258 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002259 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2260 {
2261 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002262 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002263 peer->host,
2264 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2265 p->prefixlen);
2266
paul902212c2006-02-05 17:51:19 +00002267 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2268 {
2269 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2270 bgp_process (bgp, rn, afi, safi);
2271 }
paul718e3742002-12-13 20:15:29 +00002272 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002273 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002274 {
2275 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002276 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002277 "%s rcvd %s/%d...duplicate ignored",
2278 peer->host,
2279 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2280 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002281
2282 /* graceful restart STALE flag unset. */
2283 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2284 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002285 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002286 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002287 }
paul718e3742002-12-13 20:15:29 +00002288 }
2289
2290 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002291 bgp_attr_unintern (&attr_new);
Lou Berger050defe2016-01-12 13:41:59 -05002292 bgp_attr_flush (&new_attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002293
paul718e3742002-12-13 20:15:29 +00002294 return 0;
2295 }
2296
Paul Jakma16d2e242007-04-10 19:32:10 +00002297 /* Withdraw/Announce before we fully processed the withdraw */
2298 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2299 {
2300 if (BGP_DEBUG (update, UPDATE_IN))
2301 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2302 peer->host,
2303 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2304 p->prefixlen);
2305 bgp_info_restore (rn, ri);
2306 }
2307
paul718e3742002-12-13 20:15:29 +00002308 /* Received Logging. */
2309 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002310 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002311 peer->host,
2312 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2313 p->prefixlen);
2314
hasso93406d82005-02-02 14:40:33 +00002315 /* graceful restart STALE flag unset. */
2316 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002317 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002318
paul718e3742002-12-13 20:15:29 +00002319 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002320 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002321
2322 /* implicit withdraw, decrement aggregate and pcount here.
2323 * only if update is accepted, they'll increment below.
2324 */
paul902212c2006-02-05 17:51:19 +00002325 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2326
paul718e3742002-12-13 20:15:29 +00002327 /* Update bgp route dampening information. */
2328 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002329 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002330 {
2331 /* This is implicit withdraw so we should update dampening
2332 information. */
2333 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2334 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002335 }
2336
paul718e3742002-12-13 20:15:29 +00002337 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002338 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002339 ri->attr = attr_new;
2340
2341 /* Update MPLS tag. */
2342 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002343 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002344
Lou Berger050defe2016-01-12 13:41:59 -05002345 bgp_attr_flush (&new_attr);
2346
paul718e3742002-12-13 20:15:29 +00002347 /* Update bgp route dampening information. */
2348 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002349 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002350 {
2351 /* Now we do normal update dampening. */
2352 ret = bgp_damp_update (ri, rn, afi, safi);
2353 if (ret == BGP_DAMP_SUPPRESSED)
2354 {
2355 bgp_unlock_node (rn);
2356 return 0;
2357 }
2358 }
2359
2360 /* Nexthop reachability check. */
2361 if ((afi == AFI_IP || afi == AFI_IP6)
2362 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002363 && (peer->sort == BGP_PEER_IBGP
2364 || peer->sort == BGP_PEER_CONFED
2365 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002366 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002367 {
2368 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002369 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002370 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002371 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002372 }
2373 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002374 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002375
Lou Berger050defe2016-01-12 13:41:59 -05002376 bgp_attr_flush (&new_attr);
2377
paul718e3742002-12-13 20:15:29 +00002378 /* Process change. */
2379 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2380
2381 bgp_process (bgp, rn, afi, safi);
2382 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002383
paul718e3742002-12-13 20:15:29 +00002384 return 0;
2385 }
2386
2387 /* Received Logging. */
2388 if (BGP_DEBUG (update, UPDATE_IN))
2389 {
ajsd2c1f162004-12-08 21:10:20 +00002390 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002391 peer->host,
2392 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2393 p->prefixlen);
2394 }
2395
paul718e3742002-12-13 20:15:29 +00002396 /* Make new BGP info. */
2397 new = bgp_info_new ();
2398 new->type = type;
2399 new->sub_type = sub_type;
2400 new->peer = peer;
2401 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002402 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002403
2404 /* Update MPLS tag. */
2405 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002406 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002407
2408 /* Nexthop reachability check. */
2409 if ((afi == AFI_IP || afi == AFI_IP6)
2410 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002411 && (peer->sort == BGP_PEER_IBGP
2412 || peer->sort == BGP_PEER_CONFED
2413 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002414 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002415 {
2416 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002417 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002418 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002419 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002420 }
2421 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002422 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002423
paul902212c2006-02-05 17:51:19 +00002424 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002425 bgp_aggregate_increment (bgp, p, new, afi, safi);
2426
2427 /* Register new BGP information. */
2428 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002429
2430 /* route_node_get lock */
2431 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002432
Lou Berger050defe2016-01-12 13:41:59 -05002433 bgp_attr_flush (&new_attr);
2434
paul718e3742002-12-13 20:15:29 +00002435 /* If maximum prefix count is configured and current prefix
2436 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002437 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2438 return -1;
paul718e3742002-12-13 20:15:29 +00002439
2440 /* Process change. */
2441 bgp_process (bgp, rn, afi, safi);
2442
2443 return 0;
2444
2445 /* This BGP update is filtered. Log the reason then update BGP
2446 entry. */
2447 filtered:
2448 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002449 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002450 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2451 peer->host,
2452 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2453 p->prefixlen, reason);
2454
2455 if (ri)
paulb40d9392005-08-22 22:34:41 +00002456 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002457
2458 bgp_unlock_node (rn);
Lou Berger050defe2016-01-12 13:41:59 -05002459 bgp_attr_flush (&new_attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002460
paul718e3742002-12-13 20:15:29 +00002461 return 0;
2462}
2463
2464int
paulfee0f4c2004-09-13 05:12:46 +00002465bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2466 afi_t afi, safi_t safi, int type, int sub_type,
2467 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2468{
2469 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002470 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002471 struct bgp *bgp;
2472 int ret;
2473
2474 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2475 soft_reconfig);
2476
2477 bgp = peer->bgp;
2478
2479 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002480 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002481 {
2482 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2483 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2484 sub_type, prd, tag);
2485 }
2486
2487 return ret;
2488}
2489
2490int
paul718e3742002-12-13 20:15:29 +00002491bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002492 afi_t afi, safi_t safi, int type, int sub_type,
2493 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002494{
2495 struct bgp *bgp;
2496 char buf[SU_ADDRSTRLEN];
2497 struct bgp_node *rn;
2498 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002499 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002500 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002501
2502 bgp = peer->bgp;
2503
David Lamparter4584c232015-04-13 09:50:00 +02002504 /* Lookup node. */
2505 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2506
2507 /* Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2508 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2509 * the iteration over all RS clients.
2510 * Since we need to remove the entry from adj_in anyway, do that first and
2511 * if there was no entry, we don't need to do anything more. */
2512 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2513 && peer != bgp->peer_self)
2514 if (!bgp_adj_in_unset (rn, peer))
2515 {
2516 if (BGP_DEBUG (update, UPDATE_IN))
2517 zlog (peer->log, LOG_DEBUG, "%s withdrawing route %s/%d "
2518 "not in adj-in", peer->host,
2519 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2520 p->prefixlen);
2521 bgp_unlock_node (rn);
2522 return 0;
2523 }
2524
paulfee0f4c2004-09-13 05:12:46 +00002525 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002526 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002527 {
2528 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2529 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2530 }
2531
paul718e3742002-12-13 20:15:29 +00002532 /* Logging. */
2533 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002534 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002535 peer->host,
2536 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2537 p->prefixlen);
2538
paul718e3742002-12-13 20:15:29 +00002539 /* Lookup withdrawn route. */
2540 for (ri = rn->info; ri; ri = ri->next)
2541 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2542 break;
2543
2544 /* Withdraw specified route from routing table. */
2545 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Lou Berger050defe2016-01-12 13:41:59 -05002546 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
paul718e3742002-12-13 20:15:29 +00002547 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002548 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002549 "%s Can't find the route %s/%d", peer->host,
2550 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2551 p->prefixlen);
2552
2553 /* Unlock bgp_node_get() lock. */
2554 bgp_unlock_node (rn);
2555
2556 return 0;
2557}
David Lamparter6b0655a2014-06-04 06:53:35 +02002558
paul718e3742002-12-13 20:15:29 +00002559void
2560bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2561{
2562 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002563 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002564 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002565 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002566 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002567 struct bgp_node *rn;
2568 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002569 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002570
Paul Jakmab2497022007-06-14 11:17:58 +00002571 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002572 return;
2573
paul718e3742002-12-13 20:15:29 +00002574 bgp = peer->bgp;
2575 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002576
paul718e3742002-12-13 20:15:29 +00002577 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2578 aspath = attr.aspath;
2579 attr.local_pref = bgp->default_local_pref;
2580 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2581
2582 if (afi == AFI_IP)
2583 str2prefix ("0.0.0.0/0", &p);
2584#ifdef HAVE_IPV6
2585 else if (afi == AFI_IP6)
2586 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002587 struct attr_extra *ae = attr.extra;
2588
paul718e3742002-12-13 20:15:29 +00002589 str2prefix ("::/0", &p);
2590
2591 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002592 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002593 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002594 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002595
2596 /* If the peer is on shared nextwork and we have link-local
2597 nexthop set it. */
2598 if (peer->shared_network
2599 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2600 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002601 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002602 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002603 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002604 }
2605 }
2606#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002607
2608 if (peer->default_rmap[afi][safi].name)
2609 {
paulfee0f4c2004-09-13 05:12:46 +00002610 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002611 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2612 {
2613 for (ri = rn->info; ri; ri = ri->next)
2614 {
2615 struct attr dummy_attr;
2616 struct attr_extra dummy_extra;
2617 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002618
Christian Frankedcab1bb2012-12-07 16:45:52 +00002619 /* Provide dummy so the route-map can't modify the attributes */
2620 dummy_attr.extra = &dummy_extra;
2621 bgp_attr_dup(&dummy_attr, ri->attr);
2622 info.peer = ri->peer;
2623 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002624
Christian Frankedcab1bb2012-12-07 16:45:52 +00002625 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2626 RMAP_BGP, &info);
2627
2628 /* The route map might have set attributes. If we don't flush them
2629 * here, they will be leaked. */
2630 bgp_attr_flush(&dummy_attr);
2631 if (ret != RMAP_DENYMATCH)
2632 break;
2633 }
2634 if (ret != RMAP_DENYMATCH)
2635 break;
2636 }
paulfee0f4c2004-09-13 05:12:46 +00002637 bgp->peer_self->rmap_type = 0;
2638
paul718e3742002-12-13 20:15:29 +00002639 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002640 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002641 }
2642
2643 if (withdraw)
2644 {
2645 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2646 bgp_default_withdraw_send (peer, afi, safi);
2647 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2648 }
2649 else
2650 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002651 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2652 {
2653 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2654 bgp_default_update_send (peer, &attr, afi, safi, from);
2655 }
paul718e3742002-12-13 20:15:29 +00002656 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002657
2658 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002659 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002660}
David Lamparter6b0655a2014-06-04 06:53:35 +02002661
paul718e3742002-12-13 20:15:29 +00002662static void
2663bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002664 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002665{
2666 struct bgp_node *rn;
2667 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002668 struct attr attr;
2669 struct attr_extra extra;
2670
Lou Berger298cc2f2016-01-12 13:42:02 -05002671 memset(&extra, 0, sizeof(extra));
2672
paul718e3742002-12-13 20:15:29 +00002673 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002674 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002675
Lou Berger298cc2f2016-01-12 13:42:02 -05002676 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP)
paul718e3742002-12-13 20:15:29 +00002677 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2678 bgp_default_originate (peer, afi, safi, 0);
2679
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002680 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2681 attr.extra = &extra;
2682
paul718e3742002-12-13 20:15:29 +00002683 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2684 for (ri = rn->info; ri; ri = ri->next)
2685 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2686 {
paulfee0f4c2004-09-13 05:12:46 +00002687 if ( (rsclient) ?
2688 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2689 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002690 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2691 else
2692 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2693 }
Lou Berger298cc2f2016-01-12 13:42:02 -05002694
2695 bgp_attr_flush_encap(&attr);
paul718e3742002-12-13 20:15:29 +00002696}
2697
2698void
2699bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2700{
2701 struct bgp_node *rn;
2702 struct bgp_table *table;
2703
2704 if (peer->status != Established)
2705 return;
2706
2707 if (! peer->afc_nego[afi][safi])
2708 return;
2709
2710 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2711 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2712 return;
2713
Lou Berger298cc2f2016-01-12 13:42:02 -05002714 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
paulfee0f4c2004-09-13 05:12:46 +00002715 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002716 else
2717 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2718 rn = bgp_route_next(rn))
2719 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002720 bgp_announce_table (peer, afi, safi, table, 0);
2721
2722 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2723 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002724}
2725
2726void
2727bgp_announce_route_all (struct peer *peer)
2728{
2729 afi_t afi;
2730 safi_t safi;
2731
2732 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2733 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2734 bgp_announce_route (peer, afi, safi);
2735}
David Lamparter6b0655a2014-06-04 06:53:35 +02002736
paul718e3742002-12-13 20:15:29 +00002737static void
paulfee0f4c2004-09-13 05:12:46 +00002738bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002739 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002740{
2741 struct bgp_node *rn;
2742 struct bgp_adj_in *ain;
2743
2744 if (! table)
2745 table = rsclient->bgp->rib[afi][safi];
2746
2747 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2748 for (ain = rn->adj_in; ain; ain = ain->next)
2749 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002750 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002751 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002752
paulfee0f4c2004-09-13 05:12:46 +00002753 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002754 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002755 }
2756}
2757
2758void
2759bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2760{
2761 struct bgp_table *table;
2762 struct bgp_node *rn;
2763
Lou Berger298cc2f2016-01-12 13:42:02 -05002764 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002765 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002766
2767 else
2768 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2769 rn = bgp_route_next (rn))
2770 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002771 {
2772 struct prefix_rd prd;
2773 prd.family = AF_UNSPEC;
2774 prd.prefixlen = 64;
2775 memcpy(&prd.val, rn->p.u.val, 8);
2776
2777 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2778 }
paulfee0f4c2004-09-13 05:12:46 +00002779}
David Lamparter6b0655a2014-06-04 06:53:35 +02002780
paulfee0f4c2004-09-13 05:12:46 +00002781static void
paul718e3742002-12-13 20:15:29 +00002782bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002783 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002784{
2785 int ret;
2786 struct bgp_node *rn;
2787 struct bgp_adj_in *ain;
2788
2789 if (! table)
2790 table = peer->bgp->rib[afi][safi];
2791
2792 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2793 for (ain = rn->adj_in; ain; ain = ain->next)
2794 {
2795 if (ain->peer == peer)
2796 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002797 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002798 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002799
paul718e3742002-12-13 20:15:29 +00002800 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2801 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002802 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002803
paul718e3742002-12-13 20:15:29 +00002804 if (ret < 0)
2805 {
2806 bgp_unlock_node (rn);
2807 return;
2808 }
2809 continue;
2810 }
2811 }
2812}
2813
2814void
2815bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2816{
2817 struct bgp_node *rn;
2818 struct bgp_table *table;
2819
2820 if (peer->status != Established)
2821 return;
2822
Lou Berger298cc2f2016-01-12 13:42:02 -05002823 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002824 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002825 else
2826 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2827 rn = bgp_route_next (rn))
2828 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002829 {
2830 struct prefix_rd prd;
2831 prd.family = AF_UNSPEC;
2832 prd.prefixlen = 64;
2833 memcpy(&prd.val, rn->p.u.val, 8);
2834
2835 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2836 }
paul718e3742002-12-13 20:15:29 +00002837}
David Lamparter6b0655a2014-06-04 06:53:35 +02002838
Chris Caputo228da422009-07-18 05:44:03 +00002839
2840struct bgp_clear_node_queue
2841{
2842 struct bgp_node *rn;
2843 enum bgp_clear_route_type purpose;
2844};
2845
paul200df112005-06-01 11:17:05 +00002846static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002847bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002848{
Chris Caputo228da422009-07-18 05:44:03 +00002849 struct bgp_clear_node_queue *cnq = data;
2850 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002851 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002852 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002853 afi_t afi = bgp_node_table (rn)->afi;
2854 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002855
Paul Jakma64e580a2006-02-21 01:09:01 +00002856 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002857
Paul Jakma64e580a2006-02-21 01:09:01 +00002858 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002859 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002860 {
2861 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002862 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2863 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002864 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002865 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2866 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002867 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002868 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002869 break;
2870 }
paul200df112005-06-01 11:17:05 +00002871 return WQ_SUCCESS;
2872}
2873
2874static void
paul0fb58d52005-11-14 14:31:49 +00002875bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002876{
Chris Caputo228da422009-07-18 05:44:03 +00002877 struct bgp_clear_node_queue *cnq = data;
2878 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002879 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002880
2881 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002882 bgp_table_unlock (table);
2883 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002884}
2885
2886static void
paul94f2b392005-06-28 12:44:16 +00002887bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002888{
Paul Jakma64e580a2006-02-21 01:09:01 +00002889 struct peer *peer = wq->spec.data;
2890
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002891 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002892 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002893
2894 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002895}
2896
2897static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002898bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002899{
Paul Jakmaa2943652009-07-21 14:02:04 +01002900 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002901
Paul Jakmaa2943652009-07-21 14:02:04 +01002902 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002903#undef CLEAR_QUEUE_NAME_LEN
2904
2905 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002906 {
2907 zlog_err ("%s: Failed to allocate work queue", __func__);
2908 exit (1);
2909 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002910 peer->clear_node_queue->spec.hold = 10;
2911 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2912 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2913 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2914 peer->clear_node_queue->spec.max_retries = 0;
2915
2916 /* we only 'lock' this peer reference when the queue is actually active */
2917 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002918}
2919
paul718e3742002-12-13 20:15:29 +00002920static void
2921bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002922 struct bgp_table *table, struct peer *rsclient,
2923 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002924{
2925 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002926
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002927
paul718e3742002-12-13 20:15:29 +00002928 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002929 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002930
hasso6cf159b2005-03-21 10:28:14 +00002931 /* If still no table => afi/safi isn't configured at all or smth. */
2932 if (! table)
2933 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002934
2935 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2936 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002937 struct bgp_info *ri;
2938 struct bgp_adj_in *ain;
2939 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002940
2941 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2942 * queued for every clearing peer, regardless of whether it is
2943 * relevant to the peer at hand.
2944 *
2945 * Overview: There are 3 different indices which need to be
2946 * scrubbed, potentially, when a peer is removed:
2947 *
2948 * 1 peer's routes visible via the RIB (ie accepted routes)
2949 * 2 peer's routes visible by the (optional) peer's adj-in index
2950 * 3 other routes visible by the peer's adj-out index
2951 *
2952 * 3 there is no hurry in scrubbing, once the struct peer is
2953 * removed from bgp->peer, we could just GC such deleted peer's
2954 * adj-outs at our leisure.
2955 *
2956 * 1 and 2 must be 'scrubbed' in some way, at least made
2957 * invisible via RIB index before peer session is allowed to be
2958 * brought back up. So one needs to know when such a 'search' is
2959 * complete.
2960 *
2961 * Ideally:
2962 *
2963 * - there'd be a single global queue or a single RIB walker
2964 * - rather than tracking which route_nodes still need to be
2965 * examined on a peer basis, we'd track which peers still
2966 * aren't cleared
2967 *
2968 * Given that our per-peer prefix-counts now should be reliable,
2969 * this may actually be achievable. It doesn't seem to be a huge
2970 * problem at this time,
2971 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002972 for (ain = rn->adj_in; ain; ain = ain->next)
2973 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2974 {
2975 bgp_adj_in_remove (rn, ain);
2976 bgp_unlock_node (rn);
2977 break;
2978 }
2979 for (aout = rn->adj_out; aout; aout = aout->next)
2980 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2981 {
2982 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2983 bgp_unlock_node (rn);
2984 break;
2985 }
2986
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002987 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002988 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002989 {
Chris Caputo228da422009-07-18 05:44:03 +00002990 struct bgp_clear_node_queue *cnq;
2991
2992 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002993 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002994 bgp_lock_node (rn);
2995 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2996 sizeof (struct bgp_clear_node_queue));
2997 cnq->rn = rn;
2998 cnq->purpose = purpose;
2999 work_queue_add (peer->clear_node_queue, cnq);
3000 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00003001 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00003002 }
3003 return;
3004}
3005
3006void
Chris Caputo228da422009-07-18 05:44:03 +00003007bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
3008 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00003009{
3010 struct bgp_node *rn;
3011 struct bgp_table *table;
3012 struct peer *rsclient;
3013 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00003014
Paul Jakma64e580a2006-02-21 01:09:01 +00003015 if (peer->clear_node_queue == NULL)
3016 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00003017
Paul Jakmaca058a32006-09-14 02:58:49 +00003018 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3019 * Idle until it receives a Clearing_Completed event. This protects
3020 * against peers which flap faster than we can we clear, which could
3021 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00003022 *
3023 * a) race with routes from the new session being installed before
3024 * clear_route_node visits the node (to delete the route of that
3025 * peer)
3026 * b) resource exhaustion, clear_route_node likely leads to an entry
3027 * on the process_main queue. Fast-flapping could cause that queue
3028 * to grow and grow.
paul200df112005-06-01 11:17:05 +00003029 */
Donald Sharp7ef42212015-03-30 06:32:52 -07003030
3031 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3032 * the unlock will happen upon work-queue completion; other wise, the
3033 * unlock happens at the end of this function.
3034 */
Paul Jakmaca058a32006-09-14 02:58:49 +00003035 if (!peer->clear_node_queue->thread)
Lou Berger050defe2016-01-12 13:41:59 -05003036 peer_lock (peer); /* bgp_clear_node_complete */
Chris Caputo228da422009-07-18 05:44:03 +00003037 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00003038 {
Chris Caputo228da422009-07-18 05:44:03 +00003039 case BGP_CLEAR_ROUTE_NORMAL:
Lou Berger298cc2f2016-01-12 13:42:02 -05003040 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Chris Caputo228da422009-07-18 05:44:03 +00003041 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
3042 else
3043 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3044 rn = bgp_route_next (rn))
3045 if ((table = rn->info) != NULL)
3046 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3047
3048 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
3049 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
3050 PEER_FLAG_RSERVER_CLIENT))
3051 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3052 break;
3053
3054 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
Lou Berger050defe2016-01-12 13:41:59 -05003055 /*
3056 * gpz 091009: TBD why don't we have special handling for
3057 * SAFI_MPLS_VPN here in the original quagga code?
3058 * (and, by extension, for SAFI_ENCAP)
3059 */
Chris Caputo228da422009-07-18 05:44:03 +00003060 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3061 break;
3062
3063 default:
3064 assert (0);
3065 break;
paulfee0f4c2004-09-13 05:12:46 +00003066 }
Donald Sharp7ef42212015-03-30 06:32:52 -07003067
3068 /* unlock if no nodes got added to the clear-node-queue. */
Paul Jakma65ca75e2006-05-04 08:08:15 +00003069 if (!peer->clear_node_queue->thread)
Donald Sharp7ef42212015-03-30 06:32:52 -07003070 peer_unlock (peer);
3071
paul718e3742002-12-13 20:15:29 +00003072}
3073
3074void
3075bgp_clear_route_all (struct peer *peer)
3076{
3077 afi_t afi;
3078 safi_t safi;
3079
3080 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3081 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003082 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003083}
3084
Lou Berger82dd7072016-01-12 13:41:57 -05003085/*
3086 * Finish freeing things when exiting
3087 */
3088static void
3089bgp_drain_workqueue_immediate (struct work_queue *wq)
3090{
3091 if (!wq)
3092 return;
3093
3094 if (!wq->thread)
3095 {
3096 /*
3097 * no thread implies no queued items
3098 */
3099 assert(!wq->items->count);
3100 return;
3101 }
3102
3103 while (wq->items->count)
3104 {
3105 if (wq->thread)
3106 thread_cancel(wq->thread);
3107 work_queue_run(wq->thread);
3108 }
3109}
3110
3111/*
3112 * Special function to process clear node queue when bgpd is exiting
3113 * and the thread scheduler is no longer running.
3114 */
3115void
3116bgp_peer_clear_node_queue_drain_immediate(struct peer *peer)
3117{
3118 if (!peer)
3119 return;
3120
3121 bgp_drain_workqueue_immediate(peer->clear_node_queue);
3122}
3123
3124/*
3125 * The work queues are not specific to a BGP instance, but the
3126 * items in them refer to BGP instances, so this should be called
3127 * before each BGP instance is deleted.
3128 */
3129void
3130bgp_process_queues_drain_immediate(void)
3131{
3132 bgp_drain_workqueue_immediate(bm->process_main_queue);
3133 bgp_drain_workqueue_immediate(bm->process_rsclient_queue);
3134}
3135
paul718e3742002-12-13 20:15:29 +00003136void
3137bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3138{
3139 struct bgp_table *table;
3140 struct bgp_node *rn;
3141 struct bgp_adj_in *ain;
3142
3143 table = peer->bgp->rib[afi][safi];
3144
3145 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3146 for (ain = rn->adj_in; ain ; ain = ain->next)
3147 if (ain->peer == peer)
3148 {
3149 bgp_adj_in_remove (rn, ain);
3150 bgp_unlock_node (rn);
3151 break;
3152 }
3153}
hasso93406d82005-02-02 14:40:33 +00003154
3155void
3156bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3157{
3158 struct bgp_node *rn;
3159 struct bgp_info *ri;
3160 struct bgp_table *table;
3161
3162 table = peer->bgp->rib[afi][safi];
3163
3164 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3165 {
3166 for (ri = rn->info; ri; ri = ri->next)
3167 if (ri->peer == peer)
3168 {
3169 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3170 bgp_rib_remove (rn, ri, peer, afi, safi);
3171 break;
3172 }
3173 }
3174}
David Lamparter6b0655a2014-06-04 06:53:35 +02003175
Lou Berger82dd7072016-01-12 13:41:57 -05003176static void
3177bgp_cleanup_table(struct bgp_table *table, safi_t safi)
3178{
3179 struct bgp_node *rn;
3180 struct bgp_info *ri;
3181 struct bgp_info *next;
3182
3183 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3184 for (ri = rn->info; ri; ri = next)
3185 {
3186 next = ri->next;
3187 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3188 && ri->type == ZEBRA_ROUTE_BGP
3189 && ri->sub_type == BGP_ROUTE_NORMAL)
3190 bgp_zebra_withdraw (&rn->p, ri, safi);
3191 }
3192}
3193
paul718e3742002-12-13 20:15:29 +00003194/* Delete all kernel routes. */
3195void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003196bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003197{
3198 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003199 struct listnode *node, *nnode;
Lou Berger82dd7072016-01-12 13:41:57 -05003200 afi_t afi;
paul718e3742002-12-13 20:15:29 +00003201
paul1eb8ef22005-04-07 07:30:20 +00003202 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003203 {
Lou Berger82dd7072016-01-12 13:41:57 -05003204 for (afi = AFI_IP; afi < AFI_MAX; ++afi)
3205 {
3206 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00003207
Lou Berger82dd7072016-01-12 13:41:57 -05003208 bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003209
Lou Berger82dd7072016-01-12 13:41:57 -05003210 /*
3211 * VPN and ENCAP tables are two-level (RD is top level)
3212 */
3213 for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn;
3214 rn = bgp_route_next (rn))
Lou Berger298cc2f2016-01-12 13:42:02 -05003215 {
3216 if (rn->info)
Lou Berger82dd7072016-01-12 13:41:57 -05003217 {
Lou Berger298cc2f2016-01-12 13:42:02 -05003218 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN);
3219 bgp_table_finish ((struct bgp_table **)&(rn->info));
3220 rn->info = NULL;
3221 bgp_unlock_node(rn);
Lou Berger82dd7072016-01-12 13:41:57 -05003222 }
Lou Berger298cc2f2016-01-12 13:42:02 -05003223 }
3224
3225 for (rn = bgp_table_top(bgp->rib[afi][SAFI_ENCAP]); rn;
3226 rn = bgp_route_next (rn))
3227 {
3228 if (rn->info)
3229 {
3230 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_ENCAP);
3231 bgp_table_finish ((struct bgp_table **)&(rn->info));
3232 rn->info = NULL;
3233 bgp_unlock_node(rn);
3234 }
3235 }
Lou Berger82dd7072016-01-12 13:41:57 -05003236 }
paul718e3742002-12-13 20:15:29 +00003237 }
3238}
3239
3240void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003241bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003242{
3243 vty_reset ();
3244 bgp_zclient_reset ();
3245 access_list_reset ();
3246 prefix_list_reset ();
3247}
David Lamparter6b0655a2014-06-04 06:53:35 +02003248
paul718e3742002-12-13 20:15:29 +00003249/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3250 value. */
3251int
3252bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3253{
3254 u_char *pnt;
3255 u_char *lim;
3256 struct prefix p;
3257 int psize;
3258 int ret;
3259
3260 /* Check peer status. */
3261 if (peer->status != Established)
3262 return 0;
3263
3264 pnt = packet->nlri;
3265 lim = pnt + packet->length;
3266
3267 for (; pnt < lim; pnt += psize)
3268 {
3269 /* Clear prefix structure. */
3270 memset (&p, 0, sizeof (struct prefix));
3271
3272 /* Fetch prefix length. */
3273 p.prefixlen = *pnt++;
3274 p.family = afi2family (packet->afi);
3275
3276 /* Already checked in nlri_sanity_check(). We do double check
3277 here. */
3278 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3279 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3280 return -1;
3281
3282 /* Packet size overflow check. */
3283 psize = PSIZE (p.prefixlen);
3284
3285 /* When packet overflow occur return immediately. */
3286 if (pnt + psize > lim)
3287 return -1;
3288
3289 /* Fetch prefix from NLRI packet. */
3290 memcpy (&p.u.prefix, pnt, psize);
3291
3292 /* Check address. */
3293 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3294 {
3295 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3296 {
paulf5ba3872004-07-09 12:11:31 +00003297 /*
3298 * From draft-ietf-idr-bgp4-22, Section 6.3:
3299 * If a BGP router receives an UPDATE message with a
3300 * semantically incorrect NLRI field, in which a prefix is
3301 * semantically incorrect (eg. an unexpected multicast IP
3302 * address), it should ignore the prefix.
3303 */
paul718e3742002-12-13 20:15:29 +00003304 zlog (peer->log, LOG_ERR,
3305 "IPv4 unicast NLRI is multicast address %s",
3306 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003307
paul718e3742002-12-13 20:15:29 +00003308 return -1;
3309 }
3310 }
3311
3312#ifdef HAVE_IPV6
3313 /* Check address. */
3314 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3315 {
3316 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3317 {
3318 char buf[BUFSIZ];
3319
3320 zlog (peer->log, LOG_WARNING,
3321 "IPv6 link-local NLRI received %s ignore this NLRI",
3322 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3323
3324 continue;
3325 }
3326 }
3327#endif /* HAVE_IPV6 */
3328
3329 /* Normal process. */
3330 if (attr)
3331 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3332 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3333 else
3334 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3335 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3336
3337 /* Address family configuration mismatch or maximum-prefix count
3338 overflow. */
3339 if (ret < 0)
3340 return -1;
3341 }
3342
3343 /* Packet length consistency check. */
3344 if (pnt != lim)
3345 return -1;
3346
3347 return 0;
3348}
3349
3350/* NLRI encode syntax check routine. */
3351int
Lou Berger050defe2016-01-12 13:41:59 -05003352bgp_nlri_sanity_check (struct peer *peer, int afi, safi_t safi,
3353 u_char *pnt, bgp_size_t length)
paul718e3742002-12-13 20:15:29 +00003354{
3355 u_char *end;
3356 u_char prefixlen;
3357 int psize;
3358
3359 end = pnt + length;
3360
3361 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3362 syntactic validity. If the field is syntactically incorrect,
3363 then the Error Subcode is set to Invalid Network Field. */
3364
3365 while (pnt < end)
3366 {
Lou Berger298cc2f2016-01-12 13:42:02 -05003367 int badlength;
paul718e3742002-12-13 20:15:29 +00003368 prefixlen = *pnt++;
3369
3370 /* Prefix length check. */
Lou Berger298cc2f2016-01-12 13:42:02 -05003371 badlength = 0;
3372 if (safi == SAFI_ENCAP) {
3373 if (prefixlen > 128)
3374 badlength = 1;
3375 } else {
3376 if ((afi == AFI_IP && prefixlen > 32) ||
3377 (afi == AFI_IP6 && prefixlen > 128)) {
3378
3379 badlength = 1;
3380 }
3381 }
3382 if (badlength)
paul718e3742002-12-13 20:15:29 +00003383 {
3384 plog_err (peer->log,
3385 "%s [Error] Update packet error (wrong prefix length %d)",
3386 peer->host, prefixlen);
3387 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3388 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3389 return -1;
3390 }
3391
3392 /* Packet size overflow check. */
3393 psize = PSIZE (prefixlen);
3394
3395 if (pnt + psize > end)
3396 {
3397 plog_err (peer->log,
3398 "%s [Error] Update packet error"
3399 " (prefix data overflow prefix size is %d)",
3400 peer->host, psize);
3401 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3402 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3403 return -1;
3404 }
3405
3406 pnt += psize;
3407 }
3408
3409 /* Packet length consistency check. */
3410 if (pnt != end)
3411 {
3412 plog_err (peer->log,
3413 "%s [Error] Update packet error"
3414 " (prefix length mismatch with total length)",
3415 peer->host);
3416 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3417 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3418 return -1;
3419 }
3420 return 0;
3421}
David Lamparter6b0655a2014-06-04 06:53:35 +02003422
paul94f2b392005-06-28 12:44:16 +00003423static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003424bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003425{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003426 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003427}
3428
paul94f2b392005-06-28 12:44:16 +00003429static void
paul718e3742002-12-13 20:15:29 +00003430bgp_static_free (struct bgp_static *bgp_static)
3431{
3432 if (bgp_static->rmap.name)
3433 free (bgp_static->rmap.name);
3434 XFREE (MTYPE_BGP_STATIC, bgp_static);
3435}
3436
paul94f2b392005-06-28 12:44:16 +00003437static void
paulfee0f4c2004-09-13 05:12:46 +00003438bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3439 struct prefix *p, afi_t afi, safi_t safi)
3440{
3441 struct bgp_node *rn;
3442 struct bgp_info *ri;
3443
3444 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3445
3446 /* Check selected route and self inserted route. */
3447 for (ri = rn->info; ri; ri = ri->next)
3448 if (ri->peer == bgp->peer_self
3449 && ri->type == ZEBRA_ROUTE_BGP
3450 && ri->sub_type == BGP_ROUTE_STATIC)
3451 break;
3452
3453 /* Withdraw static BGP route from routing table. */
3454 if (ri)
3455 {
paulfee0f4c2004-09-13 05:12:46 +00003456 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003457 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003458 }
3459
3460 /* Unlock bgp_node_lookup. */
3461 bgp_unlock_node (rn);
3462}
3463
paul94f2b392005-06-28 12:44:16 +00003464static void
paulfee0f4c2004-09-13 05:12:46 +00003465bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003466 struct bgp_static *bgp_static,
3467 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003468{
3469 struct bgp_node *rn;
3470 struct bgp_info *ri;
3471 struct bgp_info *new;
3472 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003473 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003474 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003475 struct attr new_attr;
3476 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003477 struct bgp *bgp;
3478 int ret;
3479 char buf[SU_ADDRSTRLEN];
3480
3481 bgp = rsclient->bgp;
3482
Paul Jakma06e110f2006-05-12 23:29:22 +00003483 assert (bgp_static);
3484 if (!bgp_static)
3485 return;
3486
paulfee0f4c2004-09-13 05:12:46 +00003487 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3488
3489 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003490
3491 attr.nexthop = bgp_static->igpnexthop;
3492 attr.med = bgp_static->igpmetric;
3493 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003494
Paul Jakma41367172007-08-06 15:24:51 +00003495 if (bgp_static->atomic)
3496 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3497
paulfee0f4c2004-09-13 05:12:46 +00003498 /* Apply network route-map for export to this rsclient. */
3499 if (bgp_static->rmap.name)
3500 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003501 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003502 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003503 info.attr = &attr_tmp;
3504
paulfee0f4c2004-09-13 05:12:46 +00003505 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3506 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3507
3508 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3509
3510 rsclient->rmap_type = 0;
3511
3512 if (ret == RMAP_DENYMATCH)
3513 {
3514 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003515 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003516
3517 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003518 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003519 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003520 bgp_attr_extra_free (&attr);
3521
paulfee0f4c2004-09-13 05:12:46 +00003522 return;
3523 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003524 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003525 }
3526 else
3527 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003528
3529 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003530 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003531
paulfee0f4c2004-09-13 05:12:46 +00003532 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3533
Paul Jakmafb982c22007-05-04 20:15:47 +00003534 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3535 == RMAP_DENY)
3536 {
paulfee0f4c2004-09-13 05:12:46 +00003537 /* This BGP update is filtered. Log the reason then update BGP entry. */
3538 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003539 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003540 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3541 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3542 p->prefixlen, rsclient->host);
3543
3544 bgp->peer_self->rmap_type = 0;
3545
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003546 bgp_attr_unintern (&attr_new);
3547 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003548 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003549
3550 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3551
3552 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003553 }
paulfee0f4c2004-09-13 05:12:46 +00003554
3555 bgp->peer_self->rmap_type = 0;
3556
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003557 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003558 attr_new = bgp_attr_intern (&new_attr);
3559
3560 for (ri = rn->info; ri; ri = ri->next)
3561 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3562 && ri->sub_type == BGP_ROUTE_STATIC)
3563 break;
3564
3565 if (ri)
3566 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003567 if (attrhash_cmp (ri->attr, attr_new) &&
3568 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003569 {
3570 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003571 bgp_attr_unintern (&attr_new);
3572 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003573 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003574 return;
3575 }
3576 else
3577 {
3578 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003579 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003580
3581 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003582 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3583 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003584 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003585 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003586 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003587
3588 /* Process change. */
3589 bgp_process (bgp, rn, afi, safi);
3590 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003591 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003592 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003593 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003594 }
paulfee0f4c2004-09-13 05:12:46 +00003595 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003596
paulfee0f4c2004-09-13 05:12:46 +00003597 /* Make new BGP info. */
3598 new = bgp_info_new ();
3599 new->type = ZEBRA_ROUTE_BGP;
3600 new->sub_type = BGP_ROUTE_STATIC;
3601 new->peer = bgp->peer_self;
3602 SET_FLAG (new->flags, BGP_INFO_VALID);
3603 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003604 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003605
3606 /* Register new BGP information. */
3607 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003608
3609 /* route_node_get lock */
3610 bgp_unlock_node (rn);
3611
paulfee0f4c2004-09-13 05:12:46 +00003612 /* Process change. */
3613 bgp_process (bgp, rn, afi, safi);
3614
3615 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003616 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003617 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003618}
3619
paul94f2b392005-06-28 12:44:16 +00003620static void
paulfee0f4c2004-09-13 05:12:46 +00003621bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003622 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3623{
3624 struct bgp_node *rn;
3625 struct bgp_info *ri;
3626 struct bgp_info *new;
3627 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003628 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003629 struct attr *attr_new;
3630 int ret;
3631
Paul Jakmadd8103a2006-05-12 23:27:30 +00003632 assert (bgp_static);
3633 if (!bgp_static)
3634 return;
3635
paulfee0f4c2004-09-13 05:12:46 +00003636 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003637
3638 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003639
3640 attr.nexthop = bgp_static->igpnexthop;
3641 attr.med = bgp_static->igpmetric;
3642 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003643
Paul Jakma41367172007-08-06 15:24:51 +00003644 if (bgp_static->atomic)
3645 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3646
paul718e3742002-12-13 20:15:29 +00003647 /* Apply route-map. */
3648 if (bgp_static->rmap.name)
3649 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003650 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003651 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003652 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003653
paulfee0f4c2004-09-13 05:12:46 +00003654 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3655
paul718e3742002-12-13 20:15:29 +00003656 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003657
paulfee0f4c2004-09-13 05:12:46 +00003658 bgp->peer_self->rmap_type = 0;
3659
paul718e3742002-12-13 20:15:29 +00003660 if (ret == RMAP_DENYMATCH)
3661 {
3662 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003663 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003664
3665 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003666 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003667 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003668 bgp_static_withdraw (bgp, p, afi, safi);
3669 return;
3670 }
paul286e1e72003-08-08 00:24:31 +00003671 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003672 }
paul286e1e72003-08-08 00:24:31 +00003673 else
3674 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003675
3676 for (ri = rn->info; ri; ri = ri->next)
3677 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3678 && ri->sub_type == BGP_ROUTE_STATIC)
3679 break;
3680
3681 if (ri)
3682 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003683 if (attrhash_cmp (ri->attr, attr_new) &&
3684 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003685 {
3686 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003687 bgp_attr_unintern (&attr_new);
3688 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003689 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003690 return;
3691 }
3692 else
3693 {
3694 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003695 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003696
3697 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003698 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3699 bgp_info_restore(rn, ri);
3700 else
3701 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003702 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003703 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003704 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003705
3706 /* Process change. */
3707 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3708 bgp_process (bgp, rn, afi, safi);
3709 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003710 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003711 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003712 return;
3713 }
3714 }
3715
3716 /* Make new BGP info. */
3717 new = bgp_info_new ();
3718 new->type = ZEBRA_ROUTE_BGP;
3719 new->sub_type = BGP_ROUTE_STATIC;
3720 new->peer = bgp->peer_self;
3721 SET_FLAG (new->flags, BGP_INFO_VALID);
3722 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003723 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003724
3725 /* Aggregate address increment. */
3726 bgp_aggregate_increment (bgp, p, new, afi, safi);
3727
3728 /* Register new BGP information. */
3729 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003730
3731 /* route_node_get lock */
3732 bgp_unlock_node (rn);
3733
paul718e3742002-12-13 20:15:29 +00003734 /* Process change. */
3735 bgp_process (bgp, rn, afi, safi);
3736
3737 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003738 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003739 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003740}
3741
3742void
paulfee0f4c2004-09-13 05:12:46 +00003743bgp_static_update (struct bgp *bgp, struct prefix *p,
3744 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3745{
3746 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003747 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003748
3749 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3750
paul1eb8ef22005-04-07 07:30:20 +00003751 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003752 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003753 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3754 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003755 }
3756}
3757
paul718e3742002-12-13 20:15:29 +00003758void
3759bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3760 safi_t safi)
3761{
3762 struct bgp_node *rn;
3763 struct bgp_info *ri;
3764
paulfee0f4c2004-09-13 05:12:46 +00003765 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003766
3767 /* Check selected route and self inserted route. */
3768 for (ri = rn->info; ri; ri = ri->next)
3769 if (ri->peer == bgp->peer_self
3770 && ri->type == ZEBRA_ROUTE_BGP
3771 && ri->sub_type == BGP_ROUTE_STATIC)
3772 break;
3773
3774 /* Withdraw static BGP route from routing table. */
3775 if (ri)
3776 {
3777 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003778 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003779 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003780 }
3781
3782 /* Unlock bgp_node_lookup. */
3783 bgp_unlock_node (rn);
3784}
3785
3786void
paulfee0f4c2004-09-13 05:12:46 +00003787bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3788{
3789 struct bgp_static *bgp_static;
3790 struct bgp *bgp;
3791 struct bgp_node *rn;
3792 struct prefix *p;
3793
3794 bgp = rsclient->bgp;
3795
3796 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3797 if ((bgp_static = rn->info) != NULL)
3798 {
3799 p = &rn->p;
3800
3801 bgp_static_update_rsclient (rsclient, p, bgp_static,
3802 afi, safi);
3803 }
3804}
3805
Lou Bergera76d9ca2016-01-12 13:41:53 -05003806/*
3807 * Used for SAFI_MPLS_VPN and SAFI_ENCAP
3808 */
paul94f2b392005-06-28 12:44:16 +00003809static void
Lou Bergera76d9ca2016-01-12 13:41:53 -05003810bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
3811 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003812{
3813 struct bgp_node *rn;
3814 struct bgp_info *ri;
3815
paulfee0f4c2004-09-13 05:12:46 +00003816 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003817
3818 /* Check selected route and self inserted route. */
3819 for (ri = rn->info; ri; ri = ri->next)
3820 if (ri->peer == bgp->peer_self
3821 && ri->type == ZEBRA_ROUTE_BGP
3822 && ri->sub_type == BGP_ROUTE_STATIC)
3823 break;
3824
3825 /* Withdraw static BGP route from routing table. */
3826 if (ri)
3827 {
3828 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003829 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003830 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003831 }
3832
3833 /* Unlock bgp_node_lookup. */
3834 bgp_unlock_node (rn);
3835}
3836
Lou Bergera76d9ca2016-01-12 13:41:53 -05003837static void
3838bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
3839 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3840{
3841 struct bgp_node *rn;
3842 struct bgp_info *new;
3843 struct attr *attr_new;
3844 struct attr attr = { 0 };
3845 struct bgp_info *ri;
3846
3847 assert (bgp_static);
3848
3849 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
3850
3851 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3852
3853 attr.nexthop = bgp_static->igpnexthop;
3854 attr.med = bgp_static->igpmetric;
3855 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3856
3857 /* Apply route-map. */
3858 if (bgp_static->rmap.name)
3859 {
3860 struct attr attr_tmp = attr;
3861 struct bgp_info info;
3862 int ret;
3863
3864 info.peer = bgp->peer_self;
3865 info.attr = &attr_tmp;
3866
3867 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3868
3869 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3870
3871 bgp->peer_self->rmap_type = 0;
3872
3873 if (ret == RMAP_DENYMATCH)
3874 {
3875 /* Free uninterned attribute. */
3876 bgp_attr_flush (&attr_tmp);
3877
3878 /* Unintern original. */
3879 aspath_unintern (&attr.aspath);
3880 bgp_attr_extra_free (&attr);
3881 bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
3882 bgp_static->tag);
3883 return;
3884 }
3885
3886 attr_new = bgp_attr_intern (&attr_tmp);
3887 }
3888 else
3889 {
3890 attr_new = bgp_attr_intern (&attr);
3891 }
3892
3893 for (ri = rn->info; ri; ri = ri->next)
3894 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3895 && ri->sub_type == BGP_ROUTE_STATIC)
3896 break;
3897
3898 if (ri)
3899 {
3900 if (attrhash_cmp (ri->attr, attr_new) &&
3901 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3902 {
3903 bgp_unlock_node (rn);
3904 bgp_attr_unintern (&attr_new);
3905 aspath_unintern (&attr.aspath);
3906 bgp_attr_extra_free (&attr);
3907 return;
3908 }
3909 else
3910 {
3911 /* The attribute is changed. */
3912 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3913
3914 /* Rewrite BGP route information. */
3915 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3916 bgp_info_restore(rn, ri);
3917 else
3918 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3919 bgp_attr_unintern (&ri->attr);
3920 ri->attr = attr_new;
3921 ri->uptime = bgp_clock ();
3922
3923 /* Process change. */
3924 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3925 bgp_process (bgp, rn, afi, safi);
3926 bgp_unlock_node (rn);
3927 aspath_unintern (&attr.aspath);
3928 bgp_attr_extra_free (&attr);
3929 return;
3930 }
3931 }
3932
3933
3934 /* Make new BGP info. */
3935 new = bgp_info_new ();
3936 new->type = ZEBRA_ROUTE_BGP;
3937 new->sub_type = BGP_ROUTE_STATIC;
3938 new->peer = bgp->peer_self;
3939 new->attr = attr_new;
3940 SET_FLAG (new->flags, BGP_INFO_VALID);
3941 new->uptime = bgp_clock ();
3942 new->extra = bgp_info_extra_new();
3943 memcpy (new->extra->tag, bgp_static->tag, 3);
3944
3945 /* Aggregate address increment. */
3946 bgp_aggregate_increment (bgp, p, new, afi, safi);
3947
3948 /* Register new BGP information. */
3949 bgp_info_add (rn, new);
3950
3951 /* route_node_get lock */
3952 bgp_unlock_node (rn);
3953
3954 /* Process change. */
3955 bgp_process (bgp, rn, afi, safi);
3956
3957 /* Unintern original. */
3958 aspath_unintern (&attr.aspath);
3959 bgp_attr_extra_free (&attr);
3960}
3961
paul718e3742002-12-13 20:15:29 +00003962/* Configure static BGP network. When user don't run zebra, static
3963 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003964static int
paulfd79ac92004-10-13 05:06:08 +00003965bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003966 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003967{
3968 int ret;
3969 struct prefix p;
3970 struct bgp_static *bgp_static;
3971 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003972 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003973
3974 /* Convert IP prefix string to struct prefix. */
3975 ret = str2prefix (ip_str, &p);
3976 if (! ret)
3977 {
3978 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3979 return CMD_WARNING;
3980 }
3981#ifdef HAVE_IPV6
3982 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3983 {
3984 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3985 VTY_NEWLINE);
3986 return CMD_WARNING;
3987 }
3988#endif /* HAVE_IPV6 */
3989
3990 apply_mask (&p);
3991
3992 /* Set BGP static route configuration. */
3993 rn = bgp_node_get (bgp->route[afi][safi], &p);
3994
3995 if (rn->info)
3996 {
3997 /* Configuration change. */
3998 bgp_static = rn->info;
3999
4000 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004001 if (bgp_static->valid && bgp_static->backdoor != backdoor)
4002 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00004003
paul718e3742002-12-13 20:15:29 +00004004 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00004005
paul718e3742002-12-13 20:15:29 +00004006 if (rmap)
4007 {
4008 if (bgp_static->rmap.name)
4009 free (bgp_static->rmap.name);
4010 bgp_static->rmap.name = strdup (rmap);
4011 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4012 }
4013 else
4014 {
4015 if (bgp_static->rmap.name)
4016 free (bgp_static->rmap.name);
4017 bgp_static->rmap.name = NULL;
4018 bgp_static->rmap.map = NULL;
4019 bgp_static->valid = 0;
4020 }
4021 bgp_unlock_node (rn);
4022 }
4023 else
4024 {
4025 /* New configuration. */
4026 bgp_static = bgp_static_new ();
4027 bgp_static->backdoor = backdoor;
4028 bgp_static->valid = 0;
4029 bgp_static->igpmetric = 0;
4030 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00004031
paul718e3742002-12-13 20:15:29 +00004032 if (rmap)
4033 {
4034 if (bgp_static->rmap.name)
4035 free (bgp_static->rmap.name);
4036 bgp_static->rmap.name = strdup (rmap);
4037 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4038 }
4039 rn->info = bgp_static;
4040 }
4041
4042 /* If BGP scan is not enabled, we should install this route here. */
4043 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
4044 {
4045 bgp_static->valid = 1;
4046
4047 if (need_update)
4048 bgp_static_withdraw (bgp, &p, afi, safi);
4049
4050 if (! bgp_static->backdoor)
4051 bgp_static_update (bgp, &p, bgp_static, afi, safi);
4052 }
4053
4054 return CMD_SUCCESS;
4055}
4056
4057/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00004058static int
paulfd79ac92004-10-13 05:06:08 +00004059bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04004060 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004061{
4062 int ret;
4063 struct prefix p;
4064 struct bgp_static *bgp_static;
4065 struct bgp_node *rn;
4066
4067 /* Convert IP prefix string to struct prefix. */
4068 ret = str2prefix (ip_str, &p);
4069 if (! ret)
4070 {
4071 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4072 return CMD_WARNING;
4073 }
4074#ifdef HAVE_IPV6
4075 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4076 {
4077 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4078 VTY_NEWLINE);
4079 return CMD_WARNING;
4080 }
4081#endif /* HAVE_IPV6 */
4082
4083 apply_mask (&p);
4084
4085 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4086 if (! rn)
4087 {
4088 vty_out (vty, "%% Can't find specified static route configuration.%s",
4089 VTY_NEWLINE);
4090 return CMD_WARNING;
4091 }
4092
4093 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00004094
paul718e3742002-12-13 20:15:29 +00004095 /* Update BGP RIB. */
4096 if (! bgp_static->backdoor)
4097 bgp_static_withdraw (bgp, &p, afi, safi);
4098
4099 /* Clear configuration. */
4100 bgp_static_free (bgp_static);
4101 rn->info = NULL;
4102 bgp_unlock_node (rn);
4103 bgp_unlock_node (rn);
4104
4105 return CMD_SUCCESS;
4106}
4107
4108/* Called from bgp_delete(). Delete all static routes from the BGP
4109 instance. */
4110void
4111bgp_static_delete (struct bgp *bgp)
4112{
4113 afi_t afi;
4114 safi_t safi;
4115 struct bgp_node *rn;
4116 struct bgp_node *rm;
4117 struct bgp_table *table;
4118 struct bgp_static *bgp_static;
4119
4120 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4121 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4122 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4123 if (rn->info != NULL)
4124 {
Lou Berger298cc2f2016-01-12 13:42:02 -05004125 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004126 {
4127 table = rn->info;
4128
4129 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4130 {
4131 bgp_static = rn->info;
Lou Bergera76d9ca2016-01-12 13:41:53 -05004132 bgp_static_withdraw_safi (bgp, &rm->p,
4133 AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00004134 (struct prefix_rd *)&rn->p,
4135 bgp_static->tag);
4136 bgp_static_free (bgp_static);
4137 rn->info = NULL;
4138 bgp_unlock_node (rn);
4139 }
4140 }
4141 else
4142 {
4143 bgp_static = rn->info;
4144 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4145 bgp_static_free (bgp_static);
4146 rn->info = NULL;
4147 bgp_unlock_node (rn);
4148 }
4149 }
4150}
4151
Lou Bergera76d9ca2016-01-12 13:41:53 -05004152/*
4153 * gpz 110624
4154 * Currently this is used to set static routes for VPN and ENCAP.
4155 * I think it can probably be factored with bgp_static_set.
4156 */
paul718e3742002-12-13 20:15:29 +00004157int
Lou Bergera76d9ca2016-01-12 13:41:53 -05004158bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
4159 const char *rd_str, const char *tag_str,
4160 const char *rmap_str)
paul718e3742002-12-13 20:15:29 +00004161{
4162 int ret;
4163 struct prefix p;
4164 struct prefix_rd prd;
4165 struct bgp *bgp;
4166 struct bgp_node *prn;
4167 struct bgp_node *rn;
4168 struct bgp_table *table;
4169 struct bgp_static *bgp_static;
4170 u_char tag[3];
4171
4172 bgp = vty->index;
4173
4174 ret = str2prefix (ip_str, &p);
4175 if (! ret)
4176 {
4177 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4178 return CMD_WARNING;
4179 }
4180 apply_mask (&p);
4181
4182 ret = str2prefix_rd (rd_str, &prd);
4183 if (! ret)
4184 {
4185 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4186 return CMD_WARNING;
4187 }
4188
4189 ret = str2tag (tag_str, tag);
4190 if (! ret)
4191 {
4192 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4193 return CMD_WARNING;
4194 }
4195
Lou Bergera76d9ca2016-01-12 13:41:53 -05004196 prn = bgp_node_get (bgp->route[AFI_IP][safi],
paul718e3742002-12-13 20:15:29 +00004197 (struct prefix *)&prd);
4198 if (prn->info == NULL)
Lou Bergera76d9ca2016-01-12 13:41:53 -05004199 prn->info = bgp_table_init (AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004200 else
4201 bgp_unlock_node (prn);
4202 table = prn->info;
4203
4204 rn = bgp_node_get (table, &p);
4205
4206 if (rn->info)
4207 {
4208 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4209 bgp_unlock_node (rn);
4210 }
4211 else
4212 {
4213 /* New configuration. */
4214 bgp_static = bgp_static_new ();
Lou Bergera76d9ca2016-01-12 13:41:53 -05004215 bgp_static->backdoor = 0;
4216 bgp_static->valid = 0;
4217 bgp_static->igpmetric = 0;
4218 bgp_static->igpnexthop.s_addr = 0;
4219 memcpy(bgp_static->tag, tag, 3);
4220 bgp_static->prd = prd;
4221
4222 if (rmap_str)
4223 {
4224 if (bgp_static->rmap.name)
4225 free (bgp_static->rmap.name);
4226 bgp_static->rmap.name = strdup (rmap_str);
4227 bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
4228 }
paul718e3742002-12-13 20:15:29 +00004229 rn->info = bgp_static;
4230
Lou Bergera76d9ca2016-01-12 13:41:53 -05004231 bgp_static->valid = 1;
4232 bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004233 }
4234
4235 return CMD_SUCCESS;
4236}
4237
4238/* Configure static BGP network. */
4239int
Lou Bergera76d9ca2016-01-12 13:41:53 -05004240bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
4241 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00004242{
4243 int ret;
4244 struct bgp *bgp;
4245 struct prefix p;
4246 struct prefix_rd prd;
4247 struct bgp_node *prn;
4248 struct bgp_node *rn;
4249 struct bgp_table *table;
4250 struct bgp_static *bgp_static;
4251 u_char tag[3];
4252
4253 bgp = vty->index;
4254
4255 /* Convert IP prefix string to struct prefix. */
4256 ret = str2prefix (ip_str, &p);
4257 if (! ret)
4258 {
4259 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4260 return CMD_WARNING;
4261 }
4262 apply_mask (&p);
4263
4264 ret = str2prefix_rd (rd_str, &prd);
4265 if (! ret)
4266 {
4267 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4268 return CMD_WARNING;
4269 }
4270
4271 ret = str2tag (tag_str, tag);
4272 if (! ret)
4273 {
4274 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4275 return CMD_WARNING;
4276 }
4277
Lou Bergera76d9ca2016-01-12 13:41:53 -05004278 prn = bgp_node_get (bgp->route[AFI_IP][safi],
paul718e3742002-12-13 20:15:29 +00004279 (struct prefix *)&prd);
4280 if (prn->info == NULL)
Lou Bergera76d9ca2016-01-12 13:41:53 -05004281 prn->info = bgp_table_init (AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004282 else
4283 bgp_unlock_node (prn);
4284 table = prn->info;
4285
4286 rn = bgp_node_lookup (table, &p);
4287
4288 if (rn)
4289 {
Lou Bergera76d9ca2016-01-12 13:41:53 -05004290 bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
paul718e3742002-12-13 20:15:29 +00004291
4292 bgp_static = rn->info;
4293 bgp_static_free (bgp_static);
4294 rn->info = NULL;
4295 bgp_unlock_node (rn);
4296 bgp_unlock_node (rn);
4297 }
4298 else
4299 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4300
4301 return CMD_SUCCESS;
4302}
David Lamparter6b0655a2014-06-04 06:53:35 +02004303
paul718e3742002-12-13 20:15:29 +00004304DEFUN (bgp_network,
4305 bgp_network_cmd,
4306 "network A.B.C.D/M",
4307 "Specify a network to announce via BGP\n"
4308 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4309{
4310 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004311 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004312}
4313
4314DEFUN (bgp_network_route_map,
4315 bgp_network_route_map_cmd,
4316 "network A.B.C.D/M route-map WORD",
4317 "Specify a network to announce via BGP\n"
4318 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4319 "Route-map to modify the attributes\n"
4320 "Name of the route map\n")
4321{
4322 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004323 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004324}
4325
4326DEFUN (bgp_network_backdoor,
4327 bgp_network_backdoor_cmd,
4328 "network A.B.C.D/M backdoor",
4329 "Specify a network to announce via BGP\n"
4330 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4331 "Specify a BGP backdoor route\n")
4332{
Paul Jakma41367172007-08-06 15:24:51 +00004333 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004334 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004335}
4336
4337DEFUN (bgp_network_mask,
4338 bgp_network_mask_cmd,
4339 "network A.B.C.D mask A.B.C.D",
4340 "Specify a network to announce via BGP\n"
4341 "Network number\n"
4342 "Network mask\n"
4343 "Network mask\n")
4344{
4345 int ret;
4346 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004347
paul718e3742002-12-13 20:15:29 +00004348 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4349 if (! ret)
4350 {
4351 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4352 return CMD_WARNING;
4353 }
4354
4355 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004356 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004357}
4358
4359DEFUN (bgp_network_mask_route_map,
4360 bgp_network_mask_route_map_cmd,
4361 "network A.B.C.D mask A.B.C.D route-map WORD",
4362 "Specify a network to announce via BGP\n"
4363 "Network number\n"
4364 "Network mask\n"
4365 "Network mask\n"
4366 "Route-map to modify the attributes\n"
4367 "Name of the route map\n")
4368{
4369 int ret;
4370 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004371
paul718e3742002-12-13 20:15:29 +00004372 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4373 if (! ret)
4374 {
4375 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4376 return CMD_WARNING;
4377 }
4378
4379 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004380 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004381}
4382
4383DEFUN (bgp_network_mask_backdoor,
4384 bgp_network_mask_backdoor_cmd,
4385 "network A.B.C.D mask A.B.C.D backdoor",
4386 "Specify a network to announce via BGP\n"
4387 "Network number\n"
4388 "Network mask\n"
4389 "Network mask\n"
4390 "Specify a BGP backdoor route\n")
4391{
4392 int ret;
4393 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004394
paul718e3742002-12-13 20:15:29 +00004395 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4396 if (! ret)
4397 {
4398 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4399 return CMD_WARNING;
4400 }
4401
Paul Jakma41367172007-08-06 15:24:51 +00004402 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004403 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004404}
4405
4406DEFUN (bgp_network_mask_natural,
4407 bgp_network_mask_natural_cmd,
4408 "network A.B.C.D",
4409 "Specify a network to announce via BGP\n"
4410 "Network number\n")
4411{
4412 int ret;
4413 char prefix_str[BUFSIZ];
4414
4415 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4416 if (! ret)
4417 {
4418 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4419 return CMD_WARNING;
4420 }
4421
4422 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004423 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004424}
4425
4426DEFUN (bgp_network_mask_natural_route_map,
4427 bgp_network_mask_natural_route_map_cmd,
4428 "network A.B.C.D route-map WORD",
4429 "Specify a network to announce via BGP\n"
4430 "Network number\n"
4431 "Route-map to modify the attributes\n"
4432 "Name of the route map\n")
4433{
4434 int ret;
4435 char prefix_str[BUFSIZ];
4436
4437 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4438 if (! ret)
4439 {
4440 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4441 return CMD_WARNING;
4442 }
4443
4444 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004445 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004446}
4447
4448DEFUN (bgp_network_mask_natural_backdoor,
4449 bgp_network_mask_natural_backdoor_cmd,
4450 "network A.B.C.D backdoor",
4451 "Specify a network to announce via BGP\n"
4452 "Network number\n"
4453 "Specify a BGP backdoor route\n")
4454{
4455 int ret;
4456 char prefix_str[BUFSIZ];
4457
4458 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4459 if (! ret)
4460 {
4461 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4462 return CMD_WARNING;
4463 }
4464
Paul Jakma41367172007-08-06 15:24:51 +00004465 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004466 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004467}
4468
4469DEFUN (no_bgp_network,
4470 no_bgp_network_cmd,
4471 "no network A.B.C.D/M",
4472 NO_STR
4473 "Specify a network to announce via BGP\n"
4474 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4475{
4476 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4477 bgp_node_safi (vty));
4478}
4479
4480ALIAS (no_bgp_network,
4481 no_bgp_network_route_map_cmd,
4482 "no network A.B.C.D/M route-map WORD",
4483 NO_STR
4484 "Specify a network to announce via BGP\n"
4485 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4486 "Route-map to modify the attributes\n"
4487 "Name of the route map\n")
4488
4489ALIAS (no_bgp_network,
4490 no_bgp_network_backdoor_cmd,
4491 "no network A.B.C.D/M backdoor",
4492 NO_STR
4493 "Specify a network to announce via BGP\n"
4494 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4495 "Specify a BGP backdoor route\n")
4496
4497DEFUN (no_bgp_network_mask,
4498 no_bgp_network_mask_cmd,
4499 "no network A.B.C.D mask A.B.C.D",
4500 NO_STR
4501 "Specify a network to announce via BGP\n"
4502 "Network number\n"
4503 "Network mask\n"
4504 "Network mask\n")
4505{
4506 int ret;
4507 char prefix_str[BUFSIZ];
4508
4509 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4510 if (! ret)
4511 {
4512 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4513 return CMD_WARNING;
4514 }
4515
4516 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4517 bgp_node_safi (vty));
4518}
4519
4520ALIAS (no_bgp_network_mask,
4521 no_bgp_network_mask_route_map_cmd,
4522 "no network A.B.C.D mask A.B.C.D route-map WORD",
4523 NO_STR
4524 "Specify a network to announce via BGP\n"
4525 "Network number\n"
4526 "Network mask\n"
4527 "Network mask\n"
4528 "Route-map to modify the attributes\n"
4529 "Name of the route map\n")
4530
4531ALIAS (no_bgp_network_mask,
4532 no_bgp_network_mask_backdoor_cmd,
4533 "no network A.B.C.D mask A.B.C.D backdoor",
4534 NO_STR
4535 "Specify a network to announce via BGP\n"
4536 "Network number\n"
4537 "Network mask\n"
4538 "Network mask\n"
4539 "Specify a BGP backdoor route\n")
4540
4541DEFUN (no_bgp_network_mask_natural,
4542 no_bgp_network_mask_natural_cmd,
4543 "no network A.B.C.D",
4544 NO_STR
4545 "Specify a network to announce via BGP\n"
4546 "Network number\n")
4547{
4548 int ret;
4549 char prefix_str[BUFSIZ];
4550
4551 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4552 if (! ret)
4553 {
4554 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4555 return CMD_WARNING;
4556 }
4557
4558 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4559 bgp_node_safi (vty));
4560}
4561
4562ALIAS (no_bgp_network_mask_natural,
4563 no_bgp_network_mask_natural_route_map_cmd,
4564 "no network A.B.C.D route-map WORD",
4565 NO_STR
4566 "Specify a network to announce via BGP\n"
4567 "Network number\n"
4568 "Route-map to modify the attributes\n"
4569 "Name of the route map\n")
4570
4571ALIAS (no_bgp_network_mask_natural,
4572 no_bgp_network_mask_natural_backdoor_cmd,
4573 "no network A.B.C.D backdoor",
4574 NO_STR
4575 "Specify a network to announce via BGP\n"
4576 "Network number\n"
4577 "Specify a BGP backdoor route\n")
4578
4579#ifdef HAVE_IPV6
4580DEFUN (ipv6_bgp_network,
4581 ipv6_bgp_network_cmd,
4582 "network X:X::X:X/M",
4583 "Specify a network to announce via BGP\n"
4584 "IPv6 prefix <network>/<length>\n")
4585{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304586 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004587 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004588}
4589
4590DEFUN (ipv6_bgp_network_route_map,
4591 ipv6_bgp_network_route_map_cmd,
4592 "network X:X::X:X/M route-map WORD",
4593 "Specify a network to announce via BGP\n"
4594 "IPv6 prefix <network>/<length>\n"
4595 "Route-map to modify the attributes\n"
4596 "Name of the route map\n")
4597{
4598 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004599 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004600}
4601
4602DEFUN (no_ipv6_bgp_network,
4603 no_ipv6_bgp_network_cmd,
4604 "no network X:X::X:X/M",
4605 NO_STR
4606 "Specify a network to announce via BGP\n"
4607 "IPv6 prefix <network>/<length>\n")
4608{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304609 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004610}
4611
4612ALIAS (no_ipv6_bgp_network,
4613 no_ipv6_bgp_network_route_map_cmd,
4614 "no network X:X::X:X/M route-map WORD",
4615 NO_STR
4616 "Specify a network to announce via BGP\n"
4617 "IPv6 prefix <network>/<length>\n"
4618 "Route-map to modify the attributes\n"
4619 "Name of the route map\n")
4620
4621ALIAS (ipv6_bgp_network,
4622 old_ipv6_bgp_network_cmd,
4623 "ipv6 bgp network X:X::X:X/M",
4624 IPV6_STR
4625 BGP_STR
4626 "Specify a network to announce via BGP\n"
4627 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4628
4629ALIAS (no_ipv6_bgp_network,
4630 old_no_ipv6_bgp_network_cmd,
4631 "no ipv6 bgp network X:X::X:X/M",
4632 NO_STR
4633 IPV6_STR
4634 BGP_STR
4635 "Specify a network to announce via BGP\n"
4636 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4637#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004638
4639/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4640ALIAS_DEPRECATED (bgp_network,
4641 bgp_network_ttl_cmd,
4642 "network A.B.C.D/M pathlimit <0-255>",
4643 "Specify a network to announce via BGP\n"
4644 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4645 "AS-Path hopcount limit attribute\n"
4646 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4647ALIAS_DEPRECATED (bgp_network_backdoor,
4648 bgp_network_backdoor_ttl_cmd,
4649 "network A.B.C.D/M backdoor pathlimit <0-255>",
4650 "Specify a network to announce via BGP\n"
4651 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4652 "Specify a BGP backdoor route\n"
4653 "AS-Path hopcount limit attribute\n"
4654 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4655ALIAS_DEPRECATED (bgp_network_mask,
4656 bgp_network_mask_ttl_cmd,
4657 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4658 "Specify a network to announce via BGP\n"
4659 "Network number\n"
4660 "Network mask\n"
4661 "Network mask\n"
4662 "AS-Path hopcount limit attribute\n"
4663 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4664ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4665 bgp_network_mask_backdoor_ttl_cmd,
4666 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4667 "Specify a network to announce via BGP\n"
4668 "Network number\n"
4669 "Network mask\n"
4670 "Network mask\n"
4671 "Specify a BGP backdoor route\n"
4672 "AS-Path hopcount limit attribute\n"
4673 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4674ALIAS_DEPRECATED (bgp_network_mask_natural,
4675 bgp_network_mask_natural_ttl_cmd,
4676 "network A.B.C.D pathlimit <0-255>",
4677 "Specify a network to announce via BGP\n"
4678 "Network number\n"
4679 "AS-Path hopcount limit attribute\n"
4680 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4681ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4682 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004683 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004684 "Specify a network to announce via BGP\n"
4685 "Network number\n"
4686 "Specify a BGP backdoor route\n"
4687 "AS-Path hopcount limit attribute\n"
4688 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4689ALIAS_DEPRECATED (no_bgp_network,
4690 no_bgp_network_ttl_cmd,
4691 "no network A.B.C.D/M pathlimit <0-255>",
4692 NO_STR
4693 "Specify a network to announce via BGP\n"
4694 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4695 "AS-Path hopcount limit attribute\n"
4696 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4697ALIAS_DEPRECATED (no_bgp_network,
4698 no_bgp_network_backdoor_ttl_cmd,
4699 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4700 NO_STR
4701 "Specify a network to announce via BGP\n"
4702 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4703 "Specify a BGP backdoor route\n"
4704 "AS-Path hopcount limit attribute\n"
4705 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4706ALIAS_DEPRECATED (no_bgp_network,
4707 no_bgp_network_mask_ttl_cmd,
4708 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4709 NO_STR
4710 "Specify a network to announce via BGP\n"
4711 "Network number\n"
4712 "Network mask\n"
4713 "Network mask\n"
4714 "AS-Path hopcount limit attribute\n"
4715 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4716ALIAS_DEPRECATED (no_bgp_network_mask,
4717 no_bgp_network_mask_backdoor_ttl_cmd,
4718 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4719 NO_STR
4720 "Specify a network to announce via BGP\n"
4721 "Network number\n"
4722 "Network mask\n"
4723 "Network mask\n"
4724 "Specify a BGP backdoor route\n"
4725 "AS-Path hopcount limit attribute\n"
4726 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4727ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4728 no_bgp_network_mask_natural_ttl_cmd,
4729 "no network A.B.C.D pathlimit <0-255>",
4730 NO_STR
4731 "Specify a network to announce via BGP\n"
4732 "Network number\n"
4733 "AS-Path hopcount limit attribute\n"
4734 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4735ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4736 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4737 "no network A.B.C.D backdoor pathlimit <0-255>",
4738 NO_STR
4739 "Specify a network to announce via BGP\n"
4740 "Network number\n"
4741 "Specify a BGP backdoor route\n"
4742 "AS-Path hopcount limit attribute\n"
4743 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004744#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004745ALIAS_DEPRECATED (ipv6_bgp_network,
4746 ipv6_bgp_network_ttl_cmd,
4747 "network X:X::X:X/M pathlimit <0-255>",
4748 "Specify a network to announce via BGP\n"
4749 "IPv6 prefix <network>/<length>\n"
4750 "AS-Path hopcount limit attribute\n"
4751 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4752ALIAS_DEPRECATED (no_ipv6_bgp_network,
4753 no_ipv6_bgp_network_ttl_cmd,
4754 "no network X:X::X:X/M pathlimit <0-255>",
4755 NO_STR
4756 "Specify a network to announce via BGP\n"
4757 "IPv6 prefix <network>/<length>\n"
4758 "AS-Path hopcount limit attribute\n"
4759 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004760#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02004761
paul718e3742002-12-13 20:15:29 +00004762/* Aggreagete address:
4763
4764 advertise-map Set condition to advertise attribute
4765 as-set Generate AS set path information
4766 attribute-map Set attributes of aggregate
4767 route-map Set parameters of aggregate
4768 summary-only Filter more specific routes from updates
4769 suppress-map Conditionally filter more specific routes from updates
4770 <cr>
4771 */
4772struct bgp_aggregate
4773{
4774 /* Summary-only flag. */
4775 u_char summary_only;
4776
4777 /* AS set generation. */
4778 u_char as_set;
4779
4780 /* Route-map for aggregated route. */
4781 struct route_map *map;
4782
4783 /* Suppress-count. */
4784 unsigned long count;
4785
4786 /* SAFI configuration. */
4787 safi_t safi;
4788};
4789
paul94f2b392005-06-28 12:44:16 +00004790static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004791bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004792{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004793 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004794}
4795
paul94f2b392005-06-28 12:44:16 +00004796static void
paul718e3742002-12-13 20:15:29 +00004797bgp_aggregate_free (struct bgp_aggregate *aggregate)
4798{
4799 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4800}
4801
paul94f2b392005-06-28 12:44:16 +00004802static void
paul718e3742002-12-13 20:15:29 +00004803bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4804 afi_t afi, safi_t safi, struct bgp_info *del,
4805 struct bgp_aggregate *aggregate)
4806{
4807 struct bgp_table *table;
4808 struct bgp_node *top;
4809 struct bgp_node *rn;
4810 u_char origin;
4811 struct aspath *aspath = NULL;
4812 struct aspath *asmerge = NULL;
4813 struct community *community = NULL;
4814 struct community *commerge = NULL;
paul718e3742002-12-13 20:15:29 +00004815 struct bgp_info *ri;
4816 struct bgp_info *new;
4817 int first = 1;
4818 unsigned long match = 0;
4819
paul718e3742002-12-13 20:15:29 +00004820 /* ORIGIN attribute: If at least one route among routes that are
4821 aggregated has ORIGIN with the value INCOMPLETE, then the
4822 aggregated route must have the ORIGIN attribute with the value
4823 INCOMPLETE. Otherwise, if at least one route among routes that
4824 are aggregated has ORIGIN with the value EGP, then the aggregated
4825 route must have the origin attribute with the value EGP. In all
4826 other case the value of the ORIGIN attribute of the aggregated
4827 route is INTERNAL. */
4828 origin = BGP_ORIGIN_IGP;
4829
4830 table = bgp->rib[afi][safi];
4831
4832 top = bgp_node_get (table, p);
4833 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4834 if (rn->p.prefixlen > p->prefixlen)
4835 {
4836 match = 0;
4837
4838 for (ri = rn->info; ri; ri = ri->next)
4839 {
4840 if (BGP_INFO_HOLDDOWN (ri))
4841 continue;
4842
4843 if (del && ri == del)
4844 continue;
4845
4846 if (! rinew && first)
Paul Jakma7aa9dce2014-09-19 14:42:23 +01004847 first = 0;
paul718e3742002-12-13 20:15:29 +00004848
4849#ifdef AGGREGATE_NEXTHOP_CHECK
4850 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4851 || ri->attr->med != med)
4852 {
4853 if (aspath)
4854 aspath_free (aspath);
4855 if (community)
4856 community_free (community);
4857 bgp_unlock_node (rn);
4858 bgp_unlock_node (top);
4859 return;
4860 }
4861#endif /* AGGREGATE_NEXTHOP_CHECK */
4862
4863 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4864 {
4865 if (aggregate->summary_only)
4866 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004867 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004868 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004869 match++;
4870 }
4871
4872 aggregate->count++;
4873
4874 if (aggregate->as_set)
4875 {
4876 if (origin < ri->attr->origin)
4877 origin = ri->attr->origin;
4878
4879 if (aspath)
4880 {
4881 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4882 aspath_free (aspath);
4883 aspath = asmerge;
4884 }
4885 else
4886 aspath = aspath_dup (ri->attr->aspath);
4887
4888 if (ri->attr->community)
4889 {
4890 if (community)
4891 {
4892 commerge = community_merge (community,
4893 ri->attr->community);
4894 community = community_uniq_sort (commerge);
4895 community_free (commerge);
4896 }
4897 else
4898 community = community_dup (ri->attr->community);
4899 }
4900 }
4901 }
4902 }
4903 if (match)
4904 bgp_process (bgp, rn, afi, safi);
4905 }
4906 bgp_unlock_node (top);
4907
4908 if (rinew)
4909 {
4910 aggregate->count++;
4911
4912 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004913 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004914
4915 if (aggregate->as_set)
4916 {
4917 if (origin < rinew->attr->origin)
4918 origin = rinew->attr->origin;
4919
4920 if (aspath)
4921 {
4922 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4923 aspath_free (aspath);
4924 aspath = asmerge;
4925 }
4926 else
4927 aspath = aspath_dup (rinew->attr->aspath);
4928
4929 if (rinew->attr->community)
4930 {
4931 if (community)
4932 {
4933 commerge = community_merge (community,
4934 rinew->attr->community);
4935 community = community_uniq_sort (commerge);
4936 community_free (commerge);
4937 }
4938 else
4939 community = community_dup (rinew->attr->community);
4940 }
4941 }
4942 }
4943
4944 if (aggregate->count > 0)
4945 {
4946 rn = bgp_node_get (table, p);
4947 new = bgp_info_new ();
4948 new->type = ZEBRA_ROUTE_BGP;
4949 new->sub_type = BGP_ROUTE_AGGREGATE;
4950 new->peer = bgp->peer_self;
4951 SET_FLAG (new->flags, BGP_INFO_VALID);
4952 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004953 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004954
4955 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004956 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004957 bgp_process (bgp, rn, afi, safi);
4958 }
4959 else
4960 {
4961 if (aspath)
4962 aspath_free (aspath);
4963 if (community)
4964 community_free (community);
4965 }
4966}
4967
4968void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4969 struct bgp_aggregate *);
4970
4971void
4972bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4973 struct bgp_info *ri, afi_t afi, safi_t safi)
4974{
4975 struct bgp_node *child;
4976 struct bgp_node *rn;
4977 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004978 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004979
4980 /* MPLS-VPN aggregation is not yet supported. */
Lou Berger298cc2f2016-01-12 13:42:02 -05004981 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004982 return;
4983
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004984 table = bgp->aggregate[afi][safi];
4985
4986 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004987 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004988 return;
4989
paul718e3742002-12-13 20:15:29 +00004990 if (p->prefixlen == 0)
4991 return;
4992
4993 if (BGP_INFO_HOLDDOWN (ri))
4994 return;
4995
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004996 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004997
4998 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004999 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00005000 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5001 {
5002 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00005003 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00005004 }
5005 bgp_unlock_node (child);
5006}
5007
5008void
5009bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
5010 struct bgp_info *del, afi_t afi, safi_t safi)
5011{
5012 struct bgp_node *child;
5013 struct bgp_node *rn;
5014 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00005015 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00005016
5017 /* MPLS-VPN aggregation is not yet supported. */
Lou Berger298cc2f2016-01-12 13:42:02 -05005018 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00005019 return;
5020
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00005021 table = bgp->aggregate[afi][safi];
5022
5023 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07005024 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00005025 return;
5026
paul718e3742002-12-13 20:15:29 +00005027 if (p->prefixlen == 0)
5028 return;
5029
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02005030 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00005031
5032 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07005033 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00005034 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5035 {
5036 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00005037 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00005038 }
5039 bgp_unlock_node (child);
5040}
5041
paul94f2b392005-06-28 12:44:16 +00005042static void
paul718e3742002-12-13 20:15:29 +00005043bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
5044 struct bgp_aggregate *aggregate)
5045{
5046 struct bgp_table *table;
5047 struct bgp_node *top;
5048 struct bgp_node *rn;
5049 struct bgp_info *new;
5050 struct bgp_info *ri;
5051 unsigned long match;
5052 u_char origin = BGP_ORIGIN_IGP;
5053 struct aspath *aspath = NULL;
5054 struct aspath *asmerge = NULL;
5055 struct community *community = NULL;
5056 struct community *commerge = NULL;
5057
5058 table = bgp->rib[afi][safi];
5059
5060 /* Sanity check. */
5061 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5062 return;
5063 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5064 return;
5065
5066 /* If routes exists below this node, generate aggregate routes. */
5067 top = bgp_node_get (table, p);
5068 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5069 if (rn->p.prefixlen > p->prefixlen)
5070 {
5071 match = 0;
5072
5073 for (ri = rn->info; ri; ri = ri->next)
5074 {
5075 if (BGP_INFO_HOLDDOWN (ri))
5076 continue;
5077
5078 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5079 {
5080 /* summary-only aggregate route suppress aggregated
5081 route announcement. */
5082 if (aggregate->summary_only)
5083 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005084 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00005085 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005086 match++;
5087 }
5088 /* as-set aggregate route generate origin, as path,
5089 community aggregation. */
5090 if (aggregate->as_set)
5091 {
5092 if (origin < ri->attr->origin)
5093 origin = ri->attr->origin;
5094
5095 if (aspath)
5096 {
5097 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5098 aspath_free (aspath);
5099 aspath = asmerge;
5100 }
5101 else
5102 aspath = aspath_dup (ri->attr->aspath);
5103
5104 if (ri->attr->community)
5105 {
5106 if (community)
5107 {
5108 commerge = community_merge (community,
5109 ri->attr->community);
5110 community = community_uniq_sort (commerge);
5111 community_free (commerge);
5112 }
5113 else
5114 community = community_dup (ri->attr->community);
5115 }
5116 }
5117 aggregate->count++;
5118 }
5119 }
5120
5121 /* If this node is suppressed, process the change. */
5122 if (match)
5123 bgp_process (bgp, rn, afi, safi);
5124 }
5125 bgp_unlock_node (top);
5126
5127 /* Add aggregate route to BGP table. */
5128 if (aggregate->count)
5129 {
5130 rn = bgp_node_get (table, p);
5131
5132 new = bgp_info_new ();
5133 new->type = ZEBRA_ROUTE_BGP;
5134 new->sub_type = BGP_ROUTE_AGGREGATE;
5135 new->peer = bgp->peer_self;
5136 SET_FLAG (new->flags, BGP_INFO_VALID);
5137 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03005138 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005139
5140 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00005141 bgp_unlock_node (rn);
5142
paul718e3742002-12-13 20:15:29 +00005143 /* Process change. */
5144 bgp_process (bgp, rn, afi, safi);
5145 }
Denil Virae2a92582015-08-11 13:34:59 -07005146 else
5147 {
5148 if (aspath)
5149 aspath_free (aspath);
5150 if (community)
5151 community_free (community);
5152 }
paul718e3742002-12-13 20:15:29 +00005153}
5154
5155void
5156bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5157 safi_t safi, struct bgp_aggregate *aggregate)
5158{
5159 struct bgp_table *table;
5160 struct bgp_node *top;
5161 struct bgp_node *rn;
5162 struct bgp_info *ri;
5163 unsigned long match;
5164
5165 table = bgp->rib[afi][safi];
5166
5167 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5168 return;
5169 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5170 return;
5171
5172 /* If routes exists below this node, generate aggregate routes. */
5173 top = bgp_node_get (table, p);
5174 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5175 if (rn->p.prefixlen > p->prefixlen)
5176 {
5177 match = 0;
5178
5179 for (ri = rn->info; ri; ri = ri->next)
5180 {
5181 if (BGP_INFO_HOLDDOWN (ri))
5182 continue;
5183
5184 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5185 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005186 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00005187 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005188 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00005189
Paul Jakmafb982c22007-05-04 20:15:47 +00005190 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00005191 {
Paul Jakma1a392d42006-09-07 00:24:49 +00005192 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005193 match++;
5194 }
5195 }
5196 aggregate->count--;
5197 }
5198 }
5199
Paul Jakmafb982c22007-05-04 20:15:47 +00005200 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00005201 if (match)
5202 bgp_process (bgp, rn, afi, safi);
5203 }
5204 bgp_unlock_node (top);
5205
5206 /* Delete aggregate route from BGP table. */
5207 rn = bgp_node_get (table, p);
5208
5209 for (ri = rn->info; ri; ri = ri->next)
5210 if (ri->peer == bgp->peer_self
5211 && ri->type == ZEBRA_ROUTE_BGP
5212 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5213 break;
5214
5215 /* Withdraw static BGP route from routing table. */
5216 if (ri)
5217 {
paul718e3742002-12-13 20:15:29 +00005218 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005219 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00005220 }
5221
5222 /* Unlock bgp_node_lookup. */
5223 bgp_unlock_node (rn);
5224}
5225
5226/* Aggregate route attribute. */
5227#define AGGREGATE_SUMMARY_ONLY 1
5228#define AGGREGATE_AS_SET 1
5229
paul94f2b392005-06-28 12:44:16 +00005230static int
Robert Baysf6269b42010-08-05 10:26:28 -07005231bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5232 afi_t afi, safi_t safi)
5233{
5234 int ret;
5235 struct prefix p;
5236 struct bgp_node *rn;
5237 struct bgp *bgp;
5238 struct bgp_aggregate *aggregate;
5239
5240 /* Convert string to prefix structure. */
5241 ret = str2prefix (prefix_str, &p);
5242 if (!ret)
5243 {
5244 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5245 return CMD_WARNING;
5246 }
5247 apply_mask (&p);
5248
5249 /* Get BGP structure. */
5250 bgp = vty->index;
5251
5252 /* Old configuration check. */
5253 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5254 if (! rn)
5255 {
5256 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5257 VTY_NEWLINE);
5258 return CMD_WARNING;
5259 }
5260
5261 aggregate = rn->info;
5262 if (aggregate->safi & SAFI_UNICAST)
5263 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5264 if (aggregate->safi & SAFI_MULTICAST)
5265 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5266
5267 /* Unlock aggregate address configuration. */
5268 rn->info = NULL;
5269 bgp_aggregate_free (aggregate);
5270 bgp_unlock_node (rn);
5271 bgp_unlock_node (rn);
5272
5273 return CMD_SUCCESS;
5274}
5275
5276static int
5277bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00005278 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00005279 u_char summary_only, u_char as_set)
5280{
5281 int ret;
5282 struct prefix p;
5283 struct bgp_node *rn;
5284 struct bgp *bgp;
5285 struct bgp_aggregate *aggregate;
5286
5287 /* Convert string to prefix structure. */
5288 ret = str2prefix (prefix_str, &p);
5289 if (!ret)
5290 {
5291 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5292 return CMD_WARNING;
5293 }
5294 apply_mask (&p);
5295
5296 /* Get BGP structure. */
5297 bgp = vty->index;
5298
5299 /* Old configuration check. */
5300 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5301
5302 if (rn->info)
5303 {
5304 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005305 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005306 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5307 if (ret)
5308 {
Robert Bays368473f2010-08-05 10:26:29 -07005309 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5310 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005311 return CMD_WARNING;
5312 }
paul718e3742002-12-13 20:15:29 +00005313 }
5314
5315 /* Make aggregate address structure. */
5316 aggregate = bgp_aggregate_new ();
5317 aggregate->summary_only = summary_only;
5318 aggregate->as_set = as_set;
5319 aggregate->safi = safi;
5320 rn->info = aggregate;
5321
5322 /* Aggregate address insert into BGP routing table. */
5323 if (safi & SAFI_UNICAST)
5324 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5325 if (safi & SAFI_MULTICAST)
5326 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5327
5328 return CMD_SUCCESS;
5329}
5330
paul718e3742002-12-13 20:15:29 +00005331DEFUN (aggregate_address,
5332 aggregate_address_cmd,
5333 "aggregate-address A.B.C.D/M",
5334 "Configure BGP aggregate entries\n"
5335 "Aggregate prefix\n")
5336{
5337 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5338}
5339
5340DEFUN (aggregate_address_mask,
5341 aggregate_address_mask_cmd,
5342 "aggregate-address A.B.C.D A.B.C.D",
5343 "Configure BGP aggregate entries\n"
5344 "Aggregate address\n"
5345 "Aggregate mask\n")
5346{
5347 int ret;
5348 char prefix_str[BUFSIZ];
5349
5350 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5351
5352 if (! ret)
5353 {
5354 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5355 return CMD_WARNING;
5356 }
5357
5358 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5359 0, 0);
5360}
5361
5362DEFUN (aggregate_address_summary_only,
5363 aggregate_address_summary_only_cmd,
5364 "aggregate-address A.B.C.D/M summary-only",
5365 "Configure BGP aggregate entries\n"
5366 "Aggregate prefix\n"
5367 "Filter more specific routes from updates\n")
5368{
5369 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5370 AGGREGATE_SUMMARY_ONLY, 0);
5371}
5372
5373DEFUN (aggregate_address_mask_summary_only,
5374 aggregate_address_mask_summary_only_cmd,
5375 "aggregate-address A.B.C.D A.B.C.D summary-only",
5376 "Configure BGP aggregate entries\n"
5377 "Aggregate address\n"
5378 "Aggregate mask\n"
5379 "Filter more specific routes from updates\n")
5380{
5381 int ret;
5382 char prefix_str[BUFSIZ];
5383
5384 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5385
5386 if (! ret)
5387 {
5388 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5389 return CMD_WARNING;
5390 }
5391
5392 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5393 AGGREGATE_SUMMARY_ONLY, 0);
5394}
5395
5396DEFUN (aggregate_address_as_set,
5397 aggregate_address_as_set_cmd,
5398 "aggregate-address A.B.C.D/M as-set",
5399 "Configure BGP aggregate entries\n"
5400 "Aggregate prefix\n"
5401 "Generate AS set path information\n")
5402{
5403 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5404 0, AGGREGATE_AS_SET);
5405}
5406
5407DEFUN (aggregate_address_mask_as_set,
5408 aggregate_address_mask_as_set_cmd,
5409 "aggregate-address A.B.C.D A.B.C.D as-set",
5410 "Configure BGP aggregate entries\n"
5411 "Aggregate address\n"
5412 "Aggregate mask\n"
5413 "Generate AS set path information\n")
5414{
5415 int ret;
5416 char prefix_str[BUFSIZ];
5417
5418 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5419
5420 if (! ret)
5421 {
5422 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5423 return CMD_WARNING;
5424 }
5425
5426 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5427 0, AGGREGATE_AS_SET);
5428}
5429
5430
5431DEFUN (aggregate_address_as_set_summary,
5432 aggregate_address_as_set_summary_cmd,
5433 "aggregate-address A.B.C.D/M as-set summary-only",
5434 "Configure BGP aggregate entries\n"
5435 "Aggregate prefix\n"
5436 "Generate AS set path information\n"
5437 "Filter more specific routes from updates\n")
5438{
5439 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5440 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5441}
5442
5443ALIAS (aggregate_address_as_set_summary,
5444 aggregate_address_summary_as_set_cmd,
5445 "aggregate-address A.B.C.D/M summary-only as-set",
5446 "Configure BGP aggregate entries\n"
5447 "Aggregate prefix\n"
5448 "Filter more specific routes from updates\n"
5449 "Generate AS set path information\n")
5450
5451DEFUN (aggregate_address_mask_as_set_summary,
5452 aggregate_address_mask_as_set_summary_cmd,
5453 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5454 "Configure BGP aggregate entries\n"
5455 "Aggregate address\n"
5456 "Aggregate mask\n"
5457 "Generate AS set path information\n"
5458 "Filter more specific routes from updates\n")
5459{
5460 int ret;
5461 char prefix_str[BUFSIZ];
5462
5463 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5464
5465 if (! ret)
5466 {
5467 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5468 return CMD_WARNING;
5469 }
5470
5471 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5472 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5473}
5474
5475ALIAS (aggregate_address_mask_as_set_summary,
5476 aggregate_address_mask_summary_as_set_cmd,
5477 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5478 "Configure BGP aggregate entries\n"
5479 "Aggregate address\n"
5480 "Aggregate mask\n"
5481 "Filter more specific routes from updates\n"
5482 "Generate AS set path information\n")
5483
5484DEFUN (no_aggregate_address,
5485 no_aggregate_address_cmd,
5486 "no aggregate-address A.B.C.D/M",
5487 NO_STR
5488 "Configure BGP aggregate entries\n"
5489 "Aggregate prefix\n")
5490{
5491 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5492}
5493
5494ALIAS (no_aggregate_address,
5495 no_aggregate_address_summary_only_cmd,
5496 "no aggregate-address A.B.C.D/M summary-only",
5497 NO_STR
5498 "Configure BGP aggregate entries\n"
5499 "Aggregate prefix\n"
5500 "Filter more specific routes from updates\n")
5501
5502ALIAS (no_aggregate_address,
5503 no_aggregate_address_as_set_cmd,
5504 "no aggregate-address A.B.C.D/M as-set",
5505 NO_STR
5506 "Configure BGP aggregate entries\n"
5507 "Aggregate prefix\n"
5508 "Generate AS set path information\n")
5509
5510ALIAS (no_aggregate_address,
5511 no_aggregate_address_as_set_summary_cmd,
5512 "no aggregate-address A.B.C.D/M as-set summary-only",
5513 NO_STR
5514 "Configure BGP aggregate entries\n"
5515 "Aggregate prefix\n"
5516 "Generate AS set path information\n"
5517 "Filter more specific routes from updates\n")
5518
5519ALIAS (no_aggregate_address,
5520 no_aggregate_address_summary_as_set_cmd,
5521 "no aggregate-address A.B.C.D/M summary-only as-set",
5522 NO_STR
5523 "Configure BGP aggregate entries\n"
5524 "Aggregate prefix\n"
5525 "Filter more specific routes from updates\n"
5526 "Generate AS set path information\n")
5527
5528DEFUN (no_aggregate_address_mask,
5529 no_aggregate_address_mask_cmd,
5530 "no aggregate-address A.B.C.D A.B.C.D",
5531 NO_STR
5532 "Configure BGP aggregate entries\n"
5533 "Aggregate address\n"
5534 "Aggregate mask\n")
5535{
5536 int ret;
5537 char prefix_str[BUFSIZ];
5538
5539 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5540
5541 if (! ret)
5542 {
5543 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5544 return CMD_WARNING;
5545 }
5546
5547 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5548}
5549
5550ALIAS (no_aggregate_address_mask,
5551 no_aggregate_address_mask_summary_only_cmd,
5552 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5553 NO_STR
5554 "Configure BGP aggregate entries\n"
5555 "Aggregate address\n"
5556 "Aggregate mask\n"
5557 "Filter more specific routes from updates\n")
5558
5559ALIAS (no_aggregate_address_mask,
5560 no_aggregate_address_mask_as_set_cmd,
5561 "no aggregate-address A.B.C.D A.B.C.D as-set",
5562 NO_STR
5563 "Configure BGP aggregate entries\n"
5564 "Aggregate address\n"
5565 "Aggregate mask\n"
5566 "Generate AS set path information\n")
5567
5568ALIAS (no_aggregate_address_mask,
5569 no_aggregate_address_mask_as_set_summary_cmd,
5570 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5571 NO_STR
5572 "Configure BGP aggregate entries\n"
5573 "Aggregate address\n"
5574 "Aggregate mask\n"
5575 "Generate AS set path information\n"
5576 "Filter more specific routes from updates\n")
5577
5578ALIAS (no_aggregate_address_mask,
5579 no_aggregate_address_mask_summary_as_set_cmd,
5580 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5581 NO_STR
5582 "Configure BGP aggregate entries\n"
5583 "Aggregate address\n"
5584 "Aggregate mask\n"
5585 "Filter more specific routes from updates\n"
5586 "Generate AS set path information\n")
5587
5588#ifdef HAVE_IPV6
5589DEFUN (ipv6_aggregate_address,
5590 ipv6_aggregate_address_cmd,
5591 "aggregate-address X:X::X:X/M",
5592 "Configure BGP aggregate entries\n"
5593 "Aggregate prefix\n")
5594{
5595 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5596}
5597
5598DEFUN (ipv6_aggregate_address_summary_only,
5599 ipv6_aggregate_address_summary_only_cmd,
5600 "aggregate-address X:X::X:X/M summary-only",
5601 "Configure BGP aggregate entries\n"
5602 "Aggregate prefix\n"
5603 "Filter more specific routes from updates\n")
5604{
5605 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5606 AGGREGATE_SUMMARY_ONLY, 0);
5607}
5608
5609DEFUN (no_ipv6_aggregate_address,
5610 no_ipv6_aggregate_address_cmd,
5611 "no aggregate-address X:X::X:X/M",
5612 NO_STR
5613 "Configure BGP aggregate entries\n"
5614 "Aggregate prefix\n")
5615{
5616 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5617}
5618
5619DEFUN (no_ipv6_aggregate_address_summary_only,
5620 no_ipv6_aggregate_address_summary_only_cmd,
5621 "no aggregate-address X:X::X:X/M summary-only",
5622 NO_STR
5623 "Configure BGP aggregate entries\n"
5624 "Aggregate prefix\n"
5625 "Filter more specific routes from updates\n")
5626{
5627 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5628}
5629
5630ALIAS (ipv6_aggregate_address,
5631 old_ipv6_aggregate_address_cmd,
5632 "ipv6 bgp aggregate-address X:X::X:X/M",
5633 IPV6_STR
5634 BGP_STR
5635 "Configure BGP aggregate entries\n"
5636 "Aggregate prefix\n")
5637
5638ALIAS (ipv6_aggregate_address_summary_only,
5639 old_ipv6_aggregate_address_summary_only_cmd,
5640 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5641 IPV6_STR
5642 BGP_STR
5643 "Configure BGP aggregate entries\n"
5644 "Aggregate prefix\n"
5645 "Filter more specific routes from updates\n")
5646
5647ALIAS (no_ipv6_aggregate_address,
5648 old_no_ipv6_aggregate_address_cmd,
5649 "no ipv6 bgp aggregate-address X:X::X:X/M",
5650 NO_STR
5651 IPV6_STR
5652 BGP_STR
5653 "Configure BGP aggregate entries\n"
5654 "Aggregate prefix\n")
5655
5656ALIAS (no_ipv6_aggregate_address_summary_only,
5657 old_no_ipv6_aggregate_address_summary_only_cmd,
5658 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5659 NO_STR
5660 IPV6_STR
5661 BGP_STR
5662 "Configure BGP aggregate entries\n"
5663 "Aggregate prefix\n"
5664 "Filter more specific routes from updates\n")
5665#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02005666
paul718e3742002-12-13 20:15:29 +00005667/* Redistribute route treatment. */
5668void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005669bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5670 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005671 u_int32_t metric, u_char type)
5672{
5673 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005674 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005675 struct bgp_info *new;
5676 struct bgp_info *bi;
5677 struct bgp_info info;
5678 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005679 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005680 struct attr *new_attr;
5681 afi_t afi;
5682 int ret;
5683
5684 /* Make default attribute. */
5685 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5686 if (nexthop)
5687 attr.nexthop = *nexthop;
5688
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005689#ifdef HAVE_IPV6
5690 if (nexthop6)
5691 {
5692 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5693 extra->mp_nexthop_global = *nexthop6;
5694 extra->mp_nexthop_len = 16;
5695 }
5696#endif
5697
paul718e3742002-12-13 20:15:29 +00005698 attr.med = metric;
5699 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5700
paul1eb8ef22005-04-07 07:30:20 +00005701 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005702 {
5703 afi = family2afi (p->family);
5704
5705 if (bgp->redist[afi][type])
5706 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005707 struct attr attr_new;
5708 struct attr_extra extra_new;
5709
paul718e3742002-12-13 20:15:29 +00005710 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005711 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005712 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005713
5714 if (bgp->redist_metric_flag[afi][type])
5715 attr_new.med = bgp->redist_metric[afi][type];
5716
5717 /* Apply route-map. */
Daniel Walton1994dc82015-09-17 10:15:59 -04005718 if (bgp->rmap[afi][type].name)
paul718e3742002-12-13 20:15:29 +00005719 {
5720 info.peer = bgp->peer_self;
5721 info.attr = &attr_new;
5722
paulfee0f4c2004-09-13 05:12:46 +00005723 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5724
paul718e3742002-12-13 20:15:29 +00005725 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5726 &info);
paulfee0f4c2004-09-13 05:12:46 +00005727
5728 bgp->peer_self->rmap_type = 0;
5729
paul718e3742002-12-13 20:15:29 +00005730 if (ret == RMAP_DENYMATCH)
5731 {
5732 /* Free uninterned attribute. */
5733 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005734
paul718e3742002-12-13 20:15:29 +00005735 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005736 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005737 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005738 bgp_redistribute_delete (p, type);
5739 return;
5740 }
5741 }
5742
Paul Jakmafb982c22007-05-04 20:15:47 +00005743 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5744 afi, SAFI_UNICAST, p, NULL);
5745
paul718e3742002-12-13 20:15:29 +00005746 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005747
paul718e3742002-12-13 20:15:29 +00005748 for (bi = bn->info; bi; bi = bi->next)
5749 if (bi->peer == bgp->peer_self
5750 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5751 break;
5752
5753 if (bi)
5754 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005755 if (attrhash_cmp (bi->attr, new_attr) &&
5756 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005757 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005758 bgp_attr_unintern (&new_attr);
5759 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005760 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005761 bgp_unlock_node (bn);
5762 return;
5763 }
5764 else
5765 {
5766 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005767 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005768
5769 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005770 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5771 bgp_info_restore(bn, bi);
5772 else
5773 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005774 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005775 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005776 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005777
5778 /* Process change. */
5779 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5780 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5781 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005782 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005783 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005784 return;
5785 }
5786 }
5787
5788 new = bgp_info_new ();
5789 new->type = type;
5790 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5791 new->peer = bgp->peer_self;
5792 SET_FLAG (new->flags, BGP_INFO_VALID);
5793 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005794 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005795
5796 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5797 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005798 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005799 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5800 }
5801 }
5802
5803 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005804 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005805 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005806}
5807
5808void
5809bgp_redistribute_delete (struct prefix *p, u_char type)
5810{
5811 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005812 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005813 afi_t afi;
5814 struct bgp_node *rn;
5815 struct bgp_info *ri;
5816
paul1eb8ef22005-04-07 07:30:20 +00005817 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005818 {
5819 afi = family2afi (p->family);
5820
5821 if (bgp->redist[afi][type])
5822 {
paulfee0f4c2004-09-13 05:12:46 +00005823 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005824
5825 for (ri = rn->info; ri; ri = ri->next)
5826 if (ri->peer == bgp->peer_self
5827 && ri->type == type)
5828 break;
5829
5830 if (ri)
5831 {
5832 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005833 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005834 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005835 }
5836 bgp_unlock_node (rn);
5837 }
5838 }
5839}
5840
5841/* Withdraw specified route type's route. */
5842void
5843bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5844{
5845 struct bgp_node *rn;
5846 struct bgp_info *ri;
5847 struct bgp_table *table;
5848
5849 table = bgp->rib[afi][SAFI_UNICAST];
5850
5851 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5852 {
5853 for (ri = rn->info; ri; ri = ri->next)
5854 if (ri->peer == bgp->peer_self
5855 && ri->type == type)
5856 break;
5857
5858 if (ri)
5859 {
5860 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005861 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005862 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005863 }
5864 }
5865}
David Lamparter6b0655a2014-06-04 06:53:35 +02005866
paul718e3742002-12-13 20:15:29 +00005867/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005868static void
paul718e3742002-12-13 20:15:29 +00005869route_vty_out_route (struct prefix *p, struct vty *vty)
5870{
5871 int len;
5872 u_int32_t destination;
5873 char buf[BUFSIZ];
5874
5875 if (p->family == AF_INET)
5876 {
5877 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5878 destination = ntohl (p->u.prefix4.s_addr);
5879
5880 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5881 || (IN_CLASSB (destination) && p->prefixlen == 16)
5882 || (IN_CLASSA (destination) && p->prefixlen == 8)
5883 || p->u.prefix4.s_addr == 0)
5884 {
5885 /* When mask is natural, mask is not displayed. */
5886 }
5887 else
5888 len += vty_out (vty, "/%d", p->prefixlen);
5889 }
5890 else
5891 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5892 p->prefixlen);
5893
5894 len = 17 - len;
5895 if (len < 1)
5896 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5897 else
5898 vty_out (vty, "%*s", len, " ");
5899}
5900
paul718e3742002-12-13 20:15:29 +00005901enum bgp_display_type
5902{
5903 normal_list,
5904};
5905
paulb40d9392005-08-22 22:34:41 +00005906/* Print the short form route status for a bgp_info */
5907static void
5908route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005909{
paulb40d9392005-08-22 22:34:41 +00005910 /* Route status display. */
5911 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5912 vty_out (vty, "R");
5913 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005914 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005915 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005916 vty_out (vty, "s");
5917 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5918 vty_out (vty, "*");
5919 else
5920 vty_out (vty, " ");
5921
5922 /* Selected */
5923 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5924 vty_out (vty, "h");
5925 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5926 vty_out (vty, "d");
5927 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5928 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005929 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5930 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005931 else
5932 vty_out (vty, " ");
5933
5934 /* Internal route. */
5935 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5936 vty_out (vty, "i");
5937 else
paulb40d9392005-08-22 22:34:41 +00005938 vty_out (vty, " ");
5939}
5940
5941/* called from terminal list command */
5942void
5943route_vty_out (struct vty *vty, struct prefix *p,
5944 struct bgp_info *binfo, int display, safi_t safi)
5945{
5946 struct attr *attr;
5947
5948 /* short status lead text */
5949 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005950
5951 /* print prefix and mask */
5952 if (! display)
5953 route_vty_out_route (p, vty);
5954 else
5955 vty_out (vty, "%*s", 17, " ");
5956
5957 /* Print attribute */
5958 attr = binfo->attr;
5959 if (attr)
5960 {
paul718e3742002-12-13 20:15:29 +00005961
Lou Berger298cc2f2016-01-12 13:42:02 -05005962 /*
5963 * NEXTHOP start
5964 */
5965
5966 /*
5967 * For ENCAP routes, nexthop address family is not
5968 * neccessarily the same as the prefix address family.
5969 * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
5970 */
5971 if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN)) {
5972 if (attr->extra) {
5973 char buf[BUFSIZ];
5974 int af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len);
5975
5976 switch (af) {
5977 case AF_INET:
5978 vty_out (vty, "%s", inet_ntop(af,
5979 &attr->extra->mp_nexthop_global_in, buf, BUFSIZ));
5980 break;
5981#if HAVE_IPV6
5982 case AF_INET6:
5983 vty_out (vty, "%s", inet_ntop(af,
5984 &attr->extra->mp_nexthop_global, buf, BUFSIZ));
5985 break;
5986#endif
5987
5988 default:
5989 vty_out(vty, "?");
5990 }
5991 } else {
5992 vty_out(vty, "?");
paul718e3742002-12-13 20:15:29 +00005993 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005994 } else {
5995
5996 if (p->family == AF_INET)
5997 {
5998 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5999 }
6000#ifdef HAVE_IPV6
6001 else if (p->family == AF_INET6)
6002 {
6003 int len;
6004 char buf[BUFSIZ];
6005
6006 len = vty_out (vty, "%s",
6007 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6008 buf, BUFSIZ));
6009 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#endif /* HAVE_IPV6 */
Lou Berger298cc2f2016-01-12 13:42:02 -05006016 else
6017 {
6018 vty_out(vty, "?");
6019 }
6020 }
6021
6022 /*
6023 * NEXTHOP end
6024 */
6025
paul718e3742002-12-13 20:15:29 +00006026
6027 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006028 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00006029 else
6030 vty_out (vty, " ");
6031
6032 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006033 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006034 else
6035 vty_out (vty, " ");
6036
Paul Jakmafb982c22007-05-04 20:15:47 +00006037 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00006038
Paul Jakmab2518c12006-05-12 23:48:40 +00006039 /* Print aspath */
6040 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006041 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006042
Paul Jakmab2518c12006-05-12 23:48:40 +00006043 /* Print origin */
paul718e3742002-12-13 20:15:29 +00006044 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00006045 }
paul718e3742002-12-13 20:15:29 +00006046 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006047}
6048
6049/* called from terminal list command */
6050void
6051route_vty_out_tmp (struct vty *vty, struct prefix *p,
6052 struct attr *attr, safi_t safi)
6053{
6054 /* Route status display. */
6055 vty_out (vty, "*");
6056 vty_out (vty, ">");
6057 vty_out (vty, " ");
6058
6059 /* print prefix and mask */
6060 route_vty_out_route (p, vty);
6061
6062 /* Print attribute */
6063 if (attr)
6064 {
6065 if (p->family == AF_INET)
6066 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006067 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00006068 vty_out (vty, "%-16s",
6069 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00006070 else
6071 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6072 }
6073#ifdef HAVE_IPV6
6074 else if (p->family == AF_INET6)
6075 {
6076 int len;
6077 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006078
6079 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006080
6081 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006082 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6083 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006084 len = 16 - len;
6085 if (len < 1)
6086 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6087 else
6088 vty_out (vty, "%*s", len, " ");
6089 }
6090#endif /* HAVE_IPV6 */
6091
6092 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006093 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00006094 else
6095 vty_out (vty, " ");
6096
6097 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006098 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006099 else
6100 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006101
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006102 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00006103
Paul Jakmab2518c12006-05-12 23:48:40 +00006104 /* Print aspath */
6105 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006106 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006107
Paul Jakmab2518c12006-05-12 23:48:40 +00006108 /* Print origin */
paul718e3742002-12-13 20:15:29 +00006109 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00006110 }
paul718e3742002-12-13 20:15:29 +00006111
6112 vty_out (vty, "%s", VTY_NEWLINE);
6113}
6114
ajs5a646652004-11-05 01:25:55 +00006115void
paul718e3742002-12-13 20:15:29 +00006116route_vty_out_tag (struct vty *vty, struct prefix *p,
6117 struct bgp_info *binfo, int display, safi_t safi)
6118{
6119 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006120 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00006121
6122 if (!binfo->extra)
6123 return;
6124
paulb40d9392005-08-22 22:34:41 +00006125 /* short status lead text */
6126 route_vty_short_status_out (vty, binfo);
6127
paul718e3742002-12-13 20:15:29 +00006128 /* print prefix and mask */
6129 if (! display)
6130 route_vty_out_route (p, vty);
6131 else
6132 vty_out (vty, "%*s", 17, " ");
6133
6134 /* Print attribute */
6135 attr = binfo->attr;
6136 if (attr)
6137 {
6138 if (p->family == AF_INET)
6139 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006140 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00006141 vty_out (vty, "%-16s",
6142 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00006143 else
6144 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6145 }
6146#ifdef HAVE_IPV6
6147 else if (p->family == AF_INET6)
6148 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006149 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006150 char buf[BUFSIZ];
6151 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006152 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00006153 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006154 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6155 buf, BUFSIZ));
6156 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006157 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006158 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6159 buf, BUFSIZ),
6160 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6161 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006162
6163 }
6164#endif /* HAVE_IPV6 */
6165 }
6166
Paul Jakmafb982c22007-05-04 20:15:47 +00006167 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00006168
6169 vty_out (vty, "notag/%d", label);
6170
6171 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006172}
6173
6174/* dampening route */
ajs5a646652004-11-05 01:25:55 +00006175static void
paul718e3742002-12-13 20:15:29 +00006176damp_route_vty_out (struct vty *vty, struct prefix *p,
6177 struct bgp_info *binfo, int display, safi_t safi)
6178{
6179 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006180 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00006181 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00006182
paulb40d9392005-08-22 22:34:41 +00006183 /* short status lead text */
6184 route_vty_short_status_out (vty, binfo);
6185
paul718e3742002-12-13 20:15:29 +00006186 /* print prefix and mask */
6187 if (! display)
6188 route_vty_out_route (p, vty);
6189 else
6190 vty_out (vty, "%*s", 17, " ");
6191
6192 len = vty_out (vty, "%s", binfo->peer->host);
6193 len = 17 - len;
6194 if (len < 1)
6195 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6196 else
6197 vty_out (vty, "%*s", len, " ");
6198
Chris Caputo50aef6f2009-06-23 06:06:49 +00006199 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006200
6201 /* Print attribute */
6202 attr = binfo->attr;
6203 if (attr)
6204 {
6205 /* Print aspath */
6206 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006207 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006208
6209 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006210 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006211 }
6212 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006213}
6214
paul718e3742002-12-13 20:15:29 +00006215/* flap route */
ajs5a646652004-11-05 01:25:55 +00006216static void
paul718e3742002-12-13 20:15:29 +00006217flap_route_vty_out (struct vty *vty, struct prefix *p,
6218 struct bgp_info *binfo, int display, safi_t safi)
6219{
6220 struct attr *attr;
6221 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00006222 char timebuf[BGP_UPTIME_LEN];
6223 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00006224
6225 if (!binfo->extra)
6226 return;
6227
6228 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00006229
paulb40d9392005-08-22 22:34:41 +00006230 /* short status lead text */
6231 route_vty_short_status_out (vty, binfo);
6232
paul718e3742002-12-13 20:15:29 +00006233 /* print prefix and mask */
6234 if (! display)
6235 route_vty_out_route (p, vty);
6236 else
6237 vty_out (vty, "%*s", 17, " ");
6238
6239 len = vty_out (vty, "%s", binfo->peer->host);
6240 len = 16 - len;
6241 if (len < 1)
6242 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6243 else
6244 vty_out (vty, "%*s", len, " ");
6245
6246 len = vty_out (vty, "%d", bdi->flap);
6247 len = 5 - len;
6248 if (len < 1)
6249 vty_out (vty, " ");
6250 else
6251 vty_out (vty, "%*s ", len, " ");
6252
6253 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6254 timebuf, BGP_UPTIME_LEN));
6255
6256 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6257 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00006258 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006259 else
6260 vty_out (vty, "%*s ", 8, " ");
6261
6262 /* Print attribute */
6263 attr = binfo->attr;
6264 if (attr)
6265 {
6266 /* Print aspath */
6267 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006268 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006269
6270 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006271 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006272 }
6273 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006274}
6275
paul94f2b392005-06-28 12:44:16 +00006276static void
paul718e3742002-12-13 20:15:29 +00006277route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6278 struct bgp_info *binfo, afi_t afi, safi_t safi)
6279{
6280 char buf[INET6_ADDRSTRLEN];
6281 char buf1[BUFSIZ];
6282 struct attr *attr;
6283 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03006284#ifdef HAVE_CLOCK_MONOTONIC
6285 time_t tbuf;
6286#endif
paul718e3742002-12-13 20:15:29 +00006287
6288 attr = binfo->attr;
6289
6290 if (attr)
6291 {
6292 /* Line1 display AS-path, Aggregator */
6293 if (attr->aspath)
6294 {
6295 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00006296 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00006297 vty_out (vty, "Local");
6298 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006299 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00006300 }
6301
paulb40d9392005-08-22 22:34:41 +00006302 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6303 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00006304 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6305 vty_out (vty, ", (stale)");
6306 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006307 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006308 attr->extra->aggregator_as,
6309 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006310 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6311 vty_out (vty, ", (Received from a RR-client)");
6312 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6313 vty_out (vty, ", (Received from a RS-client)");
6314 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6315 vty_out (vty, ", (history entry)");
6316 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6317 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006318 vty_out (vty, "%s", VTY_NEWLINE);
6319
6320 /* Line2 display Next-hop, Neighbor, Router-id */
6321 if (p->family == AF_INET)
6322 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006323 vty_out (vty, " %s", ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)) ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006324 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006325 inet_ntoa (attr->nexthop));
6326 }
6327#ifdef HAVE_IPV6
6328 else
6329 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006330 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006331 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006332 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006333 buf, INET6_ADDRSTRLEN));
6334 }
6335#endif /* HAVE_IPV6 */
6336
6337 if (binfo->peer == bgp->peer_self)
6338 {
6339 vty_out (vty, " from %s ",
6340 p->family == AF_INET ? "0.0.0.0" : "::");
6341 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6342 }
6343 else
6344 {
6345 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6346 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006347 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006348 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006349 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
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, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006352 else
6353 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6354 }
6355 vty_out (vty, "%s", VTY_NEWLINE);
6356
6357#ifdef HAVE_IPV6
6358 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006359 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006360 {
6361 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006362 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006363 buf, INET6_ADDRSTRLEN),
6364 VTY_NEWLINE);
6365 }
6366#endif /* HAVE_IPV6 */
6367
6368 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6369 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6370
6371 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006372 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006373
6374 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006375 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006376 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006377 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006378
Paul Jakmafb982c22007-05-04 20:15:47 +00006379 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006380 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006381
6382 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6383 vty_out (vty, ", valid");
6384
6385 if (binfo->peer != bgp->peer_self)
6386 {
6387 if (binfo->peer->as == binfo->peer->local_as)
6388 vty_out (vty, ", internal");
6389 else
6390 vty_out (vty, ", %s",
6391 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6392 }
6393 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6394 vty_out (vty, ", aggregated, local");
6395 else if (binfo->type != ZEBRA_ROUTE_BGP)
6396 vty_out (vty, ", sourced");
6397 else
6398 vty_out (vty, ", sourced, local");
6399
6400 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6401 vty_out (vty, ", atomic-aggregate");
6402
Josh Baileyde8d5df2011-07-20 20:46:01 -07006403 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6404 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6405 bgp_info_mpath_count (binfo)))
6406 vty_out (vty, ", multipath");
6407
paul718e3742002-12-13 20:15:29 +00006408 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6409 vty_out (vty, ", best");
6410
6411 vty_out (vty, "%s", VTY_NEWLINE);
6412
6413 /* Line 4 display Community */
6414 if (attr->community)
6415 vty_out (vty, " Community: %s%s", attr->community->str,
6416 VTY_NEWLINE);
6417
6418 /* Line 5 display Extended-community */
6419 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006420 vty_out (vty, " Extended Community: %s%s",
6421 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006422
6423 /* Line 6 display Originator, Cluster-id */
6424 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6425 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6426 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006427 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006428 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006429 vty_out (vty, " Originator: %s",
6430 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006431
6432 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6433 {
6434 int i;
6435 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006436 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6437 vty_out (vty, "%s ",
6438 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006439 }
6440 vty_out (vty, "%s", VTY_NEWLINE);
6441 }
Paul Jakma41367172007-08-06 15:24:51 +00006442
Paul Jakmafb982c22007-05-04 20:15:47 +00006443 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006444 bgp_damp_info_vty (vty, binfo);
6445
6446 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006447#ifdef HAVE_CLOCK_MONOTONIC
6448 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006449 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006450#else
6451 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6452#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006453 }
6454 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006455}
6456
6457#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6458 "h history, * valid, > best, = multipath,%s"\
6459 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006460#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006461#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6462#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6463#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6464
6465enum bgp_show_type
6466{
6467 bgp_show_type_normal,
6468 bgp_show_type_regexp,
6469 bgp_show_type_prefix_list,
6470 bgp_show_type_filter_list,
6471 bgp_show_type_route_map,
6472 bgp_show_type_neighbor,
6473 bgp_show_type_cidr_only,
6474 bgp_show_type_prefix_longer,
6475 bgp_show_type_community_all,
6476 bgp_show_type_community,
6477 bgp_show_type_community_exact,
6478 bgp_show_type_community_list,
6479 bgp_show_type_community_list_exact,
6480 bgp_show_type_flap_statistics,
6481 bgp_show_type_flap_address,
6482 bgp_show_type_flap_prefix,
6483 bgp_show_type_flap_cidr_only,
6484 bgp_show_type_flap_regexp,
6485 bgp_show_type_flap_filter_list,
6486 bgp_show_type_flap_prefix_list,
6487 bgp_show_type_flap_prefix_longer,
6488 bgp_show_type_flap_route_map,
6489 bgp_show_type_flap_neighbor,
6490 bgp_show_type_dampend_paths,
6491 bgp_show_type_damp_neighbor
6492};
6493
ajs5a646652004-11-05 01:25:55 +00006494static int
paulfee0f4c2004-09-13 05:12:46 +00006495bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006496 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006497{
paul718e3742002-12-13 20:15:29 +00006498 struct bgp_info *ri;
6499 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006500 int header = 1;
paul718e3742002-12-13 20:15:29 +00006501 int display;
ajs5a646652004-11-05 01:25:55 +00006502 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006503
6504 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006505 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006506
paul718e3742002-12-13 20:15:29 +00006507 /* Start processing of routes. */
6508 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6509 if (rn->info != NULL)
6510 {
6511 display = 0;
6512
6513 for (ri = rn->info; ri; ri = ri->next)
6514 {
ajs5a646652004-11-05 01:25:55 +00006515 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006516 || type == bgp_show_type_flap_address
6517 || type == bgp_show_type_flap_prefix
6518 || type == bgp_show_type_flap_cidr_only
6519 || type == bgp_show_type_flap_regexp
6520 || type == bgp_show_type_flap_filter_list
6521 || type == bgp_show_type_flap_prefix_list
6522 || type == bgp_show_type_flap_prefix_longer
6523 || type == bgp_show_type_flap_route_map
6524 || type == bgp_show_type_flap_neighbor
6525 || type == bgp_show_type_dampend_paths
6526 || type == bgp_show_type_damp_neighbor)
6527 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006528 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006529 continue;
6530 }
6531 if (type == bgp_show_type_regexp
6532 || type == bgp_show_type_flap_regexp)
6533 {
ajs5a646652004-11-05 01:25:55 +00006534 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006535
6536 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6537 continue;
6538 }
6539 if (type == bgp_show_type_prefix_list
6540 || type == bgp_show_type_flap_prefix_list)
6541 {
ajs5a646652004-11-05 01:25:55 +00006542 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006543
6544 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6545 continue;
6546 }
6547 if (type == bgp_show_type_filter_list
6548 || type == bgp_show_type_flap_filter_list)
6549 {
ajs5a646652004-11-05 01:25:55 +00006550 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006551
6552 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6553 continue;
6554 }
6555 if (type == bgp_show_type_route_map
6556 || type == bgp_show_type_flap_route_map)
6557 {
ajs5a646652004-11-05 01:25:55 +00006558 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006559 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006560 struct attr dummy_attr;
6561 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006562 int ret;
6563
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006564 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006565 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006566
paul718e3742002-12-13 20:15:29 +00006567 binfo.peer = ri->peer;
6568 binfo.attr = &dummy_attr;
6569
6570 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006571 if (ret == RMAP_DENYMATCH)
6572 continue;
6573 }
6574 if (type == bgp_show_type_neighbor
6575 || type == bgp_show_type_flap_neighbor
6576 || type == bgp_show_type_damp_neighbor)
6577 {
ajs5a646652004-11-05 01:25:55 +00006578 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006579
6580 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6581 continue;
6582 }
6583 if (type == bgp_show_type_cidr_only
6584 || type == bgp_show_type_flap_cidr_only)
6585 {
6586 u_int32_t destination;
6587
6588 destination = ntohl (rn->p.u.prefix4.s_addr);
6589 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6590 continue;
6591 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6592 continue;
6593 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6594 continue;
6595 }
6596 if (type == bgp_show_type_prefix_longer
6597 || type == bgp_show_type_flap_prefix_longer)
6598 {
ajs5a646652004-11-05 01:25:55 +00006599 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006600
6601 if (! prefix_match (p, &rn->p))
6602 continue;
6603 }
6604 if (type == bgp_show_type_community_all)
6605 {
6606 if (! ri->attr->community)
6607 continue;
6608 }
6609 if (type == bgp_show_type_community)
6610 {
ajs5a646652004-11-05 01:25:55 +00006611 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006612
6613 if (! ri->attr->community ||
6614 ! community_match (ri->attr->community, com))
6615 continue;
6616 }
6617 if (type == bgp_show_type_community_exact)
6618 {
ajs5a646652004-11-05 01:25:55 +00006619 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006620
6621 if (! ri->attr->community ||
6622 ! community_cmp (ri->attr->community, com))
6623 continue;
6624 }
6625 if (type == bgp_show_type_community_list)
6626 {
ajs5a646652004-11-05 01:25:55 +00006627 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006628
6629 if (! community_list_match (ri->attr->community, list))
6630 continue;
6631 }
6632 if (type == bgp_show_type_community_list_exact)
6633 {
ajs5a646652004-11-05 01:25:55 +00006634 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006635
6636 if (! community_list_exact_match (ri->attr->community, list))
6637 continue;
6638 }
6639 if (type == bgp_show_type_flap_address
6640 || type == bgp_show_type_flap_prefix)
6641 {
ajs5a646652004-11-05 01:25:55 +00006642 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006643
6644 if (! prefix_match (&rn->p, p))
6645 continue;
6646
6647 if (type == bgp_show_type_flap_prefix)
6648 if (p->prefixlen != rn->p.prefixlen)
6649 continue;
6650 }
6651 if (type == bgp_show_type_dampend_paths
6652 || type == bgp_show_type_damp_neighbor)
6653 {
6654 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6655 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6656 continue;
6657 }
6658
6659 if (header)
6660 {
hasso93406d82005-02-02 14:40:33 +00006661 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6662 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6663 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006664 if (type == bgp_show_type_dampend_paths
6665 || type == bgp_show_type_damp_neighbor)
6666 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6667 else if (type == bgp_show_type_flap_statistics
6668 || type == bgp_show_type_flap_address
6669 || type == bgp_show_type_flap_prefix
6670 || type == bgp_show_type_flap_cidr_only
6671 || type == bgp_show_type_flap_regexp
6672 || type == bgp_show_type_flap_filter_list
6673 || type == bgp_show_type_flap_prefix_list
6674 || type == bgp_show_type_flap_prefix_longer
6675 || type == bgp_show_type_flap_route_map
6676 || type == bgp_show_type_flap_neighbor)
6677 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6678 else
6679 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006680 header = 0;
6681 }
6682
6683 if (type == bgp_show_type_dampend_paths
6684 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006685 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006686 else if (type == bgp_show_type_flap_statistics
6687 || type == bgp_show_type_flap_address
6688 || type == bgp_show_type_flap_prefix
6689 || type == bgp_show_type_flap_cidr_only
6690 || type == bgp_show_type_flap_regexp
6691 || type == bgp_show_type_flap_filter_list
6692 || type == bgp_show_type_flap_prefix_list
6693 || type == bgp_show_type_flap_prefix_longer
6694 || type == bgp_show_type_flap_route_map
6695 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006696 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006697 else
ajs5a646652004-11-05 01:25:55 +00006698 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006699 display++;
6700 }
6701 if (display)
ajs5a646652004-11-05 01:25:55 +00006702 output_count++;
paul718e3742002-12-13 20:15:29 +00006703 }
6704
6705 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006706 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006707 {
6708 if (type == bgp_show_type_normal)
6709 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6710 }
6711 else
6712 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006713 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006714
6715 return CMD_SUCCESS;
6716}
6717
ajs5a646652004-11-05 01:25:55 +00006718static int
paulfee0f4c2004-09-13 05:12:46 +00006719bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006720 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006721{
6722 struct bgp_table *table;
6723
6724 if (bgp == NULL) {
6725 bgp = bgp_get_default ();
6726 }
6727
6728 if (bgp == NULL)
6729 {
6730 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6731 return CMD_WARNING;
6732 }
6733
6734
6735 table = bgp->rib[afi][safi];
6736
ajs5a646652004-11-05 01:25:55 +00006737 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006738}
6739
paul718e3742002-12-13 20:15:29 +00006740/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006741static void
paul718e3742002-12-13 20:15:29 +00006742route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6743 struct bgp_node *rn,
6744 struct prefix_rd *prd, afi_t afi, safi_t safi)
6745{
6746 struct bgp_info *ri;
6747 struct prefix *p;
6748 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006749 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006750 char buf1[INET6_ADDRSTRLEN];
6751 char buf2[INET6_ADDRSTRLEN];
6752 int count = 0;
6753 int best = 0;
6754 int suppress = 0;
6755 int no_export = 0;
6756 int no_advertise = 0;
6757 int local_as = 0;
6758 int first = 0;
Lou Berger298cc2f2016-01-12 13:42:02 -05006759 int printrd = ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP));
paul718e3742002-12-13 20:15:29 +00006760
6761 p = &rn->p;
6762 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
Lou Berger298cc2f2016-01-12 13:42:02 -05006763 (printrd ? prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6764 printrd ? ":" : "",
paul718e3742002-12-13 20:15:29 +00006765 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6766 p->prefixlen, VTY_NEWLINE);
6767
6768 for (ri = rn->info; ri; ri = ri->next)
6769 {
6770 count++;
6771 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6772 {
6773 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006774 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006775 suppress = 1;
6776 if (ri->attr->community != NULL)
6777 {
6778 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6779 no_advertise = 1;
6780 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6781 no_export = 1;
6782 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6783 local_as = 1;
6784 }
6785 }
6786 }
6787
6788 vty_out (vty, "Paths: (%d available", count);
6789 if (best)
6790 {
6791 vty_out (vty, ", best #%d", best);
6792 if (safi == SAFI_UNICAST)
6793 vty_out (vty, ", table Default-IP-Routing-Table");
6794 }
6795 else
6796 vty_out (vty, ", no best path");
6797 if (no_advertise)
6798 vty_out (vty, ", not advertised to any peer");
6799 else if (no_export)
6800 vty_out (vty, ", not advertised to EBGP peer");
6801 else if (local_as)
6802 vty_out (vty, ", not advertised outside local AS");
6803 if (suppress)
6804 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6805 vty_out (vty, ")%s", VTY_NEWLINE);
6806
6807 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006808 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006809 {
6810 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6811 {
6812 if (! first)
6813 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6814 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6815 first = 1;
6816 }
6817 }
6818 if (! first)
6819 vty_out (vty, " Not advertised to any peer");
6820 vty_out (vty, "%s", VTY_NEWLINE);
6821}
6822
6823/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006824static int
paulfee0f4c2004-09-13 05:12:46 +00006825bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006826 struct bgp_table *rib, const char *ip_str,
6827 afi_t afi, safi_t safi, struct prefix_rd *prd,
6828 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006829{
6830 int ret;
6831 int header;
6832 int display = 0;
6833 struct prefix match;
6834 struct bgp_node *rn;
6835 struct bgp_node *rm;
6836 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006837 struct bgp_table *table;
6838
Lou Berger050defe2016-01-12 13:41:59 -05006839 memset (&match, 0, sizeof (struct prefix)); /* keep valgrind happy */
paul718e3742002-12-13 20:15:29 +00006840 /* Check IP address argument. */
6841 ret = str2prefix (ip_str, &match);
6842 if (! ret)
6843 {
6844 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6845 return CMD_WARNING;
6846 }
6847
6848 match.family = afi2family (afi);
6849
Lou Berger298cc2f2016-01-12 13:42:02 -05006850 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00006851 {
paulfee0f4c2004-09-13 05:12:46 +00006852 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006853 {
6854 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6855 continue;
6856
6857 if ((table = rn->info) != NULL)
6858 {
6859 header = 1;
6860
6861 if ((rm = bgp_node_match (table, &match)) != NULL)
6862 {
6863 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006864 {
6865 bgp_unlock_node (rm);
6866 continue;
6867 }
paul718e3742002-12-13 20:15:29 +00006868
6869 for (ri = rm->info; ri; ri = ri->next)
6870 {
6871 if (header)
6872 {
6873 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
Lou Berger298cc2f2016-01-12 13:42:02 -05006874 AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00006875
6876 header = 0;
6877 }
6878 display++;
Lou Berger298cc2f2016-01-12 13:42:02 -05006879 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00006880 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006881
6882 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006883 }
6884 }
6885 }
6886 }
6887 else
6888 {
6889 header = 1;
6890
paulfee0f4c2004-09-13 05:12:46 +00006891 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006892 {
6893 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6894 {
6895 for (ri = rn->info; ri; ri = ri->next)
6896 {
6897 if (header)
6898 {
6899 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6900 header = 0;
6901 }
6902 display++;
6903 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6904 }
6905 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006906
6907 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006908 }
6909 }
6910
6911 if (! display)
6912 {
6913 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6914 return CMD_WARNING;
6915 }
6916
6917 return CMD_SUCCESS;
6918}
6919
paulfee0f4c2004-09-13 05:12:46 +00006920/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006921static int
paulfd79ac92004-10-13 05:06:08 +00006922bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006923 afi_t afi, safi_t safi, struct prefix_rd *prd,
6924 int prefix_check)
6925{
6926 struct bgp *bgp;
6927
6928 /* BGP structure lookup. */
6929 if (view_name)
6930 {
6931 bgp = bgp_lookup_by_name (view_name);
6932 if (bgp == NULL)
6933 {
6934 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6935 return CMD_WARNING;
6936 }
6937 }
6938 else
6939 {
6940 bgp = bgp_get_default ();
6941 if (bgp == NULL)
6942 {
6943 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6944 return CMD_WARNING;
6945 }
6946 }
6947
6948 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6949 afi, safi, prd, prefix_check);
6950}
6951
paul718e3742002-12-13 20:15:29 +00006952/* BGP route print out function. */
Lou Berger35c36862016-01-12 13:42:06 -05006953DEFUN (show_bgp_ipv4_safi,
6954 show_bgp_ipv4_safi_cmd,
6955 "show bgp ipv4 (unicast|multicast)",
paul718e3742002-12-13 20:15:29 +00006956 SHOW_STR
paul718e3742002-12-13 20:15:29 +00006957 BGP_STR
6958 "Address family\n"
6959 "Address Family modifier\n"
6960 "Address Family modifier\n")
6961{
6962 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006963 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6964 NULL);
paul718e3742002-12-13 20:15:29 +00006965
ajs5a646652004-11-05 01:25:55 +00006966 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006967}
6968
Lou Berger35c36862016-01-12 13:42:06 -05006969DEFUN (show_bgp_ipv4_safi_route,
6970 show_bgp_ipv4_safi_route_cmd,
6971 "show bgp ipv4 (unicast|multicast) A.B.C.D",
Michael Lambert95cbbd22010-07-23 14:43:04 -04006972 SHOW_STR
6973 BGP_STR
6974 "Address family\n"
6975 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00006976 "Address Family modifier\n"
6977 "Network in the BGP routing table to display\n")
6978{
6979 if (strncmp (argv[0], "m", 1) == 0)
6980 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6981
6982 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6983}
6984
Lou Berger35c36862016-01-12 13:42:06 -05006985DEFUN (show_bgp_ipv4_vpn_route,
6986 show_bgp_ipv4_vpn_route_cmd,
6987 "show bgp ipv4 vpn A.B.C.D",
Michael Lambert95cbbd22010-07-23 14:43:04 -04006988 SHOW_STR
6989 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05006990 "Address Family\n"
6991 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +00006992 "Network in the BGP routing table to display\n")
6993{
6994 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6995}
6996
Lou Berger35c36862016-01-12 13:42:06 -05006997#ifdef HAVE_IPV6
6998DEFUN (show_bgp_ipv6_vpn_route,
6999 show_bgp_ipv6_vpn_route_cmd,
7000 "show bgp ipv6 vpn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007001 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007002 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007003 "Address Family\n"
7004 "Display VPN NLRI specific information\n"
7005 "Network in the BGP routing table to display\n")
7006{
7007 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MPLS_VPN, NULL, 0);
7008}
7009#endif
7010
7011DEFUN (show_bgp_ipv4_vpn_rd_route,
7012 show_bgp_ipv4_vpn_rd_route_cmd,
7013 "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn A.B.C.D",
7014 SHOW_STR
7015 BGP_STR
7016 IP_STR
7017 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +00007018 "Display information for a route distinguisher\n"
7019 "VPN Route Distinguisher\n"
7020 "Network in the BGP routing table to display\n")
7021{
7022 int ret;
7023 struct prefix_rd prd;
7024
7025 ret = str2prefix_rd (argv[0], &prd);
7026 if (! ret)
7027 {
7028 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7029 return CMD_WARNING;
7030 }
7031 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
7032}
7033
Lou Berger35c36862016-01-12 13:42:06 -05007034DEFUN (show_bgp_ipv6_vpn_rd_route,
7035 show_bgp_ipv6_vpn_rd_route_cmd,
7036 "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007037 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007038 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007039 "Address Family\n"
7040 "Display VPN NLRI specific information\n"
7041 "Display information for a route distinguisher\n"
7042 "VPN Route Distinguisher\n"
7043 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007044{
Lou Berger35c36862016-01-12 13:42:06 -05007045 int ret;
7046 struct prefix_rd prd;
7047
7048 ret = str2prefix_rd (argv[0], &prd);
7049 if (! ret)
7050 {
7051 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7052 return CMD_WARNING;
7053 }
7054 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MPLS_VPN, &prd, 0);
paul718e3742002-12-13 20:15:29 +00007055}
7056
Lou Berger651b4022016-01-12 13:42:07 -05007057DEFUN (show_bgp_ipv4_encap_route,
7058 show_bgp_ipv4_encap_route_cmd,
7059 "show bgp ipv4 encap A.B.C.D",
paul718e3742002-12-13 20:15:29 +00007060 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007061 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007062 IP_STR
7063 "Display ENCAP NLRI specific information\n"
7064 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007065{
Lou Berger651b4022016-01-12 13:42:07 -05007066 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 0);
paul718e3742002-12-13 20:15:29 +00007067}
7068
Lou Berger651b4022016-01-12 13:42:07 -05007069#ifdef HAVE_IPV6
7070DEFUN (show_bgp_ipv6_encap_route,
7071 show_bgp_ipv6_encap_route_cmd,
7072 "show bgp ipv6 encap X:X::X:X",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007073 SHOW_STR
7074 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007075 IP6_STR
7076 "Display ENCAP NLRI specific information\n"
7077 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007078{
Lou Berger651b4022016-01-12 13:42:07 -05007079 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 0);
paul718e3742002-12-13 20:15:29 +00007080}
Lou Berger651b4022016-01-12 13:42:07 -05007081#endif
paul718e3742002-12-13 20:15:29 +00007082
Lou Berger651b4022016-01-12 13:42:07 -05007083DEFUN (show_bgp_ipv4_safi_rd_route,
7084 show_bgp_ipv4_safi_rd_route_cmd,
7085 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D",
paul718e3742002-12-13 20:15:29 +00007086 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007087 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007088 "Address Family\n"
7089 "Address Family Modifier\n"
7090 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00007091 "Display information for a route distinguisher\n"
Lou Berger651b4022016-01-12 13:42:07 -05007092 "ENCAP Route Distinguisher\n"
7093 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007094{
7095 int ret;
7096 struct prefix_rd prd;
Lou Berger651b4022016-01-12 13:42:07 -05007097 safi_t safi;
paul718e3742002-12-13 20:15:29 +00007098
Lou Berger651b4022016-01-12 13:42:07 -05007099 if (bgp_parse_safi(argv[0], &safi)) {
7100 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7101 return CMD_WARNING;
7102 }
7103 ret = str2prefix_rd (argv[1], &prd);
paul718e3742002-12-13 20:15:29 +00007104 if (! ret)
7105 {
7106 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7107 return CMD_WARNING;
7108 }
Lou Berger651b4022016-01-12 13:42:07 -05007109 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 0);
paul718e3742002-12-13 20:15:29 +00007110}
7111
Lou Berger651b4022016-01-12 13:42:07 -05007112#ifdef HAVE_IPV6
7113DEFUN (show_bgp_ipv6_safi_rd_route,
7114 show_bgp_ipv6_safi_rd_route_cmd,
7115 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007116 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007117 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007118 "Address Family\n"
7119 "Address Family Modifier\n"
7120 "Address Family Modifier\n"
7121 "Display information for a route distinguisher\n"
7122 "ENCAP Route Distinguisher\n"
7123 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007124{
Lou Berger651b4022016-01-12 13:42:07 -05007125 int ret;
7126 struct prefix_rd prd;
7127 safi_t safi;
paulbb46e942003-10-24 19:02:03 +00007128
Lou Berger651b4022016-01-12 13:42:07 -05007129 if (bgp_parse_safi(argv[0], &safi)) {
7130 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7131 return CMD_WARNING;
7132 }
7133 ret = str2prefix_rd (argv[1], &prd);
7134 if (! ret)
7135 {
7136 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7137 return CMD_WARNING;
7138 }
7139 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, SAFI_ENCAP, &prd, 0);
paul718e3742002-12-13 20:15:29 +00007140}
Lou Berger651b4022016-01-12 13:42:07 -05007141#endif
paul718e3742002-12-13 20:15:29 +00007142
Lou Berger35c36862016-01-12 13:42:06 -05007143DEFUN (show_bgp_ipv4_prefix,
7144 show_bgp_ipv4_prefix_cmd,
7145 "show bgp ipv4 A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007146 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007147 BGP_STR
paul718e3742002-12-13 20:15:29 +00007148 IP_STR
paul718e3742002-12-13 20:15:29 +00007149 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7150{
Lou Berger35c36862016-01-12 13:42:06 -05007151 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
paul718e3742002-12-13 20:15:29 +00007152}
7153
Lou Berger35c36862016-01-12 13:42:06 -05007154DEFUN (show_bgp_ipv4_safi_prefix,
7155 show_bgp_ipv4_safi_prefix_cmd,
7156 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007157 SHOW_STR
7158 BGP_STR
7159 "Address family\n"
7160 "Address Family modifier\n"
Lou Berger35c36862016-01-12 13:42:06 -05007161 "Address Family modifier\n"
7162 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007163{
7164 if (strncmp (argv[0], "m", 1) == 0)
Lou Berger35c36862016-01-12 13:42:06 -05007165 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007166
Lou Berger35c36862016-01-12 13:42:06 -05007167 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007168}
7169
Lou Berger35c36862016-01-12 13:42:06 -05007170DEFUN (show_bgp_ipv4_vpn_prefix,
7171 show_bgp_ipv4_vpn_prefix_cmd,
7172 "show bgp ipv4 vpn A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007173 SHOW_STR
7174 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007175 IP_STR
7176 "Display VPN NLRI specific information\n"
7177 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paul718e3742002-12-13 20:15:29 +00007178{
Lou Berger35c36862016-01-12 13:42:06 -05007179 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
paul718e3742002-12-13 20:15:29 +00007180}
7181
Lou Berger35c36862016-01-12 13:42:06 -05007182#ifdef HAVE_IPV6
7183DEFUN (show_bgp_ipv6_vpn_prefix,
7184 show_bgp_ipv6_vpn_prefix_cmd,
7185 "show bgp ipv6 vpn X:X::X:X/M",
7186 SHOW_STR
7187 BGP_STR
7188 "Address Family\n"
7189 "Display VPN NLRI specific information\n"
7190 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7191{
7192 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MPLS_VPN, NULL, 1);
7193}
7194#endif
7195
Lou Berger651b4022016-01-12 13:42:07 -05007196DEFUN (show_bgp_ipv4_encap_prefix,
7197 show_bgp_ipv4_encap_prefix_cmd,
7198 "show bgp ipv4 encap A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007199 SHOW_STR
7200 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007201 IP_STR
7202 "Display ENCAP NLRI specific information\n"
7203 "Display information about ENCAP NLRIs\n"
7204 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7205{
7206 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 1);
7207}
paul718e3742002-12-13 20:15:29 +00007208
Lou Berger651b4022016-01-12 13:42:07 -05007209#ifdef HAVE_IPV6
7210DEFUN (show_bgp_ipv6_encap_prefix,
7211 show_bgp_ipv6_encap_prefix_cmd,
7212 "show bgp ipv6 encap X:X::X:X/M",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007213 SHOW_STR
7214 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007215 IP_STR
7216 "Display ENCAP NLRI specific information\n"
7217 "Display information about ENCAP NLRIs\n"
7218 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7219{
7220 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 1);
7221}
7222#endif
7223
7224DEFUN (show_bgp_ipv4_safi_rd_prefix,
7225 show_bgp_ipv4_safi_rd_prefix_cmd,
7226 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7227 SHOW_STR
7228 BGP_STR
7229 "Address Family\n"
7230 "Address Family Modifier\n"
7231 "Address Family Modifier\n"
7232 "Display information for a route distinguisher\n"
7233 "ENCAP Route Distinguisher\n"
7234 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7235{
7236 int ret;
7237 struct prefix_rd prd;
7238 safi_t safi;
7239
7240 if (bgp_parse_safi(argv[0], &safi)) {
7241 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7242 return CMD_WARNING;
7243 }
7244
7245 ret = str2prefix_rd (argv[1], &prd);
7246 if (! ret)
7247 {
7248 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7249 return CMD_WARNING;
7250 }
7251 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 1);
7252}
7253
7254#ifdef HAVE_IPV6
7255DEFUN (show_bgp_ipv6_safi_rd_prefix,
7256 show_bgp_ipv6_safi_rd_prefix_cmd,
7257 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X/M",
7258 SHOW_STR
7259 BGP_STR
7260 "Address Family\n"
7261 "Address Family Modifier\n"
7262 "Address Family Modifier\n"
7263 "Display information for a route distinguisher\n"
7264 "ENCAP Route Distinguisher\n"
7265 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7266{
7267 int ret;
7268 struct prefix_rd prd;
7269 safi_t safi;
7270
7271 if (bgp_parse_safi(argv[0], &safi)) {
7272 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7273 return CMD_WARNING;
7274 }
7275
7276 ret = str2prefix_rd (argv[1], &prd);
7277 if (! ret)
7278 {
7279 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7280 return CMD_WARNING;
7281 }
7282 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, safi, &prd, 1);
7283}
7284#endif
7285
7286DEFUN (show_bgp_afi_safi_view,
7287 show_bgp_afi_safi_view_cmd,
7288 "show bgp view WORD (ipv4|ipv6) (encap|mulicast|unicast|vpn)",
7289 SHOW_STR
7290 BGP_STR
7291 "BGP view\n"
7292 "BGP view name\n"
7293 "Address Family\n"
7294 "Address Family\n"
7295 "Address Family Modifier\n"
7296 "Address Family Modifier\n"
7297 "Address Family Modifier\n"
7298 "Address Family Modifier\n"
7299 )
7300{
7301 struct bgp *bgp;
7302 safi_t safi;
7303 afi_t afi;
7304
7305 if (bgp_parse_afi(argv[1], &afi)) {
7306 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7307 return CMD_WARNING;
7308 }
7309 if (bgp_parse_safi(argv[2], &safi)) {
7310 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7311 return CMD_WARNING;
7312 }
7313
7314 /* BGP structure lookup. */
7315 bgp = bgp_lookup_by_name (argv[0]);
7316 if (bgp == NULL)
7317 {
7318 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7319 return CMD_WARNING;
7320 }
7321
7322 return bgp_show (vty, bgp, afi, safi, bgp_show_type_normal, NULL);
7323}
7324
7325DEFUN (show_bgp_view_afi_safi_route,
7326 show_bgp_view_afi_safi_route_cmd,
7327 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) A.B.C.D",
7328 SHOW_STR
7329 BGP_STR
7330 "BGP view\n"
7331 "View name\n"
7332 "Address Family\n"
7333 "Address Family\n"
7334 "Address Family Modifier\n"
7335 "Address Family Modifier\n"
7336 "Address Family Modifier\n"
7337 "Address Family Modifier\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007338 "Network in the BGP routing table to display\n")
7339{
Lou Berger651b4022016-01-12 13:42:07 -05007340 safi_t safi;
7341 afi_t afi;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007342
Lou Berger651b4022016-01-12 13:42:07 -05007343 if (bgp_parse_afi(argv[1], &afi)) {
7344 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7345 return CMD_WARNING;
7346 }
7347 if (bgp_parse_safi(argv[2], &safi)) {
7348 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7349 return CMD_WARNING;
7350 }
7351 return bgp_show_route (vty, argv[0], argv[3], afi, safi, NULL, 0);
7352}
7353
7354DEFUN (show_bgp_view_afi_safi_prefix,
7355 show_bgp_view_afi_safi_prefix_cmd,
7356 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) A.B.C.D/M",
7357 SHOW_STR
7358 BGP_STR
7359 "BGP view\n"
7360 "View name\n"
7361 "Address Family\n"
7362 "Address Family\n"
7363 "Address Family Modifier\n"
7364 "Address Family Modifier\n"
7365 "Address Family Modifier\n"
7366 "Address Family Modifier\n"
7367 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7368{
7369 safi_t safi;
7370 afi_t afi;
7371
7372 if (bgp_parse_afi(argv[1], &afi)) {
7373 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7374 return CMD_WARNING;
7375 }
7376 if (bgp_parse_safi(argv[2], &safi)) {
7377 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7378 return CMD_WARNING;
7379 }
7380 return bgp_show_route (vty, argv[0], argv[3], afi, safi, NULL, 1);
7381}
7382
7383/* new001 */
7384DEFUN (show_bgp_afi,
7385 show_bgp_afi_cmd,
7386 "show bgp (ipv4|ipv6)",
7387 SHOW_STR
7388 BGP_STR
7389 "Address family\n"
7390 "Address family\n")
7391{
7392 afi_t afi;
7393
7394 if (bgp_parse_afi(argv[0], &afi)) {
7395 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7396 return CMD_WARNING;
7397 }
7398 return bgp_show (vty, NULL, afi, SAFI_UNICAST, bgp_show_type_normal,
7399 NULL);
7400}
7401
7402#ifdef HAVE_IPV6
7403DEFUN (show_bgp_ipv6_safi,
7404 show_bgp_ipv6_safi_cmd,
7405 "show bgp ipv6 (unicast|multicast)",
7406 SHOW_STR
7407 BGP_STR
7408 "Address family\n"
7409 "Address Family modifier\n"
7410 "Address Family modifier\n")
7411{
7412 if (strncmp (argv[0], "m", 1) == 0)
7413 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7414 NULL);
7415
7416 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007417}
7418
Lou Berger35c36862016-01-12 13:42:06 -05007419DEFUN (show_bgp_ipv6_route,
7420 show_bgp_ipv6_route_cmd,
7421 "show bgp ipv6 X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007422 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007423 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007424 "Address family\n"
paul718e3742002-12-13 20:15:29 +00007425 "Network in the BGP routing table to display\n")
7426{
7427 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7428}
7429
Lou Berger35c36862016-01-12 13:42:06 -05007430DEFUN (show_bgp_ipv6_safi_route,
7431 show_bgp_ipv6_safi_route_cmd,
7432 "show bgp ipv6 (unicast|multicast) X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007433 SHOW_STR
7434 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007435 "Address family\n"
7436 "Address Family modifier\n"
7437 "Address Family modifier\n"
7438 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007439{
Lou Berger35c36862016-01-12 13:42:06 -05007440 if (strncmp (argv[0], "m", 1) == 0)
7441 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7442
7443 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
paul718e3742002-12-13 20:15:29 +00007444}
7445
Lou Berger35c36862016-01-12 13:42:06 -05007446/* new002 */
7447DEFUN (show_bgp_ipv6_prefix,
paul718e3742002-12-13 20:15:29 +00007448 show_bgp_ipv6_prefix_cmd,
7449 "show bgp ipv6 X:X::X:X/M",
7450 SHOW_STR
7451 BGP_STR
7452 "Address family\n"
Lou Berger35c36862016-01-12 13:42:06 -05007453 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7454{
7455 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7456}
Michael Lambert95cbbd22010-07-23 14:43:04 -04007457DEFUN (show_bgp_ipv6_safi_prefix,
7458 show_bgp_ipv6_safi_prefix_cmd,
7459 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
7460 SHOW_STR
7461 BGP_STR
7462 "Address family\n"
7463 "Address Family modifier\n"
7464 "Address Family modifier\n"
7465 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7466{
7467 if (strncmp (argv[0], "m", 1) == 0)
7468 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7469
7470 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7471}
7472
paulbb46e942003-10-24 19:02:03 +00007473DEFUN (show_bgp_view,
Lou Berger35c36862016-01-12 13:42:06 -05007474 show_bgp_view_ipv6_cmd,
7475 "show bgp view WORD ipv6",
paulbb46e942003-10-24 19:02:03 +00007476 SHOW_STR
Lou Berger35c36862016-01-12 13:42:06 -05007477 BGP_STR
paulbb46e942003-10-24 19:02:03 +00007478 "BGP view\n"
Lou Berger35c36862016-01-12 13:42:06 -05007479 "View name\n"
7480 "Address family\n")
paulbb46e942003-10-24 19:02:03 +00007481{
7482 struct bgp *bgp;
7483
7484 /* BGP structure lookup. */
7485 bgp = bgp_lookup_by_name (argv[0]);
7486 if (bgp == NULL)
7487 {
7488 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7489 return CMD_WARNING;
7490 }
7491
ajs5a646652004-11-05 01:25:55 +00007492 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007493}
paulbb46e942003-10-24 19:02:03 +00007494
7495DEFUN (show_bgp_view_route,
paulbb46e942003-10-24 19:02:03 +00007496 show_bgp_view_ipv6_route_cmd,
7497 "show bgp view WORD ipv6 X:X::X:X",
7498 SHOW_STR
7499 BGP_STR
7500 "BGP view\n"
7501 "View name\n"
7502 "Address family\n"
7503 "Network in the BGP routing table to display\n")
paulbb46e942003-10-24 19:02:03 +00007504{
Lou Berger35c36862016-01-12 13:42:06 -05007505 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
paulbb46e942003-10-24 19:02:03 +00007506}
7507
Lou Berger35c36862016-01-12 13:42:06 -05007508DEFUN (show_bgp_view_prefix,
paulbb46e942003-10-24 19:02:03 +00007509 show_bgp_view_ipv6_prefix_cmd,
7510 "show bgp view WORD ipv6 X:X::X:X/M",
7511 SHOW_STR
7512 BGP_STR
7513 "BGP view\n"
7514 "View name\n"
7515 "Address family\n"
7516 "IPv6 prefix <network>/<length>\n")
paul718e3742002-12-13 20:15:29 +00007517{
Lou Berger35c36862016-01-12 13:42:06 -05007518 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
paul718e3742002-12-13 20:15:29 +00007519}
7520
paul718e3742002-12-13 20:15:29 +00007521#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02007522
paul718e3742002-12-13 20:15:29 +00007523
paul94f2b392005-06-28 12:44:16 +00007524static int
paulfd79ac92004-10-13 05:06:08 +00007525bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007526 safi_t safi, enum bgp_show_type type)
7527{
7528 int i;
7529 struct buffer *b;
7530 char *regstr;
7531 int first;
7532 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007533 int rc;
paul718e3742002-12-13 20:15:29 +00007534
7535 first = 0;
7536 b = buffer_new (1024);
7537 for (i = 0; i < argc; i++)
7538 {
7539 if (first)
7540 buffer_putc (b, ' ');
7541 else
7542 {
7543 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7544 continue;
7545 first = 1;
7546 }
7547
7548 buffer_putstr (b, argv[i]);
7549 }
7550 buffer_putc (b, '\0');
7551
7552 regstr = buffer_getstr (b);
7553 buffer_free (b);
7554
7555 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007556 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007557 if (! regex)
7558 {
7559 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7560 VTY_NEWLINE);
7561 return CMD_WARNING;
7562 }
7563
ajs5a646652004-11-05 01:25:55 +00007564 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7565 bgp_regex_free (regex);
7566 return rc;
paul718e3742002-12-13 20:15:29 +00007567}
7568
Lou Berger651b4022016-01-12 13:42:07 -05007569DEFUN (show_bgp_ipv4_safi_flap_regexp,
7570 show_bgp_ipv4_safi_flap_regexp_cmd,
7571 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics regexp .LINE",
paul718e3742002-12-13 20:15:29 +00007572 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007573 BGP_STR
paul718e3742002-12-13 20:15:29 +00007574 IP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007575 "Address Family Modifier\n"
7576 "Address Family Modifier\n"
7577 "Address Family Modifier\n"
7578 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00007579 "Display flap statistics of routes\n"
7580 "Display routes matching the AS path regular expression\n"
7581 "A regular-expression to match the BGP AS paths\n")
7582{
Lou Berger651b4022016-01-12 13:42:07 -05007583 safi_t safi;
7584
7585 if (bgp_parse_safi(argv[0], &safi)) {
7586 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7587 return CMD_WARNING;
7588 }
7589 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP, safi,
7590 bgp_show_type_flap_regexp);
paul718e3742002-12-13 20:15:29 +00007591}
7592
Lou Berger651b4022016-01-12 13:42:07 -05007593ALIAS (show_bgp_ipv4_safi_flap_regexp,
7594 show_bgp_ipv4_safi_damp_flap_regexp_cmd,
7595 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics regexp .LINE",
Balaji3921cc52015-05-16 23:12:17 +05307596 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05307597 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007598 IP_STR
7599 "Address Family Modifier\n"
7600 "Address Family Modifier\n"
7601 "Address Family Modifier\n"
7602 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05307603 "Display detailed information about dampening\n"
7604 "Display flap statistics of routes\n"
7605 "Display routes matching the AS path regular expression\n"
7606 "A regular-expression to match the BGP AS paths\n")
7607
Lou Berger651b4022016-01-12 13:42:07 -05007608#ifdef HAVE_IPV6
7609DEFUN (show_bgp_ipv6_safi_flap_regexp,
7610 show_bgp_ipv6_safi_flap_regexp_cmd,
7611 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics regexp .LINE",
paul718e3742002-12-13 20:15:29 +00007612 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05007613 BGP_STR
7614 IPV6_STR
7615 "Address Family Modifier\n"
7616 "Address Family Modifier\n"
7617 "Address Family Modifier\n"
7618 "Address Family Modifier\n"
7619 "Display flap statistics of routes\n"
7620 "Display routes matching the AS path regular expression\n"
7621 "A regular-expression to match the BGP AS paths\n")
7622{
7623 safi_t safi;
7624
7625 if (bgp_parse_safi(argv[0], &safi)) {
7626 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7627 return CMD_WARNING;
7628 }
7629 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP6, safi,
7630 bgp_show_type_flap_regexp);
7631}
7632
7633ALIAS (show_bgp_ipv6_safi_flap_regexp,
7634 show_bgp_ipv6_safi_damp_flap_regexp_cmd,
7635 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics regexp .LINE",
7636 SHOW_STR
7637 BGP_STR
7638 IPV6_STR
7639 "Address Family Modifier\n"
7640 "Address Family Modifier\n"
7641 "Address Family Modifier\n"
7642 "Address Family Modifier\n"
7643 "Display detailed information about dampening\n"
7644 "Display flap statistics of routes\n"
7645 "Display routes matching the AS path regular expression\n"
7646 "A regular-expression to match the BGP AS paths\n")
7647#endif
7648
7649DEFUN (show_bgp_ipv4_safi_regexp,
7650 show_bgp_ipv4_safi_regexp_cmd,
7651 "show bgp ipv4 (encap|multicast|unicast|vpn) regexp .LINE",
7652 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007653 BGP_STR
7654 "Address family\n"
7655 "Address Family modifier\n"
7656 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05007657 "Address Family modifier\n"
7658 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00007659 "Display routes matching the AS path regular expression\n"
7660 "A regular-expression to match the BGP AS paths\n")
7661{
Lou Berger651b4022016-01-12 13:42:07 -05007662 safi_t safi;
7663 if (bgp_parse_safi(argv[0], &safi)) {
7664 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7665 return CMD_WARNING;
7666 }
paul718e3742002-12-13 20:15:29 +00007667
Lou Berger651b4022016-01-12 13:42:07 -05007668 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00007669 bgp_show_type_regexp);
7670}
paul718e3742002-12-13 20:15:29 +00007671#ifdef HAVE_IPV6
Lou Berger651b4022016-01-12 13:42:07 -05007672DEFUN (show_bgp_ipv6_safi_regexp,
7673 show_bgp_ipv6_safi_regexp_cmd,
7674 "show bgp ipv6 (encap|multicast|unicast|vpn) regexp .LINE",
paul718e3742002-12-13 20:15:29 +00007675 SHOW_STR
7676 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007677 "Address family\n"
7678 "Address Family modifier\n"
7679 "Address Family modifier\n"
7680 "Address Family modifier\n"
7681 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00007682 "Display routes matching the AS path regular expression\n"
7683 "A regular-expression to match the BGP AS paths\n")
7684{
Lou Berger651b4022016-01-12 13:42:07 -05007685 safi_t safi;
7686 if (bgp_parse_safi(argv[0], &safi)) {
7687 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7688 return CMD_WARNING;
7689 }
7690
7691 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00007692 bgp_show_type_regexp);
7693}
7694
Lou Berger651b4022016-01-12 13:42:07 -05007695DEFUN (show_bgp_ipv6_regexp,
paul718e3742002-12-13 20:15:29 +00007696 show_bgp_ipv6_regexp_cmd,
7697 "show bgp ipv6 regexp .LINE",
7698 SHOW_STR
7699 BGP_STR
7700 "Address family\n"
7701 "Display routes matching the AS path regular expression\n"
7702 "A regular-expression to match the BGP AS paths\n")
paul718e3742002-12-13 20:15:29 +00007703{
7704 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7705 bgp_show_type_regexp);
7706}
7707
paul718e3742002-12-13 20:15:29 +00007708#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007709
paul94f2b392005-06-28 12:44:16 +00007710static int
paulfd79ac92004-10-13 05:06:08 +00007711bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007712 safi_t safi, enum bgp_show_type type)
7713{
7714 struct prefix_list *plist;
7715
7716 plist = prefix_list_lookup (afi, prefix_list_str);
7717 if (plist == NULL)
7718 {
7719 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7720 prefix_list_str, VTY_NEWLINE);
7721 return CMD_WARNING;
7722 }
7723
ajs5a646652004-11-05 01:25:55 +00007724 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007725}
7726
Lou Berger35c36862016-01-12 13:42:06 -05007727DEFUN (show_bgp_ipv4_prefix_list,
7728 show_bgp_ipv4_prefix_list_cmd,
7729 "show bgp ipv4 prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00007730 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007731 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007732 IP_STR
paul718e3742002-12-13 20:15:29 +00007733 "Display routes conforming to the prefix-list\n"
7734 "IP prefix-list name\n")
7735{
7736 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7737 bgp_show_type_prefix_list);
7738}
7739
Lou Berger651b4022016-01-12 13:42:07 -05007740DEFUN (show_bgp_ipv4_safi_flap_prefix_list,
7741 show_bgp_ipv4_safi_flap_prefix_list_cmd,
7742 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00007743 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007744 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007745 IP_STR
7746 "Address Family Modifier\n"
7747 "Address Family Modifier\n"
7748 "Address Family Modifier\n"
7749 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00007750 "Display flap statistics of routes\n"
7751 "Display routes conforming to the prefix-list\n"
7752 "IP prefix-list name\n")
7753{
Lou Berger651b4022016-01-12 13:42:07 -05007754 safi_t safi;
7755 if (bgp_parse_safi(argv[0], &safi)) {
7756 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7757 return CMD_WARNING;
7758 }
7759 return bgp_show_prefix_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00007760 bgp_show_type_flap_prefix_list);
7761}
7762
Lou Berger651b4022016-01-12 13:42:07 -05007763ALIAS (show_bgp_ipv4_safi_flap_prefix_list,
7764 show_bgp_ipv4_safi_damp_flap_prefix_list_cmd,
7765 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics prefix-list WORD",
Balaji3921cc52015-05-16 23:12:17 +05307766 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05307767 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007768 IP_STR
7769 "Address Family Modifier\n"
7770 "Address Family Modifier\n"
7771 "Address Family Modifier\n"
7772 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05307773 "Display detailed information about dampening\n"
7774 "Display flap statistics of routes\n"
7775 "Display routes conforming to the prefix-list\n"
7776 "IP prefix-list name\n")
7777
Lou Berger651b4022016-01-12 13:42:07 -05007778#ifdef HAVE_IPV6
7779DEFUN (show_bgp_ipv6_safi_flap_prefix_list,
7780 show_bgp_ipv6_safi_flap_prefix_list_cmd,
7781 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00007782 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05007783 BGP_STR
7784 IPV6_STR
7785 "Address Family Modifier\n"
7786 "Address Family Modifier\n"
7787 "Address Family Modifier\n"
7788 "Address Family Modifier\n"
7789 "Display flap statistics of routes\n"
7790 "Display routes conforming to the prefix-list\n"
7791 "IP prefix-list name\n")
7792{
7793 safi_t safi;
7794 if (bgp_parse_safi(argv[0], &safi)) {
7795 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7796 return CMD_WARNING;
7797 }
7798 return bgp_show_prefix_list (vty, argv[1], AFI_IP6, safi,
7799 bgp_show_type_flap_prefix_list);
7800}
7801ALIAS (show_bgp_ipv6_safi_flap_prefix_list,
7802 show_bgp_ipv6_safi_damp_flap_prefix_list_cmd,
7803 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics prefix-list WORD",
7804 SHOW_STR
7805 BGP_STR
7806 IPV6_STR
7807 "Address Family Modifier\n"
7808 "Address Family Modifier\n"
7809 "Address Family Modifier\n"
7810 "Address Family Modifier\n"
7811 "Display detailed information about dampening\n"
7812 "Display flap statistics of routes\n"
7813 "Display routes conforming to the prefix-list\n"
7814 "IP prefix-list name\n")
7815#endif
7816
7817DEFUN (show_bgp_ipv4_safi_prefix_list,
7818 show_bgp_ipv4_safi_prefix_list_cmd,
7819 "show bgp ipv4 (encap|multicast|unicast|vpn) prefix-list WORD",
7820 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007821 BGP_STR
7822 "Address family\n"
7823 "Address Family modifier\n"
7824 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05007825 "Address Family modifier\n"
7826 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00007827 "Display routes conforming to the prefix-list\n"
7828 "IP prefix-list name\n")
7829{
Lou Berger651b4022016-01-12 13:42:07 -05007830 safi_t safi;
7831 if (bgp_parse_safi(argv[0], &safi)) {
7832 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7833 return CMD_WARNING;
7834 }
7835 return bgp_show_prefix_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00007836 bgp_show_type_prefix_list);
7837}
paul718e3742002-12-13 20:15:29 +00007838#ifdef HAVE_IPV6
Lou Berger651b4022016-01-12 13:42:07 -05007839DEFUN (show_bgp_ipv6_safi_prefix_list,
7840 show_bgp_ipv6_safi_prefix_list_cmd,
7841 "show bgp ipv6 (encap|multicast|unicast|vpn) prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00007842 SHOW_STR
7843 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007844 "Address family\n"
7845 "Address Family modifier\n"
7846 "Address Family modifier\n"
7847 "Address Family modifier\n"
7848 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00007849 "Display routes conforming to the prefix-list\n"
Lou Berger651b4022016-01-12 13:42:07 -05007850 "IP prefix-list name\n")
paul718e3742002-12-13 20:15:29 +00007851{
Lou Berger651b4022016-01-12 13:42:07 -05007852 safi_t safi;
7853 if (bgp_parse_safi(argv[0], &safi)) {
7854 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7855 return CMD_WARNING;
7856 }
7857 return bgp_show_prefix_list (vty, argv[1], AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00007858 bgp_show_type_prefix_list);
7859}
7860
Lou Berger651b4022016-01-12 13:42:07 -05007861DEFUN (show_bgp_prefix_list,
paul718e3742002-12-13 20:15:29 +00007862 show_bgp_ipv6_prefix_list_cmd,
7863 "show bgp ipv6 prefix-list WORD",
7864 SHOW_STR
7865 BGP_STR
7866 "Address family\n"
7867 "Display routes conforming to the prefix-list\n"
7868 "IPv6 prefix-list name\n")
paul718e3742002-12-13 20:15:29 +00007869{
7870 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7871 bgp_show_type_prefix_list);
7872}
7873
paul718e3742002-12-13 20:15:29 +00007874#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007875
paul94f2b392005-06-28 12:44:16 +00007876static int
paulfd79ac92004-10-13 05:06:08 +00007877bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007878 safi_t safi, enum bgp_show_type type)
7879{
7880 struct as_list *as_list;
7881
7882 as_list = as_list_lookup (filter);
7883 if (as_list == NULL)
7884 {
7885 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7886 return CMD_WARNING;
7887 }
7888
ajs5a646652004-11-05 01:25:55 +00007889 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007890}
7891
Lou Berger651b4022016-01-12 13:42:07 -05007892DEFUN (show_bgp_ipv4_filter_list,
7893 show_bgp_ipv4_filter_list_cmd,
7894 "show bgp ipv4 filter-list WORD",
paul718e3742002-12-13 20:15:29 +00007895 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007896 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007897 IP_STR
paul718e3742002-12-13 20:15:29 +00007898 "Display routes conforming to the filter-list\n"
7899 "Regular expression access list name\n")
7900{
7901 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7902 bgp_show_type_filter_list);
7903}
7904
Lou Berger651b4022016-01-12 13:42:07 -05007905DEFUN (show_bgp_ipv4_safi_flap_filter_list,
7906 show_bgp_ipv4_safi_flap_filter_list_cmd,
7907 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics filter-list WORD",
paul718e3742002-12-13 20:15:29 +00007908 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007909 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007910 IP_STR
7911 "Address Family modifier\n"
7912 "Address Family modifier\n"
7913 "Address Family modifier\n"
7914 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00007915 "Display flap statistics of routes\n"
7916 "Display routes conforming to the filter-list\n"
7917 "Regular expression access list name\n")
7918{
Lou Berger651b4022016-01-12 13:42:07 -05007919 safi_t safi;
7920
7921 if (bgp_parse_safi(argv[0], &safi)) {
7922 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7923 return CMD_WARNING;
7924 }
7925 return bgp_show_filter_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00007926 bgp_show_type_flap_filter_list);
7927}
7928
Lou Berger651b4022016-01-12 13:42:07 -05007929ALIAS (show_bgp_ipv4_safi_flap_filter_list,
7930 show_bgp_ipv4_safi_damp_flap_filter_list_cmd,
7931 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics filter-list WORD",
Balaji3921cc52015-05-16 23:12:17 +05307932 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05307933 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007934 IP_STR
7935 "Address Family modifier\n"
7936 "Address Family modifier\n"
7937 "Address Family modifier\n"
7938 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05307939 "Display detailed information about dampening\n"
7940 "Display flap statistics of routes\n"
7941 "Display routes conforming to the filter-list\n"
7942 "Regular expression access list name\n")
7943
paul718e3742002-12-13 20:15:29 +00007944#ifdef HAVE_IPV6
Lou Berger651b4022016-01-12 13:42:07 -05007945DEFUN (show_bgp_ipv6_safi_flap_filter_list,
7946 show_bgp_ipv6_safi_flap_filter_list_cmd,
7947 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics filter-list WORD",
paul718e3742002-12-13 20:15:29 +00007948 SHOW_STR
7949 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007950 IPV6_STR
7951 "Address Family modifier\n"
7952 "Address Family modifier\n"
7953 "Address Family modifier\n"
7954 "Address Family modifier\n"
7955 "Display flap statistics of routes\n"
paul718e3742002-12-13 20:15:29 +00007956 "Display routes conforming to the filter-list\n"
7957 "Regular expression access list name\n")
7958{
Lou Berger651b4022016-01-12 13:42:07 -05007959 safi_t safi;
7960
7961 if (bgp_parse_safi(argv[0], &safi)) {
7962 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7963 return CMD_WARNING;
7964 }
7965 return bgp_show_filter_list (vty, argv[1], AFI_IP6, safi,
7966 bgp_show_type_flap_filter_list);
7967}
7968ALIAS (show_bgp_ipv6_safi_flap_filter_list,
7969 show_bgp_ipv6_safi_damp_flap_filter_list_cmd,
7970 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics filter-list WORD",
7971 SHOW_STR
7972 BGP_STR
7973 IPV6_STR
7974 "Address Family modifier\n"
7975 "Address Family modifier\n"
7976 "Address Family modifier\n"
7977 "Address Family modifier\n"
7978 "Display detailed information about dampening\n"
7979 "Display flap statistics of routes\n"
7980 "Display routes conforming to the filter-list\n"
7981 "Regular expression access list name\n")
7982#endif
7983
7984DEFUN (show_bgp_ipv4_safi_filter_list,
7985 show_bgp_ipv4_safi_filter_list_cmd,
7986 "show bgp ipv4 (encap|multicast|unicast|vpn) filter-list WORD",
7987 SHOW_STR
7988 BGP_STR
7989 "Address Family modifier\n"
7990 "Address Family modifier\n"
7991 "Address Family modifier\n"
7992 "Address Family modifier\n"
7993 "Display routes conforming to the filter-list\n"
7994 "Regular expression access list name\n")
7995{
7996 safi_t safi;
7997
7998 if (bgp_parse_safi(argv[0], &safi)) {
7999 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8000 return CMD_WARNING;
8001 }
8002 return bgp_show_filter_list (vty, argv[1], AFI_IP, safi,
8003 bgp_show_type_filter_list);
8004}
8005#ifdef HAVE_IPV6
8006DEFUN (show_bgp_ipv6_safi_filter_list,
8007 show_bgp_ipv6_safi_filter_list_cmd,
8008 "show bgp ipv6 (encap|multicast|unicast|vpn) filter-list WORD",
8009 SHOW_STR
8010 BGP_STR
8011 "Address Family modifier\n"
8012 "Address Family modifier\n"
8013 "Address Family modifier\n"
8014 "Address Family modifier\n"
8015 "Display routes conforming to the filter-list\n"
8016 "Regular expression access list name\n")
8017{
8018 safi_t safi;
8019
8020 if (bgp_parse_safi(argv[0], &safi)) {
8021 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8022 return CMD_WARNING;
8023 }
8024 return bgp_show_filter_list (vty, argv[1], AFI_IP6, safi,
8025 bgp_show_type_filter_list);
paul718e3742002-12-13 20:15:29 +00008026}
8027
Lou Berger651b4022016-01-12 13:42:07 -05008028DEFUN (show_bgp_filter_list,
paul718e3742002-12-13 20:15:29 +00008029 show_bgp_ipv6_filter_list_cmd,
8030 "show bgp ipv6 filter-list WORD",
8031 SHOW_STR
8032 BGP_STR
8033 "Address family\n"
8034 "Display routes conforming to the filter-list\n"
8035 "Regular expression access list name\n")
paul718e3742002-12-13 20:15:29 +00008036{
8037 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8038 bgp_show_type_filter_list);
8039}
8040
paul718e3742002-12-13 20:15:29 +00008041#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02008042
Balaji3921cc52015-05-16 23:12:17 +05308043DEFUN (show_ip_bgp_dampening_info,
8044 show_ip_bgp_dampening_params_cmd,
8045 "show ip bgp dampening parameters",
8046 SHOW_STR
8047 IP_STR
8048 BGP_STR
8049 "Display detailed information about dampening\n"
8050 "Display detail of configured dampening parameters\n")
8051{
8052 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
8053}
8054
paul94f2b392005-06-28 12:44:16 +00008055static int
paulfd79ac92004-10-13 05:06:08 +00008056bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008057 safi_t safi, enum bgp_show_type type)
8058{
8059 struct route_map *rmap;
8060
8061 rmap = route_map_lookup_by_name (rmap_str);
8062 if (! rmap)
8063 {
8064 vty_out (vty, "%% %s is not a valid route-map name%s",
8065 rmap_str, VTY_NEWLINE);
8066 return CMD_WARNING;
8067 }
8068
ajs5a646652004-11-05 01:25:55 +00008069 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00008070}
8071
Lou Berger651b4022016-01-12 13:42:07 -05008072DEFUN (show_bgp_ipv4_route_map,
8073 show_bgp_ipv4_route_map_cmd,
8074 "show bgp ipv4 route-map WORD",
paul718e3742002-12-13 20:15:29 +00008075 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008076 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008077 IP_STR
paul718e3742002-12-13 20:15:29 +00008078 "Display routes matching the route-map\n"
8079 "A route-map to match on\n")
8080{
8081 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8082 bgp_show_type_route_map);
8083}
8084
Lou Berger651b4022016-01-12 13:42:07 -05008085DEFUN (show_bgp_ipv4_safi_flap_route_map,
8086 show_bgp_ipv4_safi_flap_route_map_cmd,
8087 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics route-map WORD",
paul718e3742002-12-13 20:15:29 +00008088 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008089 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008090 IP_STR
8091 "Address Family Modifier\n"
8092 "Address Family Modifier\n"
8093 "Address Family Modifier\n"
8094 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00008095 "Display flap statistics of routes\n"
8096 "Display routes matching the route-map\n"
8097 "A route-map to match on\n")
8098{
Lou Berger651b4022016-01-12 13:42:07 -05008099 safi_t safi;
8100 if (bgp_parse_safi(argv[0], &safi)) {
8101 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8102 return CMD_WARNING;
8103 }
8104 return bgp_show_route_map (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008105 bgp_show_type_flap_route_map);
8106}
8107
Lou Berger651b4022016-01-12 13:42:07 -05008108ALIAS (show_bgp_ipv4_safi_flap_route_map,
8109 show_bgp_ipv4_safi_damp_flap_route_map_cmd,
8110 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics route-map WORD",
Balaji3921cc52015-05-16 23:12:17 +05308111 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308112 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008113 IP_STR
8114 "Address Family Modifier\n"
8115 "Address Family Modifier\n"
8116 "Address Family Modifier\n"
8117 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308118 "Display detailed information about dampening\n"
8119 "Display flap statistics of routes\n"
8120 "Display routes matching the route-map\n"
8121 "A route-map to match on\n")
Lou Berger651b4022016-01-12 13:42:07 -05008122#ifdef HAVE_IPV6
8123DEFUN (show_bgp_ipv6_safi_flap_route_map,
8124 show_bgp_ipv6_safi_flap_route_map_cmd,
8125 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics route-map WORD",
paul718e3742002-12-13 20:15:29 +00008126 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05008127 BGP_STR
8128 IPV6_STR
8129 "Address Family Modifier\n"
8130 "Address Family Modifier\n"
8131 "Address Family Modifier\n"
8132 "Address Family Modifier\n"
8133 "Display flap statistics of routes\n"
8134 "Display routes matching the route-map\n"
8135 "A route-map to match on\n")
8136{
8137 safi_t safi;
8138 if (bgp_parse_safi(argv[0], &safi)) {
8139 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8140 return CMD_WARNING;
8141 }
8142 return bgp_show_route_map (vty, argv[1], AFI_IP6, safi,
8143 bgp_show_type_flap_route_map);
8144}
8145ALIAS (show_bgp_ipv6_safi_flap_route_map,
8146 show_bgp_ipv6_safi_damp_flap_route_map_cmd,
8147 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics route-map WORD",
8148 SHOW_STR
8149 BGP_STR
8150 IPV6_STR
8151 "Address Family Modifier\n"
8152 "Address Family Modifier\n"
8153 "Address Family Modifier\n"
8154 "Address Family Modifier\n"
8155 "Display detailed information about dampening\n"
8156 "Display flap statistics of routes\n"
8157 "Display routes matching the route-map\n"
8158 "A route-map to match on\n")
8159#endif
8160
8161DEFUN (show_bgp_ipv4_safi_route_map,
8162 show_bgp_ipv4_safi_route_map_cmd,
8163 "show bgp ipv4 (encap|multicast|unicast|vpn) route-map WORD",
8164 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008165 BGP_STR
8166 "Address family\n"
8167 "Address Family modifier\n"
8168 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05008169 "Address Family modifier\n"
8170 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008171 "Display routes matching the route-map\n"
8172 "A route-map to match on\n")
8173{
Lou Berger651b4022016-01-12 13:42:07 -05008174 safi_t safi;
8175 if (bgp_parse_safi(argv[0], &safi)) {
8176 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8177 return CMD_WARNING;
8178 }
8179 return bgp_show_route_map (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008180 bgp_show_type_route_map);
8181}
Lou Berger651b4022016-01-12 13:42:07 -05008182#ifdef HAVE_IPV6
8183DEFUN (show_bgp_ipv6_safi_route_map,
8184 show_bgp_ipv6_safi_route_map_cmd,
8185 "show bgp ipv6 (encap|multicast|unicast|vpn) route-map WORD",
paul718e3742002-12-13 20:15:29 +00008186 SHOW_STR
8187 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008188 "Address family\n"
8189 "Address Family modifier\n"
8190 "Address Family modifier\n"
8191 "Address Family modifier\n"
8192 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008193 "Display routes matching the route-map\n"
8194 "A route-map to match on\n")
8195{
Lou Berger651b4022016-01-12 13:42:07 -05008196 safi_t safi;
8197 if (bgp_parse_safi(argv[0], &safi)) {
8198 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8199 return CMD_WARNING;
8200 }
8201 return bgp_show_route_map (vty, argv[1], AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00008202 bgp_show_type_route_map);
8203}
8204
Lou Berger651b4022016-01-12 13:42:07 -05008205DEFUN (show_bgp_ipv6_route_map,
paul718e3742002-12-13 20:15:29 +00008206 show_bgp_ipv6_route_map_cmd,
8207 "show bgp ipv6 route-map WORD",
8208 SHOW_STR
8209 BGP_STR
8210 "Address family\n"
8211 "Display routes matching the route-map\n"
8212 "A route-map to match on\n")
Lou Berger651b4022016-01-12 13:42:07 -05008213{
8214 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8215 bgp_show_type_route_map);
8216}
8217#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02008218
Lou Berger651b4022016-01-12 13:42:07 -05008219DEFUN (show_bgp_ipv4_cidr_only,
8220 show_bgp_ipv4_cidr_only_cmd,
8221 "show bgp ipv4 cidr-only",
paul718e3742002-12-13 20:15:29 +00008222 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008223 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008224 IP_STR
paul718e3742002-12-13 20:15:29 +00008225 "Display only routes with non-natural netmasks\n")
8226{
8227 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00008228 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00008229}
8230
Lou Berger651b4022016-01-12 13:42:07 -05008231DEFUN (show_bgp_ipv4_safi_flap_cidr_only,
8232 show_bgp_ipv4_safi_flap_cidr_only_cmd,
8233 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics cidr-only",
paul718e3742002-12-13 20:15:29 +00008234 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008235 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008236 "Address Family\n"
8237 "Address Family Modifier\n"
8238 "Address Family Modifier\n"
8239 "Address Family Modifier\n"
8240 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00008241 "Display flap statistics of routes\n"
8242 "Display only routes with non-natural netmasks\n")
8243{
Lou Berger651b4022016-01-12 13:42:07 -05008244 safi_t safi;
8245
8246 if (bgp_parse_safi(argv[0], &safi)) {
8247 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8248 return CMD_WARNING;
8249 }
8250 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00008251}
8252
Lou Berger651b4022016-01-12 13:42:07 -05008253ALIAS (show_bgp_ipv4_safi_flap_cidr_only,
8254 show_bgp_ipv4_safi_damp_flap_cidr_only_cmd,
8255 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics cidr-only",
Balaji3921cc52015-05-16 23:12:17 +05308256 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308257 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008258 "Address Family\n"
8259 "Address Family Modifier\n"
8260 "Address Family Modifier\n"
8261 "Address Family Modifier\n"
8262 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308263 "Display detailed information about dampening\n"
8264 "Display flap statistics of routes\n"
8265 "Display only routes with non-natural netmasks\n")
8266
Lou Berger651b4022016-01-12 13:42:07 -05008267DEFUN (show_bgp_ipv4_safi_cidr_only,
8268 show_bgp_ipv4_safi_cidr_only_cmd,
8269 "show bgp ipv4 (unicast|multicast) cidr-only",
paul718e3742002-12-13 20:15:29 +00008270 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008271 BGP_STR
8272 "Address family\n"
8273 "Address Family modifier\n"
8274 "Address Family modifier\n"
8275 "Display only routes with non-natural netmasks\n")
8276{
8277 if (strncmp (argv[0], "m", 1) == 0)
8278 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00008279 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00008280
8281 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00008282 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00008283}
David Lamparter6b0655a2014-06-04 06:53:35 +02008284
Lou Berger651b4022016-01-12 13:42:07 -05008285/* new046 */
8286DEFUN (show_bgp_afi_safi_community_all,
8287 show_bgp_afi_safi_community_all_cmd,
paul718e3742002-12-13 20:15:29 +00008288#ifdef HAVE_IPV6
Lou Berger651b4022016-01-12 13:42:07 -05008289 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) community",
8290#else
8291 "show bgp ipv4 (encap|multicast|unicast|vpn) community",
8292#endif
paul718e3742002-12-13 20:15:29 +00008293 SHOW_STR
8294 BGP_STR
8295 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008296#ifdef HAVE_IPV6
8297 "Address family\n"
8298#endif
8299 "Address Family modifier\n"
8300 "Address Family modifier\n"
8301 "Address Family modifier\n"
8302 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008303 "Display routes matching the communities\n")
Lou Berger651b4022016-01-12 13:42:07 -05008304{
8305 safi_t safi;
8306 afi_t afi;
paul718e3742002-12-13 20:15:29 +00008307
Lou Berger651b4022016-01-12 13:42:07 -05008308 if (bgp_parse_afi(argv[0], &afi)) {
8309 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
8310 return CMD_WARNING;
8311 }
8312 if (bgp_parse_safi(argv[1], &safi)) {
8313 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
8314 return CMD_WARNING;
8315 }
8316
8317 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_all, NULL);
8318}
8319DEFUN (show_bgp_afi_community_all,
8320 show_bgp_afi_community_all_cmd,
8321#ifdef HAVE_IPV6
8322 "show bgp (ipv4|ipv6) community",
8323#else
8324 "show bgp ipv4 community",
8325#endif
paul718e3742002-12-13 20:15:29 +00008326 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008327 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008328 "Address family\n"
8329#ifdef HAVE_IPV6
8330 "Address family\n"
8331#endif
paul718e3742002-12-13 20:15:29 +00008332 "Display routes matching the communities\n")
8333{
Lou Berger651b4022016-01-12 13:42:07 -05008334 afi_t afi;
8335 safi_t safi = SAFI_UNICAST;
paul718e3742002-12-13 20:15:29 +00008336
Lou Berger651b4022016-01-12 13:42:07 -05008337 if (bgp_parse_afi(argv[0], &afi)) {
8338 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
8339 return CMD_WARNING;
8340 }
8341 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00008342}
David Lamparter6b0655a2014-06-04 06:53:35 +02008343
paul94f2b392005-06-28 12:44:16 +00008344static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04008345bgp_show_community (struct vty *vty, const char *view_name, int argc,
8346 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008347{
8348 struct community *com;
8349 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04008350 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00008351 int i;
8352 char *str;
8353 int first = 0;
8354
Michael Lambert95cbbd22010-07-23 14:43:04 -04008355 /* BGP structure lookup */
8356 if (view_name)
8357 {
8358 bgp = bgp_lookup_by_name (view_name);
8359 if (bgp == NULL)
8360 {
8361 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8362 return CMD_WARNING;
8363 }
8364 }
8365 else
8366 {
8367 bgp = bgp_get_default ();
8368 if (bgp == NULL)
8369 {
8370 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8371 return CMD_WARNING;
8372 }
8373 }
8374
paul718e3742002-12-13 20:15:29 +00008375 b = buffer_new (1024);
8376 for (i = 0; i < argc; i++)
8377 {
8378 if (first)
8379 buffer_putc (b, ' ');
8380 else
8381 {
8382 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8383 continue;
8384 first = 1;
8385 }
8386
8387 buffer_putstr (b, argv[i]);
8388 }
8389 buffer_putc (b, '\0');
8390
8391 str = buffer_getstr (b);
8392 buffer_free (b);
8393
8394 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00008395 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00008396 if (! com)
8397 {
8398 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
8399 return CMD_WARNING;
8400 }
8401
Michael Lambert95cbbd22010-07-23 14:43:04 -04008402 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00008403 (exact ? bgp_show_type_community_exact :
8404 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00008405}
8406
Lou Berger651b4022016-01-12 13:42:07 -05008407DEFUN (show_bgp_ipv4_community,
8408 show_bgp_ipv4_community_cmd,
8409 "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +00008410 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008411 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008412 IP_STR
paul718e3742002-12-13 20:15:29 +00008413 "Display routes matching the communities\n"
8414 "community number\n"
8415 "Do not send outside local AS (well-known community)\n"
8416 "Do not advertise to any peer (well-known community)\n"
8417 "Do not export to next AS (well-known community)\n")
8418{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008419 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008420}
8421
Lou Berger651b4022016-01-12 13:42:07 -05008422ALIAS (show_bgp_ipv4_community,
8423 show_bgp_ipv4_community2_cmd,
8424 "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 +00008425 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008426 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008427 IP_STR
paul718e3742002-12-13 20:15:29 +00008428 "Display routes matching the communities\n"
8429 "community number\n"
8430 "Do not send outside local AS (well-known community)\n"
8431 "Do not advertise to any peer (well-known community)\n"
8432 "Do not export to next AS (well-known community)\n"
8433 "community number\n"
8434 "Do not send outside local AS (well-known community)\n"
8435 "Do not advertise to any peer (well-known community)\n"
8436 "Do not export to next AS (well-known community)\n")
8437
Lou Berger651b4022016-01-12 13:42:07 -05008438ALIAS (show_bgp_ipv4_community,
8439 show_bgp_ipv4_community3_cmd,
8440 "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 +00008441 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008442 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008443 IP_STR
paul718e3742002-12-13 20:15:29 +00008444 "Display routes matching the communities\n"
8445 "community number\n"
8446 "Do not send outside local AS (well-known community)\n"
8447 "Do not advertise to any peer (well-known community)\n"
8448 "Do not export to next AS (well-known community)\n"
8449 "community number\n"
8450 "Do not send outside local AS (well-known community)\n"
8451 "Do not advertise to any peer (well-known community)\n"
8452 "Do not export to next AS (well-known community)\n"
8453 "community number\n"
8454 "Do not send outside local AS (well-known community)\n"
8455 "Do not advertise to any peer (well-known community)\n"
8456 "Do not export to next AS (well-known community)\n")
8457
Lou Berger651b4022016-01-12 13:42:07 -05008458ALIAS (show_bgp_ipv4_community,
8459 show_bgp_ipv4_community4_cmd,
8460 "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 +00008461 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008462 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008463 IP_STR
paul718e3742002-12-13 20:15:29 +00008464 "Display routes matching the communities\n"
8465 "community number\n"
8466 "Do not send outside local AS (well-known community)\n"
8467 "Do not advertise to any peer (well-known community)\n"
8468 "Do not export to next AS (well-known community)\n"
8469 "community number\n"
8470 "Do not send outside local AS (well-known community)\n"
8471 "Do not advertise to any peer (well-known community)\n"
8472 "Do not export to next AS (well-known community)\n"
8473 "community number\n"
8474 "Do not send outside local AS (well-known community)\n"
8475 "Do not advertise to any peer (well-known community)\n"
8476 "Do not export to next AS (well-known community)\n"
8477 "community number\n"
8478 "Do not send outside local AS (well-known community)\n"
8479 "Do not advertise to any peer (well-known community)\n"
8480 "Do not export to next AS (well-known community)\n")
8481
Lou Berger651b4022016-01-12 13:42:07 -05008482DEFUN (show_bgp_ipv4_safi_community,
8483 show_bgp_ipv4_safi_community_cmd,
8484 "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +00008485 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008486 BGP_STR
8487 "Address family\n"
8488 "Address Family modifier\n"
8489 "Address Family modifier\n"
8490 "Display routes matching the communities\n"
8491 "community number\n"
8492 "Do not send outside local AS (well-known community)\n"
8493 "Do not advertise to any peer (well-known community)\n"
8494 "Do not export to next AS (well-known community)\n")
8495{
8496 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008497 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008498
Michael Lambert95cbbd22010-07-23 14:43:04 -04008499 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008500}
8501
Lou Berger651b4022016-01-12 13:42:07 -05008502ALIAS (show_bgp_ipv4_safi_community,
8503 show_bgp_ipv4_safi_community2_cmd,
8504 "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 +00008505 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008506 BGP_STR
8507 "Address family\n"
8508 "Address Family modifier\n"
8509 "Address Family modifier\n"
8510 "Display routes matching the communities\n"
8511 "community number\n"
8512 "Do not send outside local AS (well-known community)\n"
8513 "Do not advertise to any peer (well-known community)\n"
8514 "Do not export to next AS (well-known community)\n"
8515 "community number\n"
8516 "Do not send outside local AS (well-known community)\n"
8517 "Do not advertise to any peer (well-known community)\n"
8518 "Do not export to next AS (well-known community)\n")
8519
Lou Berger651b4022016-01-12 13:42:07 -05008520ALIAS (show_bgp_ipv4_safi_community,
8521 show_bgp_ipv4_safi_community3_cmd,
8522 "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 +00008523 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008524 BGP_STR
8525 "Address family\n"
8526 "Address Family modifier\n"
8527 "Address Family modifier\n"
8528 "Display routes matching the communities\n"
8529 "community number\n"
8530 "Do not send outside local AS (well-known community)\n"
8531 "Do not advertise to any peer (well-known community)\n"
8532 "Do not export to next AS (well-known community)\n"
8533 "community number\n"
8534 "Do not send outside local AS (well-known community)\n"
8535 "Do not advertise to any peer (well-known community)\n"
8536 "Do not export to next AS (well-known community)\n"
8537 "community number\n"
8538 "Do not send outside local AS (well-known community)\n"
8539 "Do not advertise to any peer (well-known community)\n"
8540 "Do not export to next AS (well-known community)\n")
8541
Lou Berger651b4022016-01-12 13:42:07 -05008542ALIAS (show_bgp_ipv4_safi_community,
8543 show_bgp_ipv4_safi_community4_cmd,
8544 "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 +00008545 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008546 BGP_STR
8547 "Address family\n"
8548 "Address Family modifier\n"
8549 "Address Family modifier\n"
8550 "Display routes matching the communities\n"
8551 "community number\n"
8552 "Do not send outside local AS (well-known community)\n"
8553 "Do not advertise to any peer (well-known community)\n"
8554 "Do not export to next AS (well-known community)\n"
8555 "community number\n"
8556 "Do not send outside local AS (well-known community)\n"
8557 "Do not advertise to any peer (well-known community)\n"
8558 "Do not export to next AS (well-known community)\n"
8559 "community number\n"
8560 "Do not send outside local AS (well-known community)\n"
8561 "Do not advertise to any peer (well-known community)\n"
8562 "Do not export to next AS (well-known community)\n"
8563 "community number\n"
8564 "Do not send outside local AS (well-known community)\n"
8565 "Do not advertise to any peer (well-known community)\n"
8566 "Do not export to next AS (well-known community)\n")
8567
Michael Lambert95cbbd22010-07-23 14:43:04 -04008568DEFUN (show_bgp_view_afi_safi_community_all,
8569 show_bgp_view_afi_safi_community_all_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05008570#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -04008571 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Lou Berger651b4022016-01-12 13:42:07 -05008572#else
8573 "show bgp view WORD ipv4 (unicast|multicast) community",
8574#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -04008575 SHOW_STR
8576 BGP_STR
8577 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008578 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008579 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008580#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -04008581 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008582#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -04008583 "Address Family modifier\n"
8584 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00008585 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04008586{
8587 int afi;
8588 int safi;
8589 struct bgp *bgp;
8590
8591 /* BGP structure lookup. */
8592 bgp = bgp_lookup_by_name (argv[0]);
8593 if (bgp == NULL)
8594 {
8595 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8596 return CMD_WARNING;
8597 }
8598
Lou Berger651b4022016-01-12 13:42:07 -05008599#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -04008600 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8601 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Lou Berger651b4022016-01-12 13:42:07 -05008602#else
8603 afi = AFI_IP;
8604 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8605#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -04008606 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
8607}
8608
8609DEFUN (show_bgp_view_afi_safi_community,
8610 show_bgp_view_afi_safi_community_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05008611#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -04008612 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Lou Berger651b4022016-01-12 13:42:07 -05008613#else
8614 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
8615#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -04008616 SHOW_STR
8617 BGP_STR
8618 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008619 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008620 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008621#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -04008622 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008623#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -04008624 "Address family modifier\n"
8625 "Address family modifier\n"
8626 "Display routes matching the communities\n"
8627 "community number\n"
8628 "Do not send outside local AS (well-known community)\n"
8629 "Do not advertise to any peer (well-known community)\n"
8630 "Do not export to next AS (well-known community)\n")
8631{
8632 int afi;
8633 int safi;
8634
Lou Berger651b4022016-01-12 13:42:07 -05008635#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -04008636 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8637 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8638 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Lou Berger651b4022016-01-12 13:42:07 -05008639#else
8640 afi = AFI_IP;
8641 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8642 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
8643#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -04008644}
8645
8646ALIAS (show_bgp_view_afi_safi_community,
8647 show_bgp_view_afi_safi_community2_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05008648#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -04008649 "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)",
Lou Berger651b4022016-01-12 13:42:07 -05008650#else
8651 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8652#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -04008653 SHOW_STR
8654 BGP_STR
8655 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008656 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008657 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008658#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -04008659 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008660#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -04008661 "Address family modifier\n"
8662 "Address family modifier\n"
8663 "Display routes matching the communities\n"
8664 "community number\n"
8665 "Do not send outside local AS (well-known community)\n"
8666 "Do not advertise to any peer (well-known community)\n"
8667 "Do not export to next AS (well-known community)\n"
8668 "community number\n"
8669 "Do not send outside local AS (well-known community)\n"
8670 "Do not advertise to any peer (well-known community)\n"
8671 "Do not export to next AS (well-known community)\n")
8672
8673ALIAS (show_bgp_view_afi_safi_community,
8674 show_bgp_view_afi_safi_community3_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05008675#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -04008676 "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)",
Lou Berger651b4022016-01-12 13:42:07 -05008677#else
8678 "show bgp view WORD 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)",
8679#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -04008680 SHOW_STR
8681 BGP_STR
8682 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008683 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008684 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008685#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -04008686 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008687#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -04008688 "Address family modifier\n"
8689 "Address family modifier\n"
8690 "Display routes matching the communities\n"
8691 "community number\n"
8692 "Do not send outside local AS (well-known community)\n"
8693 "Do not advertise to any peer (well-known community)\n"
8694 "Do not export to next AS (well-known community)\n"
8695 "community number\n"
8696 "Do not send outside local AS (well-known community)\n"
8697 "Do not advertise to any peer (well-known community)\n"
8698 "Do not export to next AS (well-known community)\n"
8699 "community number\n"
8700 "Do not send outside local AS (well-known community)\n"
8701 "Do not advertise to any peer (well-known community)\n"
8702 "Do not export to next AS (well-known community)\n")
8703
8704ALIAS (show_bgp_view_afi_safi_community,
8705 show_bgp_view_afi_safi_community4_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05008706#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -04008707 "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)",
Lou Berger651b4022016-01-12 13:42:07 -05008708#else
8709 "show bgp view WORD 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)",
8710#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -04008711 SHOW_STR
8712 BGP_STR
8713 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008714 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008715 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008716#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -04008717 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008718#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -04008719 "Address family modifier\n"
8720 "Address family modifier\n"
8721 "Display routes matching the communities\n"
8722 "community number\n"
8723 "Do not send outside local AS (well-known community)\n"
8724 "Do not advertise to any peer (well-known community)\n"
8725 "Do not export to next AS (well-known community)\n"
8726 "community number\n"
8727 "Do not send outside local AS (well-known community)\n"
8728 "Do not advertise to any peer (well-known community)\n"
8729 "Do not export to next AS (well-known community)\n"
8730 "community number\n"
8731 "Do not send outside local AS (well-known community)\n"
8732 "Do not advertise to any peer (well-known community)\n"
8733 "Do not export to next AS (well-known community)\n"
8734 "community number\n"
8735 "Do not send outside local AS (well-known community)\n"
8736 "Do not advertise to any peer (well-known community)\n"
8737 "Do not export to next AS (well-known community)\n")
8738
Lou Berger651b4022016-01-12 13:42:07 -05008739DEFUN (show_bgp_ipv4_community_exact,
8740 show_bgp_ipv4_community_exact_cmd,
8741 "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +00008742 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008743 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008744 IP_STR
paul718e3742002-12-13 20:15:29 +00008745 "Display routes matching the communities\n"
8746 "community number\n"
8747 "Do not send outside local AS (well-known community)\n"
8748 "Do not advertise to any peer (well-known community)\n"
8749 "Do not export to next AS (well-known community)\n"
8750 "Exact match of the communities")
8751{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008752 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008753}
8754
Lou Berger651b4022016-01-12 13:42:07 -05008755ALIAS (show_bgp_ipv4_community_exact,
8756 show_bgp_ipv4_community2_exact_cmd,
8757 "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 +00008758 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008759 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008760 IP_STR
paul718e3742002-12-13 20:15:29 +00008761 "Display routes matching the communities\n"
8762 "community number\n"
8763 "Do not send outside local AS (well-known community)\n"
8764 "Do not advertise to any peer (well-known community)\n"
8765 "Do not export to next AS (well-known community)\n"
8766 "community number\n"
8767 "Do not send outside local AS (well-known community)\n"
8768 "Do not advertise to any peer (well-known community)\n"
8769 "Do not export to next AS (well-known community)\n"
8770 "Exact match of the communities")
8771
Lou Berger651b4022016-01-12 13:42:07 -05008772ALIAS (show_bgp_ipv4_community_exact,
8773 show_bgp_ipv4_community3_exact_cmd,
8774 "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 +00008775 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008776 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008777 IP_STR
paul718e3742002-12-13 20:15:29 +00008778 "Display routes matching the communities\n"
8779 "community number\n"
8780 "Do not send outside local AS (well-known community)\n"
8781 "Do not advertise to any peer (well-known community)\n"
8782 "Do not export to next AS (well-known community)\n"
8783 "community number\n"
8784 "Do not send outside local AS (well-known community)\n"
8785 "Do not advertise to any peer (well-known community)\n"
8786 "Do not export to next AS (well-known community)\n"
8787 "community number\n"
8788 "Do not send outside local AS (well-known community)\n"
8789 "Do not advertise to any peer (well-known community)\n"
8790 "Do not export to next AS (well-known community)\n"
8791 "Exact match of the communities")
8792
Lou Berger651b4022016-01-12 13:42:07 -05008793ALIAS (show_bgp_ipv4_community_exact,
8794 show_bgp_ipv4_community4_exact_cmd,
8795 "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 +00008796 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008797 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008798 IP_STR
paul718e3742002-12-13 20:15:29 +00008799 "Display routes matching the communities\n"
8800 "community number\n"
8801 "Do not send outside local AS (well-known community)\n"
8802 "Do not advertise to any peer (well-known community)\n"
8803 "Do not export to next AS (well-known community)\n"
8804 "community number\n"
8805 "Do not send outside local AS (well-known community)\n"
8806 "Do not advertise to any peer (well-known community)\n"
8807 "Do not export to next AS (well-known community)\n"
8808 "community number\n"
8809 "Do not send outside local AS (well-known community)\n"
8810 "Do not advertise to any peer (well-known community)\n"
8811 "Do not export to next AS (well-known community)\n"
8812 "community number\n"
8813 "Do not send outside local AS (well-known community)\n"
8814 "Do not advertise to any peer (well-known community)\n"
8815 "Do not export to next AS (well-known community)\n"
8816 "Exact match of the communities")
8817
Lou Berger651b4022016-01-12 13:42:07 -05008818DEFUN (show_bgp_ipv4_safi_community4_exact,
8819 show_bgp_ipv4_safi_community_exact_cmd,
8820 "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +00008821 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008822 BGP_STR
8823 "Address family\n"
8824 "Address Family modifier\n"
8825 "Address Family modifier\n"
8826 "Display routes matching the communities\n"
8827 "community number\n"
8828 "Do not send outside local AS (well-known community)\n"
8829 "Do not advertise to any peer (well-known community)\n"
8830 "Do not export to next AS (well-known community)\n"
8831 "Exact match of the communities")
8832{
8833 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008834 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008835
Michael Lambert95cbbd22010-07-23 14:43:04 -04008836 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008837}
8838
Lou Berger651b4022016-01-12 13:42:07 -05008839ALIAS (show_bgp_ipv4_safi_community4_exact,
8840 show_bgp_ipv4_safi_community2_exact_cmd,
8841 "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 +00008842 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008843 BGP_STR
8844 "Address family\n"
8845 "Address Family modifier\n"
8846 "Address Family modifier\n"
8847 "Display routes matching the communities\n"
8848 "community number\n"
8849 "Do not send outside local AS (well-known community)\n"
8850 "Do not advertise to any peer (well-known community)\n"
8851 "Do not export to next AS (well-known community)\n"
8852 "community number\n"
8853 "Do not send outside local AS (well-known community)\n"
8854 "Do not advertise to any peer (well-known community)\n"
8855 "Do not export to next AS (well-known community)\n"
8856 "Exact match of the communities")
8857
Lou Berger651b4022016-01-12 13:42:07 -05008858ALIAS (show_bgp_ipv4_safi_community4_exact,
8859 show_bgp_ipv4_safi_community3_exact_cmd,
8860 "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 +00008861 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008862 BGP_STR
8863 "Address family\n"
8864 "Address Family modifier\n"
8865 "Address Family modifier\n"
8866 "Display routes matching the communities\n"
8867 "community number\n"
8868 "Do not send outside local AS (well-known community)\n"
8869 "Do not advertise to any peer (well-known community)\n"
8870 "Do not export to next AS (well-known community)\n"
8871 "community number\n"
8872 "Do not send outside local AS (well-known community)\n"
8873 "Do not advertise to any peer (well-known community)\n"
8874 "Do not export to next AS (well-known community)\n"
8875 "community number\n"
8876 "Do not send outside local AS (well-known community)\n"
8877 "Do not advertise to any peer (well-known community)\n"
8878 "Do not export to next AS (well-known community)\n"
8879 "Exact match of the communities")
8880
Lou Berger651b4022016-01-12 13:42:07 -05008881ALIAS (show_bgp_ipv4_safi_community4_exact,
8882 show_bgp_ipv4_safi_community4_exact_cmd,
8883 "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 +00008884 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008885 BGP_STR
8886 "Address family\n"
8887 "Address Family modifier\n"
8888 "Address Family modifier\n"
8889 "Display routes matching the communities\n"
8890 "community number\n"
8891 "Do not send outside local AS (well-known community)\n"
8892 "Do not advertise to any peer (well-known community)\n"
8893 "Do not export to next AS (well-known community)\n"
8894 "community number\n"
8895 "Do not send outside local AS (well-known community)\n"
8896 "Do not advertise to any peer (well-known community)\n"
8897 "Do not export to next AS (well-known community)\n"
8898 "community number\n"
8899 "Do not send outside local AS (well-known community)\n"
8900 "Do not advertise to any peer (well-known community)\n"
8901 "Do not export to next AS (well-known community)\n"
8902 "community number\n"
8903 "Do not send outside local AS (well-known community)\n"
8904 "Do not advertise to any peer (well-known community)\n"
8905 "Do not export to next AS (well-known community)\n"
8906 "Exact match of the communities")
8907
Lou Berger651b4022016-01-12 13:42:07 -05008908
paul718e3742002-12-13 20:15:29 +00008909#ifdef HAVE_IPV6
Lou Berger651b4022016-01-12 13:42:07 -05008910DEFUN (show_bgp_ipv6_community,
8911 show_bgp_ipv6_community_cmd,
8912 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +00008913 SHOW_STR
8914 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008915 "Address family\n"
8916 "Address family modifier\n"
8917 "Address family modifier\n"
8918 "Address family modifier\n"
8919 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +00008920 "Display routes matching the communities\n"
8921 "community number\n"
8922 "Do not send outside local AS (well-known community)\n"
8923 "Do not advertise to any peer (well-known community)\n"
8924 "Do not export to next AS (well-known community)\n")
8925{
Lou Berger651b4022016-01-12 13:42:07 -05008926 safi_t safi;
8927
8928 if (bgp_parse_safi(argv[0], &safi)) {
8929 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8930 return CMD_WARNING;
8931 }
8932 return bgp_show_community (vty, NULL, argc-1, argv+1, 0, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +00008933}
8934
Lou Berger651b4022016-01-12 13:42:07 -05008935ALIAS (show_bgp_ipv6_community,
paul718e3742002-12-13 20:15:29 +00008936 show_bgp_ipv6_community2_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05008937 "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 +00008938 SHOW_STR
8939 BGP_STR
8940 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008941 "Address family modifier\n"
8942 "Address family modifier\n"
8943 "Address family modifier\n"
8944 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +00008945 "Display routes matching the communities\n"
8946 "community number\n"
8947 "Do not send outside local AS (well-known community)\n"
8948 "Do not advertise to any peer (well-known community)\n"
8949 "Do not export to next AS (well-known community)\n"
8950 "community number\n"
8951 "Do not send outside local AS (well-known community)\n"
8952 "Do not advertise to any peer (well-known community)\n"
8953 "Do not export to next AS (well-known community)\n")
8954
Lou Berger651b4022016-01-12 13:42:07 -05008955ALIAS (show_bgp_ipv6_community,
paul718e3742002-12-13 20:15:29 +00008956 show_bgp_ipv6_community3_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05008957 "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 +00008958 SHOW_STR
8959 BGP_STR
8960 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008961 "Address family modifier\n"
8962 "Address family modifier\n"
8963 "Address family modifier\n"
8964 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +00008965 "Display routes matching the communities\n"
8966 "community number\n"
8967 "Do not send outside local AS (well-known community)\n"
8968 "Do not advertise to any peer (well-known community)\n"
8969 "Do not export to next AS (well-known community)\n"
8970 "community number\n"
8971 "Do not send outside local AS (well-known community)\n"
8972 "Do not advertise to any peer (well-known community)\n"
8973 "Do not export to next AS (well-known community)\n"
8974 "community number\n"
8975 "Do not send outside local AS (well-known community)\n"
8976 "Do not advertise to any peer (well-known community)\n"
8977 "Do not export to next AS (well-known community)\n")
8978
Lou Berger651b4022016-01-12 13:42:07 -05008979ALIAS (show_bgp_ipv6_community,
paul718e3742002-12-13 20:15:29 +00008980 show_bgp_ipv6_community4_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05008981 "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 +00008982 SHOW_STR
8983 BGP_STR
8984 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008985 "Address family modifier\n"
8986 "Address family modifier\n"
8987 "Address family modifier\n"
8988 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +00008989 "Display routes matching the communities\n"
8990 "community number\n"
8991 "Do not send outside local AS (well-known community)\n"
8992 "Do not advertise to any peer (well-known community)\n"
8993 "Do not export to next AS (well-known community)\n"
8994 "community number\n"
8995 "Do not send outside local AS (well-known community)\n"
8996 "Do not advertise to any peer (well-known community)\n"
8997 "Do not export to next AS (well-known community)\n"
8998 "community number\n"
8999 "Do not send outside local AS (well-known community)\n"
9000 "Do not advertise to any peer (well-known community)\n"
9001 "Do not export to next AS (well-known community)\n"
9002 "community number\n"
9003 "Do not send outside local AS (well-known community)\n"
9004 "Do not advertise to any peer (well-known community)\n"
9005 "Do not export to next AS (well-known community)\n")
9006
paul718e3742002-12-13 20:15:29 +00009007
9008DEFUN (show_bgp_community_exact,
Lou Berger651b4022016-01-12 13:42:07 -05009009 show_bgp_ipv6_community_exact_cmd,
9010 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +00009011 SHOW_STR
9012 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009013 "Address family\n"
9014 "Address family modifier\n"
9015 "Address family modifier\n"
9016 "Address family modifier\n"
9017 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +00009018 "Display routes matching the communities\n"
9019 "community number\n"
9020 "Do not send outside local AS (well-known community)\n"
9021 "Do not advertise to any peer (well-known community)\n"
9022 "Do not export to next AS (well-known community)\n"
9023 "Exact match of the communities")
9024{
Lou Berger651b4022016-01-12 13:42:07 -05009025 safi_t safi;
9026
9027 if (bgp_parse_safi(argv[0], &safi)) {
9028 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9029 return CMD_WARNING;
9030 }
9031 return bgp_show_community (vty, NULL, argc-1, argv+1, 1, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +00009032}
9033
paul718e3742002-12-13 20:15:29 +00009034
9035ALIAS (show_bgp_community_exact,
9036 show_bgp_ipv6_community2_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009037 "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 +00009038 SHOW_STR
9039 BGP_STR
9040 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009041 "Address family modifier\n"
9042 "Address family modifier\n"
9043 "Address family modifier\n"
9044 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +00009045 "Display routes matching the communities\n"
9046 "community number\n"
9047 "Do not send outside local AS (well-known community)\n"
9048 "Do not advertise to any peer (well-known community)\n"
9049 "Do not export to next AS (well-known community)\n"
9050 "community number\n"
9051 "Do not send outside local AS (well-known community)\n"
9052 "Do not advertise to any peer (well-known community)\n"
9053 "Do not export to next AS (well-known community)\n"
9054 "Exact match of the communities")
9055
9056ALIAS (show_bgp_community_exact,
paul718e3742002-12-13 20:15:29 +00009057 show_bgp_ipv6_community3_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009058 "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 +00009059 SHOW_STR
9060 BGP_STR
9061 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009062 "Address family modifier\n"
9063 "Address family modifier\n"
9064 "Address family modifier\n"
9065 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +00009066 "Display routes matching the communities\n"
9067 "community number\n"
9068 "Do not send outside local AS (well-known community)\n"
9069 "Do not advertise to any peer (well-known community)\n"
9070 "Do not export to next AS (well-known community)\n"
9071 "community number\n"
9072 "Do not send outside local AS (well-known community)\n"
9073 "Do not advertise to any peer (well-known community)\n"
9074 "Do not export to next AS (well-known community)\n"
9075 "community number\n"
9076 "Do not send outside local AS (well-known community)\n"
9077 "Do not advertise to any peer (well-known community)\n"
9078 "Do not export to next AS (well-known community)\n"
9079 "Exact match of the communities")
9080
9081ALIAS (show_bgp_community_exact,
paul718e3742002-12-13 20:15:29 +00009082 show_bgp_ipv6_community4_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009083 "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 +00009084 SHOW_STR
9085 BGP_STR
9086 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009087 "Address family modifier\n"
9088 "Address family modifier\n"
9089 "Address family modifier\n"
9090 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +00009091 "Display routes matching the communities\n"
9092 "community number\n"
9093 "Do not send outside local AS (well-known community)\n"
9094 "Do not advertise to any peer (well-known community)\n"
9095 "Do not export to next AS (well-known community)\n"
9096 "community number\n"
9097 "Do not send outside local AS (well-known community)\n"
9098 "Do not advertise to any peer (well-known community)\n"
9099 "Do not export to next AS (well-known community)\n"
9100 "community number\n"
9101 "Do not send outside local AS (well-known community)\n"
9102 "Do not advertise to any peer (well-known community)\n"
9103 "Do not export to next AS (well-known community)\n"
9104 "community number\n"
9105 "Do not send outside local AS (well-known community)\n"
9106 "Do not advertise to any peer (well-known community)\n"
9107 "Do not export to next AS (well-known community)\n"
9108 "Exact match of the communities")
9109
paul718e3742002-12-13 20:15:29 +00009110#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009111
paul94f2b392005-06-28 12:44:16 +00009112static int
paulfd79ac92004-10-13 05:06:08 +00009113bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04009114 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00009115{
9116 struct community_list *list;
9117
hassofee6e4e2005-02-02 16:29:31 +00009118 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00009119 if (list == NULL)
9120 {
9121 vty_out (vty, "%% %s is not a valid community-list name%s", com,
9122 VTY_NEWLINE);
9123 return CMD_WARNING;
9124 }
9125
ajs5a646652004-11-05 01:25:55 +00009126 return bgp_show (vty, NULL, afi, safi,
9127 (exact ? bgp_show_type_community_list_exact :
9128 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00009129}
9130
Lou Berger651b4022016-01-12 13:42:07 -05009131DEFUN (show_bgp_ipv4_community_list,
9132 show_bgp_ipv4_community_list_cmd,
9133 "show bgp ipv4 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009134 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009135 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009136 IP_STR
paul718e3742002-12-13 20:15:29 +00009137 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009138 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009139 "community-list name\n")
9140{
9141 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
9142}
9143
Lou Berger651b4022016-01-12 13:42:07 -05009144DEFUN (show_bgp_ipv4_safi_community_list,
9145 show_bgp_ipv4_safi_community_list_cmd,
9146 "show bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009147 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009148 BGP_STR
9149 "Address family\n"
9150 "Address Family modifier\n"
9151 "Address Family modifier\n"
9152 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009153 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009154 "community-list name\n")
9155{
9156 if (strncmp (argv[0], "m", 1) == 0)
9157 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
9158
9159 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
9160}
9161
Lou Berger651b4022016-01-12 13:42:07 -05009162DEFUN (show_bgp_ipv4_community_list_exact,
9163 show_bgp_ipv4_community_list_exact_cmd,
9164 "show bgp ipv4 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009165 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009166 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009167 IP_STR
paul718e3742002-12-13 20:15:29 +00009168 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009169 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009170 "community-list name\n"
9171 "Exact match of the communities\n")
9172{
9173 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
9174}
9175
Lou Berger651b4022016-01-12 13:42:07 -05009176DEFUN (show_bgp_ipv4_safi_community_list_exact,
9177 show_bgp_ipv4_safi_community_list_exact_cmd,
9178 "show bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009179 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009180 BGP_STR
9181 "Address family\n"
9182 "Address Family modifier\n"
9183 "Address Family modifier\n"
9184 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009185 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009186 "community-list name\n"
9187 "Exact match of the communities\n")
9188{
9189 if (strncmp (argv[0], "m", 1) == 0)
9190 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
9191
9192 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
9193}
9194
9195#ifdef HAVE_IPV6
9196DEFUN (show_bgp_community_list,
9197 show_bgp_community_list_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009198 "show bgp ipv6 (encap|multicast|unicast|vpn) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009199 SHOW_STR
9200 BGP_STR
9201 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009202 "Address family modifier\n"
9203 "Address family modifier\n"
9204 "Address family modifier\n"
9205 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +00009206 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009207 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00009208 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00009209{
Lou Berger651b4022016-01-12 13:42:07 -05009210 safi_t safi;
paul718e3742002-12-13 20:15:29 +00009211
Lou Berger651b4022016-01-12 13:42:07 -05009212 if (bgp_parse_safi(argv[0], &safi)) {
9213 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9214 return CMD_WARNING;
9215 }
9216 return bgp_show_community_list (vty, argv[1], 0, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +00009217}
9218
9219DEFUN (show_bgp_community_list_exact,
paul718e3742002-12-13 20:15:29 +00009220 show_bgp_ipv6_community_list_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009221 "show bgp ipv6 (encap|multicast|unicast|vpn) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009222 SHOW_STR
9223 BGP_STR
9224 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009225 "Address family modifier\n"
9226 "Address family modifier\n"
9227 "Address family modifier\n"
9228 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +00009229 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009230 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009231 "community-list name\n"
9232 "Exact match of the communities\n")
paul718e3742002-12-13 20:15:29 +00009233{
Lou Berger651b4022016-01-12 13:42:07 -05009234 safi_t safi;
paul718e3742002-12-13 20:15:29 +00009235
Lou Berger651b4022016-01-12 13:42:07 -05009236 if (bgp_parse_safi(argv[0], &safi)) {
9237 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9238 return CMD_WARNING;
9239 }
9240 return bgp_show_community_list (vty, argv[1], 1, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +00009241}
9242#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009243
paul94f2b392005-06-28 12:44:16 +00009244static int
paulfd79ac92004-10-13 05:06:08 +00009245bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009246 safi_t safi, enum bgp_show_type type)
9247{
9248 int ret;
9249 struct prefix *p;
9250
9251 p = prefix_new();
9252
9253 ret = str2prefix (prefix, p);
9254 if (! ret)
9255 {
9256 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9257 return CMD_WARNING;
9258 }
9259
ajs5a646652004-11-05 01:25:55 +00009260 ret = bgp_show (vty, NULL, afi, safi, type, p);
9261 prefix_free(p);
9262 return ret;
paul718e3742002-12-13 20:15:29 +00009263}
9264
Lou Berger651b4022016-01-12 13:42:07 -05009265DEFUN (show_bgp_ipv4_prefix_longer,
9266 show_bgp_ipv4_prefix_longer_cmd,
9267 "show bgp ipv4 A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +00009268 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009269 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009270 IP_STR
paul718e3742002-12-13 20:15:29 +00009271 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9272 "Display route and more specific routes\n")
9273{
9274 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9275 bgp_show_type_prefix_longer);
9276}
9277
Lou Berger651b4022016-01-12 13:42:07 -05009278DEFUN (show_bgp_ipv4_safi_flap_prefix_longer,
9279 show_bgp_ipv4_safi_flap_prefix_longer_cmd,
9280 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +00009281 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009282 BGP_STR
9283 "Address family\n"
9284 "Address Family modifier\n"
9285 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05009286 "Address Family modifier\n"
9287 "Address Family modifier\n"
9288 "Display flap statistics of routes\n"
paul718e3742002-12-13 20:15:29 +00009289 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9290 "Display route and more specific routes\n")
9291{
Lou Berger651b4022016-01-12 13:42:07 -05009292 safi_t safi;
paul718e3742002-12-13 20:15:29 +00009293
Lou Berger651b4022016-01-12 13:42:07 -05009294 if (bgp_parse_safi(argv[0], &safi)) {
9295 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9296 return CMD_WARNING;
9297 }
9298 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
9299 bgp_show_type_flap_prefix_longer);
paul718e3742002-12-13 20:15:29 +00009300}
9301
Lou Berger651b4022016-01-12 13:42:07 -05009302ALIAS (show_bgp_ipv4_safi_flap_prefix_longer,
9303 show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd,
9304 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +00009305 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009306 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009307 "Address family\n"
9308 "Address Family modifier\n"
9309 "Address Family modifier\n"
9310 "Address Family modifier\n"
9311 "Address Family modifier\n"
9312 "Display detailed information about dampening\n"
9313 "Display flap statistics of routes\n"
9314 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9315 "Display route and more specific routes\n")
9316
9317#ifdef HAVE_IPV6
9318DEFUN (show_bgp_ipv6_safi_flap_prefix_longer,
9319 show_bgp_ipv6_safi_flap_prefix_longer_cmd,
9320 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics X:X::X:X/M longer-prefixes",
9321 SHOW_STR
9322 BGP_STR
9323 "Address family\n"
9324 "Address Family modifier\n"
9325 "Address Family modifier\n"
9326 "Address Family modifier\n"
9327 "Address Family modifier\n"
9328 "Display flap statistics of routes\n"
9329 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9330 "Display route and more specific routes\n")
9331{
9332 safi_t safi;
9333
9334 if (bgp_parse_safi(argv[0], &safi)) {
9335 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9336 return CMD_WARNING;
9337 }
9338 return bgp_show_prefix_longer (vty, argv[1], AFI_IP6, safi,
9339 bgp_show_type_flap_prefix_longer);
9340}
9341ALIAS (show_bgp_ipv6_safi_flap_prefix_longer,
9342 show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd,
9343 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics X:X::X:X/M longer-prefixes",
9344 SHOW_STR
9345 BGP_STR
9346 "Address family\n"
9347 "Address Family modifier\n"
9348 "Address Family modifier\n"
9349 "Address Family modifier\n"
9350 "Address Family modifier\n"
9351 "Display detailed information about dampening\n"
9352 "Display flap statistics of routes\n"
9353 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9354 "Display route and more specific routes\n")
9355#endif
9356
9357DEFUN (show_bgp_ipv4_safi_prefix_longer,
9358 show_bgp_ipv4_safi_prefix_longer_cmd,
9359 "show bgp ipv4 (encap|multicast|unicast|vpn) A.B.C.D/M longer-prefixes",
9360 SHOW_STR
9361 BGP_STR
9362 "Address family\n"
9363 "Address Family modifier\n"
9364 "Address Family modifier\n"
9365 "Address Family modifier\n"
9366 "Address Family modifier\n"
9367 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9368 "Display route and more specific routes\n")
9369{
9370 safi_t safi;
9371
9372 if (bgp_parse_safi(argv[0], &safi)) {
9373 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9374 return CMD_WARNING;
9375 }
9376
9377 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
9378 bgp_show_type_prefix_longer);
9379}
9380
9381#ifdef HAVE_IPV6
9382DEFUN (show_bgp_ipv6_safi_prefix_longer,
9383 show_bgp_ipv6_safi_prefix_longer_cmd,
9384 "show bgp ipv6 (encap|multicast|unicast|vpn) X:X::X:X/M longer-prefixes",
9385 SHOW_STR
9386 BGP_STR
9387 "Address family\n"
9388 "Address Family modifier\n"
9389 "Address Family modifier\n"
9390 "Address Family modifier\n"
9391 "Address Family modifier\n"
9392 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9393 "Display route and more specific routes\n")
9394{
9395 safi_t safi;
9396
9397 if (bgp_parse_safi(argv[0], &safi)) {
9398 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9399 return CMD_WARNING;
9400 }
9401
9402 return bgp_show_prefix_longer (vty, argv[1], AFI_IP6, safi,
9403 bgp_show_type_prefix_longer);
9404}
9405#endif
9406
9407DEFUN (show_bgp_ipv4_safi_flap_address,
9408 show_bgp_ipv4_safi_flap_address_cmd,
9409 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D",
9410 SHOW_STR
9411 BGP_STR
9412 "Address family\n"
9413 "Address Family modifier\n"
9414 "Address Family modifier\n"
9415 "Address Family modifier\n"
9416 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009417 "Display flap statistics of routes\n"
9418 "Network in the BGP routing table to display\n")
9419{
Lou Berger651b4022016-01-12 13:42:07 -05009420 safi_t safi;
9421
9422 if (bgp_parse_safi(argv[0], &safi)) {
9423 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9424 return CMD_WARNING;
9425 }
9426 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00009427 bgp_show_type_flap_address);
9428}
Lou Berger651b4022016-01-12 13:42:07 -05009429ALIAS (show_bgp_ipv4_safi_flap_address,
9430 show_bgp_ipv4_safi_damp_flap_address_cmd,
9431 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D",
Balaji3921cc52015-05-16 23:12:17 +05309432 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05309433 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009434 "Address family\n"
9435 "Address Family modifier\n"
9436 "Address Family modifier\n"
9437 "Address Family modifier\n"
9438 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05309439 "Display detailed information about dampening\n"
9440 "Display flap statistics of routes\n"
9441 "Network in the BGP routing table to display\n")
Lou Berger651b4022016-01-12 13:42:07 -05009442#ifdef HAVE_IPV6
9443DEFUN (show_bgp_ipv6_flap_address,
9444 show_bgp_ipv6_flap_address_cmd,
9445 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D",
paul718e3742002-12-13 20:15:29 +00009446 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009447 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009448 "Address family\n"
9449 "Address Family modifier\n"
9450 "Address Family modifier\n"
9451 "Address Family modifier\n"
9452 "Address Family modifier\n"
9453 "Display flap statistics of routes\n"
9454 "Network in the BGP routing table to display\n")
9455{
9456 safi_t safi;
9457
9458 if (bgp_parse_safi(argv[0], &safi)) {
9459 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
9460 return CMD_WARNING;
9461 }
9462 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
9463 bgp_show_type_flap_address);
9464}
9465ALIAS (show_bgp_ipv6_flap_address,
9466 show_bgp_ipv6_damp_flap_address_cmd,
9467 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D",
9468 SHOW_STR
9469 BGP_STR
9470 "Address family\n"
9471 "Address Family modifier\n"
9472 "Address Family modifier\n"
9473 "Address Family modifier\n"
9474 "Address Family modifier\n"
9475 "Display detailed information about dampening\n"
9476 "Display flap statistics of routes\n"
9477 "Network in the BGP routing table to display\n")
9478#endif
9479
9480DEFUN (show_bgp_ipv4_safi_flap_prefix,
9481 show_bgp_ipv4_safi_flap_prefix_cmd,
9482 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D/M",
9483 SHOW_STR
9484 BGP_STR
9485 "Address family\n"
9486 "Address Family modifier\n"
9487 "Address Family modifier\n"
9488 "Address Family modifier\n"
9489 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009490 "Display flap statistics of routes\n"
9491 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9492{
Lou Berger651b4022016-01-12 13:42:07 -05009493 safi_t safi;
9494
9495 if (bgp_parse_safi(argv[0], &safi)) {
9496 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
9497 return CMD_WARNING;
9498 }
9499 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00009500 bgp_show_type_flap_prefix);
9501}
Balaji3921cc52015-05-16 23:12:17 +05309502
Lou Berger651b4022016-01-12 13:42:07 -05009503ALIAS (show_bgp_ipv4_safi_flap_prefix,
9504 show_bgp_ipv4_safi_damp_flap_prefix_cmd,
9505 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D/M",
Balaji3921cc52015-05-16 23:12:17 +05309506 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05309507 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009508 "Address family\n"
9509 "Address Family modifier\n"
9510 "Address Family modifier\n"
9511 "Address Family modifier\n"
9512 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05309513 "Display detailed information about dampening\n"
9514 "Display flap statistics of routes\n"
9515 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9516
paul718e3742002-12-13 20:15:29 +00009517#ifdef HAVE_IPV6
Lou Berger651b4022016-01-12 13:42:07 -05009518DEFUN (show_bgp_ipv6_safi_flap_prefix,
9519 show_bgp_ipv6_safi_flap_prefix_cmd,
9520 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics X:X::X:X/M",
paul718e3742002-12-13 20:15:29 +00009521 SHOW_STR
9522 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009523 "Address family\n"
9524 "Address Family modifier\n"
9525 "Address Family modifier\n"
9526 "Address Family modifier\n"
9527 "Address Family modifier\n"
9528 "Display flap statistics of routes\n"
9529 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paul718e3742002-12-13 20:15:29 +00009530{
Lou Berger651b4022016-01-12 13:42:07 -05009531 safi_t safi;
9532
9533 if (bgp_parse_safi(argv[0], &safi)) {
9534 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
9535 return CMD_WARNING;
9536 }
9537 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, safi,
9538 bgp_show_type_flap_prefix);
paul718e3742002-12-13 20:15:29 +00009539}
9540
Lou Berger651b4022016-01-12 13:42:07 -05009541ALIAS (show_bgp_ipv6_safi_flap_prefix,
9542 show_bgp_ipv6_safi_damp_flap_prefix_cmd,
9543 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics X:X::X:X/M",
9544 SHOW_STR
9545 BGP_STR
9546 "Address family\n"
9547 "Address Family modifier\n"
9548 "Address Family modifier\n"
9549 "Address Family modifier\n"
9550 "Address Family modifier\n"
9551 "Display detailed information about dampening\n"
9552 "Display flap statistics of routes\n"
9553 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9554
9555DEFUN (show_bgp_ipv6_prefix_longer,
paul718e3742002-12-13 20:15:29 +00009556 show_bgp_ipv6_prefix_longer_cmd,
9557 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9558 SHOW_STR
9559 BGP_STR
9560 "Address family\n"
9561 "IPv6 prefix <network>/<length>\n"
9562 "Display route and more specific routes\n")
paul718e3742002-12-13 20:15:29 +00009563{
9564 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9565 bgp_show_type_prefix_longer);
9566}
9567
paul718e3742002-12-13 20:15:29 +00009568#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009569
paul94f2b392005-06-28 12:44:16 +00009570static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009571peer_lookup_in_view (struct vty *vty, const char *view_name,
9572 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009573{
9574 int ret;
9575 struct bgp *bgp;
9576 struct peer *peer;
9577 union sockunion su;
9578
9579 /* BGP structure lookup. */
9580 if (view_name)
9581 {
9582 bgp = bgp_lookup_by_name (view_name);
9583 if (! bgp)
9584 {
9585 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9586 return NULL;
9587 }
9588 }
paul5228ad22004-06-04 17:58:18 +00009589 else
paulbb46e942003-10-24 19:02:03 +00009590 {
9591 bgp = bgp_get_default ();
9592 if (! bgp)
9593 {
9594 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9595 return NULL;
9596 }
9597 }
9598
9599 /* Get peer sockunion. */
9600 ret = str2sockunion (ip_str, &su);
9601 if (ret < 0)
9602 {
9603 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9604 return NULL;
9605 }
9606
9607 /* Peer structure lookup. */
9608 peer = peer_lookup (bgp, &su);
9609 if (! peer)
9610 {
9611 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9612 return NULL;
9613 }
9614
9615 return peer;
9616}
David Lamparter6b0655a2014-06-04 06:53:35 +02009617
Paul Jakma2815e612006-09-14 02:56:07 +00009618enum bgp_stats
9619{
9620 BGP_STATS_MAXBITLEN = 0,
9621 BGP_STATS_RIB,
9622 BGP_STATS_PREFIXES,
9623 BGP_STATS_TOTPLEN,
9624 BGP_STATS_UNAGGREGATEABLE,
9625 BGP_STATS_MAX_AGGREGATEABLE,
9626 BGP_STATS_AGGREGATES,
9627 BGP_STATS_SPACE,
9628 BGP_STATS_ASPATH_COUNT,
9629 BGP_STATS_ASPATH_MAXHOPS,
9630 BGP_STATS_ASPATH_TOTHOPS,
9631 BGP_STATS_ASPATH_MAXSIZE,
9632 BGP_STATS_ASPATH_TOTSIZE,
9633 BGP_STATS_ASN_HIGHEST,
9634 BGP_STATS_MAX,
9635};
paulbb46e942003-10-24 19:02:03 +00009636
Paul Jakma2815e612006-09-14 02:56:07 +00009637static const char *table_stats_strs[] =
9638{
9639 [BGP_STATS_PREFIXES] = "Total Prefixes",
9640 [BGP_STATS_TOTPLEN] = "Average prefix length",
9641 [BGP_STATS_RIB] = "Total Advertisements",
9642 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9643 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9644 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9645 [BGP_STATS_SPACE] = "Address space advertised",
9646 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9647 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9648 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9649 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9650 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9651 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9652 [BGP_STATS_MAX] = NULL,
9653};
9654
9655struct bgp_table_stats
9656{
9657 struct bgp_table *table;
9658 unsigned long long counts[BGP_STATS_MAX];
9659};
9660
9661#if 0
9662#define TALLY_SIGFIG 100000
9663static unsigned long
9664ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9665{
9666 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9667 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9668 unsigned long ret = newtot / count;
9669
9670 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9671 return ret + 1;
9672 else
9673 return ret;
9674}
9675#endif
9676
9677static int
9678bgp_table_stats_walker (struct thread *t)
9679{
9680 struct bgp_node *rn;
9681 struct bgp_node *top;
9682 struct bgp_table_stats *ts = THREAD_ARG (t);
9683 unsigned int space = 0;
9684
Paul Jakma53d9f672006-10-15 23:41:16 +00009685 if (!(top = bgp_table_top (ts->table)))
9686 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009687
9688 switch (top->p.family)
9689 {
9690 case AF_INET:
9691 space = IPV4_MAX_BITLEN;
9692 break;
9693 case AF_INET6:
9694 space = IPV6_MAX_BITLEN;
9695 break;
9696 }
9697
9698 ts->counts[BGP_STATS_MAXBITLEN] = space;
9699
9700 for (rn = top; rn; rn = bgp_route_next (rn))
9701 {
9702 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009703 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009704 unsigned int rinum = 0;
9705
9706 if (rn == top)
9707 continue;
9708
9709 if (!rn->info)
9710 continue;
9711
9712 ts->counts[BGP_STATS_PREFIXES]++;
9713 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9714
9715#if 0
9716 ts->counts[BGP_STATS_AVGPLEN]
9717 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9718 ts->counts[BGP_STATS_AVGPLEN],
9719 rn->p.prefixlen);
9720#endif
9721
9722 /* check if the prefix is included by any other announcements */
9723 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009724 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009725
9726 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009727 {
9728 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9729 /* announced address space */
9730 if (space)
9731 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9732 }
Paul Jakma2815e612006-09-14 02:56:07 +00009733 else if (prn->info)
9734 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9735
Paul Jakma2815e612006-09-14 02:56:07 +00009736 for (ri = rn->info; ri; ri = ri->next)
9737 {
9738 rinum++;
9739 ts->counts[BGP_STATS_RIB]++;
9740
9741 if (ri->attr &&
9742 (CHECK_FLAG (ri->attr->flag,
9743 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9744 ts->counts[BGP_STATS_AGGREGATES]++;
9745
9746 /* as-path stats */
9747 if (ri->attr && ri->attr->aspath)
9748 {
9749 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9750 unsigned int size = aspath_size (ri->attr->aspath);
9751 as_t highest = aspath_highest (ri->attr->aspath);
9752
9753 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9754
9755 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9756 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9757
9758 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9759 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9760
9761 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9762 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9763#if 0
9764 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9765 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9766 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9767 hops);
9768 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9769 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9770 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9771 size);
9772#endif
9773 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9774 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9775 }
9776 }
9777 }
9778 return 0;
9779}
9780
9781static int
9782bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9783{
9784 struct bgp_table_stats ts;
9785 unsigned int i;
9786
9787 if (!bgp->rib[afi][safi])
9788 {
9789 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9790 return CMD_WARNING;
9791 }
9792
9793 memset (&ts, 0, sizeof (ts));
9794 ts.table = bgp->rib[afi][safi];
9795 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9796
9797 vty_out (vty, "BGP %s RIB statistics%s%s",
9798 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9799
9800 for (i = 0; i < BGP_STATS_MAX; i++)
9801 {
9802 if (!table_stats_strs[i])
9803 continue;
9804
9805 switch (i)
9806 {
9807#if 0
9808 case BGP_STATS_ASPATH_AVGHOPS:
9809 case BGP_STATS_ASPATH_AVGSIZE:
9810 case BGP_STATS_AVGPLEN:
9811 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9812 vty_out (vty, "%12.2f",
9813 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9814 break;
9815#endif
9816 case BGP_STATS_ASPATH_TOTHOPS:
9817 case BGP_STATS_ASPATH_TOTSIZE:
9818 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9819 vty_out (vty, "%12.2f",
9820 ts.counts[i] ?
9821 (float)ts.counts[i] /
9822 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9823 : 0);
9824 break;
9825 case BGP_STATS_TOTPLEN:
9826 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9827 vty_out (vty, "%12.2f",
9828 ts.counts[i] ?
9829 (float)ts.counts[i] /
9830 (float)ts.counts[BGP_STATS_PREFIXES]
9831 : 0);
9832 break;
9833 case BGP_STATS_SPACE:
9834 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9835 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9836 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9837 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009838 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009839 vty_out (vty, "%12.2f%s",
9840 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009841 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009842 VTY_NEWLINE);
9843 vty_out (vty, "%30s: ", "/8 equivalent ");
9844 vty_out (vty, "%12.2f%s",
9845 (float)ts.counts[BGP_STATS_SPACE] /
9846 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9847 VTY_NEWLINE);
9848 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9849 break;
9850 vty_out (vty, "%30s: ", "/24 equivalent ");
9851 vty_out (vty, "%12.2f",
9852 (float)ts.counts[BGP_STATS_SPACE] /
9853 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9854 break;
9855 default:
9856 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9857 vty_out (vty, "%12llu", ts.counts[i]);
9858 }
9859
9860 vty_out (vty, "%s", VTY_NEWLINE);
9861 }
9862 return CMD_SUCCESS;
9863}
9864
9865static int
9866bgp_table_stats_vty (struct vty *vty, const char *name,
9867 const char *afi_str, const char *safi_str)
9868{
9869 struct bgp *bgp;
9870 afi_t afi;
9871 safi_t safi;
9872
9873 if (name)
9874 bgp = bgp_lookup_by_name (name);
9875 else
9876 bgp = bgp_get_default ();
9877
9878 if (!bgp)
9879 {
9880 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9881 return CMD_WARNING;
9882 }
9883 if (strncmp (afi_str, "ipv", 3) == 0)
9884 {
9885 if (strncmp (afi_str, "ipv4", 4) == 0)
9886 afi = AFI_IP;
9887 else if (strncmp (afi_str, "ipv6", 4) == 0)
9888 afi = AFI_IP6;
9889 else
9890 {
9891 vty_out (vty, "%% Invalid address family %s%s",
9892 afi_str, VTY_NEWLINE);
9893 return CMD_WARNING;
9894 }
Lou Berger298cc2f2016-01-12 13:42:02 -05009895 switch (safi_str[0]) {
9896 case 'm':
9897 safi = SAFI_MULTICAST;
9898 break;
9899 case 'u':
9900 safi = SAFI_UNICAST;
9901 break;
9902 case 'v':
9903 safi = SAFI_MPLS_LABELED_VPN;
9904 break;
9905 case 'e':
9906 safi = SAFI_ENCAP;
9907 break;
9908 default:
9909 vty_out (vty, "%% Invalid subsequent address family %s%s",
Paul Jakma2815e612006-09-14 02:56:07 +00009910 safi_str, VTY_NEWLINE);
Lou Berger298cc2f2016-01-12 13:42:02 -05009911 return CMD_WARNING;
9912 }
Paul Jakma2815e612006-09-14 02:56:07 +00009913 }
9914 else
9915 {
Lou Berger298cc2f2016-01-12 13:42:02 -05009916 vty_out (vty, "%% Invalid address family \"%s\"%s",
Paul Jakma2815e612006-09-14 02:56:07 +00009917 afi_str, VTY_NEWLINE);
9918 return CMD_WARNING;
9919 }
9920
Paul Jakma2815e612006-09-14 02:56:07 +00009921 return bgp_table_stats (vty, bgp, afi, safi);
9922}
9923
9924DEFUN (show_bgp_statistics,
9925 show_bgp_statistics_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -05009926 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +00009927 SHOW_STR
9928 BGP_STR
9929 "Address family\n"
9930 "Address family\n"
9931 "Address Family modifier\n"
9932 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -05009933 "Address Family modifier\n"
9934 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +00009935 "BGP RIB advertisement statistics\n")
9936{
9937 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9938}
9939
Paul Jakma2815e612006-09-14 02:56:07 +00009940DEFUN (show_bgp_statistics_view,
9941 show_bgp_statistics_view_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -05009942 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +00009943 SHOW_STR
9944 BGP_STR
9945 "BGP view\n"
9946 "Address family\n"
9947 "Address family\n"
9948 "Address Family modifier\n"
9949 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -05009950 "Address Family modifier\n"
9951 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +00009952 "BGP RIB advertisement statistics\n")
9953{
9954 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9955}
9956
Lou Berger298cc2f2016-01-12 13:42:02 -05009957#if 0 /* added as options to above command */
Paul Jakma2815e612006-09-14 02:56:07 +00009958ALIAS (show_bgp_statistics_view,
Lou Berger298cc2f2016-01-12 13:42:02 -05009959 show_bgp_statistics_view_encap_cmd,
9960 "show bgp view WORD (ipv4) (encap) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +00009961 SHOW_STR
9962 BGP_STR
9963 "BGP view\n"
9964 "Address family\n"
9965 "Address Family modifier\n"
9966 "BGP RIB advertisement statistics\n")
Lou Berger298cc2f2016-01-12 13:42:02 -05009967#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02009968
Paul Jakmaff7924f2006-09-04 01:10:36 +00009969enum bgp_pcounts
9970{
9971 PCOUNT_ADJ_IN = 0,
9972 PCOUNT_DAMPED,
9973 PCOUNT_REMOVED,
9974 PCOUNT_HISTORY,
9975 PCOUNT_STALE,
9976 PCOUNT_VALID,
9977 PCOUNT_ALL,
9978 PCOUNT_COUNTED,
9979 PCOUNT_PFCNT, /* the figure we display to users */
9980 PCOUNT_MAX,
9981};
9982
9983static const char *pcount_strs[] =
9984{
9985 [PCOUNT_ADJ_IN] = "Adj-in",
9986 [PCOUNT_DAMPED] = "Damped",
9987 [PCOUNT_REMOVED] = "Removed",
9988 [PCOUNT_HISTORY] = "History",
9989 [PCOUNT_STALE] = "Stale",
9990 [PCOUNT_VALID] = "Valid",
9991 [PCOUNT_ALL] = "All RIB",
9992 [PCOUNT_COUNTED] = "PfxCt counted",
9993 [PCOUNT_PFCNT] = "Useable",
9994 [PCOUNT_MAX] = NULL,
9995};
9996
Paul Jakma2815e612006-09-14 02:56:07 +00009997struct peer_pcounts
9998{
9999 unsigned int count[PCOUNT_MAX];
10000 const struct peer *peer;
10001 const struct bgp_table *table;
10002};
10003
Paul Jakmaff7924f2006-09-04 01:10:36 +000010004static int
Paul Jakma2815e612006-09-14 02:56:07 +000010005bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +000010006{
10007 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +000010008 struct peer_pcounts *pc = THREAD_ARG (t);
10009 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010010
Paul Jakma2815e612006-09-14 02:56:07 +000010011 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +000010012 {
10013 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +000010014 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010015
10016 for (ain = rn->adj_in; ain; ain = ain->next)
10017 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +000010018 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010019
Paul Jakmaff7924f2006-09-04 01:10:36 +000010020 for (ri = rn->info; ri; ri = ri->next)
10021 {
10022 char buf[SU_ADDRSTRLEN];
10023
10024 if (ri->peer != peer)
10025 continue;
10026
Paul Jakma2815e612006-09-14 02:56:07 +000010027 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010028
10029 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +000010030 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010031 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +000010032 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010033 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +000010034 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010035 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +000010036 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010037 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +000010038 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +000010039 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +000010040 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010041
10042 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
10043 {
Paul Jakma2815e612006-09-14 02:56:07 +000010044 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +000010045 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +000010046 plog_warn (peer->log,
10047 "%s [pcount] %s/%d is counted but flags 0x%x",
10048 peer->host,
10049 inet_ntop(rn->p.family, &rn->p.u.prefix,
10050 buf, SU_ADDRSTRLEN),
10051 rn->p.prefixlen,
10052 ri->flags);
10053 }
10054 else
10055 {
Paul Jakma1a392d42006-09-07 00:24:49 +000010056 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +000010057 plog_warn (peer->log,
10058 "%s [pcount] %s/%d not counted but flags 0x%x",
10059 peer->host,
10060 inet_ntop(rn->p.family, &rn->p.u.prefix,
10061 buf, SU_ADDRSTRLEN),
10062 rn->p.prefixlen,
10063 ri->flags);
10064 }
10065 }
10066 }
Paul Jakma2815e612006-09-14 02:56:07 +000010067 return 0;
10068}
Paul Jakmaff7924f2006-09-04 01:10:36 +000010069
Paul Jakma2815e612006-09-14 02:56:07 +000010070static int
10071bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
10072{
10073 struct peer_pcounts pcounts = { .peer = peer };
10074 unsigned int i;
10075
10076 if (!peer || !peer->bgp || !peer->afc[afi][safi]
10077 || !peer->bgp->rib[afi][safi])
10078 {
10079 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10080 return CMD_WARNING;
10081 }
10082
10083 memset (&pcounts, 0, sizeof(pcounts));
10084 pcounts.peer = peer;
10085 pcounts.table = peer->bgp->rib[afi][safi];
10086
10087 /* in-place call via thread subsystem so as to record execution time
10088 * stats for the thread-walk (i.e. ensure this can't be blamed on
10089 * on just vty_read()).
10090 */
10091 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
10092
Paul Jakmaff7924f2006-09-04 01:10:36 +000010093 vty_out (vty, "Prefix counts for %s, %s%s",
10094 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
10095 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
10096 vty_out (vty, "%sCounts from RIB table walk:%s%s",
10097 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
10098
10099 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +000010100 vty_out (vty, "%20s: %-10d%s",
10101 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +000010102
Paul Jakma2815e612006-09-14 02:56:07 +000010103 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +000010104 {
10105 vty_out (vty, "%s [pcount] PfxCt drift!%s",
10106 peer->host, VTY_NEWLINE);
10107 vty_out (vty, "Please report this bug, with the above command output%s",
10108 VTY_NEWLINE);
10109 }
10110
10111 return CMD_SUCCESS;
10112}
10113
Lou Berger651b4022016-01-12 13:42:07 -050010114#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000010115DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
10116 show_bgp_ipv6_neighbor_prefix_counts_cmd,
10117 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
10118 SHOW_STR
10119 BGP_STR
10120 "Address family\n"
10121 "Detailed information on TCP and BGP neighbor connections\n"
10122 "Neighbor to display information about\n"
10123 "Neighbor to display information about\n"
10124 "Display detailed prefix count information\n")
10125{
10126 struct peer *peer;
10127
10128 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10129 if (! peer)
10130 return CMD_WARNING;
10131
10132 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
10133}
Lou Berger651b4022016-01-12 13:42:07 -050010134#endif
Paul Jakmaff7924f2006-09-04 01:10:36 +000010135
Lou Berger651b4022016-01-12 13:42:07 -050010136DEFUN (show_bgp_ipv4_safi_neighbor_prefix_counts,
10137 show_bgp_ipv4_safi_neighbor_prefix_counts_cmd,
10138 "show bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
Paul Jakmaff7924f2006-09-04 01:10:36 +000010139 SHOW_STR
Paul Jakmaff7924f2006-09-04 01:10:36 +000010140 BGP_STR
10141 "Address family\n"
10142 "Address Family modifier\n"
10143 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050010144 "Address Family modifier\n"
10145 "Address Family modifier\n"
Paul Jakmaff7924f2006-09-04 01:10:36 +000010146 "Detailed information on TCP and BGP neighbor connections\n"
10147 "Neighbor to display information about\n"
10148 "Neighbor to display information about\n"
10149 "Display detailed prefix count information\n")
10150{
10151 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050010152 safi_t safi;
10153
10154 if (bgp_parse_safi(argv[0], &safi)) {
10155 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10156 return CMD_WARNING;
10157 }
Paul Jakmaff7924f2006-09-04 01:10:36 +000010158
10159 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10160 if (! peer)
10161 return CMD_WARNING;
10162
Lou Berger651b4022016-01-12 13:42:07 -050010163 return bgp_peer_counts (vty, peer, AFI_IP, safi);
Paul Jakmaff7924f2006-09-04 01:10:36 +000010164}
Lou Berger651b4022016-01-12 13:42:07 -050010165#ifdef HAVE_IPV6
10166DEFUN (show_bgp_ipv6_safi_neighbor_prefix_counts,
10167 show_bgp_ipv6_safi_neighbor_prefix_counts_cmd,
10168 "show bgp ipv6 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
10169 SHOW_STR
10170 BGP_STR
10171 "Address family\n"
10172 "Address Family modifier\n"
10173 "Address Family modifier\n"
10174 "Address Family modifier\n"
10175 "Address Family modifier\n"
10176 "Detailed information on TCP and BGP neighbor connections\n"
10177 "Neighbor to display information about\n"
10178 "Neighbor to display information about\n"
10179 "Display detailed prefix count information\n")
10180{
10181 struct peer *peer;
10182 safi_t safi;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010183
Lou Berger651b4022016-01-12 13:42:07 -050010184 if (bgp_parse_safi(argv[0], &safi)) {
10185 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10186 return CMD_WARNING;
10187 }
10188
10189 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10190 if (! peer)
10191 return CMD_WARNING;
10192
10193 return bgp_peer_counts (vty, peer, AFI_IP6, safi);
10194}
10195#endif
10196
10197DEFUN (show_ip_bgp_encap_neighbor_prefix_counts,
10198 show_ip_bgp_encap_neighbor_prefix_counts_cmd,
10199 "show ip bgp encap all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
Paul Jakmaff7924f2006-09-04 01:10:36 +000010200 SHOW_STR
10201 IP_STR
10202 BGP_STR
10203 "Address family\n"
10204 "Address Family modifier\n"
10205 "Address Family modifier\n"
10206 "Detailed information on TCP and BGP neighbor connections\n"
10207 "Neighbor to display information about\n"
10208 "Neighbor to display information about\n"
10209 "Display detailed prefix count information\n")
10210{
10211 struct peer *peer;
10212
10213 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10214 if (! peer)
10215 return CMD_WARNING;
10216
Lou Berger651b4022016-01-12 13:42:07 -050010217 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_ENCAP);
Paul Jakmaff7924f2006-09-04 01:10:36 +000010218}
10219
10220
paul94f2b392005-06-28 12:44:16 +000010221static void
paul718e3742002-12-13 20:15:29 +000010222show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
10223 int in)
10224{
10225 struct bgp_table *table;
10226 struct bgp_adj_in *ain;
10227 struct bgp_adj_out *adj;
10228 unsigned long output_count;
10229 struct bgp_node *rn;
10230 int header1 = 1;
10231 struct bgp *bgp;
10232 int header2 = 1;
10233
paulbb46e942003-10-24 19:02:03 +000010234 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +000010235
10236 if (! bgp)
10237 return;
10238
10239 table = bgp->rib[afi][safi];
10240
10241 output_count = 0;
10242
10243 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
10244 PEER_STATUS_DEFAULT_ORIGINATE))
10245 {
10246 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 +000010247 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10248 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010249
10250 vty_out (vty, "Originating default network 0.0.0.0%s%s",
10251 VTY_NEWLINE, VTY_NEWLINE);
10252 header1 = 0;
10253 }
10254
10255 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
10256 if (in)
10257 {
10258 for (ain = rn->adj_in; ain; ain = ain->next)
10259 if (ain->peer == peer)
10260 {
10261 if (header1)
10262 {
10263 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 +000010264 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10265 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010266 header1 = 0;
10267 }
10268 if (header2)
10269 {
10270 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
10271 header2 = 0;
10272 }
10273 if (ain->attr)
10274 {
10275 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
10276 output_count++;
10277 }
10278 }
10279 }
10280 else
10281 {
10282 for (adj = rn->adj_out; adj; adj = adj->next)
10283 if (adj->peer == peer)
10284 {
10285 if (header1)
10286 {
10287 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 +000010288 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10289 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010290 header1 = 0;
10291 }
10292 if (header2)
10293 {
10294 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
10295 header2 = 0;
10296 }
10297 if (adj->attr)
10298 {
10299 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
10300 output_count++;
10301 }
10302 }
10303 }
10304
10305 if (output_count != 0)
10306 vty_out (vty, "%sTotal number of prefixes %ld%s",
10307 VTY_NEWLINE, output_count, VTY_NEWLINE);
10308}
10309
paul94f2b392005-06-28 12:44:16 +000010310static int
paulbb46e942003-10-24 19:02:03 +000010311peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
10312{
paul718e3742002-12-13 20:15:29 +000010313 if (! peer || ! peer->afc[afi][safi])
10314 {
10315 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10316 return CMD_WARNING;
10317 }
10318
10319 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10320 {
10321 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
10322 VTY_NEWLINE);
10323 return CMD_WARNING;
10324 }
10325
10326 show_adj_route (vty, peer, afi, safi, in);
10327
10328 return CMD_SUCCESS;
10329}
10330
Lou Berger651b4022016-01-12 13:42:07 -050010331DEFUN (show_bgp_ipv4_safi_neighbor_advertised_route,
10332 show_bgp_ipv4_safi_neighbor_advertised_route_cmd,
10333 "show bgp ipv4 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010334 SHOW_STR
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010335 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010336 "Address Family modifier\n"
10337 "Address Family modifier\n"
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010338 "Detailed information on TCP and BGP neighbor connections\n"
10339 "Neighbor to display information about\n"
10340 "Neighbor to display information about\n"
10341 "Display the routes advertised to a BGP neighbor\n")
10342{
10343 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050010344 safi_t safi;
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010345
Lou Berger651b4022016-01-12 13:42:07 -050010346 if (bgp_parse_safi(argv[0], &safi)) {
10347 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010348 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050010349 }
paul718e3742002-12-13 20:15:29 +000010350
paulbb46e942003-10-24 19:02:03 +000010351 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10352 if (! peer)
10353 return CMD_WARNING;
10354
Lou Berger651b4022016-01-12 13:42:07 -050010355 return peer_adj_routes (vty, peer, AFI_IP, safi, 0);
10356}
10357#ifdef HAVE_IPV6
10358DEFUN (show_bgp_ipv6_safi_neighbor_advertised_route,
10359 show_bgp_ipv6_safi_neighbor_advertised_route_cmd,
10360 "show bgp ipv6 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10361 SHOW_STR
10362 BGP_STR
10363 "Address Family modifier\n"
10364 "Address Family modifier\n"
10365 "Address Family modifier\n"
10366 "Detailed information on TCP and BGP neighbor connections\n"
10367 "Neighbor to display information about\n"
10368 "Neighbor to display information about\n"
10369 "Display the routes advertised to a BGP neighbor\n")
10370{
10371 struct peer *peer;
10372 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000010373
Lou Berger651b4022016-01-12 13:42:07 -050010374 if (bgp_parse_safi(argv[0], &safi)) {
10375 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10376 return CMD_WARNING;
10377 }
10378
10379 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10380 if (! peer)
10381 return CMD_WARNING;
10382
10383 return peer_adj_routes (vty, peer, AFI_IP6, safi, 0);
paul718e3742002-12-13 20:15:29 +000010384}
10385
paulbb46e942003-10-24 19:02:03 +000010386DEFUN (show_bgp_view_neighbor_advertised_route,
Lou Berger651b4022016-01-12 13:42:07 -050010387 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10388 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
paulbb46e942003-10-24 19:02:03 +000010389 SHOW_STR
10390 BGP_STR
10391 "BGP view\n"
10392 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050010393 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000010394 "Detailed information on TCP and BGP neighbor connections\n"
10395 "Neighbor to display information about\n"
10396 "Neighbor to display information about\n"
10397 "Display the routes advertised to a BGP neighbor\n")
10398{
10399 struct peer *peer;
10400
10401 if (argc == 2)
10402 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10403 else
10404 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10405
10406 if (! peer)
10407 return CMD_WARNING;
10408
10409 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10410}
10411
Lou Berger651b4022016-01-12 13:42:07 -050010412DEFUN (show_bgp_view_neighbor_received_routes,
10413 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10414 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
paulbb46e942003-10-24 19:02:03 +000010415 SHOW_STR
10416 BGP_STR
10417 "BGP view\n"
10418 "View name\n"
10419 "Address family\n"
10420 "Detailed information on TCP and BGP neighbor connections\n"
10421 "Neighbor to display information about\n"
10422 "Neighbor to display information about\n"
paulbb46e942003-10-24 19:02:03 +000010423 "Display the received routes from neighbor\n")
10424{
10425 struct peer *peer;
10426
10427 if (argc == 2)
10428 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10429 else
10430 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10431
10432 if (! peer)
10433 return CMD_WARNING;
10434
10435 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10436}
10437
paulbb46e942003-10-24 19:02:03 +000010438ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010439 show_bgp_ipv6_neighbor_advertised_route_cmd,
10440 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10441 SHOW_STR
10442 BGP_STR
10443 "Address family\n"
10444 "Detailed information on TCP and BGP neighbor connections\n"
10445 "Neighbor to display information about\n"
10446 "Neighbor to display information about\n"
10447 "Display the routes advertised to a BGP neighbor\n")
10448
paul718e3742002-12-13 20:15:29 +000010449#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010450
Lou Berger651b4022016-01-12 13:42:07 -050010451
10452DEFUN (show_bgp_ipv4_safi_neighbor_received_routes,
10453 show_bgp_ipv4_safi_neighbor_received_routes_cmd,
10454 "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 +010010455 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010456 BGP_STR
10457 "Address family\n"
10458 "Address Family modifier\n"
10459 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050010460 "Address Family modifier\n"
10461 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000010462 "Detailed information on TCP and BGP neighbor connections\n"
10463 "Neighbor to display information about\n"
10464 "Neighbor to display information about\n"
10465 "Display the received routes from neighbor\n")
10466{
paulbb46e942003-10-24 19:02:03 +000010467 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050010468 safi_t safi;
10469
10470 if (bgp_parse_safi(argv[0], &safi)) {
10471 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10472 return CMD_WARNING;
10473 }
paul718e3742002-12-13 20:15:29 +000010474
paulbb46e942003-10-24 19:02:03 +000010475 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10476 if (! peer)
10477 return CMD_WARNING;
10478
Lou Berger651b4022016-01-12 13:42:07 -050010479 return peer_adj_routes (vty, peer, AFI_IP, safi, 1);
paul718e3742002-12-13 20:15:29 +000010480}
Lou Berger651b4022016-01-12 13:42:07 -050010481#ifdef HAVE_IPV6
10482DEFUN (show_bgp_ipv6_safi_neighbor_received_routes,
10483 show_bgp_ipv6_safi_neighbor_received_routes_cmd,
10484 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) received-routes",
10485 SHOW_STR
10486 BGP_STR
10487 "Address family\n"
10488 "Address Family modifier\n"
10489 "Address Family modifier\n"
10490 "Address Family modifier\n"
10491 "Address Family modifier\n"
10492 "Detailed information on TCP and BGP neighbor connections\n"
10493 "Neighbor to display information about\n"
10494 "Neighbor to display information about\n"
10495 "Display the received routes from neighbor\n")
10496{
10497 struct peer *peer;
10498 safi_t safi;
10499
10500 if (bgp_parse_safi(argv[0], &safi)) {
10501 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10502 return CMD_WARNING;
10503 }
10504
10505 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10506 if (! peer)
10507 return CMD_WARNING;
10508
10509 return peer_adj_routes (vty, peer, AFI_IP6, safi, 1);
10510}
10511#endif
paul718e3742002-12-13 20:15:29 +000010512
Michael Lambert95cbbd22010-07-23 14:43:04 -040010513DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10514 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010515 "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 -040010516 SHOW_STR
10517 BGP_STR
10518 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010519 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010520 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010521 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010522 "Address family modifier\n"
10523 "Address family modifier\n"
10524 "Detailed information on TCP and BGP neighbor connections\n"
10525 "Neighbor to display information about\n"
10526 "Neighbor to display information about\n"
10527 "Display the advertised routes to neighbor\n"
10528 "Display the received routes from neighbor\n")
10529{
10530 int afi;
10531 int safi;
10532 int in;
10533 struct peer *peer;
10534
David Lamparter94bad672015-03-03 08:52:22 +010010535 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010536
10537 if (! peer)
10538 return CMD_WARNING;
10539
Michael Lambert95cbbd22010-07-23 14:43:04 -040010540 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10541 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10542 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010543
10544 return peer_adj_routes (vty, peer, afi, safi, in);
10545}
10546
Lou Berger651b4022016-01-12 13:42:07 -050010547DEFUN (show_bgp_ipv4_safi_neighbor_received_prefix_filter,
10548 show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd,
10549 "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 +000010550 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010551 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010552 IP_STR
10553 "Address Family modifier\n"
10554 "Address Family modifier\n"
10555 "Address Family modifier\n"
10556 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000010557 "Detailed information on TCP and BGP neighbor connections\n"
10558 "Neighbor to display information about\n"
10559 "Neighbor to display information about\n"
10560 "Display information received from a BGP neighbor\n"
10561 "Display the prefixlist filter\n")
10562{
10563 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010564 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010565 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010566 int count, ret;
Lou Berger651b4022016-01-12 13:42:07 -050010567 safi_t safi;
paul718e3742002-12-13 20:15:29 +000010568
Lou Berger651b4022016-01-12 13:42:07 -050010569 if (bgp_parse_safi(argv[0], &safi)) {
10570 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010571 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050010572 }
paul718e3742002-12-13 20:15:29 +000010573
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010574 ret = str2sockunion (argv[1], &su);
10575 if (ret < 0)
10576 {
10577 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10578 return CMD_WARNING;
10579 }
paul718e3742002-12-13 20:15:29 +000010580
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010581 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010582 if (! peer)
10583 return CMD_WARNING;
10584
Lou Berger651b4022016-01-12 13:42:07 -050010585 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, safi);
10586 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10587 if (count) {
10588 vty_out (vty, "Address family: IPv4 %s%s", safi2str(safi), VTY_NEWLINE);
10589 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10590 }
paul718e3742002-12-13 20:15:29 +000010591
10592 return CMD_SUCCESS;
10593}
paul718e3742002-12-13 20:15:29 +000010594#ifdef HAVE_IPV6
Lou Berger651b4022016-01-12 13:42:07 -050010595DEFUN (show_bgp_ipv6_safi_neighbor_received_prefix_filter,
10596 show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd,
10597 "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 +000010598 SHOW_STR
10599 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010600 IP_STR
10601 "Address Family modifier\n"
10602 "Address Family modifier\n"
10603 "Address Family modifier\n"
10604 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000010605 "Detailed information on TCP and BGP neighbor connections\n"
10606 "Neighbor to display information about\n"
10607 "Neighbor to display information about\n"
Lou Berger651b4022016-01-12 13:42:07 -050010608 "Display information received from a BGP neighbor\n"
10609 "Display the prefixlist filter\n")
10610{
10611 char name[BUFSIZ];
10612 union sockunion su;
10613 struct peer *peer;
10614 int count, ret;
10615 safi_t safi;
10616
10617 if (bgp_parse_safi(argv[0], &safi)) {
10618 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10619 return CMD_WARNING;
10620 }
10621
10622 ret = str2sockunion (argv[1], &su);
10623 if (ret < 0)
10624 {
10625 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10626 return CMD_WARNING;
10627 }
10628
10629 peer = peer_lookup (NULL, &su);
10630 if (! peer)
10631 return CMD_WARNING;
10632
10633 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, safi);
10634 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10635 if (count) {
10636 vty_out (vty, "Address family: IPv6 %s%s", safi2str(safi), VTY_NEWLINE);
10637 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10638 }
10639
10640 return CMD_SUCCESS;
10641}
paul718e3742002-12-13 20:15:29 +000010642
paulbb46e942003-10-24 19:02:03 +000010643ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010644 show_bgp_ipv6_neighbor_received_routes_cmd,
10645 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10646 SHOW_STR
10647 BGP_STR
10648 "Address family\n"
10649 "Detailed information on TCP and BGP neighbor connections\n"
10650 "Neighbor to display information about\n"
10651 "Neighbor to display information about\n"
10652 "Display the received routes from neighbor\n")
10653
10654DEFUN (show_bgp_neighbor_received_prefix_filter,
Lou Berger651b4022016-01-12 13:42:07 -050010655 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10656 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
paul718e3742002-12-13 20:15:29 +000010657 SHOW_STR
10658 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010659 "Address family\n"
paul718e3742002-12-13 20:15:29 +000010660 "Detailed information on TCP and BGP neighbor connections\n"
10661 "Neighbor to display information about\n"
10662 "Neighbor to display information about\n"
10663 "Display information received from a BGP neighbor\n"
10664 "Display the prefixlist filter\n")
10665{
10666 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010667 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010668 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010669 int count, ret;
paul718e3742002-12-13 20:15:29 +000010670
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010671 ret = str2sockunion (argv[0], &su);
10672 if (ret < 0)
10673 {
10674 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10675 return CMD_WARNING;
10676 }
paul718e3742002-12-13 20:15:29 +000010677
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010678 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010679 if (! peer)
10680 return CMD_WARNING;
10681
10682 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10683 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10684 if (count)
10685 {
10686 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10687 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10688 }
10689
10690 return CMD_SUCCESS;
10691}
10692
paulbb46e942003-10-24 19:02:03 +000010693DEFUN (show_bgp_view_neighbor_received_prefix_filter,
Lou Berger651b4022016-01-12 13:42:07 -050010694 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10695 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
paulbb46e942003-10-24 19:02:03 +000010696 SHOW_STR
10697 BGP_STR
10698 "BGP view\n"
10699 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050010700 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000010701 "Detailed information on TCP and BGP neighbor connections\n"
10702 "Neighbor to display information about\n"
10703 "Neighbor to display information about\n"
10704 "Display information received from a BGP neighbor\n"
10705 "Display the prefixlist filter\n")
10706{
10707 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010708 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010709 struct peer *peer;
10710 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010711 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010712
10713 /* BGP structure lookup. */
10714 bgp = bgp_lookup_by_name (argv[0]);
10715 if (bgp == NULL)
10716 {
10717 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10718 return CMD_WARNING;
10719 }
10720
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010721 ret = str2sockunion (argv[1], &su);
10722 if (ret < 0)
10723 {
10724 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10725 return CMD_WARNING;
10726 }
paulbb46e942003-10-24 19:02:03 +000010727
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010728 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010729 if (! peer)
10730 return CMD_WARNING;
10731
10732 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10733 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10734 if (count)
10735 {
10736 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10737 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10738 }
10739
10740 return CMD_SUCCESS;
10741}
paul718e3742002-12-13 20:15:29 +000010742#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010743
paul94f2b392005-06-28 12:44:16 +000010744static int
paulbb46e942003-10-24 19:02:03 +000010745bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010746 safi_t safi, enum bgp_show_type type)
10747{
paul718e3742002-12-13 20:15:29 +000010748 if (! peer || ! peer->afc[afi][safi])
10749 {
10750 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010751 return CMD_WARNING;
10752 }
10753
ajs5a646652004-11-05 01:25:55 +000010754 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010755}
10756
Lou Berger651b4022016-01-12 13:42:07 -050010757DEFUN (show_bgp_ipv4_safi_neighbor_flap,
10758 show_bgp_ipv4_safi_neighbor_flap_cmd,
10759 "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paul718e3742002-12-13 20:15:29 +000010760 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010761 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010762 "Address Family Modifier\n"
10763 "Address Family Modifier\n"
10764 "Address Family Modifier\n"
10765 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +000010766 "Detailed information on TCP and BGP neighbor connections\n"
10767 "Neighbor to display information about\n"
10768 "Neighbor to display information about\n"
10769 "Display flap statistics of the routes learned from neighbor\n")
10770{
paulbb46e942003-10-24 19:02:03 +000010771 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050010772 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000010773
Lou Berger651b4022016-01-12 13:42:07 -050010774 if (bgp_parse_safi(argv[0], &safi)) {
10775 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10776 return CMD_WARNING;
10777 }
10778
10779 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulbb46e942003-10-24 19:02:03 +000010780 if (! peer)
10781 return CMD_WARNING;
10782
Lou Berger651b4022016-01-12 13:42:07 -050010783 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000010784 bgp_show_type_flap_neighbor);
10785}
Lou Berger651b4022016-01-12 13:42:07 -050010786#ifdef HAVE_IPV6
10787DEFUN (show_bgp_ipv6_safi_neighbor_flap,
10788 show_bgp_ipv6_safi_neighbor_flap_cmd,
10789 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paul718e3742002-12-13 20:15:29 +000010790 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010791 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010792 "Address Family Modifier\n"
10793 "Address Family Modifier\n"
10794 "Address Family Modifier\n"
10795 "Address Family Modifier\n"
10796 "Detailed information on TCP and BGP neighbor connections\n"
10797 "Neighbor to display information about\n"
10798 "Neighbor to display information about\n"
10799 "Display flap statistics of the routes learned from neighbor\n")
10800{
10801 struct peer *peer;
10802 safi_t safi;
10803
10804 if (bgp_parse_safi(argv[0], &safi)) {
10805 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10806 return CMD_WARNING;
10807 }
10808
10809 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10810 if (! peer)
10811 return CMD_WARNING;
10812
10813 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
10814 bgp_show_type_flap_neighbor);
10815}
10816#endif
10817
10818DEFUN (show_bgp_ipv4_safi_neighbor_damp,
10819 show_bgp_ipv4_safi_neighbor_damp_cmd,
10820 "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10821 SHOW_STR
10822 BGP_STR
10823 "Address Family Modifier\n"
10824 "Address Family Modifier\n"
10825 "Address Family Modifier\n"
10826 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +000010827 "Detailed information on TCP and BGP neighbor connections\n"
10828 "Neighbor to display information about\n"
10829 "Neighbor to display information about\n"
10830 "Display the dampened routes received from neighbor\n")
10831{
paulbb46e942003-10-24 19:02:03 +000010832 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050010833 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000010834
Lou Berger651b4022016-01-12 13:42:07 -050010835 if (bgp_parse_safi(argv[0], &safi)) {
10836 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10837 return CMD_WARNING;
10838 }
10839
10840 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulbb46e942003-10-24 19:02:03 +000010841 if (! peer)
10842 return CMD_WARNING;
10843
Lou Berger651b4022016-01-12 13:42:07 -050010844 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000010845 bgp_show_type_damp_neighbor);
10846}
Lou Berger651b4022016-01-12 13:42:07 -050010847#ifdef HAVE_IPV6
10848DEFUN (show_bgp_ipv6_safi_neighbor_damp,
10849 show_bgp_ipv6_safi_neighbor_damp_cmd,
10850 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) dampened-routes",
paul718e3742002-12-13 20:15:29 +000010851 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -050010852 BGP_STR
10853 "Address Family Modifier\n"
10854 "Address Family Modifier\n"
10855 "Address Family Modifier\n"
10856 "Address Family Modifier\n"
10857 "Detailed information on TCP and BGP neighbor connections\n"
10858 "Neighbor to display information about\n"
10859 "Neighbor to display information about\n"
10860 "Display the dampened routes received from neighbor\n")
10861{
10862 struct peer *peer;
10863 safi_t safi;
10864
10865 if (bgp_parse_safi(argv[0], &safi)) {
10866 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10867 return CMD_WARNING;
10868 }
10869
10870 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10871 if (! peer)
10872 return CMD_WARNING;
10873
10874 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
10875 bgp_show_type_damp_neighbor);
10876}
10877#endif
10878
10879DEFUN (show_bgp_ipv4_safi_neighbor_routes,
10880 show_bgp_ipv4_safi_neighbor_routes_cmd,
10881 "show bgp ipv4 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) routes",
10882 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010883 BGP_STR
10884 "Address family\n"
10885 "Address Family modifier\n"
10886 "Address Family modifier\n"
10887 "Detailed information on TCP and BGP neighbor connections\n"
10888 "Neighbor to display information about\n"
10889 "Neighbor to display information about\n"
10890 "Display routes learned from neighbor\n")
10891{
paulbb46e942003-10-24 19:02:03 +000010892 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050010893 safi_t safi;
10894
10895 if (bgp_parse_safi(argv[0], &safi)) {
10896 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10897 return CMD_WARNING;
10898 }
paulbb46e942003-10-24 19:02:03 +000010899
10900 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10901 if (! peer)
10902 return CMD_WARNING;
10903
Lou Berger651b4022016-01-12 13:42:07 -050010904 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000010905 bgp_show_type_neighbor);
10906}
Lou Berger651b4022016-01-12 13:42:07 -050010907#ifdef HAVE_IPV6
10908DEFUN (show_bgp_ipv6_safi_neighbor_routes,
10909 show_bgp_ipv6_safi_neighbor_routes_cmd,
10910 "show bgp ipv6 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) routes",
paulfee0f4c2004-09-13 05:12:46 +000010911 SHOW_STR
paulfee0f4c2004-09-13 05:12:46 +000010912 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010913 "Address family\n"
10914 "Address Family modifier\n"
10915 "Address Family modifier\n"
10916 "Detailed information on TCP and BGP neighbor connections\n"
10917 NEIGHBOR_ADDR_STR
10918 NEIGHBOR_ADDR_STR
10919 "Display routes learned from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000010920{
paulfee0f4c2004-09-13 05:12:46 +000010921 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050010922 safi_t safi;
paulfee0f4c2004-09-13 05:12:46 +000010923
Lou Berger651b4022016-01-12 13:42:07 -050010924 if (bgp_parse_safi(argv[0], &safi)) {
10925 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10926 return CMD_WARNING;
10927 }
paulfee0f4c2004-09-13 05:12:46 +000010928
Lou Berger651b4022016-01-12 13:42:07 -050010929 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulfee0f4c2004-09-13 05:12:46 +000010930 if (! peer)
10931 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050010932
10933 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
10934 bgp_show_type_neighbor);
paulfee0f4c2004-09-13 05:12:46 +000010935}
Lou Berger651b4022016-01-12 13:42:07 -050010936#endif
paulfee0f4c2004-09-13 05:12:46 +000010937
Michael Lambert95cbbd22010-07-23 14:43:04 -040010938DEFUN (show_bgp_view_ipv4_safi_rsclient,
10939 show_bgp_view_ipv4_safi_rsclient_cmd,
10940 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10941 SHOW_STR
10942 BGP_STR
10943 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010944 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010945 "Address family\n"
10946 "Address Family modifier\n"
10947 "Address Family modifier\n"
10948 "Information about Route Server Client\n"
10949 NEIGHBOR_ADDR_STR)
10950{
10951 struct bgp_table *table;
10952 struct peer *peer;
10953 safi_t safi;
10954
10955 if (argc == 3) {
10956 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10957 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10958 } else {
10959 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10960 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10961 }
10962
10963 if (! peer)
10964 return CMD_WARNING;
10965
10966 if (! peer->afc[AFI_IP][safi])
10967 {
10968 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10969 VTY_NEWLINE);
10970 return CMD_WARNING;
10971 }
10972
10973 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10974 PEER_FLAG_RSERVER_CLIENT))
10975 {
10976 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10977 VTY_NEWLINE);
10978 return CMD_WARNING;
10979 }
10980
10981 table = peer->rib[AFI_IP][safi];
10982
10983 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10984}
10985
10986ALIAS (show_bgp_view_ipv4_safi_rsclient,
10987 show_bgp_ipv4_safi_rsclient_cmd,
10988 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10989 SHOW_STR
10990 BGP_STR
10991 "Address family\n"
10992 "Address Family modifier\n"
10993 "Address Family modifier\n"
10994 "Information about Route Server Client\n"
10995 NEIGHBOR_ADDR_STR)
10996
Lou Berger651b4022016-01-12 13:42:07 -050010997#if 0 /* from 0.99.24.1 merge */
paulfee0f4c2004-09-13 05:12:46 +000010998DEFUN (show_ip_bgp_view_rsclient_route,
10999 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010011000 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000011001 SHOW_STR
11002 IP_STR
11003 BGP_STR
11004 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011005 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011006 "Information about Route Server Client\n"
11007 NEIGHBOR_ADDR_STR
11008 "Network in the BGP routing table to display\n")
11009{
11010 struct bgp *bgp;
11011 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050011012#endif
paulfee0f4c2004-09-13 05:12:46 +000011013
Michael Lambert95cbbd22010-07-23 14:43:04 -040011014DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
11015 show_bgp_view_ipv4_safi_rsclient_route_cmd,
11016 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
11017 SHOW_STR
11018 BGP_STR
11019 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011020 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011021 "Address family\n"
11022 "Address Family modifier\n"
11023 "Address Family modifier\n"
11024 "Information about Route Server Client\n"
11025 NEIGHBOR_ADDR_STR
11026 "Network in the BGP routing table to display\n")
11027{
11028 struct bgp *bgp;
11029 struct peer *peer;
11030 safi_t safi;
11031
11032 /* BGP structure lookup. */
11033 if (argc == 4)
11034 {
11035 bgp = bgp_lookup_by_name (argv[0]);
11036 if (bgp == NULL)
11037 {
11038 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11039 return CMD_WARNING;
11040 }
11041 }
11042 else
11043 {
11044 bgp = bgp_get_default ();
11045 if (bgp == NULL)
11046 {
11047 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11048 return CMD_WARNING;
11049 }
11050 }
11051
11052 if (argc == 4) {
11053 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11054 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11055 } else {
11056 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11057 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11058 }
11059
11060 if (! peer)
11061 return CMD_WARNING;
11062
11063 if (! peer->afc[AFI_IP][safi])
11064 {
11065 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11066 VTY_NEWLINE);
11067 return CMD_WARNING;
11068}
11069
11070 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11071 PEER_FLAG_RSERVER_CLIENT))
11072 {
11073 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11074 VTY_NEWLINE);
11075 return CMD_WARNING;
11076 }
11077
11078 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11079 (argc == 4) ? argv[3] : argv[2],
11080 AFI_IP, safi, NULL, 0);
11081}
11082
11083ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
11084 show_bgp_ipv4_safi_rsclient_route_cmd,
11085 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
11086 SHOW_STR
11087 BGP_STR
11088 "Address family\n"
11089 "Address Family modifier\n"
11090 "Address Family modifier\n"
11091 "Information about Route Server Client\n"
11092 NEIGHBOR_ADDR_STR
11093 "Network in the BGP routing table to display\n")
11094
Lou Berger651b4022016-01-12 13:42:07 -050011095#if 0 /* from 0.99.24.1 merge */
paulfee0f4c2004-09-13 05:12:46 +000011096DEFUN (show_ip_bgp_view_rsclient_prefix,
11097 show_ip_bgp_view_rsclient_prefix_cmd,
11098 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11099 SHOW_STR
11100 IP_STR
11101 BGP_STR
11102 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011103 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011104 "Information about Route Server Client\n"
11105 NEIGHBOR_ADDR_STR
11106 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11107{
11108 struct bgp *bgp;
11109 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050011110#endif
paulfee0f4c2004-09-13 05:12:46 +000011111
Michael Lambert95cbbd22010-07-23 14:43:04 -040011112DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
11113 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
11114 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11115 SHOW_STR
11116 BGP_STR
11117 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011118 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011119 "Address family\n"
11120 "Address Family modifier\n"
11121 "Address Family modifier\n"
11122 "Information about Route Server Client\n"
11123 NEIGHBOR_ADDR_STR
11124 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11125{
11126 struct bgp *bgp;
11127 struct peer *peer;
11128 safi_t safi;
11129
11130 /* BGP structure lookup. */
11131 if (argc == 4)
11132 {
11133 bgp = bgp_lookup_by_name (argv[0]);
11134 if (bgp == NULL)
11135 {
11136 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11137 return CMD_WARNING;
11138 }
11139 }
11140 else
11141 {
11142 bgp = bgp_get_default ();
11143 if (bgp == NULL)
11144 {
11145 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11146 return CMD_WARNING;
11147 }
11148 }
11149
11150 if (argc == 4) {
11151 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11152 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11153 } else {
11154 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11155 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11156 }
11157
11158 if (! peer)
11159 return CMD_WARNING;
11160
11161 if (! peer->afc[AFI_IP][safi])
11162 {
11163 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11164 VTY_NEWLINE);
11165 return CMD_WARNING;
11166}
11167
11168 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11169 PEER_FLAG_RSERVER_CLIENT))
11170{
11171 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11172 VTY_NEWLINE);
11173 return CMD_WARNING;
11174 }
11175
11176 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11177 (argc == 4) ? argv[3] : argv[2],
11178 AFI_IP, safi, NULL, 1);
11179}
11180
11181ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11182 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11183 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11184 SHOW_STR
11185 BGP_STR
11186 "Address family\n"
11187 "Address Family modifier\n"
11188 "Address Family modifier\n"
11189 "Information about Route Server Client\n"
11190 NEIGHBOR_ADDR_STR
11191 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011192
paul718e3742002-12-13 20:15:29 +000011193#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011194DEFUN (show_bgp_view_neighbor_routes,
Lou Berger651b4022016-01-12 13:42:07 -050011195 show_bgp_view_ipv6_neighbor_routes_cmd,
11196 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
paulbb46e942003-10-24 19:02:03 +000011197 SHOW_STR
11198 BGP_STR
11199 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011200 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050011201 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000011202 "Detailed information on TCP and BGP neighbor connections\n"
11203 "Neighbor to display information about\n"
11204 "Neighbor to display information about\n"
11205 "Display routes learned from neighbor\n")
11206{
11207 struct peer *peer;
11208
11209 if (argc == 2)
11210 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11211 else
11212 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11213
11214 if (! peer)
11215 return CMD_WARNING;
11216
11217 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11218 bgp_show_type_neighbor);
11219}
11220
Lou Berger651b4022016-01-12 13:42:07 -050011221DEFUN (show_bgp_view_neighbor_damp,
11222 show_bgp_view_ipv6_neighbor_damp_cmd,
11223 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
paulbb46e942003-10-24 19:02:03 +000011224 SHOW_STR
11225 BGP_STR
11226 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011227 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011228 "Address family\n"
11229 "Detailed information on TCP and BGP neighbor connections\n"
11230 "Neighbor to display information about\n"
11231 "Neighbor to display information about\n"
paulbb46e942003-10-24 19:02:03 +000011232 "Display the dampened routes received from neighbor\n")
11233{
11234 struct peer *peer;
11235
11236 if (argc == 2)
11237 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11238 else
11239 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11240
11241 if (! peer)
11242 return CMD_WARNING;
11243
11244 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11245 bgp_show_type_damp_neighbor);
11246}
11247
Lou Berger651b4022016-01-12 13:42:07 -050011248DEFUN (show_bgp_view_neighbor_flap,
11249 show_bgp_view_ipv6_neighbor_flap_cmd,
11250 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paulbb46e942003-10-24 19:02:03 +000011251 SHOW_STR
11252 BGP_STR
11253 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011254 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011255 "Address family\n"
11256 "Detailed information on TCP and BGP neighbor connections\n"
11257 "Neighbor to display information about\n"
11258 "Neighbor to display information about\n"
11259 "Display the dampened routes received from neighbor\n")
paulbb46e942003-10-24 19:02:03 +000011260{
11261 struct peer *peer;
11262
11263 if (argc == 2)
11264 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11265 else
11266 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11267
11268 if (! peer)
11269 return CMD_WARNING;
11270
11271 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11272 bgp_show_type_flap_neighbor);
11273}
11274
paulbb46e942003-10-24 19:02:03 +000011275ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011276 show_bgp_ipv6_neighbor_routes_cmd,
11277 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11278 SHOW_STR
11279 BGP_STR
11280 "Address family\n"
11281 "Detailed information on TCP and BGP neighbor connections\n"
11282 "Neighbor to display information about\n"
11283 "Neighbor to display information about\n"
11284 "Display routes learned from neighbor\n")
11285
paulbb46e942003-10-24 19:02:03 +000011286ALIAS (show_bgp_view_neighbor_flap,
11287 show_bgp_ipv6_neighbor_flap_cmd,
11288 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11289 SHOW_STR
11290 BGP_STR
11291 "Address family\n"
11292 "Detailed information on TCP and BGP neighbor connections\n"
11293 "Neighbor to display information about\n"
11294 "Neighbor to display information about\n"
11295 "Display flap statistics of the routes learned from neighbor\n")
11296
11297ALIAS (show_bgp_view_neighbor_damp,
paulbb46e942003-10-24 19:02:03 +000011298 show_bgp_ipv6_neighbor_damp_cmd,
11299 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11300 SHOW_STR
11301 BGP_STR
11302 "Address family\n"
11303 "Detailed information on TCP and BGP neighbor connections\n"
11304 "Neighbor to display information about\n"
11305 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011306 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011307
Lou Berger651b4022016-01-12 13:42:07 -050011308#endif /* HAVE_IPV6 */
11309
11310DEFUN (show_bgp_view_ipv4_rsclient,
11311 show_bgp_view_ipv4_rsclient_cmd,
11312 "show bgp view WORD ipv4 rsclient (A.B.C.D|X:X::X:X)",
paulfee0f4c2004-09-13 05:12:46 +000011313 SHOW_STR
11314 BGP_STR
11315 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011316 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050011317 "Address Family\n"
paulfee0f4c2004-09-13 05:12:46 +000011318 "Information about Route Server Client\n"
Lou Berger651b4022016-01-12 13:42:07 -050011319 NEIGHBOR_ADDR_STR2)
paulfee0f4c2004-09-13 05:12:46 +000011320{
Lou Berger651b4022016-01-12 13:42:07 -050011321 struct bgp_table *table;
11322 struct peer *peer;
11323
11324 if (argc == 2)
11325 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11326 else
11327 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11328
11329 if (! peer)
11330 return CMD_WARNING;
11331
11332 if (! peer->afc[AFI_IP][SAFI_UNICAST])
11333 {
11334 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11335 VTY_NEWLINE);
11336 return CMD_WARNING;
11337 }
11338
11339 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
11340 PEER_FLAG_RSERVER_CLIENT))
11341 {
11342 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11343 VTY_NEWLINE);
11344 return CMD_WARNING;
11345 }
11346
11347 table = peer->rib[AFI_IP][SAFI_UNICAST];
11348
11349 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11350}
11351DEFUN (show_bgp_view_ipv6_rsclient,
11352 show_bgp_view_ipv6_rsclient_cmd,
11353 "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X)",
11354 SHOW_STR
11355 BGP_STR
11356 "BGP view\n"
11357 "BGP view name\n"
11358 "Address Family\n"
11359 "Information about Route Server Client\n"
11360 NEIGHBOR_ADDR_STR2)
11361{
11362 struct bgp_table *table;
11363 struct peer *peer;
paulfee0f4c2004-09-13 05:12:46 +000011364
11365 if (argc == 2)
11366 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11367 else
11368 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11369
11370 if (! peer)
11371 return CMD_WARNING;
11372
11373 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11374 {
11375 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11376 VTY_NEWLINE);
11377 return CMD_WARNING;
11378 }
11379
11380 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11381 PEER_FLAG_RSERVER_CLIENT))
11382 {
11383 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11384 VTY_NEWLINE);
11385 return CMD_WARNING;
11386 }
11387
11388 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11389
ajs5a646652004-11-05 01:25:55 +000011390 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011391}
11392
Lou Berger651b4022016-01-12 13:42:07 -050011393ALIAS (show_bgp_view_ipv4_rsclient,
11394 show_bgp_ipv4_rsclient_cmd,
11395 "show bgp ipv4 rsclient (A.B.C.D|X:X::X:X)",
paulfee0f4c2004-09-13 05:12:46 +000011396 SHOW_STR
11397 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011398 "Address Family\n"
paulfee0f4c2004-09-13 05:12:46 +000011399 "Information about Route Server Client\n"
Lou Berger651b4022016-01-12 13:42:07 -050011400 NEIGHBOR_ADDR_STR2)
11401
11402#ifdef HAVE_IPV6
11403ALIAS (show_bgp_view_ipv6_rsclient,
11404 show_bgp_ipv6_rsclient_cmd,
11405 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X)",
11406 SHOW_STR
11407 BGP_STR
11408 "Address Family\n"
11409 "Information about Route Server Client\n"
11410 NEIGHBOR_ADDR_STR2)
paulfee0f4c2004-09-13 05:12:46 +000011411
Michael Lambert95cbbd22010-07-23 14:43:04 -040011412DEFUN (show_bgp_view_ipv6_safi_rsclient,
11413 show_bgp_view_ipv6_safi_rsclient_cmd,
11414 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11415 SHOW_STR
11416 BGP_STR
11417 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011418 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011419 "Address family\n"
11420 "Address Family modifier\n"
11421 "Address Family modifier\n"
11422 "Information about Route Server Client\n"
11423 NEIGHBOR_ADDR_STR)
11424{
11425 struct bgp_table *table;
11426 struct peer *peer;
11427 safi_t safi;
11428
11429 if (argc == 3) {
11430 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11431 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11432 } else {
11433 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11434 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11435 }
11436
11437 if (! peer)
11438 return CMD_WARNING;
11439
11440 if (! peer->afc[AFI_IP6][safi])
11441 {
11442 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11443 VTY_NEWLINE);
11444 return CMD_WARNING;
11445 }
11446
11447 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11448 PEER_FLAG_RSERVER_CLIENT))
11449 {
11450 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11451 VTY_NEWLINE);
11452 return CMD_WARNING;
11453 }
11454
11455 table = peer->rib[AFI_IP6][safi];
11456
11457 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11458}
11459
11460ALIAS (show_bgp_view_ipv6_safi_rsclient,
11461 show_bgp_ipv6_safi_rsclient_cmd,
11462 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11463 SHOW_STR
11464 BGP_STR
11465 "Address family\n"
11466 "Address Family modifier\n"
11467 "Address Family modifier\n"
11468 "Information about Route Server Client\n"
11469 NEIGHBOR_ADDR_STR)
11470
Lou Berger651b4022016-01-12 13:42:07 -050011471
paulfee0f4c2004-09-13 05:12:46 +000011472DEFUN (show_bgp_view_rsclient_route,
11473 show_bgp_view_rsclient_route_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011474 "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
paulfee0f4c2004-09-13 05:12:46 +000011475 SHOW_STR
11476 BGP_STR
11477 "BGP view\n"
Lou Berger651b4022016-01-12 13:42:07 -050011478 "BGP view name\n"
11479 "IP6_STR"
paulfee0f4c2004-09-13 05:12:46 +000011480 "Information about Route Server Client\n"
11481 NEIGHBOR_ADDR_STR
11482 "Network in the BGP routing table to display\n")
11483{
11484 struct bgp *bgp;
11485 struct peer *peer;
11486
11487 /* BGP structure lookup. */
11488 if (argc == 3)
11489 {
11490 bgp = bgp_lookup_by_name (argv[0]);
11491 if (bgp == NULL)
11492 {
11493 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11494 return CMD_WARNING;
11495 }
11496 }
11497 else
11498 {
11499 bgp = bgp_get_default ();
11500 if (bgp == NULL)
11501 {
11502 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11503 return CMD_WARNING;
11504 }
11505 }
11506
11507 if (argc == 3)
11508 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11509 else
11510 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11511
11512 if (! peer)
11513 return CMD_WARNING;
11514
11515 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11516 {
11517 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11518 VTY_NEWLINE);
11519 return CMD_WARNING;
11520 }
11521
11522 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11523 PEER_FLAG_RSERVER_CLIENT))
11524 {
11525 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11526 VTY_NEWLINE);
11527 return CMD_WARNING;
11528 }
11529
11530 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11531 (argc == 3) ? argv[2] : argv[1],
11532 AFI_IP6, SAFI_UNICAST, NULL, 0);
11533}
11534
11535ALIAS (show_bgp_view_rsclient_route,
11536 show_bgp_rsclient_route_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011537 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
paulfee0f4c2004-09-13 05:12:46 +000011538 SHOW_STR
11539 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011540 IP6_STR
paulfee0f4c2004-09-13 05:12:46 +000011541 "Information about Route Server Client\n"
11542 NEIGHBOR_ADDR_STR
11543 "Network in the BGP routing table to display\n")
11544
Michael Lambert95cbbd22010-07-23 14:43:04 -040011545DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11546 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11547 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11548 SHOW_STR
11549 BGP_STR
11550 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011551 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011552 "Address family\n"
11553 "Address Family modifier\n"
11554 "Address Family modifier\n"
11555 "Information about Route Server Client\n"
11556 NEIGHBOR_ADDR_STR
11557 "Network in the BGP routing table to display\n")
11558{
11559 struct bgp *bgp;
11560 struct peer *peer;
11561 safi_t safi;
11562
11563 /* BGP structure lookup. */
11564 if (argc == 4)
11565 {
11566 bgp = bgp_lookup_by_name (argv[0]);
11567 if (bgp == NULL)
11568 {
11569 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11570 return CMD_WARNING;
11571 }
11572 }
11573 else
11574 {
11575 bgp = bgp_get_default ();
11576 if (bgp == NULL)
11577 {
11578 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11579 return CMD_WARNING;
11580 }
11581 }
11582
11583 if (argc == 4) {
11584 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11585 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11586 } else {
11587 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11588 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11589 }
11590
11591 if (! peer)
11592 return CMD_WARNING;
11593
11594 if (! peer->afc[AFI_IP6][safi])
11595 {
11596 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11597 VTY_NEWLINE);
11598 return CMD_WARNING;
11599}
11600
11601 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11602 PEER_FLAG_RSERVER_CLIENT))
11603 {
11604 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11605 VTY_NEWLINE);
11606 return CMD_WARNING;
11607 }
11608
11609 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11610 (argc == 4) ? argv[3] : argv[2],
11611 AFI_IP6, safi, NULL, 0);
11612}
11613
11614ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11615 show_bgp_ipv6_safi_rsclient_route_cmd,
11616 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11617 SHOW_STR
11618 BGP_STR
11619 "Address family\n"
11620 "Address Family modifier\n"
11621 "Address Family modifier\n"
11622 "Information about Route Server Client\n"
11623 NEIGHBOR_ADDR_STR
11624 "Network in the BGP routing table to display\n")
11625
Lou Berger651b4022016-01-12 13:42:07 -050011626
paulfee0f4c2004-09-13 05:12:46 +000011627DEFUN (show_bgp_view_rsclient_prefix,
11628 show_bgp_view_rsclient_prefix_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011629 "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 +000011630 SHOW_STR
11631 BGP_STR
11632 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011633 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050011634 IP6_STR
paulfee0f4c2004-09-13 05:12:46 +000011635 "Information about Route Server Client\n"
11636 NEIGHBOR_ADDR_STR
11637 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11638{
11639 struct bgp *bgp;
11640 struct peer *peer;
11641
11642 /* BGP structure lookup. */
11643 if (argc == 3)
11644 {
11645 bgp = bgp_lookup_by_name (argv[0]);
11646 if (bgp == NULL)
11647 {
11648 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11649 return CMD_WARNING;
11650 }
11651 }
11652 else
11653 {
11654 bgp = bgp_get_default ();
11655 if (bgp == NULL)
11656 {
11657 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11658 return CMD_WARNING;
11659 }
11660 }
11661
11662 if (argc == 3)
11663 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11664 else
11665 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11666
11667 if (! peer)
11668 return CMD_WARNING;
11669
11670 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11671 {
11672 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11673 VTY_NEWLINE);
11674 return CMD_WARNING;
11675 }
11676
11677 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11678 PEER_FLAG_RSERVER_CLIENT))
11679 {
11680 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11681 VTY_NEWLINE);
11682 return CMD_WARNING;
11683 }
11684
11685 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11686 (argc == 3) ? argv[2] : argv[1],
11687 AFI_IP6, SAFI_UNICAST, NULL, 1);
11688}
11689
11690ALIAS (show_bgp_view_rsclient_prefix,
11691 show_bgp_rsclient_prefix_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011692 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
paulfee0f4c2004-09-13 05:12:46 +000011693 SHOW_STR
11694 BGP_STR
11695 "Information about Route Server Client\n"
11696 NEIGHBOR_ADDR_STR
11697 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11698
Michael Lambert95cbbd22010-07-23 14:43:04 -040011699DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11700 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11701 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11702 SHOW_STR
11703 BGP_STR
11704 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011705 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011706 "Address family\n"
11707 "Address Family modifier\n"
11708 "Address Family modifier\n"
11709 "Information about Route Server Client\n"
11710 NEIGHBOR_ADDR_STR
11711 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11712{
11713 struct bgp *bgp;
11714 struct peer *peer;
11715 safi_t safi;
11716
11717 /* BGP structure lookup. */
11718 if (argc == 4)
11719 {
11720 bgp = bgp_lookup_by_name (argv[0]);
11721 if (bgp == NULL)
11722 {
11723 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11724 return CMD_WARNING;
11725 }
11726 }
11727 else
11728 {
11729 bgp = bgp_get_default ();
11730 if (bgp == NULL)
11731 {
11732 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11733 return CMD_WARNING;
11734 }
11735 }
11736
11737 if (argc == 4) {
11738 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11739 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11740 } else {
11741 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11742 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11743 }
11744
11745 if (! peer)
11746 return CMD_WARNING;
11747
11748 if (! peer->afc[AFI_IP6][safi])
11749 {
11750 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11751 VTY_NEWLINE);
11752 return CMD_WARNING;
11753}
11754
11755 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11756 PEER_FLAG_RSERVER_CLIENT))
11757{
11758 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11759 VTY_NEWLINE);
11760 return CMD_WARNING;
11761 }
11762
11763 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11764 (argc == 4) ? argv[3] : argv[2],
11765 AFI_IP6, safi, NULL, 1);
11766}
11767
11768ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11769 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11770 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11771 SHOW_STR
11772 BGP_STR
11773 "Address family\n"
11774 "Address Family modifier\n"
11775 "Address Family modifier\n"
11776 "Information about Route Server Client\n"
11777 NEIGHBOR_ADDR_STR
11778 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11779
paul718e3742002-12-13 20:15:29 +000011780#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020011781
paul718e3742002-12-13 20:15:29 +000011782struct bgp_table *bgp_distance_table;
11783
11784struct bgp_distance
11785{
11786 /* Distance value for the IP source prefix. */
11787 u_char distance;
11788
11789 /* Name of the access-list to be matched. */
11790 char *access_list;
11791};
11792
paul94f2b392005-06-28 12:44:16 +000011793static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011794bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011795{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011796 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011797}
11798
paul94f2b392005-06-28 12:44:16 +000011799static void
paul718e3742002-12-13 20:15:29 +000011800bgp_distance_free (struct bgp_distance *bdistance)
11801{
11802 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11803}
11804
paul94f2b392005-06-28 12:44:16 +000011805static int
paulfd79ac92004-10-13 05:06:08 +000011806bgp_distance_set (struct vty *vty, const char *distance_str,
11807 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011808{
11809 int ret;
11810 struct prefix_ipv4 p;
11811 u_char distance;
11812 struct bgp_node *rn;
11813 struct bgp_distance *bdistance;
11814
11815 ret = str2prefix_ipv4 (ip_str, &p);
11816 if (ret == 0)
11817 {
11818 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11819 return CMD_WARNING;
11820 }
11821
11822 distance = atoi (distance_str);
11823
11824 /* Get BGP distance node. */
11825 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11826 if (rn->info)
11827 {
11828 bdistance = rn->info;
11829 bgp_unlock_node (rn);
11830 }
11831 else
11832 {
11833 bdistance = bgp_distance_new ();
11834 rn->info = bdistance;
11835 }
11836
11837 /* Set distance value. */
11838 bdistance->distance = distance;
11839
11840 /* Reset access-list configuration. */
11841 if (bdistance->access_list)
11842 {
11843 free (bdistance->access_list);
11844 bdistance->access_list = NULL;
11845 }
11846 if (access_list_str)
11847 bdistance->access_list = strdup (access_list_str);
11848
11849 return CMD_SUCCESS;
11850}
11851
paul94f2b392005-06-28 12:44:16 +000011852static int
paulfd79ac92004-10-13 05:06:08 +000011853bgp_distance_unset (struct vty *vty, const char *distance_str,
11854 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011855{
11856 int ret;
11857 struct prefix_ipv4 p;
11858 u_char distance;
11859 struct bgp_node *rn;
11860 struct bgp_distance *bdistance;
11861
11862 ret = str2prefix_ipv4 (ip_str, &p);
11863 if (ret == 0)
11864 {
11865 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11866 return CMD_WARNING;
11867 }
11868
11869 distance = atoi (distance_str);
11870
11871 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11872 if (! rn)
11873 {
11874 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11875 return CMD_WARNING;
11876 }
11877
11878 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010011879
11880 if (bdistance->distance != distance)
11881 {
11882 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
11883 return CMD_WARNING;
11884 }
11885
paul718e3742002-12-13 20:15:29 +000011886 if (bdistance->access_list)
11887 free (bdistance->access_list);
11888 bgp_distance_free (bdistance);
11889
11890 rn->info = NULL;
11891 bgp_unlock_node (rn);
11892 bgp_unlock_node (rn);
11893
11894 return CMD_SUCCESS;
11895}
11896
paul718e3742002-12-13 20:15:29 +000011897/* Apply BGP information to distance method. */
11898u_char
11899bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11900{
11901 struct bgp_node *rn;
11902 struct prefix_ipv4 q;
11903 struct peer *peer;
11904 struct bgp_distance *bdistance;
11905 struct access_list *alist;
11906 struct bgp_static *bgp_static;
11907
11908 if (! bgp)
11909 return 0;
11910
11911 if (p->family != AF_INET)
11912 return 0;
11913
11914 peer = rinfo->peer;
11915
11916 if (peer->su.sa.sa_family != AF_INET)
11917 return 0;
11918
11919 memset (&q, 0, sizeof (struct prefix_ipv4));
11920 q.family = AF_INET;
11921 q.prefix = peer->su.sin.sin_addr;
11922 q.prefixlen = IPV4_MAX_BITLEN;
11923
11924 /* Check source address. */
11925 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11926 if (rn)
11927 {
11928 bdistance = rn->info;
11929 bgp_unlock_node (rn);
11930
11931 if (bdistance->access_list)
11932 {
11933 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11934 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11935 return bdistance->distance;
11936 }
11937 else
11938 return bdistance->distance;
11939 }
11940
11941 /* Backdoor check. */
11942 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11943 if (rn)
11944 {
11945 bgp_static = rn->info;
11946 bgp_unlock_node (rn);
11947
11948 if (bgp_static->backdoor)
11949 {
11950 if (bgp->distance_local)
11951 return bgp->distance_local;
11952 else
11953 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11954 }
11955 }
11956
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011957 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011958 {
11959 if (bgp->distance_ebgp)
11960 return bgp->distance_ebgp;
11961 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11962 }
11963 else
11964 {
11965 if (bgp->distance_ibgp)
11966 return bgp->distance_ibgp;
11967 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11968 }
11969}
11970
11971DEFUN (bgp_distance,
11972 bgp_distance_cmd,
11973 "distance bgp <1-255> <1-255> <1-255>",
11974 "Define an administrative distance\n"
11975 "BGP distance\n"
11976 "Distance for routes external to the AS\n"
11977 "Distance for routes internal to the AS\n"
11978 "Distance for local routes\n")
11979{
11980 struct bgp *bgp;
11981
11982 bgp = vty->index;
11983
11984 bgp->distance_ebgp = atoi (argv[0]);
11985 bgp->distance_ibgp = atoi (argv[1]);
11986 bgp->distance_local = atoi (argv[2]);
11987 return CMD_SUCCESS;
11988}
11989
11990DEFUN (no_bgp_distance,
11991 no_bgp_distance_cmd,
11992 "no distance bgp <1-255> <1-255> <1-255>",
11993 NO_STR
11994 "Define an administrative distance\n"
11995 "BGP distance\n"
11996 "Distance for routes external to the AS\n"
11997 "Distance for routes internal to the AS\n"
11998 "Distance for local routes\n")
11999{
12000 struct bgp *bgp;
12001
12002 bgp = vty->index;
12003
12004 bgp->distance_ebgp= 0;
12005 bgp->distance_ibgp = 0;
12006 bgp->distance_local = 0;
12007 return CMD_SUCCESS;
12008}
12009
12010ALIAS (no_bgp_distance,
12011 no_bgp_distance2_cmd,
12012 "no distance bgp",
12013 NO_STR
12014 "Define an administrative distance\n"
12015 "BGP distance\n")
12016
12017DEFUN (bgp_distance_source,
12018 bgp_distance_source_cmd,
12019 "distance <1-255> A.B.C.D/M",
12020 "Define an administrative distance\n"
12021 "Administrative distance\n"
12022 "IP source prefix\n")
12023{
12024 bgp_distance_set (vty, argv[0], argv[1], NULL);
12025 return CMD_SUCCESS;
12026}
12027
12028DEFUN (no_bgp_distance_source,
12029 no_bgp_distance_source_cmd,
12030 "no distance <1-255> A.B.C.D/M",
12031 NO_STR
12032 "Define an administrative distance\n"
12033 "Administrative distance\n"
12034 "IP source prefix\n")
12035{
12036 bgp_distance_unset (vty, argv[0], argv[1], NULL);
12037 return CMD_SUCCESS;
12038}
12039
12040DEFUN (bgp_distance_source_access_list,
12041 bgp_distance_source_access_list_cmd,
12042 "distance <1-255> A.B.C.D/M WORD",
12043 "Define an administrative distance\n"
12044 "Administrative distance\n"
12045 "IP source prefix\n"
12046 "Access list name\n")
12047{
12048 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
12049 return CMD_SUCCESS;
12050}
12051
12052DEFUN (no_bgp_distance_source_access_list,
12053 no_bgp_distance_source_access_list_cmd,
12054 "no distance <1-255> A.B.C.D/M WORD",
12055 NO_STR
12056 "Define an administrative distance\n"
12057 "Administrative distance\n"
12058 "IP source prefix\n"
12059 "Access list name\n")
12060{
12061 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
12062 return CMD_SUCCESS;
12063}
David Lamparter6b0655a2014-06-04 06:53:35 +020012064
paul718e3742002-12-13 20:15:29 +000012065DEFUN (bgp_damp_set,
12066 bgp_damp_set_cmd,
12067 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12068 "BGP Specific commands\n"
12069 "Enable route-flap dampening\n"
12070 "Half-life time for the penalty\n"
12071 "Value to start reusing a route\n"
12072 "Value to start suppressing a route\n"
12073 "Maximum duration to suppress a stable route\n")
12074{
12075 struct bgp *bgp;
12076 int half = DEFAULT_HALF_LIFE * 60;
12077 int reuse = DEFAULT_REUSE;
12078 int suppress = DEFAULT_SUPPRESS;
12079 int max = 4 * half;
12080
12081 if (argc == 4)
12082 {
12083 half = atoi (argv[0]) * 60;
12084 reuse = atoi (argv[1]);
12085 suppress = atoi (argv[2]);
12086 max = atoi (argv[3]) * 60;
12087 }
12088 else if (argc == 1)
12089 {
12090 half = atoi (argv[0]) * 60;
12091 max = 4 * half;
12092 }
12093
12094 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000012095
12096 if (suppress < reuse)
12097 {
12098 vty_out (vty, "Suppress value cannot be less than reuse value %s",
12099 VTY_NEWLINE);
12100 return 0;
12101 }
12102
paul718e3742002-12-13 20:15:29 +000012103 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
12104 half, reuse, suppress, max);
12105}
12106
12107ALIAS (bgp_damp_set,
12108 bgp_damp_set2_cmd,
12109 "bgp dampening <1-45>",
12110 "BGP Specific commands\n"
12111 "Enable route-flap dampening\n"
12112 "Half-life time for the penalty\n")
12113
12114ALIAS (bgp_damp_set,
12115 bgp_damp_set3_cmd,
12116 "bgp dampening",
12117 "BGP Specific commands\n"
12118 "Enable route-flap dampening\n")
12119
12120DEFUN (bgp_damp_unset,
12121 bgp_damp_unset_cmd,
12122 "no bgp dampening",
12123 NO_STR
12124 "BGP Specific commands\n"
12125 "Enable route-flap dampening\n")
12126{
12127 struct bgp *bgp;
12128
12129 bgp = vty->index;
12130 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
12131}
12132
12133ALIAS (bgp_damp_unset,
12134 bgp_damp_unset2_cmd,
12135 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12136 NO_STR
12137 "BGP Specific commands\n"
12138 "Enable route-flap dampening\n"
12139 "Half-life time for the penalty\n"
12140 "Value to start reusing a route\n"
12141 "Value to start suppressing a route\n"
12142 "Maximum duration to suppress a stable route\n")
12143
Lou Berger651b4022016-01-12 13:42:07 -050012144DEFUN (show_bgp_ipv4_safi_dampened_paths,
12145 show_bgp_ipv4_safi_dampened_paths_cmd,
12146 "show bgp ipv4 (encap|multicast|unicast|vpn) dampened-paths",
paul718e3742002-12-13 20:15:29 +000012147 SHOW_STR
paul718e3742002-12-13 20:15:29 +000012148 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050012149 IP_STR
12150 "Address Family modifier\n"
12151 "Address Family modifier\n"
12152 "Address Family modifier\n"
12153 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000012154 "Display paths suppressed due to dampening\n")
12155{
Lou Berger651b4022016-01-12 13:42:07 -050012156 safi_t safi;
paul718e3742002-12-13 20:15:29 +000012157
Lou Berger651b4022016-01-12 13:42:07 -050012158 if (bgp_parse_safi(argv[0], &safi)) {
12159 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12160 return CMD_WARNING;
12161 }
12162
12163 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_dampend_paths, NULL);
12164}
12165ALIAS (show_bgp_ipv4_safi_dampened_paths,
12166 show_bgp_ipv4_safi_damp_dampened_paths_cmd,
12167 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening dampened-paths",
Balaji3921cc52015-05-16 23:12:17 +053012168 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053012169 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050012170 IP_STR
12171 "Address Family modifier\n"
12172 "Address Family modifier\n"
12173 "Address Family modifier\n"
12174 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053012175 "Display detailed information about dampening\n"
12176 "Display paths suppressed due to dampening\n")
Lou Berger651b4022016-01-12 13:42:07 -050012177#ifdef HAVE_IPV6
12178DEFUN (show_bgp_ipv6_safi_dampened_paths,
12179 show_bgp_ipv6_safi_dampened_paths_cmd,
12180 "show bgp ipv6 (encap|multicast|unicast|vpn) dampened-paths",
paul718e3742002-12-13 20:15:29 +000012181 SHOW_STR
paul718e3742002-12-13 20:15:29 +000012182 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050012183 IPV6_STR
12184 "Address Family modifier\n"
12185 "Address Family modifier\n"
12186 "Address Family modifier\n"
12187 "Address Family modifier\n"
12188 "Display paths suppressed due to dampening\n")
12189{
12190 safi_t safi;
12191
12192 if (bgp_parse_safi(argv[0], &safi)) {
12193 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12194 return CMD_WARNING;
12195 }
12196
12197 return bgp_show (vty, NULL, AFI_IP6, safi, bgp_show_type_dampend_paths, NULL);
12198}
12199ALIAS (show_bgp_ipv6_safi_dampened_paths,
12200 show_bgp_ipv6_safi_damp_dampened_paths_cmd,
12201 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening dampened-paths",
12202 SHOW_STR
12203 BGP_STR
12204 IPV6_STR
12205 "Address Family modifier\n"
12206 "Address Family modifier\n"
12207 "Address Family modifier\n"
12208 "Address Family modifier\n"
12209 "Display detailed information about dampening\n"
12210 "Display paths suppressed due to dampening\n")
12211#endif
12212
12213DEFUN (show_bgp_ipv4_safi_flap_statistics,
12214 show_bgp_ipv4_safi_flap_statistics_cmd,
12215 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics",
12216 SHOW_STR
12217 BGP_STR
12218 "Address Family\n"
12219 "Address Family modifier\n"
12220 "Address Family modifier\n"
12221 "Address Family modifier\n"
12222 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000012223 "Display flap statistics of routes\n")
12224{
Lou Berger651b4022016-01-12 13:42:07 -050012225 safi_t safi;
David Lamparter6b0655a2014-06-04 06:53:35 +020012226
Lou Berger651b4022016-01-12 13:42:07 -050012227 if (bgp_parse_safi(argv[0], &safi)) {
12228 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12229 return CMD_WARNING;
12230 }
12231
12232 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_statistics, NULL);
12233}
12234ALIAS (show_bgp_ipv4_safi_flap_statistics,
12235 show_bgp_ipv4_safi_damp_flap_statistics_cmd,
12236 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics",
Balaji3921cc52015-05-16 23:12:17 +053012237 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053012238 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050012239 "Address Family\n"
12240 "Address Family modifier\n"
12241 "Address Family modifier\n"
12242 "Address Family modifier\n"
12243 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053012244 "Display detailed information about dampening\n"
12245 "Display flap statistics of routes\n")
Lou Berger651b4022016-01-12 13:42:07 -050012246#ifdef HAVE_IPV6
12247DEFUN (show_bgp_ipv6_safi_flap_statistics,
12248 show_bgp_ipv6_safi_flap_statistics_cmd,
12249 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics",
12250 SHOW_STR
12251 BGP_STR
12252 "Address Family\n"
12253 "Address Family modifier\n"
12254 "Address Family modifier\n"
12255 "Address Family modifier\n"
12256 "Address Family modifier\n"
12257 "Display flap statistics of routes\n")
12258{
12259 safi_t safi;
12260
12261 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 return bgp_show (vty, NULL, AFI_IP6, safi, bgp_show_type_flap_statistics, NULL);
12267}
12268ALIAS (show_bgp_ipv6_safi_flap_statistics,
12269 show_bgp_ipv6_safi_damp_flap_statistics_cmd,
12270 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics",
12271 SHOW_STR
12272 BGP_STR
12273 "Address Family\n"
12274 "Address Family modifier\n"
12275 "Address Family modifier\n"
12276 "Address Family modifier\n"
12277 "Address Family modifier\n"
12278 "Display detailed information about dampening\n"
12279 "Display flap statistics of routes\n")
12280#endif
Balaji3921cc52015-05-16 23:12:17 +053012281
paul718e3742002-12-13 20:15:29 +000012282/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012283static int
paulfd79ac92004-10-13 05:06:08 +000012284bgp_clear_damp_route (struct vty *vty, const char *view_name,
12285 const char *ip_str, afi_t afi, safi_t safi,
12286 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012287{
12288 int ret;
12289 struct prefix match;
12290 struct bgp_node *rn;
12291 struct bgp_node *rm;
12292 struct bgp_info *ri;
12293 struct bgp_info *ri_temp;
12294 struct bgp *bgp;
12295 struct bgp_table *table;
12296
12297 /* BGP structure lookup. */
12298 if (view_name)
12299 {
12300 bgp = bgp_lookup_by_name (view_name);
12301 if (bgp == NULL)
12302 {
12303 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12304 return CMD_WARNING;
12305 }
12306 }
12307 else
12308 {
12309 bgp = bgp_get_default ();
12310 if (bgp == NULL)
12311 {
12312 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12313 return CMD_WARNING;
12314 }
12315 }
12316
12317 /* Check IP address argument. */
12318 ret = str2prefix (ip_str, &match);
12319 if (! ret)
12320 {
12321 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12322 return CMD_WARNING;
12323 }
12324
12325 match.family = afi2family (afi);
12326
Lou Berger298cc2f2016-01-12 13:42:02 -050012327 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000012328 {
Lou Berger298cc2f2016-01-12 13:42:02 -050012329 for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +000012330 {
12331 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12332 continue;
12333
12334 if ((table = rn->info) != NULL)
12335 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012336 {
12337 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12338 {
12339 ri = rm->info;
12340 while (ri)
12341 {
12342 if (ri->extra && ri->extra->damp_info)
12343 {
12344 ri_temp = ri->next;
12345 bgp_damp_info_free (ri->extra->damp_info, 1);
12346 ri = ri_temp;
12347 }
12348 else
12349 ri = ri->next;
12350 }
12351 }
12352
12353 bgp_unlock_node (rm);
12354 }
paul718e3742002-12-13 20:15:29 +000012355 }
12356 }
12357 else
12358 {
12359 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012360 {
12361 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12362 {
12363 ri = rn->info;
12364 while (ri)
12365 {
12366 if (ri->extra && ri->extra->damp_info)
12367 {
12368 ri_temp = ri->next;
12369 bgp_damp_info_free (ri->extra->damp_info, 1);
12370 ri = ri_temp;
12371 }
12372 else
12373 ri = ri->next;
12374 }
12375 }
12376
12377 bgp_unlock_node (rn);
12378 }
paul718e3742002-12-13 20:15:29 +000012379 }
12380
12381 return CMD_SUCCESS;
12382}
12383
12384DEFUN (clear_ip_bgp_dampening,
12385 clear_ip_bgp_dampening_cmd,
12386 "clear ip bgp dampening",
12387 CLEAR_STR
12388 IP_STR
12389 BGP_STR
12390 "Clear route flap dampening information\n")
12391{
12392 bgp_damp_info_clean ();
12393 return CMD_SUCCESS;
12394}
12395
12396DEFUN (clear_ip_bgp_dampening_prefix,
12397 clear_ip_bgp_dampening_prefix_cmd,
12398 "clear ip bgp dampening A.B.C.D/M",
12399 CLEAR_STR
12400 IP_STR
12401 BGP_STR
12402 "Clear route flap dampening information\n"
12403 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12404{
12405 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12406 SAFI_UNICAST, NULL, 1);
12407}
12408
12409DEFUN (clear_ip_bgp_dampening_address,
12410 clear_ip_bgp_dampening_address_cmd,
12411 "clear ip bgp dampening A.B.C.D",
12412 CLEAR_STR
12413 IP_STR
12414 BGP_STR
12415 "Clear route flap dampening information\n"
12416 "Network to clear damping information\n")
12417{
12418 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12419 SAFI_UNICAST, NULL, 0);
12420}
12421
12422DEFUN (clear_ip_bgp_dampening_address_mask,
12423 clear_ip_bgp_dampening_address_mask_cmd,
12424 "clear ip bgp dampening A.B.C.D A.B.C.D",
12425 CLEAR_STR
12426 IP_STR
12427 BGP_STR
12428 "Clear route flap dampening information\n"
12429 "Network to clear damping information\n"
12430 "Network mask\n")
12431{
12432 int ret;
12433 char prefix_str[BUFSIZ];
12434
12435 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12436 if (! ret)
12437 {
12438 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12439 return CMD_WARNING;
12440 }
12441
12442 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12443 SAFI_UNICAST, NULL, 0);
12444}
David Lamparter6b0655a2014-06-04 06:53:35 +020012445
Lou Berger298cc2f2016-01-12 13:42:02 -050012446/* also used for encap safi */
paul94f2b392005-06-28 12:44:16 +000012447static int
paul718e3742002-12-13 20:15:29 +000012448bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12449 afi_t afi, safi_t safi, int *write)
12450{
12451 struct bgp_node *prn;
12452 struct bgp_node *rn;
12453 struct bgp_table *table;
12454 struct prefix *p;
12455 struct prefix_rd *prd;
12456 struct bgp_static *bgp_static;
12457 u_int32_t label;
12458 char buf[SU_ADDRSTRLEN];
12459 char rdbuf[RD_ADDRSTRLEN];
12460
12461 /* Network configuration. */
12462 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12463 if ((table = prn->info) != NULL)
12464 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12465 if ((bgp_static = rn->info) != NULL)
12466 {
12467 p = &rn->p;
12468 prd = (struct prefix_rd *) &prn->p;
12469
12470 /* "address-family" display. */
12471 bgp_config_write_family_header (vty, afi, safi, write);
12472
12473 /* "network" configuration display. */
12474 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12475 label = decode_label (bgp_static->tag);
12476
12477 vty_out (vty, " network %s/%d rd %s tag %d",
12478 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12479 p->prefixlen,
12480 rdbuf, label);
12481 vty_out (vty, "%s", VTY_NEWLINE);
12482 }
12483 return 0;
12484}
12485
12486/* Configuration of static route announcement and aggregate
12487 information. */
12488int
12489bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12490 afi_t afi, safi_t safi, int *write)
12491{
12492 struct bgp_node *rn;
12493 struct prefix *p;
12494 struct bgp_static *bgp_static;
12495 struct bgp_aggregate *bgp_aggregate;
12496 char buf[SU_ADDRSTRLEN];
12497
Lou Berger298cc2f2016-01-12 13:42:02 -050012498 if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
paul718e3742002-12-13 20:15:29 +000012499 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12500
12501 /* Network configuration. */
12502 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12503 if ((bgp_static = rn->info) != NULL)
12504 {
12505 p = &rn->p;
12506
12507 /* "address-family" display. */
12508 bgp_config_write_family_header (vty, afi, safi, write);
12509
12510 /* "network" configuration display. */
12511 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12512 {
12513 u_int32_t destination;
12514 struct in_addr netmask;
12515
12516 destination = ntohl (p->u.prefix4.s_addr);
12517 masklen2ip (p->prefixlen, &netmask);
12518 vty_out (vty, " network %s",
12519 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12520
12521 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12522 || (IN_CLASSB (destination) && p->prefixlen == 16)
12523 || (IN_CLASSA (destination) && p->prefixlen == 8)
12524 || p->u.prefix4.s_addr == 0)
12525 {
12526 /* Natural mask is not display. */
12527 }
12528 else
12529 vty_out (vty, " mask %s", inet_ntoa (netmask));
12530 }
12531 else
12532 {
12533 vty_out (vty, " network %s/%d",
12534 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12535 p->prefixlen);
12536 }
12537
12538 if (bgp_static->rmap.name)
12539 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012540 else
12541 {
12542 if (bgp_static->backdoor)
12543 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012544 }
paul718e3742002-12-13 20:15:29 +000012545
12546 vty_out (vty, "%s", VTY_NEWLINE);
12547 }
12548
12549 /* Aggregate-address configuration. */
12550 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12551 if ((bgp_aggregate = rn->info) != NULL)
12552 {
12553 p = &rn->p;
12554
12555 /* "address-family" display. */
12556 bgp_config_write_family_header (vty, afi, safi, write);
12557
12558 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12559 {
12560 struct in_addr netmask;
12561
12562 masklen2ip (p->prefixlen, &netmask);
12563 vty_out (vty, " aggregate-address %s %s",
12564 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12565 inet_ntoa (netmask));
12566 }
12567 else
12568 {
12569 vty_out (vty, " aggregate-address %s/%d",
12570 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12571 p->prefixlen);
12572 }
12573
12574 if (bgp_aggregate->as_set)
12575 vty_out (vty, " as-set");
12576
12577 if (bgp_aggregate->summary_only)
12578 vty_out (vty, " summary-only");
12579
12580 vty_out (vty, "%s", VTY_NEWLINE);
12581 }
12582
12583 return 0;
12584}
12585
12586int
12587bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12588{
12589 struct bgp_node *rn;
12590 struct bgp_distance *bdistance;
12591
12592 /* Distance configuration. */
12593 if (bgp->distance_ebgp
12594 && bgp->distance_ibgp
12595 && bgp->distance_local
12596 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12597 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12598 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12599 vty_out (vty, " distance bgp %d %d %d%s",
12600 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12601 VTY_NEWLINE);
12602
12603 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12604 if ((bdistance = rn->info) != NULL)
12605 {
12606 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12607 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12608 bdistance->access_list ? bdistance->access_list : "",
12609 VTY_NEWLINE);
12610 }
12611
12612 return 0;
12613}
12614
12615/* Allocate routing table structure and install commands. */
12616void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012617bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012618{
12619 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012620 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012621
12622 /* IPv4 BGP commands. */
12623 install_element (BGP_NODE, &bgp_network_cmd);
12624 install_element (BGP_NODE, &bgp_network_mask_cmd);
12625 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12626 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12627 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12628 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12629 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12630 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12631 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12632 install_element (BGP_NODE, &no_bgp_network_cmd);
12633 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12634 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12635 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12636 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12637 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12638 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12639 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12640 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12641
12642 install_element (BGP_NODE, &aggregate_address_cmd);
12643 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12644 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12645 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12646 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12647 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12648 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12649 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12650 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12651 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12652 install_element (BGP_NODE, &no_aggregate_address_cmd);
12653 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12654 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12655 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12656 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12657 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12658 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12659 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12660 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12661 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12662
12663 /* IPv4 unicast configuration. */
12664 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12665 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12666 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12667 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12668 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12669 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012670 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012671 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12672 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12673 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12674 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12675 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012676
paul718e3742002-12-13 20:15:29 +000012677 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12678 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12679 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12680 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12681 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12682 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12683 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12684 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12685 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12686 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12687 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12688 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12689 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12690 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12691 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12692 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12693 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12694 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12695 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12696 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12697
12698 /* IPv4 multicast configuration. */
12699 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12700 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12701 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12702 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12703 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12704 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12705 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12706 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12707 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12708 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12709 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12710 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12711 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12712 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12713 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12714 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12715 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12716 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12717 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12718 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12719 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12720 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12721 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12722 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12723 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12724 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12725 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12726 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12727 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12728 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12729 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12730 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12731
Michael Lambert95cbbd22010-07-23 14:43:04 -040012732 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012733 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050012734 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_route_cmd);
12735 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_route_cmd);
12736 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
12737 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
12738 install_element (VIEW_NODE, &show_bgp_ipv4_encap_route_cmd);
12739 install_element (VIEW_NODE, &show_bgp_ipv6_encap_route_cmd);
12740 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
12741 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
12742 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012743 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050012744 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
12745 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
12746 install_element (VIEW_NODE, &show_bgp_ipv4_encap_prefix_cmd);
12747 install_element (VIEW_NODE, &show_bgp_ipv6_encap_prefix_cmd);
12748 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
12749 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
12750 install_element (VIEW_NODE, &show_bgp_afi_safi_view_cmd);
12751 install_element (VIEW_NODE, &show_bgp_view_afi_safi_route_cmd);
12752 install_element (VIEW_NODE, &show_bgp_view_afi_safi_prefix_cmd);
12753 install_element (VIEW_NODE, &show_bgp_ipv4_safi_regexp_cmd);
12754 install_element (VIEW_NODE, &show_bgp_ipv6_safi_regexp_cmd);
12755 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_list_cmd);
12756 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_list_cmd);
12757 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_list_cmd);
12758 install_element (VIEW_NODE, &show_bgp_ipv4_filter_list_cmd);
12759 install_element (VIEW_NODE, &show_bgp_ipv4_safi_filter_list_cmd);
12760 install_element (VIEW_NODE, &show_bgp_ipv6_safi_filter_list_cmd);
12761 install_element (VIEW_NODE, &show_bgp_ipv4_route_map_cmd);
12762 install_element (VIEW_NODE, &show_bgp_ipv4_cidr_only_cmd);
12763 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cidr_only_cmd);
12764 install_element (VIEW_NODE, &show_bgp_ipv4_community_cmd);
12765 install_element (VIEW_NODE, &show_bgp_ipv4_community2_cmd);
12766 install_element (VIEW_NODE, &show_bgp_ipv4_community3_cmd);
12767 install_element (VIEW_NODE, &show_bgp_ipv4_community4_cmd);
12768 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_cmd);
12769 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community2_cmd);
12770 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community3_cmd);
12771 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012772 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12773 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12774 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12775 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12776 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050012777 install_element (VIEW_NODE, &show_bgp_ipv4_community_exact_cmd);
12778 install_element (VIEW_NODE, &show_bgp_ipv4_community2_exact_cmd);
12779 install_element (VIEW_NODE, &show_bgp_ipv4_community3_exact_cmd);
12780 install_element (VIEW_NODE, &show_bgp_ipv4_community4_exact_cmd);
12781 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
12782 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
12783 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
12784 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
12785 install_element (VIEW_NODE, &show_bgp_ipv4_community_list_cmd);
12786 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_list_cmd);
12787 install_element (VIEW_NODE, &show_bgp_ipv4_community_list_exact_cmd);
12788 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_list_exact_cmd);
12789 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_longer_cmd);
12790 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_longer_cmd);
12791 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_longer_cmd);
12792 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_advertised_route_cmd);
12793 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_advertised_route_cmd);
12794 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_received_routes_cmd);
12795 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012796 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050012797 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_routes_cmd);
12798 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_routes_cmd);
12799 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd);
12800 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd);
12801 install_element (VIEW_NODE, &show_bgp_ipv4_safi_dampened_paths_cmd);
12802 install_element (VIEW_NODE, &show_bgp_ipv6_safi_dampened_paths_cmd);
12803 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_dampened_paths_cmd);
12804 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_dampened_paths_cmd);
12805 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_statistics_cmd);
12806 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_statistics_cmd);
12807 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_statistics_cmd);
12808 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_statistics_cmd);
12809 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_address_cmd);
12810 install_element (VIEW_NODE, &show_bgp_ipv6_flap_address_cmd);
12811 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_address_cmd);
12812 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_cmd);
12813 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_cmd);
12814 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_cmd);
12815 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_cmd);
12816 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_cidr_only_cmd);
12817 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_cidr_only_cmd);
12818 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_regexp_cmd);
12819 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_regexp_cmd);
12820 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_regexp_cmd);
12821 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_regexp_cmd);
12822 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_filter_list_cmd);
12823 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_filter_list_cmd);
12824 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_filter_list_cmd);
12825 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_filter_list_cmd);
12826 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_list_cmd);
12827 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_list_cmd);
12828 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_list_cmd);
12829 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_list_cmd);
12830 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_longer_cmd);
12831 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_longer_cmd);
12832 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd);
12833 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd);
12834 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_route_map_cmd);
12835 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_route_map_cmd);
12836 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_route_map_cmd);
12837 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_route_map_cmd);
12838 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_flap_cmd);
12839 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_flap_cmd);
12840 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_damp_cmd);
12841 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_damp_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012842 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012843 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012844 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012845 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012846 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012847 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012848
12849 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
Michael Lambert95cbbd22010-07-23 14:43:04 -040012850 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050012851 install_element (RESTRICTED_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
12852 install_element (RESTRICTED_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
12853 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
12854 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
12855 install_element (RESTRICTED_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012856 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050012857 install_element (RESTRICTED_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
12858 install_element (RESTRICTED_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
12859 install_element (RESTRICTED_NODE, &show_bgp_ipv4_encap_prefix_cmd);
12860 install_element (RESTRICTED_NODE, &show_bgp_ipv6_encap_prefix_cmd);
12861 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
12862 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
12863 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_route_cmd);
12864 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_prefix_cmd);
12865 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community_cmd);
12866 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community2_cmd);
12867 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community3_cmd);
12868 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community4_cmd);
12869 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community_cmd);
12870 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community2_cmd);
12871 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community3_cmd);
12872 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012873 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12874 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12875 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12876 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12877 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050012878 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community_exact_cmd);
12879 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community2_exact_cmd);
12880 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community3_exact_cmd);
12881 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community4_exact_cmd);
12882 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
12883 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
12884 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
12885 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012886 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012887 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012888 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012889 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012890
Michael Lambert95cbbd22010-07-23 14:43:04 -040012891 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012892 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050012893 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_route_cmd);
12894 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_route_cmd);
12895 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
12896 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
12897 install_element (ENABLE_NODE, &show_bgp_ipv4_encap_route_cmd);
12898 install_element (ENABLE_NODE, &show_bgp_ipv6_encap_route_cmd);
12899 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
12900 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
12901 install_element (ENABLE_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012902 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050012903 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
12904 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
12905 install_element (ENABLE_NODE, &show_bgp_ipv4_encap_prefix_cmd);
12906 install_element (ENABLE_NODE, &show_bgp_ipv6_encap_prefix_cmd);
12907 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
12908 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
12909 install_element (ENABLE_NODE, &show_bgp_afi_safi_view_cmd);
12910 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_route_cmd);
12911 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_prefix_cmd);
12912 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_regexp_cmd);
12913 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_regexp_cmd);
12914 install_element (ENABLE_NODE, &show_bgp_ipv4_prefix_list_cmd);
12915 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_list_cmd);
12916 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_list_cmd);
12917 install_element (ENABLE_NODE, &show_bgp_ipv4_filter_list_cmd);
12918 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_filter_list_cmd);
12919 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_filter_list_cmd);
12920 install_element (ENABLE_NODE, &show_bgp_ipv4_route_map_cmd);
12921 install_element (ENABLE_NODE, &show_bgp_ipv4_cidr_only_cmd);
12922 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cidr_only_cmd);
12923 install_element (ENABLE_NODE, &show_bgp_ipv4_community_cmd);
12924 install_element (ENABLE_NODE, &show_bgp_ipv4_community2_cmd);
12925 install_element (ENABLE_NODE, &show_bgp_ipv4_community3_cmd);
12926 install_element (ENABLE_NODE, &show_bgp_ipv4_community4_cmd);
12927 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community_cmd);
12928 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community2_cmd);
12929 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community3_cmd);
12930 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012931 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12932 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12933 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12934 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12935 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050012936 install_element (ENABLE_NODE, &show_bgp_ipv4_community_exact_cmd);
12937 install_element (ENABLE_NODE, &show_bgp_ipv4_community2_exact_cmd);
12938 install_element (ENABLE_NODE, &show_bgp_ipv4_community3_exact_cmd);
12939 install_element (ENABLE_NODE, &show_bgp_ipv4_community4_exact_cmd);
12940 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
12941 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
12942 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
12943 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
12944 install_element (ENABLE_NODE, &show_bgp_ipv4_community_list_cmd);
12945 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community_list_cmd);
12946 install_element (ENABLE_NODE, &show_bgp_ipv4_community_list_exact_cmd);
12947 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community_list_exact_cmd);
12948 install_element (ENABLE_NODE, &show_bgp_ipv4_prefix_longer_cmd);
12949 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_longer_cmd);
12950 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_longer_cmd);
12951 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_neighbor_advertised_route_cmd);
12952 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_neighbor_advertised_route_cmd);
12953 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_neighbor_received_routes_cmd);
12954 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012955 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050012956 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_neighbor_routes_cmd);
12957 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_neighbor_routes_cmd);
12958 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd);
12959 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd);
12960 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_dampened_paths_cmd);
12961 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_dampened_paths_cmd);
12962 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_dampened_paths_cmd);
12963 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_damp_dampened_paths_cmd);
12964 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_statistics_cmd);
12965 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_flap_statistics_cmd);
12966 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_statistics_cmd);
12967 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_damp_flap_statistics_cmd);
12968 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_address_cmd);
12969 install_element (ENABLE_NODE, &show_bgp_ipv6_flap_address_cmd);
12970 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_address_cmd);
12971 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_prefix_cmd);
12972 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_flap_prefix_cmd);
12973 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_cmd);
12974 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_cmd);
12975 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_cidr_only_cmd);
12976 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_cidr_only_cmd);
12977 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_regexp_cmd);
12978 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_flap_regexp_cmd);
12979 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_regexp_cmd);
12980 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_damp_flap_regexp_cmd);
12981 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_filter_list_cmd);
12982 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_flap_filter_list_cmd);
12983 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_filter_list_cmd);
12984 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_damp_flap_filter_list_cmd);
12985 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_prefix_list_cmd);
12986 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_flap_prefix_list_cmd);
12987 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_list_cmd);
12988 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_list_cmd);
12989 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_prefix_longer_cmd);
12990 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_flap_prefix_longer_cmd);
12991 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd);
12992 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd);
12993 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_route_map_cmd);
12994 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_flap_route_map_cmd);
12995 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_route_map_cmd);
12996 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_damp_flap_route_map_cmd);
12997 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_neighbor_flap_cmd);
12998 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_neighbor_flap_cmd);
12999 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_neighbor_damp_cmd);
13000 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_neighbor_damp_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013001 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013002 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013003 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013004 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013005 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013006 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013007
13008 /* BGP dampening clear commands */
13009 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
13010 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
13011 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
13012 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
13013
Paul Jakmaff7924f2006-09-04 01:10:36 +000013014 /* prefix count */
Lou Berger651b4022016-01-12 13:42:07 -050013015 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_neighbor_prefix_counts_cmd);
13016 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000013017#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000013018 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
13019
paul718e3742002-12-13 20:15:29 +000013020 /* New config IPv6 BGP commands. */
13021 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
13022 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
13023 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
13024 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
13025
13026 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
13027 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
13028 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
13029 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
13030
G.Balaji73bfe0b2011-09-23 22:36:20 +053013031 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
13032 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
13033
paul718e3742002-12-13 20:15:29 +000013034 /* Old config IPv6 BGP commands. */
13035 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
13036 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
13037
13038 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
13039 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
13040 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
13041 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
13042
Michael Lambert95cbbd22010-07-23 14:43:04 -040013043 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000013044 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013045 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000013046 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013047 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013048 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
paul718e3742002-12-13 20:15:29 +000013049 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000013050 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000013051 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
paul718e3742002-12-13 20:15:29 +000013052 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
paul718e3742002-12-13 20:15:29 +000013053 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
paul718e3742002-12-13 20:15:29 +000013054 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
paul718e3742002-12-13 20:15:29 +000013055 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
paul718e3742002-12-13 20:15:29 +000013056 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
paul718e3742002-12-13 20:15:29 +000013057 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
paul718e3742002-12-13 20:15:29 +000013058 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
paul718e3742002-12-13 20:15:29 +000013059 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
13060 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
paul718e3742002-12-13 20:15:29 +000013061 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000013062 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
paul718e3742002-12-13 20:15:29 +000013063 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
paul718e3742002-12-13 20:15:29 +000013064 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
paul718e3742002-12-13 20:15:29 +000013065 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000013066 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000013067 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050013068 install_element (VIEW_NODE, &show_bgp_ipv4_rsclient_cmd);
13069 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013070 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013071 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013072 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013073 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013074 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000013075 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
paulbb46e942003-10-24 19:02:03 +000013076 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
paulbb46e942003-10-24 19:02:03 +000013077 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000013078 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
paulbb46e942003-10-24 19:02:03 +000013079 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000013080 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000013081 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000013082 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000013083 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050013084 install_element (VIEW_NODE, &show_bgp_view_ipv4_rsclient_cmd);
13085 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013086 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013087 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013088 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013089 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013090 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013091
13092 /* Restricted:
13093 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
13094 */
Paul Jakma62687ff2008-08-23 14:27:06 +010013095 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013096 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013097 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013098 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013099 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013100 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013101 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013102 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013103 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013104 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013105 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013106 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
13107 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013108 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013109 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013110 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013111 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013112 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013113 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13114 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013115 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013116 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013117 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013118
Michael Lambert95cbbd22010-07-23 14:43:04 -040013119 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000013120 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013121 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000013122 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013123 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013124 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
paul718e3742002-12-13 20:15:29 +000013125 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000013126 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000013127 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
paul718e3742002-12-13 20:15:29 +000013128 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
paul718e3742002-12-13 20:15:29 +000013129 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
paul718e3742002-12-13 20:15:29 +000013130 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
paul718e3742002-12-13 20:15:29 +000013131 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
paul718e3742002-12-13 20:15:29 +000013132 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
paul718e3742002-12-13 20:15:29 +000013133 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
paul718e3742002-12-13 20:15:29 +000013134 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
paul718e3742002-12-13 20:15:29 +000013135 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
13136 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
paul718e3742002-12-13 20:15:29 +000013137 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
paul718e3742002-12-13 20:15:29 +000013138 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000013139 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
paul718e3742002-12-13 20:15:29 +000013140 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
paul718e3742002-12-13 20:15:29 +000013141 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
paul718e3742002-12-13 20:15:29 +000013142 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000013143 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000013144 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050013145 install_element (ENABLE_NODE, &show_bgp_ipv4_rsclient_cmd);
13146 install_element (ENABLE_NODE, &show_bgp_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013147 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013148 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013149 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013150 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013151 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000013152 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
paulbb46e942003-10-24 19:02:03 +000013153 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
paulbb46e942003-10-24 19:02:03 +000013154 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000013155 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
paulbb46e942003-10-24 19:02:03 +000013156 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000013157 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000013158 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000013159 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000013160 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050013161 install_element (ENABLE_NODE, &show_bgp_view_ipv4_rsclient_cmd);
13162 install_element (ENABLE_NODE, &show_bgp_view_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013163 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013164 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013165 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013166 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013167 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000013168
13169 /* Statistics */
13170 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050013171 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
paul718e3742002-12-13 20:15:29 +000013172#endif /* HAVE_IPV6 */
13173
13174 install_element (BGP_NODE, &bgp_distance_cmd);
13175 install_element (BGP_NODE, &no_bgp_distance_cmd);
13176 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13177 install_element (BGP_NODE, &bgp_distance_source_cmd);
13178 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13179 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13180 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13181
13182 install_element (BGP_NODE, &bgp_damp_set_cmd);
13183 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13184 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13185 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13186 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13187 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13188 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13189 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13190 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13191 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013192
13193 /* Deprecated AS-Pathlimit commands */
13194 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13195 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13196 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13197 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13198 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13199 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13200
13201 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13202 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13203 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13204 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13205 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13206 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13207
13208 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13209 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13210 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13211 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13212 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13213 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13214
13215 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13216 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13217 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13218 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13219 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13220 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13221
13222 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13223 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13224 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13225 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13226 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13227 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13228
13229 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13230 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13231 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13232 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13233 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13234 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013235
13236#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013237 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13238 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013239#endif
paul718e3742002-12-13 20:15:29 +000013240}
Chris Caputo228da422009-07-18 05:44:03 +000013241
13242void
13243bgp_route_finish (void)
13244{
13245 bgp_table_unlock (bgp_distance_table);
13246 bgp_distance_table = NULL;
13247}