blob: ff541e845ea057616d339676ea71f8b0bce43d72 [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
paul718e3742002-12-13 20:15:29 +000074 if (safi == SAFI_MPLS_VPN)
75 {
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
87 if (safi == SAFI_MPLS_VPN)
88 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
983 /* next-hop-set */
Timo Teräs9e7a53c2014-04-24 10:22:37 +0300984 if (transparent
985 || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
paul718e3742002-12-13 20:15:29 +0000986 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
987 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000988#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000989 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000990 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000991#endif /* HAVE_IPV6 */
992 )))
paul718e3742002-12-13 20:15:29 +0000993 {
994 /* NEXT-HOP Unchanged. */
995 }
996 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
997 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
998#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000999 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001000 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +00001001#endif /* HAVE_IPV6 */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001002 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001003 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
1004 {
1005 /* Set IPv4 nexthop. */
1006 if (p->family == AF_INET)
1007 {
1008 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001009 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1010 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +00001011 else
1012 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1013 }
1014#ifdef HAVE_IPV6
1015 /* Set IPv6 nexthop. */
1016 if (p->family == AF_INET6)
1017 {
1018 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001019 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001020 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001021 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001022 }
1023#endif /* HAVE_IPV6 */
1024 }
1025
1026#ifdef HAVE_IPV6
1027 if (p->family == AF_INET6)
1028 {
paulfee0f4c2004-09-13 05:12:46 +00001029 /* Left nexthop_local unchanged if so configured. */
1030 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1031 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1032 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001033 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1034 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001035 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001036 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001037 }
1038
1039 /* Default nexthop_local treatment for non-RS-Clients */
1040 else
1041 {
paul718e3742002-12-13 20:15:29 +00001042 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001043 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001044
1045 /* Set link-local address for shared network peer. */
1046 if (peer->shared_network
1047 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1048 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001049 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001050 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001051 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001052 }
1053
1054 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1055 address.*/
1056 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001057 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001058
1059 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1060 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001061 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001062 }
paulfee0f4c2004-09-13 05:12:46 +00001063
1064 }
paul718e3742002-12-13 20:15:29 +00001065#endif /* HAVE_IPV6 */
1066
1067 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001068 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001069 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1070 && aspath_private_as_check (attr->aspath))
1071 attr->aspath = aspath_empty_get ();
1072
1073 /* Route map & unsuppress-map apply. */
1074 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001075 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001076 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001077 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001078 struct attr dummy_attr;
1079 struct attr_extra dummy_extra;
1080
1081 dummy_attr.extra = &dummy_extra;
1082
paul718e3742002-12-13 20:15:29 +00001083 info.peer = peer;
1084 info.attr = attr;
1085
1086 /* The route reflector is not allowed to modify the attributes
1087 of the reflected IBGP routes. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001088 if (from->sort == BGP_PEER_IBGP
1089 && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +00001090 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001091 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001092 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001093 }
paulac41b2a2003-08-12 05:32:27 +00001094
1095 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1096
Paul Jakmafb982c22007-05-04 20:15:47 +00001097 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001098 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1099 else
1100 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1101
paulac41b2a2003-08-12 05:32:27 +00001102 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001103
paul718e3742002-12-13 20:15:29 +00001104 if (ret == RMAP_DENYMATCH)
1105 {
1106 bgp_attr_flush (attr);
1107 return 0;
1108 }
1109 }
1110 return 1;
1111}
1112
paul94f2b392005-06-28 12:44:16 +00001113static int
paulfee0f4c2004-09-13 05:12:46 +00001114bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1115 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001116{
paulfee0f4c2004-09-13 05:12:46 +00001117 int ret;
1118 char buf[SU_ADDRSTRLEN];
1119 struct bgp_filter *filter;
1120 struct bgp_info info;
1121 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001122 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001123
1124 from = ri->peer;
1125 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001126 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001127
Paul Jakma750e8142008-07-22 21:11:48 +00001128 if (DISABLE_BGP_ANNOUNCE)
1129 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001130
1131 /* Do not send back route to sender. */
1132 if (from == rsclient)
1133 return 0;
1134
1135 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001136 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001137 if (! UNSUPPRESS_MAP_NAME (filter))
1138 return 0;
1139
1140 /* Default route check. */
1141 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1142 PEER_STATUS_DEFAULT_ORIGINATE))
1143 {
1144 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1145 return 0;
1146#ifdef HAVE_IPV6
1147 else if (p->family == AF_INET6 && p->prefixlen == 0)
1148 return 0;
1149#endif /* HAVE_IPV6 */
1150 }
1151
1152 /* If the attribute has originator-id and it is same as remote
1153 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001154 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001155 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001156 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001157 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001158 {
1159 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001160 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001161 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1162 rsclient->host,
1163 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1164 p->prefixlen);
1165 return 0;
1166 }
1167 }
1168
1169 /* ORF prefix-list filter check */
1170 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1171 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1172 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1173 if (rsclient->orf_plist[afi][safi])
1174 {
1175 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1176 return 0;
1177 }
1178
1179 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001180 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001181 {
1182 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001183 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001184 "%s [Update:SEND] %s/%d is filtered",
1185 rsclient->host,
1186 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1187 p->prefixlen);
1188 return 0;
1189 }
1190
1191#ifdef BGP_SEND_ASPATH_CHECK
1192 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001193 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001194 {
1195 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001196 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001197 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001198 rsclient->host, rsclient->as);
1199 return 0;
1200 }
1201#endif /* BGP_SEND_ASPATH_CHECK */
1202
1203 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001204 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001205
1206 /* next-hop-set */
1207 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1208#ifdef HAVE_IPV6
1209 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001210 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001211#endif /* HAVE_IPV6 */
1212 )
1213 {
1214 /* Set IPv4 nexthop. */
1215 if (p->family == AF_INET)
1216 {
1217 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001218 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001219 IPV4_MAX_BYTELEN);
1220 else
1221 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1222 }
1223#ifdef HAVE_IPV6
1224 /* Set IPv6 nexthop. */
1225 if (p->family == AF_INET6)
1226 {
1227 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001228 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001229 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001230 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001231 }
1232#endif /* HAVE_IPV6 */
1233 }
1234
1235#ifdef HAVE_IPV6
1236 if (p->family == AF_INET6)
1237 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001238 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001239
paulfee0f4c2004-09-13 05:12:46 +00001240 /* Left nexthop_local unchanged if so configured. */
1241 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1242 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1243 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001244 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1245 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001246 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001247 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001248 }
1249
1250 /* Default nexthop_local treatment for RS-Clients */
1251 else
1252 {
1253 /* Announcer and RS-Client are both in the same network */
1254 if (rsclient->shared_network && from->shared_network &&
1255 (rsclient->ifindex == from->ifindex))
1256 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001257 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1258 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001259 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001260 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001261 }
1262
1263 /* Set link-local address for shared network peer. */
1264 else if (rsclient->shared_network
1265 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1266 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001267 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001268 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001269 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001270 }
1271
1272 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001273 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001274 }
1275
1276 }
1277#endif /* HAVE_IPV6 */
1278
1279
1280 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001281 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001282 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1283 && aspath_private_as_check (attr->aspath))
1284 attr->aspath = aspath_empty_get ();
1285
1286 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001287 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001288 {
1289 info.peer = rsclient;
1290 info.attr = attr;
1291
1292 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1293
Paul Jakmafb982c22007-05-04 20:15:47 +00001294 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001295 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1296 else
1297 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1298
1299 rsclient->rmap_type = 0;
1300
1301 if (ret == RMAP_DENYMATCH)
1302 {
1303 bgp_attr_flush (attr);
1304 return 0;
1305 }
1306 }
1307
1308 return 1;
1309}
1310
1311struct bgp_info_pair
1312{
1313 struct bgp_info *old;
1314 struct bgp_info *new;
1315};
1316
paul94f2b392005-06-28 12:44:16 +00001317static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001318bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
Paul Jakma6d4742b2015-11-25 17:14:37 +00001319 struct bgp_info_pair *result,
1320 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00001321{
paul718e3742002-12-13 20:15:29 +00001322 struct bgp_info *new_select;
1323 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001324 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001325 struct bgp_info *ri1;
1326 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001327 struct bgp_info *nextri = NULL;
Paul Jakma6d4742b2015-11-25 17:14:37 +00001328 int cmpret, do_mpath;
Josh Bailey96450fa2011-07-20 20:45:12 -07001329 struct list mp_list;
Paul Jakma91b9e852015-12-01 14:32:11 +00001330
1331 result->old = result->new = NULL;
1332
1333 if (rn->info == NULL)
1334 {
1335 char buf[PREFIX_STRLEN];
1336 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1337 __func__,
1338 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1339 return;
1340 }
1341
Josh Bailey96450fa2011-07-20 20:45:12 -07001342 bgp_mp_list_init (&mp_list);
Paul Jakma6d4742b2015-11-25 17:14:37 +00001343 do_mpath = bgp_mpath_is_configured (bgp, afi, safi);
Josh Bailey96450fa2011-07-20 20:45:12 -07001344
paul718e3742002-12-13 20:15:29 +00001345 /* bgp deterministic-med */
1346 new_select = NULL;
1347 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1348 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1349 {
1350 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1351 continue;
1352 if (BGP_INFO_HOLDDOWN (ri1))
1353 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001354 if (ri1->peer && ri1->peer != bgp->peer_self)
1355 if (ri1->peer->status != Established)
1356 continue;
paul718e3742002-12-13 20:15:29 +00001357
1358 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001359 if (do_mpath)
1360 bgp_mp_list_add (&mp_list, ri1);
1361 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001362 if (ri1->next)
1363 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1364 {
1365 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1366 continue;
1367 if (BGP_INFO_HOLDDOWN (ri2))
1368 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001369 if (ri2->peer &&
1370 ri2->peer != bgp->peer_self &&
1371 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1372 if (ri2->peer->status != Established)
1373 continue;
paul718e3742002-12-13 20:15:29 +00001374
1375 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1376 || aspath_cmp_left_confed (ri1->attr->aspath,
1377 ri2->attr->aspath))
1378 {
Josh Bailey6918e742011-07-20 20:48:20 -07001379 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1380 old_select = ri2;
Paul Jakma6d4742b2015-11-25 17:14:37 +00001381 if ((cmpret = bgp_info_cmp (bgp, ri2, new_select, afi, safi))
1382 == -1)
paul718e3742002-12-13 20:15:29 +00001383 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001384 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001385 new_select = ri2;
1386 }
1387
Paul Jakma6d4742b2015-11-25 17:14:37 +00001388 if (do_mpath)
1389 {
1390 if (cmpret != 0)
1391 bgp_mp_list_clear (&mp_list);
1392
1393 if (cmpret == 0 || cmpret == -1)
1394 bgp_mp_list_add (&mp_list, ri2);
1395 }
Josh Bailey6918e742011-07-20 20:48:20 -07001396
Paul Jakma1a392d42006-09-07 00:24:49 +00001397 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001398 }
1399 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001400 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1401 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001402
Paul Jakma6d4742b2015-11-25 17:14:37 +00001403 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, afi, safi);
Josh Bailey6918e742011-07-20 20:48:20 -07001404 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001405 }
1406
1407 /* Check old selected route and new selected route. */
1408 old_select = NULL;
1409 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001410 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001411 {
1412 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1413 old_select = ri;
1414
1415 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001416 {
1417 /* reap REMOVED routes, if needs be
1418 * selected route must stay for a while longer though
1419 */
1420 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1421 && (ri != old_select))
1422 bgp_info_reap (rn, ri);
1423
1424 continue;
1425 }
paul718e3742002-12-13 20:15:29 +00001426
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001427 if (ri->peer &&
1428 ri->peer != bgp->peer_self &&
1429 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1430 if (ri->peer->status != Established)
1431 continue;
1432
paul718e3742002-12-13 20:15:29 +00001433 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1434 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1435 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001436 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001437 continue;
1438 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001439 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1440 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001441
Paul Jakma6d4742b2015-11-25 17:14:37 +00001442 if ((cmpret = bgp_info_cmp (bgp, ri, new_select, afi, safi)) == -1)
Josh Bailey96450fa2011-07-20 20:45:12 -07001443 {
Josh Bailey6918e742011-07-20 20:48:20 -07001444 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1445 bgp_mp_dmed_deselect (new_select);
1446
Josh Bailey96450fa2011-07-20 20:45:12 -07001447 new_select = ri;
Josh Bailey96450fa2011-07-20 20:45:12 -07001448 }
Paul Jakma6d4742b2015-11-25 17:14:37 +00001449 else if (cmpret == 1 && do_mpath
1450 && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
Josh Bailey6918e742011-07-20 20:48:20 -07001451 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001452
Paul Jakma6d4742b2015-11-25 17:14:37 +00001453 if (do_mpath)
1454 {
1455 if (cmpret != 0)
1456 bgp_mp_list_clear (&mp_list);
1457
1458 if (cmpret == 0 || cmpret == -1)
1459 bgp_mp_list_add (&mp_list, ri);
1460 }
paul718e3742002-12-13 20:15:29 +00001461 }
paulfee0f4c2004-09-13 05:12:46 +00001462
Josh Bailey6918e742011-07-20 20:48:20 -07001463 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
Paul Jakma6d4742b2015-11-25 17:14:37 +00001464 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, afi, safi);
Josh Bailey96450fa2011-07-20 20:45:12 -07001465
Josh Bailey0b597ef2011-07-20 20:49:11 -07001466 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001467 bgp_mp_list_clear (&mp_list);
1468
1469 result->old = old_select;
1470 result->new = new_select;
1471
1472 return;
paulfee0f4c2004-09-13 05:12:46 +00001473}
1474
paul94f2b392005-06-28 12:44:16 +00001475static int
paulfee0f4c2004-09-13 05:12:46 +00001476bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001477 struct bgp_node *rn, afi_t afi, safi_t safi)
1478{
paulfee0f4c2004-09-13 05:12:46 +00001479 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001480 struct attr attr;
1481 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001482
1483 p = &rn->p;
1484
Paul Jakma9eda90c2007-08-30 13:36:17 +00001485 /* Announce route to Established peer. */
1486 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001487 return 0;
1488
Paul Jakma9eda90c2007-08-30 13:36:17 +00001489 /* Address family configuration check. */
1490 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001491 return 0;
1492
Paul Jakma9eda90c2007-08-30 13:36:17 +00001493 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001494 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1495 PEER_STATUS_ORF_WAIT_REFRESH))
1496 return 0;
1497
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001498 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1499 attr.extra = &extra;
1500
Avneesh Sachdev67174042012-08-17 08:19:49 -07001501 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001502 {
1503 case BGP_TABLE_MAIN:
1504 /* Announcement to peer->conf. If the route is filtered,
1505 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001506 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1507 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001508 else
1509 bgp_adj_out_unset (rn, peer, p, afi, safi);
1510 break;
1511 case BGP_TABLE_RSCLIENT:
1512 /* Announcement to peer->conf. If the route is filtered,
1513 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001514 if (selected &&
1515 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1516 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1517 else
1518 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001519 break;
1520 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001521
paulfee0f4c2004-09-13 05:12:46 +00001522 return 0;
paul200df112005-06-01 11:17:05 +00001523}
paulfee0f4c2004-09-13 05:12:46 +00001524
paul200df112005-06-01 11:17:05 +00001525struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001526{
paul200df112005-06-01 11:17:05 +00001527 struct bgp *bgp;
1528 struct bgp_node *rn;
1529 afi_t afi;
1530 safi_t safi;
1531};
1532
1533static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001534bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001535{
paul0fb58d52005-11-14 14:31:49 +00001536 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001537 struct bgp *bgp = pq->bgp;
1538 struct bgp_node *rn = pq->rn;
1539 afi_t afi = pq->afi;
1540 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001541 struct bgp_info *new_select;
1542 struct bgp_info *old_select;
1543 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001544 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001545 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001546
paulfee0f4c2004-09-13 05:12:46 +00001547 /* Best path selection. */
Paul Jakma6d4742b2015-11-25 17:14:37 +00001548 bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001549 new_select = old_and_new.new;
1550 old_select = old_and_new.old;
1551
paul200df112005-06-01 11:17:05 +00001552 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1553 {
Chris Caputo228da422009-07-18 05:44:03 +00001554 if (rsclient->group)
1555 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1556 {
1557 /* Nothing to do. */
1558 if (old_select && old_select == new_select)
1559 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1560 continue;
paulfee0f4c2004-09-13 05:12:46 +00001561
Chris Caputo228da422009-07-18 05:44:03 +00001562 if (old_select)
1563 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1564 if (new_select)
1565 {
1566 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1567 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001568 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1569 }
paulfee0f4c2004-09-13 05:12:46 +00001570
Chris Caputo228da422009-07-18 05:44:03 +00001571 bgp_process_announce_selected (rsclient, new_select, rn,
1572 afi, safi);
1573 }
paul200df112005-06-01 11:17:05 +00001574 }
1575 else
1576 {
hassob7395792005-08-26 12:58:38 +00001577 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001578 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001579 if (new_select)
1580 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001581 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);
hassob7395792005-08-26 12:58:38 +00001584 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001585 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001586 }
paulfee0f4c2004-09-13 05:12:46 +00001587
paulb40d9392005-08-22 22:34:41 +00001588 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1589 bgp_info_reap (rn, old_select);
1590
paul200df112005-06-01 11:17:05 +00001591 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1592 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001593}
1594
paul200df112005-06-01 11:17:05 +00001595static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001596bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001597{
paul0fb58d52005-11-14 14:31:49 +00001598 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001599 struct bgp *bgp = pq->bgp;
1600 struct bgp_node *rn = pq->rn;
1601 afi_t afi = pq->afi;
1602 safi_t safi = pq->safi;
1603 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001604 struct bgp_info *new_select;
1605 struct bgp_info *old_select;
1606 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001607 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001608 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001609
paulfee0f4c2004-09-13 05:12:46 +00001610 /* Best path selection. */
Paul Jakma6d4742b2015-11-25 17:14:37 +00001611 bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001612 old_select = old_and_new.old;
1613 new_select = old_and_new.new;
1614
1615 /* Nothing to do. */
1616 if (old_select && old_select == new_select)
1617 {
1618 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001619 {
Josh Bailey8196f132011-07-20 20:47:07 -07001620 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1621 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001622 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001623
Josh Bailey8196f132011-07-20 20:47:07 -07001624 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001625 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1626 return WQ_SUCCESS;
1627 }
paulfee0f4c2004-09-13 05:12:46 +00001628 }
paul718e3742002-12-13 20:15:29 +00001629
hasso338b3422005-02-23 14:27:24 +00001630 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001631 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001632 if (new_select)
1633 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001634 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1635 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001636 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001637 }
1638
1639
paul718e3742002-12-13 20:15:29 +00001640 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001641 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001642 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001643 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001644 }
1645
1646 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001647 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1648 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001649 {
1650 if (new_select
1651 && new_select->type == ZEBRA_ROUTE_BGP
1652 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001653 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001654 else
1655 {
1656 /* Withdraw the route from the kernel. */
1657 if (old_select
1658 && old_select->type == ZEBRA_ROUTE_BGP
1659 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001660 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001661 }
1662 }
paulb40d9392005-08-22 22:34:41 +00001663
1664 /* Reap old select bgp_info, it it has been removed */
1665 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1666 bgp_info_reap (rn, old_select);
1667
paul200df112005-06-01 11:17:05 +00001668 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1669 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001670}
1671
paul200df112005-06-01 11:17:05 +00001672static void
paul0fb58d52005-11-14 14:31:49 +00001673bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001674{
paul0fb58d52005-11-14 14:31:49 +00001675 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001676 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001677
Chris Caputo228da422009-07-18 05:44:03 +00001678 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001679 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001680 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001681 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1682}
1683
1684static void
1685bgp_process_queue_init (void)
1686{
1687 bm->process_main_queue
1688 = work_queue_new (bm->master, "process_main_queue");
1689 bm->process_rsclient_queue
1690 = work_queue_new (bm->master, "process_rsclient_queue");
1691
1692 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1693 {
1694 zlog_err ("%s: Failed to allocate work queue", __func__);
1695 exit (1);
1696 }
1697
1698 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001699 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001700 bm->process_main_queue->spec.max_retries = 0;
1701 bm->process_main_queue->spec.hold = 50;
1702
Paul Jakma838bbde2010-01-08 14:05:32 +00001703 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
David Lamparterd43f8b32015-03-03 08:54:54 +01001704 bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del;
1705 bm->process_rsclient_queue->spec.max_retries = 0;
1706 bm->process_rsclient_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001707}
1708
1709void
paulfee0f4c2004-09-13 05:12:46 +00001710bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1711{
paul200df112005-06-01 11:17:05 +00001712 struct bgp_process_queue *pqnode;
1713
1714 /* already scheduled for processing? */
1715 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1716 return;
1717
Paul Jakma91b9e852015-12-01 14:32:11 +00001718 if (rn->info == NULL)
1719 {
1720 /* XXX: Perhaps remove before next release, after we've flushed out
1721 * any obvious cases
1722 */
1723 assert (rn->info != NULL);
1724 char buf[PREFIX_STRLEN];
1725 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1726 __func__,
1727 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1728 return;
1729 }
1730
paul200df112005-06-01 11:17:05 +00001731 if ( (bm->process_main_queue == NULL) ||
1732 (bm->process_rsclient_queue == NULL) )
1733 bgp_process_queue_init ();
1734
1735 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1736 sizeof (struct bgp_process_queue));
1737 if (!pqnode)
1738 return;
Chris Caputo228da422009-07-18 05:44:03 +00001739
1740 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001741 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001742 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001743 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001744 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001745 pqnode->afi = afi;
1746 pqnode->safi = safi;
1747
Avneesh Sachdev67174042012-08-17 08:19:49 -07001748 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001749 {
paul200df112005-06-01 11:17:05 +00001750 case BGP_TABLE_MAIN:
1751 work_queue_add (bm->process_main_queue, pqnode);
1752 break;
1753 case BGP_TABLE_RSCLIENT:
1754 work_queue_add (bm->process_rsclient_queue, pqnode);
1755 break;
paulfee0f4c2004-09-13 05:12:46 +00001756 }
paul200df112005-06-01 11:17:05 +00001757
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001758 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001759 return;
paulfee0f4c2004-09-13 05:12:46 +00001760}
hasso0a486e52005-02-01 20:57:17 +00001761
paul94f2b392005-06-28 12:44:16 +00001762static int
hasso0a486e52005-02-01 20:57:17 +00001763bgp_maximum_prefix_restart_timer (struct thread *thread)
1764{
1765 struct peer *peer;
1766
1767 peer = THREAD_ARG (thread);
1768 peer->t_pmax_restart = NULL;
1769
1770 if (BGP_DEBUG (events, EVENTS))
1771 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1772 peer->host);
1773
1774 peer_clear (peer);
1775
1776 return 0;
1777}
1778
paulfee0f4c2004-09-13 05:12:46 +00001779int
paul5228ad22004-06-04 17:58:18 +00001780bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1781 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001782{
hassoe0701b72004-05-20 09:19:34 +00001783 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1784 return 0;
1785
1786 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001787 {
hassoe0701b72004-05-20 09:19:34 +00001788 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1789 && ! always)
1790 return 0;
paul718e3742002-12-13 20:15:29 +00001791
hassoe0701b72004-05-20 09:19:34 +00001792 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001793 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1794 "limit %ld", afi_safi_print (afi, safi), peer->host,
1795 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001796 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
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_WARNING))
1799 return 0;
paul718e3742002-12-13 20:15:29 +00001800
hassoe0701b72004-05-20 09:19:34 +00001801 {
paul5228ad22004-06-04 17:58:18 +00001802 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001803
1804 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001805 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001806
1807 ndata[0] = (afi >> 8);
1808 ndata[1] = afi;
1809 ndata[2] = safi;
1810 ndata[3] = (peer->pmax[afi][safi] >> 24);
1811 ndata[4] = (peer->pmax[afi][safi] >> 16);
1812 ndata[5] = (peer->pmax[afi][safi] >> 8);
1813 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001814
1815 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1816 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1817 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1818 }
hasso0a486e52005-02-01 20:57:17 +00001819
1820 /* restart timer start */
1821 if (peer->pmax_restart[afi][safi])
1822 {
1823 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1824
1825 if (BGP_DEBUG (events, EVENTS))
1826 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1827 peer->host, peer->v_pmax_restart);
1828
1829 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1830 peer->v_pmax_restart);
1831 }
1832
hassoe0701b72004-05-20 09:19:34 +00001833 return 1;
paul718e3742002-12-13 20:15:29 +00001834 }
hassoe0701b72004-05-20 09:19:34 +00001835 else
1836 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1837
1838 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1839 {
1840 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1841 && ! always)
1842 return 0;
1843
1844 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001845 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1846 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1847 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001848 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1849 }
1850 else
1851 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001852 return 0;
1853}
1854
paulb40d9392005-08-22 22:34:41 +00001855/* Unconditionally remove the route from the RIB, without taking
1856 * damping into consideration (eg, because the session went down)
1857 */
paul94f2b392005-06-28 12:44:16 +00001858static void
paul718e3742002-12-13 20:15:29 +00001859bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1860 afi_t afi, safi_t safi)
1861{
paul902212c2006-02-05 17:51:19 +00001862 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1863
1864 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1865 bgp_info_delete (rn, ri); /* keep historical info */
1866
paulb40d9392005-08-22 22:34:41 +00001867 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001868}
1869
paul94f2b392005-06-28 12:44:16 +00001870static void
paul718e3742002-12-13 20:15:29 +00001871bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001872 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001873{
paul718e3742002-12-13 20:15:29 +00001874 int status = BGP_DAMP_NONE;
1875
paulb40d9392005-08-22 22:34:41 +00001876 /* apply dampening, if result is suppressed, we'll be retaining
1877 * the bgp_info in the RIB for historical reference.
1878 */
1879 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001880 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001881 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1882 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001883 {
paul902212c2006-02-05 17:51:19 +00001884 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1885 return;
1886 }
1887
1888 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001889}
1890
paul94f2b392005-06-28 12:44:16 +00001891static void
paulfee0f4c2004-09-13 05:12:46 +00001892bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1893 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1894 int sub_type, struct prefix_rd *prd, u_char *tag)
1895{
1896 struct bgp_node *rn;
1897 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001898 struct attr new_attr;
1899 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001900 struct attr *attr_new;
1901 struct attr *attr_new2;
1902 struct bgp_info *ri;
1903 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001904 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001905 char buf[SU_ADDRSTRLEN];
1906
1907 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1908 if (peer == rsclient)
1909 return;
1910
1911 bgp = peer->bgp;
1912 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1913
1914 /* Check previously received route. */
1915 for (ri = rn->info; ri; ri = ri->next)
1916 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1917 break;
1918
1919 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001920 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001921 {
1922 reason = "as-path contains our own AS;";
1923 goto filtered;
1924 }
1925
1926 /* Route reflector originator ID check. */
1927 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001928 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001929 {
1930 reason = "originator is us;";
1931 goto filtered;
1932 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001933
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001934 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001935 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001936
1937 /* Apply export policy. */
1938 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1939 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1940 {
1941 reason = "export-policy;";
1942 goto filtered;
1943 }
1944
1945 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001946
paulfee0f4c2004-09-13 05:12:46 +00001947 /* Apply import policy. */
1948 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1949 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001950 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001951
1952 reason = "import-policy;";
1953 goto filtered;
1954 }
1955
1956 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001957 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001958
1959 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001960 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001961 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001962 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001963 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001964 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001965 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001966 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001967
1968 reason = "martian next-hop;";
1969 goto filtered;
1970 }
1971 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001972
paulfee0f4c2004-09-13 05:12:46 +00001973 /* If the update is implicit withdraw. */
1974 if (ri)
1975 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001976 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001977
1978 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001979 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1980 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001981 {
1982
Paul Jakma1a392d42006-09-07 00:24:49 +00001983 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001984
1985 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001986 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001987 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1988 peer->host,
1989 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1990 p->prefixlen, rsclient->host);
1991
Chris Caputo228da422009-07-18 05:44:03 +00001992 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001993 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001994
Chris Caputo228da422009-07-18 05:44:03 +00001995 return;
paulfee0f4c2004-09-13 05:12:46 +00001996 }
1997
Paul Jakma16d2e242007-04-10 19:32:10 +00001998 /* Withdraw/Announce before we fully processed the withdraw */
1999 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2000 bgp_info_restore (rn, ri);
2001
paulfee0f4c2004-09-13 05:12:46 +00002002 /* Received Logging. */
2003 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002004 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002005 peer->host,
2006 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2007 p->prefixlen, rsclient->host);
2008
2009 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002010 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00002011
2012 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002013 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00002014 ri->attr = attr_new;
2015
2016 /* Update MPLS tag. */
2017 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002018 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002019
Paul Jakma1a392d42006-09-07 00:24:49 +00002020 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002021
2022 /* Process change. */
2023 bgp_process (bgp, rn, afi, safi);
2024 bgp_unlock_node (rn);
2025
2026 return;
2027 }
2028
2029 /* Received Logging. */
2030 if (BGP_DEBUG (update, UPDATE_IN))
2031 {
ajsd2c1f162004-12-08 21:10:20 +00002032 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002033 peer->host,
2034 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2035 p->prefixlen, rsclient->host);
2036 }
2037
2038 /* Make new BGP info. */
2039 new = bgp_info_new ();
2040 new->type = type;
2041 new->sub_type = sub_type;
2042 new->peer = peer;
2043 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002044 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00002045
2046 /* Update MPLS tag. */
2047 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002048 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002049
Paul Jakma1a392d42006-09-07 00:24:49 +00002050 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002051
2052 /* Register new BGP information. */
2053 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002054
2055 /* route_node_get lock */
2056 bgp_unlock_node (rn);
2057
paulfee0f4c2004-09-13 05:12:46 +00002058 /* Process change. */
2059 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002060
paulfee0f4c2004-09-13 05:12:46 +00002061 return;
2062
2063 filtered:
2064
2065 /* This BGP update is filtered. Log the reason then update BGP entry. */
2066 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002067 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002068 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2069 peer->host,
2070 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2071 p->prefixlen, rsclient->host, reason);
2072
2073 if (ri)
paulb40d9392005-08-22 22:34:41 +00002074 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002075
2076 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002077
paulfee0f4c2004-09-13 05:12:46 +00002078 return;
2079}
2080
paul94f2b392005-06-28 12:44:16 +00002081static void
paulfee0f4c2004-09-13 05:12:46 +00002082bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2083 struct peer *peer, struct prefix *p, int type, int sub_type,
2084 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002085{
paulfee0f4c2004-09-13 05:12:46 +00002086 struct bgp_node *rn;
2087 struct bgp_info *ri;
2088 char buf[SU_ADDRSTRLEN];
2089
2090 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002091 return;
paulfee0f4c2004-09-13 05:12:46 +00002092
2093 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2094
2095 /* Lookup withdrawn route. */
2096 for (ri = rn->info; ri; ri = ri->next)
2097 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2098 break;
2099
2100 /* Withdraw specified route from routing table. */
2101 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002102 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002103 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002104 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002105 "%s Can't find the route %s/%d", peer->host,
2106 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2107 p->prefixlen);
2108
2109 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002110 bgp_unlock_node (rn);
2111}
paulfee0f4c2004-09-13 05:12:46 +00002112
paul94f2b392005-06-28 12:44:16 +00002113static int
paulfee0f4c2004-09-13 05:12:46 +00002114bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002115 afi_t afi, safi_t safi, int type, int sub_type,
2116 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2117{
2118 int ret;
2119 int aspath_loop_count = 0;
2120 struct bgp_node *rn;
2121 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002122 struct attr new_attr;
2123 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002124 struct attr *attr_new;
2125 struct bgp_info *ri;
2126 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002127 const char *reason;
paul718e3742002-12-13 20:15:29 +00002128 char buf[SU_ADDRSTRLEN];
2129
2130 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002131 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002132
paul718e3742002-12-13 20:15:29 +00002133 /* When peer's soft reconfiguration enabled. Record input packet in
2134 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002135 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2136 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002137 bgp_adj_in_set (rn, peer, attr);
2138
2139 /* Check previously received route. */
2140 for (ri = rn->info; ri; ri = ri->next)
2141 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2142 break;
2143
2144 /* AS path local-as loop check. */
2145 if (peer->change_local_as)
2146 {
2147 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2148 aspath_loop_count = 1;
2149
2150 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2151 {
2152 reason = "as-path contains our own AS;";
2153 goto filtered;
2154 }
2155 }
2156
2157 /* AS path loop check. */
2158 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2159 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2160 && aspath_loop_check(attr->aspath, bgp->confed_id)
2161 > peer->allowas_in[afi][safi]))
2162 {
2163 reason = "as-path contains our own AS;";
2164 goto filtered;
2165 }
2166
2167 /* Route reflector originator ID check. */
2168 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002169 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002170 {
2171 reason = "originator is us;";
2172 goto filtered;
2173 }
2174
2175 /* Route reflector cluster ID check. */
2176 if (bgp_cluster_filter (peer, attr))
2177 {
2178 reason = "reflected from the same cluster;";
2179 goto filtered;
2180 }
2181
2182 /* Apply incoming filter. */
2183 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2184 {
2185 reason = "filter;";
2186 goto filtered;
2187 }
2188
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002189 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002190 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002191
David Lamparterc460e572014-06-04 00:54:58 +02002192 /* Apply incoming route-map.
2193 * NB: new_attr may now contain newly allocated values from route-map "set"
2194 * commands, so we need bgp_attr_flush in the error paths, until we intern
2195 * the attr (which takes over the memory references) */
paul718e3742002-12-13 20:15:29 +00002196 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2197 {
2198 reason = "route-map;";
David Lamparterc460e572014-06-04 00:54:58 +02002199 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002200 goto filtered;
2201 }
2202
2203 /* IPv4 unicast next hop check. */
2204 if (afi == AFI_IP && safi == SAFI_UNICAST)
2205 {
2206 /* If the peer is EBGP and nexthop is not on connected route,
2207 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002208 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002209 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002210 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002211 {
2212 reason = "non-connected next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002213 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002214 goto filtered;
2215 }
2216
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002217 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002218 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002219 if (new_attr.nexthop.s_addr == 0
2220 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2221 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002222 {
2223 reason = "martian next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002224 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002225 goto filtered;
2226 }
2227 }
2228
2229 attr_new = bgp_attr_intern (&new_attr);
2230
2231 /* If the update is implicit withdraw. */
2232 if (ri)
2233 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002234 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002235
2236 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002237 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2238 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002239 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002240 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002241
2242 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002243 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002244 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2245 {
2246 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002247 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002248 peer->host,
2249 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2250 p->prefixlen);
2251
paul902212c2006-02-05 17:51:19 +00002252 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2253 {
2254 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2255 bgp_process (bgp, rn, afi, safi);
2256 }
paul718e3742002-12-13 20:15:29 +00002257 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002258 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002259 {
2260 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002261 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002262 "%s rcvd %s/%d...duplicate ignored",
2263 peer->host,
2264 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2265 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002266
2267 /* graceful restart STALE flag unset. */
2268 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2269 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002270 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002271 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002272 }
paul718e3742002-12-13 20:15:29 +00002273 }
2274
2275 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002276 bgp_attr_unintern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002277
paul718e3742002-12-13 20:15:29 +00002278 return 0;
2279 }
2280
Paul Jakma16d2e242007-04-10 19:32:10 +00002281 /* Withdraw/Announce before we fully processed the withdraw */
2282 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2283 {
2284 if (BGP_DEBUG (update, UPDATE_IN))
2285 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2286 peer->host,
2287 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2288 p->prefixlen);
2289 bgp_info_restore (rn, ri);
2290 }
2291
paul718e3742002-12-13 20:15:29 +00002292 /* Received Logging. */
2293 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002294 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002295 peer->host,
2296 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2297 p->prefixlen);
2298
hasso93406d82005-02-02 14:40:33 +00002299 /* graceful restart STALE flag unset. */
2300 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002301 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002302
paul718e3742002-12-13 20:15:29 +00002303 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002304 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002305
2306 /* implicit withdraw, decrement aggregate and pcount here.
2307 * only if update is accepted, they'll increment below.
2308 */
paul902212c2006-02-05 17:51:19 +00002309 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2310
paul718e3742002-12-13 20:15:29 +00002311 /* Update bgp route dampening information. */
2312 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002313 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002314 {
2315 /* This is implicit withdraw so we should update dampening
2316 information. */
2317 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2318 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002319 }
2320
paul718e3742002-12-13 20:15:29 +00002321 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002322 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002323 ri->attr = attr_new;
2324
2325 /* Update MPLS tag. */
2326 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002327 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002328
2329 /* Update bgp route dampening information. */
2330 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002331 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002332 {
2333 /* Now we do normal update dampening. */
2334 ret = bgp_damp_update (ri, rn, afi, safi);
2335 if (ret == BGP_DAMP_SUPPRESSED)
2336 {
2337 bgp_unlock_node (rn);
2338 return 0;
2339 }
2340 }
2341
2342 /* Nexthop reachability check. */
2343 if ((afi == AFI_IP || afi == AFI_IP6)
2344 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002345 && (peer->sort == BGP_PEER_IBGP
2346 || peer->sort == BGP_PEER_CONFED
2347 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002348 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002349 {
2350 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002351 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002352 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002353 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002354 }
2355 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002356 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002357
2358 /* Process change. */
2359 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2360
2361 bgp_process (bgp, rn, afi, safi);
2362 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002363
paul718e3742002-12-13 20:15:29 +00002364 return 0;
2365 }
2366
2367 /* Received Logging. */
2368 if (BGP_DEBUG (update, UPDATE_IN))
2369 {
ajsd2c1f162004-12-08 21:10:20 +00002370 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002371 peer->host,
2372 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2373 p->prefixlen);
2374 }
2375
paul718e3742002-12-13 20:15:29 +00002376 /* Make new BGP info. */
2377 new = bgp_info_new ();
2378 new->type = type;
2379 new->sub_type = sub_type;
2380 new->peer = peer;
2381 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002382 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002383
2384 /* Update MPLS tag. */
2385 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002386 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002387
2388 /* Nexthop reachability check. */
2389 if ((afi == AFI_IP || afi == AFI_IP6)
2390 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002391 && (peer->sort == BGP_PEER_IBGP
2392 || peer->sort == BGP_PEER_CONFED
2393 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002394 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002395 {
2396 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002397 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002398 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002399 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002400 }
2401 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002402 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002403
paul902212c2006-02-05 17:51:19 +00002404 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002405 bgp_aggregate_increment (bgp, p, new, afi, safi);
2406
2407 /* Register new BGP information. */
2408 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002409
2410 /* route_node_get lock */
2411 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002412
paul718e3742002-12-13 20:15:29 +00002413 /* If maximum prefix count is configured and current prefix
2414 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002415 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2416 return -1;
paul718e3742002-12-13 20:15:29 +00002417
2418 /* Process change. */
2419 bgp_process (bgp, rn, afi, safi);
2420
2421 return 0;
2422
2423 /* This BGP update is filtered. Log the reason then update BGP
2424 entry. */
2425 filtered:
2426 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002427 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002428 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2429 peer->host,
2430 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2431 p->prefixlen, reason);
2432
2433 if (ri)
paulb40d9392005-08-22 22:34:41 +00002434 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002435
2436 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002437
paul718e3742002-12-13 20:15:29 +00002438 return 0;
2439}
2440
2441int
paulfee0f4c2004-09-13 05:12:46 +00002442bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2443 afi_t afi, safi_t safi, int type, int sub_type,
2444 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2445{
2446 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002447 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002448 struct bgp *bgp;
2449 int ret;
2450
2451 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2452 soft_reconfig);
2453
2454 bgp = peer->bgp;
2455
2456 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002457 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002458 {
2459 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2460 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2461 sub_type, prd, tag);
2462 }
2463
2464 return ret;
2465}
2466
2467int
paul718e3742002-12-13 20:15:29 +00002468bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002469 afi_t afi, safi_t safi, int type, int sub_type,
2470 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002471{
2472 struct bgp *bgp;
2473 char buf[SU_ADDRSTRLEN];
2474 struct bgp_node *rn;
2475 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002476 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002477 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002478
2479 bgp = peer->bgp;
2480
David Lamparter4584c232015-04-13 09:50:00 +02002481 /* Lookup node. */
2482 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2483
2484 /* Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2485 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2486 * the iteration over all RS clients.
2487 * Since we need to remove the entry from adj_in anyway, do that first and
2488 * if there was no entry, we don't need to do anything more. */
2489 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2490 && peer != bgp->peer_self)
2491 if (!bgp_adj_in_unset (rn, peer))
2492 {
2493 if (BGP_DEBUG (update, UPDATE_IN))
2494 zlog (peer->log, LOG_DEBUG, "%s withdrawing route %s/%d "
2495 "not in adj-in", peer->host,
2496 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2497 p->prefixlen);
2498 bgp_unlock_node (rn);
2499 return 0;
2500 }
2501
paulfee0f4c2004-09-13 05:12:46 +00002502 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002503 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002504 {
2505 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2506 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2507 }
2508
paul718e3742002-12-13 20:15:29 +00002509 /* Logging. */
2510 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002511 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002512 peer->host,
2513 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2514 p->prefixlen);
2515
paul718e3742002-12-13 20:15:29 +00002516 /* Lookup withdrawn route. */
2517 for (ri = rn->info; ri; ri = ri->next)
2518 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2519 break;
2520
2521 /* Withdraw specified route from routing table. */
2522 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002523 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002524 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002525 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002526 "%s Can't find the route %s/%d", peer->host,
2527 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2528 p->prefixlen);
2529
2530 /* Unlock bgp_node_get() lock. */
2531 bgp_unlock_node (rn);
2532
2533 return 0;
2534}
David Lamparter6b0655a2014-06-04 06:53:35 +02002535
paul718e3742002-12-13 20:15:29 +00002536void
2537bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2538{
2539 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002540 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002541 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002542 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002543 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002544 struct bgp_node *rn;
2545 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002546 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002547
Paul Jakmab2497022007-06-14 11:17:58 +00002548 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002549 return;
2550
paul718e3742002-12-13 20:15:29 +00002551 bgp = peer->bgp;
2552 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002553
paul718e3742002-12-13 20:15:29 +00002554 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2555 aspath = attr.aspath;
2556 attr.local_pref = bgp->default_local_pref;
2557 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2558
2559 if (afi == AFI_IP)
2560 str2prefix ("0.0.0.0/0", &p);
2561#ifdef HAVE_IPV6
2562 else if (afi == AFI_IP6)
2563 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002564 struct attr_extra *ae = attr.extra;
2565
paul718e3742002-12-13 20:15:29 +00002566 str2prefix ("::/0", &p);
2567
2568 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002569 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002570 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002571 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002572
2573 /* If the peer is on shared nextwork and we have link-local
2574 nexthop set it. */
2575 if (peer->shared_network
2576 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2577 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002578 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002579 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002580 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002581 }
2582 }
2583#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002584
2585 if (peer->default_rmap[afi][safi].name)
2586 {
paulfee0f4c2004-09-13 05:12:46 +00002587 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002588 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2589 {
2590 for (ri = rn->info; ri; ri = ri->next)
2591 {
2592 struct attr dummy_attr;
2593 struct attr_extra dummy_extra;
2594 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002595
Christian Frankedcab1bb2012-12-07 16:45:52 +00002596 /* Provide dummy so the route-map can't modify the attributes */
2597 dummy_attr.extra = &dummy_extra;
2598 bgp_attr_dup(&dummy_attr, ri->attr);
2599 info.peer = ri->peer;
2600 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002601
Christian Frankedcab1bb2012-12-07 16:45:52 +00002602 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2603 RMAP_BGP, &info);
2604
2605 /* The route map might have set attributes. If we don't flush them
2606 * here, they will be leaked. */
2607 bgp_attr_flush(&dummy_attr);
2608 if (ret != RMAP_DENYMATCH)
2609 break;
2610 }
2611 if (ret != RMAP_DENYMATCH)
2612 break;
2613 }
paulfee0f4c2004-09-13 05:12:46 +00002614 bgp->peer_self->rmap_type = 0;
2615
paul718e3742002-12-13 20:15:29 +00002616 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002617 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002618 }
2619
2620 if (withdraw)
2621 {
2622 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2623 bgp_default_withdraw_send (peer, afi, safi);
2624 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2625 }
2626 else
2627 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002628 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2629 {
2630 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2631 bgp_default_update_send (peer, &attr, afi, safi, from);
2632 }
paul718e3742002-12-13 20:15:29 +00002633 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002634
2635 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002636 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002637}
David Lamparter6b0655a2014-06-04 06:53:35 +02002638
paul718e3742002-12-13 20:15:29 +00002639static void
2640bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002641 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002642{
2643 struct bgp_node *rn;
2644 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002645 struct attr attr;
2646 struct attr_extra extra;
2647
paul718e3742002-12-13 20:15:29 +00002648 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002649 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002650
2651 if (safi != SAFI_MPLS_VPN
2652 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2653 bgp_default_originate (peer, afi, safi, 0);
2654
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002655 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2656 attr.extra = &extra;
2657
paul718e3742002-12-13 20:15:29 +00002658 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2659 for (ri = rn->info; ri; ri = ri->next)
2660 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2661 {
paulfee0f4c2004-09-13 05:12:46 +00002662 if ( (rsclient) ?
2663 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2664 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002665 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2666 else
2667 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2668 }
2669}
2670
2671void
2672bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2673{
2674 struct bgp_node *rn;
2675 struct bgp_table *table;
2676
2677 if (peer->status != Established)
2678 return;
2679
2680 if (! peer->afc_nego[afi][safi])
2681 return;
2682
2683 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2684 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2685 return;
2686
2687 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002688 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002689 else
2690 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2691 rn = bgp_route_next(rn))
2692 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002693 bgp_announce_table (peer, afi, safi, table, 0);
2694
2695 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2696 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002697}
2698
2699void
2700bgp_announce_route_all (struct peer *peer)
2701{
2702 afi_t afi;
2703 safi_t safi;
2704
2705 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2706 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2707 bgp_announce_route (peer, afi, safi);
2708}
David Lamparter6b0655a2014-06-04 06:53:35 +02002709
paul718e3742002-12-13 20:15:29 +00002710static void
paulfee0f4c2004-09-13 05:12:46 +00002711bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002712 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002713{
2714 struct bgp_node *rn;
2715 struct bgp_adj_in *ain;
2716
2717 if (! table)
2718 table = rsclient->bgp->rib[afi][safi];
2719
2720 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2721 for (ain = rn->adj_in; ain; ain = ain->next)
2722 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002723 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002724 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002725
paulfee0f4c2004-09-13 05:12:46 +00002726 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002727 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002728 }
2729}
2730
2731void
2732bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2733{
2734 struct bgp_table *table;
2735 struct bgp_node *rn;
2736
2737 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002738 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002739
2740 else
2741 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2742 rn = bgp_route_next (rn))
2743 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002744 {
2745 struct prefix_rd prd;
2746 prd.family = AF_UNSPEC;
2747 prd.prefixlen = 64;
2748 memcpy(&prd.val, rn->p.u.val, 8);
2749
2750 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2751 }
paulfee0f4c2004-09-13 05:12:46 +00002752}
David Lamparter6b0655a2014-06-04 06:53:35 +02002753
paulfee0f4c2004-09-13 05:12:46 +00002754static void
paul718e3742002-12-13 20:15:29 +00002755bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002756 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002757{
2758 int ret;
2759 struct bgp_node *rn;
2760 struct bgp_adj_in *ain;
2761
2762 if (! table)
2763 table = peer->bgp->rib[afi][safi];
2764
2765 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2766 for (ain = rn->adj_in; ain; ain = ain->next)
2767 {
2768 if (ain->peer == peer)
2769 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002770 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002771 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002772
paul718e3742002-12-13 20:15:29 +00002773 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2774 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002775 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002776
paul718e3742002-12-13 20:15:29 +00002777 if (ret < 0)
2778 {
2779 bgp_unlock_node (rn);
2780 return;
2781 }
2782 continue;
2783 }
2784 }
2785}
2786
2787void
2788bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2789{
2790 struct bgp_node *rn;
2791 struct bgp_table *table;
2792
2793 if (peer->status != Established)
2794 return;
2795
2796 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002797 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002798 else
2799 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2800 rn = bgp_route_next (rn))
2801 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002802 {
2803 struct prefix_rd prd;
2804 prd.family = AF_UNSPEC;
2805 prd.prefixlen = 64;
2806 memcpy(&prd.val, rn->p.u.val, 8);
2807
2808 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2809 }
paul718e3742002-12-13 20:15:29 +00002810}
David Lamparter6b0655a2014-06-04 06:53:35 +02002811
Chris Caputo228da422009-07-18 05:44:03 +00002812
2813struct bgp_clear_node_queue
2814{
2815 struct bgp_node *rn;
2816 enum bgp_clear_route_type purpose;
2817};
2818
paul200df112005-06-01 11:17:05 +00002819static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002820bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002821{
Chris Caputo228da422009-07-18 05:44:03 +00002822 struct bgp_clear_node_queue *cnq = data;
2823 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002824 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002825 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002826 afi_t afi = bgp_node_table (rn)->afi;
2827 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002828
Paul Jakma64e580a2006-02-21 01:09:01 +00002829 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002830
Paul Jakma64e580a2006-02-21 01:09:01 +00002831 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002832 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002833 {
2834 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002835 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2836 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002837 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002838 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2839 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002840 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002841 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002842 break;
2843 }
paul200df112005-06-01 11:17:05 +00002844 return WQ_SUCCESS;
2845}
2846
2847static void
paul0fb58d52005-11-14 14:31:49 +00002848bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002849{
Chris Caputo228da422009-07-18 05:44:03 +00002850 struct bgp_clear_node_queue *cnq = data;
2851 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002852 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002853
2854 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002855 bgp_table_unlock (table);
2856 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002857}
2858
2859static void
paul94f2b392005-06-28 12:44:16 +00002860bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002861{
Paul Jakma64e580a2006-02-21 01:09:01 +00002862 struct peer *peer = wq->spec.data;
2863
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002864 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002865 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002866
2867 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002868}
2869
2870static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002871bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002872{
Paul Jakmaa2943652009-07-21 14:02:04 +01002873 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002874
Paul Jakmaa2943652009-07-21 14:02:04 +01002875 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002876#undef CLEAR_QUEUE_NAME_LEN
2877
2878 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002879 {
2880 zlog_err ("%s: Failed to allocate work queue", __func__);
2881 exit (1);
2882 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002883 peer->clear_node_queue->spec.hold = 10;
2884 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2885 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2886 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2887 peer->clear_node_queue->spec.max_retries = 0;
2888
2889 /* we only 'lock' this peer reference when the queue is actually active */
2890 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002891}
2892
paul718e3742002-12-13 20:15:29 +00002893static void
2894bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002895 struct bgp_table *table, struct peer *rsclient,
2896 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002897{
2898 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002899
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002900
paul718e3742002-12-13 20:15:29 +00002901 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002902 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002903
hasso6cf159b2005-03-21 10:28:14 +00002904 /* If still no table => afi/safi isn't configured at all or smth. */
2905 if (! table)
2906 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002907
2908 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2909 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002910 struct bgp_info *ri;
2911 struct bgp_adj_in *ain;
2912 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002913
2914 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2915 * queued for every clearing peer, regardless of whether it is
2916 * relevant to the peer at hand.
2917 *
2918 * Overview: There are 3 different indices which need to be
2919 * scrubbed, potentially, when a peer is removed:
2920 *
2921 * 1 peer's routes visible via the RIB (ie accepted routes)
2922 * 2 peer's routes visible by the (optional) peer's adj-in index
2923 * 3 other routes visible by the peer's adj-out index
2924 *
2925 * 3 there is no hurry in scrubbing, once the struct peer is
2926 * removed from bgp->peer, we could just GC such deleted peer's
2927 * adj-outs at our leisure.
2928 *
2929 * 1 and 2 must be 'scrubbed' in some way, at least made
2930 * invisible via RIB index before peer session is allowed to be
2931 * brought back up. So one needs to know when such a 'search' is
2932 * complete.
2933 *
2934 * Ideally:
2935 *
2936 * - there'd be a single global queue or a single RIB walker
2937 * - rather than tracking which route_nodes still need to be
2938 * examined on a peer basis, we'd track which peers still
2939 * aren't cleared
2940 *
2941 * Given that our per-peer prefix-counts now should be reliable,
2942 * this may actually be achievable. It doesn't seem to be a huge
2943 * problem at this time,
2944 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002945 for (ain = rn->adj_in; ain; ain = ain->next)
2946 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2947 {
2948 bgp_adj_in_remove (rn, ain);
2949 bgp_unlock_node (rn);
2950 break;
2951 }
2952 for (aout = rn->adj_out; aout; aout = aout->next)
2953 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2954 {
2955 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2956 bgp_unlock_node (rn);
2957 break;
2958 }
2959
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002960 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002961 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002962 {
Chris Caputo228da422009-07-18 05:44:03 +00002963 struct bgp_clear_node_queue *cnq;
2964
2965 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002966 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002967 bgp_lock_node (rn);
2968 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2969 sizeof (struct bgp_clear_node_queue));
2970 cnq->rn = rn;
2971 cnq->purpose = purpose;
2972 work_queue_add (peer->clear_node_queue, cnq);
2973 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002974 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002975 }
2976 return;
2977}
2978
2979void
Chris Caputo228da422009-07-18 05:44:03 +00002980bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2981 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002982{
2983 struct bgp_node *rn;
2984 struct bgp_table *table;
2985 struct peer *rsclient;
2986 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002987
Paul Jakma64e580a2006-02-21 01:09:01 +00002988 if (peer->clear_node_queue == NULL)
2989 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002990
Paul Jakmaca058a32006-09-14 02:58:49 +00002991 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2992 * Idle until it receives a Clearing_Completed event. This protects
2993 * against peers which flap faster than we can we clear, which could
2994 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002995 *
2996 * a) race with routes from the new session being installed before
2997 * clear_route_node visits the node (to delete the route of that
2998 * peer)
2999 * b) resource exhaustion, clear_route_node likely leads to an entry
3000 * on the process_main queue. Fast-flapping could cause that queue
3001 * to grow and grow.
paul200df112005-06-01 11:17:05 +00003002 */
Donald Sharp7ef42212015-03-30 06:32:52 -07003003
3004 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3005 * the unlock will happen upon work-queue completion; other wise, the
3006 * unlock happens at the end of this function.
3007 */
Paul Jakmaca058a32006-09-14 02:58:49 +00003008 if (!peer->clear_node_queue->thread)
Donald Sharp7ef42212015-03-30 06:32:52 -07003009 peer_lock (peer);
paulfee0f4c2004-09-13 05:12:46 +00003010
Chris Caputo228da422009-07-18 05:44:03 +00003011 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00003012 {
Chris Caputo228da422009-07-18 05:44:03 +00003013 case BGP_CLEAR_ROUTE_NORMAL:
3014 if (safi != SAFI_MPLS_VPN)
3015 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
3016 else
3017 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3018 rn = bgp_route_next (rn))
3019 if ((table = rn->info) != NULL)
3020 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3021
3022 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
3023 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
3024 PEER_FLAG_RSERVER_CLIENT))
3025 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3026 break;
3027
3028 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
3029 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3030 break;
3031
3032 default:
3033 assert (0);
3034 break;
paulfee0f4c2004-09-13 05:12:46 +00003035 }
Donald Sharp7ef42212015-03-30 06:32:52 -07003036
3037 /* unlock if no nodes got added to the clear-node-queue. */
Paul Jakma65ca75e2006-05-04 08:08:15 +00003038 if (!peer->clear_node_queue->thread)
Donald Sharp7ef42212015-03-30 06:32:52 -07003039 peer_unlock (peer);
3040
paul718e3742002-12-13 20:15:29 +00003041}
3042
3043void
3044bgp_clear_route_all (struct peer *peer)
3045{
3046 afi_t afi;
3047 safi_t safi;
3048
3049 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3050 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003051 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003052}
3053
3054void
3055bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3056{
3057 struct bgp_table *table;
3058 struct bgp_node *rn;
3059 struct bgp_adj_in *ain;
3060
3061 table = peer->bgp->rib[afi][safi];
3062
3063 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3064 for (ain = rn->adj_in; ain ; ain = ain->next)
3065 if (ain->peer == peer)
3066 {
3067 bgp_adj_in_remove (rn, ain);
3068 bgp_unlock_node (rn);
3069 break;
3070 }
3071}
hasso93406d82005-02-02 14:40:33 +00003072
3073void
3074bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3075{
3076 struct bgp_node *rn;
3077 struct bgp_info *ri;
3078 struct bgp_table *table;
3079
3080 table = peer->bgp->rib[afi][safi];
3081
3082 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3083 {
3084 for (ri = rn->info; ri; ri = ri->next)
3085 if (ri->peer == peer)
3086 {
3087 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3088 bgp_rib_remove (rn, ri, peer, afi, safi);
3089 break;
3090 }
3091 }
3092}
David Lamparter6b0655a2014-06-04 06:53:35 +02003093
paul718e3742002-12-13 20:15:29 +00003094/* Delete all kernel routes. */
3095void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003096bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003097{
3098 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003099 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003100 struct bgp_node *rn;
3101 struct bgp_table *table;
3102 struct bgp_info *ri;
3103
paul1eb8ef22005-04-07 07:30:20 +00003104 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003105 {
3106 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3107
3108 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3109 for (ri = rn->info; ri; ri = ri->next)
3110 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3111 && ri->type == ZEBRA_ROUTE_BGP
3112 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003113 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003114
3115 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3116
3117 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3118 for (ri = rn->info; ri; ri = ri->next)
3119 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3120 && ri->type == ZEBRA_ROUTE_BGP
3121 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003122 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003123 }
3124}
3125
3126void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003127bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003128{
3129 vty_reset ();
3130 bgp_zclient_reset ();
3131 access_list_reset ();
3132 prefix_list_reset ();
3133}
David Lamparter6b0655a2014-06-04 06:53:35 +02003134
paul718e3742002-12-13 20:15:29 +00003135/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3136 value. */
3137int
3138bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3139{
3140 u_char *pnt;
3141 u_char *lim;
3142 struct prefix p;
3143 int psize;
3144 int ret;
3145
3146 /* Check peer status. */
3147 if (peer->status != Established)
3148 return 0;
3149
3150 pnt = packet->nlri;
3151 lim = pnt + packet->length;
3152
3153 for (; pnt < lim; pnt += psize)
3154 {
3155 /* Clear prefix structure. */
3156 memset (&p, 0, sizeof (struct prefix));
3157
3158 /* Fetch prefix length. */
3159 p.prefixlen = *pnt++;
3160 p.family = afi2family (packet->afi);
3161
3162 /* Already checked in nlri_sanity_check(). We do double check
3163 here. */
3164 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3165 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3166 return -1;
3167
3168 /* Packet size overflow check. */
3169 psize = PSIZE (p.prefixlen);
3170
3171 /* When packet overflow occur return immediately. */
3172 if (pnt + psize > lim)
3173 return -1;
3174
3175 /* Fetch prefix from NLRI packet. */
3176 memcpy (&p.u.prefix, pnt, psize);
3177
3178 /* Check address. */
3179 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3180 {
3181 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3182 {
paulf5ba3872004-07-09 12:11:31 +00003183 /*
3184 * From draft-ietf-idr-bgp4-22, Section 6.3:
3185 * If a BGP router receives an UPDATE message with a
3186 * semantically incorrect NLRI field, in which a prefix is
3187 * semantically incorrect (eg. an unexpected multicast IP
3188 * address), it should ignore the prefix.
3189 */
paul718e3742002-12-13 20:15:29 +00003190 zlog (peer->log, LOG_ERR,
3191 "IPv4 unicast NLRI is multicast address %s",
3192 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003193
paul718e3742002-12-13 20:15:29 +00003194 return -1;
3195 }
3196 }
3197
3198#ifdef HAVE_IPV6
3199 /* Check address. */
3200 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3201 {
3202 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3203 {
3204 char buf[BUFSIZ];
3205
3206 zlog (peer->log, LOG_WARNING,
3207 "IPv6 link-local NLRI received %s ignore this NLRI",
3208 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3209
3210 continue;
3211 }
3212 }
3213#endif /* HAVE_IPV6 */
3214
3215 /* Normal process. */
3216 if (attr)
3217 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3218 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3219 else
3220 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3221 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3222
3223 /* Address family configuration mismatch or maximum-prefix count
3224 overflow. */
3225 if (ret < 0)
3226 return -1;
3227 }
3228
3229 /* Packet length consistency check. */
3230 if (pnt != lim)
3231 return -1;
3232
3233 return 0;
3234}
3235
3236/* NLRI encode syntax check routine. */
3237int
3238bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3239 bgp_size_t length)
3240{
3241 u_char *end;
3242 u_char prefixlen;
3243 int psize;
3244
3245 end = pnt + length;
3246
3247 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3248 syntactic validity. If the field is syntactically incorrect,
3249 then the Error Subcode is set to Invalid Network Field. */
3250
3251 while (pnt < end)
3252 {
3253 prefixlen = *pnt++;
3254
3255 /* Prefix length check. */
3256 if ((afi == AFI_IP && prefixlen > 32)
3257 || (afi == AFI_IP6 && prefixlen > 128))
3258 {
3259 plog_err (peer->log,
3260 "%s [Error] Update packet error (wrong prefix length %d)",
3261 peer->host, prefixlen);
3262 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3263 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3264 return -1;
3265 }
3266
3267 /* Packet size overflow check. */
3268 psize = PSIZE (prefixlen);
3269
3270 if (pnt + psize > end)
3271 {
3272 plog_err (peer->log,
3273 "%s [Error] Update packet error"
3274 " (prefix data overflow prefix size is %d)",
3275 peer->host, psize);
3276 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3277 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3278 return -1;
3279 }
3280
3281 pnt += psize;
3282 }
3283
3284 /* Packet length consistency check. */
3285 if (pnt != end)
3286 {
3287 plog_err (peer->log,
3288 "%s [Error] Update packet error"
3289 " (prefix length mismatch with total length)",
3290 peer->host);
3291 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3292 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3293 return -1;
3294 }
3295 return 0;
3296}
David Lamparter6b0655a2014-06-04 06:53:35 +02003297
paul94f2b392005-06-28 12:44:16 +00003298static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003299bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003300{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003301 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003302}
3303
paul94f2b392005-06-28 12:44:16 +00003304static void
paul718e3742002-12-13 20:15:29 +00003305bgp_static_free (struct bgp_static *bgp_static)
3306{
3307 if (bgp_static->rmap.name)
3308 free (bgp_static->rmap.name);
3309 XFREE (MTYPE_BGP_STATIC, bgp_static);
3310}
3311
paul94f2b392005-06-28 12:44:16 +00003312static void
paulfee0f4c2004-09-13 05:12:46 +00003313bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3314 struct prefix *p, afi_t afi, safi_t safi)
3315{
3316 struct bgp_node *rn;
3317 struct bgp_info *ri;
3318
3319 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3320
3321 /* Check selected route and self inserted route. */
3322 for (ri = rn->info; ri; ri = ri->next)
3323 if (ri->peer == bgp->peer_self
3324 && ri->type == ZEBRA_ROUTE_BGP
3325 && ri->sub_type == BGP_ROUTE_STATIC)
3326 break;
3327
3328 /* Withdraw static BGP route from routing table. */
3329 if (ri)
3330 {
paulfee0f4c2004-09-13 05:12:46 +00003331 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003332 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003333 }
3334
3335 /* Unlock bgp_node_lookup. */
3336 bgp_unlock_node (rn);
3337}
3338
paul94f2b392005-06-28 12:44:16 +00003339static void
paulfee0f4c2004-09-13 05:12:46 +00003340bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003341 struct bgp_static *bgp_static,
3342 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003343{
3344 struct bgp_node *rn;
3345 struct bgp_info *ri;
3346 struct bgp_info *new;
3347 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003348 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003349 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003350 struct attr new_attr;
3351 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003352 struct bgp *bgp;
3353 int ret;
3354 char buf[SU_ADDRSTRLEN];
3355
3356 bgp = rsclient->bgp;
3357
Paul Jakma06e110f2006-05-12 23:29:22 +00003358 assert (bgp_static);
3359 if (!bgp_static)
3360 return;
3361
paulfee0f4c2004-09-13 05:12:46 +00003362 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3363
3364 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003365
3366 attr.nexthop = bgp_static->igpnexthop;
3367 attr.med = bgp_static->igpmetric;
3368 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003369
Paul Jakma41367172007-08-06 15:24:51 +00003370 if (bgp_static->atomic)
3371 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3372
paulfee0f4c2004-09-13 05:12:46 +00003373 /* Apply network route-map for export to this rsclient. */
3374 if (bgp_static->rmap.name)
3375 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003376 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003377 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003378 info.attr = &attr_tmp;
3379
paulfee0f4c2004-09-13 05:12:46 +00003380 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3381 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3382
3383 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3384
3385 rsclient->rmap_type = 0;
3386
3387 if (ret == RMAP_DENYMATCH)
3388 {
3389 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003390 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003391
3392 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003393 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003394 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003395 bgp_attr_extra_free (&attr);
3396
paulfee0f4c2004-09-13 05:12:46 +00003397 return;
3398 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003399 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003400 }
3401 else
3402 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003403
3404 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003405 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003406
paulfee0f4c2004-09-13 05:12:46 +00003407 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3408
Paul Jakmafb982c22007-05-04 20:15:47 +00003409 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3410 == RMAP_DENY)
3411 {
paulfee0f4c2004-09-13 05:12:46 +00003412 /* This BGP update is filtered. Log the reason then update BGP entry. */
3413 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003414 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003415 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3416 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3417 p->prefixlen, rsclient->host);
3418
3419 bgp->peer_self->rmap_type = 0;
3420
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003421 bgp_attr_unintern (&attr_new);
3422 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003423 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003424
3425 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3426
3427 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003428 }
paulfee0f4c2004-09-13 05:12:46 +00003429
3430 bgp->peer_self->rmap_type = 0;
3431
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003432 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003433 attr_new = bgp_attr_intern (&new_attr);
3434
3435 for (ri = rn->info; ri; ri = ri->next)
3436 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3437 && ri->sub_type == BGP_ROUTE_STATIC)
3438 break;
3439
3440 if (ri)
3441 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003442 if (attrhash_cmp (ri->attr, attr_new) &&
3443 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003444 {
3445 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003446 bgp_attr_unintern (&attr_new);
3447 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003448 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003449 return;
3450 }
3451 else
3452 {
3453 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003454 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003455
3456 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003457 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3458 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003459 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003460 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003461 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003462
3463 /* Process change. */
3464 bgp_process (bgp, rn, afi, safi);
3465 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003466 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003467 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003468 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003469 }
paulfee0f4c2004-09-13 05:12:46 +00003470 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003471
paulfee0f4c2004-09-13 05:12:46 +00003472 /* Make new BGP info. */
3473 new = bgp_info_new ();
3474 new->type = ZEBRA_ROUTE_BGP;
3475 new->sub_type = BGP_ROUTE_STATIC;
3476 new->peer = bgp->peer_self;
3477 SET_FLAG (new->flags, BGP_INFO_VALID);
3478 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003479 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003480
3481 /* Register new BGP information. */
3482 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003483
3484 /* route_node_get lock */
3485 bgp_unlock_node (rn);
3486
paulfee0f4c2004-09-13 05:12:46 +00003487 /* Process change. */
3488 bgp_process (bgp, rn, afi, safi);
3489
3490 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003491 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003492 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003493}
3494
paul94f2b392005-06-28 12:44:16 +00003495static void
paulfee0f4c2004-09-13 05:12:46 +00003496bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003497 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3498{
3499 struct bgp_node *rn;
3500 struct bgp_info *ri;
3501 struct bgp_info *new;
3502 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003503 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003504 struct attr *attr_new;
3505 int ret;
3506
Paul Jakmadd8103a2006-05-12 23:27:30 +00003507 assert (bgp_static);
3508 if (!bgp_static)
3509 return;
3510
paulfee0f4c2004-09-13 05:12:46 +00003511 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003512
3513 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003514
3515 attr.nexthop = bgp_static->igpnexthop;
3516 attr.med = bgp_static->igpmetric;
3517 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003518
Paul Jakma41367172007-08-06 15:24:51 +00003519 if (bgp_static->atomic)
3520 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3521
paul718e3742002-12-13 20:15:29 +00003522 /* Apply route-map. */
3523 if (bgp_static->rmap.name)
3524 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003525 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003526 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003527 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003528
paulfee0f4c2004-09-13 05:12:46 +00003529 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3530
paul718e3742002-12-13 20:15:29 +00003531 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003532
paulfee0f4c2004-09-13 05:12:46 +00003533 bgp->peer_self->rmap_type = 0;
3534
paul718e3742002-12-13 20:15:29 +00003535 if (ret == RMAP_DENYMATCH)
3536 {
3537 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003538 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003539
3540 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003541 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003542 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003543 bgp_static_withdraw (bgp, p, afi, safi);
3544 return;
3545 }
paul286e1e72003-08-08 00:24:31 +00003546 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003547 }
paul286e1e72003-08-08 00:24:31 +00003548 else
3549 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003550
3551 for (ri = rn->info; ri; ri = ri->next)
3552 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3553 && ri->sub_type == BGP_ROUTE_STATIC)
3554 break;
3555
3556 if (ri)
3557 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003558 if (attrhash_cmp (ri->attr, attr_new) &&
3559 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003560 {
3561 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003562 bgp_attr_unintern (&attr_new);
3563 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003564 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003565 return;
3566 }
3567 else
3568 {
3569 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003570 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003571
3572 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003573 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3574 bgp_info_restore(rn, ri);
3575 else
3576 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003577 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003578 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003579 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003580
3581 /* Process change. */
3582 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3583 bgp_process (bgp, rn, afi, safi);
3584 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003585 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003586 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003587 return;
3588 }
3589 }
3590
3591 /* Make new BGP info. */
3592 new = bgp_info_new ();
3593 new->type = ZEBRA_ROUTE_BGP;
3594 new->sub_type = BGP_ROUTE_STATIC;
3595 new->peer = bgp->peer_self;
3596 SET_FLAG (new->flags, BGP_INFO_VALID);
3597 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003598 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003599
3600 /* Aggregate address increment. */
3601 bgp_aggregate_increment (bgp, p, new, afi, safi);
3602
3603 /* Register new BGP information. */
3604 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003605
3606 /* route_node_get lock */
3607 bgp_unlock_node (rn);
3608
paul718e3742002-12-13 20:15:29 +00003609 /* Process change. */
3610 bgp_process (bgp, rn, afi, safi);
3611
3612 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003613 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003614 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003615}
3616
3617void
paulfee0f4c2004-09-13 05:12:46 +00003618bgp_static_update (struct bgp *bgp, struct prefix *p,
3619 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3620{
3621 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003622 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003623
3624 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3625
paul1eb8ef22005-04-07 07:30:20 +00003626 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003627 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003628 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3629 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003630 }
3631}
3632
paul718e3742002-12-13 20:15:29 +00003633void
3634bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3635 safi_t safi)
3636{
3637 struct bgp_node *rn;
3638 struct bgp_info *ri;
3639
paulfee0f4c2004-09-13 05:12:46 +00003640 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003641
3642 /* Check selected route and self inserted route. */
3643 for (ri = rn->info; ri; ri = ri->next)
3644 if (ri->peer == bgp->peer_self
3645 && ri->type == ZEBRA_ROUTE_BGP
3646 && ri->sub_type == BGP_ROUTE_STATIC)
3647 break;
3648
3649 /* Withdraw static BGP route from routing table. */
3650 if (ri)
3651 {
3652 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003653 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003654 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003655 }
3656
3657 /* Unlock bgp_node_lookup. */
3658 bgp_unlock_node (rn);
3659}
3660
3661void
paulfee0f4c2004-09-13 05:12:46 +00003662bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3663{
3664 struct bgp_static *bgp_static;
3665 struct bgp *bgp;
3666 struct bgp_node *rn;
3667 struct prefix *p;
3668
3669 bgp = rsclient->bgp;
3670
3671 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3672 if ((bgp_static = rn->info) != NULL)
3673 {
3674 p = &rn->p;
3675
3676 bgp_static_update_rsclient (rsclient, p, bgp_static,
3677 afi, safi);
3678 }
3679}
3680
Lou Bergera76d9ca2016-01-12 13:41:53 -05003681/*
3682 * Used for SAFI_MPLS_VPN and SAFI_ENCAP
3683 */
paul94f2b392005-06-28 12:44:16 +00003684static void
Lou Bergera76d9ca2016-01-12 13:41:53 -05003685bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
3686 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003687{
3688 struct bgp_node *rn;
3689 struct bgp_info *ri;
3690
paulfee0f4c2004-09-13 05:12:46 +00003691 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003692
3693 /* Check selected route and self inserted route. */
3694 for (ri = rn->info; ri; ri = ri->next)
3695 if (ri->peer == bgp->peer_self
3696 && ri->type == ZEBRA_ROUTE_BGP
3697 && ri->sub_type == BGP_ROUTE_STATIC)
3698 break;
3699
3700 /* Withdraw static BGP route from routing table. */
3701 if (ri)
3702 {
3703 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003704 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003705 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003706 }
3707
3708 /* Unlock bgp_node_lookup. */
3709 bgp_unlock_node (rn);
3710}
3711
Lou Bergera76d9ca2016-01-12 13:41:53 -05003712static void
3713bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
3714 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3715{
3716 struct bgp_node *rn;
3717 struct bgp_info *new;
3718 struct attr *attr_new;
3719 struct attr attr = { 0 };
3720 struct bgp_info *ri;
3721
3722 assert (bgp_static);
3723
3724 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
3725
3726 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3727
3728 attr.nexthop = bgp_static->igpnexthop;
3729 attr.med = bgp_static->igpmetric;
3730 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3731
3732 /* Apply route-map. */
3733 if (bgp_static->rmap.name)
3734 {
3735 struct attr attr_tmp = attr;
3736 struct bgp_info info;
3737 int ret;
3738
3739 info.peer = bgp->peer_self;
3740 info.attr = &attr_tmp;
3741
3742 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3743
3744 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3745
3746 bgp->peer_self->rmap_type = 0;
3747
3748 if (ret == RMAP_DENYMATCH)
3749 {
3750 /* Free uninterned attribute. */
3751 bgp_attr_flush (&attr_tmp);
3752
3753 /* Unintern original. */
3754 aspath_unintern (&attr.aspath);
3755 bgp_attr_extra_free (&attr);
3756 bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
3757 bgp_static->tag);
3758 return;
3759 }
3760
3761 attr_new = bgp_attr_intern (&attr_tmp);
3762 }
3763 else
3764 {
3765 attr_new = bgp_attr_intern (&attr);
3766 }
3767
3768 for (ri = rn->info; ri; ri = ri->next)
3769 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3770 && ri->sub_type == BGP_ROUTE_STATIC)
3771 break;
3772
3773 if (ri)
3774 {
3775 if (attrhash_cmp (ri->attr, attr_new) &&
3776 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3777 {
3778 bgp_unlock_node (rn);
3779 bgp_attr_unintern (&attr_new);
3780 aspath_unintern (&attr.aspath);
3781 bgp_attr_extra_free (&attr);
3782 return;
3783 }
3784 else
3785 {
3786 /* The attribute is changed. */
3787 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3788
3789 /* Rewrite BGP route information. */
3790 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3791 bgp_info_restore(rn, ri);
3792 else
3793 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3794 bgp_attr_unintern (&ri->attr);
3795 ri->attr = attr_new;
3796 ri->uptime = bgp_clock ();
3797
3798 /* Process change. */
3799 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3800 bgp_process (bgp, rn, afi, safi);
3801 bgp_unlock_node (rn);
3802 aspath_unintern (&attr.aspath);
3803 bgp_attr_extra_free (&attr);
3804 return;
3805 }
3806 }
3807
3808
3809 /* Make new BGP info. */
3810 new = bgp_info_new ();
3811 new->type = ZEBRA_ROUTE_BGP;
3812 new->sub_type = BGP_ROUTE_STATIC;
3813 new->peer = bgp->peer_self;
3814 new->attr = attr_new;
3815 SET_FLAG (new->flags, BGP_INFO_VALID);
3816 new->uptime = bgp_clock ();
3817 new->extra = bgp_info_extra_new();
3818 memcpy (new->extra->tag, bgp_static->tag, 3);
3819
3820 /* Aggregate address increment. */
3821 bgp_aggregate_increment (bgp, p, new, afi, safi);
3822
3823 /* Register new BGP information. */
3824 bgp_info_add (rn, new);
3825
3826 /* route_node_get lock */
3827 bgp_unlock_node (rn);
3828
3829 /* Process change. */
3830 bgp_process (bgp, rn, afi, safi);
3831
3832 /* Unintern original. */
3833 aspath_unintern (&attr.aspath);
3834 bgp_attr_extra_free (&attr);
3835}
3836
paul718e3742002-12-13 20:15:29 +00003837/* Configure static BGP network. When user don't run zebra, static
3838 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003839static int
paulfd79ac92004-10-13 05:06:08 +00003840bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003841 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003842{
3843 int ret;
3844 struct prefix p;
3845 struct bgp_static *bgp_static;
3846 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003847 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003848
3849 /* Convert IP prefix string to struct prefix. */
3850 ret = str2prefix (ip_str, &p);
3851 if (! ret)
3852 {
3853 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3854 return CMD_WARNING;
3855 }
3856#ifdef HAVE_IPV6
3857 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3858 {
3859 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3860 VTY_NEWLINE);
3861 return CMD_WARNING;
3862 }
3863#endif /* HAVE_IPV6 */
3864
3865 apply_mask (&p);
3866
3867 /* Set BGP static route configuration. */
3868 rn = bgp_node_get (bgp->route[afi][safi], &p);
3869
3870 if (rn->info)
3871 {
3872 /* Configuration change. */
3873 bgp_static = rn->info;
3874
3875 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003876 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3877 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003878
paul718e3742002-12-13 20:15:29 +00003879 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003880
paul718e3742002-12-13 20:15:29 +00003881 if (rmap)
3882 {
3883 if (bgp_static->rmap.name)
3884 free (bgp_static->rmap.name);
3885 bgp_static->rmap.name = strdup (rmap);
3886 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3887 }
3888 else
3889 {
3890 if (bgp_static->rmap.name)
3891 free (bgp_static->rmap.name);
3892 bgp_static->rmap.name = NULL;
3893 bgp_static->rmap.map = NULL;
3894 bgp_static->valid = 0;
3895 }
3896 bgp_unlock_node (rn);
3897 }
3898 else
3899 {
3900 /* New configuration. */
3901 bgp_static = bgp_static_new ();
3902 bgp_static->backdoor = backdoor;
3903 bgp_static->valid = 0;
3904 bgp_static->igpmetric = 0;
3905 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003906
paul718e3742002-12-13 20:15:29 +00003907 if (rmap)
3908 {
3909 if (bgp_static->rmap.name)
3910 free (bgp_static->rmap.name);
3911 bgp_static->rmap.name = strdup (rmap);
3912 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3913 }
3914 rn->info = bgp_static;
3915 }
3916
3917 /* If BGP scan is not enabled, we should install this route here. */
3918 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3919 {
3920 bgp_static->valid = 1;
3921
3922 if (need_update)
3923 bgp_static_withdraw (bgp, &p, afi, safi);
3924
3925 if (! bgp_static->backdoor)
3926 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3927 }
3928
3929 return CMD_SUCCESS;
3930}
3931
3932/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003933static int
paulfd79ac92004-10-13 05:06:08 +00003934bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003935 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003936{
3937 int ret;
3938 struct prefix p;
3939 struct bgp_static *bgp_static;
3940 struct bgp_node *rn;
3941
3942 /* Convert IP prefix string to struct prefix. */
3943 ret = str2prefix (ip_str, &p);
3944 if (! ret)
3945 {
3946 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3947 return CMD_WARNING;
3948 }
3949#ifdef HAVE_IPV6
3950 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3951 {
3952 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3953 VTY_NEWLINE);
3954 return CMD_WARNING;
3955 }
3956#endif /* HAVE_IPV6 */
3957
3958 apply_mask (&p);
3959
3960 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3961 if (! rn)
3962 {
3963 vty_out (vty, "%% Can't find specified static route configuration.%s",
3964 VTY_NEWLINE);
3965 return CMD_WARNING;
3966 }
3967
3968 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003969
paul718e3742002-12-13 20:15:29 +00003970 /* Update BGP RIB. */
3971 if (! bgp_static->backdoor)
3972 bgp_static_withdraw (bgp, &p, afi, safi);
3973
3974 /* Clear configuration. */
3975 bgp_static_free (bgp_static);
3976 rn->info = NULL;
3977 bgp_unlock_node (rn);
3978 bgp_unlock_node (rn);
3979
3980 return CMD_SUCCESS;
3981}
3982
3983/* Called from bgp_delete(). Delete all static routes from the BGP
3984 instance. */
3985void
3986bgp_static_delete (struct bgp *bgp)
3987{
3988 afi_t afi;
3989 safi_t safi;
3990 struct bgp_node *rn;
3991 struct bgp_node *rm;
3992 struct bgp_table *table;
3993 struct bgp_static *bgp_static;
3994
3995 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3996 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3997 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3998 if (rn->info != NULL)
3999 {
4000 if (safi == SAFI_MPLS_VPN)
4001 {
4002 table = rn->info;
4003
4004 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4005 {
4006 bgp_static = rn->info;
Lou Bergera76d9ca2016-01-12 13:41:53 -05004007 bgp_static_withdraw_safi (bgp, &rm->p,
4008 AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00004009 (struct prefix_rd *)&rn->p,
4010 bgp_static->tag);
4011 bgp_static_free (bgp_static);
4012 rn->info = NULL;
4013 bgp_unlock_node (rn);
4014 }
4015 }
4016 else
4017 {
4018 bgp_static = rn->info;
4019 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4020 bgp_static_free (bgp_static);
4021 rn->info = NULL;
4022 bgp_unlock_node (rn);
4023 }
4024 }
4025}
4026
Lou Bergera76d9ca2016-01-12 13:41:53 -05004027/*
4028 * gpz 110624
4029 * Currently this is used to set static routes for VPN and ENCAP.
4030 * I think it can probably be factored with bgp_static_set.
4031 */
paul718e3742002-12-13 20:15:29 +00004032int
Lou Bergera76d9ca2016-01-12 13:41:53 -05004033bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
4034 const char *rd_str, const char *tag_str,
4035 const char *rmap_str)
paul718e3742002-12-13 20:15:29 +00004036{
4037 int ret;
4038 struct prefix p;
4039 struct prefix_rd prd;
4040 struct bgp *bgp;
4041 struct bgp_node *prn;
4042 struct bgp_node *rn;
4043 struct bgp_table *table;
4044 struct bgp_static *bgp_static;
4045 u_char tag[3];
4046
4047 bgp = vty->index;
4048
4049 ret = str2prefix (ip_str, &p);
4050 if (! ret)
4051 {
4052 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4053 return CMD_WARNING;
4054 }
4055 apply_mask (&p);
4056
4057 ret = str2prefix_rd (rd_str, &prd);
4058 if (! ret)
4059 {
4060 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4061 return CMD_WARNING;
4062 }
4063
4064 ret = str2tag (tag_str, tag);
4065 if (! ret)
4066 {
4067 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4068 return CMD_WARNING;
4069 }
4070
Lou Bergera76d9ca2016-01-12 13:41:53 -05004071 prn = bgp_node_get (bgp->route[AFI_IP][safi],
paul718e3742002-12-13 20:15:29 +00004072 (struct prefix *)&prd);
4073 if (prn->info == NULL)
Lou Bergera76d9ca2016-01-12 13:41:53 -05004074 prn->info = bgp_table_init (AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004075 else
4076 bgp_unlock_node (prn);
4077 table = prn->info;
4078
4079 rn = bgp_node_get (table, &p);
4080
4081 if (rn->info)
4082 {
4083 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4084 bgp_unlock_node (rn);
4085 }
4086 else
4087 {
4088 /* New configuration. */
4089 bgp_static = bgp_static_new ();
Lou Bergera76d9ca2016-01-12 13:41:53 -05004090 bgp_static->backdoor = 0;
4091 bgp_static->valid = 0;
4092 bgp_static->igpmetric = 0;
4093 bgp_static->igpnexthop.s_addr = 0;
4094 memcpy(bgp_static->tag, tag, 3);
4095 bgp_static->prd = prd;
4096
4097 if (rmap_str)
4098 {
4099 if (bgp_static->rmap.name)
4100 free (bgp_static->rmap.name);
4101 bgp_static->rmap.name = strdup (rmap_str);
4102 bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
4103 }
paul718e3742002-12-13 20:15:29 +00004104 rn->info = bgp_static;
4105
Lou Bergera76d9ca2016-01-12 13:41:53 -05004106 bgp_static->valid = 1;
4107 bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004108 }
4109
4110 return CMD_SUCCESS;
4111}
4112
4113/* Configure static BGP network. */
4114int
Lou Bergera76d9ca2016-01-12 13:41:53 -05004115bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
4116 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00004117{
4118 int ret;
4119 struct bgp *bgp;
4120 struct prefix p;
4121 struct prefix_rd prd;
4122 struct bgp_node *prn;
4123 struct bgp_node *rn;
4124 struct bgp_table *table;
4125 struct bgp_static *bgp_static;
4126 u_char tag[3];
4127
4128 bgp = vty->index;
4129
4130 /* Convert IP prefix string to struct prefix. */
4131 ret = str2prefix (ip_str, &p);
4132 if (! ret)
4133 {
4134 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4135 return CMD_WARNING;
4136 }
4137 apply_mask (&p);
4138
4139 ret = str2prefix_rd (rd_str, &prd);
4140 if (! ret)
4141 {
4142 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4143 return CMD_WARNING;
4144 }
4145
4146 ret = str2tag (tag_str, tag);
4147 if (! ret)
4148 {
4149 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4150 return CMD_WARNING;
4151 }
4152
Lou Bergera76d9ca2016-01-12 13:41:53 -05004153 prn = bgp_node_get (bgp->route[AFI_IP][safi],
paul718e3742002-12-13 20:15:29 +00004154 (struct prefix *)&prd);
4155 if (prn->info == NULL)
Lou Bergera76d9ca2016-01-12 13:41:53 -05004156 prn->info = bgp_table_init (AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004157 else
4158 bgp_unlock_node (prn);
4159 table = prn->info;
4160
4161 rn = bgp_node_lookup (table, &p);
4162
4163 if (rn)
4164 {
Lou Bergera76d9ca2016-01-12 13:41:53 -05004165 bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
paul718e3742002-12-13 20:15:29 +00004166
4167 bgp_static = rn->info;
4168 bgp_static_free (bgp_static);
4169 rn->info = NULL;
4170 bgp_unlock_node (rn);
4171 bgp_unlock_node (rn);
4172 }
4173 else
4174 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4175
4176 return CMD_SUCCESS;
4177}
David Lamparter6b0655a2014-06-04 06:53:35 +02004178
paul718e3742002-12-13 20:15:29 +00004179DEFUN (bgp_network,
4180 bgp_network_cmd,
4181 "network A.B.C.D/M",
4182 "Specify a network to announce via BGP\n"
4183 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4184{
4185 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004186 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004187}
4188
4189DEFUN (bgp_network_route_map,
4190 bgp_network_route_map_cmd,
4191 "network A.B.C.D/M route-map WORD",
4192 "Specify a network to announce via BGP\n"
4193 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4194 "Route-map to modify the attributes\n"
4195 "Name of the route map\n")
4196{
4197 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004198 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004199}
4200
4201DEFUN (bgp_network_backdoor,
4202 bgp_network_backdoor_cmd,
4203 "network A.B.C.D/M backdoor",
4204 "Specify a network to announce via BGP\n"
4205 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4206 "Specify a BGP backdoor route\n")
4207{
Paul Jakma41367172007-08-06 15:24:51 +00004208 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004209 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004210}
4211
4212DEFUN (bgp_network_mask,
4213 bgp_network_mask_cmd,
4214 "network A.B.C.D mask A.B.C.D",
4215 "Specify a network to announce via BGP\n"
4216 "Network number\n"
4217 "Network mask\n"
4218 "Network mask\n")
4219{
4220 int ret;
4221 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004222
paul718e3742002-12-13 20:15:29 +00004223 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4224 if (! ret)
4225 {
4226 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4227 return CMD_WARNING;
4228 }
4229
4230 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004231 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004232}
4233
4234DEFUN (bgp_network_mask_route_map,
4235 bgp_network_mask_route_map_cmd,
4236 "network A.B.C.D mask A.B.C.D route-map WORD",
4237 "Specify a network to announce via BGP\n"
4238 "Network number\n"
4239 "Network mask\n"
4240 "Network mask\n"
4241 "Route-map to modify the attributes\n"
4242 "Name of the route map\n")
4243{
4244 int ret;
4245 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004246
paul718e3742002-12-13 20:15:29 +00004247 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4248 if (! ret)
4249 {
4250 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4251 return CMD_WARNING;
4252 }
4253
4254 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004255 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004256}
4257
4258DEFUN (bgp_network_mask_backdoor,
4259 bgp_network_mask_backdoor_cmd,
4260 "network A.B.C.D mask A.B.C.D backdoor",
4261 "Specify a network to announce via BGP\n"
4262 "Network number\n"
4263 "Network mask\n"
4264 "Network mask\n"
4265 "Specify a BGP backdoor route\n")
4266{
4267 int ret;
4268 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004269
paul718e3742002-12-13 20:15:29 +00004270 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4271 if (! ret)
4272 {
4273 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4274 return CMD_WARNING;
4275 }
4276
Paul Jakma41367172007-08-06 15:24:51 +00004277 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004278 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004279}
4280
4281DEFUN (bgp_network_mask_natural,
4282 bgp_network_mask_natural_cmd,
4283 "network A.B.C.D",
4284 "Specify a network to announce via BGP\n"
4285 "Network number\n")
4286{
4287 int ret;
4288 char prefix_str[BUFSIZ];
4289
4290 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4291 if (! ret)
4292 {
4293 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4294 return CMD_WARNING;
4295 }
4296
4297 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004298 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004299}
4300
4301DEFUN (bgp_network_mask_natural_route_map,
4302 bgp_network_mask_natural_route_map_cmd,
4303 "network A.B.C.D route-map WORD",
4304 "Specify a network to announce via BGP\n"
4305 "Network number\n"
4306 "Route-map to modify the attributes\n"
4307 "Name of the route map\n")
4308{
4309 int ret;
4310 char prefix_str[BUFSIZ];
4311
4312 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4313 if (! ret)
4314 {
4315 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4316 return CMD_WARNING;
4317 }
4318
4319 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004320 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004321}
4322
4323DEFUN (bgp_network_mask_natural_backdoor,
4324 bgp_network_mask_natural_backdoor_cmd,
4325 "network A.B.C.D backdoor",
4326 "Specify a network to announce via BGP\n"
4327 "Network number\n"
4328 "Specify a BGP backdoor route\n")
4329{
4330 int ret;
4331 char prefix_str[BUFSIZ];
4332
4333 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4334 if (! ret)
4335 {
4336 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4337 return CMD_WARNING;
4338 }
4339
Paul Jakma41367172007-08-06 15:24:51 +00004340 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004341 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004342}
4343
4344DEFUN (no_bgp_network,
4345 no_bgp_network_cmd,
4346 "no network A.B.C.D/M",
4347 NO_STR
4348 "Specify a network to announce via BGP\n"
4349 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4350{
4351 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4352 bgp_node_safi (vty));
4353}
4354
4355ALIAS (no_bgp_network,
4356 no_bgp_network_route_map_cmd,
4357 "no network A.B.C.D/M route-map WORD",
4358 NO_STR
4359 "Specify a network to announce via BGP\n"
4360 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4361 "Route-map to modify the attributes\n"
4362 "Name of the route map\n")
4363
4364ALIAS (no_bgp_network,
4365 no_bgp_network_backdoor_cmd,
4366 "no network A.B.C.D/M backdoor",
4367 NO_STR
4368 "Specify a network to announce via BGP\n"
4369 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4370 "Specify a BGP backdoor route\n")
4371
4372DEFUN (no_bgp_network_mask,
4373 no_bgp_network_mask_cmd,
4374 "no network A.B.C.D mask A.B.C.D",
4375 NO_STR
4376 "Specify a network to announce via BGP\n"
4377 "Network number\n"
4378 "Network mask\n"
4379 "Network mask\n")
4380{
4381 int ret;
4382 char prefix_str[BUFSIZ];
4383
4384 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4385 if (! ret)
4386 {
4387 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4388 return CMD_WARNING;
4389 }
4390
4391 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4392 bgp_node_safi (vty));
4393}
4394
4395ALIAS (no_bgp_network_mask,
4396 no_bgp_network_mask_route_map_cmd,
4397 "no network A.B.C.D mask A.B.C.D route-map WORD",
4398 NO_STR
4399 "Specify a network to announce via BGP\n"
4400 "Network number\n"
4401 "Network mask\n"
4402 "Network mask\n"
4403 "Route-map to modify the attributes\n"
4404 "Name of the route map\n")
4405
4406ALIAS (no_bgp_network_mask,
4407 no_bgp_network_mask_backdoor_cmd,
4408 "no network A.B.C.D mask A.B.C.D backdoor",
4409 NO_STR
4410 "Specify a network to announce via BGP\n"
4411 "Network number\n"
4412 "Network mask\n"
4413 "Network mask\n"
4414 "Specify a BGP backdoor route\n")
4415
4416DEFUN (no_bgp_network_mask_natural,
4417 no_bgp_network_mask_natural_cmd,
4418 "no network A.B.C.D",
4419 NO_STR
4420 "Specify a network to announce via BGP\n"
4421 "Network number\n")
4422{
4423 int ret;
4424 char prefix_str[BUFSIZ];
4425
4426 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4427 if (! ret)
4428 {
4429 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4430 return CMD_WARNING;
4431 }
4432
4433 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4434 bgp_node_safi (vty));
4435}
4436
4437ALIAS (no_bgp_network_mask_natural,
4438 no_bgp_network_mask_natural_route_map_cmd,
4439 "no network A.B.C.D route-map WORD",
4440 NO_STR
4441 "Specify a network to announce via BGP\n"
4442 "Network number\n"
4443 "Route-map to modify the attributes\n"
4444 "Name of the route map\n")
4445
4446ALIAS (no_bgp_network_mask_natural,
4447 no_bgp_network_mask_natural_backdoor_cmd,
4448 "no network A.B.C.D backdoor",
4449 NO_STR
4450 "Specify a network to announce via BGP\n"
4451 "Network number\n"
4452 "Specify a BGP backdoor route\n")
4453
4454#ifdef HAVE_IPV6
4455DEFUN (ipv6_bgp_network,
4456 ipv6_bgp_network_cmd,
4457 "network X:X::X:X/M",
4458 "Specify a network to announce via BGP\n"
4459 "IPv6 prefix <network>/<length>\n")
4460{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304461 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004462 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004463}
4464
4465DEFUN (ipv6_bgp_network_route_map,
4466 ipv6_bgp_network_route_map_cmd,
4467 "network X:X::X:X/M route-map WORD",
4468 "Specify a network to announce via BGP\n"
4469 "IPv6 prefix <network>/<length>\n"
4470 "Route-map to modify the attributes\n"
4471 "Name of the route map\n")
4472{
4473 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004474 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004475}
4476
4477DEFUN (no_ipv6_bgp_network,
4478 no_ipv6_bgp_network_cmd,
4479 "no network X:X::X:X/M",
4480 NO_STR
4481 "Specify a network to announce via BGP\n"
4482 "IPv6 prefix <network>/<length>\n")
4483{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304484 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004485}
4486
4487ALIAS (no_ipv6_bgp_network,
4488 no_ipv6_bgp_network_route_map_cmd,
4489 "no network X:X::X:X/M route-map WORD",
4490 NO_STR
4491 "Specify a network to announce via BGP\n"
4492 "IPv6 prefix <network>/<length>\n"
4493 "Route-map to modify the attributes\n"
4494 "Name of the route map\n")
4495
4496ALIAS (ipv6_bgp_network,
4497 old_ipv6_bgp_network_cmd,
4498 "ipv6 bgp network X:X::X:X/M",
4499 IPV6_STR
4500 BGP_STR
4501 "Specify a network to announce via BGP\n"
4502 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4503
4504ALIAS (no_ipv6_bgp_network,
4505 old_no_ipv6_bgp_network_cmd,
4506 "no ipv6 bgp network X:X::X:X/M",
4507 NO_STR
4508 IPV6_STR
4509 BGP_STR
4510 "Specify a network to announce via BGP\n"
4511 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4512#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004513
4514/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4515ALIAS_DEPRECATED (bgp_network,
4516 bgp_network_ttl_cmd,
4517 "network A.B.C.D/M pathlimit <0-255>",
4518 "Specify a network to announce via BGP\n"
4519 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4520 "AS-Path hopcount limit attribute\n"
4521 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4522ALIAS_DEPRECATED (bgp_network_backdoor,
4523 bgp_network_backdoor_ttl_cmd,
4524 "network A.B.C.D/M backdoor pathlimit <0-255>",
4525 "Specify a network to announce via BGP\n"
4526 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4527 "Specify a BGP backdoor route\n"
4528 "AS-Path hopcount limit attribute\n"
4529 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4530ALIAS_DEPRECATED (bgp_network_mask,
4531 bgp_network_mask_ttl_cmd,
4532 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4533 "Specify a network to announce via BGP\n"
4534 "Network number\n"
4535 "Network mask\n"
4536 "Network mask\n"
4537 "AS-Path hopcount limit attribute\n"
4538 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4539ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4540 bgp_network_mask_backdoor_ttl_cmd,
4541 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4542 "Specify a network to announce via BGP\n"
4543 "Network number\n"
4544 "Network mask\n"
4545 "Network mask\n"
4546 "Specify a BGP backdoor route\n"
4547 "AS-Path hopcount limit attribute\n"
4548 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4549ALIAS_DEPRECATED (bgp_network_mask_natural,
4550 bgp_network_mask_natural_ttl_cmd,
4551 "network A.B.C.D pathlimit <0-255>",
4552 "Specify a network to announce via BGP\n"
4553 "Network number\n"
4554 "AS-Path hopcount limit attribute\n"
4555 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4556ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4557 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004558 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004559 "Specify a network to announce via BGP\n"
4560 "Network number\n"
4561 "Specify a BGP backdoor route\n"
4562 "AS-Path hopcount limit attribute\n"
4563 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4564ALIAS_DEPRECATED (no_bgp_network,
4565 no_bgp_network_ttl_cmd,
4566 "no network A.B.C.D/M pathlimit <0-255>",
4567 NO_STR
4568 "Specify a network to announce via BGP\n"
4569 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4570 "AS-Path hopcount limit attribute\n"
4571 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4572ALIAS_DEPRECATED (no_bgp_network,
4573 no_bgp_network_backdoor_ttl_cmd,
4574 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4575 NO_STR
4576 "Specify a network to announce via BGP\n"
4577 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4578 "Specify a BGP backdoor route\n"
4579 "AS-Path hopcount limit attribute\n"
4580 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4581ALIAS_DEPRECATED (no_bgp_network,
4582 no_bgp_network_mask_ttl_cmd,
4583 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4584 NO_STR
4585 "Specify a network to announce via BGP\n"
4586 "Network number\n"
4587 "Network mask\n"
4588 "Network mask\n"
4589 "AS-Path hopcount limit attribute\n"
4590 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4591ALIAS_DEPRECATED (no_bgp_network_mask,
4592 no_bgp_network_mask_backdoor_ttl_cmd,
4593 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4594 NO_STR
4595 "Specify a network to announce via BGP\n"
4596 "Network number\n"
4597 "Network mask\n"
4598 "Network mask\n"
4599 "Specify a BGP backdoor route\n"
4600 "AS-Path hopcount limit attribute\n"
4601 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4602ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4603 no_bgp_network_mask_natural_ttl_cmd,
4604 "no network A.B.C.D pathlimit <0-255>",
4605 NO_STR
4606 "Specify a network to announce via BGP\n"
4607 "Network number\n"
4608 "AS-Path hopcount limit attribute\n"
4609 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4610ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4611 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4612 "no network A.B.C.D backdoor pathlimit <0-255>",
4613 NO_STR
4614 "Specify a network to announce via BGP\n"
4615 "Network number\n"
4616 "Specify a BGP backdoor route\n"
4617 "AS-Path hopcount limit attribute\n"
4618 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004619#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004620ALIAS_DEPRECATED (ipv6_bgp_network,
4621 ipv6_bgp_network_ttl_cmd,
4622 "network X:X::X:X/M pathlimit <0-255>",
4623 "Specify a network to announce via BGP\n"
4624 "IPv6 prefix <network>/<length>\n"
4625 "AS-Path hopcount limit attribute\n"
4626 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4627ALIAS_DEPRECATED (no_ipv6_bgp_network,
4628 no_ipv6_bgp_network_ttl_cmd,
4629 "no network X:X::X:X/M pathlimit <0-255>",
4630 NO_STR
4631 "Specify a network to announce via BGP\n"
4632 "IPv6 prefix <network>/<length>\n"
4633 "AS-Path hopcount limit attribute\n"
4634 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004635#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02004636
paul718e3742002-12-13 20:15:29 +00004637/* Aggreagete address:
4638
4639 advertise-map Set condition to advertise attribute
4640 as-set Generate AS set path information
4641 attribute-map Set attributes of aggregate
4642 route-map Set parameters of aggregate
4643 summary-only Filter more specific routes from updates
4644 suppress-map Conditionally filter more specific routes from updates
4645 <cr>
4646 */
4647struct bgp_aggregate
4648{
4649 /* Summary-only flag. */
4650 u_char summary_only;
4651
4652 /* AS set generation. */
4653 u_char as_set;
4654
4655 /* Route-map for aggregated route. */
4656 struct route_map *map;
4657
4658 /* Suppress-count. */
4659 unsigned long count;
4660
4661 /* SAFI configuration. */
4662 safi_t safi;
4663};
4664
paul94f2b392005-06-28 12:44:16 +00004665static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004666bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004667{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004668 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004669}
4670
paul94f2b392005-06-28 12:44:16 +00004671static void
paul718e3742002-12-13 20:15:29 +00004672bgp_aggregate_free (struct bgp_aggregate *aggregate)
4673{
4674 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4675}
4676
paul94f2b392005-06-28 12:44:16 +00004677static void
paul718e3742002-12-13 20:15:29 +00004678bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4679 afi_t afi, safi_t safi, struct bgp_info *del,
4680 struct bgp_aggregate *aggregate)
4681{
4682 struct bgp_table *table;
4683 struct bgp_node *top;
4684 struct bgp_node *rn;
4685 u_char origin;
4686 struct aspath *aspath = NULL;
4687 struct aspath *asmerge = NULL;
4688 struct community *community = NULL;
4689 struct community *commerge = NULL;
paul718e3742002-12-13 20:15:29 +00004690 struct bgp_info *ri;
4691 struct bgp_info *new;
4692 int first = 1;
4693 unsigned long match = 0;
4694
paul718e3742002-12-13 20:15:29 +00004695 /* ORIGIN attribute: If at least one route among routes that are
4696 aggregated has ORIGIN with the value INCOMPLETE, then the
4697 aggregated route must have the ORIGIN attribute with the value
4698 INCOMPLETE. Otherwise, if at least one route among routes that
4699 are aggregated has ORIGIN with the value EGP, then the aggregated
4700 route must have the origin attribute with the value EGP. In all
4701 other case the value of the ORIGIN attribute of the aggregated
4702 route is INTERNAL. */
4703 origin = BGP_ORIGIN_IGP;
4704
4705 table = bgp->rib[afi][safi];
4706
4707 top = bgp_node_get (table, p);
4708 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4709 if (rn->p.prefixlen > p->prefixlen)
4710 {
4711 match = 0;
4712
4713 for (ri = rn->info; ri; ri = ri->next)
4714 {
4715 if (BGP_INFO_HOLDDOWN (ri))
4716 continue;
4717
4718 if (del && ri == del)
4719 continue;
4720
4721 if (! rinew && first)
Paul Jakma7aa9dce2014-09-19 14:42:23 +01004722 first = 0;
paul718e3742002-12-13 20:15:29 +00004723
4724#ifdef AGGREGATE_NEXTHOP_CHECK
4725 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4726 || ri->attr->med != med)
4727 {
4728 if (aspath)
4729 aspath_free (aspath);
4730 if (community)
4731 community_free (community);
4732 bgp_unlock_node (rn);
4733 bgp_unlock_node (top);
4734 return;
4735 }
4736#endif /* AGGREGATE_NEXTHOP_CHECK */
4737
4738 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4739 {
4740 if (aggregate->summary_only)
4741 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004742 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004743 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004744 match++;
4745 }
4746
4747 aggregate->count++;
4748
4749 if (aggregate->as_set)
4750 {
4751 if (origin < ri->attr->origin)
4752 origin = ri->attr->origin;
4753
4754 if (aspath)
4755 {
4756 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4757 aspath_free (aspath);
4758 aspath = asmerge;
4759 }
4760 else
4761 aspath = aspath_dup (ri->attr->aspath);
4762
4763 if (ri->attr->community)
4764 {
4765 if (community)
4766 {
4767 commerge = community_merge (community,
4768 ri->attr->community);
4769 community = community_uniq_sort (commerge);
4770 community_free (commerge);
4771 }
4772 else
4773 community = community_dup (ri->attr->community);
4774 }
4775 }
4776 }
4777 }
4778 if (match)
4779 bgp_process (bgp, rn, afi, safi);
4780 }
4781 bgp_unlock_node (top);
4782
4783 if (rinew)
4784 {
4785 aggregate->count++;
4786
4787 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004788 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004789
4790 if (aggregate->as_set)
4791 {
4792 if (origin < rinew->attr->origin)
4793 origin = rinew->attr->origin;
4794
4795 if (aspath)
4796 {
4797 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4798 aspath_free (aspath);
4799 aspath = asmerge;
4800 }
4801 else
4802 aspath = aspath_dup (rinew->attr->aspath);
4803
4804 if (rinew->attr->community)
4805 {
4806 if (community)
4807 {
4808 commerge = community_merge (community,
4809 rinew->attr->community);
4810 community = community_uniq_sort (commerge);
4811 community_free (commerge);
4812 }
4813 else
4814 community = community_dup (rinew->attr->community);
4815 }
4816 }
4817 }
4818
4819 if (aggregate->count > 0)
4820 {
4821 rn = bgp_node_get (table, p);
4822 new = bgp_info_new ();
4823 new->type = ZEBRA_ROUTE_BGP;
4824 new->sub_type = BGP_ROUTE_AGGREGATE;
4825 new->peer = bgp->peer_self;
4826 SET_FLAG (new->flags, BGP_INFO_VALID);
4827 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004828 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004829
4830 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004831 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004832 bgp_process (bgp, rn, afi, safi);
4833 }
4834 else
4835 {
4836 if (aspath)
4837 aspath_free (aspath);
4838 if (community)
4839 community_free (community);
4840 }
4841}
4842
4843void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4844 struct bgp_aggregate *);
4845
4846void
4847bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4848 struct bgp_info *ri, afi_t afi, safi_t safi)
4849{
4850 struct bgp_node *child;
4851 struct bgp_node *rn;
4852 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004853 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004854
4855 /* MPLS-VPN aggregation is not yet supported. */
4856 if (safi == SAFI_MPLS_VPN)
4857 return;
4858
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004859 table = bgp->aggregate[afi][safi];
4860
4861 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004862 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004863 return;
4864
paul718e3742002-12-13 20:15:29 +00004865 if (p->prefixlen == 0)
4866 return;
4867
4868 if (BGP_INFO_HOLDDOWN (ri))
4869 return;
4870
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004871 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004872
4873 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004874 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004875 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4876 {
4877 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004878 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004879 }
4880 bgp_unlock_node (child);
4881}
4882
4883void
4884bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4885 struct bgp_info *del, afi_t afi, safi_t safi)
4886{
4887 struct bgp_node *child;
4888 struct bgp_node *rn;
4889 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004890 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004891
4892 /* MPLS-VPN aggregation is not yet supported. */
4893 if (safi == SAFI_MPLS_VPN)
4894 return;
4895
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004896 table = bgp->aggregate[afi][safi];
4897
4898 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004899 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004900 return;
4901
paul718e3742002-12-13 20:15:29 +00004902 if (p->prefixlen == 0)
4903 return;
4904
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004905 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004906
4907 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004908 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004909 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4910 {
4911 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004912 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004913 }
4914 bgp_unlock_node (child);
4915}
4916
paul94f2b392005-06-28 12:44:16 +00004917static void
paul718e3742002-12-13 20:15:29 +00004918bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4919 struct bgp_aggregate *aggregate)
4920{
4921 struct bgp_table *table;
4922 struct bgp_node *top;
4923 struct bgp_node *rn;
4924 struct bgp_info *new;
4925 struct bgp_info *ri;
4926 unsigned long match;
4927 u_char origin = BGP_ORIGIN_IGP;
4928 struct aspath *aspath = NULL;
4929 struct aspath *asmerge = NULL;
4930 struct community *community = NULL;
4931 struct community *commerge = NULL;
4932
4933 table = bgp->rib[afi][safi];
4934
4935 /* Sanity check. */
4936 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4937 return;
4938 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4939 return;
4940
4941 /* If routes exists below this node, generate aggregate routes. */
4942 top = bgp_node_get (table, p);
4943 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4944 if (rn->p.prefixlen > p->prefixlen)
4945 {
4946 match = 0;
4947
4948 for (ri = rn->info; ri; ri = ri->next)
4949 {
4950 if (BGP_INFO_HOLDDOWN (ri))
4951 continue;
4952
4953 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4954 {
4955 /* summary-only aggregate route suppress aggregated
4956 route announcement. */
4957 if (aggregate->summary_only)
4958 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004959 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004960 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004961 match++;
4962 }
4963 /* as-set aggregate route generate origin, as path,
4964 community aggregation. */
4965 if (aggregate->as_set)
4966 {
4967 if (origin < ri->attr->origin)
4968 origin = ri->attr->origin;
4969
4970 if (aspath)
4971 {
4972 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4973 aspath_free (aspath);
4974 aspath = asmerge;
4975 }
4976 else
4977 aspath = aspath_dup (ri->attr->aspath);
4978
4979 if (ri->attr->community)
4980 {
4981 if (community)
4982 {
4983 commerge = community_merge (community,
4984 ri->attr->community);
4985 community = community_uniq_sort (commerge);
4986 community_free (commerge);
4987 }
4988 else
4989 community = community_dup (ri->attr->community);
4990 }
4991 }
4992 aggregate->count++;
4993 }
4994 }
4995
4996 /* If this node is suppressed, process the change. */
4997 if (match)
4998 bgp_process (bgp, rn, afi, safi);
4999 }
5000 bgp_unlock_node (top);
5001
5002 /* Add aggregate route to BGP table. */
5003 if (aggregate->count)
5004 {
5005 rn = bgp_node_get (table, p);
5006
5007 new = bgp_info_new ();
5008 new->type = ZEBRA_ROUTE_BGP;
5009 new->sub_type = BGP_ROUTE_AGGREGATE;
5010 new->peer = bgp->peer_self;
5011 SET_FLAG (new->flags, BGP_INFO_VALID);
5012 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03005013 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005014
5015 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00005016 bgp_unlock_node (rn);
5017
paul718e3742002-12-13 20:15:29 +00005018 /* Process change. */
5019 bgp_process (bgp, rn, afi, safi);
5020 }
Denil Virae2a92582015-08-11 13:34:59 -07005021 else
5022 {
5023 if (aspath)
5024 aspath_free (aspath);
5025 if (community)
5026 community_free (community);
5027 }
paul718e3742002-12-13 20:15:29 +00005028}
5029
5030void
5031bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5032 safi_t safi, struct bgp_aggregate *aggregate)
5033{
5034 struct bgp_table *table;
5035 struct bgp_node *top;
5036 struct bgp_node *rn;
5037 struct bgp_info *ri;
5038 unsigned long match;
5039
5040 table = bgp->rib[afi][safi];
5041
5042 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5043 return;
5044 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5045 return;
5046
5047 /* If routes exists below this node, generate aggregate routes. */
5048 top = bgp_node_get (table, p);
5049 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5050 if (rn->p.prefixlen > p->prefixlen)
5051 {
5052 match = 0;
5053
5054 for (ri = rn->info; ri; ri = ri->next)
5055 {
5056 if (BGP_INFO_HOLDDOWN (ri))
5057 continue;
5058
5059 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5060 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005061 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00005062 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005063 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00005064
Paul Jakmafb982c22007-05-04 20:15:47 +00005065 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00005066 {
Paul Jakma1a392d42006-09-07 00:24:49 +00005067 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005068 match++;
5069 }
5070 }
5071 aggregate->count--;
5072 }
5073 }
5074
Paul Jakmafb982c22007-05-04 20:15:47 +00005075 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00005076 if (match)
5077 bgp_process (bgp, rn, afi, safi);
5078 }
5079 bgp_unlock_node (top);
5080
5081 /* Delete aggregate route from BGP table. */
5082 rn = bgp_node_get (table, p);
5083
5084 for (ri = rn->info; ri; ri = ri->next)
5085 if (ri->peer == bgp->peer_self
5086 && ri->type == ZEBRA_ROUTE_BGP
5087 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5088 break;
5089
5090 /* Withdraw static BGP route from routing table. */
5091 if (ri)
5092 {
paul718e3742002-12-13 20:15:29 +00005093 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005094 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00005095 }
5096
5097 /* Unlock bgp_node_lookup. */
5098 bgp_unlock_node (rn);
5099}
5100
5101/* Aggregate route attribute. */
5102#define AGGREGATE_SUMMARY_ONLY 1
5103#define AGGREGATE_AS_SET 1
5104
paul94f2b392005-06-28 12:44:16 +00005105static int
Robert Baysf6269b42010-08-05 10:26:28 -07005106bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5107 afi_t afi, safi_t safi)
5108{
5109 int ret;
5110 struct prefix p;
5111 struct bgp_node *rn;
5112 struct bgp *bgp;
5113 struct bgp_aggregate *aggregate;
5114
5115 /* Convert string to prefix structure. */
5116 ret = str2prefix (prefix_str, &p);
5117 if (!ret)
5118 {
5119 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5120 return CMD_WARNING;
5121 }
5122 apply_mask (&p);
5123
5124 /* Get BGP structure. */
5125 bgp = vty->index;
5126
5127 /* Old configuration check. */
5128 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5129 if (! rn)
5130 {
5131 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5132 VTY_NEWLINE);
5133 return CMD_WARNING;
5134 }
5135
5136 aggregate = rn->info;
5137 if (aggregate->safi & SAFI_UNICAST)
5138 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5139 if (aggregate->safi & SAFI_MULTICAST)
5140 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5141
5142 /* Unlock aggregate address configuration. */
5143 rn->info = NULL;
5144 bgp_aggregate_free (aggregate);
5145 bgp_unlock_node (rn);
5146 bgp_unlock_node (rn);
5147
5148 return CMD_SUCCESS;
5149}
5150
5151static int
5152bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00005153 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00005154 u_char summary_only, u_char as_set)
5155{
5156 int ret;
5157 struct prefix p;
5158 struct bgp_node *rn;
5159 struct bgp *bgp;
5160 struct bgp_aggregate *aggregate;
5161
5162 /* Convert string to prefix structure. */
5163 ret = str2prefix (prefix_str, &p);
5164 if (!ret)
5165 {
5166 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5167 return CMD_WARNING;
5168 }
5169 apply_mask (&p);
5170
5171 /* Get BGP structure. */
5172 bgp = vty->index;
5173
5174 /* Old configuration check. */
5175 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5176
5177 if (rn->info)
5178 {
5179 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005180 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005181 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5182 if (ret)
5183 {
Robert Bays368473f2010-08-05 10:26:29 -07005184 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5185 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005186 return CMD_WARNING;
5187 }
paul718e3742002-12-13 20:15:29 +00005188 }
5189
5190 /* Make aggregate address structure. */
5191 aggregate = bgp_aggregate_new ();
5192 aggregate->summary_only = summary_only;
5193 aggregate->as_set = as_set;
5194 aggregate->safi = safi;
5195 rn->info = aggregate;
5196
5197 /* Aggregate address insert into BGP routing table. */
5198 if (safi & SAFI_UNICAST)
5199 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5200 if (safi & SAFI_MULTICAST)
5201 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5202
5203 return CMD_SUCCESS;
5204}
5205
paul718e3742002-12-13 20:15:29 +00005206DEFUN (aggregate_address,
5207 aggregate_address_cmd,
5208 "aggregate-address A.B.C.D/M",
5209 "Configure BGP aggregate entries\n"
5210 "Aggregate prefix\n")
5211{
5212 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5213}
5214
5215DEFUN (aggregate_address_mask,
5216 aggregate_address_mask_cmd,
5217 "aggregate-address A.B.C.D A.B.C.D",
5218 "Configure BGP aggregate entries\n"
5219 "Aggregate address\n"
5220 "Aggregate mask\n")
5221{
5222 int ret;
5223 char prefix_str[BUFSIZ];
5224
5225 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5226
5227 if (! ret)
5228 {
5229 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5230 return CMD_WARNING;
5231 }
5232
5233 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5234 0, 0);
5235}
5236
5237DEFUN (aggregate_address_summary_only,
5238 aggregate_address_summary_only_cmd,
5239 "aggregate-address A.B.C.D/M summary-only",
5240 "Configure BGP aggregate entries\n"
5241 "Aggregate prefix\n"
5242 "Filter more specific routes from updates\n")
5243{
5244 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5245 AGGREGATE_SUMMARY_ONLY, 0);
5246}
5247
5248DEFUN (aggregate_address_mask_summary_only,
5249 aggregate_address_mask_summary_only_cmd,
5250 "aggregate-address A.B.C.D A.B.C.D summary-only",
5251 "Configure BGP aggregate entries\n"
5252 "Aggregate address\n"
5253 "Aggregate mask\n"
5254 "Filter more specific routes from updates\n")
5255{
5256 int ret;
5257 char prefix_str[BUFSIZ];
5258
5259 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5260
5261 if (! ret)
5262 {
5263 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5264 return CMD_WARNING;
5265 }
5266
5267 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5268 AGGREGATE_SUMMARY_ONLY, 0);
5269}
5270
5271DEFUN (aggregate_address_as_set,
5272 aggregate_address_as_set_cmd,
5273 "aggregate-address A.B.C.D/M as-set",
5274 "Configure BGP aggregate entries\n"
5275 "Aggregate prefix\n"
5276 "Generate AS set path information\n")
5277{
5278 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5279 0, AGGREGATE_AS_SET);
5280}
5281
5282DEFUN (aggregate_address_mask_as_set,
5283 aggregate_address_mask_as_set_cmd,
5284 "aggregate-address A.B.C.D A.B.C.D as-set",
5285 "Configure BGP aggregate entries\n"
5286 "Aggregate address\n"
5287 "Aggregate mask\n"
5288 "Generate AS set path information\n")
5289{
5290 int ret;
5291 char prefix_str[BUFSIZ];
5292
5293 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5294
5295 if (! ret)
5296 {
5297 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5298 return CMD_WARNING;
5299 }
5300
5301 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5302 0, AGGREGATE_AS_SET);
5303}
5304
5305
5306DEFUN (aggregate_address_as_set_summary,
5307 aggregate_address_as_set_summary_cmd,
5308 "aggregate-address A.B.C.D/M as-set summary-only",
5309 "Configure BGP aggregate entries\n"
5310 "Aggregate prefix\n"
5311 "Generate AS set path information\n"
5312 "Filter more specific routes from updates\n")
5313{
5314 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5315 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5316}
5317
5318ALIAS (aggregate_address_as_set_summary,
5319 aggregate_address_summary_as_set_cmd,
5320 "aggregate-address A.B.C.D/M summary-only as-set",
5321 "Configure BGP aggregate entries\n"
5322 "Aggregate prefix\n"
5323 "Filter more specific routes from updates\n"
5324 "Generate AS set path information\n")
5325
5326DEFUN (aggregate_address_mask_as_set_summary,
5327 aggregate_address_mask_as_set_summary_cmd,
5328 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5329 "Configure BGP aggregate entries\n"
5330 "Aggregate address\n"
5331 "Aggregate mask\n"
5332 "Generate AS set path information\n"
5333 "Filter more specific routes from updates\n")
5334{
5335 int ret;
5336 char prefix_str[BUFSIZ];
5337
5338 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5339
5340 if (! ret)
5341 {
5342 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5343 return CMD_WARNING;
5344 }
5345
5346 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5347 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5348}
5349
5350ALIAS (aggregate_address_mask_as_set_summary,
5351 aggregate_address_mask_summary_as_set_cmd,
5352 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5353 "Configure BGP aggregate entries\n"
5354 "Aggregate address\n"
5355 "Aggregate mask\n"
5356 "Filter more specific routes from updates\n"
5357 "Generate AS set path information\n")
5358
5359DEFUN (no_aggregate_address,
5360 no_aggregate_address_cmd,
5361 "no aggregate-address A.B.C.D/M",
5362 NO_STR
5363 "Configure BGP aggregate entries\n"
5364 "Aggregate prefix\n")
5365{
5366 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5367}
5368
5369ALIAS (no_aggregate_address,
5370 no_aggregate_address_summary_only_cmd,
5371 "no aggregate-address A.B.C.D/M summary-only",
5372 NO_STR
5373 "Configure BGP aggregate entries\n"
5374 "Aggregate prefix\n"
5375 "Filter more specific routes from updates\n")
5376
5377ALIAS (no_aggregate_address,
5378 no_aggregate_address_as_set_cmd,
5379 "no aggregate-address A.B.C.D/M as-set",
5380 NO_STR
5381 "Configure BGP aggregate entries\n"
5382 "Aggregate prefix\n"
5383 "Generate AS set path information\n")
5384
5385ALIAS (no_aggregate_address,
5386 no_aggregate_address_as_set_summary_cmd,
5387 "no aggregate-address A.B.C.D/M as-set summary-only",
5388 NO_STR
5389 "Configure BGP aggregate entries\n"
5390 "Aggregate prefix\n"
5391 "Generate AS set path information\n"
5392 "Filter more specific routes from updates\n")
5393
5394ALIAS (no_aggregate_address,
5395 no_aggregate_address_summary_as_set_cmd,
5396 "no aggregate-address A.B.C.D/M summary-only as-set",
5397 NO_STR
5398 "Configure BGP aggregate entries\n"
5399 "Aggregate prefix\n"
5400 "Filter more specific routes from updates\n"
5401 "Generate AS set path information\n")
5402
5403DEFUN (no_aggregate_address_mask,
5404 no_aggregate_address_mask_cmd,
5405 "no aggregate-address A.B.C.D A.B.C.D",
5406 NO_STR
5407 "Configure BGP aggregate entries\n"
5408 "Aggregate address\n"
5409 "Aggregate mask\n")
5410{
5411 int ret;
5412 char prefix_str[BUFSIZ];
5413
5414 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5415
5416 if (! ret)
5417 {
5418 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5419 return CMD_WARNING;
5420 }
5421
5422 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5423}
5424
5425ALIAS (no_aggregate_address_mask,
5426 no_aggregate_address_mask_summary_only_cmd,
5427 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5428 NO_STR
5429 "Configure BGP aggregate entries\n"
5430 "Aggregate address\n"
5431 "Aggregate mask\n"
5432 "Filter more specific routes from updates\n")
5433
5434ALIAS (no_aggregate_address_mask,
5435 no_aggregate_address_mask_as_set_cmd,
5436 "no aggregate-address A.B.C.D A.B.C.D as-set",
5437 NO_STR
5438 "Configure BGP aggregate entries\n"
5439 "Aggregate address\n"
5440 "Aggregate mask\n"
5441 "Generate AS set path information\n")
5442
5443ALIAS (no_aggregate_address_mask,
5444 no_aggregate_address_mask_as_set_summary_cmd,
5445 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5446 NO_STR
5447 "Configure BGP aggregate entries\n"
5448 "Aggregate address\n"
5449 "Aggregate mask\n"
5450 "Generate AS set path information\n"
5451 "Filter more specific routes from updates\n")
5452
5453ALIAS (no_aggregate_address_mask,
5454 no_aggregate_address_mask_summary_as_set_cmd,
5455 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5456 NO_STR
5457 "Configure BGP aggregate entries\n"
5458 "Aggregate address\n"
5459 "Aggregate mask\n"
5460 "Filter more specific routes from updates\n"
5461 "Generate AS set path information\n")
5462
5463#ifdef HAVE_IPV6
5464DEFUN (ipv6_aggregate_address,
5465 ipv6_aggregate_address_cmd,
5466 "aggregate-address X:X::X:X/M",
5467 "Configure BGP aggregate entries\n"
5468 "Aggregate prefix\n")
5469{
5470 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5471}
5472
5473DEFUN (ipv6_aggregate_address_summary_only,
5474 ipv6_aggregate_address_summary_only_cmd,
5475 "aggregate-address X:X::X:X/M summary-only",
5476 "Configure BGP aggregate entries\n"
5477 "Aggregate prefix\n"
5478 "Filter more specific routes from updates\n")
5479{
5480 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5481 AGGREGATE_SUMMARY_ONLY, 0);
5482}
5483
5484DEFUN (no_ipv6_aggregate_address,
5485 no_ipv6_aggregate_address_cmd,
5486 "no aggregate-address X:X::X:X/M",
5487 NO_STR
5488 "Configure BGP aggregate entries\n"
5489 "Aggregate prefix\n")
5490{
5491 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5492}
5493
5494DEFUN (no_ipv6_aggregate_address_summary_only,
5495 no_ipv6_aggregate_address_summary_only_cmd,
5496 "no aggregate-address X:X::X:X/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{
5502 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5503}
5504
5505ALIAS (ipv6_aggregate_address,
5506 old_ipv6_aggregate_address_cmd,
5507 "ipv6 bgp aggregate-address X:X::X:X/M",
5508 IPV6_STR
5509 BGP_STR
5510 "Configure BGP aggregate entries\n"
5511 "Aggregate prefix\n")
5512
5513ALIAS (ipv6_aggregate_address_summary_only,
5514 old_ipv6_aggregate_address_summary_only_cmd,
5515 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5516 IPV6_STR
5517 BGP_STR
5518 "Configure BGP aggregate entries\n"
5519 "Aggregate prefix\n"
5520 "Filter more specific routes from updates\n")
5521
5522ALIAS (no_ipv6_aggregate_address,
5523 old_no_ipv6_aggregate_address_cmd,
5524 "no ipv6 bgp aggregate-address X:X::X:X/M",
5525 NO_STR
5526 IPV6_STR
5527 BGP_STR
5528 "Configure BGP aggregate entries\n"
5529 "Aggregate prefix\n")
5530
5531ALIAS (no_ipv6_aggregate_address_summary_only,
5532 old_no_ipv6_aggregate_address_summary_only_cmd,
5533 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5534 NO_STR
5535 IPV6_STR
5536 BGP_STR
5537 "Configure BGP aggregate entries\n"
5538 "Aggregate prefix\n"
5539 "Filter more specific routes from updates\n")
5540#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02005541
paul718e3742002-12-13 20:15:29 +00005542/* Redistribute route treatment. */
5543void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005544bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5545 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005546 u_int32_t metric, u_char type)
5547{
5548 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005549 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005550 struct bgp_info *new;
5551 struct bgp_info *bi;
5552 struct bgp_info info;
5553 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005554 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005555 struct attr *new_attr;
5556 afi_t afi;
5557 int ret;
5558
5559 /* Make default attribute. */
5560 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5561 if (nexthop)
5562 attr.nexthop = *nexthop;
5563
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005564#ifdef HAVE_IPV6
5565 if (nexthop6)
5566 {
5567 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5568 extra->mp_nexthop_global = *nexthop6;
5569 extra->mp_nexthop_len = 16;
5570 }
5571#endif
5572
paul718e3742002-12-13 20:15:29 +00005573 attr.med = metric;
5574 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5575
paul1eb8ef22005-04-07 07:30:20 +00005576 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005577 {
5578 afi = family2afi (p->family);
5579
5580 if (bgp->redist[afi][type])
5581 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005582 struct attr attr_new;
5583 struct attr_extra extra_new;
5584
paul718e3742002-12-13 20:15:29 +00005585 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005586 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005587 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005588
5589 if (bgp->redist_metric_flag[afi][type])
5590 attr_new.med = bgp->redist_metric[afi][type];
5591
5592 /* Apply route-map. */
Daniel Walton1994dc82015-09-17 10:15:59 -04005593 if (bgp->rmap[afi][type].name)
paul718e3742002-12-13 20:15:29 +00005594 {
5595 info.peer = bgp->peer_self;
5596 info.attr = &attr_new;
5597
paulfee0f4c2004-09-13 05:12:46 +00005598 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5599
paul718e3742002-12-13 20:15:29 +00005600 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5601 &info);
paulfee0f4c2004-09-13 05:12:46 +00005602
5603 bgp->peer_self->rmap_type = 0;
5604
paul718e3742002-12-13 20:15:29 +00005605 if (ret == RMAP_DENYMATCH)
5606 {
5607 /* Free uninterned attribute. */
5608 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005609
paul718e3742002-12-13 20:15:29 +00005610 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005611 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005612 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005613 bgp_redistribute_delete (p, type);
5614 return;
5615 }
5616 }
5617
Paul Jakmafb982c22007-05-04 20:15:47 +00005618 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5619 afi, SAFI_UNICAST, p, NULL);
5620
paul718e3742002-12-13 20:15:29 +00005621 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005622
paul718e3742002-12-13 20:15:29 +00005623 for (bi = bn->info; bi; bi = bi->next)
5624 if (bi->peer == bgp->peer_self
5625 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5626 break;
5627
5628 if (bi)
5629 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005630 if (attrhash_cmp (bi->attr, new_attr) &&
5631 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005632 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005633 bgp_attr_unintern (&new_attr);
5634 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005635 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005636 bgp_unlock_node (bn);
5637 return;
5638 }
5639 else
5640 {
5641 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005642 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005643
5644 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005645 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5646 bgp_info_restore(bn, bi);
5647 else
5648 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005649 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005650 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005651 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005652
5653 /* Process change. */
5654 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5655 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5656 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005657 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005658 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005659 return;
5660 }
5661 }
5662
5663 new = bgp_info_new ();
5664 new->type = type;
5665 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5666 new->peer = bgp->peer_self;
5667 SET_FLAG (new->flags, BGP_INFO_VALID);
5668 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005669 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005670
5671 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5672 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005673 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005674 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5675 }
5676 }
5677
5678 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005679 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005680 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005681}
5682
5683void
5684bgp_redistribute_delete (struct prefix *p, u_char type)
5685{
5686 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005687 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005688 afi_t afi;
5689 struct bgp_node *rn;
5690 struct bgp_info *ri;
5691
paul1eb8ef22005-04-07 07:30:20 +00005692 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005693 {
5694 afi = family2afi (p->family);
5695
5696 if (bgp->redist[afi][type])
5697 {
paulfee0f4c2004-09-13 05:12:46 +00005698 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005699
5700 for (ri = rn->info; ri; ri = ri->next)
5701 if (ri->peer == bgp->peer_self
5702 && ri->type == type)
5703 break;
5704
5705 if (ri)
5706 {
5707 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005708 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005709 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005710 }
5711 bgp_unlock_node (rn);
5712 }
5713 }
5714}
5715
5716/* Withdraw specified route type's route. */
5717void
5718bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5719{
5720 struct bgp_node *rn;
5721 struct bgp_info *ri;
5722 struct bgp_table *table;
5723
5724 table = bgp->rib[afi][SAFI_UNICAST];
5725
5726 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5727 {
5728 for (ri = rn->info; ri; ri = ri->next)
5729 if (ri->peer == bgp->peer_self
5730 && ri->type == type)
5731 break;
5732
5733 if (ri)
5734 {
5735 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005736 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005737 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005738 }
5739 }
5740}
David Lamparter6b0655a2014-06-04 06:53:35 +02005741
paul718e3742002-12-13 20:15:29 +00005742/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005743static void
paul718e3742002-12-13 20:15:29 +00005744route_vty_out_route (struct prefix *p, struct vty *vty)
5745{
5746 int len;
5747 u_int32_t destination;
5748 char buf[BUFSIZ];
5749
5750 if (p->family == AF_INET)
5751 {
5752 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5753 destination = ntohl (p->u.prefix4.s_addr);
5754
5755 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5756 || (IN_CLASSB (destination) && p->prefixlen == 16)
5757 || (IN_CLASSA (destination) && p->prefixlen == 8)
5758 || p->u.prefix4.s_addr == 0)
5759 {
5760 /* When mask is natural, mask is not displayed. */
5761 }
5762 else
5763 len += vty_out (vty, "/%d", p->prefixlen);
5764 }
5765 else
5766 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5767 p->prefixlen);
5768
5769 len = 17 - len;
5770 if (len < 1)
5771 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5772 else
5773 vty_out (vty, "%*s", len, " ");
5774}
5775
paul718e3742002-12-13 20:15:29 +00005776enum bgp_display_type
5777{
5778 normal_list,
5779};
5780
paulb40d9392005-08-22 22:34:41 +00005781/* Print the short form route status for a bgp_info */
5782static void
5783route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005784{
paulb40d9392005-08-22 22:34:41 +00005785 /* Route status display. */
5786 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5787 vty_out (vty, "R");
5788 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005789 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005790 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005791 vty_out (vty, "s");
5792 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5793 vty_out (vty, "*");
5794 else
5795 vty_out (vty, " ");
5796
5797 /* Selected */
5798 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5799 vty_out (vty, "h");
5800 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5801 vty_out (vty, "d");
5802 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5803 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005804 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5805 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005806 else
5807 vty_out (vty, " ");
5808
5809 /* Internal route. */
5810 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5811 vty_out (vty, "i");
5812 else
paulb40d9392005-08-22 22:34:41 +00005813 vty_out (vty, " ");
5814}
5815
5816/* called from terminal list command */
5817void
5818route_vty_out (struct vty *vty, struct prefix *p,
5819 struct bgp_info *binfo, int display, safi_t safi)
5820{
5821 struct attr *attr;
5822
5823 /* short status lead text */
5824 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005825
5826 /* print prefix and mask */
5827 if (! display)
5828 route_vty_out_route (p, vty);
5829 else
5830 vty_out (vty, "%*s", 17, " ");
5831
5832 /* Print attribute */
5833 attr = binfo->attr;
5834 if (attr)
5835 {
5836 if (p->family == AF_INET)
5837 {
5838 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005839 vty_out (vty, "%-16s",
5840 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005841 else
5842 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5843 }
5844#ifdef HAVE_IPV6
5845 else if (p->family == AF_INET6)
5846 {
5847 int len;
5848 char buf[BUFSIZ];
5849
5850 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005851 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5852 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005853 len = 16 - len;
5854 if (len < 1)
5855 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5856 else
5857 vty_out (vty, "%*s", len, " ");
5858 }
5859#endif /* HAVE_IPV6 */
5860
5861 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005862 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005863 else
5864 vty_out (vty, " ");
5865
5866 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005867 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005868 else
5869 vty_out (vty, " ");
5870
Paul Jakmafb982c22007-05-04 20:15:47 +00005871 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005872
Paul Jakmab2518c12006-05-12 23:48:40 +00005873 /* Print aspath */
5874 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005875 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005876
Paul Jakmab2518c12006-05-12 23:48:40 +00005877 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005878 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005879 }
paul718e3742002-12-13 20:15:29 +00005880 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005881}
5882
5883/* called from terminal list command */
5884void
5885route_vty_out_tmp (struct vty *vty, struct prefix *p,
5886 struct attr *attr, safi_t safi)
5887{
5888 /* Route status display. */
5889 vty_out (vty, "*");
5890 vty_out (vty, ">");
5891 vty_out (vty, " ");
5892
5893 /* print prefix and mask */
5894 route_vty_out_route (p, vty);
5895
5896 /* Print attribute */
5897 if (attr)
5898 {
5899 if (p->family == AF_INET)
5900 {
5901 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005902 vty_out (vty, "%-16s",
5903 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005904 else
5905 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5906 }
5907#ifdef HAVE_IPV6
5908 else if (p->family == AF_INET6)
5909 {
5910 int len;
5911 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005912
5913 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005914
5915 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005916 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5917 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005918 len = 16 - len;
5919 if (len < 1)
5920 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5921 else
5922 vty_out (vty, "%*s", len, " ");
5923 }
5924#endif /* HAVE_IPV6 */
5925
5926 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005927 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005928 else
5929 vty_out (vty, " ");
5930
5931 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005932 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005933 else
5934 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005935
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005936 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005937
Paul Jakmab2518c12006-05-12 23:48:40 +00005938 /* Print aspath */
5939 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005940 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005941
Paul Jakmab2518c12006-05-12 23:48:40 +00005942 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005943 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005944 }
paul718e3742002-12-13 20:15:29 +00005945
5946 vty_out (vty, "%s", VTY_NEWLINE);
5947}
5948
ajs5a646652004-11-05 01:25:55 +00005949void
paul718e3742002-12-13 20:15:29 +00005950route_vty_out_tag (struct vty *vty, struct prefix *p,
5951 struct bgp_info *binfo, int display, safi_t safi)
5952{
5953 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005954 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005955
5956 if (!binfo->extra)
5957 return;
5958
paulb40d9392005-08-22 22:34:41 +00005959 /* short status lead text */
5960 route_vty_short_status_out (vty, binfo);
5961
paul718e3742002-12-13 20:15:29 +00005962 /* print prefix and mask */
5963 if (! display)
5964 route_vty_out_route (p, vty);
5965 else
5966 vty_out (vty, "%*s", 17, " ");
5967
5968 /* Print attribute */
5969 attr = binfo->attr;
5970 if (attr)
5971 {
5972 if (p->family == AF_INET)
5973 {
5974 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005975 vty_out (vty, "%-16s",
5976 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005977 else
5978 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5979 }
5980#ifdef HAVE_IPV6
5981 else if (p->family == AF_INET6)
5982 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005983 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005984 char buf[BUFSIZ];
5985 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005986 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005987 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005988 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5989 buf, BUFSIZ));
5990 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005991 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005992 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5993 buf, BUFSIZ),
5994 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5995 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005996
5997 }
5998#endif /* HAVE_IPV6 */
5999 }
6000
Paul Jakmafb982c22007-05-04 20:15:47 +00006001 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00006002
6003 vty_out (vty, "notag/%d", label);
6004
6005 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006006}
6007
6008/* dampening route */
ajs5a646652004-11-05 01:25:55 +00006009static void
paul718e3742002-12-13 20:15:29 +00006010damp_route_vty_out (struct vty *vty, struct prefix *p,
6011 struct bgp_info *binfo, int display, safi_t safi)
6012{
6013 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006014 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00006015 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00006016
paulb40d9392005-08-22 22:34:41 +00006017 /* short status lead text */
6018 route_vty_short_status_out (vty, binfo);
6019
paul718e3742002-12-13 20:15:29 +00006020 /* print prefix and mask */
6021 if (! display)
6022 route_vty_out_route (p, vty);
6023 else
6024 vty_out (vty, "%*s", 17, " ");
6025
6026 len = vty_out (vty, "%s", binfo->peer->host);
6027 len = 17 - len;
6028 if (len < 1)
6029 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6030 else
6031 vty_out (vty, "%*s", len, " ");
6032
Chris Caputo50aef6f2009-06-23 06:06:49 +00006033 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006034
6035 /* Print attribute */
6036 attr = binfo->attr;
6037 if (attr)
6038 {
6039 /* Print aspath */
6040 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006041 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006042
6043 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006044 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006045 }
6046 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006047}
6048
paul718e3742002-12-13 20:15:29 +00006049/* flap route */
ajs5a646652004-11-05 01:25:55 +00006050static void
paul718e3742002-12-13 20:15:29 +00006051flap_route_vty_out (struct vty *vty, struct prefix *p,
6052 struct bgp_info *binfo, int display, safi_t safi)
6053{
6054 struct attr *attr;
6055 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00006056 char timebuf[BGP_UPTIME_LEN];
6057 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00006058
6059 if (!binfo->extra)
6060 return;
6061
6062 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00006063
paulb40d9392005-08-22 22:34:41 +00006064 /* short status lead text */
6065 route_vty_short_status_out (vty, binfo);
6066
paul718e3742002-12-13 20:15:29 +00006067 /* print prefix and mask */
6068 if (! display)
6069 route_vty_out_route (p, vty);
6070 else
6071 vty_out (vty, "%*s", 17, " ");
6072
6073 len = vty_out (vty, "%s", binfo->peer->host);
6074 len = 16 - len;
6075 if (len < 1)
6076 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6077 else
6078 vty_out (vty, "%*s", len, " ");
6079
6080 len = vty_out (vty, "%d", bdi->flap);
6081 len = 5 - len;
6082 if (len < 1)
6083 vty_out (vty, " ");
6084 else
6085 vty_out (vty, "%*s ", len, " ");
6086
6087 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6088 timebuf, BGP_UPTIME_LEN));
6089
6090 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6091 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00006092 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006093 else
6094 vty_out (vty, "%*s ", 8, " ");
6095
6096 /* Print attribute */
6097 attr = binfo->attr;
6098 if (attr)
6099 {
6100 /* Print aspath */
6101 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006102 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006103
6104 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006105 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006106 }
6107 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006108}
6109
paul94f2b392005-06-28 12:44:16 +00006110static void
paul718e3742002-12-13 20:15:29 +00006111route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6112 struct bgp_info *binfo, afi_t afi, safi_t safi)
6113{
6114 char buf[INET6_ADDRSTRLEN];
6115 char buf1[BUFSIZ];
6116 struct attr *attr;
6117 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03006118#ifdef HAVE_CLOCK_MONOTONIC
6119 time_t tbuf;
6120#endif
paul718e3742002-12-13 20:15:29 +00006121
6122 attr = binfo->attr;
6123
6124 if (attr)
6125 {
6126 /* Line1 display AS-path, Aggregator */
6127 if (attr->aspath)
6128 {
6129 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00006130 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00006131 vty_out (vty, "Local");
6132 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006133 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00006134 }
6135
paulb40d9392005-08-22 22:34:41 +00006136 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6137 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00006138 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6139 vty_out (vty, ", (stale)");
6140 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006141 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006142 attr->extra->aggregator_as,
6143 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006144 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6145 vty_out (vty, ", (Received from a RR-client)");
6146 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6147 vty_out (vty, ", (Received from a RS-client)");
6148 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6149 vty_out (vty, ", (history entry)");
6150 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6151 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006152 vty_out (vty, "%s", VTY_NEWLINE);
6153
6154 /* Line2 display Next-hop, Neighbor, Router-id */
6155 if (p->family == AF_INET)
6156 {
6157 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006158 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006159 inet_ntoa (attr->nexthop));
6160 }
6161#ifdef HAVE_IPV6
6162 else
6163 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006164 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006165 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006166 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006167 buf, INET6_ADDRSTRLEN));
6168 }
6169#endif /* HAVE_IPV6 */
6170
6171 if (binfo->peer == bgp->peer_self)
6172 {
6173 vty_out (vty, " from %s ",
6174 p->family == AF_INET ? "0.0.0.0" : "::");
6175 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6176 }
6177 else
6178 {
6179 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6180 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006181 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006182 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006183 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006184 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006185 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006186 else
6187 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6188 }
6189 vty_out (vty, "%s", VTY_NEWLINE);
6190
6191#ifdef HAVE_IPV6
6192 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006193 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006194 {
6195 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006196 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006197 buf, INET6_ADDRSTRLEN),
6198 VTY_NEWLINE);
6199 }
6200#endif /* HAVE_IPV6 */
6201
6202 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6203 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6204
6205 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006206 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006207
6208 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006209 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006210 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006211 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006212
Paul Jakmafb982c22007-05-04 20:15:47 +00006213 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006214 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006215
6216 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6217 vty_out (vty, ", valid");
6218
6219 if (binfo->peer != bgp->peer_self)
6220 {
6221 if (binfo->peer->as == binfo->peer->local_as)
6222 vty_out (vty, ", internal");
6223 else
6224 vty_out (vty, ", %s",
6225 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6226 }
6227 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6228 vty_out (vty, ", aggregated, local");
6229 else if (binfo->type != ZEBRA_ROUTE_BGP)
6230 vty_out (vty, ", sourced");
6231 else
6232 vty_out (vty, ", sourced, local");
6233
6234 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6235 vty_out (vty, ", atomic-aggregate");
6236
Josh Baileyde8d5df2011-07-20 20:46:01 -07006237 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6238 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6239 bgp_info_mpath_count (binfo)))
6240 vty_out (vty, ", multipath");
6241
paul718e3742002-12-13 20:15:29 +00006242 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6243 vty_out (vty, ", best");
6244
6245 vty_out (vty, "%s", VTY_NEWLINE);
6246
6247 /* Line 4 display Community */
6248 if (attr->community)
6249 vty_out (vty, " Community: %s%s", attr->community->str,
6250 VTY_NEWLINE);
6251
6252 /* Line 5 display Extended-community */
6253 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006254 vty_out (vty, " Extended Community: %s%s",
6255 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006256
6257 /* Line 6 display Originator, Cluster-id */
6258 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6259 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6260 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006261 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006262 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006263 vty_out (vty, " Originator: %s",
6264 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006265
6266 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6267 {
6268 int i;
6269 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006270 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6271 vty_out (vty, "%s ",
6272 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006273 }
6274 vty_out (vty, "%s", VTY_NEWLINE);
6275 }
Paul Jakma41367172007-08-06 15:24:51 +00006276
Paul Jakmafb982c22007-05-04 20:15:47 +00006277 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006278 bgp_damp_info_vty (vty, binfo);
6279
6280 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006281#ifdef HAVE_CLOCK_MONOTONIC
6282 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006283 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006284#else
6285 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6286#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006287 }
6288 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006289}
6290
6291#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6292 "h history, * valid, > best, = multipath,%s"\
6293 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006294#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006295#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6296#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6297#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6298
6299enum bgp_show_type
6300{
6301 bgp_show_type_normal,
6302 bgp_show_type_regexp,
6303 bgp_show_type_prefix_list,
6304 bgp_show_type_filter_list,
6305 bgp_show_type_route_map,
6306 bgp_show_type_neighbor,
6307 bgp_show_type_cidr_only,
6308 bgp_show_type_prefix_longer,
6309 bgp_show_type_community_all,
6310 bgp_show_type_community,
6311 bgp_show_type_community_exact,
6312 bgp_show_type_community_list,
6313 bgp_show_type_community_list_exact,
6314 bgp_show_type_flap_statistics,
6315 bgp_show_type_flap_address,
6316 bgp_show_type_flap_prefix,
6317 bgp_show_type_flap_cidr_only,
6318 bgp_show_type_flap_regexp,
6319 bgp_show_type_flap_filter_list,
6320 bgp_show_type_flap_prefix_list,
6321 bgp_show_type_flap_prefix_longer,
6322 bgp_show_type_flap_route_map,
6323 bgp_show_type_flap_neighbor,
6324 bgp_show_type_dampend_paths,
6325 bgp_show_type_damp_neighbor
6326};
6327
ajs5a646652004-11-05 01:25:55 +00006328static int
paulfee0f4c2004-09-13 05:12:46 +00006329bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006330 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006331{
paul718e3742002-12-13 20:15:29 +00006332 struct bgp_info *ri;
6333 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006334 int header = 1;
paul718e3742002-12-13 20:15:29 +00006335 int display;
ajs5a646652004-11-05 01:25:55 +00006336 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006337
6338 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006339 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006340
paul718e3742002-12-13 20:15:29 +00006341 /* Start processing of routes. */
6342 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6343 if (rn->info != NULL)
6344 {
6345 display = 0;
6346
6347 for (ri = rn->info; ri; ri = ri->next)
6348 {
ajs5a646652004-11-05 01:25:55 +00006349 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006350 || type == bgp_show_type_flap_address
6351 || type == bgp_show_type_flap_prefix
6352 || type == bgp_show_type_flap_cidr_only
6353 || type == bgp_show_type_flap_regexp
6354 || type == bgp_show_type_flap_filter_list
6355 || type == bgp_show_type_flap_prefix_list
6356 || type == bgp_show_type_flap_prefix_longer
6357 || type == bgp_show_type_flap_route_map
6358 || type == bgp_show_type_flap_neighbor
6359 || type == bgp_show_type_dampend_paths
6360 || type == bgp_show_type_damp_neighbor)
6361 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006362 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006363 continue;
6364 }
6365 if (type == bgp_show_type_regexp
6366 || type == bgp_show_type_flap_regexp)
6367 {
ajs5a646652004-11-05 01:25:55 +00006368 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006369
6370 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6371 continue;
6372 }
6373 if (type == bgp_show_type_prefix_list
6374 || type == bgp_show_type_flap_prefix_list)
6375 {
ajs5a646652004-11-05 01:25:55 +00006376 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006377
6378 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6379 continue;
6380 }
6381 if (type == bgp_show_type_filter_list
6382 || type == bgp_show_type_flap_filter_list)
6383 {
ajs5a646652004-11-05 01:25:55 +00006384 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006385
6386 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6387 continue;
6388 }
6389 if (type == bgp_show_type_route_map
6390 || type == bgp_show_type_flap_route_map)
6391 {
ajs5a646652004-11-05 01:25:55 +00006392 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006393 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006394 struct attr dummy_attr;
6395 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006396 int ret;
6397
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006398 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006399 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006400
paul718e3742002-12-13 20:15:29 +00006401 binfo.peer = ri->peer;
6402 binfo.attr = &dummy_attr;
6403
6404 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006405 if (ret == RMAP_DENYMATCH)
6406 continue;
6407 }
6408 if (type == bgp_show_type_neighbor
6409 || type == bgp_show_type_flap_neighbor
6410 || type == bgp_show_type_damp_neighbor)
6411 {
ajs5a646652004-11-05 01:25:55 +00006412 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006413
6414 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6415 continue;
6416 }
6417 if (type == bgp_show_type_cidr_only
6418 || type == bgp_show_type_flap_cidr_only)
6419 {
6420 u_int32_t destination;
6421
6422 destination = ntohl (rn->p.u.prefix4.s_addr);
6423 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6424 continue;
6425 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6426 continue;
6427 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6428 continue;
6429 }
6430 if (type == bgp_show_type_prefix_longer
6431 || type == bgp_show_type_flap_prefix_longer)
6432 {
ajs5a646652004-11-05 01:25:55 +00006433 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006434
6435 if (! prefix_match (p, &rn->p))
6436 continue;
6437 }
6438 if (type == bgp_show_type_community_all)
6439 {
6440 if (! ri->attr->community)
6441 continue;
6442 }
6443 if (type == bgp_show_type_community)
6444 {
ajs5a646652004-11-05 01:25:55 +00006445 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006446
6447 if (! ri->attr->community ||
6448 ! community_match (ri->attr->community, com))
6449 continue;
6450 }
6451 if (type == bgp_show_type_community_exact)
6452 {
ajs5a646652004-11-05 01:25:55 +00006453 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006454
6455 if (! ri->attr->community ||
6456 ! community_cmp (ri->attr->community, com))
6457 continue;
6458 }
6459 if (type == bgp_show_type_community_list)
6460 {
ajs5a646652004-11-05 01:25:55 +00006461 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006462
6463 if (! community_list_match (ri->attr->community, list))
6464 continue;
6465 }
6466 if (type == bgp_show_type_community_list_exact)
6467 {
ajs5a646652004-11-05 01:25:55 +00006468 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006469
6470 if (! community_list_exact_match (ri->attr->community, list))
6471 continue;
6472 }
6473 if (type == bgp_show_type_flap_address
6474 || type == bgp_show_type_flap_prefix)
6475 {
ajs5a646652004-11-05 01:25:55 +00006476 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006477
6478 if (! prefix_match (&rn->p, p))
6479 continue;
6480
6481 if (type == bgp_show_type_flap_prefix)
6482 if (p->prefixlen != rn->p.prefixlen)
6483 continue;
6484 }
6485 if (type == bgp_show_type_dampend_paths
6486 || type == bgp_show_type_damp_neighbor)
6487 {
6488 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6489 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6490 continue;
6491 }
6492
6493 if (header)
6494 {
hasso93406d82005-02-02 14:40:33 +00006495 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6496 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6497 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006498 if (type == bgp_show_type_dampend_paths
6499 || type == bgp_show_type_damp_neighbor)
6500 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6501 else if (type == bgp_show_type_flap_statistics
6502 || type == bgp_show_type_flap_address
6503 || type == bgp_show_type_flap_prefix
6504 || type == bgp_show_type_flap_cidr_only
6505 || type == bgp_show_type_flap_regexp
6506 || type == bgp_show_type_flap_filter_list
6507 || type == bgp_show_type_flap_prefix_list
6508 || type == bgp_show_type_flap_prefix_longer
6509 || type == bgp_show_type_flap_route_map
6510 || type == bgp_show_type_flap_neighbor)
6511 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6512 else
6513 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006514 header = 0;
6515 }
6516
6517 if (type == bgp_show_type_dampend_paths
6518 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006519 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006520 else if (type == bgp_show_type_flap_statistics
6521 || type == bgp_show_type_flap_address
6522 || type == bgp_show_type_flap_prefix
6523 || type == bgp_show_type_flap_cidr_only
6524 || type == bgp_show_type_flap_regexp
6525 || type == bgp_show_type_flap_filter_list
6526 || type == bgp_show_type_flap_prefix_list
6527 || type == bgp_show_type_flap_prefix_longer
6528 || type == bgp_show_type_flap_route_map
6529 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006530 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006531 else
ajs5a646652004-11-05 01:25:55 +00006532 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006533 display++;
6534 }
6535 if (display)
ajs5a646652004-11-05 01:25:55 +00006536 output_count++;
paul718e3742002-12-13 20:15:29 +00006537 }
6538
6539 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006540 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006541 {
6542 if (type == bgp_show_type_normal)
6543 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6544 }
6545 else
6546 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006547 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006548
6549 return CMD_SUCCESS;
6550}
6551
ajs5a646652004-11-05 01:25:55 +00006552static int
paulfee0f4c2004-09-13 05:12:46 +00006553bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006554 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006555{
6556 struct bgp_table *table;
6557
6558 if (bgp == NULL) {
6559 bgp = bgp_get_default ();
6560 }
6561
6562 if (bgp == NULL)
6563 {
6564 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6565 return CMD_WARNING;
6566 }
6567
6568
6569 table = bgp->rib[afi][safi];
6570
ajs5a646652004-11-05 01:25:55 +00006571 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006572}
6573
paul718e3742002-12-13 20:15:29 +00006574/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006575static void
paul718e3742002-12-13 20:15:29 +00006576route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6577 struct bgp_node *rn,
6578 struct prefix_rd *prd, afi_t afi, safi_t safi)
6579{
6580 struct bgp_info *ri;
6581 struct prefix *p;
6582 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006583 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006584 char buf1[INET6_ADDRSTRLEN];
6585 char buf2[INET6_ADDRSTRLEN];
6586 int count = 0;
6587 int best = 0;
6588 int suppress = 0;
6589 int no_export = 0;
6590 int no_advertise = 0;
6591 int local_as = 0;
6592 int first = 0;
6593
6594 p = &rn->p;
6595 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6596 (safi == SAFI_MPLS_VPN ?
6597 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6598 safi == SAFI_MPLS_VPN ? ":" : "",
6599 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6600 p->prefixlen, VTY_NEWLINE);
6601
6602 for (ri = rn->info; ri; ri = ri->next)
6603 {
6604 count++;
6605 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6606 {
6607 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006608 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006609 suppress = 1;
6610 if (ri->attr->community != NULL)
6611 {
6612 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6613 no_advertise = 1;
6614 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6615 no_export = 1;
6616 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6617 local_as = 1;
6618 }
6619 }
6620 }
6621
6622 vty_out (vty, "Paths: (%d available", count);
6623 if (best)
6624 {
6625 vty_out (vty, ", best #%d", best);
6626 if (safi == SAFI_UNICAST)
6627 vty_out (vty, ", table Default-IP-Routing-Table");
6628 }
6629 else
6630 vty_out (vty, ", no best path");
6631 if (no_advertise)
6632 vty_out (vty, ", not advertised to any peer");
6633 else if (no_export)
6634 vty_out (vty, ", not advertised to EBGP peer");
6635 else if (local_as)
6636 vty_out (vty, ", not advertised outside local AS");
6637 if (suppress)
6638 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6639 vty_out (vty, ")%s", VTY_NEWLINE);
6640
6641 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006642 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006643 {
6644 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6645 {
6646 if (! first)
6647 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6648 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6649 first = 1;
6650 }
6651 }
6652 if (! first)
6653 vty_out (vty, " Not advertised to any peer");
6654 vty_out (vty, "%s", VTY_NEWLINE);
6655}
6656
6657/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006658static int
paulfee0f4c2004-09-13 05:12:46 +00006659bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006660 struct bgp_table *rib, const char *ip_str,
6661 afi_t afi, safi_t safi, struct prefix_rd *prd,
6662 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006663{
6664 int ret;
6665 int header;
6666 int display = 0;
6667 struct prefix match;
6668 struct bgp_node *rn;
6669 struct bgp_node *rm;
6670 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006671 struct bgp_table *table;
6672
paul718e3742002-12-13 20:15:29 +00006673 /* Check IP address argument. */
6674 ret = str2prefix (ip_str, &match);
6675 if (! ret)
6676 {
6677 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6678 return CMD_WARNING;
6679 }
6680
6681 match.family = afi2family (afi);
6682
6683 if (safi == SAFI_MPLS_VPN)
6684 {
paulfee0f4c2004-09-13 05:12:46 +00006685 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006686 {
6687 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6688 continue;
6689
6690 if ((table = rn->info) != NULL)
6691 {
6692 header = 1;
6693
6694 if ((rm = bgp_node_match (table, &match)) != NULL)
6695 {
6696 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006697 {
6698 bgp_unlock_node (rm);
6699 continue;
6700 }
paul718e3742002-12-13 20:15:29 +00006701
6702 for (ri = rm->info; ri; ri = ri->next)
6703 {
6704 if (header)
6705 {
6706 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6707 AFI_IP, SAFI_MPLS_VPN);
6708
6709 header = 0;
6710 }
6711 display++;
6712 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6713 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006714
6715 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006716 }
6717 }
6718 }
6719 }
6720 else
6721 {
6722 header = 1;
6723
paulfee0f4c2004-09-13 05:12:46 +00006724 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006725 {
6726 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6727 {
6728 for (ri = rn->info; ri; ri = ri->next)
6729 {
6730 if (header)
6731 {
6732 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6733 header = 0;
6734 }
6735 display++;
6736 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6737 }
6738 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006739
6740 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006741 }
6742 }
6743
6744 if (! display)
6745 {
6746 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6747 return CMD_WARNING;
6748 }
6749
6750 return CMD_SUCCESS;
6751}
6752
paulfee0f4c2004-09-13 05:12:46 +00006753/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006754static int
paulfd79ac92004-10-13 05:06:08 +00006755bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006756 afi_t afi, safi_t safi, struct prefix_rd *prd,
6757 int prefix_check)
6758{
6759 struct bgp *bgp;
6760
6761 /* BGP structure lookup. */
6762 if (view_name)
6763 {
6764 bgp = bgp_lookup_by_name (view_name);
6765 if (bgp == NULL)
6766 {
6767 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6768 return CMD_WARNING;
6769 }
6770 }
6771 else
6772 {
6773 bgp = bgp_get_default ();
6774 if (bgp == NULL)
6775 {
6776 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6777 return CMD_WARNING;
6778 }
6779 }
6780
6781 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6782 afi, safi, prd, prefix_check);
6783}
6784
paul718e3742002-12-13 20:15:29 +00006785/* BGP route print out function. */
6786DEFUN (show_ip_bgp,
6787 show_ip_bgp_cmd,
6788 "show ip bgp",
6789 SHOW_STR
6790 IP_STR
6791 BGP_STR)
6792{
ajs5a646652004-11-05 01:25:55 +00006793 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006794}
6795
6796DEFUN (show_ip_bgp_ipv4,
6797 show_ip_bgp_ipv4_cmd,
6798 "show ip bgp ipv4 (unicast|multicast)",
6799 SHOW_STR
6800 IP_STR
6801 BGP_STR
6802 "Address family\n"
6803 "Address Family modifier\n"
6804 "Address Family modifier\n")
6805{
6806 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006807 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6808 NULL);
paul718e3742002-12-13 20:15:29 +00006809
ajs5a646652004-11-05 01:25:55 +00006810 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006811}
6812
Michael Lambert95cbbd22010-07-23 14:43:04 -04006813ALIAS (show_ip_bgp_ipv4,
6814 show_bgp_ipv4_safi_cmd,
6815 "show bgp ipv4 (unicast|multicast)",
6816 SHOW_STR
6817 BGP_STR
6818 "Address family\n"
6819 "Address Family modifier\n"
6820 "Address Family modifier\n")
6821
paul718e3742002-12-13 20:15:29 +00006822DEFUN (show_ip_bgp_route,
6823 show_ip_bgp_route_cmd,
6824 "show ip bgp A.B.C.D",
6825 SHOW_STR
6826 IP_STR
6827 BGP_STR
6828 "Network in the BGP routing table to display\n")
6829{
6830 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6831}
6832
6833DEFUN (show_ip_bgp_ipv4_route,
6834 show_ip_bgp_ipv4_route_cmd,
6835 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6836 SHOW_STR
6837 IP_STR
6838 BGP_STR
6839 "Address family\n"
6840 "Address Family modifier\n"
6841 "Address Family modifier\n"
6842 "Network in the BGP routing table to display\n")
6843{
6844 if (strncmp (argv[0], "m", 1) == 0)
6845 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6846
6847 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6848}
6849
Michael Lambert95cbbd22010-07-23 14:43:04 -04006850ALIAS (show_ip_bgp_ipv4_route,
6851 show_bgp_ipv4_safi_route_cmd,
6852 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6853 SHOW_STR
6854 BGP_STR
6855 "Address family\n"
6856 "Address Family modifier\n"
6857 "Address Family modifier\n"
6858 "Network in the BGP routing table to display\n")
6859
paul718e3742002-12-13 20:15:29 +00006860DEFUN (show_ip_bgp_vpnv4_all_route,
6861 show_ip_bgp_vpnv4_all_route_cmd,
6862 "show ip bgp vpnv4 all A.B.C.D",
6863 SHOW_STR
6864 IP_STR
6865 BGP_STR
6866 "Display VPNv4 NLRI specific information\n"
6867 "Display information about all VPNv4 NLRIs\n"
6868 "Network in the BGP routing table to display\n")
6869{
6870 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6871}
6872
6873DEFUN (show_ip_bgp_vpnv4_rd_route,
6874 show_ip_bgp_vpnv4_rd_route_cmd,
6875 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6876 SHOW_STR
6877 IP_STR
6878 BGP_STR
6879 "Display VPNv4 NLRI specific information\n"
6880 "Display information for a route distinguisher\n"
6881 "VPN Route Distinguisher\n"
6882 "Network in the BGP routing table to display\n")
6883{
6884 int ret;
6885 struct prefix_rd prd;
6886
6887 ret = str2prefix_rd (argv[0], &prd);
6888 if (! ret)
6889 {
6890 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6891 return CMD_WARNING;
6892 }
6893 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6894}
6895
6896DEFUN (show_ip_bgp_prefix,
6897 show_ip_bgp_prefix_cmd,
6898 "show ip bgp A.B.C.D/M",
6899 SHOW_STR
6900 IP_STR
6901 BGP_STR
6902 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6903{
6904 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6905}
6906
6907DEFUN (show_ip_bgp_ipv4_prefix,
6908 show_ip_bgp_ipv4_prefix_cmd,
6909 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6910 SHOW_STR
6911 IP_STR
6912 BGP_STR
6913 "Address family\n"
6914 "Address Family modifier\n"
6915 "Address Family modifier\n"
6916 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6917{
6918 if (strncmp (argv[0], "m", 1) == 0)
6919 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6920
6921 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6922}
6923
Michael Lambert95cbbd22010-07-23 14:43:04 -04006924ALIAS (show_ip_bgp_ipv4_prefix,
6925 show_bgp_ipv4_safi_prefix_cmd,
6926 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6927 SHOW_STR
6928 BGP_STR
6929 "Address family\n"
6930 "Address Family modifier\n"
6931 "Address Family modifier\n"
6932 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6933
paul718e3742002-12-13 20:15:29 +00006934DEFUN (show_ip_bgp_vpnv4_all_prefix,
6935 show_ip_bgp_vpnv4_all_prefix_cmd,
6936 "show ip bgp vpnv4 all A.B.C.D/M",
6937 SHOW_STR
6938 IP_STR
6939 BGP_STR
6940 "Display VPNv4 NLRI specific information\n"
6941 "Display information about all VPNv4 NLRIs\n"
6942 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6943{
6944 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6945}
6946
6947DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6948 show_ip_bgp_vpnv4_rd_prefix_cmd,
6949 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6950 SHOW_STR
6951 IP_STR
6952 BGP_STR
6953 "Display VPNv4 NLRI specific information\n"
6954 "Display information for a route distinguisher\n"
6955 "VPN Route Distinguisher\n"
6956 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6957{
6958 int ret;
6959 struct prefix_rd prd;
6960
6961 ret = str2prefix_rd (argv[0], &prd);
6962 if (! ret)
6963 {
6964 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6965 return CMD_WARNING;
6966 }
6967 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6968}
6969
6970DEFUN (show_ip_bgp_view,
6971 show_ip_bgp_view_cmd,
6972 "show ip bgp view WORD",
6973 SHOW_STR
6974 IP_STR
6975 BGP_STR
6976 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006977 "View name\n")
paul718e3742002-12-13 20:15:29 +00006978{
paulbb46e942003-10-24 19:02:03 +00006979 struct bgp *bgp;
6980
6981 /* BGP structure lookup. */
6982 bgp = bgp_lookup_by_name (argv[0]);
6983 if (bgp == NULL)
6984 {
6985 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6986 return CMD_WARNING;
6987 }
6988
ajs5a646652004-11-05 01:25:55 +00006989 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006990}
6991
6992DEFUN (show_ip_bgp_view_route,
6993 show_ip_bgp_view_route_cmd,
6994 "show ip bgp view WORD A.B.C.D",
6995 SHOW_STR
6996 IP_STR
6997 BGP_STR
6998 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006999 "View name\n"
paul718e3742002-12-13 20:15:29 +00007000 "Network in the BGP routing table to display\n")
7001{
7002 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
7003}
7004
7005DEFUN (show_ip_bgp_view_prefix,
7006 show_ip_bgp_view_prefix_cmd,
7007 "show ip bgp view WORD A.B.C.D/M",
7008 SHOW_STR
7009 IP_STR
7010 BGP_STR
7011 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007012 "View name\n"
paul718e3742002-12-13 20:15:29 +00007013 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7014{
7015 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
7016}
7017
7018#ifdef HAVE_IPV6
7019DEFUN (show_bgp,
7020 show_bgp_cmd,
7021 "show bgp",
7022 SHOW_STR
7023 BGP_STR)
7024{
ajs5a646652004-11-05 01:25:55 +00007025 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7026 NULL);
paul718e3742002-12-13 20:15:29 +00007027}
7028
7029ALIAS (show_bgp,
7030 show_bgp_ipv6_cmd,
7031 "show bgp ipv6",
7032 SHOW_STR
7033 BGP_STR
7034 "Address family\n")
7035
Michael Lambert95cbbd22010-07-23 14:43:04 -04007036DEFUN (show_bgp_ipv6_safi,
7037 show_bgp_ipv6_safi_cmd,
7038 "show bgp ipv6 (unicast|multicast)",
7039 SHOW_STR
7040 BGP_STR
7041 "Address family\n"
7042 "Address Family modifier\n"
7043 "Address Family modifier\n")
7044{
7045 if (strncmp (argv[0], "m", 1) == 0)
7046 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7047 NULL);
7048
7049 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
7050}
7051
paul718e3742002-12-13 20:15:29 +00007052/* old command */
7053DEFUN (show_ipv6_bgp,
7054 show_ipv6_bgp_cmd,
7055 "show ipv6 bgp",
7056 SHOW_STR
7057 IP_STR
7058 BGP_STR)
7059{
ajs5a646652004-11-05 01:25:55 +00007060 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7061 NULL);
paul718e3742002-12-13 20:15:29 +00007062}
7063
7064DEFUN (show_bgp_route,
7065 show_bgp_route_cmd,
7066 "show bgp X:X::X:X",
7067 SHOW_STR
7068 BGP_STR
7069 "Network in the BGP routing table to display\n")
7070{
7071 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7072}
7073
7074ALIAS (show_bgp_route,
7075 show_bgp_ipv6_route_cmd,
7076 "show bgp ipv6 X:X::X:X",
7077 SHOW_STR
7078 BGP_STR
7079 "Address family\n"
7080 "Network in the BGP routing table to display\n")
7081
Michael Lambert95cbbd22010-07-23 14:43:04 -04007082DEFUN (show_bgp_ipv6_safi_route,
7083 show_bgp_ipv6_safi_route_cmd,
7084 "show bgp ipv6 (unicast|multicast) X:X::X:X",
7085 SHOW_STR
7086 BGP_STR
7087 "Address family\n"
7088 "Address Family modifier\n"
7089 "Address Family modifier\n"
7090 "Network in the BGP routing table to display\n")
7091{
7092 if (strncmp (argv[0], "m", 1) == 0)
7093 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7094
7095 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7096}
7097
paul718e3742002-12-13 20:15:29 +00007098/* old command */
7099DEFUN (show_ipv6_bgp_route,
7100 show_ipv6_bgp_route_cmd,
7101 "show ipv6 bgp X:X::X:X",
7102 SHOW_STR
7103 IP_STR
7104 BGP_STR
7105 "Network in the BGP routing table to display\n")
7106{
7107 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7108}
7109
7110DEFUN (show_bgp_prefix,
7111 show_bgp_prefix_cmd,
7112 "show bgp X:X::X:X/M",
7113 SHOW_STR
7114 BGP_STR
7115 "IPv6 prefix <network>/<length>\n")
7116{
7117 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7118}
7119
7120ALIAS (show_bgp_prefix,
7121 show_bgp_ipv6_prefix_cmd,
7122 "show bgp ipv6 X:X::X:X/M",
7123 SHOW_STR
7124 BGP_STR
7125 "Address family\n"
7126 "IPv6 prefix <network>/<length>\n")
7127
Michael Lambert95cbbd22010-07-23 14:43:04 -04007128DEFUN (show_bgp_ipv6_safi_prefix,
7129 show_bgp_ipv6_safi_prefix_cmd,
7130 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
7131 SHOW_STR
7132 BGP_STR
7133 "Address family\n"
7134 "Address Family modifier\n"
7135 "Address Family modifier\n"
7136 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7137{
7138 if (strncmp (argv[0], "m", 1) == 0)
7139 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7140
7141 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7142}
7143
paul718e3742002-12-13 20:15:29 +00007144/* old command */
7145DEFUN (show_ipv6_bgp_prefix,
7146 show_ipv6_bgp_prefix_cmd,
7147 "show ipv6 bgp X:X::X:X/M",
7148 SHOW_STR
7149 IP_STR
7150 BGP_STR
7151 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7152{
7153 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7154}
7155
paulbb46e942003-10-24 19:02:03 +00007156DEFUN (show_bgp_view,
7157 show_bgp_view_cmd,
7158 "show bgp view WORD",
7159 SHOW_STR
7160 BGP_STR
7161 "BGP view\n"
7162 "View name\n")
7163{
7164 struct bgp *bgp;
7165
7166 /* BGP structure lookup. */
7167 bgp = bgp_lookup_by_name (argv[0]);
7168 if (bgp == NULL)
7169 {
7170 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7171 return CMD_WARNING;
7172 }
7173
ajs5a646652004-11-05 01:25:55 +00007174 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007175}
7176
7177ALIAS (show_bgp_view,
7178 show_bgp_view_ipv6_cmd,
7179 "show bgp view WORD ipv6",
7180 SHOW_STR
7181 BGP_STR
7182 "BGP view\n"
7183 "View name\n"
7184 "Address family\n")
7185
7186DEFUN (show_bgp_view_route,
7187 show_bgp_view_route_cmd,
7188 "show bgp view WORD X:X::X:X",
7189 SHOW_STR
7190 BGP_STR
7191 "BGP view\n"
7192 "View name\n"
7193 "Network in the BGP routing table to display\n")
7194{
7195 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7196}
7197
7198ALIAS (show_bgp_view_route,
7199 show_bgp_view_ipv6_route_cmd,
7200 "show bgp view WORD ipv6 X:X::X:X",
7201 SHOW_STR
7202 BGP_STR
7203 "BGP view\n"
7204 "View name\n"
7205 "Address family\n"
7206 "Network in the BGP routing table to display\n")
7207
7208DEFUN (show_bgp_view_prefix,
7209 show_bgp_view_prefix_cmd,
7210 "show bgp view WORD X:X::X:X/M",
7211 SHOW_STR
7212 BGP_STR
7213 "BGP view\n"
7214 "View name\n"
7215 "IPv6 prefix <network>/<length>\n")
7216{
7217 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7218}
7219
7220ALIAS (show_bgp_view_prefix,
7221 show_bgp_view_ipv6_prefix_cmd,
7222 "show bgp view WORD ipv6 X:X::X:X/M",
7223 SHOW_STR
7224 BGP_STR
7225 "BGP view\n"
7226 "View name\n"
7227 "Address family\n"
7228 "IPv6 prefix <network>/<length>\n")
7229
paul718e3742002-12-13 20:15:29 +00007230/* old command */
7231DEFUN (show_ipv6_mbgp,
7232 show_ipv6_mbgp_cmd,
7233 "show ipv6 mbgp",
7234 SHOW_STR
7235 IP_STR
7236 MBGP_STR)
7237{
ajs5a646652004-11-05 01:25:55 +00007238 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7239 NULL);
paul718e3742002-12-13 20:15:29 +00007240}
7241
7242/* old command */
7243DEFUN (show_ipv6_mbgp_route,
7244 show_ipv6_mbgp_route_cmd,
7245 "show ipv6 mbgp X:X::X:X",
7246 SHOW_STR
7247 IP_STR
7248 MBGP_STR
7249 "Network in the MBGP routing table to display\n")
7250{
7251 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7252}
7253
7254/* old command */
7255DEFUN (show_ipv6_mbgp_prefix,
7256 show_ipv6_mbgp_prefix_cmd,
7257 "show ipv6 mbgp X:X::X:X/M",
7258 SHOW_STR
7259 IP_STR
7260 MBGP_STR
7261 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7262{
7263 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7264}
7265#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02007266
paul718e3742002-12-13 20:15:29 +00007267
paul94f2b392005-06-28 12:44:16 +00007268static int
paulfd79ac92004-10-13 05:06:08 +00007269bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007270 safi_t safi, enum bgp_show_type type)
7271{
7272 int i;
7273 struct buffer *b;
7274 char *regstr;
7275 int first;
7276 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007277 int rc;
paul718e3742002-12-13 20:15:29 +00007278
7279 first = 0;
7280 b = buffer_new (1024);
7281 for (i = 0; i < argc; i++)
7282 {
7283 if (first)
7284 buffer_putc (b, ' ');
7285 else
7286 {
7287 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7288 continue;
7289 first = 1;
7290 }
7291
7292 buffer_putstr (b, argv[i]);
7293 }
7294 buffer_putc (b, '\0');
7295
7296 regstr = buffer_getstr (b);
7297 buffer_free (b);
7298
7299 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007300 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007301 if (! regex)
7302 {
7303 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7304 VTY_NEWLINE);
7305 return CMD_WARNING;
7306 }
7307
ajs5a646652004-11-05 01:25:55 +00007308 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7309 bgp_regex_free (regex);
7310 return rc;
paul718e3742002-12-13 20:15:29 +00007311}
7312
7313DEFUN (show_ip_bgp_regexp,
7314 show_ip_bgp_regexp_cmd,
7315 "show ip bgp regexp .LINE",
7316 SHOW_STR
7317 IP_STR
7318 BGP_STR
7319 "Display routes matching the AS path regular expression\n"
7320 "A regular-expression to match the BGP AS paths\n")
7321{
7322 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7323 bgp_show_type_regexp);
7324}
7325
7326DEFUN (show_ip_bgp_flap_regexp,
7327 show_ip_bgp_flap_regexp_cmd,
7328 "show ip bgp flap-statistics regexp .LINE",
7329 SHOW_STR
7330 IP_STR
7331 BGP_STR
7332 "Display flap statistics of routes\n"
7333 "Display routes matching the AS path regular expression\n"
7334 "A regular-expression to match the BGP AS paths\n")
7335{
7336 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7337 bgp_show_type_flap_regexp);
7338}
7339
Balaji3921cc52015-05-16 23:12:17 +05307340ALIAS (show_ip_bgp_flap_regexp,
7341 show_ip_bgp_damp_flap_regexp_cmd,
7342 "show ip bgp dampening flap-statistics regexp .LINE",
7343 SHOW_STR
7344 IP_STR
7345 BGP_STR
7346 "Display detailed information about dampening\n"
7347 "Display flap statistics of routes\n"
7348 "Display routes matching the AS path regular expression\n"
7349 "A regular-expression to match the BGP AS paths\n")
7350
paul718e3742002-12-13 20:15:29 +00007351DEFUN (show_ip_bgp_ipv4_regexp,
7352 show_ip_bgp_ipv4_regexp_cmd,
7353 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7354 SHOW_STR
7355 IP_STR
7356 BGP_STR
7357 "Address family\n"
7358 "Address Family modifier\n"
7359 "Address Family modifier\n"
7360 "Display routes matching the AS path regular expression\n"
7361 "A regular-expression to match the BGP AS paths\n")
7362{
7363 if (strncmp (argv[0], "m", 1) == 0)
7364 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7365 bgp_show_type_regexp);
7366
7367 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7368 bgp_show_type_regexp);
7369}
7370
7371#ifdef HAVE_IPV6
7372DEFUN (show_bgp_regexp,
7373 show_bgp_regexp_cmd,
7374 "show bgp regexp .LINE",
7375 SHOW_STR
7376 BGP_STR
7377 "Display routes matching the AS path regular expression\n"
7378 "A regular-expression to match the BGP AS paths\n")
7379{
7380 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7381 bgp_show_type_regexp);
7382}
7383
7384ALIAS (show_bgp_regexp,
7385 show_bgp_ipv6_regexp_cmd,
7386 "show bgp ipv6 regexp .LINE",
7387 SHOW_STR
7388 BGP_STR
7389 "Address family\n"
7390 "Display routes matching the AS path regular expression\n"
7391 "A regular-expression to match the BGP AS paths\n")
7392
7393/* old command */
7394DEFUN (show_ipv6_bgp_regexp,
7395 show_ipv6_bgp_regexp_cmd,
7396 "show ipv6 bgp regexp .LINE",
7397 SHOW_STR
7398 IP_STR
7399 BGP_STR
7400 "Display routes matching the AS path regular expression\n"
7401 "A regular-expression to match the BGP AS paths\n")
7402{
7403 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7404 bgp_show_type_regexp);
7405}
7406
7407/* old command */
7408DEFUN (show_ipv6_mbgp_regexp,
7409 show_ipv6_mbgp_regexp_cmd,
7410 "show ipv6 mbgp regexp .LINE",
7411 SHOW_STR
7412 IP_STR
7413 BGP_STR
7414 "Display routes matching the AS path regular expression\n"
7415 "A regular-expression to match the MBGP AS paths\n")
7416{
7417 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7418 bgp_show_type_regexp);
7419}
7420#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007421
paul94f2b392005-06-28 12:44:16 +00007422static int
paulfd79ac92004-10-13 05:06:08 +00007423bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007424 safi_t safi, enum bgp_show_type type)
7425{
7426 struct prefix_list *plist;
7427
7428 plist = prefix_list_lookup (afi, prefix_list_str);
7429 if (plist == NULL)
7430 {
7431 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7432 prefix_list_str, VTY_NEWLINE);
7433 return CMD_WARNING;
7434 }
7435
ajs5a646652004-11-05 01:25:55 +00007436 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007437}
7438
7439DEFUN (show_ip_bgp_prefix_list,
7440 show_ip_bgp_prefix_list_cmd,
7441 "show ip bgp prefix-list WORD",
7442 SHOW_STR
7443 IP_STR
7444 BGP_STR
7445 "Display routes conforming to the prefix-list\n"
7446 "IP prefix-list name\n")
7447{
7448 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7449 bgp_show_type_prefix_list);
7450}
7451
7452DEFUN (show_ip_bgp_flap_prefix_list,
7453 show_ip_bgp_flap_prefix_list_cmd,
7454 "show ip bgp flap-statistics prefix-list WORD",
7455 SHOW_STR
7456 IP_STR
7457 BGP_STR
7458 "Display flap statistics of routes\n"
7459 "Display routes conforming to the prefix-list\n"
7460 "IP prefix-list name\n")
7461{
7462 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7463 bgp_show_type_flap_prefix_list);
7464}
7465
Balaji3921cc52015-05-16 23:12:17 +05307466ALIAS (show_ip_bgp_flap_prefix_list,
7467 show_ip_bgp_damp_flap_prefix_list_cmd,
7468 "show ip bgp dampening flap-statistics prefix-list WORD",
7469 SHOW_STR
7470 IP_STR
7471 BGP_STR
7472 "Display detailed information about dampening\n"
7473 "Display flap statistics of routes\n"
7474 "Display routes conforming to the prefix-list\n"
7475 "IP prefix-list name\n")
7476
paul718e3742002-12-13 20:15:29 +00007477DEFUN (show_ip_bgp_ipv4_prefix_list,
7478 show_ip_bgp_ipv4_prefix_list_cmd,
7479 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7480 SHOW_STR
7481 IP_STR
7482 BGP_STR
7483 "Address family\n"
7484 "Address Family modifier\n"
7485 "Address Family modifier\n"
7486 "Display routes conforming to the prefix-list\n"
7487 "IP prefix-list name\n")
7488{
7489 if (strncmp (argv[0], "m", 1) == 0)
7490 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7491 bgp_show_type_prefix_list);
7492
7493 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7494 bgp_show_type_prefix_list);
7495}
7496
7497#ifdef HAVE_IPV6
7498DEFUN (show_bgp_prefix_list,
7499 show_bgp_prefix_list_cmd,
7500 "show bgp prefix-list WORD",
7501 SHOW_STR
7502 BGP_STR
7503 "Display routes conforming to the prefix-list\n"
7504 "IPv6 prefix-list name\n")
7505{
7506 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7507 bgp_show_type_prefix_list);
7508}
7509
7510ALIAS (show_bgp_prefix_list,
7511 show_bgp_ipv6_prefix_list_cmd,
7512 "show bgp ipv6 prefix-list WORD",
7513 SHOW_STR
7514 BGP_STR
7515 "Address family\n"
7516 "Display routes conforming to the prefix-list\n"
7517 "IPv6 prefix-list name\n")
7518
7519/* old command */
7520DEFUN (show_ipv6_bgp_prefix_list,
7521 show_ipv6_bgp_prefix_list_cmd,
7522 "show ipv6 bgp prefix-list WORD",
7523 SHOW_STR
7524 IPV6_STR
7525 BGP_STR
7526 "Display routes matching the prefix-list\n"
7527 "IPv6 prefix-list name\n")
7528{
7529 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7530 bgp_show_type_prefix_list);
7531}
7532
7533/* old command */
7534DEFUN (show_ipv6_mbgp_prefix_list,
7535 show_ipv6_mbgp_prefix_list_cmd,
7536 "show ipv6 mbgp prefix-list WORD",
7537 SHOW_STR
7538 IPV6_STR
7539 MBGP_STR
7540 "Display routes matching the prefix-list\n"
7541 "IPv6 prefix-list name\n")
7542{
7543 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7544 bgp_show_type_prefix_list);
7545}
7546#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007547
paul94f2b392005-06-28 12:44:16 +00007548static int
paulfd79ac92004-10-13 05:06:08 +00007549bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007550 safi_t safi, enum bgp_show_type type)
7551{
7552 struct as_list *as_list;
7553
7554 as_list = as_list_lookup (filter);
7555 if (as_list == NULL)
7556 {
7557 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7558 return CMD_WARNING;
7559 }
7560
ajs5a646652004-11-05 01:25:55 +00007561 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007562}
7563
7564DEFUN (show_ip_bgp_filter_list,
7565 show_ip_bgp_filter_list_cmd,
7566 "show ip bgp filter-list WORD",
7567 SHOW_STR
7568 IP_STR
7569 BGP_STR
7570 "Display routes conforming to the filter-list\n"
7571 "Regular expression access list name\n")
7572{
7573 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7574 bgp_show_type_filter_list);
7575}
7576
7577DEFUN (show_ip_bgp_flap_filter_list,
7578 show_ip_bgp_flap_filter_list_cmd,
7579 "show ip bgp flap-statistics filter-list WORD",
7580 SHOW_STR
7581 IP_STR
7582 BGP_STR
7583 "Display flap statistics of routes\n"
7584 "Display routes conforming to the filter-list\n"
7585 "Regular expression access list name\n")
7586{
7587 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7588 bgp_show_type_flap_filter_list);
7589}
7590
Balaji3921cc52015-05-16 23:12:17 +05307591ALIAS (show_ip_bgp_flap_filter_list,
7592 show_ip_bgp_damp_flap_filter_list_cmd,
7593 "show ip bgp dampening flap-statistics filter-list WORD",
7594 SHOW_STR
7595 IP_STR
7596 BGP_STR
7597 "Display detailed information about dampening\n"
7598 "Display flap statistics of routes\n"
7599 "Display routes conforming to the filter-list\n"
7600 "Regular expression access list name\n")
7601
paul718e3742002-12-13 20:15:29 +00007602DEFUN (show_ip_bgp_ipv4_filter_list,
7603 show_ip_bgp_ipv4_filter_list_cmd,
7604 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7605 SHOW_STR
7606 IP_STR
7607 BGP_STR
7608 "Address family\n"
7609 "Address Family modifier\n"
7610 "Address Family modifier\n"
7611 "Display routes conforming to the filter-list\n"
7612 "Regular expression access list name\n")
7613{
7614 if (strncmp (argv[0], "m", 1) == 0)
7615 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7616 bgp_show_type_filter_list);
7617
7618 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7619 bgp_show_type_filter_list);
7620}
7621
7622#ifdef HAVE_IPV6
7623DEFUN (show_bgp_filter_list,
7624 show_bgp_filter_list_cmd,
7625 "show bgp filter-list WORD",
7626 SHOW_STR
7627 BGP_STR
7628 "Display routes conforming to the filter-list\n"
7629 "Regular expression access list name\n")
7630{
7631 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7632 bgp_show_type_filter_list);
7633}
7634
7635ALIAS (show_bgp_filter_list,
7636 show_bgp_ipv6_filter_list_cmd,
7637 "show bgp ipv6 filter-list WORD",
7638 SHOW_STR
7639 BGP_STR
7640 "Address family\n"
7641 "Display routes conforming to the filter-list\n"
7642 "Regular expression access list name\n")
7643
7644/* old command */
7645DEFUN (show_ipv6_bgp_filter_list,
7646 show_ipv6_bgp_filter_list_cmd,
7647 "show ipv6 bgp filter-list WORD",
7648 SHOW_STR
7649 IPV6_STR
7650 BGP_STR
7651 "Display routes conforming to the filter-list\n"
7652 "Regular expression access list name\n")
7653{
7654 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7655 bgp_show_type_filter_list);
7656}
7657
7658/* old command */
7659DEFUN (show_ipv6_mbgp_filter_list,
7660 show_ipv6_mbgp_filter_list_cmd,
7661 "show ipv6 mbgp filter-list WORD",
7662 SHOW_STR
7663 IPV6_STR
7664 MBGP_STR
7665 "Display routes conforming to the filter-list\n"
7666 "Regular expression access list name\n")
7667{
7668 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7669 bgp_show_type_filter_list);
7670}
7671#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007672
Balaji3921cc52015-05-16 23:12:17 +05307673DEFUN (show_ip_bgp_dampening_info,
7674 show_ip_bgp_dampening_params_cmd,
7675 "show ip bgp dampening parameters",
7676 SHOW_STR
7677 IP_STR
7678 BGP_STR
7679 "Display detailed information about dampening\n"
7680 "Display detail of configured dampening parameters\n")
7681{
7682 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
7683}
7684
paul94f2b392005-06-28 12:44:16 +00007685static int
paulfd79ac92004-10-13 05:06:08 +00007686bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007687 safi_t safi, enum bgp_show_type type)
7688{
7689 struct route_map *rmap;
7690
7691 rmap = route_map_lookup_by_name (rmap_str);
7692 if (! rmap)
7693 {
7694 vty_out (vty, "%% %s is not a valid route-map name%s",
7695 rmap_str, VTY_NEWLINE);
7696 return CMD_WARNING;
7697 }
7698
ajs5a646652004-11-05 01:25:55 +00007699 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007700}
7701
7702DEFUN (show_ip_bgp_route_map,
7703 show_ip_bgp_route_map_cmd,
7704 "show ip bgp route-map WORD",
7705 SHOW_STR
7706 IP_STR
7707 BGP_STR
7708 "Display routes matching the route-map\n"
7709 "A route-map to match on\n")
7710{
7711 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7712 bgp_show_type_route_map);
7713}
7714
7715DEFUN (show_ip_bgp_flap_route_map,
7716 show_ip_bgp_flap_route_map_cmd,
7717 "show ip bgp flap-statistics route-map WORD",
7718 SHOW_STR
7719 IP_STR
7720 BGP_STR
7721 "Display flap statistics of routes\n"
7722 "Display routes matching the route-map\n"
7723 "A route-map to match on\n")
7724{
7725 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7726 bgp_show_type_flap_route_map);
7727}
7728
Balaji3921cc52015-05-16 23:12:17 +05307729ALIAS (show_ip_bgp_flap_route_map,
7730 show_ip_bgp_damp_flap_route_map_cmd,
7731 "show ip bgp dampening flap-statistics route-map WORD",
7732 SHOW_STR
7733 IP_STR
7734 BGP_STR
7735 "Display detailed information about dampening\n"
7736 "Display flap statistics of routes\n"
7737 "Display routes matching the route-map\n"
7738 "A route-map to match on\n")
7739
paul718e3742002-12-13 20:15:29 +00007740DEFUN (show_ip_bgp_ipv4_route_map,
7741 show_ip_bgp_ipv4_route_map_cmd,
7742 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7743 SHOW_STR
7744 IP_STR
7745 BGP_STR
7746 "Address family\n"
7747 "Address Family modifier\n"
7748 "Address Family modifier\n"
7749 "Display routes matching the route-map\n"
7750 "A route-map to match on\n")
7751{
7752 if (strncmp (argv[0], "m", 1) == 0)
7753 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7754 bgp_show_type_route_map);
7755
7756 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7757 bgp_show_type_route_map);
7758}
7759
7760DEFUN (show_bgp_route_map,
7761 show_bgp_route_map_cmd,
7762 "show bgp route-map WORD",
7763 SHOW_STR
7764 BGP_STR
7765 "Display routes matching the route-map\n"
7766 "A route-map to match on\n")
7767{
7768 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7769 bgp_show_type_route_map);
7770}
7771
7772ALIAS (show_bgp_route_map,
7773 show_bgp_ipv6_route_map_cmd,
7774 "show bgp ipv6 route-map WORD",
7775 SHOW_STR
7776 BGP_STR
7777 "Address family\n"
7778 "Display routes matching the route-map\n"
7779 "A route-map to match on\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02007780
paul718e3742002-12-13 20:15:29 +00007781DEFUN (show_ip_bgp_cidr_only,
7782 show_ip_bgp_cidr_only_cmd,
7783 "show ip bgp cidr-only",
7784 SHOW_STR
7785 IP_STR
7786 BGP_STR
7787 "Display only routes with non-natural netmasks\n")
7788{
7789 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007790 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007791}
7792
7793DEFUN (show_ip_bgp_flap_cidr_only,
7794 show_ip_bgp_flap_cidr_only_cmd,
7795 "show ip bgp flap-statistics cidr-only",
7796 SHOW_STR
7797 IP_STR
7798 BGP_STR
7799 "Display flap statistics of routes\n"
7800 "Display only routes with non-natural netmasks\n")
7801{
7802 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007803 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007804}
7805
Balaji3921cc52015-05-16 23:12:17 +05307806ALIAS (show_ip_bgp_flap_cidr_only,
7807 show_ip_bgp_damp_flap_cidr_only_cmd,
7808 "show ip bgp dampening flap-statistics cidr-only",
7809 SHOW_STR
7810 IP_STR
7811 BGP_STR
7812 "Display detailed information about dampening\n"
7813 "Display flap statistics of routes\n"
7814 "Display only routes with non-natural netmasks\n")
7815
paul718e3742002-12-13 20:15:29 +00007816DEFUN (show_ip_bgp_ipv4_cidr_only,
7817 show_ip_bgp_ipv4_cidr_only_cmd,
7818 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7819 SHOW_STR
7820 IP_STR
7821 BGP_STR
7822 "Address family\n"
7823 "Address Family modifier\n"
7824 "Address Family modifier\n"
7825 "Display only routes with non-natural netmasks\n")
7826{
7827 if (strncmp (argv[0], "m", 1) == 0)
7828 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007829 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007830
7831 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007832 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007833}
David Lamparter6b0655a2014-06-04 06:53:35 +02007834
paul718e3742002-12-13 20:15:29 +00007835DEFUN (show_ip_bgp_community_all,
7836 show_ip_bgp_community_all_cmd,
7837 "show ip bgp community",
7838 SHOW_STR
7839 IP_STR
7840 BGP_STR
7841 "Display routes matching the communities\n")
7842{
7843 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007844 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007845}
7846
7847DEFUN (show_ip_bgp_ipv4_community_all,
7848 show_ip_bgp_ipv4_community_all_cmd,
7849 "show ip bgp ipv4 (unicast|multicast) community",
7850 SHOW_STR
7851 IP_STR
7852 BGP_STR
7853 "Address family\n"
7854 "Address Family modifier\n"
7855 "Address Family modifier\n"
7856 "Display routes matching the communities\n")
7857{
7858 if (strncmp (argv[0], "m", 1) == 0)
7859 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007860 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007861
7862 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007863 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007864}
7865
7866#ifdef HAVE_IPV6
7867DEFUN (show_bgp_community_all,
7868 show_bgp_community_all_cmd,
7869 "show bgp community",
7870 SHOW_STR
7871 BGP_STR
7872 "Display routes matching the communities\n")
7873{
7874 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007875 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007876}
7877
7878ALIAS (show_bgp_community_all,
7879 show_bgp_ipv6_community_all_cmd,
7880 "show bgp ipv6 community",
7881 SHOW_STR
7882 BGP_STR
7883 "Address family\n"
7884 "Display routes matching the communities\n")
7885
7886/* old command */
7887DEFUN (show_ipv6_bgp_community_all,
7888 show_ipv6_bgp_community_all_cmd,
7889 "show ipv6 bgp community",
7890 SHOW_STR
7891 IPV6_STR
7892 BGP_STR
7893 "Display routes matching the communities\n")
7894{
7895 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007896 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007897}
7898
7899/* old command */
7900DEFUN (show_ipv6_mbgp_community_all,
7901 show_ipv6_mbgp_community_all_cmd,
7902 "show ipv6 mbgp community",
7903 SHOW_STR
7904 IPV6_STR
7905 MBGP_STR
7906 "Display routes matching the communities\n")
7907{
7908 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007909 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007910}
7911#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007912
paul94f2b392005-06-28 12:44:16 +00007913static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007914bgp_show_community (struct vty *vty, const char *view_name, int argc,
7915 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007916{
7917 struct community *com;
7918 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007919 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007920 int i;
7921 char *str;
7922 int first = 0;
7923
Michael Lambert95cbbd22010-07-23 14:43:04 -04007924 /* BGP structure lookup */
7925 if (view_name)
7926 {
7927 bgp = bgp_lookup_by_name (view_name);
7928 if (bgp == NULL)
7929 {
7930 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7931 return CMD_WARNING;
7932 }
7933 }
7934 else
7935 {
7936 bgp = bgp_get_default ();
7937 if (bgp == NULL)
7938 {
7939 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7940 return CMD_WARNING;
7941 }
7942 }
7943
paul718e3742002-12-13 20:15:29 +00007944 b = buffer_new (1024);
7945 for (i = 0; i < argc; i++)
7946 {
7947 if (first)
7948 buffer_putc (b, ' ');
7949 else
7950 {
7951 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7952 continue;
7953 first = 1;
7954 }
7955
7956 buffer_putstr (b, argv[i]);
7957 }
7958 buffer_putc (b, '\0');
7959
7960 str = buffer_getstr (b);
7961 buffer_free (b);
7962
7963 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007964 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007965 if (! com)
7966 {
7967 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7968 return CMD_WARNING;
7969 }
7970
Michael Lambert95cbbd22010-07-23 14:43:04 -04007971 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007972 (exact ? bgp_show_type_community_exact :
7973 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007974}
7975
7976DEFUN (show_ip_bgp_community,
7977 show_ip_bgp_community_cmd,
7978 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7979 SHOW_STR
7980 IP_STR
7981 BGP_STR
7982 "Display routes matching the communities\n"
7983 "community number\n"
7984 "Do not send outside local AS (well-known community)\n"
7985 "Do not advertise to any peer (well-known community)\n"
7986 "Do not export to next AS (well-known community)\n")
7987{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007988 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007989}
7990
7991ALIAS (show_ip_bgp_community,
7992 show_ip_bgp_community2_cmd,
7993 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7994 SHOW_STR
7995 IP_STR
7996 BGP_STR
7997 "Display routes matching the communities\n"
7998 "community number\n"
7999 "Do not send outside local AS (well-known community)\n"
8000 "Do not advertise to any peer (well-known community)\n"
8001 "Do not export to next AS (well-known community)\n"
8002 "community number\n"
8003 "Do not send outside local AS (well-known community)\n"
8004 "Do not advertise to any peer (well-known community)\n"
8005 "Do not export to next AS (well-known community)\n")
8006
8007ALIAS (show_ip_bgp_community,
8008 show_ip_bgp_community3_cmd,
8009 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8010 SHOW_STR
8011 IP_STR
8012 BGP_STR
8013 "Display routes matching the communities\n"
8014 "community number\n"
8015 "Do not send outside local AS (well-known community)\n"
8016 "Do not advertise to any peer (well-known community)\n"
8017 "Do not export to next AS (well-known community)\n"
8018 "community number\n"
8019 "Do not send outside local AS (well-known community)\n"
8020 "Do not advertise to any peer (well-known community)\n"
8021 "Do not export to next AS (well-known community)\n"
8022 "community number\n"
8023 "Do not send outside local AS (well-known community)\n"
8024 "Do not advertise to any peer (well-known community)\n"
8025 "Do not export to next AS (well-known community)\n")
8026
8027ALIAS (show_ip_bgp_community,
8028 show_ip_bgp_community4_cmd,
8029 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8030 SHOW_STR
8031 IP_STR
8032 BGP_STR
8033 "Display routes matching the communities\n"
8034 "community number\n"
8035 "Do not send outside local AS (well-known community)\n"
8036 "Do not advertise to any peer (well-known community)\n"
8037 "Do not export to next AS (well-known community)\n"
8038 "community number\n"
8039 "Do not send outside local AS (well-known community)\n"
8040 "Do not advertise to any peer (well-known community)\n"
8041 "Do not export to next AS (well-known community)\n"
8042 "community number\n"
8043 "Do not send outside local AS (well-known community)\n"
8044 "Do not advertise to any peer (well-known community)\n"
8045 "Do not export to next AS (well-known community)\n"
8046 "community number\n"
8047 "Do not send outside local AS (well-known community)\n"
8048 "Do not advertise to any peer (well-known community)\n"
8049 "Do not export to next AS (well-known community)\n")
8050
8051DEFUN (show_ip_bgp_ipv4_community,
8052 show_ip_bgp_ipv4_community_cmd,
8053 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
8054 SHOW_STR
8055 IP_STR
8056 BGP_STR
8057 "Address family\n"
8058 "Address Family modifier\n"
8059 "Address Family modifier\n"
8060 "Display routes matching the communities\n"
8061 "community number\n"
8062 "Do not send outside local AS (well-known community)\n"
8063 "Do not advertise to any peer (well-known community)\n"
8064 "Do not export to next AS (well-known community)\n")
8065{
8066 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008067 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008068
Michael Lambert95cbbd22010-07-23 14:43:04 -04008069 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008070}
8071
8072ALIAS (show_ip_bgp_ipv4_community,
8073 show_ip_bgp_ipv4_community2_cmd,
8074 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8075 SHOW_STR
8076 IP_STR
8077 BGP_STR
8078 "Address family\n"
8079 "Address Family modifier\n"
8080 "Address Family modifier\n"
8081 "Display routes matching the communities\n"
8082 "community number\n"
8083 "Do not send outside local AS (well-known community)\n"
8084 "Do not advertise to any peer (well-known community)\n"
8085 "Do not export to next AS (well-known community)\n"
8086 "community number\n"
8087 "Do not send outside local AS (well-known community)\n"
8088 "Do not advertise to any peer (well-known community)\n"
8089 "Do not export to next AS (well-known community)\n")
8090
8091ALIAS (show_ip_bgp_ipv4_community,
8092 show_ip_bgp_ipv4_community3_cmd,
8093 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8094 SHOW_STR
8095 IP_STR
8096 BGP_STR
8097 "Address family\n"
8098 "Address Family modifier\n"
8099 "Address Family modifier\n"
8100 "Display routes matching the communities\n"
8101 "community number\n"
8102 "Do not send outside local AS (well-known community)\n"
8103 "Do not advertise to any peer (well-known community)\n"
8104 "Do not export to next AS (well-known community)\n"
8105 "community number\n"
8106 "Do not send outside local AS (well-known community)\n"
8107 "Do not advertise to any peer (well-known community)\n"
8108 "Do not export to next AS (well-known community)\n"
8109 "community number\n"
8110 "Do not send outside local AS (well-known community)\n"
8111 "Do not advertise to any peer (well-known community)\n"
8112 "Do not export to next AS (well-known community)\n")
8113
8114ALIAS (show_ip_bgp_ipv4_community,
8115 show_ip_bgp_ipv4_community4_cmd,
8116 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8117 SHOW_STR
8118 IP_STR
8119 BGP_STR
8120 "Address family\n"
8121 "Address Family modifier\n"
8122 "Address Family modifier\n"
8123 "Display routes matching the communities\n"
8124 "community number\n"
8125 "Do not send outside local AS (well-known community)\n"
8126 "Do not advertise to any peer (well-known community)\n"
8127 "Do not export to next AS (well-known community)\n"
8128 "community number\n"
8129 "Do not send outside local AS (well-known community)\n"
8130 "Do not advertise to any peer (well-known community)\n"
8131 "Do not export to next AS (well-known community)\n"
8132 "community number\n"
8133 "Do not send outside local AS (well-known community)\n"
8134 "Do not advertise to any peer (well-known community)\n"
8135 "Do not export to next AS (well-known community)\n"
8136 "community number\n"
8137 "Do not send outside local AS (well-known community)\n"
8138 "Do not advertise to any peer (well-known community)\n"
8139 "Do not export to next AS (well-known community)\n")
8140
Michael Lambert95cbbd22010-07-23 14:43:04 -04008141DEFUN (show_bgp_view_afi_safi_community_all,
8142 show_bgp_view_afi_safi_community_all_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008143 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008144 SHOW_STR
8145 BGP_STR
8146 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008147 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008148 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008149 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008150 "Address Family modifier\n"
8151 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00008152 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04008153{
8154 int afi;
8155 int safi;
8156 struct bgp *bgp;
8157
8158 /* BGP structure lookup. */
8159 bgp = bgp_lookup_by_name (argv[0]);
8160 if (bgp == NULL)
8161 {
8162 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8163 return CMD_WARNING;
8164 }
8165
Michael Lambert95cbbd22010-07-23 14:43:04 -04008166 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8167 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Michael Lambert95cbbd22010-07-23 14:43:04 -04008168 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
8169}
8170
8171DEFUN (show_bgp_view_afi_safi_community,
8172 show_bgp_view_afi_safi_community_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008173 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008174 SHOW_STR
8175 BGP_STR
8176 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008177 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008178 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008179 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008180 "Address family modifier\n"
8181 "Address family modifier\n"
8182 "Display routes matching the communities\n"
8183 "community number\n"
8184 "Do not send outside local AS (well-known community)\n"
8185 "Do not advertise to any peer (well-known community)\n"
8186 "Do not export to next AS (well-known community)\n")
8187{
8188 int afi;
8189 int safi;
8190
Michael Lambert95cbbd22010-07-23 14:43:04 -04008191 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8192 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8193 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Michael Lambert95cbbd22010-07-23 14:43:04 -04008194}
8195
8196ALIAS (show_bgp_view_afi_safi_community,
8197 show_bgp_view_afi_safi_community2_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008198 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008199 SHOW_STR
8200 BGP_STR
8201 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008202 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008203 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008204 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008205 "Address family modifier\n"
8206 "Address family modifier\n"
8207 "Display routes matching the communities\n"
8208 "community number\n"
8209 "Do not send outside local AS (well-known community)\n"
8210 "Do not advertise to any peer (well-known community)\n"
8211 "Do not export to next AS (well-known community)\n"
8212 "community number\n"
8213 "Do not send outside local AS (well-known community)\n"
8214 "Do not advertise to any peer (well-known community)\n"
8215 "Do not export to next AS (well-known community)\n")
8216
8217ALIAS (show_bgp_view_afi_safi_community,
8218 show_bgp_view_afi_safi_community3_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008219 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008220 SHOW_STR
8221 BGP_STR
8222 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008223 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008224 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008225 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008226 "Address family modifier\n"
8227 "Address family modifier\n"
8228 "Display routes matching the communities\n"
8229 "community number\n"
8230 "Do not send outside local AS (well-known community)\n"
8231 "Do not advertise to any peer (well-known community)\n"
8232 "Do not export to next AS (well-known community)\n"
8233 "community number\n"
8234 "Do not send outside local AS (well-known community)\n"
8235 "Do not advertise to any peer (well-known community)\n"
8236 "Do not export to next AS (well-known community)\n"
8237 "community number\n"
8238 "Do not send outside local AS (well-known community)\n"
8239 "Do not advertise to any peer (well-known community)\n"
8240 "Do not export to next AS (well-known community)\n")
8241
8242ALIAS (show_bgp_view_afi_safi_community,
8243 show_bgp_view_afi_safi_community4_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008244 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008245 SHOW_STR
8246 BGP_STR
8247 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008248 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008249 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008250 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008251 "Address family modifier\n"
8252 "Address family modifier\n"
8253 "Display routes matching the communities\n"
8254 "community number\n"
8255 "Do not send outside local AS (well-known community)\n"
8256 "Do not advertise to any peer (well-known community)\n"
8257 "Do not export to next AS (well-known community)\n"
8258 "community number\n"
8259 "Do not send outside local AS (well-known community)\n"
8260 "Do not advertise to any peer (well-known community)\n"
8261 "Do not export to next AS (well-known community)\n"
8262 "community number\n"
8263 "Do not send outside local AS (well-known community)\n"
8264 "Do not advertise to any peer (well-known community)\n"
8265 "Do not export to next AS (well-known community)\n"
8266 "community number\n"
8267 "Do not send outside local AS (well-known community)\n"
8268 "Do not advertise to any peer (well-known community)\n"
8269 "Do not export to next AS (well-known community)\n")
8270
paul718e3742002-12-13 20:15:29 +00008271DEFUN (show_ip_bgp_community_exact,
8272 show_ip_bgp_community_exact_cmd,
8273 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8274 SHOW_STR
8275 IP_STR
8276 BGP_STR
8277 "Display routes matching the communities\n"
8278 "community number\n"
8279 "Do not send outside local AS (well-known community)\n"
8280 "Do not advertise to any peer (well-known community)\n"
8281 "Do not export to next AS (well-known community)\n"
8282 "Exact match of the communities")
8283{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008284 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008285}
8286
8287ALIAS (show_ip_bgp_community_exact,
8288 show_ip_bgp_community2_exact_cmd,
8289 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8290 SHOW_STR
8291 IP_STR
8292 BGP_STR
8293 "Display routes matching the communities\n"
8294 "community number\n"
8295 "Do not send outside local AS (well-known community)\n"
8296 "Do not advertise to any peer (well-known community)\n"
8297 "Do not export to next AS (well-known community)\n"
8298 "community number\n"
8299 "Do not send outside local AS (well-known community)\n"
8300 "Do not advertise to any peer (well-known community)\n"
8301 "Do not export to next AS (well-known community)\n"
8302 "Exact match of the communities")
8303
8304ALIAS (show_ip_bgp_community_exact,
8305 show_ip_bgp_community3_exact_cmd,
8306 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8307 SHOW_STR
8308 IP_STR
8309 BGP_STR
8310 "Display routes matching the communities\n"
8311 "community number\n"
8312 "Do not send outside local AS (well-known community)\n"
8313 "Do not advertise to any peer (well-known community)\n"
8314 "Do not export to next AS (well-known community)\n"
8315 "community number\n"
8316 "Do not send outside local AS (well-known community)\n"
8317 "Do not advertise to any peer (well-known community)\n"
8318 "Do not export to next AS (well-known community)\n"
8319 "community number\n"
8320 "Do not send outside local AS (well-known community)\n"
8321 "Do not advertise to any peer (well-known community)\n"
8322 "Do not export to next AS (well-known community)\n"
8323 "Exact match of the communities")
8324
8325ALIAS (show_ip_bgp_community_exact,
8326 show_ip_bgp_community4_exact_cmd,
8327 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8328 SHOW_STR
8329 IP_STR
8330 BGP_STR
8331 "Display routes matching the communities\n"
8332 "community number\n"
8333 "Do not send outside local AS (well-known community)\n"
8334 "Do not advertise to any peer (well-known community)\n"
8335 "Do not export to next AS (well-known community)\n"
8336 "community number\n"
8337 "Do not send outside local AS (well-known community)\n"
8338 "Do not advertise to any peer (well-known community)\n"
8339 "Do not export to next AS (well-known community)\n"
8340 "community number\n"
8341 "Do not send outside local AS (well-known community)\n"
8342 "Do not advertise to any peer (well-known community)\n"
8343 "Do not export to next AS (well-known community)\n"
8344 "community number\n"
8345 "Do not send outside local AS (well-known community)\n"
8346 "Do not advertise to any peer (well-known community)\n"
8347 "Do not export to next AS (well-known community)\n"
8348 "Exact match of the communities")
8349
8350DEFUN (show_ip_bgp_ipv4_community_exact,
8351 show_ip_bgp_ipv4_community_exact_cmd,
8352 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8353 SHOW_STR
8354 IP_STR
8355 BGP_STR
8356 "Address family\n"
8357 "Address Family modifier\n"
8358 "Address Family modifier\n"
8359 "Display routes matching the communities\n"
8360 "community number\n"
8361 "Do not send outside local AS (well-known community)\n"
8362 "Do not advertise to any peer (well-known community)\n"
8363 "Do not export to next AS (well-known community)\n"
8364 "Exact match of the communities")
8365{
8366 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008367 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008368
Michael Lambert95cbbd22010-07-23 14:43:04 -04008369 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008370}
8371
8372ALIAS (show_ip_bgp_ipv4_community_exact,
8373 show_ip_bgp_ipv4_community2_exact_cmd,
8374 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8375 SHOW_STR
8376 IP_STR
8377 BGP_STR
8378 "Address family\n"
8379 "Address Family modifier\n"
8380 "Address Family modifier\n"
8381 "Display routes matching the communities\n"
8382 "community number\n"
8383 "Do not send outside local AS (well-known community)\n"
8384 "Do not advertise to any peer (well-known community)\n"
8385 "Do not export to next AS (well-known community)\n"
8386 "community number\n"
8387 "Do not send outside local AS (well-known community)\n"
8388 "Do not advertise to any peer (well-known community)\n"
8389 "Do not export to next AS (well-known community)\n"
8390 "Exact match of the communities")
8391
8392ALIAS (show_ip_bgp_ipv4_community_exact,
8393 show_ip_bgp_ipv4_community3_exact_cmd,
8394 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8395 SHOW_STR
8396 IP_STR
8397 BGP_STR
8398 "Address family\n"
8399 "Address Family modifier\n"
8400 "Address Family modifier\n"
8401 "Display routes matching the communities\n"
8402 "community number\n"
8403 "Do not send outside local AS (well-known community)\n"
8404 "Do not advertise to any peer (well-known community)\n"
8405 "Do not export to next AS (well-known community)\n"
8406 "community number\n"
8407 "Do not send outside local AS (well-known community)\n"
8408 "Do not advertise to any peer (well-known community)\n"
8409 "Do not export to next AS (well-known community)\n"
8410 "community number\n"
8411 "Do not send outside local AS (well-known community)\n"
8412 "Do not advertise to any peer (well-known community)\n"
8413 "Do not export to next AS (well-known community)\n"
8414 "Exact match of the communities")
8415
8416ALIAS (show_ip_bgp_ipv4_community_exact,
8417 show_ip_bgp_ipv4_community4_exact_cmd,
8418 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8419 SHOW_STR
8420 IP_STR
8421 BGP_STR
8422 "Address family\n"
8423 "Address Family modifier\n"
8424 "Address Family modifier\n"
8425 "Display routes matching the communities\n"
8426 "community number\n"
8427 "Do not send outside local AS (well-known community)\n"
8428 "Do not advertise to any peer (well-known community)\n"
8429 "Do not export to next AS (well-known community)\n"
8430 "community number\n"
8431 "Do not send outside local AS (well-known community)\n"
8432 "Do not advertise to any peer (well-known community)\n"
8433 "Do not export to next AS (well-known community)\n"
8434 "community number\n"
8435 "Do not send outside local AS (well-known community)\n"
8436 "Do not advertise to any peer (well-known community)\n"
8437 "Do not export to next AS (well-known community)\n"
8438 "community number\n"
8439 "Do not send outside local AS (well-known community)\n"
8440 "Do not advertise to any peer (well-known community)\n"
8441 "Do not export to next AS (well-known community)\n"
8442 "Exact match of the communities")
8443
8444#ifdef HAVE_IPV6
8445DEFUN (show_bgp_community,
8446 show_bgp_community_cmd,
8447 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8448 SHOW_STR
8449 BGP_STR
8450 "Display routes matching the communities\n"
8451 "community number\n"
8452 "Do not send outside local AS (well-known community)\n"
8453 "Do not advertise to any peer (well-known community)\n"
8454 "Do not export to next AS (well-known community)\n")
8455{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008456 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008457}
8458
8459ALIAS (show_bgp_community,
8460 show_bgp_ipv6_community_cmd,
8461 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8462 SHOW_STR
8463 BGP_STR
8464 "Address family\n"
8465 "Display routes matching the communities\n"
8466 "community number\n"
8467 "Do not send outside local AS (well-known community)\n"
8468 "Do not advertise to any peer (well-known community)\n"
8469 "Do not export to next AS (well-known community)\n")
8470
8471ALIAS (show_bgp_community,
8472 show_bgp_community2_cmd,
8473 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8474 SHOW_STR
8475 BGP_STR
8476 "Display routes matching the communities\n"
8477 "community number\n"
8478 "Do not send outside local AS (well-known community)\n"
8479 "Do not advertise to any peer (well-known community)\n"
8480 "Do not export to next AS (well-known community)\n"
8481 "community number\n"
8482 "Do not send outside local AS (well-known community)\n"
8483 "Do not advertise to any peer (well-known community)\n"
8484 "Do not export to next AS (well-known community)\n")
8485
8486ALIAS (show_bgp_community,
8487 show_bgp_ipv6_community2_cmd,
8488 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8489 SHOW_STR
8490 BGP_STR
8491 "Address family\n"
8492 "Display routes matching the communities\n"
8493 "community number\n"
8494 "Do not send outside local AS (well-known community)\n"
8495 "Do not advertise to any peer (well-known community)\n"
8496 "Do not export to next AS (well-known community)\n"
8497 "community number\n"
8498 "Do not send outside local AS (well-known community)\n"
8499 "Do not advertise to any peer (well-known community)\n"
8500 "Do not export to next AS (well-known community)\n")
8501
8502ALIAS (show_bgp_community,
8503 show_bgp_community3_cmd,
8504 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8505 SHOW_STR
8506 BGP_STR
8507 "Display routes matching the communities\n"
8508 "community number\n"
8509 "Do not send outside local AS (well-known community)\n"
8510 "Do not advertise to any peer (well-known community)\n"
8511 "Do not export to next AS (well-known community)\n"
8512 "community number\n"
8513 "Do not send outside local AS (well-known community)\n"
8514 "Do not advertise to any peer (well-known community)\n"
8515 "Do not export to next AS (well-known community)\n"
8516 "community number\n"
8517 "Do not send outside local AS (well-known community)\n"
8518 "Do not advertise to any peer (well-known community)\n"
8519 "Do not export to next AS (well-known community)\n")
8520
8521ALIAS (show_bgp_community,
8522 show_bgp_ipv6_community3_cmd,
8523 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8524 SHOW_STR
8525 BGP_STR
8526 "Address family\n"
8527 "Display routes matching the communities\n"
8528 "community number\n"
8529 "Do not send outside local AS (well-known community)\n"
8530 "Do not advertise to any peer (well-known community)\n"
8531 "Do not export to next AS (well-known community)\n"
8532 "community number\n"
8533 "Do not send outside local AS (well-known community)\n"
8534 "Do not advertise to any peer (well-known community)\n"
8535 "Do not export to next AS (well-known community)\n"
8536 "community number\n"
8537 "Do not send outside local AS (well-known community)\n"
8538 "Do not advertise to any peer (well-known community)\n"
8539 "Do not export to next AS (well-known community)\n")
8540
8541ALIAS (show_bgp_community,
8542 show_bgp_community4_cmd,
8543 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8544 SHOW_STR
8545 BGP_STR
8546 "Display routes matching the communities\n"
8547 "community number\n"
8548 "Do not send outside local AS (well-known community)\n"
8549 "Do not advertise to any peer (well-known community)\n"
8550 "Do not export to next AS (well-known community)\n"
8551 "community number\n"
8552 "Do not send outside local AS (well-known community)\n"
8553 "Do not advertise to any peer (well-known community)\n"
8554 "Do not export to next AS (well-known community)\n"
8555 "community number\n"
8556 "Do not send outside local AS (well-known community)\n"
8557 "Do not advertise to any peer (well-known community)\n"
8558 "Do not export to next AS (well-known community)\n"
8559 "community number\n"
8560 "Do not send outside local AS (well-known community)\n"
8561 "Do not advertise to any peer (well-known community)\n"
8562 "Do not export to next AS (well-known community)\n")
8563
8564ALIAS (show_bgp_community,
8565 show_bgp_ipv6_community4_cmd,
8566 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8567 SHOW_STR
8568 BGP_STR
8569 "Address family\n"
8570 "Display routes matching the communities\n"
8571 "community number\n"
8572 "Do not send outside local AS (well-known community)\n"
8573 "Do not advertise to any peer (well-known community)\n"
8574 "Do not export to next AS (well-known community)\n"
8575 "community number\n"
8576 "Do not send outside local AS (well-known community)\n"
8577 "Do not advertise to any peer (well-known community)\n"
8578 "Do not export to next AS (well-known community)\n"
8579 "community number\n"
8580 "Do not send outside local AS (well-known community)\n"
8581 "Do not advertise to any peer (well-known community)\n"
8582 "Do not export to next AS (well-known community)\n"
8583 "community number\n"
8584 "Do not send outside local AS (well-known community)\n"
8585 "Do not advertise to any peer (well-known community)\n"
8586 "Do not export to next AS (well-known community)\n")
8587
8588/* old command */
8589DEFUN (show_ipv6_bgp_community,
8590 show_ipv6_bgp_community_cmd,
8591 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8592 SHOW_STR
8593 IPV6_STR
8594 BGP_STR
8595 "Display routes matching the communities\n"
8596 "community number\n"
8597 "Do not send outside local AS (well-known community)\n"
8598 "Do not advertise to any peer (well-known community)\n"
8599 "Do not export to next AS (well-known community)\n")
8600{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008601 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008602}
8603
8604/* old command */
8605ALIAS (show_ipv6_bgp_community,
8606 show_ipv6_bgp_community2_cmd,
8607 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8608 SHOW_STR
8609 IPV6_STR
8610 BGP_STR
8611 "Display routes matching the communities\n"
8612 "community number\n"
8613 "Do not send outside local AS (well-known community)\n"
8614 "Do not advertise to any peer (well-known community)\n"
8615 "Do not export to next AS (well-known community)\n"
8616 "community number\n"
8617 "Do not send outside local AS (well-known community)\n"
8618 "Do not advertise to any peer (well-known community)\n"
8619 "Do not export to next AS (well-known community)\n")
8620
8621/* old command */
8622ALIAS (show_ipv6_bgp_community,
8623 show_ipv6_bgp_community3_cmd,
8624 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8625 SHOW_STR
8626 IPV6_STR
8627 BGP_STR
8628 "Display routes matching the communities\n"
8629 "community number\n"
8630 "Do not send outside local AS (well-known community)\n"
8631 "Do not advertise to any peer (well-known community)\n"
8632 "Do not export to next AS (well-known community)\n"
8633 "community number\n"
8634 "Do not send outside local AS (well-known community)\n"
8635 "Do not advertise to any peer (well-known community)\n"
8636 "Do not export to next AS (well-known community)\n"
8637 "community number\n"
8638 "Do not send outside local AS (well-known community)\n"
8639 "Do not advertise to any peer (well-known community)\n"
8640 "Do not export to next AS (well-known community)\n")
8641
8642/* old command */
8643ALIAS (show_ipv6_bgp_community,
8644 show_ipv6_bgp_community4_cmd,
8645 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8646 SHOW_STR
8647 IPV6_STR
8648 BGP_STR
8649 "Display routes matching the communities\n"
8650 "community number\n"
8651 "Do not send outside local AS (well-known community)\n"
8652 "Do not advertise to any peer (well-known community)\n"
8653 "Do not export to next AS (well-known community)\n"
8654 "community number\n"
8655 "Do not send outside local AS (well-known community)\n"
8656 "Do not advertise to any peer (well-known community)\n"
8657 "Do not export to next AS (well-known community)\n"
8658 "community number\n"
8659 "Do not send outside local AS (well-known community)\n"
8660 "Do not advertise to any peer (well-known community)\n"
8661 "Do not export to next AS (well-known community)\n"
8662 "community number\n"
8663 "Do not send outside local AS (well-known community)\n"
8664 "Do not advertise to any peer (well-known community)\n"
8665 "Do not export to next AS (well-known community)\n")
8666
8667DEFUN (show_bgp_community_exact,
8668 show_bgp_community_exact_cmd,
8669 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8670 SHOW_STR
8671 BGP_STR
8672 "Display routes matching the communities\n"
8673 "community number\n"
8674 "Do not send outside local AS (well-known community)\n"
8675 "Do not advertise to any peer (well-known community)\n"
8676 "Do not export to next AS (well-known community)\n"
8677 "Exact match of the communities")
8678{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008679 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008680}
8681
8682ALIAS (show_bgp_community_exact,
8683 show_bgp_ipv6_community_exact_cmd,
8684 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8685 SHOW_STR
8686 BGP_STR
8687 "Address family\n"
8688 "Display routes matching the communities\n"
8689 "community number\n"
8690 "Do not send outside local AS (well-known community)\n"
8691 "Do not advertise to any peer (well-known community)\n"
8692 "Do not export to next AS (well-known community)\n"
8693 "Exact match of the communities")
8694
8695ALIAS (show_bgp_community_exact,
8696 show_bgp_community2_exact_cmd,
8697 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8698 SHOW_STR
8699 BGP_STR
8700 "Display routes matching the communities\n"
8701 "community number\n"
8702 "Do not send outside local AS (well-known community)\n"
8703 "Do not advertise to any peer (well-known community)\n"
8704 "Do not export to next AS (well-known community)\n"
8705 "community number\n"
8706 "Do not send outside local AS (well-known community)\n"
8707 "Do not advertise to any peer (well-known community)\n"
8708 "Do not export to next AS (well-known community)\n"
8709 "Exact match of the communities")
8710
8711ALIAS (show_bgp_community_exact,
8712 show_bgp_ipv6_community2_exact_cmd,
8713 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8714 SHOW_STR
8715 BGP_STR
8716 "Address family\n"
8717 "Display routes matching the communities\n"
8718 "community number\n"
8719 "Do not send outside local AS (well-known community)\n"
8720 "Do not advertise to any peer (well-known community)\n"
8721 "Do not export to next AS (well-known community)\n"
8722 "community number\n"
8723 "Do not send outside local AS (well-known community)\n"
8724 "Do not advertise to any peer (well-known community)\n"
8725 "Do not export to next AS (well-known community)\n"
8726 "Exact match of the communities")
8727
8728ALIAS (show_bgp_community_exact,
8729 show_bgp_community3_exact_cmd,
8730 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8731 SHOW_STR
8732 BGP_STR
8733 "Display routes matching the communities\n"
8734 "community number\n"
8735 "Do not send outside local AS (well-known community)\n"
8736 "Do not advertise to any peer (well-known community)\n"
8737 "Do not export to next AS (well-known community)\n"
8738 "community number\n"
8739 "Do not send outside local AS (well-known community)\n"
8740 "Do not advertise to any peer (well-known community)\n"
8741 "Do not export to next AS (well-known community)\n"
8742 "community number\n"
8743 "Do not send outside local AS (well-known community)\n"
8744 "Do not advertise to any peer (well-known community)\n"
8745 "Do not export to next AS (well-known community)\n"
8746 "Exact match of the communities")
8747
8748ALIAS (show_bgp_community_exact,
8749 show_bgp_ipv6_community3_exact_cmd,
8750 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8751 SHOW_STR
8752 BGP_STR
8753 "Address family\n"
8754 "Display routes matching the communities\n"
8755 "community number\n"
8756 "Do not send outside local AS (well-known community)\n"
8757 "Do not advertise to any peer (well-known community)\n"
8758 "Do not export to next AS (well-known community)\n"
8759 "community number\n"
8760 "Do not send outside local AS (well-known community)\n"
8761 "Do not advertise to any peer (well-known community)\n"
8762 "Do not export to next AS (well-known community)\n"
8763 "community number\n"
8764 "Do not send outside local AS (well-known community)\n"
8765 "Do not advertise to any peer (well-known community)\n"
8766 "Do not export to next AS (well-known community)\n"
8767 "Exact match of the communities")
8768
8769ALIAS (show_bgp_community_exact,
8770 show_bgp_community4_exact_cmd,
8771 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8772 SHOW_STR
8773 BGP_STR
8774 "Display routes matching the communities\n"
8775 "community number\n"
8776 "Do not send outside local AS (well-known community)\n"
8777 "Do not advertise to any peer (well-known community)\n"
8778 "Do not export to next AS (well-known community)\n"
8779 "community number\n"
8780 "Do not send outside local AS (well-known community)\n"
8781 "Do not advertise to any peer (well-known community)\n"
8782 "Do not export to next AS (well-known community)\n"
8783 "community number\n"
8784 "Do not send outside local AS (well-known community)\n"
8785 "Do not advertise to any peer (well-known community)\n"
8786 "Do not export to next AS (well-known community)\n"
8787 "community number\n"
8788 "Do not send outside local AS (well-known community)\n"
8789 "Do not advertise to any peer (well-known community)\n"
8790 "Do not export to next AS (well-known community)\n"
8791 "Exact match of the communities")
8792
8793ALIAS (show_bgp_community_exact,
8794 show_bgp_ipv6_community4_exact_cmd,
8795 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8796 SHOW_STR
8797 BGP_STR
8798 "Address family\n"
8799 "Display routes matching the communities\n"
8800 "community number\n"
8801 "Do not send outside local AS (well-known community)\n"
8802 "Do not advertise to any peer (well-known community)\n"
8803 "Do not export to next AS (well-known community)\n"
8804 "community number\n"
8805 "Do not send outside local AS (well-known community)\n"
8806 "Do not advertise to any peer (well-known community)\n"
8807 "Do not export to next AS (well-known community)\n"
8808 "community number\n"
8809 "Do not send outside local AS (well-known community)\n"
8810 "Do not advertise to any peer (well-known community)\n"
8811 "Do not export to next AS (well-known community)\n"
8812 "community number\n"
8813 "Do not send outside local AS (well-known community)\n"
8814 "Do not advertise to any peer (well-known community)\n"
8815 "Do not export to next AS (well-known community)\n"
8816 "Exact match of the communities")
8817
8818/* old command */
8819DEFUN (show_ipv6_bgp_community_exact,
8820 show_ipv6_bgp_community_exact_cmd,
8821 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8822 SHOW_STR
8823 IPV6_STR
8824 BGP_STR
8825 "Display routes matching the communities\n"
8826 "community number\n"
8827 "Do not send outside local AS (well-known community)\n"
8828 "Do not advertise to any peer (well-known community)\n"
8829 "Do not export to next AS (well-known community)\n"
8830 "Exact match of the communities")
8831{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008832 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008833}
8834
8835/* old command */
8836ALIAS (show_ipv6_bgp_community_exact,
8837 show_ipv6_bgp_community2_exact_cmd,
8838 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8839 SHOW_STR
8840 IPV6_STR
8841 BGP_STR
8842 "Display routes matching the communities\n"
8843 "community number\n"
8844 "Do not send outside local AS (well-known community)\n"
8845 "Do not advertise to any peer (well-known community)\n"
8846 "Do not export to next AS (well-known community)\n"
8847 "community number\n"
8848 "Do not send outside local AS (well-known community)\n"
8849 "Do not advertise to any peer (well-known community)\n"
8850 "Do not export to next AS (well-known community)\n"
8851 "Exact match of the communities")
8852
8853/* old command */
8854ALIAS (show_ipv6_bgp_community_exact,
8855 show_ipv6_bgp_community3_exact_cmd,
8856 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8857 SHOW_STR
8858 IPV6_STR
8859 BGP_STR
8860 "Display routes matching the communities\n"
8861 "community number\n"
8862 "Do not send outside local AS (well-known community)\n"
8863 "Do not advertise to any peer (well-known community)\n"
8864 "Do not export to next AS (well-known community)\n"
8865 "community number\n"
8866 "Do not send outside local AS (well-known community)\n"
8867 "Do not advertise to any peer (well-known community)\n"
8868 "Do not export to next AS (well-known community)\n"
8869 "community number\n"
8870 "Do not send outside local AS (well-known community)\n"
8871 "Do not advertise to any peer (well-known community)\n"
8872 "Do not export to next AS (well-known community)\n"
8873 "Exact match of the communities")
8874
8875/* old command */
8876ALIAS (show_ipv6_bgp_community_exact,
8877 show_ipv6_bgp_community4_exact_cmd,
8878 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8879 SHOW_STR
8880 IPV6_STR
8881 BGP_STR
8882 "Display routes matching the communities\n"
8883 "community number\n"
8884 "Do not send outside local AS (well-known community)\n"
8885 "Do not advertise to any peer (well-known community)\n"
8886 "Do not export to next AS (well-known community)\n"
8887 "community number\n"
8888 "Do not send outside local AS (well-known community)\n"
8889 "Do not advertise to any peer (well-known community)\n"
8890 "Do not export to next AS (well-known community)\n"
8891 "community number\n"
8892 "Do not send outside local AS (well-known community)\n"
8893 "Do not advertise to any peer (well-known community)\n"
8894 "Do not export to next AS (well-known community)\n"
8895 "community number\n"
8896 "Do not send outside local AS (well-known community)\n"
8897 "Do not advertise to any peer (well-known community)\n"
8898 "Do not export to next AS (well-known community)\n"
8899 "Exact match of the communities")
8900
8901/* old command */
8902DEFUN (show_ipv6_mbgp_community,
8903 show_ipv6_mbgp_community_cmd,
8904 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8905 SHOW_STR
8906 IPV6_STR
8907 MBGP_STR
8908 "Display routes matching the communities\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{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008914 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008915}
8916
8917/* old command */
8918ALIAS (show_ipv6_mbgp_community,
8919 show_ipv6_mbgp_community2_cmd,
8920 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8921 SHOW_STR
8922 IPV6_STR
8923 MBGP_STR
8924 "Display routes matching the communities\n"
8925 "community number\n"
8926 "Do not send outside local AS (well-known community)\n"
8927 "Do not advertise to any peer (well-known community)\n"
8928 "Do not export to next AS (well-known community)\n"
8929 "community number\n"
8930 "Do not send outside local AS (well-known community)\n"
8931 "Do not advertise to any peer (well-known community)\n"
8932 "Do not export to next AS (well-known community)\n")
8933
8934/* old command */
8935ALIAS (show_ipv6_mbgp_community,
8936 show_ipv6_mbgp_community3_cmd,
8937 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8938 SHOW_STR
8939 IPV6_STR
8940 MBGP_STR
8941 "Display routes matching the communities\n"
8942 "community number\n"
8943 "Do not send outside local AS (well-known community)\n"
8944 "Do not advertise to any peer (well-known community)\n"
8945 "Do not export to next AS (well-known community)\n"
8946 "community number\n"
8947 "Do not send outside local AS (well-known community)\n"
8948 "Do not advertise to any peer (well-known community)\n"
8949 "Do not export to next AS (well-known community)\n"
8950 "community number\n"
8951 "Do not send outside local AS (well-known community)\n"
8952 "Do not advertise to any peer (well-known community)\n"
8953 "Do not export to next AS (well-known community)\n")
8954
8955/* old command */
8956ALIAS (show_ipv6_mbgp_community,
8957 show_ipv6_mbgp_community4_cmd,
8958 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8959 SHOW_STR
8960 IPV6_STR
8961 MBGP_STR
8962 "Display routes matching the communities\n"
8963 "community number\n"
8964 "Do not send outside local AS (well-known community)\n"
8965 "Do not advertise to any peer (well-known community)\n"
8966 "Do not export to next AS (well-known community)\n"
8967 "community number\n"
8968 "Do not send outside local AS (well-known community)\n"
8969 "Do not advertise to any peer (well-known community)\n"
8970 "Do not export to next AS (well-known community)\n"
8971 "community number\n"
8972 "Do not send outside local AS (well-known community)\n"
8973 "Do not advertise to any peer (well-known community)\n"
8974 "Do not export to next AS (well-known community)\n"
8975 "community number\n"
8976 "Do not send outside local AS (well-known community)\n"
8977 "Do not advertise to any peer (well-known community)\n"
8978 "Do not export to next AS (well-known community)\n")
8979
8980/* old command */
8981DEFUN (show_ipv6_mbgp_community_exact,
8982 show_ipv6_mbgp_community_exact_cmd,
8983 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8984 SHOW_STR
8985 IPV6_STR
8986 MBGP_STR
8987 "Display routes matching the communities\n"
8988 "community number\n"
8989 "Do not send outside local AS (well-known community)\n"
8990 "Do not advertise to any peer (well-known community)\n"
8991 "Do not export to next AS (well-known community)\n"
8992 "Exact match of the communities")
8993{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008994 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008995}
8996
8997/* old command */
8998ALIAS (show_ipv6_mbgp_community_exact,
8999 show_ipv6_mbgp_community2_exact_cmd,
9000 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9001 SHOW_STR
9002 IPV6_STR
9003 MBGP_STR
9004 "Display routes matching the communities\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 "Exact match of the communities")
9014
9015/* old command */
9016ALIAS (show_ipv6_mbgp_community_exact,
9017 show_ipv6_mbgp_community3_exact_cmd,
9018 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9019 SHOW_STR
9020 IPV6_STR
9021 MBGP_STR
9022 "Display routes matching the communities\n"
9023 "community number\n"
9024 "Do not send outside local AS (well-known community)\n"
9025 "Do not advertise to any peer (well-known community)\n"
9026 "Do not export to next AS (well-known community)\n"
9027 "community number\n"
9028 "Do not send outside local AS (well-known community)\n"
9029 "Do not advertise to any peer (well-known community)\n"
9030 "Do not export to next AS (well-known community)\n"
9031 "community number\n"
9032 "Do not send outside local AS (well-known community)\n"
9033 "Do not advertise to any peer (well-known community)\n"
9034 "Do not export to next AS (well-known community)\n"
9035 "Exact match of the communities")
9036
9037/* old command */
9038ALIAS (show_ipv6_mbgp_community_exact,
9039 show_ipv6_mbgp_community4_exact_cmd,
9040 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9041 SHOW_STR
9042 IPV6_STR
9043 MBGP_STR
9044 "Display routes matching the communities\n"
9045 "community number\n"
9046 "Do not send outside local AS (well-known community)\n"
9047 "Do not advertise to any peer (well-known community)\n"
9048 "Do not export to next AS (well-known community)\n"
9049 "community number\n"
9050 "Do not send outside local AS (well-known community)\n"
9051 "Do not advertise to any peer (well-known community)\n"
9052 "Do not export to next AS (well-known community)\n"
9053 "community number\n"
9054 "Do not send outside local AS (well-known community)\n"
9055 "Do not advertise to any peer (well-known community)\n"
9056 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
9062#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009063
paul94f2b392005-06-28 12:44:16 +00009064static int
paulfd79ac92004-10-13 05:06:08 +00009065bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04009066 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00009067{
9068 struct community_list *list;
9069
hassofee6e4e2005-02-02 16:29:31 +00009070 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00009071 if (list == NULL)
9072 {
9073 vty_out (vty, "%% %s is not a valid community-list name%s", com,
9074 VTY_NEWLINE);
9075 return CMD_WARNING;
9076 }
9077
ajs5a646652004-11-05 01:25:55 +00009078 return bgp_show (vty, NULL, afi, safi,
9079 (exact ? bgp_show_type_community_list_exact :
9080 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00009081}
9082
9083DEFUN (show_ip_bgp_community_list,
9084 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009085 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009086 SHOW_STR
9087 IP_STR
9088 BGP_STR
9089 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009090 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009091 "community-list name\n")
9092{
9093 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
9094}
9095
9096DEFUN (show_ip_bgp_ipv4_community_list,
9097 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009098 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009099 SHOW_STR
9100 IP_STR
9101 BGP_STR
9102 "Address family\n"
9103 "Address Family modifier\n"
9104 "Address Family modifier\n"
9105 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009106 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009107 "community-list name\n")
9108{
9109 if (strncmp (argv[0], "m", 1) == 0)
9110 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
9111
9112 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
9113}
9114
9115DEFUN (show_ip_bgp_community_list_exact,
9116 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009117 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009118 SHOW_STR
9119 IP_STR
9120 BGP_STR
9121 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009122 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009123 "community-list name\n"
9124 "Exact match of the communities\n")
9125{
9126 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
9127}
9128
9129DEFUN (show_ip_bgp_ipv4_community_list_exact,
9130 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009131 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009132 SHOW_STR
9133 IP_STR
9134 BGP_STR
9135 "Address family\n"
9136 "Address Family modifier\n"
9137 "Address Family modifier\n"
9138 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009139 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009140 "community-list name\n"
9141 "Exact match of the communities\n")
9142{
9143 if (strncmp (argv[0], "m", 1) == 0)
9144 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
9145
9146 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
9147}
9148
9149#ifdef HAVE_IPV6
9150DEFUN (show_bgp_community_list,
9151 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009152 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009153 SHOW_STR
9154 BGP_STR
9155 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009156 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009157 "community-list name\n")
9158{
9159 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9160}
9161
9162ALIAS (show_bgp_community_list,
9163 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009164 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009165 SHOW_STR
9166 BGP_STR
9167 "Address family\n"
9168 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009169 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00009170 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00009171
9172/* old command */
9173DEFUN (show_ipv6_bgp_community_list,
9174 show_ipv6_bgp_community_list_cmd,
9175 "show ipv6 bgp community-list WORD",
9176 SHOW_STR
9177 IPV6_STR
9178 BGP_STR
9179 "Display routes matching the community-list\n"
9180 "community-list name\n")
9181{
9182 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9183}
9184
9185/* old command */
9186DEFUN (show_ipv6_mbgp_community_list,
9187 show_ipv6_mbgp_community_list_cmd,
9188 "show ipv6 mbgp community-list WORD",
9189 SHOW_STR
9190 IPV6_STR
9191 MBGP_STR
9192 "Display routes matching the community-list\n"
9193 "community-list name\n")
9194{
9195 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
9196}
9197
9198DEFUN (show_bgp_community_list_exact,
9199 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009200 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009201 SHOW_STR
9202 BGP_STR
9203 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009204 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009205 "community-list name\n"
9206 "Exact match of the communities\n")
9207{
9208 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9209}
9210
9211ALIAS (show_bgp_community_list_exact,
9212 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009213 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009214 SHOW_STR
9215 BGP_STR
9216 "Address family\n"
9217 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009218 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009219 "community-list name\n"
9220 "Exact match of the communities\n")
9221
9222/* old command */
9223DEFUN (show_ipv6_bgp_community_list_exact,
9224 show_ipv6_bgp_community_list_exact_cmd,
9225 "show ipv6 bgp community-list WORD exact-match",
9226 SHOW_STR
9227 IPV6_STR
9228 BGP_STR
9229 "Display routes matching the community-list\n"
9230 "community-list name\n"
9231 "Exact match of the communities\n")
9232{
9233 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9234}
9235
9236/* old command */
9237DEFUN (show_ipv6_mbgp_community_list_exact,
9238 show_ipv6_mbgp_community_list_exact_cmd,
9239 "show ipv6 mbgp community-list WORD exact-match",
9240 SHOW_STR
9241 IPV6_STR
9242 MBGP_STR
9243 "Display routes matching the community-list\n"
9244 "community-list name\n"
9245 "Exact match of the communities\n")
9246{
9247 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9248}
9249#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009250
paul94f2b392005-06-28 12:44:16 +00009251static int
paulfd79ac92004-10-13 05:06:08 +00009252bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009253 safi_t safi, enum bgp_show_type type)
9254{
9255 int ret;
9256 struct prefix *p;
9257
9258 p = prefix_new();
9259
9260 ret = str2prefix (prefix, p);
9261 if (! ret)
9262 {
9263 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9264 return CMD_WARNING;
9265 }
9266
ajs5a646652004-11-05 01:25:55 +00009267 ret = bgp_show (vty, NULL, afi, safi, type, p);
9268 prefix_free(p);
9269 return ret;
paul718e3742002-12-13 20:15:29 +00009270}
9271
9272DEFUN (show_ip_bgp_prefix_longer,
9273 show_ip_bgp_prefix_longer_cmd,
9274 "show ip bgp A.B.C.D/M longer-prefixes",
9275 SHOW_STR
9276 IP_STR
9277 BGP_STR
9278 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9279 "Display route and more specific routes\n")
9280{
9281 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9282 bgp_show_type_prefix_longer);
9283}
9284
9285DEFUN (show_ip_bgp_flap_prefix_longer,
9286 show_ip_bgp_flap_prefix_longer_cmd,
9287 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9288 SHOW_STR
9289 IP_STR
9290 BGP_STR
9291 "Display flap statistics of routes\n"
9292 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9293 "Display route and more specific routes\n")
9294{
9295 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9296 bgp_show_type_flap_prefix_longer);
9297}
9298
Balaji3921cc52015-05-16 23:12:17 +05309299ALIAS (show_ip_bgp_flap_prefix_longer,
9300 show_ip_bgp_damp_flap_prefix_longer_cmd,
9301 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
9302 SHOW_STR
9303 IP_STR
9304 BGP_STR
9305 "Display detailed information about dampening\n"
9306 "Display flap statistics of routes\n"
9307 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9308 "Display route and more specific routes\n")
9309
paul718e3742002-12-13 20:15:29 +00009310DEFUN (show_ip_bgp_ipv4_prefix_longer,
9311 show_ip_bgp_ipv4_prefix_longer_cmd,
9312 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9313 SHOW_STR
9314 IP_STR
9315 BGP_STR
9316 "Address family\n"
9317 "Address Family modifier\n"
9318 "Address Family modifier\n"
9319 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9320 "Display route and more specific routes\n")
9321{
9322 if (strncmp (argv[0], "m", 1) == 0)
9323 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9324 bgp_show_type_prefix_longer);
9325
9326 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9327 bgp_show_type_prefix_longer);
9328}
9329
9330DEFUN (show_ip_bgp_flap_address,
9331 show_ip_bgp_flap_address_cmd,
9332 "show ip bgp flap-statistics A.B.C.D",
9333 SHOW_STR
9334 IP_STR
9335 BGP_STR
9336 "Display flap statistics of routes\n"
9337 "Network in the BGP routing table to display\n")
9338{
9339 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9340 bgp_show_type_flap_address);
9341}
9342
Balaji3921cc52015-05-16 23:12:17 +05309343ALIAS (show_ip_bgp_flap_address,
9344 show_ip_bgp_damp_flap_address_cmd,
9345 "show ip bgp dampening flap-statistics A.B.C.D",
9346 SHOW_STR
9347 IP_STR
9348 BGP_STR
9349 "Display detailed information about dampening\n"
9350 "Display flap statistics of routes\n"
9351 "Network in the BGP routing table to display\n")
9352
paul718e3742002-12-13 20:15:29 +00009353DEFUN (show_ip_bgp_flap_prefix,
9354 show_ip_bgp_flap_prefix_cmd,
9355 "show ip bgp flap-statistics A.B.C.D/M",
9356 SHOW_STR
9357 IP_STR
9358 BGP_STR
9359 "Display flap statistics of routes\n"
9360 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9361{
9362 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9363 bgp_show_type_flap_prefix);
9364}
Balaji3921cc52015-05-16 23:12:17 +05309365
9366ALIAS (show_ip_bgp_flap_prefix,
9367 show_ip_bgp_damp_flap_prefix_cmd,
9368 "show ip bgp dampening flap-statistics A.B.C.D/M",
9369 SHOW_STR
9370 IP_STR
9371 BGP_STR
9372 "Display detailed information about dampening\n"
9373 "Display flap statistics of routes\n"
9374 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9375
paul718e3742002-12-13 20:15:29 +00009376#ifdef HAVE_IPV6
9377DEFUN (show_bgp_prefix_longer,
9378 show_bgp_prefix_longer_cmd,
9379 "show bgp X:X::X:X/M longer-prefixes",
9380 SHOW_STR
9381 BGP_STR
9382 "IPv6 prefix <network>/<length>\n"
9383 "Display route and more specific routes\n")
9384{
9385 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9386 bgp_show_type_prefix_longer);
9387}
9388
9389ALIAS (show_bgp_prefix_longer,
9390 show_bgp_ipv6_prefix_longer_cmd,
9391 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9392 SHOW_STR
9393 BGP_STR
9394 "Address family\n"
9395 "IPv6 prefix <network>/<length>\n"
9396 "Display route and more specific routes\n")
9397
9398/* old command */
9399DEFUN (show_ipv6_bgp_prefix_longer,
9400 show_ipv6_bgp_prefix_longer_cmd,
9401 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9402 SHOW_STR
9403 IPV6_STR
9404 BGP_STR
9405 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9406 "Display route and more specific routes\n")
9407{
9408 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9409 bgp_show_type_prefix_longer);
9410}
9411
9412/* old command */
9413DEFUN (show_ipv6_mbgp_prefix_longer,
9414 show_ipv6_mbgp_prefix_longer_cmd,
9415 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9416 SHOW_STR
9417 IPV6_STR
9418 MBGP_STR
9419 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9420 "Display route and more specific routes\n")
9421{
9422 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9423 bgp_show_type_prefix_longer);
9424}
9425#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009426
paul94f2b392005-06-28 12:44:16 +00009427static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009428peer_lookup_in_view (struct vty *vty, const char *view_name,
9429 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009430{
9431 int ret;
9432 struct bgp *bgp;
9433 struct peer *peer;
9434 union sockunion su;
9435
9436 /* BGP structure lookup. */
9437 if (view_name)
9438 {
9439 bgp = bgp_lookup_by_name (view_name);
9440 if (! bgp)
9441 {
9442 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9443 return NULL;
9444 }
9445 }
paul5228ad22004-06-04 17:58:18 +00009446 else
paulbb46e942003-10-24 19:02:03 +00009447 {
9448 bgp = bgp_get_default ();
9449 if (! bgp)
9450 {
9451 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9452 return NULL;
9453 }
9454 }
9455
9456 /* Get peer sockunion. */
9457 ret = str2sockunion (ip_str, &su);
9458 if (ret < 0)
9459 {
9460 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9461 return NULL;
9462 }
9463
9464 /* Peer structure lookup. */
9465 peer = peer_lookup (bgp, &su);
9466 if (! peer)
9467 {
9468 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9469 return NULL;
9470 }
9471
9472 return peer;
9473}
David Lamparter6b0655a2014-06-04 06:53:35 +02009474
Paul Jakma2815e612006-09-14 02:56:07 +00009475enum bgp_stats
9476{
9477 BGP_STATS_MAXBITLEN = 0,
9478 BGP_STATS_RIB,
9479 BGP_STATS_PREFIXES,
9480 BGP_STATS_TOTPLEN,
9481 BGP_STATS_UNAGGREGATEABLE,
9482 BGP_STATS_MAX_AGGREGATEABLE,
9483 BGP_STATS_AGGREGATES,
9484 BGP_STATS_SPACE,
9485 BGP_STATS_ASPATH_COUNT,
9486 BGP_STATS_ASPATH_MAXHOPS,
9487 BGP_STATS_ASPATH_TOTHOPS,
9488 BGP_STATS_ASPATH_MAXSIZE,
9489 BGP_STATS_ASPATH_TOTSIZE,
9490 BGP_STATS_ASN_HIGHEST,
9491 BGP_STATS_MAX,
9492};
paulbb46e942003-10-24 19:02:03 +00009493
Paul Jakma2815e612006-09-14 02:56:07 +00009494static const char *table_stats_strs[] =
9495{
9496 [BGP_STATS_PREFIXES] = "Total Prefixes",
9497 [BGP_STATS_TOTPLEN] = "Average prefix length",
9498 [BGP_STATS_RIB] = "Total Advertisements",
9499 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9500 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9501 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9502 [BGP_STATS_SPACE] = "Address space advertised",
9503 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9504 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9505 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9506 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9507 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9508 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9509 [BGP_STATS_MAX] = NULL,
9510};
9511
9512struct bgp_table_stats
9513{
9514 struct bgp_table *table;
9515 unsigned long long counts[BGP_STATS_MAX];
9516};
9517
9518#if 0
9519#define TALLY_SIGFIG 100000
9520static unsigned long
9521ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9522{
9523 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9524 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9525 unsigned long ret = newtot / count;
9526
9527 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9528 return ret + 1;
9529 else
9530 return ret;
9531}
9532#endif
9533
9534static int
9535bgp_table_stats_walker (struct thread *t)
9536{
9537 struct bgp_node *rn;
9538 struct bgp_node *top;
9539 struct bgp_table_stats *ts = THREAD_ARG (t);
9540 unsigned int space = 0;
9541
Paul Jakma53d9f672006-10-15 23:41:16 +00009542 if (!(top = bgp_table_top (ts->table)))
9543 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009544
9545 switch (top->p.family)
9546 {
9547 case AF_INET:
9548 space = IPV4_MAX_BITLEN;
9549 break;
9550 case AF_INET6:
9551 space = IPV6_MAX_BITLEN;
9552 break;
9553 }
9554
9555 ts->counts[BGP_STATS_MAXBITLEN] = space;
9556
9557 for (rn = top; rn; rn = bgp_route_next (rn))
9558 {
9559 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009560 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009561 unsigned int rinum = 0;
9562
9563 if (rn == top)
9564 continue;
9565
9566 if (!rn->info)
9567 continue;
9568
9569 ts->counts[BGP_STATS_PREFIXES]++;
9570 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9571
9572#if 0
9573 ts->counts[BGP_STATS_AVGPLEN]
9574 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9575 ts->counts[BGP_STATS_AVGPLEN],
9576 rn->p.prefixlen);
9577#endif
9578
9579 /* check if the prefix is included by any other announcements */
9580 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009581 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009582
9583 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009584 {
9585 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9586 /* announced address space */
9587 if (space)
9588 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9589 }
Paul Jakma2815e612006-09-14 02:56:07 +00009590 else if (prn->info)
9591 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9592
Paul Jakma2815e612006-09-14 02:56:07 +00009593 for (ri = rn->info; ri; ri = ri->next)
9594 {
9595 rinum++;
9596 ts->counts[BGP_STATS_RIB]++;
9597
9598 if (ri->attr &&
9599 (CHECK_FLAG (ri->attr->flag,
9600 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9601 ts->counts[BGP_STATS_AGGREGATES]++;
9602
9603 /* as-path stats */
9604 if (ri->attr && ri->attr->aspath)
9605 {
9606 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9607 unsigned int size = aspath_size (ri->attr->aspath);
9608 as_t highest = aspath_highest (ri->attr->aspath);
9609
9610 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9611
9612 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9613 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9614
9615 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9616 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9617
9618 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9619 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9620#if 0
9621 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9622 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9623 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9624 hops);
9625 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9626 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9627 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9628 size);
9629#endif
9630 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9631 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9632 }
9633 }
9634 }
9635 return 0;
9636}
9637
9638static int
9639bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9640{
9641 struct bgp_table_stats ts;
9642 unsigned int i;
9643
9644 if (!bgp->rib[afi][safi])
9645 {
9646 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9647 return CMD_WARNING;
9648 }
9649
9650 memset (&ts, 0, sizeof (ts));
9651 ts.table = bgp->rib[afi][safi];
9652 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9653
9654 vty_out (vty, "BGP %s RIB statistics%s%s",
9655 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9656
9657 for (i = 0; i < BGP_STATS_MAX; i++)
9658 {
9659 if (!table_stats_strs[i])
9660 continue;
9661
9662 switch (i)
9663 {
9664#if 0
9665 case BGP_STATS_ASPATH_AVGHOPS:
9666 case BGP_STATS_ASPATH_AVGSIZE:
9667 case BGP_STATS_AVGPLEN:
9668 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9669 vty_out (vty, "%12.2f",
9670 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9671 break;
9672#endif
9673 case BGP_STATS_ASPATH_TOTHOPS:
9674 case BGP_STATS_ASPATH_TOTSIZE:
9675 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9676 vty_out (vty, "%12.2f",
9677 ts.counts[i] ?
9678 (float)ts.counts[i] /
9679 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9680 : 0);
9681 break;
9682 case BGP_STATS_TOTPLEN:
9683 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9684 vty_out (vty, "%12.2f",
9685 ts.counts[i] ?
9686 (float)ts.counts[i] /
9687 (float)ts.counts[BGP_STATS_PREFIXES]
9688 : 0);
9689 break;
9690 case BGP_STATS_SPACE:
9691 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9692 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9693 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9694 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009695 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009696 vty_out (vty, "%12.2f%s",
9697 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009698 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009699 VTY_NEWLINE);
9700 vty_out (vty, "%30s: ", "/8 equivalent ");
9701 vty_out (vty, "%12.2f%s",
9702 (float)ts.counts[BGP_STATS_SPACE] /
9703 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9704 VTY_NEWLINE);
9705 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9706 break;
9707 vty_out (vty, "%30s: ", "/24 equivalent ");
9708 vty_out (vty, "%12.2f",
9709 (float)ts.counts[BGP_STATS_SPACE] /
9710 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9711 break;
9712 default:
9713 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9714 vty_out (vty, "%12llu", ts.counts[i]);
9715 }
9716
9717 vty_out (vty, "%s", VTY_NEWLINE);
9718 }
9719 return CMD_SUCCESS;
9720}
9721
9722static int
9723bgp_table_stats_vty (struct vty *vty, const char *name,
9724 const char *afi_str, const char *safi_str)
9725{
9726 struct bgp *bgp;
9727 afi_t afi;
9728 safi_t safi;
9729
9730 if (name)
9731 bgp = bgp_lookup_by_name (name);
9732 else
9733 bgp = bgp_get_default ();
9734
9735 if (!bgp)
9736 {
9737 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9738 return CMD_WARNING;
9739 }
9740 if (strncmp (afi_str, "ipv", 3) == 0)
9741 {
9742 if (strncmp (afi_str, "ipv4", 4) == 0)
9743 afi = AFI_IP;
9744 else if (strncmp (afi_str, "ipv6", 4) == 0)
9745 afi = AFI_IP6;
9746 else
9747 {
9748 vty_out (vty, "%% Invalid address family %s%s",
9749 afi_str, VTY_NEWLINE);
9750 return CMD_WARNING;
9751 }
9752 if (strncmp (safi_str, "m", 1) == 0)
9753 safi = SAFI_MULTICAST;
9754 else if (strncmp (safi_str, "u", 1) == 0)
9755 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009756 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9757 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009758 else
9759 {
9760 vty_out (vty, "%% Invalid subsequent address family %s%s",
9761 safi_str, VTY_NEWLINE);
9762 return CMD_WARNING;
9763 }
9764 }
9765 else
9766 {
9767 vty_out (vty, "%% Invalid address family %s%s",
9768 afi_str, VTY_NEWLINE);
9769 return CMD_WARNING;
9770 }
9771
Paul Jakma2815e612006-09-14 02:56:07 +00009772 return bgp_table_stats (vty, bgp, afi, safi);
9773}
9774
9775DEFUN (show_bgp_statistics,
9776 show_bgp_statistics_cmd,
9777 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9778 SHOW_STR
9779 BGP_STR
9780 "Address family\n"
9781 "Address family\n"
9782 "Address Family modifier\n"
9783 "Address Family modifier\n"
9784 "BGP RIB advertisement statistics\n")
9785{
9786 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9787}
9788
9789ALIAS (show_bgp_statistics,
9790 show_bgp_statistics_vpnv4_cmd,
9791 "show bgp (ipv4) (vpnv4) statistics",
9792 SHOW_STR
9793 BGP_STR
9794 "Address family\n"
9795 "Address Family modifier\n"
9796 "BGP RIB advertisement statistics\n")
9797
9798DEFUN (show_bgp_statistics_view,
9799 show_bgp_statistics_view_cmd,
9800 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9801 SHOW_STR
9802 BGP_STR
9803 "BGP view\n"
9804 "Address family\n"
9805 "Address family\n"
9806 "Address Family modifier\n"
9807 "Address Family modifier\n"
9808 "BGP RIB advertisement statistics\n")
9809{
9810 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9811}
9812
9813ALIAS (show_bgp_statistics_view,
9814 show_bgp_statistics_view_vpnv4_cmd,
9815 "show bgp view WORD (ipv4) (vpnv4) statistics",
9816 SHOW_STR
9817 BGP_STR
9818 "BGP view\n"
9819 "Address family\n"
9820 "Address Family modifier\n"
9821 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02009822
Paul Jakmaff7924f2006-09-04 01:10:36 +00009823enum bgp_pcounts
9824{
9825 PCOUNT_ADJ_IN = 0,
9826 PCOUNT_DAMPED,
9827 PCOUNT_REMOVED,
9828 PCOUNT_HISTORY,
9829 PCOUNT_STALE,
9830 PCOUNT_VALID,
9831 PCOUNT_ALL,
9832 PCOUNT_COUNTED,
9833 PCOUNT_PFCNT, /* the figure we display to users */
9834 PCOUNT_MAX,
9835};
9836
9837static const char *pcount_strs[] =
9838{
9839 [PCOUNT_ADJ_IN] = "Adj-in",
9840 [PCOUNT_DAMPED] = "Damped",
9841 [PCOUNT_REMOVED] = "Removed",
9842 [PCOUNT_HISTORY] = "History",
9843 [PCOUNT_STALE] = "Stale",
9844 [PCOUNT_VALID] = "Valid",
9845 [PCOUNT_ALL] = "All RIB",
9846 [PCOUNT_COUNTED] = "PfxCt counted",
9847 [PCOUNT_PFCNT] = "Useable",
9848 [PCOUNT_MAX] = NULL,
9849};
9850
Paul Jakma2815e612006-09-14 02:56:07 +00009851struct peer_pcounts
9852{
9853 unsigned int count[PCOUNT_MAX];
9854 const struct peer *peer;
9855 const struct bgp_table *table;
9856};
9857
Paul Jakmaff7924f2006-09-04 01:10:36 +00009858static int
Paul Jakma2815e612006-09-14 02:56:07 +00009859bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009860{
9861 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009862 struct peer_pcounts *pc = THREAD_ARG (t);
9863 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009864
Paul Jakma2815e612006-09-14 02:56:07 +00009865 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009866 {
9867 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009868 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009869
9870 for (ain = rn->adj_in; ain; ain = ain->next)
9871 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009872 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009873
Paul Jakmaff7924f2006-09-04 01:10:36 +00009874 for (ri = rn->info; ri; ri = ri->next)
9875 {
9876 char buf[SU_ADDRSTRLEN];
9877
9878 if (ri->peer != peer)
9879 continue;
9880
Paul Jakma2815e612006-09-14 02:56:07 +00009881 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009882
9883 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009884 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009885 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009886 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009887 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009888 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009889 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009890 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009891 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009892 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009893 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009894 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009895
9896 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9897 {
Paul Jakma2815e612006-09-14 02:56:07 +00009898 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009899 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009900 plog_warn (peer->log,
9901 "%s [pcount] %s/%d is counted but flags 0x%x",
9902 peer->host,
9903 inet_ntop(rn->p.family, &rn->p.u.prefix,
9904 buf, SU_ADDRSTRLEN),
9905 rn->p.prefixlen,
9906 ri->flags);
9907 }
9908 else
9909 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009910 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009911 plog_warn (peer->log,
9912 "%s [pcount] %s/%d not counted but flags 0x%x",
9913 peer->host,
9914 inet_ntop(rn->p.family, &rn->p.u.prefix,
9915 buf, SU_ADDRSTRLEN),
9916 rn->p.prefixlen,
9917 ri->flags);
9918 }
9919 }
9920 }
Paul Jakma2815e612006-09-14 02:56:07 +00009921 return 0;
9922}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009923
Paul Jakma2815e612006-09-14 02:56:07 +00009924static int
9925bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9926{
9927 struct peer_pcounts pcounts = { .peer = peer };
9928 unsigned int i;
9929
9930 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9931 || !peer->bgp->rib[afi][safi])
9932 {
9933 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9934 return CMD_WARNING;
9935 }
9936
9937 memset (&pcounts, 0, sizeof(pcounts));
9938 pcounts.peer = peer;
9939 pcounts.table = peer->bgp->rib[afi][safi];
9940
9941 /* in-place call via thread subsystem so as to record execution time
9942 * stats for the thread-walk (i.e. ensure this can't be blamed on
9943 * on just vty_read()).
9944 */
9945 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9946
Paul Jakmaff7924f2006-09-04 01:10:36 +00009947 vty_out (vty, "Prefix counts for %s, %s%s",
9948 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9949 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9950 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9951 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9952
9953 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009954 vty_out (vty, "%20s: %-10d%s",
9955 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009956
Paul Jakma2815e612006-09-14 02:56:07 +00009957 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009958 {
9959 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9960 peer->host, VTY_NEWLINE);
9961 vty_out (vty, "Please report this bug, with the above command output%s",
9962 VTY_NEWLINE);
9963 }
9964
9965 return CMD_SUCCESS;
9966}
9967
9968DEFUN (show_ip_bgp_neighbor_prefix_counts,
9969 show_ip_bgp_neighbor_prefix_counts_cmd,
9970 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9971 SHOW_STR
9972 IP_STR
9973 BGP_STR
9974 "Detailed information on TCP and BGP neighbor connections\n"
9975 "Neighbor to display information about\n"
9976 "Neighbor to display information about\n"
9977 "Display detailed prefix count information\n")
9978{
9979 struct peer *peer;
9980
9981 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9982 if (! peer)
9983 return CMD_WARNING;
9984
9985 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9986}
9987
9988DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9989 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9990 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9991 SHOW_STR
9992 BGP_STR
9993 "Address family\n"
9994 "Detailed information on TCP and BGP neighbor connections\n"
9995 "Neighbor to display information about\n"
9996 "Neighbor to display information about\n"
9997 "Display detailed prefix count information\n")
9998{
9999 struct peer *peer;
10000
10001 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10002 if (! peer)
10003 return CMD_WARNING;
10004
10005 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
10006}
10007
10008DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
10009 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
10010 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
10011 SHOW_STR
10012 IP_STR
10013 BGP_STR
10014 "Address family\n"
10015 "Address Family modifier\n"
10016 "Address Family modifier\n"
10017 "Detailed information on TCP and BGP neighbor connections\n"
10018 "Neighbor to display information about\n"
10019 "Neighbor to display information about\n"
10020 "Display detailed prefix count information\n")
10021{
10022 struct peer *peer;
10023
10024 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10025 if (! peer)
10026 return CMD_WARNING;
10027
10028 if (strncmp (argv[0], "m", 1) == 0)
10029 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
10030
10031 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
10032}
10033
10034DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
10035 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
10036 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
10037 SHOW_STR
10038 IP_STR
10039 BGP_STR
10040 "Address family\n"
10041 "Address Family modifier\n"
10042 "Address Family modifier\n"
10043 "Detailed information on TCP and BGP neighbor connections\n"
10044 "Neighbor to display information about\n"
10045 "Neighbor to display information about\n"
10046 "Display detailed prefix count information\n")
10047{
10048 struct peer *peer;
10049
10050 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10051 if (! peer)
10052 return CMD_WARNING;
10053
10054 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
10055}
10056
10057
paul94f2b392005-06-28 12:44:16 +000010058static void
paul718e3742002-12-13 20:15:29 +000010059show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
10060 int in)
10061{
10062 struct bgp_table *table;
10063 struct bgp_adj_in *ain;
10064 struct bgp_adj_out *adj;
10065 unsigned long output_count;
10066 struct bgp_node *rn;
10067 int header1 = 1;
10068 struct bgp *bgp;
10069 int header2 = 1;
10070
paulbb46e942003-10-24 19:02:03 +000010071 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +000010072
10073 if (! bgp)
10074 return;
10075
10076 table = bgp->rib[afi][safi];
10077
10078 output_count = 0;
10079
10080 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
10081 PEER_STATUS_DEFAULT_ORIGINATE))
10082 {
10083 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 +000010084 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10085 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010086
10087 vty_out (vty, "Originating default network 0.0.0.0%s%s",
10088 VTY_NEWLINE, VTY_NEWLINE);
10089 header1 = 0;
10090 }
10091
10092 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
10093 if (in)
10094 {
10095 for (ain = rn->adj_in; ain; ain = ain->next)
10096 if (ain->peer == peer)
10097 {
10098 if (header1)
10099 {
10100 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 +000010101 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10102 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010103 header1 = 0;
10104 }
10105 if (header2)
10106 {
10107 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
10108 header2 = 0;
10109 }
10110 if (ain->attr)
10111 {
10112 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
10113 output_count++;
10114 }
10115 }
10116 }
10117 else
10118 {
10119 for (adj = rn->adj_out; adj; adj = adj->next)
10120 if (adj->peer == peer)
10121 {
10122 if (header1)
10123 {
10124 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 +000010125 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10126 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010127 header1 = 0;
10128 }
10129 if (header2)
10130 {
10131 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
10132 header2 = 0;
10133 }
10134 if (adj->attr)
10135 {
10136 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
10137 output_count++;
10138 }
10139 }
10140 }
10141
10142 if (output_count != 0)
10143 vty_out (vty, "%sTotal number of prefixes %ld%s",
10144 VTY_NEWLINE, output_count, VTY_NEWLINE);
10145}
10146
paul94f2b392005-06-28 12:44:16 +000010147static int
paulbb46e942003-10-24 19:02:03 +000010148peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
10149{
paul718e3742002-12-13 20:15:29 +000010150 if (! peer || ! peer->afc[afi][safi])
10151 {
10152 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10153 return CMD_WARNING;
10154 }
10155
10156 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10157 {
10158 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
10159 VTY_NEWLINE);
10160 return CMD_WARNING;
10161 }
10162
10163 show_adj_route (vty, peer, afi, safi, in);
10164
10165 return CMD_SUCCESS;
10166}
10167
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010168DEFUN (show_ip_bgp_view_neighbor_advertised_route,
10169 show_ip_bgp_view_neighbor_advertised_route_cmd,
10170 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10171 SHOW_STR
10172 IP_STR
10173 BGP_STR
10174 "BGP view\n"
10175 "View name\n"
10176 "Detailed information on TCP and BGP neighbor connections\n"
10177 "Neighbor to display information about\n"
10178 "Neighbor to display information about\n"
10179 "Display the routes advertised to a BGP neighbor\n")
10180{
10181 struct peer *peer;
10182
10183 if (argc == 2)
10184 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10185 else
10186 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10187
10188 if (! peer)
10189 return CMD_WARNING;
10190
10191 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
10192}
10193
10194ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010195 show_ip_bgp_neighbor_advertised_route_cmd,
10196 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10197 SHOW_STR
10198 IP_STR
10199 BGP_STR
10200 "Detailed information on TCP and BGP neighbor connections\n"
10201 "Neighbor to display information about\n"
10202 "Neighbor to display information about\n"
10203 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +000010204
10205DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
10206 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
10207 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10208 SHOW_STR
10209 IP_STR
10210 BGP_STR
10211 "Address family\n"
10212 "Address Family modifier\n"
10213 "Address Family modifier\n"
10214 "Detailed information on TCP and BGP neighbor connections\n"
10215 "Neighbor to display information about\n"
10216 "Neighbor to display information about\n"
10217 "Display the routes advertised to a BGP neighbor\n")
10218{
paulbb46e942003-10-24 19:02:03 +000010219 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010220
paulbb46e942003-10-24 19:02:03 +000010221 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10222 if (! peer)
10223 return CMD_WARNING;
10224
10225 if (strncmp (argv[0], "m", 1) == 0)
10226 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
10227
10228 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +000010229}
10230
10231#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010232DEFUN (show_bgp_view_neighbor_advertised_route,
10233 show_bgp_view_neighbor_advertised_route_cmd,
10234 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10235 SHOW_STR
10236 BGP_STR
10237 "BGP view\n"
10238 "View name\n"
10239 "Detailed information on TCP and BGP neighbor connections\n"
10240 "Neighbor to display information about\n"
10241 "Neighbor to display information about\n"
10242 "Display the routes advertised to a BGP neighbor\n")
10243{
10244 struct peer *peer;
10245
10246 if (argc == 2)
10247 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10248 else
10249 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10250
10251 if (! peer)
10252 return CMD_WARNING;
10253
10254 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10255}
10256
10257ALIAS (show_bgp_view_neighbor_advertised_route,
10258 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10259 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10260 SHOW_STR
10261 BGP_STR
10262 "BGP view\n"
10263 "View name\n"
10264 "Address family\n"
10265 "Detailed information on TCP and BGP neighbor connections\n"
10266 "Neighbor to display information about\n"
10267 "Neighbor to display information about\n"
10268 "Display the routes advertised to a BGP neighbor\n")
10269
10270DEFUN (show_bgp_view_neighbor_received_routes,
10271 show_bgp_view_neighbor_received_routes_cmd,
10272 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10273 SHOW_STR
10274 BGP_STR
10275 "BGP view\n"
10276 "View name\n"
10277 "Detailed information on TCP and BGP neighbor connections\n"
10278 "Neighbor to display information about\n"
10279 "Neighbor to display information about\n"
10280 "Display the received routes from neighbor\n")
10281{
10282 struct peer *peer;
10283
10284 if (argc == 2)
10285 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10286 else
10287 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10288
10289 if (! peer)
10290 return CMD_WARNING;
10291
10292 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10293}
10294
10295ALIAS (show_bgp_view_neighbor_received_routes,
10296 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10297 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10298 SHOW_STR
10299 BGP_STR
10300 "BGP view\n"
10301 "View name\n"
10302 "Address family\n"
10303 "Detailed information on TCP and BGP neighbor connections\n"
10304 "Neighbor to display information about\n"
10305 "Neighbor to display information about\n"
10306 "Display the received routes from neighbor\n")
10307
10308ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010309 show_bgp_neighbor_advertised_route_cmd,
10310 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10311 SHOW_STR
10312 BGP_STR
10313 "Detailed information on TCP and BGP neighbor connections\n"
10314 "Neighbor to display information about\n"
10315 "Neighbor to display information about\n"
10316 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010317
10318ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010319 show_bgp_ipv6_neighbor_advertised_route_cmd,
10320 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10321 SHOW_STR
10322 BGP_STR
10323 "Address family\n"
10324 "Detailed information on TCP and BGP neighbor connections\n"
10325 "Neighbor to display information about\n"
10326 "Neighbor to display information about\n"
10327 "Display the routes advertised to a BGP neighbor\n")
10328
10329/* old command */
paulbb46e942003-10-24 19:02:03 +000010330ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010331 ipv6_bgp_neighbor_advertised_route_cmd,
10332 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10333 SHOW_STR
10334 IPV6_STR
10335 BGP_STR
10336 "Detailed information on TCP and BGP neighbor connections\n"
10337 "Neighbor to display information about\n"
10338 "Neighbor to display information about\n"
10339 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010340
paul718e3742002-12-13 20:15:29 +000010341/* old command */
10342DEFUN (ipv6_mbgp_neighbor_advertised_route,
10343 ipv6_mbgp_neighbor_advertised_route_cmd,
10344 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10345 SHOW_STR
10346 IPV6_STR
10347 MBGP_STR
10348 "Detailed information on TCP and BGP neighbor connections\n"
10349 "Neighbor to display information about\n"
10350 "Neighbor to display information about\n"
10351 "Display the routes advertised to a BGP neighbor\n")
10352{
paulbb46e942003-10-24 19:02:03 +000010353 struct peer *peer;
10354
10355 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10356 if (! peer)
10357 return CMD_WARNING;
10358
10359 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010360}
10361#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010362
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010363DEFUN (show_ip_bgp_view_neighbor_received_routes,
10364 show_ip_bgp_view_neighbor_received_routes_cmd,
10365 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10366 SHOW_STR
10367 IP_STR
10368 BGP_STR
10369 "BGP view\n"
10370 "View name\n"
10371 "Detailed information on TCP and BGP neighbor connections\n"
10372 "Neighbor to display information about\n"
10373 "Neighbor to display information about\n"
10374 "Display the received routes from neighbor\n")
10375{
10376 struct peer *peer;
10377
10378 if (argc == 2)
10379 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10380 else
10381 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10382
10383 if (! peer)
10384 return CMD_WARNING;
10385
10386 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10387}
10388
10389ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010390 show_ip_bgp_neighbor_received_routes_cmd,
10391 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10392 SHOW_STR
10393 IP_STR
10394 BGP_STR
10395 "Detailed information on TCP and BGP neighbor connections\n"
10396 "Neighbor to display information about\n"
10397 "Neighbor to display information about\n"
10398 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010399
10400DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10401 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10402 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10403 SHOW_STR
10404 IP_STR
10405 BGP_STR
10406 "Address family\n"
10407 "Address Family modifier\n"
10408 "Address Family modifier\n"
10409 "Detailed information on TCP and BGP neighbor connections\n"
10410 "Neighbor to display information about\n"
10411 "Neighbor to display information about\n"
10412 "Display the received routes from neighbor\n")
10413{
paulbb46e942003-10-24 19:02:03 +000010414 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010415
paulbb46e942003-10-24 19:02:03 +000010416 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10417 if (! peer)
10418 return CMD_WARNING;
10419
10420 if (strncmp (argv[0], "m", 1) == 0)
10421 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10422
10423 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010424}
10425
Michael Lambert95cbbd22010-07-23 14:43:04 -040010426DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10427 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010428 "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 -040010429 SHOW_STR
10430 BGP_STR
10431 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010432 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010433 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010434 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010435 "Address family modifier\n"
10436 "Address family modifier\n"
10437 "Detailed information on TCP and BGP neighbor connections\n"
10438 "Neighbor to display information about\n"
10439 "Neighbor to display information about\n"
10440 "Display the advertised routes to neighbor\n"
10441 "Display the received routes from neighbor\n")
10442{
10443 int afi;
10444 int safi;
10445 int in;
10446 struct peer *peer;
10447
David Lamparter94bad672015-03-03 08:52:22 +010010448 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010449
10450 if (! peer)
10451 return CMD_WARNING;
10452
Michael Lambert95cbbd22010-07-23 14:43:04 -040010453 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10454 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10455 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010456
10457 return peer_adj_routes (vty, peer, afi, safi, in);
10458}
10459
paul718e3742002-12-13 20:15:29 +000010460DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10461 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10462 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10463 SHOW_STR
10464 IP_STR
10465 BGP_STR
10466 "Detailed information on TCP and BGP neighbor connections\n"
10467 "Neighbor to display information about\n"
10468 "Neighbor to display information about\n"
10469 "Display information received from a BGP neighbor\n"
10470 "Display the prefixlist filter\n")
10471{
10472 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010473 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010474 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010475 int count, ret;
paul718e3742002-12-13 20:15:29 +000010476
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010477 ret = str2sockunion (argv[0], &su);
10478 if (ret < 0)
10479 {
10480 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10481 return CMD_WARNING;
10482 }
paul718e3742002-12-13 20:15:29 +000010483
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010484 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010485 if (! peer)
10486 return CMD_WARNING;
10487
10488 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10489 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10490 if (count)
10491 {
10492 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10493 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10494 }
10495
10496 return CMD_SUCCESS;
10497}
10498
10499DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10500 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10501 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10502 SHOW_STR
10503 IP_STR
10504 BGP_STR
10505 "Address family\n"
10506 "Address Family modifier\n"
10507 "Address Family modifier\n"
10508 "Detailed information on TCP and BGP neighbor connections\n"
10509 "Neighbor to display information about\n"
10510 "Neighbor to display information about\n"
10511 "Display information received from a BGP neighbor\n"
10512 "Display the prefixlist filter\n")
10513{
10514 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010515 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010516 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010517 int count, ret;
paul718e3742002-12-13 20:15:29 +000010518
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010519 ret = str2sockunion (argv[1], &su);
10520 if (ret < 0)
10521 {
10522 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10523 return CMD_WARNING;
10524 }
paul718e3742002-12-13 20:15:29 +000010525
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010526 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010527 if (! peer)
10528 return CMD_WARNING;
10529
10530 if (strncmp (argv[0], "m", 1) == 0)
10531 {
10532 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10533 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10534 if (count)
10535 {
10536 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10537 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10538 }
10539 }
10540 else
10541 {
10542 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10543 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10544 if (count)
10545 {
10546 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10547 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10548 }
10549 }
10550
10551 return CMD_SUCCESS;
10552}
10553
10554
10555#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010556ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010557 show_bgp_neighbor_received_routes_cmd,
10558 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10559 SHOW_STR
10560 BGP_STR
10561 "Detailed information on TCP and BGP neighbor connections\n"
10562 "Neighbor to display information about\n"
10563 "Neighbor to display information about\n"
10564 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010565
paulbb46e942003-10-24 19:02:03 +000010566ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010567 show_bgp_ipv6_neighbor_received_routes_cmd,
10568 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10569 SHOW_STR
10570 BGP_STR
10571 "Address family\n"
10572 "Detailed information on TCP and BGP neighbor connections\n"
10573 "Neighbor to display information about\n"
10574 "Neighbor to display information about\n"
10575 "Display the received routes from neighbor\n")
10576
10577DEFUN (show_bgp_neighbor_received_prefix_filter,
10578 show_bgp_neighbor_received_prefix_filter_cmd,
10579 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10580 SHOW_STR
10581 BGP_STR
10582 "Detailed information on TCP and BGP neighbor connections\n"
10583 "Neighbor to display information about\n"
10584 "Neighbor to display information about\n"
10585 "Display information received from a BGP neighbor\n"
10586 "Display the prefixlist filter\n")
10587{
10588 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010589 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010590 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010591 int count, ret;
paul718e3742002-12-13 20:15:29 +000010592
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010593 ret = str2sockunion (argv[0], &su);
10594 if (ret < 0)
10595 {
10596 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10597 return CMD_WARNING;
10598 }
paul718e3742002-12-13 20:15:29 +000010599
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010600 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010601 if (! peer)
10602 return CMD_WARNING;
10603
10604 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10605 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10606 if (count)
10607 {
10608 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10609 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10610 }
10611
10612 return CMD_SUCCESS;
10613}
10614
10615ALIAS (show_bgp_neighbor_received_prefix_filter,
10616 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10617 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10618 SHOW_STR
10619 BGP_STR
10620 "Address family\n"
10621 "Detailed information on TCP and BGP neighbor connections\n"
10622 "Neighbor to display information about\n"
10623 "Neighbor to display information about\n"
10624 "Display information received from a BGP neighbor\n"
10625 "Display the prefixlist filter\n")
10626
10627/* old command */
paulbb46e942003-10-24 19:02:03 +000010628ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010629 ipv6_bgp_neighbor_received_routes_cmd,
10630 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10631 SHOW_STR
10632 IPV6_STR
10633 BGP_STR
10634 "Detailed information on TCP and BGP neighbor connections\n"
10635 "Neighbor to display information about\n"
10636 "Neighbor to display information about\n"
10637 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010638
10639/* old command */
10640DEFUN (ipv6_mbgp_neighbor_received_routes,
10641 ipv6_mbgp_neighbor_received_routes_cmd,
10642 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10643 SHOW_STR
10644 IPV6_STR
10645 MBGP_STR
10646 "Detailed information on TCP and BGP neighbor connections\n"
10647 "Neighbor to display information about\n"
10648 "Neighbor to display information about\n"
10649 "Display the received routes from neighbor\n")
10650{
paulbb46e942003-10-24 19:02:03 +000010651 struct peer *peer;
10652
10653 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10654 if (! peer)
10655 return CMD_WARNING;
10656
10657 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010658}
paulbb46e942003-10-24 19:02:03 +000010659
10660DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10661 show_bgp_view_neighbor_received_prefix_filter_cmd,
10662 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10663 SHOW_STR
10664 BGP_STR
10665 "BGP view\n"
10666 "View name\n"
10667 "Detailed information on TCP and BGP neighbor connections\n"
10668 "Neighbor to display information about\n"
10669 "Neighbor to display information about\n"
10670 "Display information received from a BGP neighbor\n"
10671 "Display the prefixlist filter\n")
10672{
10673 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010674 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010675 struct peer *peer;
10676 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010677 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010678
10679 /* BGP structure lookup. */
10680 bgp = bgp_lookup_by_name (argv[0]);
10681 if (bgp == NULL)
10682 {
10683 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10684 return CMD_WARNING;
10685 }
10686
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010687 ret = str2sockunion (argv[1], &su);
10688 if (ret < 0)
10689 {
10690 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10691 return CMD_WARNING;
10692 }
paulbb46e942003-10-24 19:02:03 +000010693
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010694 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010695 if (! peer)
10696 return CMD_WARNING;
10697
10698 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10699 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10700 if (count)
10701 {
10702 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10703 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10704 }
10705
10706 return CMD_SUCCESS;
10707}
10708
10709ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10710 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10711 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10712 SHOW_STR
10713 BGP_STR
10714 "BGP view\n"
10715 "View name\n"
10716 "Address family\n"
10717 "Detailed information on TCP and BGP neighbor connections\n"
10718 "Neighbor to display information about\n"
10719 "Neighbor to display information about\n"
10720 "Display information received from a BGP neighbor\n"
10721 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010722#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010723
paul94f2b392005-06-28 12:44:16 +000010724static int
paulbb46e942003-10-24 19:02:03 +000010725bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010726 safi_t safi, enum bgp_show_type type)
10727{
paul718e3742002-12-13 20:15:29 +000010728 if (! peer || ! peer->afc[afi][safi])
10729 {
10730 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010731 return CMD_WARNING;
10732 }
10733
ajs5a646652004-11-05 01:25:55 +000010734 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010735}
10736
10737DEFUN (show_ip_bgp_neighbor_routes,
10738 show_ip_bgp_neighbor_routes_cmd,
10739 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10740 SHOW_STR
10741 IP_STR
10742 BGP_STR
10743 "Detailed information on TCP and BGP neighbor connections\n"
10744 "Neighbor to display information about\n"
10745 "Neighbor to display information about\n"
10746 "Display routes learned from neighbor\n")
10747{
paulbb46e942003-10-24 19:02:03 +000010748 struct peer *peer;
10749
10750 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10751 if (! peer)
10752 return CMD_WARNING;
10753
10754 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010755 bgp_show_type_neighbor);
10756}
10757
10758DEFUN (show_ip_bgp_neighbor_flap,
10759 show_ip_bgp_neighbor_flap_cmd,
10760 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10761 SHOW_STR
10762 IP_STR
10763 BGP_STR
10764 "Detailed information on TCP and BGP neighbor connections\n"
10765 "Neighbor to display information about\n"
10766 "Neighbor to display information about\n"
10767 "Display flap statistics of the routes learned from neighbor\n")
10768{
paulbb46e942003-10-24 19:02:03 +000010769 struct peer *peer;
10770
10771 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10772 if (! peer)
10773 return CMD_WARNING;
10774
10775 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010776 bgp_show_type_flap_neighbor);
10777}
10778
10779DEFUN (show_ip_bgp_neighbor_damp,
10780 show_ip_bgp_neighbor_damp_cmd,
10781 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10782 SHOW_STR
10783 IP_STR
10784 BGP_STR
10785 "Detailed information on TCP and BGP neighbor connections\n"
10786 "Neighbor to display information about\n"
10787 "Neighbor to display information about\n"
10788 "Display the dampened routes received from neighbor\n")
10789{
paulbb46e942003-10-24 19:02:03 +000010790 struct peer *peer;
10791
10792 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10793 if (! peer)
10794 return CMD_WARNING;
10795
10796 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010797 bgp_show_type_damp_neighbor);
10798}
10799
10800DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10801 show_ip_bgp_ipv4_neighbor_routes_cmd,
10802 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10803 SHOW_STR
10804 IP_STR
10805 BGP_STR
10806 "Address family\n"
10807 "Address Family modifier\n"
10808 "Address Family modifier\n"
10809 "Detailed information on TCP and BGP neighbor connections\n"
10810 "Neighbor to display information about\n"
10811 "Neighbor to display information about\n"
10812 "Display routes learned from neighbor\n")
10813{
paulbb46e942003-10-24 19:02:03 +000010814 struct peer *peer;
10815
10816 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10817 if (! peer)
10818 return CMD_WARNING;
10819
paul718e3742002-12-13 20:15:29 +000010820 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010821 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010822 bgp_show_type_neighbor);
10823
paulbb46e942003-10-24 19:02:03 +000010824 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010825 bgp_show_type_neighbor);
10826}
paulbb46e942003-10-24 19:02:03 +000010827
paulfee0f4c2004-09-13 05:12:46 +000010828DEFUN (show_ip_bgp_view_rsclient,
10829 show_ip_bgp_view_rsclient_cmd,
10830 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10831 SHOW_STR
10832 IP_STR
10833 BGP_STR
10834 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010835 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010836 "Information about Route Server Client\n"
10837 NEIGHBOR_ADDR_STR)
10838{
10839 struct bgp_table *table;
10840 struct peer *peer;
10841
10842 if (argc == 2)
10843 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10844 else
10845 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10846
10847 if (! peer)
10848 return CMD_WARNING;
10849
10850 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10851 {
10852 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10853 VTY_NEWLINE);
10854 return CMD_WARNING;
10855 }
10856
10857 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10858 PEER_FLAG_RSERVER_CLIENT))
10859 {
10860 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10861 VTY_NEWLINE);
10862 return CMD_WARNING;
10863 }
10864
10865 table = peer->rib[AFI_IP][SAFI_UNICAST];
10866
ajs5a646652004-11-05 01:25:55 +000010867 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010868}
10869
10870ALIAS (show_ip_bgp_view_rsclient,
10871 show_ip_bgp_rsclient_cmd,
10872 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10873 SHOW_STR
10874 IP_STR
10875 BGP_STR
10876 "Information about Route Server Client\n"
10877 NEIGHBOR_ADDR_STR)
10878
Michael Lambert95cbbd22010-07-23 14:43:04 -040010879DEFUN (show_bgp_view_ipv4_safi_rsclient,
10880 show_bgp_view_ipv4_safi_rsclient_cmd,
10881 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10882 SHOW_STR
10883 BGP_STR
10884 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010885 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010886 "Address family\n"
10887 "Address Family modifier\n"
10888 "Address Family modifier\n"
10889 "Information about Route Server Client\n"
10890 NEIGHBOR_ADDR_STR)
10891{
10892 struct bgp_table *table;
10893 struct peer *peer;
10894 safi_t safi;
10895
10896 if (argc == 3) {
10897 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10898 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10899 } else {
10900 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10901 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10902 }
10903
10904 if (! peer)
10905 return CMD_WARNING;
10906
10907 if (! peer->afc[AFI_IP][safi])
10908 {
10909 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10910 VTY_NEWLINE);
10911 return CMD_WARNING;
10912 }
10913
10914 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10915 PEER_FLAG_RSERVER_CLIENT))
10916 {
10917 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10918 VTY_NEWLINE);
10919 return CMD_WARNING;
10920 }
10921
10922 table = peer->rib[AFI_IP][safi];
10923
10924 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10925}
10926
10927ALIAS (show_bgp_view_ipv4_safi_rsclient,
10928 show_bgp_ipv4_safi_rsclient_cmd,
10929 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10930 SHOW_STR
10931 BGP_STR
10932 "Address family\n"
10933 "Address Family modifier\n"
10934 "Address Family modifier\n"
10935 "Information about Route Server Client\n"
10936 NEIGHBOR_ADDR_STR)
10937
paulfee0f4c2004-09-13 05:12:46 +000010938DEFUN (show_ip_bgp_view_rsclient_route,
10939 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010940 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010941 SHOW_STR
10942 IP_STR
10943 BGP_STR
10944 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010945 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010946 "Information about Route Server Client\n"
10947 NEIGHBOR_ADDR_STR
10948 "Network in the BGP routing table to display\n")
10949{
10950 struct bgp *bgp;
10951 struct peer *peer;
10952
10953 /* BGP structure lookup. */
10954 if (argc == 3)
10955 {
10956 bgp = bgp_lookup_by_name (argv[0]);
10957 if (bgp == NULL)
10958 {
10959 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10960 return CMD_WARNING;
10961 }
10962 }
10963 else
10964 {
10965 bgp = bgp_get_default ();
10966 if (bgp == NULL)
10967 {
10968 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10969 return CMD_WARNING;
10970 }
10971 }
10972
10973 if (argc == 3)
10974 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10975 else
10976 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10977
10978 if (! peer)
10979 return CMD_WARNING;
10980
10981 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10982 {
10983 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10984 VTY_NEWLINE);
10985 return CMD_WARNING;
10986}
10987
10988 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10989 PEER_FLAG_RSERVER_CLIENT))
10990 {
10991 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10992 VTY_NEWLINE);
10993 return CMD_WARNING;
10994 }
10995
10996 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10997 (argc == 3) ? argv[2] : argv[1],
10998 AFI_IP, SAFI_UNICAST, NULL, 0);
10999}
11000
11001ALIAS (show_ip_bgp_view_rsclient_route,
11002 show_ip_bgp_rsclient_route_cmd,
11003 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
11004 SHOW_STR
11005 IP_STR
11006 BGP_STR
11007 "Information about Route Server Client\n"
11008 NEIGHBOR_ADDR_STR
11009 "Network in the BGP routing table to display\n")
11010
Michael Lambert95cbbd22010-07-23 14:43:04 -040011011DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
11012 show_bgp_view_ipv4_safi_rsclient_route_cmd,
11013 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
11014 SHOW_STR
11015 BGP_STR
11016 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011017 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011018 "Address family\n"
11019 "Address Family modifier\n"
11020 "Address Family modifier\n"
11021 "Information about Route Server Client\n"
11022 NEIGHBOR_ADDR_STR
11023 "Network in the BGP routing table to display\n")
11024{
11025 struct bgp *bgp;
11026 struct peer *peer;
11027 safi_t safi;
11028
11029 /* BGP structure lookup. */
11030 if (argc == 4)
11031 {
11032 bgp = bgp_lookup_by_name (argv[0]);
11033 if (bgp == NULL)
11034 {
11035 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11036 return CMD_WARNING;
11037 }
11038 }
11039 else
11040 {
11041 bgp = bgp_get_default ();
11042 if (bgp == NULL)
11043 {
11044 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11045 return CMD_WARNING;
11046 }
11047 }
11048
11049 if (argc == 4) {
11050 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11051 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11052 } else {
11053 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11054 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11055 }
11056
11057 if (! peer)
11058 return CMD_WARNING;
11059
11060 if (! peer->afc[AFI_IP][safi])
11061 {
11062 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11063 VTY_NEWLINE);
11064 return CMD_WARNING;
11065}
11066
11067 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11068 PEER_FLAG_RSERVER_CLIENT))
11069 {
11070 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11071 VTY_NEWLINE);
11072 return CMD_WARNING;
11073 }
11074
11075 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11076 (argc == 4) ? argv[3] : argv[2],
11077 AFI_IP, safi, NULL, 0);
11078}
11079
11080ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
11081 show_bgp_ipv4_safi_rsclient_route_cmd,
11082 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
11083 SHOW_STR
11084 BGP_STR
11085 "Address family\n"
11086 "Address Family modifier\n"
11087 "Address Family modifier\n"
11088 "Information about Route Server Client\n"
11089 NEIGHBOR_ADDR_STR
11090 "Network in the BGP routing table to display\n")
11091
paulfee0f4c2004-09-13 05:12:46 +000011092DEFUN (show_ip_bgp_view_rsclient_prefix,
11093 show_ip_bgp_view_rsclient_prefix_cmd,
11094 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11095 SHOW_STR
11096 IP_STR
11097 BGP_STR
11098 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011099 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011100 "Information about Route Server Client\n"
11101 NEIGHBOR_ADDR_STR
11102 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11103{
11104 struct bgp *bgp;
11105 struct peer *peer;
11106
11107 /* BGP structure lookup. */
11108 if (argc == 3)
11109 {
11110 bgp = bgp_lookup_by_name (argv[0]);
11111 if (bgp == NULL)
11112 {
11113 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11114 return CMD_WARNING;
11115 }
11116 }
11117 else
11118 {
11119 bgp = bgp_get_default ();
11120 if (bgp == NULL)
11121 {
11122 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11123 return CMD_WARNING;
11124 }
11125 }
11126
11127 if (argc == 3)
11128 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11129 else
11130 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11131
11132 if (! peer)
11133 return CMD_WARNING;
11134
11135 if (! peer->afc[AFI_IP][SAFI_UNICAST])
11136 {
11137 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11138 VTY_NEWLINE);
11139 return CMD_WARNING;
11140}
11141
11142 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
11143 PEER_FLAG_RSERVER_CLIENT))
11144{
11145 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11146 VTY_NEWLINE);
11147 return CMD_WARNING;
11148 }
11149
11150 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
11151 (argc == 3) ? argv[2] : argv[1],
11152 AFI_IP, SAFI_UNICAST, NULL, 1);
11153}
11154
11155ALIAS (show_ip_bgp_view_rsclient_prefix,
11156 show_ip_bgp_rsclient_prefix_cmd,
11157 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11158 SHOW_STR
11159 IP_STR
11160 BGP_STR
11161 "Information about Route Server Client\n"
11162 NEIGHBOR_ADDR_STR
11163 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11164
Michael Lambert95cbbd22010-07-23 14:43:04 -040011165DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
11166 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
11167 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11168 SHOW_STR
11169 BGP_STR
11170 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011171 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011172 "Address family\n"
11173 "Address Family modifier\n"
11174 "Address Family modifier\n"
11175 "Information about Route Server Client\n"
11176 NEIGHBOR_ADDR_STR
11177 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11178{
11179 struct bgp *bgp;
11180 struct peer *peer;
11181 safi_t safi;
11182
11183 /* BGP structure lookup. */
11184 if (argc == 4)
11185 {
11186 bgp = bgp_lookup_by_name (argv[0]);
11187 if (bgp == NULL)
11188 {
11189 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11190 return CMD_WARNING;
11191 }
11192 }
11193 else
11194 {
11195 bgp = bgp_get_default ();
11196 if (bgp == NULL)
11197 {
11198 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11199 return CMD_WARNING;
11200 }
11201 }
11202
11203 if (argc == 4) {
11204 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11205 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11206 } else {
11207 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11208 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11209 }
11210
11211 if (! peer)
11212 return CMD_WARNING;
11213
11214 if (! peer->afc[AFI_IP][safi])
11215 {
11216 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11217 VTY_NEWLINE);
11218 return CMD_WARNING;
11219}
11220
11221 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11222 PEER_FLAG_RSERVER_CLIENT))
11223{
11224 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11225 VTY_NEWLINE);
11226 return CMD_WARNING;
11227 }
11228
11229 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11230 (argc == 4) ? argv[3] : argv[2],
11231 AFI_IP, safi, NULL, 1);
11232}
11233
11234ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11235 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11236 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11237 SHOW_STR
11238 BGP_STR
11239 "Address family\n"
11240 "Address Family modifier\n"
11241 "Address Family modifier\n"
11242 "Information about Route Server Client\n"
11243 NEIGHBOR_ADDR_STR
11244 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011245
paul718e3742002-12-13 20:15:29 +000011246#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011247DEFUN (show_bgp_view_neighbor_routes,
11248 show_bgp_view_neighbor_routes_cmd,
11249 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11250 SHOW_STR
11251 BGP_STR
11252 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011253 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011254 "Detailed information on TCP and BGP neighbor connections\n"
11255 "Neighbor to display information about\n"
11256 "Neighbor to display information about\n"
11257 "Display routes learned from neighbor\n")
11258{
11259 struct peer *peer;
11260
11261 if (argc == 2)
11262 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11263 else
11264 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11265
11266 if (! peer)
11267 return CMD_WARNING;
11268
11269 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11270 bgp_show_type_neighbor);
11271}
11272
11273ALIAS (show_bgp_view_neighbor_routes,
11274 show_bgp_view_ipv6_neighbor_routes_cmd,
11275 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11276 SHOW_STR
11277 BGP_STR
11278 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011279 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011280 "Address family\n"
11281 "Detailed information on TCP and BGP neighbor connections\n"
11282 "Neighbor to display information about\n"
11283 "Neighbor to display information about\n"
11284 "Display routes learned from neighbor\n")
11285
11286DEFUN (show_bgp_view_neighbor_damp,
11287 show_bgp_view_neighbor_damp_cmd,
11288 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11289 SHOW_STR
11290 BGP_STR
11291 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011292 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011293 "Detailed information on TCP and BGP neighbor connections\n"
11294 "Neighbor to display information about\n"
11295 "Neighbor to display information about\n"
11296 "Display the dampened routes received from neighbor\n")
11297{
11298 struct peer *peer;
11299
11300 if (argc == 2)
11301 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11302 else
11303 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11304
11305 if (! peer)
11306 return CMD_WARNING;
11307
11308 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11309 bgp_show_type_damp_neighbor);
11310}
11311
11312ALIAS (show_bgp_view_neighbor_damp,
11313 show_bgp_view_ipv6_neighbor_damp_cmd,
11314 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11315 SHOW_STR
11316 BGP_STR
11317 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011318 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011319 "Address family\n"
11320 "Detailed information on TCP and BGP neighbor connections\n"
11321 "Neighbor to display information about\n"
11322 "Neighbor to display information about\n"
11323 "Display the dampened routes received from neighbor\n")
11324
11325DEFUN (show_bgp_view_neighbor_flap,
11326 show_bgp_view_neighbor_flap_cmd,
11327 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11328 SHOW_STR
11329 BGP_STR
11330 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011331 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011332 "Detailed information on TCP and BGP neighbor connections\n"
11333 "Neighbor to display information about\n"
11334 "Neighbor to display information about\n"
11335 "Display flap statistics of the routes learned from neighbor\n")
11336{
11337 struct peer *peer;
11338
11339 if (argc == 2)
11340 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11341 else
11342 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11343
11344 if (! peer)
11345 return CMD_WARNING;
11346
11347 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11348 bgp_show_type_flap_neighbor);
11349}
11350
11351ALIAS (show_bgp_view_neighbor_flap,
11352 show_bgp_view_ipv6_neighbor_flap_cmd,
11353 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11354 SHOW_STR
11355 BGP_STR
11356 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011357 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011358 "Address family\n"
11359 "Detailed information on TCP and BGP neighbor connections\n"
11360 "Neighbor to display information about\n"
11361 "Neighbor to display information about\n"
11362 "Display flap statistics of the routes learned from neighbor\n")
11363
11364ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011365 show_bgp_neighbor_routes_cmd,
11366 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11367 SHOW_STR
11368 BGP_STR
11369 "Detailed information on TCP and BGP neighbor connections\n"
11370 "Neighbor to display information about\n"
11371 "Neighbor to display information about\n"
11372 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011373
paulbb46e942003-10-24 19:02:03 +000011374
11375ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011376 show_bgp_ipv6_neighbor_routes_cmd,
11377 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11378 SHOW_STR
11379 BGP_STR
11380 "Address family\n"
11381 "Detailed information on TCP and BGP neighbor connections\n"
11382 "Neighbor to display information about\n"
11383 "Neighbor to display information about\n"
11384 "Display routes learned from neighbor\n")
11385
11386/* old command */
paulbb46e942003-10-24 19:02:03 +000011387ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011388 ipv6_bgp_neighbor_routes_cmd,
11389 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11390 SHOW_STR
11391 IPV6_STR
11392 BGP_STR
11393 "Detailed information on TCP and BGP neighbor connections\n"
11394 "Neighbor to display information about\n"
11395 "Neighbor to display information about\n"
11396 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011397
11398/* old command */
11399DEFUN (ipv6_mbgp_neighbor_routes,
11400 ipv6_mbgp_neighbor_routes_cmd,
11401 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11402 SHOW_STR
11403 IPV6_STR
11404 MBGP_STR
11405 "Detailed information on TCP and BGP neighbor connections\n"
11406 "Neighbor to display information about\n"
11407 "Neighbor to display information about\n"
11408 "Display routes learned from neighbor\n")
11409{
paulbb46e942003-10-24 19:02:03 +000011410 struct peer *peer;
11411
11412 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11413 if (! peer)
11414 return CMD_WARNING;
11415
11416 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011417 bgp_show_type_neighbor);
11418}
paulbb46e942003-10-24 19:02:03 +000011419
11420ALIAS (show_bgp_view_neighbor_flap,
11421 show_bgp_neighbor_flap_cmd,
11422 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11423 SHOW_STR
11424 BGP_STR
11425 "Detailed information on TCP and BGP neighbor connections\n"
11426 "Neighbor to display information about\n"
11427 "Neighbor to display information about\n"
11428 "Display flap statistics of the routes learned from neighbor\n")
11429
11430ALIAS (show_bgp_view_neighbor_flap,
11431 show_bgp_ipv6_neighbor_flap_cmd,
11432 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11433 SHOW_STR
11434 BGP_STR
11435 "Address family\n"
11436 "Detailed information on TCP and BGP neighbor connections\n"
11437 "Neighbor to display information about\n"
11438 "Neighbor to display information about\n"
11439 "Display flap statistics of the routes learned from neighbor\n")
11440
11441ALIAS (show_bgp_view_neighbor_damp,
11442 show_bgp_neighbor_damp_cmd,
11443 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11444 SHOW_STR
11445 BGP_STR
11446 "Detailed information on TCP and BGP neighbor connections\n"
11447 "Neighbor to display information about\n"
11448 "Neighbor to display information about\n"
11449 "Display the dampened routes received from neighbor\n")
11450
11451ALIAS (show_bgp_view_neighbor_damp,
11452 show_bgp_ipv6_neighbor_damp_cmd,
11453 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11454 SHOW_STR
11455 BGP_STR
11456 "Address family\n"
11457 "Detailed information on TCP and BGP neighbor connections\n"
11458 "Neighbor to display information about\n"
11459 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011460 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011461
11462DEFUN (show_bgp_view_rsclient,
11463 show_bgp_view_rsclient_cmd,
11464 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11465 SHOW_STR
11466 BGP_STR
11467 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011468 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011469 "Information about Route Server Client\n"
11470 NEIGHBOR_ADDR_STR)
11471{
11472 struct bgp_table *table;
11473 struct peer *peer;
11474
11475 if (argc == 2)
11476 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11477 else
11478 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11479
11480 if (! peer)
11481 return CMD_WARNING;
11482
11483 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11484 {
11485 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11486 VTY_NEWLINE);
11487 return CMD_WARNING;
11488 }
11489
11490 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11491 PEER_FLAG_RSERVER_CLIENT))
11492 {
11493 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11494 VTY_NEWLINE);
11495 return CMD_WARNING;
11496 }
11497
11498 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11499
ajs5a646652004-11-05 01:25:55 +000011500 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011501}
11502
11503ALIAS (show_bgp_view_rsclient,
11504 show_bgp_rsclient_cmd,
11505 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11506 SHOW_STR
11507 BGP_STR
11508 "Information about Route Server Client\n"
11509 NEIGHBOR_ADDR_STR)
11510
Michael Lambert95cbbd22010-07-23 14:43:04 -040011511DEFUN (show_bgp_view_ipv6_safi_rsclient,
11512 show_bgp_view_ipv6_safi_rsclient_cmd,
11513 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11514 SHOW_STR
11515 BGP_STR
11516 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011517 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011518 "Address family\n"
11519 "Address Family modifier\n"
11520 "Address Family modifier\n"
11521 "Information about Route Server Client\n"
11522 NEIGHBOR_ADDR_STR)
11523{
11524 struct bgp_table *table;
11525 struct peer *peer;
11526 safi_t safi;
11527
11528 if (argc == 3) {
11529 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11530 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11531 } else {
11532 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11533 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11534 }
11535
11536 if (! peer)
11537 return CMD_WARNING;
11538
11539 if (! peer->afc[AFI_IP6][safi])
11540 {
11541 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11542 VTY_NEWLINE);
11543 return CMD_WARNING;
11544 }
11545
11546 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11547 PEER_FLAG_RSERVER_CLIENT))
11548 {
11549 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11550 VTY_NEWLINE);
11551 return CMD_WARNING;
11552 }
11553
11554 table = peer->rib[AFI_IP6][safi];
11555
11556 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11557}
11558
11559ALIAS (show_bgp_view_ipv6_safi_rsclient,
11560 show_bgp_ipv6_safi_rsclient_cmd,
11561 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11562 SHOW_STR
11563 BGP_STR
11564 "Address family\n"
11565 "Address Family modifier\n"
11566 "Address Family modifier\n"
11567 "Information about Route Server Client\n"
11568 NEIGHBOR_ADDR_STR)
11569
paulfee0f4c2004-09-13 05:12:46 +000011570DEFUN (show_bgp_view_rsclient_route,
11571 show_bgp_view_rsclient_route_cmd,
11572 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11573 SHOW_STR
11574 BGP_STR
11575 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011576 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011577 "Information about Route Server Client\n"
11578 NEIGHBOR_ADDR_STR
11579 "Network in the BGP routing table to display\n")
11580{
11581 struct bgp *bgp;
11582 struct peer *peer;
11583
11584 /* BGP structure lookup. */
11585 if (argc == 3)
11586 {
11587 bgp = bgp_lookup_by_name (argv[0]);
11588 if (bgp == NULL)
11589 {
11590 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11591 return CMD_WARNING;
11592 }
11593 }
11594 else
11595 {
11596 bgp = bgp_get_default ();
11597 if (bgp == NULL)
11598 {
11599 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11600 return CMD_WARNING;
11601 }
11602 }
11603
11604 if (argc == 3)
11605 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11606 else
11607 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11608
11609 if (! peer)
11610 return CMD_WARNING;
11611
11612 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11613 {
11614 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11615 VTY_NEWLINE);
11616 return CMD_WARNING;
11617 }
11618
11619 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11620 PEER_FLAG_RSERVER_CLIENT))
11621 {
11622 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11623 VTY_NEWLINE);
11624 return CMD_WARNING;
11625 }
11626
11627 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11628 (argc == 3) ? argv[2] : argv[1],
11629 AFI_IP6, SAFI_UNICAST, NULL, 0);
11630}
11631
11632ALIAS (show_bgp_view_rsclient_route,
11633 show_bgp_rsclient_route_cmd,
11634 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11635 SHOW_STR
11636 BGP_STR
11637 "Information about Route Server Client\n"
11638 NEIGHBOR_ADDR_STR
11639 "Network in the BGP routing table to display\n")
11640
Michael Lambert95cbbd22010-07-23 14:43:04 -040011641DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11642 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11643 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11644 SHOW_STR
11645 BGP_STR
11646 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011647 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011648 "Address family\n"
11649 "Address Family modifier\n"
11650 "Address Family modifier\n"
11651 "Information about Route Server Client\n"
11652 NEIGHBOR_ADDR_STR
11653 "Network in the BGP routing table to display\n")
11654{
11655 struct bgp *bgp;
11656 struct peer *peer;
11657 safi_t safi;
11658
11659 /* BGP structure lookup. */
11660 if (argc == 4)
11661 {
11662 bgp = bgp_lookup_by_name (argv[0]);
11663 if (bgp == NULL)
11664 {
11665 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11666 return CMD_WARNING;
11667 }
11668 }
11669 else
11670 {
11671 bgp = bgp_get_default ();
11672 if (bgp == NULL)
11673 {
11674 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11675 return CMD_WARNING;
11676 }
11677 }
11678
11679 if (argc == 4) {
11680 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11681 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11682 } else {
11683 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11684 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11685 }
11686
11687 if (! peer)
11688 return CMD_WARNING;
11689
11690 if (! peer->afc[AFI_IP6][safi])
11691 {
11692 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11693 VTY_NEWLINE);
11694 return CMD_WARNING;
11695}
11696
11697 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11698 PEER_FLAG_RSERVER_CLIENT))
11699 {
11700 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11701 VTY_NEWLINE);
11702 return CMD_WARNING;
11703 }
11704
11705 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11706 (argc == 4) ? argv[3] : argv[2],
11707 AFI_IP6, safi, NULL, 0);
11708}
11709
11710ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11711 show_bgp_ipv6_safi_rsclient_route_cmd,
11712 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11713 SHOW_STR
11714 BGP_STR
11715 "Address family\n"
11716 "Address Family modifier\n"
11717 "Address Family modifier\n"
11718 "Information about Route Server Client\n"
11719 NEIGHBOR_ADDR_STR
11720 "Network in the BGP routing table to display\n")
11721
paulfee0f4c2004-09-13 05:12:46 +000011722DEFUN (show_bgp_view_rsclient_prefix,
11723 show_bgp_view_rsclient_prefix_cmd,
11724 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11725 SHOW_STR
11726 BGP_STR
11727 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011728 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011729 "Information about Route Server Client\n"
11730 NEIGHBOR_ADDR_STR
11731 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11732{
11733 struct bgp *bgp;
11734 struct peer *peer;
11735
11736 /* BGP structure lookup. */
11737 if (argc == 3)
11738 {
11739 bgp = bgp_lookup_by_name (argv[0]);
11740 if (bgp == NULL)
11741 {
11742 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11743 return CMD_WARNING;
11744 }
11745 }
11746 else
11747 {
11748 bgp = bgp_get_default ();
11749 if (bgp == NULL)
11750 {
11751 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11752 return CMD_WARNING;
11753 }
11754 }
11755
11756 if (argc == 3)
11757 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11758 else
11759 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11760
11761 if (! peer)
11762 return CMD_WARNING;
11763
11764 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11765 {
11766 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11767 VTY_NEWLINE);
11768 return CMD_WARNING;
11769 }
11770
11771 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11772 PEER_FLAG_RSERVER_CLIENT))
11773 {
11774 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11775 VTY_NEWLINE);
11776 return CMD_WARNING;
11777 }
11778
11779 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11780 (argc == 3) ? argv[2] : argv[1],
11781 AFI_IP6, SAFI_UNICAST, NULL, 1);
11782}
11783
11784ALIAS (show_bgp_view_rsclient_prefix,
11785 show_bgp_rsclient_prefix_cmd,
11786 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11787 SHOW_STR
11788 BGP_STR
11789 "Information about Route Server Client\n"
11790 NEIGHBOR_ADDR_STR
11791 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11792
Michael Lambert95cbbd22010-07-23 14:43:04 -040011793DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11794 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11795 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11796 SHOW_STR
11797 BGP_STR
11798 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011799 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011800 "Address family\n"
11801 "Address Family modifier\n"
11802 "Address Family modifier\n"
11803 "Information about Route Server Client\n"
11804 NEIGHBOR_ADDR_STR
11805 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11806{
11807 struct bgp *bgp;
11808 struct peer *peer;
11809 safi_t safi;
11810
11811 /* BGP structure lookup. */
11812 if (argc == 4)
11813 {
11814 bgp = bgp_lookup_by_name (argv[0]);
11815 if (bgp == NULL)
11816 {
11817 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11818 return CMD_WARNING;
11819 }
11820 }
11821 else
11822 {
11823 bgp = bgp_get_default ();
11824 if (bgp == NULL)
11825 {
11826 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11827 return CMD_WARNING;
11828 }
11829 }
11830
11831 if (argc == 4) {
11832 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11833 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11834 } else {
11835 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11836 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11837 }
11838
11839 if (! peer)
11840 return CMD_WARNING;
11841
11842 if (! peer->afc[AFI_IP6][safi])
11843 {
11844 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11845 VTY_NEWLINE);
11846 return CMD_WARNING;
11847}
11848
11849 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11850 PEER_FLAG_RSERVER_CLIENT))
11851{
11852 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11853 VTY_NEWLINE);
11854 return CMD_WARNING;
11855 }
11856
11857 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11858 (argc == 4) ? argv[3] : argv[2],
11859 AFI_IP6, safi, NULL, 1);
11860}
11861
11862ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11863 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11864 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11865 SHOW_STR
11866 BGP_STR
11867 "Address family\n"
11868 "Address Family modifier\n"
11869 "Address Family modifier\n"
11870 "Information about Route Server Client\n"
11871 NEIGHBOR_ADDR_STR
11872 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11873
paul718e3742002-12-13 20:15:29 +000011874#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020011875
paul718e3742002-12-13 20:15:29 +000011876struct bgp_table *bgp_distance_table;
11877
11878struct bgp_distance
11879{
11880 /* Distance value for the IP source prefix. */
11881 u_char distance;
11882
11883 /* Name of the access-list to be matched. */
11884 char *access_list;
11885};
11886
paul94f2b392005-06-28 12:44:16 +000011887static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011888bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011889{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011890 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011891}
11892
paul94f2b392005-06-28 12:44:16 +000011893static void
paul718e3742002-12-13 20:15:29 +000011894bgp_distance_free (struct bgp_distance *bdistance)
11895{
11896 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11897}
11898
paul94f2b392005-06-28 12:44:16 +000011899static int
paulfd79ac92004-10-13 05:06:08 +000011900bgp_distance_set (struct vty *vty, const char *distance_str,
11901 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011902{
11903 int ret;
11904 struct prefix_ipv4 p;
11905 u_char distance;
11906 struct bgp_node *rn;
11907 struct bgp_distance *bdistance;
11908
11909 ret = str2prefix_ipv4 (ip_str, &p);
11910 if (ret == 0)
11911 {
11912 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11913 return CMD_WARNING;
11914 }
11915
11916 distance = atoi (distance_str);
11917
11918 /* Get BGP distance node. */
11919 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11920 if (rn->info)
11921 {
11922 bdistance = rn->info;
11923 bgp_unlock_node (rn);
11924 }
11925 else
11926 {
11927 bdistance = bgp_distance_new ();
11928 rn->info = bdistance;
11929 }
11930
11931 /* Set distance value. */
11932 bdistance->distance = distance;
11933
11934 /* Reset access-list configuration. */
11935 if (bdistance->access_list)
11936 {
11937 free (bdistance->access_list);
11938 bdistance->access_list = NULL;
11939 }
11940 if (access_list_str)
11941 bdistance->access_list = strdup (access_list_str);
11942
11943 return CMD_SUCCESS;
11944}
11945
paul94f2b392005-06-28 12:44:16 +000011946static int
paulfd79ac92004-10-13 05:06:08 +000011947bgp_distance_unset (struct vty *vty, const char *distance_str,
11948 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011949{
11950 int ret;
11951 struct prefix_ipv4 p;
11952 u_char distance;
11953 struct bgp_node *rn;
11954 struct bgp_distance *bdistance;
11955
11956 ret = str2prefix_ipv4 (ip_str, &p);
11957 if (ret == 0)
11958 {
11959 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11960 return CMD_WARNING;
11961 }
11962
11963 distance = atoi (distance_str);
11964
11965 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11966 if (! rn)
11967 {
11968 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11969 return CMD_WARNING;
11970 }
11971
11972 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010011973
11974 if (bdistance->distance != distance)
11975 {
11976 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
11977 return CMD_WARNING;
11978 }
11979
paul718e3742002-12-13 20:15:29 +000011980 if (bdistance->access_list)
11981 free (bdistance->access_list);
11982 bgp_distance_free (bdistance);
11983
11984 rn->info = NULL;
11985 bgp_unlock_node (rn);
11986 bgp_unlock_node (rn);
11987
11988 return CMD_SUCCESS;
11989}
11990
paul718e3742002-12-13 20:15:29 +000011991/* Apply BGP information to distance method. */
11992u_char
11993bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11994{
11995 struct bgp_node *rn;
11996 struct prefix_ipv4 q;
11997 struct peer *peer;
11998 struct bgp_distance *bdistance;
11999 struct access_list *alist;
12000 struct bgp_static *bgp_static;
12001
12002 if (! bgp)
12003 return 0;
12004
12005 if (p->family != AF_INET)
12006 return 0;
12007
12008 peer = rinfo->peer;
12009
12010 if (peer->su.sa.sa_family != AF_INET)
12011 return 0;
12012
12013 memset (&q, 0, sizeof (struct prefix_ipv4));
12014 q.family = AF_INET;
12015 q.prefix = peer->su.sin.sin_addr;
12016 q.prefixlen = IPV4_MAX_BITLEN;
12017
12018 /* Check source address. */
12019 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
12020 if (rn)
12021 {
12022 bdistance = rn->info;
12023 bgp_unlock_node (rn);
12024
12025 if (bdistance->access_list)
12026 {
12027 alist = access_list_lookup (AFI_IP, bdistance->access_list);
12028 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
12029 return bdistance->distance;
12030 }
12031 else
12032 return bdistance->distance;
12033 }
12034
12035 /* Backdoor check. */
12036 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
12037 if (rn)
12038 {
12039 bgp_static = rn->info;
12040 bgp_unlock_node (rn);
12041
12042 if (bgp_static->backdoor)
12043 {
12044 if (bgp->distance_local)
12045 return bgp->distance_local;
12046 else
12047 return ZEBRA_IBGP_DISTANCE_DEFAULT;
12048 }
12049 }
12050
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000012051 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000012052 {
12053 if (bgp->distance_ebgp)
12054 return bgp->distance_ebgp;
12055 return ZEBRA_EBGP_DISTANCE_DEFAULT;
12056 }
12057 else
12058 {
12059 if (bgp->distance_ibgp)
12060 return bgp->distance_ibgp;
12061 return ZEBRA_IBGP_DISTANCE_DEFAULT;
12062 }
12063}
12064
12065DEFUN (bgp_distance,
12066 bgp_distance_cmd,
12067 "distance bgp <1-255> <1-255> <1-255>",
12068 "Define an administrative distance\n"
12069 "BGP distance\n"
12070 "Distance for routes external to the AS\n"
12071 "Distance for routes internal to the AS\n"
12072 "Distance for local routes\n")
12073{
12074 struct bgp *bgp;
12075
12076 bgp = vty->index;
12077
12078 bgp->distance_ebgp = atoi (argv[0]);
12079 bgp->distance_ibgp = atoi (argv[1]);
12080 bgp->distance_local = atoi (argv[2]);
12081 return CMD_SUCCESS;
12082}
12083
12084DEFUN (no_bgp_distance,
12085 no_bgp_distance_cmd,
12086 "no distance bgp <1-255> <1-255> <1-255>",
12087 NO_STR
12088 "Define an administrative distance\n"
12089 "BGP distance\n"
12090 "Distance for routes external to the AS\n"
12091 "Distance for routes internal to the AS\n"
12092 "Distance for local routes\n")
12093{
12094 struct bgp *bgp;
12095
12096 bgp = vty->index;
12097
12098 bgp->distance_ebgp= 0;
12099 bgp->distance_ibgp = 0;
12100 bgp->distance_local = 0;
12101 return CMD_SUCCESS;
12102}
12103
12104ALIAS (no_bgp_distance,
12105 no_bgp_distance2_cmd,
12106 "no distance bgp",
12107 NO_STR
12108 "Define an administrative distance\n"
12109 "BGP distance\n")
12110
12111DEFUN (bgp_distance_source,
12112 bgp_distance_source_cmd,
12113 "distance <1-255> A.B.C.D/M",
12114 "Define an administrative distance\n"
12115 "Administrative distance\n"
12116 "IP source prefix\n")
12117{
12118 bgp_distance_set (vty, argv[0], argv[1], NULL);
12119 return CMD_SUCCESS;
12120}
12121
12122DEFUN (no_bgp_distance_source,
12123 no_bgp_distance_source_cmd,
12124 "no distance <1-255> A.B.C.D/M",
12125 NO_STR
12126 "Define an administrative distance\n"
12127 "Administrative distance\n"
12128 "IP source prefix\n")
12129{
12130 bgp_distance_unset (vty, argv[0], argv[1], NULL);
12131 return CMD_SUCCESS;
12132}
12133
12134DEFUN (bgp_distance_source_access_list,
12135 bgp_distance_source_access_list_cmd,
12136 "distance <1-255> A.B.C.D/M WORD",
12137 "Define an administrative distance\n"
12138 "Administrative distance\n"
12139 "IP source prefix\n"
12140 "Access list name\n")
12141{
12142 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
12143 return CMD_SUCCESS;
12144}
12145
12146DEFUN (no_bgp_distance_source_access_list,
12147 no_bgp_distance_source_access_list_cmd,
12148 "no distance <1-255> A.B.C.D/M WORD",
12149 NO_STR
12150 "Define an administrative distance\n"
12151 "Administrative distance\n"
12152 "IP source prefix\n"
12153 "Access list name\n")
12154{
12155 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
12156 return CMD_SUCCESS;
12157}
David Lamparter6b0655a2014-06-04 06:53:35 +020012158
paul718e3742002-12-13 20:15:29 +000012159DEFUN (bgp_damp_set,
12160 bgp_damp_set_cmd,
12161 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12162 "BGP Specific commands\n"
12163 "Enable route-flap dampening\n"
12164 "Half-life time for the penalty\n"
12165 "Value to start reusing a route\n"
12166 "Value to start suppressing a route\n"
12167 "Maximum duration to suppress a stable route\n")
12168{
12169 struct bgp *bgp;
12170 int half = DEFAULT_HALF_LIFE * 60;
12171 int reuse = DEFAULT_REUSE;
12172 int suppress = DEFAULT_SUPPRESS;
12173 int max = 4 * half;
12174
12175 if (argc == 4)
12176 {
12177 half = atoi (argv[0]) * 60;
12178 reuse = atoi (argv[1]);
12179 suppress = atoi (argv[2]);
12180 max = atoi (argv[3]) * 60;
12181 }
12182 else if (argc == 1)
12183 {
12184 half = atoi (argv[0]) * 60;
12185 max = 4 * half;
12186 }
12187
12188 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000012189
12190 if (suppress < reuse)
12191 {
12192 vty_out (vty, "Suppress value cannot be less than reuse value %s",
12193 VTY_NEWLINE);
12194 return 0;
12195 }
12196
paul718e3742002-12-13 20:15:29 +000012197 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
12198 half, reuse, suppress, max);
12199}
12200
12201ALIAS (bgp_damp_set,
12202 bgp_damp_set2_cmd,
12203 "bgp dampening <1-45>",
12204 "BGP Specific commands\n"
12205 "Enable route-flap dampening\n"
12206 "Half-life time for the penalty\n")
12207
12208ALIAS (bgp_damp_set,
12209 bgp_damp_set3_cmd,
12210 "bgp dampening",
12211 "BGP Specific commands\n"
12212 "Enable route-flap dampening\n")
12213
12214DEFUN (bgp_damp_unset,
12215 bgp_damp_unset_cmd,
12216 "no bgp dampening",
12217 NO_STR
12218 "BGP Specific commands\n"
12219 "Enable route-flap dampening\n")
12220{
12221 struct bgp *bgp;
12222
12223 bgp = vty->index;
12224 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
12225}
12226
12227ALIAS (bgp_damp_unset,
12228 bgp_damp_unset2_cmd,
12229 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12230 NO_STR
12231 "BGP Specific commands\n"
12232 "Enable route-flap dampening\n"
12233 "Half-life time for the penalty\n"
12234 "Value to start reusing a route\n"
12235 "Value to start suppressing a route\n"
12236 "Maximum duration to suppress a stable route\n")
12237
12238DEFUN (show_ip_bgp_dampened_paths,
12239 show_ip_bgp_dampened_paths_cmd,
12240 "show ip bgp dampened-paths",
12241 SHOW_STR
12242 IP_STR
12243 BGP_STR
12244 "Display paths suppressed due to dampening\n")
12245{
ajs5a646652004-11-05 01:25:55 +000012246 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
12247 NULL);
paul718e3742002-12-13 20:15:29 +000012248}
12249
Balaji3921cc52015-05-16 23:12:17 +053012250ALIAS (show_ip_bgp_dampened_paths,
12251 show_ip_bgp_damp_dampened_paths_cmd,
12252 "show ip bgp dampening dampened-paths",
12253 SHOW_STR
12254 IP_STR
12255 BGP_STR
12256 "Display detailed information about dampening\n"
12257 "Display paths suppressed due to dampening\n")
12258
paul718e3742002-12-13 20:15:29 +000012259DEFUN (show_ip_bgp_flap_statistics,
12260 show_ip_bgp_flap_statistics_cmd,
12261 "show ip bgp flap-statistics",
12262 SHOW_STR
12263 IP_STR
12264 BGP_STR
12265 "Display flap statistics of routes\n")
12266{
ajs5a646652004-11-05 01:25:55 +000012267 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12268 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012269}
David Lamparter6b0655a2014-06-04 06:53:35 +020012270
Balaji3921cc52015-05-16 23:12:17 +053012271ALIAS (show_ip_bgp_flap_statistics,
12272 show_ip_bgp_damp_flap_statistics_cmd,
12273 "show ip bgp dampening flap-statistics",
12274 SHOW_STR
12275 IP_STR
12276 BGP_STR
12277 "Display detailed information about dampening\n"
12278 "Display flap statistics of routes\n")
12279
paul718e3742002-12-13 20:15:29 +000012280/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012281static int
paulfd79ac92004-10-13 05:06:08 +000012282bgp_clear_damp_route (struct vty *vty, const char *view_name,
12283 const char *ip_str, afi_t afi, safi_t safi,
12284 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012285{
12286 int ret;
12287 struct prefix match;
12288 struct bgp_node *rn;
12289 struct bgp_node *rm;
12290 struct bgp_info *ri;
12291 struct bgp_info *ri_temp;
12292 struct bgp *bgp;
12293 struct bgp_table *table;
12294
12295 /* BGP structure lookup. */
12296 if (view_name)
12297 {
12298 bgp = bgp_lookup_by_name (view_name);
12299 if (bgp == NULL)
12300 {
12301 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12302 return CMD_WARNING;
12303 }
12304 }
12305 else
12306 {
12307 bgp = bgp_get_default ();
12308 if (bgp == NULL)
12309 {
12310 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12311 return CMD_WARNING;
12312 }
12313 }
12314
12315 /* Check IP address argument. */
12316 ret = str2prefix (ip_str, &match);
12317 if (! ret)
12318 {
12319 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12320 return CMD_WARNING;
12321 }
12322
12323 match.family = afi2family (afi);
12324
12325 if (safi == SAFI_MPLS_VPN)
12326 {
12327 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12328 {
12329 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12330 continue;
12331
12332 if ((table = rn->info) != NULL)
12333 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012334 {
12335 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12336 {
12337 ri = rm->info;
12338 while (ri)
12339 {
12340 if (ri->extra && ri->extra->damp_info)
12341 {
12342 ri_temp = ri->next;
12343 bgp_damp_info_free (ri->extra->damp_info, 1);
12344 ri = ri_temp;
12345 }
12346 else
12347 ri = ri->next;
12348 }
12349 }
12350
12351 bgp_unlock_node (rm);
12352 }
paul718e3742002-12-13 20:15:29 +000012353 }
12354 }
12355 else
12356 {
12357 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012358 {
12359 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12360 {
12361 ri = rn->info;
12362 while (ri)
12363 {
12364 if (ri->extra && ri->extra->damp_info)
12365 {
12366 ri_temp = ri->next;
12367 bgp_damp_info_free (ri->extra->damp_info, 1);
12368 ri = ri_temp;
12369 }
12370 else
12371 ri = ri->next;
12372 }
12373 }
12374
12375 bgp_unlock_node (rn);
12376 }
paul718e3742002-12-13 20:15:29 +000012377 }
12378
12379 return CMD_SUCCESS;
12380}
12381
12382DEFUN (clear_ip_bgp_dampening,
12383 clear_ip_bgp_dampening_cmd,
12384 "clear ip bgp dampening",
12385 CLEAR_STR
12386 IP_STR
12387 BGP_STR
12388 "Clear route flap dampening information\n")
12389{
12390 bgp_damp_info_clean ();
12391 return CMD_SUCCESS;
12392}
12393
12394DEFUN (clear_ip_bgp_dampening_prefix,
12395 clear_ip_bgp_dampening_prefix_cmd,
12396 "clear ip bgp dampening A.B.C.D/M",
12397 CLEAR_STR
12398 IP_STR
12399 BGP_STR
12400 "Clear route flap dampening information\n"
12401 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12402{
12403 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12404 SAFI_UNICAST, NULL, 1);
12405}
12406
12407DEFUN (clear_ip_bgp_dampening_address,
12408 clear_ip_bgp_dampening_address_cmd,
12409 "clear ip bgp dampening A.B.C.D",
12410 CLEAR_STR
12411 IP_STR
12412 BGP_STR
12413 "Clear route flap dampening information\n"
12414 "Network to clear damping information\n")
12415{
12416 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12417 SAFI_UNICAST, NULL, 0);
12418}
12419
12420DEFUN (clear_ip_bgp_dampening_address_mask,
12421 clear_ip_bgp_dampening_address_mask_cmd,
12422 "clear ip bgp dampening A.B.C.D 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 "Network mask\n")
12429{
12430 int ret;
12431 char prefix_str[BUFSIZ];
12432
12433 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12434 if (! ret)
12435 {
12436 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12437 return CMD_WARNING;
12438 }
12439
12440 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12441 SAFI_UNICAST, NULL, 0);
12442}
David Lamparter6b0655a2014-06-04 06:53:35 +020012443
paul94f2b392005-06-28 12:44:16 +000012444static int
paul718e3742002-12-13 20:15:29 +000012445bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12446 afi_t afi, safi_t safi, int *write)
12447{
12448 struct bgp_node *prn;
12449 struct bgp_node *rn;
12450 struct bgp_table *table;
12451 struct prefix *p;
12452 struct prefix_rd *prd;
12453 struct bgp_static *bgp_static;
12454 u_int32_t label;
12455 char buf[SU_ADDRSTRLEN];
12456 char rdbuf[RD_ADDRSTRLEN];
12457
12458 /* Network configuration. */
12459 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12460 if ((table = prn->info) != NULL)
12461 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12462 if ((bgp_static = rn->info) != NULL)
12463 {
12464 p = &rn->p;
12465 prd = (struct prefix_rd *) &prn->p;
12466
12467 /* "address-family" display. */
12468 bgp_config_write_family_header (vty, afi, safi, write);
12469
12470 /* "network" configuration display. */
12471 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12472 label = decode_label (bgp_static->tag);
12473
12474 vty_out (vty, " network %s/%d rd %s tag %d",
12475 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12476 p->prefixlen,
12477 rdbuf, label);
12478 vty_out (vty, "%s", VTY_NEWLINE);
12479 }
12480 return 0;
12481}
12482
12483/* Configuration of static route announcement and aggregate
12484 information. */
12485int
12486bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12487 afi_t afi, safi_t safi, int *write)
12488{
12489 struct bgp_node *rn;
12490 struct prefix *p;
12491 struct bgp_static *bgp_static;
12492 struct bgp_aggregate *bgp_aggregate;
12493 char buf[SU_ADDRSTRLEN];
12494
12495 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12496 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12497
12498 /* Network configuration. */
12499 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12500 if ((bgp_static = rn->info) != NULL)
12501 {
12502 p = &rn->p;
12503
12504 /* "address-family" display. */
12505 bgp_config_write_family_header (vty, afi, safi, write);
12506
12507 /* "network" configuration display. */
12508 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12509 {
12510 u_int32_t destination;
12511 struct in_addr netmask;
12512
12513 destination = ntohl (p->u.prefix4.s_addr);
12514 masklen2ip (p->prefixlen, &netmask);
12515 vty_out (vty, " network %s",
12516 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12517
12518 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12519 || (IN_CLASSB (destination) && p->prefixlen == 16)
12520 || (IN_CLASSA (destination) && p->prefixlen == 8)
12521 || p->u.prefix4.s_addr == 0)
12522 {
12523 /* Natural mask is not display. */
12524 }
12525 else
12526 vty_out (vty, " mask %s", inet_ntoa (netmask));
12527 }
12528 else
12529 {
12530 vty_out (vty, " network %s/%d",
12531 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12532 p->prefixlen);
12533 }
12534
12535 if (bgp_static->rmap.name)
12536 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012537 else
12538 {
12539 if (bgp_static->backdoor)
12540 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012541 }
paul718e3742002-12-13 20:15:29 +000012542
12543 vty_out (vty, "%s", VTY_NEWLINE);
12544 }
12545
12546 /* Aggregate-address configuration. */
12547 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12548 if ((bgp_aggregate = rn->info) != NULL)
12549 {
12550 p = &rn->p;
12551
12552 /* "address-family" display. */
12553 bgp_config_write_family_header (vty, afi, safi, write);
12554
12555 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12556 {
12557 struct in_addr netmask;
12558
12559 masklen2ip (p->prefixlen, &netmask);
12560 vty_out (vty, " aggregate-address %s %s",
12561 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12562 inet_ntoa (netmask));
12563 }
12564 else
12565 {
12566 vty_out (vty, " aggregate-address %s/%d",
12567 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12568 p->prefixlen);
12569 }
12570
12571 if (bgp_aggregate->as_set)
12572 vty_out (vty, " as-set");
12573
12574 if (bgp_aggregate->summary_only)
12575 vty_out (vty, " summary-only");
12576
12577 vty_out (vty, "%s", VTY_NEWLINE);
12578 }
12579
12580 return 0;
12581}
12582
12583int
12584bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12585{
12586 struct bgp_node *rn;
12587 struct bgp_distance *bdistance;
12588
12589 /* Distance configuration. */
12590 if (bgp->distance_ebgp
12591 && bgp->distance_ibgp
12592 && bgp->distance_local
12593 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12594 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12595 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12596 vty_out (vty, " distance bgp %d %d %d%s",
12597 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12598 VTY_NEWLINE);
12599
12600 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12601 if ((bdistance = rn->info) != NULL)
12602 {
12603 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12604 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12605 bdistance->access_list ? bdistance->access_list : "",
12606 VTY_NEWLINE);
12607 }
12608
12609 return 0;
12610}
12611
12612/* Allocate routing table structure and install commands. */
12613void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012614bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012615{
12616 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012617 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012618
12619 /* IPv4 BGP commands. */
12620 install_element (BGP_NODE, &bgp_network_cmd);
12621 install_element (BGP_NODE, &bgp_network_mask_cmd);
12622 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12623 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12624 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12625 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12626 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12627 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12628 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12629 install_element (BGP_NODE, &no_bgp_network_cmd);
12630 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12631 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12632 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12633 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12634 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12635 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12636 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12637 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12638
12639 install_element (BGP_NODE, &aggregate_address_cmd);
12640 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12641 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12642 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12643 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12644 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12645 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12646 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12647 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12648 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12649 install_element (BGP_NODE, &no_aggregate_address_cmd);
12650 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12651 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12652 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12653 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12654 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12655 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12656 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12657 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12658 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12659
12660 /* IPv4 unicast configuration. */
12661 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12662 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12663 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12664 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12665 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12666 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012667 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012668 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12669 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12670 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12671 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12672 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012673
paul718e3742002-12-13 20:15:29 +000012674 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12675 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12676 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12677 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12678 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12679 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12680 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12681 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12682 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12683 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12684 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12685 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12686 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12687 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12688 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12689 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12690 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12691 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12692 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12693 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12694
12695 /* IPv4 multicast configuration. */
12696 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12697 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12698 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12699 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12700 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12701 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12702 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12703 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12704 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12705 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12706 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12707 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12708 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12709 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12710 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12711 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12712 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12713 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12714 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12715 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12716 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12717 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12718 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12719 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12720 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12721 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12722 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12723 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12724 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12725 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12726 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12727 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12728
12729 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12730 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012731 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012732 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12733 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012734 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012735 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12736 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12737 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12738 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012739 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012740 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12741 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12742 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12743 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12744 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12745 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12746 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12747 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12748 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12749 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12750 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12751 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12752 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12753 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12754 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12755 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12756 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12757 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12758 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12759 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12760 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12761 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12762 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12763 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12764 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012765 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12766 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12767 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12768 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12769 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012770 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12771 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12772 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12773 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12774 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12775 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12776 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12777 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12778 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12779 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12780 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12781 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12782 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12783 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12784 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12785 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12786 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12787 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012788 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012789 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12790 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12791 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12792 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012793 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
paul718e3742002-12-13 20:15:29 +000012794 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012795 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
paul718e3742002-12-13 20:15:29 +000012796 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012797 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
paul718e3742002-12-13 20:15:29 +000012798 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012799 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
paul718e3742002-12-13 20:15:29 +000012800 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12801 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012802 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
paul718e3742002-12-13 20:15:29 +000012803 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12804 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012805 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000012806 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012807 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000012808 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012809 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000012810 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012811 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
paul718e3742002-12-13 20:15:29 +000012812 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12813 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012814 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012815 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012816 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012817 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012818 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012819 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012820 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12821 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012822 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012823 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012824 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012825 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012826 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012827 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012828
12829 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12830 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12831 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012832 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012833 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12834 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12835 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012836 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012837 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12838 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12839 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12840 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12841 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12842 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12843 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12844 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12845 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12846 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12847 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12848 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012849 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12850 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12851 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12852 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12853 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012854 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12855 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12856 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12857 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12858 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12859 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12860 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12861 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12862 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012863 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012864 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012865 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012866 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012867 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012868 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012869 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012870
12871 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12872 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012873 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012874 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12875 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012876 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012877 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12878 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12879 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12880 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012881 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012882 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12883 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12884 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12885 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12886 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12887 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12888 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12889 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12890 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12891 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12892 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12893 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12894 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12895 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12896 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12897 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12898 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12899 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12900 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12901 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12902 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12903 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12904 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12905 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12906 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012907 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12908 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12909 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12910 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12911 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012912 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12913 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12914 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12915 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12916 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12917 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12918 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12919 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12920 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12921 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12922 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12923 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12924 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12925 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12926 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12927 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12928 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12929 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012930 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012931 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12932 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12933 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12934 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012935 install_element (ENABLE_NODE, &show_ip_bgp_dampening_params_cmd);
paul718e3742002-12-13 20:15:29 +000012936 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012937 install_element (ENABLE_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
paul718e3742002-12-13 20:15:29 +000012938 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012939 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
paul718e3742002-12-13 20:15:29 +000012940 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012941 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_address_cmd);
paul718e3742002-12-13 20:15:29 +000012942 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12943 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012944 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
paul718e3742002-12-13 20:15:29 +000012945 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012946 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_regexp_cmd);
paul718e3742002-12-13 20:15:29 +000012947 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012948 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000012949 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012950 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
12951 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000012952 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012953 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000012954 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012955 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
paul718e3742002-12-13 20:15:29 +000012956 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12957 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012958 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012959 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012960 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012961 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012962 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012963 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012964 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12965 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012966 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012967 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012968 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012969 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012970 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012971 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012972
12973 /* BGP dampening clear commands */
12974 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12975 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12976 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12977 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12978
Paul Jakmaff7924f2006-09-04 01:10:36 +000012979 /* prefix count */
12980 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12981 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12982 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012983#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012984 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12985
paul718e3742002-12-13 20:15:29 +000012986 /* New config IPv6 BGP commands. */
12987 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12988 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12989 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12990 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12991
12992 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12993 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12994 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12995 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12996
G.Balaji73bfe0b2011-09-23 22:36:20 +053012997 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12998 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12999
paul718e3742002-12-13 20:15:29 +000013000 /* Old config IPv6 BGP commands. */
13001 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
13002 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
13003
13004 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
13005 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
13006 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
13007 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
13008
13009 install_element (VIEW_NODE, &show_bgp_cmd);
13010 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013011 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000013012 install_element (VIEW_NODE, &show_bgp_route_cmd);
13013 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013014 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000013015 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
13016 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013017 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013018 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
13019 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
13020 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
13021 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
13022 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
13023 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
13024 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
13025 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
13026 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
13027 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
13028 install_element (VIEW_NODE, &show_bgp_community_cmd);
13029 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
13030 install_element (VIEW_NODE, &show_bgp_community2_cmd);
13031 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
13032 install_element (VIEW_NODE, &show_bgp_community3_cmd);
13033 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
13034 install_element (VIEW_NODE, &show_bgp_community4_cmd);
13035 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
13036 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
13037 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
13038 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
13039 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
13040 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
13041 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
13042 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
13043 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
13044 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
13045 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
13046 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
13047 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
13048 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
13049 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
13050 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
13051 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
13052 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
13053 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
13054 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
13055 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
13056 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
13057 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000013058 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
13059 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
13060 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
13061 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013062 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013063 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013064 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013065 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013066 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013067 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000013068 install_element (VIEW_NODE, &show_bgp_view_cmd);
13069 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
13070 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
13071 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
13072 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
13073 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
13074 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
13075 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
13076 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
13077 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
13078 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
13079 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
13080 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13081 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13082 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
13083 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
13084 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
13085 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013086 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013087 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013088 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013089 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013090 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013091 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013092
13093 /* Restricted:
13094 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
13095 */
13096 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
13097 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013098 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013099 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
13100 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013101 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013102 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
13103 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
13104 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
13105 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
13106 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
13107 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
13108 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
13109 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
13110 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
13111 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
13112 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
13113 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
13114 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
13115 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
13116 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
13117 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_route_cmd);
13123 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
13124 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
13125 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
13126 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13127 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13128 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013129 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013130 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013131 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013132
13133 install_element (ENABLE_NODE, &show_bgp_cmd);
13134 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013135 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000013136 install_element (ENABLE_NODE, &show_bgp_route_cmd);
13137 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013138 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000013139 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
13140 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013141 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013142 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
13143 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
13144 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
13145 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
13146 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
13147 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
13148 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
13149 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
13150 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
13151 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
13152 install_element (ENABLE_NODE, &show_bgp_community_cmd);
13153 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
13154 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
13155 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
13156 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
13157 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
13158 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
13159 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
13160 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
13161 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
13162 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
13163 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
13164 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
13165 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
13166 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
13167 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
13168 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
13169 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
13170 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
13171 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
13172 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
13173 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
13174 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
13175 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
13176 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
13177 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
13178 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
13179 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
13180 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
13181 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000013182 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
13183 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
13184 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
13185 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013186 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013187 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013188 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013189 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013190 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013191 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000013192 install_element (ENABLE_NODE, &show_bgp_view_cmd);
13193 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
13194 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
13195 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
13196 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
13197 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
13198 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
13199 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
13200 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
13201 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
13202 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
13203 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
13204 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13205 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13206 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
13207 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
13208 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
13209 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013210 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013211 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013212 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013213 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013214 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013215 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000013216
13217 /* Statistics */
13218 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
13219 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
13220 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
13221 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
13222
paul718e3742002-12-13 20:15:29 +000013223 /* old command */
13224 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
13225 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
13226 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
13227 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
13228 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
13229 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
13230 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
13231 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
13232 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
13233 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
13234 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
13235 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
13236 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
13237 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
13238 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
13239 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
13240 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13241 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13242 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
13243 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
13244 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
13245 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
13246 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13247 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
13248 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
13249 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
13250 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
13251 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
13252 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
13253 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
13254 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13255 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13256 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13257 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
13258 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13259 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000013260
paul718e3742002-12-13 20:15:29 +000013261 /* old command */
13262 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
13263 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
13264 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
13265 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
13266 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
13267 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
13268 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
13269 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
13270 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
13271 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
13272 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13273 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13274 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13275 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13276 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13277 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13278 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13279 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13280 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13281 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13282 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13283 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13284 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13285 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13286 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13287 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13288 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13289 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13290 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13291 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13292 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13293 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13294 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13295 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13296 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13297 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13298
13299 /* old command */
13300 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13301 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13302 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13303 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13304
13305 /* old command */
13306 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13307 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13308 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13309 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13310
13311 /* old command */
13312 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13313 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13314 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13315 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13316#endif /* HAVE_IPV6 */
13317
13318 install_element (BGP_NODE, &bgp_distance_cmd);
13319 install_element (BGP_NODE, &no_bgp_distance_cmd);
13320 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13321 install_element (BGP_NODE, &bgp_distance_source_cmd);
13322 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13323 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13324 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13325
13326 install_element (BGP_NODE, &bgp_damp_set_cmd);
13327 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13328 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13329 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13330 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13331 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13332 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13333 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13334 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13335 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013336
13337 /* Deprecated AS-Pathlimit commands */
13338 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13339 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13340 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13341 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13342 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13343 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13344
13345 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13346 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13347 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13348 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13349 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13350 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13351
13352 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13353 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13354 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13355 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13356 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13357 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13358
13359 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13360 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13361 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13362 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13363 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13364 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13365
13366 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13367 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13368 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13369 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13370 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13371 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13372
13373 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13374 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13375 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13376 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13377 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13378 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013379
13380#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013381 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13382 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013383#endif
paul718e3742002-12-13 20:15:29 +000013384}
Chris Caputo228da422009-07-18 05:44:03 +000013385
13386void
13387bgp_route_finish (void)
13388{
13389 bgp_table_unlock (bgp_distance_table);
13390 bgp_distance_table = NULL;
13391}