blob: f421ca5eb25979ca6a6104334f13e3f487eae55c [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
324/* Compare two bgp route entity. br is preferable then return 1. */
paul94f2b392005-06-28 12:44:16 +0000325static int
Josh Bailey96450fa2011-07-20 20:45:12 -0700326bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
327 int *paths_eq)
paul718e3742002-12-13 20:15:29 +0000328{
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000329 struct attr *newattr, *existattr;
330 struct attr_extra *newattre, *existattre;
331 bgp_peer_sort_t new_sort;
332 bgp_peer_sort_t exist_sort;
paul718e3742002-12-13 20:15:29 +0000333 u_int32_t new_pref;
334 u_int32_t exist_pref;
335 u_int32_t new_med;
336 u_int32_t exist_med;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000337 u_int32_t new_weight;
338 u_int32_t exist_weight;
339 uint32_t newm, existm;
paul718e3742002-12-13 20:15:29 +0000340 struct in_addr new_id;
341 struct in_addr exist_id;
342 int new_cluster;
343 int exist_cluster;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000344 int internal_as_route;
345 int confed_as_route;
paul718e3742002-12-13 20:15:29 +0000346 int ret;
Josh Bailey96450fa2011-07-20 20:45:12 -0700347
348 *paths_eq = 0;
paul718e3742002-12-13 20:15:29 +0000349
350 /* 0. Null check. */
351 if (new == NULL)
352 return 0;
353 if (exist == NULL)
354 return 1;
355
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)
paul718e3742002-12-13 20:15:29 +0000370 return 1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000371 if (new_weight < exist_weight)
paul718e3742002-12-13 20:15:29 +0000372 return 0;
373
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)
383 return 1;
384 if (new_pref < exist_pref)
385 return 0;
386
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))
393 return 1;
394 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
395 return 0;
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))
hasso68118452005-04-08 15:40:36 +0000411 return 1;
paulfe69a502005-09-10 16:55:02 +0000412 if ( aspath_hops > (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000413 return 0;
414 }
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)
hasso68118452005-04-08 15:40:36 +0000420 return 1;
paulfe69a502005-09-10 16:55:02 +0000421 if (newhops > exist_hops)
hasso68118452005-04-08 15:40:36 +0000422 return 0;
423 }
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)
paul718e3742002-12-13 20:15:29 +0000428 return 1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000429 if (newattr->origin > existattr->origin)
paul718e3742002-12-13 20:15:29 +0000430 return 0;
431
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)
451 return 1;
452 if (new_med > exist_med)
453 return 0;
454 }
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))
paul718e3742002-12-13 20:15:29 +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))
paul718e3742002-12-13 20:15:29 +0000465 return 0;
466
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)
476 ret = 1;
477 if (newm > existm)
478 ret = 0;
paul718e3742002-12-13 20:15:29 +0000479
480 /* 9. Maximum path check. */
Josh Bailey96450fa2011-07-20 20:45:12 -0700481 if (newm == existm)
482 {
Pradosh Mohapatra2fdd4552013-09-07 07:02:36 +0000483 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
484 {
485
486 /*
487 * For the two paths, all comparison steps till IGP metric
488 * have succeeded - including AS_PATH hop count. Since 'bgp
489 * bestpath as-path multipath-relax' knob is on, we don't need
490 * an exact match of AS_PATH. Thus, mark the paths are equal.
491 * That will trigger both these paths to get into the multipath
492 * array.
493 */
494 *paths_eq = 1;
495 }
496 else if (new->peer->sort == BGP_PEER_IBGP)
Josh Bailey96450fa2011-07-20 20:45:12 -0700497 {
498 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
499 *paths_eq = 1;
500 }
501 else if (new->peer->as == exist->peer->as)
502 *paths_eq = 1;
503 }
504 else
505 {
506 /*
507 * TODO: If unequal cost ibgp multipath is enabled we can
508 * mark the paths as equal here instead of returning
509 */
510 return ret;
511 }
paul718e3742002-12-13 20:15:29 +0000512
513 /* 10. If both paths are external, prefer the path that was received
514 first (the oldest one). This step minimizes route-flap, since a
515 newer path won't displace an older one, even if it was the
516 preferred route based on the additional decision criteria below. */
517 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000518 && new_sort == BGP_PEER_EBGP
519 && exist_sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +0000520 {
521 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
522 return 1;
523 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
524 return 0;
525 }
526
527 /* 11. Rourter-ID comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000528 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
529 new_id.s_addr = newattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000530 else
531 new_id.s_addr = new->peer->remote_id.s_addr;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000532 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
533 exist_id.s_addr = existattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000534 else
535 exist_id.s_addr = exist->peer->remote_id.s_addr;
536
537 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
538 return 1;
539 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
540 return 0;
541
542 /* 12. Cluster length comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000543 new_cluster = exist_cluster = 0;
544
545 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
546 new_cluster = newattre->cluster->length;
547 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
548 exist_cluster = existattre->cluster->length;
paul718e3742002-12-13 20:15:29 +0000549
550 if (new_cluster < exist_cluster)
551 return 1;
552 if (new_cluster > exist_cluster)
553 return 0;
554
555 /* 13. Neighbor address comparision. */
556 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
557
558 if (ret == 1)
559 return 0;
560 if (ret == -1)
561 return 1;
562
563 return 1;
564}
565
paul94f2b392005-06-28 12:44:16 +0000566static enum filter_type
paul718e3742002-12-13 20:15:29 +0000567bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
568 afi_t afi, safi_t safi)
569{
570 struct bgp_filter *filter;
571
572 filter = &peer->filter[afi][safi];
573
Paul Jakma650f76c2009-06-25 18:06:31 +0100574#define FILTER_EXIST_WARN(F,f,filter) \
575 if (BGP_DEBUG (update, UPDATE_IN) \
576 && !(F ## _IN (filter))) \
577 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
578 peer->host, #f, F ## _IN_NAME(filter));
579
580 if (DISTRIBUTE_IN_NAME (filter)) {
581 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
582
paul718e3742002-12-13 20:15:29 +0000583 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
584 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100585 }
paul718e3742002-12-13 20:15:29 +0000586
Paul Jakma650f76c2009-06-25 18:06:31 +0100587 if (PREFIX_LIST_IN_NAME (filter)) {
588 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
589
paul718e3742002-12-13 20:15:29 +0000590 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
591 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100592 }
paul718e3742002-12-13 20:15:29 +0000593
Paul Jakma650f76c2009-06-25 18:06:31 +0100594 if (FILTER_LIST_IN_NAME (filter)) {
595 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
596
paul718e3742002-12-13 20:15:29 +0000597 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
598 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100599 }
600
paul718e3742002-12-13 20:15:29 +0000601 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100602#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000603}
604
paul94f2b392005-06-28 12:44:16 +0000605static enum filter_type
paul718e3742002-12-13 20:15:29 +0000606bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
607 afi_t afi, safi_t safi)
608{
609 struct bgp_filter *filter;
610
611 filter = &peer->filter[afi][safi];
612
Paul Jakma650f76c2009-06-25 18:06:31 +0100613#define FILTER_EXIST_WARN(F,f,filter) \
614 if (BGP_DEBUG (update, UPDATE_OUT) \
615 && !(F ## _OUT (filter))) \
616 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
617 peer->host, #f, F ## _OUT_NAME(filter));
618
619 if (DISTRIBUTE_OUT_NAME (filter)) {
620 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
621
paul718e3742002-12-13 20:15:29 +0000622 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
623 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100624 }
paul718e3742002-12-13 20:15:29 +0000625
Paul Jakma650f76c2009-06-25 18:06:31 +0100626 if (PREFIX_LIST_OUT_NAME (filter)) {
627 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
628
paul718e3742002-12-13 20:15:29 +0000629 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
630 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100631 }
paul718e3742002-12-13 20:15:29 +0000632
Paul Jakma650f76c2009-06-25 18:06:31 +0100633 if (FILTER_LIST_OUT_NAME (filter)) {
634 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
635
paul718e3742002-12-13 20:15:29 +0000636 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
637 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100638 }
paul718e3742002-12-13 20:15:29 +0000639
640 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100641#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000642}
643
644/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000645static int
paul718e3742002-12-13 20:15:29 +0000646bgp_community_filter (struct peer *peer, struct attr *attr)
647{
648 if (attr->community)
649 {
650 /* NO_ADVERTISE check. */
651 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
652 return 1;
653
654 /* NO_EXPORT check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000655 if (peer->sort == BGP_PEER_EBGP &&
paul718e3742002-12-13 20:15:29 +0000656 community_include (attr->community, COMMUNITY_NO_EXPORT))
657 return 1;
658
659 /* NO_EXPORT_SUBCONFED check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000660 if (peer->sort == BGP_PEER_EBGP
661 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000662 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
663 return 1;
664 }
665 return 0;
666}
667
668/* Route reflection loop check. */
669static int
670bgp_cluster_filter (struct peer *peer, struct attr *attr)
671{
672 struct in_addr cluster_id;
673
Paul Jakmafb982c22007-05-04 20:15:47 +0000674 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000675 {
676 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
677 cluster_id = peer->bgp->cluster_id;
678 else
679 cluster_id = peer->bgp->router_id;
680
Paul Jakmafb982c22007-05-04 20:15:47 +0000681 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000682 return 1;
683 }
684 return 0;
685}
David Lamparter6b0655a2014-06-04 06:53:35 +0200686
paul94f2b392005-06-28 12:44:16 +0000687static int
paul718e3742002-12-13 20:15:29 +0000688bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
689 afi_t afi, safi_t safi)
690{
691 struct bgp_filter *filter;
692 struct bgp_info info;
693 route_map_result_t ret;
694
695 filter = &peer->filter[afi][safi];
696
697 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000698 if (peer->weight)
699 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000700
701 /* Route map apply. */
702 if (ROUTE_MAP_IN_NAME (filter))
703 {
704 /* Duplicate current value to new strucutre for modification. */
705 info.peer = peer;
706 info.attr = attr;
707
paulac41b2a2003-08-12 05:32:27 +0000708 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
709
paul718e3742002-12-13 20:15:29 +0000710 /* Apply BGP route map to the attribute. */
711 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000712
713 peer->rmap_type = 0;
714
paul718e3742002-12-13 20:15:29 +0000715 if (ret == RMAP_DENYMATCH)
716 {
717 /* Free newly generated AS path and community by route-map. */
718 bgp_attr_flush (attr);
719 return RMAP_DENY;
720 }
721 }
722 return RMAP_PERMIT;
723}
David Lamparter6b0655a2014-06-04 06:53:35 +0200724
paul94f2b392005-06-28 12:44:16 +0000725static int
paulfee0f4c2004-09-13 05:12:46 +0000726bgp_export_modifier (struct peer *rsclient, struct peer *peer,
727 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
728{
729 struct bgp_filter *filter;
730 struct bgp_info info;
731 route_map_result_t ret;
732
733 filter = &peer->filter[afi][safi];
734
735 /* Route map apply. */
736 if (ROUTE_MAP_EXPORT_NAME (filter))
737 {
738 /* Duplicate current value to new strucutre for modification. */
739 info.peer = rsclient;
740 info.attr = attr;
741
742 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
743
744 /* Apply BGP route map to the attribute. */
745 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
746
747 rsclient->rmap_type = 0;
748
749 if (ret == RMAP_DENYMATCH)
750 {
751 /* Free newly generated AS path and community by route-map. */
752 bgp_attr_flush (attr);
753 return RMAP_DENY;
754 }
755 }
756 return RMAP_PERMIT;
757}
758
paul94f2b392005-06-28 12:44:16 +0000759static int
paulfee0f4c2004-09-13 05:12:46 +0000760bgp_import_modifier (struct peer *rsclient, struct peer *peer,
761 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
762{
763 struct bgp_filter *filter;
764 struct bgp_info info;
765 route_map_result_t ret;
766
767 filter = &rsclient->filter[afi][safi];
768
769 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000770 if (peer->weight)
771 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000772
773 /* Route map apply. */
774 if (ROUTE_MAP_IMPORT_NAME (filter))
775 {
776 /* Duplicate current value to new strucutre for modification. */
777 info.peer = peer;
778 info.attr = attr;
779
780 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
781
782 /* Apply BGP route map to the attribute. */
783 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
784
785 peer->rmap_type = 0;
786
787 if (ret == RMAP_DENYMATCH)
788 {
789 /* Free newly generated AS path and community by route-map. */
790 bgp_attr_flush (attr);
791 return RMAP_DENY;
792 }
793 }
794 return RMAP_PERMIT;
795}
David Lamparter6b0655a2014-06-04 06:53:35 +0200796
paul94f2b392005-06-28 12:44:16 +0000797static int
paul718e3742002-12-13 20:15:29 +0000798bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
799 struct attr *attr, afi_t afi, safi_t safi)
800{
801 int ret;
802 char buf[SU_ADDRSTRLEN];
803 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000804 struct peer *from;
805 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000806 int transparent;
807 int reflect;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700808 struct attr *riattr;
paul718e3742002-12-13 20:15:29 +0000809
810 from = ri->peer;
811 filter = &peer->filter[afi][safi];
812 bgp = peer->bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700813 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paul718e3742002-12-13 20:15:29 +0000814
Paul Jakma750e8142008-07-22 21:11:48 +0000815 if (DISABLE_BGP_ANNOUNCE)
816 return 0;
paul718e3742002-12-13 20:15:29 +0000817
paulfee0f4c2004-09-13 05:12:46 +0000818 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
819 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
820 return 0;
821
paul718e3742002-12-13 20:15:29 +0000822 /* Do not send back route to sender. */
823 if (from == peer)
824 return 0;
825
826 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000827 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000828 if (! UNSUPPRESS_MAP_NAME (filter))
829 return 0;
830
831 /* Default route check. */
832 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
833 {
834 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
835 return 0;
836#ifdef HAVE_IPV6
837 else if (p->family == AF_INET6 && p->prefixlen == 0)
838 return 0;
839#endif /* HAVE_IPV6 */
840 }
841
paul286e1e72003-08-08 00:24:31 +0000842 /* Transparency check. */
843 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
844 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
845 transparent = 1;
846 else
847 transparent = 0;
848
paul718e3742002-12-13 20:15:29 +0000849 /* If community is not disabled check the no-export and local. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700850 if (! transparent && bgp_community_filter (peer, riattr))
paul718e3742002-12-13 20:15:29 +0000851 return 0;
852
853 /* If the attribute has originator-id and it is same as remote
854 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700855 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paul718e3742002-12-13 20:15:29 +0000856 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700857 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000858 {
859 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000860 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000861 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
862 peer->host,
863 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
864 p->prefixlen);
865 return 0;
866 }
867 }
868
869 /* ORF prefix-list filter check */
870 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
871 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
872 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
873 if (peer->orf_plist[afi][safi])
874 {
875 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
876 return 0;
877 }
878
879 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700880 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
paul718e3742002-12-13 20:15:29 +0000881 {
882 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000883 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000884 "%s [Update:SEND] %s/%d is filtered",
885 peer->host,
886 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
887 p->prefixlen);
888 return 0;
889 }
890
891#ifdef BGP_SEND_ASPATH_CHECK
892 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700893 if (aspath_loop_check (riattr->aspath, peer->as))
paul718e3742002-12-13 20:15:29 +0000894 {
895 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000896 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400897 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000898 peer->host, peer->as);
899 return 0;
900 }
901#endif /* BGP_SEND_ASPATH_CHECK */
902
903 /* If we're a CONFED we need to loop check the CONFED ID too */
904 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
905 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700906 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
paul718e3742002-12-13 20:15:29 +0000907 {
908 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000909 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400910 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000911 peer->host,
912 bgp->confed_id);
913 return 0;
914 }
915 }
916
917 /* Route-Reflect check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000918 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +0000919 reflect = 1;
920 else
921 reflect = 0;
922
923 /* IBGP reflection check. */
924 if (reflect)
925 {
926 /* A route from a Client peer. */
927 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
928 {
929 /* Reflect to all the Non-Client peers and also to the
930 Client peers other than the originator. Originator check
931 is already done. So there is noting to do. */
932 /* no bgp client-to-client reflection check. */
933 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
934 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
935 return 0;
936 }
937 else
938 {
939 /* A route from a Non-client peer. Reflect to all other
940 clients. */
941 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
942 return 0;
943 }
944 }
Paul Jakma41367172007-08-06 15:24:51 +0000945
paul718e3742002-12-13 20:15:29 +0000946 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700947 bgp_attr_dup (attr, riattr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000948
paul718e3742002-12-13 20:15:29 +0000949 /* If local-preference is not set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000950 if ((peer->sort == BGP_PEER_IBGP
951 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000952 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
953 {
954 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
955 attr->local_pref = bgp->default_local_pref;
956 }
957
Pradosh Mohapatra689bb662013-09-07 07:13:37 +0000958 /* If originator-id is not set and the route is to be reflected,
959 set the originator id */
960 if (peer && from && peer->sort == BGP_PEER_IBGP &&
961 from->sort == BGP_PEER_IBGP &&
962 (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
963 {
964 attr->extra = bgp_attr_extra_get(attr);
965 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
966 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
967 }
968
paul718e3742002-12-13 20:15:29 +0000969 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000970 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000971 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
972 {
973 if (ri->peer != bgp->peer_self && ! transparent
974 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
975 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
976 }
977
978 /* next-hop-set */
979 if (transparent || reflect
980 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
981 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000982#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000983 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000984 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000985#endif /* HAVE_IPV6 */
986 )))
paul718e3742002-12-13 20:15:29 +0000987 {
988 /* NEXT-HOP Unchanged. */
989 }
990 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
991 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
992#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000993 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000994 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000995#endif /* HAVE_IPV6 */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000996 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000997 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
998 {
999 /* Set IPv4 nexthop. */
1000 if (p->family == AF_INET)
1001 {
1002 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001003 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1004 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +00001005 else
1006 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1007 }
1008#ifdef HAVE_IPV6
1009 /* Set IPv6 nexthop. */
1010 if (p->family == AF_INET6)
1011 {
1012 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001013 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001014 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001015 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001016 }
1017#endif /* HAVE_IPV6 */
1018 }
1019
1020#ifdef HAVE_IPV6
1021 if (p->family == AF_INET6)
1022 {
paulfee0f4c2004-09-13 05:12:46 +00001023 /* Left nexthop_local unchanged if so configured. */
1024 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1025 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1026 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001027 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1028 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001029 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001030 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001031 }
1032
1033 /* Default nexthop_local treatment for non-RS-Clients */
1034 else
1035 {
paul718e3742002-12-13 20:15:29 +00001036 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001037 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001038
1039 /* Set link-local address for shared network peer. */
1040 if (peer->shared_network
1041 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1042 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001043 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001044 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001045 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001046 }
1047
1048 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1049 address.*/
1050 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001051 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001052
1053 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1054 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001055 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001056 }
paulfee0f4c2004-09-13 05:12:46 +00001057
1058 }
paul718e3742002-12-13 20:15:29 +00001059#endif /* HAVE_IPV6 */
1060
1061 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001062 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001063 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1064 && aspath_private_as_check (attr->aspath))
1065 attr->aspath = aspath_empty_get ();
1066
1067 /* Route map & unsuppress-map apply. */
1068 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001069 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001070 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001071 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001072 struct attr dummy_attr;
1073 struct attr_extra dummy_extra;
1074
1075 dummy_attr.extra = &dummy_extra;
1076
paul718e3742002-12-13 20:15:29 +00001077 info.peer = peer;
1078 info.attr = attr;
1079
1080 /* The route reflector is not allowed to modify the attributes
1081 of the reflected IBGP routes. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001082 if (from->sort == BGP_PEER_IBGP
1083 && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +00001084 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001085 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001086 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001087 }
paulac41b2a2003-08-12 05:32:27 +00001088
1089 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1090
Paul Jakmafb982c22007-05-04 20:15:47 +00001091 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001092 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1093 else
1094 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1095
paulac41b2a2003-08-12 05:32:27 +00001096 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001097
paul718e3742002-12-13 20:15:29 +00001098 if (ret == RMAP_DENYMATCH)
1099 {
1100 bgp_attr_flush (attr);
1101 return 0;
1102 }
1103 }
1104 return 1;
1105}
1106
paul94f2b392005-06-28 12:44:16 +00001107static int
paulfee0f4c2004-09-13 05:12:46 +00001108bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1109 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001110{
paulfee0f4c2004-09-13 05:12:46 +00001111 int ret;
1112 char buf[SU_ADDRSTRLEN];
1113 struct bgp_filter *filter;
1114 struct bgp_info info;
1115 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001116 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001117
1118 from = ri->peer;
1119 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001120 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001121
Paul Jakma750e8142008-07-22 21:11:48 +00001122 if (DISABLE_BGP_ANNOUNCE)
1123 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001124
1125 /* Do not send back route to sender. */
1126 if (from == rsclient)
1127 return 0;
1128
1129 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001130 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001131 if (! UNSUPPRESS_MAP_NAME (filter))
1132 return 0;
1133
1134 /* Default route check. */
1135 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1136 PEER_STATUS_DEFAULT_ORIGINATE))
1137 {
1138 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1139 return 0;
1140#ifdef HAVE_IPV6
1141 else if (p->family == AF_INET6 && p->prefixlen == 0)
1142 return 0;
1143#endif /* HAVE_IPV6 */
1144 }
1145
1146 /* If the attribute has originator-id and it is same as remote
1147 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001148 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001149 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001150 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001151 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001152 {
1153 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001154 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001155 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1156 rsclient->host,
1157 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1158 p->prefixlen);
1159 return 0;
1160 }
1161 }
1162
1163 /* ORF prefix-list filter check */
1164 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1165 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1166 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1167 if (rsclient->orf_plist[afi][safi])
1168 {
1169 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1170 return 0;
1171 }
1172
1173 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001174 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001175 {
1176 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001177 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001178 "%s [Update:SEND] %s/%d is filtered",
1179 rsclient->host,
1180 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1181 p->prefixlen);
1182 return 0;
1183 }
1184
1185#ifdef BGP_SEND_ASPATH_CHECK
1186 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001187 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001188 {
1189 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001190 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001191 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001192 rsclient->host, rsclient->as);
1193 return 0;
1194 }
1195#endif /* BGP_SEND_ASPATH_CHECK */
1196
1197 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001198 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001199
1200 /* next-hop-set */
1201 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1202#ifdef HAVE_IPV6
1203 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001204 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001205#endif /* HAVE_IPV6 */
1206 )
1207 {
1208 /* Set IPv4 nexthop. */
1209 if (p->family == AF_INET)
1210 {
1211 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001212 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001213 IPV4_MAX_BYTELEN);
1214 else
1215 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1216 }
1217#ifdef HAVE_IPV6
1218 /* Set IPv6 nexthop. */
1219 if (p->family == AF_INET6)
1220 {
1221 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001222 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001223 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001224 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001225 }
1226#endif /* HAVE_IPV6 */
1227 }
1228
1229#ifdef HAVE_IPV6
1230 if (p->family == AF_INET6)
1231 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001232 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001233
paulfee0f4c2004-09-13 05:12:46 +00001234 /* Left nexthop_local unchanged if so configured. */
1235 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1236 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1237 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001238 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1239 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001240 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001241 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001242 }
1243
1244 /* Default nexthop_local treatment for RS-Clients */
1245 else
1246 {
1247 /* Announcer and RS-Client are both in the same network */
1248 if (rsclient->shared_network && from->shared_network &&
1249 (rsclient->ifindex == from->ifindex))
1250 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001251 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1252 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001253 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001254 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001255 }
1256
1257 /* Set link-local address for shared network peer. */
1258 else if (rsclient->shared_network
1259 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1260 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001261 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001262 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001263 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001264 }
1265
1266 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001267 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001268 }
1269
1270 }
1271#endif /* HAVE_IPV6 */
1272
1273
1274 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001275 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001276 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1277 && aspath_private_as_check (attr->aspath))
1278 attr->aspath = aspath_empty_get ();
1279
1280 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001281 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001282 {
1283 info.peer = rsclient;
1284 info.attr = attr;
1285
1286 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1287
Paul Jakmafb982c22007-05-04 20:15:47 +00001288 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001289 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1290 else
1291 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1292
1293 rsclient->rmap_type = 0;
1294
1295 if (ret == RMAP_DENYMATCH)
1296 {
1297 bgp_attr_flush (attr);
1298 return 0;
1299 }
1300 }
1301
1302 return 1;
1303}
1304
1305struct bgp_info_pair
1306{
1307 struct bgp_info *old;
1308 struct bgp_info *new;
1309};
1310
paul94f2b392005-06-28 12:44:16 +00001311static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001312bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1313 struct bgp_maxpaths_cfg *mpath_cfg,
1314 struct bgp_info_pair *result)
paulfee0f4c2004-09-13 05:12:46 +00001315{
paul718e3742002-12-13 20:15:29 +00001316 struct bgp_info *new_select;
1317 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001318 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001319 struct bgp_info *ri1;
1320 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001321 struct bgp_info *nextri = NULL;
Josh Bailey96450fa2011-07-20 20:45:12 -07001322 int paths_eq, do_mpath;
1323 struct list mp_list;
1324
1325 bgp_mp_list_init (&mp_list);
1326 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1327 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1328
paul718e3742002-12-13 20:15:29 +00001329 /* bgp deterministic-med */
1330 new_select = NULL;
1331 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1332 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1333 {
1334 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1335 continue;
1336 if (BGP_INFO_HOLDDOWN (ri1))
1337 continue;
1338
1339 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001340 if (do_mpath)
1341 bgp_mp_list_add (&mp_list, ri1);
1342 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001343 if (ri1->next)
1344 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1345 {
1346 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1347 continue;
1348 if (BGP_INFO_HOLDDOWN (ri2))
1349 continue;
1350
1351 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1352 || aspath_cmp_left_confed (ri1->attr->aspath,
1353 ri2->attr->aspath))
1354 {
Josh Bailey6918e742011-07-20 20:48:20 -07001355 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1356 old_select = ri2;
Josh Bailey96450fa2011-07-20 20:45:12 -07001357 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
paul718e3742002-12-13 20:15:29 +00001358 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001359 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001360 new_select = ri2;
Josh Bailey6918e742011-07-20 20:48:20 -07001361 if (do_mpath && !paths_eq)
1362 {
1363 bgp_mp_list_clear (&mp_list);
1364 bgp_mp_list_add (&mp_list, ri2);
1365 }
paul718e3742002-12-13 20:15:29 +00001366 }
1367
Josh Bailey6918e742011-07-20 20:48:20 -07001368 if (do_mpath && paths_eq)
1369 bgp_mp_list_add (&mp_list, ri2);
1370
Paul Jakma1a392d42006-09-07 00:24:49 +00001371 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001372 }
1373 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001374 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1375 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001376
1377 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1378 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001379 }
1380
1381 /* Check old selected route and new selected route. */
1382 old_select = NULL;
1383 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001384 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001385 {
1386 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1387 old_select = ri;
1388
1389 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001390 {
1391 /* reap REMOVED routes, if needs be
1392 * selected route must stay for a while longer though
1393 */
1394 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1395 && (ri != old_select))
1396 bgp_info_reap (rn, ri);
1397
1398 continue;
1399 }
paul718e3742002-12-13 20:15:29 +00001400
1401 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1402 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1403 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001404 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001405 continue;
1406 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001407 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1408 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001409
Josh Bailey96450fa2011-07-20 20:45:12 -07001410 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1411 {
Josh Bailey6918e742011-07-20 20:48:20 -07001412 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1413 bgp_mp_dmed_deselect (new_select);
1414
Josh Bailey96450fa2011-07-20 20:45:12 -07001415 new_select = ri;
1416
1417 if (do_mpath && !paths_eq)
1418 {
1419 bgp_mp_list_clear (&mp_list);
1420 bgp_mp_list_add (&mp_list, ri);
1421 }
1422 }
Josh Bailey6918e742011-07-20 20:48:20 -07001423 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1424 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001425
1426 if (do_mpath && paths_eq)
1427 bgp_mp_list_add (&mp_list, ri);
paul718e3742002-12-13 20:15:29 +00001428 }
paulb40d9392005-08-22 22:34:41 +00001429
paulfee0f4c2004-09-13 05:12:46 +00001430
Josh Bailey6918e742011-07-20 20:48:20 -07001431 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1432 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
Josh Bailey96450fa2011-07-20 20:45:12 -07001433
Josh Bailey0b597ef2011-07-20 20:49:11 -07001434 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001435 bgp_mp_list_clear (&mp_list);
1436
1437 result->old = old_select;
1438 result->new = new_select;
1439
1440 return;
paulfee0f4c2004-09-13 05:12:46 +00001441}
1442
paul94f2b392005-06-28 12:44:16 +00001443static int
paulfee0f4c2004-09-13 05:12:46 +00001444bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001445 struct bgp_node *rn, afi_t afi, safi_t safi)
1446{
paulfee0f4c2004-09-13 05:12:46 +00001447 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001448 struct attr attr;
1449 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001450
1451 p = &rn->p;
1452
Paul Jakma9eda90c2007-08-30 13:36:17 +00001453 /* Announce route to Established peer. */
1454 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001455 return 0;
1456
Paul Jakma9eda90c2007-08-30 13:36:17 +00001457 /* Address family configuration check. */
1458 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001459 return 0;
1460
Paul Jakma9eda90c2007-08-30 13:36:17 +00001461 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001462 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1463 PEER_STATUS_ORF_WAIT_REFRESH))
1464 return 0;
1465
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001466 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1467 attr.extra = &extra;
1468
Avneesh Sachdev67174042012-08-17 08:19:49 -07001469 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001470 {
1471 case BGP_TABLE_MAIN:
1472 /* Announcement to peer->conf. If the route is filtered,
1473 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001474 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1475 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001476 else
1477 bgp_adj_out_unset (rn, peer, p, afi, safi);
1478 break;
1479 case BGP_TABLE_RSCLIENT:
1480 /* Announcement to peer->conf. If the route is filtered,
1481 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001482 if (selected &&
1483 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1484 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1485 else
1486 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001487 break;
1488 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001489
paulfee0f4c2004-09-13 05:12:46 +00001490 return 0;
paul200df112005-06-01 11:17:05 +00001491}
paulfee0f4c2004-09-13 05:12:46 +00001492
paul200df112005-06-01 11:17:05 +00001493struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001494{
paul200df112005-06-01 11:17:05 +00001495 struct bgp *bgp;
1496 struct bgp_node *rn;
1497 afi_t afi;
1498 safi_t safi;
1499};
1500
1501static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001502bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001503{
paul0fb58d52005-11-14 14:31:49 +00001504 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001505 struct bgp *bgp = pq->bgp;
1506 struct bgp_node *rn = pq->rn;
1507 afi_t afi = pq->afi;
1508 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001509 struct bgp_info *new_select;
1510 struct bgp_info *old_select;
1511 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001512 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001513 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001514
paulfee0f4c2004-09-13 05:12:46 +00001515 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001516 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001517 new_select = old_and_new.new;
1518 old_select = old_and_new.old;
1519
paul200df112005-06-01 11:17:05 +00001520 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1521 {
Chris Caputo228da422009-07-18 05:44:03 +00001522 if (rsclient->group)
1523 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1524 {
1525 /* Nothing to do. */
1526 if (old_select && old_select == new_select)
1527 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1528 continue;
paulfee0f4c2004-09-13 05:12:46 +00001529
Chris Caputo228da422009-07-18 05:44:03 +00001530 if (old_select)
1531 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1532 if (new_select)
1533 {
1534 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1535 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001536 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1537 }
paulfee0f4c2004-09-13 05:12:46 +00001538
Chris Caputo228da422009-07-18 05:44:03 +00001539 bgp_process_announce_selected (rsclient, new_select, rn,
1540 afi, safi);
1541 }
paul200df112005-06-01 11:17:05 +00001542 }
1543 else
1544 {
hassob7395792005-08-26 12:58:38 +00001545 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001546 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001547 if (new_select)
1548 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001549 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1550 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001551 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001552 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001553 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001554 }
paulfee0f4c2004-09-13 05:12:46 +00001555
paulb40d9392005-08-22 22:34:41 +00001556 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1557 bgp_info_reap (rn, old_select);
1558
paul200df112005-06-01 11:17:05 +00001559 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1560 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001561}
1562
paul200df112005-06-01 11:17:05 +00001563static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001564bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001565{
paul0fb58d52005-11-14 14:31:49 +00001566 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001567 struct bgp *bgp = pq->bgp;
1568 struct bgp_node *rn = pq->rn;
1569 afi_t afi = pq->afi;
1570 safi_t safi = pq->safi;
1571 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001572 struct bgp_info *new_select;
1573 struct bgp_info *old_select;
1574 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001575 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001576 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001577
paulfee0f4c2004-09-13 05:12:46 +00001578 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001579 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001580 old_select = old_and_new.old;
1581 new_select = old_and_new.new;
1582
1583 /* Nothing to do. */
1584 if (old_select && old_select == new_select)
1585 {
1586 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001587 {
Josh Bailey8196f132011-07-20 20:47:07 -07001588 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1589 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001590 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001591
Josh Bailey8196f132011-07-20 20:47:07 -07001592 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001593 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1594 return WQ_SUCCESS;
1595 }
paulfee0f4c2004-09-13 05:12:46 +00001596 }
paul718e3742002-12-13 20:15:29 +00001597
hasso338b3422005-02-23 14:27:24 +00001598 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001599 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001600 if (new_select)
1601 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001602 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1603 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001604 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001605 }
1606
1607
paul718e3742002-12-13 20:15:29 +00001608 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001609 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001610 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001611 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001612 }
1613
1614 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001615 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1616 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001617 {
1618 if (new_select
1619 && new_select->type == ZEBRA_ROUTE_BGP
1620 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001621 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001622 else
1623 {
1624 /* Withdraw the route from the kernel. */
1625 if (old_select
1626 && old_select->type == ZEBRA_ROUTE_BGP
1627 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001628 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001629 }
1630 }
paulb40d9392005-08-22 22:34:41 +00001631
1632 /* Reap old select bgp_info, it it has been removed */
1633 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1634 bgp_info_reap (rn, old_select);
1635
paul200df112005-06-01 11:17:05 +00001636 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1637 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001638}
1639
paul200df112005-06-01 11:17:05 +00001640static void
paul0fb58d52005-11-14 14:31:49 +00001641bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001642{
paul0fb58d52005-11-14 14:31:49 +00001643 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001644 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001645
Chris Caputo228da422009-07-18 05:44:03 +00001646 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001647 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001648 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001649 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1650}
1651
1652static void
1653bgp_process_queue_init (void)
1654{
1655 bm->process_main_queue
1656 = work_queue_new (bm->master, "process_main_queue");
1657 bm->process_rsclient_queue
1658 = work_queue_new (bm->master, "process_rsclient_queue");
1659
1660 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1661 {
1662 zlog_err ("%s: Failed to allocate work queue", __func__);
1663 exit (1);
1664 }
1665
1666 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001667 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001668 bm->process_main_queue->spec.max_retries = 0;
1669 bm->process_main_queue->spec.hold = 50;
1670
1671 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1672 sizeof (struct work_queue *));
1673 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
paul200df112005-06-01 11:17:05 +00001674}
1675
1676void
paulfee0f4c2004-09-13 05:12:46 +00001677bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1678{
paul200df112005-06-01 11:17:05 +00001679 struct bgp_process_queue *pqnode;
1680
1681 /* already scheduled for processing? */
1682 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1683 return;
1684
1685 if ( (bm->process_main_queue == NULL) ||
1686 (bm->process_rsclient_queue == NULL) )
1687 bgp_process_queue_init ();
1688
1689 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1690 sizeof (struct bgp_process_queue));
1691 if (!pqnode)
1692 return;
Chris Caputo228da422009-07-18 05:44:03 +00001693
1694 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001695 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001696 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001697 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001698 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001699 pqnode->afi = afi;
1700 pqnode->safi = safi;
1701
Avneesh Sachdev67174042012-08-17 08:19:49 -07001702 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001703 {
paul200df112005-06-01 11:17:05 +00001704 case BGP_TABLE_MAIN:
1705 work_queue_add (bm->process_main_queue, pqnode);
1706 break;
1707 case BGP_TABLE_RSCLIENT:
1708 work_queue_add (bm->process_rsclient_queue, pqnode);
1709 break;
paulfee0f4c2004-09-13 05:12:46 +00001710 }
paul200df112005-06-01 11:17:05 +00001711
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001712 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001713 return;
paulfee0f4c2004-09-13 05:12:46 +00001714}
hasso0a486e52005-02-01 20:57:17 +00001715
paul94f2b392005-06-28 12:44:16 +00001716static int
hasso0a486e52005-02-01 20:57:17 +00001717bgp_maximum_prefix_restart_timer (struct thread *thread)
1718{
1719 struct peer *peer;
1720
1721 peer = THREAD_ARG (thread);
1722 peer->t_pmax_restart = NULL;
1723
1724 if (BGP_DEBUG (events, EVENTS))
1725 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1726 peer->host);
1727
1728 peer_clear (peer);
1729
1730 return 0;
1731}
1732
paulfee0f4c2004-09-13 05:12:46 +00001733int
paul5228ad22004-06-04 17:58:18 +00001734bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1735 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001736{
hassoe0701b72004-05-20 09:19:34 +00001737 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1738 return 0;
1739
1740 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001741 {
hassoe0701b72004-05-20 09:19:34 +00001742 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1743 && ! always)
1744 return 0;
paul718e3742002-12-13 20:15:29 +00001745
hassoe0701b72004-05-20 09:19:34 +00001746 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001747 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1748 "limit %ld", afi_safi_print (afi, safi), peer->host,
1749 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001750 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001751
hassoe0701b72004-05-20 09:19:34 +00001752 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1753 return 0;
paul718e3742002-12-13 20:15:29 +00001754
hassoe0701b72004-05-20 09:19:34 +00001755 {
paul5228ad22004-06-04 17:58:18 +00001756 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001757
1758 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001759 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001760
1761 ndata[0] = (afi >> 8);
1762 ndata[1] = afi;
1763 ndata[2] = safi;
1764 ndata[3] = (peer->pmax[afi][safi] >> 24);
1765 ndata[4] = (peer->pmax[afi][safi] >> 16);
1766 ndata[5] = (peer->pmax[afi][safi] >> 8);
1767 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001768
1769 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1770 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1771 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1772 }
hasso0a486e52005-02-01 20:57:17 +00001773
1774 /* restart timer start */
1775 if (peer->pmax_restart[afi][safi])
1776 {
1777 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1778
1779 if (BGP_DEBUG (events, EVENTS))
1780 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1781 peer->host, peer->v_pmax_restart);
1782
1783 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1784 peer->v_pmax_restart);
1785 }
1786
hassoe0701b72004-05-20 09:19:34 +00001787 return 1;
paul718e3742002-12-13 20:15:29 +00001788 }
hassoe0701b72004-05-20 09:19:34 +00001789 else
1790 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1791
1792 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1793 {
1794 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1795 && ! always)
1796 return 0;
1797
1798 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001799 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1800 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1801 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001802 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1803 }
1804 else
1805 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001806 return 0;
1807}
1808
paulb40d9392005-08-22 22:34:41 +00001809/* Unconditionally remove the route from the RIB, without taking
1810 * damping into consideration (eg, because the session went down)
1811 */
paul94f2b392005-06-28 12:44:16 +00001812static void
paul718e3742002-12-13 20:15:29 +00001813bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1814 afi_t afi, safi_t safi)
1815{
paul902212c2006-02-05 17:51:19 +00001816 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1817
1818 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1819 bgp_info_delete (rn, ri); /* keep historical info */
1820
paulb40d9392005-08-22 22:34:41 +00001821 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001822}
1823
paul94f2b392005-06-28 12:44:16 +00001824static void
paul718e3742002-12-13 20:15:29 +00001825bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001826 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001827{
paul718e3742002-12-13 20:15:29 +00001828 int status = BGP_DAMP_NONE;
1829
paulb40d9392005-08-22 22:34:41 +00001830 /* apply dampening, if result is suppressed, we'll be retaining
1831 * the bgp_info in the RIB for historical reference.
1832 */
1833 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001834 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001835 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1836 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001837 {
paul902212c2006-02-05 17:51:19 +00001838 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1839 return;
1840 }
1841
1842 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001843}
1844
paul94f2b392005-06-28 12:44:16 +00001845static void
paulfee0f4c2004-09-13 05:12:46 +00001846bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1847 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1848 int sub_type, struct prefix_rd *prd, u_char *tag)
1849{
1850 struct bgp_node *rn;
1851 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001852 struct attr new_attr;
1853 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001854 struct attr *attr_new;
1855 struct attr *attr_new2;
1856 struct bgp_info *ri;
1857 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001858 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001859 char buf[SU_ADDRSTRLEN];
1860
1861 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1862 if (peer == rsclient)
1863 return;
1864
1865 bgp = peer->bgp;
1866 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1867
1868 /* Check previously received route. */
1869 for (ri = rn->info; ri; ri = ri->next)
1870 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1871 break;
1872
1873 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001874 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001875 {
1876 reason = "as-path contains our own AS;";
1877 goto filtered;
1878 }
1879
1880 /* Route reflector originator ID check. */
1881 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001882 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001883 {
1884 reason = "originator is us;";
1885 goto filtered;
1886 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001887
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001888 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001889 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001890
1891 /* Apply export policy. */
1892 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1893 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1894 {
1895 reason = "export-policy;";
1896 goto filtered;
1897 }
1898
1899 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001900
paulfee0f4c2004-09-13 05:12:46 +00001901 /* Apply import policy. */
1902 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1903 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001904 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001905
1906 reason = "import-policy;";
1907 goto filtered;
1908 }
1909
1910 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001911 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001912
1913 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001914 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001915 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001916 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001917 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001918 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001919 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001920 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001921
1922 reason = "martian next-hop;";
1923 goto filtered;
1924 }
1925 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001926
paulfee0f4c2004-09-13 05:12:46 +00001927 /* If the update is implicit withdraw. */
1928 if (ri)
1929 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001930 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001931
1932 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001933 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1934 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001935 {
1936
Paul Jakma1a392d42006-09-07 00:24:49 +00001937 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001938
1939 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001940 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001941 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1942 peer->host,
1943 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1944 p->prefixlen, rsclient->host);
1945
Chris Caputo228da422009-07-18 05:44:03 +00001946 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001947 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001948
Chris Caputo228da422009-07-18 05:44:03 +00001949 return;
paulfee0f4c2004-09-13 05:12:46 +00001950 }
1951
Paul Jakma16d2e242007-04-10 19:32:10 +00001952 /* Withdraw/Announce before we fully processed the withdraw */
1953 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1954 bgp_info_restore (rn, ri);
1955
paulfee0f4c2004-09-13 05:12:46 +00001956 /* Received Logging. */
1957 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001958 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001959 peer->host,
1960 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1961 p->prefixlen, rsclient->host);
1962
1963 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001964 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001965
1966 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001967 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001968 ri->attr = attr_new;
1969
1970 /* Update MPLS tag. */
1971 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001972 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001973
Paul Jakma1a392d42006-09-07 00:24:49 +00001974 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001975
1976 /* Process change. */
1977 bgp_process (bgp, rn, afi, safi);
1978 bgp_unlock_node (rn);
1979
1980 return;
1981 }
1982
1983 /* Received Logging. */
1984 if (BGP_DEBUG (update, UPDATE_IN))
1985 {
ajsd2c1f162004-12-08 21:10:20 +00001986 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001987 peer->host,
1988 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1989 p->prefixlen, rsclient->host);
1990 }
1991
1992 /* Make new BGP info. */
1993 new = bgp_info_new ();
1994 new->type = type;
1995 new->sub_type = sub_type;
1996 new->peer = peer;
1997 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03001998 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001999
2000 /* Update MPLS tag. */
2001 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002002 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002003
Paul Jakma1a392d42006-09-07 00:24:49 +00002004 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002005
2006 /* Register new BGP information. */
2007 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002008
2009 /* route_node_get lock */
2010 bgp_unlock_node (rn);
2011
paulfee0f4c2004-09-13 05:12:46 +00002012 /* Process change. */
2013 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002014
paulfee0f4c2004-09-13 05:12:46 +00002015 return;
2016
2017 filtered:
2018
2019 /* This BGP update is filtered. Log the reason then update BGP entry. */
2020 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002021 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002022 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2023 peer->host,
2024 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2025 p->prefixlen, rsclient->host, reason);
2026
2027 if (ri)
paulb40d9392005-08-22 22:34:41 +00002028 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002029
2030 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002031
paulfee0f4c2004-09-13 05:12:46 +00002032 return;
2033}
2034
paul94f2b392005-06-28 12:44:16 +00002035static void
paulfee0f4c2004-09-13 05:12:46 +00002036bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2037 struct peer *peer, struct prefix *p, int type, int sub_type,
2038 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002039{
paulfee0f4c2004-09-13 05:12:46 +00002040 struct bgp_node *rn;
2041 struct bgp_info *ri;
2042 char buf[SU_ADDRSTRLEN];
2043
2044 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002045 return;
paulfee0f4c2004-09-13 05:12:46 +00002046
2047 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2048
2049 /* Lookup withdrawn route. */
2050 for (ri = rn->info; ri; ri = ri->next)
2051 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2052 break;
2053
2054 /* Withdraw specified route from routing table. */
2055 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002056 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002057 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002058 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002059 "%s Can't find the route %s/%d", peer->host,
2060 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2061 p->prefixlen);
2062
2063 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002064 bgp_unlock_node (rn);
2065}
paulfee0f4c2004-09-13 05:12:46 +00002066
paul94f2b392005-06-28 12:44:16 +00002067static int
paulfee0f4c2004-09-13 05:12:46 +00002068bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002069 afi_t afi, safi_t safi, int type, int sub_type,
2070 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2071{
2072 int ret;
2073 int aspath_loop_count = 0;
2074 struct bgp_node *rn;
2075 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002076 struct attr new_attr;
2077 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002078 struct attr *attr_new;
2079 struct bgp_info *ri;
2080 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002081 const char *reason;
paul718e3742002-12-13 20:15:29 +00002082 char buf[SU_ADDRSTRLEN];
2083
2084 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002085 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002086
paul718e3742002-12-13 20:15:29 +00002087 /* When peer's soft reconfiguration enabled. Record input packet in
2088 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002089 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2090 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002091 bgp_adj_in_set (rn, peer, attr);
2092
2093 /* Check previously received route. */
2094 for (ri = rn->info; ri; ri = ri->next)
2095 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2096 break;
2097
2098 /* AS path local-as loop check. */
2099 if (peer->change_local_as)
2100 {
2101 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2102 aspath_loop_count = 1;
2103
2104 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2105 {
2106 reason = "as-path contains our own AS;";
2107 goto filtered;
2108 }
2109 }
2110
2111 /* AS path loop check. */
2112 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2113 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2114 && aspath_loop_check(attr->aspath, bgp->confed_id)
2115 > peer->allowas_in[afi][safi]))
2116 {
2117 reason = "as-path contains our own AS;";
2118 goto filtered;
2119 }
2120
2121 /* Route reflector originator ID check. */
2122 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002123 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002124 {
2125 reason = "originator is us;";
2126 goto filtered;
2127 }
2128
2129 /* Route reflector cluster ID check. */
2130 if (bgp_cluster_filter (peer, attr))
2131 {
2132 reason = "reflected from the same cluster;";
2133 goto filtered;
2134 }
2135
2136 /* Apply incoming filter. */
2137 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2138 {
2139 reason = "filter;";
2140 goto filtered;
2141 }
2142
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002143 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002144 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002145
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002146 /* Apply incoming route-map. */
paul718e3742002-12-13 20:15:29 +00002147 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2148 {
2149 reason = "route-map;";
2150 goto filtered;
2151 }
2152
2153 /* IPv4 unicast next hop check. */
2154 if (afi == AFI_IP && safi == SAFI_UNICAST)
2155 {
2156 /* If the peer is EBGP and nexthop is not on connected route,
2157 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002158 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002159 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002160 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002161 {
2162 reason = "non-connected next-hop;";
2163 goto filtered;
2164 }
2165
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002166 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002167 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002168 if (new_attr.nexthop.s_addr == 0
2169 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2170 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002171 {
2172 reason = "martian next-hop;";
2173 goto filtered;
2174 }
2175 }
2176
2177 attr_new = bgp_attr_intern (&new_attr);
2178
2179 /* If the update is implicit withdraw. */
2180 if (ri)
2181 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002182 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002183
2184 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002185 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2186 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002187 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002188 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002189
2190 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002191 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002192 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2193 {
2194 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002195 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002196 peer->host,
2197 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2198 p->prefixlen);
2199
paul902212c2006-02-05 17:51:19 +00002200 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2201 {
2202 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2203 bgp_process (bgp, rn, afi, safi);
2204 }
paul718e3742002-12-13 20:15:29 +00002205 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002206 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002207 {
2208 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002209 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002210 "%s rcvd %s/%d...duplicate ignored",
2211 peer->host,
2212 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2213 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002214
2215 /* graceful restart STALE flag unset. */
2216 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2217 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002218 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002219 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002220 }
paul718e3742002-12-13 20:15:29 +00002221 }
2222
2223 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002224 bgp_attr_unintern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002225
paul718e3742002-12-13 20:15:29 +00002226 return 0;
2227 }
2228
Paul Jakma16d2e242007-04-10 19:32:10 +00002229 /* Withdraw/Announce before we fully processed the withdraw */
2230 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2231 {
2232 if (BGP_DEBUG (update, UPDATE_IN))
2233 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2234 peer->host,
2235 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2236 p->prefixlen);
2237 bgp_info_restore (rn, ri);
2238 }
2239
paul718e3742002-12-13 20:15:29 +00002240 /* Received Logging. */
2241 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002242 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002243 peer->host,
2244 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2245 p->prefixlen);
2246
hasso93406d82005-02-02 14:40:33 +00002247 /* graceful restart STALE flag unset. */
2248 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002249 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002250
paul718e3742002-12-13 20:15:29 +00002251 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002252 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002253
2254 /* implicit withdraw, decrement aggregate and pcount here.
2255 * only if update is accepted, they'll increment below.
2256 */
paul902212c2006-02-05 17:51:19 +00002257 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2258
paul718e3742002-12-13 20:15:29 +00002259 /* Update bgp route dampening information. */
2260 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002261 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002262 {
2263 /* This is implicit withdraw so we should update dampening
2264 information. */
2265 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2266 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002267 }
2268
paul718e3742002-12-13 20:15:29 +00002269 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002270 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002271 ri->attr = attr_new;
2272
2273 /* Update MPLS tag. */
2274 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002275 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002276
2277 /* Update bgp route dampening information. */
2278 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002279 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002280 {
2281 /* Now we do normal update dampening. */
2282 ret = bgp_damp_update (ri, rn, afi, safi);
2283 if (ret == BGP_DAMP_SUPPRESSED)
2284 {
2285 bgp_unlock_node (rn);
2286 return 0;
2287 }
2288 }
2289
2290 /* Nexthop reachability check. */
2291 if ((afi == AFI_IP || afi == AFI_IP6)
2292 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002293 && (peer->sort == BGP_PEER_IBGP
2294 || peer->sort == BGP_PEER_CONFED
2295 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002296 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002297 {
2298 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002299 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002300 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002301 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002302 }
2303 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002304 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002305
2306 /* Process change. */
2307 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2308
2309 bgp_process (bgp, rn, afi, safi);
2310 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002311
paul718e3742002-12-13 20:15:29 +00002312 return 0;
2313 }
2314
2315 /* Received Logging. */
2316 if (BGP_DEBUG (update, UPDATE_IN))
2317 {
ajsd2c1f162004-12-08 21:10:20 +00002318 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002319 peer->host,
2320 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2321 p->prefixlen);
2322 }
2323
paul718e3742002-12-13 20:15:29 +00002324 /* Make new BGP info. */
2325 new = bgp_info_new ();
2326 new->type = type;
2327 new->sub_type = sub_type;
2328 new->peer = peer;
2329 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002330 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002331
2332 /* Update MPLS tag. */
2333 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002334 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002335
2336 /* Nexthop reachability check. */
2337 if ((afi == AFI_IP || afi == AFI_IP6)
2338 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002339 && (peer->sort == BGP_PEER_IBGP
2340 || peer->sort == BGP_PEER_CONFED
2341 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002342 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002343 {
2344 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002345 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002346 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002347 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002348 }
2349 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002350 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002351
paul902212c2006-02-05 17:51:19 +00002352 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002353 bgp_aggregate_increment (bgp, p, new, afi, safi);
2354
2355 /* Register new BGP information. */
2356 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002357
2358 /* route_node_get lock */
2359 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002360
paul718e3742002-12-13 20:15:29 +00002361 /* If maximum prefix count is configured and current prefix
2362 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002363 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2364 return -1;
paul718e3742002-12-13 20:15:29 +00002365
2366 /* Process change. */
2367 bgp_process (bgp, rn, afi, safi);
2368
2369 return 0;
2370
2371 /* This BGP update is filtered. Log the reason then update BGP
2372 entry. */
2373 filtered:
2374 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002375 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002376 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2377 peer->host,
2378 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2379 p->prefixlen, reason);
2380
2381 if (ri)
paulb40d9392005-08-22 22:34:41 +00002382 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002383
2384 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002385
paul718e3742002-12-13 20:15:29 +00002386 return 0;
2387}
2388
2389int
paulfee0f4c2004-09-13 05:12:46 +00002390bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2391 afi_t afi, safi_t safi, int type, int sub_type,
2392 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2393{
2394 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002395 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002396 struct bgp *bgp;
2397 int ret;
2398
2399 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2400 soft_reconfig);
2401
2402 bgp = peer->bgp;
2403
2404 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002405 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002406 {
2407 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2408 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2409 sub_type, prd, tag);
2410 }
2411
2412 return ret;
2413}
2414
2415int
paul718e3742002-12-13 20:15:29 +00002416bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002417 afi_t afi, safi_t safi, int type, int sub_type,
2418 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002419{
2420 struct bgp *bgp;
2421 char buf[SU_ADDRSTRLEN];
2422 struct bgp_node *rn;
2423 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002424 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002425 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002426
2427 bgp = peer->bgp;
2428
paulfee0f4c2004-09-13 05:12:46 +00002429 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002430 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002431 {
2432 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2433 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2434 }
2435
paul718e3742002-12-13 20:15:29 +00002436 /* Logging. */
2437 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002438 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002439 peer->host,
2440 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2441 p->prefixlen);
2442
2443 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002444 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002445
2446 /* If peer is soft reconfiguration enabled. Record input packet for
2447 further calculation. */
2448 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2449 && peer != bgp->peer_self)
2450 bgp_adj_in_unset (rn, peer);
2451
2452 /* Lookup withdrawn route. */
2453 for (ri = rn->info; ri; ri = ri->next)
2454 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2455 break;
2456
2457 /* Withdraw specified route from routing table. */
2458 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002459 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002460 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002461 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002462 "%s Can't find the route %s/%d", peer->host,
2463 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2464 p->prefixlen);
2465
2466 /* Unlock bgp_node_get() lock. */
2467 bgp_unlock_node (rn);
2468
2469 return 0;
2470}
David Lamparter6b0655a2014-06-04 06:53:35 +02002471
paul718e3742002-12-13 20:15:29 +00002472void
2473bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2474{
2475 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002476 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002477 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002478 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002479 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002480 struct bgp_node *rn;
2481 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002482 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002483
Paul Jakmab2497022007-06-14 11:17:58 +00002484 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002485 return;
2486
paul718e3742002-12-13 20:15:29 +00002487 bgp = peer->bgp;
2488 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002489
paul718e3742002-12-13 20:15:29 +00002490 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2491 aspath = attr.aspath;
2492 attr.local_pref = bgp->default_local_pref;
2493 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2494
2495 if (afi == AFI_IP)
2496 str2prefix ("0.0.0.0/0", &p);
2497#ifdef HAVE_IPV6
2498 else if (afi == AFI_IP6)
2499 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002500 struct attr_extra *ae = attr.extra;
2501
paul718e3742002-12-13 20:15:29 +00002502 str2prefix ("::/0", &p);
2503
2504 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002505 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002506 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002507 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002508
2509 /* If the peer is on shared nextwork and we have link-local
2510 nexthop set it. */
2511 if (peer->shared_network
2512 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2513 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002514 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002515 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002516 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002517 }
2518 }
2519#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002520
2521 if (peer->default_rmap[afi][safi].name)
2522 {
paulfee0f4c2004-09-13 05:12:46 +00002523 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002524 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2525 {
2526 for (ri = rn->info; ri; ri = ri->next)
2527 {
2528 struct attr dummy_attr;
2529 struct attr_extra dummy_extra;
2530 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002531
Christian Frankedcab1bb2012-12-07 16:45:52 +00002532 /* Provide dummy so the route-map can't modify the attributes */
2533 dummy_attr.extra = &dummy_extra;
2534 bgp_attr_dup(&dummy_attr, ri->attr);
2535 info.peer = ri->peer;
2536 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002537
Christian Frankedcab1bb2012-12-07 16:45:52 +00002538 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2539 RMAP_BGP, &info);
2540
2541 /* The route map might have set attributes. If we don't flush them
2542 * here, they will be leaked. */
2543 bgp_attr_flush(&dummy_attr);
2544 if (ret != RMAP_DENYMATCH)
2545 break;
2546 }
2547 if (ret != RMAP_DENYMATCH)
2548 break;
2549 }
paulfee0f4c2004-09-13 05:12:46 +00002550 bgp->peer_self->rmap_type = 0;
2551
paul718e3742002-12-13 20:15:29 +00002552 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002553 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002554 }
2555
2556 if (withdraw)
2557 {
2558 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2559 bgp_default_withdraw_send (peer, afi, safi);
2560 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2561 }
2562 else
2563 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002564 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2565 {
2566 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2567 bgp_default_update_send (peer, &attr, afi, safi, from);
2568 }
paul718e3742002-12-13 20:15:29 +00002569 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002570
2571 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002572 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002573}
David Lamparter6b0655a2014-06-04 06:53:35 +02002574
paul718e3742002-12-13 20:15:29 +00002575static void
2576bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002577 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002578{
2579 struct bgp_node *rn;
2580 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002581 struct attr attr;
2582 struct attr_extra extra;
2583
paul718e3742002-12-13 20:15:29 +00002584 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002585 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002586
2587 if (safi != SAFI_MPLS_VPN
2588 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2589 bgp_default_originate (peer, afi, safi, 0);
2590
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002591 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2592 attr.extra = &extra;
2593
paul718e3742002-12-13 20:15:29 +00002594 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2595 for (ri = rn->info; ri; ri = ri->next)
2596 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2597 {
paulfee0f4c2004-09-13 05:12:46 +00002598 if ( (rsclient) ?
2599 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2600 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002601 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2602 else
2603 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2604 }
2605}
2606
2607void
2608bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2609{
2610 struct bgp_node *rn;
2611 struct bgp_table *table;
2612
2613 if (peer->status != Established)
2614 return;
2615
2616 if (! peer->afc_nego[afi][safi])
2617 return;
2618
2619 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2620 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2621 return;
2622
2623 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002624 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002625 else
2626 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2627 rn = bgp_route_next(rn))
2628 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002629 bgp_announce_table (peer, afi, safi, table, 0);
2630
2631 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2632 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002633}
2634
2635void
2636bgp_announce_route_all (struct peer *peer)
2637{
2638 afi_t afi;
2639 safi_t safi;
2640
2641 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2642 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2643 bgp_announce_route (peer, afi, safi);
2644}
David Lamparter6b0655a2014-06-04 06:53:35 +02002645
paul718e3742002-12-13 20:15:29 +00002646static void
paulfee0f4c2004-09-13 05:12:46 +00002647bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002648 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002649{
2650 struct bgp_node *rn;
2651 struct bgp_adj_in *ain;
2652
2653 if (! table)
2654 table = rsclient->bgp->rib[afi][safi];
2655
2656 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2657 for (ain = rn->adj_in; ain; ain = ain->next)
2658 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002659 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002660 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002661
paulfee0f4c2004-09-13 05:12:46 +00002662 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002663 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002664 }
2665}
2666
2667void
2668bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2669{
2670 struct bgp_table *table;
2671 struct bgp_node *rn;
2672
2673 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002674 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002675
2676 else
2677 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2678 rn = bgp_route_next (rn))
2679 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002680 {
2681 struct prefix_rd prd;
2682 prd.family = AF_UNSPEC;
2683 prd.prefixlen = 64;
2684 memcpy(&prd.val, rn->p.u.val, 8);
2685
2686 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2687 }
paulfee0f4c2004-09-13 05:12:46 +00002688}
David Lamparter6b0655a2014-06-04 06:53:35 +02002689
paulfee0f4c2004-09-13 05:12:46 +00002690static void
paul718e3742002-12-13 20:15:29 +00002691bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002692 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002693{
2694 int ret;
2695 struct bgp_node *rn;
2696 struct bgp_adj_in *ain;
2697
2698 if (! table)
2699 table = peer->bgp->rib[afi][safi];
2700
2701 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2702 for (ain = rn->adj_in; ain; ain = ain->next)
2703 {
2704 if (ain->peer == peer)
2705 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002706 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002707 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002708
paul718e3742002-12-13 20:15:29 +00002709 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2710 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002711 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002712
paul718e3742002-12-13 20:15:29 +00002713 if (ret < 0)
2714 {
2715 bgp_unlock_node (rn);
2716 return;
2717 }
2718 continue;
2719 }
2720 }
2721}
2722
2723void
2724bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2725{
2726 struct bgp_node *rn;
2727 struct bgp_table *table;
2728
2729 if (peer->status != Established)
2730 return;
2731
2732 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002733 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002734 else
2735 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2736 rn = bgp_route_next (rn))
2737 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002738 {
2739 struct prefix_rd prd;
2740 prd.family = AF_UNSPEC;
2741 prd.prefixlen = 64;
2742 memcpy(&prd.val, rn->p.u.val, 8);
2743
2744 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2745 }
paul718e3742002-12-13 20:15:29 +00002746}
David Lamparter6b0655a2014-06-04 06:53:35 +02002747
Chris Caputo228da422009-07-18 05:44:03 +00002748
2749struct bgp_clear_node_queue
2750{
2751 struct bgp_node *rn;
2752 enum bgp_clear_route_type purpose;
2753};
2754
paul200df112005-06-01 11:17:05 +00002755static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002756bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002757{
Chris Caputo228da422009-07-18 05:44:03 +00002758 struct bgp_clear_node_queue *cnq = data;
2759 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002760 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002761 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002762 afi_t afi = bgp_node_table (rn)->afi;
2763 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002764
Paul Jakma64e580a2006-02-21 01:09:01 +00002765 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002766
Paul Jakma64e580a2006-02-21 01:09:01 +00002767 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002768 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002769 {
2770 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002771 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2772 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002773 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002774 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2775 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002776 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002777 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002778 break;
2779 }
paul200df112005-06-01 11:17:05 +00002780 return WQ_SUCCESS;
2781}
2782
2783static void
paul0fb58d52005-11-14 14:31:49 +00002784bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002785{
Chris Caputo228da422009-07-18 05:44:03 +00002786 struct bgp_clear_node_queue *cnq = data;
2787 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002788 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002789
2790 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002791 bgp_table_unlock (table);
2792 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002793}
2794
2795static void
paul94f2b392005-06-28 12:44:16 +00002796bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002797{
Paul Jakma64e580a2006-02-21 01:09:01 +00002798 struct peer *peer = wq->spec.data;
2799
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002800 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002801 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002802
2803 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002804}
2805
2806static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002807bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002808{
Paul Jakmaa2943652009-07-21 14:02:04 +01002809 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002810
Paul Jakmaa2943652009-07-21 14:02:04 +01002811 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002812#undef CLEAR_QUEUE_NAME_LEN
2813
2814 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002815 {
2816 zlog_err ("%s: Failed to allocate work queue", __func__);
2817 exit (1);
2818 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002819 peer->clear_node_queue->spec.hold = 10;
2820 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2821 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2822 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2823 peer->clear_node_queue->spec.max_retries = 0;
2824
2825 /* we only 'lock' this peer reference when the queue is actually active */
2826 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002827}
2828
paul718e3742002-12-13 20:15:29 +00002829static void
2830bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002831 struct bgp_table *table, struct peer *rsclient,
2832 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002833{
2834 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002835
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002836
paul718e3742002-12-13 20:15:29 +00002837 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002838 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002839
hasso6cf159b2005-03-21 10:28:14 +00002840 /* If still no table => afi/safi isn't configured at all or smth. */
2841 if (! table)
2842 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002843
2844 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2845 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002846 struct bgp_info *ri;
2847 struct bgp_adj_in *ain;
2848 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002849
2850 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2851 * queued for every clearing peer, regardless of whether it is
2852 * relevant to the peer at hand.
2853 *
2854 * Overview: There are 3 different indices which need to be
2855 * scrubbed, potentially, when a peer is removed:
2856 *
2857 * 1 peer's routes visible via the RIB (ie accepted routes)
2858 * 2 peer's routes visible by the (optional) peer's adj-in index
2859 * 3 other routes visible by the peer's adj-out index
2860 *
2861 * 3 there is no hurry in scrubbing, once the struct peer is
2862 * removed from bgp->peer, we could just GC such deleted peer's
2863 * adj-outs at our leisure.
2864 *
2865 * 1 and 2 must be 'scrubbed' in some way, at least made
2866 * invisible via RIB index before peer session is allowed to be
2867 * brought back up. So one needs to know when such a 'search' is
2868 * complete.
2869 *
2870 * Ideally:
2871 *
2872 * - there'd be a single global queue or a single RIB walker
2873 * - rather than tracking which route_nodes still need to be
2874 * examined on a peer basis, we'd track which peers still
2875 * aren't cleared
2876 *
2877 * Given that our per-peer prefix-counts now should be reliable,
2878 * this may actually be achievable. It doesn't seem to be a huge
2879 * problem at this time,
2880 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002881 for (ain = rn->adj_in; ain; ain = ain->next)
2882 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2883 {
2884 bgp_adj_in_remove (rn, ain);
2885 bgp_unlock_node (rn);
2886 break;
2887 }
2888 for (aout = rn->adj_out; aout; aout = aout->next)
2889 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2890 {
2891 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2892 bgp_unlock_node (rn);
2893 break;
2894 }
2895
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002896 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002897 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002898 {
Chris Caputo228da422009-07-18 05:44:03 +00002899 struct bgp_clear_node_queue *cnq;
2900
2901 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002902 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002903 bgp_lock_node (rn);
2904 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2905 sizeof (struct bgp_clear_node_queue));
2906 cnq->rn = rn;
2907 cnq->purpose = purpose;
2908 work_queue_add (peer->clear_node_queue, cnq);
2909 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002910 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002911 }
2912 return;
2913}
2914
2915void
Chris Caputo228da422009-07-18 05:44:03 +00002916bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2917 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002918{
2919 struct bgp_node *rn;
2920 struct bgp_table *table;
2921 struct peer *rsclient;
2922 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002923
Paul Jakma64e580a2006-02-21 01:09:01 +00002924 if (peer->clear_node_queue == NULL)
2925 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002926
Paul Jakmaca058a32006-09-14 02:58:49 +00002927 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2928 * Idle until it receives a Clearing_Completed event. This protects
2929 * against peers which flap faster than we can we clear, which could
2930 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002931 *
2932 * a) race with routes from the new session being installed before
2933 * clear_route_node visits the node (to delete the route of that
2934 * peer)
2935 * b) resource exhaustion, clear_route_node likely leads to an entry
2936 * on the process_main queue. Fast-flapping could cause that queue
2937 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002938 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002939 if (!peer->clear_node_queue->thread)
2940 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002941
Chris Caputo228da422009-07-18 05:44:03 +00002942 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002943 {
Chris Caputo228da422009-07-18 05:44:03 +00002944 case BGP_CLEAR_ROUTE_NORMAL:
2945 if (safi != SAFI_MPLS_VPN)
2946 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2947 else
2948 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2949 rn = bgp_route_next (rn))
2950 if ((table = rn->info) != NULL)
2951 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2952
2953 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2954 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2955 PEER_FLAG_RSERVER_CLIENT))
2956 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2957 break;
2958
2959 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2960 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2961 break;
2962
2963 default:
2964 assert (0);
2965 break;
paulfee0f4c2004-09-13 05:12:46 +00002966 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002967
Paul Jakmaca058a32006-09-14 02:58:49 +00002968 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002969 * completion function won't be run by workqueue code - call it here.
2970 * XXX: Actually, this assumption doesn't hold, see
2971 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002972 *
2973 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002974 * really needed if peer state is Established - peers in
2975 * pre-Established states shouldn't have any route-update state
2976 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002977 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002978 * We still can get here in pre-Established though, through
2979 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2980 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002981 *
2982 * At some future point, this check could be move to the top of the
2983 * function, and do a quick early-return when state is
2984 * pre-Established, avoiding above list and table scans. Once we're
2985 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002986 */
2987 if (!peer->clear_node_queue->thread)
2988 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002989}
2990
2991void
2992bgp_clear_route_all (struct peer *peer)
2993{
2994 afi_t afi;
2995 safi_t safi;
2996
2997 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2998 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00002999 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003000}
3001
3002void
3003bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3004{
3005 struct bgp_table *table;
3006 struct bgp_node *rn;
3007 struct bgp_adj_in *ain;
3008
3009 table = peer->bgp->rib[afi][safi];
3010
3011 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3012 for (ain = rn->adj_in; ain ; ain = ain->next)
3013 if (ain->peer == peer)
3014 {
3015 bgp_adj_in_remove (rn, ain);
3016 bgp_unlock_node (rn);
3017 break;
3018 }
3019}
hasso93406d82005-02-02 14:40:33 +00003020
3021void
3022bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3023{
3024 struct bgp_node *rn;
3025 struct bgp_info *ri;
3026 struct bgp_table *table;
3027
3028 table = peer->bgp->rib[afi][safi];
3029
3030 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3031 {
3032 for (ri = rn->info; ri; ri = ri->next)
3033 if (ri->peer == peer)
3034 {
3035 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3036 bgp_rib_remove (rn, ri, peer, afi, safi);
3037 break;
3038 }
3039 }
3040}
David Lamparter6b0655a2014-06-04 06:53:35 +02003041
paul718e3742002-12-13 20:15:29 +00003042/* Delete all kernel routes. */
3043void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003044bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003045{
3046 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003047 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003048 struct bgp_node *rn;
3049 struct bgp_table *table;
3050 struct bgp_info *ri;
3051
paul1eb8ef22005-04-07 07:30:20 +00003052 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003053 {
3054 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3055
3056 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3057 for (ri = rn->info; ri; ri = ri->next)
3058 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3059 && ri->type == ZEBRA_ROUTE_BGP
3060 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003061 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003062
3063 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3064
3065 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3066 for (ri = rn->info; ri; ri = ri->next)
3067 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3068 && ri->type == ZEBRA_ROUTE_BGP
3069 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003070 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003071 }
3072}
3073
3074void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003075bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003076{
3077 vty_reset ();
3078 bgp_zclient_reset ();
3079 access_list_reset ();
3080 prefix_list_reset ();
3081}
David Lamparter6b0655a2014-06-04 06:53:35 +02003082
paul718e3742002-12-13 20:15:29 +00003083/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3084 value. */
3085int
3086bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3087{
3088 u_char *pnt;
3089 u_char *lim;
3090 struct prefix p;
3091 int psize;
3092 int ret;
3093
3094 /* Check peer status. */
3095 if (peer->status != Established)
3096 return 0;
3097
3098 pnt = packet->nlri;
3099 lim = pnt + packet->length;
3100
3101 for (; pnt < lim; pnt += psize)
3102 {
3103 /* Clear prefix structure. */
3104 memset (&p, 0, sizeof (struct prefix));
3105
3106 /* Fetch prefix length. */
3107 p.prefixlen = *pnt++;
3108 p.family = afi2family (packet->afi);
3109
3110 /* Already checked in nlri_sanity_check(). We do double check
3111 here. */
3112 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3113 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3114 return -1;
3115
3116 /* Packet size overflow check. */
3117 psize = PSIZE (p.prefixlen);
3118
3119 /* When packet overflow occur return immediately. */
3120 if (pnt + psize > lim)
3121 return -1;
3122
3123 /* Fetch prefix from NLRI packet. */
3124 memcpy (&p.u.prefix, pnt, psize);
3125
3126 /* Check address. */
3127 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3128 {
3129 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3130 {
paulf5ba3872004-07-09 12:11:31 +00003131 /*
3132 * From draft-ietf-idr-bgp4-22, Section 6.3:
3133 * If a BGP router receives an UPDATE message with a
3134 * semantically incorrect NLRI field, in which a prefix is
3135 * semantically incorrect (eg. an unexpected multicast IP
3136 * address), it should ignore the prefix.
3137 */
paul718e3742002-12-13 20:15:29 +00003138 zlog (peer->log, LOG_ERR,
3139 "IPv4 unicast NLRI is multicast address %s",
3140 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003141
paul718e3742002-12-13 20:15:29 +00003142 return -1;
3143 }
3144 }
3145
3146#ifdef HAVE_IPV6
3147 /* Check address. */
3148 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3149 {
3150 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3151 {
3152 char buf[BUFSIZ];
3153
3154 zlog (peer->log, LOG_WARNING,
3155 "IPv6 link-local NLRI received %s ignore this NLRI",
3156 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3157
3158 continue;
3159 }
3160 }
3161#endif /* HAVE_IPV6 */
3162
3163 /* Normal process. */
3164 if (attr)
3165 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3166 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3167 else
3168 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3169 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3170
3171 /* Address family configuration mismatch or maximum-prefix count
3172 overflow. */
3173 if (ret < 0)
3174 return -1;
3175 }
3176
3177 /* Packet length consistency check. */
3178 if (pnt != lim)
3179 return -1;
3180
3181 return 0;
3182}
3183
3184/* NLRI encode syntax check routine. */
3185int
3186bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3187 bgp_size_t length)
3188{
3189 u_char *end;
3190 u_char prefixlen;
3191 int psize;
3192
3193 end = pnt + length;
3194
3195 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3196 syntactic validity. If the field is syntactically incorrect,
3197 then the Error Subcode is set to Invalid Network Field. */
3198
3199 while (pnt < end)
3200 {
3201 prefixlen = *pnt++;
3202
3203 /* Prefix length check. */
3204 if ((afi == AFI_IP && prefixlen > 32)
3205 || (afi == AFI_IP6 && prefixlen > 128))
3206 {
3207 plog_err (peer->log,
3208 "%s [Error] Update packet error (wrong prefix length %d)",
3209 peer->host, prefixlen);
3210 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3211 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3212 return -1;
3213 }
3214
3215 /* Packet size overflow check. */
3216 psize = PSIZE (prefixlen);
3217
3218 if (pnt + psize > end)
3219 {
3220 plog_err (peer->log,
3221 "%s [Error] Update packet error"
3222 " (prefix data overflow prefix size is %d)",
3223 peer->host, psize);
3224 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3225 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3226 return -1;
3227 }
3228
3229 pnt += psize;
3230 }
3231
3232 /* Packet length consistency check. */
3233 if (pnt != end)
3234 {
3235 plog_err (peer->log,
3236 "%s [Error] Update packet error"
3237 " (prefix length mismatch with total length)",
3238 peer->host);
3239 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3240 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3241 return -1;
3242 }
3243 return 0;
3244}
David Lamparter6b0655a2014-06-04 06:53:35 +02003245
paul94f2b392005-06-28 12:44:16 +00003246static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003247bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003248{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003249 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003250}
3251
paul94f2b392005-06-28 12:44:16 +00003252static void
paul718e3742002-12-13 20:15:29 +00003253bgp_static_free (struct bgp_static *bgp_static)
3254{
3255 if (bgp_static->rmap.name)
3256 free (bgp_static->rmap.name);
3257 XFREE (MTYPE_BGP_STATIC, bgp_static);
3258}
3259
paul94f2b392005-06-28 12:44:16 +00003260static void
paulfee0f4c2004-09-13 05:12:46 +00003261bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3262 struct prefix *p, afi_t afi, safi_t safi)
3263{
3264 struct bgp_node *rn;
3265 struct bgp_info *ri;
3266
3267 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3268
3269 /* Check selected route and self inserted route. */
3270 for (ri = rn->info; ri; ri = ri->next)
3271 if (ri->peer == bgp->peer_self
3272 && ri->type == ZEBRA_ROUTE_BGP
3273 && ri->sub_type == BGP_ROUTE_STATIC)
3274 break;
3275
3276 /* Withdraw static BGP route from routing table. */
3277 if (ri)
3278 {
paulfee0f4c2004-09-13 05:12:46 +00003279 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003280 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003281 }
3282
3283 /* Unlock bgp_node_lookup. */
3284 bgp_unlock_node (rn);
3285}
3286
paul94f2b392005-06-28 12:44:16 +00003287static void
paulfee0f4c2004-09-13 05:12:46 +00003288bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003289 struct bgp_static *bgp_static,
3290 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003291{
3292 struct bgp_node *rn;
3293 struct bgp_info *ri;
3294 struct bgp_info *new;
3295 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003296 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003297 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003298 struct attr new_attr;
3299 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003300 struct bgp *bgp;
3301 int ret;
3302 char buf[SU_ADDRSTRLEN];
3303
3304 bgp = rsclient->bgp;
3305
Paul Jakma06e110f2006-05-12 23:29:22 +00003306 assert (bgp_static);
3307 if (!bgp_static)
3308 return;
3309
paulfee0f4c2004-09-13 05:12:46 +00003310 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3311
3312 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003313
3314 attr.nexthop = bgp_static->igpnexthop;
3315 attr.med = bgp_static->igpmetric;
3316 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003317
Paul Jakma41367172007-08-06 15:24:51 +00003318 if (bgp_static->atomic)
3319 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3320
paulfee0f4c2004-09-13 05:12:46 +00003321 /* Apply network route-map for export to this rsclient. */
3322 if (bgp_static->rmap.name)
3323 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003324 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003325 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003326 info.attr = &attr_tmp;
3327
paulfee0f4c2004-09-13 05:12:46 +00003328 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3329 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3330
3331 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3332
3333 rsclient->rmap_type = 0;
3334
3335 if (ret == RMAP_DENYMATCH)
3336 {
3337 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003338 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003339
3340 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003341 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003342 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003343 bgp_attr_extra_free (&attr);
3344
paulfee0f4c2004-09-13 05:12:46 +00003345 return;
3346 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003347 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003348 }
3349 else
3350 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003351
3352 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003353 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003354
paulfee0f4c2004-09-13 05:12:46 +00003355 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3356
Paul Jakmafb982c22007-05-04 20:15:47 +00003357 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3358 == RMAP_DENY)
3359 {
paulfee0f4c2004-09-13 05:12:46 +00003360 /* This BGP update is filtered. Log the reason then update BGP entry. */
3361 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003362 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003363 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3364 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3365 p->prefixlen, rsclient->host);
3366
3367 bgp->peer_self->rmap_type = 0;
3368
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003369 bgp_attr_unintern (&attr_new);
3370 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003371 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003372
3373 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3374
3375 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003376 }
paulfee0f4c2004-09-13 05:12:46 +00003377
3378 bgp->peer_self->rmap_type = 0;
3379
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003380 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003381 attr_new = bgp_attr_intern (&new_attr);
3382
3383 for (ri = rn->info; ri; ri = ri->next)
3384 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3385 && ri->sub_type == BGP_ROUTE_STATIC)
3386 break;
3387
3388 if (ri)
3389 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003390 if (attrhash_cmp (ri->attr, attr_new) &&
3391 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003392 {
3393 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003394 bgp_attr_unintern (&attr_new);
3395 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003396 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003397 return;
3398 }
3399 else
3400 {
3401 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003402 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003403
3404 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003405 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3406 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003407 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003408 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003409 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003410
3411 /* Process change. */
3412 bgp_process (bgp, rn, afi, safi);
3413 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003414 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003415 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003416 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003417 }
paulfee0f4c2004-09-13 05:12:46 +00003418 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003419
paulfee0f4c2004-09-13 05:12:46 +00003420 /* Make new BGP info. */
3421 new = bgp_info_new ();
3422 new->type = ZEBRA_ROUTE_BGP;
3423 new->sub_type = BGP_ROUTE_STATIC;
3424 new->peer = bgp->peer_self;
3425 SET_FLAG (new->flags, BGP_INFO_VALID);
3426 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003427 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003428
3429 /* Register new BGP information. */
3430 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003431
3432 /* route_node_get lock */
3433 bgp_unlock_node (rn);
3434
paulfee0f4c2004-09-13 05:12:46 +00003435 /* Process change. */
3436 bgp_process (bgp, rn, afi, safi);
3437
3438 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003439 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003440 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003441}
3442
paul94f2b392005-06-28 12:44:16 +00003443static void
paulfee0f4c2004-09-13 05:12:46 +00003444bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003445 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3446{
3447 struct bgp_node *rn;
3448 struct bgp_info *ri;
3449 struct bgp_info *new;
3450 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003451 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003452 struct attr *attr_new;
3453 int ret;
3454
Paul Jakmadd8103a2006-05-12 23:27:30 +00003455 assert (bgp_static);
3456 if (!bgp_static)
3457 return;
3458
paulfee0f4c2004-09-13 05:12:46 +00003459 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003460
3461 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003462
3463 attr.nexthop = bgp_static->igpnexthop;
3464 attr.med = bgp_static->igpmetric;
3465 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003466
Paul Jakma41367172007-08-06 15:24:51 +00003467 if (bgp_static->atomic)
3468 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3469
paul718e3742002-12-13 20:15:29 +00003470 /* Apply route-map. */
3471 if (bgp_static->rmap.name)
3472 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003473 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003474 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003475 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003476
paulfee0f4c2004-09-13 05:12:46 +00003477 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3478
paul718e3742002-12-13 20:15:29 +00003479 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003480
paulfee0f4c2004-09-13 05:12:46 +00003481 bgp->peer_self->rmap_type = 0;
3482
paul718e3742002-12-13 20:15:29 +00003483 if (ret == RMAP_DENYMATCH)
3484 {
3485 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003486 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003487
3488 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003489 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003490 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003491 bgp_static_withdraw (bgp, p, afi, safi);
3492 return;
3493 }
paul286e1e72003-08-08 00:24:31 +00003494 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003495 }
paul286e1e72003-08-08 00:24:31 +00003496 else
3497 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003498
3499 for (ri = rn->info; ri; ri = ri->next)
3500 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3501 && ri->sub_type == BGP_ROUTE_STATIC)
3502 break;
3503
3504 if (ri)
3505 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003506 if (attrhash_cmp (ri->attr, attr_new) &&
3507 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003508 {
3509 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003510 bgp_attr_unintern (&attr_new);
3511 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003512 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003513 return;
3514 }
3515 else
3516 {
3517 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003518 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003519
3520 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003521 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3522 bgp_info_restore(rn, ri);
3523 else
3524 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003525 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003526 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003527 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003528
3529 /* Process change. */
3530 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3531 bgp_process (bgp, rn, afi, safi);
3532 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003533 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003534 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003535 return;
3536 }
3537 }
3538
3539 /* Make new BGP info. */
3540 new = bgp_info_new ();
3541 new->type = ZEBRA_ROUTE_BGP;
3542 new->sub_type = BGP_ROUTE_STATIC;
3543 new->peer = bgp->peer_self;
3544 SET_FLAG (new->flags, BGP_INFO_VALID);
3545 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003546 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003547
3548 /* Aggregate address increment. */
3549 bgp_aggregate_increment (bgp, p, new, afi, safi);
3550
3551 /* Register new BGP information. */
3552 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003553
3554 /* route_node_get lock */
3555 bgp_unlock_node (rn);
3556
paul718e3742002-12-13 20:15:29 +00003557 /* Process change. */
3558 bgp_process (bgp, rn, afi, safi);
3559
3560 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003561 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003562 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003563}
3564
3565void
paulfee0f4c2004-09-13 05:12:46 +00003566bgp_static_update (struct bgp *bgp, struct prefix *p,
3567 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3568{
3569 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003570 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003571
3572 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3573
paul1eb8ef22005-04-07 07:30:20 +00003574 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003575 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003576 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3577 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003578 }
3579}
3580
paul94f2b392005-06-28 12:44:16 +00003581static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003582bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3583 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003584{
3585 struct bgp_node *rn;
3586 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003587
paulfee0f4c2004-09-13 05:12:46 +00003588 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003589
3590 /* Make new BGP info. */
3591 new = bgp_info_new ();
3592 new->type = ZEBRA_ROUTE_BGP;
3593 new->sub_type = BGP_ROUTE_STATIC;
3594 new->peer = bgp->peer_self;
3595 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3596 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003597 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003598 new->extra = bgp_info_extra_new();
3599 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003600
3601 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003602 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003603
3604 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003605 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003606
paul200df112005-06-01 11:17:05 +00003607 /* route_node_get lock */
3608 bgp_unlock_node (rn);
3609
paul718e3742002-12-13 20:15:29 +00003610 /* Process change. */
3611 bgp_process (bgp, rn, afi, safi);
3612}
3613
3614void
3615bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3616 safi_t safi)
3617{
3618 struct bgp_node *rn;
3619 struct bgp_info *ri;
3620
paulfee0f4c2004-09-13 05:12:46 +00003621 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003622
3623 /* Check selected route and self inserted route. */
3624 for (ri = rn->info; ri; ri = ri->next)
3625 if (ri->peer == bgp->peer_self
3626 && ri->type == ZEBRA_ROUTE_BGP
3627 && ri->sub_type == BGP_ROUTE_STATIC)
3628 break;
3629
3630 /* Withdraw static BGP route from routing table. */
3631 if (ri)
3632 {
3633 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003634 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003635 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003636 }
3637
3638 /* Unlock bgp_node_lookup. */
3639 bgp_unlock_node (rn);
3640}
3641
3642void
paulfee0f4c2004-09-13 05:12:46 +00003643bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3644{
3645 struct bgp_static *bgp_static;
3646 struct bgp *bgp;
3647 struct bgp_node *rn;
3648 struct prefix *p;
3649
3650 bgp = rsclient->bgp;
3651
3652 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3653 if ((bgp_static = rn->info) != NULL)
3654 {
3655 p = &rn->p;
3656
3657 bgp_static_update_rsclient (rsclient, p, bgp_static,
3658 afi, safi);
3659 }
3660}
3661
paul94f2b392005-06-28 12:44:16 +00003662static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003663bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3664 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003665{
3666 struct bgp_node *rn;
3667 struct bgp_info *ri;
3668
paulfee0f4c2004-09-13 05:12:46 +00003669 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003670
3671 /* Check selected route and self inserted route. */
3672 for (ri = rn->info; ri; ri = ri->next)
3673 if (ri->peer == bgp->peer_self
3674 && ri->type == ZEBRA_ROUTE_BGP
3675 && ri->sub_type == BGP_ROUTE_STATIC)
3676 break;
3677
3678 /* Withdraw static BGP route from routing table. */
3679 if (ri)
3680 {
3681 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003682 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003683 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003684 }
3685
3686 /* Unlock bgp_node_lookup. */
3687 bgp_unlock_node (rn);
3688}
3689
3690/* Configure static BGP network. When user don't run zebra, static
3691 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003692static int
paulfd79ac92004-10-13 05:06:08 +00003693bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003694 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003695{
3696 int ret;
3697 struct prefix p;
3698 struct bgp_static *bgp_static;
3699 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003700 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003701
3702 /* Convert IP prefix string to struct prefix. */
3703 ret = str2prefix (ip_str, &p);
3704 if (! ret)
3705 {
3706 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3707 return CMD_WARNING;
3708 }
3709#ifdef HAVE_IPV6
3710 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3711 {
3712 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3713 VTY_NEWLINE);
3714 return CMD_WARNING;
3715 }
3716#endif /* HAVE_IPV6 */
3717
3718 apply_mask (&p);
3719
3720 /* Set BGP static route configuration. */
3721 rn = bgp_node_get (bgp->route[afi][safi], &p);
3722
3723 if (rn->info)
3724 {
3725 /* Configuration change. */
3726 bgp_static = rn->info;
3727
3728 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003729 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3730 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003731
paul718e3742002-12-13 20:15:29 +00003732 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003733
paul718e3742002-12-13 20:15:29 +00003734 if (rmap)
3735 {
3736 if (bgp_static->rmap.name)
3737 free (bgp_static->rmap.name);
3738 bgp_static->rmap.name = strdup (rmap);
3739 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3740 }
3741 else
3742 {
3743 if (bgp_static->rmap.name)
3744 free (bgp_static->rmap.name);
3745 bgp_static->rmap.name = NULL;
3746 bgp_static->rmap.map = NULL;
3747 bgp_static->valid = 0;
3748 }
3749 bgp_unlock_node (rn);
3750 }
3751 else
3752 {
3753 /* New configuration. */
3754 bgp_static = bgp_static_new ();
3755 bgp_static->backdoor = backdoor;
3756 bgp_static->valid = 0;
3757 bgp_static->igpmetric = 0;
3758 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003759
paul718e3742002-12-13 20:15:29 +00003760 if (rmap)
3761 {
3762 if (bgp_static->rmap.name)
3763 free (bgp_static->rmap.name);
3764 bgp_static->rmap.name = strdup (rmap);
3765 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3766 }
3767 rn->info = bgp_static;
3768 }
3769
3770 /* If BGP scan is not enabled, we should install this route here. */
3771 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3772 {
3773 bgp_static->valid = 1;
3774
3775 if (need_update)
3776 bgp_static_withdraw (bgp, &p, afi, safi);
3777
3778 if (! bgp_static->backdoor)
3779 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3780 }
3781
3782 return CMD_SUCCESS;
3783}
3784
3785/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003786static int
paulfd79ac92004-10-13 05:06:08 +00003787bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003788 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003789{
3790 int ret;
3791 struct prefix p;
3792 struct bgp_static *bgp_static;
3793 struct bgp_node *rn;
3794
3795 /* Convert IP prefix string to struct prefix. */
3796 ret = str2prefix (ip_str, &p);
3797 if (! ret)
3798 {
3799 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3800 return CMD_WARNING;
3801 }
3802#ifdef HAVE_IPV6
3803 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3804 {
3805 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3806 VTY_NEWLINE);
3807 return CMD_WARNING;
3808 }
3809#endif /* HAVE_IPV6 */
3810
3811 apply_mask (&p);
3812
3813 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3814 if (! rn)
3815 {
3816 vty_out (vty, "%% Can't find specified static route configuration.%s",
3817 VTY_NEWLINE);
3818 return CMD_WARNING;
3819 }
3820
3821 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003822
paul718e3742002-12-13 20:15:29 +00003823 /* Update BGP RIB. */
3824 if (! bgp_static->backdoor)
3825 bgp_static_withdraw (bgp, &p, afi, safi);
3826
3827 /* Clear configuration. */
3828 bgp_static_free (bgp_static);
3829 rn->info = NULL;
3830 bgp_unlock_node (rn);
3831 bgp_unlock_node (rn);
3832
3833 return CMD_SUCCESS;
3834}
3835
3836/* Called from bgp_delete(). Delete all static routes from the BGP
3837 instance. */
3838void
3839bgp_static_delete (struct bgp *bgp)
3840{
3841 afi_t afi;
3842 safi_t safi;
3843 struct bgp_node *rn;
3844 struct bgp_node *rm;
3845 struct bgp_table *table;
3846 struct bgp_static *bgp_static;
3847
3848 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3849 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3850 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3851 if (rn->info != NULL)
3852 {
3853 if (safi == SAFI_MPLS_VPN)
3854 {
3855 table = rn->info;
3856
3857 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3858 {
3859 bgp_static = rn->info;
3860 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3861 AFI_IP, SAFI_MPLS_VPN,
3862 (struct prefix_rd *)&rn->p,
3863 bgp_static->tag);
3864 bgp_static_free (bgp_static);
3865 rn->info = NULL;
3866 bgp_unlock_node (rn);
3867 }
3868 }
3869 else
3870 {
3871 bgp_static = rn->info;
3872 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3873 bgp_static_free (bgp_static);
3874 rn->info = NULL;
3875 bgp_unlock_node (rn);
3876 }
3877 }
3878}
3879
3880int
paulfd79ac92004-10-13 05:06:08 +00003881bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3882 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003883{
3884 int ret;
3885 struct prefix p;
3886 struct prefix_rd prd;
3887 struct bgp *bgp;
3888 struct bgp_node *prn;
3889 struct bgp_node *rn;
3890 struct bgp_table *table;
3891 struct bgp_static *bgp_static;
3892 u_char tag[3];
3893
3894 bgp = vty->index;
3895
3896 ret = str2prefix (ip_str, &p);
3897 if (! ret)
3898 {
3899 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3900 return CMD_WARNING;
3901 }
3902 apply_mask (&p);
3903
3904 ret = str2prefix_rd (rd_str, &prd);
3905 if (! ret)
3906 {
3907 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3908 return CMD_WARNING;
3909 }
3910
3911 ret = str2tag (tag_str, tag);
3912 if (! ret)
3913 {
3914 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3915 return CMD_WARNING;
3916 }
3917
3918 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3919 (struct prefix *)&prd);
3920 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003921 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003922 else
3923 bgp_unlock_node (prn);
3924 table = prn->info;
3925
3926 rn = bgp_node_get (table, &p);
3927
3928 if (rn->info)
3929 {
3930 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3931 bgp_unlock_node (rn);
3932 }
3933 else
3934 {
3935 /* New configuration. */
3936 bgp_static = bgp_static_new ();
3937 bgp_static->valid = 1;
3938 memcpy (bgp_static->tag, tag, 3);
3939 rn->info = bgp_static;
3940
3941 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3942 }
3943
3944 return CMD_SUCCESS;
3945}
3946
3947/* Configure static BGP network. */
3948int
paulfd79ac92004-10-13 05:06:08 +00003949bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3950 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003951{
3952 int ret;
3953 struct bgp *bgp;
3954 struct prefix p;
3955 struct prefix_rd prd;
3956 struct bgp_node *prn;
3957 struct bgp_node *rn;
3958 struct bgp_table *table;
3959 struct bgp_static *bgp_static;
3960 u_char tag[3];
3961
3962 bgp = vty->index;
3963
3964 /* Convert IP prefix string to struct prefix. */
3965 ret = str2prefix (ip_str, &p);
3966 if (! ret)
3967 {
3968 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3969 return CMD_WARNING;
3970 }
3971 apply_mask (&p);
3972
3973 ret = str2prefix_rd (rd_str, &prd);
3974 if (! ret)
3975 {
3976 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3977 return CMD_WARNING;
3978 }
3979
3980 ret = str2tag (tag_str, tag);
3981 if (! ret)
3982 {
3983 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3984 return CMD_WARNING;
3985 }
3986
3987 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3988 (struct prefix *)&prd);
3989 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003990 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003991 else
3992 bgp_unlock_node (prn);
3993 table = prn->info;
3994
3995 rn = bgp_node_lookup (table, &p);
3996
3997 if (rn)
3998 {
3999 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4000
4001 bgp_static = rn->info;
4002 bgp_static_free (bgp_static);
4003 rn->info = NULL;
4004 bgp_unlock_node (rn);
4005 bgp_unlock_node (rn);
4006 }
4007 else
4008 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4009
4010 return CMD_SUCCESS;
4011}
David Lamparter6b0655a2014-06-04 06:53:35 +02004012
paul718e3742002-12-13 20:15:29 +00004013DEFUN (bgp_network,
4014 bgp_network_cmd,
4015 "network A.B.C.D/M",
4016 "Specify a network to announce via BGP\n"
4017 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4018{
4019 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004020 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004021}
4022
4023DEFUN (bgp_network_route_map,
4024 bgp_network_route_map_cmd,
4025 "network A.B.C.D/M route-map WORD",
4026 "Specify a network to announce via BGP\n"
4027 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4028 "Route-map to modify the attributes\n"
4029 "Name of the route map\n")
4030{
4031 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004032 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004033}
4034
4035DEFUN (bgp_network_backdoor,
4036 bgp_network_backdoor_cmd,
4037 "network A.B.C.D/M backdoor",
4038 "Specify a network to announce via BGP\n"
4039 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4040 "Specify a BGP backdoor route\n")
4041{
Paul Jakma41367172007-08-06 15:24:51 +00004042 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004043 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004044}
4045
4046DEFUN (bgp_network_mask,
4047 bgp_network_mask_cmd,
4048 "network A.B.C.D mask A.B.C.D",
4049 "Specify a network to announce via BGP\n"
4050 "Network number\n"
4051 "Network mask\n"
4052 "Network mask\n")
4053{
4054 int ret;
4055 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004056
paul718e3742002-12-13 20:15:29 +00004057 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4058 if (! ret)
4059 {
4060 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4061 return CMD_WARNING;
4062 }
4063
4064 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004065 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004066}
4067
4068DEFUN (bgp_network_mask_route_map,
4069 bgp_network_mask_route_map_cmd,
4070 "network A.B.C.D mask A.B.C.D route-map WORD",
4071 "Specify a network to announce via BGP\n"
4072 "Network number\n"
4073 "Network mask\n"
4074 "Network mask\n"
4075 "Route-map to modify the attributes\n"
4076 "Name of the route map\n")
4077{
4078 int ret;
4079 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004080
paul718e3742002-12-13 20:15:29 +00004081 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4082 if (! ret)
4083 {
4084 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4085 return CMD_WARNING;
4086 }
4087
4088 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004089 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004090}
4091
4092DEFUN (bgp_network_mask_backdoor,
4093 bgp_network_mask_backdoor_cmd,
4094 "network A.B.C.D mask A.B.C.D backdoor",
4095 "Specify a network to announce via BGP\n"
4096 "Network number\n"
4097 "Network mask\n"
4098 "Network mask\n"
4099 "Specify a BGP backdoor route\n")
4100{
4101 int ret;
4102 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004103
paul718e3742002-12-13 20:15:29 +00004104 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4105 if (! ret)
4106 {
4107 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4108 return CMD_WARNING;
4109 }
4110
Paul Jakma41367172007-08-06 15:24:51 +00004111 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004112 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004113}
4114
4115DEFUN (bgp_network_mask_natural,
4116 bgp_network_mask_natural_cmd,
4117 "network A.B.C.D",
4118 "Specify a network to announce via BGP\n"
4119 "Network number\n")
4120{
4121 int ret;
4122 char prefix_str[BUFSIZ];
4123
4124 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4125 if (! ret)
4126 {
4127 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4128 return CMD_WARNING;
4129 }
4130
4131 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004132 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004133}
4134
4135DEFUN (bgp_network_mask_natural_route_map,
4136 bgp_network_mask_natural_route_map_cmd,
4137 "network A.B.C.D route-map WORD",
4138 "Specify a network to announce via BGP\n"
4139 "Network number\n"
4140 "Route-map to modify the attributes\n"
4141 "Name of the route map\n")
4142{
4143 int ret;
4144 char prefix_str[BUFSIZ];
4145
4146 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4147 if (! ret)
4148 {
4149 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4150 return CMD_WARNING;
4151 }
4152
4153 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004154 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004155}
4156
4157DEFUN (bgp_network_mask_natural_backdoor,
4158 bgp_network_mask_natural_backdoor_cmd,
4159 "network A.B.C.D backdoor",
4160 "Specify a network to announce via BGP\n"
4161 "Network number\n"
4162 "Specify a BGP backdoor route\n")
4163{
4164 int ret;
4165 char prefix_str[BUFSIZ];
4166
4167 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4168 if (! ret)
4169 {
4170 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4171 return CMD_WARNING;
4172 }
4173
Paul Jakma41367172007-08-06 15:24:51 +00004174 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004175 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004176}
4177
4178DEFUN (no_bgp_network,
4179 no_bgp_network_cmd,
4180 "no network A.B.C.D/M",
4181 NO_STR
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_unset (vty, vty->index, argv[0], AFI_IP,
4186 bgp_node_safi (vty));
4187}
4188
4189ALIAS (no_bgp_network,
4190 no_bgp_network_route_map_cmd,
4191 "no network A.B.C.D/M route-map WORD",
4192 NO_STR
4193 "Specify a network to announce via BGP\n"
4194 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4195 "Route-map to modify the attributes\n"
4196 "Name of the route map\n")
4197
4198ALIAS (no_bgp_network,
4199 no_bgp_network_backdoor_cmd,
4200 "no network A.B.C.D/M backdoor",
4201 NO_STR
4202 "Specify a network to announce via BGP\n"
4203 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4204 "Specify a BGP backdoor route\n")
4205
4206DEFUN (no_bgp_network_mask,
4207 no_bgp_network_mask_cmd,
4208 "no network A.B.C.D mask A.B.C.D",
4209 NO_STR
4210 "Specify a network to announce via BGP\n"
4211 "Network number\n"
4212 "Network mask\n"
4213 "Network mask\n")
4214{
4215 int ret;
4216 char prefix_str[BUFSIZ];
4217
4218 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4219 if (! ret)
4220 {
4221 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4222 return CMD_WARNING;
4223 }
4224
4225 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4226 bgp_node_safi (vty));
4227}
4228
4229ALIAS (no_bgp_network_mask,
4230 no_bgp_network_mask_route_map_cmd,
4231 "no network A.B.C.D mask A.B.C.D route-map WORD",
4232 NO_STR
4233 "Specify a network to announce via BGP\n"
4234 "Network number\n"
4235 "Network mask\n"
4236 "Network mask\n"
4237 "Route-map to modify the attributes\n"
4238 "Name of the route map\n")
4239
4240ALIAS (no_bgp_network_mask,
4241 no_bgp_network_mask_backdoor_cmd,
4242 "no network A.B.C.D mask A.B.C.D backdoor",
4243 NO_STR
4244 "Specify a network to announce via BGP\n"
4245 "Network number\n"
4246 "Network mask\n"
4247 "Network mask\n"
4248 "Specify a BGP backdoor route\n")
4249
4250DEFUN (no_bgp_network_mask_natural,
4251 no_bgp_network_mask_natural_cmd,
4252 "no network A.B.C.D",
4253 NO_STR
4254 "Specify a network to announce via BGP\n"
4255 "Network number\n")
4256{
4257 int ret;
4258 char prefix_str[BUFSIZ];
4259
4260 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4261 if (! ret)
4262 {
4263 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4264 return CMD_WARNING;
4265 }
4266
4267 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4268 bgp_node_safi (vty));
4269}
4270
4271ALIAS (no_bgp_network_mask_natural,
4272 no_bgp_network_mask_natural_route_map_cmd,
4273 "no network A.B.C.D route-map WORD",
4274 NO_STR
4275 "Specify a network to announce via BGP\n"
4276 "Network number\n"
4277 "Route-map to modify the attributes\n"
4278 "Name of the route map\n")
4279
4280ALIAS (no_bgp_network_mask_natural,
4281 no_bgp_network_mask_natural_backdoor_cmd,
4282 "no network A.B.C.D backdoor",
4283 NO_STR
4284 "Specify a network to announce via BGP\n"
4285 "Network number\n"
4286 "Specify a BGP backdoor route\n")
4287
4288#ifdef HAVE_IPV6
4289DEFUN (ipv6_bgp_network,
4290 ipv6_bgp_network_cmd,
4291 "network X:X::X:X/M",
4292 "Specify a network to announce via BGP\n"
4293 "IPv6 prefix <network>/<length>\n")
4294{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304295 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004296 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004297}
4298
4299DEFUN (ipv6_bgp_network_route_map,
4300 ipv6_bgp_network_route_map_cmd,
4301 "network X:X::X:X/M route-map WORD",
4302 "Specify a network to announce via BGP\n"
4303 "IPv6 prefix <network>/<length>\n"
4304 "Route-map to modify the attributes\n"
4305 "Name of the route map\n")
4306{
4307 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004308 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004309}
4310
4311DEFUN (no_ipv6_bgp_network,
4312 no_ipv6_bgp_network_cmd,
4313 "no network X:X::X:X/M",
4314 NO_STR
4315 "Specify a network to announce via BGP\n"
4316 "IPv6 prefix <network>/<length>\n")
4317{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304318 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004319}
4320
4321ALIAS (no_ipv6_bgp_network,
4322 no_ipv6_bgp_network_route_map_cmd,
4323 "no network X:X::X:X/M route-map WORD",
4324 NO_STR
4325 "Specify a network to announce via BGP\n"
4326 "IPv6 prefix <network>/<length>\n"
4327 "Route-map to modify the attributes\n"
4328 "Name of the route map\n")
4329
4330ALIAS (ipv6_bgp_network,
4331 old_ipv6_bgp_network_cmd,
4332 "ipv6 bgp network X:X::X:X/M",
4333 IPV6_STR
4334 BGP_STR
4335 "Specify a network to announce via BGP\n"
4336 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4337
4338ALIAS (no_ipv6_bgp_network,
4339 old_no_ipv6_bgp_network_cmd,
4340 "no ipv6 bgp network X:X::X:X/M",
4341 NO_STR
4342 IPV6_STR
4343 BGP_STR
4344 "Specify a network to announce via BGP\n"
4345 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4346#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004347
4348/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4349ALIAS_DEPRECATED (bgp_network,
4350 bgp_network_ttl_cmd,
4351 "network A.B.C.D/M pathlimit <0-255>",
4352 "Specify a network to announce via BGP\n"
4353 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4354 "AS-Path hopcount limit attribute\n"
4355 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4356ALIAS_DEPRECATED (bgp_network_backdoor,
4357 bgp_network_backdoor_ttl_cmd,
4358 "network A.B.C.D/M backdoor pathlimit <0-255>",
4359 "Specify a network to announce via BGP\n"
4360 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4361 "Specify a BGP backdoor route\n"
4362 "AS-Path hopcount limit attribute\n"
4363 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4364ALIAS_DEPRECATED (bgp_network_mask,
4365 bgp_network_mask_ttl_cmd,
4366 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4367 "Specify a network to announce via BGP\n"
4368 "Network number\n"
4369 "Network mask\n"
4370 "Network mask\n"
4371 "AS-Path hopcount limit attribute\n"
4372 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4373ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4374 bgp_network_mask_backdoor_ttl_cmd,
4375 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4376 "Specify a network to announce via BGP\n"
4377 "Network number\n"
4378 "Network mask\n"
4379 "Network mask\n"
4380 "Specify a BGP backdoor route\n"
4381 "AS-Path hopcount limit attribute\n"
4382 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4383ALIAS_DEPRECATED (bgp_network_mask_natural,
4384 bgp_network_mask_natural_ttl_cmd,
4385 "network A.B.C.D pathlimit <0-255>",
4386 "Specify a network to announce via BGP\n"
4387 "Network number\n"
4388 "AS-Path hopcount limit attribute\n"
4389 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4390ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4391 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004392 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004393 "Specify a network to announce via BGP\n"
4394 "Network number\n"
4395 "Specify a BGP backdoor route\n"
4396 "AS-Path hopcount limit attribute\n"
4397 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4398ALIAS_DEPRECATED (no_bgp_network,
4399 no_bgp_network_ttl_cmd,
4400 "no network A.B.C.D/M pathlimit <0-255>",
4401 NO_STR
4402 "Specify a network to announce via BGP\n"
4403 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4404 "AS-Path hopcount limit attribute\n"
4405 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4406ALIAS_DEPRECATED (no_bgp_network,
4407 no_bgp_network_backdoor_ttl_cmd,
4408 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4409 NO_STR
4410 "Specify a network to announce via BGP\n"
4411 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4412 "Specify a BGP backdoor route\n"
4413 "AS-Path hopcount limit attribute\n"
4414 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4415ALIAS_DEPRECATED (no_bgp_network,
4416 no_bgp_network_mask_ttl_cmd,
4417 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4418 NO_STR
4419 "Specify a network to announce via BGP\n"
4420 "Network number\n"
4421 "Network mask\n"
4422 "Network mask\n"
4423 "AS-Path hopcount limit attribute\n"
4424 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4425ALIAS_DEPRECATED (no_bgp_network_mask,
4426 no_bgp_network_mask_backdoor_ttl_cmd,
4427 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4428 NO_STR
4429 "Specify a network to announce via BGP\n"
4430 "Network number\n"
4431 "Network mask\n"
4432 "Network mask\n"
4433 "Specify a BGP backdoor route\n"
4434 "AS-Path hopcount limit attribute\n"
4435 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4436ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4437 no_bgp_network_mask_natural_ttl_cmd,
4438 "no network A.B.C.D pathlimit <0-255>",
4439 NO_STR
4440 "Specify a network to announce via BGP\n"
4441 "Network number\n"
4442 "AS-Path hopcount limit attribute\n"
4443 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4444ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4445 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4446 "no network A.B.C.D backdoor pathlimit <0-255>",
4447 NO_STR
4448 "Specify a network to announce via BGP\n"
4449 "Network number\n"
4450 "Specify a BGP backdoor route\n"
4451 "AS-Path hopcount limit attribute\n"
4452 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004453#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004454ALIAS_DEPRECATED (ipv6_bgp_network,
4455 ipv6_bgp_network_ttl_cmd,
4456 "network X:X::X:X/M pathlimit <0-255>",
4457 "Specify a network to announce via BGP\n"
4458 "IPv6 prefix <network>/<length>\n"
4459 "AS-Path hopcount limit attribute\n"
4460 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4461ALIAS_DEPRECATED (no_ipv6_bgp_network,
4462 no_ipv6_bgp_network_ttl_cmd,
4463 "no network X:X::X:X/M pathlimit <0-255>",
4464 NO_STR
4465 "Specify a network to announce via BGP\n"
4466 "IPv6 prefix <network>/<length>\n"
4467 "AS-Path hopcount limit attribute\n"
4468 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004469#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02004470
paul718e3742002-12-13 20:15:29 +00004471/* Aggreagete address:
4472
4473 advertise-map Set condition to advertise attribute
4474 as-set Generate AS set path information
4475 attribute-map Set attributes of aggregate
4476 route-map Set parameters of aggregate
4477 summary-only Filter more specific routes from updates
4478 suppress-map Conditionally filter more specific routes from updates
4479 <cr>
4480 */
4481struct bgp_aggregate
4482{
4483 /* Summary-only flag. */
4484 u_char summary_only;
4485
4486 /* AS set generation. */
4487 u_char as_set;
4488
4489 /* Route-map for aggregated route. */
4490 struct route_map *map;
4491
4492 /* Suppress-count. */
4493 unsigned long count;
4494
4495 /* SAFI configuration. */
4496 safi_t safi;
4497};
4498
paul94f2b392005-06-28 12:44:16 +00004499static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004500bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004501{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004502 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004503}
4504
paul94f2b392005-06-28 12:44:16 +00004505static void
paul718e3742002-12-13 20:15:29 +00004506bgp_aggregate_free (struct bgp_aggregate *aggregate)
4507{
4508 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4509}
4510
paul94f2b392005-06-28 12:44:16 +00004511static void
paul718e3742002-12-13 20:15:29 +00004512bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4513 afi_t afi, safi_t safi, struct bgp_info *del,
4514 struct bgp_aggregate *aggregate)
4515{
4516 struct bgp_table *table;
4517 struct bgp_node *top;
4518 struct bgp_node *rn;
4519 u_char origin;
4520 struct aspath *aspath = NULL;
4521 struct aspath *asmerge = NULL;
4522 struct community *community = NULL;
4523 struct community *commerge = NULL;
4524 struct in_addr nexthop;
4525 u_int32_t med = 0;
4526 struct bgp_info *ri;
4527 struct bgp_info *new;
4528 int first = 1;
4529 unsigned long match = 0;
4530
4531 /* Record adding route's nexthop and med. */
4532 if (rinew)
4533 {
4534 nexthop = rinew->attr->nexthop;
4535 med = rinew->attr->med;
4536 }
4537
4538 /* ORIGIN attribute: If at least one route among routes that are
4539 aggregated has ORIGIN with the value INCOMPLETE, then the
4540 aggregated route must have the ORIGIN attribute with the value
4541 INCOMPLETE. Otherwise, if at least one route among routes that
4542 are aggregated has ORIGIN with the value EGP, then the aggregated
4543 route must have the origin attribute with the value EGP. In all
4544 other case the value of the ORIGIN attribute of the aggregated
4545 route is INTERNAL. */
4546 origin = BGP_ORIGIN_IGP;
4547
4548 table = bgp->rib[afi][safi];
4549
4550 top = bgp_node_get (table, p);
4551 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4552 if (rn->p.prefixlen > p->prefixlen)
4553 {
4554 match = 0;
4555
4556 for (ri = rn->info; ri; ri = ri->next)
4557 {
4558 if (BGP_INFO_HOLDDOWN (ri))
4559 continue;
4560
4561 if (del && ri == del)
4562 continue;
4563
4564 if (! rinew && first)
4565 {
4566 nexthop = ri->attr->nexthop;
4567 med = ri->attr->med;
4568 first = 0;
4569 }
4570
4571#ifdef AGGREGATE_NEXTHOP_CHECK
4572 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4573 || ri->attr->med != med)
4574 {
4575 if (aspath)
4576 aspath_free (aspath);
4577 if (community)
4578 community_free (community);
4579 bgp_unlock_node (rn);
4580 bgp_unlock_node (top);
4581 return;
4582 }
4583#endif /* AGGREGATE_NEXTHOP_CHECK */
4584
4585 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4586 {
4587 if (aggregate->summary_only)
4588 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004589 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004590 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004591 match++;
4592 }
4593
4594 aggregate->count++;
4595
4596 if (aggregate->as_set)
4597 {
4598 if (origin < ri->attr->origin)
4599 origin = ri->attr->origin;
4600
4601 if (aspath)
4602 {
4603 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4604 aspath_free (aspath);
4605 aspath = asmerge;
4606 }
4607 else
4608 aspath = aspath_dup (ri->attr->aspath);
4609
4610 if (ri->attr->community)
4611 {
4612 if (community)
4613 {
4614 commerge = community_merge (community,
4615 ri->attr->community);
4616 community = community_uniq_sort (commerge);
4617 community_free (commerge);
4618 }
4619 else
4620 community = community_dup (ri->attr->community);
4621 }
4622 }
4623 }
4624 }
4625 if (match)
4626 bgp_process (bgp, rn, afi, safi);
4627 }
4628 bgp_unlock_node (top);
4629
4630 if (rinew)
4631 {
4632 aggregate->count++;
4633
4634 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004635 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004636
4637 if (aggregate->as_set)
4638 {
4639 if (origin < rinew->attr->origin)
4640 origin = rinew->attr->origin;
4641
4642 if (aspath)
4643 {
4644 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4645 aspath_free (aspath);
4646 aspath = asmerge;
4647 }
4648 else
4649 aspath = aspath_dup (rinew->attr->aspath);
4650
4651 if (rinew->attr->community)
4652 {
4653 if (community)
4654 {
4655 commerge = community_merge (community,
4656 rinew->attr->community);
4657 community = community_uniq_sort (commerge);
4658 community_free (commerge);
4659 }
4660 else
4661 community = community_dup (rinew->attr->community);
4662 }
4663 }
4664 }
4665
4666 if (aggregate->count > 0)
4667 {
4668 rn = bgp_node_get (table, p);
4669 new = bgp_info_new ();
4670 new->type = ZEBRA_ROUTE_BGP;
4671 new->sub_type = BGP_ROUTE_AGGREGATE;
4672 new->peer = bgp->peer_self;
4673 SET_FLAG (new->flags, BGP_INFO_VALID);
4674 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004675 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004676
4677 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004678 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004679 bgp_process (bgp, rn, afi, safi);
4680 }
4681 else
4682 {
4683 if (aspath)
4684 aspath_free (aspath);
4685 if (community)
4686 community_free (community);
4687 }
4688}
4689
4690void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4691 struct bgp_aggregate *);
4692
4693void
4694bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4695 struct bgp_info *ri, afi_t afi, safi_t safi)
4696{
4697 struct bgp_node *child;
4698 struct bgp_node *rn;
4699 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004700 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004701
4702 /* MPLS-VPN aggregation is not yet supported. */
4703 if (safi == SAFI_MPLS_VPN)
4704 return;
4705
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004706 table = bgp->aggregate[afi][safi];
4707
4708 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004709 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004710 return;
4711
paul718e3742002-12-13 20:15:29 +00004712 if (p->prefixlen == 0)
4713 return;
4714
4715 if (BGP_INFO_HOLDDOWN (ri))
4716 return;
4717
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004718 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004719
4720 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004721 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004722 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4723 {
4724 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004725 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004726 }
4727 bgp_unlock_node (child);
4728}
4729
4730void
4731bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4732 struct bgp_info *del, afi_t afi, safi_t safi)
4733{
4734 struct bgp_node *child;
4735 struct bgp_node *rn;
4736 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004737 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004738
4739 /* MPLS-VPN aggregation is not yet supported. */
4740 if (safi == SAFI_MPLS_VPN)
4741 return;
4742
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004743 table = bgp->aggregate[afi][safi];
4744
4745 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004746 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004747 return;
4748
paul718e3742002-12-13 20:15:29 +00004749 if (p->prefixlen == 0)
4750 return;
4751
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004752 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004753
4754 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004755 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004756 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4757 {
4758 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004759 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004760 }
4761 bgp_unlock_node (child);
4762}
4763
paul94f2b392005-06-28 12:44:16 +00004764static void
paul718e3742002-12-13 20:15:29 +00004765bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4766 struct bgp_aggregate *aggregate)
4767{
4768 struct bgp_table *table;
4769 struct bgp_node *top;
4770 struct bgp_node *rn;
4771 struct bgp_info *new;
4772 struct bgp_info *ri;
4773 unsigned long match;
4774 u_char origin = BGP_ORIGIN_IGP;
4775 struct aspath *aspath = NULL;
4776 struct aspath *asmerge = NULL;
4777 struct community *community = NULL;
4778 struct community *commerge = NULL;
4779
4780 table = bgp->rib[afi][safi];
4781
4782 /* Sanity check. */
4783 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4784 return;
4785 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4786 return;
4787
4788 /* If routes exists below this node, generate aggregate routes. */
4789 top = bgp_node_get (table, p);
4790 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4791 if (rn->p.prefixlen > p->prefixlen)
4792 {
4793 match = 0;
4794
4795 for (ri = rn->info; ri; ri = ri->next)
4796 {
4797 if (BGP_INFO_HOLDDOWN (ri))
4798 continue;
4799
4800 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4801 {
4802 /* summary-only aggregate route suppress aggregated
4803 route announcement. */
4804 if (aggregate->summary_only)
4805 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004806 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004807 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004808 match++;
4809 }
4810 /* as-set aggregate route generate origin, as path,
4811 community aggregation. */
4812 if (aggregate->as_set)
4813 {
4814 if (origin < ri->attr->origin)
4815 origin = ri->attr->origin;
4816
4817 if (aspath)
4818 {
4819 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4820 aspath_free (aspath);
4821 aspath = asmerge;
4822 }
4823 else
4824 aspath = aspath_dup (ri->attr->aspath);
4825
4826 if (ri->attr->community)
4827 {
4828 if (community)
4829 {
4830 commerge = community_merge (community,
4831 ri->attr->community);
4832 community = community_uniq_sort (commerge);
4833 community_free (commerge);
4834 }
4835 else
4836 community = community_dup (ri->attr->community);
4837 }
4838 }
4839 aggregate->count++;
4840 }
4841 }
4842
4843 /* If this node is suppressed, process the change. */
4844 if (match)
4845 bgp_process (bgp, rn, afi, safi);
4846 }
4847 bgp_unlock_node (top);
4848
4849 /* Add aggregate route to BGP table. */
4850 if (aggregate->count)
4851 {
4852 rn = bgp_node_get (table, p);
4853
4854 new = bgp_info_new ();
4855 new->type = ZEBRA_ROUTE_BGP;
4856 new->sub_type = BGP_ROUTE_AGGREGATE;
4857 new->peer = bgp->peer_self;
4858 SET_FLAG (new->flags, BGP_INFO_VALID);
4859 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004860 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004861
4862 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004863 bgp_unlock_node (rn);
4864
paul718e3742002-12-13 20:15:29 +00004865 /* Process change. */
4866 bgp_process (bgp, rn, afi, safi);
4867 }
4868}
4869
4870void
4871bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4872 safi_t safi, struct bgp_aggregate *aggregate)
4873{
4874 struct bgp_table *table;
4875 struct bgp_node *top;
4876 struct bgp_node *rn;
4877 struct bgp_info *ri;
4878 unsigned long match;
4879
4880 table = bgp->rib[afi][safi];
4881
4882 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4883 return;
4884 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4885 return;
4886
4887 /* If routes exists below this node, generate aggregate routes. */
4888 top = bgp_node_get (table, p);
4889 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4890 if (rn->p.prefixlen > p->prefixlen)
4891 {
4892 match = 0;
4893
4894 for (ri = rn->info; ri; ri = ri->next)
4895 {
4896 if (BGP_INFO_HOLDDOWN (ri))
4897 continue;
4898
4899 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4900 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004901 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004902 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004903 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004904
Paul Jakmafb982c22007-05-04 20:15:47 +00004905 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004906 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004907 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004908 match++;
4909 }
4910 }
4911 aggregate->count--;
4912 }
4913 }
4914
Paul Jakmafb982c22007-05-04 20:15:47 +00004915 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004916 if (match)
4917 bgp_process (bgp, rn, afi, safi);
4918 }
4919 bgp_unlock_node (top);
4920
4921 /* Delete aggregate route from BGP table. */
4922 rn = bgp_node_get (table, p);
4923
4924 for (ri = rn->info; ri; ri = ri->next)
4925 if (ri->peer == bgp->peer_self
4926 && ri->type == ZEBRA_ROUTE_BGP
4927 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4928 break;
4929
4930 /* Withdraw static BGP route from routing table. */
4931 if (ri)
4932 {
paul718e3742002-12-13 20:15:29 +00004933 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004934 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004935 }
4936
4937 /* Unlock bgp_node_lookup. */
4938 bgp_unlock_node (rn);
4939}
4940
4941/* Aggregate route attribute. */
4942#define AGGREGATE_SUMMARY_ONLY 1
4943#define AGGREGATE_AS_SET 1
4944
paul94f2b392005-06-28 12:44:16 +00004945static int
Robert Baysf6269b42010-08-05 10:26:28 -07004946bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4947 afi_t afi, safi_t safi)
4948{
4949 int ret;
4950 struct prefix p;
4951 struct bgp_node *rn;
4952 struct bgp *bgp;
4953 struct bgp_aggregate *aggregate;
4954
4955 /* Convert string to prefix structure. */
4956 ret = str2prefix (prefix_str, &p);
4957 if (!ret)
4958 {
4959 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4960 return CMD_WARNING;
4961 }
4962 apply_mask (&p);
4963
4964 /* Get BGP structure. */
4965 bgp = vty->index;
4966
4967 /* Old configuration check. */
4968 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4969 if (! rn)
4970 {
4971 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4972 VTY_NEWLINE);
4973 return CMD_WARNING;
4974 }
4975
4976 aggregate = rn->info;
4977 if (aggregate->safi & SAFI_UNICAST)
4978 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4979 if (aggregate->safi & SAFI_MULTICAST)
4980 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4981
4982 /* Unlock aggregate address configuration. */
4983 rn->info = NULL;
4984 bgp_aggregate_free (aggregate);
4985 bgp_unlock_node (rn);
4986 bgp_unlock_node (rn);
4987
4988 return CMD_SUCCESS;
4989}
4990
4991static int
4992bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00004993 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004994 u_char summary_only, u_char as_set)
4995{
4996 int ret;
4997 struct prefix p;
4998 struct bgp_node *rn;
4999 struct bgp *bgp;
5000 struct bgp_aggregate *aggregate;
5001
5002 /* Convert string to prefix structure. */
5003 ret = str2prefix (prefix_str, &p);
5004 if (!ret)
5005 {
5006 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5007 return CMD_WARNING;
5008 }
5009 apply_mask (&p);
5010
5011 /* Get BGP structure. */
5012 bgp = vty->index;
5013
5014 /* Old configuration check. */
5015 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5016
5017 if (rn->info)
5018 {
5019 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005020 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005021 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5022 if (ret)
5023 {
Robert Bays368473f2010-08-05 10:26:29 -07005024 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5025 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005026 return CMD_WARNING;
5027 }
paul718e3742002-12-13 20:15:29 +00005028 }
5029
5030 /* Make aggregate address structure. */
5031 aggregate = bgp_aggregate_new ();
5032 aggregate->summary_only = summary_only;
5033 aggregate->as_set = as_set;
5034 aggregate->safi = safi;
5035 rn->info = aggregate;
5036
5037 /* Aggregate address insert into BGP routing table. */
5038 if (safi & SAFI_UNICAST)
5039 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5040 if (safi & SAFI_MULTICAST)
5041 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5042
5043 return CMD_SUCCESS;
5044}
5045
paul718e3742002-12-13 20:15:29 +00005046DEFUN (aggregate_address,
5047 aggregate_address_cmd,
5048 "aggregate-address A.B.C.D/M",
5049 "Configure BGP aggregate entries\n"
5050 "Aggregate prefix\n")
5051{
5052 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5053}
5054
5055DEFUN (aggregate_address_mask,
5056 aggregate_address_mask_cmd,
5057 "aggregate-address A.B.C.D A.B.C.D",
5058 "Configure BGP aggregate entries\n"
5059 "Aggregate address\n"
5060 "Aggregate mask\n")
5061{
5062 int ret;
5063 char prefix_str[BUFSIZ];
5064
5065 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5066
5067 if (! ret)
5068 {
5069 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5070 return CMD_WARNING;
5071 }
5072
5073 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5074 0, 0);
5075}
5076
5077DEFUN (aggregate_address_summary_only,
5078 aggregate_address_summary_only_cmd,
5079 "aggregate-address A.B.C.D/M summary-only",
5080 "Configure BGP aggregate entries\n"
5081 "Aggregate prefix\n"
5082 "Filter more specific routes from updates\n")
5083{
5084 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5085 AGGREGATE_SUMMARY_ONLY, 0);
5086}
5087
5088DEFUN (aggregate_address_mask_summary_only,
5089 aggregate_address_mask_summary_only_cmd,
5090 "aggregate-address A.B.C.D A.B.C.D summary-only",
5091 "Configure BGP aggregate entries\n"
5092 "Aggregate address\n"
5093 "Aggregate mask\n"
5094 "Filter more specific routes from updates\n")
5095{
5096 int ret;
5097 char prefix_str[BUFSIZ];
5098
5099 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5100
5101 if (! ret)
5102 {
5103 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5104 return CMD_WARNING;
5105 }
5106
5107 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5108 AGGREGATE_SUMMARY_ONLY, 0);
5109}
5110
5111DEFUN (aggregate_address_as_set,
5112 aggregate_address_as_set_cmd,
5113 "aggregate-address A.B.C.D/M as-set",
5114 "Configure BGP aggregate entries\n"
5115 "Aggregate prefix\n"
5116 "Generate AS set path information\n")
5117{
5118 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5119 0, AGGREGATE_AS_SET);
5120}
5121
5122DEFUN (aggregate_address_mask_as_set,
5123 aggregate_address_mask_as_set_cmd,
5124 "aggregate-address A.B.C.D A.B.C.D as-set",
5125 "Configure BGP aggregate entries\n"
5126 "Aggregate address\n"
5127 "Aggregate mask\n"
5128 "Generate AS set path information\n")
5129{
5130 int ret;
5131 char prefix_str[BUFSIZ];
5132
5133 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5134
5135 if (! ret)
5136 {
5137 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5138 return CMD_WARNING;
5139 }
5140
5141 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5142 0, AGGREGATE_AS_SET);
5143}
5144
5145
5146DEFUN (aggregate_address_as_set_summary,
5147 aggregate_address_as_set_summary_cmd,
5148 "aggregate-address A.B.C.D/M as-set summary-only",
5149 "Configure BGP aggregate entries\n"
5150 "Aggregate prefix\n"
5151 "Generate AS set path information\n"
5152 "Filter more specific routes from updates\n")
5153{
5154 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5155 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5156}
5157
5158ALIAS (aggregate_address_as_set_summary,
5159 aggregate_address_summary_as_set_cmd,
5160 "aggregate-address A.B.C.D/M summary-only as-set",
5161 "Configure BGP aggregate entries\n"
5162 "Aggregate prefix\n"
5163 "Filter more specific routes from updates\n"
5164 "Generate AS set path information\n")
5165
5166DEFUN (aggregate_address_mask_as_set_summary,
5167 aggregate_address_mask_as_set_summary_cmd,
5168 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5169 "Configure BGP aggregate entries\n"
5170 "Aggregate address\n"
5171 "Aggregate mask\n"
5172 "Generate AS set path information\n"
5173 "Filter more specific routes from updates\n")
5174{
5175 int ret;
5176 char prefix_str[BUFSIZ];
5177
5178 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5179
5180 if (! ret)
5181 {
5182 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5183 return CMD_WARNING;
5184 }
5185
5186 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5187 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5188}
5189
5190ALIAS (aggregate_address_mask_as_set_summary,
5191 aggregate_address_mask_summary_as_set_cmd,
5192 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5193 "Configure BGP aggregate entries\n"
5194 "Aggregate address\n"
5195 "Aggregate mask\n"
5196 "Filter more specific routes from updates\n"
5197 "Generate AS set path information\n")
5198
5199DEFUN (no_aggregate_address,
5200 no_aggregate_address_cmd,
5201 "no aggregate-address A.B.C.D/M",
5202 NO_STR
5203 "Configure BGP aggregate entries\n"
5204 "Aggregate prefix\n")
5205{
5206 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5207}
5208
5209ALIAS (no_aggregate_address,
5210 no_aggregate_address_summary_only_cmd,
5211 "no aggregate-address A.B.C.D/M summary-only",
5212 NO_STR
5213 "Configure BGP aggregate entries\n"
5214 "Aggregate prefix\n"
5215 "Filter more specific routes from updates\n")
5216
5217ALIAS (no_aggregate_address,
5218 no_aggregate_address_as_set_cmd,
5219 "no aggregate-address A.B.C.D/M as-set",
5220 NO_STR
5221 "Configure BGP aggregate entries\n"
5222 "Aggregate prefix\n"
5223 "Generate AS set path information\n")
5224
5225ALIAS (no_aggregate_address,
5226 no_aggregate_address_as_set_summary_cmd,
5227 "no aggregate-address A.B.C.D/M as-set summary-only",
5228 NO_STR
5229 "Configure BGP aggregate entries\n"
5230 "Aggregate prefix\n"
5231 "Generate AS set path information\n"
5232 "Filter more specific routes from updates\n")
5233
5234ALIAS (no_aggregate_address,
5235 no_aggregate_address_summary_as_set_cmd,
5236 "no aggregate-address A.B.C.D/M summary-only as-set",
5237 NO_STR
5238 "Configure BGP aggregate entries\n"
5239 "Aggregate prefix\n"
5240 "Filter more specific routes from updates\n"
5241 "Generate AS set path information\n")
5242
5243DEFUN (no_aggregate_address_mask,
5244 no_aggregate_address_mask_cmd,
5245 "no aggregate-address A.B.C.D A.B.C.D",
5246 NO_STR
5247 "Configure BGP aggregate entries\n"
5248 "Aggregate address\n"
5249 "Aggregate mask\n")
5250{
5251 int ret;
5252 char prefix_str[BUFSIZ];
5253
5254 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5255
5256 if (! ret)
5257 {
5258 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5259 return CMD_WARNING;
5260 }
5261
5262 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5263}
5264
5265ALIAS (no_aggregate_address_mask,
5266 no_aggregate_address_mask_summary_only_cmd,
5267 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5268 NO_STR
5269 "Configure BGP aggregate entries\n"
5270 "Aggregate address\n"
5271 "Aggregate mask\n"
5272 "Filter more specific routes from updates\n")
5273
5274ALIAS (no_aggregate_address_mask,
5275 no_aggregate_address_mask_as_set_cmd,
5276 "no aggregate-address A.B.C.D A.B.C.D as-set",
5277 NO_STR
5278 "Configure BGP aggregate entries\n"
5279 "Aggregate address\n"
5280 "Aggregate mask\n"
5281 "Generate AS set path information\n")
5282
5283ALIAS (no_aggregate_address_mask,
5284 no_aggregate_address_mask_as_set_summary_cmd,
5285 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5286 NO_STR
5287 "Configure BGP aggregate entries\n"
5288 "Aggregate address\n"
5289 "Aggregate mask\n"
5290 "Generate AS set path information\n"
5291 "Filter more specific routes from updates\n")
5292
5293ALIAS (no_aggregate_address_mask,
5294 no_aggregate_address_mask_summary_as_set_cmd,
5295 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5296 NO_STR
5297 "Configure BGP aggregate entries\n"
5298 "Aggregate address\n"
5299 "Aggregate mask\n"
5300 "Filter more specific routes from updates\n"
5301 "Generate AS set path information\n")
5302
5303#ifdef HAVE_IPV6
5304DEFUN (ipv6_aggregate_address,
5305 ipv6_aggregate_address_cmd,
5306 "aggregate-address X:X::X:X/M",
5307 "Configure BGP aggregate entries\n"
5308 "Aggregate prefix\n")
5309{
5310 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5311}
5312
5313DEFUN (ipv6_aggregate_address_summary_only,
5314 ipv6_aggregate_address_summary_only_cmd,
5315 "aggregate-address X:X::X:X/M summary-only",
5316 "Configure BGP aggregate entries\n"
5317 "Aggregate prefix\n"
5318 "Filter more specific routes from updates\n")
5319{
5320 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5321 AGGREGATE_SUMMARY_ONLY, 0);
5322}
5323
5324DEFUN (no_ipv6_aggregate_address,
5325 no_ipv6_aggregate_address_cmd,
5326 "no aggregate-address X:X::X:X/M",
5327 NO_STR
5328 "Configure BGP aggregate entries\n"
5329 "Aggregate prefix\n")
5330{
5331 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5332}
5333
5334DEFUN (no_ipv6_aggregate_address_summary_only,
5335 no_ipv6_aggregate_address_summary_only_cmd,
5336 "no aggregate-address X:X::X:X/M summary-only",
5337 NO_STR
5338 "Configure BGP aggregate entries\n"
5339 "Aggregate prefix\n"
5340 "Filter more specific routes from updates\n")
5341{
5342 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5343}
5344
5345ALIAS (ipv6_aggregate_address,
5346 old_ipv6_aggregate_address_cmd,
5347 "ipv6 bgp aggregate-address X:X::X:X/M",
5348 IPV6_STR
5349 BGP_STR
5350 "Configure BGP aggregate entries\n"
5351 "Aggregate prefix\n")
5352
5353ALIAS (ipv6_aggregate_address_summary_only,
5354 old_ipv6_aggregate_address_summary_only_cmd,
5355 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5356 IPV6_STR
5357 BGP_STR
5358 "Configure BGP aggregate entries\n"
5359 "Aggregate prefix\n"
5360 "Filter more specific routes from updates\n")
5361
5362ALIAS (no_ipv6_aggregate_address,
5363 old_no_ipv6_aggregate_address_cmd,
5364 "no ipv6 bgp aggregate-address X:X::X:X/M",
5365 NO_STR
5366 IPV6_STR
5367 BGP_STR
5368 "Configure BGP aggregate entries\n"
5369 "Aggregate prefix\n")
5370
5371ALIAS (no_ipv6_aggregate_address_summary_only,
5372 old_no_ipv6_aggregate_address_summary_only_cmd,
5373 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5374 NO_STR
5375 IPV6_STR
5376 BGP_STR
5377 "Configure BGP aggregate entries\n"
5378 "Aggregate prefix\n"
5379 "Filter more specific routes from updates\n")
5380#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02005381
paul718e3742002-12-13 20:15:29 +00005382/* Redistribute route treatment. */
5383void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005384bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5385 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005386 u_int32_t metric, u_char type)
5387{
5388 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005389 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005390 struct bgp_info *new;
5391 struct bgp_info *bi;
5392 struct bgp_info info;
5393 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005394 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005395 struct attr *new_attr;
5396 afi_t afi;
5397 int ret;
5398
5399 /* Make default attribute. */
5400 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5401 if (nexthop)
5402 attr.nexthop = *nexthop;
5403
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005404#ifdef HAVE_IPV6
5405 if (nexthop6)
5406 {
5407 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5408 extra->mp_nexthop_global = *nexthop6;
5409 extra->mp_nexthop_len = 16;
5410 }
5411#endif
5412
paul718e3742002-12-13 20:15:29 +00005413 attr.med = metric;
5414 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5415
paul1eb8ef22005-04-07 07:30:20 +00005416 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005417 {
5418 afi = family2afi (p->family);
5419
5420 if (bgp->redist[afi][type])
5421 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005422 struct attr attr_new;
5423 struct attr_extra extra_new;
5424
paul718e3742002-12-13 20:15:29 +00005425 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005426 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005427 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005428
5429 if (bgp->redist_metric_flag[afi][type])
5430 attr_new.med = bgp->redist_metric[afi][type];
5431
5432 /* Apply route-map. */
5433 if (bgp->rmap[afi][type].map)
5434 {
5435 info.peer = bgp->peer_self;
5436 info.attr = &attr_new;
5437
paulfee0f4c2004-09-13 05:12:46 +00005438 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5439
paul718e3742002-12-13 20:15:29 +00005440 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5441 &info);
paulfee0f4c2004-09-13 05:12:46 +00005442
5443 bgp->peer_self->rmap_type = 0;
5444
paul718e3742002-12-13 20:15:29 +00005445 if (ret == RMAP_DENYMATCH)
5446 {
5447 /* Free uninterned attribute. */
5448 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005449
paul718e3742002-12-13 20:15:29 +00005450 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005451 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005452 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005453 bgp_redistribute_delete (p, type);
5454 return;
5455 }
5456 }
5457
Paul Jakmafb982c22007-05-04 20:15:47 +00005458 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5459 afi, SAFI_UNICAST, p, NULL);
5460
paul718e3742002-12-13 20:15:29 +00005461 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005462
paul718e3742002-12-13 20:15:29 +00005463 for (bi = bn->info; bi; bi = bi->next)
5464 if (bi->peer == bgp->peer_self
5465 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5466 break;
5467
5468 if (bi)
5469 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005470 if (attrhash_cmp (bi->attr, new_attr) &&
5471 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005472 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005473 bgp_attr_unintern (&new_attr);
5474 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005475 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005476 bgp_unlock_node (bn);
5477 return;
5478 }
5479 else
5480 {
5481 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005482 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005483
5484 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005485 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5486 bgp_info_restore(bn, bi);
5487 else
5488 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005489 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005490 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005491 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005492
5493 /* Process change. */
5494 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5495 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5496 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005497 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005498 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005499 return;
5500 }
5501 }
5502
5503 new = bgp_info_new ();
5504 new->type = type;
5505 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5506 new->peer = bgp->peer_self;
5507 SET_FLAG (new->flags, BGP_INFO_VALID);
5508 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005509 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005510
5511 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5512 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005513 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005514 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5515 }
5516 }
5517
5518 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005519 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005520 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005521}
5522
5523void
5524bgp_redistribute_delete (struct prefix *p, u_char type)
5525{
5526 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005527 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005528 afi_t afi;
5529 struct bgp_node *rn;
5530 struct bgp_info *ri;
5531
paul1eb8ef22005-04-07 07:30:20 +00005532 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005533 {
5534 afi = family2afi (p->family);
5535
5536 if (bgp->redist[afi][type])
5537 {
paulfee0f4c2004-09-13 05:12:46 +00005538 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005539
5540 for (ri = rn->info; ri; ri = ri->next)
5541 if (ri->peer == bgp->peer_self
5542 && ri->type == type)
5543 break;
5544
5545 if (ri)
5546 {
5547 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005548 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005549 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005550 }
5551 bgp_unlock_node (rn);
5552 }
5553 }
5554}
5555
5556/* Withdraw specified route type's route. */
5557void
5558bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5559{
5560 struct bgp_node *rn;
5561 struct bgp_info *ri;
5562 struct bgp_table *table;
5563
5564 table = bgp->rib[afi][SAFI_UNICAST];
5565
5566 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5567 {
5568 for (ri = rn->info; ri; ri = ri->next)
5569 if (ri->peer == bgp->peer_self
5570 && ri->type == type)
5571 break;
5572
5573 if (ri)
5574 {
5575 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005576 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005577 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005578 }
5579 }
5580}
David Lamparter6b0655a2014-06-04 06:53:35 +02005581
paul718e3742002-12-13 20:15:29 +00005582/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005583static void
paul718e3742002-12-13 20:15:29 +00005584route_vty_out_route (struct prefix *p, struct vty *vty)
5585{
5586 int len;
5587 u_int32_t destination;
5588 char buf[BUFSIZ];
5589
5590 if (p->family == AF_INET)
5591 {
5592 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5593 destination = ntohl (p->u.prefix4.s_addr);
5594
5595 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5596 || (IN_CLASSB (destination) && p->prefixlen == 16)
5597 || (IN_CLASSA (destination) && p->prefixlen == 8)
5598 || p->u.prefix4.s_addr == 0)
5599 {
5600 /* When mask is natural, mask is not displayed. */
5601 }
5602 else
5603 len += vty_out (vty, "/%d", p->prefixlen);
5604 }
5605 else
5606 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5607 p->prefixlen);
5608
5609 len = 17 - len;
5610 if (len < 1)
5611 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5612 else
5613 vty_out (vty, "%*s", len, " ");
5614}
5615
paul718e3742002-12-13 20:15:29 +00005616enum bgp_display_type
5617{
5618 normal_list,
5619};
5620
paulb40d9392005-08-22 22:34:41 +00005621/* Print the short form route status for a bgp_info */
5622static void
5623route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005624{
paulb40d9392005-08-22 22:34:41 +00005625 /* Route status display. */
5626 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5627 vty_out (vty, "R");
5628 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005629 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005630 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005631 vty_out (vty, "s");
5632 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5633 vty_out (vty, "*");
5634 else
5635 vty_out (vty, " ");
5636
5637 /* Selected */
5638 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5639 vty_out (vty, "h");
5640 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5641 vty_out (vty, "d");
5642 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5643 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005644 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5645 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005646 else
5647 vty_out (vty, " ");
5648
5649 /* Internal route. */
5650 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5651 vty_out (vty, "i");
5652 else
paulb40d9392005-08-22 22:34:41 +00005653 vty_out (vty, " ");
5654}
5655
5656/* called from terminal list command */
5657void
5658route_vty_out (struct vty *vty, struct prefix *p,
5659 struct bgp_info *binfo, int display, safi_t safi)
5660{
5661 struct attr *attr;
5662
5663 /* short status lead text */
5664 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005665
5666 /* print prefix and mask */
5667 if (! display)
5668 route_vty_out_route (p, vty);
5669 else
5670 vty_out (vty, "%*s", 17, " ");
5671
5672 /* Print attribute */
5673 attr = binfo->attr;
5674 if (attr)
5675 {
5676 if (p->family == AF_INET)
5677 {
5678 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005679 vty_out (vty, "%-16s",
5680 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005681 else
5682 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5683 }
5684#ifdef HAVE_IPV6
5685 else if (p->family == AF_INET6)
5686 {
5687 int len;
5688 char buf[BUFSIZ];
5689
5690 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005691 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5692 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005693 len = 16 - len;
5694 if (len < 1)
5695 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5696 else
5697 vty_out (vty, "%*s", len, " ");
5698 }
5699#endif /* HAVE_IPV6 */
5700
5701 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005702 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005703 else
5704 vty_out (vty, " ");
5705
5706 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005707 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005708 else
5709 vty_out (vty, " ");
5710
Paul Jakmafb982c22007-05-04 20:15:47 +00005711 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005712
Paul Jakmab2518c12006-05-12 23:48:40 +00005713 /* Print aspath */
5714 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005715 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005716
Paul Jakmab2518c12006-05-12 23:48:40 +00005717 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005718 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005719 }
paul718e3742002-12-13 20:15:29 +00005720 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005721}
5722
5723/* called from terminal list command */
5724void
5725route_vty_out_tmp (struct vty *vty, struct prefix *p,
5726 struct attr *attr, safi_t safi)
5727{
5728 /* Route status display. */
5729 vty_out (vty, "*");
5730 vty_out (vty, ">");
5731 vty_out (vty, " ");
5732
5733 /* print prefix and mask */
5734 route_vty_out_route (p, vty);
5735
5736 /* Print attribute */
5737 if (attr)
5738 {
5739 if (p->family == AF_INET)
5740 {
5741 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005742 vty_out (vty, "%-16s",
5743 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005744 else
5745 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5746 }
5747#ifdef HAVE_IPV6
5748 else if (p->family == AF_INET6)
5749 {
5750 int len;
5751 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005752
5753 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005754
5755 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005756 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5757 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005758 len = 16 - len;
5759 if (len < 1)
5760 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5761 else
5762 vty_out (vty, "%*s", len, " ");
5763 }
5764#endif /* HAVE_IPV6 */
5765
5766 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005767 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005768 else
5769 vty_out (vty, " ");
5770
5771 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005772 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005773 else
5774 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005775
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005776 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005777
Paul Jakmab2518c12006-05-12 23:48:40 +00005778 /* Print aspath */
5779 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005780 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005781
Paul Jakmab2518c12006-05-12 23:48:40 +00005782 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005783 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005784 }
paul718e3742002-12-13 20:15:29 +00005785
5786 vty_out (vty, "%s", VTY_NEWLINE);
5787}
5788
ajs5a646652004-11-05 01:25:55 +00005789void
paul718e3742002-12-13 20:15:29 +00005790route_vty_out_tag (struct vty *vty, struct prefix *p,
5791 struct bgp_info *binfo, int display, safi_t safi)
5792{
5793 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005794 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005795
5796 if (!binfo->extra)
5797 return;
5798
paulb40d9392005-08-22 22:34:41 +00005799 /* short status lead text */
5800 route_vty_short_status_out (vty, binfo);
5801
paul718e3742002-12-13 20:15:29 +00005802 /* print prefix and mask */
5803 if (! display)
5804 route_vty_out_route (p, vty);
5805 else
5806 vty_out (vty, "%*s", 17, " ");
5807
5808 /* Print attribute */
5809 attr = binfo->attr;
5810 if (attr)
5811 {
5812 if (p->family == AF_INET)
5813 {
5814 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005815 vty_out (vty, "%-16s",
5816 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005817 else
5818 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5819 }
5820#ifdef HAVE_IPV6
5821 else if (p->family == AF_INET6)
5822 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005823 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005824 char buf[BUFSIZ];
5825 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005826 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005827 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005828 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5829 buf, BUFSIZ));
5830 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005831 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005832 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5833 buf, BUFSIZ),
5834 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5835 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005836
5837 }
5838#endif /* HAVE_IPV6 */
5839 }
5840
Paul Jakmafb982c22007-05-04 20:15:47 +00005841 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005842
5843 vty_out (vty, "notag/%d", label);
5844
5845 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005846}
5847
5848/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005849static void
paul718e3742002-12-13 20:15:29 +00005850damp_route_vty_out (struct vty *vty, struct prefix *p,
5851 struct bgp_info *binfo, int display, safi_t safi)
5852{
5853 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005854 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005855 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005856
paulb40d9392005-08-22 22:34:41 +00005857 /* short status lead text */
5858 route_vty_short_status_out (vty, binfo);
5859
paul718e3742002-12-13 20:15:29 +00005860 /* print prefix and mask */
5861 if (! display)
5862 route_vty_out_route (p, vty);
5863 else
5864 vty_out (vty, "%*s", 17, " ");
5865
5866 len = vty_out (vty, "%s", binfo->peer->host);
5867 len = 17 - len;
5868 if (len < 1)
5869 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5870 else
5871 vty_out (vty, "%*s", len, " ");
5872
Chris Caputo50aef6f2009-06-23 06:06:49 +00005873 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005874
5875 /* Print attribute */
5876 attr = binfo->attr;
5877 if (attr)
5878 {
5879 /* Print aspath */
5880 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005881 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005882
5883 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005884 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005885 }
5886 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005887}
5888
paul718e3742002-12-13 20:15:29 +00005889/* flap route */
ajs5a646652004-11-05 01:25:55 +00005890static void
paul718e3742002-12-13 20:15:29 +00005891flap_route_vty_out (struct vty *vty, struct prefix *p,
5892 struct bgp_info *binfo, int display, safi_t safi)
5893{
5894 struct attr *attr;
5895 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005896 char timebuf[BGP_UPTIME_LEN];
5897 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005898
5899 if (!binfo->extra)
5900 return;
5901
5902 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005903
paulb40d9392005-08-22 22:34:41 +00005904 /* short status lead text */
5905 route_vty_short_status_out (vty, binfo);
5906
paul718e3742002-12-13 20:15:29 +00005907 /* print prefix and mask */
5908 if (! display)
5909 route_vty_out_route (p, vty);
5910 else
5911 vty_out (vty, "%*s", 17, " ");
5912
5913 len = vty_out (vty, "%s", binfo->peer->host);
5914 len = 16 - len;
5915 if (len < 1)
5916 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5917 else
5918 vty_out (vty, "%*s", len, " ");
5919
5920 len = vty_out (vty, "%d", bdi->flap);
5921 len = 5 - len;
5922 if (len < 1)
5923 vty_out (vty, " ");
5924 else
5925 vty_out (vty, "%*s ", len, " ");
5926
5927 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5928 timebuf, BGP_UPTIME_LEN));
5929
5930 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5931 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005932 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005933 else
5934 vty_out (vty, "%*s ", 8, " ");
5935
5936 /* Print attribute */
5937 attr = binfo->attr;
5938 if (attr)
5939 {
5940 /* Print aspath */
5941 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005942 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005943
5944 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005945 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005946 }
5947 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005948}
5949
paul94f2b392005-06-28 12:44:16 +00005950static void
paul718e3742002-12-13 20:15:29 +00005951route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5952 struct bgp_info *binfo, afi_t afi, safi_t safi)
5953{
5954 char buf[INET6_ADDRSTRLEN];
5955 char buf1[BUFSIZ];
5956 struct attr *attr;
5957 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005958#ifdef HAVE_CLOCK_MONOTONIC
5959 time_t tbuf;
5960#endif
paul718e3742002-12-13 20:15:29 +00005961
5962 attr = binfo->attr;
5963
5964 if (attr)
5965 {
5966 /* Line1 display AS-path, Aggregator */
5967 if (attr->aspath)
5968 {
5969 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005970 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005971 vty_out (vty, "Local");
5972 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005973 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005974 }
5975
paulb40d9392005-08-22 22:34:41 +00005976 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5977 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005978 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5979 vty_out (vty, ", (stale)");
5980 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005981 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005982 attr->extra->aggregator_as,
5983 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005984 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5985 vty_out (vty, ", (Received from a RR-client)");
5986 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5987 vty_out (vty, ", (Received from a RS-client)");
5988 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5989 vty_out (vty, ", (history entry)");
5990 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5991 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005992 vty_out (vty, "%s", VTY_NEWLINE);
5993
5994 /* Line2 display Next-hop, Neighbor, Router-id */
5995 if (p->family == AF_INET)
5996 {
5997 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005998 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005999 inet_ntoa (attr->nexthop));
6000 }
6001#ifdef HAVE_IPV6
6002 else
6003 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006004 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006005 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006006 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006007 buf, INET6_ADDRSTRLEN));
6008 }
6009#endif /* HAVE_IPV6 */
6010
6011 if (binfo->peer == bgp->peer_self)
6012 {
6013 vty_out (vty, " from %s ",
6014 p->family == AF_INET ? "0.0.0.0" : "::");
6015 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6016 }
6017 else
6018 {
6019 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6020 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006021 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006022 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006023 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006024 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006025 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006026 else
6027 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6028 }
6029 vty_out (vty, "%s", VTY_NEWLINE);
6030
6031#ifdef HAVE_IPV6
6032 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006033 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006034 {
6035 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006036 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006037 buf, INET6_ADDRSTRLEN),
6038 VTY_NEWLINE);
6039 }
6040#endif /* HAVE_IPV6 */
6041
6042 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6043 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6044
6045 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006046 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006047
6048 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006049 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006050 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006051 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006052
Paul Jakmafb982c22007-05-04 20:15:47 +00006053 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006054 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006055
6056 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6057 vty_out (vty, ", valid");
6058
6059 if (binfo->peer != bgp->peer_self)
6060 {
6061 if (binfo->peer->as == binfo->peer->local_as)
6062 vty_out (vty, ", internal");
6063 else
6064 vty_out (vty, ", %s",
6065 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6066 }
6067 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6068 vty_out (vty, ", aggregated, local");
6069 else if (binfo->type != ZEBRA_ROUTE_BGP)
6070 vty_out (vty, ", sourced");
6071 else
6072 vty_out (vty, ", sourced, local");
6073
6074 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6075 vty_out (vty, ", atomic-aggregate");
6076
Josh Baileyde8d5df2011-07-20 20:46:01 -07006077 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6078 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6079 bgp_info_mpath_count (binfo)))
6080 vty_out (vty, ", multipath");
6081
paul718e3742002-12-13 20:15:29 +00006082 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6083 vty_out (vty, ", best");
6084
6085 vty_out (vty, "%s", VTY_NEWLINE);
6086
6087 /* Line 4 display Community */
6088 if (attr->community)
6089 vty_out (vty, " Community: %s%s", attr->community->str,
6090 VTY_NEWLINE);
6091
6092 /* Line 5 display Extended-community */
6093 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006094 vty_out (vty, " Extended Community: %s%s",
6095 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006096
6097 /* Line 6 display Originator, Cluster-id */
6098 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6099 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6100 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006101 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006102 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006103 vty_out (vty, " Originator: %s",
6104 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006105
6106 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6107 {
6108 int i;
6109 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006110 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6111 vty_out (vty, "%s ",
6112 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006113 }
6114 vty_out (vty, "%s", VTY_NEWLINE);
6115 }
Paul Jakma41367172007-08-06 15:24:51 +00006116
Paul Jakmafb982c22007-05-04 20:15:47 +00006117 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006118 bgp_damp_info_vty (vty, binfo);
6119
6120 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006121#ifdef HAVE_CLOCK_MONOTONIC
6122 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006123 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006124#else
6125 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6126#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006127 }
6128 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006129}
6130
6131#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6132 "h history, * valid, > best, = multipath,%s"\
6133 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006134#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006135#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6136#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6137#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6138
6139enum bgp_show_type
6140{
6141 bgp_show_type_normal,
6142 bgp_show_type_regexp,
6143 bgp_show_type_prefix_list,
6144 bgp_show_type_filter_list,
6145 bgp_show_type_route_map,
6146 bgp_show_type_neighbor,
6147 bgp_show_type_cidr_only,
6148 bgp_show_type_prefix_longer,
6149 bgp_show_type_community_all,
6150 bgp_show_type_community,
6151 bgp_show_type_community_exact,
6152 bgp_show_type_community_list,
6153 bgp_show_type_community_list_exact,
6154 bgp_show_type_flap_statistics,
6155 bgp_show_type_flap_address,
6156 bgp_show_type_flap_prefix,
6157 bgp_show_type_flap_cidr_only,
6158 bgp_show_type_flap_regexp,
6159 bgp_show_type_flap_filter_list,
6160 bgp_show_type_flap_prefix_list,
6161 bgp_show_type_flap_prefix_longer,
6162 bgp_show_type_flap_route_map,
6163 bgp_show_type_flap_neighbor,
6164 bgp_show_type_dampend_paths,
6165 bgp_show_type_damp_neighbor
6166};
6167
ajs5a646652004-11-05 01:25:55 +00006168static int
paulfee0f4c2004-09-13 05:12:46 +00006169bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006170 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006171{
paul718e3742002-12-13 20:15:29 +00006172 struct bgp_info *ri;
6173 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006174 int header = 1;
paul718e3742002-12-13 20:15:29 +00006175 int display;
ajs5a646652004-11-05 01:25:55 +00006176 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006177
6178 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006179 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006180
paul718e3742002-12-13 20:15:29 +00006181 /* Start processing of routes. */
6182 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6183 if (rn->info != NULL)
6184 {
6185 display = 0;
6186
6187 for (ri = rn->info; ri; ri = ri->next)
6188 {
ajs5a646652004-11-05 01:25:55 +00006189 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006190 || type == bgp_show_type_flap_address
6191 || type == bgp_show_type_flap_prefix
6192 || type == bgp_show_type_flap_cidr_only
6193 || type == bgp_show_type_flap_regexp
6194 || type == bgp_show_type_flap_filter_list
6195 || type == bgp_show_type_flap_prefix_list
6196 || type == bgp_show_type_flap_prefix_longer
6197 || type == bgp_show_type_flap_route_map
6198 || type == bgp_show_type_flap_neighbor
6199 || type == bgp_show_type_dampend_paths
6200 || type == bgp_show_type_damp_neighbor)
6201 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006202 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006203 continue;
6204 }
6205 if (type == bgp_show_type_regexp
6206 || type == bgp_show_type_flap_regexp)
6207 {
ajs5a646652004-11-05 01:25:55 +00006208 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006209
6210 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6211 continue;
6212 }
6213 if (type == bgp_show_type_prefix_list
6214 || type == bgp_show_type_flap_prefix_list)
6215 {
ajs5a646652004-11-05 01:25:55 +00006216 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006217
6218 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6219 continue;
6220 }
6221 if (type == bgp_show_type_filter_list
6222 || type == bgp_show_type_flap_filter_list)
6223 {
ajs5a646652004-11-05 01:25:55 +00006224 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006225
6226 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6227 continue;
6228 }
6229 if (type == bgp_show_type_route_map
6230 || type == bgp_show_type_flap_route_map)
6231 {
ajs5a646652004-11-05 01:25:55 +00006232 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006233 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006234 struct attr dummy_attr;
6235 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006236 int ret;
6237
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006238 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006239 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006240
paul718e3742002-12-13 20:15:29 +00006241 binfo.peer = ri->peer;
6242 binfo.attr = &dummy_attr;
6243
6244 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006245 if (ret == RMAP_DENYMATCH)
6246 continue;
6247 }
6248 if (type == bgp_show_type_neighbor
6249 || type == bgp_show_type_flap_neighbor
6250 || type == bgp_show_type_damp_neighbor)
6251 {
ajs5a646652004-11-05 01:25:55 +00006252 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006253
6254 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6255 continue;
6256 }
6257 if (type == bgp_show_type_cidr_only
6258 || type == bgp_show_type_flap_cidr_only)
6259 {
6260 u_int32_t destination;
6261
6262 destination = ntohl (rn->p.u.prefix4.s_addr);
6263 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6264 continue;
6265 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6266 continue;
6267 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6268 continue;
6269 }
6270 if (type == bgp_show_type_prefix_longer
6271 || type == bgp_show_type_flap_prefix_longer)
6272 {
ajs5a646652004-11-05 01:25:55 +00006273 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006274
6275 if (! prefix_match (p, &rn->p))
6276 continue;
6277 }
6278 if (type == bgp_show_type_community_all)
6279 {
6280 if (! ri->attr->community)
6281 continue;
6282 }
6283 if (type == bgp_show_type_community)
6284 {
ajs5a646652004-11-05 01:25:55 +00006285 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006286
6287 if (! ri->attr->community ||
6288 ! community_match (ri->attr->community, com))
6289 continue;
6290 }
6291 if (type == bgp_show_type_community_exact)
6292 {
ajs5a646652004-11-05 01:25:55 +00006293 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006294
6295 if (! ri->attr->community ||
6296 ! community_cmp (ri->attr->community, com))
6297 continue;
6298 }
6299 if (type == bgp_show_type_community_list)
6300 {
ajs5a646652004-11-05 01:25:55 +00006301 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006302
6303 if (! community_list_match (ri->attr->community, list))
6304 continue;
6305 }
6306 if (type == bgp_show_type_community_list_exact)
6307 {
ajs5a646652004-11-05 01:25:55 +00006308 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006309
6310 if (! community_list_exact_match (ri->attr->community, list))
6311 continue;
6312 }
6313 if (type == bgp_show_type_flap_address
6314 || type == bgp_show_type_flap_prefix)
6315 {
ajs5a646652004-11-05 01:25:55 +00006316 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006317
6318 if (! prefix_match (&rn->p, p))
6319 continue;
6320
6321 if (type == bgp_show_type_flap_prefix)
6322 if (p->prefixlen != rn->p.prefixlen)
6323 continue;
6324 }
6325 if (type == bgp_show_type_dampend_paths
6326 || type == bgp_show_type_damp_neighbor)
6327 {
6328 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6329 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6330 continue;
6331 }
6332
6333 if (header)
6334 {
hasso93406d82005-02-02 14:40:33 +00006335 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6336 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6337 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006338 if (type == bgp_show_type_dampend_paths
6339 || type == bgp_show_type_damp_neighbor)
6340 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6341 else if (type == bgp_show_type_flap_statistics
6342 || type == bgp_show_type_flap_address
6343 || type == bgp_show_type_flap_prefix
6344 || type == bgp_show_type_flap_cidr_only
6345 || type == bgp_show_type_flap_regexp
6346 || type == bgp_show_type_flap_filter_list
6347 || type == bgp_show_type_flap_prefix_list
6348 || type == bgp_show_type_flap_prefix_longer
6349 || type == bgp_show_type_flap_route_map
6350 || type == bgp_show_type_flap_neighbor)
6351 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6352 else
6353 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006354 header = 0;
6355 }
6356
6357 if (type == bgp_show_type_dampend_paths
6358 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006359 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006360 else if (type == bgp_show_type_flap_statistics
6361 || type == bgp_show_type_flap_address
6362 || type == bgp_show_type_flap_prefix
6363 || type == bgp_show_type_flap_cidr_only
6364 || type == bgp_show_type_flap_regexp
6365 || type == bgp_show_type_flap_filter_list
6366 || type == bgp_show_type_flap_prefix_list
6367 || type == bgp_show_type_flap_prefix_longer
6368 || type == bgp_show_type_flap_route_map
6369 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006370 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006371 else
ajs5a646652004-11-05 01:25:55 +00006372 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006373 display++;
6374 }
6375 if (display)
ajs5a646652004-11-05 01:25:55 +00006376 output_count++;
paul718e3742002-12-13 20:15:29 +00006377 }
6378
6379 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006380 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006381 {
6382 if (type == bgp_show_type_normal)
6383 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6384 }
6385 else
6386 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006387 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006388
6389 return CMD_SUCCESS;
6390}
6391
ajs5a646652004-11-05 01:25:55 +00006392static int
paulfee0f4c2004-09-13 05:12:46 +00006393bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006394 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006395{
6396 struct bgp_table *table;
6397
6398 if (bgp == NULL) {
6399 bgp = bgp_get_default ();
6400 }
6401
6402 if (bgp == NULL)
6403 {
6404 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6405 return CMD_WARNING;
6406 }
6407
6408
6409 table = bgp->rib[afi][safi];
6410
ajs5a646652004-11-05 01:25:55 +00006411 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006412}
6413
paul718e3742002-12-13 20:15:29 +00006414/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006415static void
paul718e3742002-12-13 20:15:29 +00006416route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6417 struct bgp_node *rn,
6418 struct prefix_rd *prd, afi_t afi, safi_t safi)
6419{
6420 struct bgp_info *ri;
6421 struct prefix *p;
6422 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006423 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006424 char buf1[INET6_ADDRSTRLEN];
6425 char buf2[INET6_ADDRSTRLEN];
6426 int count = 0;
6427 int best = 0;
6428 int suppress = 0;
6429 int no_export = 0;
6430 int no_advertise = 0;
6431 int local_as = 0;
6432 int first = 0;
6433
6434 p = &rn->p;
6435 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6436 (safi == SAFI_MPLS_VPN ?
6437 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6438 safi == SAFI_MPLS_VPN ? ":" : "",
6439 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6440 p->prefixlen, VTY_NEWLINE);
6441
6442 for (ri = rn->info; ri; ri = ri->next)
6443 {
6444 count++;
6445 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6446 {
6447 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006448 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006449 suppress = 1;
6450 if (ri->attr->community != NULL)
6451 {
6452 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6453 no_advertise = 1;
6454 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6455 no_export = 1;
6456 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6457 local_as = 1;
6458 }
6459 }
6460 }
6461
6462 vty_out (vty, "Paths: (%d available", count);
6463 if (best)
6464 {
6465 vty_out (vty, ", best #%d", best);
6466 if (safi == SAFI_UNICAST)
6467 vty_out (vty, ", table Default-IP-Routing-Table");
6468 }
6469 else
6470 vty_out (vty, ", no best path");
6471 if (no_advertise)
6472 vty_out (vty, ", not advertised to any peer");
6473 else if (no_export)
6474 vty_out (vty, ", not advertised to EBGP peer");
6475 else if (local_as)
6476 vty_out (vty, ", not advertised outside local AS");
6477 if (suppress)
6478 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6479 vty_out (vty, ")%s", VTY_NEWLINE);
6480
6481 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006482 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006483 {
6484 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6485 {
6486 if (! first)
6487 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6488 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6489 first = 1;
6490 }
6491 }
6492 if (! first)
6493 vty_out (vty, " Not advertised to any peer");
6494 vty_out (vty, "%s", VTY_NEWLINE);
6495}
6496
6497/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006498static int
paulfee0f4c2004-09-13 05:12:46 +00006499bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006500 struct bgp_table *rib, const char *ip_str,
6501 afi_t afi, safi_t safi, struct prefix_rd *prd,
6502 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006503{
6504 int ret;
6505 int header;
6506 int display = 0;
6507 struct prefix match;
6508 struct bgp_node *rn;
6509 struct bgp_node *rm;
6510 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006511 struct bgp_table *table;
6512
paul718e3742002-12-13 20:15:29 +00006513 /* Check IP address argument. */
6514 ret = str2prefix (ip_str, &match);
6515 if (! ret)
6516 {
6517 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6518 return CMD_WARNING;
6519 }
6520
6521 match.family = afi2family (afi);
6522
6523 if (safi == SAFI_MPLS_VPN)
6524 {
paulfee0f4c2004-09-13 05:12:46 +00006525 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006526 {
6527 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6528 continue;
6529
6530 if ((table = rn->info) != NULL)
6531 {
6532 header = 1;
6533
6534 if ((rm = bgp_node_match (table, &match)) != NULL)
6535 {
6536 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006537 {
6538 bgp_unlock_node (rm);
6539 continue;
6540 }
paul718e3742002-12-13 20:15:29 +00006541
6542 for (ri = rm->info; ri; ri = ri->next)
6543 {
6544 if (header)
6545 {
6546 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6547 AFI_IP, SAFI_MPLS_VPN);
6548
6549 header = 0;
6550 }
6551 display++;
6552 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6553 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006554
6555 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006556 }
6557 }
6558 }
6559 }
6560 else
6561 {
6562 header = 1;
6563
paulfee0f4c2004-09-13 05:12:46 +00006564 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006565 {
6566 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6567 {
6568 for (ri = rn->info; ri; ri = ri->next)
6569 {
6570 if (header)
6571 {
6572 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6573 header = 0;
6574 }
6575 display++;
6576 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6577 }
6578 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006579
6580 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006581 }
6582 }
6583
6584 if (! display)
6585 {
6586 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6587 return CMD_WARNING;
6588 }
6589
6590 return CMD_SUCCESS;
6591}
6592
paulfee0f4c2004-09-13 05:12:46 +00006593/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006594static int
paulfd79ac92004-10-13 05:06:08 +00006595bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006596 afi_t afi, safi_t safi, struct prefix_rd *prd,
6597 int prefix_check)
6598{
6599 struct bgp *bgp;
6600
6601 /* BGP structure lookup. */
6602 if (view_name)
6603 {
6604 bgp = bgp_lookup_by_name (view_name);
6605 if (bgp == NULL)
6606 {
6607 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6608 return CMD_WARNING;
6609 }
6610 }
6611 else
6612 {
6613 bgp = bgp_get_default ();
6614 if (bgp == NULL)
6615 {
6616 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6617 return CMD_WARNING;
6618 }
6619 }
6620
6621 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6622 afi, safi, prd, prefix_check);
6623}
6624
paul718e3742002-12-13 20:15:29 +00006625/* BGP route print out function. */
6626DEFUN (show_ip_bgp,
6627 show_ip_bgp_cmd,
6628 "show ip bgp",
6629 SHOW_STR
6630 IP_STR
6631 BGP_STR)
6632{
ajs5a646652004-11-05 01:25:55 +00006633 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006634}
6635
6636DEFUN (show_ip_bgp_ipv4,
6637 show_ip_bgp_ipv4_cmd,
6638 "show ip bgp ipv4 (unicast|multicast)",
6639 SHOW_STR
6640 IP_STR
6641 BGP_STR
6642 "Address family\n"
6643 "Address Family modifier\n"
6644 "Address Family modifier\n")
6645{
6646 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006647 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6648 NULL);
paul718e3742002-12-13 20:15:29 +00006649
ajs5a646652004-11-05 01:25:55 +00006650 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006651}
6652
Michael Lambert95cbbd22010-07-23 14:43:04 -04006653ALIAS (show_ip_bgp_ipv4,
6654 show_bgp_ipv4_safi_cmd,
6655 "show bgp ipv4 (unicast|multicast)",
6656 SHOW_STR
6657 BGP_STR
6658 "Address family\n"
6659 "Address Family modifier\n"
6660 "Address Family modifier\n")
6661
paul718e3742002-12-13 20:15:29 +00006662DEFUN (show_ip_bgp_route,
6663 show_ip_bgp_route_cmd,
6664 "show ip bgp A.B.C.D",
6665 SHOW_STR
6666 IP_STR
6667 BGP_STR
6668 "Network in the BGP routing table to display\n")
6669{
6670 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6671}
6672
6673DEFUN (show_ip_bgp_ipv4_route,
6674 show_ip_bgp_ipv4_route_cmd,
6675 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6676 SHOW_STR
6677 IP_STR
6678 BGP_STR
6679 "Address family\n"
6680 "Address Family modifier\n"
6681 "Address Family modifier\n"
6682 "Network in the BGP routing table to display\n")
6683{
6684 if (strncmp (argv[0], "m", 1) == 0)
6685 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6686
6687 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6688}
6689
Michael Lambert95cbbd22010-07-23 14:43:04 -04006690ALIAS (show_ip_bgp_ipv4_route,
6691 show_bgp_ipv4_safi_route_cmd,
6692 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6693 SHOW_STR
6694 BGP_STR
6695 "Address family\n"
6696 "Address Family modifier\n"
6697 "Address Family modifier\n"
6698 "Network in the BGP routing table to display\n")
6699
paul718e3742002-12-13 20:15:29 +00006700DEFUN (show_ip_bgp_vpnv4_all_route,
6701 show_ip_bgp_vpnv4_all_route_cmd,
6702 "show ip bgp vpnv4 all A.B.C.D",
6703 SHOW_STR
6704 IP_STR
6705 BGP_STR
6706 "Display VPNv4 NLRI specific information\n"
6707 "Display information about all VPNv4 NLRIs\n"
6708 "Network in the BGP routing table to display\n")
6709{
6710 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6711}
6712
6713DEFUN (show_ip_bgp_vpnv4_rd_route,
6714 show_ip_bgp_vpnv4_rd_route_cmd,
6715 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6716 SHOW_STR
6717 IP_STR
6718 BGP_STR
6719 "Display VPNv4 NLRI specific information\n"
6720 "Display information for a route distinguisher\n"
6721 "VPN Route Distinguisher\n"
6722 "Network in the BGP routing table to display\n")
6723{
6724 int ret;
6725 struct prefix_rd prd;
6726
6727 ret = str2prefix_rd (argv[0], &prd);
6728 if (! ret)
6729 {
6730 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6731 return CMD_WARNING;
6732 }
6733 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6734}
6735
6736DEFUN (show_ip_bgp_prefix,
6737 show_ip_bgp_prefix_cmd,
6738 "show ip bgp A.B.C.D/M",
6739 SHOW_STR
6740 IP_STR
6741 BGP_STR
6742 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6743{
6744 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6745}
6746
6747DEFUN (show_ip_bgp_ipv4_prefix,
6748 show_ip_bgp_ipv4_prefix_cmd,
6749 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6750 SHOW_STR
6751 IP_STR
6752 BGP_STR
6753 "Address family\n"
6754 "Address Family modifier\n"
6755 "Address Family modifier\n"
6756 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6757{
6758 if (strncmp (argv[0], "m", 1) == 0)
6759 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6760
6761 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6762}
6763
Michael Lambert95cbbd22010-07-23 14:43:04 -04006764ALIAS (show_ip_bgp_ipv4_prefix,
6765 show_bgp_ipv4_safi_prefix_cmd,
6766 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6767 SHOW_STR
6768 BGP_STR
6769 "Address family\n"
6770 "Address Family modifier\n"
6771 "Address Family modifier\n"
6772 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6773
paul718e3742002-12-13 20:15:29 +00006774DEFUN (show_ip_bgp_vpnv4_all_prefix,
6775 show_ip_bgp_vpnv4_all_prefix_cmd,
6776 "show ip bgp vpnv4 all A.B.C.D/M",
6777 SHOW_STR
6778 IP_STR
6779 BGP_STR
6780 "Display VPNv4 NLRI specific information\n"
6781 "Display information about all VPNv4 NLRIs\n"
6782 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6783{
6784 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6785}
6786
6787DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6788 show_ip_bgp_vpnv4_rd_prefix_cmd,
6789 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6790 SHOW_STR
6791 IP_STR
6792 BGP_STR
6793 "Display VPNv4 NLRI specific information\n"
6794 "Display information for a route distinguisher\n"
6795 "VPN Route Distinguisher\n"
6796 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6797{
6798 int ret;
6799 struct prefix_rd prd;
6800
6801 ret = str2prefix_rd (argv[0], &prd);
6802 if (! ret)
6803 {
6804 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6805 return CMD_WARNING;
6806 }
6807 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6808}
6809
6810DEFUN (show_ip_bgp_view,
6811 show_ip_bgp_view_cmd,
6812 "show ip bgp view WORD",
6813 SHOW_STR
6814 IP_STR
6815 BGP_STR
6816 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006817 "View name\n")
paul718e3742002-12-13 20:15:29 +00006818{
paulbb46e942003-10-24 19:02:03 +00006819 struct bgp *bgp;
6820
6821 /* BGP structure lookup. */
6822 bgp = bgp_lookup_by_name (argv[0]);
6823 if (bgp == NULL)
6824 {
6825 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6826 return CMD_WARNING;
6827 }
6828
ajs5a646652004-11-05 01:25:55 +00006829 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006830}
6831
6832DEFUN (show_ip_bgp_view_route,
6833 show_ip_bgp_view_route_cmd,
6834 "show ip bgp view WORD A.B.C.D",
6835 SHOW_STR
6836 IP_STR
6837 BGP_STR
6838 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006839 "View name\n"
paul718e3742002-12-13 20:15:29 +00006840 "Network in the BGP routing table to display\n")
6841{
6842 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6843}
6844
6845DEFUN (show_ip_bgp_view_prefix,
6846 show_ip_bgp_view_prefix_cmd,
6847 "show ip bgp view WORD A.B.C.D/M",
6848 SHOW_STR
6849 IP_STR
6850 BGP_STR
6851 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006852 "View name\n"
paul718e3742002-12-13 20:15:29 +00006853 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6854{
6855 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6856}
6857
6858#ifdef HAVE_IPV6
6859DEFUN (show_bgp,
6860 show_bgp_cmd,
6861 "show bgp",
6862 SHOW_STR
6863 BGP_STR)
6864{
ajs5a646652004-11-05 01:25:55 +00006865 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6866 NULL);
paul718e3742002-12-13 20:15:29 +00006867}
6868
6869ALIAS (show_bgp,
6870 show_bgp_ipv6_cmd,
6871 "show bgp ipv6",
6872 SHOW_STR
6873 BGP_STR
6874 "Address family\n")
6875
Michael Lambert95cbbd22010-07-23 14:43:04 -04006876DEFUN (show_bgp_ipv6_safi,
6877 show_bgp_ipv6_safi_cmd,
6878 "show bgp ipv6 (unicast|multicast)",
6879 SHOW_STR
6880 BGP_STR
6881 "Address family\n"
6882 "Address Family modifier\n"
6883 "Address Family modifier\n")
6884{
6885 if (strncmp (argv[0], "m", 1) == 0)
6886 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6887 NULL);
6888
6889 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6890}
6891
paul718e3742002-12-13 20:15:29 +00006892/* old command */
6893DEFUN (show_ipv6_bgp,
6894 show_ipv6_bgp_cmd,
6895 "show ipv6 bgp",
6896 SHOW_STR
6897 IP_STR
6898 BGP_STR)
6899{
ajs5a646652004-11-05 01:25:55 +00006900 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6901 NULL);
paul718e3742002-12-13 20:15:29 +00006902}
6903
6904DEFUN (show_bgp_route,
6905 show_bgp_route_cmd,
6906 "show bgp X:X::X:X",
6907 SHOW_STR
6908 BGP_STR
6909 "Network in the BGP routing table to display\n")
6910{
6911 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6912}
6913
6914ALIAS (show_bgp_route,
6915 show_bgp_ipv6_route_cmd,
6916 "show bgp ipv6 X:X::X:X",
6917 SHOW_STR
6918 BGP_STR
6919 "Address family\n"
6920 "Network in the BGP routing table to display\n")
6921
Michael Lambert95cbbd22010-07-23 14:43:04 -04006922DEFUN (show_bgp_ipv6_safi_route,
6923 show_bgp_ipv6_safi_route_cmd,
6924 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6925 SHOW_STR
6926 BGP_STR
6927 "Address family\n"
6928 "Address Family modifier\n"
6929 "Address Family modifier\n"
6930 "Network in the BGP routing table to display\n")
6931{
6932 if (strncmp (argv[0], "m", 1) == 0)
6933 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6934
6935 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6936}
6937
paul718e3742002-12-13 20:15:29 +00006938/* old command */
6939DEFUN (show_ipv6_bgp_route,
6940 show_ipv6_bgp_route_cmd,
6941 "show ipv6 bgp X:X::X:X",
6942 SHOW_STR
6943 IP_STR
6944 BGP_STR
6945 "Network in the BGP routing table to display\n")
6946{
6947 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6948}
6949
6950DEFUN (show_bgp_prefix,
6951 show_bgp_prefix_cmd,
6952 "show bgp X:X::X:X/M",
6953 SHOW_STR
6954 BGP_STR
6955 "IPv6 prefix <network>/<length>\n")
6956{
6957 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6958}
6959
6960ALIAS (show_bgp_prefix,
6961 show_bgp_ipv6_prefix_cmd,
6962 "show bgp ipv6 X:X::X:X/M",
6963 SHOW_STR
6964 BGP_STR
6965 "Address family\n"
6966 "IPv6 prefix <network>/<length>\n")
6967
Michael Lambert95cbbd22010-07-23 14:43:04 -04006968DEFUN (show_bgp_ipv6_safi_prefix,
6969 show_bgp_ipv6_safi_prefix_cmd,
6970 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6971 SHOW_STR
6972 BGP_STR
6973 "Address family\n"
6974 "Address Family modifier\n"
6975 "Address Family modifier\n"
6976 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6977{
6978 if (strncmp (argv[0], "m", 1) == 0)
6979 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6980
6981 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6982}
6983
paul718e3742002-12-13 20:15:29 +00006984/* old command */
6985DEFUN (show_ipv6_bgp_prefix,
6986 show_ipv6_bgp_prefix_cmd,
6987 "show ipv6 bgp X:X::X:X/M",
6988 SHOW_STR
6989 IP_STR
6990 BGP_STR
6991 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6992{
6993 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6994}
6995
paulbb46e942003-10-24 19:02:03 +00006996DEFUN (show_bgp_view,
6997 show_bgp_view_cmd,
6998 "show bgp view WORD",
6999 SHOW_STR
7000 BGP_STR
7001 "BGP view\n"
7002 "View name\n")
7003{
7004 struct bgp *bgp;
7005
7006 /* BGP structure lookup. */
7007 bgp = bgp_lookup_by_name (argv[0]);
7008 if (bgp == NULL)
7009 {
7010 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7011 return CMD_WARNING;
7012 }
7013
ajs5a646652004-11-05 01:25:55 +00007014 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007015}
7016
7017ALIAS (show_bgp_view,
7018 show_bgp_view_ipv6_cmd,
7019 "show bgp view WORD ipv6",
7020 SHOW_STR
7021 BGP_STR
7022 "BGP view\n"
7023 "View name\n"
7024 "Address family\n")
7025
7026DEFUN (show_bgp_view_route,
7027 show_bgp_view_route_cmd,
7028 "show bgp view WORD X:X::X:X",
7029 SHOW_STR
7030 BGP_STR
7031 "BGP view\n"
7032 "View name\n"
7033 "Network in the BGP routing table to display\n")
7034{
7035 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7036}
7037
7038ALIAS (show_bgp_view_route,
7039 show_bgp_view_ipv6_route_cmd,
7040 "show bgp view WORD ipv6 X:X::X:X",
7041 SHOW_STR
7042 BGP_STR
7043 "BGP view\n"
7044 "View name\n"
7045 "Address family\n"
7046 "Network in the BGP routing table to display\n")
7047
7048DEFUN (show_bgp_view_prefix,
7049 show_bgp_view_prefix_cmd,
7050 "show bgp view WORD X:X::X:X/M",
7051 SHOW_STR
7052 BGP_STR
7053 "BGP view\n"
7054 "View name\n"
7055 "IPv6 prefix <network>/<length>\n")
7056{
7057 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7058}
7059
7060ALIAS (show_bgp_view_prefix,
7061 show_bgp_view_ipv6_prefix_cmd,
7062 "show bgp view WORD ipv6 X:X::X:X/M",
7063 SHOW_STR
7064 BGP_STR
7065 "BGP view\n"
7066 "View name\n"
7067 "Address family\n"
7068 "IPv6 prefix <network>/<length>\n")
7069
paul718e3742002-12-13 20:15:29 +00007070/* old command */
7071DEFUN (show_ipv6_mbgp,
7072 show_ipv6_mbgp_cmd,
7073 "show ipv6 mbgp",
7074 SHOW_STR
7075 IP_STR
7076 MBGP_STR)
7077{
ajs5a646652004-11-05 01:25:55 +00007078 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7079 NULL);
paul718e3742002-12-13 20:15:29 +00007080}
7081
7082/* old command */
7083DEFUN (show_ipv6_mbgp_route,
7084 show_ipv6_mbgp_route_cmd,
7085 "show ipv6 mbgp X:X::X:X",
7086 SHOW_STR
7087 IP_STR
7088 MBGP_STR
7089 "Network in the MBGP routing table to display\n")
7090{
7091 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7092}
7093
7094/* old command */
7095DEFUN (show_ipv6_mbgp_prefix,
7096 show_ipv6_mbgp_prefix_cmd,
7097 "show ipv6 mbgp X:X::X:X/M",
7098 SHOW_STR
7099 IP_STR
7100 MBGP_STR
7101 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7102{
7103 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7104}
7105#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02007106
paul718e3742002-12-13 20:15:29 +00007107
paul94f2b392005-06-28 12:44:16 +00007108static int
paulfd79ac92004-10-13 05:06:08 +00007109bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007110 safi_t safi, enum bgp_show_type type)
7111{
7112 int i;
7113 struct buffer *b;
7114 char *regstr;
7115 int first;
7116 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007117 int rc;
paul718e3742002-12-13 20:15:29 +00007118
7119 first = 0;
7120 b = buffer_new (1024);
7121 for (i = 0; i < argc; i++)
7122 {
7123 if (first)
7124 buffer_putc (b, ' ');
7125 else
7126 {
7127 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7128 continue;
7129 first = 1;
7130 }
7131
7132 buffer_putstr (b, argv[i]);
7133 }
7134 buffer_putc (b, '\0');
7135
7136 regstr = buffer_getstr (b);
7137 buffer_free (b);
7138
7139 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007140 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007141 if (! regex)
7142 {
7143 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7144 VTY_NEWLINE);
7145 return CMD_WARNING;
7146 }
7147
ajs5a646652004-11-05 01:25:55 +00007148 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7149 bgp_regex_free (regex);
7150 return rc;
paul718e3742002-12-13 20:15:29 +00007151}
7152
7153DEFUN (show_ip_bgp_regexp,
7154 show_ip_bgp_regexp_cmd,
7155 "show ip bgp regexp .LINE",
7156 SHOW_STR
7157 IP_STR
7158 BGP_STR
7159 "Display routes matching the AS path regular expression\n"
7160 "A regular-expression to match the BGP AS paths\n")
7161{
7162 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7163 bgp_show_type_regexp);
7164}
7165
7166DEFUN (show_ip_bgp_flap_regexp,
7167 show_ip_bgp_flap_regexp_cmd,
7168 "show ip bgp flap-statistics regexp .LINE",
7169 SHOW_STR
7170 IP_STR
7171 BGP_STR
7172 "Display flap statistics of routes\n"
7173 "Display routes matching the AS path regular expression\n"
7174 "A regular-expression to match the BGP AS paths\n")
7175{
7176 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7177 bgp_show_type_flap_regexp);
7178}
7179
7180DEFUN (show_ip_bgp_ipv4_regexp,
7181 show_ip_bgp_ipv4_regexp_cmd,
7182 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7183 SHOW_STR
7184 IP_STR
7185 BGP_STR
7186 "Address family\n"
7187 "Address Family modifier\n"
7188 "Address Family modifier\n"
7189 "Display routes matching the AS path regular expression\n"
7190 "A regular-expression to match the BGP AS paths\n")
7191{
7192 if (strncmp (argv[0], "m", 1) == 0)
7193 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7194 bgp_show_type_regexp);
7195
7196 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7197 bgp_show_type_regexp);
7198}
7199
7200#ifdef HAVE_IPV6
7201DEFUN (show_bgp_regexp,
7202 show_bgp_regexp_cmd,
7203 "show bgp regexp .LINE",
7204 SHOW_STR
7205 BGP_STR
7206 "Display routes matching the AS path regular expression\n"
7207 "A regular-expression to match the BGP AS paths\n")
7208{
7209 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7210 bgp_show_type_regexp);
7211}
7212
7213ALIAS (show_bgp_regexp,
7214 show_bgp_ipv6_regexp_cmd,
7215 "show bgp ipv6 regexp .LINE",
7216 SHOW_STR
7217 BGP_STR
7218 "Address family\n"
7219 "Display routes matching the AS path regular expression\n"
7220 "A regular-expression to match the BGP AS paths\n")
7221
7222/* old command */
7223DEFUN (show_ipv6_bgp_regexp,
7224 show_ipv6_bgp_regexp_cmd,
7225 "show ipv6 bgp regexp .LINE",
7226 SHOW_STR
7227 IP_STR
7228 BGP_STR
7229 "Display routes matching the AS path regular expression\n"
7230 "A regular-expression to match the BGP AS paths\n")
7231{
7232 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7233 bgp_show_type_regexp);
7234}
7235
7236/* old command */
7237DEFUN (show_ipv6_mbgp_regexp,
7238 show_ipv6_mbgp_regexp_cmd,
7239 "show ipv6 mbgp regexp .LINE",
7240 SHOW_STR
7241 IP_STR
7242 BGP_STR
7243 "Display routes matching the AS path regular expression\n"
7244 "A regular-expression to match the MBGP AS paths\n")
7245{
7246 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7247 bgp_show_type_regexp);
7248}
7249#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007250
paul94f2b392005-06-28 12:44:16 +00007251static int
paulfd79ac92004-10-13 05:06:08 +00007252bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007253 safi_t safi, enum bgp_show_type type)
7254{
7255 struct prefix_list *plist;
7256
7257 plist = prefix_list_lookup (afi, prefix_list_str);
7258 if (plist == NULL)
7259 {
7260 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7261 prefix_list_str, VTY_NEWLINE);
7262 return CMD_WARNING;
7263 }
7264
ajs5a646652004-11-05 01:25:55 +00007265 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007266}
7267
7268DEFUN (show_ip_bgp_prefix_list,
7269 show_ip_bgp_prefix_list_cmd,
7270 "show ip bgp prefix-list WORD",
7271 SHOW_STR
7272 IP_STR
7273 BGP_STR
7274 "Display routes conforming to the prefix-list\n"
7275 "IP prefix-list name\n")
7276{
7277 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7278 bgp_show_type_prefix_list);
7279}
7280
7281DEFUN (show_ip_bgp_flap_prefix_list,
7282 show_ip_bgp_flap_prefix_list_cmd,
7283 "show ip bgp flap-statistics prefix-list WORD",
7284 SHOW_STR
7285 IP_STR
7286 BGP_STR
7287 "Display flap statistics of routes\n"
7288 "Display routes conforming to the prefix-list\n"
7289 "IP prefix-list name\n")
7290{
7291 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7292 bgp_show_type_flap_prefix_list);
7293}
7294
7295DEFUN (show_ip_bgp_ipv4_prefix_list,
7296 show_ip_bgp_ipv4_prefix_list_cmd,
7297 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7298 SHOW_STR
7299 IP_STR
7300 BGP_STR
7301 "Address family\n"
7302 "Address Family modifier\n"
7303 "Address Family modifier\n"
7304 "Display routes conforming to the prefix-list\n"
7305 "IP prefix-list name\n")
7306{
7307 if (strncmp (argv[0], "m", 1) == 0)
7308 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7309 bgp_show_type_prefix_list);
7310
7311 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7312 bgp_show_type_prefix_list);
7313}
7314
7315#ifdef HAVE_IPV6
7316DEFUN (show_bgp_prefix_list,
7317 show_bgp_prefix_list_cmd,
7318 "show bgp prefix-list WORD",
7319 SHOW_STR
7320 BGP_STR
7321 "Display routes conforming to the prefix-list\n"
7322 "IPv6 prefix-list name\n")
7323{
7324 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7325 bgp_show_type_prefix_list);
7326}
7327
7328ALIAS (show_bgp_prefix_list,
7329 show_bgp_ipv6_prefix_list_cmd,
7330 "show bgp ipv6 prefix-list WORD",
7331 SHOW_STR
7332 BGP_STR
7333 "Address family\n"
7334 "Display routes conforming to the prefix-list\n"
7335 "IPv6 prefix-list name\n")
7336
7337/* old command */
7338DEFUN (show_ipv6_bgp_prefix_list,
7339 show_ipv6_bgp_prefix_list_cmd,
7340 "show ipv6 bgp prefix-list WORD",
7341 SHOW_STR
7342 IPV6_STR
7343 BGP_STR
7344 "Display routes matching the prefix-list\n"
7345 "IPv6 prefix-list name\n")
7346{
7347 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7348 bgp_show_type_prefix_list);
7349}
7350
7351/* old command */
7352DEFUN (show_ipv6_mbgp_prefix_list,
7353 show_ipv6_mbgp_prefix_list_cmd,
7354 "show ipv6 mbgp prefix-list WORD",
7355 SHOW_STR
7356 IPV6_STR
7357 MBGP_STR
7358 "Display routes matching the prefix-list\n"
7359 "IPv6 prefix-list name\n")
7360{
7361 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7362 bgp_show_type_prefix_list);
7363}
7364#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007365
paul94f2b392005-06-28 12:44:16 +00007366static int
paulfd79ac92004-10-13 05:06:08 +00007367bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007368 safi_t safi, enum bgp_show_type type)
7369{
7370 struct as_list *as_list;
7371
7372 as_list = as_list_lookup (filter);
7373 if (as_list == NULL)
7374 {
7375 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7376 return CMD_WARNING;
7377 }
7378
ajs5a646652004-11-05 01:25:55 +00007379 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007380}
7381
7382DEFUN (show_ip_bgp_filter_list,
7383 show_ip_bgp_filter_list_cmd,
7384 "show ip bgp filter-list WORD",
7385 SHOW_STR
7386 IP_STR
7387 BGP_STR
7388 "Display routes conforming to the filter-list\n"
7389 "Regular expression access list name\n")
7390{
7391 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7392 bgp_show_type_filter_list);
7393}
7394
7395DEFUN (show_ip_bgp_flap_filter_list,
7396 show_ip_bgp_flap_filter_list_cmd,
7397 "show ip bgp flap-statistics filter-list WORD",
7398 SHOW_STR
7399 IP_STR
7400 BGP_STR
7401 "Display flap statistics of routes\n"
7402 "Display routes conforming to the filter-list\n"
7403 "Regular expression access list name\n")
7404{
7405 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7406 bgp_show_type_flap_filter_list);
7407}
7408
7409DEFUN (show_ip_bgp_ipv4_filter_list,
7410 show_ip_bgp_ipv4_filter_list_cmd,
7411 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7412 SHOW_STR
7413 IP_STR
7414 BGP_STR
7415 "Address family\n"
7416 "Address Family modifier\n"
7417 "Address Family modifier\n"
7418 "Display routes conforming to the filter-list\n"
7419 "Regular expression access list name\n")
7420{
7421 if (strncmp (argv[0], "m", 1) == 0)
7422 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7423 bgp_show_type_filter_list);
7424
7425 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7426 bgp_show_type_filter_list);
7427}
7428
7429#ifdef HAVE_IPV6
7430DEFUN (show_bgp_filter_list,
7431 show_bgp_filter_list_cmd,
7432 "show bgp filter-list WORD",
7433 SHOW_STR
7434 BGP_STR
7435 "Display routes conforming to the filter-list\n"
7436 "Regular expression access list name\n")
7437{
7438 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7439 bgp_show_type_filter_list);
7440}
7441
7442ALIAS (show_bgp_filter_list,
7443 show_bgp_ipv6_filter_list_cmd,
7444 "show bgp ipv6 filter-list WORD",
7445 SHOW_STR
7446 BGP_STR
7447 "Address family\n"
7448 "Display routes conforming to the filter-list\n"
7449 "Regular expression access list name\n")
7450
7451/* old command */
7452DEFUN (show_ipv6_bgp_filter_list,
7453 show_ipv6_bgp_filter_list_cmd,
7454 "show ipv6 bgp filter-list WORD",
7455 SHOW_STR
7456 IPV6_STR
7457 BGP_STR
7458 "Display routes conforming to the filter-list\n"
7459 "Regular expression access list name\n")
7460{
7461 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7462 bgp_show_type_filter_list);
7463}
7464
7465/* old command */
7466DEFUN (show_ipv6_mbgp_filter_list,
7467 show_ipv6_mbgp_filter_list_cmd,
7468 "show ipv6 mbgp filter-list WORD",
7469 SHOW_STR
7470 IPV6_STR
7471 MBGP_STR
7472 "Display routes conforming to the filter-list\n"
7473 "Regular expression access list name\n")
7474{
7475 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7476 bgp_show_type_filter_list);
7477}
7478#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007479
paul94f2b392005-06-28 12:44:16 +00007480static int
paulfd79ac92004-10-13 05:06:08 +00007481bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007482 safi_t safi, enum bgp_show_type type)
7483{
7484 struct route_map *rmap;
7485
7486 rmap = route_map_lookup_by_name (rmap_str);
7487 if (! rmap)
7488 {
7489 vty_out (vty, "%% %s is not a valid route-map name%s",
7490 rmap_str, VTY_NEWLINE);
7491 return CMD_WARNING;
7492 }
7493
ajs5a646652004-11-05 01:25:55 +00007494 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007495}
7496
7497DEFUN (show_ip_bgp_route_map,
7498 show_ip_bgp_route_map_cmd,
7499 "show ip bgp route-map WORD",
7500 SHOW_STR
7501 IP_STR
7502 BGP_STR
7503 "Display routes matching the route-map\n"
7504 "A route-map to match on\n")
7505{
7506 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7507 bgp_show_type_route_map);
7508}
7509
7510DEFUN (show_ip_bgp_flap_route_map,
7511 show_ip_bgp_flap_route_map_cmd,
7512 "show ip bgp flap-statistics route-map WORD",
7513 SHOW_STR
7514 IP_STR
7515 BGP_STR
7516 "Display flap statistics of routes\n"
7517 "Display routes matching the route-map\n"
7518 "A route-map to match on\n")
7519{
7520 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7521 bgp_show_type_flap_route_map);
7522}
7523
7524DEFUN (show_ip_bgp_ipv4_route_map,
7525 show_ip_bgp_ipv4_route_map_cmd,
7526 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7527 SHOW_STR
7528 IP_STR
7529 BGP_STR
7530 "Address family\n"
7531 "Address Family modifier\n"
7532 "Address Family modifier\n"
7533 "Display routes matching the route-map\n"
7534 "A route-map to match on\n")
7535{
7536 if (strncmp (argv[0], "m", 1) == 0)
7537 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7538 bgp_show_type_route_map);
7539
7540 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7541 bgp_show_type_route_map);
7542}
7543
7544DEFUN (show_bgp_route_map,
7545 show_bgp_route_map_cmd,
7546 "show bgp route-map WORD",
7547 SHOW_STR
7548 BGP_STR
7549 "Display routes matching the route-map\n"
7550 "A route-map to match on\n")
7551{
7552 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7553 bgp_show_type_route_map);
7554}
7555
7556ALIAS (show_bgp_route_map,
7557 show_bgp_ipv6_route_map_cmd,
7558 "show bgp ipv6 route-map WORD",
7559 SHOW_STR
7560 BGP_STR
7561 "Address family\n"
7562 "Display routes matching the route-map\n"
7563 "A route-map to match on\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02007564
paul718e3742002-12-13 20:15:29 +00007565DEFUN (show_ip_bgp_cidr_only,
7566 show_ip_bgp_cidr_only_cmd,
7567 "show ip bgp cidr-only",
7568 SHOW_STR
7569 IP_STR
7570 BGP_STR
7571 "Display only routes with non-natural netmasks\n")
7572{
7573 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007574 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007575}
7576
7577DEFUN (show_ip_bgp_flap_cidr_only,
7578 show_ip_bgp_flap_cidr_only_cmd,
7579 "show ip bgp flap-statistics cidr-only",
7580 SHOW_STR
7581 IP_STR
7582 BGP_STR
7583 "Display flap statistics of routes\n"
7584 "Display only routes with non-natural netmasks\n")
7585{
7586 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007587 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007588}
7589
7590DEFUN (show_ip_bgp_ipv4_cidr_only,
7591 show_ip_bgp_ipv4_cidr_only_cmd,
7592 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7593 SHOW_STR
7594 IP_STR
7595 BGP_STR
7596 "Address family\n"
7597 "Address Family modifier\n"
7598 "Address Family modifier\n"
7599 "Display only routes with non-natural netmasks\n")
7600{
7601 if (strncmp (argv[0], "m", 1) == 0)
7602 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007603 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007604
7605 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007606 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007607}
David Lamparter6b0655a2014-06-04 06:53:35 +02007608
paul718e3742002-12-13 20:15:29 +00007609DEFUN (show_ip_bgp_community_all,
7610 show_ip_bgp_community_all_cmd,
7611 "show ip bgp community",
7612 SHOW_STR
7613 IP_STR
7614 BGP_STR
7615 "Display routes matching the communities\n")
7616{
7617 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007618 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007619}
7620
7621DEFUN (show_ip_bgp_ipv4_community_all,
7622 show_ip_bgp_ipv4_community_all_cmd,
7623 "show ip bgp ipv4 (unicast|multicast) community",
7624 SHOW_STR
7625 IP_STR
7626 BGP_STR
7627 "Address family\n"
7628 "Address Family modifier\n"
7629 "Address Family modifier\n"
7630 "Display routes matching the communities\n")
7631{
7632 if (strncmp (argv[0], "m", 1) == 0)
7633 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007634 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007635
7636 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007637 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007638}
7639
7640#ifdef HAVE_IPV6
7641DEFUN (show_bgp_community_all,
7642 show_bgp_community_all_cmd,
7643 "show bgp community",
7644 SHOW_STR
7645 BGP_STR
7646 "Display routes matching the communities\n")
7647{
7648 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007649 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007650}
7651
7652ALIAS (show_bgp_community_all,
7653 show_bgp_ipv6_community_all_cmd,
7654 "show bgp ipv6 community",
7655 SHOW_STR
7656 BGP_STR
7657 "Address family\n"
7658 "Display routes matching the communities\n")
7659
7660/* old command */
7661DEFUN (show_ipv6_bgp_community_all,
7662 show_ipv6_bgp_community_all_cmd,
7663 "show ipv6 bgp community",
7664 SHOW_STR
7665 IPV6_STR
7666 BGP_STR
7667 "Display routes matching the communities\n")
7668{
7669 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007670 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007671}
7672
7673/* old command */
7674DEFUN (show_ipv6_mbgp_community_all,
7675 show_ipv6_mbgp_community_all_cmd,
7676 "show ipv6 mbgp community",
7677 SHOW_STR
7678 IPV6_STR
7679 MBGP_STR
7680 "Display routes matching the communities\n")
7681{
7682 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007683 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007684}
7685#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007686
paul94f2b392005-06-28 12:44:16 +00007687static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007688bgp_show_community (struct vty *vty, const char *view_name, int argc,
7689 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007690{
7691 struct community *com;
7692 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007693 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007694 int i;
7695 char *str;
7696 int first = 0;
7697
Michael Lambert95cbbd22010-07-23 14:43:04 -04007698 /* BGP structure lookup */
7699 if (view_name)
7700 {
7701 bgp = bgp_lookup_by_name (view_name);
7702 if (bgp == NULL)
7703 {
7704 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7705 return CMD_WARNING;
7706 }
7707 }
7708 else
7709 {
7710 bgp = bgp_get_default ();
7711 if (bgp == NULL)
7712 {
7713 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7714 return CMD_WARNING;
7715 }
7716 }
7717
paul718e3742002-12-13 20:15:29 +00007718 b = buffer_new (1024);
7719 for (i = 0; i < argc; i++)
7720 {
7721 if (first)
7722 buffer_putc (b, ' ');
7723 else
7724 {
7725 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7726 continue;
7727 first = 1;
7728 }
7729
7730 buffer_putstr (b, argv[i]);
7731 }
7732 buffer_putc (b, '\0');
7733
7734 str = buffer_getstr (b);
7735 buffer_free (b);
7736
7737 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007738 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007739 if (! com)
7740 {
7741 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7742 return CMD_WARNING;
7743 }
7744
Michael Lambert95cbbd22010-07-23 14:43:04 -04007745 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007746 (exact ? bgp_show_type_community_exact :
7747 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007748}
7749
7750DEFUN (show_ip_bgp_community,
7751 show_ip_bgp_community_cmd,
7752 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7753 SHOW_STR
7754 IP_STR
7755 BGP_STR
7756 "Display routes matching the communities\n"
7757 "community number\n"
7758 "Do not send outside local AS (well-known community)\n"
7759 "Do not advertise to any peer (well-known community)\n"
7760 "Do not export to next AS (well-known community)\n")
7761{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007762 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007763}
7764
7765ALIAS (show_ip_bgp_community,
7766 show_ip_bgp_community2_cmd,
7767 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7768 SHOW_STR
7769 IP_STR
7770 BGP_STR
7771 "Display routes matching the communities\n"
7772 "community number\n"
7773 "Do not send outside local AS (well-known community)\n"
7774 "Do not advertise to any peer (well-known community)\n"
7775 "Do not export to next AS (well-known community)\n"
7776 "community number\n"
7777 "Do not send outside local AS (well-known community)\n"
7778 "Do not advertise to any peer (well-known community)\n"
7779 "Do not export to next AS (well-known community)\n")
7780
7781ALIAS (show_ip_bgp_community,
7782 show_ip_bgp_community3_cmd,
7783 "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)",
7784 SHOW_STR
7785 IP_STR
7786 BGP_STR
7787 "Display routes matching the communities\n"
7788 "community number\n"
7789 "Do not send outside local AS (well-known community)\n"
7790 "Do not advertise to any peer (well-known community)\n"
7791 "Do not export to next AS (well-known community)\n"
7792 "community number\n"
7793 "Do not send outside local AS (well-known community)\n"
7794 "Do not advertise to any peer (well-known community)\n"
7795 "Do not export to next AS (well-known community)\n"
7796 "community number\n"
7797 "Do not send outside local AS (well-known community)\n"
7798 "Do not advertise to any peer (well-known community)\n"
7799 "Do not export to next AS (well-known community)\n")
7800
7801ALIAS (show_ip_bgp_community,
7802 show_ip_bgp_community4_cmd,
7803 "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)",
7804 SHOW_STR
7805 IP_STR
7806 BGP_STR
7807 "Display routes matching the communities\n"
7808 "community number\n"
7809 "Do not send outside local AS (well-known community)\n"
7810 "Do not advertise to any peer (well-known community)\n"
7811 "Do not export to next AS (well-known community)\n"
7812 "community number\n"
7813 "Do not send outside local AS (well-known community)\n"
7814 "Do not advertise to any peer (well-known community)\n"
7815 "Do not export to next AS (well-known community)\n"
7816 "community number\n"
7817 "Do not send outside local AS (well-known community)\n"
7818 "Do not advertise to any peer (well-known community)\n"
7819 "Do not export to next AS (well-known community)\n"
7820 "community number\n"
7821 "Do not send outside local AS (well-known community)\n"
7822 "Do not advertise to any peer (well-known community)\n"
7823 "Do not export to next AS (well-known community)\n")
7824
7825DEFUN (show_ip_bgp_ipv4_community,
7826 show_ip_bgp_ipv4_community_cmd,
7827 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7828 SHOW_STR
7829 IP_STR
7830 BGP_STR
7831 "Address family\n"
7832 "Address Family modifier\n"
7833 "Address Family modifier\n"
7834 "Display routes matching the communities\n"
7835 "community number\n"
7836 "Do not send outside local AS (well-known community)\n"
7837 "Do not advertise to any peer (well-known community)\n"
7838 "Do not export to next AS (well-known community)\n")
7839{
7840 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007841 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007842
Michael Lambert95cbbd22010-07-23 14:43:04 -04007843 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007844}
7845
7846ALIAS (show_ip_bgp_ipv4_community,
7847 show_ip_bgp_ipv4_community2_cmd,
7848 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7849 SHOW_STR
7850 IP_STR
7851 BGP_STR
7852 "Address family\n"
7853 "Address Family modifier\n"
7854 "Address Family modifier\n"
7855 "Display routes matching the communities\n"
7856 "community number\n"
7857 "Do not send outside local AS (well-known community)\n"
7858 "Do not advertise to any peer (well-known community)\n"
7859 "Do not export to next AS (well-known community)\n"
7860 "community number\n"
7861 "Do not send outside local AS (well-known community)\n"
7862 "Do not advertise to any peer (well-known community)\n"
7863 "Do not export to next AS (well-known community)\n")
7864
7865ALIAS (show_ip_bgp_ipv4_community,
7866 show_ip_bgp_ipv4_community3_cmd,
7867 "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)",
7868 SHOW_STR
7869 IP_STR
7870 BGP_STR
7871 "Address family\n"
7872 "Address Family modifier\n"
7873 "Address Family modifier\n"
7874 "Display routes matching the communities\n"
7875 "community number\n"
7876 "Do not send outside local AS (well-known community)\n"
7877 "Do not advertise to any peer (well-known community)\n"
7878 "Do not export to next AS (well-known community)\n"
7879 "community number\n"
7880 "Do not send outside local AS (well-known community)\n"
7881 "Do not advertise to any peer (well-known community)\n"
7882 "Do not export to next AS (well-known community)\n"
7883 "community number\n"
7884 "Do not send outside local AS (well-known community)\n"
7885 "Do not advertise to any peer (well-known community)\n"
7886 "Do not export to next AS (well-known community)\n")
7887
7888ALIAS (show_ip_bgp_ipv4_community,
7889 show_ip_bgp_ipv4_community4_cmd,
7890 "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)",
7891 SHOW_STR
7892 IP_STR
7893 BGP_STR
7894 "Address family\n"
7895 "Address Family modifier\n"
7896 "Address Family modifier\n"
7897 "Display routes matching the communities\n"
7898 "community number\n"
7899 "Do not send outside local AS (well-known community)\n"
7900 "Do not advertise to any peer (well-known community)\n"
7901 "Do not export to next AS (well-known community)\n"
7902 "community number\n"
7903 "Do not send outside local AS (well-known community)\n"
7904 "Do not advertise to any peer (well-known community)\n"
7905 "Do not export to next AS (well-known community)\n"
7906 "community number\n"
7907 "Do not send outside local AS (well-known community)\n"
7908 "Do not advertise to any peer (well-known community)\n"
7909 "Do not export to next AS (well-known community)\n"
7910 "community number\n"
7911 "Do not send outside local AS (well-known community)\n"
7912 "Do not advertise to any peer (well-known community)\n"
7913 "Do not export to next AS (well-known community)\n")
7914
Michael Lambert95cbbd22010-07-23 14:43:04 -04007915DEFUN (show_bgp_view_afi_safi_community_all,
7916 show_bgp_view_afi_safi_community_all_cmd,
7917#ifdef HAVE_IPV6
7918 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7919#else
7920 "show bgp view WORD ipv4 (unicast|multicast) community",
7921#endif
7922 SHOW_STR
7923 BGP_STR
7924 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007925 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007926 "Address family\n"
7927#ifdef HAVE_IPV6
7928 "Address family\n"
7929#endif
7930 "Address Family modifier\n"
7931 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00007932 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007933{
7934 int afi;
7935 int safi;
7936 struct bgp *bgp;
7937
7938 /* BGP structure lookup. */
7939 bgp = bgp_lookup_by_name (argv[0]);
7940 if (bgp == NULL)
7941 {
7942 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7943 return CMD_WARNING;
7944 }
7945
7946#ifdef HAVE_IPV6
7947 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7948 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7949#else
7950 afi = AFI_IP;
7951 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7952#endif
7953 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7954}
7955
7956DEFUN (show_bgp_view_afi_safi_community,
7957 show_bgp_view_afi_safi_community_cmd,
7958#ifdef HAVE_IPV6
7959 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7960#else
7961 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7962#endif
7963 SHOW_STR
7964 BGP_STR
7965 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007966 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007967 "Address family\n"
7968#ifdef HAVE_IPV6
7969 "Address family\n"
7970#endif
7971 "Address family modifier\n"
7972 "Address family modifier\n"
7973 "Display routes matching the communities\n"
7974 "community number\n"
7975 "Do not send outside local AS (well-known community)\n"
7976 "Do not advertise to any peer (well-known community)\n"
7977 "Do not export to next AS (well-known community)\n")
7978{
7979 int afi;
7980 int safi;
7981
7982#ifdef HAVE_IPV6
7983 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7984 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7985 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7986#else
7987 afi = AFI_IP;
7988 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7989 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
7990#endif
7991}
7992
7993ALIAS (show_bgp_view_afi_safi_community,
7994 show_bgp_view_afi_safi_community2_cmd,
7995#ifdef HAVE_IPV6
7996 "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)",
7997#else
7998 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7999#endif
8000 SHOW_STR
8001 BGP_STR
8002 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008003 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008004 "Address family\n"
8005#ifdef HAVE_IPV6
8006 "Address family\n"
8007#endif
8008 "Address family modifier\n"
8009 "Address family modifier\n"
8010 "Display routes matching the communities\n"
8011 "community number\n"
8012 "Do not send outside local AS (well-known community)\n"
8013 "Do not advertise to any peer (well-known community)\n"
8014 "Do not export to next AS (well-known community)\n"
8015 "community number\n"
8016 "Do not send outside local AS (well-known community)\n"
8017 "Do not advertise to any peer (well-known community)\n"
8018 "Do not export to next AS (well-known community)\n")
8019
8020ALIAS (show_bgp_view_afi_safi_community,
8021 show_bgp_view_afi_safi_community3_cmd,
8022#ifdef HAVE_IPV6
8023 "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)",
8024#else
8025 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8026#endif
8027 SHOW_STR
8028 BGP_STR
8029 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008030 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008031 "Address family\n"
8032#ifdef HAVE_IPV6
8033 "Address family\n"
8034#endif
8035 "Address family modifier\n"
8036 "Address family modifier\n"
8037 "Display routes matching the communities\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
8051ALIAS (show_bgp_view_afi_safi_community,
8052 show_bgp_view_afi_safi_community4_cmd,
8053#ifdef HAVE_IPV6
8054 "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)",
8055#else
8056 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8057#endif
8058 SHOW_STR
8059 BGP_STR
8060 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008061 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008062 "Address family\n"
8063#ifdef HAVE_IPV6
8064 "Address family\n"
8065#endif
8066 "Address family modifier\n"
8067 "Address family modifier\n"
8068 "Display routes matching the communities\n"
8069 "community number\n"
8070 "Do not send outside local AS (well-known community)\n"
8071 "Do not advertise to any peer (well-known community)\n"
8072 "Do not export to next AS (well-known community)\n"
8073 "community number\n"
8074 "Do not send outside local AS (well-known community)\n"
8075 "Do not advertise to any peer (well-known community)\n"
8076 "Do not export to next AS (well-known community)\n"
8077 "community number\n"
8078 "Do not send outside local AS (well-known community)\n"
8079 "Do not advertise to any peer (well-known community)\n"
8080 "Do not export to next AS (well-known community)\n"
8081 "community number\n"
8082 "Do not send outside local AS (well-known community)\n"
8083 "Do not advertise to any peer (well-known community)\n"
8084 "Do not export to next AS (well-known community)\n")
8085
paul718e3742002-12-13 20:15:29 +00008086DEFUN (show_ip_bgp_community_exact,
8087 show_ip_bgp_community_exact_cmd,
8088 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8089 SHOW_STR
8090 IP_STR
8091 BGP_STR
8092 "Display routes matching the communities\n"
8093 "community number\n"
8094 "Do not send outside local AS (well-known community)\n"
8095 "Do not advertise to any peer (well-known community)\n"
8096 "Do not export to next AS (well-known community)\n"
8097 "Exact match of the communities")
8098{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008099 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008100}
8101
8102ALIAS (show_ip_bgp_community_exact,
8103 show_ip_bgp_community2_exact_cmd,
8104 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8105 SHOW_STR
8106 IP_STR
8107 BGP_STR
8108 "Display routes matching the communities\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 "community number\n"
8114 "Do not send outside local AS (well-known community)\n"
8115 "Do not advertise to any peer (well-known community)\n"
8116 "Do not export to next AS (well-known community)\n"
8117 "Exact match of the communities")
8118
8119ALIAS (show_ip_bgp_community_exact,
8120 show_ip_bgp_community3_exact_cmd,
8121 "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",
8122 SHOW_STR
8123 IP_STR
8124 BGP_STR
8125 "Display routes matching the communities\n"
8126 "community number\n"
8127 "Do not send outside local AS (well-known community)\n"
8128 "Do not advertise to any peer (well-known community)\n"
8129 "Do not export to next AS (well-known community)\n"
8130 "community number\n"
8131 "Do not send outside local AS (well-known community)\n"
8132 "Do not advertise to any peer (well-known community)\n"
8133 "Do not export to next AS (well-known community)\n"
8134 "community number\n"
8135 "Do not send outside local AS (well-known community)\n"
8136 "Do not advertise to any peer (well-known community)\n"
8137 "Do not export to next AS (well-known community)\n"
8138 "Exact match of the communities")
8139
8140ALIAS (show_ip_bgp_community_exact,
8141 show_ip_bgp_community4_exact_cmd,
8142 "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",
8143 SHOW_STR
8144 IP_STR
8145 BGP_STR
8146 "Display routes matching the communities\n"
8147 "community number\n"
8148 "Do not send outside local AS (well-known community)\n"
8149 "Do not advertise to any peer (well-known community)\n"
8150 "Do not export to next AS (well-known community)\n"
8151 "community number\n"
8152 "Do not send outside local AS (well-known community)\n"
8153 "Do not advertise to any peer (well-known community)\n"
8154 "Do not export to next AS (well-known community)\n"
8155 "community number\n"
8156 "Do not send outside local AS (well-known community)\n"
8157 "Do not advertise to any peer (well-known community)\n"
8158 "Do not export to next AS (well-known community)\n"
8159 "community number\n"
8160 "Do not send outside local AS (well-known community)\n"
8161 "Do not advertise to any peer (well-known community)\n"
8162 "Do not export to next AS (well-known community)\n"
8163 "Exact match of the communities")
8164
8165DEFUN (show_ip_bgp_ipv4_community_exact,
8166 show_ip_bgp_ipv4_community_exact_cmd,
8167 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8168 SHOW_STR
8169 IP_STR
8170 BGP_STR
8171 "Address family\n"
8172 "Address Family modifier\n"
8173 "Address Family modifier\n"
8174 "Display routes matching the communities\n"
8175 "community number\n"
8176 "Do not send outside local AS (well-known community)\n"
8177 "Do not advertise to any peer (well-known community)\n"
8178 "Do not export to next AS (well-known community)\n"
8179 "Exact match of the communities")
8180{
8181 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008182 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008183
Michael Lambert95cbbd22010-07-23 14:43:04 -04008184 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008185}
8186
8187ALIAS (show_ip_bgp_ipv4_community_exact,
8188 show_ip_bgp_ipv4_community2_exact_cmd,
8189 "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",
8190 SHOW_STR
8191 IP_STR
8192 BGP_STR
8193 "Address family\n"
8194 "Address Family modifier\n"
8195 "Address Family modifier\n"
8196 "Display routes matching the communities\n"
8197 "community number\n"
8198 "Do not send outside local AS (well-known community)\n"
8199 "Do not advertise to any peer (well-known community)\n"
8200 "Do not export to next AS (well-known community)\n"
8201 "community number\n"
8202 "Do not send outside local AS (well-known community)\n"
8203 "Do not advertise to any peer (well-known community)\n"
8204 "Do not export to next AS (well-known community)\n"
8205 "Exact match of the communities")
8206
8207ALIAS (show_ip_bgp_ipv4_community_exact,
8208 show_ip_bgp_ipv4_community3_exact_cmd,
8209 "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",
8210 SHOW_STR
8211 IP_STR
8212 BGP_STR
8213 "Address family\n"
8214 "Address Family modifier\n"
8215 "Address Family modifier\n"
8216 "Display routes matching the communities\n"
8217 "community number\n"
8218 "Do not send outside local AS (well-known community)\n"
8219 "Do not advertise to any peer (well-known community)\n"
8220 "Do not export to next AS (well-known community)\n"
8221 "community number\n"
8222 "Do not send outside local AS (well-known community)\n"
8223 "Do not advertise to any peer (well-known community)\n"
8224 "Do not export to next AS (well-known community)\n"
8225 "community number\n"
8226 "Do not send outside local AS (well-known community)\n"
8227 "Do not advertise to any peer (well-known community)\n"
8228 "Do not export to next AS (well-known community)\n"
8229 "Exact match of the communities")
8230
8231ALIAS (show_ip_bgp_ipv4_community_exact,
8232 show_ip_bgp_ipv4_community4_exact_cmd,
8233 "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",
8234 SHOW_STR
8235 IP_STR
8236 BGP_STR
8237 "Address family\n"
8238 "Address Family modifier\n"
8239 "Address Family modifier\n"
8240 "Display routes matching the communities\n"
8241 "community number\n"
8242 "Do not send outside local AS (well-known community)\n"
8243 "Do not advertise to any peer (well-known community)\n"
8244 "Do not export to next AS (well-known community)\n"
8245 "community number\n"
8246 "Do not send outside local AS (well-known community)\n"
8247 "Do not advertise to any peer (well-known community)\n"
8248 "Do not export to next AS (well-known community)\n"
8249 "community number\n"
8250 "Do not send outside local AS (well-known community)\n"
8251 "Do not advertise to any peer (well-known community)\n"
8252 "Do not export to next AS (well-known community)\n"
8253 "community number\n"
8254 "Do not send outside local AS (well-known community)\n"
8255 "Do not advertise to any peer (well-known community)\n"
8256 "Do not export to next AS (well-known community)\n"
8257 "Exact match of the communities")
8258
8259#ifdef HAVE_IPV6
8260DEFUN (show_bgp_community,
8261 show_bgp_community_cmd,
8262 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8263 SHOW_STR
8264 BGP_STR
8265 "Display routes matching the communities\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{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008271 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008272}
8273
8274ALIAS (show_bgp_community,
8275 show_bgp_ipv6_community_cmd,
8276 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8277 SHOW_STR
8278 BGP_STR
8279 "Address family\n"
8280 "Display routes matching the communities\n"
8281 "community number\n"
8282 "Do not send outside local AS (well-known community)\n"
8283 "Do not advertise to any peer (well-known community)\n"
8284 "Do not export to next AS (well-known community)\n")
8285
8286ALIAS (show_bgp_community,
8287 show_bgp_community2_cmd,
8288 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8289 SHOW_STR
8290 BGP_STR
8291 "Display routes matching the communities\n"
8292 "community number\n"
8293 "Do not send outside local AS (well-known community)\n"
8294 "Do not advertise to any peer (well-known community)\n"
8295 "Do not export to next AS (well-known community)\n"
8296 "community number\n"
8297 "Do not send outside local AS (well-known community)\n"
8298 "Do not advertise to any peer (well-known community)\n"
8299 "Do not export to next AS (well-known community)\n")
8300
8301ALIAS (show_bgp_community,
8302 show_bgp_ipv6_community2_cmd,
8303 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8304 SHOW_STR
8305 BGP_STR
8306 "Address family\n"
8307 "Display routes matching the communities\n"
8308 "community number\n"
8309 "Do not send outside local AS (well-known community)\n"
8310 "Do not advertise to any peer (well-known community)\n"
8311 "Do not export to next AS (well-known community)\n"
8312 "community number\n"
8313 "Do not send outside local AS (well-known community)\n"
8314 "Do not advertise to any peer (well-known community)\n"
8315 "Do not export to next AS (well-known community)\n")
8316
8317ALIAS (show_bgp_community,
8318 show_bgp_community3_cmd,
8319 "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)",
8320 SHOW_STR
8321 BGP_STR
8322 "Display routes matching the communities\n"
8323 "community number\n"
8324 "Do not send outside local AS (well-known community)\n"
8325 "Do not advertise to any peer (well-known community)\n"
8326 "Do not export to next AS (well-known community)\n"
8327 "community number\n"
8328 "Do not send outside local AS (well-known community)\n"
8329 "Do not advertise to any peer (well-known community)\n"
8330 "Do not export to next AS (well-known community)\n"
8331 "community number\n"
8332 "Do not send outside local AS (well-known community)\n"
8333 "Do not advertise to any peer (well-known community)\n"
8334 "Do not export to next AS (well-known community)\n")
8335
8336ALIAS (show_bgp_community,
8337 show_bgp_ipv6_community3_cmd,
8338 "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)",
8339 SHOW_STR
8340 BGP_STR
8341 "Address family\n"
8342 "Display routes matching the communities\n"
8343 "community number\n"
8344 "Do not send outside local AS (well-known community)\n"
8345 "Do not advertise to any peer (well-known community)\n"
8346 "Do not export to next AS (well-known community)\n"
8347 "community number\n"
8348 "Do not send outside local AS (well-known community)\n"
8349 "Do not advertise to any peer (well-known community)\n"
8350 "Do not export to next AS (well-known community)\n"
8351 "community number\n"
8352 "Do not send outside local AS (well-known community)\n"
8353 "Do not advertise to any peer (well-known community)\n"
8354 "Do not export to next AS (well-known community)\n")
8355
8356ALIAS (show_bgp_community,
8357 show_bgp_community4_cmd,
8358 "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)",
8359 SHOW_STR
8360 BGP_STR
8361 "Display routes matching the communities\n"
8362 "community number\n"
8363 "Do not send outside local AS (well-known community)\n"
8364 "Do not advertise to any peer (well-known community)\n"
8365 "Do not export to next AS (well-known community)\n"
8366 "community number\n"
8367 "Do not send outside local AS (well-known community)\n"
8368 "Do not advertise to any peer (well-known community)\n"
8369 "Do not export to next AS (well-known community)\n"
8370 "community number\n"
8371 "Do not send outside local AS (well-known community)\n"
8372 "Do not advertise to any peer (well-known community)\n"
8373 "Do not export to next AS (well-known community)\n"
8374 "community number\n"
8375 "Do not send outside local AS (well-known community)\n"
8376 "Do not advertise to any peer (well-known community)\n"
8377 "Do not export to next AS (well-known community)\n")
8378
8379ALIAS (show_bgp_community,
8380 show_bgp_ipv6_community4_cmd,
8381 "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)",
8382 SHOW_STR
8383 BGP_STR
8384 "Address family\n"
8385 "Display routes matching the communities\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 "community number\n"
8391 "Do not send outside local AS (well-known community)\n"
8392 "Do not advertise to any peer (well-known community)\n"
8393 "Do not export to next AS (well-known community)\n"
8394 "community number\n"
8395 "Do not send outside local AS (well-known community)\n"
8396 "Do not advertise to any peer (well-known community)\n"
8397 "Do not export to next AS (well-known community)\n"
8398 "community number\n"
8399 "Do not send outside local AS (well-known community)\n"
8400 "Do not advertise to any peer (well-known community)\n"
8401 "Do not export to next AS (well-known community)\n")
8402
8403/* old command */
8404DEFUN (show_ipv6_bgp_community,
8405 show_ipv6_bgp_community_cmd,
8406 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8407 SHOW_STR
8408 IPV6_STR
8409 BGP_STR
8410 "Display routes matching the communities\n"
8411 "community number\n"
8412 "Do not send outside local AS (well-known community)\n"
8413 "Do not advertise to any peer (well-known community)\n"
8414 "Do not export to next AS (well-known community)\n")
8415{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008416 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008417}
8418
8419/* old command */
8420ALIAS (show_ipv6_bgp_community,
8421 show_ipv6_bgp_community2_cmd,
8422 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8423 SHOW_STR
8424 IPV6_STR
8425 BGP_STR
8426 "Display routes matching the communities\n"
8427 "community number\n"
8428 "Do not send outside local AS (well-known community)\n"
8429 "Do not advertise to any peer (well-known community)\n"
8430 "Do not export to next AS (well-known community)\n"
8431 "community number\n"
8432 "Do not send outside local AS (well-known community)\n"
8433 "Do not advertise to any peer (well-known community)\n"
8434 "Do not export to next AS (well-known community)\n")
8435
8436/* old command */
8437ALIAS (show_ipv6_bgp_community,
8438 show_ipv6_bgp_community3_cmd,
8439 "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)",
8440 SHOW_STR
8441 IPV6_STR
8442 BGP_STR
8443 "Display routes matching the communities\n"
8444 "community number\n"
8445 "Do not send outside local AS (well-known community)\n"
8446 "Do not advertise to any peer (well-known community)\n"
8447 "Do not export to next AS (well-known community)\n"
8448 "community number\n"
8449 "Do not send outside local AS (well-known community)\n"
8450 "Do not advertise to any peer (well-known community)\n"
8451 "Do not export to next AS (well-known community)\n"
8452 "community number\n"
8453 "Do not send outside local AS (well-known community)\n"
8454 "Do not advertise to any peer (well-known community)\n"
8455 "Do not export to next AS (well-known community)\n")
8456
8457/* old command */
8458ALIAS (show_ipv6_bgp_community,
8459 show_ipv6_bgp_community4_cmd,
8460 "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)",
8461 SHOW_STR
8462 IPV6_STR
8463 BGP_STR
8464 "Display routes matching the communities\n"
8465 "community number\n"
8466 "Do not send outside local AS (well-known community)\n"
8467 "Do not advertise to any peer (well-known community)\n"
8468 "Do not export to next AS (well-known community)\n"
8469 "community number\n"
8470 "Do not send outside local AS (well-known community)\n"
8471 "Do not advertise to any peer (well-known community)\n"
8472 "Do not export to next AS (well-known community)\n"
8473 "community number\n"
8474 "Do not send outside local AS (well-known community)\n"
8475 "Do not advertise to any peer (well-known community)\n"
8476 "Do not export to next AS (well-known community)\n"
8477 "community number\n"
8478 "Do not send outside local AS (well-known community)\n"
8479 "Do not advertise to any peer (well-known community)\n"
8480 "Do not export to next AS (well-known community)\n")
8481
8482DEFUN (show_bgp_community_exact,
8483 show_bgp_community_exact_cmd,
8484 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8485 SHOW_STR
8486 BGP_STR
8487 "Display routes matching the communities\n"
8488 "community number\n"
8489 "Do not send outside local AS (well-known community)\n"
8490 "Do not advertise to any peer (well-known community)\n"
8491 "Do not export to next AS (well-known community)\n"
8492 "Exact match of the communities")
8493{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008494 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008495}
8496
8497ALIAS (show_bgp_community_exact,
8498 show_bgp_ipv6_community_exact_cmd,
8499 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8500 SHOW_STR
8501 BGP_STR
8502 "Address family\n"
8503 "Display routes matching the communities\n"
8504 "community number\n"
8505 "Do not send outside local AS (well-known community)\n"
8506 "Do not advertise to any peer (well-known community)\n"
8507 "Do not export to next AS (well-known community)\n"
8508 "Exact match of the communities")
8509
8510ALIAS (show_bgp_community_exact,
8511 show_bgp_community2_exact_cmd,
8512 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8513 SHOW_STR
8514 BGP_STR
8515 "Display routes matching the communities\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 "community number\n"
8521 "Do not send outside local AS (well-known community)\n"
8522 "Do not advertise to any peer (well-known community)\n"
8523 "Do not export to next AS (well-known community)\n"
8524 "Exact match of the communities")
8525
8526ALIAS (show_bgp_community_exact,
8527 show_bgp_ipv6_community2_exact_cmd,
8528 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8529 SHOW_STR
8530 BGP_STR
8531 "Address family\n"
8532 "Display routes matching the communities\n"
8533 "community number\n"
8534 "Do not send outside local AS (well-known community)\n"
8535 "Do not advertise to any peer (well-known community)\n"
8536 "Do not export to next AS (well-known community)\n"
8537 "community number\n"
8538 "Do not send outside local AS (well-known community)\n"
8539 "Do not advertise to any peer (well-known community)\n"
8540 "Do not export to next AS (well-known community)\n"
8541 "Exact match of the communities")
8542
8543ALIAS (show_bgp_community_exact,
8544 show_bgp_community3_exact_cmd,
8545 "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",
8546 SHOW_STR
8547 BGP_STR
8548 "Display routes matching the communities\n"
8549 "community number\n"
8550 "Do not send outside local AS (well-known community)\n"
8551 "Do not advertise to any peer (well-known community)\n"
8552 "Do not export to next AS (well-known community)\n"
8553 "community number\n"
8554 "Do not send outside local AS (well-known community)\n"
8555 "Do not advertise to any peer (well-known community)\n"
8556 "Do not export to next AS (well-known community)\n"
8557 "community number\n"
8558 "Do not send outside local AS (well-known community)\n"
8559 "Do not advertise to any peer (well-known community)\n"
8560 "Do not export to next AS (well-known community)\n"
8561 "Exact match of the communities")
8562
8563ALIAS (show_bgp_community_exact,
8564 show_bgp_ipv6_community3_exact_cmd,
8565 "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",
8566 SHOW_STR
8567 BGP_STR
8568 "Address family\n"
8569 "Display routes matching the communities\n"
8570 "community number\n"
8571 "Do not send outside local AS (well-known community)\n"
8572 "Do not advertise to any peer (well-known community)\n"
8573 "Do not export to next AS (well-known community)\n"
8574 "community number\n"
8575 "Do not send outside local AS (well-known community)\n"
8576 "Do not advertise to any peer (well-known community)\n"
8577 "Do not export to next AS (well-known community)\n"
8578 "community number\n"
8579 "Do not send outside local AS (well-known community)\n"
8580 "Do not advertise to any peer (well-known community)\n"
8581 "Do not export to next AS (well-known community)\n"
8582 "Exact match of the communities")
8583
8584ALIAS (show_bgp_community_exact,
8585 show_bgp_community4_exact_cmd,
8586 "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",
8587 SHOW_STR
8588 BGP_STR
8589 "Display routes matching the communities\n"
8590 "community number\n"
8591 "Do not send outside local AS (well-known community)\n"
8592 "Do not advertise to any peer (well-known community)\n"
8593 "Do not export to next AS (well-known community)\n"
8594 "community number\n"
8595 "Do not send outside local AS (well-known community)\n"
8596 "Do not advertise to any peer (well-known community)\n"
8597 "Do not export to next AS (well-known community)\n"
8598 "community number\n"
8599 "Do not send outside local AS (well-known community)\n"
8600 "Do not advertise to any peer (well-known community)\n"
8601 "Do not export to next AS (well-known community)\n"
8602 "community number\n"
8603 "Do not send outside local AS (well-known community)\n"
8604 "Do not advertise to any peer (well-known community)\n"
8605 "Do not export to next AS (well-known community)\n"
8606 "Exact match of the communities")
8607
8608ALIAS (show_bgp_community_exact,
8609 show_bgp_ipv6_community4_exact_cmd,
8610 "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",
8611 SHOW_STR
8612 BGP_STR
8613 "Address family\n"
8614 "Display routes matching the communities\n"
8615 "community number\n"
8616 "Do not send outside local AS (well-known community)\n"
8617 "Do not advertise to any peer (well-known community)\n"
8618 "Do not export to next AS (well-known community)\n"
8619 "community number\n"
8620 "Do not send outside local AS (well-known community)\n"
8621 "Do not advertise to any peer (well-known community)\n"
8622 "Do not export to next AS (well-known community)\n"
8623 "community number\n"
8624 "Do not send outside local AS (well-known community)\n"
8625 "Do not advertise to any peer (well-known community)\n"
8626 "Do not export to next AS (well-known community)\n"
8627 "community number\n"
8628 "Do not send outside local AS (well-known community)\n"
8629 "Do not advertise to any peer (well-known community)\n"
8630 "Do not export to next AS (well-known community)\n"
8631 "Exact match of the communities")
8632
8633/* old command */
8634DEFUN (show_ipv6_bgp_community_exact,
8635 show_ipv6_bgp_community_exact_cmd,
8636 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8637 SHOW_STR
8638 IPV6_STR
8639 BGP_STR
8640 "Display routes matching the communities\n"
8641 "community number\n"
8642 "Do not send outside local AS (well-known community)\n"
8643 "Do not advertise to any peer (well-known community)\n"
8644 "Do not export to next AS (well-known community)\n"
8645 "Exact match of the communities")
8646{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008647 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008648}
8649
8650/* old command */
8651ALIAS (show_ipv6_bgp_community_exact,
8652 show_ipv6_bgp_community2_exact_cmd,
8653 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8654 SHOW_STR
8655 IPV6_STR
8656 BGP_STR
8657 "Display routes matching the communities\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 "Exact match of the communities")
8667
8668/* old command */
8669ALIAS (show_ipv6_bgp_community_exact,
8670 show_ipv6_bgp_community3_exact_cmd,
8671 "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",
8672 SHOW_STR
8673 IPV6_STR
8674 BGP_STR
8675 "Display routes matching the communities\n"
8676 "community number\n"
8677 "Do not send outside local AS (well-known community)\n"
8678 "Do not advertise to any peer (well-known community)\n"
8679 "Do not export to next AS (well-known community)\n"
8680 "community number\n"
8681 "Do not send outside local AS (well-known community)\n"
8682 "Do not advertise to any peer (well-known community)\n"
8683 "Do not export to next AS (well-known community)\n"
8684 "community number\n"
8685 "Do not send outside local AS (well-known community)\n"
8686 "Do not advertise to any peer (well-known community)\n"
8687 "Do not export to next AS (well-known community)\n"
8688 "Exact match of the communities")
8689
8690/* old command */
8691ALIAS (show_ipv6_bgp_community_exact,
8692 show_ipv6_bgp_community4_exact_cmd,
8693 "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",
8694 SHOW_STR
8695 IPV6_STR
8696 BGP_STR
8697 "Display routes matching the communities\n"
8698 "community number\n"
8699 "Do not send outside local AS (well-known community)\n"
8700 "Do not advertise to any peer (well-known community)\n"
8701 "Do not export to next AS (well-known community)\n"
8702 "community number\n"
8703 "Do not send outside local AS (well-known community)\n"
8704 "Do not advertise to any peer (well-known community)\n"
8705 "Do not export to next AS (well-known community)\n"
8706 "community number\n"
8707 "Do not send outside local AS (well-known community)\n"
8708 "Do not advertise to any peer (well-known community)\n"
8709 "Do not export to next AS (well-known community)\n"
8710 "community number\n"
8711 "Do not send outside local AS (well-known community)\n"
8712 "Do not advertise to any peer (well-known community)\n"
8713 "Do not export to next AS (well-known community)\n"
8714 "Exact match of the communities")
8715
8716/* old command */
8717DEFUN (show_ipv6_mbgp_community,
8718 show_ipv6_mbgp_community_cmd,
8719 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8720 SHOW_STR
8721 IPV6_STR
8722 MBGP_STR
8723 "Display routes matching the communities\n"
8724 "community number\n"
8725 "Do not send outside local AS (well-known community)\n"
8726 "Do not advertise to any peer (well-known community)\n"
8727 "Do not export to next AS (well-known community)\n")
8728{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008729 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008730}
8731
8732/* old command */
8733ALIAS (show_ipv6_mbgp_community,
8734 show_ipv6_mbgp_community2_cmd,
8735 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8736 SHOW_STR
8737 IPV6_STR
8738 MBGP_STR
8739 "Display routes matching the communities\n"
8740 "community number\n"
8741 "Do not send outside local AS (well-known community)\n"
8742 "Do not advertise to any peer (well-known community)\n"
8743 "Do not export to next AS (well-known community)\n"
8744 "community number\n"
8745 "Do not send outside local AS (well-known community)\n"
8746 "Do not advertise to any peer (well-known community)\n"
8747 "Do not export to next AS (well-known community)\n")
8748
8749/* old command */
8750ALIAS (show_ipv6_mbgp_community,
8751 show_ipv6_mbgp_community3_cmd,
8752 "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)",
8753 SHOW_STR
8754 IPV6_STR
8755 MBGP_STR
8756 "Display routes matching the communities\n"
8757 "community number\n"
8758 "Do not send outside local AS (well-known community)\n"
8759 "Do not advertise to any peer (well-known community)\n"
8760 "Do not export to next AS (well-known community)\n"
8761 "community number\n"
8762 "Do not send outside local AS (well-known community)\n"
8763 "Do not advertise to any peer (well-known community)\n"
8764 "Do not export to next AS (well-known community)\n"
8765 "community number\n"
8766 "Do not send outside local AS (well-known community)\n"
8767 "Do not advertise to any peer (well-known community)\n"
8768 "Do not export to next AS (well-known community)\n")
8769
8770/* old command */
8771ALIAS (show_ipv6_mbgp_community,
8772 show_ipv6_mbgp_community4_cmd,
8773 "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)",
8774 SHOW_STR
8775 IPV6_STR
8776 MBGP_STR
8777 "Display routes matching the communities\n"
8778 "community number\n"
8779 "Do not send outside local AS (well-known community)\n"
8780 "Do not advertise to any peer (well-known community)\n"
8781 "Do not export to next AS (well-known community)\n"
8782 "community number\n"
8783 "Do not send outside local AS (well-known community)\n"
8784 "Do not advertise to any peer (well-known community)\n"
8785 "Do not export to next AS (well-known community)\n"
8786 "community number\n"
8787 "Do not send outside local AS (well-known community)\n"
8788 "Do not advertise to any peer (well-known community)\n"
8789 "Do not export to next AS (well-known community)\n"
8790 "community number\n"
8791 "Do not send outside local AS (well-known community)\n"
8792 "Do not advertise to any peer (well-known community)\n"
8793 "Do not export to next AS (well-known community)\n")
8794
8795/* old command */
8796DEFUN (show_ipv6_mbgp_community_exact,
8797 show_ipv6_mbgp_community_exact_cmd,
8798 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8799 SHOW_STR
8800 IPV6_STR
8801 MBGP_STR
8802 "Display routes matching the communities\n"
8803 "community number\n"
8804 "Do not send outside local AS (well-known community)\n"
8805 "Do not advertise to any peer (well-known community)\n"
8806 "Do not export to next AS (well-known community)\n"
8807 "Exact match of the communities")
8808{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008809 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008810}
8811
8812/* old command */
8813ALIAS (show_ipv6_mbgp_community_exact,
8814 show_ipv6_mbgp_community2_exact_cmd,
8815 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8816 SHOW_STR
8817 IPV6_STR
8818 MBGP_STR
8819 "Display routes matching the communities\n"
8820 "community number\n"
8821 "Do not send outside local AS (well-known community)\n"
8822 "Do not advertise to any peer (well-known community)\n"
8823 "Do not export to next AS (well-known community)\n"
8824 "community number\n"
8825 "Do not send outside local AS (well-known community)\n"
8826 "Do not advertise to any peer (well-known community)\n"
8827 "Do not export to next AS (well-known community)\n"
8828 "Exact match of the communities")
8829
8830/* old command */
8831ALIAS (show_ipv6_mbgp_community_exact,
8832 show_ipv6_mbgp_community3_exact_cmd,
8833 "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",
8834 SHOW_STR
8835 IPV6_STR
8836 MBGP_STR
8837 "Display routes matching the communities\n"
8838 "community number\n"
8839 "Do not send outside local AS (well-known community)\n"
8840 "Do not advertise to any peer (well-known community)\n"
8841 "Do not export to next AS (well-known community)\n"
8842 "community number\n"
8843 "Do not send outside local AS (well-known community)\n"
8844 "Do not advertise to any peer (well-known community)\n"
8845 "Do not export to next AS (well-known community)\n"
8846 "community number\n"
8847 "Do not send outside local AS (well-known community)\n"
8848 "Do not advertise to any peer (well-known community)\n"
8849 "Do not export to next AS (well-known community)\n"
8850 "Exact match of the communities")
8851
8852/* old command */
8853ALIAS (show_ipv6_mbgp_community_exact,
8854 show_ipv6_mbgp_community4_exact_cmd,
8855 "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",
8856 SHOW_STR
8857 IPV6_STR
8858 MBGP_STR
8859 "Display routes matching the communities\n"
8860 "community number\n"
8861 "Do not send outside local AS (well-known community)\n"
8862 "Do not advertise to any peer (well-known community)\n"
8863 "Do not export to next AS (well-known community)\n"
8864 "community number\n"
8865 "Do not send outside local AS (well-known community)\n"
8866 "Do not advertise to any peer (well-known community)\n"
8867 "Do not export to next AS (well-known community)\n"
8868 "community number\n"
8869 "Do not send outside local AS (well-known community)\n"
8870 "Do not advertise to any peer (well-known community)\n"
8871 "Do not export to next AS (well-known community)\n"
8872 "community number\n"
8873 "Do not send outside local AS (well-known community)\n"
8874 "Do not advertise to any peer (well-known community)\n"
8875 "Do not export to next AS (well-known community)\n"
8876 "Exact match of the communities")
8877#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02008878
paul94f2b392005-06-28 12:44:16 +00008879static int
paulfd79ac92004-10-13 05:06:08 +00008880bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008881 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008882{
8883 struct community_list *list;
8884
hassofee6e4e2005-02-02 16:29:31 +00008885 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008886 if (list == NULL)
8887 {
8888 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8889 VTY_NEWLINE);
8890 return CMD_WARNING;
8891 }
8892
ajs5a646652004-11-05 01:25:55 +00008893 return bgp_show (vty, NULL, afi, safi,
8894 (exact ? bgp_show_type_community_list_exact :
8895 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008896}
8897
8898DEFUN (show_ip_bgp_community_list,
8899 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008900 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008901 SHOW_STR
8902 IP_STR
8903 BGP_STR
8904 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008905 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008906 "community-list name\n")
8907{
8908 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8909}
8910
8911DEFUN (show_ip_bgp_ipv4_community_list,
8912 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008913 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008914 SHOW_STR
8915 IP_STR
8916 BGP_STR
8917 "Address family\n"
8918 "Address Family modifier\n"
8919 "Address Family modifier\n"
8920 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008921 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008922 "community-list name\n")
8923{
8924 if (strncmp (argv[0], "m", 1) == 0)
8925 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8926
8927 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8928}
8929
8930DEFUN (show_ip_bgp_community_list_exact,
8931 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008932 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008933 SHOW_STR
8934 IP_STR
8935 BGP_STR
8936 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008937 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008938 "community-list name\n"
8939 "Exact match of the communities\n")
8940{
8941 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8942}
8943
8944DEFUN (show_ip_bgp_ipv4_community_list_exact,
8945 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008946 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008947 SHOW_STR
8948 IP_STR
8949 BGP_STR
8950 "Address family\n"
8951 "Address Family modifier\n"
8952 "Address Family modifier\n"
8953 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008954 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008955 "community-list name\n"
8956 "Exact match of the communities\n")
8957{
8958 if (strncmp (argv[0], "m", 1) == 0)
8959 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8960
8961 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8962}
8963
8964#ifdef HAVE_IPV6
8965DEFUN (show_bgp_community_list,
8966 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008967 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008968 SHOW_STR
8969 BGP_STR
8970 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008971 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008972 "community-list name\n")
8973{
8974 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8975}
8976
8977ALIAS (show_bgp_community_list,
8978 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008979 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008980 SHOW_STR
8981 BGP_STR
8982 "Address family\n"
8983 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008984 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008985 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008986
8987/* old command */
8988DEFUN (show_ipv6_bgp_community_list,
8989 show_ipv6_bgp_community_list_cmd,
8990 "show ipv6 bgp community-list WORD",
8991 SHOW_STR
8992 IPV6_STR
8993 BGP_STR
8994 "Display routes matching the community-list\n"
8995 "community-list name\n")
8996{
8997 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8998}
8999
9000/* old command */
9001DEFUN (show_ipv6_mbgp_community_list,
9002 show_ipv6_mbgp_community_list_cmd,
9003 "show ipv6 mbgp community-list WORD",
9004 SHOW_STR
9005 IPV6_STR
9006 MBGP_STR
9007 "Display routes matching the community-list\n"
9008 "community-list name\n")
9009{
9010 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
9011}
9012
9013DEFUN (show_bgp_community_list_exact,
9014 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009015 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009016 SHOW_STR
9017 BGP_STR
9018 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009019 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009020 "community-list name\n"
9021 "Exact match of the communities\n")
9022{
9023 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9024}
9025
9026ALIAS (show_bgp_community_list_exact,
9027 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009028 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009029 SHOW_STR
9030 BGP_STR
9031 "Address family\n"
9032 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009033 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009034 "community-list name\n"
9035 "Exact match of the communities\n")
9036
9037/* old command */
9038DEFUN (show_ipv6_bgp_community_list_exact,
9039 show_ipv6_bgp_community_list_exact_cmd,
9040 "show ipv6 bgp community-list WORD exact-match",
9041 SHOW_STR
9042 IPV6_STR
9043 BGP_STR
9044 "Display routes matching the community-list\n"
9045 "community-list name\n"
9046 "Exact match of the communities\n")
9047{
9048 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9049}
9050
9051/* old command */
9052DEFUN (show_ipv6_mbgp_community_list_exact,
9053 show_ipv6_mbgp_community_list_exact_cmd,
9054 "show ipv6 mbgp community-list WORD exact-match",
9055 SHOW_STR
9056 IPV6_STR
9057 MBGP_STR
9058 "Display routes matching the community-list\n"
9059 "community-list name\n"
9060 "Exact match of the communities\n")
9061{
9062 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9063}
9064#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009065
paul94f2b392005-06-28 12:44:16 +00009066static int
paulfd79ac92004-10-13 05:06:08 +00009067bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009068 safi_t safi, enum bgp_show_type type)
9069{
9070 int ret;
9071 struct prefix *p;
9072
9073 p = prefix_new();
9074
9075 ret = str2prefix (prefix, p);
9076 if (! ret)
9077 {
9078 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9079 return CMD_WARNING;
9080 }
9081
ajs5a646652004-11-05 01:25:55 +00009082 ret = bgp_show (vty, NULL, afi, safi, type, p);
9083 prefix_free(p);
9084 return ret;
paul718e3742002-12-13 20:15:29 +00009085}
9086
9087DEFUN (show_ip_bgp_prefix_longer,
9088 show_ip_bgp_prefix_longer_cmd,
9089 "show ip bgp A.B.C.D/M longer-prefixes",
9090 SHOW_STR
9091 IP_STR
9092 BGP_STR
9093 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9094 "Display route and more specific routes\n")
9095{
9096 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9097 bgp_show_type_prefix_longer);
9098}
9099
9100DEFUN (show_ip_bgp_flap_prefix_longer,
9101 show_ip_bgp_flap_prefix_longer_cmd,
9102 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9103 SHOW_STR
9104 IP_STR
9105 BGP_STR
9106 "Display flap statistics of routes\n"
9107 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9108 "Display route and more specific routes\n")
9109{
9110 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9111 bgp_show_type_flap_prefix_longer);
9112}
9113
9114DEFUN (show_ip_bgp_ipv4_prefix_longer,
9115 show_ip_bgp_ipv4_prefix_longer_cmd,
9116 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9117 SHOW_STR
9118 IP_STR
9119 BGP_STR
9120 "Address family\n"
9121 "Address Family modifier\n"
9122 "Address Family modifier\n"
9123 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9124 "Display route and more specific routes\n")
9125{
9126 if (strncmp (argv[0], "m", 1) == 0)
9127 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9128 bgp_show_type_prefix_longer);
9129
9130 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9131 bgp_show_type_prefix_longer);
9132}
9133
9134DEFUN (show_ip_bgp_flap_address,
9135 show_ip_bgp_flap_address_cmd,
9136 "show ip bgp flap-statistics A.B.C.D",
9137 SHOW_STR
9138 IP_STR
9139 BGP_STR
9140 "Display flap statistics of routes\n"
9141 "Network in the BGP routing table to display\n")
9142{
9143 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9144 bgp_show_type_flap_address);
9145}
9146
9147DEFUN (show_ip_bgp_flap_prefix,
9148 show_ip_bgp_flap_prefix_cmd,
9149 "show ip bgp flap-statistics A.B.C.D/M",
9150 SHOW_STR
9151 IP_STR
9152 BGP_STR
9153 "Display flap statistics of routes\n"
9154 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9155{
9156 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9157 bgp_show_type_flap_prefix);
9158}
9159#ifdef HAVE_IPV6
9160DEFUN (show_bgp_prefix_longer,
9161 show_bgp_prefix_longer_cmd,
9162 "show bgp X:X::X:X/M longer-prefixes",
9163 SHOW_STR
9164 BGP_STR
9165 "IPv6 prefix <network>/<length>\n"
9166 "Display route and more specific routes\n")
9167{
9168 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9169 bgp_show_type_prefix_longer);
9170}
9171
9172ALIAS (show_bgp_prefix_longer,
9173 show_bgp_ipv6_prefix_longer_cmd,
9174 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9175 SHOW_STR
9176 BGP_STR
9177 "Address family\n"
9178 "IPv6 prefix <network>/<length>\n"
9179 "Display route and more specific routes\n")
9180
9181/* old command */
9182DEFUN (show_ipv6_bgp_prefix_longer,
9183 show_ipv6_bgp_prefix_longer_cmd,
9184 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9185 SHOW_STR
9186 IPV6_STR
9187 BGP_STR
9188 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9189 "Display route and more specific routes\n")
9190{
9191 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9192 bgp_show_type_prefix_longer);
9193}
9194
9195/* old command */
9196DEFUN (show_ipv6_mbgp_prefix_longer,
9197 show_ipv6_mbgp_prefix_longer_cmd,
9198 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9199 SHOW_STR
9200 IPV6_STR
9201 MBGP_STR
9202 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9203 "Display route and more specific routes\n")
9204{
9205 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9206 bgp_show_type_prefix_longer);
9207}
9208#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009209
paul94f2b392005-06-28 12:44:16 +00009210static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009211peer_lookup_in_view (struct vty *vty, const char *view_name,
9212 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009213{
9214 int ret;
9215 struct bgp *bgp;
9216 struct peer *peer;
9217 union sockunion su;
9218
9219 /* BGP structure lookup. */
9220 if (view_name)
9221 {
9222 bgp = bgp_lookup_by_name (view_name);
9223 if (! bgp)
9224 {
9225 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9226 return NULL;
9227 }
9228 }
paul5228ad22004-06-04 17:58:18 +00009229 else
paulbb46e942003-10-24 19:02:03 +00009230 {
9231 bgp = bgp_get_default ();
9232 if (! bgp)
9233 {
9234 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9235 return NULL;
9236 }
9237 }
9238
9239 /* Get peer sockunion. */
9240 ret = str2sockunion (ip_str, &su);
9241 if (ret < 0)
9242 {
9243 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9244 return NULL;
9245 }
9246
9247 /* Peer structure lookup. */
9248 peer = peer_lookup (bgp, &su);
9249 if (! peer)
9250 {
9251 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9252 return NULL;
9253 }
9254
9255 return peer;
9256}
David Lamparter6b0655a2014-06-04 06:53:35 +02009257
Paul Jakma2815e612006-09-14 02:56:07 +00009258enum bgp_stats
9259{
9260 BGP_STATS_MAXBITLEN = 0,
9261 BGP_STATS_RIB,
9262 BGP_STATS_PREFIXES,
9263 BGP_STATS_TOTPLEN,
9264 BGP_STATS_UNAGGREGATEABLE,
9265 BGP_STATS_MAX_AGGREGATEABLE,
9266 BGP_STATS_AGGREGATES,
9267 BGP_STATS_SPACE,
9268 BGP_STATS_ASPATH_COUNT,
9269 BGP_STATS_ASPATH_MAXHOPS,
9270 BGP_STATS_ASPATH_TOTHOPS,
9271 BGP_STATS_ASPATH_MAXSIZE,
9272 BGP_STATS_ASPATH_TOTSIZE,
9273 BGP_STATS_ASN_HIGHEST,
9274 BGP_STATS_MAX,
9275};
paulbb46e942003-10-24 19:02:03 +00009276
Paul Jakma2815e612006-09-14 02:56:07 +00009277static const char *table_stats_strs[] =
9278{
9279 [BGP_STATS_PREFIXES] = "Total Prefixes",
9280 [BGP_STATS_TOTPLEN] = "Average prefix length",
9281 [BGP_STATS_RIB] = "Total Advertisements",
9282 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9283 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9284 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9285 [BGP_STATS_SPACE] = "Address space advertised",
9286 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9287 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9288 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9289 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9290 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9291 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9292 [BGP_STATS_MAX] = NULL,
9293};
9294
9295struct bgp_table_stats
9296{
9297 struct bgp_table *table;
9298 unsigned long long counts[BGP_STATS_MAX];
9299};
9300
9301#if 0
9302#define TALLY_SIGFIG 100000
9303static unsigned long
9304ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9305{
9306 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9307 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9308 unsigned long ret = newtot / count;
9309
9310 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9311 return ret + 1;
9312 else
9313 return ret;
9314}
9315#endif
9316
9317static int
9318bgp_table_stats_walker (struct thread *t)
9319{
9320 struct bgp_node *rn;
9321 struct bgp_node *top;
9322 struct bgp_table_stats *ts = THREAD_ARG (t);
9323 unsigned int space = 0;
9324
Paul Jakma53d9f672006-10-15 23:41:16 +00009325 if (!(top = bgp_table_top (ts->table)))
9326 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009327
9328 switch (top->p.family)
9329 {
9330 case AF_INET:
9331 space = IPV4_MAX_BITLEN;
9332 break;
9333 case AF_INET6:
9334 space = IPV6_MAX_BITLEN;
9335 break;
9336 }
9337
9338 ts->counts[BGP_STATS_MAXBITLEN] = space;
9339
9340 for (rn = top; rn; rn = bgp_route_next (rn))
9341 {
9342 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009343 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009344 unsigned int rinum = 0;
9345
9346 if (rn == top)
9347 continue;
9348
9349 if (!rn->info)
9350 continue;
9351
9352 ts->counts[BGP_STATS_PREFIXES]++;
9353 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9354
9355#if 0
9356 ts->counts[BGP_STATS_AVGPLEN]
9357 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9358 ts->counts[BGP_STATS_AVGPLEN],
9359 rn->p.prefixlen);
9360#endif
9361
9362 /* check if the prefix is included by any other announcements */
9363 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009364 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009365
9366 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009367 {
9368 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9369 /* announced address space */
9370 if (space)
9371 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9372 }
Paul Jakma2815e612006-09-14 02:56:07 +00009373 else if (prn->info)
9374 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9375
Paul Jakma2815e612006-09-14 02:56:07 +00009376 for (ri = rn->info; ri; ri = ri->next)
9377 {
9378 rinum++;
9379 ts->counts[BGP_STATS_RIB]++;
9380
9381 if (ri->attr &&
9382 (CHECK_FLAG (ri->attr->flag,
9383 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9384 ts->counts[BGP_STATS_AGGREGATES]++;
9385
9386 /* as-path stats */
9387 if (ri->attr && ri->attr->aspath)
9388 {
9389 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9390 unsigned int size = aspath_size (ri->attr->aspath);
9391 as_t highest = aspath_highest (ri->attr->aspath);
9392
9393 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9394
9395 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9396 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9397
9398 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9399 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9400
9401 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9402 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9403#if 0
9404 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9405 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9406 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9407 hops);
9408 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9409 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9410 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9411 size);
9412#endif
9413 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9414 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9415 }
9416 }
9417 }
9418 return 0;
9419}
9420
9421static int
9422bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9423{
9424 struct bgp_table_stats ts;
9425 unsigned int i;
9426
9427 if (!bgp->rib[afi][safi])
9428 {
9429 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9430 return CMD_WARNING;
9431 }
9432
9433 memset (&ts, 0, sizeof (ts));
9434 ts.table = bgp->rib[afi][safi];
9435 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9436
9437 vty_out (vty, "BGP %s RIB statistics%s%s",
9438 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9439
9440 for (i = 0; i < BGP_STATS_MAX; i++)
9441 {
9442 if (!table_stats_strs[i])
9443 continue;
9444
9445 switch (i)
9446 {
9447#if 0
9448 case BGP_STATS_ASPATH_AVGHOPS:
9449 case BGP_STATS_ASPATH_AVGSIZE:
9450 case BGP_STATS_AVGPLEN:
9451 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9452 vty_out (vty, "%12.2f",
9453 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9454 break;
9455#endif
9456 case BGP_STATS_ASPATH_TOTHOPS:
9457 case BGP_STATS_ASPATH_TOTSIZE:
9458 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9459 vty_out (vty, "%12.2f",
9460 ts.counts[i] ?
9461 (float)ts.counts[i] /
9462 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9463 : 0);
9464 break;
9465 case BGP_STATS_TOTPLEN:
9466 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9467 vty_out (vty, "%12.2f",
9468 ts.counts[i] ?
9469 (float)ts.counts[i] /
9470 (float)ts.counts[BGP_STATS_PREFIXES]
9471 : 0);
9472 break;
9473 case BGP_STATS_SPACE:
9474 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9475 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9476 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9477 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009478 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009479 vty_out (vty, "%12.2f%s",
9480 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009481 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009482 VTY_NEWLINE);
9483 vty_out (vty, "%30s: ", "/8 equivalent ");
9484 vty_out (vty, "%12.2f%s",
9485 (float)ts.counts[BGP_STATS_SPACE] /
9486 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9487 VTY_NEWLINE);
9488 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9489 break;
9490 vty_out (vty, "%30s: ", "/24 equivalent ");
9491 vty_out (vty, "%12.2f",
9492 (float)ts.counts[BGP_STATS_SPACE] /
9493 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9494 break;
9495 default:
9496 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9497 vty_out (vty, "%12llu", ts.counts[i]);
9498 }
9499
9500 vty_out (vty, "%s", VTY_NEWLINE);
9501 }
9502 return CMD_SUCCESS;
9503}
9504
9505static int
9506bgp_table_stats_vty (struct vty *vty, const char *name,
9507 const char *afi_str, const char *safi_str)
9508{
9509 struct bgp *bgp;
9510 afi_t afi;
9511 safi_t safi;
9512
9513 if (name)
9514 bgp = bgp_lookup_by_name (name);
9515 else
9516 bgp = bgp_get_default ();
9517
9518 if (!bgp)
9519 {
9520 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9521 return CMD_WARNING;
9522 }
9523 if (strncmp (afi_str, "ipv", 3) == 0)
9524 {
9525 if (strncmp (afi_str, "ipv4", 4) == 0)
9526 afi = AFI_IP;
9527 else if (strncmp (afi_str, "ipv6", 4) == 0)
9528 afi = AFI_IP6;
9529 else
9530 {
9531 vty_out (vty, "%% Invalid address family %s%s",
9532 afi_str, VTY_NEWLINE);
9533 return CMD_WARNING;
9534 }
9535 if (strncmp (safi_str, "m", 1) == 0)
9536 safi = SAFI_MULTICAST;
9537 else if (strncmp (safi_str, "u", 1) == 0)
9538 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009539 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9540 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009541 else
9542 {
9543 vty_out (vty, "%% Invalid subsequent address family %s%s",
9544 safi_str, VTY_NEWLINE);
9545 return CMD_WARNING;
9546 }
9547 }
9548 else
9549 {
9550 vty_out (vty, "%% Invalid address family %s%s",
9551 afi_str, VTY_NEWLINE);
9552 return CMD_WARNING;
9553 }
9554
Paul Jakma2815e612006-09-14 02:56:07 +00009555 return bgp_table_stats (vty, bgp, afi, safi);
9556}
9557
9558DEFUN (show_bgp_statistics,
9559 show_bgp_statistics_cmd,
9560 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9561 SHOW_STR
9562 BGP_STR
9563 "Address family\n"
9564 "Address family\n"
9565 "Address Family modifier\n"
9566 "Address Family modifier\n"
9567 "BGP RIB advertisement statistics\n")
9568{
9569 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9570}
9571
9572ALIAS (show_bgp_statistics,
9573 show_bgp_statistics_vpnv4_cmd,
9574 "show bgp (ipv4) (vpnv4) statistics",
9575 SHOW_STR
9576 BGP_STR
9577 "Address family\n"
9578 "Address Family modifier\n"
9579 "BGP RIB advertisement statistics\n")
9580
9581DEFUN (show_bgp_statistics_view,
9582 show_bgp_statistics_view_cmd,
9583 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9584 SHOW_STR
9585 BGP_STR
9586 "BGP view\n"
9587 "Address family\n"
9588 "Address family\n"
9589 "Address Family modifier\n"
9590 "Address Family modifier\n"
9591 "BGP RIB advertisement statistics\n")
9592{
9593 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9594}
9595
9596ALIAS (show_bgp_statistics_view,
9597 show_bgp_statistics_view_vpnv4_cmd,
9598 "show bgp view WORD (ipv4) (vpnv4) statistics",
9599 SHOW_STR
9600 BGP_STR
9601 "BGP view\n"
9602 "Address family\n"
9603 "Address Family modifier\n"
9604 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02009605
Paul Jakmaff7924f2006-09-04 01:10:36 +00009606enum bgp_pcounts
9607{
9608 PCOUNT_ADJ_IN = 0,
9609 PCOUNT_DAMPED,
9610 PCOUNT_REMOVED,
9611 PCOUNT_HISTORY,
9612 PCOUNT_STALE,
9613 PCOUNT_VALID,
9614 PCOUNT_ALL,
9615 PCOUNT_COUNTED,
9616 PCOUNT_PFCNT, /* the figure we display to users */
9617 PCOUNT_MAX,
9618};
9619
9620static const char *pcount_strs[] =
9621{
9622 [PCOUNT_ADJ_IN] = "Adj-in",
9623 [PCOUNT_DAMPED] = "Damped",
9624 [PCOUNT_REMOVED] = "Removed",
9625 [PCOUNT_HISTORY] = "History",
9626 [PCOUNT_STALE] = "Stale",
9627 [PCOUNT_VALID] = "Valid",
9628 [PCOUNT_ALL] = "All RIB",
9629 [PCOUNT_COUNTED] = "PfxCt counted",
9630 [PCOUNT_PFCNT] = "Useable",
9631 [PCOUNT_MAX] = NULL,
9632};
9633
Paul Jakma2815e612006-09-14 02:56:07 +00009634struct peer_pcounts
9635{
9636 unsigned int count[PCOUNT_MAX];
9637 const struct peer *peer;
9638 const struct bgp_table *table;
9639};
9640
Paul Jakmaff7924f2006-09-04 01:10:36 +00009641static int
Paul Jakma2815e612006-09-14 02:56:07 +00009642bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009643{
9644 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009645 struct peer_pcounts *pc = THREAD_ARG (t);
9646 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009647
Paul Jakma2815e612006-09-14 02:56:07 +00009648 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009649 {
9650 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009651 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009652
9653 for (ain = rn->adj_in; ain; ain = ain->next)
9654 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009655 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009656
Paul Jakmaff7924f2006-09-04 01:10:36 +00009657 for (ri = rn->info; ri; ri = ri->next)
9658 {
9659 char buf[SU_ADDRSTRLEN];
9660
9661 if (ri->peer != peer)
9662 continue;
9663
Paul Jakma2815e612006-09-14 02:56:07 +00009664 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009665
9666 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009667 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009668 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009669 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009670 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009671 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009672 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009673 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009674 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009675 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009676 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009677 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009678
9679 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9680 {
Paul Jakma2815e612006-09-14 02:56:07 +00009681 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009682 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009683 plog_warn (peer->log,
9684 "%s [pcount] %s/%d is counted but flags 0x%x",
9685 peer->host,
9686 inet_ntop(rn->p.family, &rn->p.u.prefix,
9687 buf, SU_ADDRSTRLEN),
9688 rn->p.prefixlen,
9689 ri->flags);
9690 }
9691 else
9692 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009693 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009694 plog_warn (peer->log,
9695 "%s [pcount] %s/%d not counted but flags 0x%x",
9696 peer->host,
9697 inet_ntop(rn->p.family, &rn->p.u.prefix,
9698 buf, SU_ADDRSTRLEN),
9699 rn->p.prefixlen,
9700 ri->flags);
9701 }
9702 }
9703 }
Paul Jakma2815e612006-09-14 02:56:07 +00009704 return 0;
9705}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009706
Paul Jakma2815e612006-09-14 02:56:07 +00009707static int
9708bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9709{
9710 struct peer_pcounts pcounts = { .peer = peer };
9711 unsigned int i;
9712
9713 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9714 || !peer->bgp->rib[afi][safi])
9715 {
9716 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9717 return CMD_WARNING;
9718 }
9719
9720 memset (&pcounts, 0, sizeof(pcounts));
9721 pcounts.peer = peer;
9722 pcounts.table = peer->bgp->rib[afi][safi];
9723
9724 /* in-place call via thread subsystem so as to record execution time
9725 * stats for the thread-walk (i.e. ensure this can't be blamed on
9726 * on just vty_read()).
9727 */
9728 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9729
Paul Jakmaff7924f2006-09-04 01:10:36 +00009730 vty_out (vty, "Prefix counts for %s, %s%s",
9731 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9732 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9733 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9734 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9735
9736 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009737 vty_out (vty, "%20s: %-10d%s",
9738 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009739
Paul Jakma2815e612006-09-14 02:56:07 +00009740 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009741 {
9742 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9743 peer->host, VTY_NEWLINE);
9744 vty_out (vty, "Please report this bug, with the above command output%s",
9745 VTY_NEWLINE);
9746 }
9747
9748 return CMD_SUCCESS;
9749}
9750
9751DEFUN (show_ip_bgp_neighbor_prefix_counts,
9752 show_ip_bgp_neighbor_prefix_counts_cmd,
9753 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9754 SHOW_STR
9755 IP_STR
9756 BGP_STR
9757 "Detailed information on TCP and BGP neighbor connections\n"
9758 "Neighbor to display information about\n"
9759 "Neighbor to display information about\n"
9760 "Display detailed prefix count information\n")
9761{
9762 struct peer *peer;
9763
9764 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9765 if (! peer)
9766 return CMD_WARNING;
9767
9768 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9769}
9770
9771DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9772 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9773 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9774 SHOW_STR
9775 BGP_STR
9776 "Address family\n"
9777 "Detailed information on TCP and BGP neighbor connections\n"
9778 "Neighbor to display information about\n"
9779 "Neighbor to display information about\n"
9780 "Display detailed prefix count information\n")
9781{
9782 struct peer *peer;
9783
9784 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9785 if (! peer)
9786 return CMD_WARNING;
9787
9788 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9789}
9790
9791DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9792 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9793 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9794 SHOW_STR
9795 IP_STR
9796 BGP_STR
9797 "Address family\n"
9798 "Address Family modifier\n"
9799 "Address Family modifier\n"
9800 "Detailed information on TCP and BGP neighbor connections\n"
9801 "Neighbor to display information about\n"
9802 "Neighbor to display information about\n"
9803 "Display detailed prefix count information\n")
9804{
9805 struct peer *peer;
9806
9807 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9808 if (! peer)
9809 return CMD_WARNING;
9810
9811 if (strncmp (argv[0], "m", 1) == 0)
9812 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9813
9814 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9815}
9816
9817DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9818 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9819 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9820 SHOW_STR
9821 IP_STR
9822 BGP_STR
9823 "Address family\n"
9824 "Address Family modifier\n"
9825 "Address Family modifier\n"
9826 "Detailed information on TCP and BGP neighbor connections\n"
9827 "Neighbor to display information about\n"
9828 "Neighbor to display information about\n"
9829 "Display detailed prefix count information\n")
9830{
9831 struct peer *peer;
9832
9833 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9834 if (! peer)
9835 return CMD_WARNING;
9836
9837 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9838}
9839
9840
paul94f2b392005-06-28 12:44:16 +00009841static void
paul718e3742002-12-13 20:15:29 +00009842show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9843 int in)
9844{
9845 struct bgp_table *table;
9846 struct bgp_adj_in *ain;
9847 struct bgp_adj_out *adj;
9848 unsigned long output_count;
9849 struct bgp_node *rn;
9850 int header1 = 1;
9851 struct bgp *bgp;
9852 int header2 = 1;
9853
paulbb46e942003-10-24 19:02:03 +00009854 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009855
9856 if (! bgp)
9857 return;
9858
9859 table = bgp->rib[afi][safi];
9860
9861 output_count = 0;
9862
9863 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9864 PEER_STATUS_DEFAULT_ORIGINATE))
9865 {
9866 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 +00009867 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9868 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009869
9870 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9871 VTY_NEWLINE, VTY_NEWLINE);
9872 header1 = 0;
9873 }
9874
9875 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9876 if (in)
9877 {
9878 for (ain = rn->adj_in; ain; ain = ain->next)
9879 if (ain->peer == peer)
9880 {
9881 if (header1)
9882 {
9883 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 +00009884 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9885 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009886 header1 = 0;
9887 }
9888 if (header2)
9889 {
9890 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9891 header2 = 0;
9892 }
9893 if (ain->attr)
9894 {
9895 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9896 output_count++;
9897 }
9898 }
9899 }
9900 else
9901 {
9902 for (adj = rn->adj_out; adj; adj = adj->next)
9903 if (adj->peer == peer)
9904 {
9905 if (header1)
9906 {
9907 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 +00009908 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9909 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009910 header1 = 0;
9911 }
9912 if (header2)
9913 {
9914 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9915 header2 = 0;
9916 }
9917 if (adj->attr)
9918 {
9919 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9920 output_count++;
9921 }
9922 }
9923 }
9924
9925 if (output_count != 0)
9926 vty_out (vty, "%sTotal number of prefixes %ld%s",
9927 VTY_NEWLINE, output_count, VTY_NEWLINE);
9928}
9929
paul94f2b392005-06-28 12:44:16 +00009930static int
paulbb46e942003-10-24 19:02:03 +00009931peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9932{
paul718e3742002-12-13 20:15:29 +00009933 if (! peer || ! peer->afc[afi][safi])
9934 {
9935 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9936 return CMD_WARNING;
9937 }
9938
9939 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9940 {
9941 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9942 VTY_NEWLINE);
9943 return CMD_WARNING;
9944 }
9945
9946 show_adj_route (vty, peer, afi, safi, in);
9947
9948 return CMD_SUCCESS;
9949}
9950
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009951DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9952 show_ip_bgp_view_neighbor_advertised_route_cmd,
9953 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9954 SHOW_STR
9955 IP_STR
9956 BGP_STR
9957 "BGP view\n"
9958 "View name\n"
9959 "Detailed information on TCP and BGP neighbor connections\n"
9960 "Neighbor to display information about\n"
9961 "Neighbor to display information about\n"
9962 "Display the routes advertised to a BGP neighbor\n")
9963{
9964 struct peer *peer;
9965
9966 if (argc == 2)
9967 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9968 else
9969 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9970
9971 if (! peer)
9972 return CMD_WARNING;
9973
9974 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9975}
9976
9977ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009978 show_ip_bgp_neighbor_advertised_route_cmd,
9979 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9980 SHOW_STR
9981 IP_STR
9982 BGP_STR
9983 "Detailed information on TCP and BGP neighbor connections\n"
9984 "Neighbor to display information about\n"
9985 "Neighbor to display information about\n"
9986 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009987
9988DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9989 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9990 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9991 SHOW_STR
9992 IP_STR
9993 BGP_STR
9994 "Address family\n"
9995 "Address Family modifier\n"
9996 "Address Family modifier\n"
9997 "Detailed information on TCP and BGP neighbor connections\n"
9998 "Neighbor to display information about\n"
9999 "Neighbor to display information about\n"
10000 "Display the routes advertised to a BGP neighbor\n")
10001{
paulbb46e942003-10-24 19:02:03 +000010002 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010003
paulbb46e942003-10-24 19:02:03 +000010004 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10005 if (! peer)
10006 return CMD_WARNING;
10007
10008 if (strncmp (argv[0], "m", 1) == 0)
10009 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
10010
10011 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +000010012}
10013
10014#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010015DEFUN (show_bgp_view_neighbor_advertised_route,
10016 show_bgp_view_neighbor_advertised_route_cmd,
10017 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10018 SHOW_STR
10019 BGP_STR
10020 "BGP view\n"
10021 "View name\n"
10022 "Detailed information on TCP and BGP neighbor connections\n"
10023 "Neighbor to display information about\n"
10024 "Neighbor to display information about\n"
10025 "Display the routes advertised to a BGP neighbor\n")
10026{
10027 struct peer *peer;
10028
10029 if (argc == 2)
10030 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10031 else
10032 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10033
10034 if (! peer)
10035 return CMD_WARNING;
10036
10037 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10038}
10039
10040ALIAS (show_bgp_view_neighbor_advertised_route,
10041 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10042 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10043 SHOW_STR
10044 BGP_STR
10045 "BGP view\n"
10046 "View name\n"
10047 "Address family\n"
10048 "Detailed information on TCP and BGP neighbor connections\n"
10049 "Neighbor to display information about\n"
10050 "Neighbor to display information about\n"
10051 "Display the routes advertised to a BGP neighbor\n")
10052
10053DEFUN (show_bgp_view_neighbor_received_routes,
10054 show_bgp_view_neighbor_received_routes_cmd,
10055 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10056 SHOW_STR
10057 BGP_STR
10058 "BGP view\n"
10059 "View name\n"
10060 "Detailed information on TCP and BGP neighbor connections\n"
10061 "Neighbor to display information about\n"
10062 "Neighbor to display information about\n"
10063 "Display the received routes from neighbor\n")
10064{
10065 struct peer *peer;
10066
10067 if (argc == 2)
10068 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10069 else
10070 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10071
10072 if (! peer)
10073 return CMD_WARNING;
10074
10075 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10076}
10077
10078ALIAS (show_bgp_view_neighbor_received_routes,
10079 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10080 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10081 SHOW_STR
10082 BGP_STR
10083 "BGP view\n"
10084 "View name\n"
10085 "Address family\n"
10086 "Detailed information on TCP and BGP neighbor connections\n"
10087 "Neighbor to display information about\n"
10088 "Neighbor to display information about\n"
10089 "Display the received routes from neighbor\n")
10090
10091ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010092 show_bgp_neighbor_advertised_route_cmd,
10093 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10094 SHOW_STR
10095 BGP_STR
10096 "Detailed information on TCP and BGP neighbor connections\n"
10097 "Neighbor to display information about\n"
10098 "Neighbor to display information about\n"
10099 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010100
10101ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010102 show_bgp_ipv6_neighbor_advertised_route_cmd,
10103 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10104 SHOW_STR
10105 BGP_STR
10106 "Address family\n"
10107 "Detailed information on TCP and BGP neighbor connections\n"
10108 "Neighbor to display information about\n"
10109 "Neighbor to display information about\n"
10110 "Display the routes advertised to a BGP neighbor\n")
10111
10112/* old command */
paulbb46e942003-10-24 19:02:03 +000010113ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010114 ipv6_bgp_neighbor_advertised_route_cmd,
10115 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10116 SHOW_STR
10117 IPV6_STR
10118 BGP_STR
10119 "Detailed information on TCP and BGP neighbor connections\n"
10120 "Neighbor to display information about\n"
10121 "Neighbor to display information about\n"
10122 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010123
paul718e3742002-12-13 20:15:29 +000010124/* old command */
10125DEFUN (ipv6_mbgp_neighbor_advertised_route,
10126 ipv6_mbgp_neighbor_advertised_route_cmd,
10127 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10128 SHOW_STR
10129 IPV6_STR
10130 MBGP_STR
10131 "Detailed information on TCP and BGP neighbor connections\n"
10132 "Neighbor to display information about\n"
10133 "Neighbor to display information about\n"
10134 "Display the routes advertised to a BGP neighbor\n")
10135{
paulbb46e942003-10-24 19:02:03 +000010136 struct peer *peer;
10137
10138 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10139 if (! peer)
10140 return CMD_WARNING;
10141
10142 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010143}
10144#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010145
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010146DEFUN (show_ip_bgp_view_neighbor_received_routes,
10147 show_ip_bgp_view_neighbor_received_routes_cmd,
10148 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10149 SHOW_STR
10150 IP_STR
10151 BGP_STR
10152 "BGP view\n"
10153 "View name\n"
10154 "Detailed information on TCP and BGP neighbor connections\n"
10155 "Neighbor to display information about\n"
10156 "Neighbor to display information about\n"
10157 "Display the received routes from neighbor\n")
10158{
10159 struct peer *peer;
10160
10161 if (argc == 2)
10162 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10163 else
10164 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10165
10166 if (! peer)
10167 return CMD_WARNING;
10168
10169 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10170}
10171
10172ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010173 show_ip_bgp_neighbor_received_routes_cmd,
10174 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10175 SHOW_STR
10176 IP_STR
10177 BGP_STR
10178 "Detailed information on TCP and BGP neighbor connections\n"
10179 "Neighbor to display information about\n"
10180 "Neighbor to display information about\n"
10181 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010182
10183DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10184 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10185 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10186 SHOW_STR
10187 IP_STR
10188 BGP_STR
10189 "Address family\n"
10190 "Address Family modifier\n"
10191 "Address Family modifier\n"
10192 "Detailed information on TCP and BGP neighbor connections\n"
10193 "Neighbor to display information about\n"
10194 "Neighbor to display information about\n"
10195 "Display the received routes from neighbor\n")
10196{
paulbb46e942003-10-24 19:02:03 +000010197 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010198
paulbb46e942003-10-24 19:02:03 +000010199 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10200 if (! peer)
10201 return CMD_WARNING;
10202
10203 if (strncmp (argv[0], "m", 1) == 0)
10204 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10205
10206 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010207}
10208
Michael Lambert95cbbd22010-07-23 14:43:04 -040010209DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10210 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10211#ifdef HAVE_IPV6
10212 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10213#else
10214 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10215#endif
10216 SHOW_STR
10217 BGP_STR
10218 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010219 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010220 "Address family\n"
10221#ifdef HAVE_IPV6
10222 "Address family\n"
10223#endif
10224 "Address family modifier\n"
10225 "Address family modifier\n"
10226 "Detailed information on TCP and BGP neighbor connections\n"
10227 "Neighbor to display information about\n"
10228 "Neighbor to display information about\n"
10229 "Display the advertised routes to neighbor\n"
10230 "Display the received routes from neighbor\n")
10231{
10232 int afi;
10233 int safi;
10234 int in;
10235 struct peer *peer;
10236
10237#ifdef HAVE_IPV6
10238 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10239#else
10240 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10241#endif
10242
10243 if (! peer)
10244 return CMD_WARNING;
10245
10246#ifdef HAVE_IPV6
10247 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10248 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10249 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10250#else
10251 afi = AFI_IP;
10252 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10253 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10254#endif
10255
10256 return peer_adj_routes (vty, peer, afi, safi, in);
10257}
10258
paul718e3742002-12-13 20:15:29 +000010259DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10260 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10261 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10262 SHOW_STR
10263 IP_STR
10264 BGP_STR
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 information received from a BGP neighbor\n"
10269 "Display the prefixlist filter\n")
10270{
10271 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010272 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010273 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010274 int count, ret;
paul718e3742002-12-13 20:15:29 +000010275
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010276 ret = str2sockunion (argv[0], &su);
10277 if (ret < 0)
10278 {
10279 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10280 return CMD_WARNING;
10281 }
paul718e3742002-12-13 20:15:29 +000010282
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010283 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010284 if (! peer)
10285 return CMD_WARNING;
10286
10287 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10288 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10289 if (count)
10290 {
10291 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10292 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10293 }
10294
10295 return CMD_SUCCESS;
10296}
10297
10298DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10299 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10300 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10301 SHOW_STR
10302 IP_STR
10303 BGP_STR
10304 "Address family\n"
10305 "Address Family modifier\n"
10306 "Address Family modifier\n"
10307 "Detailed information on TCP and BGP neighbor connections\n"
10308 "Neighbor to display information about\n"
10309 "Neighbor to display information about\n"
10310 "Display information received from a BGP neighbor\n"
10311 "Display the prefixlist filter\n")
10312{
10313 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010314 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010315 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010316 int count, ret;
paul718e3742002-12-13 20:15:29 +000010317
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010318 ret = str2sockunion (argv[1], &su);
10319 if (ret < 0)
10320 {
10321 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10322 return CMD_WARNING;
10323 }
paul718e3742002-12-13 20:15:29 +000010324
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010325 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010326 if (! peer)
10327 return CMD_WARNING;
10328
10329 if (strncmp (argv[0], "m", 1) == 0)
10330 {
10331 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10332 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10333 if (count)
10334 {
10335 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10336 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10337 }
10338 }
10339 else
10340 {
10341 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10342 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10343 if (count)
10344 {
10345 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10346 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10347 }
10348 }
10349
10350 return CMD_SUCCESS;
10351}
10352
10353
10354#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010355ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010356 show_bgp_neighbor_received_routes_cmd,
10357 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10358 SHOW_STR
10359 BGP_STR
10360 "Detailed information on TCP and BGP neighbor connections\n"
10361 "Neighbor to display information about\n"
10362 "Neighbor to display information about\n"
10363 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010364
paulbb46e942003-10-24 19:02:03 +000010365ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010366 show_bgp_ipv6_neighbor_received_routes_cmd,
10367 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10368 SHOW_STR
10369 BGP_STR
10370 "Address family\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
10376DEFUN (show_bgp_neighbor_received_prefix_filter,
10377 show_bgp_neighbor_received_prefix_filter_cmd,
10378 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10379 SHOW_STR
10380 BGP_STR
10381 "Detailed information on TCP and BGP neighbor connections\n"
10382 "Neighbor to display information about\n"
10383 "Neighbor to display information about\n"
10384 "Display information received from a BGP neighbor\n"
10385 "Display the prefixlist filter\n")
10386{
10387 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010388 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010389 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010390 int count, ret;
paul718e3742002-12-13 20:15:29 +000010391
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010392 ret = str2sockunion (argv[0], &su);
10393 if (ret < 0)
10394 {
10395 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10396 return CMD_WARNING;
10397 }
paul718e3742002-12-13 20:15:29 +000010398
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010399 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010400 if (! peer)
10401 return CMD_WARNING;
10402
10403 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10404 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10405 if (count)
10406 {
10407 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10408 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10409 }
10410
10411 return CMD_SUCCESS;
10412}
10413
10414ALIAS (show_bgp_neighbor_received_prefix_filter,
10415 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10416 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10417 SHOW_STR
10418 BGP_STR
10419 "Address family\n"
10420 "Detailed information on TCP and BGP neighbor connections\n"
10421 "Neighbor to display information about\n"
10422 "Neighbor to display information about\n"
10423 "Display information received from a BGP neighbor\n"
10424 "Display the prefixlist filter\n")
10425
10426/* old command */
paulbb46e942003-10-24 19:02:03 +000010427ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010428 ipv6_bgp_neighbor_received_routes_cmd,
10429 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10430 SHOW_STR
10431 IPV6_STR
10432 BGP_STR
10433 "Detailed information on TCP and BGP neighbor connections\n"
10434 "Neighbor to display information about\n"
10435 "Neighbor to display information about\n"
10436 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010437
10438/* old command */
10439DEFUN (ipv6_mbgp_neighbor_received_routes,
10440 ipv6_mbgp_neighbor_received_routes_cmd,
10441 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10442 SHOW_STR
10443 IPV6_STR
10444 MBGP_STR
10445 "Detailed information on TCP and BGP neighbor connections\n"
10446 "Neighbor to display information about\n"
10447 "Neighbor to display information about\n"
10448 "Display the received routes from neighbor\n")
10449{
paulbb46e942003-10-24 19:02:03 +000010450 struct peer *peer;
10451
10452 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10453 if (! peer)
10454 return CMD_WARNING;
10455
10456 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010457}
paulbb46e942003-10-24 19:02:03 +000010458
10459DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10460 show_bgp_view_neighbor_received_prefix_filter_cmd,
10461 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10462 SHOW_STR
10463 BGP_STR
10464 "BGP view\n"
10465 "View name\n"
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;
paulbb46e942003-10-24 19:02:03 +000010474 struct peer *peer;
10475 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010476 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010477
10478 /* BGP structure lookup. */
10479 bgp = bgp_lookup_by_name (argv[0]);
10480 if (bgp == NULL)
10481 {
10482 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10483 return CMD_WARNING;
10484 }
10485
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010486 ret = str2sockunion (argv[1], &su);
10487 if (ret < 0)
10488 {
10489 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10490 return CMD_WARNING;
10491 }
paulbb46e942003-10-24 19:02:03 +000010492
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010493 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010494 if (! peer)
10495 return CMD_WARNING;
10496
10497 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10498 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10499 if (count)
10500 {
10501 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10502 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10503 }
10504
10505 return CMD_SUCCESS;
10506}
10507
10508ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10509 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10510 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10511 SHOW_STR
10512 BGP_STR
10513 "BGP view\n"
10514 "View name\n"
10515 "Address family\n"
10516 "Detailed information on TCP and BGP neighbor connections\n"
10517 "Neighbor to display information about\n"
10518 "Neighbor to display information about\n"
10519 "Display information received from a BGP neighbor\n"
10520 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010521#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010522
paul94f2b392005-06-28 12:44:16 +000010523static int
paulbb46e942003-10-24 19:02:03 +000010524bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010525 safi_t safi, enum bgp_show_type type)
10526{
paul718e3742002-12-13 20:15:29 +000010527 if (! peer || ! peer->afc[afi][safi])
10528 {
10529 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010530 return CMD_WARNING;
10531 }
10532
ajs5a646652004-11-05 01:25:55 +000010533 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010534}
10535
10536DEFUN (show_ip_bgp_neighbor_routes,
10537 show_ip_bgp_neighbor_routes_cmd,
10538 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10539 SHOW_STR
10540 IP_STR
10541 BGP_STR
10542 "Detailed information on TCP and BGP neighbor connections\n"
10543 "Neighbor to display information about\n"
10544 "Neighbor to display information about\n"
10545 "Display routes learned from neighbor\n")
10546{
paulbb46e942003-10-24 19:02:03 +000010547 struct peer *peer;
10548
10549 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10550 if (! peer)
10551 return CMD_WARNING;
10552
10553 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010554 bgp_show_type_neighbor);
10555}
10556
10557DEFUN (show_ip_bgp_neighbor_flap,
10558 show_ip_bgp_neighbor_flap_cmd,
10559 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10560 SHOW_STR
10561 IP_STR
10562 BGP_STR
10563 "Detailed information on TCP and BGP neighbor connections\n"
10564 "Neighbor to display information about\n"
10565 "Neighbor to display information about\n"
10566 "Display flap statistics of the routes learned from neighbor\n")
10567{
paulbb46e942003-10-24 19:02:03 +000010568 struct peer *peer;
10569
10570 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10571 if (! peer)
10572 return CMD_WARNING;
10573
10574 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010575 bgp_show_type_flap_neighbor);
10576}
10577
10578DEFUN (show_ip_bgp_neighbor_damp,
10579 show_ip_bgp_neighbor_damp_cmd,
10580 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10581 SHOW_STR
10582 IP_STR
10583 BGP_STR
10584 "Detailed information on TCP and BGP neighbor connections\n"
10585 "Neighbor to display information about\n"
10586 "Neighbor to display information about\n"
10587 "Display the dampened routes received from neighbor\n")
10588{
paulbb46e942003-10-24 19:02:03 +000010589 struct peer *peer;
10590
10591 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10592 if (! peer)
10593 return CMD_WARNING;
10594
10595 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010596 bgp_show_type_damp_neighbor);
10597}
10598
10599DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10600 show_ip_bgp_ipv4_neighbor_routes_cmd,
10601 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10602 SHOW_STR
10603 IP_STR
10604 BGP_STR
10605 "Address family\n"
10606 "Address Family modifier\n"
10607 "Address Family modifier\n"
10608 "Detailed information on TCP and BGP neighbor connections\n"
10609 "Neighbor to display information about\n"
10610 "Neighbor to display information about\n"
10611 "Display routes learned from neighbor\n")
10612{
paulbb46e942003-10-24 19:02:03 +000010613 struct peer *peer;
10614
10615 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10616 if (! peer)
10617 return CMD_WARNING;
10618
paul718e3742002-12-13 20:15:29 +000010619 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010620 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010621 bgp_show_type_neighbor);
10622
paulbb46e942003-10-24 19:02:03 +000010623 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010624 bgp_show_type_neighbor);
10625}
paulbb46e942003-10-24 19:02:03 +000010626
paulfee0f4c2004-09-13 05:12:46 +000010627DEFUN (show_ip_bgp_view_rsclient,
10628 show_ip_bgp_view_rsclient_cmd,
10629 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10630 SHOW_STR
10631 IP_STR
10632 BGP_STR
10633 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010634 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010635 "Information about Route Server Client\n"
10636 NEIGHBOR_ADDR_STR)
10637{
10638 struct bgp_table *table;
10639 struct peer *peer;
10640
10641 if (argc == 2)
10642 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10643 else
10644 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10645
10646 if (! peer)
10647 return CMD_WARNING;
10648
10649 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10650 {
10651 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10652 VTY_NEWLINE);
10653 return CMD_WARNING;
10654 }
10655
10656 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10657 PEER_FLAG_RSERVER_CLIENT))
10658 {
10659 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10660 VTY_NEWLINE);
10661 return CMD_WARNING;
10662 }
10663
10664 table = peer->rib[AFI_IP][SAFI_UNICAST];
10665
ajs5a646652004-11-05 01:25:55 +000010666 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010667}
10668
10669ALIAS (show_ip_bgp_view_rsclient,
10670 show_ip_bgp_rsclient_cmd,
10671 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10672 SHOW_STR
10673 IP_STR
10674 BGP_STR
10675 "Information about Route Server Client\n"
10676 NEIGHBOR_ADDR_STR)
10677
Michael Lambert95cbbd22010-07-23 14:43:04 -040010678DEFUN (show_bgp_view_ipv4_safi_rsclient,
10679 show_bgp_view_ipv4_safi_rsclient_cmd,
10680 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10681 SHOW_STR
10682 BGP_STR
10683 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010684 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010685 "Address family\n"
10686 "Address Family modifier\n"
10687 "Address Family modifier\n"
10688 "Information about Route Server Client\n"
10689 NEIGHBOR_ADDR_STR)
10690{
10691 struct bgp_table *table;
10692 struct peer *peer;
10693 safi_t safi;
10694
10695 if (argc == 3) {
10696 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10697 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10698 } else {
10699 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10700 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10701 }
10702
10703 if (! peer)
10704 return CMD_WARNING;
10705
10706 if (! peer->afc[AFI_IP][safi])
10707 {
10708 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10709 VTY_NEWLINE);
10710 return CMD_WARNING;
10711 }
10712
10713 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10714 PEER_FLAG_RSERVER_CLIENT))
10715 {
10716 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10717 VTY_NEWLINE);
10718 return CMD_WARNING;
10719 }
10720
10721 table = peer->rib[AFI_IP][safi];
10722
10723 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10724}
10725
10726ALIAS (show_bgp_view_ipv4_safi_rsclient,
10727 show_bgp_ipv4_safi_rsclient_cmd,
10728 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10729 SHOW_STR
10730 BGP_STR
10731 "Address family\n"
10732 "Address Family modifier\n"
10733 "Address Family modifier\n"
10734 "Information about Route Server Client\n"
10735 NEIGHBOR_ADDR_STR)
10736
paulfee0f4c2004-09-13 05:12:46 +000010737DEFUN (show_ip_bgp_view_rsclient_route,
10738 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010739 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010740 SHOW_STR
10741 IP_STR
10742 BGP_STR
10743 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010744 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010745 "Information about Route Server Client\n"
10746 NEIGHBOR_ADDR_STR
10747 "Network in the BGP routing table to display\n")
10748{
10749 struct bgp *bgp;
10750 struct peer *peer;
10751
10752 /* BGP structure lookup. */
10753 if (argc == 3)
10754 {
10755 bgp = bgp_lookup_by_name (argv[0]);
10756 if (bgp == NULL)
10757 {
10758 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10759 return CMD_WARNING;
10760 }
10761 }
10762 else
10763 {
10764 bgp = bgp_get_default ();
10765 if (bgp == NULL)
10766 {
10767 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10768 return CMD_WARNING;
10769 }
10770 }
10771
10772 if (argc == 3)
10773 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10774 else
10775 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10776
10777 if (! peer)
10778 return CMD_WARNING;
10779
10780 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10781 {
10782 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10783 VTY_NEWLINE);
10784 return CMD_WARNING;
10785}
10786
10787 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10788 PEER_FLAG_RSERVER_CLIENT))
10789 {
10790 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10791 VTY_NEWLINE);
10792 return CMD_WARNING;
10793 }
10794
10795 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10796 (argc == 3) ? argv[2] : argv[1],
10797 AFI_IP, SAFI_UNICAST, NULL, 0);
10798}
10799
10800ALIAS (show_ip_bgp_view_rsclient_route,
10801 show_ip_bgp_rsclient_route_cmd,
10802 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10803 SHOW_STR
10804 IP_STR
10805 BGP_STR
10806 "Information about Route Server Client\n"
10807 NEIGHBOR_ADDR_STR
10808 "Network in the BGP routing table to display\n")
10809
Michael Lambert95cbbd22010-07-23 14:43:04 -040010810DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10811 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10812 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10813 SHOW_STR
10814 BGP_STR
10815 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010816 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010817 "Address family\n"
10818 "Address Family modifier\n"
10819 "Address Family modifier\n"
10820 "Information about Route Server Client\n"
10821 NEIGHBOR_ADDR_STR
10822 "Network in the BGP routing table to display\n")
10823{
10824 struct bgp *bgp;
10825 struct peer *peer;
10826 safi_t safi;
10827
10828 /* BGP structure lookup. */
10829 if (argc == 4)
10830 {
10831 bgp = bgp_lookup_by_name (argv[0]);
10832 if (bgp == NULL)
10833 {
10834 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10835 return CMD_WARNING;
10836 }
10837 }
10838 else
10839 {
10840 bgp = bgp_get_default ();
10841 if (bgp == NULL)
10842 {
10843 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10844 return CMD_WARNING;
10845 }
10846 }
10847
10848 if (argc == 4) {
10849 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10850 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10851 } else {
10852 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10853 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10854 }
10855
10856 if (! peer)
10857 return CMD_WARNING;
10858
10859 if (! peer->afc[AFI_IP][safi])
10860 {
10861 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10862 VTY_NEWLINE);
10863 return CMD_WARNING;
10864}
10865
10866 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10867 PEER_FLAG_RSERVER_CLIENT))
10868 {
10869 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10870 VTY_NEWLINE);
10871 return CMD_WARNING;
10872 }
10873
10874 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10875 (argc == 4) ? argv[3] : argv[2],
10876 AFI_IP, safi, NULL, 0);
10877}
10878
10879ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10880 show_bgp_ipv4_safi_rsclient_route_cmd,
10881 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10882 SHOW_STR
10883 BGP_STR
10884 "Address family\n"
10885 "Address Family modifier\n"
10886 "Address Family modifier\n"
10887 "Information about Route Server Client\n"
10888 NEIGHBOR_ADDR_STR
10889 "Network in the BGP routing table to display\n")
10890
paulfee0f4c2004-09-13 05:12:46 +000010891DEFUN (show_ip_bgp_view_rsclient_prefix,
10892 show_ip_bgp_view_rsclient_prefix_cmd,
10893 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10894 SHOW_STR
10895 IP_STR
10896 BGP_STR
10897 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010898 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010899 "Information about Route Server Client\n"
10900 NEIGHBOR_ADDR_STR
10901 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10902{
10903 struct bgp *bgp;
10904 struct peer *peer;
10905
10906 /* BGP structure lookup. */
10907 if (argc == 3)
10908 {
10909 bgp = bgp_lookup_by_name (argv[0]);
10910 if (bgp == NULL)
10911 {
10912 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10913 return CMD_WARNING;
10914 }
10915 }
10916 else
10917 {
10918 bgp = bgp_get_default ();
10919 if (bgp == NULL)
10920 {
10921 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10922 return CMD_WARNING;
10923 }
10924 }
10925
10926 if (argc == 3)
10927 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10928 else
10929 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10930
10931 if (! peer)
10932 return CMD_WARNING;
10933
10934 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10935 {
10936 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10937 VTY_NEWLINE);
10938 return CMD_WARNING;
10939}
10940
10941 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10942 PEER_FLAG_RSERVER_CLIENT))
10943{
10944 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10945 VTY_NEWLINE);
10946 return CMD_WARNING;
10947 }
10948
10949 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10950 (argc == 3) ? argv[2] : argv[1],
10951 AFI_IP, SAFI_UNICAST, NULL, 1);
10952}
10953
10954ALIAS (show_ip_bgp_view_rsclient_prefix,
10955 show_ip_bgp_rsclient_prefix_cmd,
10956 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10957 SHOW_STR
10958 IP_STR
10959 BGP_STR
10960 "Information about Route Server Client\n"
10961 NEIGHBOR_ADDR_STR
10962 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10963
Michael Lambert95cbbd22010-07-23 14:43:04 -040010964DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10965 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10966 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10967 SHOW_STR
10968 BGP_STR
10969 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010970 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010971 "Address family\n"
10972 "Address Family modifier\n"
10973 "Address Family modifier\n"
10974 "Information about Route Server Client\n"
10975 NEIGHBOR_ADDR_STR
10976 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10977{
10978 struct bgp *bgp;
10979 struct peer *peer;
10980 safi_t safi;
10981
10982 /* BGP structure lookup. */
10983 if (argc == 4)
10984 {
10985 bgp = bgp_lookup_by_name (argv[0]);
10986 if (bgp == NULL)
10987 {
10988 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10989 return CMD_WARNING;
10990 }
10991 }
10992 else
10993 {
10994 bgp = bgp_get_default ();
10995 if (bgp == NULL)
10996 {
10997 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10998 return CMD_WARNING;
10999 }
11000 }
11001
11002 if (argc == 4) {
11003 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11004 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11005 } else {
11006 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11007 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11008 }
11009
11010 if (! peer)
11011 return CMD_WARNING;
11012
11013 if (! peer->afc[AFI_IP][safi])
11014 {
11015 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11016 VTY_NEWLINE);
11017 return CMD_WARNING;
11018}
11019
11020 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11021 PEER_FLAG_RSERVER_CLIENT))
11022{
11023 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11024 VTY_NEWLINE);
11025 return CMD_WARNING;
11026 }
11027
11028 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11029 (argc == 4) ? argv[3] : argv[2],
11030 AFI_IP, safi, NULL, 1);
11031}
11032
11033ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11034 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11035 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11036 SHOW_STR
11037 BGP_STR
11038 "Address family\n"
11039 "Address Family modifier\n"
11040 "Address Family modifier\n"
11041 "Information about Route Server Client\n"
11042 NEIGHBOR_ADDR_STR
11043 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011044
paul718e3742002-12-13 20:15:29 +000011045#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011046DEFUN (show_bgp_view_neighbor_routes,
11047 show_bgp_view_neighbor_routes_cmd,
11048 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11049 SHOW_STR
11050 BGP_STR
11051 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011052 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011053 "Detailed information on TCP and BGP neighbor connections\n"
11054 "Neighbor to display information about\n"
11055 "Neighbor to display information about\n"
11056 "Display routes learned from neighbor\n")
11057{
11058 struct peer *peer;
11059
11060 if (argc == 2)
11061 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11062 else
11063 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11064
11065 if (! peer)
11066 return CMD_WARNING;
11067
11068 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11069 bgp_show_type_neighbor);
11070}
11071
11072ALIAS (show_bgp_view_neighbor_routes,
11073 show_bgp_view_ipv6_neighbor_routes_cmd,
11074 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11075 SHOW_STR
11076 BGP_STR
11077 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011078 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011079 "Address family\n"
11080 "Detailed information on TCP and BGP neighbor connections\n"
11081 "Neighbor to display information about\n"
11082 "Neighbor to display information about\n"
11083 "Display routes learned from neighbor\n")
11084
11085DEFUN (show_bgp_view_neighbor_damp,
11086 show_bgp_view_neighbor_damp_cmd,
11087 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11088 SHOW_STR
11089 BGP_STR
11090 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011091 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011092 "Detailed information on TCP and BGP neighbor connections\n"
11093 "Neighbor to display information about\n"
11094 "Neighbor to display information about\n"
11095 "Display the dampened routes received from neighbor\n")
11096{
11097 struct peer *peer;
11098
11099 if (argc == 2)
11100 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11101 else
11102 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11103
11104 if (! peer)
11105 return CMD_WARNING;
11106
11107 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11108 bgp_show_type_damp_neighbor);
11109}
11110
11111ALIAS (show_bgp_view_neighbor_damp,
11112 show_bgp_view_ipv6_neighbor_damp_cmd,
11113 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11114 SHOW_STR
11115 BGP_STR
11116 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011117 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011118 "Address family\n"
11119 "Detailed information on TCP and BGP neighbor connections\n"
11120 "Neighbor to display information about\n"
11121 "Neighbor to display information about\n"
11122 "Display the dampened routes received from neighbor\n")
11123
11124DEFUN (show_bgp_view_neighbor_flap,
11125 show_bgp_view_neighbor_flap_cmd,
11126 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11127 SHOW_STR
11128 BGP_STR
11129 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011130 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011131 "Detailed information on TCP and BGP neighbor connections\n"
11132 "Neighbor to display information about\n"
11133 "Neighbor to display information about\n"
11134 "Display flap statistics of the routes learned from neighbor\n")
11135{
11136 struct peer *peer;
11137
11138 if (argc == 2)
11139 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11140 else
11141 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11142
11143 if (! peer)
11144 return CMD_WARNING;
11145
11146 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11147 bgp_show_type_flap_neighbor);
11148}
11149
11150ALIAS (show_bgp_view_neighbor_flap,
11151 show_bgp_view_ipv6_neighbor_flap_cmd,
11152 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11153 SHOW_STR
11154 BGP_STR
11155 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011156 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011157 "Address family\n"
11158 "Detailed information on TCP and BGP neighbor connections\n"
11159 "Neighbor to display information about\n"
11160 "Neighbor to display information about\n"
11161 "Display flap statistics of the routes learned from neighbor\n")
11162
11163ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011164 show_bgp_neighbor_routes_cmd,
11165 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11166 SHOW_STR
11167 BGP_STR
11168 "Detailed information on TCP and BGP neighbor connections\n"
11169 "Neighbor to display information about\n"
11170 "Neighbor to display information about\n"
11171 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011172
paulbb46e942003-10-24 19:02:03 +000011173
11174ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011175 show_bgp_ipv6_neighbor_routes_cmd,
11176 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11177 SHOW_STR
11178 BGP_STR
11179 "Address family\n"
11180 "Detailed information on TCP and BGP neighbor connections\n"
11181 "Neighbor to display information about\n"
11182 "Neighbor to display information about\n"
11183 "Display routes learned from neighbor\n")
11184
11185/* old command */
paulbb46e942003-10-24 19:02:03 +000011186ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011187 ipv6_bgp_neighbor_routes_cmd,
11188 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11189 SHOW_STR
11190 IPV6_STR
11191 BGP_STR
11192 "Detailed information on TCP and BGP neighbor connections\n"
11193 "Neighbor to display information about\n"
11194 "Neighbor to display information about\n"
11195 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011196
11197/* old command */
11198DEFUN (ipv6_mbgp_neighbor_routes,
11199 ipv6_mbgp_neighbor_routes_cmd,
11200 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11201 SHOW_STR
11202 IPV6_STR
11203 MBGP_STR
11204 "Detailed information on TCP and BGP neighbor connections\n"
11205 "Neighbor to display information about\n"
11206 "Neighbor to display information about\n"
11207 "Display routes learned from neighbor\n")
11208{
paulbb46e942003-10-24 19:02:03 +000011209 struct peer *peer;
11210
11211 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11212 if (! peer)
11213 return CMD_WARNING;
11214
11215 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011216 bgp_show_type_neighbor);
11217}
paulbb46e942003-10-24 19:02:03 +000011218
11219ALIAS (show_bgp_view_neighbor_flap,
11220 show_bgp_neighbor_flap_cmd,
11221 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11222 SHOW_STR
11223 BGP_STR
11224 "Detailed information on TCP and BGP neighbor connections\n"
11225 "Neighbor to display information about\n"
11226 "Neighbor to display information about\n"
11227 "Display flap statistics of the routes learned from neighbor\n")
11228
11229ALIAS (show_bgp_view_neighbor_flap,
11230 show_bgp_ipv6_neighbor_flap_cmd,
11231 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11232 SHOW_STR
11233 BGP_STR
11234 "Address family\n"
11235 "Detailed information on TCP and BGP neighbor connections\n"
11236 "Neighbor to display information about\n"
11237 "Neighbor to display information about\n"
11238 "Display flap statistics of the routes learned from neighbor\n")
11239
11240ALIAS (show_bgp_view_neighbor_damp,
11241 show_bgp_neighbor_damp_cmd,
11242 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11243 SHOW_STR
11244 BGP_STR
11245 "Detailed information on TCP and BGP neighbor connections\n"
11246 "Neighbor to display information about\n"
11247 "Neighbor to display information about\n"
11248 "Display the dampened routes received from neighbor\n")
11249
11250ALIAS (show_bgp_view_neighbor_damp,
11251 show_bgp_ipv6_neighbor_damp_cmd,
11252 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11253 SHOW_STR
11254 BGP_STR
11255 "Address family\n"
11256 "Detailed information on TCP and BGP neighbor connections\n"
11257 "Neighbor to display information about\n"
11258 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011259 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011260
11261DEFUN (show_bgp_view_rsclient,
11262 show_bgp_view_rsclient_cmd,
11263 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11264 SHOW_STR
11265 BGP_STR
11266 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011267 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011268 "Information about Route Server Client\n"
11269 NEIGHBOR_ADDR_STR)
11270{
11271 struct bgp_table *table;
11272 struct peer *peer;
11273
11274 if (argc == 2)
11275 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11276 else
11277 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11278
11279 if (! peer)
11280 return CMD_WARNING;
11281
11282 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11283 {
11284 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11285 VTY_NEWLINE);
11286 return CMD_WARNING;
11287 }
11288
11289 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11290 PEER_FLAG_RSERVER_CLIENT))
11291 {
11292 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11293 VTY_NEWLINE);
11294 return CMD_WARNING;
11295 }
11296
11297 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11298
ajs5a646652004-11-05 01:25:55 +000011299 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011300}
11301
11302ALIAS (show_bgp_view_rsclient,
11303 show_bgp_rsclient_cmd,
11304 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11305 SHOW_STR
11306 BGP_STR
11307 "Information about Route Server Client\n"
11308 NEIGHBOR_ADDR_STR)
11309
Michael Lambert95cbbd22010-07-23 14:43:04 -040011310DEFUN (show_bgp_view_ipv6_safi_rsclient,
11311 show_bgp_view_ipv6_safi_rsclient_cmd,
11312 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11313 SHOW_STR
11314 BGP_STR
11315 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011316 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011317 "Address family\n"
11318 "Address Family modifier\n"
11319 "Address Family modifier\n"
11320 "Information about Route Server Client\n"
11321 NEIGHBOR_ADDR_STR)
11322{
11323 struct bgp_table *table;
11324 struct peer *peer;
11325 safi_t safi;
11326
11327 if (argc == 3) {
11328 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11329 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11330 } else {
11331 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11332 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11333 }
11334
11335 if (! peer)
11336 return CMD_WARNING;
11337
11338 if (! peer->afc[AFI_IP6][safi])
11339 {
11340 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11341 VTY_NEWLINE);
11342 return CMD_WARNING;
11343 }
11344
11345 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11346 PEER_FLAG_RSERVER_CLIENT))
11347 {
11348 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11349 VTY_NEWLINE);
11350 return CMD_WARNING;
11351 }
11352
11353 table = peer->rib[AFI_IP6][safi];
11354
11355 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11356}
11357
11358ALIAS (show_bgp_view_ipv6_safi_rsclient,
11359 show_bgp_ipv6_safi_rsclient_cmd,
11360 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11361 SHOW_STR
11362 BGP_STR
11363 "Address family\n"
11364 "Address Family modifier\n"
11365 "Address Family modifier\n"
11366 "Information about Route Server Client\n"
11367 NEIGHBOR_ADDR_STR)
11368
paulfee0f4c2004-09-13 05:12:46 +000011369DEFUN (show_bgp_view_rsclient_route,
11370 show_bgp_view_rsclient_route_cmd,
11371 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11372 SHOW_STR
11373 BGP_STR
11374 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011375 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011376 "Information about Route Server Client\n"
11377 NEIGHBOR_ADDR_STR
11378 "Network in the BGP routing table to display\n")
11379{
11380 struct bgp *bgp;
11381 struct peer *peer;
11382
11383 /* BGP structure lookup. */
11384 if (argc == 3)
11385 {
11386 bgp = bgp_lookup_by_name (argv[0]);
11387 if (bgp == NULL)
11388 {
11389 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11390 return CMD_WARNING;
11391 }
11392 }
11393 else
11394 {
11395 bgp = bgp_get_default ();
11396 if (bgp == NULL)
11397 {
11398 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11399 return CMD_WARNING;
11400 }
11401 }
11402
11403 if (argc == 3)
11404 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11405 else
11406 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11407
11408 if (! peer)
11409 return CMD_WARNING;
11410
11411 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11412 {
11413 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11414 VTY_NEWLINE);
11415 return CMD_WARNING;
11416 }
11417
11418 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11419 PEER_FLAG_RSERVER_CLIENT))
11420 {
11421 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11422 VTY_NEWLINE);
11423 return CMD_WARNING;
11424 }
11425
11426 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11427 (argc == 3) ? argv[2] : argv[1],
11428 AFI_IP6, SAFI_UNICAST, NULL, 0);
11429}
11430
11431ALIAS (show_bgp_view_rsclient_route,
11432 show_bgp_rsclient_route_cmd,
11433 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11434 SHOW_STR
11435 BGP_STR
11436 "Information about Route Server Client\n"
11437 NEIGHBOR_ADDR_STR
11438 "Network in the BGP routing table to display\n")
11439
Michael Lambert95cbbd22010-07-23 14:43:04 -040011440DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11441 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11442 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11443 SHOW_STR
11444 BGP_STR
11445 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011446 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011447 "Address family\n"
11448 "Address Family modifier\n"
11449 "Address Family modifier\n"
11450 "Information about Route Server Client\n"
11451 NEIGHBOR_ADDR_STR
11452 "Network in the BGP routing table to display\n")
11453{
11454 struct bgp *bgp;
11455 struct peer *peer;
11456 safi_t safi;
11457
11458 /* BGP structure lookup. */
11459 if (argc == 4)
11460 {
11461 bgp = bgp_lookup_by_name (argv[0]);
11462 if (bgp == NULL)
11463 {
11464 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11465 return CMD_WARNING;
11466 }
11467 }
11468 else
11469 {
11470 bgp = bgp_get_default ();
11471 if (bgp == NULL)
11472 {
11473 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11474 return CMD_WARNING;
11475 }
11476 }
11477
11478 if (argc == 4) {
11479 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11480 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11481 } else {
11482 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11483 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11484 }
11485
11486 if (! peer)
11487 return CMD_WARNING;
11488
11489 if (! peer->afc[AFI_IP6][safi])
11490 {
11491 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11492 VTY_NEWLINE);
11493 return CMD_WARNING;
11494}
11495
11496 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11497 PEER_FLAG_RSERVER_CLIENT))
11498 {
11499 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11500 VTY_NEWLINE);
11501 return CMD_WARNING;
11502 }
11503
11504 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11505 (argc == 4) ? argv[3] : argv[2],
11506 AFI_IP6, safi, NULL, 0);
11507}
11508
11509ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11510 show_bgp_ipv6_safi_rsclient_route_cmd,
11511 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11512 SHOW_STR
11513 BGP_STR
11514 "Address family\n"
11515 "Address Family modifier\n"
11516 "Address Family modifier\n"
11517 "Information about Route Server Client\n"
11518 NEIGHBOR_ADDR_STR
11519 "Network in the BGP routing table to display\n")
11520
paulfee0f4c2004-09-13 05:12:46 +000011521DEFUN (show_bgp_view_rsclient_prefix,
11522 show_bgp_view_rsclient_prefix_cmd,
11523 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11524 SHOW_STR
11525 BGP_STR
11526 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011527 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011528 "Information about Route Server Client\n"
11529 NEIGHBOR_ADDR_STR
11530 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11531{
11532 struct bgp *bgp;
11533 struct peer *peer;
11534
11535 /* BGP structure lookup. */
11536 if (argc == 3)
11537 {
11538 bgp = bgp_lookup_by_name (argv[0]);
11539 if (bgp == NULL)
11540 {
11541 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11542 return CMD_WARNING;
11543 }
11544 }
11545 else
11546 {
11547 bgp = bgp_get_default ();
11548 if (bgp == NULL)
11549 {
11550 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11551 return CMD_WARNING;
11552 }
11553 }
11554
11555 if (argc == 3)
11556 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11557 else
11558 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11559
11560 if (! peer)
11561 return CMD_WARNING;
11562
11563 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11564 {
11565 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11566 VTY_NEWLINE);
11567 return CMD_WARNING;
11568 }
11569
11570 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11571 PEER_FLAG_RSERVER_CLIENT))
11572 {
11573 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11574 VTY_NEWLINE);
11575 return CMD_WARNING;
11576 }
11577
11578 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11579 (argc == 3) ? argv[2] : argv[1],
11580 AFI_IP6, SAFI_UNICAST, NULL, 1);
11581}
11582
11583ALIAS (show_bgp_view_rsclient_prefix,
11584 show_bgp_rsclient_prefix_cmd,
11585 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11586 SHOW_STR
11587 BGP_STR
11588 "Information about Route Server Client\n"
11589 NEIGHBOR_ADDR_STR
11590 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11591
Michael Lambert95cbbd22010-07-23 14:43:04 -040011592DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11593 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11594 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11595 SHOW_STR
11596 BGP_STR
11597 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011598 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011599 "Address family\n"
11600 "Address Family modifier\n"
11601 "Address Family modifier\n"
11602 "Information about Route Server Client\n"
11603 NEIGHBOR_ADDR_STR
11604 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11605{
11606 struct bgp *bgp;
11607 struct peer *peer;
11608 safi_t safi;
11609
11610 /* BGP structure lookup. */
11611 if (argc == 4)
11612 {
11613 bgp = bgp_lookup_by_name (argv[0]);
11614 if (bgp == NULL)
11615 {
11616 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11617 return CMD_WARNING;
11618 }
11619 }
11620 else
11621 {
11622 bgp = bgp_get_default ();
11623 if (bgp == NULL)
11624 {
11625 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11626 return CMD_WARNING;
11627 }
11628 }
11629
11630 if (argc == 4) {
11631 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11632 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11633 } else {
11634 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11635 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11636 }
11637
11638 if (! peer)
11639 return CMD_WARNING;
11640
11641 if (! peer->afc[AFI_IP6][safi])
11642 {
11643 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11644 VTY_NEWLINE);
11645 return CMD_WARNING;
11646}
11647
11648 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11649 PEER_FLAG_RSERVER_CLIENT))
11650{
11651 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11652 VTY_NEWLINE);
11653 return CMD_WARNING;
11654 }
11655
11656 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11657 (argc == 4) ? argv[3] : argv[2],
11658 AFI_IP6, safi, NULL, 1);
11659}
11660
11661ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11662 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11663 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11664 SHOW_STR
11665 BGP_STR
11666 "Address family\n"
11667 "Address Family modifier\n"
11668 "Address Family modifier\n"
11669 "Information about Route Server Client\n"
11670 NEIGHBOR_ADDR_STR
11671 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11672
paul718e3742002-12-13 20:15:29 +000011673#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020011674
paul718e3742002-12-13 20:15:29 +000011675struct bgp_table *bgp_distance_table;
11676
11677struct bgp_distance
11678{
11679 /* Distance value for the IP source prefix. */
11680 u_char distance;
11681
11682 /* Name of the access-list to be matched. */
11683 char *access_list;
11684};
11685
paul94f2b392005-06-28 12:44:16 +000011686static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011687bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011688{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011689 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011690}
11691
paul94f2b392005-06-28 12:44:16 +000011692static void
paul718e3742002-12-13 20:15:29 +000011693bgp_distance_free (struct bgp_distance *bdistance)
11694{
11695 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11696}
11697
paul94f2b392005-06-28 12:44:16 +000011698static int
paulfd79ac92004-10-13 05:06:08 +000011699bgp_distance_set (struct vty *vty, const char *distance_str,
11700 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011701{
11702 int ret;
11703 struct prefix_ipv4 p;
11704 u_char distance;
11705 struct bgp_node *rn;
11706 struct bgp_distance *bdistance;
11707
11708 ret = str2prefix_ipv4 (ip_str, &p);
11709 if (ret == 0)
11710 {
11711 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11712 return CMD_WARNING;
11713 }
11714
11715 distance = atoi (distance_str);
11716
11717 /* Get BGP distance node. */
11718 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11719 if (rn->info)
11720 {
11721 bdistance = rn->info;
11722 bgp_unlock_node (rn);
11723 }
11724 else
11725 {
11726 bdistance = bgp_distance_new ();
11727 rn->info = bdistance;
11728 }
11729
11730 /* Set distance value. */
11731 bdistance->distance = distance;
11732
11733 /* Reset access-list configuration. */
11734 if (bdistance->access_list)
11735 {
11736 free (bdistance->access_list);
11737 bdistance->access_list = NULL;
11738 }
11739 if (access_list_str)
11740 bdistance->access_list = strdup (access_list_str);
11741
11742 return CMD_SUCCESS;
11743}
11744
paul94f2b392005-06-28 12:44:16 +000011745static int
paulfd79ac92004-10-13 05:06:08 +000011746bgp_distance_unset (struct vty *vty, const char *distance_str,
11747 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011748{
11749 int ret;
11750 struct prefix_ipv4 p;
11751 u_char distance;
11752 struct bgp_node *rn;
11753 struct bgp_distance *bdistance;
11754
11755 ret = str2prefix_ipv4 (ip_str, &p);
11756 if (ret == 0)
11757 {
11758 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11759 return CMD_WARNING;
11760 }
11761
11762 distance = atoi (distance_str);
11763
11764 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11765 if (! rn)
11766 {
11767 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11768 return CMD_WARNING;
11769 }
11770
11771 bdistance = rn->info;
11772
11773 if (bdistance->access_list)
11774 free (bdistance->access_list);
11775 bgp_distance_free (bdistance);
11776
11777 rn->info = NULL;
11778 bgp_unlock_node (rn);
11779 bgp_unlock_node (rn);
11780
11781 return CMD_SUCCESS;
11782}
11783
paul718e3742002-12-13 20:15:29 +000011784/* Apply BGP information to distance method. */
11785u_char
11786bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11787{
11788 struct bgp_node *rn;
11789 struct prefix_ipv4 q;
11790 struct peer *peer;
11791 struct bgp_distance *bdistance;
11792 struct access_list *alist;
11793 struct bgp_static *bgp_static;
11794
11795 if (! bgp)
11796 return 0;
11797
11798 if (p->family != AF_INET)
11799 return 0;
11800
11801 peer = rinfo->peer;
11802
11803 if (peer->su.sa.sa_family != AF_INET)
11804 return 0;
11805
11806 memset (&q, 0, sizeof (struct prefix_ipv4));
11807 q.family = AF_INET;
11808 q.prefix = peer->su.sin.sin_addr;
11809 q.prefixlen = IPV4_MAX_BITLEN;
11810
11811 /* Check source address. */
11812 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11813 if (rn)
11814 {
11815 bdistance = rn->info;
11816 bgp_unlock_node (rn);
11817
11818 if (bdistance->access_list)
11819 {
11820 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11821 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11822 return bdistance->distance;
11823 }
11824 else
11825 return bdistance->distance;
11826 }
11827
11828 /* Backdoor check. */
11829 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11830 if (rn)
11831 {
11832 bgp_static = rn->info;
11833 bgp_unlock_node (rn);
11834
11835 if (bgp_static->backdoor)
11836 {
11837 if (bgp->distance_local)
11838 return bgp->distance_local;
11839 else
11840 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11841 }
11842 }
11843
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011844 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011845 {
11846 if (bgp->distance_ebgp)
11847 return bgp->distance_ebgp;
11848 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11849 }
11850 else
11851 {
11852 if (bgp->distance_ibgp)
11853 return bgp->distance_ibgp;
11854 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11855 }
11856}
11857
11858DEFUN (bgp_distance,
11859 bgp_distance_cmd,
11860 "distance bgp <1-255> <1-255> <1-255>",
11861 "Define an administrative distance\n"
11862 "BGP distance\n"
11863 "Distance for routes external to the AS\n"
11864 "Distance for routes internal to the AS\n"
11865 "Distance for local routes\n")
11866{
11867 struct bgp *bgp;
11868
11869 bgp = vty->index;
11870
11871 bgp->distance_ebgp = atoi (argv[0]);
11872 bgp->distance_ibgp = atoi (argv[1]);
11873 bgp->distance_local = atoi (argv[2]);
11874 return CMD_SUCCESS;
11875}
11876
11877DEFUN (no_bgp_distance,
11878 no_bgp_distance_cmd,
11879 "no distance bgp <1-255> <1-255> <1-255>",
11880 NO_STR
11881 "Define an administrative distance\n"
11882 "BGP distance\n"
11883 "Distance for routes external to the AS\n"
11884 "Distance for routes internal to the AS\n"
11885 "Distance for local routes\n")
11886{
11887 struct bgp *bgp;
11888
11889 bgp = vty->index;
11890
11891 bgp->distance_ebgp= 0;
11892 bgp->distance_ibgp = 0;
11893 bgp->distance_local = 0;
11894 return CMD_SUCCESS;
11895}
11896
11897ALIAS (no_bgp_distance,
11898 no_bgp_distance2_cmd,
11899 "no distance bgp",
11900 NO_STR
11901 "Define an administrative distance\n"
11902 "BGP distance\n")
11903
11904DEFUN (bgp_distance_source,
11905 bgp_distance_source_cmd,
11906 "distance <1-255> A.B.C.D/M",
11907 "Define an administrative distance\n"
11908 "Administrative distance\n"
11909 "IP source prefix\n")
11910{
11911 bgp_distance_set (vty, argv[0], argv[1], NULL);
11912 return CMD_SUCCESS;
11913}
11914
11915DEFUN (no_bgp_distance_source,
11916 no_bgp_distance_source_cmd,
11917 "no distance <1-255> A.B.C.D/M",
11918 NO_STR
11919 "Define an administrative distance\n"
11920 "Administrative distance\n"
11921 "IP source prefix\n")
11922{
11923 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11924 return CMD_SUCCESS;
11925}
11926
11927DEFUN (bgp_distance_source_access_list,
11928 bgp_distance_source_access_list_cmd,
11929 "distance <1-255> A.B.C.D/M WORD",
11930 "Define an administrative distance\n"
11931 "Administrative distance\n"
11932 "IP source prefix\n"
11933 "Access list name\n")
11934{
11935 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11936 return CMD_SUCCESS;
11937}
11938
11939DEFUN (no_bgp_distance_source_access_list,
11940 no_bgp_distance_source_access_list_cmd,
11941 "no distance <1-255> A.B.C.D/M WORD",
11942 NO_STR
11943 "Define an administrative distance\n"
11944 "Administrative distance\n"
11945 "IP source prefix\n"
11946 "Access list name\n")
11947{
11948 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11949 return CMD_SUCCESS;
11950}
David Lamparter6b0655a2014-06-04 06:53:35 +020011951
paul718e3742002-12-13 20:15:29 +000011952DEFUN (bgp_damp_set,
11953 bgp_damp_set_cmd,
11954 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11955 "BGP Specific commands\n"
11956 "Enable route-flap dampening\n"
11957 "Half-life time for the penalty\n"
11958 "Value to start reusing a route\n"
11959 "Value to start suppressing a route\n"
11960 "Maximum duration to suppress a stable route\n")
11961{
11962 struct bgp *bgp;
11963 int half = DEFAULT_HALF_LIFE * 60;
11964 int reuse = DEFAULT_REUSE;
11965 int suppress = DEFAULT_SUPPRESS;
11966 int max = 4 * half;
11967
11968 if (argc == 4)
11969 {
11970 half = atoi (argv[0]) * 60;
11971 reuse = atoi (argv[1]);
11972 suppress = atoi (argv[2]);
11973 max = atoi (argv[3]) * 60;
11974 }
11975 else if (argc == 1)
11976 {
11977 half = atoi (argv[0]) * 60;
11978 max = 4 * half;
11979 }
11980
11981 bgp = vty->index;
11982 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11983 half, reuse, suppress, max);
11984}
11985
11986ALIAS (bgp_damp_set,
11987 bgp_damp_set2_cmd,
11988 "bgp dampening <1-45>",
11989 "BGP Specific commands\n"
11990 "Enable route-flap dampening\n"
11991 "Half-life time for the penalty\n")
11992
11993ALIAS (bgp_damp_set,
11994 bgp_damp_set3_cmd,
11995 "bgp dampening",
11996 "BGP Specific commands\n"
11997 "Enable route-flap dampening\n")
11998
11999DEFUN (bgp_damp_unset,
12000 bgp_damp_unset_cmd,
12001 "no bgp dampening",
12002 NO_STR
12003 "BGP Specific commands\n"
12004 "Enable route-flap dampening\n")
12005{
12006 struct bgp *bgp;
12007
12008 bgp = vty->index;
12009 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
12010}
12011
12012ALIAS (bgp_damp_unset,
12013 bgp_damp_unset2_cmd,
12014 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12015 NO_STR
12016 "BGP Specific commands\n"
12017 "Enable route-flap dampening\n"
12018 "Half-life time for the penalty\n"
12019 "Value to start reusing a route\n"
12020 "Value to start suppressing a route\n"
12021 "Maximum duration to suppress a stable route\n")
12022
12023DEFUN (show_ip_bgp_dampened_paths,
12024 show_ip_bgp_dampened_paths_cmd,
12025 "show ip bgp dampened-paths",
12026 SHOW_STR
12027 IP_STR
12028 BGP_STR
12029 "Display paths suppressed due to dampening\n")
12030{
ajs5a646652004-11-05 01:25:55 +000012031 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
12032 NULL);
paul718e3742002-12-13 20:15:29 +000012033}
12034
12035DEFUN (show_ip_bgp_flap_statistics,
12036 show_ip_bgp_flap_statistics_cmd,
12037 "show ip bgp flap-statistics",
12038 SHOW_STR
12039 IP_STR
12040 BGP_STR
12041 "Display flap statistics of routes\n")
12042{
ajs5a646652004-11-05 01:25:55 +000012043 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12044 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012045}
David Lamparter6b0655a2014-06-04 06:53:35 +020012046
paul718e3742002-12-13 20:15:29 +000012047/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012048static int
paulfd79ac92004-10-13 05:06:08 +000012049bgp_clear_damp_route (struct vty *vty, const char *view_name,
12050 const char *ip_str, afi_t afi, safi_t safi,
12051 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012052{
12053 int ret;
12054 struct prefix match;
12055 struct bgp_node *rn;
12056 struct bgp_node *rm;
12057 struct bgp_info *ri;
12058 struct bgp_info *ri_temp;
12059 struct bgp *bgp;
12060 struct bgp_table *table;
12061
12062 /* BGP structure lookup. */
12063 if (view_name)
12064 {
12065 bgp = bgp_lookup_by_name (view_name);
12066 if (bgp == NULL)
12067 {
12068 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12069 return CMD_WARNING;
12070 }
12071 }
12072 else
12073 {
12074 bgp = bgp_get_default ();
12075 if (bgp == NULL)
12076 {
12077 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12078 return CMD_WARNING;
12079 }
12080 }
12081
12082 /* Check IP address argument. */
12083 ret = str2prefix (ip_str, &match);
12084 if (! ret)
12085 {
12086 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12087 return CMD_WARNING;
12088 }
12089
12090 match.family = afi2family (afi);
12091
12092 if (safi == SAFI_MPLS_VPN)
12093 {
12094 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12095 {
12096 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12097 continue;
12098
12099 if ((table = rn->info) != NULL)
12100 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012101 {
12102 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12103 {
12104 ri = rm->info;
12105 while (ri)
12106 {
12107 if (ri->extra && ri->extra->damp_info)
12108 {
12109 ri_temp = ri->next;
12110 bgp_damp_info_free (ri->extra->damp_info, 1);
12111 ri = ri_temp;
12112 }
12113 else
12114 ri = ri->next;
12115 }
12116 }
12117
12118 bgp_unlock_node (rm);
12119 }
paul718e3742002-12-13 20:15:29 +000012120 }
12121 }
12122 else
12123 {
12124 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012125 {
12126 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12127 {
12128 ri = rn->info;
12129 while (ri)
12130 {
12131 if (ri->extra && ri->extra->damp_info)
12132 {
12133 ri_temp = ri->next;
12134 bgp_damp_info_free (ri->extra->damp_info, 1);
12135 ri = ri_temp;
12136 }
12137 else
12138 ri = ri->next;
12139 }
12140 }
12141
12142 bgp_unlock_node (rn);
12143 }
paul718e3742002-12-13 20:15:29 +000012144 }
12145
12146 return CMD_SUCCESS;
12147}
12148
12149DEFUN (clear_ip_bgp_dampening,
12150 clear_ip_bgp_dampening_cmd,
12151 "clear ip bgp dampening",
12152 CLEAR_STR
12153 IP_STR
12154 BGP_STR
12155 "Clear route flap dampening information\n")
12156{
12157 bgp_damp_info_clean ();
12158 return CMD_SUCCESS;
12159}
12160
12161DEFUN (clear_ip_bgp_dampening_prefix,
12162 clear_ip_bgp_dampening_prefix_cmd,
12163 "clear ip bgp dampening A.B.C.D/M",
12164 CLEAR_STR
12165 IP_STR
12166 BGP_STR
12167 "Clear route flap dampening information\n"
12168 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12169{
12170 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12171 SAFI_UNICAST, NULL, 1);
12172}
12173
12174DEFUN (clear_ip_bgp_dampening_address,
12175 clear_ip_bgp_dampening_address_cmd,
12176 "clear ip bgp dampening A.B.C.D",
12177 CLEAR_STR
12178 IP_STR
12179 BGP_STR
12180 "Clear route flap dampening information\n"
12181 "Network to clear damping information\n")
12182{
12183 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12184 SAFI_UNICAST, NULL, 0);
12185}
12186
12187DEFUN (clear_ip_bgp_dampening_address_mask,
12188 clear_ip_bgp_dampening_address_mask_cmd,
12189 "clear ip bgp dampening A.B.C.D A.B.C.D",
12190 CLEAR_STR
12191 IP_STR
12192 BGP_STR
12193 "Clear route flap dampening information\n"
12194 "Network to clear damping information\n"
12195 "Network mask\n")
12196{
12197 int ret;
12198 char prefix_str[BUFSIZ];
12199
12200 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12201 if (! ret)
12202 {
12203 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12204 return CMD_WARNING;
12205 }
12206
12207 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12208 SAFI_UNICAST, NULL, 0);
12209}
David Lamparter6b0655a2014-06-04 06:53:35 +020012210
paul94f2b392005-06-28 12:44:16 +000012211static int
paul718e3742002-12-13 20:15:29 +000012212bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12213 afi_t afi, safi_t safi, int *write)
12214{
12215 struct bgp_node *prn;
12216 struct bgp_node *rn;
12217 struct bgp_table *table;
12218 struct prefix *p;
12219 struct prefix_rd *prd;
12220 struct bgp_static *bgp_static;
12221 u_int32_t label;
12222 char buf[SU_ADDRSTRLEN];
12223 char rdbuf[RD_ADDRSTRLEN];
12224
12225 /* Network configuration. */
12226 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12227 if ((table = prn->info) != NULL)
12228 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12229 if ((bgp_static = rn->info) != NULL)
12230 {
12231 p = &rn->p;
12232 prd = (struct prefix_rd *) &prn->p;
12233
12234 /* "address-family" display. */
12235 bgp_config_write_family_header (vty, afi, safi, write);
12236
12237 /* "network" configuration display. */
12238 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12239 label = decode_label (bgp_static->tag);
12240
12241 vty_out (vty, " network %s/%d rd %s tag %d",
12242 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12243 p->prefixlen,
12244 rdbuf, label);
12245 vty_out (vty, "%s", VTY_NEWLINE);
12246 }
12247 return 0;
12248}
12249
12250/* Configuration of static route announcement and aggregate
12251 information. */
12252int
12253bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12254 afi_t afi, safi_t safi, int *write)
12255{
12256 struct bgp_node *rn;
12257 struct prefix *p;
12258 struct bgp_static *bgp_static;
12259 struct bgp_aggregate *bgp_aggregate;
12260 char buf[SU_ADDRSTRLEN];
12261
12262 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12263 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12264
12265 /* Network configuration. */
12266 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12267 if ((bgp_static = rn->info) != NULL)
12268 {
12269 p = &rn->p;
12270
12271 /* "address-family" display. */
12272 bgp_config_write_family_header (vty, afi, safi, write);
12273
12274 /* "network" configuration display. */
12275 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12276 {
12277 u_int32_t destination;
12278 struct in_addr netmask;
12279
12280 destination = ntohl (p->u.prefix4.s_addr);
12281 masklen2ip (p->prefixlen, &netmask);
12282 vty_out (vty, " network %s",
12283 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12284
12285 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12286 || (IN_CLASSB (destination) && p->prefixlen == 16)
12287 || (IN_CLASSA (destination) && p->prefixlen == 8)
12288 || p->u.prefix4.s_addr == 0)
12289 {
12290 /* Natural mask is not display. */
12291 }
12292 else
12293 vty_out (vty, " mask %s", inet_ntoa (netmask));
12294 }
12295 else
12296 {
12297 vty_out (vty, " network %s/%d",
12298 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12299 p->prefixlen);
12300 }
12301
12302 if (bgp_static->rmap.name)
12303 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012304 else
12305 {
12306 if (bgp_static->backdoor)
12307 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012308 }
paul718e3742002-12-13 20:15:29 +000012309
12310 vty_out (vty, "%s", VTY_NEWLINE);
12311 }
12312
12313 /* Aggregate-address configuration. */
12314 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12315 if ((bgp_aggregate = rn->info) != NULL)
12316 {
12317 p = &rn->p;
12318
12319 /* "address-family" display. */
12320 bgp_config_write_family_header (vty, afi, safi, write);
12321
12322 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12323 {
12324 struct in_addr netmask;
12325
12326 masklen2ip (p->prefixlen, &netmask);
12327 vty_out (vty, " aggregate-address %s %s",
12328 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12329 inet_ntoa (netmask));
12330 }
12331 else
12332 {
12333 vty_out (vty, " aggregate-address %s/%d",
12334 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12335 p->prefixlen);
12336 }
12337
12338 if (bgp_aggregate->as_set)
12339 vty_out (vty, " as-set");
12340
12341 if (bgp_aggregate->summary_only)
12342 vty_out (vty, " summary-only");
12343
12344 vty_out (vty, "%s", VTY_NEWLINE);
12345 }
12346
12347 return 0;
12348}
12349
12350int
12351bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12352{
12353 struct bgp_node *rn;
12354 struct bgp_distance *bdistance;
12355
12356 /* Distance configuration. */
12357 if (bgp->distance_ebgp
12358 && bgp->distance_ibgp
12359 && bgp->distance_local
12360 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12361 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12362 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12363 vty_out (vty, " distance bgp %d %d %d%s",
12364 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12365 VTY_NEWLINE);
12366
12367 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12368 if ((bdistance = rn->info) != NULL)
12369 {
12370 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12371 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12372 bdistance->access_list ? bdistance->access_list : "",
12373 VTY_NEWLINE);
12374 }
12375
12376 return 0;
12377}
12378
12379/* Allocate routing table structure and install commands. */
12380void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012381bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012382{
12383 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012384 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012385
12386 /* IPv4 BGP commands. */
12387 install_element (BGP_NODE, &bgp_network_cmd);
12388 install_element (BGP_NODE, &bgp_network_mask_cmd);
12389 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12390 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12391 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12392 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12393 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12394 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12395 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12396 install_element (BGP_NODE, &no_bgp_network_cmd);
12397 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12398 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12399 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12400 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12401 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12402 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12403 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12404 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12405
12406 install_element (BGP_NODE, &aggregate_address_cmd);
12407 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12408 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12409 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12410 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12411 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12412 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12413 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12414 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12415 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12416 install_element (BGP_NODE, &no_aggregate_address_cmd);
12417 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12418 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12419 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12420 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12421 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12422 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12423 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12424 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12425 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12426
12427 /* IPv4 unicast configuration. */
12428 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12429 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12430 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12431 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12432 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12433 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012434 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012435 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12436 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12437 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12438 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12439 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012440
paul718e3742002-12-13 20:15:29 +000012441 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12442 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12443 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12444 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12445 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12446 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12447 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12448 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12449 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12450 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12451 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12452 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12453 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12454 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12455 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12456 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12457 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12458 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12459 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12460 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12461
12462 /* IPv4 multicast configuration. */
12463 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12464 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12465 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12466 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12467 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12468 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12469 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12470 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12471 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12472 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12473 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12474 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12475 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12476 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12477 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12478 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12479 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12480 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12481 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12482 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12483 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12484 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12485 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12486 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12487 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12488 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12489 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12490 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12491 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12492 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12493 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12494 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12495
12496 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12497 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012498 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012499 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12500 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012501 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012502 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12503 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12504 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12505 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012506 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012507 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12508 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12509 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12510 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12511 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12512 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12513 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12514 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12515 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12516 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12517 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12518 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12519 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12520 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12521 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12522 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12523 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12524 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12525 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12526 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12527 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12528 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12529 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12530 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12531 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012532 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12533 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12534 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12535 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12536 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012537 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12538 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12539 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12540 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12541 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12542 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12543 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12544 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12545 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12546 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12547 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12548 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12549 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12550 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12551 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12552 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12553 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12554 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012555 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012556 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12557 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12558 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12559 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12560 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12561 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12562 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12563 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12564 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12565 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12566 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12567 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12568 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12569 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12570 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12571 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012572 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012573 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012574 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012575 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012576 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012577 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012578 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12579 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012580 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012581 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012582 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012583 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012584 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012585 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012586
12587 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12588 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12589 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012590 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012591 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12592 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12593 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012594 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012595 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12596 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12597 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12598 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12599 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12600 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12601 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12602 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12603 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12604 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12605 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12606 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012607 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12608 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12609 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12610 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12611 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012612 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12613 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12614 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12615 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12616 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12617 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12618 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12619 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12620 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012621 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012622 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012623 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012624 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012625 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012626 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012627 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012628
12629 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12630 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012631 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012632 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12633 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012634 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012635 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12636 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12637 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12638 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012639 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012640 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12641 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12642 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12643 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12644 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12645 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12646 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12647 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12648 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12649 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12650 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12651 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12652 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12653 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12654 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12655 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12656 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12657 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12658 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12659 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12660 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12661 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12662 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12663 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12664 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012665 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12666 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12667 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12668 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12669 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012670 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12671 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12672 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12673 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12674 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12675 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12676 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12677 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12678 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12679 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12680 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12681 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12682 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12683 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12684 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12685 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12686 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12687 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012688 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012689 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12690 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12691 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12692 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12693 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12694 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12695 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12696 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12697 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12698 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12699 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12700 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12701 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12702 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12703 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12704 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012705 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012706 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012707 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012708 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012709 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012710 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012711 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12712 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012713 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012714 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012715 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012716 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012717 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012718 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012719
12720 /* BGP dampening clear commands */
12721 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12722 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12723 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12724 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12725
Paul Jakmaff7924f2006-09-04 01:10:36 +000012726 /* prefix count */
12727 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12728 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12729 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012730#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012731 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12732
paul718e3742002-12-13 20:15:29 +000012733 /* New config IPv6 BGP commands. */
12734 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12735 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12736 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12737 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12738
12739 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12740 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12741 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12742 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12743
G.Balaji73bfe0b2011-09-23 22:36:20 +053012744 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12745 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12746
paul718e3742002-12-13 20:15:29 +000012747 /* Old config IPv6 BGP commands. */
12748 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12749 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12750
12751 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12752 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12753 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12754 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12755
12756 install_element (VIEW_NODE, &show_bgp_cmd);
12757 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012758 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012759 install_element (VIEW_NODE, &show_bgp_route_cmd);
12760 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012761 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012762 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12763 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012764 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012765 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12766 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12767 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12768 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12769 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12770 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12771 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12772 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12773 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12774 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12775 install_element (VIEW_NODE, &show_bgp_community_cmd);
12776 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12777 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12778 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12779 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12780 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12781 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12782 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12783 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12784 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12785 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12786 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12787 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12788 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12789 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12790 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12791 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12792 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12793 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12794 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12795 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12796 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12797 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12798 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12799 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12800 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12801 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12802 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12803 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12804 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012805 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12806 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12807 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12808 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012809 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012810 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012811 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012812 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012813 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012814 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012815 install_element (VIEW_NODE, &show_bgp_view_cmd);
12816 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12817 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12818 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12819 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12820 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12821 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12822 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12823 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12824 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12825 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12826 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12827 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12828 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12829 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12830 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12831 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12832 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012833 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012834 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012835 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012836 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012837 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012838 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012839
12840 /* Restricted:
12841 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12842 */
12843 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12844 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012845 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012846 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12847 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012848 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012849 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12850 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12851 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12852 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12853 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12854 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12855 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12856 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12857 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12858 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12859 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12860 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12861 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12862 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12863 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12864 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12865 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012866 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012867 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012868 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012869 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12870 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12871 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12872 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12873 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12874 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12875 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012876 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012877 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012878 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012879
12880 install_element (ENABLE_NODE, &show_bgp_cmd);
12881 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012882 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012883 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12884 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012885 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012886 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12887 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012888 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012889 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12890 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12891 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12892 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12893 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12894 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12895 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12896 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12897 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12898 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12899 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12900 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12901 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12902 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12903 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12904 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12905 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12906 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12907 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12908 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12909 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12910 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12911 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12912 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12913 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12914 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12915 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12916 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12917 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12918 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12919 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12920 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12921 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12922 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12923 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12924 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12925 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12926 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12927 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12928 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012929 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12930 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12931 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12932 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012933 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012934 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012935 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012936 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012937 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012938 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012939 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12940 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12941 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12942 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12943 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12944 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12945 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12946 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12947 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12948 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12949 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12950 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12951 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12952 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12953 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12954 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12955 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12956 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012957 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012958 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012959 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012960 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012961 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012962 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012963
12964 /* Statistics */
12965 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12966 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12967 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12968 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12969
paul718e3742002-12-13 20:15:29 +000012970 /* old command */
12971 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12972 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12973 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12974 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12975 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12976 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12977 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12978 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12979 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12980 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12981 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12982 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12983 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12984 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12985 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12986 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12987 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12988 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12989 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12990 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12991 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12992 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12993 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12994 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12995 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12996 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12997 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12998 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12999 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
13000 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
13001 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13002 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13003 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13004 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
13005 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13006 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000013007
paul718e3742002-12-13 20:15:29 +000013008 /* old command */
13009 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
13010 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
13011 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
13012 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
13013 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
13014 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
13015 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
13016 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
13017 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
13018 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
13019 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13020 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13021 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13022 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13023 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13024 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13025 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13026 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13027 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13028 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13029 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13030 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13031 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13032 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13033 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13034 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13035 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13036 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13037 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13038 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13039 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13040 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13041 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13042 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13043 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13044 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13045
13046 /* old command */
13047 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13048 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13049 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13050 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13051
13052 /* old command */
13053 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13054 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13055 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13056 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13057
13058 /* old command */
13059 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13060 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13061 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13062 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13063#endif /* HAVE_IPV6 */
13064
13065 install_element (BGP_NODE, &bgp_distance_cmd);
13066 install_element (BGP_NODE, &no_bgp_distance_cmd);
13067 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13068 install_element (BGP_NODE, &bgp_distance_source_cmd);
13069 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13070 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13071 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13072
13073 install_element (BGP_NODE, &bgp_damp_set_cmd);
13074 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13075 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13076 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13077 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13078 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13079 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13080 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13081 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13082 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013083
13084 /* Deprecated AS-Pathlimit commands */
13085 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13086 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13087 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13088 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13089 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13090 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13091
13092 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13093 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13094 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13095 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13096 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13097 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13098
13099 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13100 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13101 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13102 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13103 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13104 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13105
13106 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13107 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13108 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13109 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13110 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13111 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13112
13113 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13114 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13115 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13116 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13117 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13118 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13119
13120 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13121 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13122 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13123 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13124 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13125 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013126
13127#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013128 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13129 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013130#endif
paul718e3742002-12-13 20:15:29 +000013131}
Chris Caputo228da422009-07-18 05:44:03 +000013132
13133void
13134bgp_route_finish (void)
13135{
13136 bgp_table_unlock (bgp_distance_table);
13137 bgp_distance_table = NULL;
13138}