blob: 232a6a1c38febaf0103d0f259b5064e7e1101cd4 [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 */
Timo Teräs9e7a53c2014-04-24 10:22:37 +0300979 if (transparent
980 || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
paul718e3742002-12-13 20:15:29 +0000981 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
982 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000983#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000984 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000985 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000986#endif /* HAVE_IPV6 */
987 )))
paul718e3742002-12-13 20:15:29 +0000988 {
989 /* NEXT-HOP Unchanged. */
990 }
991 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
992 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
993#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000994 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000995 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000996#endif /* HAVE_IPV6 */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000997 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000998 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
999 {
1000 /* Set IPv4 nexthop. */
1001 if (p->family == AF_INET)
1002 {
1003 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001004 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1005 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +00001006 else
1007 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1008 }
1009#ifdef HAVE_IPV6
1010 /* Set IPv6 nexthop. */
1011 if (p->family == AF_INET6)
1012 {
1013 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001014 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001015 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001016 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001017 }
1018#endif /* HAVE_IPV6 */
1019 }
1020
1021#ifdef HAVE_IPV6
1022 if (p->family == AF_INET6)
1023 {
paulfee0f4c2004-09-13 05:12:46 +00001024 /* Left nexthop_local unchanged if so configured. */
1025 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1026 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1027 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001028 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1029 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001030 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001031 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001032 }
1033
1034 /* Default nexthop_local treatment for non-RS-Clients */
1035 else
1036 {
paul718e3742002-12-13 20:15:29 +00001037 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001038 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001039
1040 /* Set link-local address for shared network peer. */
1041 if (peer->shared_network
1042 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1043 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001044 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001045 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001046 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001047 }
1048
1049 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1050 address.*/
1051 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001052 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001053
1054 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1055 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001056 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001057 }
paulfee0f4c2004-09-13 05:12:46 +00001058
1059 }
paul718e3742002-12-13 20:15:29 +00001060#endif /* HAVE_IPV6 */
1061
1062 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001063 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001064 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1065 && aspath_private_as_check (attr->aspath))
1066 attr->aspath = aspath_empty_get ();
1067
1068 /* Route map & unsuppress-map apply. */
1069 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001070 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001071 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001072 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001073 struct attr dummy_attr;
1074 struct attr_extra dummy_extra;
1075
1076 dummy_attr.extra = &dummy_extra;
1077
paul718e3742002-12-13 20:15:29 +00001078 info.peer = peer;
1079 info.attr = attr;
1080
1081 /* The route reflector is not allowed to modify the attributes
1082 of the reflected IBGP routes. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001083 if (from->sort == BGP_PEER_IBGP
1084 && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +00001085 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001086 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001087 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001088 }
paulac41b2a2003-08-12 05:32:27 +00001089
1090 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1091
Paul Jakmafb982c22007-05-04 20:15:47 +00001092 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001093 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1094 else
1095 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1096
paulac41b2a2003-08-12 05:32:27 +00001097 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001098
paul718e3742002-12-13 20:15:29 +00001099 if (ret == RMAP_DENYMATCH)
1100 {
1101 bgp_attr_flush (attr);
1102 return 0;
1103 }
1104 }
1105 return 1;
1106}
1107
paul94f2b392005-06-28 12:44:16 +00001108static int
paulfee0f4c2004-09-13 05:12:46 +00001109bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1110 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001111{
paulfee0f4c2004-09-13 05:12:46 +00001112 int ret;
1113 char buf[SU_ADDRSTRLEN];
1114 struct bgp_filter *filter;
1115 struct bgp_info info;
1116 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001117 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001118
1119 from = ri->peer;
1120 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001121 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001122
Paul Jakma750e8142008-07-22 21:11:48 +00001123 if (DISABLE_BGP_ANNOUNCE)
1124 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001125
1126 /* Do not send back route to sender. */
1127 if (from == rsclient)
1128 return 0;
1129
1130 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001131 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001132 if (! UNSUPPRESS_MAP_NAME (filter))
1133 return 0;
1134
1135 /* Default route check. */
1136 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1137 PEER_STATUS_DEFAULT_ORIGINATE))
1138 {
1139 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1140 return 0;
1141#ifdef HAVE_IPV6
1142 else if (p->family == AF_INET6 && p->prefixlen == 0)
1143 return 0;
1144#endif /* HAVE_IPV6 */
1145 }
1146
1147 /* If the attribute has originator-id and it is same as remote
1148 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001149 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001150 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001151 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001152 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001153 {
1154 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001155 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001156 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1157 rsclient->host,
1158 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1159 p->prefixlen);
1160 return 0;
1161 }
1162 }
1163
1164 /* ORF prefix-list filter check */
1165 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1166 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1167 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1168 if (rsclient->orf_plist[afi][safi])
1169 {
1170 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1171 return 0;
1172 }
1173
1174 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001175 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001176 {
1177 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001178 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001179 "%s [Update:SEND] %s/%d is filtered",
1180 rsclient->host,
1181 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1182 p->prefixlen);
1183 return 0;
1184 }
1185
1186#ifdef BGP_SEND_ASPATH_CHECK
1187 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001188 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001189 {
1190 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001191 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001192 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001193 rsclient->host, rsclient->as);
1194 return 0;
1195 }
1196#endif /* BGP_SEND_ASPATH_CHECK */
1197
1198 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001199 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001200
1201 /* next-hop-set */
1202 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1203#ifdef HAVE_IPV6
1204 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001205 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001206#endif /* HAVE_IPV6 */
1207 )
1208 {
1209 /* Set IPv4 nexthop. */
1210 if (p->family == AF_INET)
1211 {
1212 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001213 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001214 IPV4_MAX_BYTELEN);
1215 else
1216 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1217 }
1218#ifdef HAVE_IPV6
1219 /* Set IPv6 nexthop. */
1220 if (p->family == AF_INET6)
1221 {
1222 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001223 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001224 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001225 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001226 }
1227#endif /* HAVE_IPV6 */
1228 }
1229
1230#ifdef HAVE_IPV6
1231 if (p->family == AF_INET6)
1232 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001233 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001234
paulfee0f4c2004-09-13 05:12:46 +00001235 /* Left nexthop_local unchanged if so configured. */
1236 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1237 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1238 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001239 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1240 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001241 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001242 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001243 }
1244
1245 /* Default nexthop_local treatment for RS-Clients */
1246 else
1247 {
1248 /* Announcer and RS-Client are both in the same network */
1249 if (rsclient->shared_network && from->shared_network &&
1250 (rsclient->ifindex == from->ifindex))
1251 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001252 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1253 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001254 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001255 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001256 }
1257
1258 /* Set link-local address for shared network peer. */
1259 else if (rsclient->shared_network
1260 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1261 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001262 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001263 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001264 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001265 }
1266
1267 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001268 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001269 }
1270
1271 }
1272#endif /* HAVE_IPV6 */
1273
1274
1275 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001276 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001277 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1278 && aspath_private_as_check (attr->aspath))
1279 attr->aspath = aspath_empty_get ();
1280
1281 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001282 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001283 {
1284 info.peer = rsclient;
1285 info.attr = attr;
1286
1287 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1288
Paul Jakmafb982c22007-05-04 20:15:47 +00001289 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001290 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1291 else
1292 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1293
1294 rsclient->rmap_type = 0;
1295
1296 if (ret == RMAP_DENYMATCH)
1297 {
1298 bgp_attr_flush (attr);
1299 return 0;
1300 }
1301 }
1302
1303 return 1;
1304}
1305
1306struct bgp_info_pair
1307{
1308 struct bgp_info *old;
1309 struct bgp_info *new;
1310};
1311
paul94f2b392005-06-28 12:44:16 +00001312static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001313bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1314 struct bgp_maxpaths_cfg *mpath_cfg,
1315 struct bgp_info_pair *result)
paulfee0f4c2004-09-13 05:12:46 +00001316{
paul718e3742002-12-13 20:15:29 +00001317 struct bgp_info *new_select;
1318 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001319 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001320 struct bgp_info *ri1;
1321 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001322 struct bgp_info *nextri = NULL;
Josh Bailey96450fa2011-07-20 20:45:12 -07001323 int paths_eq, do_mpath;
1324 struct list mp_list;
1325
1326 bgp_mp_list_init (&mp_list);
1327 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1328 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1329
paul718e3742002-12-13 20:15:29 +00001330 /* bgp deterministic-med */
1331 new_select = NULL;
1332 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1333 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1334 {
1335 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1336 continue;
1337 if (BGP_INFO_HOLDDOWN (ri1))
1338 continue;
1339
1340 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001341 if (do_mpath)
1342 bgp_mp_list_add (&mp_list, ri1);
1343 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001344 if (ri1->next)
1345 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1346 {
1347 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1348 continue;
1349 if (BGP_INFO_HOLDDOWN (ri2))
1350 continue;
1351
1352 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1353 || aspath_cmp_left_confed (ri1->attr->aspath,
1354 ri2->attr->aspath))
1355 {
Josh Bailey6918e742011-07-20 20:48:20 -07001356 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1357 old_select = ri2;
Josh Bailey96450fa2011-07-20 20:45:12 -07001358 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
paul718e3742002-12-13 20:15:29 +00001359 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001360 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001361 new_select = ri2;
Josh Bailey6918e742011-07-20 20:48:20 -07001362 if (do_mpath && !paths_eq)
1363 {
1364 bgp_mp_list_clear (&mp_list);
1365 bgp_mp_list_add (&mp_list, ri2);
1366 }
paul718e3742002-12-13 20:15:29 +00001367 }
1368
Josh Bailey6918e742011-07-20 20:48:20 -07001369 if (do_mpath && paths_eq)
1370 bgp_mp_list_add (&mp_list, ri2);
1371
Paul Jakma1a392d42006-09-07 00:24:49 +00001372 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001373 }
1374 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001375 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1376 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001377
1378 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1379 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001380 }
1381
1382 /* Check old selected route and new selected route. */
1383 old_select = NULL;
1384 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001385 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001386 {
1387 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1388 old_select = ri;
1389
1390 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001391 {
1392 /* reap REMOVED routes, if needs be
1393 * selected route must stay for a while longer though
1394 */
1395 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1396 && (ri != old_select))
1397 bgp_info_reap (rn, ri);
1398
1399 continue;
1400 }
paul718e3742002-12-13 20:15:29 +00001401
1402 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1403 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1404 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001405 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001406 continue;
1407 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001408 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1409 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001410
Josh Bailey96450fa2011-07-20 20:45:12 -07001411 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1412 {
Josh Bailey6918e742011-07-20 20:48:20 -07001413 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1414 bgp_mp_dmed_deselect (new_select);
1415
Josh Bailey96450fa2011-07-20 20:45:12 -07001416 new_select = ri;
1417
1418 if (do_mpath && !paths_eq)
1419 {
1420 bgp_mp_list_clear (&mp_list);
1421 bgp_mp_list_add (&mp_list, ri);
1422 }
1423 }
Josh Bailey6918e742011-07-20 20:48:20 -07001424 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1425 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001426
1427 if (do_mpath && paths_eq)
1428 bgp_mp_list_add (&mp_list, ri);
paul718e3742002-12-13 20:15:29 +00001429 }
paulb40d9392005-08-22 22:34:41 +00001430
paulfee0f4c2004-09-13 05:12:46 +00001431
Josh Bailey6918e742011-07-20 20:48:20 -07001432 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1433 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
Josh Bailey96450fa2011-07-20 20:45:12 -07001434
Josh Bailey0b597ef2011-07-20 20:49:11 -07001435 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001436 bgp_mp_list_clear (&mp_list);
1437
1438 result->old = old_select;
1439 result->new = new_select;
1440
1441 return;
paulfee0f4c2004-09-13 05:12:46 +00001442}
1443
paul94f2b392005-06-28 12:44:16 +00001444static int
paulfee0f4c2004-09-13 05:12:46 +00001445bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001446 struct bgp_node *rn, afi_t afi, safi_t safi)
1447{
paulfee0f4c2004-09-13 05:12:46 +00001448 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001449 struct attr attr;
1450 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001451
1452 p = &rn->p;
1453
Paul Jakma9eda90c2007-08-30 13:36:17 +00001454 /* Announce route to Established peer. */
1455 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001456 return 0;
1457
Paul Jakma9eda90c2007-08-30 13:36:17 +00001458 /* Address family configuration check. */
1459 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001460 return 0;
1461
Paul Jakma9eda90c2007-08-30 13:36:17 +00001462 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001463 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1464 PEER_STATUS_ORF_WAIT_REFRESH))
1465 return 0;
1466
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001467 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1468 attr.extra = &extra;
1469
Avneesh Sachdev67174042012-08-17 08:19:49 -07001470 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001471 {
1472 case BGP_TABLE_MAIN:
1473 /* Announcement to peer->conf. If the route is filtered,
1474 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001475 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1476 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001477 else
1478 bgp_adj_out_unset (rn, peer, p, afi, safi);
1479 break;
1480 case BGP_TABLE_RSCLIENT:
1481 /* Announcement to peer->conf. If the route is filtered,
1482 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001483 if (selected &&
1484 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1485 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1486 else
1487 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001488 break;
1489 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001490
paulfee0f4c2004-09-13 05:12:46 +00001491 return 0;
paul200df112005-06-01 11:17:05 +00001492}
paulfee0f4c2004-09-13 05:12:46 +00001493
paul200df112005-06-01 11:17:05 +00001494struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001495{
paul200df112005-06-01 11:17:05 +00001496 struct bgp *bgp;
1497 struct bgp_node *rn;
1498 afi_t afi;
1499 safi_t safi;
1500};
1501
1502static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001503bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001504{
paul0fb58d52005-11-14 14:31:49 +00001505 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001506 struct bgp *bgp = pq->bgp;
1507 struct bgp_node *rn = pq->rn;
1508 afi_t afi = pq->afi;
1509 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001510 struct bgp_info *new_select;
1511 struct bgp_info *old_select;
1512 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001513 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001514 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001515
paulfee0f4c2004-09-13 05:12:46 +00001516 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001517 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001518 new_select = old_and_new.new;
1519 old_select = old_and_new.old;
1520
paul200df112005-06-01 11:17:05 +00001521 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1522 {
Chris Caputo228da422009-07-18 05:44:03 +00001523 if (rsclient->group)
1524 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1525 {
1526 /* Nothing to do. */
1527 if (old_select && old_select == new_select)
1528 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1529 continue;
paulfee0f4c2004-09-13 05:12:46 +00001530
Chris Caputo228da422009-07-18 05:44:03 +00001531 if (old_select)
1532 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1533 if (new_select)
1534 {
1535 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1536 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001537 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1538 }
paulfee0f4c2004-09-13 05:12:46 +00001539
Chris Caputo228da422009-07-18 05:44:03 +00001540 bgp_process_announce_selected (rsclient, new_select, rn,
1541 afi, safi);
1542 }
paul200df112005-06-01 11:17:05 +00001543 }
1544 else
1545 {
hassob7395792005-08-26 12:58:38 +00001546 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001547 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001548 if (new_select)
1549 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001550 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1551 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001552 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001553 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001554 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001555 }
paulfee0f4c2004-09-13 05:12:46 +00001556
paulb40d9392005-08-22 22:34:41 +00001557 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1558 bgp_info_reap (rn, old_select);
1559
paul200df112005-06-01 11:17:05 +00001560 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1561 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001562}
1563
paul200df112005-06-01 11:17:05 +00001564static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001565bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001566{
paul0fb58d52005-11-14 14:31:49 +00001567 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001568 struct bgp *bgp = pq->bgp;
1569 struct bgp_node *rn = pq->rn;
1570 afi_t afi = pq->afi;
1571 safi_t safi = pq->safi;
1572 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001573 struct bgp_info *new_select;
1574 struct bgp_info *old_select;
1575 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001576 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001577 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001578
paulfee0f4c2004-09-13 05:12:46 +00001579 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001580 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001581 old_select = old_and_new.old;
1582 new_select = old_and_new.new;
1583
1584 /* Nothing to do. */
1585 if (old_select && old_select == new_select)
1586 {
1587 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001588 {
Josh Bailey8196f132011-07-20 20:47:07 -07001589 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1590 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001591 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001592
Josh Bailey8196f132011-07-20 20:47:07 -07001593 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001594 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1595 return WQ_SUCCESS;
1596 }
paulfee0f4c2004-09-13 05:12:46 +00001597 }
paul718e3742002-12-13 20:15:29 +00001598
hasso338b3422005-02-23 14:27:24 +00001599 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001600 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001601 if (new_select)
1602 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001603 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1604 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001605 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001606 }
1607
1608
paul718e3742002-12-13 20:15:29 +00001609 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001610 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001611 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001612 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001613 }
1614
1615 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001616 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1617 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001618 {
1619 if (new_select
1620 && new_select->type == ZEBRA_ROUTE_BGP
1621 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001622 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001623 else
1624 {
1625 /* Withdraw the route from the kernel. */
1626 if (old_select
1627 && old_select->type == ZEBRA_ROUTE_BGP
1628 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001629 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001630 }
1631 }
paulb40d9392005-08-22 22:34:41 +00001632
1633 /* Reap old select bgp_info, it it has been removed */
1634 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1635 bgp_info_reap (rn, old_select);
1636
paul200df112005-06-01 11:17:05 +00001637 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1638 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001639}
1640
paul200df112005-06-01 11:17:05 +00001641static void
paul0fb58d52005-11-14 14:31:49 +00001642bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001643{
paul0fb58d52005-11-14 14:31:49 +00001644 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001645 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001646
Chris Caputo228da422009-07-18 05:44:03 +00001647 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001648 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001649 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001650 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1651}
1652
1653static void
1654bgp_process_queue_init (void)
1655{
1656 bm->process_main_queue
1657 = work_queue_new (bm->master, "process_main_queue");
1658 bm->process_rsclient_queue
1659 = work_queue_new (bm->master, "process_rsclient_queue");
1660
1661 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1662 {
1663 zlog_err ("%s: Failed to allocate work queue", __func__);
1664 exit (1);
1665 }
1666
1667 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001668 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001669 bm->process_main_queue->spec.max_retries = 0;
1670 bm->process_main_queue->spec.hold = 50;
1671
1672 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1673 sizeof (struct work_queue *));
1674 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
paul200df112005-06-01 11:17:05 +00001675}
1676
1677void
paulfee0f4c2004-09-13 05:12:46 +00001678bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1679{
paul200df112005-06-01 11:17:05 +00001680 struct bgp_process_queue *pqnode;
1681
1682 /* already scheduled for processing? */
1683 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1684 return;
1685
1686 if ( (bm->process_main_queue == NULL) ||
1687 (bm->process_rsclient_queue == NULL) )
1688 bgp_process_queue_init ();
1689
1690 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1691 sizeof (struct bgp_process_queue));
1692 if (!pqnode)
1693 return;
Chris Caputo228da422009-07-18 05:44:03 +00001694
1695 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001696 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001697 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001698 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001699 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001700 pqnode->afi = afi;
1701 pqnode->safi = safi;
1702
Avneesh Sachdev67174042012-08-17 08:19:49 -07001703 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001704 {
paul200df112005-06-01 11:17:05 +00001705 case BGP_TABLE_MAIN:
1706 work_queue_add (bm->process_main_queue, pqnode);
1707 break;
1708 case BGP_TABLE_RSCLIENT:
1709 work_queue_add (bm->process_rsclient_queue, pqnode);
1710 break;
paulfee0f4c2004-09-13 05:12:46 +00001711 }
paul200df112005-06-01 11:17:05 +00001712
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001713 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001714 return;
paulfee0f4c2004-09-13 05:12:46 +00001715}
hasso0a486e52005-02-01 20:57:17 +00001716
paul94f2b392005-06-28 12:44:16 +00001717static int
hasso0a486e52005-02-01 20:57:17 +00001718bgp_maximum_prefix_restart_timer (struct thread *thread)
1719{
1720 struct peer *peer;
1721
1722 peer = THREAD_ARG (thread);
1723 peer->t_pmax_restart = NULL;
1724
1725 if (BGP_DEBUG (events, EVENTS))
1726 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1727 peer->host);
1728
1729 peer_clear (peer);
1730
1731 return 0;
1732}
1733
paulfee0f4c2004-09-13 05:12:46 +00001734int
paul5228ad22004-06-04 17:58:18 +00001735bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1736 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001737{
hassoe0701b72004-05-20 09:19:34 +00001738 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1739 return 0;
1740
1741 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001742 {
hassoe0701b72004-05-20 09:19:34 +00001743 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1744 && ! always)
1745 return 0;
paul718e3742002-12-13 20:15:29 +00001746
hassoe0701b72004-05-20 09:19:34 +00001747 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001748 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1749 "limit %ld", afi_safi_print (afi, safi), peer->host,
1750 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001751 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001752
hassoe0701b72004-05-20 09:19:34 +00001753 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1754 return 0;
paul718e3742002-12-13 20:15:29 +00001755
hassoe0701b72004-05-20 09:19:34 +00001756 {
paul5228ad22004-06-04 17:58:18 +00001757 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001758
1759 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001760 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001761
1762 ndata[0] = (afi >> 8);
1763 ndata[1] = afi;
1764 ndata[2] = safi;
1765 ndata[3] = (peer->pmax[afi][safi] >> 24);
1766 ndata[4] = (peer->pmax[afi][safi] >> 16);
1767 ndata[5] = (peer->pmax[afi][safi] >> 8);
1768 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001769
1770 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1771 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1772 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1773 }
hasso0a486e52005-02-01 20:57:17 +00001774
1775 /* restart timer start */
1776 if (peer->pmax_restart[afi][safi])
1777 {
1778 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1779
1780 if (BGP_DEBUG (events, EVENTS))
1781 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1782 peer->host, peer->v_pmax_restart);
1783
1784 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1785 peer->v_pmax_restart);
1786 }
1787
hassoe0701b72004-05-20 09:19:34 +00001788 return 1;
paul718e3742002-12-13 20:15:29 +00001789 }
hassoe0701b72004-05-20 09:19:34 +00001790 else
1791 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1792
1793 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1794 {
1795 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1796 && ! always)
1797 return 0;
1798
1799 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001800 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1801 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1802 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001803 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1804 }
1805 else
1806 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001807 return 0;
1808}
1809
paulb40d9392005-08-22 22:34:41 +00001810/* Unconditionally remove the route from the RIB, without taking
1811 * damping into consideration (eg, because the session went down)
1812 */
paul94f2b392005-06-28 12:44:16 +00001813static void
paul718e3742002-12-13 20:15:29 +00001814bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1815 afi_t afi, safi_t safi)
1816{
paul902212c2006-02-05 17:51:19 +00001817 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1818
1819 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1820 bgp_info_delete (rn, ri); /* keep historical info */
1821
paulb40d9392005-08-22 22:34:41 +00001822 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001823}
1824
paul94f2b392005-06-28 12:44:16 +00001825static void
paul718e3742002-12-13 20:15:29 +00001826bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001827 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001828{
paul718e3742002-12-13 20:15:29 +00001829 int status = BGP_DAMP_NONE;
1830
paulb40d9392005-08-22 22:34:41 +00001831 /* apply dampening, if result is suppressed, we'll be retaining
1832 * the bgp_info in the RIB for historical reference.
1833 */
1834 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001835 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001836 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1837 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001838 {
paul902212c2006-02-05 17:51:19 +00001839 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1840 return;
1841 }
1842
1843 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001844}
1845
paul94f2b392005-06-28 12:44:16 +00001846static void
paulfee0f4c2004-09-13 05:12:46 +00001847bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1848 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1849 int sub_type, struct prefix_rd *prd, u_char *tag)
1850{
1851 struct bgp_node *rn;
1852 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001853 struct attr new_attr;
1854 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001855 struct attr *attr_new;
1856 struct attr *attr_new2;
1857 struct bgp_info *ri;
1858 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001859 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001860 char buf[SU_ADDRSTRLEN];
1861
1862 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1863 if (peer == rsclient)
1864 return;
1865
1866 bgp = peer->bgp;
1867 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1868
1869 /* Check previously received route. */
1870 for (ri = rn->info; ri; ri = ri->next)
1871 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1872 break;
1873
1874 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001875 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001876 {
1877 reason = "as-path contains our own AS;";
1878 goto filtered;
1879 }
1880
1881 /* Route reflector originator ID check. */
1882 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001883 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001884 {
1885 reason = "originator is us;";
1886 goto filtered;
1887 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001888
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001889 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001890 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001891
1892 /* Apply export policy. */
1893 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1894 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1895 {
1896 reason = "export-policy;";
1897 goto filtered;
1898 }
1899
1900 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001901
paulfee0f4c2004-09-13 05:12:46 +00001902 /* Apply import policy. */
1903 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1904 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001905 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001906
1907 reason = "import-policy;";
1908 goto filtered;
1909 }
1910
1911 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001912 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001913
1914 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001915 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001916 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001917 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001918 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001919 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001920 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001921 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001922
1923 reason = "martian next-hop;";
1924 goto filtered;
1925 }
1926 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001927
paulfee0f4c2004-09-13 05:12:46 +00001928 /* If the update is implicit withdraw. */
1929 if (ri)
1930 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001931 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001932
1933 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001934 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1935 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001936 {
1937
Paul Jakma1a392d42006-09-07 00:24:49 +00001938 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001939
1940 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001941 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001942 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1943 peer->host,
1944 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1945 p->prefixlen, rsclient->host);
1946
Chris Caputo228da422009-07-18 05:44:03 +00001947 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001948 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001949
Chris Caputo228da422009-07-18 05:44:03 +00001950 return;
paulfee0f4c2004-09-13 05:12:46 +00001951 }
1952
Paul Jakma16d2e242007-04-10 19:32:10 +00001953 /* Withdraw/Announce before we fully processed the withdraw */
1954 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1955 bgp_info_restore (rn, ri);
1956
paulfee0f4c2004-09-13 05:12:46 +00001957 /* Received Logging. */
1958 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001959 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001960 peer->host,
1961 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1962 p->prefixlen, rsclient->host);
1963
1964 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001965 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001966
1967 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001968 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001969 ri->attr = attr_new;
1970
1971 /* Update MPLS tag. */
1972 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001973 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001974
Paul Jakma1a392d42006-09-07 00:24:49 +00001975 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001976
1977 /* Process change. */
1978 bgp_process (bgp, rn, afi, safi);
1979 bgp_unlock_node (rn);
1980
1981 return;
1982 }
1983
1984 /* Received Logging. */
1985 if (BGP_DEBUG (update, UPDATE_IN))
1986 {
ajsd2c1f162004-12-08 21:10:20 +00001987 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001988 peer->host,
1989 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1990 p->prefixlen, rsclient->host);
1991 }
1992
1993 /* Make new BGP info. */
1994 new = bgp_info_new ();
1995 new->type = type;
1996 new->sub_type = sub_type;
1997 new->peer = peer;
1998 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03001999 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00002000
2001 /* Update MPLS tag. */
2002 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002003 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002004
Paul Jakma1a392d42006-09-07 00:24:49 +00002005 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002006
2007 /* Register new BGP information. */
2008 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002009
2010 /* route_node_get lock */
2011 bgp_unlock_node (rn);
2012
paulfee0f4c2004-09-13 05:12:46 +00002013 /* Process change. */
2014 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002015
paulfee0f4c2004-09-13 05:12:46 +00002016 return;
2017
2018 filtered:
2019
2020 /* This BGP update is filtered. Log the reason then update BGP entry. */
2021 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002022 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002023 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2024 peer->host,
2025 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2026 p->prefixlen, rsclient->host, reason);
2027
2028 if (ri)
paulb40d9392005-08-22 22:34:41 +00002029 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002030
2031 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002032
paulfee0f4c2004-09-13 05:12:46 +00002033 return;
2034}
2035
paul94f2b392005-06-28 12:44:16 +00002036static void
paulfee0f4c2004-09-13 05:12:46 +00002037bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2038 struct peer *peer, struct prefix *p, int type, int sub_type,
2039 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002040{
paulfee0f4c2004-09-13 05:12:46 +00002041 struct bgp_node *rn;
2042 struct bgp_info *ri;
2043 char buf[SU_ADDRSTRLEN];
2044
2045 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002046 return;
paulfee0f4c2004-09-13 05:12:46 +00002047
2048 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2049
2050 /* Lookup withdrawn route. */
2051 for (ri = rn->info; ri; ri = ri->next)
2052 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2053 break;
2054
2055 /* Withdraw specified route from routing table. */
2056 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002057 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002058 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002059 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002060 "%s Can't find the route %s/%d", peer->host,
2061 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2062 p->prefixlen);
2063
2064 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002065 bgp_unlock_node (rn);
2066}
paulfee0f4c2004-09-13 05:12:46 +00002067
paul94f2b392005-06-28 12:44:16 +00002068static int
paulfee0f4c2004-09-13 05:12:46 +00002069bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002070 afi_t afi, safi_t safi, int type, int sub_type,
2071 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2072{
2073 int ret;
2074 int aspath_loop_count = 0;
2075 struct bgp_node *rn;
2076 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002077 struct attr new_attr;
2078 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002079 struct attr *attr_new;
2080 struct bgp_info *ri;
2081 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002082 const char *reason;
paul718e3742002-12-13 20:15:29 +00002083 char buf[SU_ADDRSTRLEN];
2084
2085 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002086 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002087
paul718e3742002-12-13 20:15:29 +00002088 /* When peer's soft reconfiguration enabled. Record input packet in
2089 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002090 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2091 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002092 bgp_adj_in_set (rn, peer, attr);
2093
2094 /* Check previously received route. */
2095 for (ri = rn->info; ri; ri = ri->next)
2096 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2097 break;
2098
2099 /* AS path local-as loop check. */
2100 if (peer->change_local_as)
2101 {
2102 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2103 aspath_loop_count = 1;
2104
2105 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2106 {
2107 reason = "as-path contains our own AS;";
2108 goto filtered;
2109 }
2110 }
2111
2112 /* AS path loop check. */
2113 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2114 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2115 && aspath_loop_check(attr->aspath, bgp->confed_id)
2116 > peer->allowas_in[afi][safi]))
2117 {
2118 reason = "as-path contains our own AS;";
2119 goto filtered;
2120 }
2121
2122 /* Route reflector originator ID check. */
2123 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002124 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002125 {
2126 reason = "originator is us;";
2127 goto filtered;
2128 }
2129
2130 /* Route reflector cluster ID check. */
2131 if (bgp_cluster_filter (peer, attr))
2132 {
2133 reason = "reflected from the same cluster;";
2134 goto filtered;
2135 }
2136
2137 /* Apply incoming filter. */
2138 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2139 {
2140 reason = "filter;";
2141 goto filtered;
2142 }
2143
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002144 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002145 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002146
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002147 /* Apply incoming route-map. */
paul718e3742002-12-13 20:15:29 +00002148 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2149 {
2150 reason = "route-map;";
2151 goto filtered;
2152 }
2153
2154 /* IPv4 unicast next hop check. */
2155 if (afi == AFI_IP && safi == SAFI_UNICAST)
2156 {
2157 /* If the peer is EBGP and nexthop is not on connected route,
2158 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002159 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002160 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002161 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002162 {
2163 reason = "non-connected next-hop;";
2164 goto filtered;
2165 }
2166
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002167 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002168 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002169 if (new_attr.nexthop.s_addr == 0
2170 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2171 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002172 {
2173 reason = "martian next-hop;";
2174 goto filtered;
2175 }
2176 }
2177
2178 attr_new = bgp_attr_intern (&new_attr);
2179
2180 /* If the update is implicit withdraw. */
2181 if (ri)
2182 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002183 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002184
2185 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002186 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2187 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002188 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002189 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002190
2191 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002192 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002193 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2194 {
2195 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002196 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002197 peer->host,
2198 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2199 p->prefixlen);
2200
paul902212c2006-02-05 17:51:19 +00002201 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2202 {
2203 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2204 bgp_process (bgp, rn, afi, safi);
2205 }
paul718e3742002-12-13 20:15:29 +00002206 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002207 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002208 {
2209 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002210 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002211 "%s rcvd %s/%d...duplicate ignored",
2212 peer->host,
2213 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2214 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002215
2216 /* graceful restart STALE flag unset. */
2217 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2218 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002219 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002220 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002221 }
paul718e3742002-12-13 20:15:29 +00002222 }
2223
2224 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002225 bgp_attr_unintern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002226
paul718e3742002-12-13 20:15:29 +00002227 return 0;
2228 }
2229
Paul Jakma16d2e242007-04-10 19:32:10 +00002230 /* Withdraw/Announce before we fully processed the withdraw */
2231 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2232 {
2233 if (BGP_DEBUG (update, UPDATE_IN))
2234 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2235 peer->host,
2236 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2237 p->prefixlen);
2238 bgp_info_restore (rn, ri);
2239 }
2240
paul718e3742002-12-13 20:15:29 +00002241 /* Received Logging. */
2242 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002243 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002244 peer->host,
2245 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2246 p->prefixlen);
2247
hasso93406d82005-02-02 14:40:33 +00002248 /* graceful restart STALE flag unset. */
2249 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002250 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002251
paul718e3742002-12-13 20:15:29 +00002252 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002253 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002254
2255 /* implicit withdraw, decrement aggregate and pcount here.
2256 * only if update is accepted, they'll increment below.
2257 */
paul902212c2006-02-05 17:51:19 +00002258 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2259
paul718e3742002-12-13 20:15:29 +00002260 /* Update bgp route dampening information. */
2261 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002262 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002263 {
2264 /* This is implicit withdraw so we should update dampening
2265 information. */
2266 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2267 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002268 }
2269
paul718e3742002-12-13 20:15:29 +00002270 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002271 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002272 ri->attr = attr_new;
2273
2274 /* Update MPLS tag. */
2275 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002276 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002277
2278 /* Update bgp route dampening information. */
2279 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002280 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002281 {
2282 /* Now we do normal update dampening. */
2283 ret = bgp_damp_update (ri, rn, afi, safi);
2284 if (ret == BGP_DAMP_SUPPRESSED)
2285 {
2286 bgp_unlock_node (rn);
2287 return 0;
2288 }
2289 }
2290
2291 /* Nexthop reachability check. */
2292 if ((afi == AFI_IP || afi == AFI_IP6)
2293 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002294 && (peer->sort == BGP_PEER_IBGP
2295 || peer->sort == BGP_PEER_CONFED
2296 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002297 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002298 {
2299 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002300 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002301 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002302 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002303 }
2304 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002305 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002306
2307 /* Process change. */
2308 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2309
2310 bgp_process (bgp, rn, afi, safi);
2311 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002312
paul718e3742002-12-13 20:15:29 +00002313 return 0;
2314 }
2315
2316 /* Received Logging. */
2317 if (BGP_DEBUG (update, UPDATE_IN))
2318 {
ajsd2c1f162004-12-08 21:10:20 +00002319 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002320 peer->host,
2321 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2322 p->prefixlen);
2323 }
2324
paul718e3742002-12-13 20:15:29 +00002325 /* Make new BGP info. */
2326 new = bgp_info_new ();
2327 new->type = type;
2328 new->sub_type = sub_type;
2329 new->peer = peer;
2330 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002331 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002332
2333 /* Update MPLS tag. */
2334 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002335 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002336
2337 /* Nexthop reachability check. */
2338 if ((afi == AFI_IP || afi == AFI_IP6)
2339 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002340 && (peer->sort == BGP_PEER_IBGP
2341 || peer->sort == BGP_PEER_CONFED
2342 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002343 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002344 {
2345 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002346 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002347 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002348 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002349 }
2350 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002351 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002352
paul902212c2006-02-05 17:51:19 +00002353 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002354 bgp_aggregate_increment (bgp, p, new, afi, safi);
2355
2356 /* Register new BGP information. */
2357 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002358
2359 /* route_node_get lock */
2360 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002361
paul718e3742002-12-13 20:15:29 +00002362 /* If maximum prefix count is configured and current prefix
2363 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002364 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2365 return -1;
paul718e3742002-12-13 20:15:29 +00002366
2367 /* Process change. */
2368 bgp_process (bgp, rn, afi, safi);
2369
2370 return 0;
2371
2372 /* This BGP update is filtered. Log the reason then update BGP
2373 entry. */
2374 filtered:
2375 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002376 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002377 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2378 peer->host,
2379 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2380 p->prefixlen, reason);
2381
2382 if (ri)
paulb40d9392005-08-22 22:34:41 +00002383 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002384
2385 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002386
paul718e3742002-12-13 20:15:29 +00002387 return 0;
2388}
2389
2390int
paulfee0f4c2004-09-13 05:12:46 +00002391bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2392 afi_t afi, safi_t safi, int type, int sub_type,
2393 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2394{
2395 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002396 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002397 struct bgp *bgp;
2398 int ret;
2399
2400 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2401 soft_reconfig);
2402
2403 bgp = peer->bgp;
2404
2405 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002406 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002407 {
2408 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2409 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2410 sub_type, prd, tag);
2411 }
2412
2413 return ret;
2414}
2415
2416int
paul718e3742002-12-13 20:15:29 +00002417bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002418 afi_t afi, safi_t safi, int type, int sub_type,
2419 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002420{
2421 struct bgp *bgp;
2422 char buf[SU_ADDRSTRLEN];
2423 struct bgp_node *rn;
2424 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002425 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002426 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002427
2428 bgp = peer->bgp;
2429
paulfee0f4c2004-09-13 05:12:46 +00002430 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002431 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002432 {
2433 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2434 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2435 }
2436
paul718e3742002-12-13 20:15:29 +00002437 /* Logging. */
2438 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002439 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002440 peer->host,
2441 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2442 p->prefixlen);
2443
2444 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002445 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002446
2447 /* If peer is soft reconfiguration enabled. Record input packet for
2448 further calculation. */
2449 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2450 && peer != bgp->peer_self)
2451 bgp_adj_in_unset (rn, peer);
2452
2453 /* Lookup withdrawn route. */
2454 for (ri = rn->info; ri; ri = ri->next)
2455 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2456 break;
2457
2458 /* Withdraw specified route from routing table. */
2459 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002460 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002461 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002462 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002463 "%s Can't find the route %s/%d", peer->host,
2464 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2465 p->prefixlen);
2466
2467 /* Unlock bgp_node_get() lock. */
2468 bgp_unlock_node (rn);
2469
2470 return 0;
2471}
David Lamparter6b0655a2014-06-04 06:53:35 +02002472
paul718e3742002-12-13 20:15:29 +00002473void
2474bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2475{
2476 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002477 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002478 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002479 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002480 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002481 struct bgp_node *rn;
2482 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002483 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002484
Paul Jakmab2497022007-06-14 11:17:58 +00002485 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002486 return;
2487
paul718e3742002-12-13 20:15:29 +00002488 bgp = peer->bgp;
2489 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002490
paul718e3742002-12-13 20:15:29 +00002491 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2492 aspath = attr.aspath;
2493 attr.local_pref = bgp->default_local_pref;
2494 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2495
2496 if (afi == AFI_IP)
2497 str2prefix ("0.0.0.0/0", &p);
2498#ifdef HAVE_IPV6
2499 else if (afi == AFI_IP6)
2500 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002501 struct attr_extra *ae = attr.extra;
2502
paul718e3742002-12-13 20:15:29 +00002503 str2prefix ("::/0", &p);
2504
2505 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002506 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002507 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002508 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002509
2510 /* If the peer is on shared nextwork and we have link-local
2511 nexthop set it. */
2512 if (peer->shared_network
2513 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2514 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002515 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002516 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002517 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002518 }
2519 }
2520#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002521
2522 if (peer->default_rmap[afi][safi].name)
2523 {
paulfee0f4c2004-09-13 05:12:46 +00002524 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002525 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2526 {
2527 for (ri = rn->info; ri; ri = ri->next)
2528 {
2529 struct attr dummy_attr;
2530 struct attr_extra dummy_extra;
2531 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002532
Christian Frankedcab1bb2012-12-07 16:45:52 +00002533 /* Provide dummy so the route-map can't modify the attributes */
2534 dummy_attr.extra = &dummy_extra;
2535 bgp_attr_dup(&dummy_attr, ri->attr);
2536 info.peer = ri->peer;
2537 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002538
Christian Frankedcab1bb2012-12-07 16:45:52 +00002539 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2540 RMAP_BGP, &info);
2541
2542 /* The route map might have set attributes. If we don't flush them
2543 * here, they will be leaked. */
2544 bgp_attr_flush(&dummy_attr);
2545 if (ret != RMAP_DENYMATCH)
2546 break;
2547 }
2548 if (ret != RMAP_DENYMATCH)
2549 break;
2550 }
paulfee0f4c2004-09-13 05:12:46 +00002551 bgp->peer_self->rmap_type = 0;
2552
paul718e3742002-12-13 20:15:29 +00002553 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002554 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002555 }
2556
2557 if (withdraw)
2558 {
2559 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2560 bgp_default_withdraw_send (peer, afi, safi);
2561 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2562 }
2563 else
2564 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002565 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2566 {
2567 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2568 bgp_default_update_send (peer, &attr, afi, safi, from);
2569 }
paul718e3742002-12-13 20:15:29 +00002570 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002571
2572 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002573 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002574}
David Lamparter6b0655a2014-06-04 06:53:35 +02002575
paul718e3742002-12-13 20:15:29 +00002576static void
2577bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002578 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002579{
2580 struct bgp_node *rn;
2581 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002582 struct attr attr;
2583 struct attr_extra extra;
2584
paul718e3742002-12-13 20:15:29 +00002585 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002586 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002587
2588 if (safi != SAFI_MPLS_VPN
2589 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2590 bgp_default_originate (peer, afi, safi, 0);
2591
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002592 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2593 attr.extra = &extra;
2594
paul718e3742002-12-13 20:15:29 +00002595 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2596 for (ri = rn->info; ri; ri = ri->next)
2597 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2598 {
paulfee0f4c2004-09-13 05:12:46 +00002599 if ( (rsclient) ?
2600 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2601 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002602 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2603 else
2604 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2605 }
2606}
2607
2608void
2609bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2610{
2611 struct bgp_node *rn;
2612 struct bgp_table *table;
2613
2614 if (peer->status != Established)
2615 return;
2616
2617 if (! peer->afc_nego[afi][safi])
2618 return;
2619
2620 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2621 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2622 return;
2623
2624 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002625 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002626 else
2627 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2628 rn = bgp_route_next(rn))
2629 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002630 bgp_announce_table (peer, afi, safi, table, 0);
2631
2632 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2633 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002634}
2635
2636void
2637bgp_announce_route_all (struct peer *peer)
2638{
2639 afi_t afi;
2640 safi_t safi;
2641
2642 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2643 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2644 bgp_announce_route (peer, afi, safi);
2645}
David Lamparter6b0655a2014-06-04 06:53:35 +02002646
paul718e3742002-12-13 20:15:29 +00002647static void
paulfee0f4c2004-09-13 05:12:46 +00002648bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002649 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002650{
2651 struct bgp_node *rn;
2652 struct bgp_adj_in *ain;
2653
2654 if (! table)
2655 table = rsclient->bgp->rib[afi][safi];
2656
2657 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2658 for (ain = rn->adj_in; ain; ain = ain->next)
2659 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002660 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002661 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002662
paulfee0f4c2004-09-13 05:12:46 +00002663 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002664 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002665 }
2666}
2667
2668void
2669bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2670{
2671 struct bgp_table *table;
2672 struct bgp_node *rn;
2673
2674 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002675 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002676
2677 else
2678 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2679 rn = bgp_route_next (rn))
2680 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002681 {
2682 struct prefix_rd prd;
2683 prd.family = AF_UNSPEC;
2684 prd.prefixlen = 64;
2685 memcpy(&prd.val, rn->p.u.val, 8);
2686
2687 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2688 }
paulfee0f4c2004-09-13 05:12:46 +00002689}
David Lamparter6b0655a2014-06-04 06:53:35 +02002690
paulfee0f4c2004-09-13 05:12:46 +00002691static void
paul718e3742002-12-13 20:15:29 +00002692bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002693 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002694{
2695 int ret;
2696 struct bgp_node *rn;
2697 struct bgp_adj_in *ain;
2698
2699 if (! table)
2700 table = peer->bgp->rib[afi][safi];
2701
2702 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2703 for (ain = rn->adj_in; ain; ain = ain->next)
2704 {
2705 if (ain->peer == peer)
2706 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002707 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002708 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002709
paul718e3742002-12-13 20:15:29 +00002710 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2711 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002712 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002713
paul718e3742002-12-13 20:15:29 +00002714 if (ret < 0)
2715 {
2716 bgp_unlock_node (rn);
2717 return;
2718 }
2719 continue;
2720 }
2721 }
2722}
2723
2724void
2725bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2726{
2727 struct bgp_node *rn;
2728 struct bgp_table *table;
2729
2730 if (peer->status != Established)
2731 return;
2732
2733 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002734 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002735 else
2736 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2737 rn = bgp_route_next (rn))
2738 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002739 {
2740 struct prefix_rd prd;
2741 prd.family = AF_UNSPEC;
2742 prd.prefixlen = 64;
2743 memcpy(&prd.val, rn->p.u.val, 8);
2744
2745 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2746 }
paul718e3742002-12-13 20:15:29 +00002747}
David Lamparter6b0655a2014-06-04 06:53:35 +02002748
Chris Caputo228da422009-07-18 05:44:03 +00002749
2750struct bgp_clear_node_queue
2751{
2752 struct bgp_node *rn;
2753 enum bgp_clear_route_type purpose;
2754};
2755
paul200df112005-06-01 11:17:05 +00002756static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002757bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002758{
Chris Caputo228da422009-07-18 05:44:03 +00002759 struct bgp_clear_node_queue *cnq = data;
2760 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002761 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002762 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002763 afi_t afi = bgp_node_table (rn)->afi;
2764 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002765
Paul Jakma64e580a2006-02-21 01:09:01 +00002766 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002767
Paul Jakma64e580a2006-02-21 01:09:01 +00002768 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002769 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002770 {
2771 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002772 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2773 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002774 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002775 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2776 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002777 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002778 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002779 break;
2780 }
paul200df112005-06-01 11:17:05 +00002781 return WQ_SUCCESS;
2782}
2783
2784static void
paul0fb58d52005-11-14 14:31:49 +00002785bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002786{
Chris Caputo228da422009-07-18 05:44:03 +00002787 struct bgp_clear_node_queue *cnq = data;
2788 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002789 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002790
2791 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002792 bgp_table_unlock (table);
2793 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002794}
2795
2796static void
paul94f2b392005-06-28 12:44:16 +00002797bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002798{
Paul Jakma64e580a2006-02-21 01:09:01 +00002799 struct peer *peer = wq->spec.data;
2800
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002801 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002802 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002803
2804 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002805}
2806
2807static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002808bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002809{
Paul Jakmaa2943652009-07-21 14:02:04 +01002810 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002811
Paul Jakmaa2943652009-07-21 14:02:04 +01002812 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002813#undef CLEAR_QUEUE_NAME_LEN
2814
2815 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002816 {
2817 zlog_err ("%s: Failed to allocate work queue", __func__);
2818 exit (1);
2819 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002820 peer->clear_node_queue->spec.hold = 10;
2821 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2822 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2823 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2824 peer->clear_node_queue->spec.max_retries = 0;
2825
2826 /* we only 'lock' this peer reference when the queue is actually active */
2827 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002828}
2829
paul718e3742002-12-13 20:15:29 +00002830static void
2831bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002832 struct bgp_table *table, struct peer *rsclient,
2833 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002834{
2835 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002836
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002837
paul718e3742002-12-13 20:15:29 +00002838 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002839 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002840
hasso6cf159b2005-03-21 10:28:14 +00002841 /* If still no table => afi/safi isn't configured at all or smth. */
2842 if (! table)
2843 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002844
2845 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2846 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002847 struct bgp_info *ri;
2848 struct bgp_adj_in *ain;
2849 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002850
2851 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2852 * queued for every clearing peer, regardless of whether it is
2853 * relevant to the peer at hand.
2854 *
2855 * Overview: There are 3 different indices which need to be
2856 * scrubbed, potentially, when a peer is removed:
2857 *
2858 * 1 peer's routes visible via the RIB (ie accepted routes)
2859 * 2 peer's routes visible by the (optional) peer's adj-in index
2860 * 3 other routes visible by the peer's adj-out index
2861 *
2862 * 3 there is no hurry in scrubbing, once the struct peer is
2863 * removed from bgp->peer, we could just GC such deleted peer's
2864 * adj-outs at our leisure.
2865 *
2866 * 1 and 2 must be 'scrubbed' in some way, at least made
2867 * invisible via RIB index before peer session is allowed to be
2868 * brought back up. So one needs to know when such a 'search' is
2869 * complete.
2870 *
2871 * Ideally:
2872 *
2873 * - there'd be a single global queue or a single RIB walker
2874 * - rather than tracking which route_nodes still need to be
2875 * examined on a peer basis, we'd track which peers still
2876 * aren't cleared
2877 *
2878 * Given that our per-peer prefix-counts now should be reliable,
2879 * this may actually be achievable. It doesn't seem to be a huge
2880 * problem at this time,
2881 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002882 for (ain = rn->adj_in; ain; ain = ain->next)
2883 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2884 {
2885 bgp_adj_in_remove (rn, ain);
2886 bgp_unlock_node (rn);
2887 break;
2888 }
2889 for (aout = rn->adj_out; aout; aout = aout->next)
2890 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2891 {
2892 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2893 bgp_unlock_node (rn);
2894 break;
2895 }
2896
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002897 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002898 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002899 {
Chris Caputo228da422009-07-18 05:44:03 +00002900 struct bgp_clear_node_queue *cnq;
2901
2902 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002903 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002904 bgp_lock_node (rn);
2905 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2906 sizeof (struct bgp_clear_node_queue));
2907 cnq->rn = rn;
2908 cnq->purpose = purpose;
2909 work_queue_add (peer->clear_node_queue, cnq);
2910 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002911 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002912 }
2913 return;
2914}
2915
2916void
Chris Caputo228da422009-07-18 05:44:03 +00002917bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2918 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002919{
2920 struct bgp_node *rn;
2921 struct bgp_table *table;
2922 struct peer *rsclient;
2923 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002924
Paul Jakma64e580a2006-02-21 01:09:01 +00002925 if (peer->clear_node_queue == NULL)
2926 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002927
Paul Jakmaca058a32006-09-14 02:58:49 +00002928 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2929 * Idle until it receives a Clearing_Completed event. This protects
2930 * against peers which flap faster than we can we clear, which could
2931 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002932 *
2933 * a) race with routes from the new session being installed before
2934 * clear_route_node visits the node (to delete the route of that
2935 * peer)
2936 * b) resource exhaustion, clear_route_node likely leads to an entry
2937 * on the process_main queue. Fast-flapping could cause that queue
2938 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002939 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002940 if (!peer->clear_node_queue->thread)
2941 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002942
Chris Caputo228da422009-07-18 05:44:03 +00002943 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002944 {
Chris Caputo228da422009-07-18 05:44:03 +00002945 case BGP_CLEAR_ROUTE_NORMAL:
2946 if (safi != SAFI_MPLS_VPN)
2947 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2948 else
2949 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2950 rn = bgp_route_next (rn))
2951 if ((table = rn->info) != NULL)
2952 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2953
2954 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2955 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2956 PEER_FLAG_RSERVER_CLIENT))
2957 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2958 break;
2959
2960 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2961 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2962 break;
2963
2964 default:
2965 assert (0);
2966 break;
paulfee0f4c2004-09-13 05:12:46 +00002967 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002968
Paul Jakmaca058a32006-09-14 02:58:49 +00002969 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002970 * completion function won't be run by workqueue code - call it here.
2971 * XXX: Actually, this assumption doesn't hold, see
2972 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002973 *
2974 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002975 * really needed if peer state is Established - peers in
2976 * pre-Established states shouldn't have any route-update state
2977 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002978 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002979 * We still can get here in pre-Established though, through
2980 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2981 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002982 *
2983 * At some future point, this check could be move to the top of the
2984 * function, and do a quick early-return when state is
2985 * pre-Established, avoiding above list and table scans. Once we're
2986 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002987 */
2988 if (!peer->clear_node_queue->thread)
2989 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002990}
2991
2992void
2993bgp_clear_route_all (struct peer *peer)
2994{
2995 afi_t afi;
2996 safi_t safi;
2997
2998 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2999 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003000 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003001}
3002
3003void
3004bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3005{
3006 struct bgp_table *table;
3007 struct bgp_node *rn;
3008 struct bgp_adj_in *ain;
3009
3010 table = peer->bgp->rib[afi][safi];
3011
3012 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3013 for (ain = rn->adj_in; ain ; ain = ain->next)
3014 if (ain->peer == peer)
3015 {
3016 bgp_adj_in_remove (rn, ain);
3017 bgp_unlock_node (rn);
3018 break;
3019 }
3020}
hasso93406d82005-02-02 14:40:33 +00003021
3022void
3023bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3024{
3025 struct bgp_node *rn;
3026 struct bgp_info *ri;
3027 struct bgp_table *table;
3028
3029 table = peer->bgp->rib[afi][safi];
3030
3031 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3032 {
3033 for (ri = rn->info; ri; ri = ri->next)
3034 if (ri->peer == peer)
3035 {
3036 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3037 bgp_rib_remove (rn, ri, peer, afi, safi);
3038 break;
3039 }
3040 }
3041}
David Lamparter6b0655a2014-06-04 06:53:35 +02003042
paul718e3742002-12-13 20:15:29 +00003043/* Delete all kernel routes. */
3044void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003045bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003046{
3047 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003048 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003049 struct bgp_node *rn;
3050 struct bgp_table *table;
3051 struct bgp_info *ri;
3052
paul1eb8ef22005-04-07 07:30:20 +00003053 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003054 {
3055 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3056
3057 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3058 for (ri = rn->info; ri; ri = ri->next)
3059 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3060 && ri->type == ZEBRA_ROUTE_BGP
3061 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003062 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003063
3064 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3065
3066 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3067 for (ri = rn->info; ri; ri = ri->next)
3068 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3069 && ri->type == ZEBRA_ROUTE_BGP
3070 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003071 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003072 }
3073}
3074
3075void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003076bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003077{
3078 vty_reset ();
3079 bgp_zclient_reset ();
3080 access_list_reset ();
3081 prefix_list_reset ();
3082}
David Lamparter6b0655a2014-06-04 06:53:35 +02003083
paul718e3742002-12-13 20:15:29 +00003084/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3085 value. */
3086int
3087bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3088{
3089 u_char *pnt;
3090 u_char *lim;
3091 struct prefix p;
3092 int psize;
3093 int ret;
3094
3095 /* Check peer status. */
3096 if (peer->status != Established)
3097 return 0;
3098
3099 pnt = packet->nlri;
3100 lim = pnt + packet->length;
3101
3102 for (; pnt < lim; pnt += psize)
3103 {
3104 /* Clear prefix structure. */
3105 memset (&p, 0, sizeof (struct prefix));
3106
3107 /* Fetch prefix length. */
3108 p.prefixlen = *pnt++;
3109 p.family = afi2family (packet->afi);
3110
3111 /* Already checked in nlri_sanity_check(). We do double check
3112 here. */
3113 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3114 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3115 return -1;
3116
3117 /* Packet size overflow check. */
3118 psize = PSIZE (p.prefixlen);
3119
3120 /* When packet overflow occur return immediately. */
3121 if (pnt + psize > lim)
3122 return -1;
3123
3124 /* Fetch prefix from NLRI packet. */
3125 memcpy (&p.u.prefix, pnt, psize);
3126
3127 /* Check address. */
3128 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3129 {
3130 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3131 {
paulf5ba3872004-07-09 12:11:31 +00003132 /*
3133 * From draft-ietf-idr-bgp4-22, Section 6.3:
3134 * If a BGP router receives an UPDATE message with a
3135 * semantically incorrect NLRI field, in which a prefix is
3136 * semantically incorrect (eg. an unexpected multicast IP
3137 * address), it should ignore the prefix.
3138 */
paul718e3742002-12-13 20:15:29 +00003139 zlog (peer->log, LOG_ERR,
3140 "IPv4 unicast NLRI is multicast address %s",
3141 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003142
paul718e3742002-12-13 20:15:29 +00003143 return -1;
3144 }
3145 }
3146
3147#ifdef HAVE_IPV6
3148 /* Check address. */
3149 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3150 {
3151 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3152 {
3153 char buf[BUFSIZ];
3154
3155 zlog (peer->log, LOG_WARNING,
3156 "IPv6 link-local NLRI received %s ignore this NLRI",
3157 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3158
3159 continue;
3160 }
3161 }
3162#endif /* HAVE_IPV6 */
3163
3164 /* Normal process. */
3165 if (attr)
3166 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3167 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3168 else
3169 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3170 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3171
3172 /* Address family configuration mismatch or maximum-prefix count
3173 overflow. */
3174 if (ret < 0)
3175 return -1;
3176 }
3177
3178 /* Packet length consistency check. */
3179 if (pnt != lim)
3180 return -1;
3181
3182 return 0;
3183}
3184
3185/* NLRI encode syntax check routine. */
3186int
3187bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3188 bgp_size_t length)
3189{
3190 u_char *end;
3191 u_char prefixlen;
3192 int psize;
3193
3194 end = pnt + length;
3195
3196 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3197 syntactic validity. If the field is syntactically incorrect,
3198 then the Error Subcode is set to Invalid Network Field. */
3199
3200 while (pnt < end)
3201 {
3202 prefixlen = *pnt++;
3203
3204 /* Prefix length check. */
3205 if ((afi == AFI_IP && prefixlen > 32)
3206 || (afi == AFI_IP6 && prefixlen > 128))
3207 {
3208 plog_err (peer->log,
3209 "%s [Error] Update packet error (wrong prefix length %d)",
3210 peer->host, prefixlen);
3211 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3212 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3213 return -1;
3214 }
3215
3216 /* Packet size overflow check. */
3217 psize = PSIZE (prefixlen);
3218
3219 if (pnt + psize > end)
3220 {
3221 plog_err (peer->log,
3222 "%s [Error] Update packet error"
3223 " (prefix data overflow prefix size is %d)",
3224 peer->host, psize);
3225 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3226 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3227 return -1;
3228 }
3229
3230 pnt += psize;
3231 }
3232
3233 /* Packet length consistency check. */
3234 if (pnt != end)
3235 {
3236 plog_err (peer->log,
3237 "%s [Error] Update packet error"
3238 " (prefix length mismatch with total length)",
3239 peer->host);
3240 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3241 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3242 return -1;
3243 }
3244 return 0;
3245}
David Lamparter6b0655a2014-06-04 06:53:35 +02003246
paul94f2b392005-06-28 12:44:16 +00003247static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003248bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003249{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003250 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003251}
3252
paul94f2b392005-06-28 12:44:16 +00003253static void
paul718e3742002-12-13 20:15:29 +00003254bgp_static_free (struct bgp_static *bgp_static)
3255{
3256 if (bgp_static->rmap.name)
3257 free (bgp_static->rmap.name);
3258 XFREE (MTYPE_BGP_STATIC, bgp_static);
3259}
3260
paul94f2b392005-06-28 12:44:16 +00003261static void
paulfee0f4c2004-09-13 05:12:46 +00003262bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3263 struct prefix *p, afi_t afi, safi_t safi)
3264{
3265 struct bgp_node *rn;
3266 struct bgp_info *ri;
3267
3268 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3269
3270 /* Check selected route and self inserted route. */
3271 for (ri = rn->info; ri; ri = ri->next)
3272 if (ri->peer == bgp->peer_self
3273 && ri->type == ZEBRA_ROUTE_BGP
3274 && ri->sub_type == BGP_ROUTE_STATIC)
3275 break;
3276
3277 /* Withdraw static BGP route from routing table. */
3278 if (ri)
3279 {
paulfee0f4c2004-09-13 05:12:46 +00003280 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003281 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003282 }
3283
3284 /* Unlock bgp_node_lookup. */
3285 bgp_unlock_node (rn);
3286}
3287
paul94f2b392005-06-28 12:44:16 +00003288static void
paulfee0f4c2004-09-13 05:12:46 +00003289bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003290 struct bgp_static *bgp_static,
3291 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003292{
3293 struct bgp_node *rn;
3294 struct bgp_info *ri;
3295 struct bgp_info *new;
3296 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003297 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003298 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003299 struct attr new_attr;
3300 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003301 struct bgp *bgp;
3302 int ret;
3303 char buf[SU_ADDRSTRLEN];
3304
3305 bgp = rsclient->bgp;
3306
Paul Jakma06e110f2006-05-12 23:29:22 +00003307 assert (bgp_static);
3308 if (!bgp_static)
3309 return;
3310
paulfee0f4c2004-09-13 05:12:46 +00003311 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3312
3313 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003314
3315 attr.nexthop = bgp_static->igpnexthop;
3316 attr.med = bgp_static->igpmetric;
3317 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003318
Paul Jakma41367172007-08-06 15:24:51 +00003319 if (bgp_static->atomic)
3320 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3321
paulfee0f4c2004-09-13 05:12:46 +00003322 /* Apply network route-map for export to this rsclient. */
3323 if (bgp_static->rmap.name)
3324 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003325 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003326 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003327 info.attr = &attr_tmp;
3328
paulfee0f4c2004-09-13 05:12:46 +00003329 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3330 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3331
3332 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3333
3334 rsclient->rmap_type = 0;
3335
3336 if (ret == RMAP_DENYMATCH)
3337 {
3338 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003339 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003340
3341 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003342 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003343 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003344 bgp_attr_extra_free (&attr);
3345
paulfee0f4c2004-09-13 05:12:46 +00003346 return;
3347 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003348 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003349 }
3350 else
3351 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003352
3353 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003354 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003355
paulfee0f4c2004-09-13 05:12:46 +00003356 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3357
Paul Jakmafb982c22007-05-04 20:15:47 +00003358 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3359 == RMAP_DENY)
3360 {
paulfee0f4c2004-09-13 05:12:46 +00003361 /* This BGP update is filtered. Log the reason then update BGP entry. */
3362 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003363 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003364 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3365 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3366 p->prefixlen, rsclient->host);
3367
3368 bgp->peer_self->rmap_type = 0;
3369
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003370 bgp_attr_unintern (&attr_new);
3371 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003372 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003373
3374 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3375
3376 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003377 }
paulfee0f4c2004-09-13 05:12:46 +00003378
3379 bgp->peer_self->rmap_type = 0;
3380
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003381 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003382 attr_new = bgp_attr_intern (&new_attr);
3383
3384 for (ri = rn->info; ri; ri = ri->next)
3385 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3386 && ri->sub_type == BGP_ROUTE_STATIC)
3387 break;
3388
3389 if (ri)
3390 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003391 if (attrhash_cmp (ri->attr, attr_new) &&
3392 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003393 {
3394 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003395 bgp_attr_unintern (&attr_new);
3396 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003397 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003398 return;
3399 }
3400 else
3401 {
3402 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003403 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003404
3405 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003406 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3407 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003408 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003409 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003410 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003411
3412 /* Process change. */
3413 bgp_process (bgp, rn, afi, safi);
3414 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003415 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003416 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003417 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003418 }
paulfee0f4c2004-09-13 05:12:46 +00003419 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003420
paulfee0f4c2004-09-13 05:12:46 +00003421 /* Make new BGP info. */
3422 new = bgp_info_new ();
3423 new->type = ZEBRA_ROUTE_BGP;
3424 new->sub_type = BGP_ROUTE_STATIC;
3425 new->peer = bgp->peer_self;
3426 SET_FLAG (new->flags, BGP_INFO_VALID);
3427 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003428 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003429
3430 /* Register new BGP information. */
3431 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003432
3433 /* route_node_get lock */
3434 bgp_unlock_node (rn);
3435
paulfee0f4c2004-09-13 05:12:46 +00003436 /* Process change. */
3437 bgp_process (bgp, rn, afi, safi);
3438
3439 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003440 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003441 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003442}
3443
paul94f2b392005-06-28 12:44:16 +00003444static void
paulfee0f4c2004-09-13 05:12:46 +00003445bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003446 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3447{
3448 struct bgp_node *rn;
3449 struct bgp_info *ri;
3450 struct bgp_info *new;
3451 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003452 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003453 struct attr *attr_new;
3454 int ret;
3455
Paul Jakmadd8103a2006-05-12 23:27:30 +00003456 assert (bgp_static);
3457 if (!bgp_static)
3458 return;
3459
paulfee0f4c2004-09-13 05:12:46 +00003460 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003461
3462 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003463
3464 attr.nexthop = bgp_static->igpnexthop;
3465 attr.med = bgp_static->igpmetric;
3466 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003467
Paul Jakma41367172007-08-06 15:24:51 +00003468 if (bgp_static->atomic)
3469 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3470
paul718e3742002-12-13 20:15:29 +00003471 /* Apply route-map. */
3472 if (bgp_static->rmap.name)
3473 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003474 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003475 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003476 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003477
paulfee0f4c2004-09-13 05:12:46 +00003478 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3479
paul718e3742002-12-13 20:15:29 +00003480 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003481
paulfee0f4c2004-09-13 05:12:46 +00003482 bgp->peer_self->rmap_type = 0;
3483
paul718e3742002-12-13 20:15:29 +00003484 if (ret == RMAP_DENYMATCH)
3485 {
3486 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003487 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003488
3489 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003490 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003491 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003492 bgp_static_withdraw (bgp, p, afi, safi);
3493 return;
3494 }
paul286e1e72003-08-08 00:24:31 +00003495 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003496 }
paul286e1e72003-08-08 00:24:31 +00003497 else
3498 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003499
3500 for (ri = rn->info; ri; ri = ri->next)
3501 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3502 && ri->sub_type == BGP_ROUTE_STATIC)
3503 break;
3504
3505 if (ri)
3506 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003507 if (attrhash_cmp (ri->attr, attr_new) &&
3508 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003509 {
3510 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003511 bgp_attr_unintern (&attr_new);
3512 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003513 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003514 return;
3515 }
3516 else
3517 {
3518 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003519 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003520
3521 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003522 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3523 bgp_info_restore(rn, ri);
3524 else
3525 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003526 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003527 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003528 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003529
3530 /* Process change. */
3531 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3532 bgp_process (bgp, rn, afi, safi);
3533 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003534 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003535 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003536 return;
3537 }
3538 }
3539
3540 /* Make new BGP info. */
3541 new = bgp_info_new ();
3542 new->type = ZEBRA_ROUTE_BGP;
3543 new->sub_type = BGP_ROUTE_STATIC;
3544 new->peer = bgp->peer_self;
3545 SET_FLAG (new->flags, BGP_INFO_VALID);
3546 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003547 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003548
3549 /* Aggregate address increment. */
3550 bgp_aggregate_increment (bgp, p, new, afi, safi);
3551
3552 /* Register new BGP information. */
3553 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003554
3555 /* route_node_get lock */
3556 bgp_unlock_node (rn);
3557
paul718e3742002-12-13 20:15:29 +00003558 /* Process change. */
3559 bgp_process (bgp, rn, afi, safi);
3560
3561 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003562 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003563 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003564}
3565
3566void
paulfee0f4c2004-09-13 05:12:46 +00003567bgp_static_update (struct bgp *bgp, struct prefix *p,
3568 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3569{
3570 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003571 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003572
3573 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3574
paul1eb8ef22005-04-07 07:30:20 +00003575 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003576 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003577 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3578 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003579 }
3580}
3581
paul94f2b392005-06-28 12:44:16 +00003582static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003583bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3584 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003585{
3586 struct bgp_node *rn;
3587 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003588
paulfee0f4c2004-09-13 05:12:46 +00003589 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003590
3591 /* Make new BGP info. */
3592 new = bgp_info_new ();
3593 new->type = ZEBRA_ROUTE_BGP;
3594 new->sub_type = BGP_ROUTE_STATIC;
3595 new->peer = bgp->peer_self;
3596 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3597 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003598 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003599 new->extra = bgp_info_extra_new();
3600 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003601
3602 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003603 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003604
3605 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003606 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003607
paul200df112005-06-01 11:17:05 +00003608 /* route_node_get lock */
3609 bgp_unlock_node (rn);
3610
paul718e3742002-12-13 20:15:29 +00003611 /* Process change. */
3612 bgp_process (bgp, rn, afi, safi);
3613}
3614
3615void
3616bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3617 safi_t safi)
3618{
3619 struct bgp_node *rn;
3620 struct bgp_info *ri;
3621
paulfee0f4c2004-09-13 05:12:46 +00003622 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003623
3624 /* Check selected route and self inserted route. */
3625 for (ri = rn->info; ri; ri = ri->next)
3626 if (ri->peer == bgp->peer_self
3627 && ri->type == ZEBRA_ROUTE_BGP
3628 && ri->sub_type == BGP_ROUTE_STATIC)
3629 break;
3630
3631 /* Withdraw static BGP route from routing table. */
3632 if (ri)
3633 {
3634 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003635 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003636 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003637 }
3638
3639 /* Unlock bgp_node_lookup. */
3640 bgp_unlock_node (rn);
3641}
3642
3643void
paulfee0f4c2004-09-13 05:12:46 +00003644bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3645{
3646 struct bgp_static *bgp_static;
3647 struct bgp *bgp;
3648 struct bgp_node *rn;
3649 struct prefix *p;
3650
3651 bgp = rsclient->bgp;
3652
3653 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3654 if ((bgp_static = rn->info) != NULL)
3655 {
3656 p = &rn->p;
3657
3658 bgp_static_update_rsclient (rsclient, p, bgp_static,
3659 afi, safi);
3660 }
3661}
3662
paul94f2b392005-06-28 12:44:16 +00003663static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003664bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3665 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003666{
3667 struct bgp_node *rn;
3668 struct bgp_info *ri;
3669
paulfee0f4c2004-09-13 05:12:46 +00003670 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003671
3672 /* Check selected route and self inserted route. */
3673 for (ri = rn->info; ri; ri = ri->next)
3674 if (ri->peer == bgp->peer_self
3675 && ri->type == ZEBRA_ROUTE_BGP
3676 && ri->sub_type == BGP_ROUTE_STATIC)
3677 break;
3678
3679 /* Withdraw static BGP route from routing table. */
3680 if (ri)
3681 {
3682 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003683 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003684 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003685 }
3686
3687 /* Unlock bgp_node_lookup. */
3688 bgp_unlock_node (rn);
3689}
3690
3691/* Configure static BGP network. When user don't run zebra, static
3692 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003693static int
paulfd79ac92004-10-13 05:06:08 +00003694bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003695 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003696{
3697 int ret;
3698 struct prefix p;
3699 struct bgp_static *bgp_static;
3700 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003701 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003702
3703 /* Convert IP prefix string to struct prefix. */
3704 ret = str2prefix (ip_str, &p);
3705 if (! ret)
3706 {
3707 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3708 return CMD_WARNING;
3709 }
3710#ifdef HAVE_IPV6
3711 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3712 {
3713 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3714 VTY_NEWLINE);
3715 return CMD_WARNING;
3716 }
3717#endif /* HAVE_IPV6 */
3718
3719 apply_mask (&p);
3720
3721 /* Set BGP static route configuration. */
3722 rn = bgp_node_get (bgp->route[afi][safi], &p);
3723
3724 if (rn->info)
3725 {
3726 /* Configuration change. */
3727 bgp_static = rn->info;
3728
3729 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003730 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3731 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003732
paul718e3742002-12-13 20:15:29 +00003733 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003734
paul718e3742002-12-13 20:15:29 +00003735 if (rmap)
3736 {
3737 if (bgp_static->rmap.name)
3738 free (bgp_static->rmap.name);
3739 bgp_static->rmap.name = strdup (rmap);
3740 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3741 }
3742 else
3743 {
3744 if (bgp_static->rmap.name)
3745 free (bgp_static->rmap.name);
3746 bgp_static->rmap.name = NULL;
3747 bgp_static->rmap.map = NULL;
3748 bgp_static->valid = 0;
3749 }
3750 bgp_unlock_node (rn);
3751 }
3752 else
3753 {
3754 /* New configuration. */
3755 bgp_static = bgp_static_new ();
3756 bgp_static->backdoor = backdoor;
3757 bgp_static->valid = 0;
3758 bgp_static->igpmetric = 0;
3759 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003760
paul718e3742002-12-13 20:15:29 +00003761 if (rmap)
3762 {
3763 if (bgp_static->rmap.name)
3764 free (bgp_static->rmap.name);
3765 bgp_static->rmap.name = strdup (rmap);
3766 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3767 }
3768 rn->info = bgp_static;
3769 }
3770
3771 /* If BGP scan is not enabled, we should install this route here. */
3772 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3773 {
3774 bgp_static->valid = 1;
3775
3776 if (need_update)
3777 bgp_static_withdraw (bgp, &p, afi, safi);
3778
3779 if (! bgp_static->backdoor)
3780 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3781 }
3782
3783 return CMD_SUCCESS;
3784}
3785
3786/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003787static int
paulfd79ac92004-10-13 05:06:08 +00003788bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003789 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003790{
3791 int ret;
3792 struct prefix p;
3793 struct bgp_static *bgp_static;
3794 struct bgp_node *rn;
3795
3796 /* Convert IP prefix string to struct prefix. */
3797 ret = str2prefix (ip_str, &p);
3798 if (! ret)
3799 {
3800 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3801 return CMD_WARNING;
3802 }
3803#ifdef HAVE_IPV6
3804 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3805 {
3806 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3807 VTY_NEWLINE);
3808 return CMD_WARNING;
3809 }
3810#endif /* HAVE_IPV6 */
3811
3812 apply_mask (&p);
3813
3814 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3815 if (! rn)
3816 {
3817 vty_out (vty, "%% Can't find specified static route configuration.%s",
3818 VTY_NEWLINE);
3819 return CMD_WARNING;
3820 }
3821
3822 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003823
paul718e3742002-12-13 20:15:29 +00003824 /* Update BGP RIB. */
3825 if (! bgp_static->backdoor)
3826 bgp_static_withdraw (bgp, &p, afi, safi);
3827
3828 /* Clear configuration. */
3829 bgp_static_free (bgp_static);
3830 rn->info = NULL;
3831 bgp_unlock_node (rn);
3832 bgp_unlock_node (rn);
3833
3834 return CMD_SUCCESS;
3835}
3836
3837/* Called from bgp_delete(). Delete all static routes from the BGP
3838 instance. */
3839void
3840bgp_static_delete (struct bgp *bgp)
3841{
3842 afi_t afi;
3843 safi_t safi;
3844 struct bgp_node *rn;
3845 struct bgp_node *rm;
3846 struct bgp_table *table;
3847 struct bgp_static *bgp_static;
3848
3849 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3850 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3851 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3852 if (rn->info != NULL)
3853 {
3854 if (safi == SAFI_MPLS_VPN)
3855 {
3856 table = rn->info;
3857
3858 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3859 {
3860 bgp_static = rn->info;
3861 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3862 AFI_IP, SAFI_MPLS_VPN,
3863 (struct prefix_rd *)&rn->p,
3864 bgp_static->tag);
3865 bgp_static_free (bgp_static);
3866 rn->info = NULL;
3867 bgp_unlock_node (rn);
3868 }
3869 }
3870 else
3871 {
3872 bgp_static = rn->info;
3873 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3874 bgp_static_free (bgp_static);
3875 rn->info = NULL;
3876 bgp_unlock_node (rn);
3877 }
3878 }
3879}
3880
3881int
paulfd79ac92004-10-13 05:06:08 +00003882bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3883 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003884{
3885 int ret;
3886 struct prefix p;
3887 struct prefix_rd prd;
3888 struct bgp *bgp;
3889 struct bgp_node *prn;
3890 struct bgp_node *rn;
3891 struct bgp_table *table;
3892 struct bgp_static *bgp_static;
3893 u_char tag[3];
3894
3895 bgp = vty->index;
3896
3897 ret = str2prefix (ip_str, &p);
3898 if (! ret)
3899 {
3900 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3901 return CMD_WARNING;
3902 }
3903 apply_mask (&p);
3904
3905 ret = str2prefix_rd (rd_str, &prd);
3906 if (! ret)
3907 {
3908 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3909 return CMD_WARNING;
3910 }
3911
3912 ret = str2tag (tag_str, tag);
3913 if (! ret)
3914 {
3915 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3916 return CMD_WARNING;
3917 }
3918
3919 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3920 (struct prefix *)&prd);
3921 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003922 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003923 else
3924 bgp_unlock_node (prn);
3925 table = prn->info;
3926
3927 rn = bgp_node_get (table, &p);
3928
3929 if (rn->info)
3930 {
3931 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3932 bgp_unlock_node (rn);
3933 }
3934 else
3935 {
3936 /* New configuration. */
3937 bgp_static = bgp_static_new ();
3938 bgp_static->valid = 1;
3939 memcpy (bgp_static->tag, tag, 3);
3940 rn->info = bgp_static;
3941
3942 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3943 }
3944
3945 return CMD_SUCCESS;
3946}
3947
3948/* Configure static BGP network. */
3949int
paulfd79ac92004-10-13 05:06:08 +00003950bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3951 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003952{
3953 int ret;
3954 struct bgp *bgp;
3955 struct prefix p;
3956 struct prefix_rd prd;
3957 struct bgp_node *prn;
3958 struct bgp_node *rn;
3959 struct bgp_table *table;
3960 struct bgp_static *bgp_static;
3961 u_char tag[3];
3962
3963 bgp = vty->index;
3964
3965 /* Convert IP prefix string to struct prefix. */
3966 ret = str2prefix (ip_str, &p);
3967 if (! ret)
3968 {
3969 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3970 return CMD_WARNING;
3971 }
3972 apply_mask (&p);
3973
3974 ret = str2prefix_rd (rd_str, &prd);
3975 if (! ret)
3976 {
3977 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3978 return CMD_WARNING;
3979 }
3980
3981 ret = str2tag (tag_str, tag);
3982 if (! ret)
3983 {
3984 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3985 return CMD_WARNING;
3986 }
3987
3988 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3989 (struct prefix *)&prd);
3990 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003991 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003992 else
3993 bgp_unlock_node (prn);
3994 table = prn->info;
3995
3996 rn = bgp_node_lookup (table, &p);
3997
3998 if (rn)
3999 {
4000 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4001
4002 bgp_static = rn->info;
4003 bgp_static_free (bgp_static);
4004 rn->info = NULL;
4005 bgp_unlock_node (rn);
4006 bgp_unlock_node (rn);
4007 }
4008 else
4009 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4010
4011 return CMD_SUCCESS;
4012}
David Lamparter6b0655a2014-06-04 06:53:35 +02004013
paul718e3742002-12-13 20:15:29 +00004014DEFUN (bgp_network,
4015 bgp_network_cmd,
4016 "network A.B.C.D/M",
4017 "Specify a network to announce via BGP\n"
4018 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4019{
4020 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004021 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004022}
4023
4024DEFUN (bgp_network_route_map,
4025 bgp_network_route_map_cmd,
4026 "network A.B.C.D/M route-map WORD",
4027 "Specify a network to announce via BGP\n"
4028 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4029 "Route-map to modify the attributes\n"
4030 "Name of the route map\n")
4031{
4032 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004033 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004034}
4035
4036DEFUN (bgp_network_backdoor,
4037 bgp_network_backdoor_cmd,
4038 "network A.B.C.D/M backdoor",
4039 "Specify a network to announce via BGP\n"
4040 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4041 "Specify a BGP backdoor route\n")
4042{
Paul Jakma41367172007-08-06 15:24:51 +00004043 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004044 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004045}
4046
4047DEFUN (bgp_network_mask,
4048 bgp_network_mask_cmd,
4049 "network A.B.C.D mask A.B.C.D",
4050 "Specify a network to announce via BGP\n"
4051 "Network number\n"
4052 "Network mask\n"
4053 "Network mask\n")
4054{
4055 int ret;
4056 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004057
paul718e3742002-12-13 20:15:29 +00004058 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4059 if (! ret)
4060 {
4061 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4062 return CMD_WARNING;
4063 }
4064
4065 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004066 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004067}
4068
4069DEFUN (bgp_network_mask_route_map,
4070 bgp_network_mask_route_map_cmd,
4071 "network A.B.C.D mask A.B.C.D route-map WORD",
4072 "Specify a network to announce via BGP\n"
4073 "Network number\n"
4074 "Network mask\n"
4075 "Network mask\n"
4076 "Route-map to modify the attributes\n"
4077 "Name of the route map\n")
4078{
4079 int ret;
4080 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004081
paul718e3742002-12-13 20:15:29 +00004082 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4083 if (! ret)
4084 {
4085 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4086 return CMD_WARNING;
4087 }
4088
4089 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004090 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004091}
4092
4093DEFUN (bgp_network_mask_backdoor,
4094 bgp_network_mask_backdoor_cmd,
4095 "network A.B.C.D mask A.B.C.D backdoor",
4096 "Specify a network to announce via BGP\n"
4097 "Network number\n"
4098 "Network mask\n"
4099 "Network mask\n"
4100 "Specify a BGP backdoor route\n")
4101{
4102 int ret;
4103 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004104
paul718e3742002-12-13 20:15:29 +00004105 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4106 if (! ret)
4107 {
4108 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4109 return CMD_WARNING;
4110 }
4111
Paul Jakma41367172007-08-06 15:24:51 +00004112 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004113 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004114}
4115
4116DEFUN (bgp_network_mask_natural,
4117 bgp_network_mask_natural_cmd,
4118 "network A.B.C.D",
4119 "Specify a network to announce via BGP\n"
4120 "Network number\n")
4121{
4122 int ret;
4123 char prefix_str[BUFSIZ];
4124
4125 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4126 if (! ret)
4127 {
4128 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4129 return CMD_WARNING;
4130 }
4131
4132 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004133 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004134}
4135
4136DEFUN (bgp_network_mask_natural_route_map,
4137 bgp_network_mask_natural_route_map_cmd,
4138 "network A.B.C.D route-map WORD",
4139 "Specify a network to announce via BGP\n"
4140 "Network number\n"
4141 "Route-map to modify the attributes\n"
4142 "Name of the route map\n")
4143{
4144 int ret;
4145 char prefix_str[BUFSIZ];
4146
4147 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4148 if (! ret)
4149 {
4150 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4151 return CMD_WARNING;
4152 }
4153
4154 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004155 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004156}
4157
4158DEFUN (bgp_network_mask_natural_backdoor,
4159 bgp_network_mask_natural_backdoor_cmd,
4160 "network A.B.C.D backdoor",
4161 "Specify a network to announce via BGP\n"
4162 "Network number\n"
4163 "Specify a BGP backdoor route\n")
4164{
4165 int ret;
4166 char prefix_str[BUFSIZ];
4167
4168 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4169 if (! ret)
4170 {
4171 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4172 return CMD_WARNING;
4173 }
4174
Paul Jakma41367172007-08-06 15:24:51 +00004175 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004176 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004177}
4178
4179DEFUN (no_bgp_network,
4180 no_bgp_network_cmd,
4181 "no network A.B.C.D/M",
4182 NO_STR
4183 "Specify a network to announce via BGP\n"
4184 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4185{
4186 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4187 bgp_node_safi (vty));
4188}
4189
4190ALIAS (no_bgp_network,
4191 no_bgp_network_route_map_cmd,
4192 "no network A.B.C.D/M route-map WORD",
4193 NO_STR
4194 "Specify a network to announce via BGP\n"
4195 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4196 "Route-map to modify the attributes\n"
4197 "Name of the route map\n")
4198
4199ALIAS (no_bgp_network,
4200 no_bgp_network_backdoor_cmd,
4201 "no network A.B.C.D/M backdoor",
4202 NO_STR
4203 "Specify a network to announce via BGP\n"
4204 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4205 "Specify a BGP backdoor route\n")
4206
4207DEFUN (no_bgp_network_mask,
4208 no_bgp_network_mask_cmd,
4209 "no network A.B.C.D mask A.B.C.D",
4210 NO_STR
4211 "Specify a network to announce via BGP\n"
4212 "Network number\n"
4213 "Network mask\n"
4214 "Network mask\n")
4215{
4216 int ret;
4217 char prefix_str[BUFSIZ];
4218
4219 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4220 if (! ret)
4221 {
4222 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4223 return CMD_WARNING;
4224 }
4225
4226 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4227 bgp_node_safi (vty));
4228}
4229
4230ALIAS (no_bgp_network_mask,
4231 no_bgp_network_mask_route_map_cmd,
4232 "no network A.B.C.D mask A.B.C.D route-map WORD",
4233 NO_STR
4234 "Specify a network to announce via BGP\n"
4235 "Network number\n"
4236 "Network mask\n"
4237 "Network mask\n"
4238 "Route-map to modify the attributes\n"
4239 "Name of the route map\n")
4240
4241ALIAS (no_bgp_network_mask,
4242 no_bgp_network_mask_backdoor_cmd,
4243 "no network A.B.C.D mask A.B.C.D backdoor",
4244 NO_STR
4245 "Specify a network to announce via BGP\n"
4246 "Network number\n"
4247 "Network mask\n"
4248 "Network mask\n"
4249 "Specify a BGP backdoor route\n")
4250
4251DEFUN (no_bgp_network_mask_natural,
4252 no_bgp_network_mask_natural_cmd,
4253 "no network A.B.C.D",
4254 NO_STR
4255 "Specify a network to announce via BGP\n"
4256 "Network number\n")
4257{
4258 int ret;
4259 char prefix_str[BUFSIZ];
4260
4261 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4262 if (! ret)
4263 {
4264 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4265 return CMD_WARNING;
4266 }
4267
4268 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4269 bgp_node_safi (vty));
4270}
4271
4272ALIAS (no_bgp_network_mask_natural,
4273 no_bgp_network_mask_natural_route_map_cmd,
4274 "no network A.B.C.D route-map WORD",
4275 NO_STR
4276 "Specify a network to announce via BGP\n"
4277 "Network number\n"
4278 "Route-map to modify the attributes\n"
4279 "Name of the route map\n")
4280
4281ALIAS (no_bgp_network_mask_natural,
4282 no_bgp_network_mask_natural_backdoor_cmd,
4283 "no network A.B.C.D backdoor",
4284 NO_STR
4285 "Specify a network to announce via BGP\n"
4286 "Network number\n"
4287 "Specify a BGP backdoor route\n")
4288
4289#ifdef HAVE_IPV6
4290DEFUN (ipv6_bgp_network,
4291 ipv6_bgp_network_cmd,
4292 "network X:X::X:X/M",
4293 "Specify a network to announce via BGP\n"
4294 "IPv6 prefix <network>/<length>\n")
4295{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304296 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004297 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004298}
4299
4300DEFUN (ipv6_bgp_network_route_map,
4301 ipv6_bgp_network_route_map_cmd,
4302 "network X:X::X:X/M route-map WORD",
4303 "Specify a network to announce via BGP\n"
4304 "IPv6 prefix <network>/<length>\n"
4305 "Route-map to modify the attributes\n"
4306 "Name of the route map\n")
4307{
4308 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004309 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004310}
4311
4312DEFUN (no_ipv6_bgp_network,
4313 no_ipv6_bgp_network_cmd,
4314 "no network X:X::X:X/M",
4315 NO_STR
4316 "Specify a network to announce via BGP\n"
4317 "IPv6 prefix <network>/<length>\n")
4318{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304319 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004320}
4321
4322ALIAS (no_ipv6_bgp_network,
4323 no_ipv6_bgp_network_route_map_cmd,
4324 "no network X:X::X:X/M route-map WORD",
4325 NO_STR
4326 "Specify a network to announce via BGP\n"
4327 "IPv6 prefix <network>/<length>\n"
4328 "Route-map to modify the attributes\n"
4329 "Name of the route map\n")
4330
4331ALIAS (ipv6_bgp_network,
4332 old_ipv6_bgp_network_cmd,
4333 "ipv6 bgp network X:X::X:X/M",
4334 IPV6_STR
4335 BGP_STR
4336 "Specify a network to announce via BGP\n"
4337 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4338
4339ALIAS (no_ipv6_bgp_network,
4340 old_no_ipv6_bgp_network_cmd,
4341 "no ipv6 bgp network X:X::X:X/M",
4342 NO_STR
4343 IPV6_STR
4344 BGP_STR
4345 "Specify a network to announce via BGP\n"
4346 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4347#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004348
4349/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4350ALIAS_DEPRECATED (bgp_network,
4351 bgp_network_ttl_cmd,
4352 "network A.B.C.D/M pathlimit <0-255>",
4353 "Specify a network to announce via BGP\n"
4354 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4355 "AS-Path hopcount limit attribute\n"
4356 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4357ALIAS_DEPRECATED (bgp_network_backdoor,
4358 bgp_network_backdoor_ttl_cmd,
4359 "network A.B.C.D/M backdoor pathlimit <0-255>",
4360 "Specify a network to announce via BGP\n"
4361 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4362 "Specify a BGP backdoor route\n"
4363 "AS-Path hopcount limit attribute\n"
4364 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4365ALIAS_DEPRECATED (bgp_network_mask,
4366 bgp_network_mask_ttl_cmd,
4367 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4368 "Specify a network to announce via BGP\n"
4369 "Network number\n"
4370 "Network mask\n"
4371 "Network mask\n"
4372 "AS-Path hopcount limit attribute\n"
4373 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4374ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4375 bgp_network_mask_backdoor_ttl_cmd,
4376 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4377 "Specify a network to announce via BGP\n"
4378 "Network number\n"
4379 "Network mask\n"
4380 "Network mask\n"
4381 "Specify a BGP backdoor route\n"
4382 "AS-Path hopcount limit attribute\n"
4383 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4384ALIAS_DEPRECATED (bgp_network_mask_natural,
4385 bgp_network_mask_natural_ttl_cmd,
4386 "network A.B.C.D pathlimit <0-255>",
4387 "Specify a network to announce via BGP\n"
4388 "Network number\n"
4389 "AS-Path hopcount limit attribute\n"
4390 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4391ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4392 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004393 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004394 "Specify a network to announce via BGP\n"
4395 "Network number\n"
4396 "Specify a BGP backdoor route\n"
4397 "AS-Path hopcount limit attribute\n"
4398 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4399ALIAS_DEPRECATED (no_bgp_network,
4400 no_bgp_network_ttl_cmd,
4401 "no network A.B.C.D/M pathlimit <0-255>",
4402 NO_STR
4403 "Specify a network to announce via BGP\n"
4404 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4405 "AS-Path hopcount limit attribute\n"
4406 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4407ALIAS_DEPRECATED (no_bgp_network,
4408 no_bgp_network_backdoor_ttl_cmd,
4409 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4410 NO_STR
4411 "Specify a network to announce via BGP\n"
4412 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4413 "Specify a BGP backdoor route\n"
4414 "AS-Path hopcount limit attribute\n"
4415 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4416ALIAS_DEPRECATED (no_bgp_network,
4417 no_bgp_network_mask_ttl_cmd,
4418 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4419 NO_STR
4420 "Specify a network to announce via BGP\n"
4421 "Network number\n"
4422 "Network mask\n"
4423 "Network mask\n"
4424 "AS-Path hopcount limit attribute\n"
4425 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4426ALIAS_DEPRECATED (no_bgp_network_mask,
4427 no_bgp_network_mask_backdoor_ttl_cmd,
4428 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4429 NO_STR
4430 "Specify a network to announce via BGP\n"
4431 "Network number\n"
4432 "Network mask\n"
4433 "Network mask\n"
4434 "Specify a BGP backdoor route\n"
4435 "AS-Path hopcount limit attribute\n"
4436 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4437ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4438 no_bgp_network_mask_natural_ttl_cmd,
4439 "no network A.B.C.D pathlimit <0-255>",
4440 NO_STR
4441 "Specify a network to announce via BGP\n"
4442 "Network number\n"
4443 "AS-Path hopcount limit attribute\n"
4444 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4445ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4446 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4447 "no network A.B.C.D backdoor pathlimit <0-255>",
4448 NO_STR
4449 "Specify a network to announce via BGP\n"
4450 "Network number\n"
4451 "Specify a BGP backdoor route\n"
4452 "AS-Path hopcount limit attribute\n"
4453 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004454#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004455ALIAS_DEPRECATED (ipv6_bgp_network,
4456 ipv6_bgp_network_ttl_cmd,
4457 "network X:X::X:X/M pathlimit <0-255>",
4458 "Specify a network to announce via BGP\n"
4459 "IPv6 prefix <network>/<length>\n"
4460 "AS-Path hopcount limit attribute\n"
4461 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4462ALIAS_DEPRECATED (no_ipv6_bgp_network,
4463 no_ipv6_bgp_network_ttl_cmd,
4464 "no network X:X::X:X/M pathlimit <0-255>",
4465 NO_STR
4466 "Specify a network to announce via BGP\n"
4467 "IPv6 prefix <network>/<length>\n"
4468 "AS-Path hopcount limit attribute\n"
4469 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004470#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02004471
paul718e3742002-12-13 20:15:29 +00004472/* Aggreagete address:
4473
4474 advertise-map Set condition to advertise attribute
4475 as-set Generate AS set path information
4476 attribute-map Set attributes of aggregate
4477 route-map Set parameters of aggregate
4478 summary-only Filter more specific routes from updates
4479 suppress-map Conditionally filter more specific routes from updates
4480 <cr>
4481 */
4482struct bgp_aggregate
4483{
4484 /* Summary-only flag. */
4485 u_char summary_only;
4486
4487 /* AS set generation. */
4488 u_char as_set;
4489
4490 /* Route-map for aggregated route. */
4491 struct route_map *map;
4492
4493 /* Suppress-count. */
4494 unsigned long count;
4495
4496 /* SAFI configuration. */
4497 safi_t safi;
4498};
4499
paul94f2b392005-06-28 12:44:16 +00004500static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004501bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004502{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004503 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004504}
4505
paul94f2b392005-06-28 12:44:16 +00004506static void
paul718e3742002-12-13 20:15:29 +00004507bgp_aggregate_free (struct bgp_aggregate *aggregate)
4508{
4509 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4510}
4511
paul94f2b392005-06-28 12:44:16 +00004512static void
paul718e3742002-12-13 20:15:29 +00004513bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4514 afi_t afi, safi_t safi, struct bgp_info *del,
4515 struct bgp_aggregate *aggregate)
4516{
4517 struct bgp_table *table;
4518 struct bgp_node *top;
4519 struct bgp_node *rn;
4520 u_char origin;
4521 struct aspath *aspath = NULL;
4522 struct aspath *asmerge = NULL;
4523 struct community *community = NULL;
4524 struct community *commerge = NULL;
4525 struct in_addr nexthop;
4526 u_int32_t med = 0;
4527 struct bgp_info *ri;
4528 struct bgp_info *new;
4529 int first = 1;
4530 unsigned long match = 0;
4531
4532 /* Record adding route's nexthop and med. */
4533 if (rinew)
4534 {
4535 nexthop = rinew->attr->nexthop;
4536 med = rinew->attr->med;
4537 }
4538
4539 /* ORIGIN attribute: If at least one route among routes that are
4540 aggregated has ORIGIN with the value INCOMPLETE, then the
4541 aggregated route must have the ORIGIN attribute with the value
4542 INCOMPLETE. Otherwise, if at least one route among routes that
4543 are aggregated has ORIGIN with the value EGP, then the aggregated
4544 route must have the origin attribute with the value EGP. In all
4545 other case the value of the ORIGIN attribute of the aggregated
4546 route is INTERNAL. */
4547 origin = BGP_ORIGIN_IGP;
4548
4549 table = bgp->rib[afi][safi];
4550
4551 top = bgp_node_get (table, p);
4552 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4553 if (rn->p.prefixlen > p->prefixlen)
4554 {
4555 match = 0;
4556
4557 for (ri = rn->info; ri; ri = ri->next)
4558 {
4559 if (BGP_INFO_HOLDDOWN (ri))
4560 continue;
4561
4562 if (del && ri == del)
4563 continue;
4564
4565 if (! rinew && first)
4566 {
4567 nexthop = ri->attr->nexthop;
4568 med = ri->attr->med;
4569 first = 0;
4570 }
4571
4572#ifdef AGGREGATE_NEXTHOP_CHECK
4573 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4574 || ri->attr->med != med)
4575 {
4576 if (aspath)
4577 aspath_free (aspath);
4578 if (community)
4579 community_free (community);
4580 bgp_unlock_node (rn);
4581 bgp_unlock_node (top);
4582 return;
4583 }
4584#endif /* AGGREGATE_NEXTHOP_CHECK */
4585
4586 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4587 {
4588 if (aggregate->summary_only)
4589 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004590 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004591 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004592 match++;
4593 }
4594
4595 aggregate->count++;
4596
4597 if (aggregate->as_set)
4598 {
4599 if (origin < ri->attr->origin)
4600 origin = ri->attr->origin;
4601
4602 if (aspath)
4603 {
4604 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4605 aspath_free (aspath);
4606 aspath = asmerge;
4607 }
4608 else
4609 aspath = aspath_dup (ri->attr->aspath);
4610
4611 if (ri->attr->community)
4612 {
4613 if (community)
4614 {
4615 commerge = community_merge (community,
4616 ri->attr->community);
4617 community = community_uniq_sort (commerge);
4618 community_free (commerge);
4619 }
4620 else
4621 community = community_dup (ri->attr->community);
4622 }
4623 }
4624 }
4625 }
4626 if (match)
4627 bgp_process (bgp, rn, afi, safi);
4628 }
4629 bgp_unlock_node (top);
4630
4631 if (rinew)
4632 {
4633 aggregate->count++;
4634
4635 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004636 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004637
4638 if (aggregate->as_set)
4639 {
4640 if (origin < rinew->attr->origin)
4641 origin = rinew->attr->origin;
4642
4643 if (aspath)
4644 {
4645 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4646 aspath_free (aspath);
4647 aspath = asmerge;
4648 }
4649 else
4650 aspath = aspath_dup (rinew->attr->aspath);
4651
4652 if (rinew->attr->community)
4653 {
4654 if (community)
4655 {
4656 commerge = community_merge (community,
4657 rinew->attr->community);
4658 community = community_uniq_sort (commerge);
4659 community_free (commerge);
4660 }
4661 else
4662 community = community_dup (rinew->attr->community);
4663 }
4664 }
4665 }
4666
4667 if (aggregate->count > 0)
4668 {
4669 rn = bgp_node_get (table, p);
4670 new = bgp_info_new ();
4671 new->type = ZEBRA_ROUTE_BGP;
4672 new->sub_type = BGP_ROUTE_AGGREGATE;
4673 new->peer = bgp->peer_self;
4674 SET_FLAG (new->flags, BGP_INFO_VALID);
4675 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004676 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004677
4678 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004679 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004680 bgp_process (bgp, rn, afi, safi);
4681 }
4682 else
4683 {
4684 if (aspath)
4685 aspath_free (aspath);
4686 if (community)
4687 community_free (community);
4688 }
4689}
4690
4691void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4692 struct bgp_aggregate *);
4693
4694void
4695bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4696 struct bgp_info *ri, afi_t afi, safi_t safi)
4697{
4698 struct bgp_node *child;
4699 struct bgp_node *rn;
4700 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004701 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004702
4703 /* MPLS-VPN aggregation is not yet supported. */
4704 if (safi == SAFI_MPLS_VPN)
4705 return;
4706
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004707 table = bgp->aggregate[afi][safi];
4708
4709 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004710 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004711 return;
4712
paul718e3742002-12-13 20:15:29 +00004713 if (p->prefixlen == 0)
4714 return;
4715
4716 if (BGP_INFO_HOLDDOWN (ri))
4717 return;
4718
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004719 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004720
4721 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004722 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004723 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4724 {
4725 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004726 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004727 }
4728 bgp_unlock_node (child);
4729}
4730
4731void
4732bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4733 struct bgp_info *del, afi_t afi, safi_t safi)
4734{
4735 struct bgp_node *child;
4736 struct bgp_node *rn;
4737 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004738 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004739
4740 /* MPLS-VPN aggregation is not yet supported. */
4741 if (safi == SAFI_MPLS_VPN)
4742 return;
4743
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004744 table = bgp->aggregate[afi][safi];
4745
4746 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004747 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004748 return;
4749
paul718e3742002-12-13 20:15:29 +00004750 if (p->prefixlen == 0)
4751 return;
4752
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004753 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004754
4755 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004756 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004757 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4758 {
4759 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004760 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004761 }
4762 bgp_unlock_node (child);
4763}
4764
paul94f2b392005-06-28 12:44:16 +00004765static void
paul718e3742002-12-13 20:15:29 +00004766bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4767 struct bgp_aggregate *aggregate)
4768{
4769 struct bgp_table *table;
4770 struct bgp_node *top;
4771 struct bgp_node *rn;
4772 struct bgp_info *new;
4773 struct bgp_info *ri;
4774 unsigned long match;
4775 u_char origin = BGP_ORIGIN_IGP;
4776 struct aspath *aspath = NULL;
4777 struct aspath *asmerge = NULL;
4778 struct community *community = NULL;
4779 struct community *commerge = NULL;
4780
4781 table = bgp->rib[afi][safi];
4782
4783 /* Sanity check. */
4784 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4785 return;
4786 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4787 return;
4788
4789 /* If routes exists below this node, generate aggregate routes. */
4790 top = bgp_node_get (table, p);
4791 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4792 if (rn->p.prefixlen > p->prefixlen)
4793 {
4794 match = 0;
4795
4796 for (ri = rn->info; ri; ri = ri->next)
4797 {
4798 if (BGP_INFO_HOLDDOWN (ri))
4799 continue;
4800
4801 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4802 {
4803 /* summary-only aggregate route suppress aggregated
4804 route announcement. */
4805 if (aggregate->summary_only)
4806 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004807 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004808 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004809 match++;
4810 }
4811 /* as-set aggregate route generate origin, as path,
4812 community aggregation. */
4813 if (aggregate->as_set)
4814 {
4815 if (origin < ri->attr->origin)
4816 origin = ri->attr->origin;
4817
4818 if (aspath)
4819 {
4820 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4821 aspath_free (aspath);
4822 aspath = asmerge;
4823 }
4824 else
4825 aspath = aspath_dup (ri->attr->aspath);
4826
4827 if (ri->attr->community)
4828 {
4829 if (community)
4830 {
4831 commerge = community_merge (community,
4832 ri->attr->community);
4833 community = community_uniq_sort (commerge);
4834 community_free (commerge);
4835 }
4836 else
4837 community = community_dup (ri->attr->community);
4838 }
4839 }
4840 aggregate->count++;
4841 }
4842 }
4843
4844 /* If this node is suppressed, process the change. */
4845 if (match)
4846 bgp_process (bgp, rn, afi, safi);
4847 }
4848 bgp_unlock_node (top);
4849
4850 /* Add aggregate route to BGP table. */
4851 if (aggregate->count)
4852 {
4853 rn = bgp_node_get (table, p);
4854
4855 new = bgp_info_new ();
4856 new->type = ZEBRA_ROUTE_BGP;
4857 new->sub_type = BGP_ROUTE_AGGREGATE;
4858 new->peer = bgp->peer_self;
4859 SET_FLAG (new->flags, BGP_INFO_VALID);
4860 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004861 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004862
4863 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004864 bgp_unlock_node (rn);
4865
paul718e3742002-12-13 20:15:29 +00004866 /* Process change. */
4867 bgp_process (bgp, rn, afi, safi);
4868 }
4869}
4870
4871void
4872bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4873 safi_t safi, struct bgp_aggregate *aggregate)
4874{
4875 struct bgp_table *table;
4876 struct bgp_node *top;
4877 struct bgp_node *rn;
4878 struct bgp_info *ri;
4879 unsigned long match;
4880
4881 table = bgp->rib[afi][safi];
4882
4883 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4884 return;
4885 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4886 return;
4887
4888 /* If routes exists below this node, generate aggregate routes. */
4889 top = bgp_node_get (table, p);
4890 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4891 if (rn->p.prefixlen > p->prefixlen)
4892 {
4893 match = 0;
4894
4895 for (ri = rn->info; ri; ri = ri->next)
4896 {
4897 if (BGP_INFO_HOLDDOWN (ri))
4898 continue;
4899
4900 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4901 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004902 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004903 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004904 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004905
Paul Jakmafb982c22007-05-04 20:15:47 +00004906 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004907 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004908 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004909 match++;
4910 }
4911 }
4912 aggregate->count--;
4913 }
4914 }
4915
Paul Jakmafb982c22007-05-04 20:15:47 +00004916 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004917 if (match)
4918 bgp_process (bgp, rn, afi, safi);
4919 }
4920 bgp_unlock_node (top);
4921
4922 /* Delete aggregate route from BGP table. */
4923 rn = bgp_node_get (table, p);
4924
4925 for (ri = rn->info; ri; ri = ri->next)
4926 if (ri->peer == bgp->peer_self
4927 && ri->type == ZEBRA_ROUTE_BGP
4928 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4929 break;
4930
4931 /* Withdraw static BGP route from routing table. */
4932 if (ri)
4933 {
paul718e3742002-12-13 20:15:29 +00004934 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004935 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004936 }
4937
4938 /* Unlock bgp_node_lookup. */
4939 bgp_unlock_node (rn);
4940}
4941
4942/* Aggregate route attribute. */
4943#define AGGREGATE_SUMMARY_ONLY 1
4944#define AGGREGATE_AS_SET 1
4945
paul94f2b392005-06-28 12:44:16 +00004946static int
Robert Baysf6269b42010-08-05 10:26:28 -07004947bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4948 afi_t afi, safi_t safi)
4949{
4950 int ret;
4951 struct prefix p;
4952 struct bgp_node *rn;
4953 struct bgp *bgp;
4954 struct bgp_aggregate *aggregate;
4955
4956 /* Convert string to prefix structure. */
4957 ret = str2prefix (prefix_str, &p);
4958 if (!ret)
4959 {
4960 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4961 return CMD_WARNING;
4962 }
4963 apply_mask (&p);
4964
4965 /* Get BGP structure. */
4966 bgp = vty->index;
4967
4968 /* Old configuration check. */
4969 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4970 if (! rn)
4971 {
4972 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4973 VTY_NEWLINE);
4974 return CMD_WARNING;
4975 }
4976
4977 aggregate = rn->info;
4978 if (aggregate->safi & SAFI_UNICAST)
4979 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4980 if (aggregate->safi & SAFI_MULTICAST)
4981 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4982
4983 /* Unlock aggregate address configuration. */
4984 rn->info = NULL;
4985 bgp_aggregate_free (aggregate);
4986 bgp_unlock_node (rn);
4987 bgp_unlock_node (rn);
4988
4989 return CMD_SUCCESS;
4990}
4991
4992static int
4993bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00004994 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004995 u_char summary_only, u_char as_set)
4996{
4997 int ret;
4998 struct prefix p;
4999 struct bgp_node *rn;
5000 struct bgp *bgp;
5001 struct bgp_aggregate *aggregate;
5002
5003 /* Convert string to prefix structure. */
5004 ret = str2prefix (prefix_str, &p);
5005 if (!ret)
5006 {
5007 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5008 return CMD_WARNING;
5009 }
5010 apply_mask (&p);
5011
5012 /* Get BGP structure. */
5013 bgp = vty->index;
5014
5015 /* Old configuration check. */
5016 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5017
5018 if (rn->info)
5019 {
5020 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005021 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005022 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5023 if (ret)
5024 {
Robert Bays368473f2010-08-05 10:26:29 -07005025 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5026 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005027 return CMD_WARNING;
5028 }
paul718e3742002-12-13 20:15:29 +00005029 }
5030
5031 /* Make aggregate address structure. */
5032 aggregate = bgp_aggregate_new ();
5033 aggregate->summary_only = summary_only;
5034 aggregate->as_set = as_set;
5035 aggregate->safi = safi;
5036 rn->info = aggregate;
5037
5038 /* Aggregate address insert into BGP routing table. */
5039 if (safi & SAFI_UNICAST)
5040 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5041 if (safi & SAFI_MULTICAST)
5042 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5043
5044 return CMD_SUCCESS;
5045}
5046
paul718e3742002-12-13 20:15:29 +00005047DEFUN (aggregate_address,
5048 aggregate_address_cmd,
5049 "aggregate-address A.B.C.D/M",
5050 "Configure BGP aggregate entries\n"
5051 "Aggregate prefix\n")
5052{
5053 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5054}
5055
5056DEFUN (aggregate_address_mask,
5057 aggregate_address_mask_cmd,
5058 "aggregate-address A.B.C.D A.B.C.D",
5059 "Configure BGP aggregate entries\n"
5060 "Aggregate address\n"
5061 "Aggregate mask\n")
5062{
5063 int ret;
5064 char prefix_str[BUFSIZ];
5065
5066 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5067
5068 if (! ret)
5069 {
5070 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5071 return CMD_WARNING;
5072 }
5073
5074 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5075 0, 0);
5076}
5077
5078DEFUN (aggregate_address_summary_only,
5079 aggregate_address_summary_only_cmd,
5080 "aggregate-address A.B.C.D/M summary-only",
5081 "Configure BGP aggregate entries\n"
5082 "Aggregate prefix\n"
5083 "Filter more specific routes from updates\n")
5084{
5085 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5086 AGGREGATE_SUMMARY_ONLY, 0);
5087}
5088
5089DEFUN (aggregate_address_mask_summary_only,
5090 aggregate_address_mask_summary_only_cmd,
5091 "aggregate-address A.B.C.D A.B.C.D summary-only",
5092 "Configure BGP aggregate entries\n"
5093 "Aggregate address\n"
5094 "Aggregate mask\n"
5095 "Filter more specific routes from updates\n")
5096{
5097 int ret;
5098 char prefix_str[BUFSIZ];
5099
5100 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5101
5102 if (! ret)
5103 {
5104 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5105 return CMD_WARNING;
5106 }
5107
5108 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5109 AGGREGATE_SUMMARY_ONLY, 0);
5110}
5111
5112DEFUN (aggregate_address_as_set,
5113 aggregate_address_as_set_cmd,
5114 "aggregate-address A.B.C.D/M as-set",
5115 "Configure BGP aggregate entries\n"
5116 "Aggregate prefix\n"
5117 "Generate AS set path information\n")
5118{
5119 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5120 0, AGGREGATE_AS_SET);
5121}
5122
5123DEFUN (aggregate_address_mask_as_set,
5124 aggregate_address_mask_as_set_cmd,
5125 "aggregate-address A.B.C.D A.B.C.D as-set",
5126 "Configure BGP aggregate entries\n"
5127 "Aggregate address\n"
5128 "Aggregate mask\n"
5129 "Generate AS set path information\n")
5130{
5131 int ret;
5132 char prefix_str[BUFSIZ];
5133
5134 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5135
5136 if (! ret)
5137 {
5138 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5139 return CMD_WARNING;
5140 }
5141
5142 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5143 0, AGGREGATE_AS_SET);
5144}
5145
5146
5147DEFUN (aggregate_address_as_set_summary,
5148 aggregate_address_as_set_summary_cmd,
5149 "aggregate-address A.B.C.D/M as-set summary-only",
5150 "Configure BGP aggregate entries\n"
5151 "Aggregate prefix\n"
5152 "Generate AS set path information\n"
5153 "Filter more specific routes from updates\n")
5154{
5155 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5156 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5157}
5158
5159ALIAS (aggregate_address_as_set_summary,
5160 aggregate_address_summary_as_set_cmd,
5161 "aggregate-address A.B.C.D/M summary-only as-set",
5162 "Configure BGP aggregate entries\n"
5163 "Aggregate prefix\n"
5164 "Filter more specific routes from updates\n"
5165 "Generate AS set path information\n")
5166
5167DEFUN (aggregate_address_mask_as_set_summary,
5168 aggregate_address_mask_as_set_summary_cmd,
5169 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5170 "Configure BGP aggregate entries\n"
5171 "Aggregate address\n"
5172 "Aggregate mask\n"
5173 "Generate AS set path information\n"
5174 "Filter more specific routes from updates\n")
5175{
5176 int ret;
5177 char prefix_str[BUFSIZ];
5178
5179 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5180
5181 if (! ret)
5182 {
5183 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5184 return CMD_WARNING;
5185 }
5186
5187 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5188 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5189}
5190
5191ALIAS (aggregate_address_mask_as_set_summary,
5192 aggregate_address_mask_summary_as_set_cmd,
5193 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5194 "Configure BGP aggregate entries\n"
5195 "Aggregate address\n"
5196 "Aggregate mask\n"
5197 "Filter more specific routes from updates\n"
5198 "Generate AS set path information\n")
5199
5200DEFUN (no_aggregate_address,
5201 no_aggregate_address_cmd,
5202 "no aggregate-address A.B.C.D/M",
5203 NO_STR
5204 "Configure BGP aggregate entries\n"
5205 "Aggregate prefix\n")
5206{
5207 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5208}
5209
5210ALIAS (no_aggregate_address,
5211 no_aggregate_address_summary_only_cmd,
5212 "no aggregate-address A.B.C.D/M summary-only",
5213 NO_STR
5214 "Configure BGP aggregate entries\n"
5215 "Aggregate prefix\n"
5216 "Filter more specific routes from updates\n")
5217
5218ALIAS (no_aggregate_address,
5219 no_aggregate_address_as_set_cmd,
5220 "no aggregate-address A.B.C.D/M as-set",
5221 NO_STR
5222 "Configure BGP aggregate entries\n"
5223 "Aggregate prefix\n"
5224 "Generate AS set path information\n")
5225
5226ALIAS (no_aggregate_address,
5227 no_aggregate_address_as_set_summary_cmd,
5228 "no aggregate-address A.B.C.D/M as-set summary-only",
5229 NO_STR
5230 "Configure BGP aggregate entries\n"
5231 "Aggregate prefix\n"
5232 "Generate AS set path information\n"
5233 "Filter more specific routes from updates\n")
5234
5235ALIAS (no_aggregate_address,
5236 no_aggregate_address_summary_as_set_cmd,
5237 "no aggregate-address A.B.C.D/M summary-only as-set",
5238 NO_STR
5239 "Configure BGP aggregate entries\n"
5240 "Aggregate prefix\n"
5241 "Filter more specific routes from updates\n"
5242 "Generate AS set path information\n")
5243
5244DEFUN (no_aggregate_address_mask,
5245 no_aggregate_address_mask_cmd,
5246 "no aggregate-address A.B.C.D A.B.C.D",
5247 NO_STR
5248 "Configure BGP aggregate entries\n"
5249 "Aggregate address\n"
5250 "Aggregate mask\n")
5251{
5252 int ret;
5253 char prefix_str[BUFSIZ];
5254
5255 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5256
5257 if (! ret)
5258 {
5259 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5260 return CMD_WARNING;
5261 }
5262
5263 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5264}
5265
5266ALIAS (no_aggregate_address_mask,
5267 no_aggregate_address_mask_summary_only_cmd,
5268 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5269 NO_STR
5270 "Configure BGP aggregate entries\n"
5271 "Aggregate address\n"
5272 "Aggregate mask\n"
5273 "Filter more specific routes from updates\n")
5274
5275ALIAS (no_aggregate_address_mask,
5276 no_aggregate_address_mask_as_set_cmd,
5277 "no aggregate-address A.B.C.D A.B.C.D as-set",
5278 NO_STR
5279 "Configure BGP aggregate entries\n"
5280 "Aggregate address\n"
5281 "Aggregate mask\n"
5282 "Generate AS set path information\n")
5283
5284ALIAS (no_aggregate_address_mask,
5285 no_aggregate_address_mask_as_set_summary_cmd,
5286 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5287 NO_STR
5288 "Configure BGP aggregate entries\n"
5289 "Aggregate address\n"
5290 "Aggregate mask\n"
5291 "Generate AS set path information\n"
5292 "Filter more specific routes from updates\n")
5293
5294ALIAS (no_aggregate_address_mask,
5295 no_aggregate_address_mask_summary_as_set_cmd,
5296 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5297 NO_STR
5298 "Configure BGP aggregate entries\n"
5299 "Aggregate address\n"
5300 "Aggregate mask\n"
5301 "Filter more specific routes from updates\n"
5302 "Generate AS set path information\n")
5303
5304#ifdef HAVE_IPV6
5305DEFUN (ipv6_aggregate_address,
5306 ipv6_aggregate_address_cmd,
5307 "aggregate-address X:X::X:X/M",
5308 "Configure BGP aggregate entries\n"
5309 "Aggregate prefix\n")
5310{
5311 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5312}
5313
5314DEFUN (ipv6_aggregate_address_summary_only,
5315 ipv6_aggregate_address_summary_only_cmd,
5316 "aggregate-address X:X::X:X/M summary-only",
5317 "Configure BGP aggregate entries\n"
5318 "Aggregate prefix\n"
5319 "Filter more specific routes from updates\n")
5320{
5321 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5322 AGGREGATE_SUMMARY_ONLY, 0);
5323}
5324
5325DEFUN (no_ipv6_aggregate_address,
5326 no_ipv6_aggregate_address_cmd,
5327 "no aggregate-address X:X::X:X/M",
5328 NO_STR
5329 "Configure BGP aggregate entries\n"
5330 "Aggregate prefix\n")
5331{
5332 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5333}
5334
5335DEFUN (no_ipv6_aggregate_address_summary_only,
5336 no_ipv6_aggregate_address_summary_only_cmd,
5337 "no aggregate-address X:X::X:X/M summary-only",
5338 NO_STR
5339 "Configure BGP aggregate entries\n"
5340 "Aggregate prefix\n"
5341 "Filter more specific routes from updates\n")
5342{
5343 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5344}
5345
5346ALIAS (ipv6_aggregate_address,
5347 old_ipv6_aggregate_address_cmd,
5348 "ipv6 bgp aggregate-address X:X::X:X/M",
5349 IPV6_STR
5350 BGP_STR
5351 "Configure BGP aggregate entries\n"
5352 "Aggregate prefix\n")
5353
5354ALIAS (ipv6_aggregate_address_summary_only,
5355 old_ipv6_aggregate_address_summary_only_cmd,
5356 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5357 IPV6_STR
5358 BGP_STR
5359 "Configure BGP aggregate entries\n"
5360 "Aggregate prefix\n"
5361 "Filter more specific routes from updates\n")
5362
5363ALIAS (no_ipv6_aggregate_address,
5364 old_no_ipv6_aggregate_address_cmd,
5365 "no ipv6 bgp aggregate-address X:X::X:X/M",
5366 NO_STR
5367 IPV6_STR
5368 BGP_STR
5369 "Configure BGP aggregate entries\n"
5370 "Aggregate prefix\n")
5371
5372ALIAS (no_ipv6_aggregate_address_summary_only,
5373 old_no_ipv6_aggregate_address_summary_only_cmd,
5374 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5375 NO_STR
5376 IPV6_STR
5377 BGP_STR
5378 "Configure BGP aggregate entries\n"
5379 "Aggregate prefix\n"
5380 "Filter more specific routes from updates\n")
5381#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02005382
paul718e3742002-12-13 20:15:29 +00005383/* Redistribute route treatment. */
5384void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005385bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5386 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005387 u_int32_t metric, u_char type)
5388{
5389 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005390 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005391 struct bgp_info *new;
5392 struct bgp_info *bi;
5393 struct bgp_info info;
5394 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005395 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005396 struct attr *new_attr;
5397 afi_t afi;
5398 int ret;
5399
5400 /* Make default attribute. */
5401 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5402 if (nexthop)
5403 attr.nexthop = *nexthop;
5404
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005405#ifdef HAVE_IPV6
5406 if (nexthop6)
5407 {
5408 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5409 extra->mp_nexthop_global = *nexthop6;
5410 extra->mp_nexthop_len = 16;
5411 }
5412#endif
5413
paul718e3742002-12-13 20:15:29 +00005414 attr.med = metric;
5415 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5416
paul1eb8ef22005-04-07 07:30:20 +00005417 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005418 {
5419 afi = family2afi (p->family);
5420
5421 if (bgp->redist[afi][type])
5422 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005423 struct attr attr_new;
5424 struct attr_extra extra_new;
5425
paul718e3742002-12-13 20:15:29 +00005426 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005427 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005428 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005429
5430 if (bgp->redist_metric_flag[afi][type])
5431 attr_new.med = bgp->redist_metric[afi][type];
5432
5433 /* Apply route-map. */
5434 if (bgp->rmap[afi][type].map)
5435 {
5436 info.peer = bgp->peer_self;
5437 info.attr = &attr_new;
5438
paulfee0f4c2004-09-13 05:12:46 +00005439 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5440
paul718e3742002-12-13 20:15:29 +00005441 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5442 &info);
paulfee0f4c2004-09-13 05:12:46 +00005443
5444 bgp->peer_self->rmap_type = 0;
5445
paul718e3742002-12-13 20:15:29 +00005446 if (ret == RMAP_DENYMATCH)
5447 {
5448 /* Free uninterned attribute. */
5449 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005450
paul718e3742002-12-13 20:15:29 +00005451 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005452 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005453 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005454 bgp_redistribute_delete (p, type);
5455 return;
5456 }
5457 }
5458
Paul Jakmafb982c22007-05-04 20:15:47 +00005459 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5460 afi, SAFI_UNICAST, p, NULL);
5461
paul718e3742002-12-13 20:15:29 +00005462 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005463
paul718e3742002-12-13 20:15:29 +00005464 for (bi = bn->info; bi; bi = bi->next)
5465 if (bi->peer == bgp->peer_self
5466 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5467 break;
5468
5469 if (bi)
5470 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005471 if (attrhash_cmp (bi->attr, new_attr) &&
5472 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005473 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005474 bgp_attr_unintern (&new_attr);
5475 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005476 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005477 bgp_unlock_node (bn);
5478 return;
5479 }
5480 else
5481 {
5482 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005483 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005484
5485 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005486 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5487 bgp_info_restore(bn, bi);
5488 else
5489 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005490 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005491 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005492 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005493
5494 /* Process change. */
5495 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5496 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5497 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005498 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005499 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005500 return;
5501 }
5502 }
5503
5504 new = bgp_info_new ();
5505 new->type = type;
5506 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5507 new->peer = bgp->peer_self;
5508 SET_FLAG (new->flags, BGP_INFO_VALID);
5509 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005510 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005511
5512 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5513 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005514 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005515 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5516 }
5517 }
5518
5519 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005520 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005521 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005522}
5523
5524void
5525bgp_redistribute_delete (struct prefix *p, u_char type)
5526{
5527 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005528 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005529 afi_t afi;
5530 struct bgp_node *rn;
5531 struct bgp_info *ri;
5532
paul1eb8ef22005-04-07 07:30:20 +00005533 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005534 {
5535 afi = family2afi (p->family);
5536
5537 if (bgp->redist[afi][type])
5538 {
paulfee0f4c2004-09-13 05:12:46 +00005539 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005540
5541 for (ri = rn->info; ri; ri = ri->next)
5542 if (ri->peer == bgp->peer_self
5543 && ri->type == type)
5544 break;
5545
5546 if (ri)
5547 {
5548 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005549 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005550 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005551 }
5552 bgp_unlock_node (rn);
5553 }
5554 }
5555}
5556
5557/* Withdraw specified route type's route. */
5558void
5559bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5560{
5561 struct bgp_node *rn;
5562 struct bgp_info *ri;
5563 struct bgp_table *table;
5564
5565 table = bgp->rib[afi][SAFI_UNICAST];
5566
5567 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5568 {
5569 for (ri = rn->info; ri; ri = ri->next)
5570 if (ri->peer == bgp->peer_self
5571 && ri->type == type)
5572 break;
5573
5574 if (ri)
5575 {
5576 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005577 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005578 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005579 }
5580 }
5581}
David Lamparter6b0655a2014-06-04 06:53:35 +02005582
paul718e3742002-12-13 20:15:29 +00005583/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005584static void
paul718e3742002-12-13 20:15:29 +00005585route_vty_out_route (struct prefix *p, struct vty *vty)
5586{
5587 int len;
5588 u_int32_t destination;
5589 char buf[BUFSIZ];
5590
5591 if (p->family == AF_INET)
5592 {
5593 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5594 destination = ntohl (p->u.prefix4.s_addr);
5595
5596 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5597 || (IN_CLASSB (destination) && p->prefixlen == 16)
5598 || (IN_CLASSA (destination) && p->prefixlen == 8)
5599 || p->u.prefix4.s_addr == 0)
5600 {
5601 /* When mask is natural, mask is not displayed. */
5602 }
5603 else
5604 len += vty_out (vty, "/%d", p->prefixlen);
5605 }
5606 else
5607 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5608 p->prefixlen);
5609
5610 len = 17 - len;
5611 if (len < 1)
5612 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5613 else
5614 vty_out (vty, "%*s", len, " ");
5615}
5616
paul718e3742002-12-13 20:15:29 +00005617enum bgp_display_type
5618{
5619 normal_list,
5620};
5621
paulb40d9392005-08-22 22:34:41 +00005622/* Print the short form route status for a bgp_info */
5623static void
5624route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005625{
paulb40d9392005-08-22 22:34:41 +00005626 /* Route status display. */
5627 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5628 vty_out (vty, "R");
5629 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005630 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005631 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005632 vty_out (vty, "s");
5633 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5634 vty_out (vty, "*");
5635 else
5636 vty_out (vty, " ");
5637
5638 /* Selected */
5639 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5640 vty_out (vty, "h");
5641 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5642 vty_out (vty, "d");
5643 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5644 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005645 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5646 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005647 else
5648 vty_out (vty, " ");
5649
5650 /* Internal route. */
5651 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5652 vty_out (vty, "i");
5653 else
paulb40d9392005-08-22 22:34:41 +00005654 vty_out (vty, " ");
5655}
5656
5657/* called from terminal list command */
5658void
5659route_vty_out (struct vty *vty, struct prefix *p,
5660 struct bgp_info *binfo, int display, safi_t safi)
5661{
5662 struct attr *attr;
5663
5664 /* short status lead text */
5665 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005666
5667 /* print prefix and mask */
5668 if (! display)
5669 route_vty_out_route (p, vty);
5670 else
5671 vty_out (vty, "%*s", 17, " ");
5672
5673 /* Print attribute */
5674 attr = binfo->attr;
5675 if (attr)
5676 {
5677 if (p->family == AF_INET)
5678 {
5679 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005680 vty_out (vty, "%-16s",
5681 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005682 else
5683 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5684 }
5685#ifdef HAVE_IPV6
5686 else if (p->family == AF_INET6)
5687 {
5688 int len;
5689 char buf[BUFSIZ];
5690
5691 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005692 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5693 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005694 len = 16 - len;
5695 if (len < 1)
5696 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5697 else
5698 vty_out (vty, "%*s", len, " ");
5699 }
5700#endif /* HAVE_IPV6 */
5701
5702 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005703 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005704 else
5705 vty_out (vty, " ");
5706
5707 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005708 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005709 else
5710 vty_out (vty, " ");
5711
Paul Jakmafb982c22007-05-04 20:15:47 +00005712 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005713
Paul Jakmab2518c12006-05-12 23:48:40 +00005714 /* Print aspath */
5715 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005716 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005717
Paul Jakmab2518c12006-05-12 23:48:40 +00005718 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005719 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005720 }
paul718e3742002-12-13 20:15:29 +00005721 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005722}
5723
5724/* called from terminal list command */
5725void
5726route_vty_out_tmp (struct vty *vty, struct prefix *p,
5727 struct attr *attr, safi_t safi)
5728{
5729 /* Route status display. */
5730 vty_out (vty, "*");
5731 vty_out (vty, ">");
5732 vty_out (vty, " ");
5733
5734 /* print prefix and mask */
5735 route_vty_out_route (p, vty);
5736
5737 /* Print attribute */
5738 if (attr)
5739 {
5740 if (p->family == AF_INET)
5741 {
5742 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005743 vty_out (vty, "%-16s",
5744 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005745 else
5746 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5747 }
5748#ifdef HAVE_IPV6
5749 else if (p->family == AF_INET6)
5750 {
5751 int len;
5752 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005753
5754 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005755
5756 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005757 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5758 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005759 len = 16 - len;
5760 if (len < 1)
5761 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5762 else
5763 vty_out (vty, "%*s", len, " ");
5764 }
5765#endif /* HAVE_IPV6 */
5766
5767 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005768 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005769 else
5770 vty_out (vty, " ");
5771
5772 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005773 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005774 else
5775 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005776
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005777 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005778
Paul Jakmab2518c12006-05-12 23:48:40 +00005779 /* Print aspath */
5780 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005781 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005782
Paul Jakmab2518c12006-05-12 23:48:40 +00005783 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005784 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005785 }
paul718e3742002-12-13 20:15:29 +00005786
5787 vty_out (vty, "%s", VTY_NEWLINE);
5788}
5789
ajs5a646652004-11-05 01:25:55 +00005790void
paul718e3742002-12-13 20:15:29 +00005791route_vty_out_tag (struct vty *vty, struct prefix *p,
5792 struct bgp_info *binfo, int display, safi_t safi)
5793{
5794 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005795 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005796
5797 if (!binfo->extra)
5798 return;
5799
paulb40d9392005-08-22 22:34:41 +00005800 /* short status lead text */
5801 route_vty_short_status_out (vty, binfo);
5802
paul718e3742002-12-13 20:15:29 +00005803 /* print prefix and mask */
5804 if (! display)
5805 route_vty_out_route (p, vty);
5806 else
5807 vty_out (vty, "%*s", 17, " ");
5808
5809 /* Print attribute */
5810 attr = binfo->attr;
5811 if (attr)
5812 {
5813 if (p->family == AF_INET)
5814 {
5815 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005816 vty_out (vty, "%-16s",
5817 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005818 else
5819 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5820 }
5821#ifdef HAVE_IPV6
5822 else if (p->family == AF_INET6)
5823 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005824 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005825 char buf[BUFSIZ];
5826 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005827 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005828 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005829 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5830 buf, BUFSIZ));
5831 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005832 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005833 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5834 buf, BUFSIZ),
5835 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5836 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005837
5838 }
5839#endif /* HAVE_IPV6 */
5840 }
5841
Paul Jakmafb982c22007-05-04 20:15:47 +00005842 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005843
5844 vty_out (vty, "notag/%d", label);
5845
5846 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005847}
5848
5849/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005850static void
paul718e3742002-12-13 20:15:29 +00005851damp_route_vty_out (struct vty *vty, struct prefix *p,
5852 struct bgp_info *binfo, int display, safi_t safi)
5853{
5854 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005855 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005856 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005857
paulb40d9392005-08-22 22:34:41 +00005858 /* short status lead text */
5859 route_vty_short_status_out (vty, binfo);
5860
paul718e3742002-12-13 20:15:29 +00005861 /* print prefix and mask */
5862 if (! display)
5863 route_vty_out_route (p, vty);
5864 else
5865 vty_out (vty, "%*s", 17, " ");
5866
5867 len = vty_out (vty, "%s", binfo->peer->host);
5868 len = 17 - len;
5869 if (len < 1)
5870 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5871 else
5872 vty_out (vty, "%*s", len, " ");
5873
Chris Caputo50aef6f2009-06-23 06:06:49 +00005874 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005875
5876 /* Print attribute */
5877 attr = binfo->attr;
5878 if (attr)
5879 {
5880 /* Print aspath */
5881 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005882 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005883
5884 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005885 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005886 }
5887 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005888}
5889
paul718e3742002-12-13 20:15:29 +00005890/* flap route */
ajs5a646652004-11-05 01:25:55 +00005891static void
paul718e3742002-12-13 20:15:29 +00005892flap_route_vty_out (struct vty *vty, struct prefix *p,
5893 struct bgp_info *binfo, int display, safi_t safi)
5894{
5895 struct attr *attr;
5896 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005897 char timebuf[BGP_UPTIME_LEN];
5898 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005899
5900 if (!binfo->extra)
5901 return;
5902
5903 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005904
paulb40d9392005-08-22 22:34:41 +00005905 /* short status lead text */
5906 route_vty_short_status_out (vty, binfo);
5907
paul718e3742002-12-13 20:15:29 +00005908 /* print prefix and mask */
5909 if (! display)
5910 route_vty_out_route (p, vty);
5911 else
5912 vty_out (vty, "%*s", 17, " ");
5913
5914 len = vty_out (vty, "%s", binfo->peer->host);
5915 len = 16 - len;
5916 if (len < 1)
5917 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5918 else
5919 vty_out (vty, "%*s", len, " ");
5920
5921 len = vty_out (vty, "%d", bdi->flap);
5922 len = 5 - len;
5923 if (len < 1)
5924 vty_out (vty, " ");
5925 else
5926 vty_out (vty, "%*s ", len, " ");
5927
5928 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5929 timebuf, BGP_UPTIME_LEN));
5930
5931 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5932 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005933 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005934 else
5935 vty_out (vty, "%*s ", 8, " ");
5936
5937 /* Print attribute */
5938 attr = binfo->attr;
5939 if (attr)
5940 {
5941 /* Print aspath */
5942 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005943 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005944
5945 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005946 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005947 }
5948 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005949}
5950
paul94f2b392005-06-28 12:44:16 +00005951static void
paul718e3742002-12-13 20:15:29 +00005952route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5953 struct bgp_info *binfo, afi_t afi, safi_t safi)
5954{
5955 char buf[INET6_ADDRSTRLEN];
5956 char buf1[BUFSIZ];
5957 struct attr *attr;
5958 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005959#ifdef HAVE_CLOCK_MONOTONIC
5960 time_t tbuf;
5961#endif
paul718e3742002-12-13 20:15:29 +00005962
5963 attr = binfo->attr;
5964
5965 if (attr)
5966 {
5967 /* Line1 display AS-path, Aggregator */
5968 if (attr->aspath)
5969 {
5970 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005971 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005972 vty_out (vty, "Local");
5973 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005974 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005975 }
5976
paulb40d9392005-08-22 22:34:41 +00005977 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5978 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005979 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5980 vty_out (vty, ", (stale)");
5981 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005982 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005983 attr->extra->aggregator_as,
5984 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005985 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5986 vty_out (vty, ", (Received from a RR-client)");
5987 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5988 vty_out (vty, ", (Received from a RS-client)");
5989 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5990 vty_out (vty, ", (history entry)");
5991 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5992 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005993 vty_out (vty, "%s", VTY_NEWLINE);
5994
5995 /* Line2 display Next-hop, Neighbor, Router-id */
5996 if (p->family == AF_INET)
5997 {
5998 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005999 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006000 inet_ntoa (attr->nexthop));
6001 }
6002#ifdef HAVE_IPV6
6003 else
6004 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006005 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006006 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006007 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006008 buf, INET6_ADDRSTRLEN));
6009 }
6010#endif /* HAVE_IPV6 */
6011
6012 if (binfo->peer == bgp->peer_self)
6013 {
6014 vty_out (vty, " from %s ",
6015 p->family == AF_INET ? "0.0.0.0" : "::");
6016 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6017 }
6018 else
6019 {
6020 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6021 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006022 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006023 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006024 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006025 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006026 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006027 else
6028 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6029 }
6030 vty_out (vty, "%s", VTY_NEWLINE);
6031
6032#ifdef HAVE_IPV6
6033 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006034 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006035 {
6036 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006037 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006038 buf, INET6_ADDRSTRLEN),
6039 VTY_NEWLINE);
6040 }
6041#endif /* HAVE_IPV6 */
6042
6043 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6044 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6045
6046 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006047 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006048
6049 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006050 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006051 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006052 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006053
Paul Jakmafb982c22007-05-04 20:15:47 +00006054 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006055 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006056
6057 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6058 vty_out (vty, ", valid");
6059
6060 if (binfo->peer != bgp->peer_self)
6061 {
6062 if (binfo->peer->as == binfo->peer->local_as)
6063 vty_out (vty, ", internal");
6064 else
6065 vty_out (vty, ", %s",
6066 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6067 }
6068 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6069 vty_out (vty, ", aggregated, local");
6070 else if (binfo->type != ZEBRA_ROUTE_BGP)
6071 vty_out (vty, ", sourced");
6072 else
6073 vty_out (vty, ", sourced, local");
6074
6075 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6076 vty_out (vty, ", atomic-aggregate");
6077
Josh Baileyde8d5df2011-07-20 20:46:01 -07006078 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6079 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6080 bgp_info_mpath_count (binfo)))
6081 vty_out (vty, ", multipath");
6082
paul718e3742002-12-13 20:15:29 +00006083 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6084 vty_out (vty, ", best");
6085
6086 vty_out (vty, "%s", VTY_NEWLINE);
6087
6088 /* Line 4 display Community */
6089 if (attr->community)
6090 vty_out (vty, " Community: %s%s", attr->community->str,
6091 VTY_NEWLINE);
6092
6093 /* Line 5 display Extended-community */
6094 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006095 vty_out (vty, " Extended Community: %s%s",
6096 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006097
6098 /* Line 6 display Originator, Cluster-id */
6099 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6100 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6101 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006102 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006103 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006104 vty_out (vty, " Originator: %s",
6105 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006106
6107 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6108 {
6109 int i;
6110 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006111 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6112 vty_out (vty, "%s ",
6113 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006114 }
6115 vty_out (vty, "%s", VTY_NEWLINE);
6116 }
Paul Jakma41367172007-08-06 15:24:51 +00006117
Paul Jakmafb982c22007-05-04 20:15:47 +00006118 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006119 bgp_damp_info_vty (vty, binfo);
6120
6121 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006122#ifdef HAVE_CLOCK_MONOTONIC
6123 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006124 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006125#else
6126 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6127#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006128 }
6129 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006130}
6131
6132#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6133 "h history, * valid, > best, = multipath,%s"\
6134 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006135#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006136#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6137#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6138#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6139
6140enum bgp_show_type
6141{
6142 bgp_show_type_normal,
6143 bgp_show_type_regexp,
6144 bgp_show_type_prefix_list,
6145 bgp_show_type_filter_list,
6146 bgp_show_type_route_map,
6147 bgp_show_type_neighbor,
6148 bgp_show_type_cidr_only,
6149 bgp_show_type_prefix_longer,
6150 bgp_show_type_community_all,
6151 bgp_show_type_community,
6152 bgp_show_type_community_exact,
6153 bgp_show_type_community_list,
6154 bgp_show_type_community_list_exact,
6155 bgp_show_type_flap_statistics,
6156 bgp_show_type_flap_address,
6157 bgp_show_type_flap_prefix,
6158 bgp_show_type_flap_cidr_only,
6159 bgp_show_type_flap_regexp,
6160 bgp_show_type_flap_filter_list,
6161 bgp_show_type_flap_prefix_list,
6162 bgp_show_type_flap_prefix_longer,
6163 bgp_show_type_flap_route_map,
6164 bgp_show_type_flap_neighbor,
6165 bgp_show_type_dampend_paths,
6166 bgp_show_type_damp_neighbor
6167};
6168
ajs5a646652004-11-05 01:25:55 +00006169static int
paulfee0f4c2004-09-13 05:12:46 +00006170bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006171 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006172{
paul718e3742002-12-13 20:15:29 +00006173 struct bgp_info *ri;
6174 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006175 int header = 1;
paul718e3742002-12-13 20:15:29 +00006176 int display;
ajs5a646652004-11-05 01:25:55 +00006177 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006178
6179 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006180 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006181
paul718e3742002-12-13 20:15:29 +00006182 /* Start processing of routes. */
6183 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6184 if (rn->info != NULL)
6185 {
6186 display = 0;
6187
6188 for (ri = rn->info; ri; ri = ri->next)
6189 {
ajs5a646652004-11-05 01:25:55 +00006190 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006191 || type == bgp_show_type_flap_address
6192 || type == bgp_show_type_flap_prefix
6193 || type == bgp_show_type_flap_cidr_only
6194 || type == bgp_show_type_flap_regexp
6195 || type == bgp_show_type_flap_filter_list
6196 || type == bgp_show_type_flap_prefix_list
6197 || type == bgp_show_type_flap_prefix_longer
6198 || type == bgp_show_type_flap_route_map
6199 || type == bgp_show_type_flap_neighbor
6200 || type == bgp_show_type_dampend_paths
6201 || type == bgp_show_type_damp_neighbor)
6202 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006203 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006204 continue;
6205 }
6206 if (type == bgp_show_type_regexp
6207 || type == bgp_show_type_flap_regexp)
6208 {
ajs5a646652004-11-05 01:25:55 +00006209 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006210
6211 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6212 continue;
6213 }
6214 if (type == bgp_show_type_prefix_list
6215 || type == bgp_show_type_flap_prefix_list)
6216 {
ajs5a646652004-11-05 01:25:55 +00006217 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006218
6219 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6220 continue;
6221 }
6222 if (type == bgp_show_type_filter_list
6223 || type == bgp_show_type_flap_filter_list)
6224 {
ajs5a646652004-11-05 01:25:55 +00006225 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006226
6227 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6228 continue;
6229 }
6230 if (type == bgp_show_type_route_map
6231 || type == bgp_show_type_flap_route_map)
6232 {
ajs5a646652004-11-05 01:25:55 +00006233 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006234 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006235 struct attr dummy_attr;
6236 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006237 int ret;
6238
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006239 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006240 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006241
paul718e3742002-12-13 20:15:29 +00006242 binfo.peer = ri->peer;
6243 binfo.attr = &dummy_attr;
6244
6245 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006246 if (ret == RMAP_DENYMATCH)
6247 continue;
6248 }
6249 if (type == bgp_show_type_neighbor
6250 || type == bgp_show_type_flap_neighbor
6251 || type == bgp_show_type_damp_neighbor)
6252 {
ajs5a646652004-11-05 01:25:55 +00006253 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006254
6255 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6256 continue;
6257 }
6258 if (type == bgp_show_type_cidr_only
6259 || type == bgp_show_type_flap_cidr_only)
6260 {
6261 u_int32_t destination;
6262
6263 destination = ntohl (rn->p.u.prefix4.s_addr);
6264 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6265 continue;
6266 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6267 continue;
6268 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6269 continue;
6270 }
6271 if (type == bgp_show_type_prefix_longer
6272 || type == bgp_show_type_flap_prefix_longer)
6273 {
ajs5a646652004-11-05 01:25:55 +00006274 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006275
6276 if (! prefix_match (p, &rn->p))
6277 continue;
6278 }
6279 if (type == bgp_show_type_community_all)
6280 {
6281 if (! ri->attr->community)
6282 continue;
6283 }
6284 if (type == bgp_show_type_community)
6285 {
ajs5a646652004-11-05 01:25:55 +00006286 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006287
6288 if (! ri->attr->community ||
6289 ! community_match (ri->attr->community, com))
6290 continue;
6291 }
6292 if (type == bgp_show_type_community_exact)
6293 {
ajs5a646652004-11-05 01:25:55 +00006294 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006295
6296 if (! ri->attr->community ||
6297 ! community_cmp (ri->attr->community, com))
6298 continue;
6299 }
6300 if (type == bgp_show_type_community_list)
6301 {
ajs5a646652004-11-05 01:25:55 +00006302 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006303
6304 if (! community_list_match (ri->attr->community, list))
6305 continue;
6306 }
6307 if (type == bgp_show_type_community_list_exact)
6308 {
ajs5a646652004-11-05 01:25:55 +00006309 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006310
6311 if (! community_list_exact_match (ri->attr->community, list))
6312 continue;
6313 }
6314 if (type == bgp_show_type_flap_address
6315 || type == bgp_show_type_flap_prefix)
6316 {
ajs5a646652004-11-05 01:25:55 +00006317 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006318
6319 if (! prefix_match (&rn->p, p))
6320 continue;
6321
6322 if (type == bgp_show_type_flap_prefix)
6323 if (p->prefixlen != rn->p.prefixlen)
6324 continue;
6325 }
6326 if (type == bgp_show_type_dampend_paths
6327 || type == bgp_show_type_damp_neighbor)
6328 {
6329 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6330 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6331 continue;
6332 }
6333
6334 if (header)
6335 {
hasso93406d82005-02-02 14:40:33 +00006336 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6337 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6338 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006339 if (type == bgp_show_type_dampend_paths
6340 || type == bgp_show_type_damp_neighbor)
6341 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6342 else if (type == bgp_show_type_flap_statistics
6343 || type == bgp_show_type_flap_address
6344 || type == bgp_show_type_flap_prefix
6345 || type == bgp_show_type_flap_cidr_only
6346 || type == bgp_show_type_flap_regexp
6347 || type == bgp_show_type_flap_filter_list
6348 || type == bgp_show_type_flap_prefix_list
6349 || type == bgp_show_type_flap_prefix_longer
6350 || type == bgp_show_type_flap_route_map
6351 || type == bgp_show_type_flap_neighbor)
6352 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6353 else
6354 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006355 header = 0;
6356 }
6357
6358 if (type == bgp_show_type_dampend_paths
6359 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006360 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006361 else if (type == bgp_show_type_flap_statistics
6362 || type == bgp_show_type_flap_address
6363 || type == bgp_show_type_flap_prefix
6364 || type == bgp_show_type_flap_cidr_only
6365 || type == bgp_show_type_flap_regexp
6366 || type == bgp_show_type_flap_filter_list
6367 || type == bgp_show_type_flap_prefix_list
6368 || type == bgp_show_type_flap_prefix_longer
6369 || type == bgp_show_type_flap_route_map
6370 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006371 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006372 else
ajs5a646652004-11-05 01:25:55 +00006373 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006374 display++;
6375 }
6376 if (display)
ajs5a646652004-11-05 01:25:55 +00006377 output_count++;
paul718e3742002-12-13 20:15:29 +00006378 }
6379
6380 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006381 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006382 {
6383 if (type == bgp_show_type_normal)
6384 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6385 }
6386 else
6387 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006388 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006389
6390 return CMD_SUCCESS;
6391}
6392
ajs5a646652004-11-05 01:25:55 +00006393static int
paulfee0f4c2004-09-13 05:12:46 +00006394bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006395 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006396{
6397 struct bgp_table *table;
6398
6399 if (bgp == NULL) {
6400 bgp = bgp_get_default ();
6401 }
6402
6403 if (bgp == NULL)
6404 {
6405 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6406 return CMD_WARNING;
6407 }
6408
6409
6410 table = bgp->rib[afi][safi];
6411
ajs5a646652004-11-05 01:25:55 +00006412 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006413}
6414
paul718e3742002-12-13 20:15:29 +00006415/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006416static void
paul718e3742002-12-13 20:15:29 +00006417route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6418 struct bgp_node *rn,
6419 struct prefix_rd *prd, afi_t afi, safi_t safi)
6420{
6421 struct bgp_info *ri;
6422 struct prefix *p;
6423 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006424 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006425 char buf1[INET6_ADDRSTRLEN];
6426 char buf2[INET6_ADDRSTRLEN];
6427 int count = 0;
6428 int best = 0;
6429 int suppress = 0;
6430 int no_export = 0;
6431 int no_advertise = 0;
6432 int local_as = 0;
6433 int first = 0;
6434
6435 p = &rn->p;
6436 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6437 (safi == SAFI_MPLS_VPN ?
6438 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6439 safi == SAFI_MPLS_VPN ? ":" : "",
6440 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6441 p->prefixlen, VTY_NEWLINE);
6442
6443 for (ri = rn->info; ri; ri = ri->next)
6444 {
6445 count++;
6446 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6447 {
6448 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006449 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006450 suppress = 1;
6451 if (ri->attr->community != NULL)
6452 {
6453 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6454 no_advertise = 1;
6455 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6456 no_export = 1;
6457 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6458 local_as = 1;
6459 }
6460 }
6461 }
6462
6463 vty_out (vty, "Paths: (%d available", count);
6464 if (best)
6465 {
6466 vty_out (vty, ", best #%d", best);
6467 if (safi == SAFI_UNICAST)
6468 vty_out (vty, ", table Default-IP-Routing-Table");
6469 }
6470 else
6471 vty_out (vty, ", no best path");
6472 if (no_advertise)
6473 vty_out (vty, ", not advertised to any peer");
6474 else if (no_export)
6475 vty_out (vty, ", not advertised to EBGP peer");
6476 else if (local_as)
6477 vty_out (vty, ", not advertised outside local AS");
6478 if (suppress)
6479 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6480 vty_out (vty, ")%s", VTY_NEWLINE);
6481
6482 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006483 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006484 {
6485 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6486 {
6487 if (! first)
6488 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6489 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6490 first = 1;
6491 }
6492 }
6493 if (! first)
6494 vty_out (vty, " Not advertised to any peer");
6495 vty_out (vty, "%s", VTY_NEWLINE);
6496}
6497
6498/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006499static int
paulfee0f4c2004-09-13 05:12:46 +00006500bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006501 struct bgp_table *rib, const char *ip_str,
6502 afi_t afi, safi_t safi, struct prefix_rd *prd,
6503 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006504{
6505 int ret;
6506 int header;
6507 int display = 0;
6508 struct prefix match;
6509 struct bgp_node *rn;
6510 struct bgp_node *rm;
6511 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006512 struct bgp_table *table;
6513
paul718e3742002-12-13 20:15:29 +00006514 /* Check IP address argument. */
6515 ret = str2prefix (ip_str, &match);
6516 if (! ret)
6517 {
6518 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6519 return CMD_WARNING;
6520 }
6521
6522 match.family = afi2family (afi);
6523
6524 if (safi == SAFI_MPLS_VPN)
6525 {
paulfee0f4c2004-09-13 05:12:46 +00006526 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006527 {
6528 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6529 continue;
6530
6531 if ((table = rn->info) != NULL)
6532 {
6533 header = 1;
6534
6535 if ((rm = bgp_node_match (table, &match)) != NULL)
6536 {
6537 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006538 {
6539 bgp_unlock_node (rm);
6540 continue;
6541 }
paul718e3742002-12-13 20:15:29 +00006542
6543 for (ri = rm->info; ri; ri = ri->next)
6544 {
6545 if (header)
6546 {
6547 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6548 AFI_IP, SAFI_MPLS_VPN);
6549
6550 header = 0;
6551 }
6552 display++;
6553 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6554 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006555
6556 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006557 }
6558 }
6559 }
6560 }
6561 else
6562 {
6563 header = 1;
6564
paulfee0f4c2004-09-13 05:12:46 +00006565 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006566 {
6567 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6568 {
6569 for (ri = rn->info; ri; ri = ri->next)
6570 {
6571 if (header)
6572 {
6573 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6574 header = 0;
6575 }
6576 display++;
6577 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6578 }
6579 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006580
6581 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006582 }
6583 }
6584
6585 if (! display)
6586 {
6587 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6588 return CMD_WARNING;
6589 }
6590
6591 return CMD_SUCCESS;
6592}
6593
paulfee0f4c2004-09-13 05:12:46 +00006594/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006595static int
paulfd79ac92004-10-13 05:06:08 +00006596bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006597 afi_t afi, safi_t safi, struct prefix_rd *prd,
6598 int prefix_check)
6599{
6600 struct bgp *bgp;
6601
6602 /* BGP structure lookup. */
6603 if (view_name)
6604 {
6605 bgp = bgp_lookup_by_name (view_name);
6606 if (bgp == NULL)
6607 {
6608 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6609 return CMD_WARNING;
6610 }
6611 }
6612 else
6613 {
6614 bgp = bgp_get_default ();
6615 if (bgp == NULL)
6616 {
6617 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6618 return CMD_WARNING;
6619 }
6620 }
6621
6622 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6623 afi, safi, prd, prefix_check);
6624}
6625
paul718e3742002-12-13 20:15:29 +00006626/* BGP route print out function. */
6627DEFUN (show_ip_bgp,
6628 show_ip_bgp_cmd,
6629 "show ip bgp",
6630 SHOW_STR
6631 IP_STR
6632 BGP_STR)
6633{
ajs5a646652004-11-05 01:25:55 +00006634 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006635}
6636
6637DEFUN (show_ip_bgp_ipv4,
6638 show_ip_bgp_ipv4_cmd,
6639 "show ip bgp ipv4 (unicast|multicast)",
6640 SHOW_STR
6641 IP_STR
6642 BGP_STR
6643 "Address family\n"
6644 "Address Family modifier\n"
6645 "Address Family modifier\n")
6646{
6647 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006648 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6649 NULL);
paul718e3742002-12-13 20:15:29 +00006650
ajs5a646652004-11-05 01:25:55 +00006651 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006652}
6653
Michael Lambert95cbbd22010-07-23 14:43:04 -04006654ALIAS (show_ip_bgp_ipv4,
6655 show_bgp_ipv4_safi_cmd,
6656 "show bgp ipv4 (unicast|multicast)",
6657 SHOW_STR
6658 BGP_STR
6659 "Address family\n"
6660 "Address Family modifier\n"
6661 "Address Family modifier\n")
6662
paul718e3742002-12-13 20:15:29 +00006663DEFUN (show_ip_bgp_route,
6664 show_ip_bgp_route_cmd,
6665 "show ip bgp A.B.C.D",
6666 SHOW_STR
6667 IP_STR
6668 BGP_STR
6669 "Network in the BGP routing table to display\n")
6670{
6671 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6672}
6673
6674DEFUN (show_ip_bgp_ipv4_route,
6675 show_ip_bgp_ipv4_route_cmd,
6676 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6677 SHOW_STR
6678 IP_STR
6679 BGP_STR
6680 "Address family\n"
6681 "Address Family modifier\n"
6682 "Address Family modifier\n"
6683 "Network in the BGP routing table to display\n")
6684{
6685 if (strncmp (argv[0], "m", 1) == 0)
6686 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6687
6688 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6689}
6690
Michael Lambert95cbbd22010-07-23 14:43:04 -04006691ALIAS (show_ip_bgp_ipv4_route,
6692 show_bgp_ipv4_safi_route_cmd,
6693 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6694 SHOW_STR
6695 BGP_STR
6696 "Address family\n"
6697 "Address Family modifier\n"
6698 "Address Family modifier\n"
6699 "Network in the BGP routing table to display\n")
6700
paul718e3742002-12-13 20:15:29 +00006701DEFUN (show_ip_bgp_vpnv4_all_route,
6702 show_ip_bgp_vpnv4_all_route_cmd,
6703 "show ip bgp vpnv4 all A.B.C.D",
6704 SHOW_STR
6705 IP_STR
6706 BGP_STR
6707 "Display VPNv4 NLRI specific information\n"
6708 "Display information about all VPNv4 NLRIs\n"
6709 "Network in the BGP routing table to display\n")
6710{
6711 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6712}
6713
6714DEFUN (show_ip_bgp_vpnv4_rd_route,
6715 show_ip_bgp_vpnv4_rd_route_cmd,
6716 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6717 SHOW_STR
6718 IP_STR
6719 BGP_STR
6720 "Display VPNv4 NLRI specific information\n"
6721 "Display information for a route distinguisher\n"
6722 "VPN Route Distinguisher\n"
6723 "Network in the BGP routing table to display\n")
6724{
6725 int ret;
6726 struct prefix_rd prd;
6727
6728 ret = str2prefix_rd (argv[0], &prd);
6729 if (! ret)
6730 {
6731 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6732 return CMD_WARNING;
6733 }
6734 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6735}
6736
6737DEFUN (show_ip_bgp_prefix,
6738 show_ip_bgp_prefix_cmd,
6739 "show ip bgp A.B.C.D/M",
6740 SHOW_STR
6741 IP_STR
6742 BGP_STR
6743 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6744{
6745 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6746}
6747
6748DEFUN (show_ip_bgp_ipv4_prefix,
6749 show_ip_bgp_ipv4_prefix_cmd,
6750 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6751 SHOW_STR
6752 IP_STR
6753 BGP_STR
6754 "Address family\n"
6755 "Address Family modifier\n"
6756 "Address Family modifier\n"
6757 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6758{
6759 if (strncmp (argv[0], "m", 1) == 0)
6760 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6761
6762 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6763}
6764
Michael Lambert95cbbd22010-07-23 14:43:04 -04006765ALIAS (show_ip_bgp_ipv4_prefix,
6766 show_bgp_ipv4_safi_prefix_cmd,
6767 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6768 SHOW_STR
6769 BGP_STR
6770 "Address family\n"
6771 "Address Family modifier\n"
6772 "Address Family modifier\n"
6773 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6774
paul718e3742002-12-13 20:15:29 +00006775DEFUN (show_ip_bgp_vpnv4_all_prefix,
6776 show_ip_bgp_vpnv4_all_prefix_cmd,
6777 "show ip bgp vpnv4 all A.B.C.D/M",
6778 SHOW_STR
6779 IP_STR
6780 BGP_STR
6781 "Display VPNv4 NLRI specific information\n"
6782 "Display information about all VPNv4 NLRIs\n"
6783 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6784{
6785 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6786}
6787
6788DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6789 show_ip_bgp_vpnv4_rd_prefix_cmd,
6790 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6791 SHOW_STR
6792 IP_STR
6793 BGP_STR
6794 "Display VPNv4 NLRI specific information\n"
6795 "Display information for a route distinguisher\n"
6796 "VPN Route Distinguisher\n"
6797 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6798{
6799 int ret;
6800 struct prefix_rd prd;
6801
6802 ret = str2prefix_rd (argv[0], &prd);
6803 if (! ret)
6804 {
6805 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6806 return CMD_WARNING;
6807 }
6808 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6809}
6810
6811DEFUN (show_ip_bgp_view,
6812 show_ip_bgp_view_cmd,
6813 "show ip bgp view WORD",
6814 SHOW_STR
6815 IP_STR
6816 BGP_STR
6817 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006818 "View name\n")
paul718e3742002-12-13 20:15:29 +00006819{
paulbb46e942003-10-24 19:02:03 +00006820 struct bgp *bgp;
6821
6822 /* BGP structure lookup. */
6823 bgp = bgp_lookup_by_name (argv[0]);
6824 if (bgp == NULL)
6825 {
6826 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6827 return CMD_WARNING;
6828 }
6829
ajs5a646652004-11-05 01:25:55 +00006830 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006831}
6832
6833DEFUN (show_ip_bgp_view_route,
6834 show_ip_bgp_view_route_cmd,
6835 "show ip bgp view WORD A.B.C.D",
6836 SHOW_STR
6837 IP_STR
6838 BGP_STR
6839 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006840 "View name\n"
paul718e3742002-12-13 20:15:29 +00006841 "Network in the BGP routing table to display\n")
6842{
6843 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6844}
6845
6846DEFUN (show_ip_bgp_view_prefix,
6847 show_ip_bgp_view_prefix_cmd,
6848 "show ip bgp view WORD A.B.C.D/M",
6849 SHOW_STR
6850 IP_STR
6851 BGP_STR
6852 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006853 "View name\n"
paul718e3742002-12-13 20:15:29 +00006854 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6855{
6856 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6857}
6858
6859#ifdef HAVE_IPV6
6860DEFUN (show_bgp,
6861 show_bgp_cmd,
6862 "show bgp",
6863 SHOW_STR
6864 BGP_STR)
6865{
ajs5a646652004-11-05 01:25:55 +00006866 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6867 NULL);
paul718e3742002-12-13 20:15:29 +00006868}
6869
6870ALIAS (show_bgp,
6871 show_bgp_ipv6_cmd,
6872 "show bgp ipv6",
6873 SHOW_STR
6874 BGP_STR
6875 "Address family\n")
6876
Michael Lambert95cbbd22010-07-23 14:43:04 -04006877DEFUN (show_bgp_ipv6_safi,
6878 show_bgp_ipv6_safi_cmd,
6879 "show bgp ipv6 (unicast|multicast)",
6880 SHOW_STR
6881 BGP_STR
6882 "Address family\n"
6883 "Address Family modifier\n"
6884 "Address Family modifier\n")
6885{
6886 if (strncmp (argv[0], "m", 1) == 0)
6887 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6888 NULL);
6889
6890 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6891}
6892
paul718e3742002-12-13 20:15:29 +00006893/* old command */
6894DEFUN (show_ipv6_bgp,
6895 show_ipv6_bgp_cmd,
6896 "show ipv6 bgp",
6897 SHOW_STR
6898 IP_STR
6899 BGP_STR)
6900{
ajs5a646652004-11-05 01:25:55 +00006901 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6902 NULL);
paul718e3742002-12-13 20:15:29 +00006903}
6904
6905DEFUN (show_bgp_route,
6906 show_bgp_route_cmd,
6907 "show bgp X:X::X:X",
6908 SHOW_STR
6909 BGP_STR
6910 "Network in the BGP routing table to display\n")
6911{
6912 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6913}
6914
6915ALIAS (show_bgp_route,
6916 show_bgp_ipv6_route_cmd,
6917 "show bgp ipv6 X:X::X:X",
6918 SHOW_STR
6919 BGP_STR
6920 "Address family\n"
6921 "Network in the BGP routing table to display\n")
6922
Michael Lambert95cbbd22010-07-23 14:43:04 -04006923DEFUN (show_bgp_ipv6_safi_route,
6924 show_bgp_ipv6_safi_route_cmd,
6925 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6926 SHOW_STR
6927 BGP_STR
6928 "Address family\n"
6929 "Address Family modifier\n"
6930 "Address Family modifier\n"
6931 "Network in the BGP routing table to display\n")
6932{
6933 if (strncmp (argv[0], "m", 1) == 0)
6934 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6935
6936 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6937}
6938
paul718e3742002-12-13 20:15:29 +00006939/* old command */
6940DEFUN (show_ipv6_bgp_route,
6941 show_ipv6_bgp_route_cmd,
6942 "show ipv6 bgp X:X::X:X",
6943 SHOW_STR
6944 IP_STR
6945 BGP_STR
6946 "Network in the BGP routing table to display\n")
6947{
6948 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6949}
6950
6951DEFUN (show_bgp_prefix,
6952 show_bgp_prefix_cmd,
6953 "show bgp X:X::X:X/M",
6954 SHOW_STR
6955 BGP_STR
6956 "IPv6 prefix <network>/<length>\n")
6957{
6958 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6959}
6960
6961ALIAS (show_bgp_prefix,
6962 show_bgp_ipv6_prefix_cmd,
6963 "show bgp ipv6 X:X::X:X/M",
6964 SHOW_STR
6965 BGP_STR
6966 "Address family\n"
6967 "IPv6 prefix <network>/<length>\n")
6968
Michael Lambert95cbbd22010-07-23 14:43:04 -04006969DEFUN (show_bgp_ipv6_safi_prefix,
6970 show_bgp_ipv6_safi_prefix_cmd,
6971 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6972 SHOW_STR
6973 BGP_STR
6974 "Address family\n"
6975 "Address Family modifier\n"
6976 "Address Family modifier\n"
6977 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6978{
6979 if (strncmp (argv[0], "m", 1) == 0)
6980 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6981
6982 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6983}
6984
paul718e3742002-12-13 20:15:29 +00006985/* old command */
6986DEFUN (show_ipv6_bgp_prefix,
6987 show_ipv6_bgp_prefix_cmd,
6988 "show ipv6 bgp X:X::X:X/M",
6989 SHOW_STR
6990 IP_STR
6991 BGP_STR
6992 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6993{
6994 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6995}
6996
paulbb46e942003-10-24 19:02:03 +00006997DEFUN (show_bgp_view,
6998 show_bgp_view_cmd,
6999 "show bgp view WORD",
7000 SHOW_STR
7001 BGP_STR
7002 "BGP view\n"
7003 "View name\n")
7004{
7005 struct bgp *bgp;
7006
7007 /* BGP structure lookup. */
7008 bgp = bgp_lookup_by_name (argv[0]);
7009 if (bgp == NULL)
7010 {
7011 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7012 return CMD_WARNING;
7013 }
7014
ajs5a646652004-11-05 01:25:55 +00007015 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007016}
7017
7018ALIAS (show_bgp_view,
7019 show_bgp_view_ipv6_cmd,
7020 "show bgp view WORD ipv6",
7021 SHOW_STR
7022 BGP_STR
7023 "BGP view\n"
7024 "View name\n"
7025 "Address family\n")
7026
7027DEFUN (show_bgp_view_route,
7028 show_bgp_view_route_cmd,
7029 "show bgp view WORD X:X::X:X",
7030 SHOW_STR
7031 BGP_STR
7032 "BGP view\n"
7033 "View name\n"
7034 "Network in the BGP routing table to display\n")
7035{
7036 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7037}
7038
7039ALIAS (show_bgp_view_route,
7040 show_bgp_view_ipv6_route_cmd,
7041 "show bgp view WORD ipv6 X:X::X:X",
7042 SHOW_STR
7043 BGP_STR
7044 "BGP view\n"
7045 "View name\n"
7046 "Address family\n"
7047 "Network in the BGP routing table to display\n")
7048
7049DEFUN (show_bgp_view_prefix,
7050 show_bgp_view_prefix_cmd,
7051 "show bgp view WORD X:X::X:X/M",
7052 SHOW_STR
7053 BGP_STR
7054 "BGP view\n"
7055 "View name\n"
7056 "IPv6 prefix <network>/<length>\n")
7057{
7058 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7059}
7060
7061ALIAS (show_bgp_view_prefix,
7062 show_bgp_view_ipv6_prefix_cmd,
7063 "show bgp view WORD ipv6 X:X::X:X/M",
7064 SHOW_STR
7065 BGP_STR
7066 "BGP view\n"
7067 "View name\n"
7068 "Address family\n"
7069 "IPv6 prefix <network>/<length>\n")
7070
paul718e3742002-12-13 20:15:29 +00007071/* old command */
7072DEFUN (show_ipv6_mbgp,
7073 show_ipv6_mbgp_cmd,
7074 "show ipv6 mbgp",
7075 SHOW_STR
7076 IP_STR
7077 MBGP_STR)
7078{
ajs5a646652004-11-05 01:25:55 +00007079 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7080 NULL);
paul718e3742002-12-13 20:15:29 +00007081}
7082
7083/* old command */
7084DEFUN (show_ipv6_mbgp_route,
7085 show_ipv6_mbgp_route_cmd,
7086 "show ipv6 mbgp X:X::X:X",
7087 SHOW_STR
7088 IP_STR
7089 MBGP_STR
7090 "Network in the MBGP routing table to display\n")
7091{
7092 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7093}
7094
7095/* old command */
7096DEFUN (show_ipv6_mbgp_prefix,
7097 show_ipv6_mbgp_prefix_cmd,
7098 "show ipv6 mbgp X:X::X:X/M",
7099 SHOW_STR
7100 IP_STR
7101 MBGP_STR
7102 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7103{
7104 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7105}
7106#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02007107
paul718e3742002-12-13 20:15:29 +00007108
paul94f2b392005-06-28 12:44:16 +00007109static int
paulfd79ac92004-10-13 05:06:08 +00007110bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007111 safi_t safi, enum bgp_show_type type)
7112{
7113 int i;
7114 struct buffer *b;
7115 char *regstr;
7116 int first;
7117 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007118 int rc;
paul718e3742002-12-13 20:15:29 +00007119
7120 first = 0;
7121 b = buffer_new (1024);
7122 for (i = 0; i < argc; i++)
7123 {
7124 if (first)
7125 buffer_putc (b, ' ');
7126 else
7127 {
7128 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7129 continue;
7130 first = 1;
7131 }
7132
7133 buffer_putstr (b, argv[i]);
7134 }
7135 buffer_putc (b, '\0');
7136
7137 regstr = buffer_getstr (b);
7138 buffer_free (b);
7139
7140 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007141 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007142 if (! regex)
7143 {
7144 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7145 VTY_NEWLINE);
7146 return CMD_WARNING;
7147 }
7148
ajs5a646652004-11-05 01:25:55 +00007149 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7150 bgp_regex_free (regex);
7151 return rc;
paul718e3742002-12-13 20:15:29 +00007152}
7153
7154DEFUN (show_ip_bgp_regexp,
7155 show_ip_bgp_regexp_cmd,
7156 "show ip bgp regexp .LINE",
7157 SHOW_STR
7158 IP_STR
7159 BGP_STR
7160 "Display routes matching the AS path regular expression\n"
7161 "A regular-expression to match the BGP AS paths\n")
7162{
7163 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7164 bgp_show_type_regexp);
7165}
7166
7167DEFUN (show_ip_bgp_flap_regexp,
7168 show_ip_bgp_flap_regexp_cmd,
7169 "show ip bgp flap-statistics regexp .LINE",
7170 SHOW_STR
7171 IP_STR
7172 BGP_STR
7173 "Display flap statistics of routes\n"
7174 "Display routes matching the AS path regular expression\n"
7175 "A regular-expression to match the BGP AS paths\n")
7176{
7177 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7178 bgp_show_type_flap_regexp);
7179}
7180
7181DEFUN (show_ip_bgp_ipv4_regexp,
7182 show_ip_bgp_ipv4_regexp_cmd,
7183 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7184 SHOW_STR
7185 IP_STR
7186 BGP_STR
7187 "Address family\n"
7188 "Address Family modifier\n"
7189 "Address Family modifier\n"
7190 "Display routes matching the AS path regular expression\n"
7191 "A regular-expression to match the BGP AS paths\n")
7192{
7193 if (strncmp (argv[0], "m", 1) == 0)
7194 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7195 bgp_show_type_regexp);
7196
7197 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7198 bgp_show_type_regexp);
7199}
7200
7201#ifdef HAVE_IPV6
7202DEFUN (show_bgp_regexp,
7203 show_bgp_regexp_cmd,
7204 "show bgp regexp .LINE",
7205 SHOW_STR
7206 BGP_STR
7207 "Display routes matching the AS path regular expression\n"
7208 "A regular-expression to match the BGP AS paths\n")
7209{
7210 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7211 bgp_show_type_regexp);
7212}
7213
7214ALIAS (show_bgp_regexp,
7215 show_bgp_ipv6_regexp_cmd,
7216 "show bgp ipv6 regexp .LINE",
7217 SHOW_STR
7218 BGP_STR
7219 "Address family\n"
7220 "Display routes matching the AS path regular expression\n"
7221 "A regular-expression to match the BGP AS paths\n")
7222
7223/* old command */
7224DEFUN (show_ipv6_bgp_regexp,
7225 show_ipv6_bgp_regexp_cmd,
7226 "show ipv6 bgp regexp .LINE",
7227 SHOW_STR
7228 IP_STR
7229 BGP_STR
7230 "Display routes matching the AS path regular expression\n"
7231 "A regular-expression to match the BGP AS paths\n")
7232{
7233 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7234 bgp_show_type_regexp);
7235}
7236
7237/* old command */
7238DEFUN (show_ipv6_mbgp_regexp,
7239 show_ipv6_mbgp_regexp_cmd,
7240 "show ipv6 mbgp regexp .LINE",
7241 SHOW_STR
7242 IP_STR
7243 BGP_STR
7244 "Display routes matching the AS path regular expression\n"
7245 "A regular-expression to match the MBGP AS paths\n")
7246{
7247 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7248 bgp_show_type_regexp);
7249}
7250#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007251
paul94f2b392005-06-28 12:44:16 +00007252static int
paulfd79ac92004-10-13 05:06:08 +00007253bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007254 safi_t safi, enum bgp_show_type type)
7255{
7256 struct prefix_list *plist;
7257
7258 plist = prefix_list_lookup (afi, prefix_list_str);
7259 if (plist == NULL)
7260 {
7261 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7262 prefix_list_str, VTY_NEWLINE);
7263 return CMD_WARNING;
7264 }
7265
ajs5a646652004-11-05 01:25:55 +00007266 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007267}
7268
7269DEFUN (show_ip_bgp_prefix_list,
7270 show_ip_bgp_prefix_list_cmd,
7271 "show ip bgp prefix-list WORD",
7272 SHOW_STR
7273 IP_STR
7274 BGP_STR
7275 "Display routes conforming to the prefix-list\n"
7276 "IP prefix-list name\n")
7277{
7278 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7279 bgp_show_type_prefix_list);
7280}
7281
7282DEFUN (show_ip_bgp_flap_prefix_list,
7283 show_ip_bgp_flap_prefix_list_cmd,
7284 "show ip bgp flap-statistics prefix-list WORD",
7285 SHOW_STR
7286 IP_STR
7287 BGP_STR
7288 "Display flap statistics of routes\n"
7289 "Display routes conforming to the prefix-list\n"
7290 "IP prefix-list name\n")
7291{
7292 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7293 bgp_show_type_flap_prefix_list);
7294}
7295
7296DEFUN (show_ip_bgp_ipv4_prefix_list,
7297 show_ip_bgp_ipv4_prefix_list_cmd,
7298 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7299 SHOW_STR
7300 IP_STR
7301 BGP_STR
7302 "Address family\n"
7303 "Address Family modifier\n"
7304 "Address Family modifier\n"
7305 "Display routes conforming to the prefix-list\n"
7306 "IP prefix-list name\n")
7307{
7308 if (strncmp (argv[0], "m", 1) == 0)
7309 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7310 bgp_show_type_prefix_list);
7311
7312 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7313 bgp_show_type_prefix_list);
7314}
7315
7316#ifdef HAVE_IPV6
7317DEFUN (show_bgp_prefix_list,
7318 show_bgp_prefix_list_cmd,
7319 "show bgp prefix-list WORD",
7320 SHOW_STR
7321 BGP_STR
7322 "Display routes conforming to the prefix-list\n"
7323 "IPv6 prefix-list name\n")
7324{
7325 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7326 bgp_show_type_prefix_list);
7327}
7328
7329ALIAS (show_bgp_prefix_list,
7330 show_bgp_ipv6_prefix_list_cmd,
7331 "show bgp ipv6 prefix-list WORD",
7332 SHOW_STR
7333 BGP_STR
7334 "Address family\n"
7335 "Display routes conforming to the prefix-list\n"
7336 "IPv6 prefix-list name\n")
7337
7338/* old command */
7339DEFUN (show_ipv6_bgp_prefix_list,
7340 show_ipv6_bgp_prefix_list_cmd,
7341 "show ipv6 bgp prefix-list WORD",
7342 SHOW_STR
7343 IPV6_STR
7344 BGP_STR
7345 "Display routes matching the prefix-list\n"
7346 "IPv6 prefix-list name\n")
7347{
7348 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7349 bgp_show_type_prefix_list);
7350}
7351
7352/* old command */
7353DEFUN (show_ipv6_mbgp_prefix_list,
7354 show_ipv6_mbgp_prefix_list_cmd,
7355 "show ipv6 mbgp prefix-list WORD",
7356 SHOW_STR
7357 IPV6_STR
7358 MBGP_STR
7359 "Display routes matching the prefix-list\n"
7360 "IPv6 prefix-list name\n")
7361{
7362 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7363 bgp_show_type_prefix_list);
7364}
7365#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007366
paul94f2b392005-06-28 12:44:16 +00007367static int
paulfd79ac92004-10-13 05:06:08 +00007368bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007369 safi_t safi, enum bgp_show_type type)
7370{
7371 struct as_list *as_list;
7372
7373 as_list = as_list_lookup (filter);
7374 if (as_list == NULL)
7375 {
7376 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7377 return CMD_WARNING;
7378 }
7379
ajs5a646652004-11-05 01:25:55 +00007380 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007381}
7382
7383DEFUN (show_ip_bgp_filter_list,
7384 show_ip_bgp_filter_list_cmd,
7385 "show ip bgp filter-list WORD",
7386 SHOW_STR
7387 IP_STR
7388 BGP_STR
7389 "Display routes conforming to the filter-list\n"
7390 "Regular expression access list name\n")
7391{
7392 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7393 bgp_show_type_filter_list);
7394}
7395
7396DEFUN (show_ip_bgp_flap_filter_list,
7397 show_ip_bgp_flap_filter_list_cmd,
7398 "show ip bgp flap-statistics filter-list WORD",
7399 SHOW_STR
7400 IP_STR
7401 BGP_STR
7402 "Display flap statistics of routes\n"
7403 "Display routes conforming to the filter-list\n"
7404 "Regular expression access list name\n")
7405{
7406 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7407 bgp_show_type_flap_filter_list);
7408}
7409
7410DEFUN (show_ip_bgp_ipv4_filter_list,
7411 show_ip_bgp_ipv4_filter_list_cmd,
7412 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7413 SHOW_STR
7414 IP_STR
7415 BGP_STR
7416 "Address family\n"
7417 "Address Family modifier\n"
7418 "Address Family modifier\n"
7419 "Display routes conforming to the filter-list\n"
7420 "Regular expression access list name\n")
7421{
7422 if (strncmp (argv[0], "m", 1) == 0)
7423 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7424 bgp_show_type_filter_list);
7425
7426 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7427 bgp_show_type_filter_list);
7428}
7429
7430#ifdef HAVE_IPV6
7431DEFUN (show_bgp_filter_list,
7432 show_bgp_filter_list_cmd,
7433 "show bgp filter-list WORD",
7434 SHOW_STR
7435 BGP_STR
7436 "Display routes conforming to the filter-list\n"
7437 "Regular expression access list name\n")
7438{
7439 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7440 bgp_show_type_filter_list);
7441}
7442
7443ALIAS (show_bgp_filter_list,
7444 show_bgp_ipv6_filter_list_cmd,
7445 "show bgp ipv6 filter-list WORD",
7446 SHOW_STR
7447 BGP_STR
7448 "Address family\n"
7449 "Display routes conforming to the filter-list\n"
7450 "Regular expression access list name\n")
7451
7452/* old command */
7453DEFUN (show_ipv6_bgp_filter_list,
7454 show_ipv6_bgp_filter_list_cmd,
7455 "show ipv6 bgp filter-list WORD",
7456 SHOW_STR
7457 IPV6_STR
7458 BGP_STR
7459 "Display routes conforming to the filter-list\n"
7460 "Regular expression access list name\n")
7461{
7462 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7463 bgp_show_type_filter_list);
7464}
7465
7466/* old command */
7467DEFUN (show_ipv6_mbgp_filter_list,
7468 show_ipv6_mbgp_filter_list_cmd,
7469 "show ipv6 mbgp filter-list WORD",
7470 SHOW_STR
7471 IPV6_STR
7472 MBGP_STR
7473 "Display routes conforming to the filter-list\n"
7474 "Regular expression access list name\n")
7475{
7476 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7477 bgp_show_type_filter_list);
7478}
7479#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007480
paul94f2b392005-06-28 12:44:16 +00007481static int
paulfd79ac92004-10-13 05:06:08 +00007482bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007483 safi_t safi, enum bgp_show_type type)
7484{
7485 struct route_map *rmap;
7486
7487 rmap = route_map_lookup_by_name (rmap_str);
7488 if (! rmap)
7489 {
7490 vty_out (vty, "%% %s is not a valid route-map name%s",
7491 rmap_str, VTY_NEWLINE);
7492 return CMD_WARNING;
7493 }
7494
ajs5a646652004-11-05 01:25:55 +00007495 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007496}
7497
7498DEFUN (show_ip_bgp_route_map,
7499 show_ip_bgp_route_map_cmd,
7500 "show ip bgp route-map WORD",
7501 SHOW_STR
7502 IP_STR
7503 BGP_STR
7504 "Display routes matching the route-map\n"
7505 "A route-map to match on\n")
7506{
7507 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7508 bgp_show_type_route_map);
7509}
7510
7511DEFUN (show_ip_bgp_flap_route_map,
7512 show_ip_bgp_flap_route_map_cmd,
7513 "show ip bgp flap-statistics route-map WORD",
7514 SHOW_STR
7515 IP_STR
7516 BGP_STR
7517 "Display flap statistics of routes\n"
7518 "Display routes matching the route-map\n"
7519 "A route-map to match on\n")
7520{
7521 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7522 bgp_show_type_flap_route_map);
7523}
7524
7525DEFUN (show_ip_bgp_ipv4_route_map,
7526 show_ip_bgp_ipv4_route_map_cmd,
7527 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7528 SHOW_STR
7529 IP_STR
7530 BGP_STR
7531 "Address family\n"
7532 "Address Family modifier\n"
7533 "Address Family modifier\n"
7534 "Display routes matching the route-map\n"
7535 "A route-map to match on\n")
7536{
7537 if (strncmp (argv[0], "m", 1) == 0)
7538 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7539 bgp_show_type_route_map);
7540
7541 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7542 bgp_show_type_route_map);
7543}
7544
7545DEFUN (show_bgp_route_map,
7546 show_bgp_route_map_cmd,
7547 "show bgp route-map WORD",
7548 SHOW_STR
7549 BGP_STR
7550 "Display routes matching the route-map\n"
7551 "A route-map to match on\n")
7552{
7553 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7554 bgp_show_type_route_map);
7555}
7556
7557ALIAS (show_bgp_route_map,
7558 show_bgp_ipv6_route_map_cmd,
7559 "show bgp ipv6 route-map WORD",
7560 SHOW_STR
7561 BGP_STR
7562 "Address family\n"
7563 "Display routes matching the route-map\n"
7564 "A route-map to match on\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02007565
paul718e3742002-12-13 20:15:29 +00007566DEFUN (show_ip_bgp_cidr_only,
7567 show_ip_bgp_cidr_only_cmd,
7568 "show ip bgp cidr-only",
7569 SHOW_STR
7570 IP_STR
7571 BGP_STR
7572 "Display only routes with non-natural netmasks\n")
7573{
7574 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007575 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007576}
7577
7578DEFUN (show_ip_bgp_flap_cidr_only,
7579 show_ip_bgp_flap_cidr_only_cmd,
7580 "show ip bgp flap-statistics cidr-only",
7581 SHOW_STR
7582 IP_STR
7583 BGP_STR
7584 "Display flap statistics of routes\n"
7585 "Display only routes with non-natural netmasks\n")
7586{
7587 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007588 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007589}
7590
7591DEFUN (show_ip_bgp_ipv4_cidr_only,
7592 show_ip_bgp_ipv4_cidr_only_cmd,
7593 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7594 SHOW_STR
7595 IP_STR
7596 BGP_STR
7597 "Address family\n"
7598 "Address Family modifier\n"
7599 "Address Family modifier\n"
7600 "Display only routes with non-natural netmasks\n")
7601{
7602 if (strncmp (argv[0], "m", 1) == 0)
7603 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007604 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007605
7606 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007607 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007608}
David Lamparter6b0655a2014-06-04 06:53:35 +02007609
paul718e3742002-12-13 20:15:29 +00007610DEFUN (show_ip_bgp_community_all,
7611 show_ip_bgp_community_all_cmd,
7612 "show ip bgp community",
7613 SHOW_STR
7614 IP_STR
7615 BGP_STR
7616 "Display routes matching the communities\n")
7617{
7618 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007619 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007620}
7621
7622DEFUN (show_ip_bgp_ipv4_community_all,
7623 show_ip_bgp_ipv4_community_all_cmd,
7624 "show ip bgp ipv4 (unicast|multicast) community",
7625 SHOW_STR
7626 IP_STR
7627 BGP_STR
7628 "Address family\n"
7629 "Address Family modifier\n"
7630 "Address Family modifier\n"
7631 "Display routes matching the communities\n")
7632{
7633 if (strncmp (argv[0], "m", 1) == 0)
7634 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007635 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007636
7637 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007638 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007639}
7640
7641#ifdef HAVE_IPV6
7642DEFUN (show_bgp_community_all,
7643 show_bgp_community_all_cmd,
7644 "show bgp community",
7645 SHOW_STR
7646 BGP_STR
7647 "Display routes matching the communities\n")
7648{
7649 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007650 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007651}
7652
7653ALIAS (show_bgp_community_all,
7654 show_bgp_ipv6_community_all_cmd,
7655 "show bgp ipv6 community",
7656 SHOW_STR
7657 BGP_STR
7658 "Address family\n"
7659 "Display routes matching the communities\n")
7660
7661/* old command */
7662DEFUN (show_ipv6_bgp_community_all,
7663 show_ipv6_bgp_community_all_cmd,
7664 "show ipv6 bgp community",
7665 SHOW_STR
7666 IPV6_STR
7667 BGP_STR
7668 "Display routes matching the communities\n")
7669{
7670 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007671 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007672}
7673
7674/* old command */
7675DEFUN (show_ipv6_mbgp_community_all,
7676 show_ipv6_mbgp_community_all_cmd,
7677 "show ipv6 mbgp community",
7678 SHOW_STR
7679 IPV6_STR
7680 MBGP_STR
7681 "Display routes matching the communities\n")
7682{
7683 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007684 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007685}
7686#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007687
paul94f2b392005-06-28 12:44:16 +00007688static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007689bgp_show_community (struct vty *vty, const char *view_name, int argc,
7690 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007691{
7692 struct community *com;
7693 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007694 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007695 int i;
7696 char *str;
7697 int first = 0;
7698
Michael Lambert95cbbd22010-07-23 14:43:04 -04007699 /* BGP structure lookup */
7700 if (view_name)
7701 {
7702 bgp = bgp_lookup_by_name (view_name);
7703 if (bgp == NULL)
7704 {
7705 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7706 return CMD_WARNING;
7707 }
7708 }
7709 else
7710 {
7711 bgp = bgp_get_default ();
7712 if (bgp == NULL)
7713 {
7714 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7715 return CMD_WARNING;
7716 }
7717 }
7718
paul718e3742002-12-13 20:15:29 +00007719 b = buffer_new (1024);
7720 for (i = 0; i < argc; i++)
7721 {
7722 if (first)
7723 buffer_putc (b, ' ');
7724 else
7725 {
7726 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7727 continue;
7728 first = 1;
7729 }
7730
7731 buffer_putstr (b, argv[i]);
7732 }
7733 buffer_putc (b, '\0');
7734
7735 str = buffer_getstr (b);
7736 buffer_free (b);
7737
7738 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007739 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007740 if (! com)
7741 {
7742 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7743 return CMD_WARNING;
7744 }
7745
Michael Lambert95cbbd22010-07-23 14:43:04 -04007746 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007747 (exact ? bgp_show_type_community_exact :
7748 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007749}
7750
7751DEFUN (show_ip_bgp_community,
7752 show_ip_bgp_community_cmd,
7753 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7754 SHOW_STR
7755 IP_STR
7756 BGP_STR
7757 "Display routes matching the communities\n"
7758 "community number\n"
7759 "Do not send outside local AS (well-known community)\n"
7760 "Do not advertise to any peer (well-known community)\n"
7761 "Do not export to next AS (well-known community)\n")
7762{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007763 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007764}
7765
7766ALIAS (show_ip_bgp_community,
7767 show_ip_bgp_community2_cmd,
7768 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7769 SHOW_STR
7770 IP_STR
7771 BGP_STR
7772 "Display routes matching the communities\n"
7773 "community number\n"
7774 "Do not send outside local AS (well-known community)\n"
7775 "Do not advertise to any peer (well-known community)\n"
7776 "Do not export to next AS (well-known community)\n"
7777 "community number\n"
7778 "Do not send outside local AS (well-known community)\n"
7779 "Do not advertise to any peer (well-known community)\n"
7780 "Do not export to next AS (well-known community)\n")
7781
7782ALIAS (show_ip_bgp_community,
7783 show_ip_bgp_community3_cmd,
7784 "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)",
7785 SHOW_STR
7786 IP_STR
7787 BGP_STR
7788 "Display routes matching the communities\n"
7789 "community number\n"
7790 "Do not send outside local AS (well-known community)\n"
7791 "Do not advertise to any peer (well-known community)\n"
7792 "Do not export to next AS (well-known community)\n"
7793 "community number\n"
7794 "Do not send outside local AS (well-known community)\n"
7795 "Do not advertise to any peer (well-known community)\n"
7796 "Do not export to next AS (well-known community)\n"
7797 "community number\n"
7798 "Do not send outside local AS (well-known community)\n"
7799 "Do not advertise to any peer (well-known community)\n"
7800 "Do not export to next AS (well-known community)\n")
7801
7802ALIAS (show_ip_bgp_community,
7803 show_ip_bgp_community4_cmd,
7804 "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)",
7805 SHOW_STR
7806 IP_STR
7807 BGP_STR
7808 "Display routes matching the communities\n"
7809 "community number\n"
7810 "Do not send outside local AS (well-known community)\n"
7811 "Do not advertise to any peer (well-known community)\n"
7812 "Do not export to next AS (well-known community)\n"
7813 "community number\n"
7814 "Do not send outside local AS (well-known community)\n"
7815 "Do not advertise to any peer (well-known community)\n"
7816 "Do not export to next AS (well-known community)\n"
7817 "community number\n"
7818 "Do not send outside local AS (well-known community)\n"
7819 "Do not advertise to any peer (well-known community)\n"
7820 "Do not export to next AS (well-known community)\n"
7821 "community number\n"
7822 "Do not send outside local AS (well-known community)\n"
7823 "Do not advertise to any peer (well-known community)\n"
7824 "Do not export to next AS (well-known community)\n")
7825
7826DEFUN (show_ip_bgp_ipv4_community,
7827 show_ip_bgp_ipv4_community_cmd,
7828 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7829 SHOW_STR
7830 IP_STR
7831 BGP_STR
7832 "Address family\n"
7833 "Address Family modifier\n"
7834 "Address Family modifier\n"
7835 "Display routes matching the communities\n"
7836 "community number\n"
7837 "Do not send outside local AS (well-known community)\n"
7838 "Do not advertise to any peer (well-known community)\n"
7839 "Do not export to next AS (well-known community)\n")
7840{
7841 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007842 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007843
Michael Lambert95cbbd22010-07-23 14:43:04 -04007844 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007845}
7846
7847ALIAS (show_ip_bgp_ipv4_community,
7848 show_ip_bgp_ipv4_community2_cmd,
7849 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7850 SHOW_STR
7851 IP_STR
7852 BGP_STR
7853 "Address family\n"
7854 "Address Family modifier\n"
7855 "Address Family modifier\n"
7856 "Display routes matching the communities\n"
7857 "community number\n"
7858 "Do not send outside local AS (well-known community)\n"
7859 "Do not advertise to any peer (well-known community)\n"
7860 "Do not export to next AS (well-known community)\n"
7861 "community number\n"
7862 "Do not send outside local AS (well-known community)\n"
7863 "Do not advertise to any peer (well-known community)\n"
7864 "Do not export to next AS (well-known community)\n")
7865
7866ALIAS (show_ip_bgp_ipv4_community,
7867 show_ip_bgp_ipv4_community3_cmd,
7868 "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)",
7869 SHOW_STR
7870 IP_STR
7871 BGP_STR
7872 "Address family\n"
7873 "Address Family modifier\n"
7874 "Address Family modifier\n"
7875 "Display routes matching the communities\n"
7876 "community number\n"
7877 "Do not send outside local AS (well-known community)\n"
7878 "Do not advertise to any peer (well-known community)\n"
7879 "Do not export to next AS (well-known community)\n"
7880 "community number\n"
7881 "Do not send outside local AS (well-known community)\n"
7882 "Do not advertise to any peer (well-known community)\n"
7883 "Do not export to next AS (well-known community)\n"
7884 "community number\n"
7885 "Do not send outside local AS (well-known community)\n"
7886 "Do not advertise to any peer (well-known community)\n"
7887 "Do not export to next AS (well-known community)\n")
7888
7889ALIAS (show_ip_bgp_ipv4_community,
7890 show_ip_bgp_ipv4_community4_cmd,
7891 "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)",
7892 SHOW_STR
7893 IP_STR
7894 BGP_STR
7895 "Address family\n"
7896 "Address Family modifier\n"
7897 "Address Family modifier\n"
7898 "Display routes matching the communities\n"
7899 "community number\n"
7900 "Do not send outside local AS (well-known community)\n"
7901 "Do not advertise to any peer (well-known community)\n"
7902 "Do not export to next AS (well-known community)\n"
7903 "community number\n"
7904 "Do not send outside local AS (well-known community)\n"
7905 "Do not advertise to any peer (well-known community)\n"
7906 "Do not export to next AS (well-known community)\n"
7907 "community number\n"
7908 "Do not send outside local AS (well-known community)\n"
7909 "Do not advertise to any peer (well-known community)\n"
7910 "Do not export to next AS (well-known community)\n"
7911 "community number\n"
7912 "Do not send outside local AS (well-known community)\n"
7913 "Do not advertise to any peer (well-known community)\n"
7914 "Do not export to next AS (well-known community)\n")
7915
Michael Lambert95cbbd22010-07-23 14:43:04 -04007916DEFUN (show_bgp_view_afi_safi_community_all,
7917 show_bgp_view_afi_safi_community_all_cmd,
7918#ifdef HAVE_IPV6
7919 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7920#else
7921 "show bgp view WORD ipv4 (unicast|multicast) community",
7922#endif
7923 SHOW_STR
7924 BGP_STR
7925 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007926 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007927 "Address family\n"
7928#ifdef HAVE_IPV6
7929 "Address family\n"
7930#endif
7931 "Address Family modifier\n"
7932 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00007933 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007934{
7935 int afi;
7936 int safi;
7937 struct bgp *bgp;
7938
7939 /* BGP structure lookup. */
7940 bgp = bgp_lookup_by_name (argv[0]);
7941 if (bgp == NULL)
7942 {
7943 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7944 return CMD_WARNING;
7945 }
7946
7947#ifdef HAVE_IPV6
7948 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7949 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7950#else
7951 afi = AFI_IP;
7952 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7953#endif
7954 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7955}
7956
7957DEFUN (show_bgp_view_afi_safi_community,
7958 show_bgp_view_afi_safi_community_cmd,
7959#ifdef HAVE_IPV6
7960 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7961#else
7962 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7963#endif
7964 SHOW_STR
7965 BGP_STR
7966 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007967 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007968 "Address family\n"
7969#ifdef HAVE_IPV6
7970 "Address family\n"
7971#endif
7972 "Address family modifier\n"
7973 "Address family modifier\n"
7974 "Display routes matching the communities\n"
7975 "community number\n"
7976 "Do not send outside local AS (well-known community)\n"
7977 "Do not advertise to any peer (well-known community)\n"
7978 "Do not export to next AS (well-known community)\n")
7979{
7980 int afi;
7981 int safi;
7982
7983#ifdef HAVE_IPV6
7984 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7985 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7986 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7987#else
7988 afi = AFI_IP;
7989 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7990 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
7991#endif
7992}
7993
7994ALIAS (show_bgp_view_afi_safi_community,
7995 show_bgp_view_afi_safi_community2_cmd,
7996#ifdef HAVE_IPV6
7997 "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)",
7998#else
7999 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8000#endif
8001 SHOW_STR
8002 BGP_STR
8003 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008004 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008005 "Address family\n"
8006#ifdef HAVE_IPV6
8007 "Address family\n"
8008#endif
8009 "Address family modifier\n"
8010 "Address family modifier\n"
8011 "Display routes matching the communities\n"
8012 "community number\n"
8013 "Do not send outside local AS (well-known community)\n"
8014 "Do not advertise to any peer (well-known community)\n"
8015 "Do not export to next AS (well-known community)\n"
8016 "community number\n"
8017 "Do not send outside local AS (well-known community)\n"
8018 "Do not advertise to any peer (well-known community)\n"
8019 "Do not export to next AS (well-known community)\n")
8020
8021ALIAS (show_bgp_view_afi_safi_community,
8022 show_bgp_view_afi_safi_community3_cmd,
8023#ifdef HAVE_IPV6
8024 "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)",
8025#else
8026 "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)",
8027#endif
8028 SHOW_STR
8029 BGP_STR
8030 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008031 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008032 "Address family\n"
8033#ifdef HAVE_IPV6
8034 "Address family\n"
8035#endif
8036 "Address family modifier\n"
8037 "Address family modifier\n"
8038 "Display routes matching the communities\n"
8039 "community number\n"
8040 "Do not send outside local AS (well-known community)\n"
8041 "Do not advertise to any peer (well-known community)\n"
8042 "Do not export to next AS (well-known community)\n"
8043 "community number\n"
8044 "Do not send outside local AS (well-known community)\n"
8045 "Do not advertise to any peer (well-known community)\n"
8046 "Do not export to next AS (well-known community)\n"
8047 "community number\n"
8048 "Do not send outside local AS (well-known community)\n"
8049 "Do not advertise to any peer (well-known community)\n"
8050 "Do not export to next AS (well-known community)\n")
8051
8052ALIAS (show_bgp_view_afi_safi_community,
8053 show_bgp_view_afi_safi_community4_cmd,
8054#ifdef HAVE_IPV6
8055 "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)",
8056#else
8057 "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)",
8058#endif
8059 SHOW_STR
8060 BGP_STR
8061 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008062 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008063 "Address family\n"
8064#ifdef HAVE_IPV6
8065 "Address family\n"
8066#endif
8067 "Address family modifier\n"
8068 "Address family modifier\n"
8069 "Display routes matching the communities\n"
8070 "community number\n"
8071 "Do not send outside local AS (well-known community)\n"
8072 "Do not advertise to any peer (well-known community)\n"
8073 "Do not export to next AS (well-known community)\n"
8074 "community number\n"
8075 "Do not send outside local AS (well-known community)\n"
8076 "Do not advertise to any peer (well-known community)\n"
8077 "Do not export to next AS (well-known community)\n"
8078 "community number\n"
8079 "Do not send outside local AS (well-known community)\n"
8080 "Do not advertise to any peer (well-known community)\n"
8081 "Do not export to next AS (well-known community)\n"
8082 "community number\n"
8083 "Do not send outside local AS (well-known community)\n"
8084 "Do not advertise to any peer (well-known community)\n"
8085 "Do not export to next AS (well-known community)\n")
8086
paul718e3742002-12-13 20:15:29 +00008087DEFUN (show_ip_bgp_community_exact,
8088 show_ip_bgp_community_exact_cmd,
8089 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8090 SHOW_STR
8091 IP_STR
8092 BGP_STR
8093 "Display routes matching the communities\n"
8094 "community number\n"
8095 "Do not send outside local AS (well-known community)\n"
8096 "Do not advertise to any peer (well-known community)\n"
8097 "Do not export to next AS (well-known community)\n"
8098 "Exact match of the communities")
8099{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008100 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008101}
8102
8103ALIAS (show_ip_bgp_community_exact,
8104 show_ip_bgp_community2_exact_cmd,
8105 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8106 SHOW_STR
8107 IP_STR
8108 BGP_STR
8109 "Display routes matching the communities\n"
8110 "community number\n"
8111 "Do not send outside local AS (well-known community)\n"
8112 "Do not advertise to any peer (well-known community)\n"
8113 "Do not export to next AS (well-known community)\n"
8114 "community number\n"
8115 "Do not send outside local AS (well-known community)\n"
8116 "Do not advertise to any peer (well-known community)\n"
8117 "Do not export to next AS (well-known community)\n"
8118 "Exact match of the communities")
8119
8120ALIAS (show_ip_bgp_community_exact,
8121 show_ip_bgp_community3_exact_cmd,
8122 "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",
8123 SHOW_STR
8124 IP_STR
8125 BGP_STR
8126 "Display routes matching the communities\n"
8127 "community number\n"
8128 "Do not send outside local AS (well-known community)\n"
8129 "Do not advertise to any peer (well-known community)\n"
8130 "Do not export to next AS (well-known community)\n"
8131 "community number\n"
8132 "Do not send outside local AS (well-known community)\n"
8133 "Do not advertise to any peer (well-known community)\n"
8134 "Do not export to next AS (well-known community)\n"
8135 "community number\n"
8136 "Do not send outside local AS (well-known community)\n"
8137 "Do not advertise to any peer (well-known community)\n"
8138 "Do not export to next AS (well-known community)\n"
8139 "Exact match of the communities")
8140
8141ALIAS (show_ip_bgp_community_exact,
8142 show_ip_bgp_community4_exact_cmd,
8143 "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",
8144 SHOW_STR
8145 IP_STR
8146 BGP_STR
8147 "Display routes matching the communities\n"
8148 "community number\n"
8149 "Do not send outside local AS (well-known community)\n"
8150 "Do not advertise to any peer (well-known community)\n"
8151 "Do not export to next AS (well-known community)\n"
8152 "community number\n"
8153 "Do not send outside local AS (well-known community)\n"
8154 "Do not advertise to any peer (well-known community)\n"
8155 "Do not export to next AS (well-known community)\n"
8156 "community number\n"
8157 "Do not send outside local AS (well-known community)\n"
8158 "Do not advertise to any peer (well-known community)\n"
8159 "Do not export to next AS (well-known community)\n"
8160 "community number\n"
8161 "Do not send outside local AS (well-known community)\n"
8162 "Do not advertise to any peer (well-known community)\n"
8163 "Do not export to next AS (well-known community)\n"
8164 "Exact match of the communities")
8165
8166DEFUN (show_ip_bgp_ipv4_community_exact,
8167 show_ip_bgp_ipv4_community_exact_cmd,
8168 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8169 SHOW_STR
8170 IP_STR
8171 BGP_STR
8172 "Address family\n"
8173 "Address Family modifier\n"
8174 "Address Family modifier\n"
8175 "Display routes matching the communities\n"
8176 "community number\n"
8177 "Do not send outside local AS (well-known community)\n"
8178 "Do not advertise to any peer (well-known community)\n"
8179 "Do not export to next AS (well-known community)\n"
8180 "Exact match of the communities")
8181{
8182 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008183 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008184
Michael Lambert95cbbd22010-07-23 14:43:04 -04008185 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008186}
8187
8188ALIAS (show_ip_bgp_ipv4_community_exact,
8189 show_ip_bgp_ipv4_community2_exact_cmd,
8190 "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",
8191 SHOW_STR
8192 IP_STR
8193 BGP_STR
8194 "Address family\n"
8195 "Address Family modifier\n"
8196 "Address Family modifier\n"
8197 "Display routes matching the communities\n"
8198 "community number\n"
8199 "Do not send outside local AS (well-known community)\n"
8200 "Do not advertise to any peer (well-known community)\n"
8201 "Do not export to next AS (well-known community)\n"
8202 "community number\n"
8203 "Do not send outside local AS (well-known community)\n"
8204 "Do not advertise to any peer (well-known community)\n"
8205 "Do not export to next AS (well-known community)\n"
8206 "Exact match of the communities")
8207
8208ALIAS (show_ip_bgp_ipv4_community_exact,
8209 show_ip_bgp_ipv4_community3_exact_cmd,
8210 "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",
8211 SHOW_STR
8212 IP_STR
8213 BGP_STR
8214 "Address family\n"
8215 "Address Family modifier\n"
8216 "Address Family modifier\n"
8217 "Display routes matching the communities\n"
8218 "community number\n"
8219 "Do not send outside local AS (well-known community)\n"
8220 "Do not advertise to any peer (well-known community)\n"
8221 "Do not export to next AS (well-known community)\n"
8222 "community number\n"
8223 "Do not send outside local AS (well-known community)\n"
8224 "Do not advertise to any peer (well-known community)\n"
8225 "Do not export to next AS (well-known community)\n"
8226 "community number\n"
8227 "Do not send outside local AS (well-known community)\n"
8228 "Do not advertise to any peer (well-known community)\n"
8229 "Do not export to next AS (well-known community)\n"
8230 "Exact match of the communities")
8231
8232ALIAS (show_ip_bgp_ipv4_community_exact,
8233 show_ip_bgp_ipv4_community4_exact_cmd,
8234 "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",
8235 SHOW_STR
8236 IP_STR
8237 BGP_STR
8238 "Address family\n"
8239 "Address Family modifier\n"
8240 "Address Family modifier\n"
8241 "Display routes matching the communities\n"
8242 "community number\n"
8243 "Do not send outside local AS (well-known community)\n"
8244 "Do not advertise to any peer (well-known community)\n"
8245 "Do not export to next AS (well-known community)\n"
8246 "community number\n"
8247 "Do not send outside local AS (well-known community)\n"
8248 "Do not advertise to any peer (well-known community)\n"
8249 "Do not export to next AS (well-known community)\n"
8250 "community number\n"
8251 "Do not send outside local AS (well-known community)\n"
8252 "Do not advertise to any peer (well-known community)\n"
8253 "Do not export to next AS (well-known community)\n"
8254 "community number\n"
8255 "Do not send outside local AS (well-known community)\n"
8256 "Do not advertise to any peer (well-known community)\n"
8257 "Do not export to next AS (well-known community)\n"
8258 "Exact match of the communities")
8259
8260#ifdef HAVE_IPV6
8261DEFUN (show_bgp_community,
8262 show_bgp_community_cmd,
8263 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8264 SHOW_STR
8265 BGP_STR
8266 "Display routes matching the communities\n"
8267 "community number\n"
8268 "Do not send outside local AS (well-known community)\n"
8269 "Do not advertise to any peer (well-known community)\n"
8270 "Do not export to next AS (well-known community)\n")
8271{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008272 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008273}
8274
8275ALIAS (show_bgp_community,
8276 show_bgp_ipv6_community_cmd,
8277 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8278 SHOW_STR
8279 BGP_STR
8280 "Address family\n"
8281 "Display routes matching the communities\n"
8282 "community number\n"
8283 "Do not send outside local AS (well-known community)\n"
8284 "Do not advertise to any peer (well-known community)\n"
8285 "Do not export to next AS (well-known community)\n")
8286
8287ALIAS (show_bgp_community,
8288 show_bgp_community2_cmd,
8289 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8290 SHOW_STR
8291 BGP_STR
8292 "Display routes matching the communities\n"
8293 "community number\n"
8294 "Do not send outside local AS (well-known community)\n"
8295 "Do not advertise to any peer (well-known community)\n"
8296 "Do not export to next AS (well-known community)\n"
8297 "community number\n"
8298 "Do not send outside local AS (well-known community)\n"
8299 "Do not advertise to any peer (well-known community)\n"
8300 "Do not export to next AS (well-known community)\n")
8301
8302ALIAS (show_bgp_community,
8303 show_bgp_ipv6_community2_cmd,
8304 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8305 SHOW_STR
8306 BGP_STR
8307 "Address family\n"
8308 "Display routes matching the communities\n"
8309 "community number\n"
8310 "Do not send outside local AS (well-known community)\n"
8311 "Do not advertise to any peer (well-known community)\n"
8312 "Do not export to next AS (well-known community)\n"
8313 "community number\n"
8314 "Do not send outside local AS (well-known community)\n"
8315 "Do not advertise to any peer (well-known community)\n"
8316 "Do not export to next AS (well-known community)\n")
8317
8318ALIAS (show_bgp_community,
8319 show_bgp_community3_cmd,
8320 "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)",
8321 SHOW_STR
8322 BGP_STR
8323 "Display routes matching the communities\n"
8324 "community number\n"
8325 "Do not send outside local AS (well-known community)\n"
8326 "Do not advertise to any peer (well-known community)\n"
8327 "Do not export to next AS (well-known community)\n"
8328 "community number\n"
8329 "Do not send outside local AS (well-known community)\n"
8330 "Do not advertise to any peer (well-known community)\n"
8331 "Do not export to next AS (well-known community)\n"
8332 "community number\n"
8333 "Do not send outside local AS (well-known community)\n"
8334 "Do not advertise to any peer (well-known community)\n"
8335 "Do not export to next AS (well-known community)\n")
8336
8337ALIAS (show_bgp_community,
8338 show_bgp_ipv6_community3_cmd,
8339 "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)",
8340 SHOW_STR
8341 BGP_STR
8342 "Address family\n"
8343 "Display routes matching the communities\n"
8344 "community number\n"
8345 "Do not send outside local AS (well-known community)\n"
8346 "Do not advertise to any peer (well-known community)\n"
8347 "Do not export to next AS (well-known community)\n"
8348 "community number\n"
8349 "Do not send outside local AS (well-known community)\n"
8350 "Do not advertise to any peer (well-known community)\n"
8351 "Do not export to next AS (well-known community)\n"
8352 "community number\n"
8353 "Do not send outside local AS (well-known community)\n"
8354 "Do not advertise to any peer (well-known community)\n"
8355 "Do not export to next AS (well-known community)\n")
8356
8357ALIAS (show_bgp_community,
8358 show_bgp_community4_cmd,
8359 "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)",
8360 SHOW_STR
8361 BGP_STR
8362 "Display routes matching the communities\n"
8363 "community number\n"
8364 "Do not send outside local AS (well-known community)\n"
8365 "Do not advertise to any peer (well-known community)\n"
8366 "Do not export to next AS (well-known community)\n"
8367 "community number\n"
8368 "Do not send outside local AS (well-known community)\n"
8369 "Do not advertise to any peer (well-known community)\n"
8370 "Do not export to next AS (well-known community)\n"
8371 "community number\n"
8372 "Do not send outside local AS (well-known community)\n"
8373 "Do not advertise to any peer (well-known community)\n"
8374 "Do not export to next AS (well-known community)\n"
8375 "community number\n"
8376 "Do not send outside local AS (well-known community)\n"
8377 "Do not advertise to any peer (well-known community)\n"
8378 "Do not export to next AS (well-known community)\n")
8379
8380ALIAS (show_bgp_community,
8381 show_bgp_ipv6_community4_cmd,
8382 "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)",
8383 SHOW_STR
8384 BGP_STR
8385 "Address family\n"
8386 "Display routes matching the communities\n"
8387 "community number\n"
8388 "Do not send outside local AS (well-known community)\n"
8389 "Do not advertise to any peer (well-known community)\n"
8390 "Do not export to next AS (well-known community)\n"
8391 "community number\n"
8392 "Do not send outside local AS (well-known community)\n"
8393 "Do not advertise to any peer (well-known community)\n"
8394 "Do not export to next AS (well-known community)\n"
8395 "community number\n"
8396 "Do not send outside local AS (well-known community)\n"
8397 "Do not advertise to any peer (well-known community)\n"
8398 "Do not export to next AS (well-known community)\n"
8399 "community number\n"
8400 "Do not send outside local AS (well-known community)\n"
8401 "Do not advertise to any peer (well-known community)\n"
8402 "Do not export to next AS (well-known community)\n")
8403
8404/* old command */
8405DEFUN (show_ipv6_bgp_community,
8406 show_ipv6_bgp_community_cmd,
8407 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8408 SHOW_STR
8409 IPV6_STR
8410 BGP_STR
8411 "Display routes matching the communities\n"
8412 "community number\n"
8413 "Do not send outside local AS (well-known community)\n"
8414 "Do not advertise to any peer (well-known community)\n"
8415 "Do not export to next AS (well-known community)\n")
8416{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008417 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008418}
8419
8420/* old command */
8421ALIAS (show_ipv6_bgp_community,
8422 show_ipv6_bgp_community2_cmd,
8423 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8424 SHOW_STR
8425 IPV6_STR
8426 BGP_STR
8427 "Display routes matching the communities\n"
8428 "community number\n"
8429 "Do not send outside local AS (well-known community)\n"
8430 "Do not advertise to any peer (well-known community)\n"
8431 "Do not export to next AS (well-known community)\n"
8432 "community number\n"
8433 "Do not send outside local AS (well-known community)\n"
8434 "Do not advertise to any peer (well-known community)\n"
8435 "Do not export to next AS (well-known community)\n")
8436
8437/* old command */
8438ALIAS (show_ipv6_bgp_community,
8439 show_ipv6_bgp_community3_cmd,
8440 "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)",
8441 SHOW_STR
8442 IPV6_STR
8443 BGP_STR
8444 "Display routes matching the communities\n"
8445 "community number\n"
8446 "Do not send outside local AS (well-known community)\n"
8447 "Do not advertise to any peer (well-known community)\n"
8448 "Do not export to next AS (well-known community)\n"
8449 "community number\n"
8450 "Do not send outside local AS (well-known community)\n"
8451 "Do not advertise to any peer (well-known community)\n"
8452 "Do not export to next AS (well-known community)\n"
8453 "community number\n"
8454 "Do not send outside local AS (well-known community)\n"
8455 "Do not advertise to any peer (well-known community)\n"
8456 "Do not export to next AS (well-known community)\n")
8457
8458/* old command */
8459ALIAS (show_ipv6_bgp_community,
8460 show_ipv6_bgp_community4_cmd,
8461 "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)",
8462 SHOW_STR
8463 IPV6_STR
8464 BGP_STR
8465 "Display routes matching the communities\n"
8466 "community number\n"
8467 "Do not send outside local AS (well-known community)\n"
8468 "Do not advertise to any peer (well-known community)\n"
8469 "Do not export to next AS (well-known community)\n"
8470 "community number\n"
8471 "Do not send outside local AS (well-known community)\n"
8472 "Do not advertise to any peer (well-known community)\n"
8473 "Do not export to next AS (well-known community)\n"
8474 "community number\n"
8475 "Do not send outside local AS (well-known community)\n"
8476 "Do not advertise to any peer (well-known community)\n"
8477 "Do not export to next AS (well-known community)\n"
8478 "community number\n"
8479 "Do not send outside local AS (well-known community)\n"
8480 "Do not advertise to any peer (well-known community)\n"
8481 "Do not export to next AS (well-known community)\n")
8482
8483DEFUN (show_bgp_community_exact,
8484 show_bgp_community_exact_cmd,
8485 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8486 SHOW_STR
8487 BGP_STR
8488 "Display routes matching the communities\n"
8489 "community number\n"
8490 "Do not send outside local AS (well-known community)\n"
8491 "Do not advertise to any peer (well-known community)\n"
8492 "Do not export to next AS (well-known community)\n"
8493 "Exact match of the communities")
8494{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008495 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008496}
8497
8498ALIAS (show_bgp_community_exact,
8499 show_bgp_ipv6_community_exact_cmd,
8500 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8501 SHOW_STR
8502 BGP_STR
8503 "Address family\n"
8504 "Display routes matching the communities\n"
8505 "community number\n"
8506 "Do not send outside local AS (well-known community)\n"
8507 "Do not advertise to any peer (well-known community)\n"
8508 "Do not export to next AS (well-known community)\n"
8509 "Exact match of the communities")
8510
8511ALIAS (show_bgp_community_exact,
8512 show_bgp_community2_exact_cmd,
8513 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8514 SHOW_STR
8515 BGP_STR
8516 "Display routes matching the communities\n"
8517 "community number\n"
8518 "Do not send outside local AS (well-known community)\n"
8519 "Do not advertise to any peer (well-known community)\n"
8520 "Do not export to next AS (well-known community)\n"
8521 "community number\n"
8522 "Do not send outside local AS (well-known community)\n"
8523 "Do not advertise to any peer (well-known community)\n"
8524 "Do not export to next AS (well-known community)\n"
8525 "Exact match of the communities")
8526
8527ALIAS (show_bgp_community_exact,
8528 show_bgp_ipv6_community2_exact_cmd,
8529 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8530 SHOW_STR
8531 BGP_STR
8532 "Address family\n"
8533 "Display routes matching the communities\n"
8534 "community number\n"
8535 "Do not send outside local AS (well-known community)\n"
8536 "Do not advertise to any peer (well-known community)\n"
8537 "Do not export to next AS (well-known community)\n"
8538 "community number\n"
8539 "Do not send outside local AS (well-known community)\n"
8540 "Do not advertise to any peer (well-known community)\n"
8541 "Do not export to next AS (well-known community)\n"
8542 "Exact match of the communities")
8543
8544ALIAS (show_bgp_community_exact,
8545 show_bgp_community3_exact_cmd,
8546 "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",
8547 SHOW_STR
8548 BGP_STR
8549 "Display routes matching the communities\n"
8550 "community number\n"
8551 "Do not send outside local AS (well-known community)\n"
8552 "Do not advertise to any peer (well-known community)\n"
8553 "Do not export to next AS (well-known community)\n"
8554 "community number\n"
8555 "Do not send outside local AS (well-known community)\n"
8556 "Do not advertise to any peer (well-known community)\n"
8557 "Do not export to next AS (well-known community)\n"
8558 "community number\n"
8559 "Do not send outside local AS (well-known community)\n"
8560 "Do not advertise to any peer (well-known community)\n"
8561 "Do not export to next AS (well-known community)\n"
8562 "Exact match of the communities")
8563
8564ALIAS (show_bgp_community_exact,
8565 show_bgp_ipv6_community3_exact_cmd,
8566 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8567 SHOW_STR
8568 BGP_STR
8569 "Address family\n"
8570 "Display routes matching the communities\n"
8571 "community number\n"
8572 "Do not send outside local AS (well-known community)\n"
8573 "Do not advertise to any peer (well-known community)\n"
8574 "Do not export to next AS (well-known community)\n"
8575 "community number\n"
8576 "Do not send outside local AS (well-known community)\n"
8577 "Do not advertise to any peer (well-known community)\n"
8578 "Do not export to next AS (well-known community)\n"
8579 "community number\n"
8580 "Do not send outside local AS (well-known community)\n"
8581 "Do not advertise to any peer (well-known community)\n"
8582 "Do not export to next AS (well-known community)\n"
8583 "Exact match of the communities")
8584
8585ALIAS (show_bgp_community_exact,
8586 show_bgp_community4_exact_cmd,
8587 "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",
8588 SHOW_STR
8589 BGP_STR
8590 "Display routes matching the communities\n"
8591 "community number\n"
8592 "Do not send outside local AS (well-known community)\n"
8593 "Do not advertise to any peer (well-known community)\n"
8594 "Do not export to next AS (well-known community)\n"
8595 "community number\n"
8596 "Do not send outside local AS (well-known community)\n"
8597 "Do not advertise to any peer (well-known community)\n"
8598 "Do not export to next AS (well-known community)\n"
8599 "community number\n"
8600 "Do not send outside local AS (well-known community)\n"
8601 "Do not advertise to any peer (well-known community)\n"
8602 "Do not export to next AS (well-known community)\n"
8603 "community number\n"
8604 "Do not send outside local AS (well-known community)\n"
8605 "Do not advertise to any peer (well-known community)\n"
8606 "Do not export to next AS (well-known community)\n"
8607 "Exact match of the communities")
8608
8609ALIAS (show_bgp_community_exact,
8610 show_bgp_ipv6_community4_exact_cmd,
8611 "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",
8612 SHOW_STR
8613 BGP_STR
8614 "Address family\n"
8615 "Display routes matching the communities\n"
8616 "community number\n"
8617 "Do not send outside local AS (well-known community)\n"
8618 "Do not advertise to any peer (well-known community)\n"
8619 "Do not export to next AS (well-known community)\n"
8620 "community number\n"
8621 "Do not send outside local AS (well-known community)\n"
8622 "Do not advertise to any peer (well-known community)\n"
8623 "Do not export to next AS (well-known community)\n"
8624 "community number\n"
8625 "Do not send outside local AS (well-known community)\n"
8626 "Do not advertise to any peer (well-known community)\n"
8627 "Do not export to next AS (well-known community)\n"
8628 "community number\n"
8629 "Do not send outside local AS (well-known community)\n"
8630 "Do not advertise to any peer (well-known community)\n"
8631 "Do not export to next AS (well-known community)\n"
8632 "Exact match of the communities")
8633
8634/* old command */
8635DEFUN (show_ipv6_bgp_community_exact,
8636 show_ipv6_bgp_community_exact_cmd,
8637 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8638 SHOW_STR
8639 IPV6_STR
8640 BGP_STR
8641 "Display routes matching the communities\n"
8642 "community number\n"
8643 "Do not send outside local AS (well-known community)\n"
8644 "Do not advertise to any peer (well-known community)\n"
8645 "Do not export to next AS (well-known community)\n"
8646 "Exact match of the communities")
8647{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008648 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008649}
8650
8651/* old command */
8652ALIAS (show_ipv6_bgp_community_exact,
8653 show_ipv6_bgp_community2_exact_cmd,
8654 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8655 SHOW_STR
8656 IPV6_STR
8657 BGP_STR
8658 "Display routes matching the communities\n"
8659 "community number\n"
8660 "Do not send outside local AS (well-known community)\n"
8661 "Do not advertise to any peer (well-known community)\n"
8662 "Do not export to next AS (well-known community)\n"
8663 "community number\n"
8664 "Do not send outside local AS (well-known community)\n"
8665 "Do not advertise to any peer (well-known community)\n"
8666 "Do not export to next AS (well-known community)\n"
8667 "Exact match of the communities")
8668
8669/* old command */
8670ALIAS (show_ipv6_bgp_community_exact,
8671 show_ipv6_bgp_community3_exact_cmd,
8672 "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",
8673 SHOW_STR
8674 IPV6_STR
8675 BGP_STR
8676 "Display routes matching the communities\n"
8677 "community number\n"
8678 "Do not send outside local AS (well-known community)\n"
8679 "Do not advertise to any peer (well-known community)\n"
8680 "Do not export to next AS (well-known community)\n"
8681 "community number\n"
8682 "Do not send outside local AS (well-known community)\n"
8683 "Do not advertise to any peer (well-known community)\n"
8684 "Do not export to next AS (well-known community)\n"
8685 "community number\n"
8686 "Do not send outside local AS (well-known community)\n"
8687 "Do not advertise to any peer (well-known community)\n"
8688 "Do not export to next AS (well-known community)\n"
8689 "Exact match of the communities")
8690
8691/* old command */
8692ALIAS (show_ipv6_bgp_community_exact,
8693 show_ipv6_bgp_community4_exact_cmd,
8694 "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",
8695 SHOW_STR
8696 IPV6_STR
8697 BGP_STR
8698 "Display routes matching the communities\n"
8699 "community number\n"
8700 "Do not send outside local AS (well-known community)\n"
8701 "Do not advertise to any peer (well-known community)\n"
8702 "Do not export to next AS (well-known community)\n"
8703 "community number\n"
8704 "Do not send outside local AS (well-known community)\n"
8705 "Do not advertise to any peer (well-known community)\n"
8706 "Do not export to next AS (well-known community)\n"
8707 "community number\n"
8708 "Do not send outside local AS (well-known community)\n"
8709 "Do not advertise to any peer (well-known community)\n"
8710 "Do not export to next AS (well-known community)\n"
8711 "community number\n"
8712 "Do not send outside local AS (well-known community)\n"
8713 "Do not advertise to any peer (well-known community)\n"
8714 "Do not export to next AS (well-known community)\n"
8715 "Exact match of the communities")
8716
8717/* old command */
8718DEFUN (show_ipv6_mbgp_community,
8719 show_ipv6_mbgp_community_cmd,
8720 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8721 SHOW_STR
8722 IPV6_STR
8723 MBGP_STR
8724 "Display routes matching the communities\n"
8725 "community number\n"
8726 "Do not send outside local AS (well-known community)\n"
8727 "Do not advertise to any peer (well-known community)\n"
8728 "Do not export to next AS (well-known community)\n")
8729{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008730 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008731}
8732
8733/* old command */
8734ALIAS (show_ipv6_mbgp_community,
8735 show_ipv6_mbgp_community2_cmd,
8736 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8737 SHOW_STR
8738 IPV6_STR
8739 MBGP_STR
8740 "Display routes matching the communities\n"
8741 "community number\n"
8742 "Do not send outside local AS (well-known community)\n"
8743 "Do not advertise to any peer (well-known community)\n"
8744 "Do not export to next AS (well-known community)\n"
8745 "community number\n"
8746 "Do not send outside local AS (well-known community)\n"
8747 "Do not advertise to any peer (well-known community)\n"
8748 "Do not export to next AS (well-known community)\n")
8749
8750/* old command */
8751ALIAS (show_ipv6_mbgp_community,
8752 show_ipv6_mbgp_community3_cmd,
8753 "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)",
8754 SHOW_STR
8755 IPV6_STR
8756 MBGP_STR
8757 "Display routes matching the communities\n"
8758 "community number\n"
8759 "Do not send outside local AS (well-known community)\n"
8760 "Do not advertise to any peer (well-known community)\n"
8761 "Do not export to next AS (well-known community)\n"
8762 "community number\n"
8763 "Do not send outside local AS (well-known community)\n"
8764 "Do not advertise to any peer (well-known community)\n"
8765 "Do not export to next AS (well-known community)\n"
8766 "community number\n"
8767 "Do not send outside local AS (well-known community)\n"
8768 "Do not advertise to any peer (well-known community)\n"
8769 "Do not export to next AS (well-known community)\n")
8770
8771/* old command */
8772ALIAS (show_ipv6_mbgp_community,
8773 show_ipv6_mbgp_community4_cmd,
8774 "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)",
8775 SHOW_STR
8776 IPV6_STR
8777 MBGP_STR
8778 "Display routes matching the communities\n"
8779 "community number\n"
8780 "Do not send outside local AS (well-known community)\n"
8781 "Do not advertise to any peer (well-known community)\n"
8782 "Do not export to next AS (well-known community)\n"
8783 "community number\n"
8784 "Do not send outside local AS (well-known community)\n"
8785 "Do not advertise to any peer (well-known community)\n"
8786 "Do not export to next AS (well-known community)\n"
8787 "community number\n"
8788 "Do not send outside local AS (well-known community)\n"
8789 "Do not advertise to any peer (well-known community)\n"
8790 "Do not export to next AS (well-known community)\n"
8791 "community number\n"
8792 "Do not send outside local AS (well-known community)\n"
8793 "Do not advertise to any peer (well-known community)\n"
8794 "Do not export to next AS (well-known community)\n")
8795
8796/* old command */
8797DEFUN (show_ipv6_mbgp_community_exact,
8798 show_ipv6_mbgp_community_exact_cmd,
8799 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8800 SHOW_STR
8801 IPV6_STR
8802 MBGP_STR
8803 "Display routes matching the communities\n"
8804 "community number\n"
8805 "Do not send outside local AS (well-known community)\n"
8806 "Do not advertise to any peer (well-known community)\n"
8807 "Do not export to next AS (well-known community)\n"
8808 "Exact match of the communities")
8809{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008810 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008811}
8812
8813/* old command */
8814ALIAS (show_ipv6_mbgp_community_exact,
8815 show_ipv6_mbgp_community2_exact_cmd,
8816 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8817 SHOW_STR
8818 IPV6_STR
8819 MBGP_STR
8820 "Display routes matching the communities\n"
8821 "community number\n"
8822 "Do not send outside local AS (well-known community)\n"
8823 "Do not advertise to any peer (well-known community)\n"
8824 "Do not export to next AS (well-known community)\n"
8825 "community number\n"
8826 "Do not send outside local AS (well-known community)\n"
8827 "Do not advertise to any peer (well-known community)\n"
8828 "Do not export to next AS (well-known community)\n"
8829 "Exact match of the communities")
8830
8831/* old command */
8832ALIAS (show_ipv6_mbgp_community_exact,
8833 show_ipv6_mbgp_community3_exact_cmd,
8834 "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",
8835 SHOW_STR
8836 IPV6_STR
8837 MBGP_STR
8838 "Display routes matching the communities\n"
8839 "community number\n"
8840 "Do not send outside local AS (well-known community)\n"
8841 "Do not advertise to any peer (well-known community)\n"
8842 "Do not export to next AS (well-known community)\n"
8843 "community number\n"
8844 "Do not send outside local AS (well-known community)\n"
8845 "Do not advertise to any peer (well-known community)\n"
8846 "Do not export to next AS (well-known community)\n"
8847 "community number\n"
8848 "Do not send outside local AS (well-known community)\n"
8849 "Do not advertise to any peer (well-known community)\n"
8850 "Do not export to next AS (well-known community)\n"
8851 "Exact match of the communities")
8852
8853/* old command */
8854ALIAS (show_ipv6_mbgp_community_exact,
8855 show_ipv6_mbgp_community4_exact_cmd,
8856 "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",
8857 SHOW_STR
8858 IPV6_STR
8859 MBGP_STR
8860 "Display routes matching the communities\n"
8861 "community number\n"
8862 "Do not send outside local AS (well-known community)\n"
8863 "Do not advertise to any peer (well-known community)\n"
8864 "Do not export to next AS (well-known community)\n"
8865 "community number\n"
8866 "Do not send outside local AS (well-known community)\n"
8867 "Do not advertise to any peer (well-known community)\n"
8868 "Do not export to next AS (well-known community)\n"
8869 "community number\n"
8870 "Do not send outside local AS (well-known community)\n"
8871 "Do not advertise to any peer (well-known community)\n"
8872 "Do not export to next AS (well-known community)\n"
8873 "community number\n"
8874 "Do not send outside local AS (well-known community)\n"
8875 "Do not advertise to any peer (well-known community)\n"
8876 "Do not export to next AS (well-known community)\n"
8877 "Exact match of the communities")
8878#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02008879
paul94f2b392005-06-28 12:44:16 +00008880static int
paulfd79ac92004-10-13 05:06:08 +00008881bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008882 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008883{
8884 struct community_list *list;
8885
hassofee6e4e2005-02-02 16:29:31 +00008886 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008887 if (list == NULL)
8888 {
8889 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8890 VTY_NEWLINE);
8891 return CMD_WARNING;
8892 }
8893
ajs5a646652004-11-05 01:25:55 +00008894 return bgp_show (vty, NULL, afi, safi,
8895 (exact ? bgp_show_type_community_list_exact :
8896 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008897}
8898
8899DEFUN (show_ip_bgp_community_list,
8900 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008901 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008902 SHOW_STR
8903 IP_STR
8904 BGP_STR
8905 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008906 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008907 "community-list name\n")
8908{
8909 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8910}
8911
8912DEFUN (show_ip_bgp_ipv4_community_list,
8913 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008914 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008915 SHOW_STR
8916 IP_STR
8917 BGP_STR
8918 "Address family\n"
8919 "Address Family modifier\n"
8920 "Address Family modifier\n"
8921 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008922 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008923 "community-list name\n")
8924{
8925 if (strncmp (argv[0], "m", 1) == 0)
8926 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8927
8928 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8929}
8930
8931DEFUN (show_ip_bgp_community_list_exact,
8932 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008933 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008934 SHOW_STR
8935 IP_STR
8936 BGP_STR
8937 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008938 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008939 "community-list name\n"
8940 "Exact match of the communities\n")
8941{
8942 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8943}
8944
8945DEFUN (show_ip_bgp_ipv4_community_list_exact,
8946 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008947 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008948 SHOW_STR
8949 IP_STR
8950 BGP_STR
8951 "Address family\n"
8952 "Address Family modifier\n"
8953 "Address Family modifier\n"
8954 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008955 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008956 "community-list name\n"
8957 "Exact match of the communities\n")
8958{
8959 if (strncmp (argv[0], "m", 1) == 0)
8960 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8961
8962 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8963}
8964
8965#ifdef HAVE_IPV6
8966DEFUN (show_bgp_community_list,
8967 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008968 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008969 SHOW_STR
8970 BGP_STR
8971 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008972 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008973 "community-list name\n")
8974{
8975 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8976}
8977
8978ALIAS (show_bgp_community_list,
8979 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008980 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008981 SHOW_STR
8982 BGP_STR
8983 "Address family\n"
8984 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008985 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008986 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008987
8988/* old command */
8989DEFUN (show_ipv6_bgp_community_list,
8990 show_ipv6_bgp_community_list_cmd,
8991 "show ipv6 bgp community-list WORD",
8992 SHOW_STR
8993 IPV6_STR
8994 BGP_STR
8995 "Display routes matching the community-list\n"
8996 "community-list name\n")
8997{
8998 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8999}
9000
9001/* old command */
9002DEFUN (show_ipv6_mbgp_community_list,
9003 show_ipv6_mbgp_community_list_cmd,
9004 "show ipv6 mbgp community-list WORD",
9005 SHOW_STR
9006 IPV6_STR
9007 MBGP_STR
9008 "Display routes matching the community-list\n"
9009 "community-list name\n")
9010{
9011 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
9012}
9013
9014DEFUN (show_bgp_community_list_exact,
9015 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009016 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009017 SHOW_STR
9018 BGP_STR
9019 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009020 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009021 "community-list name\n"
9022 "Exact match of the communities\n")
9023{
9024 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9025}
9026
9027ALIAS (show_bgp_community_list_exact,
9028 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009029 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009030 SHOW_STR
9031 BGP_STR
9032 "Address family\n"
9033 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009034 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009035 "community-list name\n"
9036 "Exact match of the communities\n")
9037
9038/* old command */
9039DEFUN (show_ipv6_bgp_community_list_exact,
9040 show_ipv6_bgp_community_list_exact_cmd,
9041 "show ipv6 bgp community-list WORD exact-match",
9042 SHOW_STR
9043 IPV6_STR
9044 BGP_STR
9045 "Display routes matching the community-list\n"
9046 "community-list name\n"
9047 "Exact match of the communities\n")
9048{
9049 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9050}
9051
9052/* old command */
9053DEFUN (show_ipv6_mbgp_community_list_exact,
9054 show_ipv6_mbgp_community_list_exact_cmd,
9055 "show ipv6 mbgp community-list WORD exact-match",
9056 SHOW_STR
9057 IPV6_STR
9058 MBGP_STR
9059 "Display routes matching the community-list\n"
9060 "community-list name\n"
9061 "Exact match of the communities\n")
9062{
9063 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9064}
9065#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009066
paul94f2b392005-06-28 12:44:16 +00009067static int
paulfd79ac92004-10-13 05:06:08 +00009068bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009069 safi_t safi, enum bgp_show_type type)
9070{
9071 int ret;
9072 struct prefix *p;
9073
9074 p = prefix_new();
9075
9076 ret = str2prefix (prefix, p);
9077 if (! ret)
9078 {
9079 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9080 return CMD_WARNING;
9081 }
9082
ajs5a646652004-11-05 01:25:55 +00009083 ret = bgp_show (vty, NULL, afi, safi, type, p);
9084 prefix_free(p);
9085 return ret;
paul718e3742002-12-13 20:15:29 +00009086}
9087
9088DEFUN (show_ip_bgp_prefix_longer,
9089 show_ip_bgp_prefix_longer_cmd,
9090 "show ip bgp A.B.C.D/M longer-prefixes",
9091 SHOW_STR
9092 IP_STR
9093 BGP_STR
9094 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9095 "Display route and more specific routes\n")
9096{
9097 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9098 bgp_show_type_prefix_longer);
9099}
9100
9101DEFUN (show_ip_bgp_flap_prefix_longer,
9102 show_ip_bgp_flap_prefix_longer_cmd,
9103 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9104 SHOW_STR
9105 IP_STR
9106 BGP_STR
9107 "Display flap statistics of routes\n"
9108 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9109 "Display route and more specific routes\n")
9110{
9111 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9112 bgp_show_type_flap_prefix_longer);
9113}
9114
9115DEFUN (show_ip_bgp_ipv4_prefix_longer,
9116 show_ip_bgp_ipv4_prefix_longer_cmd,
9117 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9118 SHOW_STR
9119 IP_STR
9120 BGP_STR
9121 "Address family\n"
9122 "Address Family modifier\n"
9123 "Address Family modifier\n"
9124 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9125 "Display route and more specific routes\n")
9126{
9127 if (strncmp (argv[0], "m", 1) == 0)
9128 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9129 bgp_show_type_prefix_longer);
9130
9131 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9132 bgp_show_type_prefix_longer);
9133}
9134
9135DEFUN (show_ip_bgp_flap_address,
9136 show_ip_bgp_flap_address_cmd,
9137 "show ip bgp flap-statistics A.B.C.D",
9138 SHOW_STR
9139 IP_STR
9140 BGP_STR
9141 "Display flap statistics of routes\n"
9142 "Network in the BGP routing table to display\n")
9143{
9144 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9145 bgp_show_type_flap_address);
9146}
9147
9148DEFUN (show_ip_bgp_flap_prefix,
9149 show_ip_bgp_flap_prefix_cmd,
9150 "show ip bgp flap-statistics A.B.C.D/M",
9151 SHOW_STR
9152 IP_STR
9153 BGP_STR
9154 "Display flap statistics of routes\n"
9155 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9156{
9157 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9158 bgp_show_type_flap_prefix);
9159}
9160#ifdef HAVE_IPV6
9161DEFUN (show_bgp_prefix_longer,
9162 show_bgp_prefix_longer_cmd,
9163 "show bgp X:X::X:X/M longer-prefixes",
9164 SHOW_STR
9165 BGP_STR
9166 "IPv6 prefix <network>/<length>\n"
9167 "Display route and more specific routes\n")
9168{
9169 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9170 bgp_show_type_prefix_longer);
9171}
9172
9173ALIAS (show_bgp_prefix_longer,
9174 show_bgp_ipv6_prefix_longer_cmd,
9175 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9176 SHOW_STR
9177 BGP_STR
9178 "Address family\n"
9179 "IPv6 prefix <network>/<length>\n"
9180 "Display route and more specific routes\n")
9181
9182/* old command */
9183DEFUN (show_ipv6_bgp_prefix_longer,
9184 show_ipv6_bgp_prefix_longer_cmd,
9185 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9186 SHOW_STR
9187 IPV6_STR
9188 BGP_STR
9189 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9190 "Display route and more specific routes\n")
9191{
9192 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9193 bgp_show_type_prefix_longer);
9194}
9195
9196/* old command */
9197DEFUN (show_ipv6_mbgp_prefix_longer,
9198 show_ipv6_mbgp_prefix_longer_cmd,
9199 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9200 SHOW_STR
9201 IPV6_STR
9202 MBGP_STR
9203 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9204 "Display route and more specific routes\n")
9205{
9206 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9207 bgp_show_type_prefix_longer);
9208}
9209#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009210
paul94f2b392005-06-28 12:44:16 +00009211static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009212peer_lookup_in_view (struct vty *vty, const char *view_name,
9213 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009214{
9215 int ret;
9216 struct bgp *bgp;
9217 struct peer *peer;
9218 union sockunion su;
9219
9220 /* BGP structure lookup. */
9221 if (view_name)
9222 {
9223 bgp = bgp_lookup_by_name (view_name);
9224 if (! bgp)
9225 {
9226 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9227 return NULL;
9228 }
9229 }
paul5228ad22004-06-04 17:58:18 +00009230 else
paulbb46e942003-10-24 19:02:03 +00009231 {
9232 bgp = bgp_get_default ();
9233 if (! bgp)
9234 {
9235 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9236 return NULL;
9237 }
9238 }
9239
9240 /* Get peer sockunion. */
9241 ret = str2sockunion (ip_str, &su);
9242 if (ret < 0)
9243 {
9244 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9245 return NULL;
9246 }
9247
9248 /* Peer structure lookup. */
9249 peer = peer_lookup (bgp, &su);
9250 if (! peer)
9251 {
9252 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9253 return NULL;
9254 }
9255
9256 return peer;
9257}
David Lamparter6b0655a2014-06-04 06:53:35 +02009258
Paul Jakma2815e612006-09-14 02:56:07 +00009259enum bgp_stats
9260{
9261 BGP_STATS_MAXBITLEN = 0,
9262 BGP_STATS_RIB,
9263 BGP_STATS_PREFIXES,
9264 BGP_STATS_TOTPLEN,
9265 BGP_STATS_UNAGGREGATEABLE,
9266 BGP_STATS_MAX_AGGREGATEABLE,
9267 BGP_STATS_AGGREGATES,
9268 BGP_STATS_SPACE,
9269 BGP_STATS_ASPATH_COUNT,
9270 BGP_STATS_ASPATH_MAXHOPS,
9271 BGP_STATS_ASPATH_TOTHOPS,
9272 BGP_STATS_ASPATH_MAXSIZE,
9273 BGP_STATS_ASPATH_TOTSIZE,
9274 BGP_STATS_ASN_HIGHEST,
9275 BGP_STATS_MAX,
9276};
paulbb46e942003-10-24 19:02:03 +00009277
Paul Jakma2815e612006-09-14 02:56:07 +00009278static const char *table_stats_strs[] =
9279{
9280 [BGP_STATS_PREFIXES] = "Total Prefixes",
9281 [BGP_STATS_TOTPLEN] = "Average prefix length",
9282 [BGP_STATS_RIB] = "Total Advertisements",
9283 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9284 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9285 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9286 [BGP_STATS_SPACE] = "Address space advertised",
9287 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9288 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9289 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9290 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9291 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9292 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9293 [BGP_STATS_MAX] = NULL,
9294};
9295
9296struct bgp_table_stats
9297{
9298 struct bgp_table *table;
9299 unsigned long long counts[BGP_STATS_MAX];
9300};
9301
9302#if 0
9303#define TALLY_SIGFIG 100000
9304static unsigned long
9305ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9306{
9307 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9308 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9309 unsigned long ret = newtot / count;
9310
9311 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9312 return ret + 1;
9313 else
9314 return ret;
9315}
9316#endif
9317
9318static int
9319bgp_table_stats_walker (struct thread *t)
9320{
9321 struct bgp_node *rn;
9322 struct bgp_node *top;
9323 struct bgp_table_stats *ts = THREAD_ARG (t);
9324 unsigned int space = 0;
9325
Paul Jakma53d9f672006-10-15 23:41:16 +00009326 if (!(top = bgp_table_top (ts->table)))
9327 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009328
9329 switch (top->p.family)
9330 {
9331 case AF_INET:
9332 space = IPV4_MAX_BITLEN;
9333 break;
9334 case AF_INET6:
9335 space = IPV6_MAX_BITLEN;
9336 break;
9337 }
9338
9339 ts->counts[BGP_STATS_MAXBITLEN] = space;
9340
9341 for (rn = top; rn; rn = bgp_route_next (rn))
9342 {
9343 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009344 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009345 unsigned int rinum = 0;
9346
9347 if (rn == top)
9348 continue;
9349
9350 if (!rn->info)
9351 continue;
9352
9353 ts->counts[BGP_STATS_PREFIXES]++;
9354 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9355
9356#if 0
9357 ts->counts[BGP_STATS_AVGPLEN]
9358 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9359 ts->counts[BGP_STATS_AVGPLEN],
9360 rn->p.prefixlen);
9361#endif
9362
9363 /* check if the prefix is included by any other announcements */
9364 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009365 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009366
9367 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009368 {
9369 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9370 /* announced address space */
9371 if (space)
9372 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9373 }
Paul Jakma2815e612006-09-14 02:56:07 +00009374 else if (prn->info)
9375 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9376
Paul Jakma2815e612006-09-14 02:56:07 +00009377 for (ri = rn->info; ri; ri = ri->next)
9378 {
9379 rinum++;
9380 ts->counts[BGP_STATS_RIB]++;
9381
9382 if (ri->attr &&
9383 (CHECK_FLAG (ri->attr->flag,
9384 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9385 ts->counts[BGP_STATS_AGGREGATES]++;
9386
9387 /* as-path stats */
9388 if (ri->attr && ri->attr->aspath)
9389 {
9390 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9391 unsigned int size = aspath_size (ri->attr->aspath);
9392 as_t highest = aspath_highest (ri->attr->aspath);
9393
9394 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9395
9396 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9397 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9398
9399 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9400 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9401
9402 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9403 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9404#if 0
9405 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9406 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9407 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9408 hops);
9409 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9410 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9411 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9412 size);
9413#endif
9414 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9415 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9416 }
9417 }
9418 }
9419 return 0;
9420}
9421
9422static int
9423bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9424{
9425 struct bgp_table_stats ts;
9426 unsigned int i;
9427
9428 if (!bgp->rib[afi][safi])
9429 {
9430 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9431 return CMD_WARNING;
9432 }
9433
9434 memset (&ts, 0, sizeof (ts));
9435 ts.table = bgp->rib[afi][safi];
9436 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9437
9438 vty_out (vty, "BGP %s RIB statistics%s%s",
9439 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9440
9441 for (i = 0; i < BGP_STATS_MAX; i++)
9442 {
9443 if (!table_stats_strs[i])
9444 continue;
9445
9446 switch (i)
9447 {
9448#if 0
9449 case BGP_STATS_ASPATH_AVGHOPS:
9450 case BGP_STATS_ASPATH_AVGSIZE:
9451 case BGP_STATS_AVGPLEN:
9452 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9453 vty_out (vty, "%12.2f",
9454 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9455 break;
9456#endif
9457 case BGP_STATS_ASPATH_TOTHOPS:
9458 case BGP_STATS_ASPATH_TOTSIZE:
9459 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9460 vty_out (vty, "%12.2f",
9461 ts.counts[i] ?
9462 (float)ts.counts[i] /
9463 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9464 : 0);
9465 break;
9466 case BGP_STATS_TOTPLEN:
9467 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9468 vty_out (vty, "%12.2f",
9469 ts.counts[i] ?
9470 (float)ts.counts[i] /
9471 (float)ts.counts[BGP_STATS_PREFIXES]
9472 : 0);
9473 break;
9474 case BGP_STATS_SPACE:
9475 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9476 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9477 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9478 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009479 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009480 vty_out (vty, "%12.2f%s",
9481 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009482 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009483 VTY_NEWLINE);
9484 vty_out (vty, "%30s: ", "/8 equivalent ");
9485 vty_out (vty, "%12.2f%s",
9486 (float)ts.counts[BGP_STATS_SPACE] /
9487 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9488 VTY_NEWLINE);
9489 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9490 break;
9491 vty_out (vty, "%30s: ", "/24 equivalent ");
9492 vty_out (vty, "%12.2f",
9493 (float)ts.counts[BGP_STATS_SPACE] /
9494 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9495 break;
9496 default:
9497 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9498 vty_out (vty, "%12llu", ts.counts[i]);
9499 }
9500
9501 vty_out (vty, "%s", VTY_NEWLINE);
9502 }
9503 return CMD_SUCCESS;
9504}
9505
9506static int
9507bgp_table_stats_vty (struct vty *vty, const char *name,
9508 const char *afi_str, const char *safi_str)
9509{
9510 struct bgp *bgp;
9511 afi_t afi;
9512 safi_t safi;
9513
9514 if (name)
9515 bgp = bgp_lookup_by_name (name);
9516 else
9517 bgp = bgp_get_default ();
9518
9519 if (!bgp)
9520 {
9521 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9522 return CMD_WARNING;
9523 }
9524 if (strncmp (afi_str, "ipv", 3) == 0)
9525 {
9526 if (strncmp (afi_str, "ipv4", 4) == 0)
9527 afi = AFI_IP;
9528 else if (strncmp (afi_str, "ipv6", 4) == 0)
9529 afi = AFI_IP6;
9530 else
9531 {
9532 vty_out (vty, "%% Invalid address family %s%s",
9533 afi_str, VTY_NEWLINE);
9534 return CMD_WARNING;
9535 }
9536 if (strncmp (safi_str, "m", 1) == 0)
9537 safi = SAFI_MULTICAST;
9538 else if (strncmp (safi_str, "u", 1) == 0)
9539 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009540 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9541 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009542 else
9543 {
9544 vty_out (vty, "%% Invalid subsequent address family %s%s",
9545 safi_str, VTY_NEWLINE);
9546 return CMD_WARNING;
9547 }
9548 }
9549 else
9550 {
9551 vty_out (vty, "%% Invalid address family %s%s",
9552 afi_str, VTY_NEWLINE);
9553 return CMD_WARNING;
9554 }
9555
Paul Jakma2815e612006-09-14 02:56:07 +00009556 return bgp_table_stats (vty, bgp, afi, safi);
9557}
9558
9559DEFUN (show_bgp_statistics,
9560 show_bgp_statistics_cmd,
9561 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9562 SHOW_STR
9563 BGP_STR
9564 "Address family\n"
9565 "Address family\n"
9566 "Address Family modifier\n"
9567 "Address Family modifier\n"
9568 "BGP RIB advertisement statistics\n")
9569{
9570 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9571}
9572
9573ALIAS (show_bgp_statistics,
9574 show_bgp_statistics_vpnv4_cmd,
9575 "show bgp (ipv4) (vpnv4) statistics",
9576 SHOW_STR
9577 BGP_STR
9578 "Address family\n"
9579 "Address Family modifier\n"
9580 "BGP RIB advertisement statistics\n")
9581
9582DEFUN (show_bgp_statistics_view,
9583 show_bgp_statistics_view_cmd,
9584 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9585 SHOW_STR
9586 BGP_STR
9587 "BGP view\n"
9588 "Address family\n"
9589 "Address family\n"
9590 "Address Family modifier\n"
9591 "Address Family modifier\n"
9592 "BGP RIB advertisement statistics\n")
9593{
9594 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9595}
9596
9597ALIAS (show_bgp_statistics_view,
9598 show_bgp_statistics_view_vpnv4_cmd,
9599 "show bgp view WORD (ipv4) (vpnv4) statistics",
9600 SHOW_STR
9601 BGP_STR
9602 "BGP view\n"
9603 "Address family\n"
9604 "Address Family modifier\n"
9605 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02009606
Paul Jakmaff7924f2006-09-04 01:10:36 +00009607enum bgp_pcounts
9608{
9609 PCOUNT_ADJ_IN = 0,
9610 PCOUNT_DAMPED,
9611 PCOUNT_REMOVED,
9612 PCOUNT_HISTORY,
9613 PCOUNT_STALE,
9614 PCOUNT_VALID,
9615 PCOUNT_ALL,
9616 PCOUNT_COUNTED,
9617 PCOUNT_PFCNT, /* the figure we display to users */
9618 PCOUNT_MAX,
9619};
9620
9621static const char *pcount_strs[] =
9622{
9623 [PCOUNT_ADJ_IN] = "Adj-in",
9624 [PCOUNT_DAMPED] = "Damped",
9625 [PCOUNT_REMOVED] = "Removed",
9626 [PCOUNT_HISTORY] = "History",
9627 [PCOUNT_STALE] = "Stale",
9628 [PCOUNT_VALID] = "Valid",
9629 [PCOUNT_ALL] = "All RIB",
9630 [PCOUNT_COUNTED] = "PfxCt counted",
9631 [PCOUNT_PFCNT] = "Useable",
9632 [PCOUNT_MAX] = NULL,
9633};
9634
Paul Jakma2815e612006-09-14 02:56:07 +00009635struct peer_pcounts
9636{
9637 unsigned int count[PCOUNT_MAX];
9638 const struct peer *peer;
9639 const struct bgp_table *table;
9640};
9641
Paul Jakmaff7924f2006-09-04 01:10:36 +00009642static int
Paul Jakma2815e612006-09-14 02:56:07 +00009643bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009644{
9645 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009646 struct peer_pcounts *pc = THREAD_ARG (t);
9647 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009648
Paul Jakma2815e612006-09-14 02:56:07 +00009649 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009650 {
9651 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009652 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009653
9654 for (ain = rn->adj_in; ain; ain = ain->next)
9655 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009656 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009657
Paul Jakmaff7924f2006-09-04 01:10:36 +00009658 for (ri = rn->info; ri; ri = ri->next)
9659 {
9660 char buf[SU_ADDRSTRLEN];
9661
9662 if (ri->peer != peer)
9663 continue;
9664
Paul Jakma2815e612006-09-14 02:56:07 +00009665 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009666
9667 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009668 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009669 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009670 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009671 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009672 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009673 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009674 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009675 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009676 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009677 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009678 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009679
9680 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9681 {
Paul Jakma2815e612006-09-14 02:56:07 +00009682 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009683 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009684 plog_warn (peer->log,
9685 "%s [pcount] %s/%d is counted but flags 0x%x",
9686 peer->host,
9687 inet_ntop(rn->p.family, &rn->p.u.prefix,
9688 buf, SU_ADDRSTRLEN),
9689 rn->p.prefixlen,
9690 ri->flags);
9691 }
9692 else
9693 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009694 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009695 plog_warn (peer->log,
9696 "%s [pcount] %s/%d not counted but flags 0x%x",
9697 peer->host,
9698 inet_ntop(rn->p.family, &rn->p.u.prefix,
9699 buf, SU_ADDRSTRLEN),
9700 rn->p.prefixlen,
9701 ri->flags);
9702 }
9703 }
9704 }
Paul Jakma2815e612006-09-14 02:56:07 +00009705 return 0;
9706}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009707
Paul Jakma2815e612006-09-14 02:56:07 +00009708static int
9709bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9710{
9711 struct peer_pcounts pcounts = { .peer = peer };
9712 unsigned int i;
9713
9714 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9715 || !peer->bgp->rib[afi][safi])
9716 {
9717 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9718 return CMD_WARNING;
9719 }
9720
9721 memset (&pcounts, 0, sizeof(pcounts));
9722 pcounts.peer = peer;
9723 pcounts.table = peer->bgp->rib[afi][safi];
9724
9725 /* in-place call via thread subsystem so as to record execution time
9726 * stats for the thread-walk (i.e. ensure this can't be blamed on
9727 * on just vty_read()).
9728 */
9729 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9730
Paul Jakmaff7924f2006-09-04 01:10:36 +00009731 vty_out (vty, "Prefix counts for %s, %s%s",
9732 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9733 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9734 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9735 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9736
9737 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009738 vty_out (vty, "%20s: %-10d%s",
9739 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009740
Paul Jakma2815e612006-09-14 02:56:07 +00009741 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009742 {
9743 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9744 peer->host, VTY_NEWLINE);
9745 vty_out (vty, "Please report this bug, with the above command output%s",
9746 VTY_NEWLINE);
9747 }
9748
9749 return CMD_SUCCESS;
9750}
9751
9752DEFUN (show_ip_bgp_neighbor_prefix_counts,
9753 show_ip_bgp_neighbor_prefix_counts_cmd,
9754 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9755 SHOW_STR
9756 IP_STR
9757 BGP_STR
9758 "Detailed information on TCP and BGP neighbor connections\n"
9759 "Neighbor to display information about\n"
9760 "Neighbor to display information about\n"
9761 "Display detailed prefix count information\n")
9762{
9763 struct peer *peer;
9764
9765 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9766 if (! peer)
9767 return CMD_WARNING;
9768
9769 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9770}
9771
9772DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9773 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9774 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9775 SHOW_STR
9776 BGP_STR
9777 "Address family\n"
9778 "Detailed information on TCP and BGP neighbor connections\n"
9779 "Neighbor to display information about\n"
9780 "Neighbor to display information about\n"
9781 "Display detailed prefix count information\n")
9782{
9783 struct peer *peer;
9784
9785 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9786 if (! peer)
9787 return CMD_WARNING;
9788
9789 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9790}
9791
9792DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9793 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9794 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9795 SHOW_STR
9796 IP_STR
9797 BGP_STR
9798 "Address family\n"
9799 "Address Family modifier\n"
9800 "Address Family modifier\n"
9801 "Detailed information on TCP and BGP neighbor connections\n"
9802 "Neighbor to display information about\n"
9803 "Neighbor to display information about\n"
9804 "Display detailed prefix count information\n")
9805{
9806 struct peer *peer;
9807
9808 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9809 if (! peer)
9810 return CMD_WARNING;
9811
9812 if (strncmp (argv[0], "m", 1) == 0)
9813 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9814
9815 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9816}
9817
9818DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9819 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9820 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9821 SHOW_STR
9822 IP_STR
9823 BGP_STR
9824 "Address family\n"
9825 "Address Family modifier\n"
9826 "Address Family modifier\n"
9827 "Detailed information on TCP and BGP neighbor connections\n"
9828 "Neighbor to display information about\n"
9829 "Neighbor to display information about\n"
9830 "Display detailed prefix count information\n")
9831{
9832 struct peer *peer;
9833
9834 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9835 if (! peer)
9836 return CMD_WARNING;
9837
9838 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9839}
9840
9841
paul94f2b392005-06-28 12:44:16 +00009842static void
paul718e3742002-12-13 20:15:29 +00009843show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9844 int in)
9845{
9846 struct bgp_table *table;
9847 struct bgp_adj_in *ain;
9848 struct bgp_adj_out *adj;
9849 unsigned long output_count;
9850 struct bgp_node *rn;
9851 int header1 = 1;
9852 struct bgp *bgp;
9853 int header2 = 1;
9854
paulbb46e942003-10-24 19:02:03 +00009855 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009856
9857 if (! bgp)
9858 return;
9859
9860 table = bgp->rib[afi][safi];
9861
9862 output_count = 0;
9863
9864 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9865 PEER_STATUS_DEFAULT_ORIGINATE))
9866 {
9867 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 +00009868 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9869 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009870
9871 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9872 VTY_NEWLINE, VTY_NEWLINE);
9873 header1 = 0;
9874 }
9875
9876 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9877 if (in)
9878 {
9879 for (ain = rn->adj_in; ain; ain = ain->next)
9880 if (ain->peer == peer)
9881 {
9882 if (header1)
9883 {
9884 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 +00009885 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9886 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009887 header1 = 0;
9888 }
9889 if (header2)
9890 {
9891 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9892 header2 = 0;
9893 }
9894 if (ain->attr)
9895 {
9896 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9897 output_count++;
9898 }
9899 }
9900 }
9901 else
9902 {
9903 for (adj = rn->adj_out; adj; adj = adj->next)
9904 if (adj->peer == peer)
9905 {
9906 if (header1)
9907 {
9908 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 +00009909 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9910 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009911 header1 = 0;
9912 }
9913 if (header2)
9914 {
9915 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9916 header2 = 0;
9917 }
9918 if (adj->attr)
9919 {
9920 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9921 output_count++;
9922 }
9923 }
9924 }
9925
9926 if (output_count != 0)
9927 vty_out (vty, "%sTotal number of prefixes %ld%s",
9928 VTY_NEWLINE, output_count, VTY_NEWLINE);
9929}
9930
paul94f2b392005-06-28 12:44:16 +00009931static int
paulbb46e942003-10-24 19:02:03 +00009932peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9933{
paul718e3742002-12-13 20:15:29 +00009934 if (! peer || ! peer->afc[afi][safi])
9935 {
9936 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9937 return CMD_WARNING;
9938 }
9939
9940 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9941 {
9942 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9943 VTY_NEWLINE);
9944 return CMD_WARNING;
9945 }
9946
9947 show_adj_route (vty, peer, afi, safi, in);
9948
9949 return CMD_SUCCESS;
9950}
9951
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009952DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9953 show_ip_bgp_view_neighbor_advertised_route_cmd,
9954 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9955 SHOW_STR
9956 IP_STR
9957 BGP_STR
9958 "BGP view\n"
9959 "View name\n"
9960 "Detailed information on TCP and BGP neighbor connections\n"
9961 "Neighbor to display information about\n"
9962 "Neighbor to display information about\n"
9963 "Display the routes advertised to a BGP neighbor\n")
9964{
9965 struct peer *peer;
9966
9967 if (argc == 2)
9968 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9969 else
9970 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9971
9972 if (! peer)
9973 return CMD_WARNING;
9974
9975 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9976}
9977
9978ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009979 show_ip_bgp_neighbor_advertised_route_cmd,
9980 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9981 SHOW_STR
9982 IP_STR
9983 BGP_STR
9984 "Detailed information on TCP and BGP neighbor connections\n"
9985 "Neighbor to display information about\n"
9986 "Neighbor to display information about\n"
9987 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009988
9989DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9990 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9991 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9992 SHOW_STR
9993 IP_STR
9994 BGP_STR
9995 "Address family\n"
9996 "Address Family modifier\n"
9997 "Address Family modifier\n"
9998 "Detailed information on TCP and BGP neighbor connections\n"
9999 "Neighbor to display information about\n"
10000 "Neighbor to display information about\n"
10001 "Display the routes advertised to a BGP neighbor\n")
10002{
paulbb46e942003-10-24 19:02:03 +000010003 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010004
paulbb46e942003-10-24 19:02:03 +000010005 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10006 if (! peer)
10007 return CMD_WARNING;
10008
10009 if (strncmp (argv[0], "m", 1) == 0)
10010 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
10011
10012 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +000010013}
10014
10015#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010016DEFUN (show_bgp_view_neighbor_advertised_route,
10017 show_bgp_view_neighbor_advertised_route_cmd,
10018 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10019 SHOW_STR
10020 BGP_STR
10021 "BGP view\n"
10022 "View name\n"
10023 "Detailed information on TCP and BGP neighbor connections\n"
10024 "Neighbor to display information about\n"
10025 "Neighbor to display information about\n"
10026 "Display the routes advertised to a BGP neighbor\n")
10027{
10028 struct peer *peer;
10029
10030 if (argc == 2)
10031 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10032 else
10033 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10034
10035 if (! peer)
10036 return CMD_WARNING;
10037
10038 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10039}
10040
10041ALIAS (show_bgp_view_neighbor_advertised_route,
10042 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10043 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10044 SHOW_STR
10045 BGP_STR
10046 "BGP view\n"
10047 "View name\n"
10048 "Address family\n"
10049 "Detailed information on TCP and BGP neighbor connections\n"
10050 "Neighbor to display information about\n"
10051 "Neighbor to display information about\n"
10052 "Display the routes advertised to a BGP neighbor\n")
10053
10054DEFUN (show_bgp_view_neighbor_received_routes,
10055 show_bgp_view_neighbor_received_routes_cmd,
10056 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10057 SHOW_STR
10058 BGP_STR
10059 "BGP view\n"
10060 "View name\n"
10061 "Detailed information on TCP and BGP neighbor connections\n"
10062 "Neighbor to display information about\n"
10063 "Neighbor to display information about\n"
10064 "Display the received routes from neighbor\n")
10065{
10066 struct peer *peer;
10067
10068 if (argc == 2)
10069 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10070 else
10071 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10072
10073 if (! peer)
10074 return CMD_WARNING;
10075
10076 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10077}
10078
10079ALIAS (show_bgp_view_neighbor_received_routes,
10080 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10081 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10082 SHOW_STR
10083 BGP_STR
10084 "BGP view\n"
10085 "View name\n"
10086 "Address family\n"
10087 "Detailed information on TCP and BGP neighbor connections\n"
10088 "Neighbor to display information about\n"
10089 "Neighbor to display information about\n"
10090 "Display the received routes from neighbor\n")
10091
10092ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010093 show_bgp_neighbor_advertised_route_cmd,
10094 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10095 SHOW_STR
10096 BGP_STR
10097 "Detailed information on TCP and BGP neighbor connections\n"
10098 "Neighbor to display information about\n"
10099 "Neighbor to display information about\n"
10100 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010101
10102ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010103 show_bgp_ipv6_neighbor_advertised_route_cmd,
10104 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10105 SHOW_STR
10106 BGP_STR
10107 "Address family\n"
10108 "Detailed information on TCP and BGP neighbor connections\n"
10109 "Neighbor to display information about\n"
10110 "Neighbor to display information about\n"
10111 "Display the routes advertised to a BGP neighbor\n")
10112
10113/* old command */
paulbb46e942003-10-24 19:02:03 +000010114ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010115 ipv6_bgp_neighbor_advertised_route_cmd,
10116 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10117 SHOW_STR
10118 IPV6_STR
10119 BGP_STR
10120 "Detailed information on TCP and BGP neighbor connections\n"
10121 "Neighbor to display information about\n"
10122 "Neighbor to display information about\n"
10123 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010124
paul718e3742002-12-13 20:15:29 +000010125/* old command */
10126DEFUN (ipv6_mbgp_neighbor_advertised_route,
10127 ipv6_mbgp_neighbor_advertised_route_cmd,
10128 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10129 SHOW_STR
10130 IPV6_STR
10131 MBGP_STR
10132 "Detailed information on TCP and BGP neighbor connections\n"
10133 "Neighbor to display information about\n"
10134 "Neighbor to display information about\n"
10135 "Display the routes advertised to a BGP neighbor\n")
10136{
paulbb46e942003-10-24 19:02:03 +000010137 struct peer *peer;
10138
10139 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10140 if (! peer)
10141 return CMD_WARNING;
10142
10143 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010144}
10145#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010146
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010147DEFUN (show_ip_bgp_view_neighbor_received_routes,
10148 show_ip_bgp_view_neighbor_received_routes_cmd,
10149 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10150 SHOW_STR
10151 IP_STR
10152 BGP_STR
10153 "BGP view\n"
10154 "View name\n"
10155 "Detailed information on TCP and BGP neighbor connections\n"
10156 "Neighbor to display information about\n"
10157 "Neighbor to display information about\n"
10158 "Display the received routes from neighbor\n")
10159{
10160 struct peer *peer;
10161
10162 if (argc == 2)
10163 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10164 else
10165 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10166
10167 if (! peer)
10168 return CMD_WARNING;
10169
10170 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10171}
10172
10173ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010174 show_ip_bgp_neighbor_received_routes_cmd,
10175 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10176 SHOW_STR
10177 IP_STR
10178 BGP_STR
10179 "Detailed information on TCP and BGP neighbor connections\n"
10180 "Neighbor to display information about\n"
10181 "Neighbor to display information about\n"
10182 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010183
10184DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10185 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10186 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10187 SHOW_STR
10188 IP_STR
10189 BGP_STR
10190 "Address family\n"
10191 "Address Family modifier\n"
10192 "Address Family modifier\n"
10193 "Detailed information on TCP and BGP neighbor connections\n"
10194 "Neighbor to display information about\n"
10195 "Neighbor to display information about\n"
10196 "Display the received routes from neighbor\n")
10197{
paulbb46e942003-10-24 19:02:03 +000010198 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010199
paulbb46e942003-10-24 19:02:03 +000010200 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10201 if (! peer)
10202 return CMD_WARNING;
10203
10204 if (strncmp (argv[0], "m", 1) == 0)
10205 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10206
10207 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010208}
10209
Michael Lambert95cbbd22010-07-23 14:43:04 -040010210DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10211 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10212#ifdef HAVE_IPV6
10213 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10214#else
10215 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10216#endif
10217 SHOW_STR
10218 BGP_STR
10219 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010220 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010221 "Address family\n"
10222#ifdef HAVE_IPV6
10223 "Address family\n"
10224#endif
10225 "Address family modifier\n"
10226 "Address family modifier\n"
10227 "Detailed information on TCP and BGP neighbor connections\n"
10228 "Neighbor to display information about\n"
10229 "Neighbor to display information about\n"
10230 "Display the advertised routes to neighbor\n"
10231 "Display the received routes from neighbor\n")
10232{
10233 int afi;
10234 int safi;
10235 int in;
10236 struct peer *peer;
10237
10238#ifdef HAVE_IPV6
10239 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10240#else
10241 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10242#endif
10243
10244 if (! peer)
10245 return CMD_WARNING;
10246
10247#ifdef HAVE_IPV6
10248 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10249 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10250 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10251#else
10252 afi = AFI_IP;
10253 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10254 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10255#endif
10256
10257 return peer_adj_routes (vty, peer, afi, safi, in);
10258}
10259
paul718e3742002-12-13 20:15:29 +000010260DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10261 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10262 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10263 SHOW_STR
10264 IP_STR
10265 BGP_STR
10266 "Detailed information on TCP and BGP neighbor connections\n"
10267 "Neighbor to display information about\n"
10268 "Neighbor to display information about\n"
10269 "Display information received from a BGP neighbor\n"
10270 "Display the prefixlist filter\n")
10271{
10272 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010273 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010274 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010275 int count, ret;
paul718e3742002-12-13 20:15:29 +000010276
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010277 ret = str2sockunion (argv[0], &su);
10278 if (ret < 0)
10279 {
10280 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10281 return CMD_WARNING;
10282 }
paul718e3742002-12-13 20:15:29 +000010283
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010284 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010285 if (! peer)
10286 return CMD_WARNING;
10287
10288 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10289 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10290 if (count)
10291 {
10292 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10293 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10294 }
10295
10296 return CMD_SUCCESS;
10297}
10298
10299DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10300 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10301 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10302 SHOW_STR
10303 IP_STR
10304 BGP_STR
10305 "Address family\n"
10306 "Address Family modifier\n"
10307 "Address Family modifier\n"
10308 "Detailed information on TCP and BGP neighbor connections\n"
10309 "Neighbor to display information about\n"
10310 "Neighbor to display information about\n"
10311 "Display information received from a BGP neighbor\n"
10312 "Display the prefixlist filter\n")
10313{
10314 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010315 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010316 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010317 int count, ret;
paul718e3742002-12-13 20:15:29 +000010318
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010319 ret = str2sockunion (argv[1], &su);
10320 if (ret < 0)
10321 {
10322 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10323 return CMD_WARNING;
10324 }
paul718e3742002-12-13 20:15:29 +000010325
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010326 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010327 if (! peer)
10328 return CMD_WARNING;
10329
10330 if (strncmp (argv[0], "m", 1) == 0)
10331 {
10332 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10333 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10334 if (count)
10335 {
10336 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10337 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10338 }
10339 }
10340 else
10341 {
10342 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10343 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10344 if (count)
10345 {
10346 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10347 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10348 }
10349 }
10350
10351 return CMD_SUCCESS;
10352}
10353
10354
10355#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010356ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010357 show_bgp_neighbor_received_routes_cmd,
10358 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10359 SHOW_STR
10360 BGP_STR
10361 "Detailed information on TCP and BGP neighbor connections\n"
10362 "Neighbor to display information about\n"
10363 "Neighbor to display information about\n"
10364 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010365
paulbb46e942003-10-24 19:02:03 +000010366ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010367 show_bgp_ipv6_neighbor_received_routes_cmd,
10368 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10369 SHOW_STR
10370 BGP_STR
10371 "Address family\n"
10372 "Detailed information on TCP and BGP neighbor connections\n"
10373 "Neighbor to display information about\n"
10374 "Neighbor to display information about\n"
10375 "Display the received routes from neighbor\n")
10376
10377DEFUN (show_bgp_neighbor_received_prefix_filter,
10378 show_bgp_neighbor_received_prefix_filter_cmd,
10379 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10380 SHOW_STR
10381 BGP_STR
10382 "Detailed information on TCP and BGP neighbor connections\n"
10383 "Neighbor to display information about\n"
10384 "Neighbor to display information about\n"
10385 "Display information received from a BGP neighbor\n"
10386 "Display the prefixlist filter\n")
10387{
10388 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010389 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010390 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010391 int count, ret;
paul718e3742002-12-13 20:15:29 +000010392
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010393 ret = str2sockunion (argv[0], &su);
10394 if (ret < 0)
10395 {
10396 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10397 return CMD_WARNING;
10398 }
paul718e3742002-12-13 20:15:29 +000010399
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010400 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010401 if (! peer)
10402 return CMD_WARNING;
10403
10404 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10405 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10406 if (count)
10407 {
10408 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10409 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10410 }
10411
10412 return CMD_SUCCESS;
10413}
10414
10415ALIAS (show_bgp_neighbor_received_prefix_filter,
10416 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10417 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10418 SHOW_STR
10419 BGP_STR
10420 "Address family\n"
10421 "Detailed information on TCP and BGP neighbor connections\n"
10422 "Neighbor to display information about\n"
10423 "Neighbor to display information about\n"
10424 "Display information received from a BGP neighbor\n"
10425 "Display the prefixlist filter\n")
10426
10427/* old command */
paulbb46e942003-10-24 19:02:03 +000010428ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010429 ipv6_bgp_neighbor_received_routes_cmd,
10430 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10431 SHOW_STR
10432 IPV6_STR
10433 BGP_STR
10434 "Detailed information on TCP and BGP neighbor connections\n"
10435 "Neighbor to display information about\n"
10436 "Neighbor to display information about\n"
10437 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010438
10439/* old command */
10440DEFUN (ipv6_mbgp_neighbor_received_routes,
10441 ipv6_mbgp_neighbor_received_routes_cmd,
10442 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10443 SHOW_STR
10444 IPV6_STR
10445 MBGP_STR
10446 "Detailed information on TCP and BGP neighbor connections\n"
10447 "Neighbor to display information about\n"
10448 "Neighbor to display information about\n"
10449 "Display the received routes from neighbor\n")
10450{
paulbb46e942003-10-24 19:02:03 +000010451 struct peer *peer;
10452
10453 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10454 if (! peer)
10455 return CMD_WARNING;
10456
10457 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010458}
paulbb46e942003-10-24 19:02:03 +000010459
10460DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10461 show_bgp_view_neighbor_received_prefix_filter_cmd,
10462 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10463 SHOW_STR
10464 BGP_STR
10465 "BGP view\n"
10466 "View name\n"
10467 "Detailed information on TCP and BGP neighbor connections\n"
10468 "Neighbor to display information about\n"
10469 "Neighbor to display information about\n"
10470 "Display information received from a BGP neighbor\n"
10471 "Display the prefixlist filter\n")
10472{
10473 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010474 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010475 struct peer *peer;
10476 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010477 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010478
10479 /* BGP structure lookup. */
10480 bgp = bgp_lookup_by_name (argv[0]);
10481 if (bgp == NULL)
10482 {
10483 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10484 return CMD_WARNING;
10485 }
10486
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010487 ret = str2sockunion (argv[1], &su);
10488 if (ret < 0)
10489 {
10490 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10491 return CMD_WARNING;
10492 }
paulbb46e942003-10-24 19:02:03 +000010493
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010494 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010495 if (! peer)
10496 return CMD_WARNING;
10497
10498 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10499 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10500 if (count)
10501 {
10502 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10503 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10504 }
10505
10506 return CMD_SUCCESS;
10507}
10508
10509ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10510 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10511 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10512 SHOW_STR
10513 BGP_STR
10514 "BGP view\n"
10515 "View name\n"
10516 "Address family\n"
10517 "Detailed information on TCP and BGP neighbor connections\n"
10518 "Neighbor to display information about\n"
10519 "Neighbor to display information about\n"
10520 "Display information received from a BGP neighbor\n"
10521 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010522#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010523
paul94f2b392005-06-28 12:44:16 +000010524static int
paulbb46e942003-10-24 19:02:03 +000010525bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010526 safi_t safi, enum bgp_show_type type)
10527{
paul718e3742002-12-13 20:15:29 +000010528 if (! peer || ! peer->afc[afi][safi])
10529 {
10530 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010531 return CMD_WARNING;
10532 }
10533
ajs5a646652004-11-05 01:25:55 +000010534 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010535}
10536
10537DEFUN (show_ip_bgp_neighbor_routes,
10538 show_ip_bgp_neighbor_routes_cmd,
10539 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10540 SHOW_STR
10541 IP_STR
10542 BGP_STR
10543 "Detailed information on TCP and BGP neighbor connections\n"
10544 "Neighbor to display information about\n"
10545 "Neighbor to display information about\n"
10546 "Display routes learned from neighbor\n")
10547{
paulbb46e942003-10-24 19:02:03 +000010548 struct peer *peer;
10549
10550 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10551 if (! peer)
10552 return CMD_WARNING;
10553
10554 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010555 bgp_show_type_neighbor);
10556}
10557
10558DEFUN (show_ip_bgp_neighbor_flap,
10559 show_ip_bgp_neighbor_flap_cmd,
10560 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10561 SHOW_STR
10562 IP_STR
10563 BGP_STR
10564 "Detailed information on TCP and BGP neighbor connections\n"
10565 "Neighbor to display information about\n"
10566 "Neighbor to display information about\n"
10567 "Display flap statistics of the routes learned from neighbor\n")
10568{
paulbb46e942003-10-24 19:02:03 +000010569 struct peer *peer;
10570
10571 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10572 if (! peer)
10573 return CMD_WARNING;
10574
10575 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010576 bgp_show_type_flap_neighbor);
10577}
10578
10579DEFUN (show_ip_bgp_neighbor_damp,
10580 show_ip_bgp_neighbor_damp_cmd,
10581 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10582 SHOW_STR
10583 IP_STR
10584 BGP_STR
10585 "Detailed information on TCP and BGP neighbor connections\n"
10586 "Neighbor to display information about\n"
10587 "Neighbor to display information about\n"
10588 "Display the dampened routes received from neighbor\n")
10589{
paulbb46e942003-10-24 19:02:03 +000010590 struct peer *peer;
10591
10592 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10593 if (! peer)
10594 return CMD_WARNING;
10595
10596 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010597 bgp_show_type_damp_neighbor);
10598}
10599
10600DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10601 show_ip_bgp_ipv4_neighbor_routes_cmd,
10602 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10603 SHOW_STR
10604 IP_STR
10605 BGP_STR
10606 "Address family\n"
10607 "Address Family modifier\n"
10608 "Address Family modifier\n"
10609 "Detailed information on TCP and BGP neighbor connections\n"
10610 "Neighbor to display information about\n"
10611 "Neighbor to display information about\n"
10612 "Display routes learned from neighbor\n")
10613{
paulbb46e942003-10-24 19:02:03 +000010614 struct peer *peer;
10615
10616 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10617 if (! peer)
10618 return CMD_WARNING;
10619
paul718e3742002-12-13 20:15:29 +000010620 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010621 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010622 bgp_show_type_neighbor);
10623
paulbb46e942003-10-24 19:02:03 +000010624 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010625 bgp_show_type_neighbor);
10626}
paulbb46e942003-10-24 19:02:03 +000010627
paulfee0f4c2004-09-13 05:12:46 +000010628DEFUN (show_ip_bgp_view_rsclient,
10629 show_ip_bgp_view_rsclient_cmd,
10630 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10631 SHOW_STR
10632 IP_STR
10633 BGP_STR
10634 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010635 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010636 "Information about Route Server Client\n"
10637 NEIGHBOR_ADDR_STR)
10638{
10639 struct bgp_table *table;
10640 struct peer *peer;
10641
10642 if (argc == 2)
10643 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10644 else
10645 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10646
10647 if (! peer)
10648 return CMD_WARNING;
10649
10650 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10651 {
10652 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10653 VTY_NEWLINE);
10654 return CMD_WARNING;
10655 }
10656
10657 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10658 PEER_FLAG_RSERVER_CLIENT))
10659 {
10660 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10661 VTY_NEWLINE);
10662 return CMD_WARNING;
10663 }
10664
10665 table = peer->rib[AFI_IP][SAFI_UNICAST];
10666
ajs5a646652004-11-05 01:25:55 +000010667 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010668}
10669
10670ALIAS (show_ip_bgp_view_rsclient,
10671 show_ip_bgp_rsclient_cmd,
10672 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10673 SHOW_STR
10674 IP_STR
10675 BGP_STR
10676 "Information about Route Server Client\n"
10677 NEIGHBOR_ADDR_STR)
10678
Michael Lambert95cbbd22010-07-23 14:43:04 -040010679DEFUN (show_bgp_view_ipv4_safi_rsclient,
10680 show_bgp_view_ipv4_safi_rsclient_cmd,
10681 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10682 SHOW_STR
10683 BGP_STR
10684 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010685 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010686 "Address family\n"
10687 "Address Family modifier\n"
10688 "Address Family modifier\n"
10689 "Information about Route Server Client\n"
10690 NEIGHBOR_ADDR_STR)
10691{
10692 struct bgp_table *table;
10693 struct peer *peer;
10694 safi_t safi;
10695
10696 if (argc == 3) {
10697 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10698 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10699 } else {
10700 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10701 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10702 }
10703
10704 if (! peer)
10705 return CMD_WARNING;
10706
10707 if (! peer->afc[AFI_IP][safi])
10708 {
10709 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10710 VTY_NEWLINE);
10711 return CMD_WARNING;
10712 }
10713
10714 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10715 PEER_FLAG_RSERVER_CLIENT))
10716 {
10717 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10718 VTY_NEWLINE);
10719 return CMD_WARNING;
10720 }
10721
10722 table = peer->rib[AFI_IP][safi];
10723
10724 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10725}
10726
10727ALIAS (show_bgp_view_ipv4_safi_rsclient,
10728 show_bgp_ipv4_safi_rsclient_cmd,
10729 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10730 SHOW_STR
10731 BGP_STR
10732 "Address family\n"
10733 "Address Family modifier\n"
10734 "Address Family modifier\n"
10735 "Information about Route Server Client\n"
10736 NEIGHBOR_ADDR_STR)
10737
paulfee0f4c2004-09-13 05:12:46 +000010738DEFUN (show_ip_bgp_view_rsclient_route,
10739 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010740 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010741 SHOW_STR
10742 IP_STR
10743 BGP_STR
10744 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010745 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010746 "Information about Route Server Client\n"
10747 NEIGHBOR_ADDR_STR
10748 "Network in the BGP routing table to display\n")
10749{
10750 struct bgp *bgp;
10751 struct peer *peer;
10752
10753 /* BGP structure lookup. */
10754 if (argc == 3)
10755 {
10756 bgp = bgp_lookup_by_name (argv[0]);
10757 if (bgp == NULL)
10758 {
10759 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10760 return CMD_WARNING;
10761 }
10762 }
10763 else
10764 {
10765 bgp = bgp_get_default ();
10766 if (bgp == NULL)
10767 {
10768 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10769 return CMD_WARNING;
10770 }
10771 }
10772
10773 if (argc == 3)
10774 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10775 else
10776 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10777
10778 if (! peer)
10779 return CMD_WARNING;
10780
10781 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10782 {
10783 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10784 VTY_NEWLINE);
10785 return CMD_WARNING;
10786}
10787
10788 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10789 PEER_FLAG_RSERVER_CLIENT))
10790 {
10791 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10792 VTY_NEWLINE);
10793 return CMD_WARNING;
10794 }
10795
10796 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10797 (argc == 3) ? argv[2] : argv[1],
10798 AFI_IP, SAFI_UNICAST, NULL, 0);
10799}
10800
10801ALIAS (show_ip_bgp_view_rsclient_route,
10802 show_ip_bgp_rsclient_route_cmd,
10803 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10804 SHOW_STR
10805 IP_STR
10806 BGP_STR
10807 "Information about Route Server Client\n"
10808 NEIGHBOR_ADDR_STR
10809 "Network in the BGP routing table to display\n")
10810
Michael Lambert95cbbd22010-07-23 14:43:04 -040010811DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10812 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10813 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10814 SHOW_STR
10815 BGP_STR
10816 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010817 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010818 "Address family\n"
10819 "Address Family modifier\n"
10820 "Address Family modifier\n"
10821 "Information about Route Server Client\n"
10822 NEIGHBOR_ADDR_STR
10823 "Network in the BGP routing table to display\n")
10824{
10825 struct bgp *bgp;
10826 struct peer *peer;
10827 safi_t safi;
10828
10829 /* BGP structure lookup. */
10830 if (argc == 4)
10831 {
10832 bgp = bgp_lookup_by_name (argv[0]);
10833 if (bgp == NULL)
10834 {
10835 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10836 return CMD_WARNING;
10837 }
10838 }
10839 else
10840 {
10841 bgp = bgp_get_default ();
10842 if (bgp == NULL)
10843 {
10844 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10845 return CMD_WARNING;
10846 }
10847 }
10848
10849 if (argc == 4) {
10850 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10851 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10852 } else {
10853 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10854 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10855 }
10856
10857 if (! peer)
10858 return CMD_WARNING;
10859
10860 if (! peer->afc[AFI_IP][safi])
10861 {
10862 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10863 VTY_NEWLINE);
10864 return CMD_WARNING;
10865}
10866
10867 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10868 PEER_FLAG_RSERVER_CLIENT))
10869 {
10870 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10871 VTY_NEWLINE);
10872 return CMD_WARNING;
10873 }
10874
10875 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10876 (argc == 4) ? argv[3] : argv[2],
10877 AFI_IP, safi, NULL, 0);
10878}
10879
10880ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10881 show_bgp_ipv4_safi_rsclient_route_cmd,
10882 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10883 SHOW_STR
10884 BGP_STR
10885 "Address family\n"
10886 "Address Family modifier\n"
10887 "Address Family modifier\n"
10888 "Information about Route Server Client\n"
10889 NEIGHBOR_ADDR_STR
10890 "Network in the BGP routing table to display\n")
10891
paulfee0f4c2004-09-13 05:12:46 +000010892DEFUN (show_ip_bgp_view_rsclient_prefix,
10893 show_ip_bgp_view_rsclient_prefix_cmd,
10894 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10895 SHOW_STR
10896 IP_STR
10897 BGP_STR
10898 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010899 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010900 "Information about Route Server Client\n"
10901 NEIGHBOR_ADDR_STR
10902 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10903{
10904 struct bgp *bgp;
10905 struct peer *peer;
10906
10907 /* BGP structure lookup. */
10908 if (argc == 3)
10909 {
10910 bgp = bgp_lookup_by_name (argv[0]);
10911 if (bgp == NULL)
10912 {
10913 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10914 return CMD_WARNING;
10915 }
10916 }
10917 else
10918 {
10919 bgp = bgp_get_default ();
10920 if (bgp == NULL)
10921 {
10922 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10923 return CMD_WARNING;
10924 }
10925 }
10926
10927 if (argc == 3)
10928 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10929 else
10930 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10931
10932 if (! peer)
10933 return CMD_WARNING;
10934
10935 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10936 {
10937 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10938 VTY_NEWLINE);
10939 return CMD_WARNING;
10940}
10941
10942 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10943 PEER_FLAG_RSERVER_CLIENT))
10944{
10945 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10946 VTY_NEWLINE);
10947 return CMD_WARNING;
10948 }
10949
10950 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10951 (argc == 3) ? argv[2] : argv[1],
10952 AFI_IP, SAFI_UNICAST, NULL, 1);
10953}
10954
10955ALIAS (show_ip_bgp_view_rsclient_prefix,
10956 show_ip_bgp_rsclient_prefix_cmd,
10957 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10958 SHOW_STR
10959 IP_STR
10960 BGP_STR
10961 "Information about Route Server Client\n"
10962 NEIGHBOR_ADDR_STR
10963 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10964
Michael Lambert95cbbd22010-07-23 14:43:04 -040010965DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10966 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10967 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10968 SHOW_STR
10969 BGP_STR
10970 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010971 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010972 "Address family\n"
10973 "Address Family modifier\n"
10974 "Address Family modifier\n"
10975 "Information about Route Server Client\n"
10976 NEIGHBOR_ADDR_STR
10977 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10978{
10979 struct bgp *bgp;
10980 struct peer *peer;
10981 safi_t safi;
10982
10983 /* BGP structure lookup. */
10984 if (argc == 4)
10985 {
10986 bgp = bgp_lookup_by_name (argv[0]);
10987 if (bgp == NULL)
10988 {
10989 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10990 return CMD_WARNING;
10991 }
10992 }
10993 else
10994 {
10995 bgp = bgp_get_default ();
10996 if (bgp == NULL)
10997 {
10998 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10999 return CMD_WARNING;
11000 }
11001 }
11002
11003 if (argc == 4) {
11004 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11005 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11006 } else {
11007 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11008 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11009 }
11010
11011 if (! peer)
11012 return CMD_WARNING;
11013
11014 if (! peer->afc[AFI_IP][safi])
11015 {
11016 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11017 VTY_NEWLINE);
11018 return CMD_WARNING;
11019}
11020
11021 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11022 PEER_FLAG_RSERVER_CLIENT))
11023{
11024 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11025 VTY_NEWLINE);
11026 return CMD_WARNING;
11027 }
11028
11029 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11030 (argc == 4) ? argv[3] : argv[2],
11031 AFI_IP, safi, NULL, 1);
11032}
11033
11034ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11035 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11036 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11037 SHOW_STR
11038 BGP_STR
11039 "Address family\n"
11040 "Address Family modifier\n"
11041 "Address Family modifier\n"
11042 "Information about Route Server Client\n"
11043 NEIGHBOR_ADDR_STR
11044 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011045
paul718e3742002-12-13 20:15:29 +000011046#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011047DEFUN (show_bgp_view_neighbor_routes,
11048 show_bgp_view_neighbor_routes_cmd,
11049 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11050 SHOW_STR
11051 BGP_STR
11052 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011053 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011054 "Detailed information on TCP and BGP neighbor connections\n"
11055 "Neighbor to display information about\n"
11056 "Neighbor to display information about\n"
11057 "Display routes learned from neighbor\n")
11058{
11059 struct peer *peer;
11060
11061 if (argc == 2)
11062 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11063 else
11064 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11065
11066 if (! peer)
11067 return CMD_WARNING;
11068
11069 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11070 bgp_show_type_neighbor);
11071}
11072
11073ALIAS (show_bgp_view_neighbor_routes,
11074 show_bgp_view_ipv6_neighbor_routes_cmd,
11075 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11076 SHOW_STR
11077 BGP_STR
11078 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011079 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011080 "Address family\n"
11081 "Detailed information on TCP and BGP neighbor connections\n"
11082 "Neighbor to display information about\n"
11083 "Neighbor to display information about\n"
11084 "Display routes learned from neighbor\n")
11085
11086DEFUN (show_bgp_view_neighbor_damp,
11087 show_bgp_view_neighbor_damp_cmd,
11088 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11089 SHOW_STR
11090 BGP_STR
11091 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011092 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011093 "Detailed information on TCP and BGP neighbor connections\n"
11094 "Neighbor to display information about\n"
11095 "Neighbor to display information about\n"
11096 "Display the dampened routes received from neighbor\n")
11097{
11098 struct peer *peer;
11099
11100 if (argc == 2)
11101 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11102 else
11103 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11104
11105 if (! peer)
11106 return CMD_WARNING;
11107
11108 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11109 bgp_show_type_damp_neighbor);
11110}
11111
11112ALIAS (show_bgp_view_neighbor_damp,
11113 show_bgp_view_ipv6_neighbor_damp_cmd,
11114 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11115 SHOW_STR
11116 BGP_STR
11117 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011118 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011119 "Address family\n"
11120 "Detailed information on TCP and BGP neighbor connections\n"
11121 "Neighbor to display information about\n"
11122 "Neighbor to display information about\n"
11123 "Display the dampened routes received from neighbor\n")
11124
11125DEFUN (show_bgp_view_neighbor_flap,
11126 show_bgp_view_neighbor_flap_cmd,
11127 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11128 SHOW_STR
11129 BGP_STR
11130 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011131 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011132 "Detailed information on TCP and BGP neighbor connections\n"
11133 "Neighbor to display information about\n"
11134 "Neighbor to display information about\n"
11135 "Display flap statistics of the routes learned from neighbor\n")
11136{
11137 struct peer *peer;
11138
11139 if (argc == 2)
11140 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11141 else
11142 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11143
11144 if (! peer)
11145 return CMD_WARNING;
11146
11147 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11148 bgp_show_type_flap_neighbor);
11149}
11150
11151ALIAS (show_bgp_view_neighbor_flap,
11152 show_bgp_view_ipv6_neighbor_flap_cmd,
11153 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11154 SHOW_STR
11155 BGP_STR
11156 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011157 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011158 "Address family\n"
11159 "Detailed information on TCP and BGP neighbor connections\n"
11160 "Neighbor to display information about\n"
11161 "Neighbor to display information about\n"
11162 "Display flap statistics of the routes learned from neighbor\n")
11163
11164ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011165 show_bgp_neighbor_routes_cmd,
11166 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11167 SHOW_STR
11168 BGP_STR
11169 "Detailed information on TCP and BGP neighbor connections\n"
11170 "Neighbor to display information about\n"
11171 "Neighbor to display information about\n"
11172 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011173
paulbb46e942003-10-24 19:02:03 +000011174
11175ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011176 show_bgp_ipv6_neighbor_routes_cmd,
11177 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11178 SHOW_STR
11179 BGP_STR
11180 "Address family\n"
11181 "Detailed information on TCP and BGP neighbor connections\n"
11182 "Neighbor to display information about\n"
11183 "Neighbor to display information about\n"
11184 "Display routes learned from neighbor\n")
11185
11186/* old command */
paulbb46e942003-10-24 19:02:03 +000011187ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011188 ipv6_bgp_neighbor_routes_cmd,
11189 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11190 SHOW_STR
11191 IPV6_STR
11192 BGP_STR
11193 "Detailed information on TCP and BGP neighbor connections\n"
11194 "Neighbor to display information about\n"
11195 "Neighbor to display information about\n"
11196 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011197
11198/* old command */
11199DEFUN (ipv6_mbgp_neighbor_routes,
11200 ipv6_mbgp_neighbor_routes_cmd,
11201 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11202 SHOW_STR
11203 IPV6_STR
11204 MBGP_STR
11205 "Detailed information on TCP and BGP neighbor connections\n"
11206 "Neighbor to display information about\n"
11207 "Neighbor to display information about\n"
11208 "Display routes learned from neighbor\n")
11209{
paulbb46e942003-10-24 19:02:03 +000011210 struct peer *peer;
11211
11212 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11213 if (! peer)
11214 return CMD_WARNING;
11215
11216 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011217 bgp_show_type_neighbor);
11218}
paulbb46e942003-10-24 19:02:03 +000011219
11220ALIAS (show_bgp_view_neighbor_flap,
11221 show_bgp_neighbor_flap_cmd,
11222 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11223 SHOW_STR
11224 BGP_STR
11225 "Detailed information on TCP and BGP neighbor connections\n"
11226 "Neighbor to display information about\n"
11227 "Neighbor to display information about\n"
11228 "Display flap statistics of the routes learned from neighbor\n")
11229
11230ALIAS (show_bgp_view_neighbor_flap,
11231 show_bgp_ipv6_neighbor_flap_cmd,
11232 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11233 SHOW_STR
11234 BGP_STR
11235 "Address family\n"
11236 "Detailed information on TCP and BGP neighbor connections\n"
11237 "Neighbor to display information about\n"
11238 "Neighbor to display information about\n"
11239 "Display flap statistics of the routes learned from neighbor\n")
11240
11241ALIAS (show_bgp_view_neighbor_damp,
11242 show_bgp_neighbor_damp_cmd,
11243 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11244 SHOW_STR
11245 BGP_STR
11246 "Detailed information on TCP and BGP neighbor connections\n"
11247 "Neighbor to display information about\n"
11248 "Neighbor to display information about\n"
11249 "Display the dampened routes received from neighbor\n")
11250
11251ALIAS (show_bgp_view_neighbor_damp,
11252 show_bgp_ipv6_neighbor_damp_cmd,
11253 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11254 SHOW_STR
11255 BGP_STR
11256 "Address family\n"
11257 "Detailed information on TCP and BGP neighbor connections\n"
11258 "Neighbor to display information about\n"
11259 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011260 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011261
11262DEFUN (show_bgp_view_rsclient,
11263 show_bgp_view_rsclient_cmd,
11264 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11265 SHOW_STR
11266 BGP_STR
11267 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011268 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011269 "Information about Route Server Client\n"
11270 NEIGHBOR_ADDR_STR)
11271{
11272 struct bgp_table *table;
11273 struct peer *peer;
11274
11275 if (argc == 2)
11276 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11277 else
11278 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11279
11280 if (! peer)
11281 return CMD_WARNING;
11282
11283 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11284 {
11285 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11286 VTY_NEWLINE);
11287 return CMD_WARNING;
11288 }
11289
11290 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11291 PEER_FLAG_RSERVER_CLIENT))
11292 {
11293 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11294 VTY_NEWLINE);
11295 return CMD_WARNING;
11296 }
11297
11298 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11299
ajs5a646652004-11-05 01:25:55 +000011300 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011301}
11302
11303ALIAS (show_bgp_view_rsclient,
11304 show_bgp_rsclient_cmd,
11305 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11306 SHOW_STR
11307 BGP_STR
11308 "Information about Route Server Client\n"
11309 NEIGHBOR_ADDR_STR)
11310
Michael Lambert95cbbd22010-07-23 14:43:04 -040011311DEFUN (show_bgp_view_ipv6_safi_rsclient,
11312 show_bgp_view_ipv6_safi_rsclient_cmd,
11313 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11314 SHOW_STR
11315 BGP_STR
11316 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011317 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011318 "Address family\n"
11319 "Address Family modifier\n"
11320 "Address Family modifier\n"
11321 "Information about Route Server Client\n"
11322 NEIGHBOR_ADDR_STR)
11323{
11324 struct bgp_table *table;
11325 struct peer *peer;
11326 safi_t safi;
11327
11328 if (argc == 3) {
11329 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11330 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11331 } else {
11332 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11333 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11334 }
11335
11336 if (! peer)
11337 return CMD_WARNING;
11338
11339 if (! peer->afc[AFI_IP6][safi])
11340 {
11341 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11342 VTY_NEWLINE);
11343 return CMD_WARNING;
11344 }
11345
11346 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11347 PEER_FLAG_RSERVER_CLIENT))
11348 {
11349 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11350 VTY_NEWLINE);
11351 return CMD_WARNING;
11352 }
11353
11354 table = peer->rib[AFI_IP6][safi];
11355
11356 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11357}
11358
11359ALIAS (show_bgp_view_ipv6_safi_rsclient,
11360 show_bgp_ipv6_safi_rsclient_cmd,
11361 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11362 SHOW_STR
11363 BGP_STR
11364 "Address family\n"
11365 "Address Family modifier\n"
11366 "Address Family modifier\n"
11367 "Information about Route Server Client\n"
11368 NEIGHBOR_ADDR_STR)
11369
paulfee0f4c2004-09-13 05:12:46 +000011370DEFUN (show_bgp_view_rsclient_route,
11371 show_bgp_view_rsclient_route_cmd,
11372 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11373 SHOW_STR
11374 BGP_STR
11375 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011376 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011377 "Information about Route Server Client\n"
11378 NEIGHBOR_ADDR_STR
11379 "Network in the BGP routing table to display\n")
11380{
11381 struct bgp *bgp;
11382 struct peer *peer;
11383
11384 /* BGP structure lookup. */
11385 if (argc == 3)
11386 {
11387 bgp = bgp_lookup_by_name (argv[0]);
11388 if (bgp == NULL)
11389 {
11390 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11391 return CMD_WARNING;
11392 }
11393 }
11394 else
11395 {
11396 bgp = bgp_get_default ();
11397 if (bgp == NULL)
11398 {
11399 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11400 return CMD_WARNING;
11401 }
11402 }
11403
11404 if (argc == 3)
11405 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11406 else
11407 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11408
11409 if (! peer)
11410 return CMD_WARNING;
11411
11412 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11413 {
11414 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11415 VTY_NEWLINE);
11416 return CMD_WARNING;
11417 }
11418
11419 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11420 PEER_FLAG_RSERVER_CLIENT))
11421 {
11422 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11423 VTY_NEWLINE);
11424 return CMD_WARNING;
11425 }
11426
11427 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11428 (argc == 3) ? argv[2] : argv[1],
11429 AFI_IP6, SAFI_UNICAST, NULL, 0);
11430}
11431
11432ALIAS (show_bgp_view_rsclient_route,
11433 show_bgp_rsclient_route_cmd,
11434 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11435 SHOW_STR
11436 BGP_STR
11437 "Information about Route Server Client\n"
11438 NEIGHBOR_ADDR_STR
11439 "Network in the BGP routing table to display\n")
11440
Michael Lambert95cbbd22010-07-23 14:43:04 -040011441DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11442 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11443 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11444 SHOW_STR
11445 BGP_STR
11446 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011447 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011448 "Address family\n"
11449 "Address Family modifier\n"
11450 "Address Family modifier\n"
11451 "Information about Route Server Client\n"
11452 NEIGHBOR_ADDR_STR
11453 "Network in the BGP routing table to display\n")
11454{
11455 struct bgp *bgp;
11456 struct peer *peer;
11457 safi_t safi;
11458
11459 /* BGP structure lookup. */
11460 if (argc == 4)
11461 {
11462 bgp = bgp_lookup_by_name (argv[0]);
11463 if (bgp == NULL)
11464 {
11465 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11466 return CMD_WARNING;
11467 }
11468 }
11469 else
11470 {
11471 bgp = bgp_get_default ();
11472 if (bgp == NULL)
11473 {
11474 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11475 return CMD_WARNING;
11476 }
11477 }
11478
11479 if (argc == 4) {
11480 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11481 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11482 } else {
11483 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11484 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11485 }
11486
11487 if (! peer)
11488 return CMD_WARNING;
11489
11490 if (! peer->afc[AFI_IP6][safi])
11491 {
11492 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11493 VTY_NEWLINE);
11494 return CMD_WARNING;
11495}
11496
11497 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11498 PEER_FLAG_RSERVER_CLIENT))
11499 {
11500 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11501 VTY_NEWLINE);
11502 return CMD_WARNING;
11503 }
11504
11505 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11506 (argc == 4) ? argv[3] : argv[2],
11507 AFI_IP6, safi, NULL, 0);
11508}
11509
11510ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11511 show_bgp_ipv6_safi_rsclient_route_cmd,
11512 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11513 SHOW_STR
11514 BGP_STR
11515 "Address family\n"
11516 "Address Family modifier\n"
11517 "Address Family modifier\n"
11518 "Information about Route Server Client\n"
11519 NEIGHBOR_ADDR_STR
11520 "Network in the BGP routing table to display\n")
11521
paulfee0f4c2004-09-13 05:12:46 +000011522DEFUN (show_bgp_view_rsclient_prefix,
11523 show_bgp_view_rsclient_prefix_cmd,
11524 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11525 SHOW_STR
11526 BGP_STR
11527 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011528 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011529 "Information about Route Server Client\n"
11530 NEIGHBOR_ADDR_STR
11531 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11532{
11533 struct bgp *bgp;
11534 struct peer *peer;
11535
11536 /* BGP structure lookup. */
11537 if (argc == 3)
11538 {
11539 bgp = bgp_lookup_by_name (argv[0]);
11540 if (bgp == NULL)
11541 {
11542 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11543 return CMD_WARNING;
11544 }
11545 }
11546 else
11547 {
11548 bgp = bgp_get_default ();
11549 if (bgp == NULL)
11550 {
11551 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11552 return CMD_WARNING;
11553 }
11554 }
11555
11556 if (argc == 3)
11557 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11558 else
11559 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11560
11561 if (! peer)
11562 return CMD_WARNING;
11563
11564 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11565 {
11566 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11567 VTY_NEWLINE);
11568 return CMD_WARNING;
11569 }
11570
11571 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11572 PEER_FLAG_RSERVER_CLIENT))
11573 {
11574 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11575 VTY_NEWLINE);
11576 return CMD_WARNING;
11577 }
11578
11579 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11580 (argc == 3) ? argv[2] : argv[1],
11581 AFI_IP6, SAFI_UNICAST, NULL, 1);
11582}
11583
11584ALIAS (show_bgp_view_rsclient_prefix,
11585 show_bgp_rsclient_prefix_cmd,
11586 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11587 SHOW_STR
11588 BGP_STR
11589 "Information about Route Server Client\n"
11590 NEIGHBOR_ADDR_STR
11591 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11592
Michael Lambert95cbbd22010-07-23 14:43:04 -040011593DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11594 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11595 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11596 SHOW_STR
11597 BGP_STR
11598 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011599 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011600 "Address family\n"
11601 "Address Family modifier\n"
11602 "Address Family modifier\n"
11603 "Information about Route Server Client\n"
11604 NEIGHBOR_ADDR_STR
11605 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11606{
11607 struct bgp *bgp;
11608 struct peer *peer;
11609 safi_t safi;
11610
11611 /* BGP structure lookup. */
11612 if (argc == 4)
11613 {
11614 bgp = bgp_lookup_by_name (argv[0]);
11615 if (bgp == NULL)
11616 {
11617 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11618 return CMD_WARNING;
11619 }
11620 }
11621 else
11622 {
11623 bgp = bgp_get_default ();
11624 if (bgp == NULL)
11625 {
11626 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11627 return CMD_WARNING;
11628 }
11629 }
11630
11631 if (argc == 4) {
11632 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11633 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11634 } else {
11635 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11636 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11637 }
11638
11639 if (! peer)
11640 return CMD_WARNING;
11641
11642 if (! peer->afc[AFI_IP6][safi])
11643 {
11644 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11645 VTY_NEWLINE);
11646 return CMD_WARNING;
11647}
11648
11649 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11650 PEER_FLAG_RSERVER_CLIENT))
11651{
11652 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11653 VTY_NEWLINE);
11654 return CMD_WARNING;
11655 }
11656
11657 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11658 (argc == 4) ? argv[3] : argv[2],
11659 AFI_IP6, safi, NULL, 1);
11660}
11661
11662ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11663 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11664 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11665 SHOW_STR
11666 BGP_STR
11667 "Address family\n"
11668 "Address Family modifier\n"
11669 "Address Family modifier\n"
11670 "Information about Route Server Client\n"
11671 NEIGHBOR_ADDR_STR
11672 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11673
paul718e3742002-12-13 20:15:29 +000011674#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020011675
paul718e3742002-12-13 20:15:29 +000011676struct bgp_table *bgp_distance_table;
11677
11678struct bgp_distance
11679{
11680 /* Distance value for the IP source prefix. */
11681 u_char distance;
11682
11683 /* Name of the access-list to be matched. */
11684 char *access_list;
11685};
11686
paul94f2b392005-06-28 12:44:16 +000011687static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011688bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011689{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011690 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011691}
11692
paul94f2b392005-06-28 12:44:16 +000011693static void
paul718e3742002-12-13 20:15:29 +000011694bgp_distance_free (struct bgp_distance *bdistance)
11695{
11696 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11697}
11698
paul94f2b392005-06-28 12:44:16 +000011699static int
paulfd79ac92004-10-13 05:06:08 +000011700bgp_distance_set (struct vty *vty, const char *distance_str,
11701 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011702{
11703 int ret;
11704 struct prefix_ipv4 p;
11705 u_char distance;
11706 struct bgp_node *rn;
11707 struct bgp_distance *bdistance;
11708
11709 ret = str2prefix_ipv4 (ip_str, &p);
11710 if (ret == 0)
11711 {
11712 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11713 return CMD_WARNING;
11714 }
11715
11716 distance = atoi (distance_str);
11717
11718 /* Get BGP distance node. */
11719 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11720 if (rn->info)
11721 {
11722 bdistance = rn->info;
11723 bgp_unlock_node (rn);
11724 }
11725 else
11726 {
11727 bdistance = bgp_distance_new ();
11728 rn->info = bdistance;
11729 }
11730
11731 /* Set distance value. */
11732 bdistance->distance = distance;
11733
11734 /* Reset access-list configuration. */
11735 if (bdistance->access_list)
11736 {
11737 free (bdistance->access_list);
11738 bdistance->access_list = NULL;
11739 }
11740 if (access_list_str)
11741 bdistance->access_list = strdup (access_list_str);
11742
11743 return CMD_SUCCESS;
11744}
11745
paul94f2b392005-06-28 12:44:16 +000011746static int
paulfd79ac92004-10-13 05:06:08 +000011747bgp_distance_unset (struct vty *vty, const char *distance_str,
11748 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011749{
11750 int ret;
11751 struct prefix_ipv4 p;
11752 u_char distance;
11753 struct bgp_node *rn;
11754 struct bgp_distance *bdistance;
11755
11756 ret = str2prefix_ipv4 (ip_str, &p);
11757 if (ret == 0)
11758 {
11759 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11760 return CMD_WARNING;
11761 }
11762
11763 distance = atoi (distance_str);
11764
11765 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11766 if (! rn)
11767 {
11768 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11769 return CMD_WARNING;
11770 }
11771
11772 bdistance = rn->info;
11773
11774 if (bdistance->access_list)
11775 free (bdistance->access_list);
11776 bgp_distance_free (bdistance);
11777
11778 rn->info = NULL;
11779 bgp_unlock_node (rn);
11780 bgp_unlock_node (rn);
11781
11782 return CMD_SUCCESS;
11783}
11784
paul718e3742002-12-13 20:15:29 +000011785/* Apply BGP information to distance method. */
11786u_char
11787bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11788{
11789 struct bgp_node *rn;
11790 struct prefix_ipv4 q;
11791 struct peer *peer;
11792 struct bgp_distance *bdistance;
11793 struct access_list *alist;
11794 struct bgp_static *bgp_static;
11795
11796 if (! bgp)
11797 return 0;
11798
11799 if (p->family != AF_INET)
11800 return 0;
11801
11802 peer = rinfo->peer;
11803
11804 if (peer->su.sa.sa_family != AF_INET)
11805 return 0;
11806
11807 memset (&q, 0, sizeof (struct prefix_ipv4));
11808 q.family = AF_INET;
11809 q.prefix = peer->su.sin.sin_addr;
11810 q.prefixlen = IPV4_MAX_BITLEN;
11811
11812 /* Check source address. */
11813 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11814 if (rn)
11815 {
11816 bdistance = rn->info;
11817 bgp_unlock_node (rn);
11818
11819 if (bdistance->access_list)
11820 {
11821 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11822 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11823 return bdistance->distance;
11824 }
11825 else
11826 return bdistance->distance;
11827 }
11828
11829 /* Backdoor check. */
11830 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11831 if (rn)
11832 {
11833 bgp_static = rn->info;
11834 bgp_unlock_node (rn);
11835
11836 if (bgp_static->backdoor)
11837 {
11838 if (bgp->distance_local)
11839 return bgp->distance_local;
11840 else
11841 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11842 }
11843 }
11844
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011845 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011846 {
11847 if (bgp->distance_ebgp)
11848 return bgp->distance_ebgp;
11849 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11850 }
11851 else
11852 {
11853 if (bgp->distance_ibgp)
11854 return bgp->distance_ibgp;
11855 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11856 }
11857}
11858
11859DEFUN (bgp_distance,
11860 bgp_distance_cmd,
11861 "distance bgp <1-255> <1-255> <1-255>",
11862 "Define an administrative distance\n"
11863 "BGP distance\n"
11864 "Distance for routes external to the AS\n"
11865 "Distance for routes internal to the AS\n"
11866 "Distance for local routes\n")
11867{
11868 struct bgp *bgp;
11869
11870 bgp = vty->index;
11871
11872 bgp->distance_ebgp = atoi (argv[0]);
11873 bgp->distance_ibgp = atoi (argv[1]);
11874 bgp->distance_local = atoi (argv[2]);
11875 return CMD_SUCCESS;
11876}
11877
11878DEFUN (no_bgp_distance,
11879 no_bgp_distance_cmd,
11880 "no distance bgp <1-255> <1-255> <1-255>",
11881 NO_STR
11882 "Define an administrative distance\n"
11883 "BGP distance\n"
11884 "Distance for routes external to the AS\n"
11885 "Distance for routes internal to the AS\n"
11886 "Distance for local routes\n")
11887{
11888 struct bgp *bgp;
11889
11890 bgp = vty->index;
11891
11892 bgp->distance_ebgp= 0;
11893 bgp->distance_ibgp = 0;
11894 bgp->distance_local = 0;
11895 return CMD_SUCCESS;
11896}
11897
11898ALIAS (no_bgp_distance,
11899 no_bgp_distance2_cmd,
11900 "no distance bgp",
11901 NO_STR
11902 "Define an administrative distance\n"
11903 "BGP distance\n")
11904
11905DEFUN (bgp_distance_source,
11906 bgp_distance_source_cmd,
11907 "distance <1-255> A.B.C.D/M",
11908 "Define an administrative distance\n"
11909 "Administrative distance\n"
11910 "IP source prefix\n")
11911{
11912 bgp_distance_set (vty, argv[0], argv[1], NULL);
11913 return CMD_SUCCESS;
11914}
11915
11916DEFUN (no_bgp_distance_source,
11917 no_bgp_distance_source_cmd,
11918 "no distance <1-255> A.B.C.D/M",
11919 NO_STR
11920 "Define an administrative distance\n"
11921 "Administrative distance\n"
11922 "IP source prefix\n")
11923{
11924 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11925 return CMD_SUCCESS;
11926}
11927
11928DEFUN (bgp_distance_source_access_list,
11929 bgp_distance_source_access_list_cmd,
11930 "distance <1-255> A.B.C.D/M WORD",
11931 "Define an administrative distance\n"
11932 "Administrative distance\n"
11933 "IP source prefix\n"
11934 "Access list name\n")
11935{
11936 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11937 return CMD_SUCCESS;
11938}
11939
11940DEFUN (no_bgp_distance_source_access_list,
11941 no_bgp_distance_source_access_list_cmd,
11942 "no distance <1-255> A.B.C.D/M WORD",
11943 NO_STR
11944 "Define an administrative distance\n"
11945 "Administrative distance\n"
11946 "IP source prefix\n"
11947 "Access list name\n")
11948{
11949 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11950 return CMD_SUCCESS;
11951}
David Lamparter6b0655a2014-06-04 06:53:35 +020011952
paul718e3742002-12-13 20:15:29 +000011953DEFUN (bgp_damp_set,
11954 bgp_damp_set_cmd,
11955 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11956 "BGP Specific commands\n"
11957 "Enable route-flap dampening\n"
11958 "Half-life time for the penalty\n"
11959 "Value to start reusing a route\n"
11960 "Value to start suppressing a route\n"
11961 "Maximum duration to suppress a stable route\n")
11962{
11963 struct bgp *bgp;
11964 int half = DEFAULT_HALF_LIFE * 60;
11965 int reuse = DEFAULT_REUSE;
11966 int suppress = DEFAULT_SUPPRESS;
11967 int max = 4 * half;
11968
11969 if (argc == 4)
11970 {
11971 half = atoi (argv[0]) * 60;
11972 reuse = atoi (argv[1]);
11973 suppress = atoi (argv[2]);
11974 max = atoi (argv[3]) * 60;
11975 }
11976 else if (argc == 1)
11977 {
11978 half = atoi (argv[0]) * 60;
11979 max = 4 * half;
11980 }
11981
11982 bgp = vty->index;
11983 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11984 half, reuse, suppress, max);
11985}
11986
11987ALIAS (bgp_damp_set,
11988 bgp_damp_set2_cmd,
11989 "bgp dampening <1-45>",
11990 "BGP Specific commands\n"
11991 "Enable route-flap dampening\n"
11992 "Half-life time for the penalty\n")
11993
11994ALIAS (bgp_damp_set,
11995 bgp_damp_set3_cmd,
11996 "bgp dampening",
11997 "BGP Specific commands\n"
11998 "Enable route-flap dampening\n")
11999
12000DEFUN (bgp_damp_unset,
12001 bgp_damp_unset_cmd,
12002 "no bgp dampening",
12003 NO_STR
12004 "BGP Specific commands\n"
12005 "Enable route-flap dampening\n")
12006{
12007 struct bgp *bgp;
12008
12009 bgp = vty->index;
12010 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
12011}
12012
12013ALIAS (bgp_damp_unset,
12014 bgp_damp_unset2_cmd,
12015 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12016 NO_STR
12017 "BGP Specific commands\n"
12018 "Enable route-flap dampening\n"
12019 "Half-life time for the penalty\n"
12020 "Value to start reusing a route\n"
12021 "Value to start suppressing a route\n"
12022 "Maximum duration to suppress a stable route\n")
12023
12024DEFUN (show_ip_bgp_dampened_paths,
12025 show_ip_bgp_dampened_paths_cmd,
12026 "show ip bgp dampened-paths",
12027 SHOW_STR
12028 IP_STR
12029 BGP_STR
12030 "Display paths suppressed due to dampening\n")
12031{
ajs5a646652004-11-05 01:25:55 +000012032 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
12033 NULL);
paul718e3742002-12-13 20:15:29 +000012034}
12035
12036DEFUN (show_ip_bgp_flap_statistics,
12037 show_ip_bgp_flap_statistics_cmd,
12038 "show ip bgp flap-statistics",
12039 SHOW_STR
12040 IP_STR
12041 BGP_STR
12042 "Display flap statistics of routes\n")
12043{
ajs5a646652004-11-05 01:25:55 +000012044 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12045 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012046}
David Lamparter6b0655a2014-06-04 06:53:35 +020012047
paul718e3742002-12-13 20:15:29 +000012048/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012049static int
paulfd79ac92004-10-13 05:06:08 +000012050bgp_clear_damp_route (struct vty *vty, const char *view_name,
12051 const char *ip_str, afi_t afi, safi_t safi,
12052 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012053{
12054 int ret;
12055 struct prefix match;
12056 struct bgp_node *rn;
12057 struct bgp_node *rm;
12058 struct bgp_info *ri;
12059 struct bgp_info *ri_temp;
12060 struct bgp *bgp;
12061 struct bgp_table *table;
12062
12063 /* BGP structure lookup. */
12064 if (view_name)
12065 {
12066 bgp = bgp_lookup_by_name (view_name);
12067 if (bgp == NULL)
12068 {
12069 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12070 return CMD_WARNING;
12071 }
12072 }
12073 else
12074 {
12075 bgp = bgp_get_default ();
12076 if (bgp == NULL)
12077 {
12078 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12079 return CMD_WARNING;
12080 }
12081 }
12082
12083 /* Check IP address argument. */
12084 ret = str2prefix (ip_str, &match);
12085 if (! ret)
12086 {
12087 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12088 return CMD_WARNING;
12089 }
12090
12091 match.family = afi2family (afi);
12092
12093 if (safi == SAFI_MPLS_VPN)
12094 {
12095 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12096 {
12097 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12098 continue;
12099
12100 if ((table = rn->info) != NULL)
12101 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012102 {
12103 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12104 {
12105 ri = rm->info;
12106 while (ri)
12107 {
12108 if (ri->extra && ri->extra->damp_info)
12109 {
12110 ri_temp = ri->next;
12111 bgp_damp_info_free (ri->extra->damp_info, 1);
12112 ri = ri_temp;
12113 }
12114 else
12115 ri = ri->next;
12116 }
12117 }
12118
12119 bgp_unlock_node (rm);
12120 }
paul718e3742002-12-13 20:15:29 +000012121 }
12122 }
12123 else
12124 {
12125 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012126 {
12127 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12128 {
12129 ri = rn->info;
12130 while (ri)
12131 {
12132 if (ri->extra && ri->extra->damp_info)
12133 {
12134 ri_temp = ri->next;
12135 bgp_damp_info_free (ri->extra->damp_info, 1);
12136 ri = ri_temp;
12137 }
12138 else
12139 ri = ri->next;
12140 }
12141 }
12142
12143 bgp_unlock_node (rn);
12144 }
paul718e3742002-12-13 20:15:29 +000012145 }
12146
12147 return CMD_SUCCESS;
12148}
12149
12150DEFUN (clear_ip_bgp_dampening,
12151 clear_ip_bgp_dampening_cmd,
12152 "clear ip bgp dampening",
12153 CLEAR_STR
12154 IP_STR
12155 BGP_STR
12156 "Clear route flap dampening information\n")
12157{
12158 bgp_damp_info_clean ();
12159 return CMD_SUCCESS;
12160}
12161
12162DEFUN (clear_ip_bgp_dampening_prefix,
12163 clear_ip_bgp_dampening_prefix_cmd,
12164 "clear ip bgp dampening A.B.C.D/M",
12165 CLEAR_STR
12166 IP_STR
12167 BGP_STR
12168 "Clear route flap dampening information\n"
12169 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12170{
12171 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12172 SAFI_UNICAST, NULL, 1);
12173}
12174
12175DEFUN (clear_ip_bgp_dampening_address,
12176 clear_ip_bgp_dampening_address_cmd,
12177 "clear ip bgp dampening A.B.C.D",
12178 CLEAR_STR
12179 IP_STR
12180 BGP_STR
12181 "Clear route flap dampening information\n"
12182 "Network to clear damping information\n")
12183{
12184 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12185 SAFI_UNICAST, NULL, 0);
12186}
12187
12188DEFUN (clear_ip_bgp_dampening_address_mask,
12189 clear_ip_bgp_dampening_address_mask_cmd,
12190 "clear ip bgp dampening A.B.C.D A.B.C.D",
12191 CLEAR_STR
12192 IP_STR
12193 BGP_STR
12194 "Clear route flap dampening information\n"
12195 "Network to clear damping information\n"
12196 "Network mask\n")
12197{
12198 int ret;
12199 char prefix_str[BUFSIZ];
12200
12201 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12202 if (! ret)
12203 {
12204 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12205 return CMD_WARNING;
12206 }
12207
12208 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12209 SAFI_UNICAST, NULL, 0);
12210}
David Lamparter6b0655a2014-06-04 06:53:35 +020012211
paul94f2b392005-06-28 12:44:16 +000012212static int
paul718e3742002-12-13 20:15:29 +000012213bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12214 afi_t afi, safi_t safi, int *write)
12215{
12216 struct bgp_node *prn;
12217 struct bgp_node *rn;
12218 struct bgp_table *table;
12219 struct prefix *p;
12220 struct prefix_rd *prd;
12221 struct bgp_static *bgp_static;
12222 u_int32_t label;
12223 char buf[SU_ADDRSTRLEN];
12224 char rdbuf[RD_ADDRSTRLEN];
12225
12226 /* Network configuration. */
12227 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12228 if ((table = prn->info) != NULL)
12229 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12230 if ((bgp_static = rn->info) != NULL)
12231 {
12232 p = &rn->p;
12233 prd = (struct prefix_rd *) &prn->p;
12234
12235 /* "address-family" display. */
12236 bgp_config_write_family_header (vty, afi, safi, write);
12237
12238 /* "network" configuration display. */
12239 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12240 label = decode_label (bgp_static->tag);
12241
12242 vty_out (vty, " network %s/%d rd %s tag %d",
12243 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12244 p->prefixlen,
12245 rdbuf, label);
12246 vty_out (vty, "%s", VTY_NEWLINE);
12247 }
12248 return 0;
12249}
12250
12251/* Configuration of static route announcement and aggregate
12252 information. */
12253int
12254bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12255 afi_t afi, safi_t safi, int *write)
12256{
12257 struct bgp_node *rn;
12258 struct prefix *p;
12259 struct bgp_static *bgp_static;
12260 struct bgp_aggregate *bgp_aggregate;
12261 char buf[SU_ADDRSTRLEN];
12262
12263 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12264 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12265
12266 /* Network configuration. */
12267 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12268 if ((bgp_static = rn->info) != NULL)
12269 {
12270 p = &rn->p;
12271
12272 /* "address-family" display. */
12273 bgp_config_write_family_header (vty, afi, safi, write);
12274
12275 /* "network" configuration display. */
12276 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12277 {
12278 u_int32_t destination;
12279 struct in_addr netmask;
12280
12281 destination = ntohl (p->u.prefix4.s_addr);
12282 masklen2ip (p->prefixlen, &netmask);
12283 vty_out (vty, " network %s",
12284 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12285
12286 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12287 || (IN_CLASSB (destination) && p->prefixlen == 16)
12288 || (IN_CLASSA (destination) && p->prefixlen == 8)
12289 || p->u.prefix4.s_addr == 0)
12290 {
12291 /* Natural mask is not display. */
12292 }
12293 else
12294 vty_out (vty, " mask %s", inet_ntoa (netmask));
12295 }
12296 else
12297 {
12298 vty_out (vty, " network %s/%d",
12299 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12300 p->prefixlen);
12301 }
12302
12303 if (bgp_static->rmap.name)
12304 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012305 else
12306 {
12307 if (bgp_static->backdoor)
12308 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012309 }
paul718e3742002-12-13 20:15:29 +000012310
12311 vty_out (vty, "%s", VTY_NEWLINE);
12312 }
12313
12314 /* Aggregate-address configuration. */
12315 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12316 if ((bgp_aggregate = rn->info) != NULL)
12317 {
12318 p = &rn->p;
12319
12320 /* "address-family" display. */
12321 bgp_config_write_family_header (vty, afi, safi, write);
12322
12323 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12324 {
12325 struct in_addr netmask;
12326
12327 masklen2ip (p->prefixlen, &netmask);
12328 vty_out (vty, " aggregate-address %s %s",
12329 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12330 inet_ntoa (netmask));
12331 }
12332 else
12333 {
12334 vty_out (vty, " aggregate-address %s/%d",
12335 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12336 p->prefixlen);
12337 }
12338
12339 if (bgp_aggregate->as_set)
12340 vty_out (vty, " as-set");
12341
12342 if (bgp_aggregate->summary_only)
12343 vty_out (vty, " summary-only");
12344
12345 vty_out (vty, "%s", VTY_NEWLINE);
12346 }
12347
12348 return 0;
12349}
12350
12351int
12352bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12353{
12354 struct bgp_node *rn;
12355 struct bgp_distance *bdistance;
12356
12357 /* Distance configuration. */
12358 if (bgp->distance_ebgp
12359 && bgp->distance_ibgp
12360 && bgp->distance_local
12361 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12362 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12363 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12364 vty_out (vty, " distance bgp %d %d %d%s",
12365 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12366 VTY_NEWLINE);
12367
12368 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12369 if ((bdistance = rn->info) != NULL)
12370 {
12371 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12372 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12373 bdistance->access_list ? bdistance->access_list : "",
12374 VTY_NEWLINE);
12375 }
12376
12377 return 0;
12378}
12379
12380/* Allocate routing table structure and install commands. */
12381void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012382bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012383{
12384 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012385 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012386
12387 /* IPv4 BGP commands. */
12388 install_element (BGP_NODE, &bgp_network_cmd);
12389 install_element (BGP_NODE, &bgp_network_mask_cmd);
12390 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12391 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12392 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12393 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12394 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12395 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12396 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12397 install_element (BGP_NODE, &no_bgp_network_cmd);
12398 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12399 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12400 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12401 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12402 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12403 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12404 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12405 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12406
12407 install_element (BGP_NODE, &aggregate_address_cmd);
12408 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12409 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12410 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12411 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12412 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12413 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12414 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12415 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12416 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12417 install_element (BGP_NODE, &no_aggregate_address_cmd);
12418 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12419 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12420 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12421 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12422 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12423 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12424 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12425 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12426 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12427
12428 /* IPv4 unicast configuration. */
12429 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12430 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12431 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12432 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12433 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12434 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012435 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012436 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12437 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12438 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12439 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12440 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012441
paul718e3742002-12-13 20:15:29 +000012442 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12443 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12444 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12445 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12446 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12447 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12448 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12449 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12450 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12451 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12452 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12453 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12454 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12455 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12456 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12457 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12458 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12459 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12460 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12461 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12462
12463 /* IPv4 multicast configuration. */
12464 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12465 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12466 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12467 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12468 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12469 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12470 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12471 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12472 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12473 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12474 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12475 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12476 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12477 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12478 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12479 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12480 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12481 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12482 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12483 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12484 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12485 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12486 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12487 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12488 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12489 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12490 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12491 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12492 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12493 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12494 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12495 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12496
12497 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12498 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012499 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012500 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12501 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012502 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012503 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12504 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12505 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12506 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012507 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012508 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12509 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12510 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12511 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12512 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12513 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12514 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12515 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12516 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12517 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12518 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12519 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12520 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12521 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12522 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12523 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12524 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12525 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12526 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12527 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12528 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12529 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12530 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12531 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12532 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012533 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12534 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12535 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12536 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12537 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012538 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12539 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12540 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12541 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12542 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12543 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12544 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12545 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12546 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12547 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12548 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12549 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12550 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12551 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12552 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12553 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12554 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12555 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012556 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012557 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12558 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12559 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12560 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12561 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12562 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12563 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12564 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12565 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12566 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12567 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12568 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12569 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12570 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12571 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12572 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012573 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012574 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012575 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012576 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012577 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012578 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012579 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12580 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012581 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012582 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012583 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012584 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012585 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012586 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012587
12588 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12589 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12590 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012591 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012592 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12593 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12594 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012595 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012596 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12597 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12598 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12599 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12600 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12601 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12602 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12603 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12604 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12605 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12606 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12607 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012608 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12609 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12610 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12611 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12612 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012613 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12614 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12615 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12616 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12617 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12618 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12619 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12620 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12621 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012622 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012623 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012624 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012625 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012626 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012627 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012628 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012629
12630 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12631 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012632 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012633 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12634 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012635 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012636 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12637 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12638 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12639 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012640 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012641 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12642 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12643 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12644 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12645 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12646 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12647 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12648 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12649 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12650 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12651 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12652 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12653 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12654 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12655 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12656 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12657 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12658 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12659 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12660 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12661 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12662 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12663 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12664 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12665 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012666 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12667 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12668 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12669 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12670 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012671 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12672 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12673 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12674 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12675 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12676 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12677 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12678 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12679 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12680 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12681 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12682 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12683 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12684 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12685 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12686 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12687 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12688 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012689 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012690 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12691 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12692 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12693 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12694 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12695 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12696 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12697 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12698 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12699 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12700 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12701 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12702 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12703 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12704 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12705 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012706 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012707 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012708 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012709 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012710 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012711 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012712 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12713 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012714 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012715 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012716 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012717 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012718 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012719 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012720
12721 /* BGP dampening clear commands */
12722 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12723 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12724 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12725 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12726
Paul Jakmaff7924f2006-09-04 01:10:36 +000012727 /* prefix count */
12728 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12729 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12730 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012731#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012732 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12733
paul718e3742002-12-13 20:15:29 +000012734 /* New config IPv6 BGP commands. */
12735 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12736 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12737 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12738 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12739
12740 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12741 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12742 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12743 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12744
G.Balaji73bfe0b2011-09-23 22:36:20 +053012745 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12746 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12747
paul718e3742002-12-13 20:15:29 +000012748 /* Old config IPv6 BGP commands. */
12749 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12750 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12751
12752 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12753 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12754 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12755 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12756
12757 install_element (VIEW_NODE, &show_bgp_cmd);
12758 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012759 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012760 install_element (VIEW_NODE, &show_bgp_route_cmd);
12761 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012762 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012763 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12764 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012765 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012766 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12767 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12768 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12769 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12770 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12771 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12772 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12773 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12774 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12775 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12776 install_element (VIEW_NODE, &show_bgp_community_cmd);
12777 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12778 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12779 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12780 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12781 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12782 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12783 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12784 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12785 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12786 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12787 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12788 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12789 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12790 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12791 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12792 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12793 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12794 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12795 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12796 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12797 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12798 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12799 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12800 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12801 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12802 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12803 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12804 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12805 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012806 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12807 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12808 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12809 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012810 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012811 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012812 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012813 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012814 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012815 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012816 install_element (VIEW_NODE, &show_bgp_view_cmd);
12817 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12818 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12819 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12820 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12821 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12822 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12823 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12824 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12825 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12826 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12827 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12828 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12829 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12830 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12831 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12832 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12833 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012834 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012835 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012836 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012837 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012838 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012839 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012840
12841 /* Restricted:
12842 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12843 */
12844 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12845 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012846 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012847 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12848 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012849 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012850 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12851 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12852 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12853 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12854 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12855 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12856 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12857 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12858 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12859 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12860 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12861 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12862 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12863 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12864 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12865 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12866 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012867 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012868 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012869 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012870 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12871 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12872 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12873 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12874 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12875 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12876 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012877 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012878 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012879 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012880
12881 install_element (ENABLE_NODE, &show_bgp_cmd);
12882 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012883 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012884 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12885 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012886 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012887 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12888 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012889 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012890 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12891 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12892 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12893 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12894 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12895 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12896 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12897 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12898 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12899 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12900 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12901 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12902 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12903 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12904 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12905 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12906 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12907 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12908 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12909 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12910 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12911 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12912 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12913 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12914 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12915 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12916 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12917 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12918 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12919 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12920 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12921 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12922 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12923 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12924 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12925 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12926 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12927 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12928 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12929 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012930 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12931 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12932 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12933 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012934 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012935 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012936 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012937 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012938 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012939 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012940 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12941 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12942 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12943 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12944 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12945 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12946 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12947 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12948 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12949 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12950 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12951 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12952 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12953 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12954 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12955 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12956 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12957 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012958 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012959 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012960 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012961 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012962 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012963 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012964
12965 /* Statistics */
12966 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12967 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12968 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12969 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12970
paul718e3742002-12-13 20:15:29 +000012971 /* old command */
12972 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12973 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12974 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12975 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12976 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12977 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12978 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12979 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12980 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12981 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12982 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12983 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12984 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12985 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12986 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12987 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12988 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12989 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12990 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12991 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12992 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12993 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12994 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12995 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12996 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12997 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12998 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12999 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
13000 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
13001 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
13002 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13003 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13004 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13005 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
13006 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13007 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000013008
paul718e3742002-12-13 20:15:29 +000013009 /* old command */
13010 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
13011 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
13012 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
13013 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
13014 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
13015 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
13016 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
13017 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
13018 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
13019 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
13020 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13021 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13022 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13023 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13024 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13025 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13026 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13027 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13028 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13029 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13030 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13031 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13032 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13033 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13034 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13035 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13036 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13037 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13038 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13039 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13040 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13041 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13042 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13043 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13044 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13045 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13046
13047 /* old command */
13048 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13049 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13050 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13051 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13052
13053 /* old command */
13054 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13055 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13056 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13057 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13058
13059 /* old command */
13060 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13061 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13062 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13063 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13064#endif /* HAVE_IPV6 */
13065
13066 install_element (BGP_NODE, &bgp_distance_cmd);
13067 install_element (BGP_NODE, &no_bgp_distance_cmd);
13068 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13069 install_element (BGP_NODE, &bgp_distance_source_cmd);
13070 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13071 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13072 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13073
13074 install_element (BGP_NODE, &bgp_damp_set_cmd);
13075 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13076 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13077 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13078 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13079 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13080 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13081 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13082 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13083 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013084
13085 /* Deprecated AS-Pathlimit commands */
13086 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13087 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13088 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13089 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13090 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13091 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13092
13093 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13094 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13095 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13096 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13097 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13098 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13099
13100 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13101 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13102 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13103 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13104 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13105 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13106
13107 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13108 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13109 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13110 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13111 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13112 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13113
13114 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13115 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13116 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13117 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13118 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13119 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13120
13121 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13122 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13123 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13124 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13125 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13126 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013127
13128#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013129 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13130 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013131#endif
paul718e3742002-12-13 20:15:29 +000013132}
Chris Caputo228da422009-07-18 05:44:03 +000013133
13134void
13135bgp_route_finish (void)
13136{
13137 bgp_table_unlock (bgp_distance_table);
13138 bgp_distance_table = NULL;
13139}