blob: 7890e3aa3a979b08793b5b2beb64bf462078eb23 [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
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005943route_vty_out(
5944 struct vty *vty,
5945 struct prefix *p,
5946 struct bgp_info *binfo,
5947 int display,
5948 safi_t safi)
paulb40d9392005-08-22 22:34:41 +00005949{
5950 struct attr *attr;
5951
5952 /* short status lead text */
5953 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005954
5955 /* print prefix and mask */
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005956 if (!display)
paul718e3742002-12-13 20:15:29 +00005957 route_vty_out_route (p, vty);
5958 else
5959 vty_out (vty, "%*s", 17, " ");
5960
5961 /* Print attribute */
5962 attr = binfo->attr;
5963 if (attr)
5964 {
paul718e3742002-12-13 20:15:29 +00005965
Lou Berger298cc2f2016-01-12 13:42:02 -05005966 /*
5967 * NEXTHOP start
5968 */
5969
5970 /*
5971 * For ENCAP routes, nexthop address family is not
5972 * neccessarily the same as the prefix address family.
5973 * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
5974 */
5975 if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN)) {
5976 if (attr->extra) {
5977 char buf[BUFSIZ];
5978 int af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len);
5979
5980 switch (af) {
5981 case AF_INET:
5982 vty_out (vty, "%s", inet_ntop(af,
5983 &attr->extra->mp_nexthop_global_in, buf, BUFSIZ));
5984 break;
5985#if HAVE_IPV6
5986 case AF_INET6:
5987 vty_out (vty, "%s", inet_ntop(af,
5988 &attr->extra->mp_nexthop_global, buf, BUFSIZ));
5989 break;
5990#endif
5991
5992 default:
5993 vty_out(vty, "?");
5994 }
5995 } else {
5996 vty_out(vty, "?");
paul718e3742002-12-13 20:15:29 +00005997 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005998 } else {
5999
6000 if (p->family == AF_INET)
6001 {
6002 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6003 }
6004#ifdef HAVE_IPV6
6005 else if (p->family == AF_INET6)
6006 {
6007 int len;
6008 char buf[BUFSIZ];
6009
6010 len = vty_out (vty, "%s",
6011 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6012 buf, BUFSIZ));
6013 len = 16 - len;
6014 if (len < 1)
6015 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6016 else
6017 vty_out (vty, "%*s", len, " ");
6018 }
paul718e3742002-12-13 20:15:29 +00006019#endif /* HAVE_IPV6 */
Lou Berger298cc2f2016-01-12 13:42:02 -05006020 else
6021 {
6022 vty_out(vty, "?");
6023 }
6024 }
6025
6026 /*
6027 * NEXTHOP end
6028 */
6029
paul718e3742002-12-13 20:15:29 +00006030
6031 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006032 vty_out (vty, "%10u ", attr->med);
paul718e3742002-12-13 20:15:29 +00006033 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006034 vty_out (vty, " ");
paul718e3742002-12-13 20:15:29 +00006035
6036 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006037 vty_out (vty, "%7u ", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006038 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006039 vty_out (vty, " ");
paul718e3742002-12-13 20:15:29 +00006040
Paul Jakmafb982c22007-05-04 20:15:47 +00006041 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00006042
Paul Jakmab2518c12006-05-12 23:48:40 +00006043 /* Print aspath */
6044 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006045 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006046
Paul Jakmab2518c12006-05-12 23:48:40 +00006047 /* Print origin */
paul718e3742002-12-13 20:15:29 +00006048 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00006049 }
paul718e3742002-12-13 20:15:29 +00006050 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006051}
6052
6053/* called from terminal list command */
6054void
6055route_vty_out_tmp (struct vty *vty, struct prefix *p,
6056 struct attr *attr, safi_t safi)
6057{
6058 /* Route status display. */
6059 vty_out (vty, "*");
6060 vty_out (vty, ">");
6061 vty_out (vty, " ");
6062
6063 /* print prefix and mask */
6064 route_vty_out_route (p, vty);
6065
6066 /* Print attribute */
6067 if (attr)
6068 {
6069 if (p->family == AF_INET)
6070 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006071 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00006072 vty_out (vty, "%-16s",
6073 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00006074 else
6075 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6076 }
6077#ifdef HAVE_IPV6
6078 else if (p->family == AF_INET6)
6079 {
6080 int len;
6081 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006082
6083 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006084
6085 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006086 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6087 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006088 len = 16 - len;
6089 if (len < 1)
6090 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6091 else
6092 vty_out (vty, "%*s", len, " ");
6093 }
6094#endif /* HAVE_IPV6 */
6095
6096 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006097 vty_out (vty, "%10u ", attr->med);
paul718e3742002-12-13 20:15:29 +00006098 else
6099 vty_out (vty, " ");
6100
6101 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006102 vty_out (vty, "%7u ", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006103 else
6104 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006105
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006106 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00006107
Paul Jakmab2518c12006-05-12 23:48:40 +00006108 /* Print aspath */
6109 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006110 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006111
Paul Jakmab2518c12006-05-12 23:48:40 +00006112 /* Print origin */
paul718e3742002-12-13 20:15:29 +00006113 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00006114 }
paul718e3742002-12-13 20:15:29 +00006115
6116 vty_out (vty, "%s", VTY_NEWLINE);
6117}
6118
ajs5a646652004-11-05 01:25:55 +00006119void
paul718e3742002-12-13 20:15:29 +00006120route_vty_out_tag (struct vty *vty, struct prefix *p,
6121 struct bgp_info *binfo, int display, safi_t safi)
6122{
6123 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006124 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00006125
6126 if (!binfo->extra)
6127 return;
6128
paulb40d9392005-08-22 22:34:41 +00006129 /* short status lead text */
6130 route_vty_short_status_out (vty, binfo);
6131
paul718e3742002-12-13 20:15:29 +00006132 /* print prefix and mask */
6133 if (! display)
6134 route_vty_out_route (p, vty);
6135 else
6136 vty_out (vty, "%*s", 17, " ");
6137
6138 /* Print attribute */
6139 attr = binfo->attr;
6140 if (attr)
6141 {
6142 if (p->family == AF_INET)
6143 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006144 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00006145 vty_out (vty, "%-16s",
6146 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00006147 else
6148 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6149 }
6150#ifdef HAVE_IPV6
6151 else if (p->family == AF_INET6)
6152 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006153 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006154 char buf[BUFSIZ];
6155 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006156 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00006157 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006158 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6159 buf, BUFSIZ));
6160 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006161 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006162 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6163 buf, BUFSIZ),
6164 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6165 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006166
6167 }
6168#endif /* HAVE_IPV6 */
6169 }
6170
Paul Jakmafb982c22007-05-04 20:15:47 +00006171 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00006172
6173 vty_out (vty, "notag/%d", label);
6174
6175 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006176}
6177
6178/* dampening route */
ajs5a646652004-11-05 01:25:55 +00006179static void
paul718e3742002-12-13 20:15:29 +00006180damp_route_vty_out (struct vty *vty, struct prefix *p,
6181 struct bgp_info *binfo, int display, safi_t safi)
6182{
6183 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006184 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00006185 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00006186
paulb40d9392005-08-22 22:34:41 +00006187 /* short status lead text */
6188 route_vty_short_status_out (vty, binfo);
6189
paul718e3742002-12-13 20:15:29 +00006190 /* print prefix and mask */
6191 if (! display)
6192 route_vty_out_route (p, vty);
6193 else
6194 vty_out (vty, "%*s", 17, " ");
6195
6196 len = vty_out (vty, "%s", binfo->peer->host);
6197 len = 17 - len;
6198 if (len < 1)
6199 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6200 else
6201 vty_out (vty, "%*s", len, " ");
6202
Chris Caputo50aef6f2009-06-23 06:06:49 +00006203 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006204
6205 /* Print attribute */
6206 attr = binfo->attr;
6207 if (attr)
6208 {
6209 /* Print aspath */
6210 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006211 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006212
6213 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006214 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006215 }
6216 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006217}
6218
paul718e3742002-12-13 20:15:29 +00006219/* flap route */
ajs5a646652004-11-05 01:25:55 +00006220static void
paul718e3742002-12-13 20:15:29 +00006221flap_route_vty_out (struct vty *vty, struct prefix *p,
6222 struct bgp_info *binfo, int display, safi_t safi)
6223{
6224 struct attr *attr;
6225 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00006226 char timebuf[BGP_UPTIME_LEN];
6227 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00006228
6229 if (!binfo->extra)
6230 return;
6231
6232 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00006233
paulb40d9392005-08-22 22:34:41 +00006234 /* short status lead text */
6235 route_vty_short_status_out (vty, binfo);
6236
paul718e3742002-12-13 20:15:29 +00006237 /* print prefix and mask */
6238 if (! display)
6239 route_vty_out_route (p, vty);
6240 else
6241 vty_out (vty, "%*s", 17, " ");
6242
6243 len = vty_out (vty, "%s", binfo->peer->host);
6244 len = 16 - len;
6245 if (len < 1)
6246 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6247 else
6248 vty_out (vty, "%*s", len, " ");
6249
6250 len = vty_out (vty, "%d", bdi->flap);
6251 len = 5 - len;
6252 if (len < 1)
6253 vty_out (vty, " ");
6254 else
6255 vty_out (vty, "%*s ", len, " ");
6256
6257 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6258 timebuf, BGP_UPTIME_LEN));
6259
6260 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6261 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00006262 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006263 else
6264 vty_out (vty, "%*s ", 8, " ");
6265
6266 /* Print attribute */
6267 attr = binfo->attr;
6268 if (attr)
6269 {
6270 /* Print aspath */
6271 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006272 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006273
6274 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006275 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006276 }
6277 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006278}
6279
paul94f2b392005-06-28 12:44:16 +00006280static void
paul718e3742002-12-13 20:15:29 +00006281route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6282 struct bgp_info *binfo, afi_t afi, safi_t safi)
6283{
6284 char buf[INET6_ADDRSTRLEN];
6285 char buf1[BUFSIZ];
6286 struct attr *attr;
6287 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03006288#ifdef HAVE_CLOCK_MONOTONIC
6289 time_t tbuf;
6290#endif
paul718e3742002-12-13 20:15:29 +00006291
6292 attr = binfo->attr;
6293
6294 if (attr)
6295 {
6296 /* Line1 display AS-path, Aggregator */
6297 if (attr->aspath)
6298 {
6299 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00006300 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00006301 vty_out (vty, "Local");
6302 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006303 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00006304 }
6305
paulb40d9392005-08-22 22:34:41 +00006306 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6307 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00006308 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6309 vty_out (vty, ", (stale)");
6310 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006311 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006312 attr->extra->aggregator_as,
6313 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006314 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6315 vty_out (vty, ", (Received from a RR-client)");
6316 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6317 vty_out (vty, ", (Received from a RS-client)");
6318 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6319 vty_out (vty, ", (history entry)");
6320 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6321 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006322 vty_out (vty, "%s", VTY_NEWLINE);
6323
6324 /* Line2 display Next-hop, Neighbor, Router-id */
6325 if (p->family == AF_INET)
6326 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006327 vty_out (vty, " %s", ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)) ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006328 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006329 inet_ntoa (attr->nexthop));
6330 }
6331#ifdef HAVE_IPV6
6332 else
6333 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006334 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006335 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006336 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006337 buf, INET6_ADDRSTRLEN));
6338 }
6339#endif /* HAVE_IPV6 */
6340
6341 if (binfo->peer == bgp->peer_self)
6342 {
6343 vty_out (vty, " from %s ",
6344 p->family == AF_INET ? "0.0.0.0" : "::");
6345 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6346 }
6347 else
6348 {
6349 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6350 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006351 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006352 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006353 if (!sockunion2str (&binfo->peer->su, buf, sizeof(buf))) {
6354 buf[0] = '?';
6355 buf[1] = 0;
6356 }
6357 vty_out (vty, " from %s", buf);
paul718e3742002-12-13 20:15:29 +00006358 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006359 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006360 else
6361 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6362 }
6363 vty_out (vty, "%s", VTY_NEWLINE);
6364
6365#ifdef HAVE_IPV6
6366 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006367 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006368 {
6369 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006370 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006371 buf, INET6_ADDRSTRLEN),
6372 VTY_NEWLINE);
6373 }
6374#endif /* HAVE_IPV6 */
6375
6376 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6377 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6378
6379 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006380 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006381
6382 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006383 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006384 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006385 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006386
Paul Jakmafb982c22007-05-04 20:15:47 +00006387 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006388 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006389
6390 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6391 vty_out (vty, ", valid");
6392
6393 if (binfo->peer != bgp->peer_self)
6394 {
6395 if (binfo->peer->as == binfo->peer->local_as)
6396 vty_out (vty, ", internal");
6397 else
6398 vty_out (vty, ", %s",
6399 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6400 }
6401 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6402 vty_out (vty, ", aggregated, local");
6403 else if (binfo->type != ZEBRA_ROUTE_BGP)
6404 vty_out (vty, ", sourced");
6405 else
6406 vty_out (vty, ", sourced, local");
6407
6408 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6409 vty_out (vty, ", atomic-aggregate");
6410
Josh Baileyde8d5df2011-07-20 20:46:01 -07006411 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6412 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6413 bgp_info_mpath_count (binfo)))
6414 vty_out (vty, ", multipath");
6415
paul718e3742002-12-13 20:15:29 +00006416 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6417 vty_out (vty, ", best");
6418
6419 vty_out (vty, "%s", VTY_NEWLINE);
6420
6421 /* Line 4 display Community */
6422 if (attr->community)
6423 vty_out (vty, " Community: %s%s", attr->community->str,
6424 VTY_NEWLINE);
6425
6426 /* Line 5 display Extended-community */
6427 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006428 vty_out (vty, " Extended Community: %s%s",
6429 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006430
6431 /* Line 6 display Originator, Cluster-id */
6432 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6433 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6434 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006435 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006436 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006437 vty_out (vty, " Originator: %s",
6438 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006439
6440 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6441 {
6442 int i;
6443 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006444 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6445 vty_out (vty, "%s ",
6446 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006447 }
6448 vty_out (vty, "%s", VTY_NEWLINE);
6449 }
Paul Jakma41367172007-08-06 15:24:51 +00006450
Paul Jakmafb982c22007-05-04 20:15:47 +00006451 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006452 bgp_damp_info_vty (vty, binfo);
6453
6454 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006455#ifdef HAVE_CLOCK_MONOTONIC
6456 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006457 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006458#else
6459 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6460#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006461 }
6462 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006463}
6464
6465#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6466 "h history, * valid, > best, = multipath,%s"\
6467 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006468#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006469#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6470#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6471#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6472
6473enum bgp_show_type
6474{
6475 bgp_show_type_normal,
6476 bgp_show_type_regexp,
6477 bgp_show_type_prefix_list,
6478 bgp_show_type_filter_list,
6479 bgp_show_type_route_map,
6480 bgp_show_type_neighbor,
6481 bgp_show_type_cidr_only,
6482 bgp_show_type_prefix_longer,
6483 bgp_show_type_community_all,
6484 bgp_show_type_community,
6485 bgp_show_type_community_exact,
6486 bgp_show_type_community_list,
6487 bgp_show_type_community_list_exact,
6488 bgp_show_type_flap_statistics,
6489 bgp_show_type_flap_address,
6490 bgp_show_type_flap_prefix,
6491 bgp_show_type_flap_cidr_only,
6492 bgp_show_type_flap_regexp,
6493 bgp_show_type_flap_filter_list,
6494 bgp_show_type_flap_prefix_list,
6495 bgp_show_type_flap_prefix_longer,
6496 bgp_show_type_flap_route_map,
6497 bgp_show_type_flap_neighbor,
6498 bgp_show_type_dampend_paths,
6499 bgp_show_type_damp_neighbor
6500};
6501
ajs5a646652004-11-05 01:25:55 +00006502static int
paulfee0f4c2004-09-13 05:12:46 +00006503bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006504 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006505{
paul718e3742002-12-13 20:15:29 +00006506 struct bgp_info *ri;
6507 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006508 int header = 1;
paul718e3742002-12-13 20:15:29 +00006509 int display;
ajs5a646652004-11-05 01:25:55 +00006510 unsigned long output_count;
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006511 unsigned long total_count;
paul718e3742002-12-13 20:15:29 +00006512
6513 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006514 output_count = 0;
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006515 total_count = 0;
paul718e3742002-12-13 20:15:29 +00006516
paul718e3742002-12-13 20:15:29 +00006517 /* Start processing of routes. */
6518 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6519 if (rn->info != NULL)
6520 {
6521 display = 0;
6522
6523 for (ri = rn->info; ri; ri = ri->next)
6524 {
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006525 total_count++;
ajs5a646652004-11-05 01:25:55 +00006526 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006527 || type == bgp_show_type_flap_address
6528 || type == bgp_show_type_flap_prefix
6529 || type == bgp_show_type_flap_cidr_only
6530 || type == bgp_show_type_flap_regexp
6531 || type == bgp_show_type_flap_filter_list
6532 || type == bgp_show_type_flap_prefix_list
6533 || type == bgp_show_type_flap_prefix_longer
6534 || type == bgp_show_type_flap_route_map
6535 || type == bgp_show_type_flap_neighbor
6536 || type == bgp_show_type_dampend_paths
6537 || type == bgp_show_type_damp_neighbor)
6538 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006539 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006540 continue;
6541 }
6542 if (type == bgp_show_type_regexp
6543 || type == bgp_show_type_flap_regexp)
6544 {
ajs5a646652004-11-05 01:25:55 +00006545 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006546
6547 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6548 continue;
6549 }
6550 if (type == bgp_show_type_prefix_list
6551 || type == bgp_show_type_flap_prefix_list)
6552 {
ajs5a646652004-11-05 01:25:55 +00006553 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006554
6555 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6556 continue;
6557 }
6558 if (type == bgp_show_type_filter_list
6559 || type == bgp_show_type_flap_filter_list)
6560 {
ajs5a646652004-11-05 01:25:55 +00006561 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006562
6563 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6564 continue;
6565 }
6566 if (type == bgp_show_type_route_map
6567 || type == bgp_show_type_flap_route_map)
6568 {
ajs5a646652004-11-05 01:25:55 +00006569 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006570 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006571 struct attr dummy_attr;
6572 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006573 int ret;
6574
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006575 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006576 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006577
paul718e3742002-12-13 20:15:29 +00006578 binfo.peer = ri->peer;
6579 binfo.attr = &dummy_attr;
6580
6581 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006582 if (ret == RMAP_DENYMATCH)
6583 continue;
6584 }
6585 if (type == bgp_show_type_neighbor
6586 || type == bgp_show_type_flap_neighbor
6587 || type == bgp_show_type_damp_neighbor)
6588 {
ajs5a646652004-11-05 01:25:55 +00006589 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006590
6591 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6592 continue;
6593 }
6594 if (type == bgp_show_type_cidr_only
6595 || type == bgp_show_type_flap_cidr_only)
6596 {
6597 u_int32_t destination;
6598
6599 destination = ntohl (rn->p.u.prefix4.s_addr);
6600 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6601 continue;
6602 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6603 continue;
6604 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6605 continue;
6606 }
6607 if (type == bgp_show_type_prefix_longer
6608 || type == bgp_show_type_flap_prefix_longer)
6609 {
ajs5a646652004-11-05 01:25:55 +00006610 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006611
6612 if (! prefix_match (p, &rn->p))
6613 continue;
6614 }
6615 if (type == bgp_show_type_community_all)
6616 {
6617 if (! ri->attr->community)
6618 continue;
6619 }
6620 if (type == bgp_show_type_community)
6621 {
ajs5a646652004-11-05 01:25:55 +00006622 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006623
6624 if (! ri->attr->community ||
6625 ! community_match (ri->attr->community, com))
6626 continue;
6627 }
6628 if (type == bgp_show_type_community_exact)
6629 {
ajs5a646652004-11-05 01:25:55 +00006630 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006631
6632 if (! ri->attr->community ||
6633 ! community_cmp (ri->attr->community, com))
6634 continue;
6635 }
6636 if (type == bgp_show_type_community_list)
6637 {
ajs5a646652004-11-05 01:25:55 +00006638 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006639
6640 if (! community_list_match (ri->attr->community, list))
6641 continue;
6642 }
6643 if (type == bgp_show_type_community_list_exact)
6644 {
ajs5a646652004-11-05 01:25:55 +00006645 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006646
6647 if (! community_list_exact_match (ri->attr->community, list))
6648 continue;
6649 }
6650 if (type == bgp_show_type_flap_address
6651 || type == bgp_show_type_flap_prefix)
6652 {
ajs5a646652004-11-05 01:25:55 +00006653 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006654
6655 if (! prefix_match (&rn->p, p))
6656 continue;
6657
6658 if (type == bgp_show_type_flap_prefix)
6659 if (p->prefixlen != rn->p.prefixlen)
6660 continue;
6661 }
6662 if (type == bgp_show_type_dampend_paths
6663 || type == bgp_show_type_damp_neighbor)
6664 {
6665 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6666 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6667 continue;
6668 }
6669
6670 if (header)
6671 {
hasso93406d82005-02-02 14:40:33 +00006672 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6673 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6674 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006675 if (type == bgp_show_type_dampend_paths
6676 || type == bgp_show_type_damp_neighbor)
6677 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6678 else if (type == bgp_show_type_flap_statistics
6679 || type == bgp_show_type_flap_address
6680 || type == bgp_show_type_flap_prefix
6681 || type == bgp_show_type_flap_cidr_only
6682 || type == bgp_show_type_flap_regexp
6683 || type == bgp_show_type_flap_filter_list
6684 || type == bgp_show_type_flap_prefix_list
6685 || type == bgp_show_type_flap_prefix_longer
6686 || type == bgp_show_type_flap_route_map
6687 || type == bgp_show_type_flap_neighbor)
6688 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6689 else
6690 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006691 header = 0;
6692 }
6693
6694 if (type == bgp_show_type_dampend_paths
6695 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006696 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006697 else if (type == bgp_show_type_flap_statistics
6698 || type == bgp_show_type_flap_address
6699 || type == bgp_show_type_flap_prefix
6700 || type == bgp_show_type_flap_cidr_only
6701 || type == bgp_show_type_flap_regexp
6702 || type == bgp_show_type_flap_filter_list
6703 || type == bgp_show_type_flap_prefix_list
6704 || type == bgp_show_type_flap_prefix_longer
6705 || type == bgp_show_type_flap_route_map
6706 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006707 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006708 else
ajs5a646652004-11-05 01:25:55 +00006709 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006710 display++;
6711 }
6712 if (display)
ajs5a646652004-11-05 01:25:55 +00006713 output_count++;
paul718e3742002-12-13 20:15:29 +00006714 }
6715
6716 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006717 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006718 {
6719 if (type == bgp_show_type_normal)
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006720 vty_out (vty, "No BGP prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006721 }
6722 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006723 vty_out (vty, "%sDisplayed %ld out of %ld total prefixes%s",
6724 VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006725
6726 return CMD_SUCCESS;
6727}
6728
ajs5a646652004-11-05 01:25:55 +00006729static int
paulfee0f4c2004-09-13 05:12:46 +00006730bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006731 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006732{
6733 struct bgp_table *table;
6734
6735 if (bgp == NULL) {
6736 bgp = bgp_get_default ();
6737 }
6738
6739 if (bgp == NULL)
6740 {
6741 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6742 return CMD_WARNING;
6743 }
6744
6745
6746 table = bgp->rib[afi][safi];
6747
ajs5a646652004-11-05 01:25:55 +00006748 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006749}
6750
paul718e3742002-12-13 20:15:29 +00006751/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006752static void
paul718e3742002-12-13 20:15:29 +00006753route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6754 struct bgp_node *rn,
6755 struct prefix_rd *prd, afi_t afi, safi_t safi)
6756{
6757 struct bgp_info *ri;
6758 struct prefix *p;
6759 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006760 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006761 char buf1[INET6_ADDRSTRLEN];
6762 char buf2[INET6_ADDRSTRLEN];
6763 int count = 0;
6764 int best = 0;
6765 int suppress = 0;
6766 int no_export = 0;
6767 int no_advertise = 0;
6768 int local_as = 0;
6769 int first = 0;
Lou Berger298cc2f2016-01-12 13:42:02 -05006770 int printrd = ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP));
paul718e3742002-12-13 20:15:29 +00006771
6772 p = &rn->p;
6773 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
Lou Berger298cc2f2016-01-12 13:42:02 -05006774 (printrd ? prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6775 printrd ? ":" : "",
paul718e3742002-12-13 20:15:29 +00006776 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6777 p->prefixlen, VTY_NEWLINE);
6778
6779 for (ri = rn->info; ri; ri = ri->next)
6780 {
6781 count++;
6782 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6783 {
6784 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006785 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006786 suppress = 1;
6787 if (ri->attr->community != NULL)
6788 {
6789 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6790 no_advertise = 1;
6791 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6792 no_export = 1;
6793 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6794 local_as = 1;
6795 }
6796 }
6797 }
6798
6799 vty_out (vty, "Paths: (%d available", count);
6800 if (best)
6801 {
6802 vty_out (vty, ", best #%d", best);
6803 if (safi == SAFI_UNICAST)
6804 vty_out (vty, ", table Default-IP-Routing-Table");
6805 }
6806 else
6807 vty_out (vty, ", no best path");
6808 if (no_advertise)
6809 vty_out (vty, ", not advertised to any peer");
6810 else if (no_export)
6811 vty_out (vty, ", not advertised to EBGP peer");
6812 else if (local_as)
6813 vty_out (vty, ", not advertised outside local AS");
6814 if (suppress)
6815 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6816 vty_out (vty, ")%s", VTY_NEWLINE);
6817
6818 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006819 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006820 {
6821 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6822 {
6823 if (! first)
6824 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6825 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6826 first = 1;
6827 }
6828 }
6829 if (! first)
6830 vty_out (vty, " Not advertised to any peer");
6831 vty_out (vty, "%s", VTY_NEWLINE);
6832}
6833
6834/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006835static int
paulfee0f4c2004-09-13 05:12:46 +00006836bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006837 struct bgp_table *rib, const char *ip_str,
6838 afi_t afi, safi_t safi, struct prefix_rd *prd,
6839 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006840{
6841 int ret;
6842 int header;
6843 int display = 0;
6844 struct prefix match;
6845 struct bgp_node *rn;
6846 struct bgp_node *rm;
6847 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006848 struct bgp_table *table;
6849
Lou Berger050defe2016-01-12 13:41:59 -05006850 memset (&match, 0, sizeof (struct prefix)); /* keep valgrind happy */
paul718e3742002-12-13 20:15:29 +00006851 /* Check IP address argument. */
6852 ret = str2prefix (ip_str, &match);
6853 if (! ret)
6854 {
6855 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6856 return CMD_WARNING;
6857 }
6858
6859 match.family = afi2family (afi);
6860
Lou Berger298cc2f2016-01-12 13:42:02 -05006861 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00006862 {
paulfee0f4c2004-09-13 05:12:46 +00006863 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006864 {
6865 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6866 continue;
6867
6868 if ((table = rn->info) != NULL)
6869 {
6870 header = 1;
6871
6872 if ((rm = bgp_node_match (table, &match)) != NULL)
6873 {
6874 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006875 {
6876 bgp_unlock_node (rm);
6877 continue;
6878 }
paul718e3742002-12-13 20:15:29 +00006879
6880 for (ri = rm->info; ri; ri = ri->next)
6881 {
6882 if (header)
6883 {
6884 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
Lou Berger298cc2f2016-01-12 13:42:02 -05006885 AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00006886
6887 header = 0;
6888 }
6889 display++;
Lou Berger298cc2f2016-01-12 13:42:02 -05006890 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00006891 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006892
6893 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006894 }
6895 }
6896 }
6897 }
6898 else
6899 {
6900 header = 1;
6901
paulfee0f4c2004-09-13 05:12:46 +00006902 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006903 {
6904 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6905 {
6906 for (ri = rn->info; ri; ri = ri->next)
6907 {
6908 if (header)
6909 {
6910 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6911 header = 0;
6912 }
6913 display++;
6914 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6915 }
6916 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006917
6918 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006919 }
6920 }
6921
6922 if (! display)
6923 {
6924 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6925 return CMD_WARNING;
6926 }
6927
6928 return CMD_SUCCESS;
6929}
6930
paulfee0f4c2004-09-13 05:12:46 +00006931/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006932static int
paulfd79ac92004-10-13 05:06:08 +00006933bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006934 afi_t afi, safi_t safi, struct prefix_rd *prd,
6935 int prefix_check)
6936{
6937 struct bgp *bgp;
6938
6939 /* BGP structure lookup. */
6940 if (view_name)
6941 {
6942 bgp = bgp_lookup_by_name (view_name);
6943 if (bgp == NULL)
6944 {
6945 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6946 return CMD_WARNING;
6947 }
6948 }
6949 else
6950 {
6951 bgp = bgp_get_default ();
6952 if (bgp == NULL)
6953 {
6954 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6955 return CMD_WARNING;
6956 }
6957 }
6958
6959 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6960 afi, safi, prd, prefix_check);
6961}
6962
paul718e3742002-12-13 20:15:29 +00006963/* BGP route print out function. */
Lou Berger35c36862016-01-12 13:42:06 -05006964DEFUN (show_bgp_ipv4_safi,
6965 show_bgp_ipv4_safi_cmd,
6966 "show bgp ipv4 (unicast|multicast)",
paul718e3742002-12-13 20:15:29 +00006967 SHOW_STR
paul718e3742002-12-13 20:15:29 +00006968 BGP_STR
6969 "Address family\n"
6970 "Address Family modifier\n"
6971 "Address Family modifier\n")
6972{
6973 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006974 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6975 NULL);
paul718e3742002-12-13 20:15:29 +00006976
ajs5a646652004-11-05 01:25:55 +00006977 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006978}
6979
Lou Berger35c36862016-01-12 13:42:06 -05006980DEFUN (show_bgp_ipv4_safi_route,
6981 show_bgp_ipv4_safi_route_cmd,
6982 "show bgp ipv4 (unicast|multicast) A.B.C.D",
Michael Lambert95cbbd22010-07-23 14:43:04 -04006983 SHOW_STR
6984 BGP_STR
6985 "Address family\n"
6986 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00006987 "Address Family modifier\n"
6988 "Network in the BGP routing table to display\n")
6989{
6990 if (strncmp (argv[0], "m", 1) == 0)
6991 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6992
6993 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6994}
6995
Lou Berger35c36862016-01-12 13:42:06 -05006996DEFUN (show_bgp_ipv4_vpn_route,
6997 show_bgp_ipv4_vpn_route_cmd,
6998 "show bgp ipv4 vpn A.B.C.D",
Michael Lambert95cbbd22010-07-23 14:43:04 -04006999 SHOW_STR
7000 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007001 "Address Family\n"
7002 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +00007003 "Network in the BGP routing table to display\n")
7004{
7005 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
7006}
7007
Lou Berger35c36862016-01-12 13:42:06 -05007008#ifdef HAVE_IPV6
7009DEFUN (show_bgp_ipv6_vpn_route,
7010 show_bgp_ipv6_vpn_route_cmd,
7011 "show bgp ipv6 vpn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007012 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007013 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007014 "Address Family\n"
7015 "Display VPN NLRI specific information\n"
7016 "Network in the BGP routing table to display\n")
7017{
7018 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MPLS_VPN, NULL, 0);
7019}
7020#endif
7021
7022DEFUN (show_bgp_ipv4_vpn_rd_route,
7023 show_bgp_ipv4_vpn_rd_route_cmd,
7024 "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn A.B.C.D",
7025 SHOW_STR
7026 BGP_STR
7027 IP_STR
7028 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +00007029 "Display information for a route distinguisher\n"
7030 "VPN Route Distinguisher\n"
7031 "Network in the BGP routing table to display\n")
7032{
7033 int ret;
7034 struct prefix_rd prd;
7035
7036 ret = str2prefix_rd (argv[0], &prd);
7037 if (! ret)
7038 {
7039 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7040 return CMD_WARNING;
7041 }
7042 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
7043}
7044
Lou Berger35c36862016-01-12 13:42:06 -05007045DEFUN (show_bgp_ipv6_vpn_rd_route,
7046 show_bgp_ipv6_vpn_rd_route_cmd,
7047 "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007048 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007049 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007050 "Address Family\n"
7051 "Display VPN NLRI specific information\n"
7052 "Display information for a route distinguisher\n"
7053 "VPN Route Distinguisher\n"
7054 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007055{
Lou Berger35c36862016-01-12 13:42:06 -05007056 int ret;
7057 struct prefix_rd prd;
7058
7059 ret = str2prefix_rd (argv[0], &prd);
7060 if (! ret)
7061 {
7062 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7063 return CMD_WARNING;
7064 }
7065 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MPLS_VPN, &prd, 0);
paul718e3742002-12-13 20:15:29 +00007066}
7067
Lou Berger651b4022016-01-12 13:42:07 -05007068DEFUN (show_bgp_ipv4_encap_route,
7069 show_bgp_ipv4_encap_route_cmd,
7070 "show bgp ipv4 encap A.B.C.D",
paul718e3742002-12-13 20:15:29 +00007071 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007072 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007073 IP_STR
7074 "Display ENCAP NLRI specific information\n"
7075 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007076{
Lou Berger651b4022016-01-12 13:42:07 -05007077 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 0);
paul718e3742002-12-13 20:15:29 +00007078}
7079
Lou Berger651b4022016-01-12 13:42:07 -05007080#ifdef HAVE_IPV6
7081DEFUN (show_bgp_ipv6_encap_route,
7082 show_bgp_ipv6_encap_route_cmd,
7083 "show bgp ipv6 encap X:X::X:X",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007084 SHOW_STR
7085 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007086 IP6_STR
7087 "Display ENCAP NLRI specific information\n"
7088 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007089{
Lou Berger651b4022016-01-12 13:42:07 -05007090 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 0);
paul718e3742002-12-13 20:15:29 +00007091}
Lou Berger651b4022016-01-12 13:42:07 -05007092#endif
paul718e3742002-12-13 20:15:29 +00007093
Lou Berger651b4022016-01-12 13:42:07 -05007094DEFUN (show_bgp_ipv4_safi_rd_route,
7095 show_bgp_ipv4_safi_rd_route_cmd,
7096 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D",
paul718e3742002-12-13 20:15:29 +00007097 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007098 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007099 "Address Family\n"
7100 "Address Family Modifier\n"
7101 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00007102 "Display information for a route distinguisher\n"
Lou Berger651b4022016-01-12 13:42:07 -05007103 "ENCAP Route Distinguisher\n"
7104 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007105{
7106 int ret;
7107 struct prefix_rd prd;
Lou Berger651b4022016-01-12 13:42:07 -05007108 safi_t safi;
paul718e3742002-12-13 20:15:29 +00007109
Lou Berger651b4022016-01-12 13:42:07 -05007110 if (bgp_parse_safi(argv[0], &safi)) {
7111 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7112 return CMD_WARNING;
7113 }
7114 ret = str2prefix_rd (argv[1], &prd);
paul718e3742002-12-13 20:15:29 +00007115 if (! ret)
7116 {
7117 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7118 return CMD_WARNING;
7119 }
Lou Berger651b4022016-01-12 13:42:07 -05007120 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 0);
paul718e3742002-12-13 20:15:29 +00007121}
7122
Lou Berger651b4022016-01-12 13:42:07 -05007123#ifdef HAVE_IPV6
7124DEFUN (show_bgp_ipv6_safi_rd_route,
7125 show_bgp_ipv6_safi_rd_route_cmd,
7126 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007127 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007128 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007129 "Address Family\n"
7130 "Address Family Modifier\n"
7131 "Address Family Modifier\n"
7132 "Display information for a route distinguisher\n"
7133 "ENCAP Route Distinguisher\n"
7134 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007135{
Lou Berger651b4022016-01-12 13:42:07 -05007136 int ret;
7137 struct prefix_rd prd;
7138 safi_t safi;
paulbb46e942003-10-24 19:02:03 +00007139
Lou Berger651b4022016-01-12 13:42:07 -05007140 if (bgp_parse_safi(argv[0], &safi)) {
7141 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7142 return CMD_WARNING;
7143 }
7144 ret = str2prefix_rd (argv[1], &prd);
7145 if (! ret)
7146 {
7147 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7148 return CMD_WARNING;
7149 }
7150 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, SAFI_ENCAP, &prd, 0);
paul718e3742002-12-13 20:15:29 +00007151}
Lou Berger651b4022016-01-12 13:42:07 -05007152#endif
paul718e3742002-12-13 20:15:29 +00007153
Lou Berger35c36862016-01-12 13:42:06 -05007154DEFUN (show_bgp_ipv4_prefix,
7155 show_bgp_ipv4_prefix_cmd,
7156 "show bgp ipv4 A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007157 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007158 BGP_STR
paul718e3742002-12-13 20:15:29 +00007159 IP_STR
paul718e3742002-12-13 20:15:29 +00007160 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7161{
Lou Berger35c36862016-01-12 13:42:06 -05007162 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
paul718e3742002-12-13 20:15:29 +00007163}
7164
Lou Berger35c36862016-01-12 13:42:06 -05007165DEFUN (show_bgp_ipv4_safi_prefix,
7166 show_bgp_ipv4_safi_prefix_cmd,
7167 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007168 SHOW_STR
7169 BGP_STR
7170 "Address family\n"
7171 "Address Family modifier\n"
Lou Berger35c36862016-01-12 13:42:06 -05007172 "Address Family modifier\n"
7173 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007174{
7175 if (strncmp (argv[0], "m", 1) == 0)
Lou Berger35c36862016-01-12 13:42:06 -05007176 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007177
Lou Berger35c36862016-01-12 13:42:06 -05007178 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007179}
7180
Lou Berger35c36862016-01-12 13:42:06 -05007181DEFUN (show_bgp_ipv4_vpn_prefix,
7182 show_bgp_ipv4_vpn_prefix_cmd,
7183 "show bgp ipv4 vpn A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007184 SHOW_STR
7185 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007186 IP_STR
7187 "Display VPN NLRI specific information\n"
7188 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paul718e3742002-12-13 20:15:29 +00007189{
Lou Berger35c36862016-01-12 13:42:06 -05007190 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
paul718e3742002-12-13 20:15:29 +00007191}
7192
Lou Berger35c36862016-01-12 13:42:06 -05007193#ifdef HAVE_IPV6
7194DEFUN (show_bgp_ipv6_vpn_prefix,
7195 show_bgp_ipv6_vpn_prefix_cmd,
7196 "show bgp ipv6 vpn X:X::X:X/M",
7197 SHOW_STR
7198 BGP_STR
7199 "Address Family\n"
7200 "Display VPN NLRI specific information\n"
7201 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7202{
7203 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MPLS_VPN, NULL, 1);
7204}
7205#endif
7206
Lou Berger651b4022016-01-12 13:42:07 -05007207DEFUN (show_bgp_ipv4_encap_prefix,
7208 show_bgp_ipv4_encap_prefix_cmd,
7209 "show bgp ipv4 encap A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007210 SHOW_STR
7211 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007212 IP_STR
7213 "Display ENCAP NLRI specific information\n"
7214 "Display information about ENCAP NLRIs\n"
7215 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7216{
7217 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 1);
7218}
paul718e3742002-12-13 20:15:29 +00007219
Lou Berger651b4022016-01-12 13:42:07 -05007220#ifdef HAVE_IPV6
7221DEFUN (show_bgp_ipv6_encap_prefix,
7222 show_bgp_ipv6_encap_prefix_cmd,
7223 "show bgp ipv6 encap X:X::X:X/M",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007224 SHOW_STR
7225 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007226 IP_STR
7227 "Display ENCAP NLRI specific information\n"
7228 "Display information about ENCAP NLRIs\n"
7229 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7230{
7231 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 1);
7232}
7233#endif
7234
7235DEFUN (show_bgp_ipv4_safi_rd_prefix,
7236 show_bgp_ipv4_safi_rd_prefix_cmd,
7237 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7238 SHOW_STR
7239 BGP_STR
7240 "Address Family\n"
7241 "Address Family Modifier\n"
7242 "Address Family Modifier\n"
7243 "Display information for a route distinguisher\n"
7244 "ENCAP Route Distinguisher\n"
7245 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7246{
7247 int ret;
7248 struct prefix_rd prd;
7249 safi_t safi;
7250
7251 if (bgp_parse_safi(argv[0], &safi)) {
7252 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7253 return CMD_WARNING;
7254 }
7255
7256 ret = str2prefix_rd (argv[1], &prd);
7257 if (! ret)
7258 {
7259 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7260 return CMD_WARNING;
7261 }
7262 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 1);
7263}
7264
7265#ifdef HAVE_IPV6
7266DEFUN (show_bgp_ipv6_safi_rd_prefix,
7267 show_bgp_ipv6_safi_rd_prefix_cmd,
7268 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X/M",
7269 SHOW_STR
7270 BGP_STR
7271 "Address Family\n"
7272 "Address Family Modifier\n"
7273 "Address Family Modifier\n"
7274 "Display information for a route distinguisher\n"
7275 "ENCAP Route Distinguisher\n"
7276 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7277{
7278 int ret;
7279 struct prefix_rd prd;
7280 safi_t safi;
7281
7282 if (bgp_parse_safi(argv[0], &safi)) {
7283 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7284 return CMD_WARNING;
7285 }
7286
7287 ret = str2prefix_rd (argv[1], &prd);
7288 if (! ret)
7289 {
7290 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7291 return CMD_WARNING;
7292 }
7293 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, safi, &prd, 1);
7294}
7295#endif
7296
7297DEFUN (show_bgp_afi_safi_view,
7298 show_bgp_afi_safi_view_cmd,
7299 "show bgp view WORD (ipv4|ipv6) (encap|mulicast|unicast|vpn)",
7300 SHOW_STR
7301 BGP_STR
7302 "BGP view\n"
7303 "BGP view name\n"
7304 "Address Family\n"
7305 "Address Family\n"
7306 "Address Family Modifier\n"
7307 "Address Family Modifier\n"
7308 "Address Family Modifier\n"
7309 "Address Family Modifier\n"
7310 )
7311{
7312 struct bgp *bgp;
7313 safi_t safi;
7314 afi_t afi;
7315
7316 if (bgp_parse_afi(argv[1], &afi)) {
7317 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7318 return CMD_WARNING;
7319 }
7320 if (bgp_parse_safi(argv[2], &safi)) {
7321 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7322 return CMD_WARNING;
7323 }
7324
7325 /* BGP structure lookup. */
7326 bgp = bgp_lookup_by_name (argv[0]);
7327 if (bgp == NULL)
7328 {
7329 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7330 return CMD_WARNING;
7331 }
7332
7333 return bgp_show (vty, bgp, afi, safi, bgp_show_type_normal, NULL);
7334}
7335
7336DEFUN (show_bgp_view_afi_safi_route,
7337 show_bgp_view_afi_safi_route_cmd,
7338 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) A.B.C.D",
7339 SHOW_STR
7340 BGP_STR
7341 "BGP view\n"
7342 "View name\n"
7343 "Address Family\n"
7344 "Address Family\n"
7345 "Address Family Modifier\n"
7346 "Address Family Modifier\n"
7347 "Address Family Modifier\n"
7348 "Address Family Modifier\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007349 "Network in the BGP routing table to display\n")
7350{
Lou Berger651b4022016-01-12 13:42:07 -05007351 safi_t safi;
7352 afi_t afi;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007353
Lou Berger651b4022016-01-12 13:42:07 -05007354 if (bgp_parse_afi(argv[1], &afi)) {
7355 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7356 return CMD_WARNING;
7357 }
7358 if (bgp_parse_safi(argv[2], &safi)) {
7359 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7360 return CMD_WARNING;
7361 }
7362 return bgp_show_route (vty, argv[0], argv[3], afi, safi, NULL, 0);
7363}
7364
7365DEFUN (show_bgp_view_afi_safi_prefix,
7366 show_bgp_view_afi_safi_prefix_cmd,
7367 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) A.B.C.D/M",
7368 SHOW_STR
7369 BGP_STR
7370 "BGP view\n"
7371 "View name\n"
7372 "Address Family\n"
7373 "Address Family\n"
7374 "Address Family Modifier\n"
7375 "Address Family Modifier\n"
7376 "Address Family Modifier\n"
7377 "Address Family Modifier\n"
7378 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7379{
7380 safi_t safi;
7381 afi_t afi;
7382
7383 if (bgp_parse_afi(argv[1], &afi)) {
7384 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7385 return CMD_WARNING;
7386 }
7387 if (bgp_parse_safi(argv[2], &safi)) {
7388 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7389 return CMD_WARNING;
7390 }
7391 return bgp_show_route (vty, argv[0], argv[3], afi, safi, NULL, 1);
7392}
7393
7394/* new001 */
7395DEFUN (show_bgp_afi,
7396 show_bgp_afi_cmd,
7397 "show bgp (ipv4|ipv6)",
7398 SHOW_STR
7399 BGP_STR
7400 "Address family\n"
7401 "Address family\n")
7402{
7403 afi_t afi;
7404
7405 if (bgp_parse_afi(argv[0], &afi)) {
7406 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7407 return CMD_WARNING;
7408 }
7409 return bgp_show (vty, NULL, afi, SAFI_UNICAST, bgp_show_type_normal,
7410 NULL);
7411}
7412
7413#ifdef HAVE_IPV6
7414DEFUN (show_bgp_ipv6_safi,
7415 show_bgp_ipv6_safi_cmd,
7416 "show bgp ipv6 (unicast|multicast)",
7417 SHOW_STR
7418 BGP_STR
7419 "Address family\n"
7420 "Address Family modifier\n"
7421 "Address Family modifier\n")
7422{
7423 if (strncmp (argv[0], "m", 1) == 0)
7424 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7425 NULL);
7426
7427 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007428}
7429
Lou Berger35c36862016-01-12 13:42:06 -05007430DEFUN (show_bgp_ipv6_route,
7431 show_bgp_ipv6_route_cmd,
7432 "show bgp ipv6 X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007433 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007434 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007435 "Address family\n"
paul718e3742002-12-13 20:15:29 +00007436 "Network in the BGP routing table to display\n")
7437{
7438 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7439}
7440
Lou Berger35c36862016-01-12 13:42:06 -05007441DEFUN (show_bgp_ipv6_safi_route,
7442 show_bgp_ipv6_safi_route_cmd,
7443 "show bgp ipv6 (unicast|multicast) X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007444 SHOW_STR
7445 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007446 "Address family\n"
7447 "Address Family modifier\n"
7448 "Address Family modifier\n"
7449 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007450{
Lou Berger35c36862016-01-12 13:42:06 -05007451 if (strncmp (argv[0], "m", 1) == 0)
7452 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7453
7454 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
paul718e3742002-12-13 20:15:29 +00007455}
7456
Lou Berger35c36862016-01-12 13:42:06 -05007457/* new002 */
7458DEFUN (show_bgp_ipv6_prefix,
paul718e3742002-12-13 20:15:29 +00007459 show_bgp_ipv6_prefix_cmd,
7460 "show bgp ipv6 X:X::X:X/M",
7461 SHOW_STR
7462 BGP_STR
7463 "Address family\n"
Lou Berger35c36862016-01-12 13:42:06 -05007464 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7465{
7466 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7467}
Michael Lambert95cbbd22010-07-23 14:43:04 -04007468DEFUN (show_bgp_ipv6_safi_prefix,
7469 show_bgp_ipv6_safi_prefix_cmd,
7470 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
7471 SHOW_STR
7472 BGP_STR
7473 "Address family\n"
7474 "Address Family modifier\n"
7475 "Address Family modifier\n"
7476 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7477{
7478 if (strncmp (argv[0], "m", 1) == 0)
7479 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7480
7481 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7482}
7483
paulbb46e942003-10-24 19:02:03 +00007484DEFUN (show_bgp_view,
Lou Berger35c36862016-01-12 13:42:06 -05007485 show_bgp_view_ipv6_cmd,
7486 "show bgp view WORD ipv6",
paulbb46e942003-10-24 19:02:03 +00007487 SHOW_STR
Lou Berger35c36862016-01-12 13:42:06 -05007488 BGP_STR
paulbb46e942003-10-24 19:02:03 +00007489 "BGP view\n"
Lou Berger35c36862016-01-12 13:42:06 -05007490 "View name\n"
7491 "Address family\n")
paulbb46e942003-10-24 19:02:03 +00007492{
7493 struct bgp *bgp;
7494
7495 /* BGP structure lookup. */
7496 bgp = bgp_lookup_by_name (argv[0]);
7497 if (bgp == NULL)
7498 {
7499 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7500 return CMD_WARNING;
7501 }
7502
ajs5a646652004-11-05 01:25:55 +00007503 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007504}
paulbb46e942003-10-24 19:02:03 +00007505
7506DEFUN (show_bgp_view_route,
paulbb46e942003-10-24 19:02:03 +00007507 show_bgp_view_ipv6_route_cmd,
7508 "show bgp view WORD ipv6 X:X::X:X",
7509 SHOW_STR
7510 BGP_STR
7511 "BGP view\n"
7512 "View name\n"
7513 "Address family\n"
7514 "Network in the BGP routing table to display\n")
paulbb46e942003-10-24 19:02:03 +00007515{
Lou Berger35c36862016-01-12 13:42:06 -05007516 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
paulbb46e942003-10-24 19:02:03 +00007517}
7518
Lou Berger35c36862016-01-12 13:42:06 -05007519DEFUN (show_bgp_view_prefix,
paulbb46e942003-10-24 19:02:03 +00007520 show_bgp_view_ipv6_prefix_cmd,
7521 "show bgp view WORD ipv6 X:X::X:X/M",
7522 SHOW_STR
7523 BGP_STR
7524 "BGP view\n"
7525 "View name\n"
7526 "Address family\n"
7527 "IPv6 prefix <network>/<length>\n")
paul718e3742002-12-13 20:15:29 +00007528{
Lou Berger35c36862016-01-12 13:42:06 -05007529 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
paul718e3742002-12-13 20:15:29 +00007530}
7531
paul718e3742002-12-13 20:15:29 +00007532#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02007533
paul718e3742002-12-13 20:15:29 +00007534
paul94f2b392005-06-28 12:44:16 +00007535static int
paulfd79ac92004-10-13 05:06:08 +00007536bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007537 safi_t safi, enum bgp_show_type type)
7538{
7539 int i;
7540 struct buffer *b;
7541 char *regstr;
7542 int first;
7543 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007544 int rc;
paul718e3742002-12-13 20:15:29 +00007545
7546 first = 0;
7547 b = buffer_new (1024);
7548 for (i = 0; i < argc; i++)
7549 {
7550 if (first)
7551 buffer_putc (b, ' ');
7552 else
7553 {
7554 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7555 continue;
7556 first = 1;
7557 }
7558
7559 buffer_putstr (b, argv[i]);
7560 }
7561 buffer_putc (b, '\0');
7562
7563 regstr = buffer_getstr (b);
7564 buffer_free (b);
7565
7566 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007567 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007568 if (! regex)
7569 {
7570 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7571 VTY_NEWLINE);
7572 return CMD_WARNING;
7573 }
7574
ajs5a646652004-11-05 01:25:55 +00007575 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7576 bgp_regex_free (regex);
7577 return rc;
paul718e3742002-12-13 20:15:29 +00007578}
7579
Lou Berger651b4022016-01-12 13:42:07 -05007580DEFUN (show_bgp_ipv4_safi_flap_regexp,
7581 show_bgp_ipv4_safi_flap_regexp_cmd,
7582 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics regexp .LINE",
paul718e3742002-12-13 20:15:29 +00007583 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007584 BGP_STR
paul718e3742002-12-13 20:15:29 +00007585 IP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007586 "Address Family Modifier\n"
7587 "Address Family Modifier\n"
7588 "Address Family Modifier\n"
7589 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00007590 "Display flap statistics of routes\n"
7591 "Display routes matching the AS path regular expression\n"
7592 "A regular-expression to match the BGP AS paths\n")
7593{
Lou Berger651b4022016-01-12 13:42:07 -05007594 safi_t safi;
7595
7596 if (bgp_parse_safi(argv[0], &safi)) {
7597 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7598 return CMD_WARNING;
7599 }
7600 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP, safi,
7601 bgp_show_type_flap_regexp);
paul718e3742002-12-13 20:15:29 +00007602}
7603
Lou Berger651b4022016-01-12 13:42:07 -05007604ALIAS (show_bgp_ipv4_safi_flap_regexp,
7605 show_bgp_ipv4_safi_damp_flap_regexp_cmd,
7606 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics regexp .LINE",
Balaji3921cc52015-05-16 23:12:17 +05307607 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05307608 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007609 IP_STR
7610 "Address Family Modifier\n"
7611 "Address Family Modifier\n"
7612 "Address Family Modifier\n"
7613 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05307614 "Display detailed information about dampening\n"
7615 "Display flap statistics of routes\n"
7616 "Display routes matching the AS path regular expression\n"
7617 "A regular-expression to match the BGP AS paths\n")
7618
Lou Berger651b4022016-01-12 13:42:07 -05007619#ifdef HAVE_IPV6
7620DEFUN (show_bgp_ipv6_safi_flap_regexp,
7621 show_bgp_ipv6_safi_flap_regexp_cmd,
7622 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics regexp .LINE",
paul718e3742002-12-13 20:15:29 +00007623 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05007624 BGP_STR
7625 IPV6_STR
7626 "Address Family Modifier\n"
7627 "Address Family Modifier\n"
7628 "Address Family Modifier\n"
7629 "Address Family Modifier\n"
7630 "Display flap statistics of routes\n"
7631 "Display routes matching the AS path regular expression\n"
7632 "A regular-expression to match the BGP AS paths\n")
7633{
7634 safi_t safi;
7635
7636 if (bgp_parse_safi(argv[0], &safi)) {
7637 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7638 return CMD_WARNING;
7639 }
7640 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP6, safi,
7641 bgp_show_type_flap_regexp);
7642}
7643
7644ALIAS (show_bgp_ipv6_safi_flap_regexp,
7645 show_bgp_ipv6_safi_damp_flap_regexp_cmd,
7646 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics regexp .LINE",
7647 SHOW_STR
7648 BGP_STR
7649 IPV6_STR
7650 "Address Family Modifier\n"
7651 "Address Family Modifier\n"
7652 "Address Family Modifier\n"
7653 "Address Family Modifier\n"
7654 "Display detailed information about dampening\n"
7655 "Display flap statistics of routes\n"
7656 "Display routes matching the AS path regular expression\n"
7657 "A regular-expression to match the BGP AS paths\n")
7658#endif
7659
7660DEFUN (show_bgp_ipv4_safi_regexp,
7661 show_bgp_ipv4_safi_regexp_cmd,
7662 "show bgp ipv4 (encap|multicast|unicast|vpn) regexp .LINE",
7663 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007664 BGP_STR
7665 "Address family\n"
7666 "Address Family modifier\n"
7667 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05007668 "Address Family modifier\n"
7669 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00007670 "Display routes matching the AS path regular expression\n"
7671 "A regular-expression to match the BGP AS paths\n")
7672{
Lou Berger651b4022016-01-12 13:42:07 -05007673 safi_t safi;
7674 if (bgp_parse_safi(argv[0], &safi)) {
7675 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7676 return CMD_WARNING;
7677 }
paul718e3742002-12-13 20:15:29 +00007678
Lou Berger651b4022016-01-12 13:42:07 -05007679 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00007680 bgp_show_type_regexp);
7681}
paul718e3742002-12-13 20:15:29 +00007682#ifdef HAVE_IPV6
Lou Berger651b4022016-01-12 13:42:07 -05007683DEFUN (show_bgp_ipv6_safi_regexp,
7684 show_bgp_ipv6_safi_regexp_cmd,
7685 "show bgp ipv6 (encap|multicast|unicast|vpn) regexp .LINE",
paul718e3742002-12-13 20:15:29 +00007686 SHOW_STR
7687 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007688 "Address family\n"
7689 "Address Family modifier\n"
7690 "Address Family modifier\n"
7691 "Address Family modifier\n"
7692 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00007693 "Display routes matching the AS path regular expression\n"
7694 "A regular-expression to match the BGP AS paths\n")
7695{
Lou Berger651b4022016-01-12 13:42:07 -05007696 safi_t safi;
7697 if (bgp_parse_safi(argv[0], &safi)) {
7698 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7699 return CMD_WARNING;
7700 }
7701
7702 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00007703 bgp_show_type_regexp);
7704}
7705
Lou Berger651b4022016-01-12 13:42:07 -05007706DEFUN (show_bgp_ipv6_regexp,
paul718e3742002-12-13 20:15:29 +00007707 show_bgp_ipv6_regexp_cmd,
7708 "show bgp ipv6 regexp .LINE",
7709 SHOW_STR
7710 BGP_STR
7711 "Address family\n"
7712 "Display routes matching the AS path regular expression\n"
7713 "A regular-expression to match the BGP AS paths\n")
paul718e3742002-12-13 20:15:29 +00007714{
7715 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7716 bgp_show_type_regexp);
7717}
7718
paul718e3742002-12-13 20:15:29 +00007719#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007720
paul94f2b392005-06-28 12:44:16 +00007721static int
paulfd79ac92004-10-13 05:06:08 +00007722bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007723 safi_t safi, enum bgp_show_type type)
7724{
7725 struct prefix_list *plist;
7726
7727 plist = prefix_list_lookup (afi, prefix_list_str);
7728 if (plist == NULL)
7729 {
7730 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7731 prefix_list_str, VTY_NEWLINE);
7732 return CMD_WARNING;
7733 }
7734
ajs5a646652004-11-05 01:25:55 +00007735 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007736}
7737
Lou Berger35c36862016-01-12 13:42:06 -05007738DEFUN (show_bgp_ipv4_prefix_list,
7739 show_bgp_ipv4_prefix_list_cmd,
7740 "show bgp ipv4 prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00007741 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007742 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007743 IP_STR
paul718e3742002-12-13 20:15:29 +00007744 "Display routes conforming to the prefix-list\n"
7745 "IP prefix-list name\n")
7746{
7747 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7748 bgp_show_type_prefix_list);
7749}
7750
Lou Berger651b4022016-01-12 13:42:07 -05007751DEFUN (show_bgp_ipv4_safi_flap_prefix_list,
7752 show_bgp_ipv4_safi_flap_prefix_list_cmd,
7753 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00007754 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007755 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007756 IP_STR
7757 "Address Family Modifier\n"
7758 "Address Family Modifier\n"
7759 "Address Family Modifier\n"
7760 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00007761 "Display flap statistics of routes\n"
7762 "Display routes conforming to the prefix-list\n"
7763 "IP prefix-list name\n")
7764{
Lou Berger651b4022016-01-12 13:42:07 -05007765 safi_t safi;
7766 if (bgp_parse_safi(argv[0], &safi)) {
7767 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7768 return CMD_WARNING;
7769 }
7770 return bgp_show_prefix_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00007771 bgp_show_type_flap_prefix_list);
7772}
7773
Lou Berger651b4022016-01-12 13:42:07 -05007774ALIAS (show_bgp_ipv4_safi_flap_prefix_list,
7775 show_bgp_ipv4_safi_damp_flap_prefix_list_cmd,
7776 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics prefix-list WORD",
Balaji3921cc52015-05-16 23:12:17 +05307777 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05307778 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007779 IP_STR
7780 "Address Family Modifier\n"
7781 "Address Family Modifier\n"
7782 "Address Family Modifier\n"
7783 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05307784 "Display detailed information about dampening\n"
7785 "Display flap statistics of routes\n"
7786 "Display routes conforming to the prefix-list\n"
7787 "IP prefix-list name\n")
7788
Lou Berger651b4022016-01-12 13:42:07 -05007789#ifdef HAVE_IPV6
7790DEFUN (show_bgp_ipv6_safi_flap_prefix_list,
7791 show_bgp_ipv6_safi_flap_prefix_list_cmd,
7792 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00007793 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05007794 BGP_STR
7795 IPV6_STR
7796 "Address Family Modifier\n"
7797 "Address Family Modifier\n"
7798 "Address Family Modifier\n"
7799 "Address Family Modifier\n"
7800 "Display flap statistics of routes\n"
7801 "Display routes conforming to the prefix-list\n"
7802 "IP prefix-list name\n")
7803{
7804 safi_t safi;
7805 if (bgp_parse_safi(argv[0], &safi)) {
7806 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7807 return CMD_WARNING;
7808 }
7809 return bgp_show_prefix_list (vty, argv[1], AFI_IP6, safi,
7810 bgp_show_type_flap_prefix_list);
7811}
7812ALIAS (show_bgp_ipv6_safi_flap_prefix_list,
7813 show_bgp_ipv6_safi_damp_flap_prefix_list_cmd,
7814 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics prefix-list WORD",
7815 SHOW_STR
7816 BGP_STR
7817 IPV6_STR
7818 "Address Family Modifier\n"
7819 "Address Family Modifier\n"
7820 "Address Family Modifier\n"
7821 "Address Family Modifier\n"
7822 "Display detailed information about dampening\n"
7823 "Display flap statistics of routes\n"
7824 "Display routes conforming to the prefix-list\n"
7825 "IP prefix-list name\n")
7826#endif
7827
7828DEFUN (show_bgp_ipv4_safi_prefix_list,
7829 show_bgp_ipv4_safi_prefix_list_cmd,
7830 "show bgp ipv4 (encap|multicast|unicast|vpn) prefix-list WORD",
7831 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007832 BGP_STR
7833 "Address family\n"
7834 "Address Family modifier\n"
7835 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05007836 "Address Family modifier\n"
7837 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00007838 "Display routes conforming to the prefix-list\n"
7839 "IP prefix-list name\n")
7840{
Lou Berger651b4022016-01-12 13:42:07 -05007841 safi_t safi;
7842 if (bgp_parse_safi(argv[0], &safi)) {
7843 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7844 return CMD_WARNING;
7845 }
7846 return bgp_show_prefix_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00007847 bgp_show_type_prefix_list);
7848}
paul718e3742002-12-13 20:15:29 +00007849#ifdef HAVE_IPV6
Lou Berger651b4022016-01-12 13:42:07 -05007850DEFUN (show_bgp_ipv6_safi_prefix_list,
7851 show_bgp_ipv6_safi_prefix_list_cmd,
7852 "show bgp ipv6 (encap|multicast|unicast|vpn) prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00007853 SHOW_STR
7854 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007855 "Address family\n"
7856 "Address Family modifier\n"
7857 "Address Family modifier\n"
7858 "Address Family modifier\n"
7859 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00007860 "Display routes conforming to the prefix-list\n"
Lou Berger651b4022016-01-12 13:42:07 -05007861 "IP prefix-list name\n")
paul718e3742002-12-13 20:15:29 +00007862{
Lou Berger651b4022016-01-12 13:42:07 -05007863 safi_t safi;
7864 if (bgp_parse_safi(argv[0], &safi)) {
7865 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7866 return CMD_WARNING;
7867 }
7868 return bgp_show_prefix_list (vty, argv[1], AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00007869 bgp_show_type_prefix_list);
7870}
7871
Lou Berger651b4022016-01-12 13:42:07 -05007872DEFUN (show_bgp_prefix_list,
paul718e3742002-12-13 20:15:29 +00007873 show_bgp_ipv6_prefix_list_cmd,
7874 "show bgp ipv6 prefix-list WORD",
7875 SHOW_STR
7876 BGP_STR
7877 "Address family\n"
7878 "Display routes conforming to the prefix-list\n"
7879 "IPv6 prefix-list name\n")
paul718e3742002-12-13 20:15:29 +00007880{
7881 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7882 bgp_show_type_prefix_list);
7883}
7884
paul718e3742002-12-13 20:15:29 +00007885#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007886
paul94f2b392005-06-28 12:44:16 +00007887static int
paulfd79ac92004-10-13 05:06:08 +00007888bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007889 safi_t safi, enum bgp_show_type type)
7890{
7891 struct as_list *as_list;
7892
7893 as_list = as_list_lookup (filter);
7894 if (as_list == NULL)
7895 {
7896 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7897 return CMD_WARNING;
7898 }
7899
ajs5a646652004-11-05 01:25:55 +00007900 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007901}
7902
Lou Berger651b4022016-01-12 13:42:07 -05007903DEFUN (show_bgp_ipv4_filter_list,
7904 show_bgp_ipv4_filter_list_cmd,
7905 "show bgp ipv4 filter-list WORD",
paul718e3742002-12-13 20:15:29 +00007906 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007907 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007908 IP_STR
paul718e3742002-12-13 20:15:29 +00007909 "Display routes conforming to the filter-list\n"
7910 "Regular expression access list name\n")
7911{
7912 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7913 bgp_show_type_filter_list);
7914}
7915
Lou Berger651b4022016-01-12 13:42:07 -05007916DEFUN (show_bgp_ipv4_safi_flap_filter_list,
7917 show_bgp_ipv4_safi_flap_filter_list_cmd,
7918 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics filter-list WORD",
paul718e3742002-12-13 20:15:29 +00007919 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007920 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007921 IP_STR
7922 "Address Family modifier\n"
7923 "Address Family modifier\n"
7924 "Address Family modifier\n"
7925 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00007926 "Display flap statistics of routes\n"
7927 "Display routes conforming to the filter-list\n"
7928 "Regular expression access list name\n")
7929{
Lou Berger651b4022016-01-12 13:42:07 -05007930 safi_t safi;
7931
7932 if (bgp_parse_safi(argv[0], &safi)) {
7933 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7934 return CMD_WARNING;
7935 }
7936 return bgp_show_filter_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00007937 bgp_show_type_flap_filter_list);
7938}
7939
Lou Berger651b4022016-01-12 13:42:07 -05007940ALIAS (show_bgp_ipv4_safi_flap_filter_list,
7941 show_bgp_ipv4_safi_damp_flap_filter_list_cmd,
7942 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics filter-list WORD",
Balaji3921cc52015-05-16 23:12:17 +05307943 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05307944 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007945 IP_STR
7946 "Address Family modifier\n"
7947 "Address Family modifier\n"
7948 "Address Family modifier\n"
7949 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05307950 "Display detailed information about dampening\n"
7951 "Display flap statistics of routes\n"
7952 "Display routes conforming to the filter-list\n"
7953 "Regular expression access list name\n")
7954
paul718e3742002-12-13 20:15:29 +00007955#ifdef HAVE_IPV6
Lou Berger651b4022016-01-12 13:42:07 -05007956DEFUN (show_bgp_ipv6_safi_flap_filter_list,
7957 show_bgp_ipv6_safi_flap_filter_list_cmd,
7958 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics filter-list WORD",
paul718e3742002-12-13 20:15:29 +00007959 SHOW_STR
7960 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007961 IPV6_STR
7962 "Address Family modifier\n"
7963 "Address Family modifier\n"
7964 "Address Family modifier\n"
7965 "Address Family modifier\n"
7966 "Display flap statistics of routes\n"
paul718e3742002-12-13 20:15:29 +00007967 "Display routes conforming to the filter-list\n"
7968 "Regular expression access list name\n")
7969{
Lou Berger651b4022016-01-12 13:42:07 -05007970 safi_t safi;
7971
7972 if (bgp_parse_safi(argv[0], &safi)) {
7973 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7974 return CMD_WARNING;
7975 }
7976 return bgp_show_filter_list (vty, argv[1], AFI_IP6, safi,
7977 bgp_show_type_flap_filter_list);
7978}
7979ALIAS (show_bgp_ipv6_safi_flap_filter_list,
7980 show_bgp_ipv6_safi_damp_flap_filter_list_cmd,
7981 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics filter-list WORD",
7982 SHOW_STR
7983 BGP_STR
7984 IPV6_STR
7985 "Address Family modifier\n"
7986 "Address Family modifier\n"
7987 "Address Family modifier\n"
7988 "Address Family modifier\n"
7989 "Display detailed information about dampening\n"
7990 "Display flap statistics of routes\n"
7991 "Display routes conforming to the filter-list\n"
7992 "Regular expression access list name\n")
7993#endif
7994
7995DEFUN (show_bgp_ipv4_safi_filter_list,
7996 show_bgp_ipv4_safi_filter_list_cmd,
7997 "show bgp ipv4 (encap|multicast|unicast|vpn) filter-list WORD",
7998 SHOW_STR
7999 BGP_STR
8000 "Address Family modifier\n"
8001 "Address Family modifier\n"
8002 "Address Family modifier\n"
8003 "Address Family modifier\n"
8004 "Display routes conforming to the filter-list\n"
8005 "Regular expression access list name\n")
8006{
8007 safi_t safi;
8008
8009 if (bgp_parse_safi(argv[0], &safi)) {
8010 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8011 return CMD_WARNING;
8012 }
8013 return bgp_show_filter_list (vty, argv[1], AFI_IP, safi,
8014 bgp_show_type_filter_list);
8015}
8016#ifdef HAVE_IPV6
8017DEFUN (show_bgp_ipv6_safi_filter_list,
8018 show_bgp_ipv6_safi_filter_list_cmd,
8019 "show bgp ipv6 (encap|multicast|unicast|vpn) filter-list WORD",
8020 SHOW_STR
8021 BGP_STR
8022 "Address Family modifier\n"
8023 "Address Family modifier\n"
8024 "Address Family modifier\n"
8025 "Address Family modifier\n"
8026 "Display routes conforming to the filter-list\n"
8027 "Regular expression access list name\n")
8028{
8029 safi_t safi;
8030
8031 if (bgp_parse_safi(argv[0], &safi)) {
8032 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8033 return CMD_WARNING;
8034 }
8035 return bgp_show_filter_list (vty, argv[1], AFI_IP6, safi,
8036 bgp_show_type_filter_list);
paul718e3742002-12-13 20:15:29 +00008037}
8038
Lou Berger651b4022016-01-12 13:42:07 -05008039DEFUN (show_bgp_filter_list,
paul718e3742002-12-13 20:15:29 +00008040 show_bgp_ipv6_filter_list_cmd,
8041 "show bgp ipv6 filter-list WORD",
8042 SHOW_STR
8043 BGP_STR
8044 "Address family\n"
8045 "Display routes conforming to the filter-list\n"
8046 "Regular expression access list name\n")
paul718e3742002-12-13 20:15:29 +00008047{
8048 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8049 bgp_show_type_filter_list);
8050}
8051
paul718e3742002-12-13 20:15:29 +00008052#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02008053
Balaji3921cc52015-05-16 23:12:17 +05308054DEFUN (show_ip_bgp_dampening_info,
8055 show_ip_bgp_dampening_params_cmd,
8056 "show ip bgp dampening parameters",
8057 SHOW_STR
8058 IP_STR
8059 BGP_STR
8060 "Display detailed information about dampening\n"
8061 "Display detail of configured dampening parameters\n")
8062{
8063 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
8064}
8065
paul94f2b392005-06-28 12:44:16 +00008066static int
paulfd79ac92004-10-13 05:06:08 +00008067bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008068 safi_t safi, enum bgp_show_type type)
8069{
8070 struct route_map *rmap;
8071
8072 rmap = route_map_lookup_by_name (rmap_str);
8073 if (! rmap)
8074 {
8075 vty_out (vty, "%% %s is not a valid route-map name%s",
8076 rmap_str, VTY_NEWLINE);
8077 return CMD_WARNING;
8078 }
8079
ajs5a646652004-11-05 01:25:55 +00008080 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00008081}
8082
Lou Berger651b4022016-01-12 13:42:07 -05008083DEFUN (show_bgp_ipv4_route_map,
8084 show_bgp_ipv4_route_map_cmd,
8085 "show bgp ipv4 route-map WORD",
paul718e3742002-12-13 20:15:29 +00008086 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008087 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008088 IP_STR
paul718e3742002-12-13 20:15:29 +00008089 "Display routes matching the route-map\n"
8090 "A route-map to match on\n")
8091{
8092 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8093 bgp_show_type_route_map);
8094}
8095
Lou Berger651b4022016-01-12 13:42:07 -05008096DEFUN (show_bgp_ipv4_safi_flap_route_map,
8097 show_bgp_ipv4_safi_flap_route_map_cmd,
8098 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics route-map WORD",
paul718e3742002-12-13 20:15:29 +00008099 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008100 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008101 IP_STR
8102 "Address Family Modifier\n"
8103 "Address Family Modifier\n"
8104 "Address Family Modifier\n"
8105 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00008106 "Display flap statistics of routes\n"
8107 "Display routes matching the route-map\n"
8108 "A route-map to match on\n")
8109{
Lou Berger651b4022016-01-12 13:42:07 -05008110 safi_t safi;
8111 if (bgp_parse_safi(argv[0], &safi)) {
8112 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8113 return CMD_WARNING;
8114 }
8115 return bgp_show_route_map (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008116 bgp_show_type_flap_route_map);
8117}
8118
Lou Berger651b4022016-01-12 13:42:07 -05008119ALIAS (show_bgp_ipv4_safi_flap_route_map,
8120 show_bgp_ipv4_safi_damp_flap_route_map_cmd,
8121 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics route-map WORD",
Balaji3921cc52015-05-16 23:12:17 +05308122 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308123 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008124 IP_STR
8125 "Address Family Modifier\n"
8126 "Address Family Modifier\n"
8127 "Address Family Modifier\n"
8128 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308129 "Display detailed information about dampening\n"
8130 "Display flap statistics of routes\n"
8131 "Display routes matching the route-map\n"
8132 "A route-map to match on\n")
Lou Berger651b4022016-01-12 13:42:07 -05008133#ifdef HAVE_IPV6
8134DEFUN (show_bgp_ipv6_safi_flap_route_map,
8135 show_bgp_ipv6_safi_flap_route_map_cmd,
8136 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics route-map WORD",
paul718e3742002-12-13 20:15:29 +00008137 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05008138 BGP_STR
8139 IPV6_STR
8140 "Address Family Modifier\n"
8141 "Address Family Modifier\n"
8142 "Address Family Modifier\n"
8143 "Address Family Modifier\n"
8144 "Display flap statistics of routes\n"
8145 "Display routes matching the route-map\n"
8146 "A route-map to match on\n")
8147{
8148 safi_t safi;
8149 if (bgp_parse_safi(argv[0], &safi)) {
8150 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8151 return CMD_WARNING;
8152 }
8153 return bgp_show_route_map (vty, argv[1], AFI_IP6, safi,
8154 bgp_show_type_flap_route_map);
8155}
8156ALIAS (show_bgp_ipv6_safi_flap_route_map,
8157 show_bgp_ipv6_safi_damp_flap_route_map_cmd,
8158 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics route-map WORD",
8159 SHOW_STR
8160 BGP_STR
8161 IPV6_STR
8162 "Address Family Modifier\n"
8163 "Address Family Modifier\n"
8164 "Address Family Modifier\n"
8165 "Address Family Modifier\n"
8166 "Display detailed information about dampening\n"
8167 "Display flap statistics of routes\n"
8168 "Display routes matching the route-map\n"
8169 "A route-map to match on\n")
8170#endif
8171
8172DEFUN (show_bgp_ipv4_safi_route_map,
8173 show_bgp_ipv4_safi_route_map_cmd,
8174 "show bgp ipv4 (encap|multicast|unicast|vpn) route-map WORD",
8175 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008176 BGP_STR
8177 "Address family\n"
8178 "Address Family modifier\n"
8179 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05008180 "Address Family modifier\n"
8181 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008182 "Display routes matching the route-map\n"
8183 "A route-map to match on\n")
8184{
Lou Berger651b4022016-01-12 13:42:07 -05008185 safi_t safi;
8186 if (bgp_parse_safi(argv[0], &safi)) {
8187 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8188 return CMD_WARNING;
8189 }
8190 return bgp_show_route_map (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008191 bgp_show_type_route_map);
8192}
Lou Berger651b4022016-01-12 13:42:07 -05008193#ifdef HAVE_IPV6
8194DEFUN (show_bgp_ipv6_safi_route_map,
8195 show_bgp_ipv6_safi_route_map_cmd,
8196 "show bgp ipv6 (encap|multicast|unicast|vpn) route-map WORD",
paul718e3742002-12-13 20:15:29 +00008197 SHOW_STR
8198 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008199 "Address family\n"
8200 "Address Family modifier\n"
8201 "Address Family modifier\n"
8202 "Address Family modifier\n"
8203 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008204 "Display routes matching the route-map\n"
8205 "A route-map to match on\n")
8206{
Lou Berger651b4022016-01-12 13:42:07 -05008207 safi_t safi;
8208 if (bgp_parse_safi(argv[0], &safi)) {
8209 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8210 return CMD_WARNING;
8211 }
8212 return bgp_show_route_map (vty, argv[1], AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00008213 bgp_show_type_route_map);
8214}
8215
Lou Berger651b4022016-01-12 13:42:07 -05008216DEFUN (show_bgp_ipv6_route_map,
paul718e3742002-12-13 20:15:29 +00008217 show_bgp_ipv6_route_map_cmd,
8218 "show bgp ipv6 route-map WORD",
8219 SHOW_STR
8220 BGP_STR
8221 "Address family\n"
8222 "Display routes matching the route-map\n"
8223 "A route-map to match on\n")
Lou Berger651b4022016-01-12 13:42:07 -05008224{
8225 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8226 bgp_show_type_route_map);
8227}
8228#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02008229
Lou Berger651b4022016-01-12 13:42:07 -05008230DEFUN (show_bgp_ipv4_cidr_only,
8231 show_bgp_ipv4_cidr_only_cmd,
8232 "show bgp ipv4 cidr-only",
paul718e3742002-12-13 20:15:29 +00008233 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008234 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008235 IP_STR
paul718e3742002-12-13 20:15:29 +00008236 "Display only routes with non-natural netmasks\n")
8237{
8238 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00008239 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00008240}
8241
Lou Berger651b4022016-01-12 13:42:07 -05008242DEFUN (show_bgp_ipv4_safi_flap_cidr_only,
8243 show_bgp_ipv4_safi_flap_cidr_only_cmd,
8244 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics cidr-only",
paul718e3742002-12-13 20:15:29 +00008245 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008246 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008247 "Address Family\n"
8248 "Address Family Modifier\n"
8249 "Address Family Modifier\n"
8250 "Address Family Modifier\n"
8251 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00008252 "Display flap statistics of routes\n"
8253 "Display only routes with non-natural netmasks\n")
8254{
Lou Berger651b4022016-01-12 13:42:07 -05008255 safi_t safi;
8256
8257 if (bgp_parse_safi(argv[0], &safi)) {
8258 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8259 return CMD_WARNING;
8260 }
8261 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00008262}
8263
Lou Berger651b4022016-01-12 13:42:07 -05008264ALIAS (show_bgp_ipv4_safi_flap_cidr_only,
8265 show_bgp_ipv4_safi_damp_flap_cidr_only_cmd,
8266 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics cidr-only",
Balaji3921cc52015-05-16 23:12:17 +05308267 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308268 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008269 "Address Family\n"
8270 "Address Family Modifier\n"
8271 "Address Family Modifier\n"
8272 "Address Family Modifier\n"
8273 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308274 "Display detailed information about dampening\n"
8275 "Display flap statistics of routes\n"
8276 "Display only routes with non-natural netmasks\n")
8277
Lou Berger651b4022016-01-12 13:42:07 -05008278DEFUN (show_bgp_ipv4_safi_cidr_only,
8279 show_bgp_ipv4_safi_cidr_only_cmd,
8280 "show bgp ipv4 (unicast|multicast) cidr-only",
paul718e3742002-12-13 20:15:29 +00008281 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008282 BGP_STR
8283 "Address family\n"
8284 "Address Family modifier\n"
8285 "Address Family modifier\n"
8286 "Display only routes with non-natural netmasks\n")
8287{
8288 if (strncmp (argv[0], "m", 1) == 0)
8289 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00008290 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00008291
8292 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00008293 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00008294}
David Lamparter6b0655a2014-06-04 06:53:35 +02008295
Lou Berger651b4022016-01-12 13:42:07 -05008296/* new046 */
8297DEFUN (show_bgp_afi_safi_community_all,
8298 show_bgp_afi_safi_community_all_cmd,
paul718e3742002-12-13 20:15:29 +00008299#ifdef HAVE_IPV6
Lou Berger651b4022016-01-12 13:42:07 -05008300 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) community",
8301#else
8302 "show bgp ipv4 (encap|multicast|unicast|vpn) community",
8303#endif
paul718e3742002-12-13 20:15:29 +00008304 SHOW_STR
8305 BGP_STR
8306 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008307#ifdef HAVE_IPV6
8308 "Address family\n"
8309#endif
8310 "Address Family modifier\n"
8311 "Address Family modifier\n"
8312 "Address Family modifier\n"
8313 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008314 "Display routes matching the communities\n")
Lou Berger651b4022016-01-12 13:42:07 -05008315{
8316 safi_t safi;
8317 afi_t afi;
paul718e3742002-12-13 20:15:29 +00008318
Lou Berger651b4022016-01-12 13:42:07 -05008319 if (bgp_parse_afi(argv[0], &afi)) {
8320 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
8321 return CMD_WARNING;
8322 }
8323 if (bgp_parse_safi(argv[1], &safi)) {
8324 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
8325 return CMD_WARNING;
8326 }
8327
8328 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_all, NULL);
8329}
8330DEFUN (show_bgp_afi_community_all,
8331 show_bgp_afi_community_all_cmd,
8332#ifdef HAVE_IPV6
8333 "show bgp (ipv4|ipv6) community",
8334#else
8335 "show bgp ipv4 community",
8336#endif
paul718e3742002-12-13 20:15:29 +00008337 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008338 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008339 "Address family\n"
8340#ifdef HAVE_IPV6
8341 "Address family\n"
8342#endif
paul718e3742002-12-13 20:15:29 +00008343 "Display routes matching the communities\n")
8344{
Lou Berger651b4022016-01-12 13:42:07 -05008345 afi_t afi;
8346 safi_t safi = SAFI_UNICAST;
paul718e3742002-12-13 20:15:29 +00008347
Lou Berger651b4022016-01-12 13:42:07 -05008348 if (bgp_parse_afi(argv[0], &afi)) {
8349 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
8350 return CMD_WARNING;
8351 }
8352 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00008353}
David Lamparter6b0655a2014-06-04 06:53:35 +02008354
paul94f2b392005-06-28 12:44:16 +00008355static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04008356bgp_show_community (struct vty *vty, const char *view_name, int argc,
8357 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008358{
8359 struct community *com;
8360 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04008361 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00008362 int i;
8363 char *str;
8364 int first = 0;
8365
Michael Lambert95cbbd22010-07-23 14:43:04 -04008366 /* BGP structure lookup */
8367 if (view_name)
8368 {
8369 bgp = bgp_lookup_by_name (view_name);
8370 if (bgp == NULL)
8371 {
8372 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8373 return CMD_WARNING;
8374 }
8375 }
8376 else
8377 {
8378 bgp = bgp_get_default ();
8379 if (bgp == NULL)
8380 {
8381 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8382 return CMD_WARNING;
8383 }
8384 }
8385
paul718e3742002-12-13 20:15:29 +00008386 b = buffer_new (1024);
8387 for (i = 0; i < argc; i++)
8388 {
8389 if (first)
8390 buffer_putc (b, ' ');
8391 else
8392 {
8393 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8394 continue;
8395 first = 1;
8396 }
8397
8398 buffer_putstr (b, argv[i]);
8399 }
8400 buffer_putc (b, '\0');
8401
8402 str = buffer_getstr (b);
8403 buffer_free (b);
8404
8405 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00008406 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00008407 if (! com)
8408 {
8409 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
8410 return CMD_WARNING;
8411 }
8412
Michael Lambert95cbbd22010-07-23 14:43:04 -04008413 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00008414 (exact ? bgp_show_type_community_exact :
8415 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00008416}
8417
Lou Berger651b4022016-01-12 13:42:07 -05008418DEFUN (show_bgp_ipv4_community,
8419 show_bgp_ipv4_community_cmd,
8420 "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +00008421 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008422 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008423 IP_STR
paul718e3742002-12-13 20:15:29 +00008424 "Display routes matching the communities\n"
8425 "community number\n"
8426 "Do not send outside local AS (well-known community)\n"
8427 "Do not advertise to any peer (well-known community)\n"
8428 "Do not export to next AS (well-known community)\n")
8429{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008430 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008431}
8432
Lou Berger651b4022016-01-12 13:42:07 -05008433ALIAS (show_bgp_ipv4_community,
8434 show_bgp_ipv4_community2_cmd,
8435 "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 +00008436 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008437 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008438 IP_STR
paul718e3742002-12-13 20:15:29 +00008439 "Display routes matching the communities\n"
8440 "community number\n"
8441 "Do not send outside local AS (well-known community)\n"
8442 "Do not advertise to any peer (well-known community)\n"
8443 "Do not export to next AS (well-known community)\n"
8444 "community number\n"
8445 "Do not send outside local AS (well-known community)\n"
8446 "Do not advertise to any peer (well-known community)\n"
8447 "Do not export to next AS (well-known community)\n")
8448
Lou Berger651b4022016-01-12 13:42:07 -05008449ALIAS (show_bgp_ipv4_community,
8450 show_bgp_ipv4_community3_cmd,
8451 "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 +00008452 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008453 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008454 IP_STR
paul718e3742002-12-13 20:15:29 +00008455 "Display routes matching the communities\n"
8456 "community number\n"
8457 "Do not send outside local AS (well-known community)\n"
8458 "Do not advertise to any peer (well-known community)\n"
8459 "Do not export to next AS (well-known community)\n"
8460 "community number\n"
8461 "Do not send outside local AS (well-known community)\n"
8462 "Do not advertise to any peer (well-known community)\n"
8463 "Do not export to next AS (well-known community)\n"
8464 "community number\n"
8465 "Do not send outside local AS (well-known community)\n"
8466 "Do not advertise to any peer (well-known community)\n"
8467 "Do not export to next AS (well-known community)\n")
8468
Lou Berger651b4022016-01-12 13:42:07 -05008469ALIAS (show_bgp_ipv4_community,
8470 show_bgp_ipv4_community4_cmd,
8471 "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 +00008472 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008473 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008474 IP_STR
paul718e3742002-12-13 20:15:29 +00008475 "Display routes matching the communities\n"
8476 "community number\n"
8477 "Do not send outside local AS (well-known community)\n"
8478 "Do not advertise to any peer (well-known community)\n"
8479 "Do not export to next AS (well-known community)\n"
8480 "community number\n"
8481 "Do not send outside local AS (well-known community)\n"
8482 "Do not advertise to any peer (well-known community)\n"
8483 "Do not export to next AS (well-known community)\n"
8484 "community number\n"
8485 "Do not send outside local AS (well-known community)\n"
8486 "Do not advertise to any peer (well-known community)\n"
8487 "Do not export to next AS (well-known community)\n"
8488 "community number\n"
8489 "Do not send outside local AS (well-known community)\n"
8490 "Do not advertise to any peer (well-known community)\n"
8491 "Do not export to next AS (well-known community)\n")
8492
Lou Berger651b4022016-01-12 13:42:07 -05008493DEFUN (show_bgp_ipv4_safi_community,
8494 show_bgp_ipv4_safi_community_cmd,
8495 "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +00008496 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008497 BGP_STR
8498 "Address family\n"
8499 "Address Family modifier\n"
8500 "Address Family modifier\n"
8501 "Display routes matching the communities\n"
8502 "community number\n"
8503 "Do not send outside local AS (well-known community)\n"
8504 "Do not advertise to any peer (well-known community)\n"
8505 "Do not export to next AS (well-known community)\n")
8506{
8507 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008508 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008509
Michael Lambert95cbbd22010-07-23 14:43:04 -04008510 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008511}
8512
Lou Berger651b4022016-01-12 13:42:07 -05008513ALIAS (show_bgp_ipv4_safi_community,
8514 show_bgp_ipv4_safi_community2_cmd,
8515 "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 +00008516 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008517 BGP_STR
8518 "Address family\n"
8519 "Address Family modifier\n"
8520 "Address Family modifier\n"
8521 "Display routes matching the communities\n"
8522 "community number\n"
8523 "Do not send outside local AS (well-known community)\n"
8524 "Do not advertise to any peer (well-known community)\n"
8525 "Do not export to next AS (well-known community)\n"
8526 "community number\n"
8527 "Do not send outside local AS (well-known community)\n"
8528 "Do not advertise to any peer (well-known community)\n"
8529 "Do not export to next AS (well-known community)\n")
8530
Lou Berger651b4022016-01-12 13:42:07 -05008531ALIAS (show_bgp_ipv4_safi_community,
8532 show_bgp_ipv4_safi_community3_cmd,
8533 "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 +00008534 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008535 BGP_STR
8536 "Address family\n"
8537 "Address Family modifier\n"
8538 "Address Family modifier\n"
8539 "Display routes matching the communities\n"
8540 "community number\n"
8541 "Do not send outside local AS (well-known community)\n"
8542 "Do not advertise to any peer (well-known community)\n"
8543 "Do not export to next AS (well-known community)\n"
8544 "community number\n"
8545 "Do not send outside local AS (well-known community)\n"
8546 "Do not advertise to any peer (well-known community)\n"
8547 "Do not export to next AS (well-known community)\n"
8548 "community number\n"
8549 "Do not send outside local AS (well-known community)\n"
8550 "Do not advertise to any peer (well-known community)\n"
8551 "Do not export to next AS (well-known community)\n")
8552
Lou Berger651b4022016-01-12 13:42:07 -05008553ALIAS (show_bgp_ipv4_safi_community,
8554 show_bgp_ipv4_safi_community4_cmd,
8555 "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 +00008556 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008557 BGP_STR
8558 "Address family\n"
8559 "Address Family modifier\n"
8560 "Address Family modifier\n"
8561 "Display routes matching the communities\n"
8562 "community number\n"
8563 "Do not send outside local AS (well-known community)\n"
8564 "Do not advertise to any peer (well-known community)\n"
8565 "Do not export to next AS (well-known community)\n"
8566 "community number\n"
8567 "Do not send outside local AS (well-known community)\n"
8568 "Do not advertise to any peer (well-known community)\n"
8569 "Do not export to next AS (well-known community)\n"
8570 "community number\n"
8571 "Do not send outside local AS (well-known community)\n"
8572 "Do not advertise to any peer (well-known community)\n"
8573 "Do not export to next AS (well-known community)\n"
8574 "community number\n"
8575 "Do not send outside local AS (well-known community)\n"
8576 "Do not advertise to any peer (well-known community)\n"
8577 "Do not export to next AS (well-known community)\n")
8578
Michael Lambert95cbbd22010-07-23 14:43:04 -04008579DEFUN (show_bgp_view_afi_safi_community_all,
8580 show_bgp_view_afi_safi_community_all_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05008581#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -04008582 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Lou Berger651b4022016-01-12 13:42:07 -05008583#else
8584 "show bgp view WORD ipv4 (unicast|multicast) community",
8585#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -04008586 SHOW_STR
8587 BGP_STR
8588 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008589 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008590 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008591#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -04008592 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008593#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -04008594 "Address Family modifier\n"
8595 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00008596 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04008597{
8598 int afi;
8599 int safi;
8600 struct bgp *bgp;
8601
8602 /* BGP structure lookup. */
8603 bgp = bgp_lookup_by_name (argv[0]);
8604 if (bgp == NULL)
8605 {
8606 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8607 return CMD_WARNING;
8608 }
8609
Lou Berger651b4022016-01-12 13:42:07 -05008610#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -04008611 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8612 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Lou Berger651b4022016-01-12 13:42:07 -05008613#else
8614 afi = AFI_IP;
8615 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8616#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -04008617 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
8618}
8619
8620DEFUN (show_bgp_view_afi_safi_community,
8621 show_bgp_view_afi_safi_community_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05008622#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -04008623 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Lou Berger651b4022016-01-12 13:42:07 -05008624#else
8625 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
8626#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -04008627 SHOW_STR
8628 BGP_STR
8629 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008630 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008631 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008632#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -04008633 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008634#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -04008635 "Address family modifier\n"
8636 "Address family modifier\n"
8637 "Display routes matching the communities\n"
8638 "community number\n"
8639 "Do not send outside local AS (well-known community)\n"
8640 "Do not advertise to any peer (well-known community)\n"
8641 "Do not export to next AS (well-known community)\n")
8642{
8643 int afi;
8644 int safi;
8645
Lou Berger651b4022016-01-12 13:42:07 -05008646#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -04008647 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8648 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8649 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Lou Berger651b4022016-01-12 13:42:07 -05008650#else
8651 afi = AFI_IP;
8652 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8653 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
8654#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -04008655}
8656
8657ALIAS (show_bgp_view_afi_safi_community,
8658 show_bgp_view_afi_safi_community2_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05008659#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -04008660 "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 -05008661#else
8662 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8663#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -04008664 SHOW_STR
8665 BGP_STR
8666 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008667 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008668 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008669#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -04008670 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008671#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -04008672 "Address family modifier\n"
8673 "Address family modifier\n"
8674 "Display routes matching the communities\n"
8675 "community number\n"
8676 "Do not send outside local AS (well-known community)\n"
8677 "Do not advertise to any peer (well-known community)\n"
8678 "Do not export to next AS (well-known community)\n"
8679 "community number\n"
8680 "Do not send outside local AS (well-known community)\n"
8681 "Do not advertise to any peer (well-known community)\n"
8682 "Do not export to next AS (well-known community)\n")
8683
8684ALIAS (show_bgp_view_afi_safi_community,
8685 show_bgp_view_afi_safi_community3_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05008686#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -04008687 "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 -05008688#else
8689 "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)",
8690#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -04008691 SHOW_STR
8692 BGP_STR
8693 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008694 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008695 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008696#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -04008697 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008698#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -04008699 "Address family modifier\n"
8700 "Address family modifier\n"
8701 "Display routes matching the communities\n"
8702 "community number\n"
8703 "Do not send outside local AS (well-known community)\n"
8704 "Do not advertise to any peer (well-known community)\n"
8705 "Do not export to next AS (well-known community)\n"
8706 "community number\n"
8707 "Do not send outside local AS (well-known community)\n"
8708 "Do not advertise to any peer (well-known community)\n"
8709 "Do not export to next AS (well-known community)\n"
8710 "community number\n"
8711 "Do not send outside local AS (well-known community)\n"
8712 "Do not advertise to any peer (well-known community)\n"
8713 "Do not export to next AS (well-known community)\n")
8714
8715ALIAS (show_bgp_view_afi_safi_community,
8716 show_bgp_view_afi_safi_community4_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05008717#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -04008718 "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 -05008719#else
8720 "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)",
8721#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -04008722 SHOW_STR
8723 BGP_STR
8724 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008725 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008726 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008727#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -04008728 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008729#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -04008730 "Address family modifier\n"
8731 "Address family modifier\n"
8732 "Display routes matching the communities\n"
8733 "community number\n"
8734 "Do not send outside local AS (well-known community)\n"
8735 "Do not advertise to any peer (well-known community)\n"
8736 "Do not export to next AS (well-known community)\n"
8737 "community number\n"
8738 "Do not send outside local AS (well-known community)\n"
8739 "Do not advertise to any peer (well-known community)\n"
8740 "Do not export to next AS (well-known community)\n"
8741 "community number\n"
8742 "Do not send outside local AS (well-known community)\n"
8743 "Do not advertise to any peer (well-known community)\n"
8744 "Do not export to next AS (well-known community)\n"
8745 "community number\n"
8746 "Do not send outside local AS (well-known community)\n"
8747 "Do not advertise to any peer (well-known community)\n"
8748 "Do not export to next AS (well-known community)\n")
8749
Lou Berger651b4022016-01-12 13:42:07 -05008750DEFUN (show_bgp_ipv4_community_exact,
8751 show_bgp_ipv4_community_exact_cmd,
8752 "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +00008753 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008754 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008755 IP_STR
paul718e3742002-12-13 20:15:29 +00008756 "Display routes matching the communities\n"
8757 "community number\n"
8758 "Do not send outside local AS (well-known community)\n"
8759 "Do not advertise to any peer (well-known community)\n"
8760 "Do not export to next AS (well-known community)\n"
8761 "Exact match of the communities")
8762{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008763 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008764}
8765
Lou Berger651b4022016-01-12 13:42:07 -05008766ALIAS (show_bgp_ipv4_community_exact,
8767 show_bgp_ipv4_community2_exact_cmd,
8768 "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 +00008769 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008770 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008771 IP_STR
paul718e3742002-12-13 20:15:29 +00008772 "Display routes matching the communities\n"
8773 "community number\n"
8774 "Do not send outside local AS (well-known community)\n"
8775 "Do not advertise to any peer (well-known community)\n"
8776 "Do not export to next AS (well-known community)\n"
8777 "community number\n"
8778 "Do not send outside local AS (well-known community)\n"
8779 "Do not advertise to any peer (well-known community)\n"
8780 "Do not export to next AS (well-known community)\n"
8781 "Exact match of the communities")
8782
Lou Berger651b4022016-01-12 13:42:07 -05008783ALIAS (show_bgp_ipv4_community_exact,
8784 show_bgp_ipv4_community3_exact_cmd,
8785 "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 +00008786 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008787 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008788 IP_STR
paul718e3742002-12-13 20:15:29 +00008789 "Display routes matching the communities\n"
8790 "community number\n"
8791 "Do not send outside local AS (well-known community)\n"
8792 "Do not advertise to any peer (well-known community)\n"
8793 "Do not export to next AS (well-known community)\n"
8794 "community number\n"
8795 "Do not send outside local AS (well-known community)\n"
8796 "Do not advertise to any peer (well-known community)\n"
8797 "Do not export to next AS (well-known community)\n"
8798 "community number\n"
8799 "Do not send outside local AS (well-known community)\n"
8800 "Do not advertise to any peer (well-known community)\n"
8801 "Do not export to next AS (well-known community)\n"
8802 "Exact match of the communities")
8803
Lou Berger651b4022016-01-12 13:42:07 -05008804ALIAS (show_bgp_ipv4_community_exact,
8805 show_bgp_ipv4_community4_exact_cmd,
8806 "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 +00008807 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008808 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008809 IP_STR
paul718e3742002-12-13 20:15:29 +00008810 "Display routes matching the communities\n"
8811 "community number\n"
8812 "Do not send outside local AS (well-known community)\n"
8813 "Do not advertise to any peer (well-known community)\n"
8814 "Do not export to next AS (well-known community)\n"
8815 "community number\n"
8816 "Do not send outside local AS (well-known community)\n"
8817 "Do not advertise to any peer (well-known community)\n"
8818 "Do not export to next AS (well-known community)\n"
8819 "community number\n"
8820 "Do not send outside local AS (well-known community)\n"
8821 "Do not advertise to any peer (well-known community)\n"
8822 "Do not export to next AS (well-known community)\n"
8823 "community number\n"
8824 "Do not send outside local AS (well-known community)\n"
8825 "Do not advertise to any peer (well-known community)\n"
8826 "Do not export to next AS (well-known community)\n"
8827 "Exact match of the communities")
8828
Lou Berger651b4022016-01-12 13:42:07 -05008829DEFUN (show_bgp_ipv4_safi_community4_exact,
8830 show_bgp_ipv4_safi_community_exact_cmd,
8831 "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +00008832 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008833 BGP_STR
8834 "Address family\n"
8835 "Address Family modifier\n"
8836 "Address Family modifier\n"
8837 "Display routes matching the communities\n"
8838 "community number\n"
8839 "Do not send outside local AS (well-known community)\n"
8840 "Do not advertise to any peer (well-known community)\n"
8841 "Do not export to next AS (well-known community)\n"
8842 "Exact match of the communities")
8843{
8844 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008845 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008846
Michael Lambert95cbbd22010-07-23 14:43:04 -04008847 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008848}
8849
Lou Berger651b4022016-01-12 13:42:07 -05008850ALIAS (show_bgp_ipv4_safi_community4_exact,
8851 show_bgp_ipv4_safi_community2_exact_cmd,
8852 "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 +00008853 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008854 BGP_STR
8855 "Address family\n"
8856 "Address Family modifier\n"
8857 "Address Family modifier\n"
8858 "Display routes matching the communities\n"
8859 "community number\n"
8860 "Do not send outside local AS (well-known community)\n"
8861 "Do not advertise to any peer (well-known community)\n"
8862 "Do not export to next AS (well-known community)\n"
8863 "community number\n"
8864 "Do not send outside local AS (well-known community)\n"
8865 "Do not advertise to any peer (well-known community)\n"
8866 "Do not export to next AS (well-known community)\n"
8867 "Exact match of the communities")
8868
Lou Berger651b4022016-01-12 13:42:07 -05008869ALIAS (show_bgp_ipv4_safi_community4_exact,
8870 show_bgp_ipv4_safi_community3_exact_cmd,
8871 "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 +00008872 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008873 BGP_STR
8874 "Address family\n"
8875 "Address Family modifier\n"
8876 "Address Family modifier\n"
8877 "Display routes matching the communities\n"
8878 "community number\n"
8879 "Do not send outside local AS (well-known community)\n"
8880 "Do not advertise to any peer (well-known community)\n"
8881 "Do not export to next AS (well-known community)\n"
8882 "community number\n"
8883 "Do not send outside local AS (well-known community)\n"
8884 "Do not advertise to any peer (well-known community)\n"
8885 "Do not export to next AS (well-known community)\n"
8886 "community number\n"
8887 "Do not send outside local AS (well-known community)\n"
8888 "Do not advertise to any peer (well-known community)\n"
8889 "Do not export to next AS (well-known community)\n"
8890 "Exact match of the communities")
8891
Lou Berger651b4022016-01-12 13:42:07 -05008892ALIAS (show_bgp_ipv4_safi_community4_exact,
8893 show_bgp_ipv4_safi_community4_exact_cmd,
8894 "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 +00008895 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008896 BGP_STR
8897 "Address family\n"
8898 "Address Family modifier\n"
8899 "Address Family modifier\n"
8900 "Display routes matching the communities\n"
8901 "community number\n"
8902 "Do not send outside local AS (well-known community)\n"
8903 "Do not advertise to any peer (well-known community)\n"
8904 "Do not export to next AS (well-known community)\n"
8905 "community number\n"
8906 "Do not send outside local AS (well-known community)\n"
8907 "Do not advertise to any peer (well-known community)\n"
8908 "Do not export to next AS (well-known community)\n"
8909 "community number\n"
8910 "Do not send outside local AS (well-known community)\n"
8911 "Do not advertise to any peer (well-known community)\n"
8912 "Do not export to next AS (well-known community)\n"
8913 "community number\n"
8914 "Do not send outside local AS (well-known community)\n"
8915 "Do not advertise to any peer (well-known community)\n"
8916 "Do not export to next AS (well-known community)\n"
8917 "Exact match of the communities")
8918
Lou Berger651b4022016-01-12 13:42:07 -05008919
paul718e3742002-12-13 20:15:29 +00008920#ifdef HAVE_IPV6
Lou Berger651b4022016-01-12 13:42:07 -05008921DEFUN (show_bgp_ipv6_community,
8922 show_bgp_ipv6_community_cmd,
8923 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +00008924 SHOW_STR
8925 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008926 "Address family\n"
8927 "Address family modifier\n"
8928 "Address family modifier\n"
8929 "Address family modifier\n"
8930 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +00008931 "Display routes matching the communities\n"
8932 "community number\n"
8933 "Do not send outside local AS (well-known community)\n"
8934 "Do not advertise to any peer (well-known community)\n"
8935 "Do not export to next AS (well-known community)\n")
8936{
Lou Berger651b4022016-01-12 13:42:07 -05008937 safi_t safi;
8938
8939 if (bgp_parse_safi(argv[0], &safi)) {
8940 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8941 return CMD_WARNING;
8942 }
8943 return bgp_show_community (vty, NULL, argc-1, argv+1, 0, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +00008944}
8945
Lou Berger651b4022016-01-12 13:42:07 -05008946ALIAS (show_bgp_ipv6_community,
paul718e3742002-12-13 20:15:29 +00008947 show_bgp_ipv6_community2_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05008948 "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 +00008949 SHOW_STR
8950 BGP_STR
8951 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008952 "Address family modifier\n"
8953 "Address family modifier\n"
8954 "Address family modifier\n"
8955 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +00008956 "Display routes matching the communities\n"
8957 "community number\n"
8958 "Do not send outside local AS (well-known community)\n"
8959 "Do not advertise to any peer (well-known community)\n"
8960 "Do not export to next AS (well-known community)\n"
8961 "community number\n"
8962 "Do not send outside local AS (well-known community)\n"
8963 "Do not advertise to any peer (well-known community)\n"
8964 "Do not export to next AS (well-known community)\n")
8965
Lou Berger651b4022016-01-12 13:42:07 -05008966ALIAS (show_bgp_ipv6_community,
paul718e3742002-12-13 20:15:29 +00008967 show_bgp_ipv6_community3_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05008968 "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 +00008969 SHOW_STR
8970 BGP_STR
8971 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008972 "Address family modifier\n"
8973 "Address family modifier\n"
8974 "Address family modifier\n"
8975 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +00008976 "Display routes matching the communities\n"
8977 "community number\n"
8978 "Do not send outside local AS (well-known community)\n"
8979 "Do not advertise to any peer (well-known community)\n"
8980 "Do not export to next AS (well-known community)\n"
8981 "community number\n"
8982 "Do not send outside local AS (well-known community)\n"
8983 "Do not advertise to any peer (well-known community)\n"
8984 "Do not export to next AS (well-known community)\n"
8985 "community number\n"
8986 "Do not send outside local AS (well-known community)\n"
8987 "Do not advertise to any peer (well-known community)\n"
8988 "Do not export to next AS (well-known community)\n")
8989
Lou Berger651b4022016-01-12 13:42:07 -05008990ALIAS (show_bgp_ipv6_community,
paul718e3742002-12-13 20:15:29 +00008991 show_bgp_ipv6_community4_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05008992 "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 +00008993 SHOW_STR
8994 BGP_STR
8995 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05008996 "Address family modifier\n"
8997 "Address family modifier\n"
8998 "Address family modifier\n"
8999 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +00009000 "Display routes matching the communities\n"
9001 "community number\n"
9002 "Do not send outside local AS (well-known community)\n"
9003 "Do not advertise to any peer (well-known community)\n"
9004 "Do not export to next AS (well-known community)\n"
9005 "community number\n"
9006 "Do not send outside local AS (well-known community)\n"
9007 "Do not advertise to any peer (well-known community)\n"
9008 "Do not export to next AS (well-known community)\n"
9009 "community number\n"
9010 "Do not send outside local AS (well-known community)\n"
9011 "Do not advertise to any peer (well-known community)\n"
9012 "Do not export to next AS (well-known community)\n"
9013 "community number\n"
9014 "Do not send outside local AS (well-known community)\n"
9015 "Do not advertise to any peer (well-known community)\n"
9016 "Do not export to next AS (well-known community)\n")
9017
paul718e3742002-12-13 20:15:29 +00009018
9019DEFUN (show_bgp_community_exact,
Lou Berger651b4022016-01-12 13:42:07 -05009020 show_bgp_ipv6_community_exact_cmd,
9021 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +00009022 SHOW_STR
9023 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009024 "Address family\n"
9025 "Address family modifier\n"
9026 "Address family modifier\n"
9027 "Address family modifier\n"
9028 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +00009029 "Display routes matching the communities\n"
9030 "community number\n"
9031 "Do not send outside local AS (well-known community)\n"
9032 "Do not advertise to any peer (well-known community)\n"
9033 "Do not export to next AS (well-known community)\n"
9034 "Exact match of the communities")
9035{
Lou Berger651b4022016-01-12 13:42:07 -05009036 safi_t safi;
9037
9038 if (bgp_parse_safi(argv[0], &safi)) {
9039 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9040 return CMD_WARNING;
9041 }
9042 return bgp_show_community (vty, NULL, argc-1, argv+1, 1, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +00009043}
9044
paul718e3742002-12-13 20:15:29 +00009045
9046ALIAS (show_bgp_community_exact,
9047 show_bgp_ipv6_community2_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009048 "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 +00009049 SHOW_STR
9050 BGP_STR
9051 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009052 "Address family modifier\n"
9053 "Address family modifier\n"
9054 "Address family modifier\n"
9055 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +00009056 "Display routes matching the communities\n"
9057 "community number\n"
9058 "Do not send outside local AS (well-known community)\n"
9059 "Do not advertise to any peer (well-known community)\n"
9060 "Do not export to next AS (well-known community)\n"
9061 "community number\n"
9062 "Do not send outside local AS (well-known community)\n"
9063 "Do not advertise to any peer (well-known community)\n"
9064 "Do not export to next AS (well-known community)\n"
9065 "Exact match of the communities")
9066
9067ALIAS (show_bgp_community_exact,
paul718e3742002-12-13 20:15:29 +00009068 show_bgp_ipv6_community3_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009069 "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 +00009070 SHOW_STR
9071 BGP_STR
9072 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009073 "Address family modifier\n"
9074 "Address family modifier\n"
9075 "Address family modifier\n"
9076 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +00009077 "Display routes matching the communities\n"
9078 "community number\n"
9079 "Do not send outside local AS (well-known community)\n"
9080 "Do not advertise to any peer (well-known community)\n"
9081 "Do not export to next AS (well-known community)\n"
9082 "community number\n"
9083 "Do not send outside local AS (well-known community)\n"
9084 "Do not advertise to any peer (well-known community)\n"
9085 "Do not export to next AS (well-known community)\n"
9086 "community number\n"
9087 "Do not send outside local AS (well-known community)\n"
9088 "Do not advertise to any peer (well-known community)\n"
9089 "Do not export to next AS (well-known community)\n"
9090 "Exact match of the communities")
9091
9092ALIAS (show_bgp_community_exact,
paul718e3742002-12-13 20:15:29 +00009093 show_bgp_ipv6_community4_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009094 "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 +00009095 SHOW_STR
9096 BGP_STR
9097 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009098 "Address family modifier\n"
9099 "Address family modifier\n"
9100 "Address family modifier\n"
9101 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +00009102 "Display routes matching the communities\n"
9103 "community number\n"
9104 "Do not send outside local AS (well-known community)\n"
9105 "Do not advertise to any peer (well-known community)\n"
9106 "Do not export to next AS (well-known community)\n"
9107 "community number\n"
9108 "Do not send outside local AS (well-known community)\n"
9109 "Do not advertise to any peer (well-known community)\n"
9110 "Do not export to next AS (well-known community)\n"
9111 "community number\n"
9112 "Do not send outside local AS (well-known community)\n"
9113 "Do not advertise to any peer (well-known community)\n"
9114 "Do not export to next AS (well-known community)\n"
9115 "community number\n"
9116 "Do not send outside local AS (well-known community)\n"
9117 "Do not advertise to any peer (well-known community)\n"
9118 "Do not export to next AS (well-known community)\n"
9119 "Exact match of the communities")
9120
paul718e3742002-12-13 20:15:29 +00009121#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009122
paul94f2b392005-06-28 12:44:16 +00009123static int
paulfd79ac92004-10-13 05:06:08 +00009124bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04009125 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00009126{
9127 struct community_list *list;
9128
hassofee6e4e2005-02-02 16:29:31 +00009129 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00009130 if (list == NULL)
9131 {
9132 vty_out (vty, "%% %s is not a valid community-list name%s", com,
9133 VTY_NEWLINE);
9134 return CMD_WARNING;
9135 }
9136
ajs5a646652004-11-05 01:25:55 +00009137 return bgp_show (vty, NULL, afi, safi,
9138 (exact ? bgp_show_type_community_list_exact :
9139 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00009140}
9141
Lou Berger651b4022016-01-12 13:42:07 -05009142DEFUN (show_bgp_ipv4_community_list,
9143 show_bgp_ipv4_community_list_cmd,
9144 "show bgp ipv4 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009145 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009146 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009147 IP_STR
paul718e3742002-12-13 20:15:29 +00009148 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009149 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009150 "community-list name\n")
9151{
9152 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
9153}
9154
Lou Berger651b4022016-01-12 13:42:07 -05009155DEFUN (show_bgp_ipv4_safi_community_list,
9156 show_bgp_ipv4_safi_community_list_cmd,
9157 "show bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009158 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009159 BGP_STR
9160 "Address family\n"
9161 "Address Family modifier\n"
9162 "Address Family modifier\n"
9163 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009164 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009165 "community-list name\n")
9166{
9167 if (strncmp (argv[0], "m", 1) == 0)
9168 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
9169
9170 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
9171}
9172
Lou Berger651b4022016-01-12 13:42:07 -05009173DEFUN (show_bgp_ipv4_community_list_exact,
9174 show_bgp_ipv4_community_list_exact_cmd,
9175 "show bgp ipv4 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009176 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009177 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009178 IP_STR
paul718e3742002-12-13 20:15:29 +00009179 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009180 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009181 "community-list name\n"
9182 "Exact match of the communities\n")
9183{
9184 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
9185}
9186
Lou Berger651b4022016-01-12 13:42:07 -05009187DEFUN (show_bgp_ipv4_safi_community_list_exact,
9188 show_bgp_ipv4_safi_community_list_exact_cmd,
9189 "show bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009190 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009191 BGP_STR
9192 "Address family\n"
9193 "Address Family modifier\n"
9194 "Address Family modifier\n"
9195 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009196 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009197 "community-list name\n"
9198 "Exact match of the communities\n")
9199{
9200 if (strncmp (argv[0], "m", 1) == 0)
9201 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
9202
9203 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
9204}
9205
9206#ifdef HAVE_IPV6
9207DEFUN (show_bgp_community_list,
9208 show_bgp_community_list_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009209 "show bgp ipv6 (encap|multicast|unicast|vpn) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009210 SHOW_STR
9211 BGP_STR
9212 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009213 "Address family modifier\n"
9214 "Address family modifier\n"
9215 "Address family modifier\n"
9216 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +00009217 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009218 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00009219 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00009220{
Lou Berger651b4022016-01-12 13:42:07 -05009221 safi_t safi;
paul718e3742002-12-13 20:15:29 +00009222
Lou Berger651b4022016-01-12 13:42:07 -05009223 if (bgp_parse_safi(argv[0], &safi)) {
9224 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9225 return CMD_WARNING;
9226 }
9227 return bgp_show_community_list (vty, argv[1], 0, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +00009228}
9229
9230DEFUN (show_bgp_community_list_exact,
paul718e3742002-12-13 20:15:29 +00009231 show_bgp_ipv6_community_list_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009232 "show bgp ipv6 (encap|multicast|unicast|vpn) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009233 SHOW_STR
9234 BGP_STR
9235 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009236 "Address family modifier\n"
9237 "Address family modifier\n"
9238 "Address family modifier\n"
9239 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +00009240 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009241 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009242 "community-list name\n"
9243 "Exact match of the communities\n")
paul718e3742002-12-13 20:15:29 +00009244{
Lou Berger651b4022016-01-12 13:42:07 -05009245 safi_t safi;
paul718e3742002-12-13 20:15:29 +00009246
Lou Berger651b4022016-01-12 13:42:07 -05009247 if (bgp_parse_safi(argv[0], &safi)) {
9248 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9249 return CMD_WARNING;
9250 }
9251 return bgp_show_community_list (vty, argv[1], 1, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +00009252}
9253#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009254
paul94f2b392005-06-28 12:44:16 +00009255static int
paulfd79ac92004-10-13 05:06:08 +00009256bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009257 safi_t safi, enum bgp_show_type type)
9258{
9259 int ret;
9260 struct prefix *p;
9261
9262 p = prefix_new();
9263
9264 ret = str2prefix (prefix, p);
9265 if (! ret)
9266 {
9267 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9268 return CMD_WARNING;
9269 }
9270
ajs5a646652004-11-05 01:25:55 +00009271 ret = bgp_show (vty, NULL, afi, safi, type, p);
9272 prefix_free(p);
9273 return ret;
paul718e3742002-12-13 20:15:29 +00009274}
9275
Lou Berger651b4022016-01-12 13:42:07 -05009276DEFUN (show_bgp_ipv4_prefix_longer,
9277 show_bgp_ipv4_prefix_longer_cmd,
9278 "show bgp ipv4 A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +00009279 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009280 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009281 IP_STR
paul718e3742002-12-13 20:15:29 +00009282 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9283 "Display route and more specific routes\n")
9284{
9285 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9286 bgp_show_type_prefix_longer);
9287}
9288
Lou Berger651b4022016-01-12 13:42:07 -05009289DEFUN (show_bgp_ipv4_safi_flap_prefix_longer,
9290 show_bgp_ipv4_safi_flap_prefix_longer_cmd,
9291 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +00009292 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009293 BGP_STR
9294 "Address family\n"
9295 "Address Family modifier\n"
9296 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05009297 "Address Family modifier\n"
9298 "Address Family modifier\n"
9299 "Display flap statistics of routes\n"
paul718e3742002-12-13 20:15:29 +00009300 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9301 "Display route and more specific routes\n")
9302{
Lou Berger651b4022016-01-12 13:42:07 -05009303 safi_t safi;
paul718e3742002-12-13 20:15:29 +00009304
Lou Berger651b4022016-01-12 13:42:07 -05009305 if (bgp_parse_safi(argv[0], &safi)) {
9306 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9307 return CMD_WARNING;
9308 }
9309 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
9310 bgp_show_type_flap_prefix_longer);
paul718e3742002-12-13 20:15:29 +00009311}
9312
Lou Berger651b4022016-01-12 13:42:07 -05009313ALIAS (show_bgp_ipv4_safi_flap_prefix_longer,
9314 show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd,
9315 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +00009316 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009317 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009318 "Address family\n"
9319 "Address Family modifier\n"
9320 "Address Family modifier\n"
9321 "Address Family modifier\n"
9322 "Address Family modifier\n"
9323 "Display detailed information about dampening\n"
9324 "Display flap statistics of routes\n"
9325 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9326 "Display route and more specific routes\n")
9327
9328#ifdef HAVE_IPV6
9329DEFUN (show_bgp_ipv6_safi_flap_prefix_longer,
9330 show_bgp_ipv6_safi_flap_prefix_longer_cmd,
9331 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics X:X::X:X/M longer-prefixes",
9332 SHOW_STR
9333 BGP_STR
9334 "Address family\n"
9335 "Address Family modifier\n"
9336 "Address Family modifier\n"
9337 "Address Family modifier\n"
9338 "Address Family modifier\n"
9339 "Display flap statistics of routes\n"
9340 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9341 "Display route and more specific routes\n")
9342{
9343 safi_t safi;
9344
9345 if (bgp_parse_safi(argv[0], &safi)) {
9346 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9347 return CMD_WARNING;
9348 }
9349 return bgp_show_prefix_longer (vty, argv[1], AFI_IP6, safi,
9350 bgp_show_type_flap_prefix_longer);
9351}
9352ALIAS (show_bgp_ipv6_safi_flap_prefix_longer,
9353 show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd,
9354 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics X:X::X:X/M longer-prefixes",
9355 SHOW_STR
9356 BGP_STR
9357 "Address family\n"
9358 "Address Family modifier\n"
9359 "Address Family modifier\n"
9360 "Address Family modifier\n"
9361 "Address Family modifier\n"
9362 "Display detailed information about dampening\n"
9363 "Display flap statistics of routes\n"
9364 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9365 "Display route and more specific routes\n")
9366#endif
9367
9368DEFUN (show_bgp_ipv4_safi_prefix_longer,
9369 show_bgp_ipv4_safi_prefix_longer_cmd,
9370 "show bgp ipv4 (encap|multicast|unicast|vpn) A.B.C.D/M longer-prefixes",
9371 SHOW_STR
9372 BGP_STR
9373 "Address family\n"
9374 "Address Family modifier\n"
9375 "Address Family modifier\n"
9376 "Address Family modifier\n"
9377 "Address Family modifier\n"
9378 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9379 "Display route and more specific routes\n")
9380{
9381 safi_t safi;
9382
9383 if (bgp_parse_safi(argv[0], &safi)) {
9384 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9385 return CMD_WARNING;
9386 }
9387
9388 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
9389 bgp_show_type_prefix_longer);
9390}
9391
9392#ifdef HAVE_IPV6
9393DEFUN (show_bgp_ipv6_safi_prefix_longer,
9394 show_bgp_ipv6_safi_prefix_longer_cmd,
9395 "show bgp ipv6 (encap|multicast|unicast|vpn) X:X::X:X/M longer-prefixes",
9396 SHOW_STR
9397 BGP_STR
9398 "Address family\n"
9399 "Address Family modifier\n"
9400 "Address Family modifier\n"
9401 "Address Family modifier\n"
9402 "Address Family modifier\n"
9403 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9404 "Display route and more specific routes\n")
9405{
9406 safi_t safi;
9407
9408 if (bgp_parse_safi(argv[0], &safi)) {
9409 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9410 return CMD_WARNING;
9411 }
9412
9413 return bgp_show_prefix_longer (vty, argv[1], AFI_IP6, safi,
9414 bgp_show_type_prefix_longer);
9415}
9416#endif
9417
9418DEFUN (show_bgp_ipv4_safi_flap_address,
9419 show_bgp_ipv4_safi_flap_address_cmd,
9420 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D",
9421 SHOW_STR
9422 BGP_STR
9423 "Address family\n"
9424 "Address Family modifier\n"
9425 "Address Family modifier\n"
9426 "Address Family modifier\n"
9427 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009428 "Display flap statistics of routes\n"
9429 "Network in the BGP routing table to display\n")
9430{
Lou Berger651b4022016-01-12 13:42:07 -05009431 safi_t safi;
9432
9433 if (bgp_parse_safi(argv[0], &safi)) {
9434 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9435 return CMD_WARNING;
9436 }
9437 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00009438 bgp_show_type_flap_address);
9439}
Lou Berger651b4022016-01-12 13:42:07 -05009440ALIAS (show_bgp_ipv4_safi_flap_address,
9441 show_bgp_ipv4_safi_damp_flap_address_cmd,
9442 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D",
Balaji3921cc52015-05-16 23:12:17 +05309443 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05309444 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009445 "Address family\n"
9446 "Address Family modifier\n"
9447 "Address Family modifier\n"
9448 "Address Family modifier\n"
9449 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05309450 "Display detailed information about dampening\n"
9451 "Display flap statistics of routes\n"
9452 "Network in the BGP routing table to display\n")
Lou Berger651b4022016-01-12 13:42:07 -05009453#ifdef HAVE_IPV6
9454DEFUN (show_bgp_ipv6_flap_address,
9455 show_bgp_ipv6_flap_address_cmd,
9456 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D",
paul718e3742002-12-13 20:15:29 +00009457 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009458 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009459 "Address family\n"
9460 "Address Family modifier\n"
9461 "Address Family modifier\n"
9462 "Address Family modifier\n"
9463 "Address Family modifier\n"
9464 "Display flap statistics of routes\n"
9465 "Network in the BGP routing table to display\n")
9466{
9467 safi_t safi;
9468
9469 if (bgp_parse_safi(argv[0], &safi)) {
9470 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
9471 return CMD_WARNING;
9472 }
9473 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
9474 bgp_show_type_flap_address);
9475}
9476ALIAS (show_bgp_ipv6_flap_address,
9477 show_bgp_ipv6_damp_flap_address_cmd,
9478 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D",
9479 SHOW_STR
9480 BGP_STR
9481 "Address family\n"
9482 "Address Family modifier\n"
9483 "Address Family modifier\n"
9484 "Address Family modifier\n"
9485 "Address Family modifier\n"
9486 "Display detailed information about dampening\n"
9487 "Display flap statistics of routes\n"
9488 "Network in the BGP routing table to display\n")
9489#endif
9490
9491DEFUN (show_bgp_ipv4_safi_flap_prefix,
9492 show_bgp_ipv4_safi_flap_prefix_cmd,
9493 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D/M",
9494 SHOW_STR
9495 BGP_STR
9496 "Address family\n"
9497 "Address Family modifier\n"
9498 "Address Family modifier\n"
9499 "Address Family modifier\n"
9500 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009501 "Display flap statistics of routes\n"
9502 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9503{
Lou Berger651b4022016-01-12 13:42:07 -05009504 safi_t safi;
9505
9506 if (bgp_parse_safi(argv[0], &safi)) {
9507 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
9508 return CMD_WARNING;
9509 }
9510 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00009511 bgp_show_type_flap_prefix);
9512}
Balaji3921cc52015-05-16 23:12:17 +05309513
Lou Berger651b4022016-01-12 13:42:07 -05009514ALIAS (show_bgp_ipv4_safi_flap_prefix,
9515 show_bgp_ipv4_safi_damp_flap_prefix_cmd,
9516 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D/M",
Balaji3921cc52015-05-16 23:12:17 +05309517 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05309518 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009519 "Address family\n"
9520 "Address Family modifier\n"
9521 "Address Family modifier\n"
9522 "Address Family modifier\n"
9523 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05309524 "Display detailed information about dampening\n"
9525 "Display flap statistics of routes\n"
9526 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9527
paul718e3742002-12-13 20:15:29 +00009528#ifdef HAVE_IPV6
Lou Berger651b4022016-01-12 13:42:07 -05009529DEFUN (show_bgp_ipv6_safi_flap_prefix,
9530 show_bgp_ipv6_safi_flap_prefix_cmd,
9531 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics X:X::X:X/M",
paul718e3742002-12-13 20:15:29 +00009532 SHOW_STR
9533 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009534 "Address family\n"
9535 "Address Family modifier\n"
9536 "Address Family modifier\n"
9537 "Address Family modifier\n"
9538 "Address Family modifier\n"
9539 "Display flap statistics of routes\n"
9540 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paul718e3742002-12-13 20:15:29 +00009541{
Lou Berger651b4022016-01-12 13:42:07 -05009542 safi_t safi;
9543
9544 if (bgp_parse_safi(argv[0], &safi)) {
9545 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
9546 return CMD_WARNING;
9547 }
9548 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, safi,
9549 bgp_show_type_flap_prefix);
paul718e3742002-12-13 20:15:29 +00009550}
9551
Lou Berger651b4022016-01-12 13:42:07 -05009552ALIAS (show_bgp_ipv6_safi_flap_prefix,
9553 show_bgp_ipv6_safi_damp_flap_prefix_cmd,
9554 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics X:X::X:X/M",
9555 SHOW_STR
9556 BGP_STR
9557 "Address family\n"
9558 "Address Family modifier\n"
9559 "Address Family modifier\n"
9560 "Address Family modifier\n"
9561 "Address Family modifier\n"
9562 "Display detailed information about dampening\n"
9563 "Display flap statistics of routes\n"
9564 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9565
9566DEFUN (show_bgp_ipv6_prefix_longer,
paul718e3742002-12-13 20:15:29 +00009567 show_bgp_ipv6_prefix_longer_cmd,
9568 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9569 SHOW_STR
9570 BGP_STR
9571 "Address family\n"
9572 "IPv6 prefix <network>/<length>\n"
9573 "Display route and more specific routes\n")
paul718e3742002-12-13 20:15:29 +00009574{
9575 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9576 bgp_show_type_prefix_longer);
9577}
9578
paul718e3742002-12-13 20:15:29 +00009579#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009580
paul94f2b392005-06-28 12:44:16 +00009581static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009582peer_lookup_in_view (struct vty *vty, const char *view_name,
9583 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009584{
9585 int ret;
9586 struct bgp *bgp;
9587 struct peer *peer;
9588 union sockunion su;
9589
9590 /* BGP structure lookup. */
9591 if (view_name)
9592 {
9593 bgp = bgp_lookup_by_name (view_name);
9594 if (! bgp)
9595 {
9596 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9597 return NULL;
9598 }
9599 }
paul5228ad22004-06-04 17:58:18 +00009600 else
paulbb46e942003-10-24 19:02:03 +00009601 {
9602 bgp = bgp_get_default ();
9603 if (! bgp)
9604 {
9605 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9606 return NULL;
9607 }
9608 }
9609
9610 /* Get peer sockunion. */
9611 ret = str2sockunion (ip_str, &su);
9612 if (ret < 0)
9613 {
9614 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9615 return NULL;
9616 }
9617
9618 /* Peer structure lookup. */
9619 peer = peer_lookup (bgp, &su);
9620 if (! peer)
9621 {
9622 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9623 return NULL;
9624 }
9625
9626 return peer;
9627}
David Lamparter6b0655a2014-06-04 06:53:35 +02009628
Paul Jakma2815e612006-09-14 02:56:07 +00009629enum bgp_stats
9630{
9631 BGP_STATS_MAXBITLEN = 0,
9632 BGP_STATS_RIB,
9633 BGP_STATS_PREFIXES,
9634 BGP_STATS_TOTPLEN,
9635 BGP_STATS_UNAGGREGATEABLE,
9636 BGP_STATS_MAX_AGGREGATEABLE,
9637 BGP_STATS_AGGREGATES,
9638 BGP_STATS_SPACE,
9639 BGP_STATS_ASPATH_COUNT,
9640 BGP_STATS_ASPATH_MAXHOPS,
9641 BGP_STATS_ASPATH_TOTHOPS,
9642 BGP_STATS_ASPATH_MAXSIZE,
9643 BGP_STATS_ASPATH_TOTSIZE,
9644 BGP_STATS_ASN_HIGHEST,
9645 BGP_STATS_MAX,
9646};
paulbb46e942003-10-24 19:02:03 +00009647
Paul Jakma2815e612006-09-14 02:56:07 +00009648static const char *table_stats_strs[] =
9649{
9650 [BGP_STATS_PREFIXES] = "Total Prefixes",
9651 [BGP_STATS_TOTPLEN] = "Average prefix length",
9652 [BGP_STATS_RIB] = "Total Advertisements",
9653 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9654 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9655 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9656 [BGP_STATS_SPACE] = "Address space advertised",
9657 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9658 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9659 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9660 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9661 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9662 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9663 [BGP_STATS_MAX] = NULL,
9664};
9665
9666struct bgp_table_stats
9667{
9668 struct bgp_table *table;
9669 unsigned long long counts[BGP_STATS_MAX];
9670};
9671
9672#if 0
9673#define TALLY_SIGFIG 100000
9674static unsigned long
9675ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9676{
9677 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9678 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9679 unsigned long ret = newtot / count;
9680
9681 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9682 return ret + 1;
9683 else
9684 return ret;
9685}
9686#endif
9687
9688static int
9689bgp_table_stats_walker (struct thread *t)
9690{
9691 struct bgp_node *rn;
9692 struct bgp_node *top;
9693 struct bgp_table_stats *ts = THREAD_ARG (t);
9694 unsigned int space = 0;
9695
Paul Jakma53d9f672006-10-15 23:41:16 +00009696 if (!(top = bgp_table_top (ts->table)))
9697 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009698
9699 switch (top->p.family)
9700 {
9701 case AF_INET:
9702 space = IPV4_MAX_BITLEN;
9703 break;
9704 case AF_INET6:
9705 space = IPV6_MAX_BITLEN;
9706 break;
9707 }
9708
9709 ts->counts[BGP_STATS_MAXBITLEN] = space;
9710
9711 for (rn = top; rn; rn = bgp_route_next (rn))
9712 {
9713 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009714 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009715 unsigned int rinum = 0;
9716
9717 if (rn == top)
9718 continue;
9719
9720 if (!rn->info)
9721 continue;
9722
9723 ts->counts[BGP_STATS_PREFIXES]++;
9724 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9725
9726#if 0
9727 ts->counts[BGP_STATS_AVGPLEN]
9728 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9729 ts->counts[BGP_STATS_AVGPLEN],
9730 rn->p.prefixlen);
9731#endif
9732
9733 /* check if the prefix is included by any other announcements */
9734 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009735 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009736
9737 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009738 {
9739 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9740 /* announced address space */
9741 if (space)
9742 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9743 }
Paul Jakma2815e612006-09-14 02:56:07 +00009744 else if (prn->info)
9745 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9746
Paul Jakma2815e612006-09-14 02:56:07 +00009747 for (ri = rn->info; ri; ri = ri->next)
9748 {
9749 rinum++;
9750 ts->counts[BGP_STATS_RIB]++;
9751
9752 if (ri->attr &&
9753 (CHECK_FLAG (ri->attr->flag,
9754 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9755 ts->counts[BGP_STATS_AGGREGATES]++;
9756
9757 /* as-path stats */
9758 if (ri->attr && ri->attr->aspath)
9759 {
9760 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9761 unsigned int size = aspath_size (ri->attr->aspath);
9762 as_t highest = aspath_highest (ri->attr->aspath);
9763
9764 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9765
9766 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9767 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9768
9769 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9770 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9771
9772 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9773 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9774#if 0
9775 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9776 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9777 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9778 hops);
9779 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9780 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9781 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9782 size);
9783#endif
9784 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9785 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9786 }
9787 }
9788 }
9789 return 0;
9790}
9791
9792static int
9793bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9794{
9795 struct bgp_table_stats ts;
9796 unsigned int i;
9797
9798 if (!bgp->rib[afi][safi])
9799 {
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05009800 vty_out (vty, "%% No RIB exists for the AFI/SAFI%s", VTY_NEWLINE);
Paul Jakma2815e612006-09-14 02:56:07 +00009801 return CMD_WARNING;
9802 }
9803
9804 memset (&ts, 0, sizeof (ts));
9805 ts.table = bgp->rib[afi][safi];
9806 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9807
9808 vty_out (vty, "BGP %s RIB statistics%s%s",
9809 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9810
9811 for (i = 0; i < BGP_STATS_MAX; i++)
9812 {
9813 if (!table_stats_strs[i])
9814 continue;
9815
9816 switch (i)
9817 {
9818#if 0
9819 case BGP_STATS_ASPATH_AVGHOPS:
9820 case BGP_STATS_ASPATH_AVGSIZE:
9821 case BGP_STATS_AVGPLEN:
9822 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9823 vty_out (vty, "%12.2f",
9824 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9825 break;
9826#endif
9827 case BGP_STATS_ASPATH_TOTHOPS:
9828 case BGP_STATS_ASPATH_TOTSIZE:
9829 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9830 vty_out (vty, "%12.2f",
9831 ts.counts[i] ?
9832 (float)ts.counts[i] /
9833 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9834 : 0);
9835 break;
9836 case BGP_STATS_TOTPLEN:
9837 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9838 vty_out (vty, "%12.2f",
9839 ts.counts[i] ?
9840 (float)ts.counts[i] /
9841 (float)ts.counts[BGP_STATS_PREFIXES]
9842 : 0);
9843 break;
9844 case BGP_STATS_SPACE:
9845 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9846 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9847 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9848 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009849 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009850 vty_out (vty, "%12.2f%s",
9851 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009852 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009853 VTY_NEWLINE);
9854 vty_out (vty, "%30s: ", "/8 equivalent ");
9855 vty_out (vty, "%12.2f%s",
9856 (float)ts.counts[BGP_STATS_SPACE] /
9857 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9858 VTY_NEWLINE);
9859 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9860 break;
9861 vty_out (vty, "%30s: ", "/24 equivalent ");
9862 vty_out (vty, "%12.2f",
9863 (float)ts.counts[BGP_STATS_SPACE] /
9864 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9865 break;
9866 default:
9867 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9868 vty_out (vty, "%12llu", ts.counts[i]);
9869 }
9870
9871 vty_out (vty, "%s", VTY_NEWLINE);
9872 }
9873 return CMD_SUCCESS;
9874}
9875
9876static int
9877bgp_table_stats_vty (struct vty *vty, const char *name,
9878 const char *afi_str, const char *safi_str)
9879{
9880 struct bgp *bgp;
9881 afi_t afi;
9882 safi_t safi;
9883
9884 if (name)
9885 bgp = bgp_lookup_by_name (name);
9886 else
9887 bgp = bgp_get_default ();
9888
9889 if (!bgp)
9890 {
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05009891 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
Paul Jakma2815e612006-09-14 02:56:07 +00009892 return CMD_WARNING;
9893 }
9894 if (strncmp (afi_str, "ipv", 3) == 0)
9895 {
9896 if (strncmp (afi_str, "ipv4", 4) == 0)
9897 afi = AFI_IP;
9898 else if (strncmp (afi_str, "ipv6", 4) == 0)
9899 afi = AFI_IP6;
9900 else
9901 {
9902 vty_out (vty, "%% Invalid address family %s%s",
9903 afi_str, VTY_NEWLINE);
9904 return CMD_WARNING;
9905 }
Lou Berger298cc2f2016-01-12 13:42:02 -05009906 switch (safi_str[0]) {
9907 case 'm':
9908 safi = SAFI_MULTICAST;
9909 break;
9910 case 'u':
9911 safi = SAFI_UNICAST;
9912 break;
9913 case 'v':
9914 safi = SAFI_MPLS_LABELED_VPN;
9915 break;
9916 case 'e':
9917 safi = SAFI_ENCAP;
9918 break;
9919 default:
9920 vty_out (vty, "%% Invalid subsequent address family %s%s",
Paul Jakma2815e612006-09-14 02:56:07 +00009921 safi_str, VTY_NEWLINE);
Lou Berger298cc2f2016-01-12 13:42:02 -05009922 return CMD_WARNING;
9923 }
Paul Jakma2815e612006-09-14 02:56:07 +00009924 }
9925 else
9926 {
Lou Berger298cc2f2016-01-12 13:42:02 -05009927 vty_out (vty, "%% Invalid address family \"%s\"%s",
Paul Jakma2815e612006-09-14 02:56:07 +00009928 afi_str, VTY_NEWLINE);
9929 return CMD_WARNING;
9930 }
9931
Paul Jakma2815e612006-09-14 02:56:07 +00009932 return bgp_table_stats (vty, bgp, afi, safi);
9933}
9934
9935DEFUN (show_bgp_statistics,
9936 show_bgp_statistics_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -05009937 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +00009938 SHOW_STR
9939 BGP_STR
9940 "Address family\n"
9941 "Address family\n"
9942 "Address Family modifier\n"
9943 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -05009944 "Address Family modifier\n"
9945 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +00009946 "BGP RIB advertisement statistics\n")
9947{
9948 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9949}
9950
Paul Jakma2815e612006-09-14 02:56:07 +00009951DEFUN (show_bgp_statistics_view,
9952 show_bgp_statistics_view_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -05009953 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +00009954 SHOW_STR
9955 BGP_STR
9956 "BGP view\n"
9957 "Address family\n"
9958 "Address family\n"
9959 "Address Family modifier\n"
9960 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -05009961 "Address Family modifier\n"
9962 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +00009963 "BGP RIB advertisement statistics\n")
9964{
9965 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9966}
9967
Lou Berger298cc2f2016-01-12 13:42:02 -05009968#if 0 /* added as options to above command */
Paul Jakma2815e612006-09-14 02:56:07 +00009969ALIAS (show_bgp_statistics_view,
Lou Berger298cc2f2016-01-12 13:42:02 -05009970 show_bgp_statistics_view_encap_cmd,
9971 "show bgp view WORD (ipv4) (encap) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +00009972 SHOW_STR
9973 BGP_STR
9974 "BGP view\n"
9975 "Address family\n"
9976 "Address Family modifier\n"
9977 "BGP RIB advertisement statistics\n")
Lou Berger298cc2f2016-01-12 13:42:02 -05009978#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02009979
Paul Jakmaff7924f2006-09-04 01:10:36 +00009980enum bgp_pcounts
9981{
9982 PCOUNT_ADJ_IN = 0,
9983 PCOUNT_DAMPED,
9984 PCOUNT_REMOVED,
9985 PCOUNT_HISTORY,
9986 PCOUNT_STALE,
9987 PCOUNT_VALID,
9988 PCOUNT_ALL,
9989 PCOUNT_COUNTED,
9990 PCOUNT_PFCNT, /* the figure we display to users */
9991 PCOUNT_MAX,
9992};
9993
9994static const char *pcount_strs[] =
9995{
9996 [PCOUNT_ADJ_IN] = "Adj-in",
9997 [PCOUNT_DAMPED] = "Damped",
9998 [PCOUNT_REMOVED] = "Removed",
9999 [PCOUNT_HISTORY] = "History",
10000 [PCOUNT_STALE] = "Stale",
10001 [PCOUNT_VALID] = "Valid",
10002 [PCOUNT_ALL] = "All RIB",
10003 [PCOUNT_COUNTED] = "PfxCt counted",
10004 [PCOUNT_PFCNT] = "Useable",
10005 [PCOUNT_MAX] = NULL,
10006};
10007
Paul Jakma2815e612006-09-14 02:56:07 +000010008struct peer_pcounts
10009{
10010 unsigned int count[PCOUNT_MAX];
10011 const struct peer *peer;
10012 const struct bgp_table *table;
10013};
10014
Paul Jakmaff7924f2006-09-04 01:10:36 +000010015static int
Paul Jakma2815e612006-09-14 02:56:07 +000010016bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +000010017{
10018 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +000010019 struct peer_pcounts *pc = THREAD_ARG (t);
10020 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010021
Paul Jakma2815e612006-09-14 02:56:07 +000010022 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +000010023 {
10024 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +000010025 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010026
10027 for (ain = rn->adj_in; ain; ain = ain->next)
10028 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +000010029 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010030
Paul Jakmaff7924f2006-09-04 01:10:36 +000010031 for (ri = rn->info; ri; ri = ri->next)
10032 {
10033 char buf[SU_ADDRSTRLEN];
10034
10035 if (ri->peer != peer)
10036 continue;
10037
Paul Jakma2815e612006-09-14 02:56:07 +000010038 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010039
10040 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +000010041 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010042 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +000010043 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010044 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +000010045 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010046 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +000010047 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010048 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +000010049 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +000010050 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +000010051 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010052
10053 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
10054 {
Paul Jakma2815e612006-09-14 02:56:07 +000010055 pc->count[PCOUNT_COUNTED]++;
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 is 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 else
10066 {
Paul Jakma1a392d42006-09-07 00:24:49 +000010067 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +000010068 plog_warn (peer->log,
10069 "%s [pcount] %s/%d not counted but flags 0x%x",
10070 peer->host,
10071 inet_ntop(rn->p.family, &rn->p.u.prefix,
10072 buf, SU_ADDRSTRLEN),
10073 rn->p.prefixlen,
10074 ri->flags);
10075 }
10076 }
10077 }
Paul Jakma2815e612006-09-14 02:56:07 +000010078 return 0;
10079}
Paul Jakmaff7924f2006-09-04 01:10:36 +000010080
Paul Jakma2815e612006-09-14 02:56:07 +000010081static int
10082bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
10083{
10084 struct peer_pcounts pcounts = { .peer = peer };
10085 unsigned int i;
10086
10087 if (!peer || !peer->bgp || !peer->afc[afi][safi]
10088 || !peer->bgp->rib[afi][safi])
10089 {
10090 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10091 return CMD_WARNING;
10092 }
10093
10094 memset (&pcounts, 0, sizeof(pcounts));
10095 pcounts.peer = peer;
10096 pcounts.table = peer->bgp->rib[afi][safi];
10097
10098 /* in-place call via thread subsystem so as to record execution time
10099 * stats for the thread-walk (i.e. ensure this can't be blamed on
10100 * on just vty_read()).
10101 */
10102 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
10103
Paul Jakmaff7924f2006-09-04 01:10:36 +000010104 vty_out (vty, "Prefix counts for %s, %s%s",
10105 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
10106 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
10107 vty_out (vty, "%sCounts from RIB table walk:%s%s",
10108 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
10109
10110 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +000010111 vty_out (vty, "%20s: %-10d%s",
10112 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +000010113
Paul Jakma2815e612006-09-14 02:56:07 +000010114 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +000010115 {
10116 vty_out (vty, "%s [pcount] PfxCt drift!%s",
10117 peer->host, VTY_NEWLINE);
10118 vty_out (vty, "Please report this bug, with the above command output%s",
10119 VTY_NEWLINE);
10120 }
10121
10122 return CMD_SUCCESS;
10123}
10124
Lou Berger651b4022016-01-12 13:42:07 -050010125#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000010126DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
10127 show_bgp_ipv6_neighbor_prefix_counts_cmd,
10128 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
10129 SHOW_STR
10130 BGP_STR
10131 "Address family\n"
10132 "Detailed information on TCP and BGP neighbor connections\n"
10133 "Neighbor to display information about\n"
10134 "Neighbor to display information about\n"
10135 "Display detailed prefix count information\n")
10136{
10137 struct peer *peer;
10138
10139 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10140 if (! peer)
10141 return CMD_WARNING;
10142
10143 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
10144}
Lou Berger651b4022016-01-12 13:42:07 -050010145#endif
Paul Jakmaff7924f2006-09-04 01:10:36 +000010146
Lou Berger651b4022016-01-12 13:42:07 -050010147DEFUN (show_bgp_ipv4_safi_neighbor_prefix_counts,
10148 show_bgp_ipv4_safi_neighbor_prefix_counts_cmd,
10149 "show bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
Paul Jakmaff7924f2006-09-04 01:10:36 +000010150 SHOW_STR
Paul Jakmaff7924f2006-09-04 01:10:36 +000010151 BGP_STR
10152 "Address family\n"
10153 "Address Family modifier\n"
10154 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050010155 "Address Family modifier\n"
10156 "Address Family modifier\n"
Paul Jakmaff7924f2006-09-04 01:10:36 +000010157 "Detailed information on TCP and BGP neighbor connections\n"
10158 "Neighbor to display information about\n"
10159 "Neighbor to display information about\n"
10160 "Display detailed prefix count information\n")
10161{
10162 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050010163 safi_t safi;
10164
10165 if (bgp_parse_safi(argv[0], &safi)) {
10166 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10167 return CMD_WARNING;
10168 }
Paul Jakmaff7924f2006-09-04 01:10:36 +000010169
10170 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10171 if (! peer)
10172 return CMD_WARNING;
10173
Lou Berger651b4022016-01-12 13:42:07 -050010174 return bgp_peer_counts (vty, peer, AFI_IP, safi);
Paul Jakmaff7924f2006-09-04 01:10:36 +000010175}
Lou Berger651b4022016-01-12 13:42:07 -050010176#ifdef HAVE_IPV6
10177DEFUN (show_bgp_ipv6_safi_neighbor_prefix_counts,
10178 show_bgp_ipv6_safi_neighbor_prefix_counts_cmd,
10179 "show bgp ipv6 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
10180 SHOW_STR
10181 BGP_STR
10182 "Address family\n"
10183 "Address Family modifier\n"
10184 "Address Family modifier\n"
10185 "Address Family modifier\n"
10186 "Address Family modifier\n"
10187 "Detailed information on TCP and BGP neighbor connections\n"
10188 "Neighbor to display information about\n"
10189 "Neighbor to display information about\n"
10190 "Display detailed prefix count information\n")
10191{
10192 struct peer *peer;
10193 safi_t safi;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010194
Lou Berger651b4022016-01-12 13:42:07 -050010195 if (bgp_parse_safi(argv[0], &safi)) {
10196 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10197 return CMD_WARNING;
10198 }
10199
10200 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10201 if (! peer)
10202 return CMD_WARNING;
10203
10204 return bgp_peer_counts (vty, peer, AFI_IP6, safi);
10205}
10206#endif
10207
10208DEFUN (show_ip_bgp_encap_neighbor_prefix_counts,
10209 show_ip_bgp_encap_neighbor_prefix_counts_cmd,
10210 "show ip bgp encap all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
Paul Jakmaff7924f2006-09-04 01:10:36 +000010211 SHOW_STR
10212 IP_STR
10213 BGP_STR
10214 "Address family\n"
10215 "Address Family modifier\n"
10216 "Address Family modifier\n"
10217 "Detailed information on TCP and BGP neighbor connections\n"
10218 "Neighbor to display information about\n"
10219 "Neighbor to display information about\n"
10220 "Display detailed prefix count information\n")
10221{
10222 struct peer *peer;
10223
10224 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10225 if (! peer)
10226 return CMD_WARNING;
10227
Lou Berger651b4022016-01-12 13:42:07 -050010228 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_ENCAP);
Paul Jakmaff7924f2006-09-04 01:10:36 +000010229}
10230
10231
paul94f2b392005-06-28 12:44:16 +000010232static void
paul718e3742002-12-13 20:15:29 +000010233show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
10234 int in)
10235{
10236 struct bgp_table *table;
10237 struct bgp_adj_in *ain;
10238 struct bgp_adj_out *adj;
10239 unsigned long output_count;
10240 struct bgp_node *rn;
10241 int header1 = 1;
10242 struct bgp *bgp;
10243 int header2 = 1;
10244
paulbb46e942003-10-24 19:02:03 +000010245 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +000010246
10247 if (! bgp)
10248 return;
10249
10250 table = bgp->rib[afi][safi];
10251
10252 output_count = 0;
10253
10254 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
10255 PEER_STATUS_DEFAULT_ORIGINATE))
10256 {
10257 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 +000010258 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10259 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010260
10261 vty_out (vty, "Originating default network 0.0.0.0%s%s",
10262 VTY_NEWLINE, VTY_NEWLINE);
10263 header1 = 0;
10264 }
10265
10266 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
10267 if (in)
10268 {
10269 for (ain = rn->adj_in; ain; ain = ain->next)
10270 if (ain->peer == peer)
10271 {
10272 if (header1)
10273 {
10274 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 +000010275 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10276 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010277 header1 = 0;
10278 }
10279 if (header2)
10280 {
10281 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
10282 header2 = 0;
10283 }
10284 if (ain->attr)
10285 {
10286 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
10287 output_count++;
10288 }
10289 }
10290 }
10291 else
10292 {
10293 for (adj = rn->adj_out; adj; adj = adj->next)
10294 if (adj->peer == peer)
10295 {
10296 if (header1)
10297 {
10298 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 +000010299 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10300 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010301 header1 = 0;
10302 }
10303 if (header2)
10304 {
10305 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
10306 header2 = 0;
10307 }
10308 if (adj->attr)
10309 {
10310 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
10311 output_count++;
10312 }
10313 }
10314 }
10315
10316 if (output_count != 0)
10317 vty_out (vty, "%sTotal number of prefixes %ld%s",
10318 VTY_NEWLINE, output_count, VTY_NEWLINE);
10319}
10320
paul94f2b392005-06-28 12:44:16 +000010321static int
paulbb46e942003-10-24 19:02:03 +000010322peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
10323{
paul718e3742002-12-13 20:15:29 +000010324 if (! peer || ! peer->afc[afi][safi])
10325 {
10326 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10327 return CMD_WARNING;
10328 }
10329
10330 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10331 {
10332 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
10333 VTY_NEWLINE);
10334 return CMD_WARNING;
10335 }
10336
10337 show_adj_route (vty, peer, afi, safi, in);
10338
10339 return CMD_SUCCESS;
10340}
10341
Lou Berger651b4022016-01-12 13:42:07 -050010342DEFUN (show_bgp_ipv4_safi_neighbor_advertised_route,
10343 show_bgp_ipv4_safi_neighbor_advertised_route_cmd,
10344 "show bgp ipv4 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010345 SHOW_STR
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010346 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010347 "Address Family modifier\n"
10348 "Address Family modifier\n"
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010349 "Detailed information on TCP and BGP neighbor connections\n"
10350 "Neighbor to display information about\n"
10351 "Neighbor to display information about\n"
10352 "Display the routes advertised to a BGP neighbor\n")
10353{
10354 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050010355 safi_t safi;
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010356
Lou Berger651b4022016-01-12 13:42:07 -050010357 if (bgp_parse_safi(argv[0], &safi)) {
10358 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010359 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050010360 }
paul718e3742002-12-13 20:15:29 +000010361
paulbb46e942003-10-24 19:02:03 +000010362 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10363 if (! peer)
10364 return CMD_WARNING;
10365
Lou Berger651b4022016-01-12 13:42:07 -050010366 return peer_adj_routes (vty, peer, AFI_IP, safi, 0);
10367}
10368#ifdef HAVE_IPV6
10369DEFUN (show_bgp_ipv6_safi_neighbor_advertised_route,
10370 show_bgp_ipv6_safi_neighbor_advertised_route_cmd,
10371 "show bgp ipv6 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10372 SHOW_STR
10373 BGP_STR
10374 "Address Family modifier\n"
10375 "Address Family modifier\n"
10376 "Address Family modifier\n"
10377 "Detailed information on TCP and BGP neighbor connections\n"
10378 "Neighbor to display information about\n"
10379 "Neighbor to display information about\n"
10380 "Display the routes advertised to a BGP neighbor\n")
10381{
10382 struct peer *peer;
10383 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000010384
Lou Berger651b4022016-01-12 13:42:07 -050010385 if (bgp_parse_safi(argv[0], &safi)) {
10386 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10387 return CMD_WARNING;
10388 }
10389
10390 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10391 if (! peer)
10392 return CMD_WARNING;
10393
10394 return peer_adj_routes (vty, peer, AFI_IP6, safi, 0);
paul718e3742002-12-13 20:15:29 +000010395}
10396
paulbb46e942003-10-24 19:02:03 +000010397DEFUN (show_bgp_view_neighbor_advertised_route,
Lou Berger651b4022016-01-12 13:42:07 -050010398 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10399 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
paulbb46e942003-10-24 19:02:03 +000010400 SHOW_STR
10401 BGP_STR
10402 "BGP view\n"
10403 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050010404 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000010405 "Detailed information on TCP and BGP neighbor connections\n"
10406 "Neighbor to display information about\n"
10407 "Neighbor to display information about\n"
10408 "Display the routes advertised to a BGP neighbor\n")
10409{
10410 struct peer *peer;
10411
10412 if (argc == 2)
10413 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10414 else
10415 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10416
10417 if (! peer)
10418 return CMD_WARNING;
10419
10420 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10421}
10422
Lou Berger651b4022016-01-12 13:42:07 -050010423DEFUN (show_bgp_view_neighbor_received_routes,
10424 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10425 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
paulbb46e942003-10-24 19:02:03 +000010426 SHOW_STR
10427 BGP_STR
10428 "BGP view\n"
10429 "View name\n"
10430 "Address family\n"
10431 "Detailed information on TCP and BGP neighbor connections\n"
10432 "Neighbor to display information about\n"
10433 "Neighbor to display information about\n"
paulbb46e942003-10-24 19:02:03 +000010434 "Display the received routes from neighbor\n")
10435{
10436 struct peer *peer;
10437
10438 if (argc == 2)
10439 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10440 else
10441 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10442
10443 if (! peer)
10444 return CMD_WARNING;
10445
10446 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10447}
10448
paulbb46e942003-10-24 19:02:03 +000010449ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010450 show_bgp_ipv6_neighbor_advertised_route_cmd,
10451 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10452 SHOW_STR
10453 BGP_STR
10454 "Address family\n"
10455 "Detailed information on TCP and BGP neighbor connections\n"
10456 "Neighbor to display information about\n"
10457 "Neighbor to display information about\n"
10458 "Display the routes advertised to a BGP neighbor\n")
10459
paul718e3742002-12-13 20:15:29 +000010460#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010461
Lou Berger651b4022016-01-12 13:42:07 -050010462
10463DEFUN (show_bgp_ipv4_safi_neighbor_received_routes,
10464 show_bgp_ipv4_safi_neighbor_received_routes_cmd,
10465 "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 +010010466 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010467 BGP_STR
10468 "Address family\n"
10469 "Address Family modifier\n"
10470 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050010471 "Address Family modifier\n"
10472 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000010473 "Detailed information on TCP and BGP neighbor connections\n"
10474 "Neighbor to display information about\n"
10475 "Neighbor to display information about\n"
10476 "Display the received routes from neighbor\n")
10477{
paulbb46e942003-10-24 19:02:03 +000010478 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050010479 safi_t safi;
10480
10481 if (bgp_parse_safi(argv[0], &safi)) {
10482 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10483 return CMD_WARNING;
10484 }
paul718e3742002-12-13 20:15:29 +000010485
paulbb46e942003-10-24 19:02:03 +000010486 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10487 if (! peer)
10488 return CMD_WARNING;
10489
Lou Berger651b4022016-01-12 13:42:07 -050010490 return peer_adj_routes (vty, peer, AFI_IP, safi, 1);
paul718e3742002-12-13 20:15:29 +000010491}
Lou Berger651b4022016-01-12 13:42:07 -050010492#ifdef HAVE_IPV6
10493DEFUN (show_bgp_ipv6_safi_neighbor_received_routes,
10494 show_bgp_ipv6_safi_neighbor_received_routes_cmd,
10495 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) received-routes",
10496 SHOW_STR
10497 BGP_STR
10498 "Address family\n"
10499 "Address Family modifier\n"
10500 "Address Family modifier\n"
10501 "Address Family modifier\n"
10502 "Address Family modifier\n"
10503 "Detailed information on TCP and BGP neighbor connections\n"
10504 "Neighbor to display information about\n"
10505 "Neighbor to display information about\n"
10506 "Display the received routes from neighbor\n")
10507{
10508 struct peer *peer;
10509 safi_t safi;
10510
10511 if (bgp_parse_safi(argv[0], &safi)) {
10512 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10513 return CMD_WARNING;
10514 }
10515
10516 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10517 if (! peer)
10518 return CMD_WARNING;
10519
10520 return peer_adj_routes (vty, peer, AFI_IP6, safi, 1);
10521}
10522#endif
paul718e3742002-12-13 20:15:29 +000010523
Michael Lambert95cbbd22010-07-23 14:43:04 -040010524DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10525 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010526 "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 -040010527 SHOW_STR
10528 BGP_STR
10529 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010530 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010531 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010532 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010533 "Address family modifier\n"
10534 "Address family modifier\n"
10535 "Detailed information on TCP and BGP neighbor connections\n"
10536 "Neighbor to display information about\n"
10537 "Neighbor to display information about\n"
10538 "Display the advertised routes to neighbor\n"
10539 "Display the received routes from neighbor\n")
10540{
10541 int afi;
10542 int safi;
10543 int in;
10544 struct peer *peer;
10545
David Lamparter94bad672015-03-03 08:52:22 +010010546 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010547
10548 if (! peer)
10549 return CMD_WARNING;
10550
Michael Lambert95cbbd22010-07-23 14:43:04 -040010551 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10552 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10553 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010554
10555 return peer_adj_routes (vty, peer, afi, safi, in);
10556}
10557
Lou Berger651b4022016-01-12 13:42:07 -050010558DEFUN (show_bgp_ipv4_safi_neighbor_received_prefix_filter,
10559 show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd,
10560 "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 +000010561 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010562 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010563 IP_STR
10564 "Address Family modifier\n"
10565 "Address Family modifier\n"
10566 "Address Family modifier\n"
10567 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000010568 "Detailed information on TCP and BGP neighbor connections\n"
10569 "Neighbor to display information about\n"
10570 "Neighbor to display information about\n"
10571 "Display information received from a BGP neighbor\n"
10572 "Display the prefixlist filter\n")
10573{
10574 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010575 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010576 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010577 int count, ret;
Lou Berger651b4022016-01-12 13:42:07 -050010578 safi_t safi;
paul718e3742002-12-13 20:15:29 +000010579
Lou Berger651b4022016-01-12 13:42:07 -050010580 if (bgp_parse_safi(argv[0], &safi)) {
10581 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010582 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050010583 }
paul718e3742002-12-13 20:15:29 +000010584
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010585 ret = str2sockunion (argv[1], &su);
10586 if (ret < 0)
10587 {
10588 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10589 return CMD_WARNING;
10590 }
paul718e3742002-12-13 20:15:29 +000010591
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010592 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010593 if (! peer)
10594 return CMD_WARNING;
10595
Lou Berger651b4022016-01-12 13:42:07 -050010596 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, safi);
10597 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10598 if (count) {
10599 vty_out (vty, "Address family: IPv4 %s%s", safi2str(safi), VTY_NEWLINE);
10600 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10601 }
paul718e3742002-12-13 20:15:29 +000010602
10603 return CMD_SUCCESS;
10604}
paul718e3742002-12-13 20:15:29 +000010605#ifdef HAVE_IPV6
Lou Berger651b4022016-01-12 13:42:07 -050010606DEFUN (show_bgp_ipv6_safi_neighbor_received_prefix_filter,
10607 show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd,
10608 "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 +000010609 SHOW_STR
10610 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010611 IP_STR
10612 "Address Family modifier\n"
10613 "Address Family modifier\n"
10614 "Address Family modifier\n"
10615 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000010616 "Detailed information on TCP and BGP neighbor connections\n"
10617 "Neighbor to display information about\n"
10618 "Neighbor to display information about\n"
Lou Berger651b4022016-01-12 13:42:07 -050010619 "Display information received from a BGP neighbor\n"
10620 "Display the prefixlist filter\n")
10621{
10622 char name[BUFSIZ];
10623 union sockunion su;
10624 struct peer *peer;
10625 int count, ret;
10626 safi_t safi;
10627
10628 if (bgp_parse_safi(argv[0], &safi)) {
10629 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10630 return CMD_WARNING;
10631 }
10632
10633 ret = str2sockunion (argv[1], &su);
10634 if (ret < 0)
10635 {
10636 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10637 return CMD_WARNING;
10638 }
10639
10640 peer = peer_lookup (NULL, &su);
10641 if (! peer)
10642 return CMD_WARNING;
10643
10644 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, safi);
10645 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10646 if (count) {
10647 vty_out (vty, "Address family: IPv6 %s%s", safi2str(safi), VTY_NEWLINE);
10648 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10649 }
10650
10651 return CMD_SUCCESS;
10652}
paul718e3742002-12-13 20:15:29 +000010653
paulbb46e942003-10-24 19:02:03 +000010654ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010655 show_bgp_ipv6_neighbor_received_routes_cmd,
10656 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10657 SHOW_STR
10658 BGP_STR
10659 "Address family\n"
10660 "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 the received routes from neighbor\n")
10664
10665DEFUN (show_bgp_neighbor_received_prefix_filter,
Lou Berger651b4022016-01-12 13:42:07 -050010666 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10667 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
paul718e3742002-12-13 20:15:29 +000010668 SHOW_STR
10669 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010670 "Address family\n"
paul718e3742002-12-13 20:15:29 +000010671 "Detailed information on TCP and BGP neighbor connections\n"
10672 "Neighbor to display information about\n"
10673 "Neighbor to display information about\n"
10674 "Display information received from a BGP neighbor\n"
10675 "Display the prefixlist filter\n")
10676{
10677 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010678 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010679 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010680 int count, ret;
paul718e3742002-12-13 20:15:29 +000010681
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010682 ret = str2sockunion (argv[0], &su);
10683 if (ret < 0)
10684 {
10685 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10686 return CMD_WARNING;
10687 }
paul718e3742002-12-13 20:15:29 +000010688
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010689 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010690 if (! peer)
10691 return CMD_WARNING;
10692
10693 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10694 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10695 if (count)
10696 {
10697 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10698 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10699 }
10700
10701 return CMD_SUCCESS;
10702}
10703
paulbb46e942003-10-24 19:02:03 +000010704DEFUN (show_bgp_view_neighbor_received_prefix_filter,
Lou Berger651b4022016-01-12 13:42:07 -050010705 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10706 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
paulbb46e942003-10-24 19:02:03 +000010707 SHOW_STR
10708 BGP_STR
10709 "BGP view\n"
10710 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050010711 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000010712 "Detailed information on TCP and BGP neighbor connections\n"
10713 "Neighbor to display information about\n"
10714 "Neighbor to display information about\n"
10715 "Display information received from a BGP neighbor\n"
10716 "Display the prefixlist filter\n")
10717{
10718 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010719 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010720 struct peer *peer;
10721 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010722 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010723
10724 /* BGP structure lookup. */
10725 bgp = bgp_lookup_by_name (argv[0]);
10726 if (bgp == NULL)
10727 {
10728 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10729 return CMD_WARNING;
10730 }
10731
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010732 ret = str2sockunion (argv[1], &su);
10733 if (ret < 0)
10734 {
10735 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10736 return CMD_WARNING;
10737 }
paulbb46e942003-10-24 19:02:03 +000010738
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010739 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010740 if (! peer)
10741 return CMD_WARNING;
10742
10743 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10744 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10745 if (count)
10746 {
10747 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10748 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10749 }
10750
10751 return CMD_SUCCESS;
10752}
paul718e3742002-12-13 20:15:29 +000010753#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010754
paul94f2b392005-06-28 12:44:16 +000010755static int
paulbb46e942003-10-24 19:02:03 +000010756bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010757 safi_t safi, enum bgp_show_type type)
10758{
paul718e3742002-12-13 20:15:29 +000010759 if (! peer || ! peer->afc[afi][safi])
10760 {
10761 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010762 return CMD_WARNING;
10763 }
10764
ajs5a646652004-11-05 01:25:55 +000010765 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010766}
10767
Lou Berger651b4022016-01-12 13:42:07 -050010768DEFUN (show_bgp_ipv4_safi_neighbor_flap,
10769 show_bgp_ipv4_safi_neighbor_flap_cmd,
10770 "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paul718e3742002-12-13 20:15:29 +000010771 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010772 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010773 "Address Family Modifier\n"
10774 "Address Family Modifier\n"
10775 "Address Family Modifier\n"
10776 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +000010777 "Detailed information on TCP and BGP neighbor connections\n"
10778 "Neighbor to display information about\n"
10779 "Neighbor to display information about\n"
10780 "Display flap statistics of the routes learned from neighbor\n")
10781{
paulbb46e942003-10-24 19:02:03 +000010782 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050010783 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000010784
Lou Berger651b4022016-01-12 13:42:07 -050010785 if (bgp_parse_safi(argv[0], &safi)) {
10786 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10787 return CMD_WARNING;
10788 }
10789
10790 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulbb46e942003-10-24 19:02:03 +000010791 if (! peer)
10792 return CMD_WARNING;
10793
Lou Berger651b4022016-01-12 13:42:07 -050010794 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000010795 bgp_show_type_flap_neighbor);
10796}
Lou Berger651b4022016-01-12 13:42:07 -050010797#ifdef HAVE_IPV6
10798DEFUN (show_bgp_ipv6_safi_neighbor_flap,
10799 show_bgp_ipv6_safi_neighbor_flap_cmd,
10800 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paul718e3742002-12-13 20:15:29 +000010801 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010802 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010803 "Address Family Modifier\n"
10804 "Address Family Modifier\n"
10805 "Address Family Modifier\n"
10806 "Address Family Modifier\n"
10807 "Detailed information on TCP and BGP neighbor connections\n"
10808 "Neighbor to display information about\n"
10809 "Neighbor to display information about\n"
10810 "Display flap statistics of the routes learned from neighbor\n")
10811{
10812 struct peer *peer;
10813 safi_t safi;
10814
10815 if (bgp_parse_safi(argv[0], &safi)) {
10816 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10817 return CMD_WARNING;
10818 }
10819
10820 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10821 if (! peer)
10822 return CMD_WARNING;
10823
10824 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
10825 bgp_show_type_flap_neighbor);
10826}
10827#endif
10828
10829DEFUN (show_bgp_ipv4_safi_neighbor_damp,
10830 show_bgp_ipv4_safi_neighbor_damp_cmd,
10831 "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10832 SHOW_STR
10833 BGP_STR
10834 "Address Family Modifier\n"
10835 "Address Family Modifier\n"
10836 "Address Family Modifier\n"
10837 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +000010838 "Detailed information on TCP and BGP neighbor connections\n"
10839 "Neighbor to display information about\n"
10840 "Neighbor to display information about\n"
10841 "Display the dampened routes received from neighbor\n")
10842{
paulbb46e942003-10-24 19:02:03 +000010843 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050010844 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000010845
Lou Berger651b4022016-01-12 13:42:07 -050010846 if (bgp_parse_safi(argv[0], &safi)) {
10847 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10848 return CMD_WARNING;
10849 }
10850
10851 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulbb46e942003-10-24 19:02:03 +000010852 if (! peer)
10853 return CMD_WARNING;
10854
Lou Berger651b4022016-01-12 13:42:07 -050010855 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000010856 bgp_show_type_damp_neighbor);
10857}
Lou Berger651b4022016-01-12 13:42:07 -050010858#ifdef HAVE_IPV6
10859DEFUN (show_bgp_ipv6_safi_neighbor_damp,
10860 show_bgp_ipv6_safi_neighbor_damp_cmd,
10861 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) dampened-routes",
paul718e3742002-12-13 20:15:29 +000010862 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -050010863 BGP_STR
10864 "Address Family Modifier\n"
10865 "Address Family Modifier\n"
10866 "Address Family Modifier\n"
10867 "Address Family Modifier\n"
10868 "Detailed information on TCP and BGP neighbor connections\n"
10869 "Neighbor to display information about\n"
10870 "Neighbor to display information about\n"
10871 "Display the dampened routes received from neighbor\n")
10872{
10873 struct peer *peer;
10874 safi_t safi;
10875
10876 if (bgp_parse_safi(argv[0], &safi)) {
10877 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10878 return CMD_WARNING;
10879 }
10880
10881 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10882 if (! peer)
10883 return CMD_WARNING;
10884
10885 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
10886 bgp_show_type_damp_neighbor);
10887}
10888#endif
10889
10890DEFUN (show_bgp_ipv4_safi_neighbor_routes,
10891 show_bgp_ipv4_safi_neighbor_routes_cmd,
10892 "show bgp ipv4 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) routes",
10893 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010894 BGP_STR
10895 "Address family\n"
10896 "Address Family modifier\n"
10897 "Address Family modifier\n"
10898 "Detailed information on TCP and BGP neighbor connections\n"
10899 "Neighbor to display information about\n"
10900 "Neighbor to display information about\n"
10901 "Display routes learned from neighbor\n")
10902{
paulbb46e942003-10-24 19:02:03 +000010903 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050010904 safi_t safi;
10905
10906 if (bgp_parse_safi(argv[0], &safi)) {
10907 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10908 return CMD_WARNING;
10909 }
paulbb46e942003-10-24 19:02:03 +000010910
10911 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10912 if (! peer)
10913 return CMD_WARNING;
10914
Lou Berger651b4022016-01-12 13:42:07 -050010915 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000010916 bgp_show_type_neighbor);
10917}
Lou Berger651b4022016-01-12 13:42:07 -050010918#ifdef HAVE_IPV6
10919DEFUN (show_bgp_ipv6_safi_neighbor_routes,
10920 show_bgp_ipv6_safi_neighbor_routes_cmd,
10921 "show bgp ipv6 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) routes",
paulfee0f4c2004-09-13 05:12:46 +000010922 SHOW_STR
paulfee0f4c2004-09-13 05:12:46 +000010923 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010924 "Address family\n"
10925 "Address Family modifier\n"
10926 "Address Family modifier\n"
10927 "Detailed information on TCP and BGP neighbor connections\n"
10928 NEIGHBOR_ADDR_STR
10929 NEIGHBOR_ADDR_STR
10930 "Display routes learned from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000010931{
paulfee0f4c2004-09-13 05:12:46 +000010932 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050010933 safi_t safi;
paulfee0f4c2004-09-13 05:12:46 +000010934
Lou Berger651b4022016-01-12 13:42:07 -050010935 if (bgp_parse_safi(argv[0], &safi)) {
10936 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10937 return CMD_WARNING;
10938 }
paulfee0f4c2004-09-13 05:12:46 +000010939
Lou Berger651b4022016-01-12 13:42:07 -050010940 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulfee0f4c2004-09-13 05:12:46 +000010941 if (! peer)
10942 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050010943
10944 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
10945 bgp_show_type_neighbor);
paulfee0f4c2004-09-13 05:12:46 +000010946}
Lou Berger651b4022016-01-12 13:42:07 -050010947#endif
paulfee0f4c2004-09-13 05:12:46 +000010948
Michael Lambert95cbbd22010-07-23 14:43:04 -040010949DEFUN (show_bgp_view_ipv4_safi_rsclient,
10950 show_bgp_view_ipv4_safi_rsclient_cmd,
10951 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10952 SHOW_STR
10953 BGP_STR
10954 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010955 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010956 "Address family\n"
10957 "Address Family modifier\n"
10958 "Address Family modifier\n"
10959 "Information about Route Server Client\n"
10960 NEIGHBOR_ADDR_STR)
10961{
10962 struct bgp_table *table;
10963 struct peer *peer;
10964 safi_t safi;
10965
10966 if (argc == 3) {
10967 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10968 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10969 } else {
10970 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10971 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10972 }
10973
10974 if (! peer)
10975 return CMD_WARNING;
10976
10977 if (! peer->afc[AFI_IP][safi])
10978 {
10979 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10980 VTY_NEWLINE);
10981 return CMD_WARNING;
10982 }
10983
10984 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10985 PEER_FLAG_RSERVER_CLIENT))
10986 {
10987 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10988 VTY_NEWLINE);
10989 return CMD_WARNING;
10990 }
10991
10992 table = peer->rib[AFI_IP][safi];
10993
10994 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10995}
10996
10997ALIAS (show_bgp_view_ipv4_safi_rsclient,
10998 show_bgp_ipv4_safi_rsclient_cmd,
10999 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11000 SHOW_STR
11001 BGP_STR
11002 "Address family\n"
11003 "Address Family modifier\n"
11004 "Address Family modifier\n"
11005 "Information about Route Server Client\n"
11006 NEIGHBOR_ADDR_STR)
11007
Lou Berger651b4022016-01-12 13:42:07 -050011008#if 0 /* from 0.99.24.1 merge */
paulfee0f4c2004-09-13 05:12:46 +000011009DEFUN (show_ip_bgp_view_rsclient_route,
11010 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010011011 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000011012 SHOW_STR
11013 IP_STR
11014 BGP_STR
11015 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011016 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011017 "Information about Route Server Client\n"
11018 NEIGHBOR_ADDR_STR
11019 "Network in the BGP routing table to display\n")
11020{
11021 struct bgp *bgp;
11022 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050011023#endif
paulfee0f4c2004-09-13 05:12:46 +000011024
Michael Lambert95cbbd22010-07-23 14:43:04 -040011025DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
11026 show_bgp_view_ipv4_safi_rsclient_route_cmd,
11027 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
11028 SHOW_STR
11029 BGP_STR
11030 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011031 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011032 "Address family\n"
11033 "Address Family modifier\n"
11034 "Address Family modifier\n"
11035 "Information about Route Server Client\n"
11036 NEIGHBOR_ADDR_STR
11037 "Network in the BGP routing table to display\n")
11038{
11039 struct bgp *bgp;
11040 struct peer *peer;
11041 safi_t safi;
11042
11043 /* BGP structure lookup. */
11044 if (argc == 4)
11045 {
11046 bgp = bgp_lookup_by_name (argv[0]);
11047 if (bgp == NULL)
11048 {
11049 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11050 return CMD_WARNING;
11051 }
11052 }
11053 else
11054 {
11055 bgp = bgp_get_default ();
11056 if (bgp == NULL)
11057 {
11058 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11059 return CMD_WARNING;
11060 }
11061 }
11062
11063 if (argc == 4) {
11064 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11065 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11066 } else {
11067 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11068 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11069 }
11070
11071 if (! peer)
11072 return CMD_WARNING;
11073
11074 if (! peer->afc[AFI_IP][safi])
11075 {
11076 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11077 VTY_NEWLINE);
11078 return CMD_WARNING;
11079}
11080
11081 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11082 PEER_FLAG_RSERVER_CLIENT))
11083 {
11084 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11085 VTY_NEWLINE);
11086 return CMD_WARNING;
11087 }
11088
11089 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11090 (argc == 4) ? argv[3] : argv[2],
11091 AFI_IP, safi, NULL, 0);
11092}
11093
11094ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
11095 show_bgp_ipv4_safi_rsclient_route_cmd,
11096 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
11097 SHOW_STR
11098 BGP_STR
11099 "Address family\n"
11100 "Address Family modifier\n"
11101 "Address Family modifier\n"
11102 "Information about Route Server Client\n"
11103 NEIGHBOR_ADDR_STR
11104 "Network in the BGP routing table to display\n")
11105
Lou Berger651b4022016-01-12 13:42:07 -050011106#if 0 /* from 0.99.24.1 merge */
paulfee0f4c2004-09-13 05:12:46 +000011107DEFUN (show_ip_bgp_view_rsclient_prefix,
11108 show_ip_bgp_view_rsclient_prefix_cmd,
11109 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11110 SHOW_STR
11111 IP_STR
11112 BGP_STR
11113 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011114 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011115 "Information about Route Server Client\n"
11116 NEIGHBOR_ADDR_STR
11117 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11118{
11119 struct bgp *bgp;
11120 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050011121#endif
paulfee0f4c2004-09-13 05:12:46 +000011122
Michael Lambert95cbbd22010-07-23 14:43:04 -040011123DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
11124 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
11125 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11126 SHOW_STR
11127 BGP_STR
11128 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011129 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011130 "Address family\n"
11131 "Address Family modifier\n"
11132 "Address Family modifier\n"
11133 "Information about Route Server Client\n"
11134 NEIGHBOR_ADDR_STR
11135 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11136{
11137 struct bgp *bgp;
11138 struct peer *peer;
11139 safi_t safi;
11140
11141 /* BGP structure lookup. */
11142 if (argc == 4)
11143 {
11144 bgp = bgp_lookup_by_name (argv[0]);
11145 if (bgp == NULL)
11146 {
11147 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11148 return CMD_WARNING;
11149 }
11150 }
11151 else
11152 {
11153 bgp = bgp_get_default ();
11154 if (bgp == NULL)
11155 {
11156 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11157 return CMD_WARNING;
11158 }
11159 }
11160
11161 if (argc == 4) {
11162 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11163 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11164 } else {
11165 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11166 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11167 }
11168
11169 if (! peer)
11170 return CMD_WARNING;
11171
11172 if (! peer->afc[AFI_IP][safi])
11173 {
11174 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11175 VTY_NEWLINE);
11176 return CMD_WARNING;
11177}
11178
11179 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11180 PEER_FLAG_RSERVER_CLIENT))
11181{
11182 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11183 VTY_NEWLINE);
11184 return CMD_WARNING;
11185 }
11186
11187 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11188 (argc == 4) ? argv[3] : argv[2],
11189 AFI_IP, safi, NULL, 1);
11190}
11191
11192ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11193 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11194 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11195 SHOW_STR
11196 BGP_STR
11197 "Address family\n"
11198 "Address Family modifier\n"
11199 "Address Family modifier\n"
11200 "Information about Route Server Client\n"
11201 NEIGHBOR_ADDR_STR
11202 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011203
paul718e3742002-12-13 20:15:29 +000011204#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011205DEFUN (show_bgp_view_neighbor_routes,
Lou Berger651b4022016-01-12 13:42:07 -050011206 show_bgp_view_ipv6_neighbor_routes_cmd,
11207 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
paulbb46e942003-10-24 19:02:03 +000011208 SHOW_STR
11209 BGP_STR
11210 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011211 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050011212 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000011213 "Detailed information on TCP and BGP neighbor connections\n"
11214 "Neighbor to display information about\n"
11215 "Neighbor to display information about\n"
11216 "Display routes learned from neighbor\n")
11217{
11218 struct peer *peer;
11219
11220 if (argc == 2)
11221 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11222 else
11223 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11224
11225 if (! peer)
11226 return CMD_WARNING;
11227
11228 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11229 bgp_show_type_neighbor);
11230}
11231
Lou Berger651b4022016-01-12 13:42:07 -050011232DEFUN (show_bgp_view_neighbor_damp,
11233 show_bgp_view_ipv6_neighbor_damp_cmd,
11234 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
paulbb46e942003-10-24 19:02:03 +000011235 SHOW_STR
11236 BGP_STR
11237 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011238 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011239 "Address family\n"
11240 "Detailed information on TCP and BGP neighbor connections\n"
11241 "Neighbor to display information about\n"
11242 "Neighbor to display information about\n"
paulbb46e942003-10-24 19:02:03 +000011243 "Display the dampened routes received from neighbor\n")
11244{
11245 struct peer *peer;
11246
11247 if (argc == 2)
11248 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11249 else
11250 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11251
11252 if (! peer)
11253 return CMD_WARNING;
11254
11255 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11256 bgp_show_type_damp_neighbor);
11257}
11258
Lou Berger651b4022016-01-12 13:42:07 -050011259DEFUN (show_bgp_view_neighbor_flap,
11260 show_bgp_view_ipv6_neighbor_flap_cmd,
11261 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paulbb46e942003-10-24 19:02:03 +000011262 SHOW_STR
11263 BGP_STR
11264 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011265 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011266 "Address family\n"
11267 "Detailed information on TCP and BGP neighbor connections\n"
11268 "Neighbor to display information about\n"
11269 "Neighbor to display information about\n"
11270 "Display the dampened routes received from neighbor\n")
paulbb46e942003-10-24 19:02:03 +000011271{
11272 struct peer *peer;
11273
11274 if (argc == 2)
11275 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11276 else
11277 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11278
11279 if (! peer)
11280 return CMD_WARNING;
11281
11282 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11283 bgp_show_type_flap_neighbor);
11284}
11285
paulbb46e942003-10-24 19:02:03 +000011286ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011287 show_bgp_ipv6_neighbor_routes_cmd,
11288 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
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 routes learned from neighbor\n")
11296
paulbb46e942003-10-24 19:02:03 +000011297ALIAS (show_bgp_view_neighbor_flap,
11298 show_bgp_ipv6_neighbor_flap_cmd,
11299 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
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"
11306 "Display flap statistics of the routes learned from neighbor\n")
11307
11308ALIAS (show_bgp_view_neighbor_damp,
paulbb46e942003-10-24 19:02:03 +000011309 show_bgp_ipv6_neighbor_damp_cmd,
11310 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11311 SHOW_STR
11312 BGP_STR
11313 "Address family\n"
11314 "Detailed information on TCP and BGP neighbor connections\n"
11315 "Neighbor to display information about\n"
11316 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011317 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011318
Lou Berger651b4022016-01-12 13:42:07 -050011319#endif /* HAVE_IPV6 */
11320
11321DEFUN (show_bgp_view_ipv4_rsclient,
11322 show_bgp_view_ipv4_rsclient_cmd,
11323 "show bgp view WORD ipv4 rsclient (A.B.C.D|X:X::X:X)",
paulfee0f4c2004-09-13 05:12:46 +000011324 SHOW_STR
11325 BGP_STR
11326 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011327 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050011328 "Address Family\n"
paulfee0f4c2004-09-13 05:12:46 +000011329 "Information about Route Server Client\n"
Lou Berger651b4022016-01-12 13:42:07 -050011330 NEIGHBOR_ADDR_STR2)
paulfee0f4c2004-09-13 05:12:46 +000011331{
Lou Berger651b4022016-01-12 13:42:07 -050011332 struct bgp_table *table;
11333 struct peer *peer;
11334
11335 if (argc == 2)
11336 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11337 else
11338 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11339
11340 if (! peer)
11341 return CMD_WARNING;
11342
11343 if (! peer->afc[AFI_IP][SAFI_UNICAST])
11344 {
11345 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11346 VTY_NEWLINE);
11347 return CMD_WARNING;
11348 }
11349
11350 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
11351 PEER_FLAG_RSERVER_CLIENT))
11352 {
11353 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11354 VTY_NEWLINE);
11355 return CMD_WARNING;
11356 }
11357
11358 table = peer->rib[AFI_IP][SAFI_UNICAST];
11359
11360 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11361}
11362DEFUN (show_bgp_view_ipv6_rsclient,
11363 show_bgp_view_ipv6_rsclient_cmd,
11364 "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X)",
11365 SHOW_STR
11366 BGP_STR
11367 "BGP view\n"
11368 "BGP view name\n"
11369 "Address Family\n"
11370 "Information about Route Server Client\n"
11371 NEIGHBOR_ADDR_STR2)
11372{
11373 struct bgp_table *table;
11374 struct peer *peer;
paulfee0f4c2004-09-13 05:12:46 +000011375
11376 if (argc == 2)
11377 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11378 else
11379 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11380
11381 if (! peer)
11382 return CMD_WARNING;
11383
11384 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11385 {
11386 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11387 VTY_NEWLINE);
11388 return CMD_WARNING;
11389 }
11390
11391 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11392 PEER_FLAG_RSERVER_CLIENT))
11393 {
11394 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11395 VTY_NEWLINE);
11396 return CMD_WARNING;
11397 }
11398
11399 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11400
ajs5a646652004-11-05 01:25:55 +000011401 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011402}
11403
Lou Berger651b4022016-01-12 13:42:07 -050011404ALIAS (show_bgp_view_ipv4_rsclient,
11405 show_bgp_ipv4_rsclient_cmd,
11406 "show bgp ipv4 rsclient (A.B.C.D|X:X::X:X)",
paulfee0f4c2004-09-13 05:12:46 +000011407 SHOW_STR
11408 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011409 "Address Family\n"
paulfee0f4c2004-09-13 05:12:46 +000011410 "Information about Route Server Client\n"
Lou Berger651b4022016-01-12 13:42:07 -050011411 NEIGHBOR_ADDR_STR2)
11412
11413#ifdef HAVE_IPV6
11414ALIAS (show_bgp_view_ipv6_rsclient,
11415 show_bgp_ipv6_rsclient_cmd,
11416 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X)",
11417 SHOW_STR
11418 BGP_STR
11419 "Address Family\n"
11420 "Information about Route Server Client\n"
11421 NEIGHBOR_ADDR_STR2)
paulfee0f4c2004-09-13 05:12:46 +000011422
Michael Lambert95cbbd22010-07-23 14:43:04 -040011423DEFUN (show_bgp_view_ipv6_safi_rsclient,
11424 show_bgp_view_ipv6_safi_rsclient_cmd,
11425 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11426 SHOW_STR
11427 BGP_STR
11428 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011429 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011430 "Address family\n"
11431 "Address Family modifier\n"
11432 "Address Family modifier\n"
11433 "Information about Route Server Client\n"
11434 NEIGHBOR_ADDR_STR)
11435{
11436 struct bgp_table *table;
11437 struct peer *peer;
11438 safi_t safi;
11439
11440 if (argc == 3) {
11441 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11442 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11443 } else {
11444 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11445 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11446 }
11447
11448 if (! peer)
11449 return CMD_WARNING;
11450
11451 if (! peer->afc[AFI_IP6][safi])
11452 {
11453 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11454 VTY_NEWLINE);
11455 return CMD_WARNING;
11456 }
11457
11458 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11459 PEER_FLAG_RSERVER_CLIENT))
11460 {
11461 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11462 VTY_NEWLINE);
11463 return CMD_WARNING;
11464 }
11465
11466 table = peer->rib[AFI_IP6][safi];
11467
11468 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11469}
11470
11471ALIAS (show_bgp_view_ipv6_safi_rsclient,
11472 show_bgp_ipv6_safi_rsclient_cmd,
11473 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11474 SHOW_STR
11475 BGP_STR
11476 "Address family\n"
11477 "Address Family modifier\n"
11478 "Address Family modifier\n"
11479 "Information about Route Server Client\n"
11480 NEIGHBOR_ADDR_STR)
11481
Lou Berger651b4022016-01-12 13:42:07 -050011482
paulfee0f4c2004-09-13 05:12:46 +000011483DEFUN (show_bgp_view_rsclient_route,
11484 show_bgp_view_rsclient_route_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011485 "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
paulfee0f4c2004-09-13 05:12:46 +000011486 SHOW_STR
11487 BGP_STR
11488 "BGP view\n"
Lou Berger651b4022016-01-12 13:42:07 -050011489 "BGP view name\n"
11490 "IP6_STR"
paulfee0f4c2004-09-13 05:12:46 +000011491 "Information about Route Server Client\n"
11492 NEIGHBOR_ADDR_STR
11493 "Network in the BGP routing table to display\n")
11494{
11495 struct bgp *bgp;
11496 struct peer *peer;
11497
11498 /* BGP structure lookup. */
11499 if (argc == 3)
11500 {
11501 bgp = bgp_lookup_by_name (argv[0]);
11502 if (bgp == NULL)
11503 {
11504 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11505 return CMD_WARNING;
11506 }
11507 }
11508 else
11509 {
11510 bgp = bgp_get_default ();
11511 if (bgp == NULL)
11512 {
11513 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11514 return CMD_WARNING;
11515 }
11516 }
11517
11518 if (argc == 3)
11519 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11520 else
11521 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11522
11523 if (! peer)
11524 return CMD_WARNING;
11525
11526 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11527 {
11528 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11529 VTY_NEWLINE);
11530 return CMD_WARNING;
11531 }
11532
11533 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11534 PEER_FLAG_RSERVER_CLIENT))
11535 {
11536 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11537 VTY_NEWLINE);
11538 return CMD_WARNING;
11539 }
11540
11541 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11542 (argc == 3) ? argv[2] : argv[1],
11543 AFI_IP6, SAFI_UNICAST, NULL, 0);
11544}
11545
11546ALIAS (show_bgp_view_rsclient_route,
11547 show_bgp_rsclient_route_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011548 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
paulfee0f4c2004-09-13 05:12:46 +000011549 SHOW_STR
11550 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011551 IP6_STR
paulfee0f4c2004-09-13 05:12:46 +000011552 "Information about Route Server Client\n"
11553 NEIGHBOR_ADDR_STR
11554 "Network in the BGP routing table to display\n")
11555
Michael Lambert95cbbd22010-07-23 14:43:04 -040011556DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11557 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11558 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11559 SHOW_STR
11560 BGP_STR
11561 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011562 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011563 "Address family\n"
11564 "Address Family modifier\n"
11565 "Address Family modifier\n"
11566 "Information about Route Server Client\n"
11567 NEIGHBOR_ADDR_STR
11568 "Network in the BGP routing table to display\n")
11569{
11570 struct bgp *bgp;
11571 struct peer *peer;
11572 safi_t safi;
11573
11574 /* BGP structure lookup. */
11575 if (argc == 4)
11576 {
11577 bgp = bgp_lookup_by_name (argv[0]);
11578 if (bgp == NULL)
11579 {
11580 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11581 return CMD_WARNING;
11582 }
11583 }
11584 else
11585 {
11586 bgp = bgp_get_default ();
11587 if (bgp == NULL)
11588 {
11589 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11590 return CMD_WARNING;
11591 }
11592 }
11593
11594 if (argc == 4) {
11595 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11596 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11597 } else {
11598 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11599 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11600 }
11601
11602 if (! peer)
11603 return CMD_WARNING;
11604
11605 if (! peer->afc[AFI_IP6][safi])
11606 {
11607 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11608 VTY_NEWLINE);
11609 return CMD_WARNING;
11610}
11611
11612 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11613 PEER_FLAG_RSERVER_CLIENT))
11614 {
11615 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11616 VTY_NEWLINE);
11617 return CMD_WARNING;
11618 }
11619
11620 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11621 (argc == 4) ? argv[3] : argv[2],
11622 AFI_IP6, safi, NULL, 0);
11623}
11624
11625ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11626 show_bgp_ipv6_safi_rsclient_route_cmd,
11627 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11628 SHOW_STR
11629 BGP_STR
11630 "Address family\n"
11631 "Address Family modifier\n"
11632 "Address Family modifier\n"
11633 "Information about Route Server Client\n"
11634 NEIGHBOR_ADDR_STR
11635 "Network in the BGP routing table to display\n")
11636
Lou Berger651b4022016-01-12 13:42:07 -050011637
paulfee0f4c2004-09-13 05:12:46 +000011638DEFUN (show_bgp_view_rsclient_prefix,
11639 show_bgp_view_rsclient_prefix_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011640 "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 +000011641 SHOW_STR
11642 BGP_STR
11643 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011644 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050011645 IP6_STR
paulfee0f4c2004-09-13 05:12:46 +000011646 "Information about Route Server Client\n"
11647 NEIGHBOR_ADDR_STR
11648 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11649{
11650 struct bgp *bgp;
11651 struct peer *peer;
11652
11653 /* BGP structure lookup. */
11654 if (argc == 3)
11655 {
11656 bgp = bgp_lookup_by_name (argv[0]);
11657 if (bgp == NULL)
11658 {
11659 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11660 return CMD_WARNING;
11661 }
11662 }
11663 else
11664 {
11665 bgp = bgp_get_default ();
11666 if (bgp == NULL)
11667 {
11668 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11669 return CMD_WARNING;
11670 }
11671 }
11672
11673 if (argc == 3)
11674 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11675 else
11676 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11677
11678 if (! peer)
11679 return CMD_WARNING;
11680
11681 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11682 {
11683 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11684 VTY_NEWLINE);
11685 return CMD_WARNING;
11686 }
11687
11688 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11689 PEER_FLAG_RSERVER_CLIENT))
11690 {
11691 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11692 VTY_NEWLINE);
11693 return CMD_WARNING;
11694 }
11695
11696 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11697 (argc == 3) ? argv[2] : argv[1],
11698 AFI_IP6, SAFI_UNICAST, NULL, 1);
11699}
11700
11701ALIAS (show_bgp_view_rsclient_prefix,
11702 show_bgp_rsclient_prefix_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011703 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
paulfee0f4c2004-09-13 05:12:46 +000011704 SHOW_STR
11705 BGP_STR
11706 "Information about Route Server Client\n"
11707 NEIGHBOR_ADDR_STR
11708 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11709
Michael Lambert95cbbd22010-07-23 14:43:04 -040011710DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11711 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11712 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11713 SHOW_STR
11714 BGP_STR
11715 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011716 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011717 "Address family\n"
11718 "Address Family modifier\n"
11719 "Address Family modifier\n"
11720 "Information about Route Server Client\n"
11721 NEIGHBOR_ADDR_STR
11722 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11723{
11724 struct bgp *bgp;
11725 struct peer *peer;
11726 safi_t safi;
11727
11728 /* BGP structure lookup. */
11729 if (argc == 4)
11730 {
11731 bgp = bgp_lookup_by_name (argv[0]);
11732 if (bgp == NULL)
11733 {
11734 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11735 return CMD_WARNING;
11736 }
11737 }
11738 else
11739 {
11740 bgp = bgp_get_default ();
11741 if (bgp == NULL)
11742 {
11743 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11744 return CMD_WARNING;
11745 }
11746 }
11747
11748 if (argc == 4) {
11749 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11750 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11751 } else {
11752 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11753 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11754 }
11755
11756 if (! peer)
11757 return CMD_WARNING;
11758
11759 if (! peer->afc[AFI_IP6][safi])
11760 {
11761 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11762 VTY_NEWLINE);
11763 return CMD_WARNING;
11764}
11765
11766 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11767 PEER_FLAG_RSERVER_CLIENT))
11768{
11769 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11770 VTY_NEWLINE);
11771 return CMD_WARNING;
11772 }
11773
11774 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11775 (argc == 4) ? argv[3] : argv[2],
11776 AFI_IP6, safi, NULL, 1);
11777}
11778
11779ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11780 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11781 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11782 SHOW_STR
11783 BGP_STR
11784 "Address family\n"
11785 "Address Family modifier\n"
11786 "Address Family modifier\n"
11787 "Information about Route Server Client\n"
11788 NEIGHBOR_ADDR_STR
11789 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11790
paul718e3742002-12-13 20:15:29 +000011791#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020011792
paul718e3742002-12-13 20:15:29 +000011793struct bgp_table *bgp_distance_table;
11794
11795struct bgp_distance
11796{
11797 /* Distance value for the IP source prefix. */
11798 u_char distance;
11799
11800 /* Name of the access-list to be matched. */
11801 char *access_list;
11802};
11803
paul94f2b392005-06-28 12:44:16 +000011804static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011805bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011806{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011807 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011808}
11809
paul94f2b392005-06-28 12:44:16 +000011810static void
paul718e3742002-12-13 20:15:29 +000011811bgp_distance_free (struct bgp_distance *bdistance)
11812{
11813 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11814}
11815
paul94f2b392005-06-28 12:44:16 +000011816static int
paulfd79ac92004-10-13 05:06:08 +000011817bgp_distance_set (struct vty *vty, const char *distance_str,
11818 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011819{
11820 int ret;
11821 struct prefix_ipv4 p;
11822 u_char distance;
11823 struct bgp_node *rn;
11824 struct bgp_distance *bdistance;
11825
11826 ret = str2prefix_ipv4 (ip_str, &p);
11827 if (ret == 0)
11828 {
11829 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11830 return CMD_WARNING;
11831 }
11832
11833 distance = atoi (distance_str);
11834
11835 /* Get BGP distance node. */
11836 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11837 if (rn->info)
11838 {
11839 bdistance = rn->info;
11840 bgp_unlock_node (rn);
11841 }
11842 else
11843 {
11844 bdistance = bgp_distance_new ();
11845 rn->info = bdistance;
11846 }
11847
11848 /* Set distance value. */
11849 bdistance->distance = distance;
11850
11851 /* Reset access-list configuration. */
11852 if (bdistance->access_list)
11853 {
11854 free (bdistance->access_list);
11855 bdistance->access_list = NULL;
11856 }
11857 if (access_list_str)
11858 bdistance->access_list = strdup (access_list_str);
11859
11860 return CMD_SUCCESS;
11861}
11862
paul94f2b392005-06-28 12:44:16 +000011863static int
paulfd79ac92004-10-13 05:06:08 +000011864bgp_distance_unset (struct vty *vty, const char *distance_str,
11865 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011866{
11867 int ret;
11868 struct prefix_ipv4 p;
11869 u_char distance;
11870 struct bgp_node *rn;
11871 struct bgp_distance *bdistance;
11872
11873 ret = str2prefix_ipv4 (ip_str, &p);
11874 if (ret == 0)
11875 {
11876 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11877 return CMD_WARNING;
11878 }
11879
11880 distance = atoi (distance_str);
11881
11882 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11883 if (! rn)
11884 {
11885 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11886 return CMD_WARNING;
11887 }
11888
11889 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010011890
11891 if (bdistance->distance != distance)
11892 {
11893 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
11894 return CMD_WARNING;
11895 }
11896
paul718e3742002-12-13 20:15:29 +000011897 if (bdistance->access_list)
11898 free (bdistance->access_list);
11899 bgp_distance_free (bdistance);
11900
11901 rn->info = NULL;
11902 bgp_unlock_node (rn);
11903 bgp_unlock_node (rn);
11904
11905 return CMD_SUCCESS;
11906}
11907
paul718e3742002-12-13 20:15:29 +000011908/* Apply BGP information to distance method. */
11909u_char
11910bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11911{
11912 struct bgp_node *rn;
11913 struct prefix_ipv4 q;
11914 struct peer *peer;
11915 struct bgp_distance *bdistance;
11916 struct access_list *alist;
11917 struct bgp_static *bgp_static;
11918
11919 if (! bgp)
11920 return 0;
11921
11922 if (p->family != AF_INET)
11923 return 0;
11924
11925 peer = rinfo->peer;
11926
11927 if (peer->su.sa.sa_family != AF_INET)
11928 return 0;
11929
11930 memset (&q, 0, sizeof (struct prefix_ipv4));
11931 q.family = AF_INET;
11932 q.prefix = peer->su.sin.sin_addr;
11933 q.prefixlen = IPV4_MAX_BITLEN;
11934
11935 /* Check source address. */
11936 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11937 if (rn)
11938 {
11939 bdistance = rn->info;
11940 bgp_unlock_node (rn);
11941
11942 if (bdistance->access_list)
11943 {
11944 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11945 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11946 return bdistance->distance;
11947 }
11948 else
11949 return bdistance->distance;
11950 }
11951
11952 /* Backdoor check. */
11953 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11954 if (rn)
11955 {
11956 bgp_static = rn->info;
11957 bgp_unlock_node (rn);
11958
11959 if (bgp_static->backdoor)
11960 {
11961 if (bgp->distance_local)
11962 return bgp->distance_local;
11963 else
11964 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11965 }
11966 }
11967
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011968 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011969 {
11970 if (bgp->distance_ebgp)
11971 return bgp->distance_ebgp;
11972 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11973 }
11974 else
11975 {
11976 if (bgp->distance_ibgp)
11977 return bgp->distance_ibgp;
11978 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11979 }
11980}
11981
11982DEFUN (bgp_distance,
11983 bgp_distance_cmd,
11984 "distance bgp <1-255> <1-255> <1-255>",
11985 "Define an administrative distance\n"
11986 "BGP distance\n"
11987 "Distance for routes external to the AS\n"
11988 "Distance for routes internal to the AS\n"
11989 "Distance for local routes\n")
11990{
11991 struct bgp *bgp;
11992
11993 bgp = vty->index;
11994
11995 bgp->distance_ebgp = atoi (argv[0]);
11996 bgp->distance_ibgp = atoi (argv[1]);
11997 bgp->distance_local = atoi (argv[2]);
11998 return CMD_SUCCESS;
11999}
12000
12001DEFUN (no_bgp_distance,
12002 no_bgp_distance_cmd,
12003 "no distance bgp <1-255> <1-255> <1-255>",
12004 NO_STR
12005 "Define an administrative distance\n"
12006 "BGP distance\n"
12007 "Distance for routes external to the AS\n"
12008 "Distance for routes internal to the AS\n"
12009 "Distance for local routes\n")
12010{
12011 struct bgp *bgp;
12012
12013 bgp = vty->index;
12014
12015 bgp->distance_ebgp= 0;
12016 bgp->distance_ibgp = 0;
12017 bgp->distance_local = 0;
12018 return CMD_SUCCESS;
12019}
12020
12021ALIAS (no_bgp_distance,
12022 no_bgp_distance2_cmd,
12023 "no distance bgp",
12024 NO_STR
12025 "Define an administrative distance\n"
12026 "BGP distance\n")
12027
12028DEFUN (bgp_distance_source,
12029 bgp_distance_source_cmd,
12030 "distance <1-255> A.B.C.D/M",
12031 "Define an administrative distance\n"
12032 "Administrative distance\n"
12033 "IP source prefix\n")
12034{
12035 bgp_distance_set (vty, argv[0], argv[1], NULL);
12036 return CMD_SUCCESS;
12037}
12038
12039DEFUN (no_bgp_distance_source,
12040 no_bgp_distance_source_cmd,
12041 "no distance <1-255> A.B.C.D/M",
12042 NO_STR
12043 "Define an administrative distance\n"
12044 "Administrative distance\n"
12045 "IP source prefix\n")
12046{
12047 bgp_distance_unset (vty, argv[0], argv[1], NULL);
12048 return CMD_SUCCESS;
12049}
12050
12051DEFUN (bgp_distance_source_access_list,
12052 bgp_distance_source_access_list_cmd,
12053 "distance <1-255> A.B.C.D/M WORD",
12054 "Define an administrative distance\n"
12055 "Administrative distance\n"
12056 "IP source prefix\n"
12057 "Access list name\n")
12058{
12059 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
12060 return CMD_SUCCESS;
12061}
12062
12063DEFUN (no_bgp_distance_source_access_list,
12064 no_bgp_distance_source_access_list_cmd,
12065 "no distance <1-255> A.B.C.D/M WORD",
12066 NO_STR
12067 "Define an administrative distance\n"
12068 "Administrative distance\n"
12069 "IP source prefix\n"
12070 "Access list name\n")
12071{
12072 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
12073 return CMD_SUCCESS;
12074}
David Lamparter6b0655a2014-06-04 06:53:35 +020012075
paul718e3742002-12-13 20:15:29 +000012076DEFUN (bgp_damp_set,
12077 bgp_damp_set_cmd,
12078 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12079 "BGP Specific commands\n"
12080 "Enable route-flap dampening\n"
12081 "Half-life time for the penalty\n"
12082 "Value to start reusing a route\n"
12083 "Value to start suppressing a route\n"
12084 "Maximum duration to suppress a stable route\n")
12085{
12086 struct bgp *bgp;
12087 int half = DEFAULT_HALF_LIFE * 60;
12088 int reuse = DEFAULT_REUSE;
12089 int suppress = DEFAULT_SUPPRESS;
12090 int max = 4 * half;
12091
12092 if (argc == 4)
12093 {
12094 half = atoi (argv[0]) * 60;
12095 reuse = atoi (argv[1]);
12096 suppress = atoi (argv[2]);
12097 max = atoi (argv[3]) * 60;
12098 }
12099 else if (argc == 1)
12100 {
12101 half = atoi (argv[0]) * 60;
12102 max = 4 * half;
12103 }
12104
12105 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000012106
12107 if (suppress < reuse)
12108 {
12109 vty_out (vty, "Suppress value cannot be less than reuse value %s",
12110 VTY_NEWLINE);
12111 return 0;
12112 }
12113
paul718e3742002-12-13 20:15:29 +000012114 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
12115 half, reuse, suppress, max);
12116}
12117
12118ALIAS (bgp_damp_set,
12119 bgp_damp_set2_cmd,
12120 "bgp dampening <1-45>",
12121 "BGP Specific commands\n"
12122 "Enable route-flap dampening\n"
12123 "Half-life time for the penalty\n")
12124
12125ALIAS (bgp_damp_set,
12126 bgp_damp_set3_cmd,
12127 "bgp dampening",
12128 "BGP Specific commands\n"
12129 "Enable route-flap dampening\n")
12130
12131DEFUN (bgp_damp_unset,
12132 bgp_damp_unset_cmd,
12133 "no bgp dampening",
12134 NO_STR
12135 "BGP Specific commands\n"
12136 "Enable route-flap dampening\n")
12137{
12138 struct bgp *bgp;
12139
12140 bgp = vty->index;
12141 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
12142}
12143
12144ALIAS (bgp_damp_unset,
12145 bgp_damp_unset2_cmd,
12146 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12147 NO_STR
12148 "BGP Specific commands\n"
12149 "Enable route-flap dampening\n"
12150 "Half-life time for the penalty\n"
12151 "Value to start reusing a route\n"
12152 "Value to start suppressing a route\n"
12153 "Maximum duration to suppress a stable route\n")
12154
Lou Berger651b4022016-01-12 13:42:07 -050012155DEFUN (show_bgp_ipv4_safi_dampened_paths,
12156 show_bgp_ipv4_safi_dampened_paths_cmd,
12157 "show bgp ipv4 (encap|multicast|unicast|vpn) dampened-paths",
paul718e3742002-12-13 20:15:29 +000012158 SHOW_STR
paul718e3742002-12-13 20:15:29 +000012159 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050012160 IP_STR
12161 "Address Family modifier\n"
12162 "Address Family modifier\n"
12163 "Address Family modifier\n"
12164 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000012165 "Display paths suppressed due to dampening\n")
12166{
Lou Berger651b4022016-01-12 13:42:07 -050012167 safi_t safi;
paul718e3742002-12-13 20:15:29 +000012168
Lou Berger651b4022016-01-12 13:42:07 -050012169 if (bgp_parse_safi(argv[0], &safi)) {
12170 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12171 return CMD_WARNING;
12172 }
12173
12174 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_dampend_paths, NULL);
12175}
12176ALIAS (show_bgp_ipv4_safi_dampened_paths,
12177 show_bgp_ipv4_safi_damp_dampened_paths_cmd,
12178 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening dampened-paths",
Balaji3921cc52015-05-16 23:12:17 +053012179 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053012180 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050012181 IP_STR
12182 "Address Family modifier\n"
12183 "Address Family modifier\n"
12184 "Address Family modifier\n"
12185 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053012186 "Display detailed information about dampening\n"
12187 "Display paths suppressed due to dampening\n")
Lou Berger651b4022016-01-12 13:42:07 -050012188#ifdef HAVE_IPV6
12189DEFUN (show_bgp_ipv6_safi_dampened_paths,
12190 show_bgp_ipv6_safi_dampened_paths_cmd,
12191 "show bgp ipv6 (encap|multicast|unicast|vpn) dampened-paths",
paul718e3742002-12-13 20:15:29 +000012192 SHOW_STR
paul718e3742002-12-13 20:15:29 +000012193 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050012194 IPV6_STR
12195 "Address Family modifier\n"
12196 "Address Family modifier\n"
12197 "Address Family modifier\n"
12198 "Address Family modifier\n"
12199 "Display paths suppressed due to dampening\n")
12200{
12201 safi_t safi;
12202
12203 if (bgp_parse_safi(argv[0], &safi)) {
12204 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12205 return CMD_WARNING;
12206 }
12207
12208 return bgp_show (vty, NULL, AFI_IP6, safi, bgp_show_type_dampend_paths, NULL);
12209}
12210ALIAS (show_bgp_ipv6_safi_dampened_paths,
12211 show_bgp_ipv6_safi_damp_dampened_paths_cmd,
12212 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening dampened-paths",
12213 SHOW_STR
12214 BGP_STR
12215 IPV6_STR
12216 "Address Family modifier\n"
12217 "Address Family modifier\n"
12218 "Address Family modifier\n"
12219 "Address Family modifier\n"
12220 "Display detailed information about dampening\n"
12221 "Display paths suppressed due to dampening\n")
12222#endif
12223
12224DEFUN (show_bgp_ipv4_safi_flap_statistics,
12225 show_bgp_ipv4_safi_flap_statistics_cmd,
12226 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics",
12227 SHOW_STR
12228 BGP_STR
12229 "Address Family\n"
12230 "Address Family modifier\n"
12231 "Address Family modifier\n"
12232 "Address Family modifier\n"
12233 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000012234 "Display flap statistics of routes\n")
12235{
Lou Berger651b4022016-01-12 13:42:07 -050012236 safi_t safi;
David Lamparter6b0655a2014-06-04 06:53:35 +020012237
Lou Berger651b4022016-01-12 13:42:07 -050012238 if (bgp_parse_safi(argv[0], &safi)) {
12239 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12240 return CMD_WARNING;
12241 }
12242
12243 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_statistics, NULL);
12244}
12245ALIAS (show_bgp_ipv4_safi_flap_statistics,
12246 show_bgp_ipv4_safi_damp_flap_statistics_cmd,
12247 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics",
Balaji3921cc52015-05-16 23:12:17 +053012248 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053012249 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050012250 "Address Family\n"
12251 "Address Family modifier\n"
12252 "Address Family modifier\n"
12253 "Address Family modifier\n"
12254 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053012255 "Display detailed information about dampening\n"
12256 "Display flap statistics of routes\n")
Lou Berger651b4022016-01-12 13:42:07 -050012257#ifdef HAVE_IPV6
12258DEFUN (show_bgp_ipv6_safi_flap_statistics,
12259 show_bgp_ipv6_safi_flap_statistics_cmd,
12260 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics",
12261 SHOW_STR
12262 BGP_STR
12263 "Address Family\n"
12264 "Address Family modifier\n"
12265 "Address Family modifier\n"
12266 "Address Family modifier\n"
12267 "Address Family modifier\n"
12268 "Display flap statistics of routes\n")
12269{
12270 safi_t safi;
12271
12272 if (bgp_parse_safi(argv[0], &safi)) {
12273 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12274 return CMD_WARNING;
12275 }
12276
12277 return bgp_show (vty, NULL, AFI_IP6, safi, bgp_show_type_flap_statistics, NULL);
12278}
12279ALIAS (show_bgp_ipv6_safi_flap_statistics,
12280 show_bgp_ipv6_safi_damp_flap_statistics_cmd,
12281 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics",
12282 SHOW_STR
12283 BGP_STR
12284 "Address Family\n"
12285 "Address Family modifier\n"
12286 "Address Family modifier\n"
12287 "Address Family modifier\n"
12288 "Address Family modifier\n"
12289 "Display detailed information about dampening\n"
12290 "Display flap statistics of routes\n")
12291#endif
Balaji3921cc52015-05-16 23:12:17 +053012292
paul718e3742002-12-13 20:15:29 +000012293/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012294static int
paulfd79ac92004-10-13 05:06:08 +000012295bgp_clear_damp_route (struct vty *vty, const char *view_name,
12296 const char *ip_str, afi_t afi, safi_t safi,
12297 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012298{
12299 int ret;
12300 struct prefix match;
12301 struct bgp_node *rn;
12302 struct bgp_node *rm;
12303 struct bgp_info *ri;
12304 struct bgp_info *ri_temp;
12305 struct bgp *bgp;
12306 struct bgp_table *table;
12307
12308 /* BGP structure lookup. */
12309 if (view_name)
12310 {
12311 bgp = bgp_lookup_by_name (view_name);
12312 if (bgp == NULL)
12313 {
12314 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12315 return CMD_WARNING;
12316 }
12317 }
12318 else
12319 {
12320 bgp = bgp_get_default ();
12321 if (bgp == NULL)
12322 {
12323 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12324 return CMD_WARNING;
12325 }
12326 }
12327
12328 /* Check IP address argument. */
12329 ret = str2prefix (ip_str, &match);
12330 if (! ret)
12331 {
12332 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12333 return CMD_WARNING;
12334 }
12335
12336 match.family = afi2family (afi);
12337
Lou Berger298cc2f2016-01-12 13:42:02 -050012338 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000012339 {
Lou Berger298cc2f2016-01-12 13:42:02 -050012340 for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +000012341 {
12342 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12343 continue;
12344
12345 if ((table = rn->info) != NULL)
12346 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012347 {
12348 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12349 {
12350 ri = rm->info;
12351 while (ri)
12352 {
12353 if (ri->extra && ri->extra->damp_info)
12354 {
12355 ri_temp = ri->next;
12356 bgp_damp_info_free (ri->extra->damp_info, 1);
12357 ri = ri_temp;
12358 }
12359 else
12360 ri = ri->next;
12361 }
12362 }
12363
12364 bgp_unlock_node (rm);
12365 }
paul718e3742002-12-13 20:15:29 +000012366 }
12367 }
12368 else
12369 {
12370 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012371 {
12372 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12373 {
12374 ri = rn->info;
12375 while (ri)
12376 {
12377 if (ri->extra && ri->extra->damp_info)
12378 {
12379 ri_temp = ri->next;
12380 bgp_damp_info_free (ri->extra->damp_info, 1);
12381 ri = ri_temp;
12382 }
12383 else
12384 ri = ri->next;
12385 }
12386 }
12387
12388 bgp_unlock_node (rn);
12389 }
paul718e3742002-12-13 20:15:29 +000012390 }
12391
12392 return CMD_SUCCESS;
12393}
12394
12395DEFUN (clear_ip_bgp_dampening,
12396 clear_ip_bgp_dampening_cmd,
12397 "clear ip bgp dampening",
12398 CLEAR_STR
12399 IP_STR
12400 BGP_STR
12401 "Clear route flap dampening information\n")
12402{
12403 bgp_damp_info_clean ();
12404 return CMD_SUCCESS;
12405}
12406
12407DEFUN (clear_ip_bgp_dampening_prefix,
12408 clear_ip_bgp_dampening_prefix_cmd,
12409 "clear ip bgp dampening A.B.C.D/M",
12410 CLEAR_STR
12411 IP_STR
12412 BGP_STR
12413 "Clear route flap dampening information\n"
12414 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12415{
12416 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12417 SAFI_UNICAST, NULL, 1);
12418}
12419
12420DEFUN (clear_ip_bgp_dampening_address,
12421 clear_ip_bgp_dampening_address_cmd,
12422 "clear ip bgp dampening A.B.C.D",
12423 CLEAR_STR
12424 IP_STR
12425 BGP_STR
12426 "Clear route flap dampening information\n"
12427 "Network to clear damping information\n")
12428{
12429 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12430 SAFI_UNICAST, NULL, 0);
12431}
12432
12433DEFUN (clear_ip_bgp_dampening_address_mask,
12434 clear_ip_bgp_dampening_address_mask_cmd,
12435 "clear ip bgp dampening A.B.C.D A.B.C.D",
12436 CLEAR_STR
12437 IP_STR
12438 BGP_STR
12439 "Clear route flap dampening information\n"
12440 "Network to clear damping information\n"
12441 "Network mask\n")
12442{
12443 int ret;
12444 char prefix_str[BUFSIZ];
12445
12446 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12447 if (! ret)
12448 {
12449 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12450 return CMD_WARNING;
12451 }
12452
12453 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12454 SAFI_UNICAST, NULL, 0);
12455}
David Lamparter6b0655a2014-06-04 06:53:35 +020012456
Lou Berger298cc2f2016-01-12 13:42:02 -050012457/* also used for encap safi */
paul94f2b392005-06-28 12:44:16 +000012458static int
paul718e3742002-12-13 20:15:29 +000012459bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12460 afi_t afi, safi_t safi, int *write)
12461{
12462 struct bgp_node *prn;
12463 struct bgp_node *rn;
12464 struct bgp_table *table;
12465 struct prefix *p;
12466 struct prefix_rd *prd;
12467 struct bgp_static *bgp_static;
12468 u_int32_t label;
12469 char buf[SU_ADDRSTRLEN];
12470 char rdbuf[RD_ADDRSTRLEN];
12471
12472 /* Network configuration. */
12473 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12474 if ((table = prn->info) != NULL)
12475 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12476 if ((bgp_static = rn->info) != NULL)
12477 {
12478 p = &rn->p;
12479 prd = (struct prefix_rd *) &prn->p;
12480
12481 /* "address-family" display. */
12482 bgp_config_write_family_header (vty, afi, safi, write);
12483
12484 /* "network" configuration display. */
12485 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12486 label = decode_label (bgp_static->tag);
12487
12488 vty_out (vty, " network %s/%d rd %s tag %d",
12489 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12490 p->prefixlen,
12491 rdbuf, label);
12492 vty_out (vty, "%s", VTY_NEWLINE);
12493 }
12494 return 0;
12495}
12496
12497/* Configuration of static route announcement and aggregate
12498 information. */
12499int
12500bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12501 afi_t afi, safi_t safi, int *write)
12502{
12503 struct bgp_node *rn;
12504 struct prefix *p;
12505 struct bgp_static *bgp_static;
12506 struct bgp_aggregate *bgp_aggregate;
12507 char buf[SU_ADDRSTRLEN];
12508
Lou Berger298cc2f2016-01-12 13:42:02 -050012509 if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
paul718e3742002-12-13 20:15:29 +000012510 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12511
12512 /* Network configuration. */
12513 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12514 if ((bgp_static = rn->info) != NULL)
12515 {
12516 p = &rn->p;
12517
12518 /* "address-family" display. */
12519 bgp_config_write_family_header (vty, afi, safi, write);
12520
12521 /* "network" configuration display. */
12522 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12523 {
12524 u_int32_t destination;
12525 struct in_addr netmask;
12526
12527 destination = ntohl (p->u.prefix4.s_addr);
12528 masklen2ip (p->prefixlen, &netmask);
12529 vty_out (vty, " network %s",
12530 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12531
12532 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12533 || (IN_CLASSB (destination) && p->prefixlen == 16)
12534 || (IN_CLASSA (destination) && p->prefixlen == 8)
12535 || p->u.prefix4.s_addr == 0)
12536 {
12537 /* Natural mask is not display. */
12538 }
12539 else
12540 vty_out (vty, " mask %s", inet_ntoa (netmask));
12541 }
12542 else
12543 {
12544 vty_out (vty, " network %s/%d",
12545 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12546 p->prefixlen);
12547 }
12548
12549 if (bgp_static->rmap.name)
12550 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012551 else
12552 {
12553 if (bgp_static->backdoor)
12554 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012555 }
paul718e3742002-12-13 20:15:29 +000012556
12557 vty_out (vty, "%s", VTY_NEWLINE);
12558 }
12559
12560 /* Aggregate-address configuration. */
12561 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12562 if ((bgp_aggregate = rn->info) != NULL)
12563 {
12564 p = &rn->p;
12565
12566 /* "address-family" display. */
12567 bgp_config_write_family_header (vty, afi, safi, write);
12568
12569 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12570 {
12571 struct in_addr netmask;
12572
12573 masklen2ip (p->prefixlen, &netmask);
12574 vty_out (vty, " aggregate-address %s %s",
12575 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12576 inet_ntoa (netmask));
12577 }
12578 else
12579 {
12580 vty_out (vty, " aggregate-address %s/%d",
12581 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12582 p->prefixlen);
12583 }
12584
12585 if (bgp_aggregate->as_set)
12586 vty_out (vty, " as-set");
12587
12588 if (bgp_aggregate->summary_only)
12589 vty_out (vty, " summary-only");
12590
12591 vty_out (vty, "%s", VTY_NEWLINE);
12592 }
12593
12594 return 0;
12595}
12596
12597int
12598bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12599{
12600 struct bgp_node *rn;
12601 struct bgp_distance *bdistance;
12602
12603 /* Distance configuration. */
12604 if (bgp->distance_ebgp
12605 && bgp->distance_ibgp
12606 && bgp->distance_local
12607 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12608 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12609 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12610 vty_out (vty, " distance bgp %d %d %d%s",
12611 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12612 VTY_NEWLINE);
12613
12614 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12615 if ((bdistance = rn->info) != NULL)
12616 {
12617 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12618 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12619 bdistance->access_list ? bdistance->access_list : "",
12620 VTY_NEWLINE);
12621 }
12622
12623 return 0;
12624}
12625
12626/* Allocate routing table structure and install commands. */
12627void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012628bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012629{
12630 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012631 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012632
12633 /* IPv4 BGP commands. */
12634 install_element (BGP_NODE, &bgp_network_cmd);
12635 install_element (BGP_NODE, &bgp_network_mask_cmd);
12636 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12637 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12638 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12639 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12640 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12641 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12642 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12643 install_element (BGP_NODE, &no_bgp_network_cmd);
12644 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12645 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12646 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12647 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12648 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12649 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12650 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12651 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12652
12653 install_element (BGP_NODE, &aggregate_address_cmd);
12654 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12655 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12656 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12657 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12658 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12659 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12660 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12661 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12662 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12663 install_element (BGP_NODE, &no_aggregate_address_cmd);
12664 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12665 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12666 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12667 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12668 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12669 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12670 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12671 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12672 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12673
12674 /* IPv4 unicast configuration. */
12675 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12676 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12677 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12678 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12679 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12680 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012681 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012682 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12683 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12684 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12685 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12686 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012687
paul718e3742002-12-13 20:15:29 +000012688 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12689 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12690 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12691 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12692 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12693 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12694 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12695 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12696 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12697 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12698 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12699 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12700 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12701 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12702 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12703 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12704 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12705 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12706 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12707 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12708
12709 /* IPv4 multicast configuration. */
12710 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12711 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12712 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12713 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12714 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12715 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12716 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12717 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12718 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12719 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12720 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12721 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12722 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12723 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12724 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12725 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12726 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12727 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12728 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12729 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12730 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12731 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12732 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12733 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12734 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12735 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12736 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12737 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12738 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12739 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12740 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12741 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12742
Michael Lambert95cbbd22010-07-23 14:43:04 -040012743 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012744 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050012745 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_route_cmd);
12746 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_route_cmd);
12747 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
12748 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
12749 install_element (VIEW_NODE, &show_bgp_ipv4_encap_route_cmd);
12750 install_element (VIEW_NODE, &show_bgp_ipv6_encap_route_cmd);
12751 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
12752 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
12753 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012754 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050012755 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
12756 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
12757 install_element (VIEW_NODE, &show_bgp_ipv4_encap_prefix_cmd);
12758 install_element (VIEW_NODE, &show_bgp_ipv6_encap_prefix_cmd);
12759 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
12760 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
12761 install_element (VIEW_NODE, &show_bgp_afi_safi_view_cmd);
12762 install_element (VIEW_NODE, &show_bgp_view_afi_safi_route_cmd);
12763 install_element (VIEW_NODE, &show_bgp_view_afi_safi_prefix_cmd);
12764 install_element (VIEW_NODE, &show_bgp_ipv4_safi_regexp_cmd);
12765 install_element (VIEW_NODE, &show_bgp_ipv6_safi_regexp_cmd);
12766 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_list_cmd);
12767 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_list_cmd);
12768 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_list_cmd);
12769 install_element (VIEW_NODE, &show_bgp_ipv4_filter_list_cmd);
12770 install_element (VIEW_NODE, &show_bgp_ipv4_safi_filter_list_cmd);
12771 install_element (VIEW_NODE, &show_bgp_ipv6_safi_filter_list_cmd);
12772 install_element (VIEW_NODE, &show_bgp_ipv4_route_map_cmd);
12773 install_element (VIEW_NODE, &show_bgp_ipv4_cidr_only_cmd);
12774 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cidr_only_cmd);
12775 install_element (VIEW_NODE, &show_bgp_ipv4_community_cmd);
12776 install_element (VIEW_NODE, &show_bgp_ipv4_community2_cmd);
12777 install_element (VIEW_NODE, &show_bgp_ipv4_community3_cmd);
12778 install_element (VIEW_NODE, &show_bgp_ipv4_community4_cmd);
12779 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_cmd);
12780 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community2_cmd);
12781 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community3_cmd);
12782 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012783 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12784 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12785 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12786 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12787 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050012788 install_element (VIEW_NODE, &show_bgp_ipv4_community_exact_cmd);
12789 install_element (VIEW_NODE, &show_bgp_ipv4_community2_exact_cmd);
12790 install_element (VIEW_NODE, &show_bgp_ipv4_community3_exact_cmd);
12791 install_element (VIEW_NODE, &show_bgp_ipv4_community4_exact_cmd);
12792 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
12793 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
12794 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
12795 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
12796 install_element (VIEW_NODE, &show_bgp_ipv4_community_list_cmd);
12797 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_list_cmd);
12798 install_element (VIEW_NODE, &show_bgp_ipv4_community_list_exact_cmd);
12799 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_list_exact_cmd);
12800 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_longer_cmd);
12801 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_longer_cmd);
12802 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_longer_cmd);
12803 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_advertised_route_cmd);
12804 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_advertised_route_cmd);
12805 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_received_routes_cmd);
12806 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012807 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050012808 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_routes_cmd);
12809 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_routes_cmd);
12810 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd);
12811 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd);
12812 install_element (VIEW_NODE, &show_bgp_ipv4_safi_dampened_paths_cmd);
12813 install_element (VIEW_NODE, &show_bgp_ipv6_safi_dampened_paths_cmd);
12814 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_dampened_paths_cmd);
12815 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_dampened_paths_cmd);
12816 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_statistics_cmd);
12817 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_statistics_cmd);
12818 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_statistics_cmd);
12819 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_statistics_cmd);
12820 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_address_cmd);
12821 install_element (VIEW_NODE, &show_bgp_ipv6_flap_address_cmd);
12822 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_address_cmd);
12823 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_cmd);
12824 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_cmd);
12825 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_cmd);
12826 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_cmd);
12827 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_cidr_only_cmd);
12828 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_cidr_only_cmd);
12829 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_regexp_cmd);
12830 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_regexp_cmd);
12831 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_regexp_cmd);
12832 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_regexp_cmd);
12833 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_filter_list_cmd);
12834 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_filter_list_cmd);
12835 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_filter_list_cmd);
12836 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_filter_list_cmd);
12837 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_list_cmd);
12838 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_list_cmd);
12839 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_list_cmd);
12840 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_list_cmd);
12841 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_longer_cmd);
12842 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_longer_cmd);
12843 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd);
12844 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd);
12845 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_route_map_cmd);
12846 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_route_map_cmd);
12847 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_route_map_cmd);
12848 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_route_map_cmd);
12849 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_flap_cmd);
12850 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_flap_cmd);
12851 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_damp_cmd);
12852 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_damp_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012853 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012854 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012855 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012856 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012857 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012858 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012859
12860 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
Michael Lambert95cbbd22010-07-23 14:43:04 -040012861 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050012862 install_element (RESTRICTED_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
12863 install_element (RESTRICTED_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
12864 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
12865 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
12866 install_element (RESTRICTED_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012867 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050012868 install_element (RESTRICTED_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
12869 install_element (RESTRICTED_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
12870 install_element (RESTRICTED_NODE, &show_bgp_ipv4_encap_prefix_cmd);
12871 install_element (RESTRICTED_NODE, &show_bgp_ipv6_encap_prefix_cmd);
12872 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
12873 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
12874 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_route_cmd);
12875 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_prefix_cmd);
12876 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community_cmd);
12877 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community2_cmd);
12878 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community3_cmd);
12879 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community4_cmd);
12880 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community_cmd);
12881 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community2_cmd);
12882 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community3_cmd);
12883 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012884 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12885 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12886 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12887 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12888 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050012889 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community_exact_cmd);
12890 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community2_exact_cmd);
12891 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community3_exact_cmd);
12892 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community4_exact_cmd);
12893 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
12894 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
12895 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
12896 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012897 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012898 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012899 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012900 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012901
Michael Lambert95cbbd22010-07-23 14:43:04 -040012902 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012903 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050012904 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_route_cmd);
12905 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_route_cmd);
12906 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
12907 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
12908 install_element (ENABLE_NODE, &show_bgp_ipv4_encap_route_cmd);
12909 install_element (ENABLE_NODE, &show_bgp_ipv6_encap_route_cmd);
12910 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
12911 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
12912 install_element (ENABLE_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012913 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050012914 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
12915 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
12916 install_element (ENABLE_NODE, &show_bgp_ipv4_encap_prefix_cmd);
12917 install_element (ENABLE_NODE, &show_bgp_ipv6_encap_prefix_cmd);
12918 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
12919 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
12920 install_element (ENABLE_NODE, &show_bgp_afi_safi_view_cmd);
12921 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_route_cmd);
12922 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_prefix_cmd);
12923 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_regexp_cmd);
12924 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_regexp_cmd);
12925 install_element (ENABLE_NODE, &show_bgp_ipv4_prefix_list_cmd);
12926 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_list_cmd);
12927 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_list_cmd);
12928 install_element (ENABLE_NODE, &show_bgp_ipv4_filter_list_cmd);
12929 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_filter_list_cmd);
12930 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_filter_list_cmd);
12931 install_element (ENABLE_NODE, &show_bgp_ipv4_route_map_cmd);
12932 install_element (ENABLE_NODE, &show_bgp_ipv4_cidr_only_cmd);
12933 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cidr_only_cmd);
12934 install_element (ENABLE_NODE, &show_bgp_ipv4_community_cmd);
12935 install_element (ENABLE_NODE, &show_bgp_ipv4_community2_cmd);
12936 install_element (ENABLE_NODE, &show_bgp_ipv4_community3_cmd);
12937 install_element (ENABLE_NODE, &show_bgp_ipv4_community4_cmd);
12938 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community_cmd);
12939 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community2_cmd);
12940 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community3_cmd);
12941 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012942 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12943 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12944 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12945 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12946 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050012947 install_element (ENABLE_NODE, &show_bgp_ipv4_community_exact_cmd);
12948 install_element (ENABLE_NODE, &show_bgp_ipv4_community2_exact_cmd);
12949 install_element (ENABLE_NODE, &show_bgp_ipv4_community3_exact_cmd);
12950 install_element (ENABLE_NODE, &show_bgp_ipv4_community4_exact_cmd);
12951 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
12952 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
12953 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
12954 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
12955 install_element (ENABLE_NODE, &show_bgp_ipv4_community_list_cmd);
12956 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community_list_cmd);
12957 install_element (ENABLE_NODE, &show_bgp_ipv4_community_list_exact_cmd);
12958 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community_list_exact_cmd);
12959 install_element (ENABLE_NODE, &show_bgp_ipv4_prefix_longer_cmd);
12960 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_longer_cmd);
12961 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_longer_cmd);
12962 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_neighbor_advertised_route_cmd);
12963 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_neighbor_advertised_route_cmd);
12964 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_neighbor_received_routes_cmd);
12965 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012966 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050012967 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_neighbor_routes_cmd);
12968 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_neighbor_routes_cmd);
12969 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd);
12970 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd);
12971 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_dampened_paths_cmd);
12972 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_dampened_paths_cmd);
12973 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_dampened_paths_cmd);
12974 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_damp_dampened_paths_cmd);
12975 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_statistics_cmd);
12976 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_flap_statistics_cmd);
12977 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_statistics_cmd);
12978 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_damp_flap_statistics_cmd);
12979 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_address_cmd);
12980 install_element (ENABLE_NODE, &show_bgp_ipv6_flap_address_cmd);
12981 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_address_cmd);
12982 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_prefix_cmd);
12983 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_flap_prefix_cmd);
12984 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_cmd);
12985 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_cmd);
12986 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_cidr_only_cmd);
12987 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_cidr_only_cmd);
12988 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_regexp_cmd);
12989 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_flap_regexp_cmd);
12990 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_regexp_cmd);
12991 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_damp_flap_regexp_cmd);
12992 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_filter_list_cmd);
12993 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_flap_filter_list_cmd);
12994 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_filter_list_cmd);
12995 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_damp_flap_filter_list_cmd);
12996 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_prefix_list_cmd);
12997 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_flap_prefix_list_cmd);
12998 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_list_cmd);
12999 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_list_cmd);
13000 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_prefix_longer_cmd);
13001 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_flap_prefix_longer_cmd);
13002 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd);
13003 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd);
13004 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_route_map_cmd);
13005 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_flap_route_map_cmd);
13006 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_route_map_cmd);
13007 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_damp_flap_route_map_cmd);
13008 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_neighbor_flap_cmd);
13009 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_neighbor_flap_cmd);
13010 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_neighbor_damp_cmd);
13011 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_neighbor_damp_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013012 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013013 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013014 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013015 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013016 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013017 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013018
13019 /* BGP dampening clear commands */
13020 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
13021 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
13022 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
13023 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
13024
Paul Jakmaff7924f2006-09-04 01:10:36 +000013025 /* prefix count */
Lou Berger651b4022016-01-12 13:42:07 -050013026 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_neighbor_prefix_counts_cmd);
13027 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000013028#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000013029 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
13030
paul718e3742002-12-13 20:15:29 +000013031 /* New config IPv6 BGP commands. */
13032 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
13033 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
13034 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
13035 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
13036
13037 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
13038 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
13039 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
13040 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
13041
G.Balaji73bfe0b2011-09-23 22:36:20 +053013042 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
13043 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
13044
paul718e3742002-12-13 20:15:29 +000013045 /* Old config IPv6 BGP commands. */
13046 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
13047 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
13048
13049 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
13050 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
13051 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
13052 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
13053
Michael Lambert95cbbd22010-07-23 14:43:04 -040013054 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000013055 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013056 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000013057 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013058 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013059 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
paul718e3742002-12-13 20:15:29 +000013060 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000013061 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000013062 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
paul718e3742002-12-13 20:15:29 +000013063 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
paul718e3742002-12-13 20:15:29 +000013064 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
paul718e3742002-12-13 20:15:29 +000013065 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
paul718e3742002-12-13 20:15:29 +000013066 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
paul718e3742002-12-13 20:15:29 +000013067 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
paul718e3742002-12-13 20:15:29 +000013068 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
paul718e3742002-12-13 20:15:29 +000013069 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
paul718e3742002-12-13 20:15:29 +000013070 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
13071 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
paul718e3742002-12-13 20:15:29 +000013072 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000013073 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
paul718e3742002-12-13 20:15:29 +000013074 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
paul718e3742002-12-13 20:15:29 +000013075 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
paul718e3742002-12-13 20:15:29 +000013076 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000013077 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000013078 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050013079 install_element (VIEW_NODE, &show_bgp_ipv4_rsclient_cmd);
13080 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013081 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013082 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013083 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013084 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013085 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000013086 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
paulbb46e942003-10-24 19:02:03 +000013087 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
paulbb46e942003-10-24 19:02:03 +000013088 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000013089 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
paulbb46e942003-10-24 19:02:03 +000013090 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000013091 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000013092 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000013093 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000013094 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050013095 install_element (VIEW_NODE, &show_bgp_view_ipv4_rsclient_cmd);
13096 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013097 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013098 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013099 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013100 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013101 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013102
13103 /* Restricted:
13104 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
13105 */
Paul Jakma62687ff2008-08-23 14:27:06 +010013106 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013107 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013108 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013109 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013110 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013111 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013112 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013113 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013114 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013115 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013116 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013117 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
13118 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013119 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013120 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013121 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013122 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013123 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013124 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13125 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013126 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013127 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013128 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013129
Michael Lambert95cbbd22010-07-23 14:43:04 -040013130 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000013131 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013132 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000013133 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013134 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013135 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
paul718e3742002-12-13 20:15:29 +000013136 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000013137 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000013138 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
paul718e3742002-12-13 20:15:29 +000013139 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
paul718e3742002-12-13 20:15:29 +000013140 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
paul718e3742002-12-13 20:15:29 +000013141 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
paul718e3742002-12-13 20:15:29 +000013142 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
paul718e3742002-12-13 20:15:29 +000013143 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
paul718e3742002-12-13 20:15:29 +000013144 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
paul718e3742002-12-13 20:15:29 +000013145 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
paul718e3742002-12-13 20:15:29 +000013146 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
13147 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
paul718e3742002-12-13 20:15:29 +000013148 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
paul718e3742002-12-13 20:15:29 +000013149 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000013150 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
paul718e3742002-12-13 20:15:29 +000013151 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
paul718e3742002-12-13 20:15:29 +000013152 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
paul718e3742002-12-13 20:15:29 +000013153 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000013154 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000013155 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050013156 install_element (ENABLE_NODE, &show_bgp_ipv4_rsclient_cmd);
13157 install_element (ENABLE_NODE, &show_bgp_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013158 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013159 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013160 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013161 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013162 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000013163 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
paulbb46e942003-10-24 19:02:03 +000013164 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
paulbb46e942003-10-24 19:02:03 +000013165 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000013166 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
paulbb46e942003-10-24 19:02:03 +000013167 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000013168 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000013169 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000013170 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000013171 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050013172 install_element (ENABLE_NODE, &show_bgp_view_ipv4_rsclient_cmd);
13173 install_element (ENABLE_NODE, &show_bgp_view_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013174 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013175 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013176 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013177 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013178 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000013179
13180 /* Statistics */
13181 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050013182 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
paul718e3742002-12-13 20:15:29 +000013183#endif /* HAVE_IPV6 */
13184
13185 install_element (BGP_NODE, &bgp_distance_cmd);
13186 install_element (BGP_NODE, &no_bgp_distance_cmd);
13187 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13188 install_element (BGP_NODE, &bgp_distance_source_cmd);
13189 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13190 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13191 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13192
13193 install_element (BGP_NODE, &bgp_damp_set_cmd);
13194 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13195 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13196 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13197 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13198 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13199 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13200 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13201 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13202 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013203
13204 /* Deprecated AS-Pathlimit commands */
13205 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13206 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13207 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13208 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13209 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13210 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13211
13212 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13213 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13214 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13215 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13216 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13217 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13218
13219 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13220 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13221 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13222 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13223 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13224 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13225
13226 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13227 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13228 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13229 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13230 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13231 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13232
13233 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13234 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13235 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13236 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13237 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13238 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13239
13240 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13241 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13242 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13243 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13244 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13245 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013246
13247#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013248 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13249 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013250#endif
paul718e3742002-12-13 20:15:29 +000013251}
Chris Caputo228da422009-07-18 05:44:03 +000013252
13253void
13254bgp_route_finish (void)
13255{
13256 bgp_table_unlock (bgp_distance_table);
13257 bgp_distance_table = NULL;
13258}