blob: f40127195f076194ab01a3db2f610389f733897f [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
vivekbd4b7f12014-09-30 15:54:45 -0700527 /* 11. Router-ID comparision. */
528 /* If one of the paths is "stale", the corresponding peer router-id will
529 * be 0 and would always win over the other path. If originator id is
530 * used for the comparision, it will decide which path is better.
531 */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000532 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
533 new_id.s_addr = newattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000534 else
535 new_id.s_addr = new->peer->remote_id.s_addr;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000536 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
537 exist_id.s_addr = existattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000538 else
539 exist_id.s_addr = exist->peer->remote_id.s_addr;
540
541 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
542 return 1;
543 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
544 return 0;
545
546 /* 12. Cluster length comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000547 new_cluster = exist_cluster = 0;
548
549 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
550 new_cluster = newattre->cluster->length;
551 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
552 exist_cluster = existattre->cluster->length;
paul718e3742002-12-13 20:15:29 +0000553
554 if (new_cluster < exist_cluster)
555 return 1;
556 if (new_cluster > exist_cluster)
557 return 0;
558
559 /* 13. Neighbor address comparision. */
vivekbd4b7f12014-09-30 15:54:45 -0700560 /* Do this only if neither path is "stale" as stale paths do not have
561 * valid peer information (as the connection may or may not be up).
562 */
563 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
564 return 1;
565 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
566 return 0;
567
paul718e3742002-12-13 20:15:29 +0000568 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
569
570 if (ret == 1)
571 return 0;
572 if (ret == -1)
573 return 1;
574
575 return 1;
576}
577
paul94f2b392005-06-28 12:44:16 +0000578static enum filter_type
paul718e3742002-12-13 20:15:29 +0000579bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
580 afi_t afi, safi_t safi)
581{
582 struct bgp_filter *filter;
583
584 filter = &peer->filter[afi][safi];
585
Paul Jakma650f76c2009-06-25 18:06:31 +0100586#define FILTER_EXIST_WARN(F,f,filter) \
587 if (BGP_DEBUG (update, UPDATE_IN) \
588 && !(F ## _IN (filter))) \
589 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
590 peer->host, #f, F ## _IN_NAME(filter));
591
592 if (DISTRIBUTE_IN_NAME (filter)) {
593 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
594
paul718e3742002-12-13 20:15:29 +0000595 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
596 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100597 }
paul718e3742002-12-13 20:15:29 +0000598
Paul Jakma650f76c2009-06-25 18:06:31 +0100599 if (PREFIX_LIST_IN_NAME (filter)) {
600 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
601
paul718e3742002-12-13 20:15:29 +0000602 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
603 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100604 }
paul718e3742002-12-13 20:15:29 +0000605
Paul Jakma650f76c2009-06-25 18:06:31 +0100606 if (FILTER_LIST_IN_NAME (filter)) {
607 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
608
paul718e3742002-12-13 20:15:29 +0000609 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
610 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100611 }
612
paul718e3742002-12-13 20:15:29 +0000613 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100614#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000615}
616
paul94f2b392005-06-28 12:44:16 +0000617static enum filter_type
paul718e3742002-12-13 20:15:29 +0000618bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
619 afi_t afi, safi_t safi)
620{
621 struct bgp_filter *filter;
622
623 filter = &peer->filter[afi][safi];
624
Paul Jakma650f76c2009-06-25 18:06:31 +0100625#define FILTER_EXIST_WARN(F,f,filter) \
626 if (BGP_DEBUG (update, UPDATE_OUT) \
627 && !(F ## _OUT (filter))) \
628 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
629 peer->host, #f, F ## _OUT_NAME(filter));
630
631 if (DISTRIBUTE_OUT_NAME (filter)) {
632 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
633
paul718e3742002-12-13 20:15:29 +0000634 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
635 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100636 }
paul718e3742002-12-13 20:15:29 +0000637
Paul Jakma650f76c2009-06-25 18:06:31 +0100638 if (PREFIX_LIST_OUT_NAME (filter)) {
639 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
640
paul718e3742002-12-13 20:15:29 +0000641 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
642 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100643 }
paul718e3742002-12-13 20:15:29 +0000644
Paul Jakma650f76c2009-06-25 18:06:31 +0100645 if (FILTER_LIST_OUT_NAME (filter)) {
646 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
647
paul718e3742002-12-13 20:15:29 +0000648 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
649 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100650 }
paul718e3742002-12-13 20:15:29 +0000651
652 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100653#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000654}
655
656/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000657static int
paul718e3742002-12-13 20:15:29 +0000658bgp_community_filter (struct peer *peer, struct attr *attr)
659{
660 if (attr->community)
661 {
662 /* NO_ADVERTISE check. */
663 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
664 return 1;
665
666 /* NO_EXPORT check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000667 if (peer->sort == BGP_PEER_EBGP &&
paul718e3742002-12-13 20:15:29 +0000668 community_include (attr->community, COMMUNITY_NO_EXPORT))
669 return 1;
670
671 /* NO_EXPORT_SUBCONFED check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000672 if (peer->sort == BGP_PEER_EBGP
673 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000674 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
675 return 1;
676 }
677 return 0;
678}
679
680/* Route reflection loop check. */
681static int
682bgp_cluster_filter (struct peer *peer, struct attr *attr)
683{
684 struct in_addr cluster_id;
685
Paul Jakmafb982c22007-05-04 20:15:47 +0000686 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000687 {
688 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
689 cluster_id = peer->bgp->cluster_id;
690 else
691 cluster_id = peer->bgp->router_id;
692
Paul Jakmafb982c22007-05-04 20:15:47 +0000693 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000694 return 1;
695 }
696 return 0;
697}
David Lamparter6b0655a2014-06-04 06:53:35 +0200698
paul94f2b392005-06-28 12:44:16 +0000699static int
paul718e3742002-12-13 20:15:29 +0000700bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
701 afi_t afi, safi_t safi)
702{
703 struct bgp_filter *filter;
704 struct bgp_info info;
705 route_map_result_t ret;
706
707 filter = &peer->filter[afi][safi];
708
709 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000710 if (peer->weight)
711 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000712
713 /* Route map apply. */
714 if (ROUTE_MAP_IN_NAME (filter))
715 {
716 /* Duplicate current value to new strucutre for modification. */
717 info.peer = peer;
718 info.attr = attr;
719
paulac41b2a2003-08-12 05:32:27 +0000720 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
721
paul718e3742002-12-13 20:15:29 +0000722 /* Apply BGP route map to the attribute. */
723 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000724
725 peer->rmap_type = 0;
726
paul718e3742002-12-13 20:15:29 +0000727 if (ret == RMAP_DENYMATCH)
David Lamparterc460e572014-06-04 00:54:58 +0200728 /* caller has multiple error paths with bgp_attr_flush() */
729 return RMAP_DENY;
paul718e3742002-12-13 20:15:29 +0000730 }
731 return RMAP_PERMIT;
732}
David Lamparter6b0655a2014-06-04 06:53:35 +0200733
paul94f2b392005-06-28 12:44:16 +0000734static int
paulfee0f4c2004-09-13 05:12:46 +0000735bgp_export_modifier (struct peer *rsclient, struct peer *peer,
736 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
737{
738 struct bgp_filter *filter;
739 struct bgp_info info;
740 route_map_result_t ret;
741
742 filter = &peer->filter[afi][safi];
743
744 /* Route map apply. */
745 if (ROUTE_MAP_EXPORT_NAME (filter))
746 {
747 /* Duplicate current value to new strucutre for modification. */
748 info.peer = rsclient;
749 info.attr = attr;
750
751 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
752
753 /* Apply BGP route map to the attribute. */
754 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
755
756 rsclient->rmap_type = 0;
757
758 if (ret == RMAP_DENYMATCH)
759 {
760 /* Free newly generated AS path and community by route-map. */
761 bgp_attr_flush (attr);
762 return RMAP_DENY;
763 }
764 }
765 return RMAP_PERMIT;
766}
767
paul94f2b392005-06-28 12:44:16 +0000768static int
paulfee0f4c2004-09-13 05:12:46 +0000769bgp_import_modifier (struct peer *rsclient, struct peer *peer,
770 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
771{
772 struct bgp_filter *filter;
773 struct bgp_info info;
774 route_map_result_t ret;
775
776 filter = &rsclient->filter[afi][safi];
777
778 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000779 if (peer->weight)
780 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000781
782 /* Route map apply. */
783 if (ROUTE_MAP_IMPORT_NAME (filter))
784 {
785 /* Duplicate current value to new strucutre for modification. */
786 info.peer = peer;
787 info.attr = attr;
788
789 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
790
791 /* Apply BGP route map to the attribute. */
792 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
793
794 peer->rmap_type = 0;
795
796 if (ret == RMAP_DENYMATCH)
797 {
798 /* Free newly generated AS path and community by route-map. */
799 bgp_attr_flush (attr);
800 return RMAP_DENY;
801 }
802 }
803 return RMAP_PERMIT;
804}
David Lamparter6b0655a2014-06-04 06:53:35 +0200805
paul94f2b392005-06-28 12:44:16 +0000806static int
paul718e3742002-12-13 20:15:29 +0000807bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
808 struct attr *attr, afi_t afi, safi_t safi)
809{
810 int ret;
811 char buf[SU_ADDRSTRLEN];
812 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000813 struct peer *from;
814 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000815 int transparent;
816 int reflect;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700817 struct attr *riattr;
paul718e3742002-12-13 20:15:29 +0000818
819 from = ri->peer;
820 filter = &peer->filter[afi][safi];
821 bgp = peer->bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700822 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paul718e3742002-12-13 20:15:29 +0000823
Paul Jakma750e8142008-07-22 21:11:48 +0000824 if (DISABLE_BGP_ANNOUNCE)
825 return 0;
paul718e3742002-12-13 20:15:29 +0000826
paulfee0f4c2004-09-13 05:12:46 +0000827 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
828 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
829 return 0;
830
paul718e3742002-12-13 20:15:29 +0000831 /* Do not send back route to sender. */
832 if (from == peer)
833 return 0;
834
835 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000836 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000837 if (! UNSUPPRESS_MAP_NAME (filter))
838 return 0;
839
840 /* Default route check. */
841 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
842 {
843 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
844 return 0;
845#ifdef HAVE_IPV6
846 else if (p->family == AF_INET6 && p->prefixlen == 0)
847 return 0;
848#endif /* HAVE_IPV6 */
849 }
850
paul286e1e72003-08-08 00:24:31 +0000851 /* Transparency check. */
852 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
853 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
854 transparent = 1;
855 else
856 transparent = 0;
857
paul718e3742002-12-13 20:15:29 +0000858 /* If community is not disabled check the no-export and local. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700859 if (! transparent && bgp_community_filter (peer, riattr))
paul718e3742002-12-13 20:15:29 +0000860 return 0;
861
862 /* If the attribute has originator-id and it is same as remote
863 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700864 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paul718e3742002-12-13 20:15:29 +0000865 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700866 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000867 {
868 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000869 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000870 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
871 peer->host,
872 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
873 p->prefixlen);
874 return 0;
875 }
876 }
877
878 /* ORF prefix-list filter check */
879 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
880 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
881 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
882 if (peer->orf_plist[afi][safi])
883 {
884 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
885 return 0;
886 }
887
888 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700889 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
paul718e3742002-12-13 20:15:29 +0000890 {
891 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000892 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000893 "%s [Update:SEND] %s/%d is filtered",
894 peer->host,
895 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
896 p->prefixlen);
897 return 0;
898 }
899
900#ifdef BGP_SEND_ASPATH_CHECK
901 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700902 if (aspath_loop_check (riattr->aspath, peer->as))
paul718e3742002-12-13 20:15:29 +0000903 {
904 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000905 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400906 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000907 peer->host, peer->as);
908 return 0;
909 }
910#endif /* BGP_SEND_ASPATH_CHECK */
911
912 /* If we're a CONFED we need to loop check the CONFED ID too */
913 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
914 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700915 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
paul718e3742002-12-13 20:15:29 +0000916 {
917 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000918 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400919 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000920 peer->host,
921 bgp->confed_id);
922 return 0;
923 }
924 }
925
926 /* Route-Reflect check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000927 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +0000928 reflect = 1;
929 else
930 reflect = 0;
931
932 /* IBGP reflection check. */
933 if (reflect)
934 {
935 /* A route from a Client peer. */
936 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
937 {
938 /* Reflect to all the Non-Client peers and also to the
939 Client peers other than the originator. Originator check
940 is already done. So there is noting to do. */
941 /* no bgp client-to-client reflection check. */
942 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
943 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
944 return 0;
945 }
946 else
947 {
948 /* A route from a Non-client peer. Reflect to all other
949 clients. */
950 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
951 return 0;
952 }
953 }
Paul Jakma41367172007-08-06 15:24:51 +0000954
paul718e3742002-12-13 20:15:29 +0000955 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700956 bgp_attr_dup (attr, riattr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000957
paul718e3742002-12-13 20:15:29 +0000958 /* If local-preference is not set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000959 if ((peer->sort == BGP_PEER_IBGP
960 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000961 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
962 {
963 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
964 attr->local_pref = bgp->default_local_pref;
965 }
966
Pradosh Mohapatra689bb662013-09-07 07:13:37 +0000967 /* If originator-id is not set and the route is to be reflected,
968 set the originator id */
969 if (peer && from && peer->sort == BGP_PEER_IBGP &&
970 from->sort == BGP_PEER_IBGP &&
971 (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
972 {
973 attr->extra = bgp_attr_extra_get(attr);
974 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
975 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
976 }
977
paul718e3742002-12-13 20:15:29 +0000978 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000979 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000980 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
981 {
982 if (ri->peer != bgp->peer_self && ! transparent
983 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
984 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
985 }
986
987 /* next-hop-set */
Timo Teräs9e7a53c2014-04-24 10:22:37 +0300988 if (transparent
989 || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
paul718e3742002-12-13 20:15:29 +0000990 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
991 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000992#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000993 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000994 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000995#endif /* HAVE_IPV6 */
996 )))
paul718e3742002-12-13 20:15:29 +0000997 {
998 /* NEXT-HOP Unchanged. */
999 }
1000 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
1001 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
1002#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +00001003 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001004 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +00001005#endif /* HAVE_IPV6 */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001006 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001007 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
1008 {
1009 /* Set IPv4 nexthop. */
1010 if (p->family == AF_INET)
1011 {
1012 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001013 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1014 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +00001015 else
1016 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1017 }
1018#ifdef HAVE_IPV6
1019 /* Set IPv6 nexthop. */
1020 if (p->family == AF_INET6)
1021 {
1022 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001023 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001024 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001025 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001026 }
1027#endif /* HAVE_IPV6 */
1028 }
1029
1030#ifdef HAVE_IPV6
1031 if (p->family == AF_INET6)
1032 {
paulfee0f4c2004-09-13 05:12:46 +00001033 /* Left nexthop_local unchanged if so configured. */
1034 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1035 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1036 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001037 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1038 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001039 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001040 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001041 }
1042
1043 /* Default nexthop_local treatment for non-RS-Clients */
1044 else
1045 {
paul718e3742002-12-13 20:15:29 +00001046 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001047 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001048
1049 /* Set link-local address for shared network peer. */
1050 if (peer->shared_network
1051 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1052 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001053 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001054 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001055 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001056 }
1057
1058 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1059 address.*/
1060 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001061 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001062
1063 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1064 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001065 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001066 }
paulfee0f4c2004-09-13 05:12:46 +00001067
1068 }
paul718e3742002-12-13 20:15:29 +00001069#endif /* HAVE_IPV6 */
1070
1071 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001072 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001073 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1074 && aspath_private_as_check (attr->aspath))
1075 attr->aspath = aspath_empty_get ();
1076
1077 /* Route map & unsuppress-map apply. */
1078 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001079 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001080 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001081 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001082 struct attr dummy_attr;
1083 struct attr_extra dummy_extra;
1084
1085 dummy_attr.extra = &dummy_extra;
1086
paul718e3742002-12-13 20:15:29 +00001087 info.peer = peer;
1088 info.attr = attr;
1089
1090 /* The route reflector is not allowed to modify the attributes
1091 of the reflected IBGP routes. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001092 if (from->sort == BGP_PEER_IBGP
1093 && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +00001094 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001095 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001096 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001097 }
paulac41b2a2003-08-12 05:32:27 +00001098
1099 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1100
Paul Jakmafb982c22007-05-04 20:15:47 +00001101 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001102 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1103 else
1104 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1105
paulac41b2a2003-08-12 05:32:27 +00001106 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001107
paul718e3742002-12-13 20:15:29 +00001108 if (ret == RMAP_DENYMATCH)
1109 {
1110 bgp_attr_flush (attr);
1111 return 0;
1112 }
1113 }
1114 return 1;
1115}
1116
paul94f2b392005-06-28 12:44:16 +00001117static int
paulfee0f4c2004-09-13 05:12:46 +00001118bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1119 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001120{
paulfee0f4c2004-09-13 05:12:46 +00001121 int ret;
1122 char buf[SU_ADDRSTRLEN];
1123 struct bgp_filter *filter;
1124 struct bgp_info info;
1125 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001126 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001127
1128 from = ri->peer;
1129 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001130 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001131
Paul Jakma750e8142008-07-22 21:11:48 +00001132 if (DISABLE_BGP_ANNOUNCE)
1133 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001134
1135 /* Do not send back route to sender. */
1136 if (from == rsclient)
1137 return 0;
1138
1139 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001140 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001141 if (! UNSUPPRESS_MAP_NAME (filter))
1142 return 0;
1143
1144 /* Default route check. */
1145 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1146 PEER_STATUS_DEFAULT_ORIGINATE))
1147 {
1148 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1149 return 0;
1150#ifdef HAVE_IPV6
1151 else if (p->family == AF_INET6 && p->prefixlen == 0)
1152 return 0;
1153#endif /* HAVE_IPV6 */
1154 }
1155
1156 /* If the attribute has originator-id and it is same as remote
1157 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001158 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001159 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001160 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001161 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001162 {
1163 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001164 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001165 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1166 rsclient->host,
1167 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1168 p->prefixlen);
1169 return 0;
1170 }
1171 }
1172
1173 /* ORF prefix-list filter check */
1174 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1175 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1176 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1177 if (rsclient->orf_plist[afi][safi])
1178 {
1179 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1180 return 0;
1181 }
1182
1183 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001184 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001185 {
1186 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001187 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001188 "%s [Update:SEND] %s/%d is filtered",
1189 rsclient->host,
1190 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1191 p->prefixlen);
1192 return 0;
1193 }
1194
1195#ifdef BGP_SEND_ASPATH_CHECK
1196 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001197 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001198 {
1199 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001200 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001201 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001202 rsclient->host, rsclient->as);
1203 return 0;
1204 }
1205#endif /* BGP_SEND_ASPATH_CHECK */
1206
1207 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001208 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001209
1210 /* next-hop-set */
1211 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1212#ifdef HAVE_IPV6
1213 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001214 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001215#endif /* HAVE_IPV6 */
1216 )
1217 {
1218 /* Set IPv4 nexthop. */
1219 if (p->family == AF_INET)
1220 {
1221 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001222 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001223 IPV4_MAX_BYTELEN);
1224 else
1225 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1226 }
1227#ifdef HAVE_IPV6
1228 /* Set IPv6 nexthop. */
1229 if (p->family == AF_INET6)
1230 {
1231 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001232 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001233 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001234 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001235 }
1236#endif /* HAVE_IPV6 */
1237 }
1238
1239#ifdef HAVE_IPV6
1240 if (p->family == AF_INET6)
1241 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001242 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001243
paulfee0f4c2004-09-13 05:12:46 +00001244 /* Left nexthop_local unchanged if so configured. */
1245 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1246 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1247 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001248 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1249 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001250 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001251 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001252 }
1253
1254 /* Default nexthop_local treatment for RS-Clients */
1255 else
1256 {
1257 /* Announcer and RS-Client are both in the same network */
1258 if (rsclient->shared_network && from->shared_network &&
1259 (rsclient->ifindex == from->ifindex))
1260 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001261 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1262 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001263 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001264 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001265 }
1266
1267 /* Set link-local address for shared network peer. */
1268 else if (rsclient->shared_network
1269 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1270 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001271 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001272 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001273 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001274 }
1275
1276 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001277 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001278 }
1279
1280 }
1281#endif /* HAVE_IPV6 */
1282
1283
1284 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001285 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001286 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1287 && aspath_private_as_check (attr->aspath))
1288 attr->aspath = aspath_empty_get ();
1289
1290 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001291 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001292 {
1293 info.peer = rsclient;
1294 info.attr = attr;
1295
1296 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1297
Paul Jakmafb982c22007-05-04 20:15:47 +00001298 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001299 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1300 else
1301 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1302
1303 rsclient->rmap_type = 0;
1304
1305 if (ret == RMAP_DENYMATCH)
1306 {
1307 bgp_attr_flush (attr);
1308 return 0;
1309 }
1310 }
1311
1312 return 1;
1313}
1314
1315struct bgp_info_pair
1316{
1317 struct bgp_info *old;
1318 struct bgp_info *new;
1319};
1320
paul94f2b392005-06-28 12:44:16 +00001321static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001322bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1323 struct bgp_maxpaths_cfg *mpath_cfg,
1324 struct bgp_info_pair *result)
paulfee0f4c2004-09-13 05:12:46 +00001325{
paul718e3742002-12-13 20:15:29 +00001326 struct bgp_info *new_select;
1327 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001328 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001329 struct bgp_info *ri1;
1330 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001331 struct bgp_info *nextri = NULL;
Josh Bailey96450fa2011-07-20 20:45:12 -07001332 int paths_eq, do_mpath;
1333 struct list mp_list;
1334
1335 bgp_mp_list_init (&mp_list);
1336 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1337 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1338
paul718e3742002-12-13 20:15:29 +00001339 /* bgp deterministic-med */
1340 new_select = NULL;
1341 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1342 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1343 {
1344 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1345 continue;
1346 if (BGP_INFO_HOLDDOWN (ri1))
1347 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001348 if (ri1->peer && ri1->peer != bgp->peer_self)
1349 if (ri1->peer->status != Established)
1350 continue;
paul718e3742002-12-13 20:15:29 +00001351
1352 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001353 if (do_mpath)
1354 bgp_mp_list_add (&mp_list, ri1);
1355 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001356 if (ri1->next)
1357 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1358 {
1359 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1360 continue;
1361 if (BGP_INFO_HOLDDOWN (ri2))
1362 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001363 if (ri2->peer &&
1364 ri2->peer != bgp->peer_self &&
1365 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1366 if (ri2->peer->status != Established)
1367 continue;
paul718e3742002-12-13 20:15:29 +00001368
1369 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1370 || aspath_cmp_left_confed (ri1->attr->aspath,
1371 ri2->attr->aspath))
1372 {
Josh Bailey6918e742011-07-20 20:48:20 -07001373 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1374 old_select = ri2;
Josh Bailey96450fa2011-07-20 20:45:12 -07001375 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
paul718e3742002-12-13 20:15:29 +00001376 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001377 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001378 new_select = ri2;
Josh Bailey6918e742011-07-20 20:48:20 -07001379 if (do_mpath && !paths_eq)
1380 {
1381 bgp_mp_list_clear (&mp_list);
1382 bgp_mp_list_add (&mp_list, ri2);
1383 }
paul718e3742002-12-13 20:15:29 +00001384 }
1385
Josh Bailey6918e742011-07-20 20:48:20 -07001386 if (do_mpath && paths_eq)
1387 bgp_mp_list_add (&mp_list, ri2);
1388
Paul Jakma1a392d42006-09-07 00:24:49 +00001389 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001390 }
1391 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001392 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1393 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001394
1395 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1396 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001397 }
1398
1399 /* Check old selected route and new selected route. */
1400 old_select = NULL;
1401 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001402 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001403 {
1404 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1405 old_select = ri;
1406
1407 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001408 {
1409 /* reap REMOVED routes, if needs be
1410 * selected route must stay for a while longer though
1411 */
1412 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1413 && (ri != old_select))
1414 bgp_info_reap (rn, ri);
1415
1416 continue;
1417 }
paul718e3742002-12-13 20:15:29 +00001418
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001419 if (ri->peer &&
1420 ri->peer != bgp->peer_self &&
1421 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1422 if (ri->peer->status != Established)
1423 continue;
1424
paul718e3742002-12-13 20:15:29 +00001425 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1426 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1427 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001428 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001429 continue;
1430 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001431 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1432 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001433
Josh Bailey96450fa2011-07-20 20:45:12 -07001434 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1435 {
Josh Bailey6918e742011-07-20 20:48:20 -07001436 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1437 bgp_mp_dmed_deselect (new_select);
1438
Josh Bailey96450fa2011-07-20 20:45:12 -07001439 new_select = ri;
1440
1441 if (do_mpath && !paths_eq)
1442 {
1443 bgp_mp_list_clear (&mp_list);
1444 bgp_mp_list_add (&mp_list, ri);
1445 }
1446 }
Josh Bailey6918e742011-07-20 20:48:20 -07001447 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1448 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001449
1450 if (do_mpath && paths_eq)
1451 bgp_mp_list_add (&mp_list, ri);
paul718e3742002-12-13 20:15:29 +00001452 }
paulb40d9392005-08-22 22:34:41 +00001453
paulfee0f4c2004-09-13 05:12:46 +00001454
Josh Bailey6918e742011-07-20 20:48:20 -07001455 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1456 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
Josh Bailey96450fa2011-07-20 20:45:12 -07001457
Josh Bailey0b597ef2011-07-20 20:49:11 -07001458 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001459 bgp_mp_list_clear (&mp_list);
1460
1461 result->old = old_select;
1462 result->new = new_select;
1463
1464 return;
paulfee0f4c2004-09-13 05:12:46 +00001465}
1466
paul94f2b392005-06-28 12:44:16 +00001467static int
paulfee0f4c2004-09-13 05:12:46 +00001468bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001469 struct bgp_node *rn, afi_t afi, safi_t safi)
1470{
paulfee0f4c2004-09-13 05:12:46 +00001471 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001472 struct attr attr;
1473 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001474
1475 p = &rn->p;
1476
Paul Jakma9eda90c2007-08-30 13:36:17 +00001477 /* Announce route to Established peer. */
1478 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001479 return 0;
1480
Paul Jakma9eda90c2007-08-30 13:36:17 +00001481 /* Address family configuration check. */
1482 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001483 return 0;
1484
Paul Jakma9eda90c2007-08-30 13:36:17 +00001485 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001486 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1487 PEER_STATUS_ORF_WAIT_REFRESH))
1488 return 0;
1489
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001490 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1491 attr.extra = &extra;
1492
Avneesh Sachdev67174042012-08-17 08:19:49 -07001493 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001494 {
1495 case BGP_TABLE_MAIN:
1496 /* Announcement to peer->conf. If the route is filtered,
1497 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001498 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1499 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001500 else
1501 bgp_adj_out_unset (rn, peer, p, afi, safi);
1502 break;
1503 case BGP_TABLE_RSCLIENT:
1504 /* Announcement to peer->conf. If the route is filtered,
1505 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001506 if (selected &&
1507 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1508 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1509 else
1510 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001511 break;
1512 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001513
paulfee0f4c2004-09-13 05:12:46 +00001514 return 0;
paul200df112005-06-01 11:17:05 +00001515}
paulfee0f4c2004-09-13 05:12:46 +00001516
paul200df112005-06-01 11:17:05 +00001517struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001518{
paul200df112005-06-01 11:17:05 +00001519 struct bgp *bgp;
1520 struct bgp_node *rn;
1521 afi_t afi;
1522 safi_t safi;
1523};
1524
1525static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001526bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001527{
paul0fb58d52005-11-14 14:31:49 +00001528 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001529 struct bgp *bgp = pq->bgp;
1530 struct bgp_node *rn = pq->rn;
1531 afi_t afi = pq->afi;
1532 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001533 struct bgp_info *new_select;
1534 struct bgp_info *old_select;
1535 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001536 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001537 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001538
paulfee0f4c2004-09-13 05:12:46 +00001539 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001540 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001541 new_select = old_and_new.new;
1542 old_select = old_and_new.old;
1543
paul200df112005-06-01 11:17:05 +00001544 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1545 {
Chris Caputo228da422009-07-18 05:44:03 +00001546 if (rsclient->group)
1547 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1548 {
1549 /* Nothing to do. */
1550 if (old_select && old_select == new_select)
1551 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1552 continue;
paulfee0f4c2004-09-13 05:12:46 +00001553
Chris Caputo228da422009-07-18 05:44:03 +00001554 if (old_select)
1555 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1556 if (new_select)
1557 {
1558 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1559 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001560 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1561 }
paulfee0f4c2004-09-13 05:12:46 +00001562
Chris Caputo228da422009-07-18 05:44:03 +00001563 bgp_process_announce_selected (rsclient, new_select, rn,
1564 afi, safi);
1565 }
paul200df112005-06-01 11:17:05 +00001566 }
1567 else
1568 {
hassob7395792005-08-26 12:58:38 +00001569 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001570 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001571 if (new_select)
1572 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001573 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1574 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001575 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001576 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001577 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001578 }
paulfee0f4c2004-09-13 05:12:46 +00001579
paulb40d9392005-08-22 22:34:41 +00001580 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1581 bgp_info_reap (rn, old_select);
1582
paul200df112005-06-01 11:17:05 +00001583 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1584 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001585}
1586
paul200df112005-06-01 11:17:05 +00001587static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001588bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001589{
paul0fb58d52005-11-14 14:31:49 +00001590 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001591 struct bgp *bgp = pq->bgp;
1592 struct bgp_node *rn = pq->rn;
1593 afi_t afi = pq->afi;
1594 safi_t safi = pq->safi;
1595 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001596 struct bgp_info *new_select;
1597 struct bgp_info *old_select;
1598 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001599 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001600 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001601
paulfee0f4c2004-09-13 05:12:46 +00001602 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001603 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001604 old_select = old_and_new.old;
1605 new_select = old_and_new.new;
1606
1607 /* Nothing to do. */
1608 if (old_select && old_select == new_select)
1609 {
1610 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001611 {
Josh Bailey8196f132011-07-20 20:47:07 -07001612 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1613 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001614 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001615
Josh Bailey8196f132011-07-20 20:47:07 -07001616 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001617 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1618 return WQ_SUCCESS;
1619 }
paulfee0f4c2004-09-13 05:12:46 +00001620 }
paul718e3742002-12-13 20:15:29 +00001621
hasso338b3422005-02-23 14:27:24 +00001622 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001623 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001624 if (new_select)
1625 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001626 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1627 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001628 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001629 }
1630
1631
paul718e3742002-12-13 20:15:29 +00001632 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001633 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001634 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001635 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001636 }
1637
1638 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001639 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1640 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001641 {
1642 if (new_select
1643 && new_select->type == ZEBRA_ROUTE_BGP
1644 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001645 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001646 else
1647 {
1648 /* Withdraw the route from the kernel. */
1649 if (old_select
1650 && old_select->type == ZEBRA_ROUTE_BGP
1651 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001652 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001653 }
1654 }
paulb40d9392005-08-22 22:34:41 +00001655
1656 /* Reap old select bgp_info, it it has been removed */
1657 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1658 bgp_info_reap (rn, old_select);
1659
paul200df112005-06-01 11:17:05 +00001660 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1661 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001662}
1663
paul200df112005-06-01 11:17:05 +00001664static void
paul0fb58d52005-11-14 14:31:49 +00001665bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001666{
paul0fb58d52005-11-14 14:31:49 +00001667 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001668 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001669
Chris Caputo228da422009-07-18 05:44:03 +00001670 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001671 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001672 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001673 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1674}
1675
1676static void
1677bgp_process_queue_init (void)
1678{
1679 bm->process_main_queue
1680 = work_queue_new (bm->master, "process_main_queue");
1681 bm->process_rsclient_queue
1682 = work_queue_new (bm->master, "process_rsclient_queue");
1683
1684 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1685 {
1686 zlog_err ("%s: Failed to allocate work queue", __func__);
1687 exit (1);
1688 }
1689
1690 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001691 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001692 bm->process_main_queue->spec.max_retries = 0;
1693 bm->process_main_queue->spec.hold = 50;
1694
Paul Jakma838bbde2010-01-08 14:05:32 +00001695 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
David Lamparterd43f8b32015-03-03 08:54:54 +01001696 bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del;
1697 bm->process_rsclient_queue->spec.max_retries = 0;
1698 bm->process_rsclient_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001699}
1700
1701void
paulfee0f4c2004-09-13 05:12:46 +00001702bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1703{
paul200df112005-06-01 11:17:05 +00001704 struct bgp_process_queue *pqnode;
1705
1706 /* already scheduled for processing? */
1707 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1708 return;
1709
1710 if ( (bm->process_main_queue == NULL) ||
1711 (bm->process_rsclient_queue == NULL) )
1712 bgp_process_queue_init ();
1713
1714 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1715 sizeof (struct bgp_process_queue));
1716 if (!pqnode)
1717 return;
Chris Caputo228da422009-07-18 05:44:03 +00001718
1719 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001720 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001721 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001722 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001723 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001724 pqnode->afi = afi;
1725 pqnode->safi = safi;
1726
Avneesh Sachdev67174042012-08-17 08:19:49 -07001727 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001728 {
paul200df112005-06-01 11:17:05 +00001729 case BGP_TABLE_MAIN:
1730 work_queue_add (bm->process_main_queue, pqnode);
1731 break;
1732 case BGP_TABLE_RSCLIENT:
1733 work_queue_add (bm->process_rsclient_queue, pqnode);
1734 break;
paulfee0f4c2004-09-13 05:12:46 +00001735 }
paul200df112005-06-01 11:17:05 +00001736
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001737 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001738 return;
paulfee0f4c2004-09-13 05:12:46 +00001739}
hasso0a486e52005-02-01 20:57:17 +00001740
paul94f2b392005-06-28 12:44:16 +00001741static int
hasso0a486e52005-02-01 20:57:17 +00001742bgp_maximum_prefix_restart_timer (struct thread *thread)
1743{
1744 struct peer *peer;
1745
1746 peer = THREAD_ARG (thread);
1747 peer->t_pmax_restart = NULL;
1748
1749 if (BGP_DEBUG (events, EVENTS))
1750 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1751 peer->host);
1752
1753 peer_clear (peer);
1754
1755 return 0;
1756}
1757
paulfee0f4c2004-09-13 05:12:46 +00001758int
paul5228ad22004-06-04 17:58:18 +00001759bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1760 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001761{
hassoe0701b72004-05-20 09:19:34 +00001762 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1763 return 0;
1764
1765 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001766 {
hassoe0701b72004-05-20 09:19:34 +00001767 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1768 && ! always)
1769 return 0;
paul718e3742002-12-13 20:15:29 +00001770
hassoe0701b72004-05-20 09:19:34 +00001771 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001772 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1773 "limit %ld", afi_safi_print (afi, safi), peer->host,
1774 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001775 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001776
hassoe0701b72004-05-20 09:19:34 +00001777 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1778 return 0;
paul718e3742002-12-13 20:15:29 +00001779
hassoe0701b72004-05-20 09:19:34 +00001780 {
paul5228ad22004-06-04 17:58:18 +00001781 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001782
1783 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001784 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001785
1786 ndata[0] = (afi >> 8);
1787 ndata[1] = afi;
1788 ndata[2] = safi;
1789 ndata[3] = (peer->pmax[afi][safi] >> 24);
1790 ndata[4] = (peer->pmax[afi][safi] >> 16);
1791 ndata[5] = (peer->pmax[afi][safi] >> 8);
1792 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001793
1794 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1795 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1796 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1797 }
hasso0a486e52005-02-01 20:57:17 +00001798
1799 /* restart timer start */
1800 if (peer->pmax_restart[afi][safi])
1801 {
1802 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1803
1804 if (BGP_DEBUG (events, EVENTS))
1805 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1806 peer->host, peer->v_pmax_restart);
1807
1808 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1809 peer->v_pmax_restart);
1810 }
1811
hassoe0701b72004-05-20 09:19:34 +00001812 return 1;
paul718e3742002-12-13 20:15:29 +00001813 }
hassoe0701b72004-05-20 09:19:34 +00001814 else
1815 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1816
1817 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1818 {
1819 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1820 && ! always)
1821 return 0;
1822
1823 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001824 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1825 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1826 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001827 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1828 }
1829 else
1830 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001831 return 0;
1832}
1833
paulb40d9392005-08-22 22:34:41 +00001834/* Unconditionally remove the route from the RIB, without taking
1835 * damping into consideration (eg, because the session went down)
1836 */
paul94f2b392005-06-28 12:44:16 +00001837static void
paul718e3742002-12-13 20:15:29 +00001838bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1839 afi_t afi, safi_t safi)
1840{
paul902212c2006-02-05 17:51:19 +00001841 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1842
1843 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1844 bgp_info_delete (rn, ri); /* keep historical info */
1845
paulb40d9392005-08-22 22:34:41 +00001846 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001847}
1848
paul94f2b392005-06-28 12:44:16 +00001849static void
paul718e3742002-12-13 20:15:29 +00001850bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001851 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001852{
paul718e3742002-12-13 20:15:29 +00001853 int status = BGP_DAMP_NONE;
1854
paulb40d9392005-08-22 22:34:41 +00001855 /* apply dampening, if result is suppressed, we'll be retaining
1856 * the bgp_info in the RIB for historical reference.
1857 */
1858 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001859 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001860 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1861 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001862 {
paul902212c2006-02-05 17:51:19 +00001863 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1864 return;
1865 }
1866
1867 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001868}
1869
paul94f2b392005-06-28 12:44:16 +00001870static void
paulfee0f4c2004-09-13 05:12:46 +00001871bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1872 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1873 int sub_type, struct prefix_rd *prd, u_char *tag)
1874{
1875 struct bgp_node *rn;
1876 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001877 struct attr new_attr;
1878 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001879 struct attr *attr_new;
1880 struct attr *attr_new2;
1881 struct bgp_info *ri;
1882 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001883 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001884 char buf[SU_ADDRSTRLEN];
1885
1886 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1887 if (peer == rsclient)
1888 return;
1889
1890 bgp = peer->bgp;
1891 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1892
1893 /* Check previously received route. */
1894 for (ri = rn->info; ri; ri = ri->next)
1895 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1896 break;
1897
1898 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001899 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001900 {
1901 reason = "as-path contains our own AS;";
1902 goto filtered;
1903 }
1904
1905 /* Route reflector originator ID check. */
1906 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001907 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001908 {
1909 reason = "originator is us;";
1910 goto filtered;
1911 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001912
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001913 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001914 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001915
1916 /* Apply export policy. */
1917 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1918 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1919 {
1920 reason = "export-policy;";
1921 goto filtered;
1922 }
1923
1924 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001925
paulfee0f4c2004-09-13 05:12:46 +00001926 /* Apply import policy. */
1927 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1928 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001929 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001930
1931 reason = "import-policy;";
1932 goto filtered;
1933 }
1934
1935 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001936 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001937
1938 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001939 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001940 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001941 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001942 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001943 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001944 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001945 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001946
1947 reason = "martian next-hop;";
1948 goto filtered;
1949 }
1950 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001951
paulfee0f4c2004-09-13 05:12:46 +00001952 /* If the update is implicit withdraw. */
1953 if (ri)
1954 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001955 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001956
1957 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001958 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1959 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001960 {
1961
Paul Jakma1a392d42006-09-07 00:24:49 +00001962 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001963
1964 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001965 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001966 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1967 peer->host,
1968 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1969 p->prefixlen, rsclient->host);
1970
Chris Caputo228da422009-07-18 05:44:03 +00001971 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001972 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001973
Chris Caputo228da422009-07-18 05:44:03 +00001974 return;
paulfee0f4c2004-09-13 05:12:46 +00001975 }
1976
Paul Jakma16d2e242007-04-10 19:32:10 +00001977 /* Withdraw/Announce before we fully processed the withdraw */
1978 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1979 bgp_info_restore (rn, ri);
1980
paulfee0f4c2004-09-13 05:12:46 +00001981 /* Received Logging. */
1982 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001983 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001984 peer->host,
1985 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1986 p->prefixlen, rsclient->host);
1987
1988 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001989 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001990
1991 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001992 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001993 ri->attr = attr_new;
1994
1995 /* Update MPLS tag. */
1996 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001997 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001998
Paul Jakma1a392d42006-09-07 00:24:49 +00001999 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002000
2001 /* Process change. */
2002 bgp_process (bgp, rn, afi, safi);
2003 bgp_unlock_node (rn);
2004
2005 return;
2006 }
2007
2008 /* Received Logging. */
2009 if (BGP_DEBUG (update, UPDATE_IN))
2010 {
ajsd2c1f162004-12-08 21:10:20 +00002011 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002012 peer->host,
2013 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2014 p->prefixlen, rsclient->host);
2015 }
2016
2017 /* Make new BGP info. */
2018 new = bgp_info_new ();
2019 new->type = type;
2020 new->sub_type = sub_type;
2021 new->peer = peer;
2022 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002023 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00002024
2025 /* Update MPLS tag. */
2026 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002027 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002028
Paul Jakma1a392d42006-09-07 00:24:49 +00002029 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002030
2031 /* Register new BGP information. */
2032 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002033
2034 /* route_node_get lock */
2035 bgp_unlock_node (rn);
2036
paulfee0f4c2004-09-13 05:12:46 +00002037 /* Process change. */
2038 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002039
paulfee0f4c2004-09-13 05:12:46 +00002040 return;
2041
2042 filtered:
2043
2044 /* This BGP update is filtered. Log the reason then update BGP entry. */
2045 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002046 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002047 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2048 peer->host,
2049 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2050 p->prefixlen, rsclient->host, reason);
2051
2052 if (ri)
paulb40d9392005-08-22 22:34:41 +00002053 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002054
2055 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002056
paulfee0f4c2004-09-13 05:12:46 +00002057 return;
2058}
2059
paul94f2b392005-06-28 12:44:16 +00002060static void
paulfee0f4c2004-09-13 05:12:46 +00002061bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2062 struct peer *peer, struct prefix *p, int type, int sub_type,
2063 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002064{
paulfee0f4c2004-09-13 05:12:46 +00002065 struct bgp_node *rn;
2066 struct bgp_info *ri;
2067 char buf[SU_ADDRSTRLEN];
2068
2069 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002070 return;
paulfee0f4c2004-09-13 05:12:46 +00002071
2072 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2073
2074 /* Lookup withdrawn route. */
2075 for (ri = rn->info; ri; ri = ri->next)
2076 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2077 break;
2078
2079 /* Withdraw specified route from routing table. */
2080 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002081 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002082 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002083 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002084 "%s Can't find the route %s/%d", peer->host,
2085 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2086 p->prefixlen);
2087
2088 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002089 bgp_unlock_node (rn);
2090}
paulfee0f4c2004-09-13 05:12:46 +00002091
paul94f2b392005-06-28 12:44:16 +00002092static int
paulfee0f4c2004-09-13 05:12:46 +00002093bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002094 afi_t afi, safi_t safi, int type, int sub_type,
2095 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2096{
2097 int ret;
2098 int aspath_loop_count = 0;
2099 struct bgp_node *rn;
2100 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002101 struct attr new_attr;
2102 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002103 struct attr *attr_new;
2104 struct bgp_info *ri;
2105 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002106 const char *reason;
paul718e3742002-12-13 20:15:29 +00002107 char buf[SU_ADDRSTRLEN];
2108
2109 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002110 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002111
paul718e3742002-12-13 20:15:29 +00002112 /* When peer's soft reconfiguration enabled. Record input packet in
2113 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002114 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2115 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002116 bgp_adj_in_set (rn, peer, attr);
2117
2118 /* Check previously received route. */
2119 for (ri = rn->info; ri; ri = ri->next)
2120 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2121 break;
2122
2123 /* AS path local-as loop check. */
2124 if (peer->change_local_as)
2125 {
2126 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2127 aspath_loop_count = 1;
2128
2129 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2130 {
2131 reason = "as-path contains our own AS;";
2132 goto filtered;
2133 }
2134 }
2135
2136 /* AS path loop check. */
2137 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2138 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2139 && aspath_loop_check(attr->aspath, bgp->confed_id)
2140 > peer->allowas_in[afi][safi]))
2141 {
2142 reason = "as-path contains our own AS;";
2143 goto filtered;
2144 }
2145
2146 /* Route reflector originator ID check. */
2147 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002148 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002149 {
2150 reason = "originator is us;";
2151 goto filtered;
2152 }
2153
2154 /* Route reflector cluster ID check. */
2155 if (bgp_cluster_filter (peer, attr))
2156 {
2157 reason = "reflected from the same cluster;";
2158 goto filtered;
2159 }
2160
2161 /* Apply incoming filter. */
2162 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2163 {
2164 reason = "filter;";
2165 goto filtered;
2166 }
2167
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002168 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002169 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002170
David Lamparterc460e572014-06-04 00:54:58 +02002171 /* Apply incoming route-map.
2172 * NB: new_attr may now contain newly allocated values from route-map "set"
2173 * commands, so we need bgp_attr_flush in the error paths, until we intern
2174 * the attr (which takes over the memory references) */
paul718e3742002-12-13 20:15:29 +00002175 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2176 {
2177 reason = "route-map;";
David Lamparterc460e572014-06-04 00:54:58 +02002178 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002179 goto filtered;
2180 }
2181
2182 /* IPv4 unicast next hop check. */
2183 if (afi == AFI_IP && safi == SAFI_UNICAST)
2184 {
2185 /* If the peer is EBGP and nexthop is not on connected route,
2186 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002187 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002188 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002189 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002190 {
2191 reason = "non-connected next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002192 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002193 goto filtered;
2194 }
2195
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002196 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002197 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002198 if (new_attr.nexthop.s_addr == 0
2199 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2200 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002201 {
2202 reason = "martian next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002203 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002204 goto filtered;
2205 }
2206 }
2207
2208 attr_new = bgp_attr_intern (&new_attr);
2209
2210 /* If the update is implicit withdraw. */
2211 if (ri)
2212 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002213 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002214
2215 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002216 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2217 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002218 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002219 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002220
2221 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002222 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002223 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2224 {
2225 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002226 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002227 peer->host,
2228 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2229 p->prefixlen);
2230
paul902212c2006-02-05 17:51:19 +00002231 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2232 {
2233 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2234 bgp_process (bgp, rn, afi, safi);
2235 }
paul718e3742002-12-13 20:15:29 +00002236 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002237 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002238 {
2239 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002240 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002241 "%s rcvd %s/%d...duplicate ignored",
2242 peer->host,
2243 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2244 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002245
2246 /* graceful restart STALE flag unset. */
2247 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2248 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002249 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002250 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002251 }
paul718e3742002-12-13 20:15:29 +00002252 }
2253
2254 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002255 bgp_attr_unintern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002256
paul718e3742002-12-13 20:15:29 +00002257 return 0;
2258 }
2259
Paul Jakma16d2e242007-04-10 19:32:10 +00002260 /* Withdraw/Announce before we fully processed the withdraw */
2261 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2262 {
2263 if (BGP_DEBUG (update, UPDATE_IN))
2264 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2265 peer->host,
2266 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2267 p->prefixlen);
2268 bgp_info_restore (rn, ri);
2269 }
2270
paul718e3742002-12-13 20:15:29 +00002271 /* Received Logging. */
2272 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002273 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002274 peer->host,
2275 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2276 p->prefixlen);
2277
hasso93406d82005-02-02 14:40:33 +00002278 /* graceful restart STALE flag unset. */
2279 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002280 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002281
paul718e3742002-12-13 20:15:29 +00002282 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002283 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002284
2285 /* implicit withdraw, decrement aggregate and pcount here.
2286 * only if update is accepted, they'll increment below.
2287 */
paul902212c2006-02-05 17:51:19 +00002288 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2289
paul718e3742002-12-13 20:15:29 +00002290 /* Update bgp route dampening information. */
2291 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002292 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002293 {
2294 /* This is implicit withdraw so we should update dampening
2295 information. */
2296 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2297 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002298 }
2299
paul718e3742002-12-13 20:15:29 +00002300 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002301 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002302 ri->attr = attr_new;
2303
2304 /* Update MPLS tag. */
2305 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002306 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002307
2308 /* Update bgp route dampening information. */
2309 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002310 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002311 {
2312 /* Now we do normal update dampening. */
2313 ret = bgp_damp_update (ri, rn, afi, safi);
2314 if (ret == BGP_DAMP_SUPPRESSED)
2315 {
2316 bgp_unlock_node (rn);
2317 return 0;
2318 }
2319 }
2320
2321 /* Nexthop reachability check. */
2322 if ((afi == AFI_IP || afi == AFI_IP6)
2323 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002324 && (peer->sort == BGP_PEER_IBGP
2325 || peer->sort == BGP_PEER_CONFED
2326 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002327 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002328 {
2329 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002330 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002331 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002332 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002333 }
2334 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002335 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002336
2337 /* Process change. */
2338 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2339
2340 bgp_process (bgp, rn, afi, safi);
2341 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002342
paul718e3742002-12-13 20:15:29 +00002343 return 0;
2344 }
2345
2346 /* Received Logging. */
2347 if (BGP_DEBUG (update, UPDATE_IN))
2348 {
ajsd2c1f162004-12-08 21:10:20 +00002349 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002350 peer->host,
2351 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2352 p->prefixlen);
2353 }
2354
paul718e3742002-12-13 20:15:29 +00002355 /* Make new BGP info. */
2356 new = bgp_info_new ();
2357 new->type = type;
2358 new->sub_type = sub_type;
2359 new->peer = peer;
2360 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002361 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002362
2363 /* Update MPLS tag. */
2364 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002365 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002366
2367 /* Nexthop reachability check. */
2368 if ((afi == AFI_IP || afi == AFI_IP6)
2369 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002370 && (peer->sort == BGP_PEER_IBGP
2371 || peer->sort == BGP_PEER_CONFED
2372 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002373 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002374 {
2375 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002376 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002377 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002378 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002379 }
2380 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002381 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002382
paul902212c2006-02-05 17:51:19 +00002383 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002384 bgp_aggregate_increment (bgp, p, new, afi, safi);
2385
2386 /* Register new BGP information. */
2387 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002388
2389 /* route_node_get lock */
2390 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002391
paul718e3742002-12-13 20:15:29 +00002392 /* If maximum prefix count is configured and current prefix
2393 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002394 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2395 return -1;
paul718e3742002-12-13 20:15:29 +00002396
2397 /* Process change. */
2398 bgp_process (bgp, rn, afi, safi);
2399
2400 return 0;
2401
2402 /* This BGP update is filtered. Log the reason then update BGP
2403 entry. */
2404 filtered:
2405 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002406 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002407 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2408 peer->host,
2409 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2410 p->prefixlen, reason);
2411
2412 if (ri)
paulb40d9392005-08-22 22:34:41 +00002413 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002414
2415 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002416
paul718e3742002-12-13 20:15:29 +00002417 return 0;
2418}
2419
2420int
paulfee0f4c2004-09-13 05:12:46 +00002421bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2422 afi_t afi, safi_t safi, int type, int sub_type,
2423 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2424{
2425 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002426 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002427 struct bgp *bgp;
2428 int ret;
2429
2430 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2431 soft_reconfig);
2432
2433 bgp = peer->bgp;
2434
2435 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002436 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002437 {
2438 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2439 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2440 sub_type, prd, tag);
2441 }
2442
2443 return ret;
2444}
2445
2446int
paul718e3742002-12-13 20:15:29 +00002447bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002448 afi_t afi, safi_t safi, int type, int sub_type,
2449 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002450{
2451 struct bgp *bgp;
2452 char buf[SU_ADDRSTRLEN];
2453 struct bgp_node *rn;
2454 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002455 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002456 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002457
2458 bgp = peer->bgp;
2459
David Lamparter4584c232015-04-13 09:50:00 +02002460 /* Lookup node. */
2461 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2462
2463 /* Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2464 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2465 * the iteration over all RS clients.
2466 * Since we need to remove the entry from adj_in anyway, do that first and
2467 * if there was no entry, we don't need to do anything more. */
2468 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2469 && peer != bgp->peer_self)
2470 if (!bgp_adj_in_unset (rn, peer))
2471 {
2472 if (BGP_DEBUG (update, UPDATE_IN))
2473 zlog (peer->log, LOG_DEBUG, "%s withdrawing route %s/%d "
2474 "not in adj-in", peer->host,
2475 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2476 p->prefixlen);
2477 bgp_unlock_node (rn);
2478 return 0;
2479 }
2480
paulfee0f4c2004-09-13 05:12:46 +00002481 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002482 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002483 {
2484 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2485 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2486 }
2487
paul718e3742002-12-13 20:15:29 +00002488 /* Logging. */
2489 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002490 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002491 peer->host,
2492 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2493 p->prefixlen);
2494
paul718e3742002-12-13 20:15:29 +00002495 /* Lookup withdrawn route. */
2496 for (ri = rn->info; ri; ri = ri->next)
2497 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2498 break;
2499
2500 /* Withdraw specified route from routing table. */
2501 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002502 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002503 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002504 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002505 "%s Can't find the route %s/%d", peer->host,
2506 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2507 p->prefixlen);
2508
2509 /* Unlock bgp_node_get() lock. */
2510 bgp_unlock_node (rn);
2511
2512 return 0;
2513}
David Lamparter6b0655a2014-06-04 06:53:35 +02002514
paul718e3742002-12-13 20:15:29 +00002515void
2516bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2517{
2518 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002519 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002520 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002521 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002522 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002523 struct bgp_node *rn;
2524 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002525 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002526
Paul Jakmab2497022007-06-14 11:17:58 +00002527 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002528 return;
2529
paul718e3742002-12-13 20:15:29 +00002530 bgp = peer->bgp;
2531 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002532
paul718e3742002-12-13 20:15:29 +00002533 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2534 aspath = attr.aspath;
2535 attr.local_pref = bgp->default_local_pref;
2536 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2537
2538 if (afi == AFI_IP)
2539 str2prefix ("0.0.0.0/0", &p);
2540#ifdef HAVE_IPV6
2541 else if (afi == AFI_IP6)
2542 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002543 struct attr_extra *ae = attr.extra;
2544
paul718e3742002-12-13 20:15:29 +00002545 str2prefix ("::/0", &p);
2546
2547 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002548 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002549 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002550 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002551
2552 /* If the peer is on shared nextwork and we have link-local
2553 nexthop set it. */
2554 if (peer->shared_network
2555 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2556 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002557 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002558 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002559 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002560 }
2561 }
2562#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002563
2564 if (peer->default_rmap[afi][safi].name)
2565 {
paulfee0f4c2004-09-13 05:12:46 +00002566 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002567 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2568 {
2569 for (ri = rn->info; ri; ri = ri->next)
2570 {
2571 struct attr dummy_attr;
2572 struct attr_extra dummy_extra;
2573 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002574
Christian Frankedcab1bb2012-12-07 16:45:52 +00002575 /* Provide dummy so the route-map can't modify the attributes */
2576 dummy_attr.extra = &dummy_extra;
2577 bgp_attr_dup(&dummy_attr, ri->attr);
2578 info.peer = ri->peer;
2579 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002580
Christian Frankedcab1bb2012-12-07 16:45:52 +00002581 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2582 RMAP_BGP, &info);
2583
2584 /* The route map might have set attributes. If we don't flush them
2585 * here, they will be leaked. */
2586 bgp_attr_flush(&dummy_attr);
2587 if (ret != RMAP_DENYMATCH)
2588 break;
2589 }
2590 if (ret != RMAP_DENYMATCH)
2591 break;
2592 }
paulfee0f4c2004-09-13 05:12:46 +00002593 bgp->peer_self->rmap_type = 0;
2594
paul718e3742002-12-13 20:15:29 +00002595 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002596 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002597 }
2598
2599 if (withdraw)
2600 {
2601 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2602 bgp_default_withdraw_send (peer, afi, safi);
2603 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2604 }
2605 else
2606 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002607 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2608 {
2609 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2610 bgp_default_update_send (peer, &attr, afi, safi, from);
2611 }
paul718e3742002-12-13 20:15:29 +00002612 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002613
2614 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002615 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002616}
David Lamparter6b0655a2014-06-04 06:53:35 +02002617
paul718e3742002-12-13 20:15:29 +00002618static void
2619bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002620 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002621{
2622 struct bgp_node *rn;
2623 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002624 struct attr attr;
2625 struct attr_extra extra;
2626
paul718e3742002-12-13 20:15:29 +00002627 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002628 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002629
2630 if (safi != SAFI_MPLS_VPN
2631 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2632 bgp_default_originate (peer, afi, safi, 0);
2633
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002634 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2635 attr.extra = &extra;
2636
paul718e3742002-12-13 20:15:29 +00002637 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2638 for (ri = rn->info; ri; ri = ri->next)
2639 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2640 {
paulfee0f4c2004-09-13 05:12:46 +00002641 if ( (rsclient) ?
2642 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2643 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002644 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2645 else
2646 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2647 }
2648}
2649
2650void
2651bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2652{
2653 struct bgp_node *rn;
2654 struct bgp_table *table;
2655
2656 if (peer->status != Established)
2657 return;
2658
2659 if (! peer->afc_nego[afi][safi])
2660 return;
2661
2662 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2663 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2664 return;
2665
2666 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002667 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002668 else
2669 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2670 rn = bgp_route_next(rn))
2671 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002672 bgp_announce_table (peer, afi, safi, table, 0);
2673
2674 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2675 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002676}
2677
2678void
2679bgp_announce_route_all (struct peer *peer)
2680{
2681 afi_t afi;
2682 safi_t safi;
2683
2684 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2685 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2686 bgp_announce_route (peer, afi, safi);
2687}
David Lamparter6b0655a2014-06-04 06:53:35 +02002688
paul718e3742002-12-13 20:15:29 +00002689static void
paulfee0f4c2004-09-13 05:12:46 +00002690bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002691 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002692{
2693 struct bgp_node *rn;
2694 struct bgp_adj_in *ain;
2695
2696 if (! table)
2697 table = rsclient->bgp->rib[afi][safi];
2698
2699 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2700 for (ain = rn->adj_in; ain; ain = ain->next)
2701 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002702 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002703 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002704
paulfee0f4c2004-09-13 05:12:46 +00002705 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002706 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002707 }
2708}
2709
2710void
2711bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2712{
2713 struct bgp_table *table;
2714 struct bgp_node *rn;
2715
2716 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002717 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002718
2719 else
2720 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2721 rn = bgp_route_next (rn))
2722 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002723 {
2724 struct prefix_rd prd;
2725 prd.family = AF_UNSPEC;
2726 prd.prefixlen = 64;
2727 memcpy(&prd.val, rn->p.u.val, 8);
2728
2729 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2730 }
paulfee0f4c2004-09-13 05:12:46 +00002731}
David Lamparter6b0655a2014-06-04 06:53:35 +02002732
paulfee0f4c2004-09-13 05:12:46 +00002733static void
paul718e3742002-12-13 20:15:29 +00002734bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002735 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002736{
2737 int ret;
2738 struct bgp_node *rn;
2739 struct bgp_adj_in *ain;
2740
2741 if (! table)
2742 table = peer->bgp->rib[afi][safi];
2743
2744 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2745 for (ain = rn->adj_in; ain; ain = ain->next)
2746 {
2747 if (ain->peer == peer)
2748 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002749 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002750 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002751
paul718e3742002-12-13 20:15:29 +00002752 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2753 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002754 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002755
paul718e3742002-12-13 20:15:29 +00002756 if (ret < 0)
2757 {
2758 bgp_unlock_node (rn);
2759 return;
2760 }
2761 continue;
2762 }
2763 }
2764}
2765
2766void
2767bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2768{
2769 struct bgp_node *rn;
2770 struct bgp_table *table;
2771
2772 if (peer->status != Established)
2773 return;
2774
2775 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002776 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002777 else
2778 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2779 rn = bgp_route_next (rn))
2780 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002781 {
2782 struct prefix_rd prd;
2783 prd.family = AF_UNSPEC;
2784 prd.prefixlen = 64;
2785 memcpy(&prd.val, rn->p.u.val, 8);
2786
2787 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2788 }
paul718e3742002-12-13 20:15:29 +00002789}
David Lamparter6b0655a2014-06-04 06:53:35 +02002790
Chris Caputo228da422009-07-18 05:44:03 +00002791
2792struct bgp_clear_node_queue
2793{
2794 struct bgp_node *rn;
2795 enum bgp_clear_route_type purpose;
2796};
2797
paul200df112005-06-01 11:17:05 +00002798static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002799bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002800{
Chris Caputo228da422009-07-18 05:44:03 +00002801 struct bgp_clear_node_queue *cnq = data;
2802 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002803 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002804 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002805 afi_t afi = bgp_node_table (rn)->afi;
2806 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002807
Paul Jakma64e580a2006-02-21 01:09:01 +00002808 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002809
Paul Jakma64e580a2006-02-21 01:09:01 +00002810 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002811 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002812 {
2813 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002814 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2815 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002816 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002817 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2818 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002819 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002820 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002821 break;
2822 }
paul200df112005-06-01 11:17:05 +00002823 return WQ_SUCCESS;
2824}
2825
2826static void
paul0fb58d52005-11-14 14:31:49 +00002827bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002828{
Chris Caputo228da422009-07-18 05:44:03 +00002829 struct bgp_clear_node_queue *cnq = data;
2830 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002831 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002832
2833 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002834 bgp_table_unlock (table);
2835 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002836}
2837
2838static void
paul94f2b392005-06-28 12:44:16 +00002839bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002840{
Paul Jakma64e580a2006-02-21 01:09:01 +00002841 struct peer *peer = wq->spec.data;
2842
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002843 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002844 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002845
2846 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002847}
2848
2849static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002850bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002851{
Paul Jakmaa2943652009-07-21 14:02:04 +01002852 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002853
Paul Jakmaa2943652009-07-21 14:02:04 +01002854 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002855#undef CLEAR_QUEUE_NAME_LEN
2856
2857 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002858 {
2859 zlog_err ("%s: Failed to allocate work queue", __func__);
2860 exit (1);
2861 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002862 peer->clear_node_queue->spec.hold = 10;
2863 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2864 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2865 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2866 peer->clear_node_queue->spec.max_retries = 0;
2867
2868 /* we only 'lock' this peer reference when the queue is actually active */
2869 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002870}
2871
paul718e3742002-12-13 20:15:29 +00002872static void
2873bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002874 struct bgp_table *table, struct peer *rsclient,
2875 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002876{
2877 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002878
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002879
paul718e3742002-12-13 20:15:29 +00002880 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002881 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002882
hasso6cf159b2005-03-21 10:28:14 +00002883 /* If still no table => afi/safi isn't configured at all or smth. */
2884 if (! table)
2885 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002886
2887 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2888 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002889 struct bgp_info *ri;
2890 struct bgp_adj_in *ain;
2891 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002892
2893 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2894 * queued for every clearing peer, regardless of whether it is
2895 * relevant to the peer at hand.
2896 *
2897 * Overview: There are 3 different indices which need to be
2898 * scrubbed, potentially, when a peer is removed:
2899 *
2900 * 1 peer's routes visible via the RIB (ie accepted routes)
2901 * 2 peer's routes visible by the (optional) peer's adj-in index
2902 * 3 other routes visible by the peer's adj-out index
2903 *
2904 * 3 there is no hurry in scrubbing, once the struct peer is
2905 * removed from bgp->peer, we could just GC such deleted peer's
2906 * adj-outs at our leisure.
2907 *
2908 * 1 and 2 must be 'scrubbed' in some way, at least made
2909 * invisible via RIB index before peer session is allowed to be
2910 * brought back up. So one needs to know when such a 'search' is
2911 * complete.
2912 *
2913 * Ideally:
2914 *
2915 * - there'd be a single global queue or a single RIB walker
2916 * - rather than tracking which route_nodes still need to be
2917 * examined on a peer basis, we'd track which peers still
2918 * aren't cleared
2919 *
2920 * Given that our per-peer prefix-counts now should be reliable,
2921 * this may actually be achievable. It doesn't seem to be a huge
2922 * problem at this time,
2923 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002924 for (ain = rn->adj_in; ain; ain = ain->next)
2925 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2926 {
2927 bgp_adj_in_remove (rn, ain);
2928 bgp_unlock_node (rn);
2929 break;
2930 }
2931 for (aout = rn->adj_out; aout; aout = aout->next)
2932 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2933 {
2934 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2935 bgp_unlock_node (rn);
2936 break;
2937 }
2938
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002939 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002940 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002941 {
Chris Caputo228da422009-07-18 05:44:03 +00002942 struct bgp_clear_node_queue *cnq;
2943
2944 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002945 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002946 bgp_lock_node (rn);
2947 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2948 sizeof (struct bgp_clear_node_queue));
2949 cnq->rn = rn;
2950 cnq->purpose = purpose;
2951 work_queue_add (peer->clear_node_queue, cnq);
2952 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002953 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002954 }
2955 return;
2956}
2957
2958void
Chris Caputo228da422009-07-18 05:44:03 +00002959bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2960 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002961{
2962 struct bgp_node *rn;
2963 struct bgp_table *table;
2964 struct peer *rsclient;
2965 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002966
Paul Jakma64e580a2006-02-21 01:09:01 +00002967 if (peer->clear_node_queue == NULL)
2968 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002969
Paul Jakmaca058a32006-09-14 02:58:49 +00002970 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2971 * Idle until it receives a Clearing_Completed event. This protects
2972 * against peers which flap faster than we can we clear, which could
2973 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002974 *
2975 * a) race with routes from the new session being installed before
2976 * clear_route_node visits the node (to delete the route of that
2977 * peer)
2978 * b) resource exhaustion, clear_route_node likely leads to an entry
2979 * on the process_main queue. Fast-flapping could cause that queue
2980 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002981 */
Donald Sharp7ef42212015-03-30 06:32:52 -07002982
2983 /* lock peer in assumption that clear-node-queue will get nodes; if so,
2984 * the unlock will happen upon work-queue completion; other wise, the
2985 * unlock happens at the end of this function.
2986 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002987 if (!peer->clear_node_queue->thread)
Donald Sharp7ef42212015-03-30 06:32:52 -07002988 peer_lock (peer);
paulfee0f4c2004-09-13 05:12:46 +00002989
Chris Caputo228da422009-07-18 05:44:03 +00002990 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002991 {
Chris Caputo228da422009-07-18 05:44:03 +00002992 case BGP_CLEAR_ROUTE_NORMAL:
2993 if (safi != SAFI_MPLS_VPN)
2994 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2995 else
2996 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2997 rn = bgp_route_next (rn))
2998 if ((table = rn->info) != NULL)
2999 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3000
3001 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
3002 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
3003 PEER_FLAG_RSERVER_CLIENT))
3004 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3005 break;
3006
3007 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
3008 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3009 break;
3010
3011 default:
3012 assert (0);
3013 break;
paulfee0f4c2004-09-13 05:12:46 +00003014 }
Donald Sharp7ef42212015-03-30 06:32:52 -07003015
3016 /* unlock if no nodes got added to the clear-node-queue. */
Paul Jakma65ca75e2006-05-04 08:08:15 +00003017 if (!peer->clear_node_queue->thread)
Donald Sharp7ef42212015-03-30 06:32:52 -07003018 peer_unlock (peer);
3019
paul718e3742002-12-13 20:15:29 +00003020}
3021
3022void
3023bgp_clear_route_all (struct peer *peer)
3024{
3025 afi_t afi;
3026 safi_t safi;
3027
3028 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3029 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003030 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003031}
3032
3033void
3034bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3035{
3036 struct bgp_table *table;
3037 struct bgp_node *rn;
3038 struct bgp_adj_in *ain;
3039
3040 table = peer->bgp->rib[afi][safi];
3041
3042 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3043 for (ain = rn->adj_in; ain ; ain = ain->next)
3044 if (ain->peer == peer)
3045 {
3046 bgp_adj_in_remove (rn, ain);
3047 bgp_unlock_node (rn);
3048 break;
3049 }
3050}
hasso93406d82005-02-02 14:40:33 +00003051
3052void
3053bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3054{
3055 struct bgp_node *rn;
3056 struct bgp_info *ri;
3057 struct bgp_table *table;
3058
3059 table = peer->bgp->rib[afi][safi];
3060
3061 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3062 {
3063 for (ri = rn->info; ri; ri = ri->next)
3064 if (ri->peer == peer)
3065 {
3066 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3067 bgp_rib_remove (rn, ri, peer, afi, safi);
3068 break;
3069 }
3070 }
3071}
David Lamparter6b0655a2014-06-04 06:53:35 +02003072
paul718e3742002-12-13 20:15:29 +00003073/* Delete all kernel routes. */
3074void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003075bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003076{
3077 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003078 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003079 struct bgp_node *rn;
3080 struct bgp_table *table;
3081 struct bgp_info *ri;
3082
paul1eb8ef22005-04-07 07:30:20 +00003083 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003084 {
3085 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3086
3087 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3088 for (ri = rn->info; ri; ri = ri->next)
3089 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3090 && ri->type == ZEBRA_ROUTE_BGP
3091 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003092 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003093
3094 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3095
3096 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3097 for (ri = rn->info; ri; ri = ri->next)
3098 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3099 && ri->type == ZEBRA_ROUTE_BGP
3100 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003101 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003102 }
3103}
3104
3105void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003106bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003107{
3108 vty_reset ();
3109 bgp_zclient_reset ();
3110 access_list_reset ();
3111 prefix_list_reset ();
3112}
David Lamparter6b0655a2014-06-04 06:53:35 +02003113
paul718e3742002-12-13 20:15:29 +00003114/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3115 value. */
3116int
3117bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3118{
3119 u_char *pnt;
3120 u_char *lim;
3121 struct prefix p;
3122 int psize;
3123 int ret;
3124
3125 /* Check peer status. */
3126 if (peer->status != Established)
3127 return 0;
3128
3129 pnt = packet->nlri;
3130 lim = pnt + packet->length;
3131
3132 for (; pnt < lim; pnt += psize)
3133 {
3134 /* Clear prefix structure. */
3135 memset (&p, 0, sizeof (struct prefix));
3136
3137 /* Fetch prefix length. */
3138 p.prefixlen = *pnt++;
3139 p.family = afi2family (packet->afi);
3140
3141 /* Already checked in nlri_sanity_check(). We do double check
3142 here. */
3143 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3144 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3145 return -1;
3146
3147 /* Packet size overflow check. */
3148 psize = PSIZE (p.prefixlen);
3149
3150 /* When packet overflow occur return immediately. */
3151 if (pnt + psize > lim)
3152 return -1;
3153
3154 /* Fetch prefix from NLRI packet. */
3155 memcpy (&p.u.prefix, pnt, psize);
3156
3157 /* Check address. */
3158 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3159 {
3160 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3161 {
paulf5ba3872004-07-09 12:11:31 +00003162 /*
3163 * From draft-ietf-idr-bgp4-22, Section 6.3:
3164 * If a BGP router receives an UPDATE message with a
3165 * semantically incorrect NLRI field, in which a prefix is
3166 * semantically incorrect (eg. an unexpected multicast IP
3167 * address), it should ignore the prefix.
3168 */
paul718e3742002-12-13 20:15:29 +00003169 zlog (peer->log, LOG_ERR,
3170 "IPv4 unicast NLRI is multicast address %s",
3171 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003172
paul718e3742002-12-13 20:15:29 +00003173 return -1;
3174 }
3175 }
3176
3177#ifdef HAVE_IPV6
3178 /* Check address. */
3179 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3180 {
3181 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3182 {
3183 char buf[BUFSIZ];
3184
3185 zlog (peer->log, LOG_WARNING,
3186 "IPv6 link-local NLRI received %s ignore this NLRI",
3187 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3188
3189 continue;
3190 }
3191 }
3192#endif /* HAVE_IPV6 */
3193
3194 /* Normal process. */
3195 if (attr)
3196 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3197 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3198 else
3199 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3200 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3201
3202 /* Address family configuration mismatch or maximum-prefix count
3203 overflow. */
3204 if (ret < 0)
3205 return -1;
3206 }
3207
3208 /* Packet length consistency check. */
3209 if (pnt != lim)
3210 return -1;
3211
3212 return 0;
3213}
3214
3215/* NLRI encode syntax check routine. */
3216int
3217bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3218 bgp_size_t length)
3219{
3220 u_char *end;
3221 u_char prefixlen;
3222 int psize;
3223
3224 end = pnt + length;
3225
3226 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3227 syntactic validity. If the field is syntactically incorrect,
3228 then the Error Subcode is set to Invalid Network Field. */
3229
3230 while (pnt < end)
3231 {
3232 prefixlen = *pnt++;
3233
3234 /* Prefix length check. */
3235 if ((afi == AFI_IP && prefixlen > 32)
3236 || (afi == AFI_IP6 && prefixlen > 128))
3237 {
3238 plog_err (peer->log,
3239 "%s [Error] Update packet error (wrong prefix length %d)",
3240 peer->host, prefixlen);
3241 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3242 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3243 return -1;
3244 }
3245
3246 /* Packet size overflow check. */
3247 psize = PSIZE (prefixlen);
3248
3249 if (pnt + psize > end)
3250 {
3251 plog_err (peer->log,
3252 "%s [Error] Update packet error"
3253 " (prefix data overflow prefix size is %d)",
3254 peer->host, psize);
3255 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3256 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3257 return -1;
3258 }
3259
3260 pnt += psize;
3261 }
3262
3263 /* Packet length consistency check. */
3264 if (pnt != end)
3265 {
3266 plog_err (peer->log,
3267 "%s [Error] Update packet error"
3268 " (prefix length mismatch with total length)",
3269 peer->host);
3270 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3271 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3272 return -1;
3273 }
3274 return 0;
3275}
David Lamparter6b0655a2014-06-04 06:53:35 +02003276
paul94f2b392005-06-28 12:44:16 +00003277static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003278bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003279{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003280 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003281}
3282
paul94f2b392005-06-28 12:44:16 +00003283static void
paul718e3742002-12-13 20:15:29 +00003284bgp_static_free (struct bgp_static *bgp_static)
3285{
3286 if (bgp_static->rmap.name)
3287 free (bgp_static->rmap.name);
3288 XFREE (MTYPE_BGP_STATIC, bgp_static);
3289}
3290
paul94f2b392005-06-28 12:44:16 +00003291static void
paulfee0f4c2004-09-13 05:12:46 +00003292bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3293 struct prefix *p, afi_t afi, safi_t safi)
3294{
3295 struct bgp_node *rn;
3296 struct bgp_info *ri;
3297
3298 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3299
3300 /* Check selected route and self inserted route. */
3301 for (ri = rn->info; ri; ri = ri->next)
3302 if (ri->peer == bgp->peer_self
3303 && ri->type == ZEBRA_ROUTE_BGP
3304 && ri->sub_type == BGP_ROUTE_STATIC)
3305 break;
3306
3307 /* Withdraw static BGP route from routing table. */
3308 if (ri)
3309 {
paulfee0f4c2004-09-13 05:12:46 +00003310 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003311 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003312 }
3313
3314 /* Unlock bgp_node_lookup. */
3315 bgp_unlock_node (rn);
3316}
3317
paul94f2b392005-06-28 12:44:16 +00003318static void
paulfee0f4c2004-09-13 05:12:46 +00003319bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003320 struct bgp_static *bgp_static,
3321 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003322{
3323 struct bgp_node *rn;
3324 struct bgp_info *ri;
3325 struct bgp_info *new;
3326 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003327 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003328 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003329 struct attr new_attr;
3330 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003331 struct bgp *bgp;
3332 int ret;
3333 char buf[SU_ADDRSTRLEN];
3334
3335 bgp = rsclient->bgp;
3336
Paul Jakma06e110f2006-05-12 23:29:22 +00003337 assert (bgp_static);
3338 if (!bgp_static)
3339 return;
3340
paulfee0f4c2004-09-13 05:12:46 +00003341 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3342
3343 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003344
3345 attr.nexthop = bgp_static->igpnexthop;
3346 attr.med = bgp_static->igpmetric;
3347 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003348
Paul Jakma41367172007-08-06 15:24:51 +00003349 if (bgp_static->atomic)
3350 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3351
paulfee0f4c2004-09-13 05:12:46 +00003352 /* Apply network route-map for export to this rsclient. */
3353 if (bgp_static->rmap.name)
3354 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003355 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003356 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003357 info.attr = &attr_tmp;
3358
paulfee0f4c2004-09-13 05:12:46 +00003359 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3360 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3361
3362 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3363
3364 rsclient->rmap_type = 0;
3365
3366 if (ret == RMAP_DENYMATCH)
3367 {
3368 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003369 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003370
3371 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003372 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003373 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003374 bgp_attr_extra_free (&attr);
3375
paulfee0f4c2004-09-13 05:12:46 +00003376 return;
3377 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003378 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003379 }
3380 else
3381 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003382
3383 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003384 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003385
paulfee0f4c2004-09-13 05:12:46 +00003386 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3387
Paul Jakmafb982c22007-05-04 20:15:47 +00003388 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3389 == RMAP_DENY)
3390 {
paulfee0f4c2004-09-13 05:12:46 +00003391 /* This BGP update is filtered. Log the reason then update BGP entry. */
3392 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003393 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003394 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3395 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3396 p->prefixlen, rsclient->host);
3397
3398 bgp->peer_self->rmap_type = 0;
3399
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003400 bgp_attr_unintern (&attr_new);
3401 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003402 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003403
3404 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3405
3406 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003407 }
paulfee0f4c2004-09-13 05:12:46 +00003408
3409 bgp->peer_self->rmap_type = 0;
3410
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003411 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003412 attr_new = bgp_attr_intern (&new_attr);
3413
3414 for (ri = rn->info; ri; ri = ri->next)
3415 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3416 && ri->sub_type == BGP_ROUTE_STATIC)
3417 break;
3418
3419 if (ri)
3420 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003421 if (attrhash_cmp (ri->attr, attr_new) &&
3422 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003423 {
3424 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003425 bgp_attr_unintern (&attr_new);
3426 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003427 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003428 return;
3429 }
3430 else
3431 {
3432 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003433 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003434
3435 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003436 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3437 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003438 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003439 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003440 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003441
3442 /* Process change. */
3443 bgp_process (bgp, rn, afi, safi);
3444 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003445 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003446 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003447 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003448 }
paulfee0f4c2004-09-13 05:12:46 +00003449 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003450
paulfee0f4c2004-09-13 05:12:46 +00003451 /* Make new BGP info. */
3452 new = bgp_info_new ();
3453 new->type = ZEBRA_ROUTE_BGP;
3454 new->sub_type = BGP_ROUTE_STATIC;
3455 new->peer = bgp->peer_self;
3456 SET_FLAG (new->flags, BGP_INFO_VALID);
3457 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003458 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003459
3460 /* Register new BGP information. */
3461 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003462
3463 /* route_node_get lock */
3464 bgp_unlock_node (rn);
3465
paulfee0f4c2004-09-13 05:12:46 +00003466 /* Process change. */
3467 bgp_process (bgp, rn, afi, safi);
3468
3469 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003470 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003471 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003472}
3473
paul94f2b392005-06-28 12:44:16 +00003474static void
paulfee0f4c2004-09-13 05:12:46 +00003475bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003476 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3477{
3478 struct bgp_node *rn;
3479 struct bgp_info *ri;
3480 struct bgp_info *new;
3481 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003482 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003483 struct attr *attr_new;
3484 int ret;
3485
Paul Jakmadd8103a2006-05-12 23:27:30 +00003486 assert (bgp_static);
3487 if (!bgp_static)
3488 return;
3489
paulfee0f4c2004-09-13 05:12:46 +00003490 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003491
3492 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003493
3494 attr.nexthop = bgp_static->igpnexthop;
3495 attr.med = bgp_static->igpmetric;
3496 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003497
Paul Jakma41367172007-08-06 15:24:51 +00003498 if (bgp_static->atomic)
3499 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3500
paul718e3742002-12-13 20:15:29 +00003501 /* Apply route-map. */
3502 if (bgp_static->rmap.name)
3503 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003504 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003505 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003506 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003507
paulfee0f4c2004-09-13 05:12:46 +00003508 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3509
paul718e3742002-12-13 20:15:29 +00003510 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003511
paulfee0f4c2004-09-13 05:12:46 +00003512 bgp->peer_self->rmap_type = 0;
3513
paul718e3742002-12-13 20:15:29 +00003514 if (ret == RMAP_DENYMATCH)
3515 {
3516 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003517 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003518
3519 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003520 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003521 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003522 bgp_static_withdraw (bgp, p, afi, safi);
3523 return;
3524 }
paul286e1e72003-08-08 00:24:31 +00003525 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003526 }
paul286e1e72003-08-08 00:24:31 +00003527 else
3528 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003529
3530 for (ri = rn->info; ri; ri = ri->next)
3531 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3532 && ri->sub_type == BGP_ROUTE_STATIC)
3533 break;
3534
3535 if (ri)
3536 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003537 if (attrhash_cmp (ri->attr, attr_new) &&
3538 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003539 {
3540 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003541 bgp_attr_unintern (&attr_new);
3542 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003543 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003544 return;
3545 }
3546 else
3547 {
3548 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003549 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003550
3551 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003552 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3553 bgp_info_restore(rn, ri);
3554 else
3555 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003556 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003557 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003558 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003559
3560 /* Process change. */
3561 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3562 bgp_process (bgp, rn, afi, safi);
3563 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003564 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003565 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003566 return;
3567 }
3568 }
3569
3570 /* Make new BGP info. */
3571 new = bgp_info_new ();
3572 new->type = ZEBRA_ROUTE_BGP;
3573 new->sub_type = BGP_ROUTE_STATIC;
3574 new->peer = bgp->peer_self;
3575 SET_FLAG (new->flags, BGP_INFO_VALID);
3576 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003577 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003578
3579 /* Aggregate address increment. */
3580 bgp_aggregate_increment (bgp, p, new, afi, safi);
3581
3582 /* Register new BGP information. */
3583 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003584
3585 /* route_node_get lock */
3586 bgp_unlock_node (rn);
3587
paul718e3742002-12-13 20:15:29 +00003588 /* Process change. */
3589 bgp_process (bgp, rn, afi, safi);
3590
3591 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003592 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003593 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003594}
3595
3596void
paulfee0f4c2004-09-13 05:12:46 +00003597bgp_static_update (struct bgp *bgp, struct prefix *p,
3598 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3599{
3600 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003601 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003602
3603 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3604
paul1eb8ef22005-04-07 07:30:20 +00003605 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003606 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003607 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3608 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003609 }
3610}
3611
paul94f2b392005-06-28 12:44:16 +00003612static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003613bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3614 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003615{
3616 struct bgp_node *rn;
3617 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003618
paulfee0f4c2004-09-13 05:12:46 +00003619 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003620
3621 /* Make new BGP info. */
3622 new = bgp_info_new ();
3623 new->type = ZEBRA_ROUTE_BGP;
3624 new->sub_type = BGP_ROUTE_STATIC;
3625 new->peer = bgp->peer_self;
3626 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3627 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003628 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003629 new->extra = bgp_info_extra_new();
3630 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003631
3632 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003633 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003634
3635 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003636 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003637
paul200df112005-06-01 11:17:05 +00003638 /* route_node_get lock */
3639 bgp_unlock_node (rn);
3640
paul718e3742002-12-13 20:15:29 +00003641 /* Process change. */
3642 bgp_process (bgp, rn, afi, safi);
3643}
3644
3645void
3646bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3647 safi_t safi)
3648{
3649 struct bgp_node *rn;
3650 struct bgp_info *ri;
3651
paulfee0f4c2004-09-13 05:12:46 +00003652 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003653
3654 /* Check selected route and self inserted route. */
3655 for (ri = rn->info; ri; ri = ri->next)
3656 if (ri->peer == bgp->peer_self
3657 && ri->type == ZEBRA_ROUTE_BGP
3658 && ri->sub_type == BGP_ROUTE_STATIC)
3659 break;
3660
3661 /* Withdraw static BGP route from routing table. */
3662 if (ri)
3663 {
3664 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003665 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003666 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003667 }
3668
3669 /* Unlock bgp_node_lookup. */
3670 bgp_unlock_node (rn);
3671}
3672
3673void
paulfee0f4c2004-09-13 05:12:46 +00003674bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3675{
3676 struct bgp_static *bgp_static;
3677 struct bgp *bgp;
3678 struct bgp_node *rn;
3679 struct prefix *p;
3680
3681 bgp = rsclient->bgp;
3682
3683 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3684 if ((bgp_static = rn->info) != NULL)
3685 {
3686 p = &rn->p;
3687
3688 bgp_static_update_rsclient (rsclient, p, bgp_static,
3689 afi, safi);
3690 }
3691}
3692
paul94f2b392005-06-28 12:44:16 +00003693static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003694bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3695 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003696{
3697 struct bgp_node *rn;
3698 struct bgp_info *ri;
3699
paulfee0f4c2004-09-13 05:12:46 +00003700 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003701
3702 /* Check selected route and self inserted route. */
3703 for (ri = rn->info; ri; ri = ri->next)
3704 if (ri->peer == bgp->peer_self
3705 && ri->type == ZEBRA_ROUTE_BGP
3706 && ri->sub_type == BGP_ROUTE_STATIC)
3707 break;
3708
3709 /* Withdraw static BGP route from routing table. */
3710 if (ri)
3711 {
3712 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003713 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003714 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003715 }
3716
3717 /* Unlock bgp_node_lookup. */
3718 bgp_unlock_node (rn);
3719}
3720
3721/* Configure static BGP network. When user don't run zebra, static
3722 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003723static int
paulfd79ac92004-10-13 05:06:08 +00003724bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003725 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003726{
3727 int ret;
3728 struct prefix p;
3729 struct bgp_static *bgp_static;
3730 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003731 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003732
3733 /* Convert IP prefix string to struct prefix. */
3734 ret = str2prefix (ip_str, &p);
3735 if (! ret)
3736 {
3737 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3738 return CMD_WARNING;
3739 }
3740#ifdef HAVE_IPV6
3741 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3742 {
3743 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3744 VTY_NEWLINE);
3745 return CMD_WARNING;
3746 }
3747#endif /* HAVE_IPV6 */
3748
3749 apply_mask (&p);
3750
3751 /* Set BGP static route configuration. */
3752 rn = bgp_node_get (bgp->route[afi][safi], &p);
3753
3754 if (rn->info)
3755 {
3756 /* Configuration change. */
3757 bgp_static = rn->info;
3758
3759 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003760 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3761 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003762
paul718e3742002-12-13 20:15:29 +00003763 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003764
paul718e3742002-12-13 20:15:29 +00003765 if (rmap)
3766 {
3767 if (bgp_static->rmap.name)
3768 free (bgp_static->rmap.name);
3769 bgp_static->rmap.name = strdup (rmap);
3770 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3771 }
3772 else
3773 {
3774 if (bgp_static->rmap.name)
3775 free (bgp_static->rmap.name);
3776 bgp_static->rmap.name = NULL;
3777 bgp_static->rmap.map = NULL;
3778 bgp_static->valid = 0;
3779 }
3780 bgp_unlock_node (rn);
3781 }
3782 else
3783 {
3784 /* New configuration. */
3785 bgp_static = bgp_static_new ();
3786 bgp_static->backdoor = backdoor;
3787 bgp_static->valid = 0;
3788 bgp_static->igpmetric = 0;
3789 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003790
paul718e3742002-12-13 20:15:29 +00003791 if (rmap)
3792 {
3793 if (bgp_static->rmap.name)
3794 free (bgp_static->rmap.name);
3795 bgp_static->rmap.name = strdup (rmap);
3796 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3797 }
3798 rn->info = bgp_static;
3799 }
3800
3801 /* If BGP scan is not enabled, we should install this route here. */
3802 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3803 {
3804 bgp_static->valid = 1;
3805
3806 if (need_update)
3807 bgp_static_withdraw (bgp, &p, afi, safi);
3808
3809 if (! bgp_static->backdoor)
3810 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3811 }
3812
3813 return CMD_SUCCESS;
3814}
3815
3816/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003817static int
paulfd79ac92004-10-13 05:06:08 +00003818bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003819 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003820{
3821 int ret;
3822 struct prefix p;
3823 struct bgp_static *bgp_static;
3824 struct bgp_node *rn;
3825
3826 /* Convert IP prefix string to struct prefix. */
3827 ret = str2prefix (ip_str, &p);
3828 if (! ret)
3829 {
3830 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3831 return CMD_WARNING;
3832 }
3833#ifdef HAVE_IPV6
3834 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3835 {
3836 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3837 VTY_NEWLINE);
3838 return CMD_WARNING;
3839 }
3840#endif /* HAVE_IPV6 */
3841
3842 apply_mask (&p);
3843
3844 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3845 if (! rn)
3846 {
3847 vty_out (vty, "%% Can't find specified static route configuration.%s",
3848 VTY_NEWLINE);
3849 return CMD_WARNING;
3850 }
3851
3852 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003853
paul718e3742002-12-13 20:15:29 +00003854 /* Update BGP RIB. */
3855 if (! bgp_static->backdoor)
3856 bgp_static_withdraw (bgp, &p, afi, safi);
3857
3858 /* Clear configuration. */
3859 bgp_static_free (bgp_static);
3860 rn->info = NULL;
3861 bgp_unlock_node (rn);
3862 bgp_unlock_node (rn);
3863
3864 return CMD_SUCCESS;
3865}
3866
3867/* Called from bgp_delete(). Delete all static routes from the BGP
3868 instance. */
3869void
3870bgp_static_delete (struct bgp *bgp)
3871{
3872 afi_t afi;
3873 safi_t safi;
3874 struct bgp_node *rn;
3875 struct bgp_node *rm;
3876 struct bgp_table *table;
3877 struct bgp_static *bgp_static;
3878
3879 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3880 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3881 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3882 if (rn->info != NULL)
3883 {
3884 if (safi == SAFI_MPLS_VPN)
3885 {
3886 table = rn->info;
3887
3888 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3889 {
3890 bgp_static = rn->info;
3891 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3892 AFI_IP, SAFI_MPLS_VPN,
3893 (struct prefix_rd *)&rn->p,
3894 bgp_static->tag);
3895 bgp_static_free (bgp_static);
3896 rn->info = NULL;
3897 bgp_unlock_node (rn);
3898 }
3899 }
3900 else
3901 {
3902 bgp_static = rn->info;
3903 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3904 bgp_static_free (bgp_static);
3905 rn->info = NULL;
3906 bgp_unlock_node (rn);
3907 }
3908 }
3909}
3910
3911int
paulfd79ac92004-10-13 05:06:08 +00003912bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3913 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003914{
3915 int ret;
3916 struct prefix p;
3917 struct prefix_rd prd;
3918 struct bgp *bgp;
3919 struct bgp_node *prn;
3920 struct bgp_node *rn;
3921 struct bgp_table *table;
3922 struct bgp_static *bgp_static;
3923 u_char tag[3];
3924
3925 bgp = vty->index;
3926
3927 ret = str2prefix (ip_str, &p);
3928 if (! ret)
3929 {
3930 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3931 return CMD_WARNING;
3932 }
3933 apply_mask (&p);
3934
3935 ret = str2prefix_rd (rd_str, &prd);
3936 if (! ret)
3937 {
3938 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3939 return CMD_WARNING;
3940 }
3941
3942 ret = str2tag (tag_str, tag);
3943 if (! ret)
3944 {
3945 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3946 return CMD_WARNING;
3947 }
3948
3949 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3950 (struct prefix *)&prd);
3951 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003952 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003953 else
3954 bgp_unlock_node (prn);
3955 table = prn->info;
3956
3957 rn = bgp_node_get (table, &p);
3958
3959 if (rn->info)
3960 {
3961 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3962 bgp_unlock_node (rn);
3963 }
3964 else
3965 {
3966 /* New configuration. */
3967 bgp_static = bgp_static_new ();
3968 bgp_static->valid = 1;
3969 memcpy (bgp_static->tag, tag, 3);
3970 rn->info = bgp_static;
3971
3972 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3973 }
3974
3975 return CMD_SUCCESS;
3976}
3977
3978/* Configure static BGP network. */
3979int
paulfd79ac92004-10-13 05:06:08 +00003980bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3981 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003982{
3983 int ret;
3984 struct bgp *bgp;
3985 struct prefix p;
3986 struct prefix_rd prd;
3987 struct bgp_node *prn;
3988 struct bgp_node *rn;
3989 struct bgp_table *table;
3990 struct bgp_static *bgp_static;
3991 u_char tag[3];
3992
3993 bgp = vty->index;
3994
3995 /* Convert IP prefix string to struct prefix. */
3996 ret = str2prefix (ip_str, &p);
3997 if (! ret)
3998 {
3999 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4000 return CMD_WARNING;
4001 }
4002 apply_mask (&p);
4003
4004 ret = str2prefix_rd (rd_str, &prd);
4005 if (! ret)
4006 {
4007 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4008 return CMD_WARNING;
4009 }
4010
4011 ret = str2tag (tag_str, tag);
4012 if (! ret)
4013 {
4014 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4015 return CMD_WARNING;
4016 }
4017
4018 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4019 (struct prefix *)&prd);
4020 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00004021 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00004022 else
4023 bgp_unlock_node (prn);
4024 table = prn->info;
4025
4026 rn = bgp_node_lookup (table, &p);
4027
4028 if (rn)
4029 {
4030 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4031
4032 bgp_static = rn->info;
4033 bgp_static_free (bgp_static);
4034 rn->info = NULL;
4035 bgp_unlock_node (rn);
4036 bgp_unlock_node (rn);
4037 }
4038 else
4039 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4040
4041 return CMD_SUCCESS;
4042}
David Lamparter6b0655a2014-06-04 06:53:35 +02004043
paul718e3742002-12-13 20:15:29 +00004044DEFUN (bgp_network,
4045 bgp_network_cmd,
4046 "network A.B.C.D/M",
4047 "Specify a network to announce via BGP\n"
4048 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4049{
4050 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004051 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004052}
4053
4054DEFUN (bgp_network_route_map,
4055 bgp_network_route_map_cmd,
4056 "network A.B.C.D/M route-map WORD",
4057 "Specify a network to announce via BGP\n"
4058 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4059 "Route-map to modify the attributes\n"
4060 "Name of the route map\n")
4061{
4062 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004063 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004064}
4065
4066DEFUN (bgp_network_backdoor,
4067 bgp_network_backdoor_cmd,
4068 "network A.B.C.D/M backdoor",
4069 "Specify a network to announce via BGP\n"
4070 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4071 "Specify a BGP backdoor route\n")
4072{
Paul Jakma41367172007-08-06 15:24:51 +00004073 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004074 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004075}
4076
4077DEFUN (bgp_network_mask,
4078 bgp_network_mask_cmd,
4079 "network A.B.C.D mask A.B.C.D",
4080 "Specify a network to announce via BGP\n"
4081 "Network number\n"
4082 "Network mask\n"
4083 "Network mask\n")
4084{
4085 int ret;
4086 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004087
paul718e3742002-12-13 20:15:29 +00004088 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4089 if (! ret)
4090 {
4091 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4092 return CMD_WARNING;
4093 }
4094
4095 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004096 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004097}
4098
4099DEFUN (bgp_network_mask_route_map,
4100 bgp_network_mask_route_map_cmd,
4101 "network A.B.C.D mask A.B.C.D route-map WORD",
4102 "Specify a network to announce via BGP\n"
4103 "Network number\n"
4104 "Network mask\n"
4105 "Network mask\n"
4106 "Route-map to modify the attributes\n"
4107 "Name of the route map\n")
4108{
4109 int ret;
4110 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004111
paul718e3742002-12-13 20:15:29 +00004112 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4113 if (! ret)
4114 {
4115 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4116 return CMD_WARNING;
4117 }
4118
4119 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004120 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004121}
4122
4123DEFUN (bgp_network_mask_backdoor,
4124 bgp_network_mask_backdoor_cmd,
4125 "network A.B.C.D mask A.B.C.D backdoor",
4126 "Specify a network to announce via BGP\n"
4127 "Network number\n"
4128 "Network mask\n"
4129 "Network mask\n"
4130 "Specify a BGP backdoor route\n")
4131{
4132 int ret;
4133 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004134
paul718e3742002-12-13 20:15:29 +00004135 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4136 if (! ret)
4137 {
4138 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4139 return CMD_WARNING;
4140 }
4141
Paul Jakma41367172007-08-06 15:24:51 +00004142 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004143 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004144}
4145
4146DEFUN (bgp_network_mask_natural,
4147 bgp_network_mask_natural_cmd,
4148 "network A.B.C.D",
4149 "Specify a network to announce via BGP\n"
4150 "Network number\n")
4151{
4152 int ret;
4153 char prefix_str[BUFSIZ];
4154
4155 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4156 if (! ret)
4157 {
4158 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4159 return CMD_WARNING;
4160 }
4161
4162 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004163 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004164}
4165
4166DEFUN (bgp_network_mask_natural_route_map,
4167 bgp_network_mask_natural_route_map_cmd,
4168 "network A.B.C.D route-map WORD",
4169 "Specify a network to announce via BGP\n"
4170 "Network number\n"
4171 "Route-map to modify the attributes\n"
4172 "Name of the route map\n")
4173{
4174 int ret;
4175 char prefix_str[BUFSIZ];
4176
4177 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4178 if (! ret)
4179 {
4180 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4181 return CMD_WARNING;
4182 }
4183
4184 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004185 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004186}
4187
4188DEFUN (bgp_network_mask_natural_backdoor,
4189 bgp_network_mask_natural_backdoor_cmd,
4190 "network A.B.C.D backdoor",
4191 "Specify a network to announce via BGP\n"
4192 "Network number\n"
4193 "Specify a BGP backdoor route\n")
4194{
4195 int ret;
4196 char prefix_str[BUFSIZ];
4197
4198 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4199 if (! ret)
4200 {
4201 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4202 return CMD_WARNING;
4203 }
4204
Paul Jakma41367172007-08-06 15:24:51 +00004205 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004206 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004207}
4208
4209DEFUN (no_bgp_network,
4210 no_bgp_network_cmd,
4211 "no network A.B.C.D/M",
4212 NO_STR
4213 "Specify a network to announce via BGP\n"
4214 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4215{
4216 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4217 bgp_node_safi (vty));
4218}
4219
4220ALIAS (no_bgp_network,
4221 no_bgp_network_route_map_cmd,
4222 "no network A.B.C.D/M route-map WORD",
4223 NO_STR
4224 "Specify a network to announce via BGP\n"
4225 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4226 "Route-map to modify the attributes\n"
4227 "Name of the route map\n")
4228
4229ALIAS (no_bgp_network,
4230 no_bgp_network_backdoor_cmd,
4231 "no network A.B.C.D/M backdoor",
4232 NO_STR
4233 "Specify a network to announce via BGP\n"
4234 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4235 "Specify a BGP backdoor route\n")
4236
4237DEFUN (no_bgp_network_mask,
4238 no_bgp_network_mask_cmd,
4239 "no network A.B.C.D mask A.B.C.D",
4240 NO_STR
4241 "Specify a network to announce via BGP\n"
4242 "Network number\n"
4243 "Network mask\n"
4244 "Network mask\n")
4245{
4246 int ret;
4247 char prefix_str[BUFSIZ];
4248
4249 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4250 if (! ret)
4251 {
4252 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4253 return CMD_WARNING;
4254 }
4255
4256 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4257 bgp_node_safi (vty));
4258}
4259
4260ALIAS (no_bgp_network_mask,
4261 no_bgp_network_mask_route_map_cmd,
4262 "no network A.B.C.D mask A.B.C.D route-map WORD",
4263 NO_STR
4264 "Specify a network to announce via BGP\n"
4265 "Network number\n"
4266 "Network mask\n"
4267 "Network mask\n"
4268 "Route-map to modify the attributes\n"
4269 "Name of the route map\n")
4270
4271ALIAS (no_bgp_network_mask,
4272 no_bgp_network_mask_backdoor_cmd,
4273 "no network A.B.C.D mask A.B.C.D backdoor",
4274 NO_STR
4275 "Specify a network to announce via BGP\n"
4276 "Network number\n"
4277 "Network mask\n"
4278 "Network mask\n"
4279 "Specify a BGP backdoor route\n")
4280
4281DEFUN (no_bgp_network_mask_natural,
4282 no_bgp_network_mask_natural_cmd,
4283 "no network A.B.C.D",
4284 NO_STR
4285 "Specify a network to announce via BGP\n"
4286 "Network number\n")
4287{
4288 int ret;
4289 char prefix_str[BUFSIZ];
4290
4291 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4292 if (! ret)
4293 {
4294 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4295 return CMD_WARNING;
4296 }
4297
4298 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4299 bgp_node_safi (vty));
4300}
4301
4302ALIAS (no_bgp_network_mask_natural,
4303 no_bgp_network_mask_natural_route_map_cmd,
4304 "no network A.B.C.D route-map WORD",
4305 NO_STR
4306 "Specify a network to announce via BGP\n"
4307 "Network number\n"
4308 "Route-map to modify the attributes\n"
4309 "Name of the route map\n")
4310
4311ALIAS (no_bgp_network_mask_natural,
4312 no_bgp_network_mask_natural_backdoor_cmd,
4313 "no network A.B.C.D backdoor",
4314 NO_STR
4315 "Specify a network to announce via BGP\n"
4316 "Network number\n"
4317 "Specify a BGP backdoor route\n")
4318
4319#ifdef HAVE_IPV6
4320DEFUN (ipv6_bgp_network,
4321 ipv6_bgp_network_cmd,
4322 "network X:X::X:X/M",
4323 "Specify a network to announce via BGP\n"
4324 "IPv6 prefix <network>/<length>\n")
4325{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304326 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004327 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004328}
4329
4330DEFUN (ipv6_bgp_network_route_map,
4331 ipv6_bgp_network_route_map_cmd,
4332 "network X:X::X:X/M route-map WORD",
4333 "Specify a network to announce via BGP\n"
4334 "IPv6 prefix <network>/<length>\n"
4335 "Route-map to modify the attributes\n"
4336 "Name of the route map\n")
4337{
4338 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004339 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004340}
4341
4342DEFUN (no_ipv6_bgp_network,
4343 no_ipv6_bgp_network_cmd,
4344 "no network X:X::X:X/M",
4345 NO_STR
4346 "Specify a network to announce via BGP\n"
4347 "IPv6 prefix <network>/<length>\n")
4348{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304349 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004350}
4351
4352ALIAS (no_ipv6_bgp_network,
4353 no_ipv6_bgp_network_route_map_cmd,
4354 "no network X:X::X:X/M route-map WORD",
4355 NO_STR
4356 "Specify a network to announce via BGP\n"
4357 "IPv6 prefix <network>/<length>\n"
4358 "Route-map to modify the attributes\n"
4359 "Name of the route map\n")
4360
4361ALIAS (ipv6_bgp_network,
4362 old_ipv6_bgp_network_cmd,
4363 "ipv6 bgp network X:X::X:X/M",
4364 IPV6_STR
4365 BGP_STR
4366 "Specify a network to announce via BGP\n"
4367 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4368
4369ALIAS (no_ipv6_bgp_network,
4370 old_no_ipv6_bgp_network_cmd,
4371 "no ipv6 bgp network X:X::X:X/M",
4372 NO_STR
4373 IPV6_STR
4374 BGP_STR
4375 "Specify a network to announce via BGP\n"
4376 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4377#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004378
4379/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4380ALIAS_DEPRECATED (bgp_network,
4381 bgp_network_ttl_cmd,
4382 "network A.B.C.D/M pathlimit <0-255>",
4383 "Specify a network to announce via BGP\n"
4384 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4385 "AS-Path hopcount limit attribute\n"
4386 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4387ALIAS_DEPRECATED (bgp_network_backdoor,
4388 bgp_network_backdoor_ttl_cmd,
4389 "network A.B.C.D/M backdoor pathlimit <0-255>",
4390 "Specify a network to announce via BGP\n"
4391 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4392 "Specify a BGP backdoor route\n"
4393 "AS-Path hopcount limit attribute\n"
4394 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4395ALIAS_DEPRECATED (bgp_network_mask,
4396 bgp_network_mask_ttl_cmd,
4397 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4398 "Specify a network to announce via BGP\n"
4399 "Network number\n"
4400 "Network mask\n"
4401 "Network mask\n"
4402 "AS-Path hopcount limit attribute\n"
4403 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4404ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4405 bgp_network_mask_backdoor_ttl_cmd,
4406 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4407 "Specify a network to announce via BGP\n"
4408 "Network number\n"
4409 "Network mask\n"
4410 "Network mask\n"
4411 "Specify a BGP backdoor route\n"
4412 "AS-Path hopcount limit attribute\n"
4413 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4414ALIAS_DEPRECATED (bgp_network_mask_natural,
4415 bgp_network_mask_natural_ttl_cmd,
4416 "network A.B.C.D pathlimit <0-255>",
4417 "Specify a network to announce via BGP\n"
4418 "Network number\n"
4419 "AS-Path hopcount limit attribute\n"
4420 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4421ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4422 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004423 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004424 "Specify a network to announce via BGP\n"
4425 "Network number\n"
4426 "Specify a BGP backdoor route\n"
4427 "AS-Path hopcount limit attribute\n"
4428 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4429ALIAS_DEPRECATED (no_bgp_network,
4430 no_bgp_network_ttl_cmd,
4431 "no network A.B.C.D/M pathlimit <0-255>",
4432 NO_STR
4433 "Specify a network to announce via BGP\n"
4434 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4435 "AS-Path hopcount limit attribute\n"
4436 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4437ALIAS_DEPRECATED (no_bgp_network,
4438 no_bgp_network_backdoor_ttl_cmd,
4439 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4440 NO_STR
4441 "Specify a network to announce via BGP\n"
4442 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4443 "Specify a BGP backdoor route\n"
4444 "AS-Path hopcount limit attribute\n"
4445 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4446ALIAS_DEPRECATED (no_bgp_network,
4447 no_bgp_network_mask_ttl_cmd,
4448 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4449 NO_STR
4450 "Specify a network to announce via BGP\n"
4451 "Network number\n"
4452 "Network mask\n"
4453 "Network mask\n"
4454 "AS-Path hopcount limit attribute\n"
4455 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4456ALIAS_DEPRECATED (no_bgp_network_mask,
4457 no_bgp_network_mask_backdoor_ttl_cmd,
4458 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4459 NO_STR
4460 "Specify a network to announce via BGP\n"
4461 "Network number\n"
4462 "Network mask\n"
4463 "Network mask\n"
4464 "Specify a BGP backdoor route\n"
4465 "AS-Path hopcount limit attribute\n"
4466 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4467ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4468 no_bgp_network_mask_natural_ttl_cmd,
4469 "no network A.B.C.D pathlimit <0-255>",
4470 NO_STR
4471 "Specify a network to announce via BGP\n"
4472 "Network number\n"
4473 "AS-Path hopcount limit attribute\n"
4474 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4475ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4476 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4477 "no network A.B.C.D backdoor pathlimit <0-255>",
4478 NO_STR
4479 "Specify a network to announce via BGP\n"
4480 "Network number\n"
4481 "Specify a BGP backdoor route\n"
4482 "AS-Path hopcount limit attribute\n"
4483 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004484#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004485ALIAS_DEPRECATED (ipv6_bgp_network,
4486 ipv6_bgp_network_ttl_cmd,
4487 "network X:X::X:X/M pathlimit <0-255>",
4488 "Specify a network to announce via BGP\n"
4489 "IPv6 prefix <network>/<length>\n"
4490 "AS-Path hopcount limit attribute\n"
4491 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4492ALIAS_DEPRECATED (no_ipv6_bgp_network,
4493 no_ipv6_bgp_network_ttl_cmd,
4494 "no network X:X::X:X/M pathlimit <0-255>",
4495 NO_STR
4496 "Specify a network to announce via BGP\n"
4497 "IPv6 prefix <network>/<length>\n"
4498 "AS-Path hopcount limit attribute\n"
4499 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004500#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02004501
paul718e3742002-12-13 20:15:29 +00004502/* Aggreagete address:
4503
4504 advertise-map Set condition to advertise attribute
4505 as-set Generate AS set path information
4506 attribute-map Set attributes of aggregate
4507 route-map Set parameters of aggregate
4508 summary-only Filter more specific routes from updates
4509 suppress-map Conditionally filter more specific routes from updates
4510 <cr>
4511 */
4512struct bgp_aggregate
4513{
4514 /* Summary-only flag. */
4515 u_char summary_only;
4516
4517 /* AS set generation. */
4518 u_char as_set;
4519
4520 /* Route-map for aggregated route. */
4521 struct route_map *map;
4522
4523 /* Suppress-count. */
4524 unsigned long count;
4525
4526 /* SAFI configuration. */
4527 safi_t safi;
4528};
4529
paul94f2b392005-06-28 12:44:16 +00004530static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004531bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004532{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004533 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004534}
4535
paul94f2b392005-06-28 12:44:16 +00004536static void
paul718e3742002-12-13 20:15:29 +00004537bgp_aggregate_free (struct bgp_aggregate *aggregate)
4538{
4539 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4540}
4541
paul94f2b392005-06-28 12:44:16 +00004542static void
paul718e3742002-12-13 20:15:29 +00004543bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4544 afi_t afi, safi_t safi, struct bgp_info *del,
4545 struct bgp_aggregate *aggregate)
4546{
4547 struct bgp_table *table;
4548 struct bgp_node *top;
4549 struct bgp_node *rn;
4550 u_char origin;
4551 struct aspath *aspath = NULL;
4552 struct aspath *asmerge = NULL;
4553 struct community *community = NULL;
4554 struct community *commerge = NULL;
paul718e3742002-12-13 20:15:29 +00004555 struct bgp_info *ri;
4556 struct bgp_info *new;
4557 int first = 1;
4558 unsigned long match = 0;
4559
paul718e3742002-12-13 20:15:29 +00004560 /* ORIGIN attribute: If at least one route among routes that are
4561 aggregated has ORIGIN with the value INCOMPLETE, then the
4562 aggregated route must have the ORIGIN attribute with the value
4563 INCOMPLETE. Otherwise, if at least one route among routes that
4564 are aggregated has ORIGIN with the value EGP, then the aggregated
4565 route must have the origin attribute with the value EGP. In all
4566 other case the value of the ORIGIN attribute of the aggregated
4567 route is INTERNAL. */
4568 origin = BGP_ORIGIN_IGP;
4569
4570 table = bgp->rib[afi][safi];
4571
4572 top = bgp_node_get (table, p);
4573 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4574 if (rn->p.prefixlen > p->prefixlen)
4575 {
4576 match = 0;
4577
4578 for (ri = rn->info; ri; ri = ri->next)
4579 {
4580 if (BGP_INFO_HOLDDOWN (ri))
4581 continue;
4582
4583 if (del && ri == del)
4584 continue;
4585
4586 if (! rinew && first)
Paul Jakma7aa9dce2014-09-19 14:42:23 +01004587 first = 0;
paul718e3742002-12-13 20:15:29 +00004588
4589#ifdef AGGREGATE_NEXTHOP_CHECK
4590 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4591 || ri->attr->med != med)
4592 {
4593 if (aspath)
4594 aspath_free (aspath);
4595 if (community)
4596 community_free (community);
4597 bgp_unlock_node (rn);
4598 bgp_unlock_node (top);
4599 return;
4600 }
4601#endif /* AGGREGATE_NEXTHOP_CHECK */
4602
4603 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4604 {
4605 if (aggregate->summary_only)
4606 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004607 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004608 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004609 match++;
4610 }
4611
4612 aggregate->count++;
4613
4614 if (aggregate->as_set)
4615 {
4616 if (origin < ri->attr->origin)
4617 origin = ri->attr->origin;
4618
4619 if (aspath)
4620 {
4621 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4622 aspath_free (aspath);
4623 aspath = asmerge;
4624 }
4625 else
4626 aspath = aspath_dup (ri->attr->aspath);
4627
4628 if (ri->attr->community)
4629 {
4630 if (community)
4631 {
4632 commerge = community_merge (community,
4633 ri->attr->community);
4634 community = community_uniq_sort (commerge);
4635 community_free (commerge);
4636 }
4637 else
4638 community = community_dup (ri->attr->community);
4639 }
4640 }
4641 }
4642 }
4643 if (match)
4644 bgp_process (bgp, rn, afi, safi);
4645 }
4646 bgp_unlock_node (top);
4647
4648 if (rinew)
4649 {
4650 aggregate->count++;
4651
4652 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004653 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004654
4655 if (aggregate->as_set)
4656 {
4657 if (origin < rinew->attr->origin)
4658 origin = rinew->attr->origin;
4659
4660 if (aspath)
4661 {
4662 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4663 aspath_free (aspath);
4664 aspath = asmerge;
4665 }
4666 else
4667 aspath = aspath_dup (rinew->attr->aspath);
4668
4669 if (rinew->attr->community)
4670 {
4671 if (community)
4672 {
4673 commerge = community_merge (community,
4674 rinew->attr->community);
4675 community = community_uniq_sort (commerge);
4676 community_free (commerge);
4677 }
4678 else
4679 community = community_dup (rinew->attr->community);
4680 }
4681 }
4682 }
4683
4684 if (aggregate->count > 0)
4685 {
4686 rn = bgp_node_get (table, p);
4687 new = bgp_info_new ();
4688 new->type = ZEBRA_ROUTE_BGP;
4689 new->sub_type = BGP_ROUTE_AGGREGATE;
4690 new->peer = bgp->peer_self;
4691 SET_FLAG (new->flags, BGP_INFO_VALID);
4692 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004693 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004694
4695 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004696 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004697 bgp_process (bgp, rn, afi, safi);
4698 }
4699 else
4700 {
4701 if (aspath)
4702 aspath_free (aspath);
4703 if (community)
4704 community_free (community);
4705 }
4706}
4707
4708void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4709 struct bgp_aggregate *);
4710
4711void
4712bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4713 struct bgp_info *ri, afi_t afi, safi_t safi)
4714{
4715 struct bgp_node *child;
4716 struct bgp_node *rn;
4717 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004718 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004719
4720 /* MPLS-VPN aggregation is not yet supported. */
4721 if (safi == SAFI_MPLS_VPN)
4722 return;
4723
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004724 table = bgp->aggregate[afi][safi];
4725
4726 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004727 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004728 return;
4729
paul718e3742002-12-13 20:15:29 +00004730 if (p->prefixlen == 0)
4731 return;
4732
4733 if (BGP_INFO_HOLDDOWN (ri))
4734 return;
4735
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004736 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004737
4738 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004739 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004740 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4741 {
4742 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004743 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004744 }
4745 bgp_unlock_node (child);
4746}
4747
4748void
4749bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4750 struct bgp_info *del, afi_t afi, safi_t safi)
4751{
4752 struct bgp_node *child;
4753 struct bgp_node *rn;
4754 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004755 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004756
4757 /* MPLS-VPN aggregation is not yet supported. */
4758 if (safi == SAFI_MPLS_VPN)
4759 return;
4760
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004761 table = bgp->aggregate[afi][safi];
4762
4763 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004764 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004765 return;
4766
paul718e3742002-12-13 20:15:29 +00004767 if (p->prefixlen == 0)
4768 return;
4769
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004770 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004771
4772 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004773 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004774 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4775 {
4776 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004777 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004778 }
4779 bgp_unlock_node (child);
4780}
4781
paul94f2b392005-06-28 12:44:16 +00004782static void
paul718e3742002-12-13 20:15:29 +00004783bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4784 struct bgp_aggregate *aggregate)
4785{
4786 struct bgp_table *table;
4787 struct bgp_node *top;
4788 struct bgp_node *rn;
4789 struct bgp_info *new;
4790 struct bgp_info *ri;
4791 unsigned long match;
4792 u_char origin = BGP_ORIGIN_IGP;
4793 struct aspath *aspath = NULL;
4794 struct aspath *asmerge = NULL;
4795 struct community *community = NULL;
4796 struct community *commerge = NULL;
4797
4798 table = bgp->rib[afi][safi];
4799
4800 /* Sanity check. */
4801 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4802 return;
4803 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4804 return;
4805
4806 /* If routes exists below this node, generate aggregate routes. */
4807 top = bgp_node_get (table, p);
4808 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4809 if (rn->p.prefixlen > p->prefixlen)
4810 {
4811 match = 0;
4812
4813 for (ri = rn->info; ri; ri = ri->next)
4814 {
4815 if (BGP_INFO_HOLDDOWN (ri))
4816 continue;
4817
4818 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4819 {
4820 /* summary-only aggregate route suppress aggregated
4821 route announcement. */
4822 if (aggregate->summary_only)
4823 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004824 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004825 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004826 match++;
4827 }
4828 /* as-set aggregate route generate origin, as path,
4829 community aggregation. */
4830 if (aggregate->as_set)
4831 {
4832 if (origin < ri->attr->origin)
4833 origin = ri->attr->origin;
4834
4835 if (aspath)
4836 {
4837 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4838 aspath_free (aspath);
4839 aspath = asmerge;
4840 }
4841 else
4842 aspath = aspath_dup (ri->attr->aspath);
4843
4844 if (ri->attr->community)
4845 {
4846 if (community)
4847 {
4848 commerge = community_merge (community,
4849 ri->attr->community);
4850 community = community_uniq_sort (commerge);
4851 community_free (commerge);
4852 }
4853 else
4854 community = community_dup (ri->attr->community);
4855 }
4856 }
4857 aggregate->count++;
4858 }
4859 }
4860
4861 /* If this node is suppressed, process the change. */
4862 if (match)
4863 bgp_process (bgp, rn, afi, safi);
4864 }
4865 bgp_unlock_node (top);
4866
4867 /* Add aggregate route to BGP table. */
4868 if (aggregate->count)
4869 {
4870 rn = bgp_node_get (table, p);
4871
4872 new = bgp_info_new ();
4873 new->type = ZEBRA_ROUTE_BGP;
4874 new->sub_type = BGP_ROUTE_AGGREGATE;
4875 new->peer = bgp->peer_self;
4876 SET_FLAG (new->flags, BGP_INFO_VALID);
4877 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004878 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004879
4880 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004881 bgp_unlock_node (rn);
4882
paul718e3742002-12-13 20:15:29 +00004883 /* Process change. */
4884 bgp_process (bgp, rn, afi, safi);
4885 }
4886}
4887
4888void
4889bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4890 safi_t safi, struct bgp_aggregate *aggregate)
4891{
4892 struct bgp_table *table;
4893 struct bgp_node *top;
4894 struct bgp_node *rn;
4895 struct bgp_info *ri;
4896 unsigned long match;
4897
4898 table = bgp->rib[afi][safi];
4899
4900 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4901 return;
4902 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4903 return;
4904
4905 /* If routes exists below this node, generate aggregate routes. */
4906 top = bgp_node_get (table, p);
4907 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4908 if (rn->p.prefixlen > p->prefixlen)
4909 {
4910 match = 0;
4911
4912 for (ri = rn->info; ri; ri = ri->next)
4913 {
4914 if (BGP_INFO_HOLDDOWN (ri))
4915 continue;
4916
4917 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4918 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004919 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004920 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004921 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004922
Paul Jakmafb982c22007-05-04 20:15:47 +00004923 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004924 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004925 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004926 match++;
4927 }
4928 }
4929 aggregate->count--;
4930 }
4931 }
4932
Paul Jakmafb982c22007-05-04 20:15:47 +00004933 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004934 if (match)
4935 bgp_process (bgp, rn, afi, safi);
4936 }
4937 bgp_unlock_node (top);
4938
4939 /* Delete aggregate route from BGP table. */
4940 rn = bgp_node_get (table, p);
4941
4942 for (ri = rn->info; ri; ri = ri->next)
4943 if (ri->peer == bgp->peer_self
4944 && ri->type == ZEBRA_ROUTE_BGP
4945 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4946 break;
4947
4948 /* Withdraw static BGP route from routing table. */
4949 if (ri)
4950 {
paul718e3742002-12-13 20:15:29 +00004951 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004952 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004953 }
4954
4955 /* Unlock bgp_node_lookup. */
4956 bgp_unlock_node (rn);
4957}
4958
4959/* Aggregate route attribute. */
4960#define AGGREGATE_SUMMARY_ONLY 1
4961#define AGGREGATE_AS_SET 1
4962
paul94f2b392005-06-28 12:44:16 +00004963static int
Robert Baysf6269b42010-08-05 10:26:28 -07004964bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4965 afi_t afi, safi_t safi)
4966{
4967 int ret;
4968 struct prefix p;
4969 struct bgp_node *rn;
4970 struct bgp *bgp;
4971 struct bgp_aggregate *aggregate;
4972
4973 /* Convert string to prefix structure. */
4974 ret = str2prefix (prefix_str, &p);
4975 if (!ret)
4976 {
4977 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4978 return CMD_WARNING;
4979 }
4980 apply_mask (&p);
4981
4982 /* Get BGP structure. */
4983 bgp = vty->index;
4984
4985 /* Old configuration check. */
4986 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4987 if (! rn)
4988 {
4989 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4990 VTY_NEWLINE);
4991 return CMD_WARNING;
4992 }
4993
4994 aggregate = rn->info;
4995 if (aggregate->safi & SAFI_UNICAST)
4996 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4997 if (aggregate->safi & SAFI_MULTICAST)
4998 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4999
5000 /* Unlock aggregate address configuration. */
5001 rn->info = NULL;
5002 bgp_aggregate_free (aggregate);
5003 bgp_unlock_node (rn);
5004 bgp_unlock_node (rn);
5005
5006 return CMD_SUCCESS;
5007}
5008
5009static int
5010bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00005011 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00005012 u_char summary_only, u_char as_set)
5013{
5014 int ret;
5015 struct prefix p;
5016 struct bgp_node *rn;
5017 struct bgp *bgp;
5018 struct bgp_aggregate *aggregate;
5019
5020 /* Convert string to prefix structure. */
5021 ret = str2prefix (prefix_str, &p);
5022 if (!ret)
5023 {
5024 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5025 return CMD_WARNING;
5026 }
5027 apply_mask (&p);
5028
5029 /* Get BGP structure. */
5030 bgp = vty->index;
5031
5032 /* Old configuration check. */
5033 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5034
5035 if (rn->info)
5036 {
5037 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005038 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005039 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5040 if (ret)
5041 {
Robert Bays368473f2010-08-05 10:26:29 -07005042 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5043 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005044 return CMD_WARNING;
5045 }
paul718e3742002-12-13 20:15:29 +00005046 }
5047
5048 /* Make aggregate address structure. */
5049 aggregate = bgp_aggregate_new ();
5050 aggregate->summary_only = summary_only;
5051 aggregate->as_set = as_set;
5052 aggregate->safi = safi;
5053 rn->info = aggregate;
5054
5055 /* Aggregate address insert into BGP routing table. */
5056 if (safi & SAFI_UNICAST)
5057 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5058 if (safi & SAFI_MULTICAST)
5059 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5060
5061 return CMD_SUCCESS;
5062}
5063
paul718e3742002-12-13 20:15:29 +00005064DEFUN (aggregate_address,
5065 aggregate_address_cmd,
5066 "aggregate-address A.B.C.D/M",
5067 "Configure BGP aggregate entries\n"
5068 "Aggregate prefix\n")
5069{
5070 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5071}
5072
5073DEFUN (aggregate_address_mask,
5074 aggregate_address_mask_cmd,
5075 "aggregate-address A.B.C.D A.B.C.D",
5076 "Configure BGP aggregate entries\n"
5077 "Aggregate address\n"
5078 "Aggregate mask\n")
5079{
5080 int ret;
5081 char prefix_str[BUFSIZ];
5082
5083 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5084
5085 if (! ret)
5086 {
5087 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5088 return CMD_WARNING;
5089 }
5090
5091 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5092 0, 0);
5093}
5094
5095DEFUN (aggregate_address_summary_only,
5096 aggregate_address_summary_only_cmd,
5097 "aggregate-address A.B.C.D/M summary-only",
5098 "Configure BGP aggregate entries\n"
5099 "Aggregate prefix\n"
5100 "Filter more specific routes from updates\n")
5101{
5102 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5103 AGGREGATE_SUMMARY_ONLY, 0);
5104}
5105
5106DEFUN (aggregate_address_mask_summary_only,
5107 aggregate_address_mask_summary_only_cmd,
5108 "aggregate-address A.B.C.D A.B.C.D summary-only",
5109 "Configure BGP aggregate entries\n"
5110 "Aggregate address\n"
5111 "Aggregate mask\n"
5112 "Filter more specific routes from updates\n")
5113{
5114 int ret;
5115 char prefix_str[BUFSIZ];
5116
5117 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5118
5119 if (! ret)
5120 {
5121 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5122 return CMD_WARNING;
5123 }
5124
5125 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5126 AGGREGATE_SUMMARY_ONLY, 0);
5127}
5128
5129DEFUN (aggregate_address_as_set,
5130 aggregate_address_as_set_cmd,
5131 "aggregate-address A.B.C.D/M as-set",
5132 "Configure BGP aggregate entries\n"
5133 "Aggregate prefix\n"
5134 "Generate AS set path information\n")
5135{
5136 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5137 0, AGGREGATE_AS_SET);
5138}
5139
5140DEFUN (aggregate_address_mask_as_set,
5141 aggregate_address_mask_as_set_cmd,
5142 "aggregate-address A.B.C.D A.B.C.D as-set",
5143 "Configure BGP aggregate entries\n"
5144 "Aggregate address\n"
5145 "Aggregate mask\n"
5146 "Generate AS set path information\n")
5147{
5148 int ret;
5149 char prefix_str[BUFSIZ];
5150
5151 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5152
5153 if (! ret)
5154 {
5155 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5156 return CMD_WARNING;
5157 }
5158
5159 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5160 0, AGGREGATE_AS_SET);
5161}
5162
5163
5164DEFUN (aggregate_address_as_set_summary,
5165 aggregate_address_as_set_summary_cmd,
5166 "aggregate-address A.B.C.D/M as-set summary-only",
5167 "Configure BGP aggregate entries\n"
5168 "Aggregate prefix\n"
5169 "Generate AS set path information\n"
5170 "Filter more specific routes from updates\n")
5171{
5172 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5173 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5174}
5175
5176ALIAS (aggregate_address_as_set_summary,
5177 aggregate_address_summary_as_set_cmd,
5178 "aggregate-address A.B.C.D/M summary-only as-set",
5179 "Configure BGP aggregate entries\n"
5180 "Aggregate prefix\n"
5181 "Filter more specific routes from updates\n"
5182 "Generate AS set path information\n")
5183
5184DEFUN (aggregate_address_mask_as_set_summary,
5185 aggregate_address_mask_as_set_summary_cmd,
5186 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5187 "Configure BGP aggregate entries\n"
5188 "Aggregate address\n"
5189 "Aggregate mask\n"
5190 "Generate AS set path information\n"
5191 "Filter more specific routes from updates\n")
5192{
5193 int ret;
5194 char prefix_str[BUFSIZ];
5195
5196 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5197
5198 if (! ret)
5199 {
5200 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5201 return CMD_WARNING;
5202 }
5203
5204 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5205 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5206}
5207
5208ALIAS (aggregate_address_mask_as_set_summary,
5209 aggregate_address_mask_summary_as_set_cmd,
5210 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5211 "Configure BGP aggregate entries\n"
5212 "Aggregate address\n"
5213 "Aggregate mask\n"
5214 "Filter more specific routes from updates\n"
5215 "Generate AS set path information\n")
5216
5217DEFUN (no_aggregate_address,
5218 no_aggregate_address_cmd,
5219 "no aggregate-address A.B.C.D/M",
5220 NO_STR
5221 "Configure BGP aggregate entries\n"
5222 "Aggregate prefix\n")
5223{
5224 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5225}
5226
5227ALIAS (no_aggregate_address,
5228 no_aggregate_address_summary_only_cmd,
5229 "no aggregate-address A.B.C.D/M summary-only",
5230 NO_STR
5231 "Configure BGP aggregate entries\n"
5232 "Aggregate prefix\n"
5233 "Filter more specific routes from updates\n")
5234
5235ALIAS (no_aggregate_address,
5236 no_aggregate_address_as_set_cmd,
5237 "no aggregate-address A.B.C.D/M as-set",
5238 NO_STR
5239 "Configure BGP aggregate entries\n"
5240 "Aggregate prefix\n"
5241 "Generate AS set path information\n")
5242
5243ALIAS (no_aggregate_address,
5244 no_aggregate_address_as_set_summary_cmd,
5245 "no aggregate-address A.B.C.D/M as-set summary-only",
5246 NO_STR
5247 "Configure BGP aggregate entries\n"
5248 "Aggregate prefix\n"
5249 "Generate AS set path information\n"
5250 "Filter more specific routes from updates\n")
5251
5252ALIAS (no_aggregate_address,
5253 no_aggregate_address_summary_as_set_cmd,
5254 "no aggregate-address A.B.C.D/M summary-only as-set",
5255 NO_STR
5256 "Configure BGP aggregate entries\n"
5257 "Aggregate prefix\n"
5258 "Filter more specific routes from updates\n"
5259 "Generate AS set path information\n")
5260
5261DEFUN (no_aggregate_address_mask,
5262 no_aggregate_address_mask_cmd,
5263 "no aggregate-address A.B.C.D A.B.C.D",
5264 NO_STR
5265 "Configure BGP aggregate entries\n"
5266 "Aggregate address\n"
5267 "Aggregate mask\n")
5268{
5269 int ret;
5270 char prefix_str[BUFSIZ];
5271
5272 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5273
5274 if (! ret)
5275 {
5276 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5277 return CMD_WARNING;
5278 }
5279
5280 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5281}
5282
5283ALIAS (no_aggregate_address_mask,
5284 no_aggregate_address_mask_summary_only_cmd,
5285 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5286 NO_STR
5287 "Configure BGP aggregate entries\n"
5288 "Aggregate address\n"
5289 "Aggregate mask\n"
5290 "Filter more specific routes from updates\n")
5291
5292ALIAS (no_aggregate_address_mask,
5293 no_aggregate_address_mask_as_set_cmd,
5294 "no aggregate-address A.B.C.D A.B.C.D as-set",
5295 NO_STR
5296 "Configure BGP aggregate entries\n"
5297 "Aggregate address\n"
5298 "Aggregate mask\n"
5299 "Generate AS set path information\n")
5300
5301ALIAS (no_aggregate_address_mask,
5302 no_aggregate_address_mask_as_set_summary_cmd,
5303 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5304 NO_STR
5305 "Configure BGP aggregate entries\n"
5306 "Aggregate address\n"
5307 "Aggregate mask\n"
5308 "Generate AS set path information\n"
5309 "Filter more specific routes from updates\n")
5310
5311ALIAS (no_aggregate_address_mask,
5312 no_aggregate_address_mask_summary_as_set_cmd,
5313 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5314 NO_STR
5315 "Configure BGP aggregate entries\n"
5316 "Aggregate address\n"
5317 "Aggregate mask\n"
5318 "Filter more specific routes from updates\n"
5319 "Generate AS set path information\n")
5320
5321#ifdef HAVE_IPV6
5322DEFUN (ipv6_aggregate_address,
5323 ipv6_aggregate_address_cmd,
5324 "aggregate-address X:X::X:X/M",
5325 "Configure BGP aggregate entries\n"
5326 "Aggregate prefix\n")
5327{
5328 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5329}
5330
5331DEFUN (ipv6_aggregate_address_summary_only,
5332 ipv6_aggregate_address_summary_only_cmd,
5333 "aggregate-address X:X::X:X/M summary-only",
5334 "Configure BGP aggregate entries\n"
5335 "Aggregate prefix\n"
5336 "Filter more specific routes from updates\n")
5337{
5338 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5339 AGGREGATE_SUMMARY_ONLY, 0);
5340}
5341
5342DEFUN (no_ipv6_aggregate_address,
5343 no_ipv6_aggregate_address_cmd,
5344 "no aggregate-address X:X::X:X/M",
5345 NO_STR
5346 "Configure BGP aggregate entries\n"
5347 "Aggregate prefix\n")
5348{
5349 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5350}
5351
5352DEFUN (no_ipv6_aggregate_address_summary_only,
5353 no_ipv6_aggregate_address_summary_only_cmd,
5354 "no aggregate-address X:X::X:X/M summary-only",
5355 NO_STR
5356 "Configure BGP aggregate entries\n"
5357 "Aggregate prefix\n"
5358 "Filter more specific routes from updates\n")
5359{
5360 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5361}
5362
5363ALIAS (ipv6_aggregate_address,
5364 old_ipv6_aggregate_address_cmd,
5365 "ipv6 bgp aggregate-address X:X::X:X/M",
5366 IPV6_STR
5367 BGP_STR
5368 "Configure BGP aggregate entries\n"
5369 "Aggregate prefix\n")
5370
5371ALIAS (ipv6_aggregate_address_summary_only,
5372 old_ipv6_aggregate_address_summary_only_cmd,
5373 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5374 IPV6_STR
5375 BGP_STR
5376 "Configure BGP aggregate entries\n"
5377 "Aggregate prefix\n"
5378 "Filter more specific routes from updates\n")
5379
5380ALIAS (no_ipv6_aggregate_address,
5381 old_no_ipv6_aggregate_address_cmd,
5382 "no ipv6 bgp aggregate-address X:X::X:X/M",
5383 NO_STR
5384 IPV6_STR
5385 BGP_STR
5386 "Configure BGP aggregate entries\n"
5387 "Aggregate prefix\n")
5388
5389ALIAS (no_ipv6_aggregate_address_summary_only,
5390 old_no_ipv6_aggregate_address_summary_only_cmd,
5391 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5392 NO_STR
5393 IPV6_STR
5394 BGP_STR
5395 "Configure BGP aggregate entries\n"
5396 "Aggregate prefix\n"
5397 "Filter more specific routes from updates\n")
5398#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02005399
paul718e3742002-12-13 20:15:29 +00005400/* Redistribute route treatment. */
5401void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005402bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5403 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005404 u_int32_t metric, u_char type)
5405{
5406 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005407 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005408 struct bgp_info *new;
5409 struct bgp_info *bi;
5410 struct bgp_info info;
5411 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005412 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005413 struct attr *new_attr;
5414 afi_t afi;
5415 int ret;
5416
5417 /* Make default attribute. */
5418 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5419 if (nexthop)
5420 attr.nexthop = *nexthop;
5421
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005422#ifdef HAVE_IPV6
5423 if (nexthop6)
5424 {
5425 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5426 extra->mp_nexthop_global = *nexthop6;
5427 extra->mp_nexthop_len = 16;
5428 }
5429#endif
5430
paul718e3742002-12-13 20:15:29 +00005431 attr.med = metric;
5432 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5433
paul1eb8ef22005-04-07 07:30:20 +00005434 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005435 {
5436 afi = family2afi (p->family);
5437
5438 if (bgp->redist[afi][type])
5439 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005440 struct attr attr_new;
5441 struct attr_extra extra_new;
5442
paul718e3742002-12-13 20:15:29 +00005443 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005444 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005445 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005446
5447 if (bgp->redist_metric_flag[afi][type])
5448 attr_new.med = bgp->redist_metric[afi][type];
5449
5450 /* Apply route-map. */
5451 if (bgp->rmap[afi][type].map)
5452 {
5453 info.peer = bgp->peer_self;
5454 info.attr = &attr_new;
5455
paulfee0f4c2004-09-13 05:12:46 +00005456 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5457
paul718e3742002-12-13 20:15:29 +00005458 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5459 &info);
paulfee0f4c2004-09-13 05:12:46 +00005460
5461 bgp->peer_self->rmap_type = 0;
5462
paul718e3742002-12-13 20:15:29 +00005463 if (ret == RMAP_DENYMATCH)
5464 {
5465 /* Free uninterned attribute. */
5466 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005467
paul718e3742002-12-13 20:15:29 +00005468 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005469 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005470 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005471 bgp_redistribute_delete (p, type);
5472 return;
5473 }
5474 }
5475
Paul Jakmafb982c22007-05-04 20:15:47 +00005476 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5477 afi, SAFI_UNICAST, p, NULL);
5478
paul718e3742002-12-13 20:15:29 +00005479 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005480
paul718e3742002-12-13 20:15:29 +00005481 for (bi = bn->info; bi; bi = bi->next)
5482 if (bi->peer == bgp->peer_self
5483 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5484 break;
5485
5486 if (bi)
5487 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005488 if (attrhash_cmp (bi->attr, new_attr) &&
5489 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005490 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005491 bgp_attr_unintern (&new_attr);
5492 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005493 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005494 bgp_unlock_node (bn);
5495 return;
5496 }
5497 else
5498 {
5499 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005500 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005501
5502 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005503 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5504 bgp_info_restore(bn, bi);
5505 else
5506 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005507 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005508 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005509 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005510
5511 /* Process change. */
5512 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5513 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5514 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005515 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005516 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005517 return;
5518 }
5519 }
5520
5521 new = bgp_info_new ();
5522 new->type = type;
5523 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5524 new->peer = bgp->peer_self;
5525 SET_FLAG (new->flags, BGP_INFO_VALID);
5526 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005527 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005528
5529 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5530 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005531 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005532 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5533 }
5534 }
5535
5536 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005537 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005538 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005539}
5540
5541void
5542bgp_redistribute_delete (struct prefix *p, u_char type)
5543{
5544 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005545 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005546 afi_t afi;
5547 struct bgp_node *rn;
5548 struct bgp_info *ri;
5549
paul1eb8ef22005-04-07 07:30:20 +00005550 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005551 {
5552 afi = family2afi (p->family);
5553
5554 if (bgp->redist[afi][type])
5555 {
paulfee0f4c2004-09-13 05:12:46 +00005556 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005557
5558 for (ri = rn->info; ri; ri = ri->next)
5559 if (ri->peer == bgp->peer_self
5560 && ri->type == type)
5561 break;
5562
5563 if (ri)
5564 {
5565 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005566 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005567 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005568 }
5569 bgp_unlock_node (rn);
5570 }
5571 }
5572}
5573
5574/* Withdraw specified route type's route. */
5575void
5576bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5577{
5578 struct bgp_node *rn;
5579 struct bgp_info *ri;
5580 struct bgp_table *table;
5581
5582 table = bgp->rib[afi][SAFI_UNICAST];
5583
5584 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5585 {
5586 for (ri = rn->info; ri; ri = ri->next)
5587 if (ri->peer == bgp->peer_self
5588 && ri->type == type)
5589 break;
5590
5591 if (ri)
5592 {
5593 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005594 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005595 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005596 }
5597 }
5598}
David Lamparter6b0655a2014-06-04 06:53:35 +02005599
paul718e3742002-12-13 20:15:29 +00005600/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005601static void
paul718e3742002-12-13 20:15:29 +00005602route_vty_out_route (struct prefix *p, struct vty *vty)
5603{
5604 int len;
5605 u_int32_t destination;
5606 char buf[BUFSIZ];
5607
5608 if (p->family == AF_INET)
5609 {
5610 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5611 destination = ntohl (p->u.prefix4.s_addr);
5612
5613 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5614 || (IN_CLASSB (destination) && p->prefixlen == 16)
5615 || (IN_CLASSA (destination) && p->prefixlen == 8)
5616 || p->u.prefix4.s_addr == 0)
5617 {
5618 /* When mask is natural, mask is not displayed. */
5619 }
5620 else
5621 len += vty_out (vty, "/%d", p->prefixlen);
5622 }
5623 else
5624 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5625 p->prefixlen);
5626
5627 len = 17 - len;
5628 if (len < 1)
5629 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5630 else
5631 vty_out (vty, "%*s", len, " ");
5632}
5633
paul718e3742002-12-13 20:15:29 +00005634enum bgp_display_type
5635{
5636 normal_list,
5637};
5638
paulb40d9392005-08-22 22:34:41 +00005639/* Print the short form route status for a bgp_info */
5640static void
5641route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005642{
paulb40d9392005-08-22 22:34:41 +00005643 /* Route status display. */
5644 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5645 vty_out (vty, "R");
5646 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005647 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005648 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005649 vty_out (vty, "s");
5650 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5651 vty_out (vty, "*");
5652 else
5653 vty_out (vty, " ");
5654
5655 /* Selected */
5656 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5657 vty_out (vty, "h");
5658 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5659 vty_out (vty, "d");
5660 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5661 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005662 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5663 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005664 else
5665 vty_out (vty, " ");
5666
5667 /* Internal route. */
5668 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5669 vty_out (vty, "i");
5670 else
paulb40d9392005-08-22 22:34:41 +00005671 vty_out (vty, " ");
5672}
5673
5674/* called from terminal list command */
5675void
5676route_vty_out (struct vty *vty, struct prefix *p,
5677 struct bgp_info *binfo, int display, safi_t safi)
5678{
5679 struct attr *attr;
5680
5681 /* short status lead text */
5682 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005683
5684 /* print prefix and mask */
5685 if (! display)
5686 route_vty_out_route (p, vty);
5687 else
5688 vty_out (vty, "%*s", 17, " ");
5689
5690 /* Print attribute */
5691 attr = binfo->attr;
5692 if (attr)
5693 {
5694 if (p->family == AF_INET)
5695 {
5696 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005697 vty_out (vty, "%-16s",
5698 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005699 else
5700 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5701 }
5702#ifdef HAVE_IPV6
5703 else if (p->family == AF_INET6)
5704 {
5705 int len;
5706 char buf[BUFSIZ];
5707
5708 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005709 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5710 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005711 len = 16 - len;
5712 if (len < 1)
5713 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5714 else
5715 vty_out (vty, "%*s", len, " ");
5716 }
5717#endif /* HAVE_IPV6 */
5718
5719 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005720 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005721 else
5722 vty_out (vty, " ");
5723
5724 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005725 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005726 else
5727 vty_out (vty, " ");
5728
Paul Jakmafb982c22007-05-04 20:15:47 +00005729 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005730
Paul Jakmab2518c12006-05-12 23:48:40 +00005731 /* Print aspath */
5732 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005733 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005734
Paul Jakmab2518c12006-05-12 23:48:40 +00005735 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005736 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005737 }
paul718e3742002-12-13 20:15:29 +00005738 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005739}
5740
5741/* called from terminal list command */
5742void
5743route_vty_out_tmp (struct vty *vty, struct prefix *p,
5744 struct attr *attr, safi_t safi)
5745{
5746 /* Route status display. */
5747 vty_out (vty, "*");
5748 vty_out (vty, ">");
5749 vty_out (vty, " ");
5750
5751 /* print prefix and mask */
5752 route_vty_out_route (p, vty);
5753
5754 /* Print attribute */
5755 if (attr)
5756 {
5757 if (p->family == AF_INET)
5758 {
5759 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005760 vty_out (vty, "%-16s",
5761 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005762 else
5763 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5764 }
5765#ifdef HAVE_IPV6
5766 else if (p->family == AF_INET6)
5767 {
5768 int len;
5769 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005770
5771 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005772
5773 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005774 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5775 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005776 len = 16 - len;
5777 if (len < 1)
5778 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5779 else
5780 vty_out (vty, "%*s", len, " ");
5781 }
5782#endif /* HAVE_IPV6 */
5783
5784 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005785 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005786 else
5787 vty_out (vty, " ");
5788
5789 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005790 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005791 else
5792 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005793
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005794 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005795
Paul Jakmab2518c12006-05-12 23:48:40 +00005796 /* Print aspath */
5797 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005798 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005799
Paul Jakmab2518c12006-05-12 23:48:40 +00005800 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005801 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005802 }
paul718e3742002-12-13 20:15:29 +00005803
5804 vty_out (vty, "%s", VTY_NEWLINE);
5805}
5806
ajs5a646652004-11-05 01:25:55 +00005807void
paul718e3742002-12-13 20:15:29 +00005808route_vty_out_tag (struct vty *vty, struct prefix *p,
5809 struct bgp_info *binfo, int display, safi_t safi)
5810{
5811 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005812 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005813
5814 if (!binfo->extra)
5815 return;
5816
paulb40d9392005-08-22 22:34:41 +00005817 /* short status lead text */
5818 route_vty_short_status_out (vty, binfo);
5819
paul718e3742002-12-13 20:15:29 +00005820 /* print prefix and mask */
5821 if (! display)
5822 route_vty_out_route (p, vty);
5823 else
5824 vty_out (vty, "%*s", 17, " ");
5825
5826 /* Print attribute */
5827 attr = binfo->attr;
5828 if (attr)
5829 {
5830 if (p->family == AF_INET)
5831 {
5832 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005833 vty_out (vty, "%-16s",
5834 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005835 else
5836 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5837 }
5838#ifdef HAVE_IPV6
5839 else if (p->family == AF_INET6)
5840 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005841 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005842 char buf[BUFSIZ];
5843 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005844 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005845 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005846 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5847 buf, BUFSIZ));
5848 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005849 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005850 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5851 buf, BUFSIZ),
5852 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5853 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005854
5855 }
5856#endif /* HAVE_IPV6 */
5857 }
5858
Paul Jakmafb982c22007-05-04 20:15:47 +00005859 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005860
5861 vty_out (vty, "notag/%d", label);
5862
5863 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005864}
5865
5866/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005867static void
paul718e3742002-12-13 20:15:29 +00005868damp_route_vty_out (struct vty *vty, struct prefix *p,
5869 struct bgp_info *binfo, int display, safi_t safi)
5870{
5871 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005872 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005873 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005874
paulb40d9392005-08-22 22:34:41 +00005875 /* short status lead text */
5876 route_vty_short_status_out (vty, binfo);
5877
paul718e3742002-12-13 20:15:29 +00005878 /* print prefix and mask */
5879 if (! display)
5880 route_vty_out_route (p, vty);
5881 else
5882 vty_out (vty, "%*s", 17, " ");
5883
5884 len = vty_out (vty, "%s", binfo->peer->host);
5885 len = 17 - len;
5886 if (len < 1)
5887 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5888 else
5889 vty_out (vty, "%*s", len, " ");
5890
Chris Caputo50aef6f2009-06-23 06:06:49 +00005891 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005892
5893 /* Print attribute */
5894 attr = binfo->attr;
5895 if (attr)
5896 {
5897 /* Print aspath */
5898 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005899 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005900
5901 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005902 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005903 }
5904 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005905}
5906
paul718e3742002-12-13 20:15:29 +00005907/* flap route */
ajs5a646652004-11-05 01:25:55 +00005908static void
paul718e3742002-12-13 20:15:29 +00005909flap_route_vty_out (struct vty *vty, struct prefix *p,
5910 struct bgp_info *binfo, int display, safi_t safi)
5911{
5912 struct attr *attr;
5913 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005914 char timebuf[BGP_UPTIME_LEN];
5915 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005916
5917 if (!binfo->extra)
5918 return;
5919
5920 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005921
paulb40d9392005-08-22 22:34:41 +00005922 /* short status lead text */
5923 route_vty_short_status_out (vty, binfo);
5924
paul718e3742002-12-13 20:15:29 +00005925 /* print prefix and mask */
5926 if (! display)
5927 route_vty_out_route (p, vty);
5928 else
5929 vty_out (vty, "%*s", 17, " ");
5930
5931 len = vty_out (vty, "%s", binfo->peer->host);
5932 len = 16 - len;
5933 if (len < 1)
5934 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5935 else
5936 vty_out (vty, "%*s", len, " ");
5937
5938 len = vty_out (vty, "%d", bdi->flap);
5939 len = 5 - len;
5940 if (len < 1)
5941 vty_out (vty, " ");
5942 else
5943 vty_out (vty, "%*s ", len, " ");
5944
5945 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5946 timebuf, BGP_UPTIME_LEN));
5947
5948 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5949 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005950 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005951 else
5952 vty_out (vty, "%*s ", 8, " ");
5953
5954 /* Print attribute */
5955 attr = binfo->attr;
5956 if (attr)
5957 {
5958 /* Print aspath */
5959 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005960 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005961
5962 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005963 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005964 }
5965 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005966}
5967
paul94f2b392005-06-28 12:44:16 +00005968static void
paul718e3742002-12-13 20:15:29 +00005969route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5970 struct bgp_info *binfo, afi_t afi, safi_t safi)
5971{
5972 char buf[INET6_ADDRSTRLEN];
5973 char buf1[BUFSIZ];
5974 struct attr *attr;
5975 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005976#ifdef HAVE_CLOCK_MONOTONIC
5977 time_t tbuf;
5978#endif
paul718e3742002-12-13 20:15:29 +00005979
5980 attr = binfo->attr;
5981
5982 if (attr)
5983 {
5984 /* Line1 display AS-path, Aggregator */
5985 if (attr->aspath)
5986 {
5987 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005988 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005989 vty_out (vty, "Local");
5990 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005991 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005992 }
5993
paulb40d9392005-08-22 22:34:41 +00005994 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5995 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005996 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5997 vty_out (vty, ", (stale)");
5998 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005999 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006000 attr->extra->aggregator_as,
6001 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006002 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6003 vty_out (vty, ", (Received from a RR-client)");
6004 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6005 vty_out (vty, ", (Received from a RS-client)");
6006 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6007 vty_out (vty, ", (history entry)");
6008 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6009 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006010 vty_out (vty, "%s", VTY_NEWLINE);
6011
6012 /* Line2 display Next-hop, Neighbor, Router-id */
6013 if (p->family == AF_INET)
6014 {
6015 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006016 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006017 inet_ntoa (attr->nexthop));
6018 }
6019#ifdef HAVE_IPV6
6020 else
6021 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006022 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006023 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006024 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006025 buf, INET6_ADDRSTRLEN));
6026 }
6027#endif /* HAVE_IPV6 */
6028
6029 if (binfo->peer == bgp->peer_self)
6030 {
6031 vty_out (vty, " from %s ",
6032 p->family == AF_INET ? "0.0.0.0" : "::");
6033 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6034 }
6035 else
6036 {
6037 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6038 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006039 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006040 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006041 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006042 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006043 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006044 else
6045 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6046 }
6047 vty_out (vty, "%s", VTY_NEWLINE);
6048
6049#ifdef HAVE_IPV6
6050 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006051 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006052 {
6053 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006054 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006055 buf, INET6_ADDRSTRLEN),
6056 VTY_NEWLINE);
6057 }
6058#endif /* HAVE_IPV6 */
6059
6060 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6061 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6062
6063 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006064 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006065
6066 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006067 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006068 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006069 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006070
Paul Jakmafb982c22007-05-04 20:15:47 +00006071 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006072 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006073
6074 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6075 vty_out (vty, ", valid");
6076
6077 if (binfo->peer != bgp->peer_self)
6078 {
6079 if (binfo->peer->as == binfo->peer->local_as)
6080 vty_out (vty, ", internal");
6081 else
6082 vty_out (vty, ", %s",
6083 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6084 }
6085 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6086 vty_out (vty, ", aggregated, local");
6087 else if (binfo->type != ZEBRA_ROUTE_BGP)
6088 vty_out (vty, ", sourced");
6089 else
6090 vty_out (vty, ", sourced, local");
6091
6092 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6093 vty_out (vty, ", atomic-aggregate");
6094
Josh Baileyde8d5df2011-07-20 20:46:01 -07006095 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6096 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6097 bgp_info_mpath_count (binfo)))
6098 vty_out (vty, ", multipath");
6099
paul718e3742002-12-13 20:15:29 +00006100 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6101 vty_out (vty, ", best");
6102
6103 vty_out (vty, "%s", VTY_NEWLINE);
6104
6105 /* Line 4 display Community */
6106 if (attr->community)
6107 vty_out (vty, " Community: %s%s", attr->community->str,
6108 VTY_NEWLINE);
6109
6110 /* Line 5 display Extended-community */
6111 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006112 vty_out (vty, " Extended Community: %s%s",
6113 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006114
6115 /* Line 6 display Originator, Cluster-id */
6116 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6117 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6118 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006119 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006120 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006121 vty_out (vty, " Originator: %s",
6122 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006123
6124 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6125 {
6126 int i;
6127 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006128 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6129 vty_out (vty, "%s ",
6130 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006131 }
6132 vty_out (vty, "%s", VTY_NEWLINE);
6133 }
Paul Jakma41367172007-08-06 15:24:51 +00006134
Paul Jakmafb982c22007-05-04 20:15:47 +00006135 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006136 bgp_damp_info_vty (vty, binfo);
6137
6138 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006139#ifdef HAVE_CLOCK_MONOTONIC
6140 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006141 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006142#else
6143 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6144#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006145 }
6146 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006147}
6148
6149#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6150 "h history, * valid, > best, = multipath,%s"\
6151 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006152#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006153#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6154#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6155#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6156
6157enum bgp_show_type
6158{
6159 bgp_show_type_normal,
6160 bgp_show_type_regexp,
6161 bgp_show_type_prefix_list,
6162 bgp_show_type_filter_list,
6163 bgp_show_type_route_map,
6164 bgp_show_type_neighbor,
6165 bgp_show_type_cidr_only,
6166 bgp_show_type_prefix_longer,
6167 bgp_show_type_community_all,
6168 bgp_show_type_community,
6169 bgp_show_type_community_exact,
6170 bgp_show_type_community_list,
6171 bgp_show_type_community_list_exact,
6172 bgp_show_type_flap_statistics,
6173 bgp_show_type_flap_address,
6174 bgp_show_type_flap_prefix,
6175 bgp_show_type_flap_cidr_only,
6176 bgp_show_type_flap_regexp,
6177 bgp_show_type_flap_filter_list,
6178 bgp_show_type_flap_prefix_list,
6179 bgp_show_type_flap_prefix_longer,
6180 bgp_show_type_flap_route_map,
6181 bgp_show_type_flap_neighbor,
6182 bgp_show_type_dampend_paths,
6183 bgp_show_type_damp_neighbor
6184};
6185
ajs5a646652004-11-05 01:25:55 +00006186static int
paulfee0f4c2004-09-13 05:12:46 +00006187bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006188 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006189{
paul718e3742002-12-13 20:15:29 +00006190 struct bgp_info *ri;
6191 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006192 int header = 1;
paul718e3742002-12-13 20:15:29 +00006193 int display;
ajs5a646652004-11-05 01:25:55 +00006194 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006195
6196 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006197 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006198
paul718e3742002-12-13 20:15:29 +00006199 /* Start processing of routes. */
6200 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6201 if (rn->info != NULL)
6202 {
6203 display = 0;
6204
6205 for (ri = rn->info; ri; ri = ri->next)
6206 {
ajs5a646652004-11-05 01:25:55 +00006207 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006208 || type == bgp_show_type_flap_address
6209 || type == bgp_show_type_flap_prefix
6210 || type == bgp_show_type_flap_cidr_only
6211 || type == bgp_show_type_flap_regexp
6212 || type == bgp_show_type_flap_filter_list
6213 || type == bgp_show_type_flap_prefix_list
6214 || type == bgp_show_type_flap_prefix_longer
6215 || type == bgp_show_type_flap_route_map
6216 || type == bgp_show_type_flap_neighbor
6217 || type == bgp_show_type_dampend_paths
6218 || type == bgp_show_type_damp_neighbor)
6219 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006220 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006221 continue;
6222 }
6223 if (type == bgp_show_type_regexp
6224 || type == bgp_show_type_flap_regexp)
6225 {
ajs5a646652004-11-05 01:25:55 +00006226 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006227
6228 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6229 continue;
6230 }
6231 if (type == bgp_show_type_prefix_list
6232 || type == bgp_show_type_flap_prefix_list)
6233 {
ajs5a646652004-11-05 01:25:55 +00006234 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006235
6236 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6237 continue;
6238 }
6239 if (type == bgp_show_type_filter_list
6240 || type == bgp_show_type_flap_filter_list)
6241 {
ajs5a646652004-11-05 01:25:55 +00006242 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006243
6244 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6245 continue;
6246 }
6247 if (type == bgp_show_type_route_map
6248 || type == bgp_show_type_flap_route_map)
6249 {
ajs5a646652004-11-05 01:25:55 +00006250 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006251 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006252 struct attr dummy_attr;
6253 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006254 int ret;
6255
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006256 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006257 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006258
paul718e3742002-12-13 20:15:29 +00006259 binfo.peer = ri->peer;
6260 binfo.attr = &dummy_attr;
6261
6262 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006263 if (ret == RMAP_DENYMATCH)
6264 continue;
6265 }
6266 if (type == bgp_show_type_neighbor
6267 || type == bgp_show_type_flap_neighbor
6268 || type == bgp_show_type_damp_neighbor)
6269 {
ajs5a646652004-11-05 01:25:55 +00006270 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006271
6272 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6273 continue;
6274 }
6275 if (type == bgp_show_type_cidr_only
6276 || type == bgp_show_type_flap_cidr_only)
6277 {
6278 u_int32_t destination;
6279
6280 destination = ntohl (rn->p.u.prefix4.s_addr);
6281 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6282 continue;
6283 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6284 continue;
6285 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6286 continue;
6287 }
6288 if (type == bgp_show_type_prefix_longer
6289 || type == bgp_show_type_flap_prefix_longer)
6290 {
ajs5a646652004-11-05 01:25:55 +00006291 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006292
6293 if (! prefix_match (p, &rn->p))
6294 continue;
6295 }
6296 if (type == bgp_show_type_community_all)
6297 {
6298 if (! ri->attr->community)
6299 continue;
6300 }
6301 if (type == bgp_show_type_community)
6302 {
ajs5a646652004-11-05 01:25:55 +00006303 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006304
6305 if (! ri->attr->community ||
6306 ! community_match (ri->attr->community, com))
6307 continue;
6308 }
6309 if (type == bgp_show_type_community_exact)
6310 {
ajs5a646652004-11-05 01:25:55 +00006311 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006312
6313 if (! ri->attr->community ||
6314 ! community_cmp (ri->attr->community, com))
6315 continue;
6316 }
6317 if (type == bgp_show_type_community_list)
6318 {
ajs5a646652004-11-05 01:25:55 +00006319 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006320
6321 if (! community_list_match (ri->attr->community, list))
6322 continue;
6323 }
6324 if (type == bgp_show_type_community_list_exact)
6325 {
ajs5a646652004-11-05 01:25:55 +00006326 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006327
6328 if (! community_list_exact_match (ri->attr->community, list))
6329 continue;
6330 }
6331 if (type == bgp_show_type_flap_address
6332 || type == bgp_show_type_flap_prefix)
6333 {
ajs5a646652004-11-05 01:25:55 +00006334 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006335
6336 if (! prefix_match (&rn->p, p))
6337 continue;
6338
6339 if (type == bgp_show_type_flap_prefix)
6340 if (p->prefixlen != rn->p.prefixlen)
6341 continue;
6342 }
6343 if (type == bgp_show_type_dampend_paths
6344 || type == bgp_show_type_damp_neighbor)
6345 {
6346 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6347 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6348 continue;
6349 }
6350
6351 if (header)
6352 {
hasso93406d82005-02-02 14:40:33 +00006353 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6354 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6355 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006356 if (type == bgp_show_type_dampend_paths
6357 || type == bgp_show_type_damp_neighbor)
6358 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6359 else if (type == bgp_show_type_flap_statistics
6360 || type == bgp_show_type_flap_address
6361 || type == bgp_show_type_flap_prefix
6362 || type == bgp_show_type_flap_cidr_only
6363 || type == bgp_show_type_flap_regexp
6364 || type == bgp_show_type_flap_filter_list
6365 || type == bgp_show_type_flap_prefix_list
6366 || type == bgp_show_type_flap_prefix_longer
6367 || type == bgp_show_type_flap_route_map
6368 || type == bgp_show_type_flap_neighbor)
6369 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6370 else
6371 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006372 header = 0;
6373 }
6374
6375 if (type == bgp_show_type_dampend_paths
6376 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006377 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006378 else if (type == bgp_show_type_flap_statistics
6379 || type == bgp_show_type_flap_address
6380 || type == bgp_show_type_flap_prefix
6381 || type == bgp_show_type_flap_cidr_only
6382 || type == bgp_show_type_flap_regexp
6383 || type == bgp_show_type_flap_filter_list
6384 || type == bgp_show_type_flap_prefix_list
6385 || type == bgp_show_type_flap_prefix_longer
6386 || type == bgp_show_type_flap_route_map
6387 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006388 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006389 else
ajs5a646652004-11-05 01:25:55 +00006390 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006391 display++;
6392 }
6393 if (display)
ajs5a646652004-11-05 01:25:55 +00006394 output_count++;
paul718e3742002-12-13 20:15:29 +00006395 }
6396
6397 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006398 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006399 {
6400 if (type == bgp_show_type_normal)
6401 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6402 }
6403 else
6404 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006405 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006406
6407 return CMD_SUCCESS;
6408}
6409
ajs5a646652004-11-05 01:25:55 +00006410static int
paulfee0f4c2004-09-13 05:12:46 +00006411bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006412 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006413{
6414 struct bgp_table *table;
6415
6416 if (bgp == NULL) {
6417 bgp = bgp_get_default ();
6418 }
6419
6420 if (bgp == NULL)
6421 {
6422 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6423 return CMD_WARNING;
6424 }
6425
6426
6427 table = bgp->rib[afi][safi];
6428
ajs5a646652004-11-05 01:25:55 +00006429 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006430}
6431
paul718e3742002-12-13 20:15:29 +00006432/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006433static void
paul718e3742002-12-13 20:15:29 +00006434route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6435 struct bgp_node *rn,
6436 struct prefix_rd *prd, afi_t afi, safi_t safi)
6437{
6438 struct bgp_info *ri;
6439 struct prefix *p;
6440 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006441 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006442 char buf1[INET6_ADDRSTRLEN];
6443 char buf2[INET6_ADDRSTRLEN];
6444 int count = 0;
6445 int best = 0;
6446 int suppress = 0;
6447 int no_export = 0;
6448 int no_advertise = 0;
6449 int local_as = 0;
6450 int first = 0;
6451
6452 p = &rn->p;
6453 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6454 (safi == SAFI_MPLS_VPN ?
6455 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6456 safi == SAFI_MPLS_VPN ? ":" : "",
6457 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6458 p->prefixlen, VTY_NEWLINE);
6459
6460 for (ri = rn->info; ri; ri = ri->next)
6461 {
6462 count++;
6463 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6464 {
6465 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006466 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006467 suppress = 1;
6468 if (ri->attr->community != NULL)
6469 {
6470 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6471 no_advertise = 1;
6472 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6473 no_export = 1;
6474 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6475 local_as = 1;
6476 }
6477 }
6478 }
6479
6480 vty_out (vty, "Paths: (%d available", count);
6481 if (best)
6482 {
6483 vty_out (vty, ", best #%d", best);
6484 if (safi == SAFI_UNICAST)
6485 vty_out (vty, ", table Default-IP-Routing-Table");
6486 }
6487 else
6488 vty_out (vty, ", no best path");
6489 if (no_advertise)
6490 vty_out (vty, ", not advertised to any peer");
6491 else if (no_export)
6492 vty_out (vty, ", not advertised to EBGP peer");
6493 else if (local_as)
6494 vty_out (vty, ", not advertised outside local AS");
6495 if (suppress)
6496 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6497 vty_out (vty, ")%s", VTY_NEWLINE);
6498
6499 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006500 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006501 {
6502 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6503 {
6504 if (! first)
6505 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6506 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6507 first = 1;
6508 }
6509 }
6510 if (! first)
6511 vty_out (vty, " Not advertised to any peer");
6512 vty_out (vty, "%s", VTY_NEWLINE);
6513}
6514
6515/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006516static int
paulfee0f4c2004-09-13 05:12:46 +00006517bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006518 struct bgp_table *rib, const char *ip_str,
6519 afi_t afi, safi_t safi, struct prefix_rd *prd,
6520 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006521{
6522 int ret;
6523 int header;
6524 int display = 0;
6525 struct prefix match;
6526 struct bgp_node *rn;
6527 struct bgp_node *rm;
6528 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006529 struct bgp_table *table;
6530
paul718e3742002-12-13 20:15:29 +00006531 /* Check IP address argument. */
6532 ret = str2prefix (ip_str, &match);
6533 if (! ret)
6534 {
6535 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6536 return CMD_WARNING;
6537 }
6538
6539 match.family = afi2family (afi);
6540
6541 if (safi == SAFI_MPLS_VPN)
6542 {
paulfee0f4c2004-09-13 05:12:46 +00006543 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006544 {
6545 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6546 continue;
6547
6548 if ((table = rn->info) != NULL)
6549 {
6550 header = 1;
6551
6552 if ((rm = bgp_node_match (table, &match)) != NULL)
6553 {
6554 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006555 {
6556 bgp_unlock_node (rm);
6557 continue;
6558 }
paul718e3742002-12-13 20:15:29 +00006559
6560 for (ri = rm->info; ri; ri = ri->next)
6561 {
6562 if (header)
6563 {
6564 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6565 AFI_IP, SAFI_MPLS_VPN);
6566
6567 header = 0;
6568 }
6569 display++;
6570 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6571 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006572
6573 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006574 }
6575 }
6576 }
6577 }
6578 else
6579 {
6580 header = 1;
6581
paulfee0f4c2004-09-13 05:12:46 +00006582 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006583 {
6584 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6585 {
6586 for (ri = rn->info; ri; ri = ri->next)
6587 {
6588 if (header)
6589 {
6590 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6591 header = 0;
6592 }
6593 display++;
6594 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6595 }
6596 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006597
6598 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006599 }
6600 }
6601
6602 if (! display)
6603 {
6604 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6605 return CMD_WARNING;
6606 }
6607
6608 return CMD_SUCCESS;
6609}
6610
paulfee0f4c2004-09-13 05:12:46 +00006611/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006612static int
paulfd79ac92004-10-13 05:06:08 +00006613bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006614 afi_t afi, safi_t safi, struct prefix_rd *prd,
6615 int prefix_check)
6616{
6617 struct bgp *bgp;
6618
6619 /* BGP structure lookup. */
6620 if (view_name)
6621 {
6622 bgp = bgp_lookup_by_name (view_name);
6623 if (bgp == NULL)
6624 {
6625 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6626 return CMD_WARNING;
6627 }
6628 }
6629 else
6630 {
6631 bgp = bgp_get_default ();
6632 if (bgp == NULL)
6633 {
6634 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6635 return CMD_WARNING;
6636 }
6637 }
6638
6639 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6640 afi, safi, prd, prefix_check);
6641}
6642
paul718e3742002-12-13 20:15:29 +00006643/* BGP route print out function. */
6644DEFUN (show_ip_bgp,
6645 show_ip_bgp_cmd,
6646 "show ip bgp",
6647 SHOW_STR
6648 IP_STR
6649 BGP_STR)
6650{
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
6654DEFUN (show_ip_bgp_ipv4,
6655 show_ip_bgp_ipv4_cmd,
6656 "show ip bgp ipv4 (unicast|multicast)",
6657 SHOW_STR
6658 IP_STR
6659 BGP_STR
6660 "Address family\n"
6661 "Address Family modifier\n"
6662 "Address Family modifier\n")
6663{
6664 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006665 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6666 NULL);
paul718e3742002-12-13 20:15:29 +00006667
ajs5a646652004-11-05 01:25:55 +00006668 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006669}
6670
Michael Lambert95cbbd22010-07-23 14:43:04 -04006671ALIAS (show_ip_bgp_ipv4,
6672 show_bgp_ipv4_safi_cmd,
6673 "show bgp ipv4 (unicast|multicast)",
6674 SHOW_STR
6675 BGP_STR
6676 "Address family\n"
6677 "Address Family modifier\n"
6678 "Address Family modifier\n")
6679
paul718e3742002-12-13 20:15:29 +00006680DEFUN (show_ip_bgp_route,
6681 show_ip_bgp_route_cmd,
6682 "show ip bgp A.B.C.D",
6683 SHOW_STR
6684 IP_STR
6685 BGP_STR
6686 "Network in the BGP routing table to display\n")
6687{
6688 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6689}
6690
6691DEFUN (show_ip_bgp_ipv4_route,
6692 show_ip_bgp_ipv4_route_cmd,
6693 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6694 SHOW_STR
6695 IP_STR
6696 BGP_STR
6697 "Address family\n"
6698 "Address Family modifier\n"
6699 "Address Family modifier\n"
6700 "Network in the BGP routing table to display\n")
6701{
6702 if (strncmp (argv[0], "m", 1) == 0)
6703 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6704
6705 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6706}
6707
Michael Lambert95cbbd22010-07-23 14:43:04 -04006708ALIAS (show_ip_bgp_ipv4_route,
6709 show_bgp_ipv4_safi_route_cmd,
6710 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6711 SHOW_STR
6712 BGP_STR
6713 "Address family\n"
6714 "Address Family modifier\n"
6715 "Address Family modifier\n"
6716 "Network in the BGP routing table to display\n")
6717
paul718e3742002-12-13 20:15:29 +00006718DEFUN (show_ip_bgp_vpnv4_all_route,
6719 show_ip_bgp_vpnv4_all_route_cmd,
6720 "show ip bgp vpnv4 all A.B.C.D",
6721 SHOW_STR
6722 IP_STR
6723 BGP_STR
6724 "Display VPNv4 NLRI specific information\n"
6725 "Display information about all VPNv4 NLRIs\n"
6726 "Network in the BGP routing table to display\n")
6727{
6728 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6729}
6730
6731DEFUN (show_ip_bgp_vpnv4_rd_route,
6732 show_ip_bgp_vpnv4_rd_route_cmd,
6733 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6734 SHOW_STR
6735 IP_STR
6736 BGP_STR
6737 "Display VPNv4 NLRI specific information\n"
6738 "Display information for a route distinguisher\n"
6739 "VPN Route Distinguisher\n"
6740 "Network in the BGP routing table to display\n")
6741{
6742 int ret;
6743 struct prefix_rd prd;
6744
6745 ret = str2prefix_rd (argv[0], &prd);
6746 if (! ret)
6747 {
6748 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6749 return CMD_WARNING;
6750 }
6751 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6752}
6753
6754DEFUN (show_ip_bgp_prefix,
6755 show_ip_bgp_prefix_cmd,
6756 "show ip bgp A.B.C.D/M",
6757 SHOW_STR
6758 IP_STR
6759 BGP_STR
6760 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6761{
6762 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6763}
6764
6765DEFUN (show_ip_bgp_ipv4_prefix,
6766 show_ip_bgp_ipv4_prefix_cmd,
6767 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6768 SHOW_STR
6769 IP_STR
6770 BGP_STR
6771 "Address family\n"
6772 "Address Family modifier\n"
6773 "Address Family modifier\n"
6774 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6775{
6776 if (strncmp (argv[0], "m", 1) == 0)
6777 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6778
6779 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6780}
6781
Michael Lambert95cbbd22010-07-23 14:43:04 -04006782ALIAS (show_ip_bgp_ipv4_prefix,
6783 show_bgp_ipv4_safi_prefix_cmd,
6784 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6785 SHOW_STR
6786 BGP_STR
6787 "Address family\n"
6788 "Address Family modifier\n"
6789 "Address Family modifier\n"
6790 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6791
paul718e3742002-12-13 20:15:29 +00006792DEFUN (show_ip_bgp_vpnv4_all_prefix,
6793 show_ip_bgp_vpnv4_all_prefix_cmd,
6794 "show ip bgp vpnv4 all A.B.C.D/M",
6795 SHOW_STR
6796 IP_STR
6797 BGP_STR
6798 "Display VPNv4 NLRI specific information\n"
6799 "Display information about all VPNv4 NLRIs\n"
6800 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6801{
6802 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6803}
6804
6805DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6806 show_ip_bgp_vpnv4_rd_prefix_cmd,
6807 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6808 SHOW_STR
6809 IP_STR
6810 BGP_STR
6811 "Display VPNv4 NLRI specific information\n"
6812 "Display information for a route distinguisher\n"
6813 "VPN Route Distinguisher\n"
6814 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6815{
6816 int ret;
6817 struct prefix_rd prd;
6818
6819 ret = str2prefix_rd (argv[0], &prd);
6820 if (! ret)
6821 {
6822 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6823 return CMD_WARNING;
6824 }
6825 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6826}
6827
6828DEFUN (show_ip_bgp_view,
6829 show_ip_bgp_view_cmd,
6830 "show ip bgp view WORD",
6831 SHOW_STR
6832 IP_STR
6833 BGP_STR
6834 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006835 "View name\n")
paul718e3742002-12-13 20:15:29 +00006836{
paulbb46e942003-10-24 19:02:03 +00006837 struct bgp *bgp;
6838
6839 /* BGP structure lookup. */
6840 bgp = bgp_lookup_by_name (argv[0]);
6841 if (bgp == NULL)
6842 {
6843 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6844 return CMD_WARNING;
6845 }
6846
ajs5a646652004-11-05 01:25:55 +00006847 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006848}
6849
6850DEFUN (show_ip_bgp_view_route,
6851 show_ip_bgp_view_route_cmd,
6852 "show ip bgp view WORD A.B.C.D",
6853 SHOW_STR
6854 IP_STR
6855 BGP_STR
6856 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006857 "View name\n"
paul718e3742002-12-13 20:15:29 +00006858 "Network in the BGP routing table to display\n")
6859{
6860 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6861}
6862
6863DEFUN (show_ip_bgp_view_prefix,
6864 show_ip_bgp_view_prefix_cmd,
6865 "show ip bgp view WORD A.B.C.D/M",
6866 SHOW_STR
6867 IP_STR
6868 BGP_STR
6869 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006870 "View name\n"
paul718e3742002-12-13 20:15:29 +00006871 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6872{
6873 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6874}
6875
6876#ifdef HAVE_IPV6
6877DEFUN (show_bgp,
6878 show_bgp_cmd,
6879 "show bgp",
6880 SHOW_STR
6881 BGP_STR)
6882{
ajs5a646652004-11-05 01:25:55 +00006883 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6884 NULL);
paul718e3742002-12-13 20:15:29 +00006885}
6886
6887ALIAS (show_bgp,
6888 show_bgp_ipv6_cmd,
6889 "show bgp ipv6",
6890 SHOW_STR
6891 BGP_STR
6892 "Address family\n")
6893
Michael Lambert95cbbd22010-07-23 14:43:04 -04006894DEFUN (show_bgp_ipv6_safi,
6895 show_bgp_ipv6_safi_cmd,
6896 "show bgp ipv6 (unicast|multicast)",
6897 SHOW_STR
6898 BGP_STR
6899 "Address family\n"
6900 "Address Family modifier\n"
6901 "Address Family modifier\n")
6902{
6903 if (strncmp (argv[0], "m", 1) == 0)
6904 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6905 NULL);
6906
6907 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6908}
6909
paul718e3742002-12-13 20:15:29 +00006910/* old command */
6911DEFUN (show_ipv6_bgp,
6912 show_ipv6_bgp_cmd,
6913 "show ipv6 bgp",
6914 SHOW_STR
6915 IP_STR
6916 BGP_STR)
6917{
ajs5a646652004-11-05 01:25:55 +00006918 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6919 NULL);
paul718e3742002-12-13 20:15:29 +00006920}
6921
6922DEFUN (show_bgp_route,
6923 show_bgp_route_cmd,
6924 "show bgp X:X::X:X",
6925 SHOW_STR
6926 BGP_STR
6927 "Network in the BGP routing table to display\n")
6928{
6929 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6930}
6931
6932ALIAS (show_bgp_route,
6933 show_bgp_ipv6_route_cmd,
6934 "show bgp ipv6 X:X::X:X",
6935 SHOW_STR
6936 BGP_STR
6937 "Address family\n"
6938 "Network in the BGP routing table to display\n")
6939
Michael Lambert95cbbd22010-07-23 14:43:04 -04006940DEFUN (show_bgp_ipv6_safi_route,
6941 show_bgp_ipv6_safi_route_cmd,
6942 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6943 SHOW_STR
6944 BGP_STR
6945 "Address family\n"
6946 "Address Family modifier\n"
6947 "Address Family modifier\n"
6948 "Network in the BGP routing table to display\n")
6949{
6950 if (strncmp (argv[0], "m", 1) == 0)
6951 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6952
6953 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6954}
6955
paul718e3742002-12-13 20:15:29 +00006956/* old command */
6957DEFUN (show_ipv6_bgp_route,
6958 show_ipv6_bgp_route_cmd,
6959 "show ipv6 bgp X:X::X:X",
6960 SHOW_STR
6961 IP_STR
6962 BGP_STR
6963 "Network in the BGP routing table to display\n")
6964{
6965 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6966}
6967
6968DEFUN (show_bgp_prefix,
6969 show_bgp_prefix_cmd,
6970 "show bgp X:X::X:X/M",
6971 SHOW_STR
6972 BGP_STR
6973 "IPv6 prefix <network>/<length>\n")
6974{
6975 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6976}
6977
6978ALIAS (show_bgp_prefix,
6979 show_bgp_ipv6_prefix_cmd,
6980 "show bgp ipv6 X:X::X:X/M",
6981 SHOW_STR
6982 BGP_STR
6983 "Address family\n"
6984 "IPv6 prefix <network>/<length>\n")
6985
Michael Lambert95cbbd22010-07-23 14:43:04 -04006986DEFUN (show_bgp_ipv6_safi_prefix,
6987 show_bgp_ipv6_safi_prefix_cmd,
6988 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6989 SHOW_STR
6990 BGP_STR
6991 "Address family\n"
6992 "Address Family modifier\n"
6993 "Address Family modifier\n"
6994 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6995{
6996 if (strncmp (argv[0], "m", 1) == 0)
6997 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6998
6999 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7000}
7001
paul718e3742002-12-13 20:15:29 +00007002/* old command */
7003DEFUN (show_ipv6_bgp_prefix,
7004 show_ipv6_bgp_prefix_cmd,
7005 "show ipv6 bgp X:X::X:X/M",
7006 SHOW_STR
7007 IP_STR
7008 BGP_STR
7009 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7010{
7011 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7012}
7013
paulbb46e942003-10-24 19:02:03 +00007014DEFUN (show_bgp_view,
7015 show_bgp_view_cmd,
7016 "show bgp view WORD",
7017 SHOW_STR
7018 BGP_STR
7019 "BGP view\n"
7020 "View name\n")
7021{
7022 struct bgp *bgp;
7023
7024 /* BGP structure lookup. */
7025 bgp = bgp_lookup_by_name (argv[0]);
7026 if (bgp == NULL)
7027 {
7028 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7029 return CMD_WARNING;
7030 }
7031
ajs5a646652004-11-05 01:25:55 +00007032 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007033}
7034
7035ALIAS (show_bgp_view,
7036 show_bgp_view_ipv6_cmd,
7037 "show bgp view WORD ipv6",
7038 SHOW_STR
7039 BGP_STR
7040 "BGP view\n"
7041 "View name\n"
7042 "Address family\n")
7043
7044DEFUN (show_bgp_view_route,
7045 show_bgp_view_route_cmd,
7046 "show bgp view WORD X:X::X:X",
7047 SHOW_STR
7048 BGP_STR
7049 "BGP view\n"
7050 "View name\n"
7051 "Network in the BGP routing table to display\n")
7052{
7053 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7054}
7055
7056ALIAS (show_bgp_view_route,
7057 show_bgp_view_ipv6_route_cmd,
7058 "show bgp view WORD ipv6 X:X::X:X",
7059 SHOW_STR
7060 BGP_STR
7061 "BGP view\n"
7062 "View name\n"
7063 "Address family\n"
7064 "Network in the BGP routing table to display\n")
7065
7066DEFUN (show_bgp_view_prefix,
7067 show_bgp_view_prefix_cmd,
7068 "show bgp view WORD X:X::X:X/M",
7069 SHOW_STR
7070 BGP_STR
7071 "BGP view\n"
7072 "View name\n"
7073 "IPv6 prefix <network>/<length>\n")
7074{
7075 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7076}
7077
7078ALIAS (show_bgp_view_prefix,
7079 show_bgp_view_ipv6_prefix_cmd,
7080 "show bgp view WORD ipv6 X:X::X:X/M",
7081 SHOW_STR
7082 BGP_STR
7083 "BGP view\n"
7084 "View name\n"
7085 "Address family\n"
7086 "IPv6 prefix <network>/<length>\n")
7087
paul718e3742002-12-13 20:15:29 +00007088/* old command */
7089DEFUN (show_ipv6_mbgp,
7090 show_ipv6_mbgp_cmd,
7091 "show ipv6 mbgp",
7092 SHOW_STR
7093 IP_STR
7094 MBGP_STR)
7095{
ajs5a646652004-11-05 01:25:55 +00007096 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7097 NULL);
paul718e3742002-12-13 20:15:29 +00007098}
7099
7100/* old command */
7101DEFUN (show_ipv6_mbgp_route,
7102 show_ipv6_mbgp_route_cmd,
7103 "show ipv6 mbgp X:X::X:X",
7104 SHOW_STR
7105 IP_STR
7106 MBGP_STR
7107 "Network in the MBGP routing table to display\n")
7108{
7109 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7110}
7111
7112/* old command */
7113DEFUN (show_ipv6_mbgp_prefix,
7114 show_ipv6_mbgp_prefix_cmd,
7115 "show ipv6 mbgp X:X::X:X/M",
7116 SHOW_STR
7117 IP_STR
7118 MBGP_STR
7119 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7120{
7121 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7122}
7123#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02007124
paul718e3742002-12-13 20:15:29 +00007125
paul94f2b392005-06-28 12:44:16 +00007126static int
paulfd79ac92004-10-13 05:06:08 +00007127bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007128 safi_t safi, enum bgp_show_type type)
7129{
7130 int i;
7131 struct buffer *b;
7132 char *regstr;
7133 int first;
7134 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007135 int rc;
paul718e3742002-12-13 20:15:29 +00007136
7137 first = 0;
7138 b = buffer_new (1024);
7139 for (i = 0; i < argc; i++)
7140 {
7141 if (first)
7142 buffer_putc (b, ' ');
7143 else
7144 {
7145 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7146 continue;
7147 first = 1;
7148 }
7149
7150 buffer_putstr (b, argv[i]);
7151 }
7152 buffer_putc (b, '\0');
7153
7154 regstr = buffer_getstr (b);
7155 buffer_free (b);
7156
7157 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007158 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007159 if (! regex)
7160 {
7161 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7162 VTY_NEWLINE);
7163 return CMD_WARNING;
7164 }
7165
ajs5a646652004-11-05 01:25:55 +00007166 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7167 bgp_regex_free (regex);
7168 return rc;
paul718e3742002-12-13 20:15:29 +00007169}
7170
7171DEFUN (show_ip_bgp_regexp,
7172 show_ip_bgp_regexp_cmd,
7173 "show ip bgp regexp .LINE",
7174 SHOW_STR
7175 IP_STR
7176 BGP_STR
7177 "Display routes matching the AS path regular expression\n"
7178 "A regular-expression to match the BGP AS paths\n")
7179{
7180 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7181 bgp_show_type_regexp);
7182}
7183
7184DEFUN (show_ip_bgp_flap_regexp,
7185 show_ip_bgp_flap_regexp_cmd,
7186 "show ip bgp flap-statistics regexp .LINE",
7187 SHOW_STR
7188 IP_STR
7189 BGP_STR
7190 "Display flap statistics of routes\n"
7191 "Display routes matching the AS path regular expression\n"
7192 "A regular-expression to match the BGP AS paths\n")
7193{
7194 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7195 bgp_show_type_flap_regexp);
7196}
7197
7198DEFUN (show_ip_bgp_ipv4_regexp,
7199 show_ip_bgp_ipv4_regexp_cmd,
7200 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7201 SHOW_STR
7202 IP_STR
7203 BGP_STR
7204 "Address family\n"
7205 "Address Family modifier\n"
7206 "Address Family modifier\n"
7207 "Display routes matching the AS path regular expression\n"
7208 "A regular-expression to match the BGP AS paths\n")
7209{
7210 if (strncmp (argv[0], "m", 1) == 0)
7211 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7212 bgp_show_type_regexp);
7213
7214 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7215 bgp_show_type_regexp);
7216}
7217
7218#ifdef HAVE_IPV6
7219DEFUN (show_bgp_regexp,
7220 show_bgp_regexp_cmd,
7221 "show bgp regexp .LINE",
7222 SHOW_STR
7223 BGP_STR
7224 "Display routes matching the AS path regular expression\n"
7225 "A regular-expression to match the BGP AS paths\n")
7226{
7227 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7228 bgp_show_type_regexp);
7229}
7230
7231ALIAS (show_bgp_regexp,
7232 show_bgp_ipv6_regexp_cmd,
7233 "show bgp ipv6 regexp .LINE",
7234 SHOW_STR
7235 BGP_STR
7236 "Address family\n"
7237 "Display routes matching the AS path regular expression\n"
7238 "A regular-expression to match the BGP AS paths\n")
7239
7240/* old command */
7241DEFUN (show_ipv6_bgp_regexp,
7242 show_ipv6_bgp_regexp_cmd,
7243 "show ipv6 bgp regexp .LINE",
7244 SHOW_STR
7245 IP_STR
7246 BGP_STR
7247 "Display routes matching the AS path regular expression\n"
7248 "A regular-expression to match the BGP AS paths\n")
7249{
7250 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7251 bgp_show_type_regexp);
7252}
7253
7254/* old command */
7255DEFUN (show_ipv6_mbgp_regexp,
7256 show_ipv6_mbgp_regexp_cmd,
7257 "show ipv6 mbgp regexp .LINE",
7258 SHOW_STR
7259 IP_STR
7260 BGP_STR
7261 "Display routes matching the AS path regular expression\n"
7262 "A regular-expression to match the MBGP AS paths\n")
7263{
7264 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7265 bgp_show_type_regexp);
7266}
7267#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007268
paul94f2b392005-06-28 12:44:16 +00007269static int
paulfd79ac92004-10-13 05:06:08 +00007270bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007271 safi_t safi, enum bgp_show_type type)
7272{
7273 struct prefix_list *plist;
7274
7275 plist = prefix_list_lookup (afi, prefix_list_str);
7276 if (plist == NULL)
7277 {
7278 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7279 prefix_list_str, VTY_NEWLINE);
7280 return CMD_WARNING;
7281 }
7282
ajs5a646652004-11-05 01:25:55 +00007283 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007284}
7285
7286DEFUN (show_ip_bgp_prefix_list,
7287 show_ip_bgp_prefix_list_cmd,
7288 "show ip bgp prefix-list WORD",
7289 SHOW_STR
7290 IP_STR
7291 BGP_STR
7292 "Display routes conforming to the prefix-list\n"
7293 "IP prefix-list name\n")
7294{
7295 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7296 bgp_show_type_prefix_list);
7297}
7298
7299DEFUN (show_ip_bgp_flap_prefix_list,
7300 show_ip_bgp_flap_prefix_list_cmd,
7301 "show ip bgp flap-statistics prefix-list WORD",
7302 SHOW_STR
7303 IP_STR
7304 BGP_STR
7305 "Display flap statistics of routes\n"
7306 "Display routes conforming to the prefix-list\n"
7307 "IP prefix-list name\n")
7308{
7309 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7310 bgp_show_type_flap_prefix_list);
7311}
7312
7313DEFUN (show_ip_bgp_ipv4_prefix_list,
7314 show_ip_bgp_ipv4_prefix_list_cmd,
7315 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7316 SHOW_STR
7317 IP_STR
7318 BGP_STR
7319 "Address family\n"
7320 "Address Family modifier\n"
7321 "Address Family modifier\n"
7322 "Display routes conforming to the prefix-list\n"
7323 "IP prefix-list name\n")
7324{
7325 if (strncmp (argv[0], "m", 1) == 0)
7326 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7327 bgp_show_type_prefix_list);
7328
7329 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7330 bgp_show_type_prefix_list);
7331}
7332
7333#ifdef HAVE_IPV6
7334DEFUN (show_bgp_prefix_list,
7335 show_bgp_prefix_list_cmd,
7336 "show bgp prefix-list WORD",
7337 SHOW_STR
7338 BGP_STR
7339 "Display routes conforming to the prefix-list\n"
7340 "IPv6 prefix-list name\n")
7341{
7342 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7343 bgp_show_type_prefix_list);
7344}
7345
7346ALIAS (show_bgp_prefix_list,
7347 show_bgp_ipv6_prefix_list_cmd,
7348 "show bgp ipv6 prefix-list WORD",
7349 SHOW_STR
7350 BGP_STR
7351 "Address family\n"
7352 "Display routes conforming to the prefix-list\n"
7353 "IPv6 prefix-list name\n")
7354
7355/* old command */
7356DEFUN (show_ipv6_bgp_prefix_list,
7357 show_ipv6_bgp_prefix_list_cmd,
7358 "show ipv6 bgp prefix-list WORD",
7359 SHOW_STR
7360 IPV6_STR
7361 BGP_STR
7362 "Display routes matching the prefix-list\n"
7363 "IPv6 prefix-list name\n")
7364{
7365 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7366 bgp_show_type_prefix_list);
7367}
7368
7369/* old command */
7370DEFUN (show_ipv6_mbgp_prefix_list,
7371 show_ipv6_mbgp_prefix_list_cmd,
7372 "show ipv6 mbgp prefix-list WORD",
7373 SHOW_STR
7374 IPV6_STR
7375 MBGP_STR
7376 "Display routes matching the prefix-list\n"
7377 "IPv6 prefix-list name\n")
7378{
7379 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7380 bgp_show_type_prefix_list);
7381}
7382#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007383
paul94f2b392005-06-28 12:44:16 +00007384static int
paulfd79ac92004-10-13 05:06:08 +00007385bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007386 safi_t safi, enum bgp_show_type type)
7387{
7388 struct as_list *as_list;
7389
7390 as_list = as_list_lookup (filter);
7391 if (as_list == NULL)
7392 {
7393 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7394 return CMD_WARNING;
7395 }
7396
ajs5a646652004-11-05 01:25:55 +00007397 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007398}
7399
7400DEFUN (show_ip_bgp_filter_list,
7401 show_ip_bgp_filter_list_cmd,
7402 "show ip bgp filter-list WORD",
7403 SHOW_STR
7404 IP_STR
7405 BGP_STR
7406 "Display routes conforming to the filter-list\n"
7407 "Regular expression access list name\n")
7408{
7409 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7410 bgp_show_type_filter_list);
7411}
7412
7413DEFUN (show_ip_bgp_flap_filter_list,
7414 show_ip_bgp_flap_filter_list_cmd,
7415 "show ip bgp flap-statistics filter-list WORD",
7416 SHOW_STR
7417 IP_STR
7418 BGP_STR
7419 "Display flap statistics of routes\n"
7420 "Display routes conforming to the filter-list\n"
7421 "Regular expression access list name\n")
7422{
7423 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7424 bgp_show_type_flap_filter_list);
7425}
7426
7427DEFUN (show_ip_bgp_ipv4_filter_list,
7428 show_ip_bgp_ipv4_filter_list_cmd,
7429 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7430 SHOW_STR
7431 IP_STR
7432 BGP_STR
7433 "Address family\n"
7434 "Address Family modifier\n"
7435 "Address Family modifier\n"
7436 "Display routes conforming to the filter-list\n"
7437 "Regular expression access list name\n")
7438{
7439 if (strncmp (argv[0], "m", 1) == 0)
7440 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7441 bgp_show_type_filter_list);
7442
7443 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7444 bgp_show_type_filter_list);
7445}
7446
7447#ifdef HAVE_IPV6
7448DEFUN (show_bgp_filter_list,
7449 show_bgp_filter_list_cmd,
7450 "show bgp filter-list WORD",
7451 SHOW_STR
7452 BGP_STR
7453 "Display routes conforming to the filter-list\n"
7454 "Regular expression access list name\n")
7455{
7456 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7457 bgp_show_type_filter_list);
7458}
7459
7460ALIAS (show_bgp_filter_list,
7461 show_bgp_ipv6_filter_list_cmd,
7462 "show bgp ipv6 filter-list WORD",
7463 SHOW_STR
7464 BGP_STR
7465 "Address family\n"
7466 "Display routes conforming to the filter-list\n"
7467 "Regular expression access list name\n")
7468
7469/* old command */
7470DEFUN (show_ipv6_bgp_filter_list,
7471 show_ipv6_bgp_filter_list_cmd,
7472 "show ipv6 bgp filter-list WORD",
7473 SHOW_STR
7474 IPV6_STR
7475 BGP_STR
7476 "Display routes conforming to the filter-list\n"
7477 "Regular expression access list name\n")
7478{
7479 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7480 bgp_show_type_filter_list);
7481}
7482
7483/* old command */
7484DEFUN (show_ipv6_mbgp_filter_list,
7485 show_ipv6_mbgp_filter_list_cmd,
7486 "show ipv6 mbgp filter-list WORD",
7487 SHOW_STR
7488 IPV6_STR
7489 MBGP_STR
7490 "Display routes conforming to the filter-list\n"
7491 "Regular expression access list name\n")
7492{
7493 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7494 bgp_show_type_filter_list);
7495}
7496#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007497
paul94f2b392005-06-28 12:44:16 +00007498static int
paulfd79ac92004-10-13 05:06:08 +00007499bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007500 safi_t safi, enum bgp_show_type type)
7501{
7502 struct route_map *rmap;
7503
7504 rmap = route_map_lookup_by_name (rmap_str);
7505 if (! rmap)
7506 {
7507 vty_out (vty, "%% %s is not a valid route-map name%s",
7508 rmap_str, VTY_NEWLINE);
7509 return CMD_WARNING;
7510 }
7511
ajs5a646652004-11-05 01:25:55 +00007512 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007513}
7514
7515DEFUN (show_ip_bgp_route_map,
7516 show_ip_bgp_route_map_cmd,
7517 "show ip bgp route-map WORD",
7518 SHOW_STR
7519 IP_STR
7520 BGP_STR
7521 "Display routes matching the route-map\n"
7522 "A route-map to match on\n")
7523{
7524 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7525 bgp_show_type_route_map);
7526}
7527
7528DEFUN (show_ip_bgp_flap_route_map,
7529 show_ip_bgp_flap_route_map_cmd,
7530 "show ip bgp flap-statistics route-map WORD",
7531 SHOW_STR
7532 IP_STR
7533 BGP_STR
7534 "Display flap statistics of routes\n"
7535 "Display routes matching the route-map\n"
7536 "A route-map to match on\n")
7537{
7538 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7539 bgp_show_type_flap_route_map);
7540}
7541
7542DEFUN (show_ip_bgp_ipv4_route_map,
7543 show_ip_bgp_ipv4_route_map_cmd,
7544 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7545 SHOW_STR
7546 IP_STR
7547 BGP_STR
7548 "Address family\n"
7549 "Address Family modifier\n"
7550 "Address Family modifier\n"
7551 "Display routes matching the route-map\n"
7552 "A route-map to match on\n")
7553{
7554 if (strncmp (argv[0], "m", 1) == 0)
7555 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7556 bgp_show_type_route_map);
7557
7558 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7559 bgp_show_type_route_map);
7560}
7561
7562DEFUN (show_bgp_route_map,
7563 show_bgp_route_map_cmd,
7564 "show bgp route-map WORD",
7565 SHOW_STR
7566 BGP_STR
7567 "Display routes matching the route-map\n"
7568 "A route-map to match on\n")
7569{
7570 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7571 bgp_show_type_route_map);
7572}
7573
7574ALIAS (show_bgp_route_map,
7575 show_bgp_ipv6_route_map_cmd,
7576 "show bgp ipv6 route-map WORD",
7577 SHOW_STR
7578 BGP_STR
7579 "Address family\n"
7580 "Display routes matching the route-map\n"
7581 "A route-map to match on\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02007582
paul718e3742002-12-13 20:15:29 +00007583DEFUN (show_ip_bgp_cidr_only,
7584 show_ip_bgp_cidr_only_cmd,
7585 "show ip bgp cidr-only",
7586 SHOW_STR
7587 IP_STR
7588 BGP_STR
7589 "Display only routes with non-natural netmasks\n")
7590{
7591 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007592 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007593}
7594
7595DEFUN (show_ip_bgp_flap_cidr_only,
7596 show_ip_bgp_flap_cidr_only_cmd,
7597 "show ip bgp flap-statistics cidr-only",
7598 SHOW_STR
7599 IP_STR
7600 BGP_STR
7601 "Display flap statistics of routes\n"
7602 "Display only routes with non-natural netmasks\n")
7603{
7604 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007605 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007606}
7607
7608DEFUN (show_ip_bgp_ipv4_cidr_only,
7609 show_ip_bgp_ipv4_cidr_only_cmd,
7610 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7611 SHOW_STR
7612 IP_STR
7613 BGP_STR
7614 "Address family\n"
7615 "Address Family modifier\n"
7616 "Address Family modifier\n"
7617 "Display only routes with non-natural netmasks\n")
7618{
7619 if (strncmp (argv[0], "m", 1) == 0)
7620 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007621 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007622
7623 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007624 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007625}
David Lamparter6b0655a2014-06-04 06:53:35 +02007626
paul718e3742002-12-13 20:15:29 +00007627DEFUN (show_ip_bgp_community_all,
7628 show_ip_bgp_community_all_cmd,
7629 "show ip bgp community",
7630 SHOW_STR
7631 IP_STR
7632 BGP_STR
7633 "Display routes matching the communities\n")
7634{
7635 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007636 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007637}
7638
7639DEFUN (show_ip_bgp_ipv4_community_all,
7640 show_ip_bgp_ipv4_community_all_cmd,
7641 "show ip bgp ipv4 (unicast|multicast) community",
7642 SHOW_STR
7643 IP_STR
7644 BGP_STR
7645 "Address family\n"
7646 "Address Family modifier\n"
7647 "Address Family modifier\n"
7648 "Display routes matching the communities\n")
7649{
7650 if (strncmp (argv[0], "m", 1) == 0)
7651 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007652 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007653
7654 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007655 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007656}
7657
7658#ifdef HAVE_IPV6
7659DEFUN (show_bgp_community_all,
7660 show_bgp_community_all_cmd,
7661 "show bgp community",
7662 SHOW_STR
7663 BGP_STR
7664 "Display routes matching the communities\n")
7665{
7666 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007667 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007668}
7669
7670ALIAS (show_bgp_community_all,
7671 show_bgp_ipv6_community_all_cmd,
7672 "show bgp ipv6 community",
7673 SHOW_STR
7674 BGP_STR
7675 "Address family\n"
7676 "Display routes matching the communities\n")
7677
7678/* old command */
7679DEFUN (show_ipv6_bgp_community_all,
7680 show_ipv6_bgp_community_all_cmd,
7681 "show ipv6 bgp community",
7682 SHOW_STR
7683 IPV6_STR
7684 BGP_STR
7685 "Display routes matching the communities\n")
7686{
7687 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007688 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007689}
7690
7691/* old command */
7692DEFUN (show_ipv6_mbgp_community_all,
7693 show_ipv6_mbgp_community_all_cmd,
7694 "show ipv6 mbgp community",
7695 SHOW_STR
7696 IPV6_STR
7697 MBGP_STR
7698 "Display routes matching the communities\n")
7699{
7700 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007701 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007702}
7703#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007704
paul94f2b392005-06-28 12:44:16 +00007705static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007706bgp_show_community (struct vty *vty, const char *view_name, int argc,
7707 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007708{
7709 struct community *com;
7710 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007711 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007712 int i;
7713 char *str;
7714 int first = 0;
7715
Michael Lambert95cbbd22010-07-23 14:43:04 -04007716 /* BGP structure lookup */
7717 if (view_name)
7718 {
7719 bgp = bgp_lookup_by_name (view_name);
7720 if (bgp == NULL)
7721 {
7722 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7723 return CMD_WARNING;
7724 }
7725 }
7726 else
7727 {
7728 bgp = bgp_get_default ();
7729 if (bgp == NULL)
7730 {
7731 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7732 return CMD_WARNING;
7733 }
7734 }
7735
paul718e3742002-12-13 20:15:29 +00007736 b = buffer_new (1024);
7737 for (i = 0; i < argc; i++)
7738 {
7739 if (first)
7740 buffer_putc (b, ' ');
7741 else
7742 {
7743 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7744 continue;
7745 first = 1;
7746 }
7747
7748 buffer_putstr (b, argv[i]);
7749 }
7750 buffer_putc (b, '\0');
7751
7752 str = buffer_getstr (b);
7753 buffer_free (b);
7754
7755 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007756 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007757 if (! com)
7758 {
7759 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7760 return CMD_WARNING;
7761 }
7762
Michael Lambert95cbbd22010-07-23 14:43:04 -04007763 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007764 (exact ? bgp_show_type_community_exact :
7765 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007766}
7767
7768DEFUN (show_ip_bgp_community,
7769 show_ip_bgp_community_cmd,
7770 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7771 SHOW_STR
7772 IP_STR
7773 BGP_STR
7774 "Display routes matching the communities\n"
7775 "community number\n"
7776 "Do not send outside local AS (well-known community)\n"
7777 "Do not advertise to any peer (well-known community)\n"
7778 "Do not export to next AS (well-known community)\n")
7779{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007780 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007781}
7782
7783ALIAS (show_ip_bgp_community,
7784 show_ip_bgp_community2_cmd,
7785 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7786 SHOW_STR
7787 IP_STR
7788 BGP_STR
7789 "Display routes matching the communities\n"
7790 "community number\n"
7791 "Do not send outside local AS (well-known community)\n"
7792 "Do not advertise to any peer (well-known community)\n"
7793 "Do not export to next AS (well-known community)\n"
7794 "community number\n"
7795 "Do not send outside local AS (well-known community)\n"
7796 "Do not advertise to any peer (well-known community)\n"
7797 "Do not export to next AS (well-known community)\n")
7798
7799ALIAS (show_ip_bgp_community,
7800 show_ip_bgp_community3_cmd,
7801 "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)",
7802 SHOW_STR
7803 IP_STR
7804 BGP_STR
7805 "Display routes matching the communities\n"
7806 "community number\n"
7807 "Do not send outside local AS (well-known community)\n"
7808 "Do not advertise to any peer (well-known community)\n"
7809 "Do not export to next AS (well-known community)\n"
7810 "community number\n"
7811 "Do not send outside local AS (well-known community)\n"
7812 "Do not advertise to any peer (well-known community)\n"
7813 "Do not export to next AS (well-known community)\n"
7814 "community number\n"
7815 "Do not send outside local AS (well-known community)\n"
7816 "Do not advertise to any peer (well-known community)\n"
7817 "Do not export to next AS (well-known community)\n")
7818
7819ALIAS (show_ip_bgp_community,
7820 show_ip_bgp_community4_cmd,
7821 "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)",
7822 SHOW_STR
7823 IP_STR
7824 BGP_STR
7825 "Display routes matching the communities\n"
7826 "community number\n"
7827 "Do not send outside local AS (well-known community)\n"
7828 "Do not advertise to any peer (well-known community)\n"
7829 "Do not export to next AS (well-known community)\n"
7830 "community number\n"
7831 "Do not send outside local AS (well-known community)\n"
7832 "Do not advertise to any peer (well-known community)\n"
7833 "Do not export to next AS (well-known community)\n"
7834 "community number\n"
7835 "Do not send outside local AS (well-known community)\n"
7836 "Do not advertise to any peer (well-known community)\n"
7837 "Do not export to next AS (well-known community)\n"
7838 "community number\n"
7839 "Do not send outside local AS (well-known community)\n"
7840 "Do not advertise to any peer (well-known community)\n"
7841 "Do not export to next AS (well-known community)\n")
7842
7843DEFUN (show_ip_bgp_ipv4_community,
7844 show_ip_bgp_ipv4_community_cmd,
7845 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7846 SHOW_STR
7847 IP_STR
7848 BGP_STR
7849 "Address family\n"
7850 "Address Family modifier\n"
7851 "Address Family modifier\n"
7852 "Display routes matching the communities\n"
7853 "community number\n"
7854 "Do not send outside local AS (well-known community)\n"
7855 "Do not advertise to any peer (well-known community)\n"
7856 "Do not export to next AS (well-known community)\n")
7857{
7858 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007859 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007860
Michael Lambert95cbbd22010-07-23 14:43:04 -04007861 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007862}
7863
7864ALIAS (show_ip_bgp_ipv4_community,
7865 show_ip_bgp_ipv4_community2_cmd,
7866 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7867 SHOW_STR
7868 IP_STR
7869 BGP_STR
7870 "Address family\n"
7871 "Address Family modifier\n"
7872 "Address Family modifier\n"
7873 "Display routes matching the communities\n"
7874 "community number\n"
7875 "Do not send outside local AS (well-known community)\n"
7876 "Do not advertise to any peer (well-known community)\n"
7877 "Do not export to next AS (well-known community)\n"
7878 "community number\n"
7879 "Do not send outside local AS (well-known community)\n"
7880 "Do not advertise to any peer (well-known community)\n"
7881 "Do not export to next AS (well-known community)\n")
7882
7883ALIAS (show_ip_bgp_ipv4_community,
7884 show_ip_bgp_ipv4_community3_cmd,
7885 "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)",
7886 SHOW_STR
7887 IP_STR
7888 BGP_STR
7889 "Address family\n"
7890 "Address Family modifier\n"
7891 "Address Family modifier\n"
7892 "Display routes matching the communities\n"
7893 "community number\n"
7894 "Do not send outside local AS (well-known community)\n"
7895 "Do not advertise to any peer (well-known community)\n"
7896 "Do not export to next AS (well-known community)\n"
7897 "community number\n"
7898 "Do not send outside local AS (well-known community)\n"
7899 "Do not advertise to any peer (well-known community)\n"
7900 "Do not export to next AS (well-known community)\n"
7901 "community number\n"
7902 "Do not send outside local AS (well-known community)\n"
7903 "Do not advertise to any peer (well-known community)\n"
7904 "Do not export to next AS (well-known community)\n")
7905
7906ALIAS (show_ip_bgp_ipv4_community,
7907 show_ip_bgp_ipv4_community4_cmd,
7908 "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)",
7909 SHOW_STR
7910 IP_STR
7911 BGP_STR
7912 "Address family\n"
7913 "Address Family modifier\n"
7914 "Address Family modifier\n"
7915 "Display routes matching the communities\n"
7916 "community number\n"
7917 "Do not send outside local AS (well-known community)\n"
7918 "Do not advertise to any peer (well-known community)\n"
7919 "Do not export to next AS (well-known community)\n"
7920 "community number\n"
7921 "Do not send outside local AS (well-known community)\n"
7922 "Do not advertise to any peer (well-known community)\n"
7923 "Do not export to next AS (well-known community)\n"
7924 "community number\n"
7925 "Do not send outside local AS (well-known community)\n"
7926 "Do not advertise to any peer (well-known community)\n"
7927 "Do not export to next AS (well-known community)\n"
7928 "community number\n"
7929 "Do not send outside local AS (well-known community)\n"
7930 "Do not advertise to any peer (well-known community)\n"
7931 "Do not export to next AS (well-known community)\n")
7932
Michael Lambert95cbbd22010-07-23 14:43:04 -04007933DEFUN (show_bgp_view_afi_safi_community_all,
7934 show_bgp_view_afi_safi_community_all_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04007935 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007936 SHOW_STR
7937 BGP_STR
7938 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007939 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007940 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007941 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007942 "Address Family modifier\n"
7943 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00007944 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007945{
7946 int afi;
7947 int safi;
7948 struct bgp *bgp;
7949
7950 /* BGP structure lookup. */
7951 bgp = bgp_lookup_by_name (argv[0]);
7952 if (bgp == NULL)
7953 {
7954 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7955 return CMD_WARNING;
7956 }
7957
Michael Lambert95cbbd22010-07-23 14:43:04 -04007958 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7959 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007960 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7961}
7962
7963DEFUN (show_bgp_view_afi_safi_community,
7964 show_bgp_view_afi_safi_community_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04007965 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007966 SHOW_STR
7967 BGP_STR
7968 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007969 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007970 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007971 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007972 "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
Michael Lambert95cbbd22010-07-23 14:43:04 -04007983 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7984 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7985 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007986}
7987
7988ALIAS (show_bgp_view_afi_safi_community,
7989 show_bgp_view_afi_safi_community2_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04007990 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007991 SHOW_STR
7992 BGP_STR
7993 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007994 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007995 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007996 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007997 "Address family modifier\n"
7998 "Address family modifier\n"
7999 "Display routes matching the communities\n"
8000 "community number\n"
8001 "Do not send outside local AS (well-known community)\n"
8002 "Do not advertise to any peer (well-known community)\n"
8003 "Do not export to next AS (well-known community)\n"
8004 "community number\n"
8005 "Do not send outside local AS (well-known community)\n"
8006 "Do not advertise to any peer (well-known community)\n"
8007 "Do not export to next AS (well-known community)\n")
8008
8009ALIAS (show_bgp_view_afi_safi_community,
8010 show_bgp_view_afi_safi_community3_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008011 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008012 SHOW_STR
8013 BGP_STR
8014 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008015 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008016 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008017 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008018 "Address family modifier\n"
8019 "Address family modifier\n"
8020 "Display routes matching the communities\n"
8021 "community number\n"
8022 "Do not send outside local AS (well-known community)\n"
8023 "Do not advertise to any peer (well-known community)\n"
8024 "Do not export to next AS (well-known community)\n"
8025 "community number\n"
8026 "Do not send outside local AS (well-known community)\n"
8027 "Do not advertise to any peer (well-known community)\n"
8028 "Do not export to next AS (well-known community)\n"
8029 "community number\n"
8030 "Do not send outside local AS (well-known community)\n"
8031 "Do not advertise to any peer (well-known community)\n"
8032 "Do not export to next AS (well-known community)\n")
8033
8034ALIAS (show_bgp_view_afi_safi_community,
8035 show_bgp_view_afi_safi_community4_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008036 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008037 SHOW_STR
8038 BGP_STR
8039 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008040 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008041 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008042 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008043 "Address family modifier\n"
8044 "Address family modifier\n"
8045 "Display routes matching the communities\n"
8046 "community number\n"
8047 "Do not send outside local AS (well-known community)\n"
8048 "Do not advertise to any peer (well-known community)\n"
8049 "Do not export to next AS (well-known community)\n"
8050 "community number\n"
8051 "Do not send outside local AS (well-known community)\n"
8052 "Do not advertise to any peer (well-known community)\n"
8053 "Do not export to next AS (well-known community)\n"
8054 "community number\n"
8055 "Do not send outside local AS (well-known community)\n"
8056 "Do not advertise to any peer (well-known community)\n"
8057 "Do not export to next AS (well-known community)\n"
8058 "community number\n"
8059 "Do not send outside local AS (well-known community)\n"
8060 "Do not advertise to any peer (well-known community)\n"
8061 "Do not export to next AS (well-known community)\n")
8062
paul718e3742002-12-13 20:15:29 +00008063DEFUN (show_ip_bgp_community_exact,
8064 show_ip_bgp_community_exact_cmd,
8065 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8066 SHOW_STR
8067 IP_STR
8068 BGP_STR
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 "Exact match of the communities")
8075{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008076 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008077}
8078
8079ALIAS (show_ip_bgp_community_exact,
8080 show_ip_bgp_community2_exact_cmd,
8081 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8082 SHOW_STR
8083 IP_STR
8084 BGP_STR
8085 "Display routes matching the communities\n"
8086 "community number\n"
8087 "Do not send outside local AS (well-known community)\n"
8088 "Do not advertise to any peer (well-known community)\n"
8089 "Do not export to next AS (well-known community)\n"
8090 "community number\n"
8091 "Do not send outside local AS (well-known community)\n"
8092 "Do not advertise to any peer (well-known community)\n"
8093 "Do not export to next AS (well-known community)\n"
8094 "Exact match of the communities")
8095
8096ALIAS (show_ip_bgp_community_exact,
8097 show_ip_bgp_community3_exact_cmd,
8098 "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",
8099 SHOW_STR
8100 IP_STR
8101 BGP_STR
8102 "Display routes matching the communities\n"
8103 "community number\n"
8104 "Do not send outside local AS (well-known community)\n"
8105 "Do not advertise to any peer (well-known community)\n"
8106 "Do not export to next AS (well-known community)\n"
8107 "community number\n"
8108 "Do not send outside local AS (well-known community)\n"
8109 "Do not advertise to any peer (well-known community)\n"
8110 "Do not export to next AS (well-known community)\n"
8111 "community number\n"
8112 "Do not send outside local AS (well-known community)\n"
8113 "Do not advertise to any peer (well-known community)\n"
8114 "Do not export to next AS (well-known community)\n"
8115 "Exact match of the communities")
8116
8117ALIAS (show_ip_bgp_community_exact,
8118 show_ip_bgp_community4_exact_cmd,
8119 "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",
8120 SHOW_STR
8121 IP_STR
8122 BGP_STR
8123 "Display routes matching the communities\n"
8124 "community number\n"
8125 "Do not send outside local AS (well-known community)\n"
8126 "Do not advertise to any peer (well-known community)\n"
8127 "Do not export to next AS (well-known community)\n"
8128 "community number\n"
8129 "Do not send outside local AS (well-known community)\n"
8130 "Do not advertise to any peer (well-known community)\n"
8131 "Do not export to next AS (well-known community)\n"
8132 "community number\n"
8133 "Do not send outside local AS (well-known community)\n"
8134 "Do not advertise to any peer (well-known community)\n"
8135 "Do not export to next AS (well-known community)\n"
8136 "community number\n"
8137 "Do not send outside local AS (well-known community)\n"
8138 "Do not advertise to any peer (well-known community)\n"
8139 "Do not export to next AS (well-known community)\n"
8140 "Exact match of the communities")
8141
8142DEFUN (show_ip_bgp_ipv4_community_exact,
8143 show_ip_bgp_ipv4_community_exact_cmd,
8144 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8145 SHOW_STR
8146 IP_STR
8147 BGP_STR
8148 "Address family\n"
8149 "Address Family modifier\n"
8150 "Address Family modifier\n"
8151 "Display routes matching the communities\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 "Exact match of the communities")
8157{
8158 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008159 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008160
Michael Lambert95cbbd22010-07-23 14:43:04 -04008161 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008162}
8163
8164ALIAS (show_ip_bgp_ipv4_community_exact,
8165 show_ip_bgp_ipv4_community2_exact_cmd,
8166 "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",
8167 SHOW_STR
8168 IP_STR
8169 BGP_STR
8170 "Address family\n"
8171 "Address Family modifier\n"
8172 "Address Family modifier\n"
8173 "Display routes matching the communities\n"
8174 "community number\n"
8175 "Do not send outside local AS (well-known community)\n"
8176 "Do not advertise to any peer (well-known community)\n"
8177 "Do not export to next AS (well-known community)\n"
8178 "community number\n"
8179 "Do not send outside local AS (well-known community)\n"
8180 "Do not advertise to any peer (well-known community)\n"
8181 "Do not export to next AS (well-known community)\n"
8182 "Exact match of the communities")
8183
8184ALIAS (show_ip_bgp_ipv4_community_exact,
8185 show_ip_bgp_ipv4_community3_exact_cmd,
8186 "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",
8187 SHOW_STR
8188 IP_STR
8189 BGP_STR
8190 "Address family\n"
8191 "Address Family modifier\n"
8192 "Address Family modifier\n"
8193 "Display routes matching the communities\n"
8194 "community number\n"
8195 "Do not send outside local AS (well-known community)\n"
8196 "Do not advertise to any peer (well-known community)\n"
8197 "Do not export to next AS (well-known community)\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_community4_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) (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 "community number\n"
8231 "Do not send outside local AS (well-known community)\n"
8232 "Do not advertise to any peer (well-known community)\n"
8233 "Do not export to next AS (well-known community)\n"
8234 "Exact match of the communities")
8235
8236#ifdef HAVE_IPV6
8237DEFUN (show_bgp_community,
8238 show_bgp_community_cmd,
8239 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8240 SHOW_STR
8241 BGP_STR
8242 "Display routes matching the communities\n"
8243 "community number\n"
8244 "Do not send outside local AS (well-known community)\n"
8245 "Do not advertise to any peer (well-known community)\n"
8246 "Do not export to next AS (well-known community)\n")
8247{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008248 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008249}
8250
8251ALIAS (show_bgp_community,
8252 show_bgp_ipv6_community_cmd,
8253 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8254 SHOW_STR
8255 BGP_STR
8256 "Address family\n"
8257 "Display routes matching the communities\n"
8258 "community number\n"
8259 "Do not send outside local AS (well-known community)\n"
8260 "Do not advertise to any peer (well-known community)\n"
8261 "Do not export to next AS (well-known community)\n")
8262
8263ALIAS (show_bgp_community,
8264 show_bgp_community2_cmd,
8265 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8266 SHOW_STR
8267 BGP_STR
8268 "Display routes matching the communities\n"
8269 "community number\n"
8270 "Do not send outside local AS (well-known community)\n"
8271 "Do not advertise to any peer (well-known community)\n"
8272 "Do not export to next AS (well-known community)\n"
8273 "community number\n"
8274 "Do not send outside local AS (well-known community)\n"
8275 "Do not advertise to any peer (well-known community)\n"
8276 "Do not export to next AS (well-known community)\n")
8277
8278ALIAS (show_bgp_community,
8279 show_bgp_ipv6_community2_cmd,
8280 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8281 SHOW_STR
8282 BGP_STR
8283 "Address family\n"
8284 "Display routes matching the communities\n"
8285 "community number\n"
8286 "Do not send outside local AS (well-known community)\n"
8287 "Do not advertise to any peer (well-known community)\n"
8288 "Do not export to next AS (well-known community)\n"
8289 "community number\n"
8290 "Do not send outside local AS (well-known community)\n"
8291 "Do not advertise to any peer (well-known community)\n"
8292 "Do not export to next AS (well-known community)\n")
8293
8294ALIAS (show_bgp_community,
8295 show_bgp_community3_cmd,
8296 "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)",
8297 SHOW_STR
8298 BGP_STR
8299 "Display routes matching the communities\n"
8300 "community number\n"
8301 "Do not send outside local AS (well-known community)\n"
8302 "Do not advertise to any peer (well-known community)\n"
8303 "Do not export to next AS (well-known community)\n"
8304 "community number\n"
8305 "Do not send outside local AS (well-known community)\n"
8306 "Do not advertise to any peer (well-known community)\n"
8307 "Do not export to next AS (well-known community)\n"
8308 "community number\n"
8309 "Do not send outside local AS (well-known community)\n"
8310 "Do not advertise to any peer (well-known community)\n"
8311 "Do not export to next AS (well-known community)\n")
8312
8313ALIAS (show_bgp_community,
8314 show_bgp_ipv6_community3_cmd,
8315 "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)",
8316 SHOW_STR
8317 BGP_STR
8318 "Address family\n"
8319 "Display routes matching the communities\n"
8320 "community number\n"
8321 "Do not send outside local AS (well-known community)\n"
8322 "Do not advertise to any peer (well-known community)\n"
8323 "Do not export to next AS (well-known community)\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
8333ALIAS (show_bgp_community,
8334 show_bgp_community4_cmd,
8335 "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)",
8336 SHOW_STR
8337 BGP_STR
8338 "Display routes matching the communities\n"
8339 "community number\n"
8340 "Do not send outside local AS (well-known community)\n"
8341 "Do not advertise to any peer (well-known community)\n"
8342 "Do not export to next AS (well-known community)\n"
8343 "community number\n"
8344 "Do not send outside local AS (well-known community)\n"
8345 "Do not advertise to any peer (well-known community)\n"
8346 "Do not export to next AS (well-known community)\n"
8347 "community number\n"
8348 "Do not send outside local AS (well-known community)\n"
8349 "Do not advertise to any peer (well-known community)\n"
8350 "Do not export to next AS (well-known community)\n"
8351 "community number\n"
8352 "Do not send outside local AS (well-known community)\n"
8353 "Do not advertise to any peer (well-known community)\n"
8354 "Do not export to next AS (well-known community)\n")
8355
8356ALIAS (show_bgp_community,
8357 show_bgp_ipv6_community4_cmd,
8358 "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)",
8359 SHOW_STR
8360 BGP_STR
8361 "Address family\n"
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
8380/* old command */
8381DEFUN (show_ipv6_bgp_community,
8382 show_ipv6_bgp_community_cmd,
8383 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8384 SHOW_STR
8385 IPV6_STR
8386 BGP_STR
8387 "Display routes matching the communities\n"
8388 "community number\n"
8389 "Do not send outside local AS (well-known community)\n"
8390 "Do not advertise to any peer (well-known community)\n"
8391 "Do not export to next AS (well-known community)\n")
8392{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008393 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008394}
8395
8396/* old command */
8397ALIAS (show_ipv6_bgp_community,
8398 show_ipv6_bgp_community2_cmd,
8399 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8400 SHOW_STR
8401 IPV6_STR
8402 BGP_STR
8403 "Display routes matching the communities\n"
8404 "community number\n"
8405 "Do not send outside local AS (well-known community)\n"
8406 "Do not advertise to any peer (well-known community)\n"
8407 "Do not export to next AS (well-known community)\n"
8408 "community number\n"
8409 "Do not send outside local AS (well-known community)\n"
8410 "Do not advertise to any peer (well-known community)\n"
8411 "Do not export to next AS (well-known community)\n")
8412
8413/* old command */
8414ALIAS (show_ipv6_bgp_community,
8415 show_ipv6_bgp_community3_cmd,
8416 "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)",
8417 SHOW_STR
8418 IPV6_STR
8419 BGP_STR
8420 "Display routes matching the communities\n"
8421 "community number\n"
8422 "Do not send outside local AS (well-known community)\n"
8423 "Do not advertise to any peer (well-known community)\n"
8424 "Do not export to next AS (well-known community)\n"
8425 "community number\n"
8426 "Do not send outside local AS (well-known community)\n"
8427 "Do not advertise to any peer (well-known community)\n"
8428 "Do not export to next AS (well-known community)\n"
8429 "community number\n"
8430 "Do not send outside local AS (well-known community)\n"
8431 "Do not advertise to any peer (well-known community)\n"
8432 "Do not export to next AS (well-known community)\n")
8433
8434/* old command */
8435ALIAS (show_ipv6_bgp_community,
8436 show_ipv6_bgp_community4_cmd,
8437 "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)",
8438 SHOW_STR
8439 IPV6_STR
8440 BGP_STR
8441 "Display routes matching the communities\n"
8442 "community number\n"
8443 "Do not send outside local AS (well-known community)\n"
8444 "Do not advertise to any peer (well-known community)\n"
8445 "Do not export to next AS (well-known community)\n"
8446 "community number\n"
8447 "Do not send outside local AS (well-known community)\n"
8448 "Do not advertise to any peer (well-known community)\n"
8449 "Do not export to next AS (well-known community)\n"
8450 "community number\n"
8451 "Do not send outside local AS (well-known community)\n"
8452 "Do not advertise to any peer (well-known community)\n"
8453 "Do not export to next AS (well-known community)\n"
8454 "community number\n"
8455 "Do not send outside local AS (well-known community)\n"
8456 "Do not advertise to any peer (well-known community)\n"
8457 "Do not export to next AS (well-known community)\n")
8458
8459DEFUN (show_bgp_community_exact,
8460 show_bgp_community_exact_cmd,
8461 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8462 SHOW_STR
8463 BGP_STR
8464 "Display routes matching the communities\n"
8465 "community number\n"
8466 "Do not send outside local AS (well-known community)\n"
8467 "Do not advertise to any peer (well-known community)\n"
8468 "Do not export to next AS (well-known community)\n"
8469 "Exact match of the communities")
8470{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008471 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008472}
8473
8474ALIAS (show_bgp_community_exact,
8475 show_bgp_ipv6_community_exact_cmd,
8476 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8477 SHOW_STR
8478 BGP_STR
8479 "Address family\n"
8480 "Display routes matching the communities\n"
8481 "community number\n"
8482 "Do not send outside local AS (well-known community)\n"
8483 "Do not advertise to any peer (well-known community)\n"
8484 "Do not export to next AS (well-known community)\n"
8485 "Exact match of the communities")
8486
8487ALIAS (show_bgp_community_exact,
8488 show_bgp_community2_exact_cmd,
8489 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8490 SHOW_STR
8491 BGP_STR
8492 "Display routes matching the communities\n"
8493 "community number\n"
8494 "Do not send outside local AS (well-known community)\n"
8495 "Do not advertise to any peer (well-known community)\n"
8496 "Do not export to next AS (well-known community)\n"
8497 "community number\n"
8498 "Do not send outside local AS (well-known community)\n"
8499 "Do not advertise to any peer (well-known community)\n"
8500 "Do not export to next AS (well-known community)\n"
8501 "Exact match of the communities")
8502
8503ALIAS (show_bgp_community_exact,
8504 show_bgp_ipv6_community2_exact_cmd,
8505 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8506 SHOW_STR
8507 BGP_STR
8508 "Address family\n"
8509 "Display routes matching the communities\n"
8510 "community number\n"
8511 "Do not send outside local AS (well-known community)\n"
8512 "Do not advertise to any peer (well-known community)\n"
8513 "Do not export to next AS (well-known community)\n"
8514 "community number\n"
8515 "Do not send outside local AS (well-known community)\n"
8516 "Do not advertise to any peer (well-known community)\n"
8517 "Do not export to next AS (well-known community)\n"
8518 "Exact match of the communities")
8519
8520ALIAS (show_bgp_community_exact,
8521 show_bgp_community3_exact_cmd,
8522 "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",
8523 SHOW_STR
8524 BGP_STR
8525 "Display routes matching the communities\n"
8526 "community number\n"
8527 "Do not send outside local AS (well-known community)\n"
8528 "Do not advertise to any peer (well-known community)\n"
8529 "Do not export to next AS (well-known community)\n"
8530 "community number\n"
8531 "Do not send outside local AS (well-known community)\n"
8532 "Do not advertise to any peer (well-known community)\n"
8533 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8539
8540ALIAS (show_bgp_community_exact,
8541 show_bgp_ipv6_community3_exact_cmd,
8542 "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",
8543 SHOW_STR
8544 BGP_STR
8545 "Address family\n"
8546 "Display routes matching the communities\n"
8547 "community number\n"
8548 "Do not send outside local AS (well-known community)\n"
8549 "Do not advertise to any peer (well-known community)\n"
8550 "Do not export to next AS (well-known community)\n"
8551 "community number\n"
8552 "Do not send outside local AS (well-known community)\n"
8553 "Do not advertise to any peer (well-known community)\n"
8554 "Do not export to next AS (well-known community)\n"
8555 "community number\n"
8556 "Do not send outside local AS (well-known community)\n"
8557 "Do not advertise to any peer (well-known community)\n"
8558 "Do not export to next AS (well-known community)\n"
8559 "Exact match of the communities")
8560
8561ALIAS (show_bgp_community_exact,
8562 show_bgp_community4_exact_cmd,
8563 "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",
8564 SHOW_STR
8565 BGP_STR
8566 "Display routes matching the communities\n"
8567 "community number\n"
8568 "Do not send outside local AS (well-known community)\n"
8569 "Do not advertise to any peer (well-known community)\n"
8570 "Do not export to next AS (well-known community)\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_ipv6_community4_exact_cmd,
8587 "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",
8588 SHOW_STR
8589 BGP_STR
8590 "Address family\n"
8591 "Display routes matching the communities\n"
8592 "community number\n"
8593 "Do not send outside local AS (well-known community)\n"
8594 "Do not advertise to any peer (well-known community)\n"
8595 "Do not export to next AS (well-known community)\n"
8596 "community number\n"
8597 "Do not send outside local AS (well-known community)\n"
8598 "Do not advertise to any peer (well-known community)\n"
8599 "Do not export to next AS (well-known community)\n"
8600 "community number\n"
8601 "Do not send outside local AS (well-known community)\n"
8602 "Do not advertise to any peer (well-known community)\n"
8603 "Do not export to next AS (well-known community)\n"
8604 "community number\n"
8605 "Do not send outside local AS (well-known community)\n"
8606 "Do not advertise to any peer (well-known community)\n"
8607 "Do not export to next AS (well-known community)\n"
8608 "Exact match of the communities")
8609
8610/* old command */
8611DEFUN (show_ipv6_bgp_community_exact,
8612 show_ipv6_bgp_community_exact_cmd,
8613 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8614 SHOW_STR
8615 IPV6_STR
8616 BGP_STR
8617 "Display routes matching the communities\n"
8618 "community number\n"
8619 "Do not send outside local AS (well-known community)\n"
8620 "Do not advertise to any peer (well-known community)\n"
8621 "Do not export to next AS (well-known community)\n"
8622 "Exact match of the communities")
8623{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008624 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008625}
8626
8627/* old command */
8628ALIAS (show_ipv6_bgp_community_exact,
8629 show_ipv6_bgp_community2_exact_cmd,
8630 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8631 SHOW_STR
8632 IPV6_STR
8633 BGP_STR
8634 "Display routes matching the communities\n"
8635 "community number\n"
8636 "Do not send outside local AS (well-known community)\n"
8637 "Do not advertise to any peer (well-known community)\n"
8638 "Do not export to next AS (well-known community)\n"
8639 "community number\n"
8640 "Do not send outside local AS (well-known community)\n"
8641 "Do not advertise to any peer (well-known community)\n"
8642 "Do not export to next AS (well-known community)\n"
8643 "Exact match of the communities")
8644
8645/* old command */
8646ALIAS (show_ipv6_bgp_community_exact,
8647 show_ipv6_bgp_community3_exact_cmd,
8648 "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",
8649 SHOW_STR
8650 IPV6_STR
8651 BGP_STR
8652 "Display routes matching the communities\n"
8653 "community number\n"
8654 "Do not send outside local AS (well-known community)\n"
8655 "Do not advertise to any peer (well-known community)\n"
8656 "Do not export to next AS (well-known community)\n"
8657 "community number\n"
8658 "Do not send outside local AS (well-known community)\n"
8659 "Do not advertise to any peer (well-known community)\n"
8660 "Do not export to next AS (well-known community)\n"
8661 "community number\n"
8662 "Do not send outside local AS (well-known community)\n"
8663 "Do not advertise to any peer (well-known community)\n"
8664 "Do not export to next AS (well-known community)\n"
8665 "Exact match of the communities")
8666
8667/* old command */
8668ALIAS (show_ipv6_bgp_community_exact,
8669 show_ipv6_bgp_community4_exact_cmd,
8670 "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",
8671 SHOW_STR
8672 IPV6_STR
8673 BGP_STR
8674 "Display routes matching the communities\n"
8675 "community number\n"
8676 "Do not send outside local AS (well-known community)\n"
8677 "Do not advertise to any peer (well-known community)\n"
8678 "Do not export to next AS (well-known community)\n"
8679 "community number\n"
8680 "Do not send outside local AS (well-known community)\n"
8681 "Do not advertise to any peer (well-known community)\n"
8682 "Do not export to next AS (well-known community)\n"
8683 "community number\n"
8684 "Do not send outside local AS (well-known community)\n"
8685 "Do not advertise to any peer (well-known community)\n"
8686 "Do not export to next AS (well-known community)\n"
8687 "community number\n"
8688 "Do not send outside local AS (well-known community)\n"
8689 "Do not advertise to any peer (well-known community)\n"
8690 "Do not export to next AS (well-known community)\n"
8691 "Exact match of the communities")
8692
8693/* old command */
8694DEFUN (show_ipv6_mbgp_community,
8695 show_ipv6_mbgp_community_cmd,
8696 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8697 SHOW_STR
8698 IPV6_STR
8699 MBGP_STR
8700 "Display routes matching the communities\n"
8701 "community number\n"
8702 "Do not send outside local AS (well-known community)\n"
8703 "Do not advertise to any peer (well-known community)\n"
8704 "Do not export to next AS (well-known community)\n")
8705{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008706 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008707}
8708
8709/* old command */
8710ALIAS (show_ipv6_mbgp_community,
8711 show_ipv6_mbgp_community2_cmd,
8712 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8713 SHOW_STR
8714 IPV6_STR
8715 MBGP_STR
8716 "Display routes matching the communities\n"
8717 "community number\n"
8718 "Do not send outside local AS (well-known community)\n"
8719 "Do not advertise to any peer (well-known community)\n"
8720 "Do not export to next AS (well-known community)\n"
8721 "community number\n"
8722 "Do not send outside local AS (well-known community)\n"
8723 "Do not advertise to any peer (well-known community)\n"
8724 "Do not export to next AS (well-known community)\n")
8725
8726/* old command */
8727ALIAS (show_ipv6_mbgp_community,
8728 show_ipv6_mbgp_community3_cmd,
8729 "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)",
8730 SHOW_STR
8731 IPV6_STR
8732 MBGP_STR
8733 "Display routes matching the communities\n"
8734 "community number\n"
8735 "Do not send outside local AS (well-known community)\n"
8736 "Do not advertise to any peer (well-known community)\n"
8737 "Do not export to next AS (well-known community)\n"
8738 "community number\n"
8739 "Do not send outside local AS (well-known community)\n"
8740 "Do not advertise to any peer (well-known community)\n"
8741 "Do not export to next AS (well-known community)\n"
8742 "community number\n"
8743 "Do not send outside local AS (well-known community)\n"
8744 "Do not advertise to any peer (well-known community)\n"
8745 "Do not export to next AS (well-known community)\n")
8746
8747/* old command */
8748ALIAS (show_ipv6_mbgp_community,
8749 show_ipv6_mbgp_community4_cmd,
8750 "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)",
8751 SHOW_STR
8752 IPV6_STR
8753 MBGP_STR
8754 "Display routes matching the communities\n"
8755 "community number\n"
8756 "Do not send outside local AS (well-known community)\n"
8757 "Do not advertise to any peer (well-known community)\n"
8758 "Do not export to next AS (well-known community)\n"
8759 "community number\n"
8760 "Do not send outside local AS (well-known community)\n"
8761 "Do not advertise to any peer (well-known community)\n"
8762 "Do not export to next AS (well-known community)\n"
8763 "community number\n"
8764 "Do not send outside local AS (well-known community)\n"
8765 "Do not advertise to any peer (well-known community)\n"
8766 "Do not export to next AS (well-known community)\n"
8767 "community number\n"
8768 "Do not send outside local AS (well-known community)\n"
8769 "Do not advertise to any peer (well-known community)\n"
8770 "Do not export to next AS (well-known community)\n")
8771
8772/* old command */
8773DEFUN (show_ipv6_mbgp_community_exact,
8774 show_ipv6_mbgp_community_exact_cmd,
8775 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8776 SHOW_STR
8777 IPV6_STR
8778 MBGP_STR
8779 "Display routes matching the communities\n"
8780 "community number\n"
8781 "Do not send outside local AS (well-known community)\n"
8782 "Do not advertise to any peer (well-known community)\n"
8783 "Do not export to next AS (well-known community)\n"
8784 "Exact match of the communities")
8785{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008786 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008787}
8788
8789/* old command */
8790ALIAS (show_ipv6_mbgp_community_exact,
8791 show_ipv6_mbgp_community2_exact_cmd,
8792 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8793 SHOW_STR
8794 IPV6_STR
8795 MBGP_STR
8796 "Display routes matching the communities\n"
8797 "community number\n"
8798 "Do not send outside local AS (well-known community)\n"
8799 "Do not advertise to any peer (well-known community)\n"
8800 "Do not export to next AS (well-known community)\n"
8801 "community number\n"
8802 "Do not send outside local AS (well-known community)\n"
8803 "Do not advertise to any peer (well-known community)\n"
8804 "Do not export to next AS (well-known community)\n"
8805 "Exact match of the communities")
8806
8807/* old command */
8808ALIAS (show_ipv6_mbgp_community_exact,
8809 show_ipv6_mbgp_community3_exact_cmd,
8810 "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",
8811 SHOW_STR
8812 IPV6_STR
8813 MBGP_STR
8814 "Display routes matching the communities\n"
8815 "community number\n"
8816 "Do not send outside local AS (well-known community)\n"
8817 "Do not advertise to any peer (well-known community)\n"
8818 "Do not export to next AS (well-known community)\n"
8819 "community number\n"
8820 "Do not send outside local AS (well-known community)\n"
8821 "Do not advertise to any peer (well-known community)\n"
8822 "Do not export to next AS (well-known community)\n"
8823 "community number\n"
8824 "Do not send outside local AS (well-known community)\n"
8825 "Do not advertise to any peer (well-known community)\n"
8826 "Do not export to next AS (well-known community)\n"
8827 "Exact match of the communities")
8828
8829/* old command */
8830ALIAS (show_ipv6_mbgp_community_exact,
8831 show_ipv6_mbgp_community4_exact_cmd,
8832 "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",
8833 SHOW_STR
8834 IPV6_STR
8835 MBGP_STR
8836 "Display routes matching the communities\n"
8837 "community number\n"
8838 "Do not send outside local AS (well-known community)\n"
8839 "Do not advertise to any peer (well-known community)\n"
8840 "Do not export to next AS (well-known community)\n"
8841 "community number\n"
8842 "Do not send outside local AS (well-known community)\n"
8843 "Do not advertise to any peer (well-known community)\n"
8844 "Do not export to next AS (well-known community)\n"
8845 "community number\n"
8846 "Do not send outside local AS (well-known community)\n"
8847 "Do not advertise to any peer (well-known community)\n"
8848 "Do not export to next AS (well-known community)\n"
8849 "community number\n"
8850 "Do not send outside local AS (well-known community)\n"
8851 "Do not advertise to any peer (well-known community)\n"
8852 "Do not export to next AS (well-known community)\n"
8853 "Exact match of the communities")
8854#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02008855
paul94f2b392005-06-28 12:44:16 +00008856static int
paulfd79ac92004-10-13 05:06:08 +00008857bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008858 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008859{
8860 struct community_list *list;
8861
hassofee6e4e2005-02-02 16:29:31 +00008862 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008863 if (list == NULL)
8864 {
8865 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8866 VTY_NEWLINE);
8867 return CMD_WARNING;
8868 }
8869
ajs5a646652004-11-05 01:25:55 +00008870 return bgp_show (vty, NULL, afi, safi,
8871 (exact ? bgp_show_type_community_list_exact :
8872 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008873}
8874
8875DEFUN (show_ip_bgp_community_list,
8876 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008877 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008878 SHOW_STR
8879 IP_STR
8880 BGP_STR
8881 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008882 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008883 "community-list name\n")
8884{
8885 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8886}
8887
8888DEFUN (show_ip_bgp_ipv4_community_list,
8889 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008890 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008891 SHOW_STR
8892 IP_STR
8893 BGP_STR
8894 "Address family\n"
8895 "Address Family modifier\n"
8896 "Address Family modifier\n"
8897 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008898 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008899 "community-list name\n")
8900{
8901 if (strncmp (argv[0], "m", 1) == 0)
8902 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8903
8904 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8905}
8906
8907DEFUN (show_ip_bgp_community_list_exact,
8908 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008909 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008910 SHOW_STR
8911 IP_STR
8912 BGP_STR
8913 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008914 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008915 "community-list name\n"
8916 "Exact match of the communities\n")
8917{
8918 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8919}
8920
8921DEFUN (show_ip_bgp_ipv4_community_list_exact,
8922 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008923 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008924 SHOW_STR
8925 IP_STR
8926 BGP_STR
8927 "Address family\n"
8928 "Address Family modifier\n"
8929 "Address Family modifier\n"
8930 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008931 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008932 "community-list name\n"
8933 "Exact match of the communities\n")
8934{
8935 if (strncmp (argv[0], "m", 1) == 0)
8936 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8937
8938 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8939}
8940
8941#ifdef HAVE_IPV6
8942DEFUN (show_bgp_community_list,
8943 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008944 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008945 SHOW_STR
8946 BGP_STR
8947 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008948 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008949 "community-list name\n")
8950{
8951 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8952}
8953
8954ALIAS (show_bgp_community_list,
8955 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008956 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008957 SHOW_STR
8958 BGP_STR
8959 "Address family\n"
8960 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008961 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008962 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008963
8964/* old command */
8965DEFUN (show_ipv6_bgp_community_list,
8966 show_ipv6_bgp_community_list_cmd,
8967 "show ipv6 bgp community-list WORD",
8968 SHOW_STR
8969 IPV6_STR
8970 BGP_STR
8971 "Display routes matching the community-list\n"
8972 "community-list name\n")
8973{
8974 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8975}
8976
8977/* old command */
8978DEFUN (show_ipv6_mbgp_community_list,
8979 show_ipv6_mbgp_community_list_cmd,
8980 "show ipv6 mbgp community-list WORD",
8981 SHOW_STR
8982 IPV6_STR
8983 MBGP_STR
8984 "Display routes matching the community-list\n"
8985 "community-list name\n")
8986{
8987 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8988}
8989
8990DEFUN (show_bgp_community_list_exact,
8991 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008992 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008993 SHOW_STR
8994 BGP_STR
8995 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008996 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008997 "community-list name\n"
8998 "Exact match of the communities\n")
8999{
9000 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9001}
9002
9003ALIAS (show_bgp_community_list_exact,
9004 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009005 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009006 SHOW_STR
9007 BGP_STR
9008 "Address family\n"
9009 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009010 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009011 "community-list name\n"
9012 "Exact match of the communities\n")
9013
9014/* old command */
9015DEFUN (show_ipv6_bgp_community_list_exact,
9016 show_ipv6_bgp_community_list_exact_cmd,
9017 "show ipv6 bgp community-list WORD exact-match",
9018 SHOW_STR
9019 IPV6_STR
9020 BGP_STR
9021 "Display routes matching the community-list\n"
9022 "community-list name\n"
9023 "Exact match of the communities\n")
9024{
9025 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9026}
9027
9028/* old command */
9029DEFUN (show_ipv6_mbgp_community_list_exact,
9030 show_ipv6_mbgp_community_list_exact_cmd,
9031 "show ipv6 mbgp community-list WORD exact-match",
9032 SHOW_STR
9033 IPV6_STR
9034 MBGP_STR
9035 "Display routes matching the community-list\n"
9036 "community-list name\n"
9037 "Exact match of the communities\n")
9038{
9039 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9040}
9041#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009042
paul94f2b392005-06-28 12:44:16 +00009043static int
paulfd79ac92004-10-13 05:06:08 +00009044bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009045 safi_t safi, enum bgp_show_type type)
9046{
9047 int ret;
9048 struct prefix *p;
9049
9050 p = prefix_new();
9051
9052 ret = str2prefix (prefix, p);
9053 if (! ret)
9054 {
9055 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9056 return CMD_WARNING;
9057 }
9058
ajs5a646652004-11-05 01:25:55 +00009059 ret = bgp_show (vty, NULL, afi, safi, type, p);
9060 prefix_free(p);
9061 return ret;
paul718e3742002-12-13 20:15:29 +00009062}
9063
9064DEFUN (show_ip_bgp_prefix_longer,
9065 show_ip_bgp_prefix_longer_cmd,
9066 "show ip bgp A.B.C.D/M longer-prefixes",
9067 SHOW_STR
9068 IP_STR
9069 BGP_STR
9070 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9071 "Display route and more specific routes\n")
9072{
9073 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9074 bgp_show_type_prefix_longer);
9075}
9076
9077DEFUN (show_ip_bgp_flap_prefix_longer,
9078 show_ip_bgp_flap_prefix_longer_cmd,
9079 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9080 SHOW_STR
9081 IP_STR
9082 BGP_STR
9083 "Display flap statistics of routes\n"
9084 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9085 "Display route and more specific routes\n")
9086{
9087 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9088 bgp_show_type_flap_prefix_longer);
9089}
9090
9091DEFUN (show_ip_bgp_ipv4_prefix_longer,
9092 show_ip_bgp_ipv4_prefix_longer_cmd,
9093 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9094 SHOW_STR
9095 IP_STR
9096 BGP_STR
9097 "Address family\n"
9098 "Address Family modifier\n"
9099 "Address Family modifier\n"
9100 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9101 "Display route and more specific routes\n")
9102{
9103 if (strncmp (argv[0], "m", 1) == 0)
9104 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9105 bgp_show_type_prefix_longer);
9106
9107 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9108 bgp_show_type_prefix_longer);
9109}
9110
9111DEFUN (show_ip_bgp_flap_address,
9112 show_ip_bgp_flap_address_cmd,
9113 "show ip bgp flap-statistics A.B.C.D",
9114 SHOW_STR
9115 IP_STR
9116 BGP_STR
9117 "Display flap statistics of routes\n"
9118 "Network in the BGP routing table to display\n")
9119{
9120 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9121 bgp_show_type_flap_address);
9122}
9123
9124DEFUN (show_ip_bgp_flap_prefix,
9125 show_ip_bgp_flap_prefix_cmd,
9126 "show ip bgp flap-statistics A.B.C.D/M",
9127 SHOW_STR
9128 IP_STR
9129 BGP_STR
9130 "Display flap statistics of routes\n"
9131 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9132{
9133 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9134 bgp_show_type_flap_prefix);
9135}
9136#ifdef HAVE_IPV6
9137DEFUN (show_bgp_prefix_longer,
9138 show_bgp_prefix_longer_cmd,
9139 "show bgp X:X::X:X/M longer-prefixes",
9140 SHOW_STR
9141 BGP_STR
9142 "IPv6 prefix <network>/<length>\n"
9143 "Display route and more specific routes\n")
9144{
9145 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9146 bgp_show_type_prefix_longer);
9147}
9148
9149ALIAS (show_bgp_prefix_longer,
9150 show_bgp_ipv6_prefix_longer_cmd,
9151 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9152 SHOW_STR
9153 BGP_STR
9154 "Address family\n"
9155 "IPv6 prefix <network>/<length>\n"
9156 "Display route and more specific routes\n")
9157
9158/* old command */
9159DEFUN (show_ipv6_bgp_prefix_longer,
9160 show_ipv6_bgp_prefix_longer_cmd,
9161 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9162 SHOW_STR
9163 IPV6_STR
9164 BGP_STR
9165 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9166 "Display route and more specific routes\n")
9167{
9168 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9169 bgp_show_type_prefix_longer);
9170}
9171
9172/* old command */
9173DEFUN (show_ipv6_mbgp_prefix_longer,
9174 show_ipv6_mbgp_prefix_longer_cmd,
9175 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9176 SHOW_STR
9177 IPV6_STR
9178 MBGP_STR
9179 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9180 "Display route and more specific routes\n")
9181{
9182 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9183 bgp_show_type_prefix_longer);
9184}
9185#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009186
paul94f2b392005-06-28 12:44:16 +00009187static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009188peer_lookup_in_view (struct vty *vty, const char *view_name,
9189 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009190{
9191 int ret;
9192 struct bgp *bgp;
9193 struct peer *peer;
9194 union sockunion su;
9195
9196 /* BGP structure lookup. */
9197 if (view_name)
9198 {
9199 bgp = bgp_lookup_by_name (view_name);
9200 if (! bgp)
9201 {
9202 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9203 return NULL;
9204 }
9205 }
paul5228ad22004-06-04 17:58:18 +00009206 else
paulbb46e942003-10-24 19:02:03 +00009207 {
9208 bgp = bgp_get_default ();
9209 if (! bgp)
9210 {
9211 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9212 return NULL;
9213 }
9214 }
9215
9216 /* Get peer sockunion. */
9217 ret = str2sockunion (ip_str, &su);
9218 if (ret < 0)
9219 {
9220 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9221 return NULL;
9222 }
9223
9224 /* Peer structure lookup. */
9225 peer = peer_lookup (bgp, &su);
9226 if (! peer)
9227 {
9228 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9229 return NULL;
9230 }
9231
9232 return peer;
9233}
David Lamparter6b0655a2014-06-04 06:53:35 +02009234
Paul Jakma2815e612006-09-14 02:56:07 +00009235enum bgp_stats
9236{
9237 BGP_STATS_MAXBITLEN = 0,
9238 BGP_STATS_RIB,
9239 BGP_STATS_PREFIXES,
9240 BGP_STATS_TOTPLEN,
9241 BGP_STATS_UNAGGREGATEABLE,
9242 BGP_STATS_MAX_AGGREGATEABLE,
9243 BGP_STATS_AGGREGATES,
9244 BGP_STATS_SPACE,
9245 BGP_STATS_ASPATH_COUNT,
9246 BGP_STATS_ASPATH_MAXHOPS,
9247 BGP_STATS_ASPATH_TOTHOPS,
9248 BGP_STATS_ASPATH_MAXSIZE,
9249 BGP_STATS_ASPATH_TOTSIZE,
9250 BGP_STATS_ASN_HIGHEST,
9251 BGP_STATS_MAX,
9252};
paulbb46e942003-10-24 19:02:03 +00009253
Paul Jakma2815e612006-09-14 02:56:07 +00009254static const char *table_stats_strs[] =
9255{
9256 [BGP_STATS_PREFIXES] = "Total Prefixes",
9257 [BGP_STATS_TOTPLEN] = "Average prefix length",
9258 [BGP_STATS_RIB] = "Total Advertisements",
9259 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9260 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9261 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9262 [BGP_STATS_SPACE] = "Address space advertised",
9263 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9264 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9265 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9266 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9267 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9268 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9269 [BGP_STATS_MAX] = NULL,
9270};
9271
9272struct bgp_table_stats
9273{
9274 struct bgp_table *table;
9275 unsigned long long counts[BGP_STATS_MAX];
9276};
9277
9278#if 0
9279#define TALLY_SIGFIG 100000
9280static unsigned long
9281ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9282{
9283 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9284 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9285 unsigned long ret = newtot / count;
9286
9287 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9288 return ret + 1;
9289 else
9290 return ret;
9291}
9292#endif
9293
9294static int
9295bgp_table_stats_walker (struct thread *t)
9296{
9297 struct bgp_node *rn;
9298 struct bgp_node *top;
9299 struct bgp_table_stats *ts = THREAD_ARG (t);
9300 unsigned int space = 0;
9301
Paul Jakma53d9f672006-10-15 23:41:16 +00009302 if (!(top = bgp_table_top (ts->table)))
9303 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009304
9305 switch (top->p.family)
9306 {
9307 case AF_INET:
9308 space = IPV4_MAX_BITLEN;
9309 break;
9310 case AF_INET6:
9311 space = IPV6_MAX_BITLEN;
9312 break;
9313 }
9314
9315 ts->counts[BGP_STATS_MAXBITLEN] = space;
9316
9317 for (rn = top; rn; rn = bgp_route_next (rn))
9318 {
9319 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009320 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009321 unsigned int rinum = 0;
9322
9323 if (rn == top)
9324 continue;
9325
9326 if (!rn->info)
9327 continue;
9328
9329 ts->counts[BGP_STATS_PREFIXES]++;
9330 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9331
9332#if 0
9333 ts->counts[BGP_STATS_AVGPLEN]
9334 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9335 ts->counts[BGP_STATS_AVGPLEN],
9336 rn->p.prefixlen);
9337#endif
9338
9339 /* check if the prefix is included by any other announcements */
9340 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009341 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009342
9343 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009344 {
9345 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9346 /* announced address space */
9347 if (space)
9348 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9349 }
Paul Jakma2815e612006-09-14 02:56:07 +00009350 else if (prn->info)
9351 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9352
Paul Jakma2815e612006-09-14 02:56:07 +00009353 for (ri = rn->info; ri; ri = ri->next)
9354 {
9355 rinum++;
9356 ts->counts[BGP_STATS_RIB]++;
9357
9358 if (ri->attr &&
9359 (CHECK_FLAG (ri->attr->flag,
9360 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9361 ts->counts[BGP_STATS_AGGREGATES]++;
9362
9363 /* as-path stats */
9364 if (ri->attr && ri->attr->aspath)
9365 {
9366 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9367 unsigned int size = aspath_size (ri->attr->aspath);
9368 as_t highest = aspath_highest (ri->attr->aspath);
9369
9370 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9371
9372 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9373 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9374
9375 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9376 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9377
9378 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9379 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9380#if 0
9381 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9382 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9383 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9384 hops);
9385 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9386 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9387 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9388 size);
9389#endif
9390 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9391 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9392 }
9393 }
9394 }
9395 return 0;
9396}
9397
9398static int
9399bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9400{
9401 struct bgp_table_stats ts;
9402 unsigned int i;
9403
9404 if (!bgp->rib[afi][safi])
9405 {
9406 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9407 return CMD_WARNING;
9408 }
9409
9410 memset (&ts, 0, sizeof (ts));
9411 ts.table = bgp->rib[afi][safi];
9412 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9413
9414 vty_out (vty, "BGP %s RIB statistics%s%s",
9415 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9416
9417 for (i = 0; i < BGP_STATS_MAX; i++)
9418 {
9419 if (!table_stats_strs[i])
9420 continue;
9421
9422 switch (i)
9423 {
9424#if 0
9425 case BGP_STATS_ASPATH_AVGHOPS:
9426 case BGP_STATS_ASPATH_AVGSIZE:
9427 case BGP_STATS_AVGPLEN:
9428 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9429 vty_out (vty, "%12.2f",
9430 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9431 break;
9432#endif
9433 case BGP_STATS_ASPATH_TOTHOPS:
9434 case BGP_STATS_ASPATH_TOTSIZE:
9435 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9436 vty_out (vty, "%12.2f",
9437 ts.counts[i] ?
9438 (float)ts.counts[i] /
9439 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9440 : 0);
9441 break;
9442 case BGP_STATS_TOTPLEN:
9443 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9444 vty_out (vty, "%12.2f",
9445 ts.counts[i] ?
9446 (float)ts.counts[i] /
9447 (float)ts.counts[BGP_STATS_PREFIXES]
9448 : 0);
9449 break;
9450 case BGP_STATS_SPACE:
9451 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9452 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9453 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9454 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009455 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009456 vty_out (vty, "%12.2f%s",
9457 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009458 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009459 VTY_NEWLINE);
9460 vty_out (vty, "%30s: ", "/8 equivalent ");
9461 vty_out (vty, "%12.2f%s",
9462 (float)ts.counts[BGP_STATS_SPACE] /
9463 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9464 VTY_NEWLINE);
9465 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9466 break;
9467 vty_out (vty, "%30s: ", "/24 equivalent ");
9468 vty_out (vty, "%12.2f",
9469 (float)ts.counts[BGP_STATS_SPACE] /
9470 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9471 break;
9472 default:
9473 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9474 vty_out (vty, "%12llu", ts.counts[i]);
9475 }
9476
9477 vty_out (vty, "%s", VTY_NEWLINE);
9478 }
9479 return CMD_SUCCESS;
9480}
9481
9482static int
9483bgp_table_stats_vty (struct vty *vty, const char *name,
9484 const char *afi_str, const char *safi_str)
9485{
9486 struct bgp *bgp;
9487 afi_t afi;
9488 safi_t safi;
9489
9490 if (name)
9491 bgp = bgp_lookup_by_name (name);
9492 else
9493 bgp = bgp_get_default ();
9494
9495 if (!bgp)
9496 {
9497 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9498 return CMD_WARNING;
9499 }
9500 if (strncmp (afi_str, "ipv", 3) == 0)
9501 {
9502 if (strncmp (afi_str, "ipv4", 4) == 0)
9503 afi = AFI_IP;
9504 else if (strncmp (afi_str, "ipv6", 4) == 0)
9505 afi = AFI_IP6;
9506 else
9507 {
9508 vty_out (vty, "%% Invalid address family %s%s",
9509 afi_str, VTY_NEWLINE);
9510 return CMD_WARNING;
9511 }
9512 if (strncmp (safi_str, "m", 1) == 0)
9513 safi = SAFI_MULTICAST;
9514 else if (strncmp (safi_str, "u", 1) == 0)
9515 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009516 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9517 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009518 else
9519 {
9520 vty_out (vty, "%% Invalid subsequent address family %s%s",
9521 safi_str, VTY_NEWLINE);
9522 return CMD_WARNING;
9523 }
9524 }
9525 else
9526 {
9527 vty_out (vty, "%% Invalid address family %s%s",
9528 afi_str, VTY_NEWLINE);
9529 return CMD_WARNING;
9530 }
9531
Paul Jakma2815e612006-09-14 02:56:07 +00009532 return bgp_table_stats (vty, bgp, afi, safi);
9533}
9534
9535DEFUN (show_bgp_statistics,
9536 show_bgp_statistics_cmd,
9537 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9538 SHOW_STR
9539 BGP_STR
9540 "Address family\n"
9541 "Address family\n"
9542 "Address Family modifier\n"
9543 "Address Family modifier\n"
9544 "BGP RIB advertisement statistics\n")
9545{
9546 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9547}
9548
9549ALIAS (show_bgp_statistics,
9550 show_bgp_statistics_vpnv4_cmd,
9551 "show bgp (ipv4) (vpnv4) statistics",
9552 SHOW_STR
9553 BGP_STR
9554 "Address family\n"
9555 "Address Family modifier\n"
9556 "BGP RIB advertisement statistics\n")
9557
9558DEFUN (show_bgp_statistics_view,
9559 show_bgp_statistics_view_cmd,
9560 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9561 SHOW_STR
9562 BGP_STR
9563 "BGP view\n"
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_view,
9574 show_bgp_statistics_view_vpnv4_cmd,
9575 "show bgp view WORD (ipv4) (vpnv4) statistics",
9576 SHOW_STR
9577 BGP_STR
9578 "BGP view\n"
9579 "Address family\n"
9580 "Address Family modifier\n"
9581 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02009582
Paul Jakmaff7924f2006-09-04 01:10:36 +00009583enum bgp_pcounts
9584{
9585 PCOUNT_ADJ_IN = 0,
9586 PCOUNT_DAMPED,
9587 PCOUNT_REMOVED,
9588 PCOUNT_HISTORY,
9589 PCOUNT_STALE,
9590 PCOUNT_VALID,
9591 PCOUNT_ALL,
9592 PCOUNT_COUNTED,
9593 PCOUNT_PFCNT, /* the figure we display to users */
9594 PCOUNT_MAX,
9595};
9596
9597static const char *pcount_strs[] =
9598{
9599 [PCOUNT_ADJ_IN] = "Adj-in",
9600 [PCOUNT_DAMPED] = "Damped",
9601 [PCOUNT_REMOVED] = "Removed",
9602 [PCOUNT_HISTORY] = "History",
9603 [PCOUNT_STALE] = "Stale",
9604 [PCOUNT_VALID] = "Valid",
9605 [PCOUNT_ALL] = "All RIB",
9606 [PCOUNT_COUNTED] = "PfxCt counted",
9607 [PCOUNT_PFCNT] = "Useable",
9608 [PCOUNT_MAX] = NULL,
9609};
9610
Paul Jakma2815e612006-09-14 02:56:07 +00009611struct peer_pcounts
9612{
9613 unsigned int count[PCOUNT_MAX];
9614 const struct peer *peer;
9615 const struct bgp_table *table;
9616};
9617
Paul Jakmaff7924f2006-09-04 01:10:36 +00009618static int
Paul Jakma2815e612006-09-14 02:56:07 +00009619bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009620{
9621 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009622 struct peer_pcounts *pc = THREAD_ARG (t);
9623 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009624
Paul Jakma2815e612006-09-14 02:56:07 +00009625 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009626 {
9627 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009628 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009629
9630 for (ain = rn->adj_in; ain; ain = ain->next)
9631 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009632 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009633
Paul Jakmaff7924f2006-09-04 01:10:36 +00009634 for (ri = rn->info; ri; ri = ri->next)
9635 {
9636 char buf[SU_ADDRSTRLEN];
9637
9638 if (ri->peer != peer)
9639 continue;
9640
Paul Jakma2815e612006-09-14 02:56:07 +00009641 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009642
9643 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009644 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009645 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009646 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009647 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009648 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009649 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009650 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009651 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009652 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009653 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009654 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009655
9656 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9657 {
Paul Jakma2815e612006-09-14 02:56:07 +00009658 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009659 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009660 plog_warn (peer->log,
9661 "%s [pcount] %s/%d is counted but flags 0x%x",
9662 peer->host,
9663 inet_ntop(rn->p.family, &rn->p.u.prefix,
9664 buf, SU_ADDRSTRLEN),
9665 rn->p.prefixlen,
9666 ri->flags);
9667 }
9668 else
9669 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009670 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009671 plog_warn (peer->log,
9672 "%s [pcount] %s/%d not counted but flags 0x%x",
9673 peer->host,
9674 inet_ntop(rn->p.family, &rn->p.u.prefix,
9675 buf, SU_ADDRSTRLEN),
9676 rn->p.prefixlen,
9677 ri->flags);
9678 }
9679 }
9680 }
Paul Jakma2815e612006-09-14 02:56:07 +00009681 return 0;
9682}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009683
Paul Jakma2815e612006-09-14 02:56:07 +00009684static int
9685bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9686{
9687 struct peer_pcounts pcounts = { .peer = peer };
9688 unsigned int i;
9689
9690 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9691 || !peer->bgp->rib[afi][safi])
9692 {
9693 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9694 return CMD_WARNING;
9695 }
9696
9697 memset (&pcounts, 0, sizeof(pcounts));
9698 pcounts.peer = peer;
9699 pcounts.table = peer->bgp->rib[afi][safi];
9700
9701 /* in-place call via thread subsystem so as to record execution time
9702 * stats for the thread-walk (i.e. ensure this can't be blamed on
9703 * on just vty_read()).
9704 */
9705 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9706
Paul Jakmaff7924f2006-09-04 01:10:36 +00009707 vty_out (vty, "Prefix counts for %s, %s%s",
9708 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9709 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9710 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9711 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9712
9713 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009714 vty_out (vty, "%20s: %-10d%s",
9715 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009716
Paul Jakma2815e612006-09-14 02:56:07 +00009717 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009718 {
9719 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9720 peer->host, VTY_NEWLINE);
9721 vty_out (vty, "Please report this bug, with the above command output%s",
9722 VTY_NEWLINE);
9723 }
9724
9725 return CMD_SUCCESS;
9726}
9727
9728DEFUN (show_ip_bgp_neighbor_prefix_counts,
9729 show_ip_bgp_neighbor_prefix_counts_cmd,
9730 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9731 SHOW_STR
9732 IP_STR
9733 BGP_STR
9734 "Detailed information on TCP and BGP neighbor connections\n"
9735 "Neighbor to display information about\n"
9736 "Neighbor to display information about\n"
9737 "Display detailed prefix count information\n")
9738{
9739 struct peer *peer;
9740
9741 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9742 if (! peer)
9743 return CMD_WARNING;
9744
9745 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9746}
9747
9748DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9749 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9750 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9751 SHOW_STR
9752 BGP_STR
9753 "Address family\n"
9754 "Detailed information on TCP and BGP neighbor connections\n"
9755 "Neighbor to display information about\n"
9756 "Neighbor to display information about\n"
9757 "Display detailed prefix count information\n")
9758{
9759 struct peer *peer;
9760
9761 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9762 if (! peer)
9763 return CMD_WARNING;
9764
9765 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9766}
9767
9768DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9769 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9770 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9771 SHOW_STR
9772 IP_STR
9773 BGP_STR
9774 "Address family\n"
9775 "Address Family modifier\n"
9776 "Address Family modifier\n"
9777 "Detailed information on TCP and BGP neighbor connections\n"
9778 "Neighbor to display information about\n"
9779 "Neighbor to display information about\n"
9780 "Display detailed prefix count information\n")
9781{
9782 struct peer *peer;
9783
9784 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9785 if (! peer)
9786 return CMD_WARNING;
9787
9788 if (strncmp (argv[0], "m", 1) == 0)
9789 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9790
9791 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9792}
9793
9794DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9795 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9796 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9797 SHOW_STR
9798 IP_STR
9799 BGP_STR
9800 "Address family\n"
9801 "Address Family modifier\n"
9802 "Address Family modifier\n"
9803 "Detailed information on TCP and BGP neighbor connections\n"
9804 "Neighbor to display information about\n"
9805 "Neighbor to display information about\n"
9806 "Display detailed prefix count information\n")
9807{
9808 struct peer *peer;
9809
9810 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9811 if (! peer)
9812 return CMD_WARNING;
9813
9814 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9815}
9816
9817
paul94f2b392005-06-28 12:44:16 +00009818static void
paul718e3742002-12-13 20:15:29 +00009819show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9820 int in)
9821{
9822 struct bgp_table *table;
9823 struct bgp_adj_in *ain;
9824 struct bgp_adj_out *adj;
9825 unsigned long output_count;
9826 struct bgp_node *rn;
9827 int header1 = 1;
9828 struct bgp *bgp;
9829 int header2 = 1;
9830
paulbb46e942003-10-24 19:02:03 +00009831 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009832
9833 if (! bgp)
9834 return;
9835
9836 table = bgp->rib[afi][safi];
9837
9838 output_count = 0;
9839
9840 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9841 PEER_STATUS_DEFAULT_ORIGINATE))
9842 {
9843 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 +00009844 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9845 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009846
9847 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9848 VTY_NEWLINE, VTY_NEWLINE);
9849 header1 = 0;
9850 }
9851
9852 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9853 if (in)
9854 {
9855 for (ain = rn->adj_in; ain; ain = ain->next)
9856 if (ain->peer == peer)
9857 {
9858 if (header1)
9859 {
9860 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 +00009861 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9862 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009863 header1 = 0;
9864 }
9865 if (header2)
9866 {
9867 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9868 header2 = 0;
9869 }
9870 if (ain->attr)
9871 {
9872 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9873 output_count++;
9874 }
9875 }
9876 }
9877 else
9878 {
9879 for (adj = rn->adj_out; adj; adj = adj->next)
9880 if (adj->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 (adj->attr)
9895 {
9896 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9897 output_count++;
9898 }
9899 }
9900 }
9901
9902 if (output_count != 0)
9903 vty_out (vty, "%sTotal number of prefixes %ld%s",
9904 VTY_NEWLINE, output_count, VTY_NEWLINE);
9905}
9906
paul94f2b392005-06-28 12:44:16 +00009907static int
paulbb46e942003-10-24 19:02:03 +00009908peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9909{
paul718e3742002-12-13 20:15:29 +00009910 if (! peer || ! peer->afc[afi][safi])
9911 {
9912 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9913 return CMD_WARNING;
9914 }
9915
9916 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9917 {
9918 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9919 VTY_NEWLINE);
9920 return CMD_WARNING;
9921 }
9922
9923 show_adj_route (vty, peer, afi, safi, in);
9924
9925 return CMD_SUCCESS;
9926}
9927
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009928DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9929 show_ip_bgp_view_neighbor_advertised_route_cmd,
9930 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9931 SHOW_STR
9932 IP_STR
9933 BGP_STR
9934 "BGP view\n"
9935 "View name\n"
9936 "Detailed information on TCP and BGP neighbor connections\n"
9937 "Neighbor to display information about\n"
9938 "Neighbor to display information about\n"
9939 "Display the routes advertised to a BGP neighbor\n")
9940{
9941 struct peer *peer;
9942
9943 if (argc == 2)
9944 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9945 else
9946 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9947
9948 if (! peer)
9949 return CMD_WARNING;
9950
9951 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9952}
9953
9954ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009955 show_ip_bgp_neighbor_advertised_route_cmd,
9956 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9957 SHOW_STR
9958 IP_STR
9959 BGP_STR
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")
paul718e3742002-12-13 20:15:29 +00009964
9965DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9966 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9967 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9968 SHOW_STR
9969 IP_STR
9970 BGP_STR
9971 "Address family\n"
9972 "Address Family modifier\n"
9973 "Address Family modifier\n"
9974 "Detailed information on TCP and BGP neighbor connections\n"
9975 "Neighbor to display information about\n"
9976 "Neighbor to display information about\n"
9977 "Display the routes advertised to a BGP neighbor\n")
9978{
paulbb46e942003-10-24 19:02:03 +00009979 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009980
paulbb46e942003-10-24 19:02:03 +00009981 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9982 if (! peer)
9983 return CMD_WARNING;
9984
9985 if (strncmp (argv[0], "m", 1) == 0)
9986 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9987
9988 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009989}
9990
9991#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009992DEFUN (show_bgp_view_neighbor_advertised_route,
9993 show_bgp_view_neighbor_advertised_route_cmd,
9994 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9995 SHOW_STR
9996 BGP_STR
9997 "BGP view\n"
9998 "View name\n"
9999 "Detailed information on TCP and BGP neighbor connections\n"
10000 "Neighbor to display information about\n"
10001 "Neighbor to display information about\n"
10002 "Display the routes advertised to a BGP neighbor\n")
10003{
10004 struct peer *peer;
10005
10006 if (argc == 2)
10007 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10008 else
10009 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10010
10011 if (! peer)
10012 return CMD_WARNING;
10013
10014 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10015}
10016
10017ALIAS (show_bgp_view_neighbor_advertised_route,
10018 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10019 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10020 SHOW_STR
10021 BGP_STR
10022 "BGP view\n"
10023 "View name\n"
10024 "Address family\n"
10025 "Detailed information on TCP and BGP neighbor connections\n"
10026 "Neighbor to display information about\n"
10027 "Neighbor to display information about\n"
10028 "Display the routes advertised to a BGP neighbor\n")
10029
10030DEFUN (show_bgp_view_neighbor_received_routes,
10031 show_bgp_view_neighbor_received_routes_cmd,
10032 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10033 SHOW_STR
10034 BGP_STR
10035 "BGP view\n"
10036 "View name\n"
10037 "Detailed information on TCP and BGP neighbor connections\n"
10038 "Neighbor to display information about\n"
10039 "Neighbor to display information about\n"
10040 "Display the received routes from neighbor\n")
10041{
10042 struct peer *peer;
10043
10044 if (argc == 2)
10045 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10046 else
10047 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10048
10049 if (! peer)
10050 return CMD_WARNING;
10051
10052 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10053}
10054
10055ALIAS (show_bgp_view_neighbor_received_routes,
10056 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10057 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10058 SHOW_STR
10059 BGP_STR
10060 "BGP view\n"
10061 "View name\n"
10062 "Address family\n"
10063 "Detailed information on TCP and BGP neighbor connections\n"
10064 "Neighbor to display information about\n"
10065 "Neighbor to display information about\n"
10066 "Display the received routes from neighbor\n")
10067
10068ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010069 show_bgp_neighbor_advertised_route_cmd,
10070 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10071 SHOW_STR
10072 BGP_STR
10073 "Detailed information on TCP and BGP neighbor connections\n"
10074 "Neighbor to display information about\n"
10075 "Neighbor to display information about\n"
10076 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010077
10078ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010079 show_bgp_ipv6_neighbor_advertised_route_cmd,
10080 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10081 SHOW_STR
10082 BGP_STR
10083 "Address family\n"
10084 "Detailed information on TCP and BGP neighbor connections\n"
10085 "Neighbor to display information about\n"
10086 "Neighbor to display information about\n"
10087 "Display the routes advertised to a BGP neighbor\n")
10088
10089/* old command */
paulbb46e942003-10-24 19:02:03 +000010090ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010091 ipv6_bgp_neighbor_advertised_route_cmd,
10092 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10093 SHOW_STR
10094 IPV6_STR
10095 BGP_STR
10096 "Detailed information on TCP and BGP neighbor connections\n"
10097 "Neighbor to display information about\n"
10098 "Neighbor to display information about\n"
10099 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010100
paul718e3742002-12-13 20:15:29 +000010101/* old command */
10102DEFUN (ipv6_mbgp_neighbor_advertised_route,
10103 ipv6_mbgp_neighbor_advertised_route_cmd,
10104 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10105 SHOW_STR
10106 IPV6_STR
10107 MBGP_STR
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{
paulbb46e942003-10-24 19:02:03 +000010113 struct peer *peer;
10114
10115 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10116 if (! peer)
10117 return CMD_WARNING;
10118
10119 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010120}
10121#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010122
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010123DEFUN (show_ip_bgp_view_neighbor_received_routes,
10124 show_ip_bgp_view_neighbor_received_routes_cmd,
10125 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10126 SHOW_STR
10127 IP_STR
10128 BGP_STR
10129 "BGP view\n"
10130 "View name\n"
10131 "Detailed information on TCP and BGP neighbor connections\n"
10132 "Neighbor to display information about\n"
10133 "Neighbor to display information about\n"
10134 "Display the received routes from neighbor\n")
10135{
10136 struct peer *peer;
10137
10138 if (argc == 2)
10139 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10140 else
10141 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10142
10143 if (! peer)
10144 return CMD_WARNING;
10145
10146 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10147}
10148
10149ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010150 show_ip_bgp_neighbor_received_routes_cmd,
10151 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10152 SHOW_STR
10153 IP_STR
10154 BGP_STR
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")
paul718e3742002-12-13 20:15:29 +000010159
10160DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10161 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10162 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10163 SHOW_STR
10164 IP_STR
10165 BGP_STR
10166 "Address family\n"
10167 "Address Family modifier\n"
10168 "Address Family modifier\n"
10169 "Detailed information on TCP and BGP neighbor connections\n"
10170 "Neighbor to display information about\n"
10171 "Neighbor to display information about\n"
10172 "Display the received routes from neighbor\n")
10173{
paulbb46e942003-10-24 19:02:03 +000010174 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010175
paulbb46e942003-10-24 19:02:03 +000010176 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10177 if (! peer)
10178 return CMD_WARNING;
10179
10180 if (strncmp (argv[0], "m", 1) == 0)
10181 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10182
10183 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010184}
10185
Michael Lambert95cbbd22010-07-23 14:43:04 -040010186DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10187 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010188 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
Michael Lambert95cbbd22010-07-23 14:43:04 -040010189 SHOW_STR
10190 BGP_STR
10191 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010192 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010193 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010194 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010195 "Address family modifier\n"
10196 "Address family modifier\n"
10197 "Detailed information on TCP and BGP neighbor connections\n"
10198 "Neighbor to display information about\n"
10199 "Neighbor to display information about\n"
10200 "Display the advertised routes to neighbor\n"
10201 "Display the received routes from neighbor\n")
10202{
10203 int afi;
10204 int safi;
10205 int in;
10206 struct peer *peer;
10207
David Lamparter94bad672015-03-03 08:52:22 +010010208 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010209
10210 if (! peer)
10211 return CMD_WARNING;
10212
Michael Lambert95cbbd22010-07-23 14:43:04 -040010213 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10214 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10215 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010216
10217 return peer_adj_routes (vty, peer, afi, safi, in);
10218}
10219
paul718e3742002-12-13 20:15:29 +000010220DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10221 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10222 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10223 SHOW_STR
10224 IP_STR
10225 BGP_STR
10226 "Detailed information on TCP and BGP neighbor connections\n"
10227 "Neighbor to display information about\n"
10228 "Neighbor to display information about\n"
10229 "Display information received from a BGP neighbor\n"
10230 "Display the prefixlist filter\n")
10231{
10232 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010233 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010234 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010235 int count, ret;
paul718e3742002-12-13 20:15:29 +000010236
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010237 ret = str2sockunion (argv[0], &su);
10238 if (ret < 0)
10239 {
10240 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10241 return CMD_WARNING;
10242 }
paul718e3742002-12-13 20:15:29 +000010243
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010244 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010245 if (! peer)
10246 return CMD_WARNING;
10247
10248 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10249 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10250 if (count)
10251 {
10252 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10253 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10254 }
10255
10256 return CMD_SUCCESS;
10257}
10258
10259DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10260 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10261 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10262 SHOW_STR
10263 IP_STR
10264 BGP_STR
10265 "Address family\n"
10266 "Address Family modifier\n"
10267 "Address Family modifier\n"
10268 "Detailed information on TCP and BGP neighbor connections\n"
10269 "Neighbor to display information about\n"
10270 "Neighbor to display information about\n"
10271 "Display information received from a BGP neighbor\n"
10272 "Display the prefixlist filter\n")
10273{
10274 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010275 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010276 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010277 int count, ret;
paul718e3742002-12-13 20:15:29 +000010278
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010279 ret = str2sockunion (argv[1], &su);
10280 if (ret < 0)
10281 {
10282 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10283 return CMD_WARNING;
10284 }
paul718e3742002-12-13 20:15:29 +000010285
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010286 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010287 if (! peer)
10288 return CMD_WARNING;
10289
10290 if (strncmp (argv[0], "m", 1) == 0)
10291 {
10292 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10293 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10294 if (count)
10295 {
10296 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10297 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10298 }
10299 }
10300 else
10301 {
10302 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10303 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10304 if (count)
10305 {
10306 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10307 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10308 }
10309 }
10310
10311 return CMD_SUCCESS;
10312}
10313
10314
10315#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010316ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010317 show_bgp_neighbor_received_routes_cmd,
10318 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10319 SHOW_STR
10320 BGP_STR
10321 "Detailed information on TCP and BGP neighbor connections\n"
10322 "Neighbor to display information about\n"
10323 "Neighbor to display information about\n"
10324 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010325
paulbb46e942003-10-24 19:02:03 +000010326ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010327 show_bgp_ipv6_neighbor_received_routes_cmd,
10328 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10329 SHOW_STR
10330 BGP_STR
10331 "Address family\n"
10332 "Detailed information on TCP and BGP neighbor connections\n"
10333 "Neighbor to display information about\n"
10334 "Neighbor to display information about\n"
10335 "Display the received routes from neighbor\n")
10336
10337DEFUN (show_bgp_neighbor_received_prefix_filter,
10338 show_bgp_neighbor_received_prefix_filter_cmd,
10339 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10340 SHOW_STR
10341 BGP_STR
10342 "Detailed information on TCP and BGP neighbor connections\n"
10343 "Neighbor to display information about\n"
10344 "Neighbor to display information about\n"
10345 "Display information received from a BGP neighbor\n"
10346 "Display the prefixlist filter\n")
10347{
10348 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010349 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010350 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010351 int count, ret;
paul718e3742002-12-13 20:15:29 +000010352
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010353 ret = str2sockunion (argv[0], &su);
10354 if (ret < 0)
10355 {
10356 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10357 return CMD_WARNING;
10358 }
paul718e3742002-12-13 20:15:29 +000010359
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010360 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010361 if (! peer)
10362 return CMD_WARNING;
10363
10364 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10365 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10366 if (count)
10367 {
10368 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10369 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10370 }
10371
10372 return CMD_SUCCESS;
10373}
10374
10375ALIAS (show_bgp_neighbor_received_prefix_filter,
10376 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10377 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10378 SHOW_STR
10379 BGP_STR
10380 "Address family\n"
10381 "Detailed information on TCP and BGP neighbor connections\n"
10382 "Neighbor to display information about\n"
10383 "Neighbor to display information about\n"
10384 "Display information received from a BGP neighbor\n"
10385 "Display the prefixlist filter\n")
10386
10387/* old command */
paulbb46e942003-10-24 19:02:03 +000010388ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010389 ipv6_bgp_neighbor_received_routes_cmd,
10390 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10391 SHOW_STR
10392 IPV6_STR
10393 BGP_STR
10394 "Detailed information on TCP and BGP neighbor connections\n"
10395 "Neighbor to display information about\n"
10396 "Neighbor to display information about\n"
10397 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010398
10399/* old command */
10400DEFUN (ipv6_mbgp_neighbor_received_routes,
10401 ipv6_mbgp_neighbor_received_routes_cmd,
10402 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10403 SHOW_STR
10404 IPV6_STR
10405 MBGP_STR
10406 "Detailed information on TCP and BGP neighbor connections\n"
10407 "Neighbor to display information about\n"
10408 "Neighbor to display information about\n"
10409 "Display the received routes from neighbor\n")
10410{
paulbb46e942003-10-24 19:02:03 +000010411 struct peer *peer;
10412
10413 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10414 if (! peer)
10415 return CMD_WARNING;
10416
10417 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010418}
paulbb46e942003-10-24 19:02:03 +000010419
10420DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10421 show_bgp_view_neighbor_received_prefix_filter_cmd,
10422 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10423 SHOW_STR
10424 BGP_STR
10425 "BGP view\n"
10426 "View name\n"
10427 "Detailed information on TCP and BGP neighbor connections\n"
10428 "Neighbor to display information about\n"
10429 "Neighbor to display information about\n"
10430 "Display information received from a BGP neighbor\n"
10431 "Display the prefixlist filter\n")
10432{
10433 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010434 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010435 struct peer *peer;
10436 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010437 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010438
10439 /* BGP structure lookup. */
10440 bgp = bgp_lookup_by_name (argv[0]);
10441 if (bgp == NULL)
10442 {
10443 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10444 return CMD_WARNING;
10445 }
10446
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010447 ret = str2sockunion (argv[1], &su);
10448 if (ret < 0)
10449 {
10450 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10451 return CMD_WARNING;
10452 }
paulbb46e942003-10-24 19:02:03 +000010453
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010454 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010455 if (! peer)
10456 return CMD_WARNING;
10457
10458 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10459 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10460 if (count)
10461 {
10462 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10463 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10464 }
10465
10466 return CMD_SUCCESS;
10467}
10468
10469ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10470 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10471 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10472 SHOW_STR
10473 BGP_STR
10474 "BGP view\n"
10475 "View name\n"
10476 "Address family\n"
10477 "Detailed information on TCP and BGP neighbor connections\n"
10478 "Neighbor to display information about\n"
10479 "Neighbor to display information about\n"
10480 "Display information received from a BGP neighbor\n"
10481 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010482#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010483
paul94f2b392005-06-28 12:44:16 +000010484static int
paulbb46e942003-10-24 19:02:03 +000010485bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010486 safi_t safi, enum bgp_show_type type)
10487{
paul718e3742002-12-13 20:15:29 +000010488 if (! peer || ! peer->afc[afi][safi])
10489 {
10490 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010491 return CMD_WARNING;
10492 }
10493
ajs5a646652004-11-05 01:25:55 +000010494 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010495}
10496
10497DEFUN (show_ip_bgp_neighbor_routes,
10498 show_ip_bgp_neighbor_routes_cmd,
10499 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10500 SHOW_STR
10501 IP_STR
10502 BGP_STR
10503 "Detailed information on TCP and BGP neighbor connections\n"
10504 "Neighbor to display information about\n"
10505 "Neighbor to display information about\n"
10506 "Display routes learned from neighbor\n")
10507{
paulbb46e942003-10-24 19:02:03 +000010508 struct peer *peer;
10509
10510 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10511 if (! peer)
10512 return CMD_WARNING;
10513
10514 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010515 bgp_show_type_neighbor);
10516}
10517
10518DEFUN (show_ip_bgp_neighbor_flap,
10519 show_ip_bgp_neighbor_flap_cmd,
10520 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10521 SHOW_STR
10522 IP_STR
10523 BGP_STR
10524 "Detailed information on TCP and BGP neighbor connections\n"
10525 "Neighbor to display information about\n"
10526 "Neighbor to display information about\n"
10527 "Display flap statistics of the routes learned from neighbor\n")
10528{
paulbb46e942003-10-24 19:02:03 +000010529 struct peer *peer;
10530
10531 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10532 if (! peer)
10533 return CMD_WARNING;
10534
10535 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010536 bgp_show_type_flap_neighbor);
10537}
10538
10539DEFUN (show_ip_bgp_neighbor_damp,
10540 show_ip_bgp_neighbor_damp_cmd,
10541 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10542 SHOW_STR
10543 IP_STR
10544 BGP_STR
10545 "Detailed information on TCP and BGP neighbor connections\n"
10546 "Neighbor to display information about\n"
10547 "Neighbor to display information about\n"
10548 "Display the dampened routes received from neighbor\n")
10549{
paulbb46e942003-10-24 19:02:03 +000010550 struct peer *peer;
10551
10552 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10553 if (! peer)
10554 return CMD_WARNING;
10555
10556 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010557 bgp_show_type_damp_neighbor);
10558}
10559
10560DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10561 show_ip_bgp_ipv4_neighbor_routes_cmd,
10562 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10563 SHOW_STR
10564 IP_STR
10565 BGP_STR
10566 "Address family\n"
10567 "Address Family modifier\n"
10568 "Address Family modifier\n"
10569 "Detailed information on TCP and BGP neighbor connections\n"
10570 "Neighbor to display information about\n"
10571 "Neighbor to display information about\n"
10572 "Display routes learned from neighbor\n")
10573{
paulbb46e942003-10-24 19:02:03 +000010574 struct peer *peer;
10575
10576 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10577 if (! peer)
10578 return CMD_WARNING;
10579
paul718e3742002-12-13 20:15:29 +000010580 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010581 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010582 bgp_show_type_neighbor);
10583
paulbb46e942003-10-24 19:02:03 +000010584 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010585 bgp_show_type_neighbor);
10586}
paulbb46e942003-10-24 19:02:03 +000010587
paulfee0f4c2004-09-13 05:12:46 +000010588DEFUN (show_ip_bgp_view_rsclient,
10589 show_ip_bgp_view_rsclient_cmd,
10590 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10591 SHOW_STR
10592 IP_STR
10593 BGP_STR
10594 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010595 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010596 "Information about Route Server Client\n"
10597 NEIGHBOR_ADDR_STR)
10598{
10599 struct bgp_table *table;
10600 struct peer *peer;
10601
10602 if (argc == 2)
10603 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10604 else
10605 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10606
10607 if (! peer)
10608 return CMD_WARNING;
10609
10610 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10611 {
10612 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10613 VTY_NEWLINE);
10614 return CMD_WARNING;
10615 }
10616
10617 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10618 PEER_FLAG_RSERVER_CLIENT))
10619 {
10620 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10621 VTY_NEWLINE);
10622 return CMD_WARNING;
10623 }
10624
10625 table = peer->rib[AFI_IP][SAFI_UNICAST];
10626
ajs5a646652004-11-05 01:25:55 +000010627 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010628}
10629
10630ALIAS (show_ip_bgp_view_rsclient,
10631 show_ip_bgp_rsclient_cmd,
10632 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10633 SHOW_STR
10634 IP_STR
10635 BGP_STR
10636 "Information about Route Server Client\n"
10637 NEIGHBOR_ADDR_STR)
10638
Michael Lambert95cbbd22010-07-23 14:43:04 -040010639DEFUN (show_bgp_view_ipv4_safi_rsclient,
10640 show_bgp_view_ipv4_safi_rsclient_cmd,
10641 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10642 SHOW_STR
10643 BGP_STR
10644 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010645 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010646 "Address family\n"
10647 "Address Family modifier\n"
10648 "Address Family modifier\n"
10649 "Information about Route Server Client\n"
10650 NEIGHBOR_ADDR_STR)
10651{
10652 struct bgp_table *table;
10653 struct peer *peer;
10654 safi_t safi;
10655
10656 if (argc == 3) {
10657 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10658 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10659 } else {
10660 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10661 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10662 }
10663
10664 if (! peer)
10665 return CMD_WARNING;
10666
10667 if (! peer->afc[AFI_IP][safi])
10668 {
10669 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10670 VTY_NEWLINE);
10671 return CMD_WARNING;
10672 }
10673
10674 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10675 PEER_FLAG_RSERVER_CLIENT))
10676 {
10677 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10678 VTY_NEWLINE);
10679 return CMD_WARNING;
10680 }
10681
10682 table = peer->rib[AFI_IP][safi];
10683
10684 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10685}
10686
10687ALIAS (show_bgp_view_ipv4_safi_rsclient,
10688 show_bgp_ipv4_safi_rsclient_cmd,
10689 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10690 SHOW_STR
10691 BGP_STR
10692 "Address family\n"
10693 "Address Family modifier\n"
10694 "Address Family modifier\n"
10695 "Information about Route Server Client\n"
10696 NEIGHBOR_ADDR_STR)
10697
paulfee0f4c2004-09-13 05:12:46 +000010698DEFUN (show_ip_bgp_view_rsclient_route,
10699 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010700 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010701 SHOW_STR
10702 IP_STR
10703 BGP_STR
10704 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010705 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010706 "Information about Route Server Client\n"
10707 NEIGHBOR_ADDR_STR
10708 "Network in the BGP routing table to display\n")
10709{
10710 struct bgp *bgp;
10711 struct peer *peer;
10712
10713 /* BGP structure lookup. */
10714 if (argc == 3)
10715 {
10716 bgp = bgp_lookup_by_name (argv[0]);
10717 if (bgp == NULL)
10718 {
10719 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10720 return CMD_WARNING;
10721 }
10722 }
10723 else
10724 {
10725 bgp = bgp_get_default ();
10726 if (bgp == NULL)
10727 {
10728 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10729 return CMD_WARNING;
10730 }
10731 }
10732
10733 if (argc == 3)
10734 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10735 else
10736 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10737
10738 if (! peer)
10739 return CMD_WARNING;
10740
10741 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10742 {
10743 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10744 VTY_NEWLINE);
10745 return CMD_WARNING;
10746}
10747
10748 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10749 PEER_FLAG_RSERVER_CLIENT))
10750 {
10751 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10752 VTY_NEWLINE);
10753 return CMD_WARNING;
10754 }
10755
10756 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10757 (argc == 3) ? argv[2] : argv[1],
10758 AFI_IP, SAFI_UNICAST, NULL, 0);
10759}
10760
10761ALIAS (show_ip_bgp_view_rsclient_route,
10762 show_ip_bgp_rsclient_route_cmd,
10763 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10764 SHOW_STR
10765 IP_STR
10766 BGP_STR
10767 "Information about Route Server Client\n"
10768 NEIGHBOR_ADDR_STR
10769 "Network in the BGP routing table to display\n")
10770
Michael Lambert95cbbd22010-07-23 14:43:04 -040010771DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10772 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10773 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10774 SHOW_STR
10775 BGP_STR
10776 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010777 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010778 "Address family\n"
10779 "Address Family modifier\n"
10780 "Address Family modifier\n"
10781 "Information about Route Server Client\n"
10782 NEIGHBOR_ADDR_STR
10783 "Network in the BGP routing table to display\n")
10784{
10785 struct bgp *bgp;
10786 struct peer *peer;
10787 safi_t safi;
10788
10789 /* BGP structure lookup. */
10790 if (argc == 4)
10791 {
10792 bgp = bgp_lookup_by_name (argv[0]);
10793 if (bgp == NULL)
10794 {
10795 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10796 return CMD_WARNING;
10797 }
10798 }
10799 else
10800 {
10801 bgp = bgp_get_default ();
10802 if (bgp == NULL)
10803 {
10804 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10805 return CMD_WARNING;
10806 }
10807 }
10808
10809 if (argc == 4) {
10810 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10811 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10812 } else {
10813 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10814 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10815 }
10816
10817 if (! peer)
10818 return CMD_WARNING;
10819
10820 if (! peer->afc[AFI_IP][safi])
10821 {
10822 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10823 VTY_NEWLINE);
10824 return CMD_WARNING;
10825}
10826
10827 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10828 PEER_FLAG_RSERVER_CLIENT))
10829 {
10830 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10831 VTY_NEWLINE);
10832 return CMD_WARNING;
10833 }
10834
10835 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10836 (argc == 4) ? argv[3] : argv[2],
10837 AFI_IP, safi, NULL, 0);
10838}
10839
10840ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10841 show_bgp_ipv4_safi_rsclient_route_cmd,
10842 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10843 SHOW_STR
10844 BGP_STR
10845 "Address family\n"
10846 "Address Family modifier\n"
10847 "Address Family modifier\n"
10848 "Information about Route Server Client\n"
10849 NEIGHBOR_ADDR_STR
10850 "Network in the BGP routing table to display\n")
10851
paulfee0f4c2004-09-13 05:12:46 +000010852DEFUN (show_ip_bgp_view_rsclient_prefix,
10853 show_ip_bgp_view_rsclient_prefix_cmd,
10854 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10855 SHOW_STR
10856 IP_STR
10857 BGP_STR
10858 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010859 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010860 "Information about Route Server Client\n"
10861 NEIGHBOR_ADDR_STR
10862 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10863{
10864 struct bgp *bgp;
10865 struct peer *peer;
10866
10867 /* BGP structure lookup. */
10868 if (argc == 3)
10869 {
10870 bgp = bgp_lookup_by_name (argv[0]);
10871 if (bgp == NULL)
10872 {
10873 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10874 return CMD_WARNING;
10875 }
10876 }
10877 else
10878 {
10879 bgp = bgp_get_default ();
10880 if (bgp == NULL)
10881 {
10882 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10883 return CMD_WARNING;
10884 }
10885 }
10886
10887 if (argc == 3)
10888 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10889 else
10890 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10891
10892 if (! peer)
10893 return CMD_WARNING;
10894
10895 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10896 {
10897 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10898 VTY_NEWLINE);
10899 return CMD_WARNING;
10900}
10901
10902 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10903 PEER_FLAG_RSERVER_CLIENT))
10904{
10905 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10906 VTY_NEWLINE);
10907 return CMD_WARNING;
10908 }
10909
10910 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10911 (argc == 3) ? argv[2] : argv[1],
10912 AFI_IP, SAFI_UNICAST, NULL, 1);
10913}
10914
10915ALIAS (show_ip_bgp_view_rsclient_prefix,
10916 show_ip_bgp_rsclient_prefix_cmd,
10917 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10918 SHOW_STR
10919 IP_STR
10920 BGP_STR
10921 "Information about Route Server Client\n"
10922 NEIGHBOR_ADDR_STR
10923 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10924
Michael Lambert95cbbd22010-07-23 14:43:04 -040010925DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10926 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10927 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10928 SHOW_STR
10929 BGP_STR
10930 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010931 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010932 "Address family\n"
10933 "Address Family modifier\n"
10934 "Address Family modifier\n"
10935 "Information about Route Server Client\n"
10936 NEIGHBOR_ADDR_STR
10937 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10938{
10939 struct bgp *bgp;
10940 struct peer *peer;
10941 safi_t safi;
10942
10943 /* BGP structure lookup. */
10944 if (argc == 4)
10945 {
10946 bgp = bgp_lookup_by_name (argv[0]);
10947 if (bgp == NULL)
10948 {
10949 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10950 return CMD_WARNING;
10951 }
10952 }
10953 else
10954 {
10955 bgp = bgp_get_default ();
10956 if (bgp == NULL)
10957 {
10958 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10959 return CMD_WARNING;
10960 }
10961 }
10962
10963 if (argc == 4) {
10964 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10965 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10966 } else {
10967 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10968 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10969 }
10970
10971 if (! peer)
10972 return CMD_WARNING;
10973
10974 if (! peer->afc[AFI_IP][safi])
10975 {
10976 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10977 VTY_NEWLINE);
10978 return CMD_WARNING;
10979}
10980
10981 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10982 PEER_FLAG_RSERVER_CLIENT))
10983{
10984 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10985 VTY_NEWLINE);
10986 return CMD_WARNING;
10987 }
10988
10989 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10990 (argc == 4) ? argv[3] : argv[2],
10991 AFI_IP, safi, NULL, 1);
10992}
10993
10994ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
10995 show_bgp_ipv4_safi_rsclient_prefix_cmd,
10996 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10997 SHOW_STR
10998 BGP_STR
10999 "Address family\n"
11000 "Address Family modifier\n"
11001 "Address Family modifier\n"
11002 "Information about Route Server Client\n"
11003 NEIGHBOR_ADDR_STR
11004 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011005
paul718e3742002-12-13 20:15:29 +000011006#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011007DEFUN (show_bgp_view_neighbor_routes,
11008 show_bgp_view_neighbor_routes_cmd,
11009 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11010 SHOW_STR
11011 BGP_STR
11012 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011013 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011014 "Detailed information on TCP and BGP neighbor connections\n"
11015 "Neighbor to display information about\n"
11016 "Neighbor to display information about\n"
11017 "Display routes learned from neighbor\n")
11018{
11019 struct peer *peer;
11020
11021 if (argc == 2)
11022 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11023 else
11024 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11025
11026 if (! peer)
11027 return CMD_WARNING;
11028
11029 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11030 bgp_show_type_neighbor);
11031}
11032
11033ALIAS (show_bgp_view_neighbor_routes,
11034 show_bgp_view_ipv6_neighbor_routes_cmd,
11035 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11036 SHOW_STR
11037 BGP_STR
11038 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011039 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011040 "Address family\n"
11041 "Detailed information on TCP and BGP neighbor connections\n"
11042 "Neighbor to display information about\n"
11043 "Neighbor to display information about\n"
11044 "Display routes learned from neighbor\n")
11045
11046DEFUN (show_bgp_view_neighbor_damp,
11047 show_bgp_view_neighbor_damp_cmd,
11048 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11049 SHOW_STR
11050 BGP_STR
11051 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011052 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011053 "Detailed information on TCP and BGP neighbor connections\n"
11054 "Neighbor to display information about\n"
11055 "Neighbor to display information about\n"
11056 "Display the dampened routes received from neighbor\n")
11057{
11058 struct peer *peer;
11059
11060 if (argc == 2)
11061 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11062 else
11063 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11064
11065 if (! peer)
11066 return CMD_WARNING;
11067
11068 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11069 bgp_show_type_damp_neighbor);
11070}
11071
11072ALIAS (show_bgp_view_neighbor_damp,
11073 show_bgp_view_ipv6_neighbor_damp_cmd,
11074 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11075 SHOW_STR
11076 BGP_STR
11077 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011078 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011079 "Address family\n"
11080 "Detailed information on TCP and BGP neighbor connections\n"
11081 "Neighbor to display information about\n"
11082 "Neighbor to display information about\n"
11083 "Display the dampened routes received from neighbor\n")
11084
11085DEFUN (show_bgp_view_neighbor_flap,
11086 show_bgp_view_neighbor_flap_cmd,
11087 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11088 SHOW_STR
11089 BGP_STR
11090 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011091 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011092 "Detailed information on TCP and BGP neighbor connections\n"
11093 "Neighbor to display information about\n"
11094 "Neighbor to display information about\n"
11095 "Display flap statistics of the routes learned from neighbor\n")
11096{
11097 struct peer *peer;
11098
11099 if (argc == 2)
11100 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11101 else
11102 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11103
11104 if (! peer)
11105 return CMD_WARNING;
11106
11107 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11108 bgp_show_type_flap_neighbor);
11109}
11110
11111ALIAS (show_bgp_view_neighbor_flap,
11112 show_bgp_view_ipv6_neighbor_flap_cmd,
11113 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11114 SHOW_STR
11115 BGP_STR
11116 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011117 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011118 "Address family\n"
11119 "Detailed information on TCP and BGP neighbor connections\n"
11120 "Neighbor to display information about\n"
11121 "Neighbor to display information about\n"
11122 "Display flap statistics of the routes learned from neighbor\n")
11123
11124ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011125 show_bgp_neighbor_routes_cmd,
11126 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11127 SHOW_STR
11128 BGP_STR
11129 "Detailed information on TCP and BGP neighbor connections\n"
11130 "Neighbor to display information about\n"
11131 "Neighbor to display information about\n"
11132 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011133
paulbb46e942003-10-24 19:02:03 +000011134
11135ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011136 show_bgp_ipv6_neighbor_routes_cmd,
11137 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11138 SHOW_STR
11139 BGP_STR
11140 "Address family\n"
11141 "Detailed information on TCP and BGP neighbor connections\n"
11142 "Neighbor to display information about\n"
11143 "Neighbor to display information about\n"
11144 "Display routes learned from neighbor\n")
11145
11146/* old command */
paulbb46e942003-10-24 19:02:03 +000011147ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011148 ipv6_bgp_neighbor_routes_cmd,
11149 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11150 SHOW_STR
11151 IPV6_STR
11152 BGP_STR
11153 "Detailed information on TCP and BGP neighbor connections\n"
11154 "Neighbor to display information about\n"
11155 "Neighbor to display information about\n"
11156 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011157
11158/* old command */
11159DEFUN (ipv6_mbgp_neighbor_routes,
11160 ipv6_mbgp_neighbor_routes_cmd,
11161 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11162 SHOW_STR
11163 IPV6_STR
11164 MBGP_STR
11165 "Detailed information on TCP and BGP neighbor connections\n"
11166 "Neighbor to display information about\n"
11167 "Neighbor to display information about\n"
11168 "Display routes learned from neighbor\n")
11169{
paulbb46e942003-10-24 19:02:03 +000011170 struct peer *peer;
11171
11172 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11173 if (! peer)
11174 return CMD_WARNING;
11175
11176 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011177 bgp_show_type_neighbor);
11178}
paulbb46e942003-10-24 19:02:03 +000011179
11180ALIAS (show_bgp_view_neighbor_flap,
11181 show_bgp_neighbor_flap_cmd,
11182 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11183 SHOW_STR
11184 BGP_STR
11185 "Detailed information on TCP and BGP neighbor connections\n"
11186 "Neighbor to display information about\n"
11187 "Neighbor to display information about\n"
11188 "Display flap statistics of the routes learned from neighbor\n")
11189
11190ALIAS (show_bgp_view_neighbor_flap,
11191 show_bgp_ipv6_neighbor_flap_cmd,
11192 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11193 SHOW_STR
11194 BGP_STR
11195 "Address family\n"
11196 "Detailed information on TCP and BGP neighbor connections\n"
11197 "Neighbor to display information about\n"
11198 "Neighbor to display information about\n"
11199 "Display flap statistics of the routes learned from neighbor\n")
11200
11201ALIAS (show_bgp_view_neighbor_damp,
11202 show_bgp_neighbor_damp_cmd,
11203 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11204 SHOW_STR
11205 BGP_STR
11206 "Detailed information on TCP and BGP neighbor connections\n"
11207 "Neighbor to display information about\n"
11208 "Neighbor to display information about\n"
11209 "Display the dampened routes received from neighbor\n")
11210
11211ALIAS (show_bgp_view_neighbor_damp,
11212 show_bgp_ipv6_neighbor_damp_cmd,
11213 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11214 SHOW_STR
11215 BGP_STR
11216 "Address family\n"
11217 "Detailed information on TCP and BGP neighbor connections\n"
11218 "Neighbor to display information about\n"
11219 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011220 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011221
11222DEFUN (show_bgp_view_rsclient,
11223 show_bgp_view_rsclient_cmd,
11224 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11225 SHOW_STR
11226 BGP_STR
11227 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011228 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011229 "Information about Route Server Client\n"
11230 NEIGHBOR_ADDR_STR)
11231{
11232 struct bgp_table *table;
11233 struct peer *peer;
11234
11235 if (argc == 2)
11236 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11237 else
11238 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11239
11240 if (! peer)
11241 return CMD_WARNING;
11242
11243 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11244 {
11245 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11246 VTY_NEWLINE);
11247 return CMD_WARNING;
11248 }
11249
11250 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11251 PEER_FLAG_RSERVER_CLIENT))
11252 {
11253 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11254 VTY_NEWLINE);
11255 return CMD_WARNING;
11256 }
11257
11258 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11259
ajs5a646652004-11-05 01:25:55 +000011260 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011261}
11262
11263ALIAS (show_bgp_view_rsclient,
11264 show_bgp_rsclient_cmd,
11265 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11266 SHOW_STR
11267 BGP_STR
11268 "Information about Route Server Client\n"
11269 NEIGHBOR_ADDR_STR)
11270
Michael Lambert95cbbd22010-07-23 14:43:04 -040011271DEFUN (show_bgp_view_ipv6_safi_rsclient,
11272 show_bgp_view_ipv6_safi_rsclient_cmd,
11273 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11274 SHOW_STR
11275 BGP_STR
11276 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011277 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011278 "Address family\n"
11279 "Address Family modifier\n"
11280 "Address Family modifier\n"
11281 "Information about Route Server Client\n"
11282 NEIGHBOR_ADDR_STR)
11283{
11284 struct bgp_table *table;
11285 struct peer *peer;
11286 safi_t safi;
11287
11288 if (argc == 3) {
11289 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11290 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11291 } else {
11292 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11293 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11294 }
11295
11296 if (! peer)
11297 return CMD_WARNING;
11298
11299 if (! peer->afc[AFI_IP6][safi])
11300 {
11301 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11302 VTY_NEWLINE);
11303 return CMD_WARNING;
11304 }
11305
11306 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11307 PEER_FLAG_RSERVER_CLIENT))
11308 {
11309 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11310 VTY_NEWLINE);
11311 return CMD_WARNING;
11312 }
11313
11314 table = peer->rib[AFI_IP6][safi];
11315
11316 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11317}
11318
11319ALIAS (show_bgp_view_ipv6_safi_rsclient,
11320 show_bgp_ipv6_safi_rsclient_cmd,
11321 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11322 SHOW_STR
11323 BGP_STR
11324 "Address family\n"
11325 "Address Family modifier\n"
11326 "Address Family modifier\n"
11327 "Information about Route Server Client\n"
11328 NEIGHBOR_ADDR_STR)
11329
paulfee0f4c2004-09-13 05:12:46 +000011330DEFUN (show_bgp_view_rsclient_route,
11331 show_bgp_view_rsclient_route_cmd,
11332 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11333 SHOW_STR
11334 BGP_STR
11335 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011336 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011337 "Information about Route Server Client\n"
11338 NEIGHBOR_ADDR_STR
11339 "Network in the BGP routing table to display\n")
11340{
11341 struct bgp *bgp;
11342 struct peer *peer;
11343
11344 /* BGP structure lookup. */
11345 if (argc == 3)
11346 {
11347 bgp = bgp_lookup_by_name (argv[0]);
11348 if (bgp == NULL)
11349 {
11350 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11351 return CMD_WARNING;
11352 }
11353 }
11354 else
11355 {
11356 bgp = bgp_get_default ();
11357 if (bgp == NULL)
11358 {
11359 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11360 return CMD_WARNING;
11361 }
11362 }
11363
11364 if (argc == 3)
11365 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11366 else
11367 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11368
11369 if (! peer)
11370 return CMD_WARNING;
11371
11372 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11373 {
11374 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11375 VTY_NEWLINE);
11376 return CMD_WARNING;
11377 }
11378
11379 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11380 PEER_FLAG_RSERVER_CLIENT))
11381 {
11382 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11383 VTY_NEWLINE);
11384 return CMD_WARNING;
11385 }
11386
11387 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11388 (argc == 3) ? argv[2] : argv[1],
11389 AFI_IP6, SAFI_UNICAST, NULL, 0);
11390}
11391
11392ALIAS (show_bgp_view_rsclient_route,
11393 show_bgp_rsclient_route_cmd,
11394 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11395 SHOW_STR
11396 BGP_STR
11397 "Information about Route Server Client\n"
11398 NEIGHBOR_ADDR_STR
11399 "Network in the BGP routing table to display\n")
11400
Michael Lambert95cbbd22010-07-23 14:43:04 -040011401DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11402 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11403 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11404 SHOW_STR
11405 BGP_STR
11406 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011407 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011408 "Address family\n"
11409 "Address Family modifier\n"
11410 "Address Family modifier\n"
11411 "Information about Route Server Client\n"
11412 NEIGHBOR_ADDR_STR
11413 "Network in the BGP routing table to display\n")
11414{
11415 struct bgp *bgp;
11416 struct peer *peer;
11417 safi_t safi;
11418
11419 /* BGP structure lookup. */
11420 if (argc == 4)
11421 {
11422 bgp = bgp_lookup_by_name (argv[0]);
11423 if (bgp == NULL)
11424 {
11425 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11426 return CMD_WARNING;
11427 }
11428 }
11429 else
11430 {
11431 bgp = bgp_get_default ();
11432 if (bgp == NULL)
11433 {
11434 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11435 return CMD_WARNING;
11436 }
11437 }
11438
11439 if (argc == 4) {
11440 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11441 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11442 } else {
11443 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11444 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11445 }
11446
11447 if (! peer)
11448 return CMD_WARNING;
11449
11450 if (! peer->afc[AFI_IP6][safi])
11451 {
11452 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11453 VTY_NEWLINE);
11454 return CMD_WARNING;
11455}
11456
11457 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11458 PEER_FLAG_RSERVER_CLIENT))
11459 {
11460 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11461 VTY_NEWLINE);
11462 return CMD_WARNING;
11463 }
11464
11465 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11466 (argc == 4) ? argv[3] : argv[2],
11467 AFI_IP6, safi, NULL, 0);
11468}
11469
11470ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11471 show_bgp_ipv6_safi_rsclient_route_cmd,
11472 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11473 SHOW_STR
11474 BGP_STR
11475 "Address family\n"
11476 "Address Family modifier\n"
11477 "Address Family modifier\n"
11478 "Information about Route Server Client\n"
11479 NEIGHBOR_ADDR_STR
11480 "Network in the BGP routing table to display\n")
11481
paulfee0f4c2004-09-13 05:12:46 +000011482DEFUN (show_bgp_view_rsclient_prefix,
11483 show_bgp_view_rsclient_prefix_cmd,
11484 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11485 SHOW_STR
11486 BGP_STR
11487 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011488 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011489 "Information about Route Server Client\n"
11490 NEIGHBOR_ADDR_STR
11491 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11492{
11493 struct bgp *bgp;
11494 struct peer *peer;
11495
11496 /* BGP structure lookup. */
11497 if (argc == 3)
11498 {
11499 bgp = bgp_lookup_by_name (argv[0]);
11500 if (bgp == NULL)
11501 {
11502 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11503 return CMD_WARNING;
11504 }
11505 }
11506 else
11507 {
11508 bgp = bgp_get_default ();
11509 if (bgp == NULL)
11510 {
11511 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11512 return CMD_WARNING;
11513 }
11514 }
11515
11516 if (argc == 3)
11517 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11518 else
11519 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11520
11521 if (! peer)
11522 return CMD_WARNING;
11523
11524 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11525 {
11526 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11527 VTY_NEWLINE);
11528 return CMD_WARNING;
11529 }
11530
11531 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11532 PEER_FLAG_RSERVER_CLIENT))
11533 {
11534 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11535 VTY_NEWLINE);
11536 return CMD_WARNING;
11537 }
11538
11539 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11540 (argc == 3) ? argv[2] : argv[1],
11541 AFI_IP6, SAFI_UNICAST, NULL, 1);
11542}
11543
11544ALIAS (show_bgp_view_rsclient_prefix,
11545 show_bgp_rsclient_prefix_cmd,
11546 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11547 SHOW_STR
11548 BGP_STR
11549 "Information about Route Server Client\n"
11550 NEIGHBOR_ADDR_STR
11551 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11552
Michael Lambert95cbbd22010-07-23 14:43:04 -040011553DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11554 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11555 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11556 SHOW_STR
11557 BGP_STR
11558 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011559 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011560 "Address family\n"
11561 "Address Family modifier\n"
11562 "Address Family modifier\n"
11563 "Information about Route Server Client\n"
11564 NEIGHBOR_ADDR_STR
11565 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11566{
11567 struct bgp *bgp;
11568 struct peer *peer;
11569 safi_t safi;
11570
11571 /* BGP structure lookup. */
11572 if (argc == 4)
11573 {
11574 bgp = bgp_lookup_by_name (argv[0]);
11575 if (bgp == NULL)
11576 {
11577 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11578 return CMD_WARNING;
11579 }
11580 }
11581 else
11582 {
11583 bgp = bgp_get_default ();
11584 if (bgp == NULL)
11585 {
11586 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11587 return CMD_WARNING;
11588 }
11589 }
11590
11591 if (argc == 4) {
11592 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11593 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11594 } else {
11595 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11596 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11597 }
11598
11599 if (! peer)
11600 return CMD_WARNING;
11601
11602 if (! peer->afc[AFI_IP6][safi])
11603 {
11604 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11605 VTY_NEWLINE);
11606 return CMD_WARNING;
11607}
11608
11609 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11610 PEER_FLAG_RSERVER_CLIENT))
11611{
11612 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11613 VTY_NEWLINE);
11614 return CMD_WARNING;
11615 }
11616
11617 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11618 (argc == 4) ? argv[3] : argv[2],
11619 AFI_IP6, safi, NULL, 1);
11620}
11621
11622ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11623 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11624 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11625 SHOW_STR
11626 BGP_STR
11627 "Address family\n"
11628 "Address Family modifier\n"
11629 "Address Family modifier\n"
11630 "Information about Route Server Client\n"
11631 NEIGHBOR_ADDR_STR
11632 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11633
paul718e3742002-12-13 20:15:29 +000011634#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020011635
paul718e3742002-12-13 20:15:29 +000011636struct bgp_table *bgp_distance_table;
11637
11638struct bgp_distance
11639{
11640 /* Distance value for the IP source prefix. */
11641 u_char distance;
11642
11643 /* Name of the access-list to be matched. */
11644 char *access_list;
11645};
11646
paul94f2b392005-06-28 12:44:16 +000011647static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011648bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011649{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011650 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011651}
11652
paul94f2b392005-06-28 12:44:16 +000011653static void
paul718e3742002-12-13 20:15:29 +000011654bgp_distance_free (struct bgp_distance *bdistance)
11655{
11656 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11657}
11658
paul94f2b392005-06-28 12:44:16 +000011659static int
paulfd79ac92004-10-13 05:06:08 +000011660bgp_distance_set (struct vty *vty, const char *distance_str,
11661 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011662{
11663 int ret;
11664 struct prefix_ipv4 p;
11665 u_char distance;
11666 struct bgp_node *rn;
11667 struct bgp_distance *bdistance;
11668
11669 ret = str2prefix_ipv4 (ip_str, &p);
11670 if (ret == 0)
11671 {
11672 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11673 return CMD_WARNING;
11674 }
11675
11676 distance = atoi (distance_str);
11677
11678 /* Get BGP distance node. */
11679 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11680 if (rn->info)
11681 {
11682 bdistance = rn->info;
11683 bgp_unlock_node (rn);
11684 }
11685 else
11686 {
11687 bdistance = bgp_distance_new ();
11688 rn->info = bdistance;
11689 }
11690
11691 /* Set distance value. */
11692 bdistance->distance = distance;
11693
11694 /* Reset access-list configuration. */
11695 if (bdistance->access_list)
11696 {
11697 free (bdistance->access_list);
11698 bdistance->access_list = NULL;
11699 }
11700 if (access_list_str)
11701 bdistance->access_list = strdup (access_list_str);
11702
11703 return CMD_SUCCESS;
11704}
11705
paul94f2b392005-06-28 12:44:16 +000011706static int
paulfd79ac92004-10-13 05:06:08 +000011707bgp_distance_unset (struct vty *vty, const char *distance_str,
11708 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011709{
11710 int ret;
11711 struct prefix_ipv4 p;
11712 u_char distance;
11713 struct bgp_node *rn;
11714 struct bgp_distance *bdistance;
11715
11716 ret = str2prefix_ipv4 (ip_str, &p);
11717 if (ret == 0)
11718 {
11719 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11720 return CMD_WARNING;
11721 }
11722
11723 distance = atoi (distance_str);
11724
11725 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11726 if (! rn)
11727 {
11728 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11729 return CMD_WARNING;
11730 }
11731
11732 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010011733
11734 if (bdistance->distance != distance)
11735 {
11736 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
11737 return CMD_WARNING;
11738 }
11739
paul718e3742002-12-13 20:15:29 +000011740 if (bdistance->access_list)
11741 free (bdistance->access_list);
11742 bgp_distance_free (bdistance);
11743
11744 rn->info = NULL;
11745 bgp_unlock_node (rn);
11746 bgp_unlock_node (rn);
11747
11748 return CMD_SUCCESS;
11749}
11750
paul718e3742002-12-13 20:15:29 +000011751/* Apply BGP information to distance method. */
11752u_char
11753bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11754{
11755 struct bgp_node *rn;
11756 struct prefix_ipv4 q;
11757 struct peer *peer;
11758 struct bgp_distance *bdistance;
11759 struct access_list *alist;
11760 struct bgp_static *bgp_static;
11761
11762 if (! bgp)
11763 return 0;
11764
11765 if (p->family != AF_INET)
11766 return 0;
11767
11768 peer = rinfo->peer;
11769
11770 if (peer->su.sa.sa_family != AF_INET)
11771 return 0;
11772
11773 memset (&q, 0, sizeof (struct prefix_ipv4));
11774 q.family = AF_INET;
11775 q.prefix = peer->su.sin.sin_addr;
11776 q.prefixlen = IPV4_MAX_BITLEN;
11777
11778 /* Check source address. */
11779 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11780 if (rn)
11781 {
11782 bdistance = rn->info;
11783 bgp_unlock_node (rn);
11784
11785 if (bdistance->access_list)
11786 {
11787 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11788 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11789 return bdistance->distance;
11790 }
11791 else
11792 return bdistance->distance;
11793 }
11794
11795 /* Backdoor check. */
11796 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11797 if (rn)
11798 {
11799 bgp_static = rn->info;
11800 bgp_unlock_node (rn);
11801
11802 if (bgp_static->backdoor)
11803 {
11804 if (bgp->distance_local)
11805 return bgp->distance_local;
11806 else
11807 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11808 }
11809 }
11810
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011811 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011812 {
11813 if (bgp->distance_ebgp)
11814 return bgp->distance_ebgp;
11815 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11816 }
11817 else
11818 {
11819 if (bgp->distance_ibgp)
11820 return bgp->distance_ibgp;
11821 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11822 }
11823}
11824
11825DEFUN (bgp_distance,
11826 bgp_distance_cmd,
11827 "distance bgp <1-255> <1-255> <1-255>",
11828 "Define an administrative distance\n"
11829 "BGP distance\n"
11830 "Distance for routes external to the AS\n"
11831 "Distance for routes internal to the AS\n"
11832 "Distance for local routes\n")
11833{
11834 struct bgp *bgp;
11835
11836 bgp = vty->index;
11837
11838 bgp->distance_ebgp = atoi (argv[0]);
11839 bgp->distance_ibgp = atoi (argv[1]);
11840 bgp->distance_local = atoi (argv[2]);
11841 return CMD_SUCCESS;
11842}
11843
11844DEFUN (no_bgp_distance,
11845 no_bgp_distance_cmd,
11846 "no distance bgp <1-255> <1-255> <1-255>",
11847 NO_STR
11848 "Define an administrative distance\n"
11849 "BGP distance\n"
11850 "Distance for routes external to the AS\n"
11851 "Distance for routes internal to the AS\n"
11852 "Distance for local routes\n")
11853{
11854 struct bgp *bgp;
11855
11856 bgp = vty->index;
11857
11858 bgp->distance_ebgp= 0;
11859 bgp->distance_ibgp = 0;
11860 bgp->distance_local = 0;
11861 return CMD_SUCCESS;
11862}
11863
11864ALIAS (no_bgp_distance,
11865 no_bgp_distance2_cmd,
11866 "no distance bgp",
11867 NO_STR
11868 "Define an administrative distance\n"
11869 "BGP distance\n")
11870
11871DEFUN (bgp_distance_source,
11872 bgp_distance_source_cmd,
11873 "distance <1-255> A.B.C.D/M",
11874 "Define an administrative distance\n"
11875 "Administrative distance\n"
11876 "IP source prefix\n")
11877{
11878 bgp_distance_set (vty, argv[0], argv[1], NULL);
11879 return CMD_SUCCESS;
11880}
11881
11882DEFUN (no_bgp_distance_source,
11883 no_bgp_distance_source_cmd,
11884 "no distance <1-255> A.B.C.D/M",
11885 NO_STR
11886 "Define an administrative distance\n"
11887 "Administrative distance\n"
11888 "IP source prefix\n")
11889{
11890 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11891 return CMD_SUCCESS;
11892}
11893
11894DEFUN (bgp_distance_source_access_list,
11895 bgp_distance_source_access_list_cmd,
11896 "distance <1-255> A.B.C.D/M WORD",
11897 "Define an administrative distance\n"
11898 "Administrative distance\n"
11899 "IP source prefix\n"
11900 "Access list name\n")
11901{
11902 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11903 return CMD_SUCCESS;
11904}
11905
11906DEFUN (no_bgp_distance_source_access_list,
11907 no_bgp_distance_source_access_list_cmd,
11908 "no distance <1-255> A.B.C.D/M WORD",
11909 NO_STR
11910 "Define an administrative distance\n"
11911 "Administrative distance\n"
11912 "IP source prefix\n"
11913 "Access list name\n")
11914{
11915 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11916 return CMD_SUCCESS;
11917}
David Lamparter6b0655a2014-06-04 06:53:35 +020011918
paul718e3742002-12-13 20:15:29 +000011919DEFUN (bgp_damp_set,
11920 bgp_damp_set_cmd,
11921 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11922 "BGP Specific commands\n"
11923 "Enable route-flap dampening\n"
11924 "Half-life time for the penalty\n"
11925 "Value to start reusing a route\n"
11926 "Value to start suppressing a route\n"
11927 "Maximum duration to suppress a stable route\n")
11928{
11929 struct bgp *bgp;
11930 int half = DEFAULT_HALF_LIFE * 60;
11931 int reuse = DEFAULT_REUSE;
11932 int suppress = DEFAULT_SUPPRESS;
11933 int max = 4 * half;
11934
11935 if (argc == 4)
11936 {
11937 half = atoi (argv[0]) * 60;
11938 reuse = atoi (argv[1]);
11939 suppress = atoi (argv[2]);
11940 max = atoi (argv[3]) * 60;
11941 }
11942 else if (argc == 1)
11943 {
11944 half = atoi (argv[0]) * 60;
11945 max = 4 * half;
11946 }
11947
11948 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000011949
11950 if (suppress < reuse)
11951 {
11952 vty_out (vty, "Suppress value cannot be less than reuse value %s",
11953 VTY_NEWLINE);
11954 return 0;
11955 }
11956
paul718e3742002-12-13 20:15:29 +000011957 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11958 half, reuse, suppress, max);
11959}
11960
11961ALIAS (bgp_damp_set,
11962 bgp_damp_set2_cmd,
11963 "bgp dampening <1-45>",
11964 "BGP Specific commands\n"
11965 "Enable route-flap dampening\n"
11966 "Half-life time for the penalty\n")
11967
11968ALIAS (bgp_damp_set,
11969 bgp_damp_set3_cmd,
11970 "bgp dampening",
11971 "BGP Specific commands\n"
11972 "Enable route-flap dampening\n")
11973
11974DEFUN (bgp_damp_unset,
11975 bgp_damp_unset_cmd,
11976 "no bgp dampening",
11977 NO_STR
11978 "BGP Specific commands\n"
11979 "Enable route-flap dampening\n")
11980{
11981 struct bgp *bgp;
11982
11983 bgp = vty->index;
11984 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11985}
11986
11987ALIAS (bgp_damp_unset,
11988 bgp_damp_unset2_cmd,
11989 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11990 NO_STR
11991 "BGP Specific commands\n"
11992 "Enable route-flap dampening\n"
11993 "Half-life time for the penalty\n"
11994 "Value to start reusing a route\n"
11995 "Value to start suppressing a route\n"
11996 "Maximum duration to suppress a stable route\n")
11997
11998DEFUN (show_ip_bgp_dampened_paths,
11999 show_ip_bgp_dampened_paths_cmd,
12000 "show ip bgp dampened-paths",
12001 SHOW_STR
12002 IP_STR
12003 BGP_STR
12004 "Display paths suppressed due to dampening\n")
12005{
ajs5a646652004-11-05 01:25:55 +000012006 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
12007 NULL);
paul718e3742002-12-13 20:15:29 +000012008}
12009
12010DEFUN (show_ip_bgp_flap_statistics,
12011 show_ip_bgp_flap_statistics_cmd,
12012 "show ip bgp flap-statistics",
12013 SHOW_STR
12014 IP_STR
12015 BGP_STR
12016 "Display flap statistics of routes\n")
12017{
ajs5a646652004-11-05 01:25:55 +000012018 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12019 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012020}
David Lamparter6b0655a2014-06-04 06:53:35 +020012021
paul718e3742002-12-13 20:15:29 +000012022/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012023static int
paulfd79ac92004-10-13 05:06:08 +000012024bgp_clear_damp_route (struct vty *vty, const char *view_name,
12025 const char *ip_str, afi_t afi, safi_t safi,
12026 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012027{
12028 int ret;
12029 struct prefix match;
12030 struct bgp_node *rn;
12031 struct bgp_node *rm;
12032 struct bgp_info *ri;
12033 struct bgp_info *ri_temp;
12034 struct bgp *bgp;
12035 struct bgp_table *table;
12036
12037 /* BGP structure lookup. */
12038 if (view_name)
12039 {
12040 bgp = bgp_lookup_by_name (view_name);
12041 if (bgp == NULL)
12042 {
12043 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12044 return CMD_WARNING;
12045 }
12046 }
12047 else
12048 {
12049 bgp = bgp_get_default ();
12050 if (bgp == NULL)
12051 {
12052 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12053 return CMD_WARNING;
12054 }
12055 }
12056
12057 /* Check IP address argument. */
12058 ret = str2prefix (ip_str, &match);
12059 if (! ret)
12060 {
12061 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12062 return CMD_WARNING;
12063 }
12064
12065 match.family = afi2family (afi);
12066
12067 if (safi == SAFI_MPLS_VPN)
12068 {
12069 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12070 {
12071 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12072 continue;
12073
12074 if ((table = rn->info) != NULL)
12075 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012076 {
12077 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12078 {
12079 ri = rm->info;
12080 while (ri)
12081 {
12082 if (ri->extra && ri->extra->damp_info)
12083 {
12084 ri_temp = ri->next;
12085 bgp_damp_info_free (ri->extra->damp_info, 1);
12086 ri = ri_temp;
12087 }
12088 else
12089 ri = ri->next;
12090 }
12091 }
12092
12093 bgp_unlock_node (rm);
12094 }
paul718e3742002-12-13 20:15:29 +000012095 }
12096 }
12097 else
12098 {
12099 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012100 {
12101 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12102 {
12103 ri = rn->info;
12104 while (ri)
12105 {
12106 if (ri->extra && ri->extra->damp_info)
12107 {
12108 ri_temp = ri->next;
12109 bgp_damp_info_free (ri->extra->damp_info, 1);
12110 ri = ri_temp;
12111 }
12112 else
12113 ri = ri->next;
12114 }
12115 }
12116
12117 bgp_unlock_node (rn);
12118 }
paul718e3742002-12-13 20:15:29 +000012119 }
12120
12121 return CMD_SUCCESS;
12122}
12123
12124DEFUN (clear_ip_bgp_dampening,
12125 clear_ip_bgp_dampening_cmd,
12126 "clear ip bgp dampening",
12127 CLEAR_STR
12128 IP_STR
12129 BGP_STR
12130 "Clear route flap dampening information\n")
12131{
12132 bgp_damp_info_clean ();
12133 return CMD_SUCCESS;
12134}
12135
12136DEFUN (clear_ip_bgp_dampening_prefix,
12137 clear_ip_bgp_dampening_prefix_cmd,
12138 "clear ip bgp dampening A.B.C.D/M",
12139 CLEAR_STR
12140 IP_STR
12141 BGP_STR
12142 "Clear route flap dampening information\n"
12143 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12144{
12145 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12146 SAFI_UNICAST, NULL, 1);
12147}
12148
12149DEFUN (clear_ip_bgp_dampening_address,
12150 clear_ip_bgp_dampening_address_cmd,
12151 "clear ip bgp dampening A.B.C.D",
12152 CLEAR_STR
12153 IP_STR
12154 BGP_STR
12155 "Clear route flap dampening information\n"
12156 "Network to clear damping information\n")
12157{
12158 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12159 SAFI_UNICAST, NULL, 0);
12160}
12161
12162DEFUN (clear_ip_bgp_dampening_address_mask,
12163 clear_ip_bgp_dampening_address_mask_cmd,
12164 "clear ip bgp dampening A.B.C.D A.B.C.D",
12165 CLEAR_STR
12166 IP_STR
12167 BGP_STR
12168 "Clear route flap dampening information\n"
12169 "Network to clear damping information\n"
12170 "Network mask\n")
12171{
12172 int ret;
12173 char prefix_str[BUFSIZ];
12174
12175 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12176 if (! ret)
12177 {
12178 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12179 return CMD_WARNING;
12180 }
12181
12182 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12183 SAFI_UNICAST, NULL, 0);
12184}
David Lamparter6b0655a2014-06-04 06:53:35 +020012185
paul94f2b392005-06-28 12:44:16 +000012186static int
paul718e3742002-12-13 20:15:29 +000012187bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12188 afi_t afi, safi_t safi, int *write)
12189{
12190 struct bgp_node *prn;
12191 struct bgp_node *rn;
12192 struct bgp_table *table;
12193 struct prefix *p;
12194 struct prefix_rd *prd;
12195 struct bgp_static *bgp_static;
12196 u_int32_t label;
12197 char buf[SU_ADDRSTRLEN];
12198 char rdbuf[RD_ADDRSTRLEN];
12199
12200 /* Network configuration. */
12201 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12202 if ((table = prn->info) != NULL)
12203 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12204 if ((bgp_static = rn->info) != NULL)
12205 {
12206 p = &rn->p;
12207 prd = (struct prefix_rd *) &prn->p;
12208
12209 /* "address-family" display. */
12210 bgp_config_write_family_header (vty, afi, safi, write);
12211
12212 /* "network" configuration display. */
12213 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12214 label = decode_label (bgp_static->tag);
12215
12216 vty_out (vty, " network %s/%d rd %s tag %d",
12217 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12218 p->prefixlen,
12219 rdbuf, label);
12220 vty_out (vty, "%s", VTY_NEWLINE);
12221 }
12222 return 0;
12223}
12224
12225/* Configuration of static route announcement and aggregate
12226 information. */
12227int
12228bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12229 afi_t afi, safi_t safi, int *write)
12230{
12231 struct bgp_node *rn;
12232 struct prefix *p;
12233 struct bgp_static *bgp_static;
12234 struct bgp_aggregate *bgp_aggregate;
12235 char buf[SU_ADDRSTRLEN];
12236
12237 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12238 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12239
12240 /* Network configuration. */
12241 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12242 if ((bgp_static = rn->info) != NULL)
12243 {
12244 p = &rn->p;
12245
12246 /* "address-family" display. */
12247 bgp_config_write_family_header (vty, afi, safi, write);
12248
12249 /* "network" configuration display. */
12250 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12251 {
12252 u_int32_t destination;
12253 struct in_addr netmask;
12254
12255 destination = ntohl (p->u.prefix4.s_addr);
12256 masklen2ip (p->prefixlen, &netmask);
12257 vty_out (vty, " network %s",
12258 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12259
12260 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12261 || (IN_CLASSB (destination) && p->prefixlen == 16)
12262 || (IN_CLASSA (destination) && p->prefixlen == 8)
12263 || p->u.prefix4.s_addr == 0)
12264 {
12265 /* Natural mask is not display. */
12266 }
12267 else
12268 vty_out (vty, " mask %s", inet_ntoa (netmask));
12269 }
12270 else
12271 {
12272 vty_out (vty, " network %s/%d",
12273 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12274 p->prefixlen);
12275 }
12276
12277 if (bgp_static->rmap.name)
12278 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012279 else
12280 {
12281 if (bgp_static->backdoor)
12282 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012283 }
paul718e3742002-12-13 20:15:29 +000012284
12285 vty_out (vty, "%s", VTY_NEWLINE);
12286 }
12287
12288 /* Aggregate-address configuration. */
12289 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12290 if ((bgp_aggregate = rn->info) != NULL)
12291 {
12292 p = &rn->p;
12293
12294 /* "address-family" display. */
12295 bgp_config_write_family_header (vty, afi, safi, write);
12296
12297 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12298 {
12299 struct in_addr netmask;
12300
12301 masklen2ip (p->prefixlen, &netmask);
12302 vty_out (vty, " aggregate-address %s %s",
12303 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12304 inet_ntoa (netmask));
12305 }
12306 else
12307 {
12308 vty_out (vty, " aggregate-address %s/%d",
12309 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12310 p->prefixlen);
12311 }
12312
12313 if (bgp_aggregate->as_set)
12314 vty_out (vty, " as-set");
12315
12316 if (bgp_aggregate->summary_only)
12317 vty_out (vty, " summary-only");
12318
12319 vty_out (vty, "%s", VTY_NEWLINE);
12320 }
12321
12322 return 0;
12323}
12324
12325int
12326bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12327{
12328 struct bgp_node *rn;
12329 struct bgp_distance *bdistance;
12330
12331 /* Distance configuration. */
12332 if (bgp->distance_ebgp
12333 && bgp->distance_ibgp
12334 && bgp->distance_local
12335 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12336 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12337 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12338 vty_out (vty, " distance bgp %d %d %d%s",
12339 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12340 VTY_NEWLINE);
12341
12342 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12343 if ((bdistance = rn->info) != NULL)
12344 {
12345 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12346 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12347 bdistance->access_list ? bdistance->access_list : "",
12348 VTY_NEWLINE);
12349 }
12350
12351 return 0;
12352}
12353
12354/* Allocate routing table structure and install commands. */
12355void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012356bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012357{
12358 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012359 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012360
12361 /* IPv4 BGP commands. */
12362 install_element (BGP_NODE, &bgp_network_cmd);
12363 install_element (BGP_NODE, &bgp_network_mask_cmd);
12364 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12365 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12366 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12367 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12368 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12369 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12370 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12371 install_element (BGP_NODE, &no_bgp_network_cmd);
12372 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12373 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12374 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12375 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12376 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12377 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12378 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12379 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12380
12381 install_element (BGP_NODE, &aggregate_address_cmd);
12382 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12383 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12384 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12385 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12386 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12387 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12388 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12389 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12390 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12391 install_element (BGP_NODE, &no_aggregate_address_cmd);
12392 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12393 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12394 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12395 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12396 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12397 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12398 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12399 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12400 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12401
12402 /* IPv4 unicast configuration. */
12403 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12404 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12405 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12406 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12407 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12408 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012409 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012410 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12411 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12412 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12413 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12414 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012415
paul718e3742002-12-13 20:15:29 +000012416 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12417 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12418 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12419 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12420 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12421 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12422 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12423 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12424 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12425 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12426 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12427 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12428 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12429 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12430 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12431 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12432 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12433 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12434 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12435 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12436
12437 /* IPv4 multicast configuration. */
12438 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12439 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12440 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12441 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12442 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12443 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12444 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12445 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12446 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12447 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12448 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12449 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12450 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12451 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12452 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12453 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12454 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12455 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12456 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12457 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12458 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12459 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12460 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12461 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12462 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12463 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12464 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12465 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12466 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12467 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12468 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12469 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12470
12471 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12472 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012473 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012474 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12475 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012476 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012477 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12478 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12479 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12480 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012481 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012482 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12483 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12484 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12485 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12486 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12487 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12488 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12489 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12490 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12491 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12492 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12493 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12494 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12495 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12496 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12497 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12498 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12499 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12500 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12501 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12502 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12503 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12504 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12505 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12506 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012507 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12508 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12509 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12510 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12511 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012512 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12513 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12514 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12515 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12516 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12517 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12518 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12519 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12520 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12521 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12522 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12523 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12524 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12525 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12526 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12527 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12528 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12529 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012530 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012531 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12532 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12533 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12534 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12535 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12536 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12537 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12538 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12539 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12540 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12541 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12542 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12543 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12544 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12545 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12546 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012547 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012548 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012549 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012550 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012551 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012552 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012553 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12554 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012555 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012556 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012557 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012558 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012559 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012560 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012561
12562 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12563 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12564 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012565 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012566 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12567 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12568 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012569 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012570 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12571 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12572 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12573 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12574 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12575 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12576 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12577 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12578 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12579 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12580 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12581 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012582 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12583 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12584 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12585 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12586 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012587 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12588 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12589 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12590 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12591 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12592 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12593 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12594 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12595 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012596 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012597 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012598 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012599 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012600 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012601 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012602 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012603
12604 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12605 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012606 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012607 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12608 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012609 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012610 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12611 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12612 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12613 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012614 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012615 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12616 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12617 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12618 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12619 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12620 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12621 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12622 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12623 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12624 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12625 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12626 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12627 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12628 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12629 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12630 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12631 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12632 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12633 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12634 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12635 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12636 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12637 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12638 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12639 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012640 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12641 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12642 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12643 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12644 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012645 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12646 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12647 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12648 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12649 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12650 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12651 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12652 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12653 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12654 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12655 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12656 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12657 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12658 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12659 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12660 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12661 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12662 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012663 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012664 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12665 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12666 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12667 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12668 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12669 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12670 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12671 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12672 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12673 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12674 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12675 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12676 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12677 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12678 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12679 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012680 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012681 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012682 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012683 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012684 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012685 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012686 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12687 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012688 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012689 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012690 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012691 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012692 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012693 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012694
12695 /* BGP dampening clear commands */
12696 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12697 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12698 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12699 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12700
Paul Jakmaff7924f2006-09-04 01:10:36 +000012701 /* prefix count */
12702 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12703 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12704 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012705#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012706 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12707
paul718e3742002-12-13 20:15:29 +000012708 /* New config IPv6 BGP commands. */
12709 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12710 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12711 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12712 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12713
12714 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12715 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12716 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12717 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12718
G.Balaji73bfe0b2011-09-23 22:36:20 +053012719 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12720 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12721
paul718e3742002-12-13 20:15:29 +000012722 /* Old config IPv6 BGP commands. */
12723 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12724 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12725
12726 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12727 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12728 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12729 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12730
12731 install_element (VIEW_NODE, &show_bgp_cmd);
12732 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012733 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012734 install_element (VIEW_NODE, &show_bgp_route_cmd);
12735 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012736 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012737 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12738 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012739 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012740 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12741 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12742 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12743 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12744 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12745 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12746 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12747 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12748 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12749 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12750 install_element (VIEW_NODE, &show_bgp_community_cmd);
12751 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12752 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12753 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12754 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12755 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12756 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12757 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12758 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12759 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12760 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12761 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12762 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12763 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12764 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12765 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12766 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12767 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12768 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12769 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12770 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12771 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12772 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12773 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12774 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12775 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12776 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12777 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12778 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12779 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012780 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12781 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12782 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12783 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012784 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012785 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012786 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012787 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012788 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012789 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012790 install_element (VIEW_NODE, &show_bgp_view_cmd);
12791 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12792 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12793 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12794 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12795 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12796 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12797 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12798 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12799 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12800 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12801 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12802 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12803 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12804 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12805 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12806 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12807 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012808 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012809 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012810 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012811 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012812 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012813 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012814
12815 /* Restricted:
12816 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12817 */
12818 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12819 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012820 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012821 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12822 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012823 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012824 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12825 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12826 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12827 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12828 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12829 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12830 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12831 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12832 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12833 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12834 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12835 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12836 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12837 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12838 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12839 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12840 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012841 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012842 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012843 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012844 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12845 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12846 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12847 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12848 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12849 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12850 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012851 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012852 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012853 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012854
12855 install_element (ENABLE_NODE, &show_bgp_cmd);
12856 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012857 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012858 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12859 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012860 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012861 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12862 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012863 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012864 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12865 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12866 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12867 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12868 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12869 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12870 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12871 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12872 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12873 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12874 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12875 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12876 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12877 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12878 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12879 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12880 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12881 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12882 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12883 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12884 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12885 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12886 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12887 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12888 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12889 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12890 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12891 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12892 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12893 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12894 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12895 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12896 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12897 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12898 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12899 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12900 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12901 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12902 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12903 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012904 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12905 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12906 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12907 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012908 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012909 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012910 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012911 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012912 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012913 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012914 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12915 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12916 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12917 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12918 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12919 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12920 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12921 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12922 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12923 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12924 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12925 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12926 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12927 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12928 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12929 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12930 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12931 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012932 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012933 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012934 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012935 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012936 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012937 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012938
12939 /* Statistics */
12940 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12941 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12942 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12943 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12944
paul718e3742002-12-13 20:15:29 +000012945 /* old command */
12946 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12947 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12948 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12949 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12950 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12951 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12952 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12953 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12954 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12955 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12956 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12957 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12958 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12959 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12960 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12961 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12962 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12963 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12964 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12965 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12966 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12967 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12968 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12969 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12970 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12971 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12972 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12973 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12974 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12975 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12976 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12977 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12978 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12979 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12980 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12981 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012982
paul718e3742002-12-13 20:15:29 +000012983 /* old command */
12984 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12985 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12986 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12987 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12988 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12989 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12990 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12991 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12992 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12993 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12994 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12995 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12996 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12997 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12998 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12999 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13000 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13001 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13002 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13003 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13004 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13005 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13006 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13007 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13008 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13009 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13010 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13011 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13012 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13013 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13014 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13015 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13016 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13017 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13018 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13019 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13020
13021 /* old command */
13022 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13023 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13024 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13025 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13026
13027 /* old command */
13028 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13029 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13030 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13031 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13032
13033 /* old command */
13034 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13035 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13036 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13037 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13038#endif /* HAVE_IPV6 */
13039
13040 install_element (BGP_NODE, &bgp_distance_cmd);
13041 install_element (BGP_NODE, &no_bgp_distance_cmd);
13042 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13043 install_element (BGP_NODE, &bgp_distance_source_cmd);
13044 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13045 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13046 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13047
13048 install_element (BGP_NODE, &bgp_damp_set_cmd);
13049 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13050 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13051 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13052 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13053 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13054 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13055 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13056 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13057 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013058
13059 /* Deprecated AS-Pathlimit commands */
13060 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13061 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13062 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13063 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13064 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13065 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13066
13067 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13068 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13069 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13070 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13071 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13072 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13073
13074 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13075 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13076 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13077 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13078 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13079 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13080
13081 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13082 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13083 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13084 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13085 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13086 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13087
13088 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13089 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13090 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13091 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13092 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13093 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13094
13095 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13096 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13097 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13098 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13099 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13100 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013101
13102#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013103 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13104 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013105#endif
paul718e3742002-12-13 20:15:29 +000013106}
Chris Caputo228da422009-07-18 05:44:03 +000013107
13108void
13109bgp_route_finish (void)
13110{
13111 bgp_table_unlock (bgp_distance_table);
13112 bgp_distance_table = NULL;
13113}