blob: 316fa5a16e6fe0020431178c1050d6aa536757d5 [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;
Timo Teräs2820a012015-06-24 15:27:21 +0300567 /* locally configured routes to advertise do not have su_remote */
568 if (new->peer->su_remote == NULL)
569 return 0;
570 if (exist->peer->su_remote == NULL)
571 return 1;
572
paul718e3742002-12-13 20:15:29 +0000573 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
574
575 if (ret == 1)
576 return 0;
577 if (ret == -1)
578 return 1;
579
580 return 1;
581}
582
paul94f2b392005-06-28 12:44:16 +0000583static enum filter_type
paul718e3742002-12-13 20:15:29 +0000584bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
585 afi_t afi, safi_t safi)
586{
587 struct bgp_filter *filter;
588
589 filter = &peer->filter[afi][safi];
590
Paul Jakma650f76c2009-06-25 18:06:31 +0100591#define FILTER_EXIST_WARN(F,f,filter) \
592 if (BGP_DEBUG (update, UPDATE_IN) \
593 && !(F ## _IN (filter))) \
594 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
595 peer->host, #f, F ## _IN_NAME(filter));
596
597 if (DISTRIBUTE_IN_NAME (filter)) {
598 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
599
paul718e3742002-12-13 20:15:29 +0000600 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
601 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100602 }
paul718e3742002-12-13 20:15:29 +0000603
Paul Jakma650f76c2009-06-25 18:06:31 +0100604 if (PREFIX_LIST_IN_NAME (filter)) {
605 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
606
paul718e3742002-12-13 20:15:29 +0000607 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
608 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100609 }
paul718e3742002-12-13 20:15:29 +0000610
Paul Jakma650f76c2009-06-25 18:06:31 +0100611 if (FILTER_LIST_IN_NAME (filter)) {
612 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
613
paul718e3742002-12-13 20:15:29 +0000614 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
615 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100616 }
617
paul718e3742002-12-13 20:15:29 +0000618 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100619#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000620}
621
paul94f2b392005-06-28 12:44:16 +0000622static enum filter_type
paul718e3742002-12-13 20:15:29 +0000623bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
624 afi_t afi, safi_t safi)
625{
626 struct bgp_filter *filter;
627
628 filter = &peer->filter[afi][safi];
629
Paul Jakma650f76c2009-06-25 18:06:31 +0100630#define FILTER_EXIST_WARN(F,f,filter) \
631 if (BGP_DEBUG (update, UPDATE_OUT) \
632 && !(F ## _OUT (filter))) \
633 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
634 peer->host, #f, F ## _OUT_NAME(filter));
635
636 if (DISTRIBUTE_OUT_NAME (filter)) {
637 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
638
paul718e3742002-12-13 20:15:29 +0000639 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
640 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100641 }
paul718e3742002-12-13 20:15:29 +0000642
Paul Jakma650f76c2009-06-25 18:06:31 +0100643 if (PREFIX_LIST_OUT_NAME (filter)) {
644 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
645
paul718e3742002-12-13 20:15:29 +0000646 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
647 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100648 }
paul718e3742002-12-13 20:15:29 +0000649
Paul Jakma650f76c2009-06-25 18:06:31 +0100650 if (FILTER_LIST_OUT_NAME (filter)) {
651 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
652
paul718e3742002-12-13 20:15:29 +0000653 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
654 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100655 }
paul718e3742002-12-13 20:15:29 +0000656
657 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100658#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000659}
660
661/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000662static int
paul718e3742002-12-13 20:15:29 +0000663bgp_community_filter (struct peer *peer, struct attr *attr)
664{
665 if (attr->community)
666 {
667 /* NO_ADVERTISE check. */
668 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
669 return 1;
670
671 /* NO_EXPORT check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000672 if (peer->sort == BGP_PEER_EBGP &&
paul718e3742002-12-13 20:15:29 +0000673 community_include (attr->community, COMMUNITY_NO_EXPORT))
674 return 1;
675
676 /* NO_EXPORT_SUBCONFED check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000677 if (peer->sort == BGP_PEER_EBGP
678 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000679 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
680 return 1;
681 }
682 return 0;
683}
684
685/* Route reflection loop check. */
686static int
687bgp_cluster_filter (struct peer *peer, struct attr *attr)
688{
689 struct in_addr cluster_id;
690
Paul Jakmafb982c22007-05-04 20:15:47 +0000691 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000692 {
693 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
694 cluster_id = peer->bgp->cluster_id;
695 else
696 cluster_id = peer->bgp->router_id;
697
Paul Jakmafb982c22007-05-04 20:15:47 +0000698 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000699 return 1;
700 }
701 return 0;
702}
David Lamparter6b0655a2014-06-04 06:53:35 +0200703
paul94f2b392005-06-28 12:44:16 +0000704static int
paul718e3742002-12-13 20:15:29 +0000705bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
706 afi_t afi, safi_t safi)
707{
708 struct bgp_filter *filter;
709 struct bgp_info info;
710 route_map_result_t ret;
711
712 filter = &peer->filter[afi][safi];
713
714 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000715 if (peer->weight)
716 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000717
718 /* Route map apply. */
719 if (ROUTE_MAP_IN_NAME (filter))
720 {
721 /* Duplicate current value to new strucutre for modification. */
722 info.peer = peer;
723 info.attr = attr;
724
paulac41b2a2003-08-12 05:32:27 +0000725 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
726
paul718e3742002-12-13 20:15:29 +0000727 /* Apply BGP route map to the attribute. */
728 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000729
730 peer->rmap_type = 0;
731
paul718e3742002-12-13 20:15:29 +0000732 if (ret == RMAP_DENYMATCH)
David Lamparterc460e572014-06-04 00:54:58 +0200733 /* caller has multiple error paths with bgp_attr_flush() */
734 return RMAP_DENY;
paul718e3742002-12-13 20:15:29 +0000735 }
736 return RMAP_PERMIT;
737}
David Lamparter6b0655a2014-06-04 06:53:35 +0200738
paul94f2b392005-06-28 12:44:16 +0000739static int
paulfee0f4c2004-09-13 05:12:46 +0000740bgp_export_modifier (struct peer *rsclient, struct peer *peer,
741 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
742{
743 struct bgp_filter *filter;
744 struct bgp_info info;
745 route_map_result_t ret;
746
747 filter = &peer->filter[afi][safi];
748
749 /* Route map apply. */
750 if (ROUTE_MAP_EXPORT_NAME (filter))
751 {
752 /* Duplicate current value to new strucutre for modification. */
753 info.peer = rsclient;
754 info.attr = attr;
755
756 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
757
758 /* Apply BGP route map to the attribute. */
759 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
760
761 rsclient->rmap_type = 0;
762
763 if (ret == RMAP_DENYMATCH)
764 {
765 /* Free newly generated AS path and community by route-map. */
766 bgp_attr_flush (attr);
767 return RMAP_DENY;
768 }
769 }
770 return RMAP_PERMIT;
771}
772
paul94f2b392005-06-28 12:44:16 +0000773static int
paulfee0f4c2004-09-13 05:12:46 +0000774bgp_import_modifier (struct peer *rsclient, struct peer *peer,
775 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
776{
777 struct bgp_filter *filter;
778 struct bgp_info info;
779 route_map_result_t ret;
780
781 filter = &rsclient->filter[afi][safi];
782
783 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000784 if (peer->weight)
785 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000786
787 /* Route map apply. */
788 if (ROUTE_MAP_IMPORT_NAME (filter))
789 {
790 /* Duplicate current value to new strucutre for modification. */
791 info.peer = peer;
792 info.attr = attr;
793
794 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
795
796 /* Apply BGP route map to the attribute. */
797 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
798
799 peer->rmap_type = 0;
800
801 if (ret == RMAP_DENYMATCH)
802 {
803 /* Free newly generated AS path and community by route-map. */
804 bgp_attr_flush (attr);
805 return RMAP_DENY;
806 }
807 }
808 return RMAP_PERMIT;
809}
David Lamparter6b0655a2014-06-04 06:53:35 +0200810
paul94f2b392005-06-28 12:44:16 +0000811static int
paul718e3742002-12-13 20:15:29 +0000812bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
813 struct attr *attr, afi_t afi, safi_t safi)
814{
815 int ret;
816 char buf[SU_ADDRSTRLEN];
817 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000818 struct peer *from;
819 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000820 int transparent;
821 int reflect;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700822 struct attr *riattr;
paul718e3742002-12-13 20:15:29 +0000823
824 from = ri->peer;
825 filter = &peer->filter[afi][safi];
826 bgp = peer->bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700827 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paul718e3742002-12-13 20:15:29 +0000828
Paul Jakma750e8142008-07-22 21:11:48 +0000829 if (DISABLE_BGP_ANNOUNCE)
830 return 0;
paul718e3742002-12-13 20:15:29 +0000831
paulfee0f4c2004-09-13 05:12:46 +0000832 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
833 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
834 return 0;
835
paul718e3742002-12-13 20:15:29 +0000836 /* Do not send back route to sender. */
837 if (from == peer)
838 return 0;
839
840 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000841 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000842 if (! UNSUPPRESS_MAP_NAME (filter))
843 return 0;
844
845 /* Default route check. */
846 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
847 {
848 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
849 return 0;
850#ifdef HAVE_IPV6
851 else if (p->family == AF_INET6 && p->prefixlen == 0)
852 return 0;
853#endif /* HAVE_IPV6 */
854 }
855
paul286e1e72003-08-08 00:24:31 +0000856 /* Transparency check. */
857 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
858 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
859 transparent = 1;
860 else
861 transparent = 0;
862
paul718e3742002-12-13 20:15:29 +0000863 /* If community is not disabled check the no-export and local. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700864 if (! transparent && bgp_community_filter (peer, riattr))
paul718e3742002-12-13 20:15:29 +0000865 return 0;
866
867 /* If the attribute has originator-id and it is same as remote
868 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700869 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paul718e3742002-12-13 20:15:29 +0000870 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700871 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000872 {
873 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000874 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000875 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
876 peer->host,
877 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
878 p->prefixlen);
879 return 0;
880 }
881 }
882
883 /* ORF prefix-list filter check */
884 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
885 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
886 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
887 if (peer->orf_plist[afi][safi])
888 {
889 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
890 return 0;
891 }
892
893 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700894 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
paul718e3742002-12-13 20:15:29 +0000895 {
896 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000897 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000898 "%s [Update:SEND] %s/%d is filtered",
899 peer->host,
900 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
901 p->prefixlen);
902 return 0;
903 }
904
905#ifdef BGP_SEND_ASPATH_CHECK
906 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700907 if (aspath_loop_check (riattr->aspath, peer->as))
paul718e3742002-12-13 20:15:29 +0000908 {
909 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000910 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400911 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000912 peer->host, peer->as);
913 return 0;
914 }
915#endif /* BGP_SEND_ASPATH_CHECK */
916
917 /* If we're a CONFED we need to loop check the CONFED ID too */
918 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
919 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700920 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
paul718e3742002-12-13 20:15:29 +0000921 {
922 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000923 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400924 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000925 peer->host,
926 bgp->confed_id);
927 return 0;
928 }
929 }
930
931 /* Route-Reflect check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000932 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +0000933 reflect = 1;
934 else
935 reflect = 0;
936
937 /* IBGP reflection check. */
938 if (reflect)
939 {
940 /* A route from a Client peer. */
941 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
942 {
943 /* Reflect to all the Non-Client peers and also to the
944 Client peers other than the originator. Originator check
945 is already done. So there is noting to do. */
946 /* no bgp client-to-client reflection check. */
947 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
948 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
949 return 0;
950 }
951 else
952 {
953 /* A route from a Non-client peer. Reflect to all other
954 clients. */
955 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
956 return 0;
957 }
958 }
Paul Jakma41367172007-08-06 15:24:51 +0000959
paul718e3742002-12-13 20:15:29 +0000960 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700961 bgp_attr_dup (attr, riattr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000962
paul718e3742002-12-13 20:15:29 +0000963 /* If local-preference is not set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000964 if ((peer->sort == BGP_PEER_IBGP
965 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000966 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
967 {
968 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
969 attr->local_pref = bgp->default_local_pref;
970 }
971
Pradosh Mohapatra689bb662013-09-07 07:13:37 +0000972 /* If originator-id is not set and the route is to be reflected,
973 set the originator id */
974 if (peer && from && peer->sort == BGP_PEER_IBGP &&
975 from->sort == BGP_PEER_IBGP &&
976 (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
977 {
978 attr->extra = bgp_attr_extra_get(attr);
979 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
980 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
981 }
982
paul718e3742002-12-13 20:15:29 +0000983 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000984 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000985 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
986 {
987 if (ri->peer != bgp->peer_self && ! transparent
988 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
989 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
990 }
991
992 /* next-hop-set */
Timo Teräs9e7a53c2014-04-24 10:22:37 +0300993 if (transparent
994 || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
paul718e3742002-12-13 20:15:29 +0000995 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
996 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000997#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000998 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000999 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +00001000#endif /* HAVE_IPV6 */
1001 )))
paul718e3742002-12-13 20:15:29 +00001002 {
1003 /* NEXT-HOP Unchanged. */
1004 }
1005 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
1006 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
1007#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +00001008 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001009 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +00001010#endif /* HAVE_IPV6 */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001011 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001012 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
1013 {
1014 /* Set IPv4 nexthop. */
1015 if (p->family == AF_INET)
1016 {
1017 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001018 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1019 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +00001020 else
1021 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1022 }
1023#ifdef HAVE_IPV6
1024 /* Set IPv6 nexthop. */
1025 if (p->family == AF_INET6)
1026 {
1027 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001028 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001029 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001030 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001031 }
1032#endif /* HAVE_IPV6 */
1033 }
1034
1035#ifdef HAVE_IPV6
1036 if (p->family == AF_INET6)
1037 {
paulfee0f4c2004-09-13 05:12:46 +00001038 /* Left nexthop_local unchanged if so configured. */
1039 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1040 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1041 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001042 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1043 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001044 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001045 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001046 }
1047
1048 /* Default nexthop_local treatment for non-RS-Clients */
1049 else
1050 {
paul718e3742002-12-13 20:15:29 +00001051 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001052 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001053
1054 /* Set link-local address for shared network peer. */
1055 if (peer->shared_network
1056 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1057 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001058 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001059 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001060 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001061 }
1062
1063 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1064 address.*/
1065 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001066 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001067
1068 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1069 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001070 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001071 }
paulfee0f4c2004-09-13 05:12:46 +00001072
1073 }
paul718e3742002-12-13 20:15:29 +00001074#endif /* HAVE_IPV6 */
1075
1076 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001077 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001078 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1079 && aspath_private_as_check (attr->aspath))
1080 attr->aspath = aspath_empty_get ();
1081
1082 /* Route map & unsuppress-map apply. */
1083 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001084 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001085 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001086 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001087 struct attr dummy_attr;
1088 struct attr_extra dummy_extra;
1089
1090 dummy_attr.extra = &dummy_extra;
1091
paul718e3742002-12-13 20:15:29 +00001092 info.peer = peer;
1093 info.attr = attr;
1094
1095 /* The route reflector is not allowed to modify the attributes
1096 of the reflected IBGP routes. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001097 if (from->sort == BGP_PEER_IBGP
1098 && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +00001099 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001100 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001101 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001102 }
paulac41b2a2003-08-12 05:32:27 +00001103
1104 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1105
Paul Jakmafb982c22007-05-04 20:15:47 +00001106 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001107 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1108 else
1109 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1110
paulac41b2a2003-08-12 05:32:27 +00001111 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001112
paul718e3742002-12-13 20:15:29 +00001113 if (ret == RMAP_DENYMATCH)
1114 {
1115 bgp_attr_flush (attr);
1116 return 0;
1117 }
1118 }
1119 return 1;
1120}
1121
paul94f2b392005-06-28 12:44:16 +00001122static int
paulfee0f4c2004-09-13 05:12:46 +00001123bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1124 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001125{
paulfee0f4c2004-09-13 05:12:46 +00001126 int ret;
1127 char buf[SU_ADDRSTRLEN];
1128 struct bgp_filter *filter;
1129 struct bgp_info info;
1130 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001131 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001132
1133 from = ri->peer;
1134 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001135 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001136
Paul Jakma750e8142008-07-22 21:11:48 +00001137 if (DISABLE_BGP_ANNOUNCE)
1138 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001139
1140 /* Do not send back route to sender. */
1141 if (from == rsclient)
1142 return 0;
1143
1144 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001145 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001146 if (! UNSUPPRESS_MAP_NAME (filter))
1147 return 0;
1148
1149 /* Default route check. */
1150 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1151 PEER_STATUS_DEFAULT_ORIGINATE))
1152 {
1153 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1154 return 0;
1155#ifdef HAVE_IPV6
1156 else if (p->family == AF_INET6 && p->prefixlen == 0)
1157 return 0;
1158#endif /* HAVE_IPV6 */
1159 }
1160
1161 /* If the attribute has originator-id and it is same as remote
1162 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001163 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001164 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001165 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001166 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001167 {
1168 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001169 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001170 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1171 rsclient->host,
1172 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1173 p->prefixlen);
1174 return 0;
1175 }
1176 }
1177
1178 /* ORF prefix-list filter check */
1179 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1180 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1181 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1182 if (rsclient->orf_plist[afi][safi])
1183 {
1184 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1185 return 0;
1186 }
1187
1188 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001189 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001190 {
1191 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001192 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001193 "%s [Update:SEND] %s/%d is filtered",
1194 rsclient->host,
1195 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1196 p->prefixlen);
1197 return 0;
1198 }
1199
1200#ifdef BGP_SEND_ASPATH_CHECK
1201 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001202 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001203 {
1204 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001205 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001206 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001207 rsclient->host, rsclient->as);
1208 return 0;
1209 }
1210#endif /* BGP_SEND_ASPATH_CHECK */
1211
1212 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001213 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001214
1215 /* next-hop-set */
1216 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1217#ifdef HAVE_IPV6
1218 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001219 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001220#endif /* HAVE_IPV6 */
1221 )
1222 {
1223 /* Set IPv4 nexthop. */
1224 if (p->family == AF_INET)
1225 {
1226 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001227 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001228 IPV4_MAX_BYTELEN);
1229 else
1230 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1231 }
1232#ifdef HAVE_IPV6
1233 /* Set IPv6 nexthop. */
1234 if (p->family == AF_INET6)
1235 {
1236 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001237 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001238 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001239 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001240 }
1241#endif /* HAVE_IPV6 */
1242 }
1243
1244#ifdef HAVE_IPV6
1245 if (p->family == AF_INET6)
1246 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001247 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001248
paulfee0f4c2004-09-13 05:12:46 +00001249 /* Left nexthop_local unchanged if so configured. */
1250 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1251 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1252 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001253 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1254 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001255 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001256 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001257 }
1258
1259 /* Default nexthop_local treatment for RS-Clients */
1260 else
1261 {
1262 /* Announcer and RS-Client are both in the same network */
1263 if (rsclient->shared_network && from->shared_network &&
1264 (rsclient->ifindex == from->ifindex))
1265 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001266 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1267 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001268 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001269 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001270 }
1271
1272 /* Set link-local address for shared network peer. */
1273 else if (rsclient->shared_network
1274 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1275 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001276 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001277 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001278 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001279 }
1280
1281 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001282 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001283 }
1284
1285 }
1286#endif /* HAVE_IPV6 */
1287
1288
1289 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001290 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001291 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1292 && aspath_private_as_check (attr->aspath))
1293 attr->aspath = aspath_empty_get ();
1294
1295 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001296 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001297 {
1298 info.peer = rsclient;
1299 info.attr = attr;
1300
1301 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1302
Paul Jakmafb982c22007-05-04 20:15:47 +00001303 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001304 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1305 else
1306 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1307
1308 rsclient->rmap_type = 0;
1309
1310 if (ret == RMAP_DENYMATCH)
1311 {
1312 bgp_attr_flush (attr);
1313 return 0;
1314 }
1315 }
1316
1317 return 1;
1318}
1319
1320struct bgp_info_pair
1321{
1322 struct bgp_info *old;
1323 struct bgp_info *new;
1324};
1325
paul94f2b392005-06-28 12:44:16 +00001326static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001327bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1328 struct bgp_maxpaths_cfg *mpath_cfg,
1329 struct bgp_info_pair *result)
paulfee0f4c2004-09-13 05:12:46 +00001330{
paul718e3742002-12-13 20:15:29 +00001331 struct bgp_info *new_select;
1332 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001333 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001334 struct bgp_info *ri1;
1335 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001336 struct bgp_info *nextri = NULL;
Josh Bailey96450fa2011-07-20 20:45:12 -07001337 int paths_eq, do_mpath;
1338 struct list mp_list;
1339
1340 bgp_mp_list_init (&mp_list);
1341 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1342 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1343
paul718e3742002-12-13 20:15:29 +00001344 /* bgp deterministic-med */
1345 new_select = NULL;
1346 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1347 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1348 {
1349 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1350 continue;
1351 if (BGP_INFO_HOLDDOWN (ri1))
1352 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001353 if (ri1->peer && ri1->peer != bgp->peer_self)
1354 if (ri1->peer->status != Established)
1355 continue;
paul718e3742002-12-13 20:15:29 +00001356
1357 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001358 if (do_mpath)
1359 bgp_mp_list_add (&mp_list, ri1);
1360 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001361 if (ri1->next)
1362 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1363 {
1364 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1365 continue;
1366 if (BGP_INFO_HOLDDOWN (ri2))
1367 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001368 if (ri2->peer &&
1369 ri2->peer != bgp->peer_self &&
1370 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1371 if (ri2->peer->status != Established)
1372 continue;
paul718e3742002-12-13 20:15:29 +00001373
1374 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1375 || aspath_cmp_left_confed (ri1->attr->aspath,
1376 ri2->attr->aspath))
1377 {
Josh Bailey6918e742011-07-20 20:48:20 -07001378 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1379 old_select = ri2;
Josh Bailey96450fa2011-07-20 20:45:12 -07001380 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
paul718e3742002-12-13 20:15:29 +00001381 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001382 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001383 new_select = ri2;
Josh Bailey6918e742011-07-20 20:48:20 -07001384 if (do_mpath && !paths_eq)
1385 {
1386 bgp_mp_list_clear (&mp_list);
1387 bgp_mp_list_add (&mp_list, ri2);
1388 }
paul718e3742002-12-13 20:15:29 +00001389 }
1390
Josh Bailey6918e742011-07-20 20:48:20 -07001391 if (do_mpath && paths_eq)
1392 bgp_mp_list_add (&mp_list, ri2);
1393
Paul Jakma1a392d42006-09-07 00:24:49 +00001394 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001395 }
1396 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001397 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1398 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001399
1400 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1401 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001402 }
1403
1404 /* Check old selected route and new selected route. */
1405 old_select = NULL;
1406 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001407 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001408 {
1409 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1410 old_select = ri;
1411
1412 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001413 {
1414 /* reap REMOVED routes, if needs be
1415 * selected route must stay for a while longer though
1416 */
1417 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1418 && (ri != old_select))
1419 bgp_info_reap (rn, ri);
1420
1421 continue;
1422 }
paul718e3742002-12-13 20:15:29 +00001423
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001424 if (ri->peer &&
1425 ri->peer != bgp->peer_self &&
1426 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1427 if (ri->peer->status != Established)
1428 continue;
1429
paul718e3742002-12-13 20:15:29 +00001430 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1431 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1432 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001433 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001434 continue;
1435 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001436 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1437 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001438
Josh Bailey96450fa2011-07-20 20:45:12 -07001439 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1440 {
Josh Bailey6918e742011-07-20 20:48:20 -07001441 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1442 bgp_mp_dmed_deselect (new_select);
1443
Josh Bailey96450fa2011-07-20 20:45:12 -07001444 new_select = ri;
1445
1446 if (do_mpath && !paths_eq)
1447 {
1448 bgp_mp_list_clear (&mp_list);
1449 bgp_mp_list_add (&mp_list, ri);
1450 }
1451 }
Josh Bailey6918e742011-07-20 20:48:20 -07001452 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1453 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001454
1455 if (do_mpath && paths_eq)
1456 bgp_mp_list_add (&mp_list, ri);
paul718e3742002-12-13 20:15:29 +00001457 }
paulb40d9392005-08-22 22:34:41 +00001458
paulfee0f4c2004-09-13 05:12:46 +00001459
Josh Bailey6918e742011-07-20 20:48:20 -07001460 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1461 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
Josh Bailey96450fa2011-07-20 20:45:12 -07001462
Josh Bailey0b597ef2011-07-20 20:49:11 -07001463 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001464 bgp_mp_list_clear (&mp_list);
1465
1466 result->old = old_select;
1467 result->new = new_select;
1468
1469 return;
paulfee0f4c2004-09-13 05:12:46 +00001470}
1471
paul94f2b392005-06-28 12:44:16 +00001472static int
paulfee0f4c2004-09-13 05:12:46 +00001473bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001474 struct bgp_node *rn, afi_t afi, safi_t safi)
1475{
paulfee0f4c2004-09-13 05:12:46 +00001476 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001477 struct attr attr;
1478 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001479
1480 p = &rn->p;
1481
Paul Jakma9eda90c2007-08-30 13:36:17 +00001482 /* Announce route to Established peer. */
1483 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001484 return 0;
1485
Paul Jakma9eda90c2007-08-30 13:36:17 +00001486 /* Address family configuration check. */
1487 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001488 return 0;
1489
Paul Jakma9eda90c2007-08-30 13:36:17 +00001490 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001491 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1492 PEER_STATUS_ORF_WAIT_REFRESH))
1493 return 0;
1494
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001495 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1496 attr.extra = &extra;
1497
Avneesh Sachdev67174042012-08-17 08:19:49 -07001498 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001499 {
1500 case BGP_TABLE_MAIN:
1501 /* Announcement to peer->conf. If the route is filtered,
1502 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001503 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1504 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001505 else
1506 bgp_adj_out_unset (rn, peer, p, afi, safi);
1507 break;
1508 case BGP_TABLE_RSCLIENT:
1509 /* Announcement to peer->conf. If the route is filtered,
1510 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001511 if (selected &&
1512 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1513 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1514 else
1515 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001516 break;
1517 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001518
paulfee0f4c2004-09-13 05:12:46 +00001519 return 0;
paul200df112005-06-01 11:17:05 +00001520}
paulfee0f4c2004-09-13 05:12:46 +00001521
paul200df112005-06-01 11:17:05 +00001522struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001523{
paul200df112005-06-01 11:17:05 +00001524 struct bgp *bgp;
1525 struct bgp_node *rn;
1526 afi_t afi;
1527 safi_t safi;
1528};
1529
1530static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001531bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001532{
paul0fb58d52005-11-14 14:31:49 +00001533 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001534 struct bgp *bgp = pq->bgp;
1535 struct bgp_node *rn = pq->rn;
1536 afi_t afi = pq->afi;
1537 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001538 struct bgp_info *new_select;
1539 struct bgp_info *old_select;
1540 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001541 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001542 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001543
paulfee0f4c2004-09-13 05:12:46 +00001544 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001545 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001546 new_select = old_and_new.new;
1547 old_select = old_and_new.old;
1548
paul200df112005-06-01 11:17:05 +00001549 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1550 {
Chris Caputo228da422009-07-18 05:44:03 +00001551 if (rsclient->group)
1552 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1553 {
1554 /* Nothing to do. */
1555 if (old_select && old_select == new_select)
1556 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1557 continue;
paulfee0f4c2004-09-13 05:12:46 +00001558
Chris Caputo228da422009-07-18 05:44:03 +00001559 if (old_select)
1560 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1561 if (new_select)
1562 {
1563 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1564 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001565 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1566 }
paulfee0f4c2004-09-13 05:12:46 +00001567
Chris Caputo228da422009-07-18 05:44:03 +00001568 bgp_process_announce_selected (rsclient, new_select, rn,
1569 afi, safi);
1570 }
paul200df112005-06-01 11:17:05 +00001571 }
1572 else
1573 {
hassob7395792005-08-26 12:58:38 +00001574 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001575 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001576 if (new_select)
1577 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001578 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1579 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001580 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001581 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001582 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001583 }
paulfee0f4c2004-09-13 05:12:46 +00001584
paulb40d9392005-08-22 22:34:41 +00001585 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1586 bgp_info_reap (rn, old_select);
1587
paul200df112005-06-01 11:17:05 +00001588 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1589 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001590}
1591
paul200df112005-06-01 11:17:05 +00001592static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001593bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001594{
paul0fb58d52005-11-14 14:31:49 +00001595 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001596 struct bgp *bgp = pq->bgp;
1597 struct bgp_node *rn = pq->rn;
1598 afi_t afi = pq->afi;
1599 safi_t safi = pq->safi;
1600 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001601 struct bgp_info *new_select;
1602 struct bgp_info *old_select;
1603 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001604 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001605 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001606
paulfee0f4c2004-09-13 05:12:46 +00001607 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001608 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001609 old_select = old_and_new.old;
1610 new_select = old_and_new.new;
1611
1612 /* Nothing to do. */
1613 if (old_select && old_select == new_select)
1614 {
1615 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001616 {
Josh Bailey8196f132011-07-20 20:47:07 -07001617 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1618 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001619 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001620
Josh Bailey8196f132011-07-20 20:47:07 -07001621 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001622 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1623 return WQ_SUCCESS;
1624 }
paulfee0f4c2004-09-13 05:12:46 +00001625 }
paul718e3742002-12-13 20:15:29 +00001626
hasso338b3422005-02-23 14:27:24 +00001627 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001628 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001629 if (new_select)
1630 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001631 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1632 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001633 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001634 }
1635
1636
paul718e3742002-12-13 20:15:29 +00001637 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001638 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001639 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001640 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001641 }
1642
1643 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001644 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1645 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001646 {
1647 if (new_select
1648 && new_select->type == ZEBRA_ROUTE_BGP
1649 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001650 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001651 else
1652 {
1653 /* Withdraw the route from the kernel. */
1654 if (old_select
1655 && old_select->type == ZEBRA_ROUTE_BGP
1656 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001657 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001658 }
1659 }
paulb40d9392005-08-22 22:34:41 +00001660
1661 /* Reap old select bgp_info, it it has been removed */
1662 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1663 bgp_info_reap (rn, old_select);
1664
paul200df112005-06-01 11:17:05 +00001665 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1666 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001667}
1668
paul200df112005-06-01 11:17:05 +00001669static void
paul0fb58d52005-11-14 14:31:49 +00001670bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001671{
paul0fb58d52005-11-14 14:31:49 +00001672 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001673 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001674
Chris Caputo228da422009-07-18 05:44:03 +00001675 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001676 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001677 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001678 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1679}
1680
1681static void
1682bgp_process_queue_init (void)
1683{
1684 bm->process_main_queue
1685 = work_queue_new (bm->master, "process_main_queue");
1686 bm->process_rsclient_queue
1687 = work_queue_new (bm->master, "process_rsclient_queue");
1688
1689 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1690 {
1691 zlog_err ("%s: Failed to allocate work queue", __func__);
1692 exit (1);
1693 }
1694
1695 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001696 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001697 bm->process_main_queue->spec.max_retries = 0;
1698 bm->process_main_queue->spec.hold = 50;
1699
Paul Jakma838bbde2010-01-08 14:05:32 +00001700 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
David Lamparterd43f8b32015-03-03 08:54:54 +01001701 bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del;
1702 bm->process_rsclient_queue->spec.max_retries = 0;
1703 bm->process_rsclient_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001704}
1705
1706void
paulfee0f4c2004-09-13 05:12:46 +00001707bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1708{
paul200df112005-06-01 11:17:05 +00001709 struct bgp_process_queue *pqnode;
1710
1711 /* already scheduled for processing? */
1712 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1713 return;
1714
1715 if ( (bm->process_main_queue == NULL) ||
1716 (bm->process_rsclient_queue == NULL) )
1717 bgp_process_queue_init ();
1718
1719 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1720 sizeof (struct bgp_process_queue));
1721 if (!pqnode)
1722 return;
Chris Caputo228da422009-07-18 05:44:03 +00001723
1724 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001725 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001726 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001727 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001728 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001729 pqnode->afi = afi;
1730 pqnode->safi = safi;
1731
Avneesh Sachdev67174042012-08-17 08:19:49 -07001732 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001733 {
paul200df112005-06-01 11:17:05 +00001734 case BGP_TABLE_MAIN:
1735 work_queue_add (bm->process_main_queue, pqnode);
1736 break;
1737 case BGP_TABLE_RSCLIENT:
1738 work_queue_add (bm->process_rsclient_queue, pqnode);
1739 break;
paulfee0f4c2004-09-13 05:12:46 +00001740 }
paul200df112005-06-01 11:17:05 +00001741
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001742 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001743 return;
paulfee0f4c2004-09-13 05:12:46 +00001744}
hasso0a486e52005-02-01 20:57:17 +00001745
paul94f2b392005-06-28 12:44:16 +00001746static int
hasso0a486e52005-02-01 20:57:17 +00001747bgp_maximum_prefix_restart_timer (struct thread *thread)
1748{
1749 struct peer *peer;
1750
1751 peer = THREAD_ARG (thread);
1752 peer->t_pmax_restart = NULL;
1753
1754 if (BGP_DEBUG (events, EVENTS))
1755 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1756 peer->host);
1757
1758 peer_clear (peer);
1759
1760 return 0;
1761}
1762
paulfee0f4c2004-09-13 05:12:46 +00001763int
paul5228ad22004-06-04 17:58:18 +00001764bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1765 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001766{
hassoe0701b72004-05-20 09:19:34 +00001767 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1768 return 0;
1769
1770 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001771 {
hassoe0701b72004-05-20 09:19:34 +00001772 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1773 && ! always)
1774 return 0;
paul718e3742002-12-13 20:15:29 +00001775
hassoe0701b72004-05-20 09:19:34 +00001776 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001777 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1778 "limit %ld", afi_safi_print (afi, safi), peer->host,
1779 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001780 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001781
hassoe0701b72004-05-20 09:19:34 +00001782 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1783 return 0;
paul718e3742002-12-13 20:15:29 +00001784
hassoe0701b72004-05-20 09:19:34 +00001785 {
paul5228ad22004-06-04 17:58:18 +00001786 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001787
1788 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001789 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001790
1791 ndata[0] = (afi >> 8);
1792 ndata[1] = afi;
1793 ndata[2] = safi;
1794 ndata[3] = (peer->pmax[afi][safi] >> 24);
1795 ndata[4] = (peer->pmax[afi][safi] >> 16);
1796 ndata[5] = (peer->pmax[afi][safi] >> 8);
1797 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001798
1799 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1800 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1801 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1802 }
hasso0a486e52005-02-01 20:57:17 +00001803
1804 /* restart timer start */
1805 if (peer->pmax_restart[afi][safi])
1806 {
1807 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1808
1809 if (BGP_DEBUG (events, EVENTS))
1810 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1811 peer->host, peer->v_pmax_restart);
1812
1813 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1814 peer->v_pmax_restart);
1815 }
1816
hassoe0701b72004-05-20 09:19:34 +00001817 return 1;
paul718e3742002-12-13 20:15:29 +00001818 }
hassoe0701b72004-05-20 09:19:34 +00001819 else
1820 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1821
1822 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1823 {
1824 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1825 && ! always)
1826 return 0;
1827
1828 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001829 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1830 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1831 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001832 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1833 }
1834 else
1835 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001836 return 0;
1837}
1838
paulb40d9392005-08-22 22:34:41 +00001839/* Unconditionally remove the route from the RIB, without taking
1840 * damping into consideration (eg, because the session went down)
1841 */
paul94f2b392005-06-28 12:44:16 +00001842static void
paul718e3742002-12-13 20:15:29 +00001843bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1844 afi_t afi, safi_t safi)
1845{
paul902212c2006-02-05 17:51:19 +00001846 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1847
1848 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1849 bgp_info_delete (rn, ri); /* keep historical info */
1850
paulb40d9392005-08-22 22:34:41 +00001851 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001852}
1853
paul94f2b392005-06-28 12:44:16 +00001854static void
paul718e3742002-12-13 20:15:29 +00001855bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001856 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001857{
paul718e3742002-12-13 20:15:29 +00001858 int status = BGP_DAMP_NONE;
1859
paulb40d9392005-08-22 22:34:41 +00001860 /* apply dampening, if result is suppressed, we'll be retaining
1861 * the bgp_info in the RIB for historical reference.
1862 */
1863 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001864 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001865 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1866 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001867 {
paul902212c2006-02-05 17:51:19 +00001868 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1869 return;
1870 }
1871
1872 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001873}
1874
paul94f2b392005-06-28 12:44:16 +00001875static void
paulfee0f4c2004-09-13 05:12:46 +00001876bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1877 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1878 int sub_type, struct prefix_rd *prd, u_char *tag)
1879{
1880 struct bgp_node *rn;
1881 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001882 struct attr new_attr;
1883 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001884 struct attr *attr_new;
1885 struct attr *attr_new2;
1886 struct bgp_info *ri;
1887 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001888 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001889 char buf[SU_ADDRSTRLEN];
1890
1891 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1892 if (peer == rsclient)
1893 return;
1894
1895 bgp = peer->bgp;
1896 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1897
1898 /* Check previously received route. */
1899 for (ri = rn->info; ri; ri = ri->next)
1900 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1901 break;
1902
1903 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001904 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001905 {
1906 reason = "as-path contains our own AS;";
1907 goto filtered;
1908 }
1909
1910 /* Route reflector originator ID check. */
1911 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001912 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001913 {
1914 reason = "originator is us;";
1915 goto filtered;
1916 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001917
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001918 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001919 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001920
1921 /* Apply export policy. */
1922 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1923 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1924 {
1925 reason = "export-policy;";
1926 goto filtered;
1927 }
1928
1929 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001930
paulfee0f4c2004-09-13 05:12:46 +00001931 /* Apply import policy. */
1932 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1933 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001934 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001935
1936 reason = "import-policy;";
1937 goto filtered;
1938 }
1939
1940 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001941 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001942
1943 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001944 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001945 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001946 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001947 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001948 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001949 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001950 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001951
1952 reason = "martian next-hop;";
1953 goto filtered;
1954 }
1955 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001956
paulfee0f4c2004-09-13 05:12:46 +00001957 /* If the update is implicit withdraw. */
1958 if (ri)
1959 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001960 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001961
1962 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001963 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1964 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001965 {
1966
Paul Jakma1a392d42006-09-07 00:24:49 +00001967 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001968
1969 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001970 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001971 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1972 peer->host,
1973 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1974 p->prefixlen, rsclient->host);
1975
Chris Caputo228da422009-07-18 05:44:03 +00001976 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001977 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001978
Chris Caputo228da422009-07-18 05:44:03 +00001979 return;
paulfee0f4c2004-09-13 05:12:46 +00001980 }
1981
Paul Jakma16d2e242007-04-10 19:32:10 +00001982 /* Withdraw/Announce before we fully processed the withdraw */
1983 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1984 bgp_info_restore (rn, ri);
1985
paulfee0f4c2004-09-13 05:12:46 +00001986 /* Received Logging. */
1987 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001988 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001989 peer->host,
1990 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1991 p->prefixlen, rsclient->host);
1992
1993 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001994 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001995
1996 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001997 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001998 ri->attr = attr_new;
1999
2000 /* Update MPLS tag. */
2001 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002002 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002003
Paul Jakma1a392d42006-09-07 00:24:49 +00002004 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002005
2006 /* Process change. */
2007 bgp_process (bgp, rn, afi, safi);
2008 bgp_unlock_node (rn);
2009
2010 return;
2011 }
2012
2013 /* Received Logging. */
2014 if (BGP_DEBUG (update, UPDATE_IN))
2015 {
ajsd2c1f162004-12-08 21:10:20 +00002016 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002017 peer->host,
2018 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2019 p->prefixlen, rsclient->host);
2020 }
2021
2022 /* Make new BGP info. */
2023 new = bgp_info_new ();
2024 new->type = type;
2025 new->sub_type = sub_type;
2026 new->peer = peer;
2027 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002028 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00002029
2030 /* Update MPLS tag. */
2031 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002032 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002033
Paul Jakma1a392d42006-09-07 00:24:49 +00002034 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002035
2036 /* Register new BGP information. */
2037 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002038
2039 /* route_node_get lock */
2040 bgp_unlock_node (rn);
2041
paulfee0f4c2004-09-13 05:12:46 +00002042 /* Process change. */
2043 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002044
paulfee0f4c2004-09-13 05:12:46 +00002045 return;
2046
2047 filtered:
2048
2049 /* This BGP update is filtered. Log the reason then update BGP entry. */
2050 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002051 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002052 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2053 peer->host,
2054 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2055 p->prefixlen, rsclient->host, reason);
2056
2057 if (ri)
paulb40d9392005-08-22 22:34:41 +00002058 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002059
2060 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002061
paulfee0f4c2004-09-13 05:12:46 +00002062 return;
2063}
2064
paul94f2b392005-06-28 12:44:16 +00002065static void
paulfee0f4c2004-09-13 05:12:46 +00002066bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2067 struct peer *peer, struct prefix *p, int type, int sub_type,
2068 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002069{
paulfee0f4c2004-09-13 05:12:46 +00002070 struct bgp_node *rn;
2071 struct bgp_info *ri;
2072 char buf[SU_ADDRSTRLEN];
2073
2074 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002075 return;
paulfee0f4c2004-09-13 05:12:46 +00002076
2077 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2078
2079 /* Lookup withdrawn route. */
2080 for (ri = rn->info; ri; ri = ri->next)
2081 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2082 break;
2083
2084 /* Withdraw specified route from routing table. */
2085 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002086 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002087 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002088 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002089 "%s Can't find the route %s/%d", peer->host,
2090 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2091 p->prefixlen);
2092
2093 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002094 bgp_unlock_node (rn);
2095}
paulfee0f4c2004-09-13 05:12:46 +00002096
paul94f2b392005-06-28 12:44:16 +00002097static int
paulfee0f4c2004-09-13 05:12:46 +00002098bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002099 afi_t afi, safi_t safi, int type, int sub_type,
2100 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2101{
2102 int ret;
2103 int aspath_loop_count = 0;
2104 struct bgp_node *rn;
2105 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002106 struct attr new_attr;
2107 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002108 struct attr *attr_new;
2109 struct bgp_info *ri;
2110 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002111 const char *reason;
paul718e3742002-12-13 20:15:29 +00002112 char buf[SU_ADDRSTRLEN];
2113
2114 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002115 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002116
paul718e3742002-12-13 20:15:29 +00002117 /* When peer's soft reconfiguration enabled. Record input packet in
2118 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002119 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2120 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002121 bgp_adj_in_set (rn, peer, attr);
2122
2123 /* Check previously received route. */
2124 for (ri = rn->info; ri; ri = ri->next)
2125 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2126 break;
2127
2128 /* AS path local-as loop check. */
2129 if (peer->change_local_as)
2130 {
2131 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2132 aspath_loop_count = 1;
2133
2134 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2135 {
2136 reason = "as-path contains our own AS;";
2137 goto filtered;
2138 }
2139 }
2140
2141 /* AS path loop check. */
2142 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2143 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2144 && aspath_loop_check(attr->aspath, bgp->confed_id)
2145 > peer->allowas_in[afi][safi]))
2146 {
2147 reason = "as-path contains our own AS;";
2148 goto filtered;
2149 }
2150
2151 /* Route reflector originator ID check. */
2152 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002153 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002154 {
2155 reason = "originator is us;";
2156 goto filtered;
2157 }
2158
2159 /* Route reflector cluster ID check. */
2160 if (bgp_cluster_filter (peer, attr))
2161 {
2162 reason = "reflected from the same cluster;";
2163 goto filtered;
2164 }
2165
2166 /* Apply incoming filter. */
2167 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2168 {
2169 reason = "filter;";
2170 goto filtered;
2171 }
2172
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002173 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002174 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002175
David Lamparterc460e572014-06-04 00:54:58 +02002176 /* Apply incoming route-map.
2177 * NB: new_attr may now contain newly allocated values from route-map "set"
2178 * commands, so we need bgp_attr_flush in the error paths, until we intern
2179 * the attr (which takes over the memory references) */
paul718e3742002-12-13 20:15:29 +00002180 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2181 {
2182 reason = "route-map;";
David Lamparterc460e572014-06-04 00:54:58 +02002183 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002184 goto filtered;
2185 }
2186
2187 /* IPv4 unicast next hop check. */
2188 if (afi == AFI_IP && safi == SAFI_UNICAST)
2189 {
2190 /* If the peer is EBGP and nexthop is not on connected route,
2191 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002192 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002193 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002194 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002195 {
2196 reason = "non-connected next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002197 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002198 goto filtered;
2199 }
2200
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002201 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002202 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002203 if (new_attr.nexthop.s_addr == 0
2204 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2205 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002206 {
2207 reason = "martian next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002208 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002209 goto filtered;
2210 }
2211 }
2212
2213 attr_new = bgp_attr_intern (&new_attr);
2214
2215 /* If the update is implicit withdraw. */
2216 if (ri)
2217 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002218 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002219
2220 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002221 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2222 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002223 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002224 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002225
2226 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002227 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002228 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2229 {
2230 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002231 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002232 peer->host,
2233 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2234 p->prefixlen);
2235
paul902212c2006-02-05 17:51:19 +00002236 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2237 {
2238 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2239 bgp_process (bgp, rn, afi, safi);
2240 }
paul718e3742002-12-13 20:15:29 +00002241 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002242 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002243 {
2244 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002245 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002246 "%s rcvd %s/%d...duplicate ignored",
2247 peer->host,
2248 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2249 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002250
2251 /* graceful restart STALE flag unset. */
2252 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2253 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002254 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002255 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002256 }
paul718e3742002-12-13 20:15:29 +00002257 }
2258
2259 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002260 bgp_attr_unintern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002261
paul718e3742002-12-13 20:15:29 +00002262 return 0;
2263 }
2264
Paul Jakma16d2e242007-04-10 19:32:10 +00002265 /* Withdraw/Announce before we fully processed the withdraw */
2266 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2267 {
2268 if (BGP_DEBUG (update, UPDATE_IN))
2269 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2270 peer->host,
2271 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2272 p->prefixlen);
2273 bgp_info_restore (rn, ri);
2274 }
2275
paul718e3742002-12-13 20:15:29 +00002276 /* Received Logging. */
2277 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002278 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002279 peer->host,
2280 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2281 p->prefixlen);
2282
hasso93406d82005-02-02 14:40:33 +00002283 /* graceful restart STALE flag unset. */
2284 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002285 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002286
paul718e3742002-12-13 20:15:29 +00002287 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002288 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002289
2290 /* implicit withdraw, decrement aggregate and pcount here.
2291 * only if update is accepted, they'll increment below.
2292 */
paul902212c2006-02-05 17:51:19 +00002293 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2294
paul718e3742002-12-13 20:15:29 +00002295 /* Update bgp route dampening information. */
2296 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002297 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002298 {
2299 /* This is implicit withdraw so we should update dampening
2300 information. */
2301 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2302 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002303 }
2304
paul718e3742002-12-13 20:15:29 +00002305 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002306 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002307 ri->attr = attr_new;
2308
2309 /* Update MPLS tag. */
2310 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002311 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002312
2313 /* Update bgp route dampening information. */
2314 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002315 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002316 {
2317 /* Now we do normal update dampening. */
2318 ret = bgp_damp_update (ri, rn, afi, safi);
2319 if (ret == BGP_DAMP_SUPPRESSED)
2320 {
2321 bgp_unlock_node (rn);
2322 return 0;
2323 }
2324 }
2325
2326 /* Nexthop reachability check. */
2327 if ((afi == AFI_IP || afi == AFI_IP6)
2328 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002329 && (peer->sort == BGP_PEER_IBGP
2330 || peer->sort == BGP_PEER_CONFED
2331 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002332 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002333 {
2334 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002335 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002336 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002337 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002338 }
2339 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002340 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002341
2342 /* Process change. */
2343 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2344
2345 bgp_process (bgp, rn, afi, safi);
2346 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002347
paul718e3742002-12-13 20:15:29 +00002348 return 0;
2349 }
2350
2351 /* Received Logging. */
2352 if (BGP_DEBUG (update, UPDATE_IN))
2353 {
ajsd2c1f162004-12-08 21:10:20 +00002354 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002355 peer->host,
2356 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2357 p->prefixlen);
2358 }
2359
paul718e3742002-12-13 20:15:29 +00002360 /* Make new BGP info. */
2361 new = bgp_info_new ();
2362 new->type = type;
2363 new->sub_type = sub_type;
2364 new->peer = peer;
2365 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002366 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002367
2368 /* Update MPLS tag. */
2369 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002370 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002371
2372 /* Nexthop reachability check. */
2373 if ((afi == AFI_IP || afi == AFI_IP6)
2374 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002375 && (peer->sort == BGP_PEER_IBGP
2376 || peer->sort == BGP_PEER_CONFED
2377 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002378 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002379 {
2380 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002381 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002382 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002383 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002384 }
2385 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002386 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002387
paul902212c2006-02-05 17:51:19 +00002388 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002389 bgp_aggregate_increment (bgp, p, new, afi, safi);
2390
2391 /* Register new BGP information. */
2392 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002393
2394 /* route_node_get lock */
2395 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002396
paul718e3742002-12-13 20:15:29 +00002397 /* If maximum prefix count is configured and current prefix
2398 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002399 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2400 return -1;
paul718e3742002-12-13 20:15:29 +00002401
2402 /* Process change. */
2403 bgp_process (bgp, rn, afi, safi);
2404
2405 return 0;
2406
2407 /* This BGP update is filtered. Log the reason then update BGP
2408 entry. */
2409 filtered:
2410 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002411 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002412 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2413 peer->host,
2414 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2415 p->prefixlen, reason);
2416
2417 if (ri)
paulb40d9392005-08-22 22:34:41 +00002418 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002419
2420 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002421
paul718e3742002-12-13 20:15:29 +00002422 return 0;
2423}
2424
2425int
paulfee0f4c2004-09-13 05:12:46 +00002426bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2427 afi_t afi, safi_t safi, int type, int sub_type,
2428 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2429{
2430 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002431 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002432 struct bgp *bgp;
2433 int ret;
2434
2435 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2436 soft_reconfig);
2437
2438 bgp = peer->bgp;
2439
2440 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002441 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002442 {
2443 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2444 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2445 sub_type, prd, tag);
2446 }
2447
2448 return ret;
2449}
2450
2451int
paul718e3742002-12-13 20:15:29 +00002452bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002453 afi_t afi, safi_t safi, int type, int sub_type,
2454 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002455{
2456 struct bgp *bgp;
2457 char buf[SU_ADDRSTRLEN];
2458 struct bgp_node *rn;
2459 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002460 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002461 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002462
2463 bgp = peer->bgp;
2464
David Lamparter4584c232015-04-13 09:50:00 +02002465 /* Lookup node. */
2466 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2467
2468 /* Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2469 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2470 * the iteration over all RS clients.
2471 * Since we need to remove the entry from adj_in anyway, do that first and
2472 * if there was no entry, we don't need to do anything more. */
2473 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2474 && peer != bgp->peer_self)
2475 if (!bgp_adj_in_unset (rn, peer))
2476 {
2477 if (BGP_DEBUG (update, UPDATE_IN))
2478 zlog (peer->log, LOG_DEBUG, "%s withdrawing route %s/%d "
2479 "not in adj-in", peer->host,
2480 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2481 p->prefixlen);
2482 bgp_unlock_node (rn);
2483 return 0;
2484 }
2485
paulfee0f4c2004-09-13 05:12:46 +00002486 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002487 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002488 {
2489 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2490 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2491 }
2492
paul718e3742002-12-13 20:15:29 +00002493 /* Logging. */
2494 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002495 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002496 peer->host,
2497 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2498 p->prefixlen);
2499
paul718e3742002-12-13 20:15:29 +00002500 /* Lookup withdrawn route. */
2501 for (ri = rn->info; ri; ri = ri->next)
2502 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2503 break;
2504
2505 /* Withdraw specified route from routing table. */
2506 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002507 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002508 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002509 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002510 "%s Can't find the route %s/%d", peer->host,
2511 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2512 p->prefixlen);
2513
2514 /* Unlock bgp_node_get() lock. */
2515 bgp_unlock_node (rn);
2516
2517 return 0;
2518}
David Lamparter6b0655a2014-06-04 06:53:35 +02002519
paul718e3742002-12-13 20:15:29 +00002520void
2521bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2522{
2523 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002524 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002525 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002526 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002527 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002528 struct bgp_node *rn;
2529 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002530 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002531
Paul Jakmab2497022007-06-14 11:17:58 +00002532 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002533 return;
2534
paul718e3742002-12-13 20:15:29 +00002535 bgp = peer->bgp;
2536 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002537
paul718e3742002-12-13 20:15:29 +00002538 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2539 aspath = attr.aspath;
2540 attr.local_pref = bgp->default_local_pref;
2541 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2542
2543 if (afi == AFI_IP)
2544 str2prefix ("0.0.0.0/0", &p);
2545#ifdef HAVE_IPV6
2546 else if (afi == AFI_IP6)
2547 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002548 struct attr_extra *ae = attr.extra;
2549
paul718e3742002-12-13 20:15:29 +00002550 str2prefix ("::/0", &p);
2551
2552 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002553 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002554 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002555 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002556
2557 /* If the peer is on shared nextwork and we have link-local
2558 nexthop set it. */
2559 if (peer->shared_network
2560 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2561 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002562 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002563 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002564 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002565 }
2566 }
2567#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002568
2569 if (peer->default_rmap[afi][safi].name)
2570 {
paulfee0f4c2004-09-13 05:12:46 +00002571 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002572 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2573 {
2574 for (ri = rn->info; ri; ri = ri->next)
2575 {
2576 struct attr dummy_attr;
2577 struct attr_extra dummy_extra;
2578 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002579
Christian Frankedcab1bb2012-12-07 16:45:52 +00002580 /* Provide dummy so the route-map can't modify the attributes */
2581 dummy_attr.extra = &dummy_extra;
2582 bgp_attr_dup(&dummy_attr, ri->attr);
2583 info.peer = ri->peer;
2584 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002585
Christian Frankedcab1bb2012-12-07 16:45:52 +00002586 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2587 RMAP_BGP, &info);
2588
2589 /* The route map might have set attributes. If we don't flush them
2590 * here, they will be leaked. */
2591 bgp_attr_flush(&dummy_attr);
2592 if (ret != RMAP_DENYMATCH)
2593 break;
2594 }
2595 if (ret != RMAP_DENYMATCH)
2596 break;
2597 }
paulfee0f4c2004-09-13 05:12:46 +00002598 bgp->peer_self->rmap_type = 0;
2599
paul718e3742002-12-13 20:15:29 +00002600 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002601 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002602 }
2603
2604 if (withdraw)
2605 {
2606 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2607 bgp_default_withdraw_send (peer, afi, safi);
2608 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2609 }
2610 else
2611 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002612 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2613 {
2614 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2615 bgp_default_update_send (peer, &attr, afi, safi, from);
2616 }
paul718e3742002-12-13 20:15:29 +00002617 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002618
2619 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002620 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002621}
David Lamparter6b0655a2014-06-04 06:53:35 +02002622
paul718e3742002-12-13 20:15:29 +00002623static void
2624bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002625 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002626{
2627 struct bgp_node *rn;
2628 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002629 struct attr attr;
2630 struct attr_extra extra;
2631
paul718e3742002-12-13 20:15:29 +00002632 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002633 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002634
2635 if (safi != SAFI_MPLS_VPN
2636 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2637 bgp_default_originate (peer, afi, safi, 0);
2638
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002639 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2640 attr.extra = &extra;
2641
paul718e3742002-12-13 20:15:29 +00002642 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2643 for (ri = rn->info; ri; ri = ri->next)
2644 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2645 {
paulfee0f4c2004-09-13 05:12:46 +00002646 if ( (rsclient) ?
2647 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2648 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002649 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2650 else
2651 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2652 }
2653}
2654
2655void
2656bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2657{
2658 struct bgp_node *rn;
2659 struct bgp_table *table;
2660
2661 if (peer->status != Established)
2662 return;
2663
2664 if (! peer->afc_nego[afi][safi])
2665 return;
2666
2667 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2668 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2669 return;
2670
2671 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002672 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002673 else
2674 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2675 rn = bgp_route_next(rn))
2676 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002677 bgp_announce_table (peer, afi, safi, table, 0);
2678
2679 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2680 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002681}
2682
2683void
2684bgp_announce_route_all (struct peer *peer)
2685{
2686 afi_t afi;
2687 safi_t safi;
2688
2689 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2690 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2691 bgp_announce_route (peer, afi, safi);
2692}
David Lamparter6b0655a2014-06-04 06:53:35 +02002693
paul718e3742002-12-13 20:15:29 +00002694static void
paulfee0f4c2004-09-13 05:12:46 +00002695bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002696 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002697{
2698 struct bgp_node *rn;
2699 struct bgp_adj_in *ain;
2700
2701 if (! table)
2702 table = rsclient->bgp->rib[afi][safi];
2703
2704 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2705 for (ain = rn->adj_in; ain; ain = ain->next)
2706 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002707 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002708 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002709
paulfee0f4c2004-09-13 05:12:46 +00002710 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002711 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002712 }
2713}
2714
2715void
2716bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2717{
2718 struct bgp_table *table;
2719 struct bgp_node *rn;
2720
2721 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002722 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002723
2724 else
2725 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2726 rn = bgp_route_next (rn))
2727 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002728 {
2729 struct prefix_rd prd;
2730 prd.family = AF_UNSPEC;
2731 prd.prefixlen = 64;
2732 memcpy(&prd.val, rn->p.u.val, 8);
2733
2734 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2735 }
paulfee0f4c2004-09-13 05:12:46 +00002736}
David Lamparter6b0655a2014-06-04 06:53:35 +02002737
paulfee0f4c2004-09-13 05:12:46 +00002738static void
paul718e3742002-12-13 20:15:29 +00002739bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002740 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002741{
2742 int ret;
2743 struct bgp_node *rn;
2744 struct bgp_adj_in *ain;
2745
2746 if (! table)
2747 table = peer->bgp->rib[afi][safi];
2748
2749 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2750 for (ain = rn->adj_in; ain; ain = ain->next)
2751 {
2752 if (ain->peer == peer)
2753 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002754 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002755 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002756
paul718e3742002-12-13 20:15:29 +00002757 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2758 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002759 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002760
paul718e3742002-12-13 20:15:29 +00002761 if (ret < 0)
2762 {
2763 bgp_unlock_node (rn);
2764 return;
2765 }
2766 continue;
2767 }
2768 }
2769}
2770
2771void
2772bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2773{
2774 struct bgp_node *rn;
2775 struct bgp_table *table;
2776
2777 if (peer->status != Established)
2778 return;
2779
2780 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002781 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002782 else
2783 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2784 rn = bgp_route_next (rn))
2785 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002786 {
2787 struct prefix_rd prd;
2788 prd.family = AF_UNSPEC;
2789 prd.prefixlen = 64;
2790 memcpy(&prd.val, rn->p.u.val, 8);
2791
2792 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2793 }
paul718e3742002-12-13 20:15:29 +00002794}
David Lamparter6b0655a2014-06-04 06:53:35 +02002795
Chris Caputo228da422009-07-18 05:44:03 +00002796
2797struct bgp_clear_node_queue
2798{
2799 struct bgp_node *rn;
2800 enum bgp_clear_route_type purpose;
2801};
2802
paul200df112005-06-01 11:17:05 +00002803static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002804bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002805{
Chris Caputo228da422009-07-18 05:44:03 +00002806 struct bgp_clear_node_queue *cnq = data;
2807 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002808 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002809 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002810 afi_t afi = bgp_node_table (rn)->afi;
2811 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002812
Paul Jakma64e580a2006-02-21 01:09:01 +00002813 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002814
Paul Jakma64e580a2006-02-21 01:09:01 +00002815 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002816 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002817 {
2818 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002819 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2820 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002821 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002822 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2823 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002824 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002825 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002826 break;
2827 }
paul200df112005-06-01 11:17:05 +00002828 return WQ_SUCCESS;
2829}
2830
2831static void
paul0fb58d52005-11-14 14:31:49 +00002832bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002833{
Chris Caputo228da422009-07-18 05:44:03 +00002834 struct bgp_clear_node_queue *cnq = data;
2835 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002836 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002837
2838 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002839 bgp_table_unlock (table);
2840 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002841}
2842
2843static void
paul94f2b392005-06-28 12:44:16 +00002844bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002845{
Paul Jakma64e580a2006-02-21 01:09:01 +00002846 struct peer *peer = wq->spec.data;
2847
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002848 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002849 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002850
2851 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002852}
2853
2854static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002855bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002856{
Paul Jakmaa2943652009-07-21 14:02:04 +01002857 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002858
Paul Jakmaa2943652009-07-21 14:02:04 +01002859 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002860#undef CLEAR_QUEUE_NAME_LEN
2861
2862 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002863 {
2864 zlog_err ("%s: Failed to allocate work queue", __func__);
2865 exit (1);
2866 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002867 peer->clear_node_queue->spec.hold = 10;
2868 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2869 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2870 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2871 peer->clear_node_queue->spec.max_retries = 0;
2872
2873 /* we only 'lock' this peer reference when the queue is actually active */
2874 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002875}
2876
paul718e3742002-12-13 20:15:29 +00002877static void
2878bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002879 struct bgp_table *table, struct peer *rsclient,
2880 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002881{
2882 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002883
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002884
paul718e3742002-12-13 20:15:29 +00002885 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002886 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002887
hasso6cf159b2005-03-21 10:28:14 +00002888 /* If still no table => afi/safi isn't configured at all or smth. */
2889 if (! table)
2890 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002891
2892 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2893 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002894 struct bgp_info *ri;
2895 struct bgp_adj_in *ain;
2896 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002897
2898 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2899 * queued for every clearing peer, regardless of whether it is
2900 * relevant to the peer at hand.
2901 *
2902 * Overview: There are 3 different indices which need to be
2903 * scrubbed, potentially, when a peer is removed:
2904 *
2905 * 1 peer's routes visible via the RIB (ie accepted routes)
2906 * 2 peer's routes visible by the (optional) peer's adj-in index
2907 * 3 other routes visible by the peer's adj-out index
2908 *
2909 * 3 there is no hurry in scrubbing, once the struct peer is
2910 * removed from bgp->peer, we could just GC such deleted peer's
2911 * adj-outs at our leisure.
2912 *
2913 * 1 and 2 must be 'scrubbed' in some way, at least made
2914 * invisible via RIB index before peer session is allowed to be
2915 * brought back up. So one needs to know when such a 'search' is
2916 * complete.
2917 *
2918 * Ideally:
2919 *
2920 * - there'd be a single global queue or a single RIB walker
2921 * - rather than tracking which route_nodes still need to be
2922 * examined on a peer basis, we'd track which peers still
2923 * aren't cleared
2924 *
2925 * Given that our per-peer prefix-counts now should be reliable,
2926 * this may actually be achievable. It doesn't seem to be a huge
2927 * problem at this time,
2928 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002929 for (ain = rn->adj_in; ain; ain = ain->next)
2930 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2931 {
2932 bgp_adj_in_remove (rn, ain);
2933 bgp_unlock_node (rn);
2934 break;
2935 }
2936 for (aout = rn->adj_out; aout; aout = aout->next)
2937 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2938 {
2939 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2940 bgp_unlock_node (rn);
2941 break;
2942 }
2943
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002944 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002945 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002946 {
Chris Caputo228da422009-07-18 05:44:03 +00002947 struct bgp_clear_node_queue *cnq;
2948
2949 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002950 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002951 bgp_lock_node (rn);
2952 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2953 sizeof (struct bgp_clear_node_queue));
2954 cnq->rn = rn;
2955 cnq->purpose = purpose;
2956 work_queue_add (peer->clear_node_queue, cnq);
2957 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002958 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002959 }
2960 return;
2961}
2962
2963void
Chris Caputo228da422009-07-18 05:44:03 +00002964bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2965 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002966{
2967 struct bgp_node *rn;
2968 struct bgp_table *table;
2969 struct peer *rsclient;
2970 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002971
Paul Jakma64e580a2006-02-21 01:09:01 +00002972 if (peer->clear_node_queue == NULL)
2973 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002974
Paul Jakmaca058a32006-09-14 02:58:49 +00002975 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2976 * Idle until it receives a Clearing_Completed event. This protects
2977 * against peers which flap faster than we can we clear, which could
2978 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002979 *
2980 * a) race with routes from the new session being installed before
2981 * clear_route_node visits the node (to delete the route of that
2982 * peer)
2983 * b) resource exhaustion, clear_route_node likely leads to an entry
2984 * on the process_main queue. Fast-flapping could cause that queue
2985 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002986 */
Donald Sharp7ef42212015-03-30 06:32:52 -07002987
2988 /* lock peer in assumption that clear-node-queue will get nodes; if so,
2989 * the unlock will happen upon work-queue completion; other wise, the
2990 * unlock happens at the end of this function.
2991 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002992 if (!peer->clear_node_queue->thread)
Donald Sharp7ef42212015-03-30 06:32:52 -07002993 peer_lock (peer);
paulfee0f4c2004-09-13 05:12:46 +00002994
Chris Caputo228da422009-07-18 05:44:03 +00002995 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002996 {
Chris Caputo228da422009-07-18 05:44:03 +00002997 case BGP_CLEAR_ROUTE_NORMAL:
2998 if (safi != SAFI_MPLS_VPN)
2999 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
3000 else
3001 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3002 rn = bgp_route_next (rn))
3003 if ((table = rn->info) != NULL)
3004 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3005
3006 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
3007 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
3008 PEER_FLAG_RSERVER_CLIENT))
3009 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3010 break;
3011
3012 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
3013 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3014 break;
3015
3016 default:
3017 assert (0);
3018 break;
paulfee0f4c2004-09-13 05:12:46 +00003019 }
Donald Sharp7ef42212015-03-30 06:32:52 -07003020
3021 /* unlock if no nodes got added to the clear-node-queue. */
Paul Jakma65ca75e2006-05-04 08:08:15 +00003022 if (!peer->clear_node_queue->thread)
Donald Sharp7ef42212015-03-30 06:32:52 -07003023 peer_unlock (peer);
3024
paul718e3742002-12-13 20:15:29 +00003025}
3026
3027void
3028bgp_clear_route_all (struct peer *peer)
3029{
3030 afi_t afi;
3031 safi_t safi;
3032
3033 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3034 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003035 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003036}
3037
3038void
3039bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3040{
3041 struct bgp_table *table;
3042 struct bgp_node *rn;
3043 struct bgp_adj_in *ain;
3044
3045 table = peer->bgp->rib[afi][safi];
3046
3047 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3048 for (ain = rn->adj_in; ain ; ain = ain->next)
3049 if (ain->peer == peer)
3050 {
3051 bgp_adj_in_remove (rn, ain);
3052 bgp_unlock_node (rn);
3053 break;
3054 }
3055}
hasso93406d82005-02-02 14:40:33 +00003056
3057void
3058bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3059{
3060 struct bgp_node *rn;
3061 struct bgp_info *ri;
3062 struct bgp_table *table;
3063
3064 table = peer->bgp->rib[afi][safi];
3065
3066 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3067 {
3068 for (ri = rn->info; ri; ri = ri->next)
3069 if (ri->peer == peer)
3070 {
3071 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3072 bgp_rib_remove (rn, ri, peer, afi, safi);
3073 break;
3074 }
3075 }
3076}
David Lamparter6b0655a2014-06-04 06:53:35 +02003077
paul718e3742002-12-13 20:15:29 +00003078/* Delete all kernel routes. */
3079void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003080bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003081{
3082 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003083 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003084 struct bgp_node *rn;
3085 struct bgp_table *table;
3086 struct bgp_info *ri;
3087
paul1eb8ef22005-04-07 07:30:20 +00003088 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003089 {
3090 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3091
3092 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3093 for (ri = rn->info; ri; ri = ri->next)
3094 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3095 && ri->type == ZEBRA_ROUTE_BGP
3096 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003097 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003098
3099 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3100
3101 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3102 for (ri = rn->info; ri; ri = ri->next)
3103 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3104 && ri->type == ZEBRA_ROUTE_BGP
3105 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003106 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003107 }
3108}
3109
3110void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003111bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003112{
3113 vty_reset ();
3114 bgp_zclient_reset ();
3115 access_list_reset ();
3116 prefix_list_reset ();
3117}
David Lamparter6b0655a2014-06-04 06:53:35 +02003118
paul718e3742002-12-13 20:15:29 +00003119/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3120 value. */
3121int
3122bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3123{
3124 u_char *pnt;
3125 u_char *lim;
3126 struct prefix p;
3127 int psize;
3128 int ret;
3129
3130 /* Check peer status. */
3131 if (peer->status != Established)
3132 return 0;
3133
3134 pnt = packet->nlri;
3135 lim = pnt + packet->length;
3136
3137 for (; pnt < lim; pnt += psize)
3138 {
3139 /* Clear prefix structure. */
3140 memset (&p, 0, sizeof (struct prefix));
3141
3142 /* Fetch prefix length. */
3143 p.prefixlen = *pnt++;
3144 p.family = afi2family (packet->afi);
3145
3146 /* Already checked in nlri_sanity_check(). We do double check
3147 here. */
3148 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3149 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3150 return -1;
3151
3152 /* Packet size overflow check. */
3153 psize = PSIZE (p.prefixlen);
3154
3155 /* When packet overflow occur return immediately. */
3156 if (pnt + psize > lim)
3157 return -1;
3158
3159 /* Fetch prefix from NLRI packet. */
3160 memcpy (&p.u.prefix, pnt, psize);
3161
3162 /* Check address. */
3163 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3164 {
3165 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3166 {
paulf5ba3872004-07-09 12:11:31 +00003167 /*
3168 * From draft-ietf-idr-bgp4-22, Section 6.3:
3169 * If a BGP router receives an UPDATE message with a
3170 * semantically incorrect NLRI field, in which a prefix is
3171 * semantically incorrect (eg. an unexpected multicast IP
3172 * address), it should ignore the prefix.
3173 */
paul718e3742002-12-13 20:15:29 +00003174 zlog (peer->log, LOG_ERR,
3175 "IPv4 unicast NLRI is multicast address %s",
3176 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003177
paul718e3742002-12-13 20:15:29 +00003178 return -1;
3179 }
3180 }
3181
3182#ifdef HAVE_IPV6
3183 /* Check address. */
3184 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3185 {
3186 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3187 {
3188 char buf[BUFSIZ];
3189
3190 zlog (peer->log, LOG_WARNING,
3191 "IPv6 link-local NLRI received %s ignore this NLRI",
3192 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3193
3194 continue;
3195 }
3196 }
3197#endif /* HAVE_IPV6 */
3198
3199 /* Normal process. */
3200 if (attr)
3201 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3202 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3203 else
3204 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3205 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3206
3207 /* Address family configuration mismatch or maximum-prefix count
3208 overflow. */
3209 if (ret < 0)
3210 return -1;
3211 }
3212
3213 /* Packet length consistency check. */
3214 if (pnt != lim)
3215 return -1;
3216
3217 return 0;
3218}
3219
3220/* NLRI encode syntax check routine. */
3221int
3222bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3223 bgp_size_t length)
3224{
3225 u_char *end;
3226 u_char prefixlen;
3227 int psize;
3228
3229 end = pnt + length;
3230
3231 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3232 syntactic validity. If the field is syntactically incorrect,
3233 then the Error Subcode is set to Invalid Network Field. */
3234
3235 while (pnt < end)
3236 {
3237 prefixlen = *pnt++;
3238
3239 /* Prefix length check. */
3240 if ((afi == AFI_IP && prefixlen > 32)
3241 || (afi == AFI_IP6 && prefixlen > 128))
3242 {
3243 plog_err (peer->log,
3244 "%s [Error] Update packet error (wrong prefix length %d)",
3245 peer->host, prefixlen);
3246 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3247 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3248 return -1;
3249 }
3250
3251 /* Packet size overflow check. */
3252 psize = PSIZE (prefixlen);
3253
3254 if (pnt + psize > end)
3255 {
3256 plog_err (peer->log,
3257 "%s [Error] Update packet error"
3258 " (prefix data overflow prefix size is %d)",
3259 peer->host, psize);
3260 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3261 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3262 return -1;
3263 }
3264
3265 pnt += psize;
3266 }
3267
3268 /* Packet length consistency check. */
3269 if (pnt != end)
3270 {
3271 plog_err (peer->log,
3272 "%s [Error] Update packet error"
3273 " (prefix length mismatch with total length)",
3274 peer->host);
3275 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3276 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3277 return -1;
3278 }
3279 return 0;
3280}
David Lamparter6b0655a2014-06-04 06:53:35 +02003281
paul94f2b392005-06-28 12:44:16 +00003282static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003283bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003284{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003285 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003286}
3287
paul94f2b392005-06-28 12:44:16 +00003288static void
paul718e3742002-12-13 20:15:29 +00003289bgp_static_free (struct bgp_static *bgp_static)
3290{
3291 if (bgp_static->rmap.name)
3292 free (bgp_static->rmap.name);
3293 XFREE (MTYPE_BGP_STATIC, bgp_static);
3294}
3295
paul94f2b392005-06-28 12:44:16 +00003296static void
paulfee0f4c2004-09-13 05:12:46 +00003297bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3298 struct prefix *p, afi_t afi, safi_t safi)
3299{
3300 struct bgp_node *rn;
3301 struct bgp_info *ri;
3302
3303 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3304
3305 /* Check selected route and self inserted route. */
3306 for (ri = rn->info; ri; ri = ri->next)
3307 if (ri->peer == bgp->peer_self
3308 && ri->type == ZEBRA_ROUTE_BGP
3309 && ri->sub_type == BGP_ROUTE_STATIC)
3310 break;
3311
3312 /* Withdraw static BGP route from routing table. */
3313 if (ri)
3314 {
paulfee0f4c2004-09-13 05:12:46 +00003315 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003316 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003317 }
3318
3319 /* Unlock bgp_node_lookup. */
3320 bgp_unlock_node (rn);
3321}
3322
paul94f2b392005-06-28 12:44:16 +00003323static void
paulfee0f4c2004-09-13 05:12:46 +00003324bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003325 struct bgp_static *bgp_static,
3326 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003327{
3328 struct bgp_node *rn;
3329 struct bgp_info *ri;
3330 struct bgp_info *new;
3331 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003332 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003333 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003334 struct attr new_attr;
3335 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003336 struct bgp *bgp;
3337 int ret;
3338 char buf[SU_ADDRSTRLEN];
3339
3340 bgp = rsclient->bgp;
3341
Paul Jakma06e110f2006-05-12 23:29:22 +00003342 assert (bgp_static);
3343 if (!bgp_static)
3344 return;
3345
paulfee0f4c2004-09-13 05:12:46 +00003346 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3347
3348 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003349
3350 attr.nexthop = bgp_static->igpnexthop;
3351 attr.med = bgp_static->igpmetric;
3352 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003353
Paul Jakma41367172007-08-06 15:24:51 +00003354 if (bgp_static->atomic)
3355 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3356
paulfee0f4c2004-09-13 05:12:46 +00003357 /* Apply network route-map for export to this rsclient. */
3358 if (bgp_static->rmap.name)
3359 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003360 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003361 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003362 info.attr = &attr_tmp;
3363
paulfee0f4c2004-09-13 05:12:46 +00003364 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3365 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3366
3367 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3368
3369 rsclient->rmap_type = 0;
3370
3371 if (ret == RMAP_DENYMATCH)
3372 {
3373 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003374 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003375
3376 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003377 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003378 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003379 bgp_attr_extra_free (&attr);
3380
paulfee0f4c2004-09-13 05:12:46 +00003381 return;
3382 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003383 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003384 }
3385 else
3386 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003387
3388 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003389 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003390
paulfee0f4c2004-09-13 05:12:46 +00003391 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3392
Paul Jakmafb982c22007-05-04 20:15:47 +00003393 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3394 == RMAP_DENY)
3395 {
paulfee0f4c2004-09-13 05:12:46 +00003396 /* This BGP update is filtered. Log the reason then update BGP entry. */
3397 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003398 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003399 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3400 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3401 p->prefixlen, rsclient->host);
3402
3403 bgp->peer_self->rmap_type = 0;
3404
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003405 bgp_attr_unintern (&attr_new);
3406 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003407 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003408
3409 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3410
3411 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003412 }
paulfee0f4c2004-09-13 05:12:46 +00003413
3414 bgp->peer_self->rmap_type = 0;
3415
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003416 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003417 attr_new = bgp_attr_intern (&new_attr);
3418
3419 for (ri = rn->info; ri; ri = ri->next)
3420 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3421 && ri->sub_type == BGP_ROUTE_STATIC)
3422 break;
3423
3424 if (ri)
3425 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003426 if (attrhash_cmp (ri->attr, attr_new) &&
3427 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003428 {
3429 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003430 bgp_attr_unintern (&attr_new);
3431 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003432 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003433 return;
3434 }
3435 else
3436 {
3437 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003438 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003439
3440 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003441 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3442 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003443 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003444 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003445 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003446
3447 /* Process change. */
3448 bgp_process (bgp, rn, afi, safi);
3449 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003450 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003451 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003452 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003453 }
paulfee0f4c2004-09-13 05:12:46 +00003454 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003455
paulfee0f4c2004-09-13 05:12:46 +00003456 /* Make new BGP info. */
3457 new = bgp_info_new ();
3458 new->type = ZEBRA_ROUTE_BGP;
3459 new->sub_type = BGP_ROUTE_STATIC;
3460 new->peer = bgp->peer_self;
3461 SET_FLAG (new->flags, BGP_INFO_VALID);
3462 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003463 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003464
3465 /* Register new BGP information. */
3466 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003467
3468 /* route_node_get lock */
3469 bgp_unlock_node (rn);
3470
paulfee0f4c2004-09-13 05:12:46 +00003471 /* Process change. */
3472 bgp_process (bgp, rn, afi, safi);
3473
3474 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003475 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003476 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003477}
3478
paul94f2b392005-06-28 12:44:16 +00003479static void
paulfee0f4c2004-09-13 05:12:46 +00003480bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003481 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3482{
3483 struct bgp_node *rn;
3484 struct bgp_info *ri;
3485 struct bgp_info *new;
3486 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003487 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003488 struct attr *attr_new;
3489 int ret;
3490
Paul Jakmadd8103a2006-05-12 23:27:30 +00003491 assert (bgp_static);
3492 if (!bgp_static)
3493 return;
3494
paulfee0f4c2004-09-13 05:12:46 +00003495 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003496
3497 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003498
3499 attr.nexthop = bgp_static->igpnexthop;
3500 attr.med = bgp_static->igpmetric;
3501 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003502
Paul Jakma41367172007-08-06 15:24:51 +00003503 if (bgp_static->atomic)
3504 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3505
paul718e3742002-12-13 20:15:29 +00003506 /* Apply route-map. */
3507 if (bgp_static->rmap.name)
3508 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003509 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003510 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003511 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003512
paulfee0f4c2004-09-13 05:12:46 +00003513 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3514
paul718e3742002-12-13 20:15:29 +00003515 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003516
paulfee0f4c2004-09-13 05:12:46 +00003517 bgp->peer_self->rmap_type = 0;
3518
paul718e3742002-12-13 20:15:29 +00003519 if (ret == RMAP_DENYMATCH)
3520 {
3521 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003522 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003523
3524 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003525 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003526 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003527 bgp_static_withdraw (bgp, p, afi, safi);
3528 return;
3529 }
paul286e1e72003-08-08 00:24:31 +00003530 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003531 }
paul286e1e72003-08-08 00:24:31 +00003532 else
3533 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003534
3535 for (ri = rn->info; ri; ri = ri->next)
3536 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3537 && ri->sub_type == BGP_ROUTE_STATIC)
3538 break;
3539
3540 if (ri)
3541 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003542 if (attrhash_cmp (ri->attr, attr_new) &&
3543 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003544 {
3545 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003546 bgp_attr_unintern (&attr_new);
3547 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003548 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003549 return;
3550 }
3551 else
3552 {
3553 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003554 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003555
3556 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003557 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3558 bgp_info_restore(rn, ri);
3559 else
3560 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003561 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003562 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003563 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003564
3565 /* Process change. */
3566 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3567 bgp_process (bgp, rn, afi, safi);
3568 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003569 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003570 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003571 return;
3572 }
3573 }
3574
3575 /* Make new BGP info. */
3576 new = bgp_info_new ();
3577 new->type = ZEBRA_ROUTE_BGP;
3578 new->sub_type = BGP_ROUTE_STATIC;
3579 new->peer = bgp->peer_self;
3580 SET_FLAG (new->flags, BGP_INFO_VALID);
3581 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003582 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003583
3584 /* Aggregate address increment. */
3585 bgp_aggregate_increment (bgp, p, new, afi, safi);
3586
3587 /* Register new BGP information. */
3588 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003589
3590 /* route_node_get lock */
3591 bgp_unlock_node (rn);
3592
paul718e3742002-12-13 20:15:29 +00003593 /* Process change. */
3594 bgp_process (bgp, rn, afi, safi);
3595
3596 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003597 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003598 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003599}
3600
3601void
paulfee0f4c2004-09-13 05:12:46 +00003602bgp_static_update (struct bgp *bgp, struct prefix *p,
3603 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3604{
3605 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003606 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003607
3608 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3609
paul1eb8ef22005-04-07 07:30:20 +00003610 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003611 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003612 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3613 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003614 }
3615}
3616
paul94f2b392005-06-28 12:44:16 +00003617static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003618bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3619 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003620{
3621 struct bgp_node *rn;
3622 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003623
paulfee0f4c2004-09-13 05:12:46 +00003624 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003625
3626 /* Make new BGP info. */
3627 new = bgp_info_new ();
3628 new->type = ZEBRA_ROUTE_BGP;
3629 new->sub_type = BGP_ROUTE_STATIC;
3630 new->peer = bgp->peer_self;
3631 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3632 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003633 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003634 new->extra = bgp_info_extra_new();
3635 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003636
3637 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003638 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003639
3640 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003641 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003642
paul200df112005-06-01 11:17:05 +00003643 /* route_node_get lock */
3644 bgp_unlock_node (rn);
3645
paul718e3742002-12-13 20:15:29 +00003646 /* Process change. */
3647 bgp_process (bgp, rn, afi, safi);
3648}
3649
3650void
3651bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3652 safi_t safi)
3653{
3654 struct bgp_node *rn;
3655 struct bgp_info *ri;
3656
paulfee0f4c2004-09-13 05:12:46 +00003657 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003658
3659 /* Check selected route and self inserted route. */
3660 for (ri = rn->info; ri; ri = ri->next)
3661 if (ri->peer == bgp->peer_self
3662 && ri->type == ZEBRA_ROUTE_BGP
3663 && ri->sub_type == BGP_ROUTE_STATIC)
3664 break;
3665
3666 /* Withdraw static BGP route from routing table. */
3667 if (ri)
3668 {
3669 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003670 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003671 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003672 }
3673
3674 /* Unlock bgp_node_lookup. */
3675 bgp_unlock_node (rn);
3676}
3677
3678void
paulfee0f4c2004-09-13 05:12:46 +00003679bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3680{
3681 struct bgp_static *bgp_static;
3682 struct bgp *bgp;
3683 struct bgp_node *rn;
3684 struct prefix *p;
3685
3686 bgp = rsclient->bgp;
3687
3688 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3689 if ((bgp_static = rn->info) != NULL)
3690 {
3691 p = &rn->p;
3692
3693 bgp_static_update_rsclient (rsclient, p, bgp_static,
3694 afi, safi);
3695 }
3696}
3697
paul94f2b392005-06-28 12:44:16 +00003698static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003699bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3700 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003701{
3702 struct bgp_node *rn;
3703 struct bgp_info *ri;
3704
paulfee0f4c2004-09-13 05:12:46 +00003705 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003706
3707 /* Check selected route and self inserted route. */
3708 for (ri = rn->info; ri; ri = ri->next)
3709 if (ri->peer == bgp->peer_self
3710 && ri->type == ZEBRA_ROUTE_BGP
3711 && ri->sub_type == BGP_ROUTE_STATIC)
3712 break;
3713
3714 /* Withdraw static BGP route from routing table. */
3715 if (ri)
3716 {
3717 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003718 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003719 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003720 }
3721
3722 /* Unlock bgp_node_lookup. */
3723 bgp_unlock_node (rn);
3724}
3725
3726/* Configure static BGP network. When user don't run zebra, static
3727 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003728static int
paulfd79ac92004-10-13 05:06:08 +00003729bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003730 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003731{
3732 int ret;
3733 struct prefix p;
3734 struct bgp_static *bgp_static;
3735 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003736 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003737
3738 /* Convert IP prefix string to struct prefix. */
3739 ret = str2prefix (ip_str, &p);
3740 if (! ret)
3741 {
3742 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3743 return CMD_WARNING;
3744 }
3745#ifdef HAVE_IPV6
3746 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3747 {
3748 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3749 VTY_NEWLINE);
3750 return CMD_WARNING;
3751 }
3752#endif /* HAVE_IPV6 */
3753
3754 apply_mask (&p);
3755
3756 /* Set BGP static route configuration. */
3757 rn = bgp_node_get (bgp->route[afi][safi], &p);
3758
3759 if (rn->info)
3760 {
3761 /* Configuration change. */
3762 bgp_static = rn->info;
3763
3764 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003765 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3766 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003767
paul718e3742002-12-13 20:15:29 +00003768 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003769
paul718e3742002-12-13 20:15:29 +00003770 if (rmap)
3771 {
3772 if (bgp_static->rmap.name)
3773 free (bgp_static->rmap.name);
3774 bgp_static->rmap.name = strdup (rmap);
3775 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3776 }
3777 else
3778 {
3779 if (bgp_static->rmap.name)
3780 free (bgp_static->rmap.name);
3781 bgp_static->rmap.name = NULL;
3782 bgp_static->rmap.map = NULL;
3783 bgp_static->valid = 0;
3784 }
3785 bgp_unlock_node (rn);
3786 }
3787 else
3788 {
3789 /* New configuration. */
3790 bgp_static = bgp_static_new ();
3791 bgp_static->backdoor = backdoor;
3792 bgp_static->valid = 0;
3793 bgp_static->igpmetric = 0;
3794 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003795
paul718e3742002-12-13 20:15:29 +00003796 if (rmap)
3797 {
3798 if (bgp_static->rmap.name)
3799 free (bgp_static->rmap.name);
3800 bgp_static->rmap.name = strdup (rmap);
3801 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3802 }
3803 rn->info = bgp_static;
3804 }
3805
3806 /* If BGP scan is not enabled, we should install this route here. */
3807 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3808 {
3809 bgp_static->valid = 1;
3810
3811 if (need_update)
3812 bgp_static_withdraw (bgp, &p, afi, safi);
3813
3814 if (! bgp_static->backdoor)
3815 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3816 }
3817
3818 return CMD_SUCCESS;
3819}
3820
3821/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003822static int
paulfd79ac92004-10-13 05:06:08 +00003823bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003824 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003825{
3826 int ret;
3827 struct prefix p;
3828 struct bgp_static *bgp_static;
3829 struct bgp_node *rn;
3830
3831 /* Convert IP prefix string to struct prefix. */
3832 ret = str2prefix (ip_str, &p);
3833 if (! ret)
3834 {
3835 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3836 return CMD_WARNING;
3837 }
3838#ifdef HAVE_IPV6
3839 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3840 {
3841 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3842 VTY_NEWLINE);
3843 return CMD_WARNING;
3844 }
3845#endif /* HAVE_IPV6 */
3846
3847 apply_mask (&p);
3848
3849 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3850 if (! rn)
3851 {
3852 vty_out (vty, "%% Can't find specified static route configuration.%s",
3853 VTY_NEWLINE);
3854 return CMD_WARNING;
3855 }
3856
3857 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003858
paul718e3742002-12-13 20:15:29 +00003859 /* Update BGP RIB. */
3860 if (! bgp_static->backdoor)
3861 bgp_static_withdraw (bgp, &p, afi, safi);
3862
3863 /* Clear configuration. */
3864 bgp_static_free (bgp_static);
3865 rn->info = NULL;
3866 bgp_unlock_node (rn);
3867 bgp_unlock_node (rn);
3868
3869 return CMD_SUCCESS;
3870}
3871
3872/* Called from bgp_delete(). Delete all static routes from the BGP
3873 instance. */
3874void
3875bgp_static_delete (struct bgp *bgp)
3876{
3877 afi_t afi;
3878 safi_t safi;
3879 struct bgp_node *rn;
3880 struct bgp_node *rm;
3881 struct bgp_table *table;
3882 struct bgp_static *bgp_static;
3883
3884 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3885 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3886 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3887 if (rn->info != NULL)
3888 {
3889 if (safi == SAFI_MPLS_VPN)
3890 {
3891 table = rn->info;
3892
3893 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3894 {
3895 bgp_static = rn->info;
3896 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3897 AFI_IP, SAFI_MPLS_VPN,
3898 (struct prefix_rd *)&rn->p,
3899 bgp_static->tag);
3900 bgp_static_free (bgp_static);
3901 rn->info = NULL;
3902 bgp_unlock_node (rn);
3903 }
3904 }
3905 else
3906 {
3907 bgp_static = rn->info;
3908 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3909 bgp_static_free (bgp_static);
3910 rn->info = NULL;
3911 bgp_unlock_node (rn);
3912 }
3913 }
3914}
3915
3916int
paulfd79ac92004-10-13 05:06:08 +00003917bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3918 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003919{
3920 int ret;
3921 struct prefix p;
3922 struct prefix_rd prd;
3923 struct bgp *bgp;
3924 struct bgp_node *prn;
3925 struct bgp_node *rn;
3926 struct bgp_table *table;
3927 struct bgp_static *bgp_static;
3928 u_char tag[3];
3929
3930 bgp = vty->index;
3931
3932 ret = str2prefix (ip_str, &p);
3933 if (! ret)
3934 {
3935 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3936 return CMD_WARNING;
3937 }
3938 apply_mask (&p);
3939
3940 ret = str2prefix_rd (rd_str, &prd);
3941 if (! ret)
3942 {
3943 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3944 return CMD_WARNING;
3945 }
3946
3947 ret = str2tag (tag_str, tag);
3948 if (! ret)
3949 {
3950 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3951 return CMD_WARNING;
3952 }
3953
3954 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3955 (struct prefix *)&prd);
3956 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003957 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003958 else
3959 bgp_unlock_node (prn);
3960 table = prn->info;
3961
3962 rn = bgp_node_get (table, &p);
3963
3964 if (rn->info)
3965 {
3966 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3967 bgp_unlock_node (rn);
3968 }
3969 else
3970 {
3971 /* New configuration. */
3972 bgp_static = bgp_static_new ();
3973 bgp_static->valid = 1;
3974 memcpy (bgp_static->tag, tag, 3);
3975 rn->info = bgp_static;
3976
3977 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3978 }
3979
3980 return CMD_SUCCESS;
3981}
3982
3983/* Configure static BGP network. */
3984int
paulfd79ac92004-10-13 05:06:08 +00003985bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3986 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003987{
3988 int ret;
3989 struct bgp *bgp;
3990 struct prefix p;
3991 struct prefix_rd prd;
3992 struct bgp_node *prn;
3993 struct bgp_node *rn;
3994 struct bgp_table *table;
3995 struct bgp_static *bgp_static;
3996 u_char tag[3];
3997
3998 bgp = vty->index;
3999
4000 /* Convert IP prefix string to struct prefix. */
4001 ret = str2prefix (ip_str, &p);
4002 if (! ret)
4003 {
4004 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4005 return CMD_WARNING;
4006 }
4007 apply_mask (&p);
4008
4009 ret = str2prefix_rd (rd_str, &prd);
4010 if (! ret)
4011 {
4012 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4013 return CMD_WARNING;
4014 }
4015
4016 ret = str2tag (tag_str, tag);
4017 if (! ret)
4018 {
4019 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4020 return CMD_WARNING;
4021 }
4022
4023 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4024 (struct prefix *)&prd);
4025 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00004026 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00004027 else
4028 bgp_unlock_node (prn);
4029 table = prn->info;
4030
4031 rn = bgp_node_lookup (table, &p);
4032
4033 if (rn)
4034 {
4035 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4036
4037 bgp_static = rn->info;
4038 bgp_static_free (bgp_static);
4039 rn->info = NULL;
4040 bgp_unlock_node (rn);
4041 bgp_unlock_node (rn);
4042 }
4043 else
4044 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4045
4046 return CMD_SUCCESS;
4047}
David Lamparter6b0655a2014-06-04 06:53:35 +02004048
paul718e3742002-12-13 20:15:29 +00004049DEFUN (bgp_network,
4050 bgp_network_cmd,
4051 "network A.B.C.D/M",
4052 "Specify a network to announce via BGP\n"
4053 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4054{
4055 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004056 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004057}
4058
4059DEFUN (bgp_network_route_map,
4060 bgp_network_route_map_cmd,
4061 "network A.B.C.D/M route-map WORD",
4062 "Specify a network to announce via BGP\n"
4063 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4064 "Route-map to modify the attributes\n"
4065 "Name of the route map\n")
4066{
4067 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004068 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004069}
4070
4071DEFUN (bgp_network_backdoor,
4072 bgp_network_backdoor_cmd,
4073 "network A.B.C.D/M backdoor",
4074 "Specify a network to announce via BGP\n"
4075 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4076 "Specify a BGP backdoor route\n")
4077{
Paul Jakma41367172007-08-06 15:24:51 +00004078 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004079 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004080}
4081
4082DEFUN (bgp_network_mask,
4083 bgp_network_mask_cmd,
4084 "network A.B.C.D mask A.B.C.D",
4085 "Specify a network to announce via BGP\n"
4086 "Network number\n"
4087 "Network mask\n"
4088 "Network mask\n")
4089{
4090 int ret;
4091 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004092
paul718e3742002-12-13 20:15:29 +00004093 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4094 if (! ret)
4095 {
4096 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4097 return CMD_WARNING;
4098 }
4099
4100 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004101 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004102}
4103
4104DEFUN (bgp_network_mask_route_map,
4105 bgp_network_mask_route_map_cmd,
4106 "network A.B.C.D mask A.B.C.D route-map WORD",
4107 "Specify a network to announce via BGP\n"
4108 "Network number\n"
4109 "Network mask\n"
4110 "Network mask\n"
4111 "Route-map to modify the attributes\n"
4112 "Name of the route map\n")
4113{
4114 int ret;
4115 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004116
paul718e3742002-12-13 20:15:29 +00004117 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4118 if (! ret)
4119 {
4120 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4121 return CMD_WARNING;
4122 }
4123
4124 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004125 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004126}
4127
4128DEFUN (bgp_network_mask_backdoor,
4129 bgp_network_mask_backdoor_cmd,
4130 "network A.B.C.D mask A.B.C.D backdoor",
4131 "Specify a network to announce via BGP\n"
4132 "Network number\n"
4133 "Network mask\n"
4134 "Network mask\n"
4135 "Specify a BGP backdoor route\n")
4136{
4137 int ret;
4138 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004139
paul718e3742002-12-13 20:15:29 +00004140 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4141 if (! ret)
4142 {
4143 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4144 return CMD_WARNING;
4145 }
4146
Paul Jakma41367172007-08-06 15:24:51 +00004147 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004148 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004149}
4150
4151DEFUN (bgp_network_mask_natural,
4152 bgp_network_mask_natural_cmd,
4153 "network A.B.C.D",
4154 "Specify a network to announce via BGP\n"
4155 "Network number\n")
4156{
4157 int ret;
4158 char prefix_str[BUFSIZ];
4159
4160 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4161 if (! ret)
4162 {
4163 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4164 return CMD_WARNING;
4165 }
4166
4167 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004168 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004169}
4170
4171DEFUN (bgp_network_mask_natural_route_map,
4172 bgp_network_mask_natural_route_map_cmd,
4173 "network A.B.C.D route-map WORD",
4174 "Specify a network to announce via BGP\n"
4175 "Network number\n"
4176 "Route-map to modify the attributes\n"
4177 "Name of the route map\n")
4178{
4179 int ret;
4180 char prefix_str[BUFSIZ];
4181
4182 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4183 if (! ret)
4184 {
4185 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4186 return CMD_WARNING;
4187 }
4188
4189 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004190 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004191}
4192
4193DEFUN (bgp_network_mask_natural_backdoor,
4194 bgp_network_mask_natural_backdoor_cmd,
4195 "network A.B.C.D backdoor",
4196 "Specify a network to announce via BGP\n"
4197 "Network number\n"
4198 "Specify a BGP backdoor route\n")
4199{
4200 int ret;
4201 char prefix_str[BUFSIZ];
4202
4203 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4204 if (! ret)
4205 {
4206 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4207 return CMD_WARNING;
4208 }
4209
Paul Jakma41367172007-08-06 15:24:51 +00004210 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004211 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004212}
4213
4214DEFUN (no_bgp_network,
4215 no_bgp_network_cmd,
4216 "no network A.B.C.D/M",
4217 NO_STR
4218 "Specify a network to announce via BGP\n"
4219 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4220{
4221 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4222 bgp_node_safi (vty));
4223}
4224
4225ALIAS (no_bgp_network,
4226 no_bgp_network_route_map_cmd,
4227 "no network A.B.C.D/M route-map WORD",
4228 NO_STR
4229 "Specify a network to announce via BGP\n"
4230 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4231 "Route-map to modify the attributes\n"
4232 "Name of the route map\n")
4233
4234ALIAS (no_bgp_network,
4235 no_bgp_network_backdoor_cmd,
4236 "no network A.B.C.D/M backdoor",
4237 NO_STR
4238 "Specify a network to announce via BGP\n"
4239 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4240 "Specify a BGP backdoor route\n")
4241
4242DEFUN (no_bgp_network_mask,
4243 no_bgp_network_mask_cmd,
4244 "no network A.B.C.D mask A.B.C.D",
4245 NO_STR
4246 "Specify a network to announce via BGP\n"
4247 "Network number\n"
4248 "Network mask\n"
4249 "Network mask\n")
4250{
4251 int ret;
4252 char prefix_str[BUFSIZ];
4253
4254 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4255 if (! ret)
4256 {
4257 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4258 return CMD_WARNING;
4259 }
4260
4261 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4262 bgp_node_safi (vty));
4263}
4264
4265ALIAS (no_bgp_network_mask,
4266 no_bgp_network_mask_route_map_cmd,
4267 "no network A.B.C.D mask A.B.C.D route-map WORD",
4268 NO_STR
4269 "Specify a network to announce via BGP\n"
4270 "Network number\n"
4271 "Network mask\n"
4272 "Network mask\n"
4273 "Route-map to modify the attributes\n"
4274 "Name of the route map\n")
4275
4276ALIAS (no_bgp_network_mask,
4277 no_bgp_network_mask_backdoor_cmd,
4278 "no network A.B.C.D mask A.B.C.D backdoor",
4279 NO_STR
4280 "Specify a network to announce via BGP\n"
4281 "Network number\n"
4282 "Network mask\n"
4283 "Network mask\n"
4284 "Specify a BGP backdoor route\n")
4285
4286DEFUN (no_bgp_network_mask_natural,
4287 no_bgp_network_mask_natural_cmd,
4288 "no network A.B.C.D",
4289 NO_STR
4290 "Specify a network to announce via BGP\n"
4291 "Network number\n")
4292{
4293 int ret;
4294 char prefix_str[BUFSIZ];
4295
4296 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4297 if (! ret)
4298 {
4299 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4300 return CMD_WARNING;
4301 }
4302
4303 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4304 bgp_node_safi (vty));
4305}
4306
4307ALIAS (no_bgp_network_mask_natural,
4308 no_bgp_network_mask_natural_route_map_cmd,
4309 "no network A.B.C.D route-map WORD",
4310 NO_STR
4311 "Specify a network to announce via BGP\n"
4312 "Network number\n"
4313 "Route-map to modify the attributes\n"
4314 "Name of the route map\n")
4315
4316ALIAS (no_bgp_network_mask_natural,
4317 no_bgp_network_mask_natural_backdoor_cmd,
4318 "no network A.B.C.D backdoor",
4319 NO_STR
4320 "Specify a network to announce via BGP\n"
4321 "Network number\n"
4322 "Specify a BGP backdoor route\n")
4323
4324#ifdef HAVE_IPV6
4325DEFUN (ipv6_bgp_network,
4326 ipv6_bgp_network_cmd,
4327 "network X:X::X:X/M",
4328 "Specify a network to announce via BGP\n"
4329 "IPv6 prefix <network>/<length>\n")
4330{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304331 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004332 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004333}
4334
4335DEFUN (ipv6_bgp_network_route_map,
4336 ipv6_bgp_network_route_map_cmd,
4337 "network X:X::X:X/M route-map WORD",
4338 "Specify a network to announce via BGP\n"
4339 "IPv6 prefix <network>/<length>\n"
4340 "Route-map to modify the attributes\n"
4341 "Name of the route map\n")
4342{
4343 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004344 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004345}
4346
4347DEFUN (no_ipv6_bgp_network,
4348 no_ipv6_bgp_network_cmd,
4349 "no network X:X::X:X/M",
4350 NO_STR
4351 "Specify a network to announce via BGP\n"
4352 "IPv6 prefix <network>/<length>\n")
4353{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304354 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004355}
4356
4357ALIAS (no_ipv6_bgp_network,
4358 no_ipv6_bgp_network_route_map_cmd,
4359 "no network X:X::X:X/M route-map WORD",
4360 NO_STR
4361 "Specify a network to announce via BGP\n"
4362 "IPv6 prefix <network>/<length>\n"
4363 "Route-map to modify the attributes\n"
4364 "Name of the route map\n")
4365
4366ALIAS (ipv6_bgp_network,
4367 old_ipv6_bgp_network_cmd,
4368 "ipv6 bgp network X:X::X:X/M",
4369 IPV6_STR
4370 BGP_STR
4371 "Specify a network to announce via BGP\n"
4372 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4373
4374ALIAS (no_ipv6_bgp_network,
4375 old_no_ipv6_bgp_network_cmd,
4376 "no ipv6 bgp network X:X::X:X/M",
4377 NO_STR
4378 IPV6_STR
4379 BGP_STR
4380 "Specify a network to announce via BGP\n"
4381 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4382#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004383
4384/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4385ALIAS_DEPRECATED (bgp_network,
4386 bgp_network_ttl_cmd,
4387 "network A.B.C.D/M pathlimit <0-255>",
4388 "Specify a network to announce via BGP\n"
4389 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4390 "AS-Path hopcount limit attribute\n"
4391 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4392ALIAS_DEPRECATED (bgp_network_backdoor,
4393 bgp_network_backdoor_ttl_cmd,
4394 "network A.B.C.D/M backdoor pathlimit <0-255>",
4395 "Specify a network to announce via BGP\n"
4396 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4397 "Specify a BGP backdoor route\n"
4398 "AS-Path hopcount limit attribute\n"
4399 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4400ALIAS_DEPRECATED (bgp_network_mask,
4401 bgp_network_mask_ttl_cmd,
4402 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4403 "Specify a network to announce via BGP\n"
4404 "Network number\n"
4405 "Network mask\n"
4406 "Network mask\n"
4407 "AS-Path hopcount limit attribute\n"
4408 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4409ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4410 bgp_network_mask_backdoor_ttl_cmd,
4411 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4412 "Specify a network to announce via BGP\n"
4413 "Network number\n"
4414 "Network mask\n"
4415 "Network mask\n"
4416 "Specify a BGP backdoor route\n"
4417 "AS-Path hopcount limit attribute\n"
4418 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4419ALIAS_DEPRECATED (bgp_network_mask_natural,
4420 bgp_network_mask_natural_ttl_cmd,
4421 "network A.B.C.D pathlimit <0-255>",
4422 "Specify a network to announce via BGP\n"
4423 "Network number\n"
4424 "AS-Path hopcount limit attribute\n"
4425 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4426ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4427 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004428 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004429 "Specify a network to announce via BGP\n"
4430 "Network number\n"
4431 "Specify a BGP backdoor route\n"
4432 "AS-Path hopcount limit attribute\n"
4433 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4434ALIAS_DEPRECATED (no_bgp_network,
4435 no_bgp_network_ttl_cmd,
4436 "no network A.B.C.D/M pathlimit <0-255>",
4437 NO_STR
4438 "Specify a network to announce via BGP\n"
4439 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4440 "AS-Path hopcount limit attribute\n"
4441 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4442ALIAS_DEPRECATED (no_bgp_network,
4443 no_bgp_network_backdoor_ttl_cmd,
4444 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4445 NO_STR
4446 "Specify a network to announce via BGP\n"
4447 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4448 "Specify a BGP backdoor route\n"
4449 "AS-Path hopcount limit attribute\n"
4450 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4451ALIAS_DEPRECATED (no_bgp_network,
4452 no_bgp_network_mask_ttl_cmd,
4453 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4454 NO_STR
4455 "Specify a network to announce via BGP\n"
4456 "Network number\n"
4457 "Network mask\n"
4458 "Network mask\n"
4459 "AS-Path hopcount limit attribute\n"
4460 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4461ALIAS_DEPRECATED (no_bgp_network_mask,
4462 no_bgp_network_mask_backdoor_ttl_cmd,
4463 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4464 NO_STR
4465 "Specify a network to announce via BGP\n"
4466 "Network number\n"
4467 "Network mask\n"
4468 "Network mask\n"
4469 "Specify a BGP backdoor route\n"
4470 "AS-Path hopcount limit attribute\n"
4471 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4472ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4473 no_bgp_network_mask_natural_ttl_cmd,
4474 "no network A.B.C.D pathlimit <0-255>",
4475 NO_STR
4476 "Specify a network to announce via BGP\n"
4477 "Network number\n"
4478 "AS-Path hopcount limit attribute\n"
4479 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4480ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4481 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4482 "no network A.B.C.D backdoor pathlimit <0-255>",
4483 NO_STR
4484 "Specify a network to announce via BGP\n"
4485 "Network number\n"
4486 "Specify a BGP backdoor route\n"
4487 "AS-Path hopcount limit attribute\n"
4488 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004489#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004490ALIAS_DEPRECATED (ipv6_bgp_network,
4491 ipv6_bgp_network_ttl_cmd,
4492 "network X:X::X:X/M pathlimit <0-255>",
4493 "Specify a network to announce via BGP\n"
4494 "IPv6 prefix <network>/<length>\n"
4495 "AS-Path hopcount limit attribute\n"
4496 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4497ALIAS_DEPRECATED (no_ipv6_bgp_network,
4498 no_ipv6_bgp_network_ttl_cmd,
4499 "no network X:X::X:X/M pathlimit <0-255>",
4500 NO_STR
4501 "Specify a network to announce via BGP\n"
4502 "IPv6 prefix <network>/<length>\n"
4503 "AS-Path hopcount limit attribute\n"
4504 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004505#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02004506
paul718e3742002-12-13 20:15:29 +00004507/* Aggreagete address:
4508
4509 advertise-map Set condition to advertise attribute
4510 as-set Generate AS set path information
4511 attribute-map Set attributes of aggregate
4512 route-map Set parameters of aggregate
4513 summary-only Filter more specific routes from updates
4514 suppress-map Conditionally filter more specific routes from updates
4515 <cr>
4516 */
4517struct bgp_aggregate
4518{
4519 /* Summary-only flag. */
4520 u_char summary_only;
4521
4522 /* AS set generation. */
4523 u_char as_set;
4524
4525 /* Route-map for aggregated route. */
4526 struct route_map *map;
4527
4528 /* Suppress-count. */
4529 unsigned long count;
4530
4531 /* SAFI configuration. */
4532 safi_t safi;
4533};
4534
paul94f2b392005-06-28 12:44:16 +00004535static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004536bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004537{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004538 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004539}
4540
paul94f2b392005-06-28 12:44:16 +00004541static void
paul718e3742002-12-13 20:15:29 +00004542bgp_aggregate_free (struct bgp_aggregate *aggregate)
4543{
4544 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4545}
4546
paul94f2b392005-06-28 12:44:16 +00004547static void
paul718e3742002-12-13 20:15:29 +00004548bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4549 afi_t afi, safi_t safi, struct bgp_info *del,
4550 struct bgp_aggregate *aggregate)
4551{
4552 struct bgp_table *table;
4553 struct bgp_node *top;
4554 struct bgp_node *rn;
4555 u_char origin;
4556 struct aspath *aspath = NULL;
4557 struct aspath *asmerge = NULL;
4558 struct community *community = NULL;
4559 struct community *commerge = NULL;
paul718e3742002-12-13 20:15:29 +00004560 struct bgp_info *ri;
4561 struct bgp_info *new;
4562 int first = 1;
4563 unsigned long match = 0;
4564
paul718e3742002-12-13 20:15:29 +00004565 /* ORIGIN attribute: If at least one route among routes that are
4566 aggregated has ORIGIN with the value INCOMPLETE, then the
4567 aggregated route must have the ORIGIN attribute with the value
4568 INCOMPLETE. Otherwise, if at least one route among routes that
4569 are aggregated has ORIGIN with the value EGP, then the aggregated
4570 route must have the origin attribute with the value EGP. In all
4571 other case the value of the ORIGIN attribute of the aggregated
4572 route is INTERNAL. */
4573 origin = BGP_ORIGIN_IGP;
4574
4575 table = bgp->rib[afi][safi];
4576
4577 top = bgp_node_get (table, p);
4578 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4579 if (rn->p.prefixlen > p->prefixlen)
4580 {
4581 match = 0;
4582
4583 for (ri = rn->info; ri; ri = ri->next)
4584 {
4585 if (BGP_INFO_HOLDDOWN (ri))
4586 continue;
4587
4588 if (del && ri == del)
4589 continue;
4590
4591 if (! rinew && first)
Paul Jakma7aa9dce2014-09-19 14:42:23 +01004592 first = 0;
paul718e3742002-12-13 20:15:29 +00004593
4594#ifdef AGGREGATE_NEXTHOP_CHECK
4595 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4596 || ri->attr->med != med)
4597 {
4598 if (aspath)
4599 aspath_free (aspath);
4600 if (community)
4601 community_free (community);
4602 bgp_unlock_node (rn);
4603 bgp_unlock_node (top);
4604 return;
4605 }
4606#endif /* AGGREGATE_NEXTHOP_CHECK */
4607
4608 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4609 {
4610 if (aggregate->summary_only)
4611 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004612 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004613 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004614 match++;
4615 }
4616
4617 aggregate->count++;
4618
4619 if (aggregate->as_set)
4620 {
4621 if (origin < ri->attr->origin)
4622 origin = ri->attr->origin;
4623
4624 if (aspath)
4625 {
4626 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4627 aspath_free (aspath);
4628 aspath = asmerge;
4629 }
4630 else
4631 aspath = aspath_dup (ri->attr->aspath);
4632
4633 if (ri->attr->community)
4634 {
4635 if (community)
4636 {
4637 commerge = community_merge (community,
4638 ri->attr->community);
4639 community = community_uniq_sort (commerge);
4640 community_free (commerge);
4641 }
4642 else
4643 community = community_dup (ri->attr->community);
4644 }
4645 }
4646 }
4647 }
4648 if (match)
4649 bgp_process (bgp, rn, afi, safi);
4650 }
4651 bgp_unlock_node (top);
4652
4653 if (rinew)
4654 {
4655 aggregate->count++;
4656
4657 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004658 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004659
4660 if (aggregate->as_set)
4661 {
4662 if (origin < rinew->attr->origin)
4663 origin = rinew->attr->origin;
4664
4665 if (aspath)
4666 {
4667 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4668 aspath_free (aspath);
4669 aspath = asmerge;
4670 }
4671 else
4672 aspath = aspath_dup (rinew->attr->aspath);
4673
4674 if (rinew->attr->community)
4675 {
4676 if (community)
4677 {
4678 commerge = community_merge (community,
4679 rinew->attr->community);
4680 community = community_uniq_sort (commerge);
4681 community_free (commerge);
4682 }
4683 else
4684 community = community_dup (rinew->attr->community);
4685 }
4686 }
4687 }
4688
4689 if (aggregate->count > 0)
4690 {
4691 rn = bgp_node_get (table, p);
4692 new = bgp_info_new ();
4693 new->type = ZEBRA_ROUTE_BGP;
4694 new->sub_type = BGP_ROUTE_AGGREGATE;
4695 new->peer = bgp->peer_self;
4696 SET_FLAG (new->flags, BGP_INFO_VALID);
4697 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004698 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004699
4700 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004701 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004702 bgp_process (bgp, rn, afi, safi);
4703 }
4704 else
4705 {
4706 if (aspath)
4707 aspath_free (aspath);
4708 if (community)
4709 community_free (community);
4710 }
4711}
4712
4713void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4714 struct bgp_aggregate *);
4715
4716void
4717bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4718 struct bgp_info *ri, afi_t afi, safi_t safi)
4719{
4720 struct bgp_node *child;
4721 struct bgp_node *rn;
4722 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004723 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004724
4725 /* MPLS-VPN aggregation is not yet supported. */
4726 if (safi == SAFI_MPLS_VPN)
4727 return;
4728
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004729 table = bgp->aggregate[afi][safi];
4730
4731 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004732 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004733 return;
4734
paul718e3742002-12-13 20:15:29 +00004735 if (p->prefixlen == 0)
4736 return;
4737
4738 if (BGP_INFO_HOLDDOWN (ri))
4739 return;
4740
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004741 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004742
4743 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004744 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004745 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4746 {
4747 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004748 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004749 }
4750 bgp_unlock_node (child);
4751}
4752
4753void
4754bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4755 struct bgp_info *del, afi_t afi, safi_t safi)
4756{
4757 struct bgp_node *child;
4758 struct bgp_node *rn;
4759 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004760 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004761
4762 /* MPLS-VPN aggregation is not yet supported. */
4763 if (safi == SAFI_MPLS_VPN)
4764 return;
4765
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004766 table = bgp->aggregate[afi][safi];
4767
4768 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004769 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004770 return;
4771
paul718e3742002-12-13 20:15:29 +00004772 if (p->prefixlen == 0)
4773 return;
4774
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004775 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004776
4777 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004778 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004779 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4780 {
4781 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004782 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004783 }
4784 bgp_unlock_node (child);
4785}
4786
paul94f2b392005-06-28 12:44:16 +00004787static void
paul718e3742002-12-13 20:15:29 +00004788bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4789 struct bgp_aggregate *aggregate)
4790{
4791 struct bgp_table *table;
4792 struct bgp_node *top;
4793 struct bgp_node *rn;
4794 struct bgp_info *new;
4795 struct bgp_info *ri;
4796 unsigned long match;
4797 u_char origin = BGP_ORIGIN_IGP;
4798 struct aspath *aspath = NULL;
4799 struct aspath *asmerge = NULL;
4800 struct community *community = NULL;
4801 struct community *commerge = NULL;
4802
4803 table = bgp->rib[afi][safi];
4804
4805 /* Sanity check. */
4806 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4807 return;
4808 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4809 return;
4810
4811 /* If routes exists below this node, generate aggregate routes. */
4812 top = bgp_node_get (table, p);
4813 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4814 if (rn->p.prefixlen > p->prefixlen)
4815 {
4816 match = 0;
4817
4818 for (ri = rn->info; ri; ri = ri->next)
4819 {
4820 if (BGP_INFO_HOLDDOWN (ri))
4821 continue;
4822
4823 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4824 {
4825 /* summary-only aggregate route suppress aggregated
4826 route announcement. */
4827 if (aggregate->summary_only)
4828 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004829 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004830 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004831 match++;
4832 }
4833 /* as-set aggregate route generate origin, as path,
4834 community aggregation. */
4835 if (aggregate->as_set)
4836 {
4837 if (origin < ri->attr->origin)
4838 origin = ri->attr->origin;
4839
4840 if (aspath)
4841 {
4842 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4843 aspath_free (aspath);
4844 aspath = asmerge;
4845 }
4846 else
4847 aspath = aspath_dup (ri->attr->aspath);
4848
4849 if (ri->attr->community)
4850 {
4851 if (community)
4852 {
4853 commerge = community_merge (community,
4854 ri->attr->community);
4855 community = community_uniq_sort (commerge);
4856 community_free (commerge);
4857 }
4858 else
4859 community = community_dup (ri->attr->community);
4860 }
4861 }
4862 aggregate->count++;
4863 }
4864 }
4865
4866 /* If this node is suppressed, process the change. */
4867 if (match)
4868 bgp_process (bgp, rn, afi, safi);
4869 }
4870 bgp_unlock_node (top);
4871
4872 /* Add aggregate route to BGP table. */
4873 if (aggregate->count)
4874 {
4875 rn = bgp_node_get (table, p);
4876
4877 new = bgp_info_new ();
4878 new->type = ZEBRA_ROUTE_BGP;
4879 new->sub_type = BGP_ROUTE_AGGREGATE;
4880 new->peer = bgp->peer_self;
4881 SET_FLAG (new->flags, BGP_INFO_VALID);
4882 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004883 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004884
4885 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004886 bgp_unlock_node (rn);
4887
paul718e3742002-12-13 20:15:29 +00004888 /* Process change. */
4889 bgp_process (bgp, rn, afi, safi);
4890 }
Denil Virae2a92582015-08-11 13:34:59 -07004891 else
4892 {
4893 if (aspath)
4894 aspath_free (aspath);
4895 if (community)
4896 community_free (community);
4897 }
paul718e3742002-12-13 20:15:29 +00004898}
4899
4900void
4901bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4902 safi_t safi, struct bgp_aggregate *aggregate)
4903{
4904 struct bgp_table *table;
4905 struct bgp_node *top;
4906 struct bgp_node *rn;
4907 struct bgp_info *ri;
4908 unsigned long match;
4909
4910 table = bgp->rib[afi][safi];
4911
4912 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4913 return;
4914 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4915 return;
4916
4917 /* If routes exists below this node, generate aggregate routes. */
4918 top = bgp_node_get (table, p);
4919 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4920 if (rn->p.prefixlen > p->prefixlen)
4921 {
4922 match = 0;
4923
4924 for (ri = rn->info; ri; ri = ri->next)
4925 {
4926 if (BGP_INFO_HOLDDOWN (ri))
4927 continue;
4928
4929 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4930 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004931 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004932 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004933 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004934
Paul Jakmafb982c22007-05-04 20:15:47 +00004935 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004936 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004937 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004938 match++;
4939 }
4940 }
4941 aggregate->count--;
4942 }
4943 }
4944
Paul Jakmafb982c22007-05-04 20:15:47 +00004945 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004946 if (match)
4947 bgp_process (bgp, rn, afi, safi);
4948 }
4949 bgp_unlock_node (top);
4950
4951 /* Delete aggregate route from BGP table. */
4952 rn = bgp_node_get (table, p);
4953
4954 for (ri = rn->info; ri; ri = ri->next)
4955 if (ri->peer == bgp->peer_self
4956 && ri->type == ZEBRA_ROUTE_BGP
4957 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4958 break;
4959
4960 /* Withdraw static BGP route from routing table. */
4961 if (ri)
4962 {
paul718e3742002-12-13 20:15:29 +00004963 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004964 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004965 }
4966
4967 /* Unlock bgp_node_lookup. */
4968 bgp_unlock_node (rn);
4969}
4970
4971/* Aggregate route attribute. */
4972#define AGGREGATE_SUMMARY_ONLY 1
4973#define AGGREGATE_AS_SET 1
4974
paul94f2b392005-06-28 12:44:16 +00004975static int
Robert Baysf6269b42010-08-05 10:26:28 -07004976bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4977 afi_t afi, safi_t safi)
4978{
4979 int ret;
4980 struct prefix p;
4981 struct bgp_node *rn;
4982 struct bgp *bgp;
4983 struct bgp_aggregate *aggregate;
4984
4985 /* Convert string to prefix structure. */
4986 ret = str2prefix (prefix_str, &p);
4987 if (!ret)
4988 {
4989 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4990 return CMD_WARNING;
4991 }
4992 apply_mask (&p);
4993
4994 /* Get BGP structure. */
4995 bgp = vty->index;
4996
4997 /* Old configuration check. */
4998 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4999 if (! rn)
5000 {
5001 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5002 VTY_NEWLINE);
5003 return CMD_WARNING;
5004 }
5005
5006 aggregate = rn->info;
5007 if (aggregate->safi & SAFI_UNICAST)
5008 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5009 if (aggregate->safi & SAFI_MULTICAST)
5010 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5011
5012 /* Unlock aggregate address configuration. */
5013 rn->info = NULL;
5014 bgp_aggregate_free (aggregate);
5015 bgp_unlock_node (rn);
5016 bgp_unlock_node (rn);
5017
5018 return CMD_SUCCESS;
5019}
5020
5021static int
5022bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00005023 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00005024 u_char summary_only, u_char as_set)
5025{
5026 int ret;
5027 struct prefix p;
5028 struct bgp_node *rn;
5029 struct bgp *bgp;
5030 struct bgp_aggregate *aggregate;
5031
5032 /* Convert string to prefix structure. */
5033 ret = str2prefix (prefix_str, &p);
5034 if (!ret)
5035 {
5036 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5037 return CMD_WARNING;
5038 }
5039 apply_mask (&p);
5040
5041 /* Get BGP structure. */
5042 bgp = vty->index;
5043
5044 /* Old configuration check. */
5045 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5046
5047 if (rn->info)
5048 {
5049 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005050 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005051 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5052 if (ret)
5053 {
Robert Bays368473f2010-08-05 10:26:29 -07005054 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5055 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005056 return CMD_WARNING;
5057 }
paul718e3742002-12-13 20:15:29 +00005058 }
5059
5060 /* Make aggregate address structure. */
5061 aggregate = bgp_aggregate_new ();
5062 aggregate->summary_only = summary_only;
5063 aggregate->as_set = as_set;
5064 aggregate->safi = safi;
5065 rn->info = aggregate;
5066
5067 /* Aggregate address insert into BGP routing table. */
5068 if (safi & SAFI_UNICAST)
5069 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5070 if (safi & SAFI_MULTICAST)
5071 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5072
5073 return CMD_SUCCESS;
5074}
5075
paul718e3742002-12-13 20:15:29 +00005076DEFUN (aggregate_address,
5077 aggregate_address_cmd,
5078 "aggregate-address A.B.C.D/M",
5079 "Configure BGP aggregate entries\n"
5080 "Aggregate prefix\n")
5081{
5082 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5083}
5084
5085DEFUN (aggregate_address_mask,
5086 aggregate_address_mask_cmd,
5087 "aggregate-address A.B.C.D A.B.C.D",
5088 "Configure BGP aggregate entries\n"
5089 "Aggregate address\n"
5090 "Aggregate mask\n")
5091{
5092 int ret;
5093 char prefix_str[BUFSIZ];
5094
5095 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5096
5097 if (! ret)
5098 {
5099 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5100 return CMD_WARNING;
5101 }
5102
5103 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5104 0, 0);
5105}
5106
5107DEFUN (aggregate_address_summary_only,
5108 aggregate_address_summary_only_cmd,
5109 "aggregate-address A.B.C.D/M summary-only",
5110 "Configure BGP aggregate entries\n"
5111 "Aggregate prefix\n"
5112 "Filter more specific routes from updates\n")
5113{
5114 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5115 AGGREGATE_SUMMARY_ONLY, 0);
5116}
5117
5118DEFUN (aggregate_address_mask_summary_only,
5119 aggregate_address_mask_summary_only_cmd,
5120 "aggregate-address A.B.C.D A.B.C.D summary-only",
5121 "Configure BGP aggregate entries\n"
5122 "Aggregate address\n"
5123 "Aggregate mask\n"
5124 "Filter more specific routes from updates\n")
5125{
5126 int ret;
5127 char prefix_str[BUFSIZ];
5128
5129 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5130
5131 if (! ret)
5132 {
5133 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5134 return CMD_WARNING;
5135 }
5136
5137 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5138 AGGREGATE_SUMMARY_ONLY, 0);
5139}
5140
5141DEFUN (aggregate_address_as_set,
5142 aggregate_address_as_set_cmd,
5143 "aggregate-address A.B.C.D/M as-set",
5144 "Configure BGP aggregate entries\n"
5145 "Aggregate prefix\n"
5146 "Generate AS set path information\n")
5147{
5148 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5149 0, AGGREGATE_AS_SET);
5150}
5151
5152DEFUN (aggregate_address_mask_as_set,
5153 aggregate_address_mask_as_set_cmd,
5154 "aggregate-address A.B.C.D A.B.C.D as-set",
5155 "Configure BGP aggregate entries\n"
5156 "Aggregate address\n"
5157 "Aggregate mask\n"
5158 "Generate AS set path information\n")
5159{
5160 int ret;
5161 char prefix_str[BUFSIZ];
5162
5163 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5164
5165 if (! ret)
5166 {
5167 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5168 return CMD_WARNING;
5169 }
5170
5171 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5172 0, AGGREGATE_AS_SET);
5173}
5174
5175
5176DEFUN (aggregate_address_as_set_summary,
5177 aggregate_address_as_set_summary_cmd,
5178 "aggregate-address A.B.C.D/M as-set summary-only",
5179 "Configure BGP aggregate entries\n"
5180 "Aggregate prefix\n"
5181 "Generate AS set path information\n"
5182 "Filter more specific routes from updates\n")
5183{
5184 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5185 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5186}
5187
5188ALIAS (aggregate_address_as_set_summary,
5189 aggregate_address_summary_as_set_cmd,
5190 "aggregate-address A.B.C.D/M summary-only as-set",
5191 "Configure BGP aggregate entries\n"
5192 "Aggregate prefix\n"
5193 "Filter more specific routes from updates\n"
5194 "Generate AS set path information\n")
5195
5196DEFUN (aggregate_address_mask_as_set_summary,
5197 aggregate_address_mask_as_set_summary_cmd,
5198 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5199 "Configure BGP aggregate entries\n"
5200 "Aggregate address\n"
5201 "Aggregate mask\n"
5202 "Generate AS set path information\n"
5203 "Filter more specific routes from updates\n")
5204{
5205 int ret;
5206 char prefix_str[BUFSIZ];
5207
5208 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5209
5210 if (! ret)
5211 {
5212 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5213 return CMD_WARNING;
5214 }
5215
5216 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5217 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5218}
5219
5220ALIAS (aggregate_address_mask_as_set_summary,
5221 aggregate_address_mask_summary_as_set_cmd,
5222 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5223 "Configure BGP aggregate entries\n"
5224 "Aggregate address\n"
5225 "Aggregate mask\n"
5226 "Filter more specific routes from updates\n"
5227 "Generate AS set path information\n")
5228
5229DEFUN (no_aggregate_address,
5230 no_aggregate_address_cmd,
5231 "no aggregate-address A.B.C.D/M",
5232 NO_STR
5233 "Configure BGP aggregate entries\n"
5234 "Aggregate prefix\n")
5235{
5236 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5237}
5238
5239ALIAS (no_aggregate_address,
5240 no_aggregate_address_summary_only_cmd,
5241 "no aggregate-address A.B.C.D/M summary-only",
5242 NO_STR
5243 "Configure BGP aggregate entries\n"
5244 "Aggregate prefix\n"
5245 "Filter more specific routes from updates\n")
5246
5247ALIAS (no_aggregate_address,
5248 no_aggregate_address_as_set_cmd,
5249 "no aggregate-address A.B.C.D/M as-set",
5250 NO_STR
5251 "Configure BGP aggregate entries\n"
5252 "Aggregate prefix\n"
5253 "Generate AS set path information\n")
5254
5255ALIAS (no_aggregate_address,
5256 no_aggregate_address_as_set_summary_cmd,
5257 "no aggregate-address A.B.C.D/M as-set summary-only",
5258 NO_STR
5259 "Configure BGP aggregate entries\n"
5260 "Aggregate prefix\n"
5261 "Generate AS set path information\n"
5262 "Filter more specific routes from updates\n")
5263
5264ALIAS (no_aggregate_address,
5265 no_aggregate_address_summary_as_set_cmd,
5266 "no aggregate-address A.B.C.D/M summary-only as-set",
5267 NO_STR
5268 "Configure BGP aggregate entries\n"
5269 "Aggregate prefix\n"
5270 "Filter more specific routes from updates\n"
5271 "Generate AS set path information\n")
5272
5273DEFUN (no_aggregate_address_mask,
5274 no_aggregate_address_mask_cmd,
5275 "no aggregate-address A.B.C.D A.B.C.D",
5276 NO_STR
5277 "Configure BGP aggregate entries\n"
5278 "Aggregate address\n"
5279 "Aggregate mask\n")
5280{
5281 int ret;
5282 char prefix_str[BUFSIZ];
5283
5284 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5285
5286 if (! ret)
5287 {
5288 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5289 return CMD_WARNING;
5290 }
5291
5292 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5293}
5294
5295ALIAS (no_aggregate_address_mask,
5296 no_aggregate_address_mask_summary_only_cmd,
5297 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5298 NO_STR
5299 "Configure BGP aggregate entries\n"
5300 "Aggregate address\n"
5301 "Aggregate mask\n"
5302 "Filter more specific routes from updates\n")
5303
5304ALIAS (no_aggregate_address_mask,
5305 no_aggregate_address_mask_as_set_cmd,
5306 "no aggregate-address A.B.C.D A.B.C.D as-set",
5307 NO_STR
5308 "Configure BGP aggregate entries\n"
5309 "Aggregate address\n"
5310 "Aggregate mask\n"
5311 "Generate AS set path information\n")
5312
5313ALIAS (no_aggregate_address_mask,
5314 no_aggregate_address_mask_as_set_summary_cmd,
5315 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5316 NO_STR
5317 "Configure BGP aggregate entries\n"
5318 "Aggregate address\n"
5319 "Aggregate mask\n"
5320 "Generate AS set path information\n"
5321 "Filter more specific routes from updates\n")
5322
5323ALIAS (no_aggregate_address_mask,
5324 no_aggregate_address_mask_summary_as_set_cmd,
5325 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5326 NO_STR
5327 "Configure BGP aggregate entries\n"
5328 "Aggregate address\n"
5329 "Aggregate mask\n"
5330 "Filter more specific routes from updates\n"
5331 "Generate AS set path information\n")
5332
5333#ifdef HAVE_IPV6
5334DEFUN (ipv6_aggregate_address,
5335 ipv6_aggregate_address_cmd,
5336 "aggregate-address X:X::X:X/M",
5337 "Configure BGP aggregate entries\n"
5338 "Aggregate prefix\n")
5339{
5340 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5341}
5342
5343DEFUN (ipv6_aggregate_address_summary_only,
5344 ipv6_aggregate_address_summary_only_cmd,
5345 "aggregate-address X:X::X:X/M summary-only",
5346 "Configure BGP aggregate entries\n"
5347 "Aggregate prefix\n"
5348 "Filter more specific routes from updates\n")
5349{
5350 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5351 AGGREGATE_SUMMARY_ONLY, 0);
5352}
5353
5354DEFUN (no_ipv6_aggregate_address,
5355 no_ipv6_aggregate_address_cmd,
5356 "no aggregate-address X:X::X:X/M",
5357 NO_STR
5358 "Configure BGP aggregate entries\n"
5359 "Aggregate prefix\n")
5360{
5361 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5362}
5363
5364DEFUN (no_ipv6_aggregate_address_summary_only,
5365 no_ipv6_aggregate_address_summary_only_cmd,
5366 "no aggregate-address X:X::X:X/M summary-only",
5367 NO_STR
5368 "Configure BGP aggregate entries\n"
5369 "Aggregate prefix\n"
5370 "Filter more specific routes from updates\n")
5371{
5372 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5373}
5374
5375ALIAS (ipv6_aggregate_address,
5376 old_ipv6_aggregate_address_cmd,
5377 "ipv6 bgp aggregate-address X:X::X:X/M",
5378 IPV6_STR
5379 BGP_STR
5380 "Configure BGP aggregate entries\n"
5381 "Aggregate prefix\n")
5382
5383ALIAS (ipv6_aggregate_address_summary_only,
5384 old_ipv6_aggregate_address_summary_only_cmd,
5385 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5386 IPV6_STR
5387 BGP_STR
5388 "Configure BGP aggregate entries\n"
5389 "Aggregate prefix\n"
5390 "Filter more specific routes from updates\n")
5391
5392ALIAS (no_ipv6_aggregate_address,
5393 old_no_ipv6_aggregate_address_cmd,
5394 "no ipv6 bgp aggregate-address X:X::X:X/M",
5395 NO_STR
5396 IPV6_STR
5397 BGP_STR
5398 "Configure BGP aggregate entries\n"
5399 "Aggregate prefix\n")
5400
5401ALIAS (no_ipv6_aggregate_address_summary_only,
5402 old_no_ipv6_aggregate_address_summary_only_cmd,
5403 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5404 NO_STR
5405 IPV6_STR
5406 BGP_STR
5407 "Configure BGP aggregate entries\n"
5408 "Aggregate prefix\n"
5409 "Filter more specific routes from updates\n")
5410#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02005411
paul718e3742002-12-13 20:15:29 +00005412/* Redistribute route treatment. */
5413void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005414bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5415 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005416 u_int32_t metric, u_char type)
5417{
5418 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005419 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005420 struct bgp_info *new;
5421 struct bgp_info *bi;
5422 struct bgp_info info;
5423 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005424 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005425 struct attr *new_attr;
5426 afi_t afi;
5427 int ret;
5428
5429 /* Make default attribute. */
5430 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5431 if (nexthop)
5432 attr.nexthop = *nexthop;
5433
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005434#ifdef HAVE_IPV6
5435 if (nexthop6)
5436 {
5437 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5438 extra->mp_nexthop_global = *nexthop6;
5439 extra->mp_nexthop_len = 16;
5440 }
5441#endif
5442
paul718e3742002-12-13 20:15:29 +00005443 attr.med = metric;
5444 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5445
paul1eb8ef22005-04-07 07:30:20 +00005446 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005447 {
5448 afi = family2afi (p->family);
5449
5450 if (bgp->redist[afi][type])
5451 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005452 struct attr attr_new;
5453 struct attr_extra extra_new;
5454
paul718e3742002-12-13 20:15:29 +00005455 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005456 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005457 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005458
5459 if (bgp->redist_metric_flag[afi][type])
5460 attr_new.med = bgp->redist_metric[afi][type];
5461
5462 /* Apply route-map. */
Daniel Walton1994dc82015-09-17 10:15:59 -04005463 if (bgp->rmap[afi][type].name)
paul718e3742002-12-13 20:15:29 +00005464 {
5465 info.peer = bgp->peer_self;
5466 info.attr = &attr_new;
5467
paulfee0f4c2004-09-13 05:12:46 +00005468 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5469
paul718e3742002-12-13 20:15:29 +00005470 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5471 &info);
paulfee0f4c2004-09-13 05:12:46 +00005472
5473 bgp->peer_self->rmap_type = 0;
5474
paul718e3742002-12-13 20:15:29 +00005475 if (ret == RMAP_DENYMATCH)
5476 {
5477 /* Free uninterned attribute. */
5478 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005479
paul718e3742002-12-13 20:15:29 +00005480 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005481 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005482 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005483 bgp_redistribute_delete (p, type);
5484 return;
5485 }
5486 }
5487
Paul Jakmafb982c22007-05-04 20:15:47 +00005488 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5489 afi, SAFI_UNICAST, p, NULL);
5490
paul718e3742002-12-13 20:15:29 +00005491 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005492
paul718e3742002-12-13 20:15:29 +00005493 for (bi = bn->info; bi; bi = bi->next)
5494 if (bi->peer == bgp->peer_self
5495 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5496 break;
5497
5498 if (bi)
5499 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005500 if (attrhash_cmp (bi->attr, new_attr) &&
5501 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005502 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005503 bgp_attr_unintern (&new_attr);
5504 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005505 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005506 bgp_unlock_node (bn);
5507 return;
5508 }
5509 else
5510 {
5511 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005512 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005513
5514 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005515 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5516 bgp_info_restore(bn, bi);
5517 else
5518 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005519 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005520 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005521 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005522
5523 /* Process change. */
5524 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5525 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5526 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005527 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005528 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005529 return;
5530 }
5531 }
5532
5533 new = bgp_info_new ();
5534 new->type = type;
5535 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5536 new->peer = bgp->peer_self;
5537 SET_FLAG (new->flags, BGP_INFO_VALID);
5538 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005539 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005540
5541 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5542 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005543 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005544 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5545 }
5546 }
5547
5548 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005549 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005550 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005551}
5552
5553void
5554bgp_redistribute_delete (struct prefix *p, u_char type)
5555{
5556 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005557 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005558 afi_t afi;
5559 struct bgp_node *rn;
5560 struct bgp_info *ri;
5561
paul1eb8ef22005-04-07 07:30:20 +00005562 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005563 {
5564 afi = family2afi (p->family);
5565
5566 if (bgp->redist[afi][type])
5567 {
paulfee0f4c2004-09-13 05:12:46 +00005568 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005569
5570 for (ri = rn->info; ri; ri = ri->next)
5571 if (ri->peer == bgp->peer_self
5572 && ri->type == type)
5573 break;
5574
5575 if (ri)
5576 {
5577 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005578 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005579 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005580 }
5581 bgp_unlock_node (rn);
5582 }
5583 }
5584}
5585
5586/* Withdraw specified route type's route. */
5587void
5588bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5589{
5590 struct bgp_node *rn;
5591 struct bgp_info *ri;
5592 struct bgp_table *table;
5593
5594 table = bgp->rib[afi][SAFI_UNICAST];
5595
5596 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5597 {
5598 for (ri = rn->info; ri; ri = ri->next)
5599 if (ri->peer == bgp->peer_self
5600 && ri->type == type)
5601 break;
5602
5603 if (ri)
5604 {
5605 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005606 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005607 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005608 }
5609 }
5610}
David Lamparter6b0655a2014-06-04 06:53:35 +02005611
paul718e3742002-12-13 20:15:29 +00005612/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005613static void
paul718e3742002-12-13 20:15:29 +00005614route_vty_out_route (struct prefix *p, struct vty *vty)
5615{
5616 int len;
5617 u_int32_t destination;
5618 char buf[BUFSIZ];
5619
5620 if (p->family == AF_INET)
5621 {
5622 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5623 destination = ntohl (p->u.prefix4.s_addr);
5624
5625 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5626 || (IN_CLASSB (destination) && p->prefixlen == 16)
5627 || (IN_CLASSA (destination) && p->prefixlen == 8)
5628 || p->u.prefix4.s_addr == 0)
5629 {
5630 /* When mask is natural, mask is not displayed. */
5631 }
5632 else
5633 len += vty_out (vty, "/%d", p->prefixlen);
5634 }
5635 else
5636 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5637 p->prefixlen);
5638
5639 len = 17 - len;
5640 if (len < 1)
5641 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5642 else
5643 vty_out (vty, "%*s", len, " ");
5644}
5645
paul718e3742002-12-13 20:15:29 +00005646enum bgp_display_type
5647{
5648 normal_list,
5649};
5650
paulb40d9392005-08-22 22:34:41 +00005651/* Print the short form route status for a bgp_info */
5652static void
5653route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005654{
paulb40d9392005-08-22 22:34:41 +00005655 /* Route status display. */
5656 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5657 vty_out (vty, "R");
5658 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005659 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005660 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005661 vty_out (vty, "s");
5662 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5663 vty_out (vty, "*");
5664 else
5665 vty_out (vty, " ");
5666
5667 /* Selected */
5668 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5669 vty_out (vty, "h");
5670 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5671 vty_out (vty, "d");
5672 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5673 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005674 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5675 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005676 else
5677 vty_out (vty, " ");
5678
5679 /* Internal route. */
5680 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5681 vty_out (vty, "i");
5682 else
paulb40d9392005-08-22 22:34:41 +00005683 vty_out (vty, " ");
5684}
5685
5686/* called from terminal list command */
5687void
5688route_vty_out (struct vty *vty, struct prefix *p,
5689 struct bgp_info *binfo, int display, safi_t safi)
5690{
5691 struct attr *attr;
5692
5693 /* short status lead text */
5694 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005695
5696 /* print prefix and mask */
5697 if (! display)
5698 route_vty_out_route (p, vty);
5699 else
5700 vty_out (vty, "%*s", 17, " ");
5701
5702 /* Print attribute */
5703 attr = binfo->attr;
5704 if (attr)
5705 {
5706 if (p->family == AF_INET)
5707 {
5708 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005709 vty_out (vty, "%-16s",
5710 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005711 else
5712 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5713 }
5714#ifdef HAVE_IPV6
5715 else if (p->family == AF_INET6)
5716 {
5717 int len;
5718 char buf[BUFSIZ];
5719
5720 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005721 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5722 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005723 len = 16 - len;
5724 if (len < 1)
5725 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5726 else
5727 vty_out (vty, "%*s", len, " ");
5728 }
5729#endif /* HAVE_IPV6 */
5730
5731 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005732 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005733 else
5734 vty_out (vty, " ");
5735
5736 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005737 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005738 else
5739 vty_out (vty, " ");
5740
Paul Jakmafb982c22007-05-04 20:15:47 +00005741 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005742
Paul Jakmab2518c12006-05-12 23:48:40 +00005743 /* Print aspath */
5744 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005745 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005746
Paul Jakmab2518c12006-05-12 23:48:40 +00005747 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005748 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005749 }
paul718e3742002-12-13 20:15:29 +00005750 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005751}
5752
5753/* called from terminal list command */
5754void
5755route_vty_out_tmp (struct vty *vty, struct prefix *p,
5756 struct attr *attr, safi_t safi)
5757{
5758 /* Route status display. */
5759 vty_out (vty, "*");
5760 vty_out (vty, ">");
5761 vty_out (vty, " ");
5762
5763 /* print prefix and mask */
5764 route_vty_out_route (p, vty);
5765
5766 /* Print attribute */
5767 if (attr)
5768 {
5769 if (p->family == AF_INET)
5770 {
5771 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005772 vty_out (vty, "%-16s",
5773 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005774 else
5775 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5776 }
5777#ifdef HAVE_IPV6
5778 else if (p->family == AF_INET6)
5779 {
5780 int len;
5781 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005782
5783 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005784
5785 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005786 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5787 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005788 len = 16 - len;
5789 if (len < 1)
5790 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5791 else
5792 vty_out (vty, "%*s", len, " ");
5793 }
5794#endif /* HAVE_IPV6 */
5795
5796 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005797 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005798 else
5799 vty_out (vty, " ");
5800
5801 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005802 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005803 else
5804 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005805
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005806 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005807
Paul Jakmab2518c12006-05-12 23:48:40 +00005808 /* Print aspath */
5809 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005810 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005811
Paul Jakmab2518c12006-05-12 23:48:40 +00005812 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005813 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005814 }
paul718e3742002-12-13 20:15:29 +00005815
5816 vty_out (vty, "%s", VTY_NEWLINE);
5817}
5818
ajs5a646652004-11-05 01:25:55 +00005819void
paul718e3742002-12-13 20:15:29 +00005820route_vty_out_tag (struct vty *vty, struct prefix *p,
5821 struct bgp_info *binfo, int display, safi_t safi)
5822{
5823 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005824 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005825
5826 if (!binfo->extra)
5827 return;
5828
paulb40d9392005-08-22 22:34:41 +00005829 /* short status lead text */
5830 route_vty_short_status_out (vty, binfo);
5831
paul718e3742002-12-13 20:15:29 +00005832 /* print prefix and mask */
5833 if (! display)
5834 route_vty_out_route (p, vty);
5835 else
5836 vty_out (vty, "%*s", 17, " ");
5837
5838 /* Print attribute */
5839 attr = binfo->attr;
5840 if (attr)
5841 {
5842 if (p->family == AF_INET)
5843 {
5844 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005845 vty_out (vty, "%-16s",
5846 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005847 else
5848 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5849 }
5850#ifdef HAVE_IPV6
5851 else if (p->family == AF_INET6)
5852 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005853 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005854 char buf[BUFSIZ];
5855 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005856 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005857 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005858 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5859 buf, BUFSIZ));
5860 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005861 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005862 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5863 buf, BUFSIZ),
5864 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5865 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005866
5867 }
5868#endif /* HAVE_IPV6 */
5869 }
5870
Paul Jakmafb982c22007-05-04 20:15:47 +00005871 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005872
5873 vty_out (vty, "notag/%d", label);
5874
5875 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005876}
5877
5878/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005879static void
paul718e3742002-12-13 20:15:29 +00005880damp_route_vty_out (struct vty *vty, struct prefix *p,
5881 struct bgp_info *binfo, int display, safi_t safi)
5882{
5883 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005884 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005885 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005886
paulb40d9392005-08-22 22:34:41 +00005887 /* short status lead text */
5888 route_vty_short_status_out (vty, binfo);
5889
paul718e3742002-12-13 20:15:29 +00005890 /* print prefix and mask */
5891 if (! display)
5892 route_vty_out_route (p, vty);
5893 else
5894 vty_out (vty, "%*s", 17, " ");
5895
5896 len = vty_out (vty, "%s", binfo->peer->host);
5897 len = 17 - len;
5898 if (len < 1)
5899 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5900 else
5901 vty_out (vty, "%*s", len, " ");
5902
Chris Caputo50aef6f2009-06-23 06:06:49 +00005903 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005904
5905 /* Print attribute */
5906 attr = binfo->attr;
5907 if (attr)
5908 {
5909 /* Print aspath */
5910 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005911 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005912
5913 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005914 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005915 }
5916 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005917}
5918
paul718e3742002-12-13 20:15:29 +00005919/* flap route */
ajs5a646652004-11-05 01:25:55 +00005920static void
paul718e3742002-12-13 20:15:29 +00005921flap_route_vty_out (struct vty *vty, struct prefix *p,
5922 struct bgp_info *binfo, int display, safi_t safi)
5923{
5924 struct attr *attr;
5925 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005926 char timebuf[BGP_UPTIME_LEN];
5927 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005928
5929 if (!binfo->extra)
5930 return;
5931
5932 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005933
paulb40d9392005-08-22 22:34:41 +00005934 /* short status lead text */
5935 route_vty_short_status_out (vty, binfo);
5936
paul718e3742002-12-13 20:15:29 +00005937 /* print prefix and mask */
5938 if (! display)
5939 route_vty_out_route (p, vty);
5940 else
5941 vty_out (vty, "%*s", 17, " ");
5942
5943 len = vty_out (vty, "%s", binfo->peer->host);
5944 len = 16 - len;
5945 if (len < 1)
5946 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5947 else
5948 vty_out (vty, "%*s", len, " ");
5949
5950 len = vty_out (vty, "%d", bdi->flap);
5951 len = 5 - len;
5952 if (len < 1)
5953 vty_out (vty, " ");
5954 else
5955 vty_out (vty, "%*s ", len, " ");
5956
5957 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5958 timebuf, BGP_UPTIME_LEN));
5959
5960 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5961 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005962 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005963 else
5964 vty_out (vty, "%*s ", 8, " ");
5965
5966 /* Print attribute */
5967 attr = binfo->attr;
5968 if (attr)
5969 {
5970 /* Print aspath */
5971 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005972 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005973
5974 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005975 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005976 }
5977 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005978}
5979
paul94f2b392005-06-28 12:44:16 +00005980static void
paul718e3742002-12-13 20:15:29 +00005981route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5982 struct bgp_info *binfo, afi_t afi, safi_t safi)
5983{
5984 char buf[INET6_ADDRSTRLEN];
5985 char buf1[BUFSIZ];
5986 struct attr *attr;
5987 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005988#ifdef HAVE_CLOCK_MONOTONIC
5989 time_t tbuf;
5990#endif
paul718e3742002-12-13 20:15:29 +00005991
5992 attr = binfo->attr;
5993
5994 if (attr)
5995 {
5996 /* Line1 display AS-path, Aggregator */
5997 if (attr->aspath)
5998 {
5999 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00006000 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00006001 vty_out (vty, "Local");
6002 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006003 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00006004 }
6005
paulb40d9392005-08-22 22:34:41 +00006006 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6007 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00006008 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6009 vty_out (vty, ", (stale)");
6010 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006011 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006012 attr->extra->aggregator_as,
6013 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006014 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6015 vty_out (vty, ", (Received from a RR-client)");
6016 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6017 vty_out (vty, ", (Received from a RS-client)");
6018 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6019 vty_out (vty, ", (history entry)");
6020 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6021 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006022 vty_out (vty, "%s", VTY_NEWLINE);
6023
6024 /* Line2 display Next-hop, Neighbor, Router-id */
6025 if (p->family == AF_INET)
6026 {
6027 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006028 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006029 inet_ntoa (attr->nexthop));
6030 }
6031#ifdef HAVE_IPV6
6032 else
6033 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006034 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006035 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006036 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006037 buf, INET6_ADDRSTRLEN));
6038 }
6039#endif /* HAVE_IPV6 */
6040
6041 if (binfo->peer == bgp->peer_self)
6042 {
6043 vty_out (vty, " from %s ",
6044 p->family == AF_INET ? "0.0.0.0" : "::");
6045 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6046 }
6047 else
6048 {
6049 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6050 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006051 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006052 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006053 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006054 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006055 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006056 else
6057 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6058 }
6059 vty_out (vty, "%s", VTY_NEWLINE);
6060
6061#ifdef HAVE_IPV6
6062 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006063 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006064 {
6065 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006066 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006067 buf, INET6_ADDRSTRLEN),
6068 VTY_NEWLINE);
6069 }
6070#endif /* HAVE_IPV6 */
6071
6072 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6073 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6074
6075 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006076 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006077
6078 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006079 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006080 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006081 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006082
Paul Jakmafb982c22007-05-04 20:15:47 +00006083 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006084 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006085
6086 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6087 vty_out (vty, ", valid");
6088
6089 if (binfo->peer != bgp->peer_self)
6090 {
6091 if (binfo->peer->as == binfo->peer->local_as)
6092 vty_out (vty, ", internal");
6093 else
6094 vty_out (vty, ", %s",
6095 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6096 }
6097 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6098 vty_out (vty, ", aggregated, local");
6099 else if (binfo->type != ZEBRA_ROUTE_BGP)
6100 vty_out (vty, ", sourced");
6101 else
6102 vty_out (vty, ", sourced, local");
6103
6104 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6105 vty_out (vty, ", atomic-aggregate");
6106
Josh Baileyde8d5df2011-07-20 20:46:01 -07006107 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6108 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6109 bgp_info_mpath_count (binfo)))
6110 vty_out (vty, ", multipath");
6111
paul718e3742002-12-13 20:15:29 +00006112 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6113 vty_out (vty, ", best");
6114
6115 vty_out (vty, "%s", VTY_NEWLINE);
6116
6117 /* Line 4 display Community */
6118 if (attr->community)
6119 vty_out (vty, " Community: %s%s", attr->community->str,
6120 VTY_NEWLINE);
6121
6122 /* Line 5 display Extended-community */
6123 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006124 vty_out (vty, " Extended Community: %s%s",
6125 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006126
6127 /* Line 6 display Originator, Cluster-id */
6128 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6129 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6130 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006131 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006132 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006133 vty_out (vty, " Originator: %s",
6134 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006135
6136 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6137 {
6138 int i;
6139 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006140 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6141 vty_out (vty, "%s ",
6142 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006143 }
6144 vty_out (vty, "%s", VTY_NEWLINE);
6145 }
Paul Jakma41367172007-08-06 15:24:51 +00006146
Paul Jakmafb982c22007-05-04 20:15:47 +00006147 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006148 bgp_damp_info_vty (vty, binfo);
6149
6150 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006151#ifdef HAVE_CLOCK_MONOTONIC
6152 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006153 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006154#else
6155 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6156#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006157 }
6158 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006159}
6160
6161#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6162 "h history, * valid, > best, = multipath,%s"\
6163 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006164#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006165#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6166#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6167#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6168
6169enum bgp_show_type
6170{
6171 bgp_show_type_normal,
6172 bgp_show_type_regexp,
6173 bgp_show_type_prefix_list,
6174 bgp_show_type_filter_list,
6175 bgp_show_type_route_map,
6176 bgp_show_type_neighbor,
6177 bgp_show_type_cidr_only,
6178 bgp_show_type_prefix_longer,
6179 bgp_show_type_community_all,
6180 bgp_show_type_community,
6181 bgp_show_type_community_exact,
6182 bgp_show_type_community_list,
6183 bgp_show_type_community_list_exact,
6184 bgp_show_type_flap_statistics,
6185 bgp_show_type_flap_address,
6186 bgp_show_type_flap_prefix,
6187 bgp_show_type_flap_cidr_only,
6188 bgp_show_type_flap_regexp,
6189 bgp_show_type_flap_filter_list,
6190 bgp_show_type_flap_prefix_list,
6191 bgp_show_type_flap_prefix_longer,
6192 bgp_show_type_flap_route_map,
6193 bgp_show_type_flap_neighbor,
6194 bgp_show_type_dampend_paths,
6195 bgp_show_type_damp_neighbor
6196};
6197
ajs5a646652004-11-05 01:25:55 +00006198static int
paulfee0f4c2004-09-13 05:12:46 +00006199bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006200 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006201{
paul718e3742002-12-13 20:15:29 +00006202 struct bgp_info *ri;
6203 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006204 int header = 1;
paul718e3742002-12-13 20:15:29 +00006205 int display;
ajs5a646652004-11-05 01:25:55 +00006206 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006207
6208 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006209 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006210
paul718e3742002-12-13 20:15:29 +00006211 /* Start processing of routes. */
6212 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6213 if (rn->info != NULL)
6214 {
6215 display = 0;
6216
6217 for (ri = rn->info; ri; ri = ri->next)
6218 {
ajs5a646652004-11-05 01:25:55 +00006219 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006220 || type == bgp_show_type_flap_address
6221 || type == bgp_show_type_flap_prefix
6222 || type == bgp_show_type_flap_cidr_only
6223 || type == bgp_show_type_flap_regexp
6224 || type == bgp_show_type_flap_filter_list
6225 || type == bgp_show_type_flap_prefix_list
6226 || type == bgp_show_type_flap_prefix_longer
6227 || type == bgp_show_type_flap_route_map
6228 || type == bgp_show_type_flap_neighbor
6229 || type == bgp_show_type_dampend_paths
6230 || type == bgp_show_type_damp_neighbor)
6231 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006232 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006233 continue;
6234 }
6235 if (type == bgp_show_type_regexp
6236 || type == bgp_show_type_flap_regexp)
6237 {
ajs5a646652004-11-05 01:25:55 +00006238 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006239
6240 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6241 continue;
6242 }
6243 if (type == bgp_show_type_prefix_list
6244 || type == bgp_show_type_flap_prefix_list)
6245 {
ajs5a646652004-11-05 01:25:55 +00006246 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006247
6248 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6249 continue;
6250 }
6251 if (type == bgp_show_type_filter_list
6252 || type == bgp_show_type_flap_filter_list)
6253 {
ajs5a646652004-11-05 01:25:55 +00006254 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006255
6256 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6257 continue;
6258 }
6259 if (type == bgp_show_type_route_map
6260 || type == bgp_show_type_flap_route_map)
6261 {
ajs5a646652004-11-05 01:25:55 +00006262 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006263 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006264 struct attr dummy_attr;
6265 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006266 int ret;
6267
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006268 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006269 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006270
paul718e3742002-12-13 20:15:29 +00006271 binfo.peer = ri->peer;
6272 binfo.attr = &dummy_attr;
6273
6274 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006275 if (ret == RMAP_DENYMATCH)
6276 continue;
6277 }
6278 if (type == bgp_show_type_neighbor
6279 || type == bgp_show_type_flap_neighbor
6280 || type == bgp_show_type_damp_neighbor)
6281 {
ajs5a646652004-11-05 01:25:55 +00006282 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006283
6284 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6285 continue;
6286 }
6287 if (type == bgp_show_type_cidr_only
6288 || type == bgp_show_type_flap_cidr_only)
6289 {
6290 u_int32_t destination;
6291
6292 destination = ntohl (rn->p.u.prefix4.s_addr);
6293 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6294 continue;
6295 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6296 continue;
6297 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6298 continue;
6299 }
6300 if (type == bgp_show_type_prefix_longer
6301 || type == bgp_show_type_flap_prefix_longer)
6302 {
ajs5a646652004-11-05 01:25:55 +00006303 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006304
6305 if (! prefix_match (p, &rn->p))
6306 continue;
6307 }
6308 if (type == bgp_show_type_community_all)
6309 {
6310 if (! ri->attr->community)
6311 continue;
6312 }
6313 if (type == bgp_show_type_community)
6314 {
ajs5a646652004-11-05 01:25:55 +00006315 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006316
6317 if (! ri->attr->community ||
6318 ! community_match (ri->attr->community, com))
6319 continue;
6320 }
6321 if (type == bgp_show_type_community_exact)
6322 {
ajs5a646652004-11-05 01:25:55 +00006323 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006324
6325 if (! ri->attr->community ||
6326 ! community_cmp (ri->attr->community, com))
6327 continue;
6328 }
6329 if (type == bgp_show_type_community_list)
6330 {
ajs5a646652004-11-05 01:25:55 +00006331 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006332
6333 if (! community_list_match (ri->attr->community, list))
6334 continue;
6335 }
6336 if (type == bgp_show_type_community_list_exact)
6337 {
ajs5a646652004-11-05 01:25:55 +00006338 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006339
6340 if (! community_list_exact_match (ri->attr->community, list))
6341 continue;
6342 }
6343 if (type == bgp_show_type_flap_address
6344 || type == bgp_show_type_flap_prefix)
6345 {
ajs5a646652004-11-05 01:25:55 +00006346 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006347
6348 if (! prefix_match (&rn->p, p))
6349 continue;
6350
6351 if (type == bgp_show_type_flap_prefix)
6352 if (p->prefixlen != rn->p.prefixlen)
6353 continue;
6354 }
6355 if (type == bgp_show_type_dampend_paths
6356 || type == bgp_show_type_damp_neighbor)
6357 {
6358 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6359 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6360 continue;
6361 }
6362
6363 if (header)
6364 {
hasso93406d82005-02-02 14:40:33 +00006365 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6366 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6367 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006368 if (type == bgp_show_type_dampend_paths
6369 || type == bgp_show_type_damp_neighbor)
6370 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6371 else if (type == bgp_show_type_flap_statistics
6372 || type == bgp_show_type_flap_address
6373 || type == bgp_show_type_flap_prefix
6374 || type == bgp_show_type_flap_cidr_only
6375 || type == bgp_show_type_flap_regexp
6376 || type == bgp_show_type_flap_filter_list
6377 || type == bgp_show_type_flap_prefix_list
6378 || type == bgp_show_type_flap_prefix_longer
6379 || type == bgp_show_type_flap_route_map
6380 || type == bgp_show_type_flap_neighbor)
6381 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6382 else
6383 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006384 header = 0;
6385 }
6386
6387 if (type == bgp_show_type_dampend_paths
6388 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006389 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006390 else if (type == bgp_show_type_flap_statistics
6391 || type == bgp_show_type_flap_address
6392 || type == bgp_show_type_flap_prefix
6393 || type == bgp_show_type_flap_cidr_only
6394 || type == bgp_show_type_flap_regexp
6395 || type == bgp_show_type_flap_filter_list
6396 || type == bgp_show_type_flap_prefix_list
6397 || type == bgp_show_type_flap_prefix_longer
6398 || type == bgp_show_type_flap_route_map
6399 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006400 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006401 else
ajs5a646652004-11-05 01:25:55 +00006402 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006403 display++;
6404 }
6405 if (display)
ajs5a646652004-11-05 01:25:55 +00006406 output_count++;
paul718e3742002-12-13 20:15:29 +00006407 }
6408
6409 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006410 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006411 {
6412 if (type == bgp_show_type_normal)
6413 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6414 }
6415 else
6416 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006417 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006418
6419 return CMD_SUCCESS;
6420}
6421
ajs5a646652004-11-05 01:25:55 +00006422static int
paulfee0f4c2004-09-13 05:12:46 +00006423bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006424 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006425{
6426 struct bgp_table *table;
6427
6428 if (bgp == NULL) {
6429 bgp = bgp_get_default ();
6430 }
6431
6432 if (bgp == NULL)
6433 {
6434 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6435 return CMD_WARNING;
6436 }
6437
6438
6439 table = bgp->rib[afi][safi];
6440
ajs5a646652004-11-05 01:25:55 +00006441 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006442}
6443
paul718e3742002-12-13 20:15:29 +00006444/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006445static void
paul718e3742002-12-13 20:15:29 +00006446route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6447 struct bgp_node *rn,
6448 struct prefix_rd *prd, afi_t afi, safi_t safi)
6449{
6450 struct bgp_info *ri;
6451 struct prefix *p;
6452 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006453 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006454 char buf1[INET6_ADDRSTRLEN];
6455 char buf2[INET6_ADDRSTRLEN];
6456 int count = 0;
6457 int best = 0;
6458 int suppress = 0;
6459 int no_export = 0;
6460 int no_advertise = 0;
6461 int local_as = 0;
6462 int first = 0;
6463
6464 p = &rn->p;
6465 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6466 (safi == SAFI_MPLS_VPN ?
6467 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6468 safi == SAFI_MPLS_VPN ? ":" : "",
6469 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6470 p->prefixlen, VTY_NEWLINE);
6471
6472 for (ri = rn->info; ri; ri = ri->next)
6473 {
6474 count++;
6475 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6476 {
6477 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006478 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006479 suppress = 1;
6480 if (ri->attr->community != NULL)
6481 {
6482 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6483 no_advertise = 1;
6484 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6485 no_export = 1;
6486 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6487 local_as = 1;
6488 }
6489 }
6490 }
6491
6492 vty_out (vty, "Paths: (%d available", count);
6493 if (best)
6494 {
6495 vty_out (vty, ", best #%d", best);
6496 if (safi == SAFI_UNICAST)
6497 vty_out (vty, ", table Default-IP-Routing-Table");
6498 }
6499 else
6500 vty_out (vty, ", no best path");
6501 if (no_advertise)
6502 vty_out (vty, ", not advertised to any peer");
6503 else if (no_export)
6504 vty_out (vty, ", not advertised to EBGP peer");
6505 else if (local_as)
6506 vty_out (vty, ", not advertised outside local AS");
6507 if (suppress)
6508 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6509 vty_out (vty, ")%s", VTY_NEWLINE);
6510
6511 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006512 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006513 {
6514 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6515 {
6516 if (! first)
6517 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6518 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6519 first = 1;
6520 }
6521 }
6522 if (! first)
6523 vty_out (vty, " Not advertised to any peer");
6524 vty_out (vty, "%s", VTY_NEWLINE);
6525}
6526
6527/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006528static int
paulfee0f4c2004-09-13 05:12:46 +00006529bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006530 struct bgp_table *rib, const char *ip_str,
6531 afi_t afi, safi_t safi, struct prefix_rd *prd,
6532 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006533{
6534 int ret;
6535 int header;
6536 int display = 0;
6537 struct prefix match;
6538 struct bgp_node *rn;
6539 struct bgp_node *rm;
6540 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006541 struct bgp_table *table;
6542
paul718e3742002-12-13 20:15:29 +00006543 /* Check IP address argument. */
6544 ret = str2prefix (ip_str, &match);
6545 if (! ret)
6546 {
6547 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6548 return CMD_WARNING;
6549 }
6550
6551 match.family = afi2family (afi);
6552
6553 if (safi == SAFI_MPLS_VPN)
6554 {
paulfee0f4c2004-09-13 05:12:46 +00006555 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006556 {
6557 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6558 continue;
6559
6560 if ((table = rn->info) != NULL)
6561 {
6562 header = 1;
6563
6564 if ((rm = bgp_node_match (table, &match)) != NULL)
6565 {
6566 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006567 {
6568 bgp_unlock_node (rm);
6569 continue;
6570 }
paul718e3742002-12-13 20:15:29 +00006571
6572 for (ri = rm->info; ri; ri = ri->next)
6573 {
6574 if (header)
6575 {
6576 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6577 AFI_IP, SAFI_MPLS_VPN);
6578
6579 header = 0;
6580 }
6581 display++;
6582 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6583 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006584
6585 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006586 }
6587 }
6588 }
6589 }
6590 else
6591 {
6592 header = 1;
6593
paulfee0f4c2004-09-13 05:12:46 +00006594 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006595 {
6596 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6597 {
6598 for (ri = rn->info; ri; ri = ri->next)
6599 {
6600 if (header)
6601 {
6602 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6603 header = 0;
6604 }
6605 display++;
6606 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6607 }
6608 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006609
6610 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006611 }
6612 }
6613
6614 if (! display)
6615 {
6616 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6617 return CMD_WARNING;
6618 }
6619
6620 return CMD_SUCCESS;
6621}
6622
paulfee0f4c2004-09-13 05:12:46 +00006623/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006624static int
paulfd79ac92004-10-13 05:06:08 +00006625bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006626 afi_t afi, safi_t safi, struct prefix_rd *prd,
6627 int prefix_check)
6628{
6629 struct bgp *bgp;
6630
6631 /* BGP structure lookup. */
6632 if (view_name)
6633 {
6634 bgp = bgp_lookup_by_name (view_name);
6635 if (bgp == NULL)
6636 {
6637 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6638 return CMD_WARNING;
6639 }
6640 }
6641 else
6642 {
6643 bgp = bgp_get_default ();
6644 if (bgp == NULL)
6645 {
6646 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6647 return CMD_WARNING;
6648 }
6649 }
6650
6651 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6652 afi, safi, prd, prefix_check);
6653}
6654
paul718e3742002-12-13 20:15:29 +00006655/* BGP route print out function. */
6656DEFUN (show_ip_bgp,
6657 show_ip_bgp_cmd,
6658 "show ip bgp",
6659 SHOW_STR
6660 IP_STR
6661 BGP_STR)
6662{
ajs5a646652004-11-05 01:25:55 +00006663 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006664}
6665
6666DEFUN (show_ip_bgp_ipv4,
6667 show_ip_bgp_ipv4_cmd,
6668 "show ip bgp ipv4 (unicast|multicast)",
6669 SHOW_STR
6670 IP_STR
6671 BGP_STR
6672 "Address family\n"
6673 "Address Family modifier\n"
6674 "Address Family modifier\n")
6675{
6676 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006677 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6678 NULL);
paul718e3742002-12-13 20:15:29 +00006679
ajs5a646652004-11-05 01:25:55 +00006680 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006681}
6682
Michael Lambert95cbbd22010-07-23 14:43:04 -04006683ALIAS (show_ip_bgp_ipv4,
6684 show_bgp_ipv4_safi_cmd,
6685 "show bgp ipv4 (unicast|multicast)",
6686 SHOW_STR
6687 BGP_STR
6688 "Address family\n"
6689 "Address Family modifier\n"
6690 "Address Family modifier\n")
6691
paul718e3742002-12-13 20:15:29 +00006692DEFUN (show_ip_bgp_route,
6693 show_ip_bgp_route_cmd,
6694 "show ip bgp A.B.C.D",
6695 SHOW_STR
6696 IP_STR
6697 BGP_STR
6698 "Network in the BGP routing table to display\n")
6699{
6700 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6701}
6702
6703DEFUN (show_ip_bgp_ipv4_route,
6704 show_ip_bgp_ipv4_route_cmd,
6705 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6706 SHOW_STR
6707 IP_STR
6708 BGP_STR
6709 "Address family\n"
6710 "Address Family modifier\n"
6711 "Address Family modifier\n"
6712 "Network in the BGP routing table to display\n")
6713{
6714 if (strncmp (argv[0], "m", 1) == 0)
6715 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6716
6717 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6718}
6719
Michael Lambert95cbbd22010-07-23 14:43:04 -04006720ALIAS (show_ip_bgp_ipv4_route,
6721 show_bgp_ipv4_safi_route_cmd,
6722 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6723 SHOW_STR
6724 BGP_STR
6725 "Address family\n"
6726 "Address Family modifier\n"
6727 "Address Family modifier\n"
6728 "Network in the BGP routing table to display\n")
6729
paul718e3742002-12-13 20:15:29 +00006730DEFUN (show_ip_bgp_vpnv4_all_route,
6731 show_ip_bgp_vpnv4_all_route_cmd,
6732 "show ip bgp vpnv4 all A.B.C.D",
6733 SHOW_STR
6734 IP_STR
6735 BGP_STR
6736 "Display VPNv4 NLRI specific information\n"
6737 "Display information about all VPNv4 NLRIs\n"
6738 "Network in the BGP routing table to display\n")
6739{
6740 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6741}
6742
6743DEFUN (show_ip_bgp_vpnv4_rd_route,
6744 show_ip_bgp_vpnv4_rd_route_cmd,
6745 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6746 SHOW_STR
6747 IP_STR
6748 BGP_STR
6749 "Display VPNv4 NLRI specific information\n"
6750 "Display information for a route distinguisher\n"
6751 "VPN Route Distinguisher\n"
6752 "Network in the BGP routing table to display\n")
6753{
6754 int ret;
6755 struct prefix_rd prd;
6756
6757 ret = str2prefix_rd (argv[0], &prd);
6758 if (! ret)
6759 {
6760 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6761 return CMD_WARNING;
6762 }
6763 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6764}
6765
6766DEFUN (show_ip_bgp_prefix,
6767 show_ip_bgp_prefix_cmd,
6768 "show ip bgp A.B.C.D/M",
6769 SHOW_STR
6770 IP_STR
6771 BGP_STR
6772 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6773{
6774 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6775}
6776
6777DEFUN (show_ip_bgp_ipv4_prefix,
6778 show_ip_bgp_ipv4_prefix_cmd,
6779 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6780 SHOW_STR
6781 IP_STR
6782 BGP_STR
6783 "Address family\n"
6784 "Address Family modifier\n"
6785 "Address Family modifier\n"
6786 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6787{
6788 if (strncmp (argv[0], "m", 1) == 0)
6789 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6790
6791 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6792}
6793
Michael Lambert95cbbd22010-07-23 14:43:04 -04006794ALIAS (show_ip_bgp_ipv4_prefix,
6795 show_bgp_ipv4_safi_prefix_cmd,
6796 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6797 SHOW_STR
6798 BGP_STR
6799 "Address family\n"
6800 "Address Family modifier\n"
6801 "Address Family modifier\n"
6802 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6803
paul718e3742002-12-13 20:15:29 +00006804DEFUN (show_ip_bgp_vpnv4_all_prefix,
6805 show_ip_bgp_vpnv4_all_prefix_cmd,
6806 "show ip bgp vpnv4 all A.B.C.D/M",
6807 SHOW_STR
6808 IP_STR
6809 BGP_STR
6810 "Display VPNv4 NLRI specific information\n"
6811 "Display information about all VPNv4 NLRIs\n"
6812 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6813{
6814 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6815}
6816
6817DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6818 show_ip_bgp_vpnv4_rd_prefix_cmd,
6819 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6820 SHOW_STR
6821 IP_STR
6822 BGP_STR
6823 "Display VPNv4 NLRI specific information\n"
6824 "Display information for a route distinguisher\n"
6825 "VPN Route Distinguisher\n"
6826 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6827{
6828 int ret;
6829 struct prefix_rd prd;
6830
6831 ret = str2prefix_rd (argv[0], &prd);
6832 if (! ret)
6833 {
6834 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6835 return CMD_WARNING;
6836 }
6837 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6838}
6839
6840DEFUN (show_ip_bgp_view,
6841 show_ip_bgp_view_cmd,
6842 "show ip bgp view WORD",
6843 SHOW_STR
6844 IP_STR
6845 BGP_STR
6846 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006847 "View name\n")
paul718e3742002-12-13 20:15:29 +00006848{
paulbb46e942003-10-24 19:02:03 +00006849 struct bgp *bgp;
6850
6851 /* BGP structure lookup. */
6852 bgp = bgp_lookup_by_name (argv[0]);
6853 if (bgp == NULL)
6854 {
6855 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6856 return CMD_WARNING;
6857 }
6858
ajs5a646652004-11-05 01:25:55 +00006859 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006860}
6861
6862DEFUN (show_ip_bgp_view_route,
6863 show_ip_bgp_view_route_cmd,
6864 "show ip bgp view WORD A.B.C.D",
6865 SHOW_STR
6866 IP_STR
6867 BGP_STR
6868 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006869 "View name\n"
paul718e3742002-12-13 20:15:29 +00006870 "Network in the BGP routing table to display\n")
6871{
6872 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6873}
6874
6875DEFUN (show_ip_bgp_view_prefix,
6876 show_ip_bgp_view_prefix_cmd,
6877 "show ip bgp view WORD A.B.C.D/M",
6878 SHOW_STR
6879 IP_STR
6880 BGP_STR
6881 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006882 "View name\n"
paul718e3742002-12-13 20:15:29 +00006883 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6884{
6885 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6886}
6887
6888#ifdef HAVE_IPV6
6889DEFUN (show_bgp,
6890 show_bgp_cmd,
6891 "show bgp",
6892 SHOW_STR
6893 BGP_STR)
6894{
ajs5a646652004-11-05 01:25:55 +00006895 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6896 NULL);
paul718e3742002-12-13 20:15:29 +00006897}
6898
6899ALIAS (show_bgp,
6900 show_bgp_ipv6_cmd,
6901 "show bgp ipv6",
6902 SHOW_STR
6903 BGP_STR
6904 "Address family\n")
6905
Michael Lambert95cbbd22010-07-23 14:43:04 -04006906DEFUN (show_bgp_ipv6_safi,
6907 show_bgp_ipv6_safi_cmd,
6908 "show bgp ipv6 (unicast|multicast)",
6909 SHOW_STR
6910 BGP_STR
6911 "Address family\n"
6912 "Address Family modifier\n"
6913 "Address Family modifier\n")
6914{
6915 if (strncmp (argv[0], "m", 1) == 0)
6916 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6917 NULL);
6918
6919 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6920}
6921
paul718e3742002-12-13 20:15:29 +00006922/* old command */
6923DEFUN (show_ipv6_bgp,
6924 show_ipv6_bgp_cmd,
6925 "show ipv6 bgp",
6926 SHOW_STR
6927 IP_STR
6928 BGP_STR)
6929{
ajs5a646652004-11-05 01:25:55 +00006930 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6931 NULL);
paul718e3742002-12-13 20:15:29 +00006932}
6933
6934DEFUN (show_bgp_route,
6935 show_bgp_route_cmd,
6936 "show bgp X:X::X:X",
6937 SHOW_STR
6938 BGP_STR
6939 "Network in the BGP routing table to display\n")
6940{
6941 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6942}
6943
6944ALIAS (show_bgp_route,
6945 show_bgp_ipv6_route_cmd,
6946 "show bgp ipv6 X:X::X:X",
6947 SHOW_STR
6948 BGP_STR
6949 "Address family\n"
6950 "Network in the BGP routing table to display\n")
6951
Michael Lambert95cbbd22010-07-23 14:43:04 -04006952DEFUN (show_bgp_ipv6_safi_route,
6953 show_bgp_ipv6_safi_route_cmd,
6954 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6955 SHOW_STR
6956 BGP_STR
6957 "Address family\n"
6958 "Address Family modifier\n"
6959 "Address Family modifier\n"
6960 "Network in the BGP routing table to display\n")
6961{
6962 if (strncmp (argv[0], "m", 1) == 0)
6963 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6964
6965 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6966}
6967
paul718e3742002-12-13 20:15:29 +00006968/* old command */
6969DEFUN (show_ipv6_bgp_route,
6970 show_ipv6_bgp_route_cmd,
6971 "show ipv6 bgp X:X::X:X",
6972 SHOW_STR
6973 IP_STR
6974 BGP_STR
6975 "Network in the BGP routing table to display\n")
6976{
6977 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6978}
6979
6980DEFUN (show_bgp_prefix,
6981 show_bgp_prefix_cmd,
6982 "show bgp X:X::X:X/M",
6983 SHOW_STR
6984 BGP_STR
6985 "IPv6 prefix <network>/<length>\n")
6986{
6987 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6988}
6989
6990ALIAS (show_bgp_prefix,
6991 show_bgp_ipv6_prefix_cmd,
6992 "show bgp ipv6 X:X::X:X/M",
6993 SHOW_STR
6994 BGP_STR
6995 "Address family\n"
6996 "IPv6 prefix <network>/<length>\n")
6997
Michael Lambert95cbbd22010-07-23 14:43:04 -04006998DEFUN (show_bgp_ipv6_safi_prefix,
6999 show_bgp_ipv6_safi_prefix_cmd,
7000 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
7001 SHOW_STR
7002 BGP_STR
7003 "Address family\n"
7004 "Address Family modifier\n"
7005 "Address Family modifier\n"
7006 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7007{
7008 if (strncmp (argv[0], "m", 1) == 0)
7009 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7010
7011 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7012}
7013
paul718e3742002-12-13 20:15:29 +00007014/* old command */
7015DEFUN (show_ipv6_bgp_prefix,
7016 show_ipv6_bgp_prefix_cmd,
7017 "show ipv6 bgp X:X::X:X/M",
7018 SHOW_STR
7019 IP_STR
7020 BGP_STR
7021 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7022{
7023 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7024}
7025
paulbb46e942003-10-24 19:02:03 +00007026DEFUN (show_bgp_view,
7027 show_bgp_view_cmd,
7028 "show bgp view WORD",
7029 SHOW_STR
7030 BGP_STR
7031 "BGP view\n"
7032 "View name\n")
7033{
7034 struct bgp *bgp;
7035
7036 /* BGP structure lookup. */
7037 bgp = bgp_lookup_by_name (argv[0]);
7038 if (bgp == NULL)
7039 {
7040 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7041 return CMD_WARNING;
7042 }
7043
ajs5a646652004-11-05 01:25:55 +00007044 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007045}
7046
7047ALIAS (show_bgp_view,
7048 show_bgp_view_ipv6_cmd,
7049 "show bgp view WORD ipv6",
7050 SHOW_STR
7051 BGP_STR
7052 "BGP view\n"
7053 "View name\n"
7054 "Address family\n")
7055
7056DEFUN (show_bgp_view_route,
7057 show_bgp_view_route_cmd,
7058 "show bgp view WORD X:X::X:X",
7059 SHOW_STR
7060 BGP_STR
7061 "BGP view\n"
7062 "View name\n"
7063 "Network in the BGP routing table to display\n")
7064{
7065 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7066}
7067
7068ALIAS (show_bgp_view_route,
7069 show_bgp_view_ipv6_route_cmd,
7070 "show bgp view WORD ipv6 X:X::X:X",
7071 SHOW_STR
7072 BGP_STR
7073 "BGP view\n"
7074 "View name\n"
7075 "Address family\n"
7076 "Network in the BGP routing table to display\n")
7077
7078DEFUN (show_bgp_view_prefix,
7079 show_bgp_view_prefix_cmd,
7080 "show bgp view WORD X:X::X:X/M",
7081 SHOW_STR
7082 BGP_STR
7083 "BGP view\n"
7084 "View name\n"
7085 "IPv6 prefix <network>/<length>\n")
7086{
7087 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7088}
7089
7090ALIAS (show_bgp_view_prefix,
7091 show_bgp_view_ipv6_prefix_cmd,
7092 "show bgp view WORD ipv6 X:X::X:X/M",
7093 SHOW_STR
7094 BGP_STR
7095 "BGP view\n"
7096 "View name\n"
7097 "Address family\n"
7098 "IPv6 prefix <network>/<length>\n")
7099
paul718e3742002-12-13 20:15:29 +00007100/* old command */
7101DEFUN (show_ipv6_mbgp,
7102 show_ipv6_mbgp_cmd,
7103 "show ipv6 mbgp",
7104 SHOW_STR
7105 IP_STR
7106 MBGP_STR)
7107{
ajs5a646652004-11-05 01:25:55 +00007108 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7109 NULL);
paul718e3742002-12-13 20:15:29 +00007110}
7111
7112/* old command */
7113DEFUN (show_ipv6_mbgp_route,
7114 show_ipv6_mbgp_route_cmd,
7115 "show ipv6 mbgp X:X::X:X",
7116 SHOW_STR
7117 IP_STR
7118 MBGP_STR
7119 "Network in the MBGP routing table to display\n")
7120{
7121 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7122}
7123
7124/* old command */
7125DEFUN (show_ipv6_mbgp_prefix,
7126 show_ipv6_mbgp_prefix_cmd,
7127 "show ipv6 mbgp X:X::X:X/M",
7128 SHOW_STR
7129 IP_STR
7130 MBGP_STR
7131 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7132{
7133 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7134}
7135#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02007136
paul718e3742002-12-13 20:15:29 +00007137
paul94f2b392005-06-28 12:44:16 +00007138static int
paulfd79ac92004-10-13 05:06:08 +00007139bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007140 safi_t safi, enum bgp_show_type type)
7141{
7142 int i;
7143 struct buffer *b;
7144 char *regstr;
7145 int first;
7146 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007147 int rc;
paul718e3742002-12-13 20:15:29 +00007148
7149 first = 0;
7150 b = buffer_new (1024);
7151 for (i = 0; i < argc; i++)
7152 {
7153 if (first)
7154 buffer_putc (b, ' ');
7155 else
7156 {
7157 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7158 continue;
7159 first = 1;
7160 }
7161
7162 buffer_putstr (b, argv[i]);
7163 }
7164 buffer_putc (b, '\0');
7165
7166 regstr = buffer_getstr (b);
7167 buffer_free (b);
7168
7169 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007170 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007171 if (! regex)
7172 {
7173 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7174 VTY_NEWLINE);
7175 return CMD_WARNING;
7176 }
7177
ajs5a646652004-11-05 01:25:55 +00007178 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7179 bgp_regex_free (regex);
7180 return rc;
paul718e3742002-12-13 20:15:29 +00007181}
7182
7183DEFUN (show_ip_bgp_regexp,
7184 show_ip_bgp_regexp_cmd,
7185 "show ip bgp regexp .LINE",
7186 SHOW_STR
7187 IP_STR
7188 BGP_STR
7189 "Display routes matching the AS path regular expression\n"
7190 "A regular-expression to match the BGP AS paths\n")
7191{
7192 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7193 bgp_show_type_regexp);
7194}
7195
7196DEFUN (show_ip_bgp_flap_regexp,
7197 show_ip_bgp_flap_regexp_cmd,
7198 "show ip bgp flap-statistics regexp .LINE",
7199 SHOW_STR
7200 IP_STR
7201 BGP_STR
7202 "Display flap statistics of routes\n"
7203 "Display routes matching the AS path regular expression\n"
7204 "A regular-expression to match the BGP AS paths\n")
7205{
7206 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7207 bgp_show_type_flap_regexp);
7208}
7209
Balaji3921cc52015-05-16 23:12:17 +05307210ALIAS (show_ip_bgp_flap_regexp,
7211 show_ip_bgp_damp_flap_regexp_cmd,
7212 "show ip bgp dampening flap-statistics regexp .LINE",
7213 SHOW_STR
7214 IP_STR
7215 BGP_STR
7216 "Display detailed information about dampening\n"
7217 "Display flap statistics of routes\n"
7218 "Display routes matching the AS path regular expression\n"
7219 "A regular-expression to match the BGP AS paths\n")
7220
paul718e3742002-12-13 20:15:29 +00007221DEFUN (show_ip_bgp_ipv4_regexp,
7222 show_ip_bgp_ipv4_regexp_cmd,
7223 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7224 SHOW_STR
7225 IP_STR
7226 BGP_STR
7227 "Address family\n"
7228 "Address Family modifier\n"
7229 "Address Family modifier\n"
7230 "Display routes matching the AS path regular expression\n"
7231 "A regular-expression to match the BGP AS paths\n")
7232{
7233 if (strncmp (argv[0], "m", 1) == 0)
7234 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7235 bgp_show_type_regexp);
7236
7237 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7238 bgp_show_type_regexp);
7239}
7240
7241#ifdef HAVE_IPV6
7242DEFUN (show_bgp_regexp,
7243 show_bgp_regexp_cmd,
7244 "show bgp regexp .LINE",
7245 SHOW_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
7254ALIAS (show_bgp_regexp,
7255 show_bgp_ipv6_regexp_cmd,
7256 "show bgp ipv6 regexp .LINE",
7257 SHOW_STR
7258 BGP_STR
7259 "Address family\n"
7260 "Display routes matching the AS path regular expression\n"
7261 "A regular-expression to match the BGP AS paths\n")
7262
7263/* old command */
7264DEFUN (show_ipv6_bgp_regexp,
7265 show_ipv6_bgp_regexp_cmd,
7266 "show ipv6 bgp regexp .LINE",
7267 SHOW_STR
7268 IP_STR
7269 BGP_STR
7270 "Display routes matching the AS path regular expression\n"
7271 "A regular-expression to match the BGP AS paths\n")
7272{
7273 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7274 bgp_show_type_regexp);
7275}
7276
7277/* old command */
7278DEFUN (show_ipv6_mbgp_regexp,
7279 show_ipv6_mbgp_regexp_cmd,
7280 "show ipv6 mbgp regexp .LINE",
7281 SHOW_STR
7282 IP_STR
7283 BGP_STR
7284 "Display routes matching the AS path regular expression\n"
7285 "A regular-expression to match the MBGP AS paths\n")
7286{
7287 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7288 bgp_show_type_regexp);
7289}
7290#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007291
paul94f2b392005-06-28 12:44:16 +00007292static int
paulfd79ac92004-10-13 05:06:08 +00007293bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007294 safi_t safi, enum bgp_show_type type)
7295{
7296 struct prefix_list *plist;
7297
7298 plist = prefix_list_lookup (afi, prefix_list_str);
7299 if (plist == NULL)
7300 {
7301 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7302 prefix_list_str, VTY_NEWLINE);
7303 return CMD_WARNING;
7304 }
7305
ajs5a646652004-11-05 01:25:55 +00007306 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007307}
7308
7309DEFUN (show_ip_bgp_prefix_list,
7310 show_ip_bgp_prefix_list_cmd,
7311 "show ip bgp prefix-list WORD",
7312 SHOW_STR
7313 IP_STR
7314 BGP_STR
7315 "Display routes conforming to the prefix-list\n"
7316 "IP prefix-list name\n")
7317{
7318 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7319 bgp_show_type_prefix_list);
7320}
7321
7322DEFUN (show_ip_bgp_flap_prefix_list,
7323 show_ip_bgp_flap_prefix_list_cmd,
7324 "show ip bgp flap-statistics prefix-list WORD",
7325 SHOW_STR
7326 IP_STR
7327 BGP_STR
7328 "Display flap statistics of routes\n"
7329 "Display routes conforming to the prefix-list\n"
7330 "IP prefix-list name\n")
7331{
7332 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7333 bgp_show_type_flap_prefix_list);
7334}
7335
Balaji3921cc52015-05-16 23:12:17 +05307336ALIAS (show_ip_bgp_flap_prefix_list,
7337 show_ip_bgp_damp_flap_prefix_list_cmd,
7338 "show ip bgp dampening flap-statistics prefix-list WORD",
7339 SHOW_STR
7340 IP_STR
7341 BGP_STR
7342 "Display detailed information about dampening\n"
7343 "Display flap statistics of routes\n"
7344 "Display routes conforming to the prefix-list\n"
7345 "IP prefix-list name\n")
7346
paul718e3742002-12-13 20:15:29 +00007347DEFUN (show_ip_bgp_ipv4_prefix_list,
7348 show_ip_bgp_ipv4_prefix_list_cmd,
7349 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7350 SHOW_STR
7351 IP_STR
7352 BGP_STR
7353 "Address family\n"
7354 "Address Family modifier\n"
7355 "Address Family modifier\n"
7356 "Display routes conforming to the prefix-list\n"
7357 "IP prefix-list name\n")
7358{
7359 if (strncmp (argv[0], "m", 1) == 0)
7360 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7361 bgp_show_type_prefix_list);
7362
7363 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7364 bgp_show_type_prefix_list);
7365}
7366
7367#ifdef HAVE_IPV6
7368DEFUN (show_bgp_prefix_list,
7369 show_bgp_prefix_list_cmd,
7370 "show bgp prefix-list WORD",
7371 SHOW_STR
7372 BGP_STR
7373 "Display routes conforming to the prefix-list\n"
7374 "IPv6 prefix-list name\n")
7375{
7376 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7377 bgp_show_type_prefix_list);
7378}
7379
7380ALIAS (show_bgp_prefix_list,
7381 show_bgp_ipv6_prefix_list_cmd,
7382 "show bgp ipv6 prefix-list WORD",
7383 SHOW_STR
7384 BGP_STR
7385 "Address family\n"
7386 "Display routes conforming to the prefix-list\n"
7387 "IPv6 prefix-list name\n")
7388
7389/* old command */
7390DEFUN (show_ipv6_bgp_prefix_list,
7391 show_ipv6_bgp_prefix_list_cmd,
7392 "show ipv6 bgp prefix-list WORD",
7393 SHOW_STR
7394 IPV6_STR
7395 BGP_STR
7396 "Display routes matching the prefix-list\n"
7397 "IPv6 prefix-list name\n")
7398{
7399 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7400 bgp_show_type_prefix_list);
7401}
7402
7403/* old command */
7404DEFUN (show_ipv6_mbgp_prefix_list,
7405 show_ipv6_mbgp_prefix_list_cmd,
7406 "show ipv6 mbgp prefix-list WORD",
7407 SHOW_STR
7408 IPV6_STR
7409 MBGP_STR
7410 "Display routes matching the prefix-list\n"
7411 "IPv6 prefix-list name\n")
7412{
7413 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7414 bgp_show_type_prefix_list);
7415}
7416#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007417
paul94f2b392005-06-28 12:44:16 +00007418static int
paulfd79ac92004-10-13 05:06:08 +00007419bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007420 safi_t safi, enum bgp_show_type type)
7421{
7422 struct as_list *as_list;
7423
7424 as_list = as_list_lookup (filter);
7425 if (as_list == NULL)
7426 {
7427 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7428 return CMD_WARNING;
7429 }
7430
ajs5a646652004-11-05 01:25:55 +00007431 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007432}
7433
7434DEFUN (show_ip_bgp_filter_list,
7435 show_ip_bgp_filter_list_cmd,
7436 "show ip bgp filter-list WORD",
7437 SHOW_STR
7438 IP_STR
7439 BGP_STR
7440 "Display routes conforming to the filter-list\n"
7441 "Regular expression access list name\n")
7442{
7443 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7444 bgp_show_type_filter_list);
7445}
7446
7447DEFUN (show_ip_bgp_flap_filter_list,
7448 show_ip_bgp_flap_filter_list_cmd,
7449 "show ip bgp flap-statistics filter-list WORD",
7450 SHOW_STR
7451 IP_STR
7452 BGP_STR
7453 "Display flap statistics of routes\n"
7454 "Display routes conforming to the filter-list\n"
7455 "Regular expression access list name\n")
7456{
7457 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7458 bgp_show_type_flap_filter_list);
7459}
7460
Balaji3921cc52015-05-16 23:12:17 +05307461ALIAS (show_ip_bgp_flap_filter_list,
7462 show_ip_bgp_damp_flap_filter_list_cmd,
7463 "show ip bgp dampening flap-statistics filter-list WORD",
7464 SHOW_STR
7465 IP_STR
7466 BGP_STR
7467 "Display detailed information about dampening\n"
7468 "Display flap statistics of routes\n"
7469 "Display routes conforming to the filter-list\n"
7470 "Regular expression access list name\n")
7471
paul718e3742002-12-13 20:15:29 +00007472DEFUN (show_ip_bgp_ipv4_filter_list,
7473 show_ip_bgp_ipv4_filter_list_cmd,
7474 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7475 SHOW_STR
7476 IP_STR
7477 BGP_STR
7478 "Address family\n"
7479 "Address Family modifier\n"
7480 "Address Family modifier\n"
7481 "Display routes conforming to the filter-list\n"
7482 "Regular expression access list name\n")
7483{
7484 if (strncmp (argv[0], "m", 1) == 0)
7485 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7486 bgp_show_type_filter_list);
7487
7488 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7489 bgp_show_type_filter_list);
7490}
7491
7492#ifdef HAVE_IPV6
7493DEFUN (show_bgp_filter_list,
7494 show_bgp_filter_list_cmd,
7495 "show bgp filter-list WORD",
7496 SHOW_STR
7497 BGP_STR
7498 "Display routes conforming to the filter-list\n"
7499 "Regular expression access list name\n")
7500{
7501 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7502 bgp_show_type_filter_list);
7503}
7504
7505ALIAS (show_bgp_filter_list,
7506 show_bgp_ipv6_filter_list_cmd,
7507 "show bgp ipv6 filter-list WORD",
7508 SHOW_STR
7509 BGP_STR
7510 "Address family\n"
7511 "Display routes conforming to the filter-list\n"
7512 "Regular expression access list name\n")
7513
7514/* old command */
7515DEFUN (show_ipv6_bgp_filter_list,
7516 show_ipv6_bgp_filter_list_cmd,
7517 "show ipv6 bgp filter-list WORD",
7518 SHOW_STR
7519 IPV6_STR
7520 BGP_STR
7521 "Display routes conforming to the filter-list\n"
7522 "Regular expression access list name\n")
7523{
7524 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7525 bgp_show_type_filter_list);
7526}
7527
7528/* old command */
7529DEFUN (show_ipv6_mbgp_filter_list,
7530 show_ipv6_mbgp_filter_list_cmd,
7531 "show ipv6 mbgp filter-list WORD",
7532 SHOW_STR
7533 IPV6_STR
7534 MBGP_STR
7535 "Display routes conforming to the filter-list\n"
7536 "Regular expression access list name\n")
7537{
7538 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7539 bgp_show_type_filter_list);
7540}
7541#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007542
Balaji3921cc52015-05-16 23:12:17 +05307543DEFUN (show_ip_bgp_dampening_info,
7544 show_ip_bgp_dampening_params_cmd,
7545 "show ip bgp dampening parameters",
7546 SHOW_STR
7547 IP_STR
7548 BGP_STR
7549 "Display detailed information about dampening\n"
7550 "Display detail of configured dampening parameters\n")
7551{
7552 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
7553}
7554
paul94f2b392005-06-28 12:44:16 +00007555static int
paulfd79ac92004-10-13 05:06:08 +00007556bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007557 safi_t safi, enum bgp_show_type type)
7558{
7559 struct route_map *rmap;
7560
7561 rmap = route_map_lookup_by_name (rmap_str);
7562 if (! rmap)
7563 {
7564 vty_out (vty, "%% %s is not a valid route-map name%s",
7565 rmap_str, VTY_NEWLINE);
7566 return CMD_WARNING;
7567 }
7568
ajs5a646652004-11-05 01:25:55 +00007569 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007570}
7571
7572DEFUN (show_ip_bgp_route_map,
7573 show_ip_bgp_route_map_cmd,
7574 "show ip bgp route-map WORD",
7575 SHOW_STR
7576 IP_STR
7577 BGP_STR
7578 "Display routes matching the route-map\n"
7579 "A route-map to match on\n")
7580{
7581 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7582 bgp_show_type_route_map);
7583}
7584
7585DEFUN (show_ip_bgp_flap_route_map,
7586 show_ip_bgp_flap_route_map_cmd,
7587 "show ip bgp flap-statistics route-map WORD",
7588 SHOW_STR
7589 IP_STR
7590 BGP_STR
7591 "Display flap statistics of routes\n"
7592 "Display routes matching the route-map\n"
7593 "A route-map to match on\n")
7594{
7595 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7596 bgp_show_type_flap_route_map);
7597}
7598
Balaji3921cc52015-05-16 23:12:17 +05307599ALIAS (show_ip_bgp_flap_route_map,
7600 show_ip_bgp_damp_flap_route_map_cmd,
7601 "show ip bgp dampening flap-statistics route-map WORD",
7602 SHOW_STR
7603 IP_STR
7604 BGP_STR
7605 "Display detailed information about dampening\n"
7606 "Display flap statistics of routes\n"
7607 "Display routes matching the route-map\n"
7608 "A route-map to match on\n")
7609
paul718e3742002-12-13 20:15:29 +00007610DEFUN (show_ip_bgp_ipv4_route_map,
7611 show_ip_bgp_ipv4_route_map_cmd,
7612 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7613 SHOW_STR
7614 IP_STR
7615 BGP_STR
7616 "Address family\n"
7617 "Address Family modifier\n"
7618 "Address Family modifier\n"
7619 "Display routes matching the route-map\n"
7620 "A route-map to match on\n")
7621{
7622 if (strncmp (argv[0], "m", 1) == 0)
7623 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7624 bgp_show_type_route_map);
7625
7626 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7627 bgp_show_type_route_map);
7628}
7629
7630DEFUN (show_bgp_route_map,
7631 show_bgp_route_map_cmd,
7632 "show bgp route-map WORD",
7633 SHOW_STR
7634 BGP_STR
7635 "Display routes matching the route-map\n"
7636 "A route-map to match on\n")
7637{
7638 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7639 bgp_show_type_route_map);
7640}
7641
7642ALIAS (show_bgp_route_map,
7643 show_bgp_ipv6_route_map_cmd,
7644 "show bgp ipv6 route-map WORD",
7645 SHOW_STR
7646 BGP_STR
7647 "Address family\n"
7648 "Display routes matching the route-map\n"
7649 "A route-map to match on\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02007650
paul718e3742002-12-13 20:15:29 +00007651DEFUN (show_ip_bgp_cidr_only,
7652 show_ip_bgp_cidr_only_cmd,
7653 "show ip bgp cidr-only",
7654 SHOW_STR
7655 IP_STR
7656 BGP_STR
7657 "Display only routes with non-natural netmasks\n")
7658{
7659 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007660 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007661}
7662
7663DEFUN (show_ip_bgp_flap_cidr_only,
7664 show_ip_bgp_flap_cidr_only_cmd,
7665 "show ip bgp flap-statistics cidr-only",
7666 SHOW_STR
7667 IP_STR
7668 BGP_STR
7669 "Display flap statistics of routes\n"
7670 "Display only routes with non-natural netmasks\n")
7671{
7672 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007673 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007674}
7675
Balaji3921cc52015-05-16 23:12:17 +05307676ALIAS (show_ip_bgp_flap_cidr_only,
7677 show_ip_bgp_damp_flap_cidr_only_cmd,
7678 "show ip bgp dampening flap-statistics cidr-only",
7679 SHOW_STR
7680 IP_STR
7681 BGP_STR
7682 "Display detailed information about dampening\n"
7683 "Display flap statistics of routes\n"
7684 "Display only routes with non-natural netmasks\n")
7685
paul718e3742002-12-13 20:15:29 +00007686DEFUN (show_ip_bgp_ipv4_cidr_only,
7687 show_ip_bgp_ipv4_cidr_only_cmd,
7688 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7689 SHOW_STR
7690 IP_STR
7691 BGP_STR
7692 "Address family\n"
7693 "Address Family modifier\n"
7694 "Address Family modifier\n"
7695 "Display only routes with non-natural netmasks\n")
7696{
7697 if (strncmp (argv[0], "m", 1) == 0)
7698 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007699 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007700
7701 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007702 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007703}
David Lamparter6b0655a2014-06-04 06:53:35 +02007704
paul718e3742002-12-13 20:15:29 +00007705DEFUN (show_ip_bgp_community_all,
7706 show_ip_bgp_community_all_cmd,
7707 "show ip bgp community",
7708 SHOW_STR
7709 IP_STR
7710 BGP_STR
7711 "Display routes matching the communities\n")
7712{
7713 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007714 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007715}
7716
7717DEFUN (show_ip_bgp_ipv4_community_all,
7718 show_ip_bgp_ipv4_community_all_cmd,
7719 "show ip bgp ipv4 (unicast|multicast) community",
7720 SHOW_STR
7721 IP_STR
7722 BGP_STR
7723 "Address family\n"
7724 "Address Family modifier\n"
7725 "Address Family modifier\n"
7726 "Display routes matching the communities\n")
7727{
7728 if (strncmp (argv[0], "m", 1) == 0)
7729 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007730 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007731
7732 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007733 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007734}
7735
7736#ifdef HAVE_IPV6
7737DEFUN (show_bgp_community_all,
7738 show_bgp_community_all_cmd,
7739 "show bgp community",
7740 SHOW_STR
7741 BGP_STR
7742 "Display routes matching the communities\n")
7743{
7744 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007745 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007746}
7747
7748ALIAS (show_bgp_community_all,
7749 show_bgp_ipv6_community_all_cmd,
7750 "show bgp ipv6 community",
7751 SHOW_STR
7752 BGP_STR
7753 "Address family\n"
7754 "Display routes matching the communities\n")
7755
7756/* old command */
7757DEFUN (show_ipv6_bgp_community_all,
7758 show_ipv6_bgp_community_all_cmd,
7759 "show ipv6 bgp community",
7760 SHOW_STR
7761 IPV6_STR
7762 BGP_STR
7763 "Display routes matching the communities\n")
7764{
7765 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007766 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007767}
7768
7769/* old command */
7770DEFUN (show_ipv6_mbgp_community_all,
7771 show_ipv6_mbgp_community_all_cmd,
7772 "show ipv6 mbgp community",
7773 SHOW_STR
7774 IPV6_STR
7775 MBGP_STR
7776 "Display routes matching the communities\n")
7777{
7778 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007779 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007780}
7781#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007782
paul94f2b392005-06-28 12:44:16 +00007783static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007784bgp_show_community (struct vty *vty, const char *view_name, int argc,
7785 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007786{
7787 struct community *com;
7788 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007789 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007790 int i;
7791 char *str;
7792 int first = 0;
7793
Michael Lambert95cbbd22010-07-23 14:43:04 -04007794 /* BGP structure lookup */
7795 if (view_name)
7796 {
7797 bgp = bgp_lookup_by_name (view_name);
7798 if (bgp == NULL)
7799 {
7800 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7801 return CMD_WARNING;
7802 }
7803 }
7804 else
7805 {
7806 bgp = bgp_get_default ();
7807 if (bgp == NULL)
7808 {
7809 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7810 return CMD_WARNING;
7811 }
7812 }
7813
paul718e3742002-12-13 20:15:29 +00007814 b = buffer_new (1024);
7815 for (i = 0; i < argc; i++)
7816 {
7817 if (first)
7818 buffer_putc (b, ' ');
7819 else
7820 {
7821 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7822 continue;
7823 first = 1;
7824 }
7825
7826 buffer_putstr (b, argv[i]);
7827 }
7828 buffer_putc (b, '\0');
7829
7830 str = buffer_getstr (b);
7831 buffer_free (b);
7832
7833 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007834 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007835 if (! com)
7836 {
7837 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7838 return CMD_WARNING;
7839 }
7840
Michael Lambert95cbbd22010-07-23 14:43:04 -04007841 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007842 (exact ? bgp_show_type_community_exact :
7843 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007844}
7845
7846DEFUN (show_ip_bgp_community,
7847 show_ip_bgp_community_cmd,
7848 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7849 SHOW_STR
7850 IP_STR
7851 BGP_STR
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{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007858 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007859}
7860
7861ALIAS (show_ip_bgp_community,
7862 show_ip_bgp_community2_cmd,
7863 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7864 SHOW_STR
7865 IP_STR
7866 BGP_STR
7867 "Display routes matching the communities\n"
7868 "community number\n"
7869 "Do not send outside local AS (well-known community)\n"
7870 "Do not advertise to any peer (well-known community)\n"
7871 "Do not export to next AS (well-known community)\n"
7872 "community number\n"
7873 "Do not send outside local AS (well-known community)\n"
7874 "Do not advertise to any peer (well-known community)\n"
7875 "Do not export to next AS (well-known community)\n")
7876
7877ALIAS (show_ip_bgp_community,
7878 show_ip_bgp_community3_cmd,
7879 "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)",
7880 SHOW_STR
7881 IP_STR
7882 BGP_STR
7883 "Display routes matching the communities\n"
7884 "community number\n"
7885 "Do not send outside local AS (well-known community)\n"
7886 "Do not advertise to any peer (well-known community)\n"
7887 "Do not export to next AS (well-known community)\n"
7888 "community number\n"
7889 "Do not send outside local AS (well-known community)\n"
7890 "Do not advertise to any peer (well-known community)\n"
7891 "Do not export to next AS (well-known community)\n"
7892 "community number\n"
7893 "Do not send outside local AS (well-known community)\n"
7894 "Do not advertise to any peer (well-known community)\n"
7895 "Do not export to next AS (well-known community)\n")
7896
7897ALIAS (show_ip_bgp_community,
7898 show_ip_bgp_community4_cmd,
7899 "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)",
7900 SHOW_STR
7901 IP_STR
7902 BGP_STR
7903 "Display routes matching the communities\n"
7904 "community number\n"
7905 "Do not send outside local AS (well-known community)\n"
7906 "Do not advertise to any peer (well-known community)\n"
7907 "Do not export to next AS (well-known community)\n"
7908 "community number\n"
7909 "Do not send outside local AS (well-known community)\n"
7910 "Do not advertise to any peer (well-known community)\n"
7911 "Do not export to next AS (well-known community)\n"
7912 "community number\n"
7913 "Do not send outside local AS (well-known community)\n"
7914 "Do not advertise to any peer (well-known community)\n"
7915 "Do not export to next AS (well-known community)\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
7921DEFUN (show_ip_bgp_ipv4_community,
7922 show_ip_bgp_ipv4_community_cmd,
7923 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7924 SHOW_STR
7925 IP_STR
7926 BGP_STR
7927 "Address family\n"
7928 "Address Family modifier\n"
7929 "Address Family modifier\n"
7930 "Display routes matching the communities\n"
7931 "community number\n"
7932 "Do not send outside local AS (well-known community)\n"
7933 "Do not advertise to any peer (well-known community)\n"
7934 "Do not export to next AS (well-known community)\n")
7935{
7936 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007937 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007938
Michael Lambert95cbbd22010-07-23 14:43:04 -04007939 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007940}
7941
7942ALIAS (show_ip_bgp_ipv4_community,
7943 show_ip_bgp_ipv4_community2_cmd,
7944 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7945 SHOW_STR
7946 IP_STR
7947 BGP_STR
7948 "Address family\n"
7949 "Address Family modifier\n"
7950 "Address Family modifier\n"
7951 "Display routes matching the communities\n"
7952 "community number\n"
7953 "Do not send outside local AS (well-known community)\n"
7954 "Do not advertise to any peer (well-known community)\n"
7955 "Do not export to next AS (well-known community)\n"
7956 "community number\n"
7957 "Do not send outside local AS (well-known community)\n"
7958 "Do not advertise to any peer (well-known community)\n"
7959 "Do not export to next AS (well-known community)\n")
7960
7961ALIAS (show_ip_bgp_ipv4_community,
7962 show_ip_bgp_ipv4_community3_cmd,
7963 "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)",
7964 SHOW_STR
7965 IP_STR
7966 BGP_STR
7967 "Address family\n"
7968 "Address Family modifier\n"
7969 "Address Family modifier\n"
7970 "Display routes matching the communities\n"
7971 "community number\n"
7972 "Do not send outside local AS (well-known community)\n"
7973 "Do not advertise to any peer (well-known community)\n"
7974 "Do not export to next AS (well-known community)\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 "community number\n"
7980 "Do not send outside local AS (well-known community)\n"
7981 "Do not advertise to any peer (well-known community)\n"
7982 "Do not export to next AS (well-known community)\n")
7983
7984ALIAS (show_ip_bgp_ipv4_community,
7985 show_ip_bgp_ipv4_community4_cmd,
7986 "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)",
7987 SHOW_STR
7988 IP_STR
7989 BGP_STR
7990 "Address family\n"
7991 "Address Family modifier\n"
7992 "Address Family modifier\n"
7993 "Display routes matching the communities\n"
7994 "community number\n"
7995 "Do not send outside local AS (well-known community)\n"
7996 "Do not advertise to any peer (well-known community)\n"
7997 "Do not export to next AS (well-known community)\n"
7998 "community number\n"
7999 "Do not send outside local AS (well-known community)\n"
8000 "Do not advertise to any peer (well-known community)\n"
8001 "Do not export to next AS (well-known community)\n"
8002 "community number\n"
8003 "Do not send outside local AS (well-known community)\n"
8004 "Do not advertise to any peer (well-known community)\n"
8005 "Do not export to next AS (well-known community)\n"
8006 "community number\n"
8007 "Do not send outside local AS (well-known community)\n"
8008 "Do not advertise to any peer (well-known community)\n"
8009 "Do not export to next AS (well-known community)\n")
8010
Michael Lambert95cbbd22010-07-23 14:43:04 -04008011DEFUN (show_bgp_view_afi_safi_community_all,
8012 show_bgp_view_afi_safi_community_all_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008013 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008014 SHOW_STR
8015 BGP_STR
8016 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008017 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008018 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008019 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008020 "Address Family modifier\n"
8021 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00008022 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04008023{
8024 int afi;
8025 int safi;
8026 struct bgp *bgp;
8027
8028 /* BGP structure lookup. */
8029 bgp = bgp_lookup_by_name (argv[0]);
8030 if (bgp == NULL)
8031 {
8032 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8033 return CMD_WARNING;
8034 }
8035
Michael Lambert95cbbd22010-07-23 14:43:04 -04008036 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8037 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Michael Lambert95cbbd22010-07-23 14:43:04 -04008038 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
8039}
8040
8041DEFUN (show_bgp_view_afi_safi_community,
8042 show_bgp_view_afi_safi_community_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008043 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008044 SHOW_STR
8045 BGP_STR
8046 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008047 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008048 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008049 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008050 "Address family modifier\n"
8051 "Address family modifier\n"
8052 "Display routes matching the communities\n"
8053 "community number\n"
8054 "Do not send outside local AS (well-known community)\n"
8055 "Do not advertise to any peer (well-known community)\n"
8056 "Do not export to next AS (well-known community)\n")
8057{
8058 int afi;
8059 int safi;
8060
Michael Lambert95cbbd22010-07-23 14:43:04 -04008061 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8062 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8063 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Michael Lambert95cbbd22010-07-23 14:43:04 -04008064}
8065
8066ALIAS (show_bgp_view_afi_safi_community,
8067 show_bgp_view_afi_safi_community2_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008068 "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 -04008069 SHOW_STR
8070 BGP_STR
8071 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008072 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008073 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008074 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008075 "Address family modifier\n"
8076 "Address family modifier\n"
8077 "Display routes matching the communities\n"
8078 "community number\n"
8079 "Do not send outside local AS (well-known community)\n"
8080 "Do not advertise to any peer (well-known community)\n"
8081 "Do not export to next AS (well-known community)\n"
8082 "community number\n"
8083 "Do not send outside local AS (well-known community)\n"
8084 "Do not advertise to any peer (well-known community)\n"
8085 "Do not export to next AS (well-known community)\n")
8086
8087ALIAS (show_bgp_view_afi_safi_community,
8088 show_bgp_view_afi_safi_community3_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008089 "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 -04008090 SHOW_STR
8091 BGP_STR
8092 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008093 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008094 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008095 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008096 "Address family modifier\n"
8097 "Address family modifier\n"
8098 "Display routes matching the communities\n"
8099 "community number\n"
8100 "Do not send outside local AS (well-known community)\n"
8101 "Do not advertise to any peer (well-known community)\n"
8102 "Do not export to next AS (well-known community)\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
8112ALIAS (show_bgp_view_afi_safi_community,
8113 show_bgp_view_afi_safi_community4_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008114 "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 -04008115 SHOW_STR
8116 BGP_STR
8117 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008118 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008119 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008120 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008121 "Address family modifier\n"
8122 "Address family modifier\n"
8123 "Display routes matching the communities\n"
8124 "community number\n"
8125 "Do not send outside local AS (well-known community)\n"
8126 "Do not advertise to any peer (well-known community)\n"
8127 "Do not export to next AS (well-known community)\n"
8128 "community number\n"
8129 "Do not send outside local AS (well-known community)\n"
8130 "Do not advertise to any peer (well-known community)\n"
8131 "Do not export to next AS (well-known community)\n"
8132 "community number\n"
8133 "Do not send outside local AS (well-known community)\n"
8134 "Do not advertise to any peer (well-known community)\n"
8135 "Do not export to next AS (well-known community)\n"
8136 "community number\n"
8137 "Do not send outside local AS (well-known community)\n"
8138 "Do not advertise to any peer (well-known community)\n"
8139 "Do not export to next AS (well-known community)\n")
8140
paul718e3742002-12-13 20:15:29 +00008141DEFUN (show_ip_bgp_community_exact,
8142 show_ip_bgp_community_exact_cmd,
8143 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8144 SHOW_STR
8145 IP_STR
8146 BGP_STR
8147 "Display routes matching the communities\n"
8148 "community number\n"
8149 "Do not send outside local AS (well-known community)\n"
8150 "Do not advertise to any peer (well-known community)\n"
8151 "Do not export to next AS (well-known community)\n"
8152 "Exact match of the communities")
8153{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008154 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008155}
8156
8157ALIAS (show_ip_bgp_community_exact,
8158 show_ip_bgp_community2_exact_cmd,
8159 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8160 SHOW_STR
8161 IP_STR
8162 BGP_STR
8163 "Display routes matching the communities\n"
8164 "community number\n"
8165 "Do not send outside local AS (well-known community)\n"
8166 "Do not advertise to any peer (well-known community)\n"
8167 "Do not export to next AS (well-known community)\n"
8168 "community number\n"
8169 "Do not send outside local AS (well-known community)\n"
8170 "Do not advertise to any peer (well-known community)\n"
8171 "Do not export to next AS (well-known community)\n"
8172 "Exact match of the communities")
8173
8174ALIAS (show_ip_bgp_community_exact,
8175 show_ip_bgp_community3_exact_cmd,
8176 "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",
8177 SHOW_STR
8178 IP_STR
8179 BGP_STR
8180 "Display routes matching the communities\n"
8181 "community number\n"
8182 "Do not send outside local AS (well-known community)\n"
8183 "Do not advertise to any peer (well-known community)\n"
8184 "Do not export to next AS (well-known community)\n"
8185 "community number\n"
8186 "Do not send outside local AS (well-known community)\n"
8187 "Do not advertise to any peer (well-known community)\n"
8188 "Do not export to next AS (well-known community)\n"
8189 "community number\n"
8190 "Do not send outside local AS (well-known community)\n"
8191 "Do not advertise to any peer (well-known community)\n"
8192 "Do not export to next AS (well-known community)\n"
8193 "Exact match of the communities")
8194
8195ALIAS (show_ip_bgp_community_exact,
8196 show_ip_bgp_community4_exact_cmd,
8197 "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",
8198 SHOW_STR
8199 IP_STR
8200 BGP_STR
8201 "Display routes matching the communities\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 "community number\n"
8207 "Do not send outside local AS (well-known community)\n"
8208 "Do not advertise to any peer (well-known community)\n"
8209 "Do not export to next AS (well-known community)\n"
8210 "community number\n"
8211 "Do not send outside local AS (well-known community)\n"
8212 "Do not advertise to any peer (well-known community)\n"
8213 "Do not export to next AS (well-known community)\n"
8214 "community number\n"
8215 "Do not send outside local AS (well-known community)\n"
8216 "Do not advertise to any peer (well-known community)\n"
8217 "Do not export to next AS (well-known community)\n"
8218 "Exact match of the communities")
8219
8220DEFUN (show_ip_bgp_ipv4_community_exact,
8221 show_ip_bgp_ipv4_community_exact_cmd,
8222 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8223 SHOW_STR
8224 IP_STR
8225 BGP_STR
8226 "Address family\n"
8227 "Address Family modifier\n"
8228 "Address Family modifier\n"
8229 "Display routes matching the communities\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 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008237 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008238
Michael Lambert95cbbd22010-07-23 14:43:04 -04008239 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008240}
8241
8242ALIAS (show_ip_bgp_ipv4_community_exact,
8243 show_ip_bgp_ipv4_community2_exact_cmd,
8244 "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",
8245 SHOW_STR
8246 IP_STR
8247 BGP_STR
8248 "Address family\n"
8249 "Address Family modifier\n"
8250 "Address Family modifier\n"
8251 "Display routes matching the communities\n"
8252 "community number\n"
8253 "Do not send outside local AS (well-known community)\n"
8254 "Do not advertise to any peer (well-known community)\n"
8255 "Do not export to next AS (well-known community)\n"
8256 "community number\n"
8257 "Do not send outside local AS (well-known community)\n"
8258 "Do not advertise to any peer (well-known community)\n"
8259 "Do not export to next AS (well-known community)\n"
8260 "Exact match of the communities")
8261
8262ALIAS (show_ip_bgp_ipv4_community_exact,
8263 show_ip_bgp_ipv4_community3_exact_cmd,
8264 "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",
8265 SHOW_STR
8266 IP_STR
8267 BGP_STR
8268 "Address family\n"
8269 "Address Family modifier\n"
8270 "Address Family modifier\n"
8271 "Display routes matching the communities\n"
8272 "community number\n"
8273 "Do not send outside local AS (well-known community)\n"
8274 "Do not advertise to any peer (well-known community)\n"
8275 "Do not export to next AS (well-known community)\n"
8276 "community number\n"
8277 "Do not send outside local AS (well-known community)\n"
8278 "Do not advertise to any peer (well-known community)\n"
8279 "Do not export to next AS (well-known community)\n"
8280 "community number\n"
8281 "Do not send outside local AS (well-known community)\n"
8282 "Do not advertise to any peer (well-known community)\n"
8283 "Do not export to next AS (well-known community)\n"
8284 "Exact match of the communities")
8285
8286ALIAS (show_ip_bgp_ipv4_community_exact,
8287 show_ip_bgp_ipv4_community4_exact_cmd,
8288 "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",
8289 SHOW_STR
8290 IP_STR
8291 BGP_STR
8292 "Address family\n"
8293 "Address Family modifier\n"
8294 "Address Family modifier\n"
8295 "Display routes matching the communities\n"
8296 "community number\n"
8297 "Do not send outside local AS (well-known community)\n"
8298 "Do not advertise to any peer (well-known community)\n"
8299 "Do not export to next AS (well-known community)\n"
8300 "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 "Exact match of the communities")
8313
8314#ifdef HAVE_IPV6
8315DEFUN (show_bgp_community,
8316 show_bgp_community_cmd,
8317 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8318 SHOW_STR
8319 BGP_STR
8320 "Display routes matching the communities\n"
8321 "community number\n"
8322 "Do not send outside local AS (well-known community)\n"
8323 "Do not advertise to any peer (well-known community)\n"
8324 "Do not export to next AS (well-known community)\n")
8325{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008326 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008327}
8328
8329ALIAS (show_bgp_community,
8330 show_bgp_ipv6_community_cmd,
8331 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8332 SHOW_STR
8333 BGP_STR
8334 "Address family\n"
8335 "Display routes matching the communities\n"
8336 "community number\n"
8337 "Do not send outside local AS (well-known community)\n"
8338 "Do not advertise to any peer (well-known community)\n"
8339 "Do not export to next AS (well-known community)\n")
8340
8341ALIAS (show_bgp_community,
8342 show_bgp_community2_cmd,
8343 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8344 SHOW_STR
8345 BGP_STR
8346 "Display routes matching the communities\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_community2_cmd,
8358 "show bgp ipv6 community (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
8372ALIAS (show_bgp_community,
8373 show_bgp_community3_cmd,
8374 "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)",
8375 SHOW_STR
8376 BGP_STR
8377 "Display routes matching the communities\n"
8378 "community number\n"
8379 "Do not send outside local AS (well-known community)\n"
8380 "Do not advertise to any peer (well-known community)\n"
8381 "Do not export to next AS (well-known community)\n"
8382 "community number\n"
8383 "Do not send outside local AS (well-known community)\n"
8384 "Do not advertise to any peer (well-known community)\n"
8385 "Do not export to next AS (well-known community)\n"
8386 "community number\n"
8387 "Do not send outside local AS (well-known community)\n"
8388 "Do not advertise to any peer (well-known community)\n"
8389 "Do not export to next AS (well-known community)\n")
8390
8391ALIAS (show_bgp_community,
8392 show_bgp_ipv6_community3_cmd,
8393 "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)",
8394 SHOW_STR
8395 BGP_STR
8396 "Address family\n"
8397 "Display routes matching the communities\n"
8398 "community number\n"
8399 "Do not send outside local AS (well-known community)\n"
8400 "Do not advertise to any peer (well-known community)\n"
8401 "Do not export to next AS (well-known community)\n"
8402 "community number\n"
8403 "Do not send outside local AS (well-known community)\n"
8404 "Do not advertise to any peer (well-known community)\n"
8405 "Do not export to next AS (well-known community)\n"
8406 "community number\n"
8407 "Do not send outside local AS (well-known community)\n"
8408 "Do not advertise to any peer (well-known community)\n"
8409 "Do not export to next AS (well-known community)\n")
8410
8411ALIAS (show_bgp_community,
8412 show_bgp_community4_cmd,
8413 "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)",
8414 SHOW_STR
8415 BGP_STR
8416 "Display routes matching the communities\n"
8417 "community number\n"
8418 "Do not send outside local AS (well-known community)\n"
8419 "Do not advertise to any peer (well-known community)\n"
8420 "Do not export to next AS (well-known community)\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
8434ALIAS (show_bgp_community,
8435 show_bgp_ipv6_community4_cmd,
8436 "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)",
8437 SHOW_STR
8438 BGP_STR
8439 "Address family\n"
8440 "Display routes matching the communities\n"
8441 "community number\n"
8442 "Do not send outside local AS (well-known community)\n"
8443 "Do not advertise to any peer (well-known community)\n"
8444 "Do not export to next AS (well-known community)\n"
8445 "community number\n"
8446 "Do not send outside local AS (well-known community)\n"
8447 "Do not advertise to any peer (well-known community)\n"
8448 "Do not export to next AS (well-known community)\n"
8449 "community number\n"
8450 "Do not send outside local AS (well-known community)\n"
8451 "Do not advertise to any peer (well-known community)\n"
8452 "Do not export to next AS (well-known community)\n"
8453 "community number\n"
8454 "Do not send outside local AS (well-known community)\n"
8455 "Do not advertise to any peer (well-known community)\n"
8456 "Do not export to next AS (well-known community)\n")
8457
8458/* old command */
8459DEFUN (show_ipv6_bgp_community,
8460 show_ipv6_bgp_community_cmd,
8461 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8462 SHOW_STR
8463 IPV6_STR
8464 BGP_STR
8465 "Display routes matching the communities\n"
8466 "community number\n"
8467 "Do not send outside local AS (well-known community)\n"
8468 "Do not advertise to any peer (well-known community)\n"
8469 "Do not export to next AS (well-known community)\n")
8470{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008471 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008472}
8473
8474/* old command */
8475ALIAS (show_ipv6_bgp_community,
8476 show_ipv6_bgp_community2_cmd,
8477 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8478 SHOW_STR
8479 IPV6_STR
8480 BGP_STR
8481 "Display routes matching the communities\n"
8482 "community number\n"
8483 "Do not send outside local AS (well-known community)\n"
8484 "Do not advertise to any peer (well-known community)\n"
8485 "Do not export to next AS (well-known community)\n"
8486 "community number\n"
8487 "Do not send outside local AS (well-known community)\n"
8488 "Do not advertise to any peer (well-known community)\n"
8489 "Do not export to next AS (well-known community)\n")
8490
8491/* old command */
8492ALIAS (show_ipv6_bgp_community,
8493 show_ipv6_bgp_community3_cmd,
8494 "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)",
8495 SHOW_STR
8496 IPV6_STR
8497 BGP_STR
8498 "Display routes matching the communities\n"
8499 "community number\n"
8500 "Do not send outside local AS (well-known community)\n"
8501 "Do not advertise to any peer (well-known community)\n"
8502 "Do not export to next AS (well-known community)\n"
8503 "community number\n"
8504 "Do not send outside local AS (well-known community)\n"
8505 "Do not advertise to any peer (well-known community)\n"
8506 "Do not export to next AS (well-known community)\n"
8507 "community number\n"
8508 "Do not send outside local AS (well-known community)\n"
8509 "Do not advertise to any peer (well-known community)\n"
8510 "Do not export to next AS (well-known community)\n")
8511
8512/* old command */
8513ALIAS (show_ipv6_bgp_community,
8514 show_ipv6_bgp_community4_cmd,
8515 "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)",
8516 SHOW_STR
8517 IPV6_STR
8518 BGP_STR
8519 "Display routes matching the communities\n"
8520 "community number\n"
8521 "Do not send outside local AS (well-known community)\n"
8522 "Do not advertise to any peer (well-known community)\n"
8523 "Do not export to next AS (well-known community)\n"
8524 "community number\n"
8525 "Do not send outside local AS (well-known community)\n"
8526 "Do not advertise to any peer (well-known community)\n"
8527 "Do not export to next AS (well-known community)\n"
8528 "community number\n"
8529 "Do not send outside local AS (well-known community)\n"
8530 "Do not advertise to any peer (well-known community)\n"
8531 "Do not export to next AS (well-known community)\n"
8532 "community number\n"
8533 "Do not send outside local AS (well-known community)\n"
8534 "Do not advertise to any peer (well-known community)\n"
8535 "Do not export to next AS (well-known community)\n")
8536
8537DEFUN (show_bgp_community_exact,
8538 show_bgp_community_exact_cmd,
8539 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8540 SHOW_STR
8541 BGP_STR
8542 "Display routes matching the communities\n"
8543 "community number\n"
8544 "Do not send outside local AS (well-known community)\n"
8545 "Do not advertise to any peer (well-known community)\n"
8546 "Do not export to next AS (well-known community)\n"
8547 "Exact match of the communities")
8548{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008549 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008550}
8551
8552ALIAS (show_bgp_community_exact,
8553 show_bgp_ipv6_community_exact_cmd,
8554 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8555 SHOW_STR
8556 BGP_STR
8557 "Address family\n"
8558 "Display routes matching the communities\n"
8559 "community number\n"
8560 "Do not send outside local AS (well-known community)\n"
8561 "Do not advertise to any peer (well-known community)\n"
8562 "Do not export to next AS (well-known community)\n"
8563 "Exact match of the communities")
8564
8565ALIAS (show_bgp_community_exact,
8566 show_bgp_community2_exact_cmd,
8567 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8568 SHOW_STR
8569 BGP_STR
8570 "Display routes matching the communities\n"
8571 "community number\n"
8572 "Do not send outside local AS (well-known community)\n"
8573 "Do not advertise to any peer (well-known community)\n"
8574 "Do not export to next AS (well-known community)\n"
8575 "community number\n"
8576 "Do not send outside local AS (well-known community)\n"
8577 "Do not advertise to any peer (well-known community)\n"
8578 "Do not export to next AS (well-known community)\n"
8579 "Exact match of the communities")
8580
8581ALIAS (show_bgp_community_exact,
8582 show_bgp_ipv6_community2_exact_cmd,
8583 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8584 SHOW_STR
8585 BGP_STR
8586 "Address family\n"
8587 "Display routes matching the communities\n"
8588 "community number\n"
8589 "Do not send outside local AS (well-known community)\n"
8590 "Do not advertise to any peer (well-known community)\n"
8591 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8597
8598ALIAS (show_bgp_community_exact,
8599 show_bgp_community3_exact_cmd,
8600 "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",
8601 SHOW_STR
8602 BGP_STR
8603 "Display routes matching the communities\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 "community number\n"
8609 "Do not send outside local AS (well-known community)\n"
8610 "Do not advertise to any peer (well-known community)\n"
8611 "Do not export to next AS (well-known community)\n"
8612 "community number\n"
8613 "Do not send outside local AS (well-known community)\n"
8614 "Do not advertise to any peer (well-known community)\n"
8615 "Do not export to next AS (well-known community)\n"
8616 "Exact match of the communities")
8617
8618ALIAS (show_bgp_community_exact,
8619 show_bgp_ipv6_community3_exact_cmd,
8620 "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",
8621 SHOW_STR
8622 BGP_STR
8623 "Address family\n"
8624 "Display routes matching the communities\n"
8625 "community number\n"
8626 "Do not send outside local AS (well-known community)\n"
8627 "Do not advertise to any peer (well-known community)\n"
8628 "Do not export to next AS (well-known community)\n"
8629 "community number\n"
8630 "Do not send outside local AS (well-known community)\n"
8631 "Do not advertise to any peer (well-known community)\n"
8632 "Do not export to next AS (well-known community)\n"
8633 "community number\n"
8634 "Do not send outside local AS (well-known community)\n"
8635 "Do not advertise to any peer (well-known community)\n"
8636 "Do not export to next AS (well-known community)\n"
8637 "Exact match of the communities")
8638
8639ALIAS (show_bgp_community_exact,
8640 show_bgp_community4_exact_cmd,
8641 "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",
8642 SHOW_STR
8643 BGP_STR
8644 "Display routes matching the communities\n"
8645 "community number\n"
8646 "Do not send outside local AS (well-known community)\n"
8647 "Do not advertise to any peer (well-known community)\n"
8648 "Do not export to next AS (well-known community)\n"
8649 "community number\n"
8650 "Do not send outside local AS (well-known community)\n"
8651 "Do not advertise to any peer (well-known community)\n"
8652 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8662
8663ALIAS (show_bgp_community_exact,
8664 show_bgp_ipv6_community4_exact_cmd,
8665 "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",
8666 SHOW_STR
8667 BGP_STR
8668 "Address family\n"
8669 "Display routes matching the communities\n"
8670 "community number\n"
8671 "Do not send outside local AS (well-known community)\n"
8672 "Do not advertise to any peer (well-known community)\n"
8673 "Do not export to next AS (well-known community)\n"
8674 "community number\n"
8675 "Do not send outside local AS (well-known community)\n"
8676 "Do not advertise to any peer (well-known community)\n"
8677 "Do not export to next AS (well-known community)\n"
8678 "community number\n"
8679 "Do not send outside local AS (well-known community)\n"
8680 "Do not advertise to any peer (well-known community)\n"
8681 "Do not export to next AS (well-known community)\n"
8682 "community number\n"
8683 "Do not send outside local AS (well-known community)\n"
8684 "Do not advertise to any peer (well-known community)\n"
8685 "Do not export to next AS (well-known community)\n"
8686 "Exact match of the communities")
8687
8688/* old command */
8689DEFUN (show_ipv6_bgp_community_exact,
8690 show_ipv6_bgp_community_exact_cmd,
8691 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8692 SHOW_STR
8693 IPV6_STR
8694 BGP_STR
8695 "Display routes matching the communities\n"
8696 "community number\n"
8697 "Do not send outside local AS (well-known community)\n"
8698 "Do not advertise to any peer (well-known community)\n"
8699 "Do not export to next AS (well-known community)\n"
8700 "Exact match of the communities")
8701{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008702 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008703}
8704
8705/* old command */
8706ALIAS (show_ipv6_bgp_community_exact,
8707 show_ipv6_bgp_community2_exact_cmd,
8708 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8709 SHOW_STR
8710 IPV6_STR
8711 BGP_STR
8712 "Display routes matching the communities\n"
8713 "community number\n"
8714 "Do not send outside local AS (well-known community)\n"
8715 "Do not advertise to any peer (well-known community)\n"
8716 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8722
8723/* old command */
8724ALIAS (show_ipv6_bgp_community_exact,
8725 show_ipv6_bgp_community3_exact_cmd,
8726 "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",
8727 SHOW_STR
8728 IPV6_STR
8729 BGP_STR
8730 "Display routes matching the communities\n"
8731 "community number\n"
8732 "Do not send outside local AS (well-known community)\n"
8733 "Do not advertise to any peer (well-known community)\n"
8734 "Do not export to next AS (well-known community)\n"
8735 "community number\n"
8736 "Do not send outside local AS (well-known community)\n"
8737 "Do not advertise to any peer (well-known community)\n"
8738 "Do not export to next AS (well-known community)\n"
8739 "community number\n"
8740 "Do not send outside local AS (well-known community)\n"
8741 "Do not advertise to any peer (well-known community)\n"
8742 "Do not export to next AS (well-known community)\n"
8743 "Exact match of the communities")
8744
8745/* old command */
8746ALIAS (show_ipv6_bgp_community_exact,
8747 show_ipv6_bgp_community4_exact_cmd,
8748 "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",
8749 SHOW_STR
8750 IPV6_STR
8751 BGP_STR
8752 "Display routes matching the communities\n"
8753 "community number\n"
8754 "Do not send outside local AS (well-known community)\n"
8755 "Do not advertise to any peer (well-known community)\n"
8756 "Do not export to next AS (well-known community)\n"
8757 "community number\n"
8758 "Do not send outside local AS (well-known community)\n"
8759 "Do not advertise to any peer (well-known community)\n"
8760 "Do not export to next AS (well-known community)\n"
8761 "community number\n"
8762 "Do not send outside local AS (well-known community)\n"
8763 "Do not advertise to any peer (well-known community)\n"
8764 "Do not export to next AS (well-known community)\n"
8765 "community number\n"
8766 "Do not send outside local AS (well-known community)\n"
8767 "Do not advertise to any peer (well-known community)\n"
8768 "Do not export to next AS (well-known community)\n"
8769 "Exact match of the communities")
8770
8771/* old command */
8772DEFUN (show_ipv6_mbgp_community,
8773 show_ipv6_mbgp_community_cmd,
8774 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8775 SHOW_STR
8776 IPV6_STR
8777 MBGP_STR
8778 "Display routes matching the communities\n"
8779 "community number\n"
8780 "Do not send outside local AS (well-known community)\n"
8781 "Do not advertise to any peer (well-known community)\n"
8782 "Do not export to next AS (well-known community)\n")
8783{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008784 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008785}
8786
8787/* old command */
8788ALIAS (show_ipv6_mbgp_community,
8789 show_ipv6_mbgp_community2_cmd,
8790 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8791 SHOW_STR
8792 IPV6_STR
8793 MBGP_STR
8794 "Display routes matching the communities\n"
8795 "community number\n"
8796 "Do not send outside local AS (well-known community)\n"
8797 "Do not advertise to any peer (well-known community)\n"
8798 "Do not export to next AS (well-known community)\n"
8799 "community number\n"
8800 "Do not send outside local AS (well-known community)\n"
8801 "Do not advertise to any peer (well-known community)\n"
8802 "Do not export to next AS (well-known community)\n")
8803
8804/* old command */
8805ALIAS (show_ipv6_mbgp_community,
8806 show_ipv6_mbgp_community3_cmd,
8807 "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)",
8808 SHOW_STR
8809 IPV6_STR
8810 MBGP_STR
8811 "Display routes matching the communities\n"
8812 "community number\n"
8813 "Do not send outside local AS (well-known community)\n"
8814 "Do not advertise to any peer (well-known community)\n"
8815 "Do not export to next AS (well-known community)\n"
8816 "community number\n"
8817 "Do not send outside local AS (well-known community)\n"
8818 "Do not advertise to any peer (well-known community)\n"
8819 "Do not export to next AS (well-known community)\n"
8820 "community number\n"
8821 "Do not send outside local AS (well-known community)\n"
8822 "Do not advertise to any peer (well-known community)\n"
8823 "Do not export to next AS (well-known community)\n")
8824
8825/* old command */
8826ALIAS (show_ipv6_mbgp_community,
8827 show_ipv6_mbgp_community4_cmd,
8828 "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)",
8829 SHOW_STR
8830 IPV6_STR
8831 MBGP_STR
8832 "Display routes matching the communities\n"
8833 "community number\n"
8834 "Do not send outside local AS (well-known community)\n"
8835 "Do not advertise to any peer (well-known community)\n"
8836 "Do not export to next AS (well-known community)\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
8850/* old command */
8851DEFUN (show_ipv6_mbgp_community_exact,
8852 show_ipv6_mbgp_community_exact_cmd,
8853 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8854 SHOW_STR
8855 IPV6_STR
8856 MBGP_STR
8857 "Display routes matching the communities\n"
8858 "community number\n"
8859 "Do not send outside local AS (well-known community)\n"
8860 "Do not advertise to any peer (well-known community)\n"
8861 "Do not export to next AS (well-known community)\n"
8862 "Exact match of the communities")
8863{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008864 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008865}
8866
8867/* old command */
8868ALIAS (show_ipv6_mbgp_community_exact,
8869 show_ipv6_mbgp_community2_exact_cmd,
8870 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8871 SHOW_STR
8872 IPV6_STR
8873 MBGP_STR
8874 "Display routes matching the communities\n"
8875 "community number\n"
8876 "Do not send outside local AS (well-known community)\n"
8877 "Do not advertise to any peer (well-known community)\n"
8878 "Do not export to next AS (well-known community)\n"
8879 "community number\n"
8880 "Do not send outside local AS (well-known community)\n"
8881 "Do not advertise to any peer (well-known community)\n"
8882 "Do not export to next AS (well-known community)\n"
8883 "Exact match of the communities")
8884
8885/* old command */
8886ALIAS (show_ipv6_mbgp_community_exact,
8887 show_ipv6_mbgp_community3_exact_cmd,
8888 "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",
8889 SHOW_STR
8890 IPV6_STR
8891 MBGP_STR
8892 "Display routes matching the communities\n"
8893 "community number\n"
8894 "Do not send outside local AS (well-known community)\n"
8895 "Do not advertise to any peer (well-known community)\n"
8896 "Do not export to next AS (well-known community)\n"
8897 "community number\n"
8898 "Do not send outside local AS (well-known community)\n"
8899 "Do not advertise to any peer (well-known community)\n"
8900 "Do not export to next AS (well-known community)\n"
8901 "community number\n"
8902 "Do not send outside local AS (well-known community)\n"
8903 "Do not advertise to any peer (well-known community)\n"
8904 "Do not export to next AS (well-known community)\n"
8905 "Exact match of the communities")
8906
8907/* old command */
8908ALIAS (show_ipv6_mbgp_community_exact,
8909 show_ipv6_mbgp_community4_exact_cmd,
8910 "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",
8911 SHOW_STR
8912 IPV6_STR
8913 MBGP_STR
8914 "Display routes matching the communities\n"
8915 "community number\n"
8916 "Do not send outside local AS (well-known community)\n"
8917 "Do not advertise to any peer (well-known community)\n"
8918 "Do not export to next AS (well-known community)\n"
8919 "community number\n"
8920 "Do not send outside local AS (well-known community)\n"
8921 "Do not advertise to any peer (well-known community)\n"
8922 "Do not export to next AS (well-known community)\n"
8923 "community number\n"
8924 "Do not send outside local AS (well-known community)\n"
8925 "Do not advertise to any peer (well-known community)\n"
8926 "Do not export to next AS (well-known community)\n"
8927 "community number\n"
8928 "Do not send outside local AS (well-known community)\n"
8929 "Do not advertise to any peer (well-known community)\n"
8930 "Do not export to next AS (well-known community)\n"
8931 "Exact match of the communities")
8932#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02008933
paul94f2b392005-06-28 12:44:16 +00008934static int
paulfd79ac92004-10-13 05:06:08 +00008935bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008936 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008937{
8938 struct community_list *list;
8939
hassofee6e4e2005-02-02 16:29:31 +00008940 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008941 if (list == NULL)
8942 {
8943 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8944 VTY_NEWLINE);
8945 return CMD_WARNING;
8946 }
8947
ajs5a646652004-11-05 01:25:55 +00008948 return bgp_show (vty, NULL, afi, safi,
8949 (exact ? bgp_show_type_community_list_exact :
8950 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008951}
8952
8953DEFUN (show_ip_bgp_community_list,
8954 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008955 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008956 SHOW_STR
8957 IP_STR
8958 BGP_STR
8959 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008960 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008961 "community-list name\n")
8962{
8963 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8964}
8965
8966DEFUN (show_ip_bgp_ipv4_community_list,
8967 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008968 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008969 SHOW_STR
8970 IP_STR
8971 BGP_STR
8972 "Address family\n"
8973 "Address Family modifier\n"
8974 "Address Family modifier\n"
8975 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008976 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008977 "community-list name\n")
8978{
8979 if (strncmp (argv[0], "m", 1) == 0)
8980 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8981
8982 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8983}
8984
8985DEFUN (show_ip_bgp_community_list_exact,
8986 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008987 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008988 SHOW_STR
8989 IP_STR
8990 BGP_STR
8991 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008992 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008993 "community-list name\n"
8994 "Exact match of the communities\n")
8995{
8996 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8997}
8998
8999DEFUN (show_ip_bgp_ipv4_community_list_exact,
9000 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009001 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009002 SHOW_STR
9003 IP_STR
9004 BGP_STR
9005 "Address family\n"
9006 "Address Family modifier\n"
9007 "Address Family modifier\n"
9008 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009009 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009010 "community-list name\n"
9011 "Exact match of the communities\n")
9012{
9013 if (strncmp (argv[0], "m", 1) == 0)
9014 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
9015
9016 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
9017}
9018
9019#ifdef HAVE_IPV6
9020DEFUN (show_bgp_community_list,
9021 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009022 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009023 SHOW_STR
9024 BGP_STR
9025 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009026 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009027 "community-list name\n")
9028{
9029 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9030}
9031
9032ALIAS (show_bgp_community_list,
9033 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009034 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009035 SHOW_STR
9036 BGP_STR
9037 "Address family\n"
9038 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009039 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00009040 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00009041
9042/* old command */
9043DEFUN (show_ipv6_bgp_community_list,
9044 show_ipv6_bgp_community_list_cmd,
9045 "show ipv6 bgp community-list WORD",
9046 SHOW_STR
9047 IPV6_STR
9048 BGP_STR
9049 "Display routes matching the community-list\n"
9050 "community-list name\n")
9051{
9052 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9053}
9054
9055/* old command */
9056DEFUN (show_ipv6_mbgp_community_list,
9057 show_ipv6_mbgp_community_list_cmd,
9058 "show ipv6 mbgp community-list WORD",
9059 SHOW_STR
9060 IPV6_STR
9061 MBGP_STR
9062 "Display routes matching the community-list\n"
9063 "community-list name\n")
9064{
9065 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
9066}
9067
9068DEFUN (show_bgp_community_list_exact,
9069 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009070 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009071 SHOW_STR
9072 BGP_STR
9073 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009074 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009075 "community-list name\n"
9076 "Exact match of the communities\n")
9077{
9078 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9079}
9080
9081ALIAS (show_bgp_community_list_exact,
9082 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009083 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009084 SHOW_STR
9085 BGP_STR
9086 "Address family\n"
9087 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009088 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009089 "community-list name\n"
9090 "Exact match of the communities\n")
9091
9092/* old command */
9093DEFUN (show_ipv6_bgp_community_list_exact,
9094 show_ipv6_bgp_community_list_exact_cmd,
9095 "show ipv6 bgp community-list WORD exact-match",
9096 SHOW_STR
9097 IPV6_STR
9098 BGP_STR
9099 "Display routes matching the community-list\n"
9100 "community-list name\n"
9101 "Exact match of the communities\n")
9102{
9103 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9104}
9105
9106/* old command */
9107DEFUN (show_ipv6_mbgp_community_list_exact,
9108 show_ipv6_mbgp_community_list_exact_cmd,
9109 "show ipv6 mbgp community-list WORD exact-match",
9110 SHOW_STR
9111 IPV6_STR
9112 MBGP_STR
9113 "Display routes matching the community-list\n"
9114 "community-list name\n"
9115 "Exact match of the communities\n")
9116{
9117 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9118}
9119#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009120
paul94f2b392005-06-28 12:44:16 +00009121static int
paulfd79ac92004-10-13 05:06:08 +00009122bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009123 safi_t safi, enum bgp_show_type type)
9124{
9125 int ret;
9126 struct prefix *p;
9127
9128 p = prefix_new();
9129
9130 ret = str2prefix (prefix, p);
9131 if (! ret)
9132 {
9133 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9134 return CMD_WARNING;
9135 }
9136
ajs5a646652004-11-05 01:25:55 +00009137 ret = bgp_show (vty, NULL, afi, safi, type, p);
9138 prefix_free(p);
9139 return ret;
paul718e3742002-12-13 20:15:29 +00009140}
9141
9142DEFUN (show_ip_bgp_prefix_longer,
9143 show_ip_bgp_prefix_longer_cmd,
9144 "show ip bgp A.B.C.D/M longer-prefixes",
9145 SHOW_STR
9146 IP_STR
9147 BGP_STR
9148 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9149 "Display route and more specific routes\n")
9150{
9151 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9152 bgp_show_type_prefix_longer);
9153}
9154
9155DEFUN (show_ip_bgp_flap_prefix_longer,
9156 show_ip_bgp_flap_prefix_longer_cmd,
9157 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9158 SHOW_STR
9159 IP_STR
9160 BGP_STR
9161 "Display flap statistics of routes\n"
9162 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9163 "Display route and more specific routes\n")
9164{
9165 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9166 bgp_show_type_flap_prefix_longer);
9167}
9168
Balaji3921cc52015-05-16 23:12:17 +05309169ALIAS (show_ip_bgp_flap_prefix_longer,
9170 show_ip_bgp_damp_flap_prefix_longer_cmd,
9171 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
9172 SHOW_STR
9173 IP_STR
9174 BGP_STR
9175 "Display detailed information about dampening\n"
9176 "Display flap statistics of routes\n"
9177 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9178 "Display route and more specific routes\n")
9179
paul718e3742002-12-13 20:15:29 +00009180DEFUN (show_ip_bgp_ipv4_prefix_longer,
9181 show_ip_bgp_ipv4_prefix_longer_cmd,
9182 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9183 SHOW_STR
9184 IP_STR
9185 BGP_STR
9186 "Address family\n"
9187 "Address Family modifier\n"
9188 "Address Family modifier\n"
9189 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9190 "Display route and more specific routes\n")
9191{
9192 if (strncmp (argv[0], "m", 1) == 0)
9193 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9194 bgp_show_type_prefix_longer);
9195
9196 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9197 bgp_show_type_prefix_longer);
9198}
9199
9200DEFUN (show_ip_bgp_flap_address,
9201 show_ip_bgp_flap_address_cmd,
9202 "show ip bgp flap-statistics A.B.C.D",
9203 SHOW_STR
9204 IP_STR
9205 BGP_STR
9206 "Display flap statistics of routes\n"
9207 "Network in the BGP routing table to display\n")
9208{
9209 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9210 bgp_show_type_flap_address);
9211}
9212
Balaji3921cc52015-05-16 23:12:17 +05309213ALIAS (show_ip_bgp_flap_address,
9214 show_ip_bgp_damp_flap_address_cmd,
9215 "show ip bgp dampening flap-statistics A.B.C.D",
9216 SHOW_STR
9217 IP_STR
9218 BGP_STR
9219 "Display detailed information about dampening\n"
9220 "Display flap statistics of routes\n"
9221 "Network in the BGP routing table to display\n")
9222
paul718e3742002-12-13 20:15:29 +00009223DEFUN (show_ip_bgp_flap_prefix,
9224 show_ip_bgp_flap_prefix_cmd,
9225 "show ip bgp flap-statistics A.B.C.D/M",
9226 SHOW_STR
9227 IP_STR
9228 BGP_STR
9229 "Display flap statistics of routes\n"
9230 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9231{
9232 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9233 bgp_show_type_flap_prefix);
9234}
Balaji3921cc52015-05-16 23:12:17 +05309235
9236ALIAS (show_ip_bgp_flap_prefix,
9237 show_ip_bgp_damp_flap_prefix_cmd,
9238 "show ip bgp dampening flap-statistics A.B.C.D/M",
9239 SHOW_STR
9240 IP_STR
9241 BGP_STR
9242 "Display detailed information about dampening\n"
9243 "Display flap statistics of routes\n"
9244 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9245
paul718e3742002-12-13 20:15:29 +00009246#ifdef HAVE_IPV6
9247DEFUN (show_bgp_prefix_longer,
9248 show_bgp_prefix_longer_cmd,
9249 "show bgp X:X::X:X/M longer-prefixes",
9250 SHOW_STR
9251 BGP_STR
9252 "IPv6 prefix <network>/<length>\n"
9253 "Display route and more specific routes\n")
9254{
9255 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9256 bgp_show_type_prefix_longer);
9257}
9258
9259ALIAS (show_bgp_prefix_longer,
9260 show_bgp_ipv6_prefix_longer_cmd,
9261 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9262 SHOW_STR
9263 BGP_STR
9264 "Address family\n"
9265 "IPv6 prefix <network>/<length>\n"
9266 "Display route and more specific routes\n")
9267
9268/* old command */
9269DEFUN (show_ipv6_bgp_prefix_longer,
9270 show_ipv6_bgp_prefix_longer_cmd,
9271 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9272 SHOW_STR
9273 IPV6_STR
9274 BGP_STR
9275 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9276 "Display route and more specific routes\n")
9277{
9278 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9279 bgp_show_type_prefix_longer);
9280}
9281
9282/* old command */
9283DEFUN (show_ipv6_mbgp_prefix_longer,
9284 show_ipv6_mbgp_prefix_longer_cmd,
9285 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9286 SHOW_STR
9287 IPV6_STR
9288 MBGP_STR
9289 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9290 "Display route and more specific routes\n")
9291{
9292 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9293 bgp_show_type_prefix_longer);
9294}
9295#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009296
paul94f2b392005-06-28 12:44:16 +00009297static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009298peer_lookup_in_view (struct vty *vty, const char *view_name,
9299 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009300{
9301 int ret;
9302 struct bgp *bgp;
9303 struct peer *peer;
9304 union sockunion su;
9305
9306 /* BGP structure lookup. */
9307 if (view_name)
9308 {
9309 bgp = bgp_lookup_by_name (view_name);
9310 if (! bgp)
9311 {
9312 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9313 return NULL;
9314 }
9315 }
paul5228ad22004-06-04 17:58:18 +00009316 else
paulbb46e942003-10-24 19:02:03 +00009317 {
9318 bgp = bgp_get_default ();
9319 if (! bgp)
9320 {
9321 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9322 return NULL;
9323 }
9324 }
9325
9326 /* Get peer sockunion. */
9327 ret = str2sockunion (ip_str, &su);
9328 if (ret < 0)
9329 {
9330 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9331 return NULL;
9332 }
9333
9334 /* Peer structure lookup. */
9335 peer = peer_lookup (bgp, &su);
9336 if (! peer)
9337 {
9338 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9339 return NULL;
9340 }
9341
9342 return peer;
9343}
David Lamparter6b0655a2014-06-04 06:53:35 +02009344
Paul Jakma2815e612006-09-14 02:56:07 +00009345enum bgp_stats
9346{
9347 BGP_STATS_MAXBITLEN = 0,
9348 BGP_STATS_RIB,
9349 BGP_STATS_PREFIXES,
9350 BGP_STATS_TOTPLEN,
9351 BGP_STATS_UNAGGREGATEABLE,
9352 BGP_STATS_MAX_AGGREGATEABLE,
9353 BGP_STATS_AGGREGATES,
9354 BGP_STATS_SPACE,
9355 BGP_STATS_ASPATH_COUNT,
9356 BGP_STATS_ASPATH_MAXHOPS,
9357 BGP_STATS_ASPATH_TOTHOPS,
9358 BGP_STATS_ASPATH_MAXSIZE,
9359 BGP_STATS_ASPATH_TOTSIZE,
9360 BGP_STATS_ASN_HIGHEST,
9361 BGP_STATS_MAX,
9362};
paulbb46e942003-10-24 19:02:03 +00009363
Paul Jakma2815e612006-09-14 02:56:07 +00009364static const char *table_stats_strs[] =
9365{
9366 [BGP_STATS_PREFIXES] = "Total Prefixes",
9367 [BGP_STATS_TOTPLEN] = "Average prefix length",
9368 [BGP_STATS_RIB] = "Total Advertisements",
9369 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9370 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9371 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9372 [BGP_STATS_SPACE] = "Address space advertised",
9373 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9374 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9375 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9376 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9377 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9378 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9379 [BGP_STATS_MAX] = NULL,
9380};
9381
9382struct bgp_table_stats
9383{
9384 struct bgp_table *table;
9385 unsigned long long counts[BGP_STATS_MAX];
9386};
9387
9388#if 0
9389#define TALLY_SIGFIG 100000
9390static unsigned long
9391ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9392{
9393 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9394 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9395 unsigned long ret = newtot / count;
9396
9397 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9398 return ret + 1;
9399 else
9400 return ret;
9401}
9402#endif
9403
9404static int
9405bgp_table_stats_walker (struct thread *t)
9406{
9407 struct bgp_node *rn;
9408 struct bgp_node *top;
9409 struct bgp_table_stats *ts = THREAD_ARG (t);
9410 unsigned int space = 0;
9411
Paul Jakma53d9f672006-10-15 23:41:16 +00009412 if (!(top = bgp_table_top (ts->table)))
9413 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009414
9415 switch (top->p.family)
9416 {
9417 case AF_INET:
9418 space = IPV4_MAX_BITLEN;
9419 break;
9420 case AF_INET6:
9421 space = IPV6_MAX_BITLEN;
9422 break;
9423 }
9424
9425 ts->counts[BGP_STATS_MAXBITLEN] = space;
9426
9427 for (rn = top; rn; rn = bgp_route_next (rn))
9428 {
9429 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009430 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009431 unsigned int rinum = 0;
9432
9433 if (rn == top)
9434 continue;
9435
9436 if (!rn->info)
9437 continue;
9438
9439 ts->counts[BGP_STATS_PREFIXES]++;
9440 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9441
9442#if 0
9443 ts->counts[BGP_STATS_AVGPLEN]
9444 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9445 ts->counts[BGP_STATS_AVGPLEN],
9446 rn->p.prefixlen);
9447#endif
9448
9449 /* check if the prefix is included by any other announcements */
9450 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009451 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009452
9453 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009454 {
9455 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9456 /* announced address space */
9457 if (space)
9458 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9459 }
Paul Jakma2815e612006-09-14 02:56:07 +00009460 else if (prn->info)
9461 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9462
Paul Jakma2815e612006-09-14 02:56:07 +00009463 for (ri = rn->info; ri; ri = ri->next)
9464 {
9465 rinum++;
9466 ts->counts[BGP_STATS_RIB]++;
9467
9468 if (ri->attr &&
9469 (CHECK_FLAG (ri->attr->flag,
9470 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9471 ts->counts[BGP_STATS_AGGREGATES]++;
9472
9473 /* as-path stats */
9474 if (ri->attr && ri->attr->aspath)
9475 {
9476 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9477 unsigned int size = aspath_size (ri->attr->aspath);
9478 as_t highest = aspath_highest (ri->attr->aspath);
9479
9480 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9481
9482 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9483 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9484
9485 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9486 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9487
9488 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9489 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9490#if 0
9491 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9492 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9493 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9494 hops);
9495 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9496 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9497 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9498 size);
9499#endif
9500 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9501 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9502 }
9503 }
9504 }
9505 return 0;
9506}
9507
9508static int
9509bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9510{
9511 struct bgp_table_stats ts;
9512 unsigned int i;
9513
9514 if (!bgp->rib[afi][safi])
9515 {
9516 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9517 return CMD_WARNING;
9518 }
9519
9520 memset (&ts, 0, sizeof (ts));
9521 ts.table = bgp->rib[afi][safi];
9522 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9523
9524 vty_out (vty, "BGP %s RIB statistics%s%s",
9525 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9526
9527 for (i = 0; i < BGP_STATS_MAX; i++)
9528 {
9529 if (!table_stats_strs[i])
9530 continue;
9531
9532 switch (i)
9533 {
9534#if 0
9535 case BGP_STATS_ASPATH_AVGHOPS:
9536 case BGP_STATS_ASPATH_AVGSIZE:
9537 case BGP_STATS_AVGPLEN:
9538 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9539 vty_out (vty, "%12.2f",
9540 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9541 break;
9542#endif
9543 case BGP_STATS_ASPATH_TOTHOPS:
9544 case BGP_STATS_ASPATH_TOTSIZE:
9545 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9546 vty_out (vty, "%12.2f",
9547 ts.counts[i] ?
9548 (float)ts.counts[i] /
9549 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9550 : 0);
9551 break;
9552 case BGP_STATS_TOTPLEN:
9553 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9554 vty_out (vty, "%12.2f",
9555 ts.counts[i] ?
9556 (float)ts.counts[i] /
9557 (float)ts.counts[BGP_STATS_PREFIXES]
9558 : 0);
9559 break;
9560 case BGP_STATS_SPACE:
9561 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9562 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9563 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9564 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009565 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009566 vty_out (vty, "%12.2f%s",
9567 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009568 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009569 VTY_NEWLINE);
9570 vty_out (vty, "%30s: ", "/8 equivalent ");
9571 vty_out (vty, "%12.2f%s",
9572 (float)ts.counts[BGP_STATS_SPACE] /
9573 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9574 VTY_NEWLINE);
9575 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9576 break;
9577 vty_out (vty, "%30s: ", "/24 equivalent ");
9578 vty_out (vty, "%12.2f",
9579 (float)ts.counts[BGP_STATS_SPACE] /
9580 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9581 break;
9582 default:
9583 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9584 vty_out (vty, "%12llu", ts.counts[i]);
9585 }
9586
9587 vty_out (vty, "%s", VTY_NEWLINE);
9588 }
9589 return CMD_SUCCESS;
9590}
9591
9592static int
9593bgp_table_stats_vty (struct vty *vty, const char *name,
9594 const char *afi_str, const char *safi_str)
9595{
9596 struct bgp *bgp;
9597 afi_t afi;
9598 safi_t safi;
9599
9600 if (name)
9601 bgp = bgp_lookup_by_name (name);
9602 else
9603 bgp = bgp_get_default ();
9604
9605 if (!bgp)
9606 {
9607 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9608 return CMD_WARNING;
9609 }
9610 if (strncmp (afi_str, "ipv", 3) == 0)
9611 {
9612 if (strncmp (afi_str, "ipv4", 4) == 0)
9613 afi = AFI_IP;
9614 else if (strncmp (afi_str, "ipv6", 4) == 0)
9615 afi = AFI_IP6;
9616 else
9617 {
9618 vty_out (vty, "%% Invalid address family %s%s",
9619 afi_str, VTY_NEWLINE);
9620 return CMD_WARNING;
9621 }
9622 if (strncmp (safi_str, "m", 1) == 0)
9623 safi = SAFI_MULTICAST;
9624 else if (strncmp (safi_str, "u", 1) == 0)
9625 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009626 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9627 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009628 else
9629 {
9630 vty_out (vty, "%% Invalid subsequent address family %s%s",
9631 safi_str, VTY_NEWLINE);
9632 return CMD_WARNING;
9633 }
9634 }
9635 else
9636 {
9637 vty_out (vty, "%% Invalid address family %s%s",
9638 afi_str, VTY_NEWLINE);
9639 return CMD_WARNING;
9640 }
9641
Paul Jakma2815e612006-09-14 02:56:07 +00009642 return bgp_table_stats (vty, bgp, afi, safi);
9643}
9644
9645DEFUN (show_bgp_statistics,
9646 show_bgp_statistics_cmd,
9647 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9648 SHOW_STR
9649 BGP_STR
9650 "Address family\n"
9651 "Address family\n"
9652 "Address Family modifier\n"
9653 "Address Family modifier\n"
9654 "BGP RIB advertisement statistics\n")
9655{
9656 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9657}
9658
9659ALIAS (show_bgp_statistics,
9660 show_bgp_statistics_vpnv4_cmd,
9661 "show bgp (ipv4) (vpnv4) statistics",
9662 SHOW_STR
9663 BGP_STR
9664 "Address family\n"
9665 "Address Family modifier\n"
9666 "BGP RIB advertisement statistics\n")
9667
9668DEFUN (show_bgp_statistics_view,
9669 show_bgp_statistics_view_cmd,
9670 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9671 SHOW_STR
9672 BGP_STR
9673 "BGP view\n"
9674 "Address family\n"
9675 "Address family\n"
9676 "Address Family modifier\n"
9677 "Address Family modifier\n"
9678 "BGP RIB advertisement statistics\n")
9679{
9680 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9681}
9682
9683ALIAS (show_bgp_statistics_view,
9684 show_bgp_statistics_view_vpnv4_cmd,
9685 "show bgp view WORD (ipv4) (vpnv4) statistics",
9686 SHOW_STR
9687 BGP_STR
9688 "BGP view\n"
9689 "Address family\n"
9690 "Address Family modifier\n"
9691 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02009692
Paul Jakmaff7924f2006-09-04 01:10:36 +00009693enum bgp_pcounts
9694{
9695 PCOUNT_ADJ_IN = 0,
9696 PCOUNT_DAMPED,
9697 PCOUNT_REMOVED,
9698 PCOUNT_HISTORY,
9699 PCOUNT_STALE,
9700 PCOUNT_VALID,
9701 PCOUNT_ALL,
9702 PCOUNT_COUNTED,
9703 PCOUNT_PFCNT, /* the figure we display to users */
9704 PCOUNT_MAX,
9705};
9706
9707static const char *pcount_strs[] =
9708{
9709 [PCOUNT_ADJ_IN] = "Adj-in",
9710 [PCOUNT_DAMPED] = "Damped",
9711 [PCOUNT_REMOVED] = "Removed",
9712 [PCOUNT_HISTORY] = "History",
9713 [PCOUNT_STALE] = "Stale",
9714 [PCOUNT_VALID] = "Valid",
9715 [PCOUNT_ALL] = "All RIB",
9716 [PCOUNT_COUNTED] = "PfxCt counted",
9717 [PCOUNT_PFCNT] = "Useable",
9718 [PCOUNT_MAX] = NULL,
9719};
9720
Paul Jakma2815e612006-09-14 02:56:07 +00009721struct peer_pcounts
9722{
9723 unsigned int count[PCOUNT_MAX];
9724 const struct peer *peer;
9725 const struct bgp_table *table;
9726};
9727
Paul Jakmaff7924f2006-09-04 01:10:36 +00009728static int
Paul Jakma2815e612006-09-14 02:56:07 +00009729bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009730{
9731 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009732 struct peer_pcounts *pc = THREAD_ARG (t);
9733 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009734
Paul Jakma2815e612006-09-14 02:56:07 +00009735 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009736 {
9737 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009738 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009739
9740 for (ain = rn->adj_in; ain; ain = ain->next)
9741 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009742 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009743
Paul Jakmaff7924f2006-09-04 01:10:36 +00009744 for (ri = rn->info; ri; ri = ri->next)
9745 {
9746 char buf[SU_ADDRSTRLEN];
9747
9748 if (ri->peer != peer)
9749 continue;
9750
Paul Jakma2815e612006-09-14 02:56:07 +00009751 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009752
9753 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009754 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009755 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009756 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009757 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009758 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009759 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009760 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009761 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009762 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009763 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009764 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009765
9766 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9767 {
Paul Jakma2815e612006-09-14 02:56:07 +00009768 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009769 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009770 plog_warn (peer->log,
9771 "%s [pcount] %s/%d is counted but flags 0x%x",
9772 peer->host,
9773 inet_ntop(rn->p.family, &rn->p.u.prefix,
9774 buf, SU_ADDRSTRLEN),
9775 rn->p.prefixlen,
9776 ri->flags);
9777 }
9778 else
9779 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009780 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009781 plog_warn (peer->log,
9782 "%s [pcount] %s/%d not counted but flags 0x%x",
9783 peer->host,
9784 inet_ntop(rn->p.family, &rn->p.u.prefix,
9785 buf, SU_ADDRSTRLEN),
9786 rn->p.prefixlen,
9787 ri->flags);
9788 }
9789 }
9790 }
Paul Jakma2815e612006-09-14 02:56:07 +00009791 return 0;
9792}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009793
Paul Jakma2815e612006-09-14 02:56:07 +00009794static int
9795bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9796{
9797 struct peer_pcounts pcounts = { .peer = peer };
9798 unsigned int i;
9799
9800 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9801 || !peer->bgp->rib[afi][safi])
9802 {
9803 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9804 return CMD_WARNING;
9805 }
9806
9807 memset (&pcounts, 0, sizeof(pcounts));
9808 pcounts.peer = peer;
9809 pcounts.table = peer->bgp->rib[afi][safi];
9810
9811 /* in-place call via thread subsystem so as to record execution time
9812 * stats for the thread-walk (i.e. ensure this can't be blamed on
9813 * on just vty_read()).
9814 */
9815 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9816
Paul Jakmaff7924f2006-09-04 01:10:36 +00009817 vty_out (vty, "Prefix counts for %s, %s%s",
9818 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9819 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9820 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9821 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9822
9823 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009824 vty_out (vty, "%20s: %-10d%s",
9825 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009826
Paul Jakma2815e612006-09-14 02:56:07 +00009827 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009828 {
9829 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9830 peer->host, VTY_NEWLINE);
9831 vty_out (vty, "Please report this bug, with the above command output%s",
9832 VTY_NEWLINE);
9833 }
9834
9835 return CMD_SUCCESS;
9836}
9837
9838DEFUN (show_ip_bgp_neighbor_prefix_counts,
9839 show_ip_bgp_neighbor_prefix_counts_cmd,
9840 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9841 SHOW_STR
9842 IP_STR
9843 BGP_STR
9844 "Detailed information on TCP and BGP neighbor connections\n"
9845 "Neighbor to display information about\n"
9846 "Neighbor to display information about\n"
9847 "Display detailed prefix count information\n")
9848{
9849 struct peer *peer;
9850
9851 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9852 if (! peer)
9853 return CMD_WARNING;
9854
9855 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9856}
9857
9858DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9859 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9860 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9861 SHOW_STR
9862 BGP_STR
9863 "Address family\n"
9864 "Detailed information on TCP and BGP neighbor connections\n"
9865 "Neighbor to display information about\n"
9866 "Neighbor to display information about\n"
9867 "Display detailed prefix count information\n")
9868{
9869 struct peer *peer;
9870
9871 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9872 if (! peer)
9873 return CMD_WARNING;
9874
9875 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9876}
9877
9878DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9879 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9880 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9881 SHOW_STR
9882 IP_STR
9883 BGP_STR
9884 "Address family\n"
9885 "Address Family modifier\n"
9886 "Address Family modifier\n"
9887 "Detailed information on TCP and BGP neighbor connections\n"
9888 "Neighbor to display information about\n"
9889 "Neighbor to display information about\n"
9890 "Display detailed prefix count information\n")
9891{
9892 struct peer *peer;
9893
9894 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9895 if (! peer)
9896 return CMD_WARNING;
9897
9898 if (strncmp (argv[0], "m", 1) == 0)
9899 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9900
9901 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9902}
9903
9904DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9905 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9906 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9907 SHOW_STR
9908 IP_STR
9909 BGP_STR
9910 "Address family\n"
9911 "Address Family modifier\n"
9912 "Address Family modifier\n"
9913 "Detailed information on TCP and BGP neighbor connections\n"
9914 "Neighbor to display information about\n"
9915 "Neighbor to display information about\n"
9916 "Display detailed prefix count information\n")
9917{
9918 struct peer *peer;
9919
9920 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9921 if (! peer)
9922 return CMD_WARNING;
9923
9924 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9925}
9926
9927
paul94f2b392005-06-28 12:44:16 +00009928static void
paul718e3742002-12-13 20:15:29 +00009929show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9930 int in)
9931{
9932 struct bgp_table *table;
9933 struct bgp_adj_in *ain;
9934 struct bgp_adj_out *adj;
9935 unsigned long output_count;
9936 struct bgp_node *rn;
9937 int header1 = 1;
9938 struct bgp *bgp;
9939 int header2 = 1;
9940
paulbb46e942003-10-24 19:02:03 +00009941 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009942
9943 if (! bgp)
9944 return;
9945
9946 table = bgp->rib[afi][safi];
9947
9948 output_count = 0;
9949
9950 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9951 PEER_STATUS_DEFAULT_ORIGINATE))
9952 {
9953 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 +00009954 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9955 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009956
9957 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9958 VTY_NEWLINE, VTY_NEWLINE);
9959 header1 = 0;
9960 }
9961
9962 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9963 if (in)
9964 {
9965 for (ain = rn->adj_in; ain; ain = ain->next)
9966 if (ain->peer == peer)
9967 {
9968 if (header1)
9969 {
9970 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 +00009971 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9972 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009973 header1 = 0;
9974 }
9975 if (header2)
9976 {
9977 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9978 header2 = 0;
9979 }
9980 if (ain->attr)
9981 {
9982 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9983 output_count++;
9984 }
9985 }
9986 }
9987 else
9988 {
9989 for (adj = rn->adj_out; adj; adj = adj->next)
9990 if (adj->peer == peer)
9991 {
9992 if (header1)
9993 {
9994 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 +00009995 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9996 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009997 header1 = 0;
9998 }
9999 if (header2)
10000 {
10001 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
10002 header2 = 0;
10003 }
10004 if (adj->attr)
10005 {
10006 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
10007 output_count++;
10008 }
10009 }
10010 }
10011
10012 if (output_count != 0)
10013 vty_out (vty, "%sTotal number of prefixes %ld%s",
10014 VTY_NEWLINE, output_count, VTY_NEWLINE);
10015}
10016
paul94f2b392005-06-28 12:44:16 +000010017static int
paulbb46e942003-10-24 19:02:03 +000010018peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
10019{
paul718e3742002-12-13 20:15:29 +000010020 if (! peer || ! peer->afc[afi][safi])
10021 {
10022 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10023 return CMD_WARNING;
10024 }
10025
10026 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10027 {
10028 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
10029 VTY_NEWLINE);
10030 return CMD_WARNING;
10031 }
10032
10033 show_adj_route (vty, peer, afi, safi, in);
10034
10035 return CMD_SUCCESS;
10036}
10037
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010038DEFUN (show_ip_bgp_view_neighbor_advertised_route,
10039 show_ip_bgp_view_neighbor_advertised_route_cmd,
10040 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10041 SHOW_STR
10042 IP_STR
10043 BGP_STR
10044 "BGP view\n"
10045 "View name\n"
10046 "Detailed information on TCP and BGP neighbor connections\n"
10047 "Neighbor to display information about\n"
10048 "Neighbor to display information about\n"
10049 "Display the routes advertised to a BGP neighbor\n")
10050{
10051 struct peer *peer;
10052
10053 if (argc == 2)
10054 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10055 else
10056 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10057
10058 if (! peer)
10059 return CMD_WARNING;
10060
10061 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
10062}
10063
10064ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010065 show_ip_bgp_neighbor_advertised_route_cmd,
10066 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10067 SHOW_STR
10068 IP_STR
10069 BGP_STR
10070 "Detailed information on TCP and BGP neighbor connections\n"
10071 "Neighbor to display information about\n"
10072 "Neighbor to display information about\n"
10073 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +000010074
10075DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
10076 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
10077 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10078 SHOW_STR
10079 IP_STR
10080 BGP_STR
10081 "Address family\n"
10082 "Address Family modifier\n"
10083 "Address Family modifier\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{
paulbb46e942003-10-24 19:02:03 +000010089 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010090
paulbb46e942003-10-24 19:02:03 +000010091 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10092 if (! peer)
10093 return CMD_WARNING;
10094
10095 if (strncmp (argv[0], "m", 1) == 0)
10096 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
10097
10098 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +000010099}
10100
10101#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010102DEFUN (show_bgp_view_neighbor_advertised_route,
10103 show_bgp_view_neighbor_advertised_route_cmd,
10104 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10105 SHOW_STR
10106 BGP_STR
10107 "BGP view\n"
10108 "View name\n"
10109 "Detailed information on TCP and BGP neighbor connections\n"
10110 "Neighbor to display information about\n"
10111 "Neighbor to display information about\n"
10112 "Display the routes advertised to a BGP neighbor\n")
10113{
10114 struct peer *peer;
10115
10116 if (argc == 2)
10117 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10118 else
10119 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10120
10121 if (! peer)
10122 return CMD_WARNING;
10123
10124 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10125}
10126
10127ALIAS (show_bgp_view_neighbor_advertised_route,
10128 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10129 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10130 SHOW_STR
10131 BGP_STR
10132 "BGP view\n"
10133 "View name\n"
10134 "Address family\n"
10135 "Detailed information on TCP and BGP neighbor connections\n"
10136 "Neighbor to display information about\n"
10137 "Neighbor to display information about\n"
10138 "Display the routes advertised to a BGP neighbor\n")
10139
10140DEFUN (show_bgp_view_neighbor_received_routes,
10141 show_bgp_view_neighbor_received_routes_cmd,
10142 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10143 SHOW_STR
10144 BGP_STR
10145 "BGP view\n"
10146 "View name\n"
10147 "Detailed information on TCP and BGP neighbor connections\n"
10148 "Neighbor to display information about\n"
10149 "Neighbor to display information about\n"
10150 "Display the received routes from neighbor\n")
10151{
10152 struct peer *peer;
10153
10154 if (argc == 2)
10155 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10156 else
10157 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10158
10159 if (! peer)
10160 return CMD_WARNING;
10161
10162 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10163}
10164
10165ALIAS (show_bgp_view_neighbor_received_routes,
10166 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10167 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10168 SHOW_STR
10169 BGP_STR
10170 "BGP view\n"
10171 "View name\n"
10172 "Address family\n"
10173 "Detailed information on TCP and BGP neighbor connections\n"
10174 "Neighbor to display information about\n"
10175 "Neighbor to display information about\n"
10176 "Display the received routes from neighbor\n")
10177
10178ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010179 show_bgp_neighbor_advertised_route_cmd,
10180 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10181 SHOW_STR
10182 BGP_STR
10183 "Detailed information on TCP and BGP neighbor connections\n"
10184 "Neighbor to display information about\n"
10185 "Neighbor to display information about\n"
10186 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010187
10188ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010189 show_bgp_ipv6_neighbor_advertised_route_cmd,
10190 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10191 SHOW_STR
10192 BGP_STR
10193 "Address family\n"
10194 "Detailed information on TCP and BGP neighbor connections\n"
10195 "Neighbor to display information about\n"
10196 "Neighbor to display information about\n"
10197 "Display the routes advertised to a BGP neighbor\n")
10198
10199/* old command */
paulbb46e942003-10-24 19:02:03 +000010200ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010201 ipv6_bgp_neighbor_advertised_route_cmd,
10202 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10203 SHOW_STR
10204 IPV6_STR
10205 BGP_STR
10206 "Detailed information on TCP and BGP neighbor connections\n"
10207 "Neighbor to display information about\n"
10208 "Neighbor to display information about\n"
10209 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010210
paul718e3742002-12-13 20:15:29 +000010211/* old command */
10212DEFUN (ipv6_mbgp_neighbor_advertised_route,
10213 ipv6_mbgp_neighbor_advertised_route_cmd,
10214 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10215 SHOW_STR
10216 IPV6_STR
10217 MBGP_STR
10218 "Detailed information on TCP and BGP neighbor connections\n"
10219 "Neighbor to display information about\n"
10220 "Neighbor to display information about\n"
10221 "Display the routes advertised to a BGP neighbor\n")
10222{
paulbb46e942003-10-24 19:02:03 +000010223 struct peer *peer;
10224
10225 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10226 if (! peer)
10227 return CMD_WARNING;
10228
10229 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010230}
10231#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010232
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010233DEFUN (show_ip_bgp_view_neighbor_received_routes,
10234 show_ip_bgp_view_neighbor_received_routes_cmd,
10235 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10236 SHOW_STR
10237 IP_STR
10238 BGP_STR
10239 "BGP view\n"
10240 "View name\n"
10241 "Detailed information on TCP and BGP neighbor connections\n"
10242 "Neighbor to display information about\n"
10243 "Neighbor to display information about\n"
10244 "Display the received routes from neighbor\n")
10245{
10246 struct peer *peer;
10247
10248 if (argc == 2)
10249 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10250 else
10251 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10252
10253 if (! peer)
10254 return CMD_WARNING;
10255
10256 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10257}
10258
10259ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010260 show_ip_bgp_neighbor_received_routes_cmd,
10261 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10262 SHOW_STR
10263 IP_STR
10264 BGP_STR
10265 "Detailed information on TCP and BGP neighbor connections\n"
10266 "Neighbor to display information about\n"
10267 "Neighbor to display information about\n"
10268 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010269
10270DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10271 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10272 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10273 SHOW_STR
10274 IP_STR
10275 BGP_STR
10276 "Address family\n"
10277 "Address Family modifier\n"
10278 "Address Family modifier\n"
10279 "Detailed information on TCP and BGP neighbor connections\n"
10280 "Neighbor to display information about\n"
10281 "Neighbor to display information about\n"
10282 "Display the received routes from neighbor\n")
10283{
paulbb46e942003-10-24 19:02:03 +000010284 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010285
paulbb46e942003-10-24 19:02:03 +000010286 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10287 if (! peer)
10288 return CMD_WARNING;
10289
10290 if (strncmp (argv[0], "m", 1) == 0)
10291 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10292
10293 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010294}
10295
Michael Lambert95cbbd22010-07-23 14:43:04 -040010296DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10297 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010298 "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 -040010299 SHOW_STR
10300 BGP_STR
10301 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010302 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010303 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010304 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010305 "Address family modifier\n"
10306 "Address family modifier\n"
10307 "Detailed information on TCP and BGP neighbor connections\n"
10308 "Neighbor to display information about\n"
10309 "Neighbor to display information about\n"
10310 "Display the advertised routes to neighbor\n"
10311 "Display the received routes from neighbor\n")
10312{
10313 int afi;
10314 int safi;
10315 int in;
10316 struct peer *peer;
10317
David Lamparter94bad672015-03-03 08:52:22 +010010318 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010319
10320 if (! peer)
10321 return CMD_WARNING;
10322
Michael Lambert95cbbd22010-07-23 14:43:04 -040010323 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10324 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10325 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010326
10327 return peer_adj_routes (vty, peer, afi, safi, in);
10328}
10329
paul718e3742002-12-13 20:15:29 +000010330DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10331 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10332 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10333 SHOW_STR
10334 IP_STR
10335 BGP_STR
10336 "Detailed information on TCP and BGP neighbor connections\n"
10337 "Neighbor to display information about\n"
10338 "Neighbor to display information about\n"
10339 "Display information received from a BGP neighbor\n"
10340 "Display the prefixlist filter\n")
10341{
10342 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010343 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010344 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010345 int count, ret;
paul718e3742002-12-13 20:15:29 +000010346
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010347 ret = str2sockunion (argv[0], &su);
10348 if (ret < 0)
10349 {
10350 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10351 return CMD_WARNING;
10352 }
paul718e3742002-12-13 20:15:29 +000010353
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010354 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010355 if (! peer)
10356 return CMD_WARNING;
10357
10358 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10359 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10360 if (count)
10361 {
10362 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10363 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10364 }
10365
10366 return CMD_SUCCESS;
10367}
10368
10369DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10370 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10371 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10372 SHOW_STR
10373 IP_STR
10374 BGP_STR
10375 "Address family\n"
10376 "Address Family modifier\n"
10377 "Address Family modifier\n"
10378 "Detailed information on TCP and BGP neighbor connections\n"
10379 "Neighbor to display information about\n"
10380 "Neighbor to display information about\n"
10381 "Display information received from a BGP neighbor\n"
10382 "Display the prefixlist filter\n")
10383{
10384 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010385 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010386 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010387 int count, ret;
paul718e3742002-12-13 20:15:29 +000010388
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010389 ret = str2sockunion (argv[1], &su);
10390 if (ret < 0)
10391 {
10392 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10393 return CMD_WARNING;
10394 }
paul718e3742002-12-13 20:15:29 +000010395
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010396 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010397 if (! peer)
10398 return CMD_WARNING;
10399
10400 if (strncmp (argv[0], "m", 1) == 0)
10401 {
10402 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10403 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10404 if (count)
10405 {
10406 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10407 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10408 }
10409 }
10410 else
10411 {
10412 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10413 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10414 if (count)
10415 {
10416 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10417 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10418 }
10419 }
10420
10421 return CMD_SUCCESS;
10422}
10423
10424
10425#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010426ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010427 show_bgp_neighbor_received_routes_cmd,
10428 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10429 SHOW_STR
10430 BGP_STR
10431 "Detailed information on TCP and BGP neighbor connections\n"
10432 "Neighbor to display information about\n"
10433 "Neighbor to display information about\n"
10434 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010435
paulbb46e942003-10-24 19:02:03 +000010436ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010437 show_bgp_ipv6_neighbor_received_routes_cmd,
10438 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10439 SHOW_STR
10440 BGP_STR
10441 "Address family\n"
10442 "Detailed information on TCP and BGP neighbor connections\n"
10443 "Neighbor to display information about\n"
10444 "Neighbor to display information about\n"
10445 "Display the received routes from neighbor\n")
10446
10447DEFUN (show_bgp_neighbor_received_prefix_filter,
10448 show_bgp_neighbor_received_prefix_filter_cmd,
10449 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10450 SHOW_STR
10451 BGP_STR
10452 "Detailed information on TCP and BGP neighbor connections\n"
10453 "Neighbor to display information about\n"
10454 "Neighbor to display information about\n"
10455 "Display information received from a BGP neighbor\n"
10456 "Display the prefixlist filter\n")
10457{
10458 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010459 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010460 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010461 int count, ret;
paul718e3742002-12-13 20:15:29 +000010462
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010463 ret = str2sockunion (argv[0], &su);
10464 if (ret < 0)
10465 {
10466 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10467 return CMD_WARNING;
10468 }
paul718e3742002-12-13 20:15:29 +000010469
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010470 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010471 if (! peer)
10472 return CMD_WARNING;
10473
10474 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10475 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10476 if (count)
10477 {
10478 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10479 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10480 }
10481
10482 return CMD_SUCCESS;
10483}
10484
10485ALIAS (show_bgp_neighbor_received_prefix_filter,
10486 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10487 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10488 SHOW_STR
10489 BGP_STR
10490 "Address family\n"
10491 "Detailed information on TCP and BGP neighbor connections\n"
10492 "Neighbor to display information about\n"
10493 "Neighbor to display information about\n"
10494 "Display information received from a BGP neighbor\n"
10495 "Display the prefixlist filter\n")
10496
10497/* old command */
paulbb46e942003-10-24 19:02:03 +000010498ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010499 ipv6_bgp_neighbor_received_routes_cmd,
10500 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10501 SHOW_STR
10502 IPV6_STR
10503 BGP_STR
10504 "Detailed information on TCP and BGP neighbor connections\n"
10505 "Neighbor to display information about\n"
10506 "Neighbor to display information about\n"
10507 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010508
10509/* old command */
10510DEFUN (ipv6_mbgp_neighbor_received_routes,
10511 ipv6_mbgp_neighbor_received_routes_cmd,
10512 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10513 SHOW_STR
10514 IPV6_STR
10515 MBGP_STR
10516 "Detailed information on TCP and BGP neighbor connections\n"
10517 "Neighbor to display information about\n"
10518 "Neighbor to display information about\n"
10519 "Display the received routes from neighbor\n")
10520{
paulbb46e942003-10-24 19:02:03 +000010521 struct peer *peer;
10522
10523 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10524 if (! peer)
10525 return CMD_WARNING;
10526
10527 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010528}
paulbb46e942003-10-24 19:02:03 +000010529
10530DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10531 show_bgp_view_neighbor_received_prefix_filter_cmd,
10532 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10533 SHOW_STR
10534 BGP_STR
10535 "BGP view\n"
10536 "View name\n"
10537 "Detailed information on TCP and BGP neighbor connections\n"
10538 "Neighbor to display information about\n"
10539 "Neighbor to display information about\n"
10540 "Display information received from a BGP neighbor\n"
10541 "Display the prefixlist filter\n")
10542{
10543 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010544 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010545 struct peer *peer;
10546 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010547 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010548
10549 /* BGP structure lookup. */
10550 bgp = bgp_lookup_by_name (argv[0]);
10551 if (bgp == NULL)
10552 {
10553 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10554 return CMD_WARNING;
10555 }
10556
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010557 ret = str2sockunion (argv[1], &su);
10558 if (ret < 0)
10559 {
10560 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10561 return CMD_WARNING;
10562 }
paulbb46e942003-10-24 19:02:03 +000010563
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010564 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010565 if (! peer)
10566 return CMD_WARNING;
10567
10568 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10569 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10570 if (count)
10571 {
10572 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10573 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10574 }
10575
10576 return CMD_SUCCESS;
10577}
10578
10579ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10580 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10581 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10582 SHOW_STR
10583 BGP_STR
10584 "BGP view\n"
10585 "View name\n"
10586 "Address family\n"
10587 "Detailed information on TCP and BGP neighbor connections\n"
10588 "Neighbor to display information about\n"
10589 "Neighbor to display information about\n"
10590 "Display information received from a BGP neighbor\n"
10591 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010592#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010593
paul94f2b392005-06-28 12:44:16 +000010594static int
paulbb46e942003-10-24 19:02:03 +000010595bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010596 safi_t safi, enum bgp_show_type type)
10597{
paul718e3742002-12-13 20:15:29 +000010598 if (! peer || ! peer->afc[afi][safi])
10599 {
10600 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010601 return CMD_WARNING;
10602 }
10603
ajs5a646652004-11-05 01:25:55 +000010604 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010605}
10606
10607DEFUN (show_ip_bgp_neighbor_routes,
10608 show_ip_bgp_neighbor_routes_cmd,
10609 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10610 SHOW_STR
10611 IP_STR
10612 BGP_STR
10613 "Detailed information on TCP and BGP neighbor connections\n"
10614 "Neighbor to display information about\n"
10615 "Neighbor to display information about\n"
10616 "Display routes learned from neighbor\n")
10617{
paulbb46e942003-10-24 19:02:03 +000010618 struct peer *peer;
10619
10620 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10621 if (! peer)
10622 return CMD_WARNING;
10623
10624 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010625 bgp_show_type_neighbor);
10626}
10627
10628DEFUN (show_ip_bgp_neighbor_flap,
10629 show_ip_bgp_neighbor_flap_cmd,
10630 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10631 SHOW_STR
10632 IP_STR
10633 BGP_STR
10634 "Detailed information on TCP and BGP neighbor connections\n"
10635 "Neighbor to display information about\n"
10636 "Neighbor to display information about\n"
10637 "Display flap statistics of the routes learned from neighbor\n")
10638{
paulbb46e942003-10-24 19:02:03 +000010639 struct peer *peer;
10640
10641 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10642 if (! peer)
10643 return CMD_WARNING;
10644
10645 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010646 bgp_show_type_flap_neighbor);
10647}
10648
10649DEFUN (show_ip_bgp_neighbor_damp,
10650 show_ip_bgp_neighbor_damp_cmd,
10651 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10652 SHOW_STR
10653 IP_STR
10654 BGP_STR
10655 "Detailed information on TCP and BGP neighbor connections\n"
10656 "Neighbor to display information about\n"
10657 "Neighbor to display information about\n"
10658 "Display the dampened routes received from neighbor\n")
10659{
paulbb46e942003-10-24 19:02:03 +000010660 struct peer *peer;
10661
10662 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10663 if (! peer)
10664 return CMD_WARNING;
10665
10666 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010667 bgp_show_type_damp_neighbor);
10668}
10669
10670DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10671 show_ip_bgp_ipv4_neighbor_routes_cmd,
10672 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10673 SHOW_STR
10674 IP_STR
10675 BGP_STR
10676 "Address family\n"
10677 "Address Family modifier\n"
10678 "Address Family modifier\n"
10679 "Detailed information on TCP and BGP neighbor connections\n"
10680 "Neighbor to display information about\n"
10681 "Neighbor to display information about\n"
10682 "Display routes learned from neighbor\n")
10683{
paulbb46e942003-10-24 19:02:03 +000010684 struct peer *peer;
10685
10686 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10687 if (! peer)
10688 return CMD_WARNING;
10689
paul718e3742002-12-13 20:15:29 +000010690 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010691 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010692 bgp_show_type_neighbor);
10693
paulbb46e942003-10-24 19:02:03 +000010694 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010695 bgp_show_type_neighbor);
10696}
paulbb46e942003-10-24 19:02:03 +000010697
paulfee0f4c2004-09-13 05:12:46 +000010698DEFUN (show_ip_bgp_view_rsclient,
10699 show_ip_bgp_view_rsclient_cmd,
10700 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10701 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{
10709 struct bgp_table *table;
10710 struct peer *peer;
10711
10712 if (argc == 2)
10713 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10714 else
10715 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10716
10717 if (! peer)
10718 return CMD_WARNING;
10719
10720 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10721 {
10722 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10723 VTY_NEWLINE);
10724 return CMD_WARNING;
10725 }
10726
10727 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10728 PEER_FLAG_RSERVER_CLIENT))
10729 {
10730 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10731 VTY_NEWLINE);
10732 return CMD_WARNING;
10733 }
10734
10735 table = peer->rib[AFI_IP][SAFI_UNICAST];
10736
ajs5a646652004-11-05 01:25:55 +000010737 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010738}
10739
10740ALIAS (show_ip_bgp_view_rsclient,
10741 show_ip_bgp_rsclient_cmd,
10742 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10743 SHOW_STR
10744 IP_STR
10745 BGP_STR
10746 "Information about Route Server Client\n"
10747 NEIGHBOR_ADDR_STR)
10748
Michael Lambert95cbbd22010-07-23 14:43:04 -040010749DEFUN (show_bgp_view_ipv4_safi_rsclient,
10750 show_bgp_view_ipv4_safi_rsclient_cmd,
10751 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10752 SHOW_STR
10753 BGP_STR
10754 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010755 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010756 "Address family\n"
10757 "Address Family modifier\n"
10758 "Address Family modifier\n"
10759 "Information about Route Server Client\n"
10760 NEIGHBOR_ADDR_STR)
10761{
10762 struct bgp_table *table;
10763 struct peer *peer;
10764 safi_t safi;
10765
10766 if (argc == 3) {
10767 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10768 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10769 } else {
10770 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10771 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10772 }
10773
10774 if (! peer)
10775 return CMD_WARNING;
10776
10777 if (! peer->afc[AFI_IP][safi])
10778 {
10779 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10780 VTY_NEWLINE);
10781 return CMD_WARNING;
10782 }
10783
10784 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10785 PEER_FLAG_RSERVER_CLIENT))
10786 {
10787 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10788 VTY_NEWLINE);
10789 return CMD_WARNING;
10790 }
10791
10792 table = peer->rib[AFI_IP][safi];
10793
10794 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10795}
10796
10797ALIAS (show_bgp_view_ipv4_safi_rsclient,
10798 show_bgp_ipv4_safi_rsclient_cmd,
10799 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10800 SHOW_STR
10801 BGP_STR
10802 "Address family\n"
10803 "Address Family modifier\n"
10804 "Address Family modifier\n"
10805 "Information about Route Server Client\n"
10806 NEIGHBOR_ADDR_STR)
10807
paulfee0f4c2004-09-13 05:12:46 +000010808DEFUN (show_ip_bgp_view_rsclient_route,
10809 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010810 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010811 SHOW_STR
10812 IP_STR
10813 BGP_STR
10814 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010815 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010816 "Information about Route Server Client\n"
10817 NEIGHBOR_ADDR_STR
10818 "Network in the BGP routing table to display\n")
10819{
10820 struct bgp *bgp;
10821 struct peer *peer;
10822
10823 /* BGP structure lookup. */
10824 if (argc == 3)
10825 {
10826 bgp = bgp_lookup_by_name (argv[0]);
10827 if (bgp == NULL)
10828 {
10829 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10830 return CMD_WARNING;
10831 }
10832 }
10833 else
10834 {
10835 bgp = bgp_get_default ();
10836 if (bgp == NULL)
10837 {
10838 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10839 return CMD_WARNING;
10840 }
10841 }
10842
10843 if (argc == 3)
10844 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10845 else
10846 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10847
10848 if (! peer)
10849 return CMD_WARNING;
10850
10851 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10852 {
10853 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10854 VTY_NEWLINE);
10855 return CMD_WARNING;
10856}
10857
10858 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10859 PEER_FLAG_RSERVER_CLIENT))
10860 {
10861 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10862 VTY_NEWLINE);
10863 return CMD_WARNING;
10864 }
10865
10866 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10867 (argc == 3) ? argv[2] : argv[1],
10868 AFI_IP, SAFI_UNICAST, NULL, 0);
10869}
10870
10871ALIAS (show_ip_bgp_view_rsclient_route,
10872 show_ip_bgp_rsclient_route_cmd,
10873 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10874 SHOW_STR
10875 IP_STR
10876 BGP_STR
10877 "Information about Route Server Client\n"
10878 NEIGHBOR_ADDR_STR
10879 "Network in the BGP routing table to display\n")
10880
Michael Lambert95cbbd22010-07-23 14:43:04 -040010881DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10882 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10883 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10884 SHOW_STR
10885 BGP_STR
10886 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010887 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010888 "Address family\n"
10889 "Address Family modifier\n"
10890 "Address Family modifier\n"
10891 "Information about Route Server Client\n"
10892 NEIGHBOR_ADDR_STR
10893 "Network in the BGP routing table to display\n")
10894{
10895 struct bgp *bgp;
10896 struct peer *peer;
10897 safi_t safi;
10898
10899 /* BGP structure lookup. */
10900 if (argc == 4)
10901 {
10902 bgp = bgp_lookup_by_name (argv[0]);
10903 if (bgp == NULL)
10904 {
10905 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10906 return CMD_WARNING;
10907 }
10908 }
10909 else
10910 {
10911 bgp = bgp_get_default ();
10912 if (bgp == NULL)
10913 {
10914 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10915 return CMD_WARNING;
10916 }
10917 }
10918
10919 if (argc == 4) {
10920 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10921 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10922 } else {
10923 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10924 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10925 }
10926
10927 if (! peer)
10928 return CMD_WARNING;
10929
10930 if (! peer->afc[AFI_IP][safi])
10931 {
10932 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10933 VTY_NEWLINE);
10934 return CMD_WARNING;
10935}
10936
10937 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10938 PEER_FLAG_RSERVER_CLIENT))
10939 {
10940 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10941 VTY_NEWLINE);
10942 return CMD_WARNING;
10943 }
10944
10945 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10946 (argc == 4) ? argv[3] : argv[2],
10947 AFI_IP, safi, NULL, 0);
10948}
10949
10950ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10951 show_bgp_ipv4_safi_rsclient_route_cmd,
10952 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10953 SHOW_STR
10954 BGP_STR
10955 "Address family\n"
10956 "Address Family modifier\n"
10957 "Address Family modifier\n"
10958 "Information about Route Server Client\n"
10959 NEIGHBOR_ADDR_STR
10960 "Network in the BGP routing table to display\n")
10961
paulfee0f4c2004-09-13 05:12:46 +000010962DEFUN (show_ip_bgp_view_rsclient_prefix,
10963 show_ip_bgp_view_rsclient_prefix_cmd,
10964 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10965 SHOW_STR
10966 IP_STR
10967 BGP_STR
10968 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010969 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010970 "Information about Route Server Client\n"
10971 NEIGHBOR_ADDR_STR
10972 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10973{
10974 struct bgp *bgp;
10975 struct peer *peer;
10976
10977 /* BGP structure lookup. */
10978 if (argc == 3)
10979 {
10980 bgp = bgp_lookup_by_name (argv[0]);
10981 if (bgp == NULL)
10982 {
10983 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10984 return CMD_WARNING;
10985 }
10986 }
10987 else
10988 {
10989 bgp = bgp_get_default ();
10990 if (bgp == NULL)
10991 {
10992 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10993 return CMD_WARNING;
10994 }
10995 }
10996
10997 if (argc == 3)
10998 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10999 else
11000 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11001
11002 if (! peer)
11003 return CMD_WARNING;
11004
11005 if (! peer->afc[AFI_IP][SAFI_UNICAST])
11006 {
11007 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11008 VTY_NEWLINE);
11009 return CMD_WARNING;
11010}
11011
11012 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
11013 PEER_FLAG_RSERVER_CLIENT))
11014{
11015 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11016 VTY_NEWLINE);
11017 return CMD_WARNING;
11018 }
11019
11020 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
11021 (argc == 3) ? argv[2] : argv[1],
11022 AFI_IP, SAFI_UNICAST, NULL, 1);
11023}
11024
11025ALIAS (show_ip_bgp_view_rsclient_prefix,
11026 show_ip_bgp_rsclient_prefix_cmd,
11027 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11028 SHOW_STR
11029 IP_STR
11030 BGP_STR
11031 "Information about Route Server Client\n"
11032 NEIGHBOR_ADDR_STR
11033 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11034
Michael Lambert95cbbd22010-07-23 14:43:04 -040011035DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
11036 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
11037 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11038 SHOW_STR
11039 BGP_STR
11040 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011041 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011042 "Address family\n"
11043 "Address Family modifier\n"
11044 "Address Family modifier\n"
11045 "Information about Route Server Client\n"
11046 NEIGHBOR_ADDR_STR
11047 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11048{
11049 struct bgp *bgp;
11050 struct peer *peer;
11051 safi_t safi;
11052
11053 /* BGP structure lookup. */
11054 if (argc == 4)
11055 {
11056 bgp = bgp_lookup_by_name (argv[0]);
11057 if (bgp == NULL)
11058 {
11059 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11060 return CMD_WARNING;
11061 }
11062 }
11063 else
11064 {
11065 bgp = bgp_get_default ();
11066 if (bgp == NULL)
11067 {
11068 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11069 return CMD_WARNING;
11070 }
11071 }
11072
11073 if (argc == 4) {
11074 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11075 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11076 } else {
11077 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11078 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11079 }
11080
11081 if (! peer)
11082 return CMD_WARNING;
11083
11084 if (! peer->afc[AFI_IP][safi])
11085 {
11086 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11087 VTY_NEWLINE);
11088 return CMD_WARNING;
11089}
11090
11091 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11092 PEER_FLAG_RSERVER_CLIENT))
11093{
11094 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11095 VTY_NEWLINE);
11096 return CMD_WARNING;
11097 }
11098
11099 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11100 (argc == 4) ? argv[3] : argv[2],
11101 AFI_IP, safi, NULL, 1);
11102}
11103
11104ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11105 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11106 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11107 SHOW_STR
11108 BGP_STR
11109 "Address family\n"
11110 "Address Family modifier\n"
11111 "Address Family modifier\n"
11112 "Information about Route Server Client\n"
11113 NEIGHBOR_ADDR_STR
11114 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011115
paul718e3742002-12-13 20:15:29 +000011116#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011117DEFUN (show_bgp_view_neighbor_routes,
11118 show_bgp_view_neighbor_routes_cmd,
11119 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11120 SHOW_STR
11121 BGP_STR
11122 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011123 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011124 "Detailed information on TCP and BGP neighbor connections\n"
11125 "Neighbor to display information about\n"
11126 "Neighbor to display information about\n"
11127 "Display routes learned from neighbor\n")
11128{
11129 struct peer *peer;
11130
11131 if (argc == 2)
11132 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11133 else
11134 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11135
11136 if (! peer)
11137 return CMD_WARNING;
11138
11139 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11140 bgp_show_type_neighbor);
11141}
11142
11143ALIAS (show_bgp_view_neighbor_routes,
11144 show_bgp_view_ipv6_neighbor_routes_cmd,
11145 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11146 SHOW_STR
11147 BGP_STR
11148 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011149 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011150 "Address family\n"
11151 "Detailed information on TCP and BGP neighbor connections\n"
11152 "Neighbor to display information about\n"
11153 "Neighbor to display information about\n"
11154 "Display routes learned from neighbor\n")
11155
11156DEFUN (show_bgp_view_neighbor_damp,
11157 show_bgp_view_neighbor_damp_cmd,
11158 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11159 SHOW_STR
11160 BGP_STR
11161 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011162 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011163 "Detailed information on TCP and BGP neighbor connections\n"
11164 "Neighbor to display information about\n"
11165 "Neighbor to display information about\n"
11166 "Display the dampened routes received from neighbor\n")
11167{
11168 struct peer *peer;
11169
11170 if (argc == 2)
11171 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11172 else
11173 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11174
11175 if (! peer)
11176 return CMD_WARNING;
11177
11178 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11179 bgp_show_type_damp_neighbor);
11180}
11181
11182ALIAS (show_bgp_view_neighbor_damp,
11183 show_bgp_view_ipv6_neighbor_damp_cmd,
11184 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11185 SHOW_STR
11186 BGP_STR
11187 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011188 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011189 "Address family\n"
11190 "Detailed information on TCP and BGP neighbor connections\n"
11191 "Neighbor to display information about\n"
11192 "Neighbor to display information about\n"
11193 "Display the dampened routes received from neighbor\n")
11194
11195DEFUN (show_bgp_view_neighbor_flap,
11196 show_bgp_view_neighbor_flap_cmd,
11197 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11198 SHOW_STR
11199 BGP_STR
11200 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011201 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011202 "Detailed information on TCP and BGP neighbor connections\n"
11203 "Neighbor to display information about\n"
11204 "Neighbor to display information about\n"
11205 "Display flap statistics of the routes learned from neighbor\n")
11206{
11207 struct peer *peer;
11208
11209 if (argc == 2)
11210 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11211 else
11212 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11213
11214 if (! peer)
11215 return CMD_WARNING;
11216
11217 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11218 bgp_show_type_flap_neighbor);
11219}
11220
11221ALIAS (show_bgp_view_neighbor_flap,
11222 show_bgp_view_ipv6_neighbor_flap_cmd,
11223 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11224 SHOW_STR
11225 BGP_STR
11226 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011227 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011228 "Address family\n"
11229 "Detailed information on TCP and BGP neighbor connections\n"
11230 "Neighbor to display information about\n"
11231 "Neighbor to display information about\n"
11232 "Display flap statistics of the routes learned from neighbor\n")
11233
11234ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011235 show_bgp_neighbor_routes_cmd,
11236 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11237 SHOW_STR
11238 BGP_STR
11239 "Detailed information on TCP and BGP neighbor connections\n"
11240 "Neighbor to display information about\n"
11241 "Neighbor to display information about\n"
11242 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011243
paulbb46e942003-10-24 19:02:03 +000011244
11245ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011246 show_bgp_ipv6_neighbor_routes_cmd,
11247 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11248 SHOW_STR
11249 BGP_STR
11250 "Address family\n"
11251 "Detailed information on TCP and BGP neighbor connections\n"
11252 "Neighbor to display information about\n"
11253 "Neighbor to display information about\n"
11254 "Display routes learned from neighbor\n")
11255
11256/* old command */
paulbb46e942003-10-24 19:02:03 +000011257ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011258 ipv6_bgp_neighbor_routes_cmd,
11259 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11260 SHOW_STR
11261 IPV6_STR
11262 BGP_STR
11263 "Detailed information on TCP and BGP neighbor connections\n"
11264 "Neighbor to display information about\n"
11265 "Neighbor to display information about\n"
11266 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011267
11268/* old command */
11269DEFUN (ipv6_mbgp_neighbor_routes,
11270 ipv6_mbgp_neighbor_routes_cmd,
11271 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11272 SHOW_STR
11273 IPV6_STR
11274 MBGP_STR
11275 "Detailed information on TCP and BGP neighbor connections\n"
11276 "Neighbor to display information about\n"
11277 "Neighbor to display information about\n"
11278 "Display routes learned from neighbor\n")
11279{
paulbb46e942003-10-24 19:02:03 +000011280 struct peer *peer;
11281
11282 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11283 if (! peer)
11284 return CMD_WARNING;
11285
11286 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011287 bgp_show_type_neighbor);
11288}
paulbb46e942003-10-24 19:02:03 +000011289
11290ALIAS (show_bgp_view_neighbor_flap,
11291 show_bgp_neighbor_flap_cmd,
11292 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11293 SHOW_STR
11294 BGP_STR
11295 "Detailed information on TCP and BGP neighbor connections\n"
11296 "Neighbor to display information about\n"
11297 "Neighbor to display information about\n"
11298 "Display flap statistics of the routes learned from neighbor\n")
11299
11300ALIAS (show_bgp_view_neighbor_flap,
11301 show_bgp_ipv6_neighbor_flap_cmd,
11302 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11303 SHOW_STR
11304 BGP_STR
11305 "Address family\n"
11306 "Detailed information on TCP and BGP neighbor connections\n"
11307 "Neighbor to display information about\n"
11308 "Neighbor to display information about\n"
11309 "Display flap statistics of the routes learned from neighbor\n")
11310
11311ALIAS (show_bgp_view_neighbor_damp,
11312 show_bgp_neighbor_damp_cmd,
11313 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11314 SHOW_STR
11315 BGP_STR
11316 "Detailed information on TCP and BGP neighbor connections\n"
11317 "Neighbor to display information about\n"
11318 "Neighbor to display information about\n"
11319 "Display the dampened routes received from neighbor\n")
11320
11321ALIAS (show_bgp_view_neighbor_damp,
11322 show_bgp_ipv6_neighbor_damp_cmd,
11323 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11324 SHOW_STR
11325 BGP_STR
11326 "Address family\n"
11327 "Detailed information on TCP and BGP neighbor connections\n"
11328 "Neighbor to display information about\n"
11329 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011330 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011331
11332DEFUN (show_bgp_view_rsclient,
11333 show_bgp_view_rsclient_cmd,
11334 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11335 SHOW_STR
11336 BGP_STR
11337 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011338 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011339 "Information about Route Server Client\n"
11340 NEIGHBOR_ADDR_STR)
11341{
11342 struct bgp_table *table;
11343 struct peer *peer;
11344
11345 if (argc == 2)
11346 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11347 else
11348 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11349
11350 if (! peer)
11351 return CMD_WARNING;
11352
11353 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11354 {
11355 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11356 VTY_NEWLINE);
11357 return CMD_WARNING;
11358 }
11359
11360 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11361 PEER_FLAG_RSERVER_CLIENT))
11362 {
11363 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11364 VTY_NEWLINE);
11365 return CMD_WARNING;
11366 }
11367
11368 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11369
ajs5a646652004-11-05 01:25:55 +000011370 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011371}
11372
11373ALIAS (show_bgp_view_rsclient,
11374 show_bgp_rsclient_cmd,
11375 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11376 SHOW_STR
11377 BGP_STR
11378 "Information about Route Server Client\n"
11379 NEIGHBOR_ADDR_STR)
11380
Michael Lambert95cbbd22010-07-23 14:43:04 -040011381DEFUN (show_bgp_view_ipv6_safi_rsclient,
11382 show_bgp_view_ipv6_safi_rsclient_cmd,
11383 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11384 SHOW_STR
11385 BGP_STR
11386 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011387 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011388 "Address family\n"
11389 "Address Family modifier\n"
11390 "Address Family modifier\n"
11391 "Information about Route Server Client\n"
11392 NEIGHBOR_ADDR_STR)
11393{
11394 struct bgp_table *table;
11395 struct peer *peer;
11396 safi_t safi;
11397
11398 if (argc == 3) {
11399 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11400 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11401 } else {
11402 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11403 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11404 }
11405
11406 if (! peer)
11407 return CMD_WARNING;
11408
11409 if (! peer->afc[AFI_IP6][safi])
11410 {
11411 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11412 VTY_NEWLINE);
11413 return CMD_WARNING;
11414 }
11415
11416 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11417 PEER_FLAG_RSERVER_CLIENT))
11418 {
11419 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11420 VTY_NEWLINE);
11421 return CMD_WARNING;
11422 }
11423
11424 table = peer->rib[AFI_IP6][safi];
11425
11426 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11427}
11428
11429ALIAS (show_bgp_view_ipv6_safi_rsclient,
11430 show_bgp_ipv6_safi_rsclient_cmd,
11431 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11432 SHOW_STR
11433 BGP_STR
11434 "Address family\n"
11435 "Address Family modifier\n"
11436 "Address Family modifier\n"
11437 "Information about Route Server Client\n"
11438 NEIGHBOR_ADDR_STR)
11439
paulfee0f4c2004-09-13 05:12:46 +000011440DEFUN (show_bgp_view_rsclient_route,
11441 show_bgp_view_rsclient_route_cmd,
11442 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11443 SHOW_STR
11444 BGP_STR
11445 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011446 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011447 "Information about Route Server Client\n"
11448 NEIGHBOR_ADDR_STR
11449 "Network in the BGP routing table to display\n")
11450{
11451 struct bgp *bgp;
11452 struct peer *peer;
11453
11454 /* BGP structure lookup. */
11455 if (argc == 3)
11456 {
11457 bgp = bgp_lookup_by_name (argv[0]);
11458 if (bgp == NULL)
11459 {
11460 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11461 return CMD_WARNING;
11462 }
11463 }
11464 else
11465 {
11466 bgp = bgp_get_default ();
11467 if (bgp == NULL)
11468 {
11469 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11470 return CMD_WARNING;
11471 }
11472 }
11473
11474 if (argc == 3)
11475 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11476 else
11477 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11478
11479 if (! peer)
11480 return CMD_WARNING;
11481
11482 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11483 {
11484 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11485 VTY_NEWLINE);
11486 return CMD_WARNING;
11487 }
11488
11489 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11490 PEER_FLAG_RSERVER_CLIENT))
11491 {
11492 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11493 VTY_NEWLINE);
11494 return CMD_WARNING;
11495 }
11496
11497 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11498 (argc == 3) ? argv[2] : argv[1],
11499 AFI_IP6, SAFI_UNICAST, NULL, 0);
11500}
11501
11502ALIAS (show_bgp_view_rsclient_route,
11503 show_bgp_rsclient_route_cmd,
11504 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11505 SHOW_STR
11506 BGP_STR
11507 "Information about Route Server Client\n"
11508 NEIGHBOR_ADDR_STR
11509 "Network in the BGP routing table to display\n")
11510
Michael Lambert95cbbd22010-07-23 14:43:04 -040011511DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11512 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11513 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11514 SHOW_STR
11515 BGP_STR
11516 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011517 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011518 "Address family\n"
11519 "Address Family modifier\n"
11520 "Address Family modifier\n"
11521 "Information about Route Server Client\n"
11522 NEIGHBOR_ADDR_STR
11523 "Network in the BGP routing table to display\n")
11524{
11525 struct bgp *bgp;
11526 struct peer *peer;
11527 safi_t safi;
11528
11529 /* BGP structure lookup. */
11530 if (argc == 4)
11531 {
11532 bgp = bgp_lookup_by_name (argv[0]);
11533 if (bgp == NULL)
11534 {
11535 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11536 return CMD_WARNING;
11537 }
11538 }
11539 else
11540 {
11541 bgp = bgp_get_default ();
11542 if (bgp == NULL)
11543 {
11544 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11545 return CMD_WARNING;
11546 }
11547 }
11548
11549 if (argc == 4) {
11550 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11551 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11552 } else {
11553 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11554 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11555 }
11556
11557 if (! peer)
11558 return CMD_WARNING;
11559
11560 if (! peer->afc[AFI_IP6][safi])
11561 {
11562 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11563 VTY_NEWLINE);
11564 return CMD_WARNING;
11565}
11566
11567 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11568 PEER_FLAG_RSERVER_CLIENT))
11569 {
11570 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11571 VTY_NEWLINE);
11572 return CMD_WARNING;
11573 }
11574
11575 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11576 (argc == 4) ? argv[3] : argv[2],
11577 AFI_IP6, safi, NULL, 0);
11578}
11579
11580ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11581 show_bgp_ipv6_safi_rsclient_route_cmd,
11582 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11583 SHOW_STR
11584 BGP_STR
11585 "Address family\n"
11586 "Address Family modifier\n"
11587 "Address Family modifier\n"
11588 "Information about Route Server Client\n"
11589 NEIGHBOR_ADDR_STR
11590 "Network in the BGP routing table to display\n")
11591
paulfee0f4c2004-09-13 05:12:46 +000011592DEFUN (show_bgp_view_rsclient_prefix,
11593 show_bgp_view_rsclient_prefix_cmd,
11594 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11595 SHOW_STR
11596 BGP_STR
11597 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011598 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011599 "Information about Route Server Client\n"
11600 NEIGHBOR_ADDR_STR
11601 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11602{
11603 struct bgp *bgp;
11604 struct peer *peer;
11605
11606 /* BGP structure lookup. */
11607 if (argc == 3)
11608 {
11609 bgp = bgp_lookup_by_name (argv[0]);
11610 if (bgp == NULL)
11611 {
11612 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11613 return CMD_WARNING;
11614 }
11615 }
11616 else
11617 {
11618 bgp = bgp_get_default ();
11619 if (bgp == NULL)
11620 {
11621 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11622 return CMD_WARNING;
11623 }
11624 }
11625
11626 if (argc == 3)
11627 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11628 else
11629 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11630
11631 if (! peer)
11632 return CMD_WARNING;
11633
11634 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11635 {
11636 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11637 VTY_NEWLINE);
11638 return CMD_WARNING;
11639 }
11640
11641 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11642 PEER_FLAG_RSERVER_CLIENT))
11643 {
11644 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11645 VTY_NEWLINE);
11646 return CMD_WARNING;
11647 }
11648
11649 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11650 (argc == 3) ? argv[2] : argv[1],
11651 AFI_IP6, SAFI_UNICAST, NULL, 1);
11652}
11653
11654ALIAS (show_bgp_view_rsclient_prefix,
11655 show_bgp_rsclient_prefix_cmd,
11656 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11657 SHOW_STR
11658 BGP_STR
11659 "Information about Route Server Client\n"
11660 NEIGHBOR_ADDR_STR
11661 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11662
Michael Lambert95cbbd22010-07-23 14:43:04 -040011663DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11664 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11665 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11666 SHOW_STR
11667 BGP_STR
11668 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011669 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011670 "Address family\n"
11671 "Address Family modifier\n"
11672 "Address Family modifier\n"
11673 "Information about Route Server Client\n"
11674 NEIGHBOR_ADDR_STR
11675 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11676{
11677 struct bgp *bgp;
11678 struct peer *peer;
11679 safi_t safi;
11680
11681 /* BGP structure lookup. */
11682 if (argc == 4)
11683 {
11684 bgp = bgp_lookup_by_name (argv[0]);
11685 if (bgp == NULL)
11686 {
11687 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11688 return CMD_WARNING;
11689 }
11690 }
11691 else
11692 {
11693 bgp = bgp_get_default ();
11694 if (bgp == NULL)
11695 {
11696 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11697 return CMD_WARNING;
11698 }
11699 }
11700
11701 if (argc == 4) {
11702 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11703 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11704 } else {
11705 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11706 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11707 }
11708
11709 if (! peer)
11710 return CMD_WARNING;
11711
11712 if (! peer->afc[AFI_IP6][safi])
11713 {
11714 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11715 VTY_NEWLINE);
11716 return CMD_WARNING;
11717}
11718
11719 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11720 PEER_FLAG_RSERVER_CLIENT))
11721{
11722 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11723 VTY_NEWLINE);
11724 return CMD_WARNING;
11725 }
11726
11727 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11728 (argc == 4) ? argv[3] : argv[2],
11729 AFI_IP6, safi, NULL, 1);
11730}
11731
11732ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11733 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11734 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11735 SHOW_STR
11736 BGP_STR
11737 "Address family\n"
11738 "Address Family modifier\n"
11739 "Address Family modifier\n"
11740 "Information about Route Server Client\n"
11741 NEIGHBOR_ADDR_STR
11742 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11743
paul718e3742002-12-13 20:15:29 +000011744#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020011745
paul718e3742002-12-13 20:15:29 +000011746struct bgp_table *bgp_distance_table;
11747
11748struct bgp_distance
11749{
11750 /* Distance value for the IP source prefix. */
11751 u_char distance;
11752
11753 /* Name of the access-list to be matched. */
11754 char *access_list;
11755};
11756
paul94f2b392005-06-28 12:44:16 +000011757static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011758bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011759{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011760 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011761}
11762
paul94f2b392005-06-28 12:44:16 +000011763static void
paul718e3742002-12-13 20:15:29 +000011764bgp_distance_free (struct bgp_distance *bdistance)
11765{
11766 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11767}
11768
paul94f2b392005-06-28 12:44:16 +000011769static int
paulfd79ac92004-10-13 05:06:08 +000011770bgp_distance_set (struct vty *vty, const char *distance_str,
11771 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011772{
11773 int ret;
11774 struct prefix_ipv4 p;
11775 u_char distance;
11776 struct bgp_node *rn;
11777 struct bgp_distance *bdistance;
11778
11779 ret = str2prefix_ipv4 (ip_str, &p);
11780 if (ret == 0)
11781 {
11782 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11783 return CMD_WARNING;
11784 }
11785
11786 distance = atoi (distance_str);
11787
11788 /* Get BGP distance node. */
11789 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11790 if (rn->info)
11791 {
11792 bdistance = rn->info;
11793 bgp_unlock_node (rn);
11794 }
11795 else
11796 {
11797 bdistance = bgp_distance_new ();
11798 rn->info = bdistance;
11799 }
11800
11801 /* Set distance value. */
11802 bdistance->distance = distance;
11803
11804 /* Reset access-list configuration. */
11805 if (bdistance->access_list)
11806 {
11807 free (bdistance->access_list);
11808 bdistance->access_list = NULL;
11809 }
11810 if (access_list_str)
11811 bdistance->access_list = strdup (access_list_str);
11812
11813 return CMD_SUCCESS;
11814}
11815
paul94f2b392005-06-28 12:44:16 +000011816static int
paulfd79ac92004-10-13 05:06:08 +000011817bgp_distance_unset (struct vty *vty, const char *distance_str,
11818 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011819{
11820 int ret;
11821 struct prefix_ipv4 p;
11822 u_char distance;
11823 struct bgp_node *rn;
11824 struct bgp_distance *bdistance;
11825
11826 ret = str2prefix_ipv4 (ip_str, &p);
11827 if (ret == 0)
11828 {
11829 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11830 return CMD_WARNING;
11831 }
11832
11833 distance = atoi (distance_str);
11834
11835 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11836 if (! rn)
11837 {
11838 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11839 return CMD_WARNING;
11840 }
11841
11842 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010011843
11844 if (bdistance->distance != distance)
11845 {
11846 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
11847 return CMD_WARNING;
11848 }
11849
paul718e3742002-12-13 20:15:29 +000011850 if (bdistance->access_list)
11851 free (bdistance->access_list);
11852 bgp_distance_free (bdistance);
11853
11854 rn->info = NULL;
11855 bgp_unlock_node (rn);
11856 bgp_unlock_node (rn);
11857
11858 return CMD_SUCCESS;
11859}
11860
paul718e3742002-12-13 20:15:29 +000011861/* Apply BGP information to distance method. */
11862u_char
11863bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11864{
11865 struct bgp_node *rn;
11866 struct prefix_ipv4 q;
11867 struct peer *peer;
11868 struct bgp_distance *bdistance;
11869 struct access_list *alist;
11870 struct bgp_static *bgp_static;
11871
11872 if (! bgp)
11873 return 0;
11874
11875 if (p->family != AF_INET)
11876 return 0;
11877
11878 peer = rinfo->peer;
11879
11880 if (peer->su.sa.sa_family != AF_INET)
11881 return 0;
11882
11883 memset (&q, 0, sizeof (struct prefix_ipv4));
11884 q.family = AF_INET;
11885 q.prefix = peer->su.sin.sin_addr;
11886 q.prefixlen = IPV4_MAX_BITLEN;
11887
11888 /* Check source address. */
11889 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11890 if (rn)
11891 {
11892 bdistance = rn->info;
11893 bgp_unlock_node (rn);
11894
11895 if (bdistance->access_list)
11896 {
11897 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11898 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11899 return bdistance->distance;
11900 }
11901 else
11902 return bdistance->distance;
11903 }
11904
11905 /* Backdoor check. */
11906 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11907 if (rn)
11908 {
11909 bgp_static = rn->info;
11910 bgp_unlock_node (rn);
11911
11912 if (bgp_static->backdoor)
11913 {
11914 if (bgp->distance_local)
11915 return bgp->distance_local;
11916 else
11917 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11918 }
11919 }
11920
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011921 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011922 {
11923 if (bgp->distance_ebgp)
11924 return bgp->distance_ebgp;
11925 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11926 }
11927 else
11928 {
11929 if (bgp->distance_ibgp)
11930 return bgp->distance_ibgp;
11931 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11932 }
11933}
11934
11935DEFUN (bgp_distance,
11936 bgp_distance_cmd,
11937 "distance bgp <1-255> <1-255> <1-255>",
11938 "Define an administrative distance\n"
11939 "BGP distance\n"
11940 "Distance for routes external to the AS\n"
11941 "Distance for routes internal to the AS\n"
11942 "Distance for local routes\n")
11943{
11944 struct bgp *bgp;
11945
11946 bgp = vty->index;
11947
11948 bgp->distance_ebgp = atoi (argv[0]);
11949 bgp->distance_ibgp = atoi (argv[1]);
11950 bgp->distance_local = atoi (argv[2]);
11951 return CMD_SUCCESS;
11952}
11953
11954DEFUN (no_bgp_distance,
11955 no_bgp_distance_cmd,
11956 "no distance bgp <1-255> <1-255> <1-255>",
11957 NO_STR
11958 "Define an administrative distance\n"
11959 "BGP distance\n"
11960 "Distance for routes external to the AS\n"
11961 "Distance for routes internal to the AS\n"
11962 "Distance for local routes\n")
11963{
11964 struct bgp *bgp;
11965
11966 bgp = vty->index;
11967
11968 bgp->distance_ebgp= 0;
11969 bgp->distance_ibgp = 0;
11970 bgp->distance_local = 0;
11971 return CMD_SUCCESS;
11972}
11973
11974ALIAS (no_bgp_distance,
11975 no_bgp_distance2_cmd,
11976 "no distance bgp",
11977 NO_STR
11978 "Define an administrative distance\n"
11979 "BGP distance\n")
11980
11981DEFUN (bgp_distance_source,
11982 bgp_distance_source_cmd,
11983 "distance <1-255> A.B.C.D/M",
11984 "Define an administrative distance\n"
11985 "Administrative distance\n"
11986 "IP source prefix\n")
11987{
11988 bgp_distance_set (vty, argv[0], argv[1], NULL);
11989 return CMD_SUCCESS;
11990}
11991
11992DEFUN (no_bgp_distance_source,
11993 no_bgp_distance_source_cmd,
11994 "no distance <1-255> A.B.C.D/M",
11995 NO_STR
11996 "Define an administrative distance\n"
11997 "Administrative distance\n"
11998 "IP source prefix\n")
11999{
12000 bgp_distance_unset (vty, argv[0], argv[1], NULL);
12001 return CMD_SUCCESS;
12002}
12003
12004DEFUN (bgp_distance_source_access_list,
12005 bgp_distance_source_access_list_cmd,
12006 "distance <1-255> A.B.C.D/M WORD",
12007 "Define an administrative distance\n"
12008 "Administrative distance\n"
12009 "IP source prefix\n"
12010 "Access list name\n")
12011{
12012 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
12013 return CMD_SUCCESS;
12014}
12015
12016DEFUN (no_bgp_distance_source_access_list,
12017 no_bgp_distance_source_access_list_cmd,
12018 "no distance <1-255> A.B.C.D/M WORD",
12019 NO_STR
12020 "Define an administrative distance\n"
12021 "Administrative distance\n"
12022 "IP source prefix\n"
12023 "Access list name\n")
12024{
12025 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
12026 return CMD_SUCCESS;
12027}
David Lamparter6b0655a2014-06-04 06:53:35 +020012028
paul718e3742002-12-13 20:15:29 +000012029DEFUN (bgp_damp_set,
12030 bgp_damp_set_cmd,
12031 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12032 "BGP Specific commands\n"
12033 "Enable route-flap dampening\n"
12034 "Half-life time for the penalty\n"
12035 "Value to start reusing a route\n"
12036 "Value to start suppressing a route\n"
12037 "Maximum duration to suppress a stable route\n")
12038{
12039 struct bgp *bgp;
12040 int half = DEFAULT_HALF_LIFE * 60;
12041 int reuse = DEFAULT_REUSE;
12042 int suppress = DEFAULT_SUPPRESS;
12043 int max = 4 * half;
12044
12045 if (argc == 4)
12046 {
12047 half = atoi (argv[0]) * 60;
12048 reuse = atoi (argv[1]);
12049 suppress = atoi (argv[2]);
12050 max = atoi (argv[3]) * 60;
12051 }
12052 else if (argc == 1)
12053 {
12054 half = atoi (argv[0]) * 60;
12055 max = 4 * half;
12056 }
12057
12058 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000012059
12060 if (suppress < reuse)
12061 {
12062 vty_out (vty, "Suppress value cannot be less than reuse value %s",
12063 VTY_NEWLINE);
12064 return 0;
12065 }
12066
paul718e3742002-12-13 20:15:29 +000012067 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
12068 half, reuse, suppress, max);
12069}
12070
12071ALIAS (bgp_damp_set,
12072 bgp_damp_set2_cmd,
12073 "bgp dampening <1-45>",
12074 "BGP Specific commands\n"
12075 "Enable route-flap dampening\n"
12076 "Half-life time for the penalty\n")
12077
12078ALIAS (bgp_damp_set,
12079 bgp_damp_set3_cmd,
12080 "bgp dampening",
12081 "BGP Specific commands\n"
12082 "Enable route-flap dampening\n")
12083
12084DEFUN (bgp_damp_unset,
12085 bgp_damp_unset_cmd,
12086 "no bgp dampening",
12087 NO_STR
12088 "BGP Specific commands\n"
12089 "Enable route-flap dampening\n")
12090{
12091 struct bgp *bgp;
12092
12093 bgp = vty->index;
12094 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
12095}
12096
12097ALIAS (bgp_damp_unset,
12098 bgp_damp_unset2_cmd,
12099 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12100 NO_STR
12101 "BGP Specific commands\n"
12102 "Enable route-flap dampening\n"
12103 "Half-life time for the penalty\n"
12104 "Value to start reusing a route\n"
12105 "Value to start suppressing a route\n"
12106 "Maximum duration to suppress a stable route\n")
12107
12108DEFUN (show_ip_bgp_dampened_paths,
12109 show_ip_bgp_dampened_paths_cmd,
12110 "show ip bgp dampened-paths",
12111 SHOW_STR
12112 IP_STR
12113 BGP_STR
12114 "Display paths suppressed due to dampening\n")
12115{
ajs5a646652004-11-05 01:25:55 +000012116 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
12117 NULL);
paul718e3742002-12-13 20:15:29 +000012118}
12119
Balaji3921cc52015-05-16 23:12:17 +053012120ALIAS (show_ip_bgp_dampened_paths,
12121 show_ip_bgp_damp_dampened_paths_cmd,
12122 "show ip bgp dampening dampened-paths",
12123 SHOW_STR
12124 IP_STR
12125 BGP_STR
12126 "Display detailed information about dampening\n"
12127 "Display paths suppressed due to dampening\n")
12128
paul718e3742002-12-13 20:15:29 +000012129DEFUN (show_ip_bgp_flap_statistics,
12130 show_ip_bgp_flap_statistics_cmd,
12131 "show ip bgp flap-statistics",
12132 SHOW_STR
12133 IP_STR
12134 BGP_STR
12135 "Display flap statistics of routes\n")
12136{
ajs5a646652004-11-05 01:25:55 +000012137 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12138 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012139}
David Lamparter6b0655a2014-06-04 06:53:35 +020012140
Balaji3921cc52015-05-16 23:12:17 +053012141ALIAS (show_ip_bgp_flap_statistics,
12142 show_ip_bgp_damp_flap_statistics_cmd,
12143 "show ip bgp dampening flap-statistics",
12144 SHOW_STR
12145 IP_STR
12146 BGP_STR
12147 "Display detailed information about dampening\n"
12148 "Display flap statistics of routes\n")
12149
paul718e3742002-12-13 20:15:29 +000012150/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012151static int
paulfd79ac92004-10-13 05:06:08 +000012152bgp_clear_damp_route (struct vty *vty, const char *view_name,
12153 const char *ip_str, afi_t afi, safi_t safi,
12154 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012155{
12156 int ret;
12157 struct prefix match;
12158 struct bgp_node *rn;
12159 struct bgp_node *rm;
12160 struct bgp_info *ri;
12161 struct bgp_info *ri_temp;
12162 struct bgp *bgp;
12163 struct bgp_table *table;
12164
12165 /* BGP structure lookup. */
12166 if (view_name)
12167 {
12168 bgp = bgp_lookup_by_name (view_name);
12169 if (bgp == NULL)
12170 {
12171 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12172 return CMD_WARNING;
12173 }
12174 }
12175 else
12176 {
12177 bgp = bgp_get_default ();
12178 if (bgp == NULL)
12179 {
12180 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12181 return CMD_WARNING;
12182 }
12183 }
12184
12185 /* Check IP address argument. */
12186 ret = str2prefix (ip_str, &match);
12187 if (! ret)
12188 {
12189 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12190 return CMD_WARNING;
12191 }
12192
12193 match.family = afi2family (afi);
12194
12195 if (safi == SAFI_MPLS_VPN)
12196 {
12197 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12198 {
12199 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12200 continue;
12201
12202 if ((table = rn->info) != NULL)
12203 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012204 {
12205 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12206 {
12207 ri = rm->info;
12208 while (ri)
12209 {
12210 if (ri->extra && ri->extra->damp_info)
12211 {
12212 ri_temp = ri->next;
12213 bgp_damp_info_free (ri->extra->damp_info, 1);
12214 ri = ri_temp;
12215 }
12216 else
12217 ri = ri->next;
12218 }
12219 }
12220
12221 bgp_unlock_node (rm);
12222 }
paul718e3742002-12-13 20:15:29 +000012223 }
12224 }
12225 else
12226 {
12227 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012228 {
12229 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12230 {
12231 ri = rn->info;
12232 while (ri)
12233 {
12234 if (ri->extra && ri->extra->damp_info)
12235 {
12236 ri_temp = ri->next;
12237 bgp_damp_info_free (ri->extra->damp_info, 1);
12238 ri = ri_temp;
12239 }
12240 else
12241 ri = ri->next;
12242 }
12243 }
12244
12245 bgp_unlock_node (rn);
12246 }
paul718e3742002-12-13 20:15:29 +000012247 }
12248
12249 return CMD_SUCCESS;
12250}
12251
12252DEFUN (clear_ip_bgp_dampening,
12253 clear_ip_bgp_dampening_cmd,
12254 "clear ip bgp dampening",
12255 CLEAR_STR
12256 IP_STR
12257 BGP_STR
12258 "Clear route flap dampening information\n")
12259{
12260 bgp_damp_info_clean ();
12261 return CMD_SUCCESS;
12262}
12263
12264DEFUN (clear_ip_bgp_dampening_prefix,
12265 clear_ip_bgp_dampening_prefix_cmd,
12266 "clear ip bgp dampening A.B.C.D/M",
12267 CLEAR_STR
12268 IP_STR
12269 BGP_STR
12270 "Clear route flap dampening information\n"
12271 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12272{
12273 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12274 SAFI_UNICAST, NULL, 1);
12275}
12276
12277DEFUN (clear_ip_bgp_dampening_address,
12278 clear_ip_bgp_dampening_address_cmd,
12279 "clear ip bgp dampening A.B.C.D",
12280 CLEAR_STR
12281 IP_STR
12282 BGP_STR
12283 "Clear route flap dampening information\n"
12284 "Network to clear damping information\n")
12285{
12286 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12287 SAFI_UNICAST, NULL, 0);
12288}
12289
12290DEFUN (clear_ip_bgp_dampening_address_mask,
12291 clear_ip_bgp_dampening_address_mask_cmd,
12292 "clear ip bgp dampening A.B.C.D A.B.C.D",
12293 CLEAR_STR
12294 IP_STR
12295 BGP_STR
12296 "Clear route flap dampening information\n"
12297 "Network to clear damping information\n"
12298 "Network mask\n")
12299{
12300 int ret;
12301 char prefix_str[BUFSIZ];
12302
12303 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12304 if (! ret)
12305 {
12306 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12307 return CMD_WARNING;
12308 }
12309
12310 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12311 SAFI_UNICAST, NULL, 0);
12312}
David Lamparter6b0655a2014-06-04 06:53:35 +020012313
paul94f2b392005-06-28 12:44:16 +000012314static int
paul718e3742002-12-13 20:15:29 +000012315bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12316 afi_t afi, safi_t safi, int *write)
12317{
12318 struct bgp_node *prn;
12319 struct bgp_node *rn;
12320 struct bgp_table *table;
12321 struct prefix *p;
12322 struct prefix_rd *prd;
12323 struct bgp_static *bgp_static;
12324 u_int32_t label;
12325 char buf[SU_ADDRSTRLEN];
12326 char rdbuf[RD_ADDRSTRLEN];
12327
12328 /* Network configuration. */
12329 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12330 if ((table = prn->info) != NULL)
12331 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12332 if ((bgp_static = rn->info) != NULL)
12333 {
12334 p = &rn->p;
12335 prd = (struct prefix_rd *) &prn->p;
12336
12337 /* "address-family" display. */
12338 bgp_config_write_family_header (vty, afi, safi, write);
12339
12340 /* "network" configuration display. */
12341 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12342 label = decode_label (bgp_static->tag);
12343
12344 vty_out (vty, " network %s/%d rd %s tag %d",
12345 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12346 p->prefixlen,
12347 rdbuf, label);
12348 vty_out (vty, "%s", VTY_NEWLINE);
12349 }
12350 return 0;
12351}
12352
12353/* Configuration of static route announcement and aggregate
12354 information. */
12355int
12356bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12357 afi_t afi, safi_t safi, int *write)
12358{
12359 struct bgp_node *rn;
12360 struct prefix *p;
12361 struct bgp_static *bgp_static;
12362 struct bgp_aggregate *bgp_aggregate;
12363 char buf[SU_ADDRSTRLEN];
12364
12365 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12366 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12367
12368 /* Network configuration. */
12369 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12370 if ((bgp_static = rn->info) != NULL)
12371 {
12372 p = &rn->p;
12373
12374 /* "address-family" display. */
12375 bgp_config_write_family_header (vty, afi, safi, write);
12376
12377 /* "network" configuration display. */
12378 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12379 {
12380 u_int32_t destination;
12381 struct in_addr netmask;
12382
12383 destination = ntohl (p->u.prefix4.s_addr);
12384 masklen2ip (p->prefixlen, &netmask);
12385 vty_out (vty, " network %s",
12386 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12387
12388 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12389 || (IN_CLASSB (destination) && p->prefixlen == 16)
12390 || (IN_CLASSA (destination) && p->prefixlen == 8)
12391 || p->u.prefix4.s_addr == 0)
12392 {
12393 /* Natural mask is not display. */
12394 }
12395 else
12396 vty_out (vty, " mask %s", inet_ntoa (netmask));
12397 }
12398 else
12399 {
12400 vty_out (vty, " network %s/%d",
12401 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12402 p->prefixlen);
12403 }
12404
12405 if (bgp_static->rmap.name)
12406 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012407 else
12408 {
12409 if (bgp_static->backdoor)
12410 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012411 }
paul718e3742002-12-13 20:15:29 +000012412
12413 vty_out (vty, "%s", VTY_NEWLINE);
12414 }
12415
12416 /* Aggregate-address configuration. */
12417 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12418 if ((bgp_aggregate = rn->info) != NULL)
12419 {
12420 p = &rn->p;
12421
12422 /* "address-family" display. */
12423 bgp_config_write_family_header (vty, afi, safi, write);
12424
12425 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12426 {
12427 struct in_addr netmask;
12428
12429 masklen2ip (p->prefixlen, &netmask);
12430 vty_out (vty, " aggregate-address %s %s",
12431 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12432 inet_ntoa (netmask));
12433 }
12434 else
12435 {
12436 vty_out (vty, " aggregate-address %s/%d",
12437 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12438 p->prefixlen);
12439 }
12440
12441 if (bgp_aggregate->as_set)
12442 vty_out (vty, " as-set");
12443
12444 if (bgp_aggregate->summary_only)
12445 vty_out (vty, " summary-only");
12446
12447 vty_out (vty, "%s", VTY_NEWLINE);
12448 }
12449
12450 return 0;
12451}
12452
12453int
12454bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12455{
12456 struct bgp_node *rn;
12457 struct bgp_distance *bdistance;
12458
12459 /* Distance configuration. */
12460 if (bgp->distance_ebgp
12461 && bgp->distance_ibgp
12462 && bgp->distance_local
12463 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12464 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12465 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12466 vty_out (vty, " distance bgp %d %d %d%s",
12467 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12468 VTY_NEWLINE);
12469
12470 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12471 if ((bdistance = rn->info) != NULL)
12472 {
12473 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12474 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12475 bdistance->access_list ? bdistance->access_list : "",
12476 VTY_NEWLINE);
12477 }
12478
12479 return 0;
12480}
12481
12482/* Allocate routing table structure and install commands. */
12483void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012484bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012485{
12486 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012487 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012488
12489 /* IPv4 BGP commands. */
12490 install_element (BGP_NODE, &bgp_network_cmd);
12491 install_element (BGP_NODE, &bgp_network_mask_cmd);
12492 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12493 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12494 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12495 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12496 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12497 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12498 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12499 install_element (BGP_NODE, &no_bgp_network_cmd);
12500 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12501 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12502 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12503 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12504 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12505 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12506 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12507 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12508
12509 install_element (BGP_NODE, &aggregate_address_cmd);
12510 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12511 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12512 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12513 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12514 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12515 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12516 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12517 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12518 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12519 install_element (BGP_NODE, &no_aggregate_address_cmd);
12520 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12521 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12522 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12523 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12524 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12525 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12526 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12527 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12528 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12529
12530 /* IPv4 unicast configuration. */
12531 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12532 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12533 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12534 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12535 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12536 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012537 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012538 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12539 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12540 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12541 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12542 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012543
paul718e3742002-12-13 20:15:29 +000012544 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12545 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12546 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12547 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12548 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12549 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12550 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12551 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12552 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12553 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12554 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12555 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12556 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12557 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12558 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12559 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12560 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12561 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12562 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12563 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12564
12565 /* IPv4 multicast configuration. */
12566 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12567 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12568 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12569 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12570 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12571 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12572 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12573 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12574 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12575 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12576 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12577 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12578 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12579 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12580 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12581 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12582 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12583 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12584 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12585 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12586 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12587 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12588 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12589 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12590 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12591 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12592 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12593 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12594 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12595 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12596 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12597 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12598
12599 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12600 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012601 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012602 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12603 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012604 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012605 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12606 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12607 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12608 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012609 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012610 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12611 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12612 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12613 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12614 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12615 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12616 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12617 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12618 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12619 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12620 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12621 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12622 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12623 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12624 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12625 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12626 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12627 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12628 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12629 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12630 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12631 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12632 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12633 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12634 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012635 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12636 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12637 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12638 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12639 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012640 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12641 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12642 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12643 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12644 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12645 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12646 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12647 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12648 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12649 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12650 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12651 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12652 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12653 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12654 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12655 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12656 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12657 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012658 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012659 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12660 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12661 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12662 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012663 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
paul718e3742002-12-13 20:15:29 +000012664 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012665 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
paul718e3742002-12-13 20:15:29 +000012666 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012667 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
paul718e3742002-12-13 20:15:29 +000012668 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012669 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
paul718e3742002-12-13 20:15:29 +000012670 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12671 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012672 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
paul718e3742002-12-13 20:15:29 +000012673 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12674 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012675 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000012676 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012677 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000012678 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012679 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000012680 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012681 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
paul718e3742002-12-13 20:15:29 +000012682 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12683 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012684 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012685 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012686 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012687 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012688 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012689 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012690 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12691 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012692 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012693 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012694 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012695 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012696 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012697 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012698
12699 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12700 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12701 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012702 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012703 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12704 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12705 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012706 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012707 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12708 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12709 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12710 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12711 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12712 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12713 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12714 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12715 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12716 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12717 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12718 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012719 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12720 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12721 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12722 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12723 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012724 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12725 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12726 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12727 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12728 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12729 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12730 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12731 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12732 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012733 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012734 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012735 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012736 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012737 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012738 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012739 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012740
12741 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12742 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012743 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012744 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12745 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012746 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012747 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12748 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12749 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12750 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012751 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012752 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12753 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12754 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12755 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12756 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12757 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12758 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12759 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12760 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12761 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12762 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12763 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12764 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12765 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12766 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12767 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12768 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12769 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12770 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12771 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12772 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12773 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12774 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12775 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12776 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012777 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12778 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12779 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12780 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12781 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012782 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12783 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12784 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12785 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12786 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12787 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12788 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12789 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12790 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12791 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12792 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12793 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12794 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12795 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12796 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12797 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12798 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12799 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012800 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012801 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12802 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12803 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12804 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012805 install_element (ENABLE_NODE, &show_ip_bgp_dampening_params_cmd);
paul718e3742002-12-13 20:15:29 +000012806 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012807 install_element (ENABLE_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
paul718e3742002-12-13 20:15:29 +000012808 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012809 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
paul718e3742002-12-13 20:15:29 +000012810 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012811 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_address_cmd);
paul718e3742002-12-13 20:15:29 +000012812 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12813 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012814 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
paul718e3742002-12-13 20:15:29 +000012815 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012816 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_regexp_cmd);
paul718e3742002-12-13 20:15:29 +000012817 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012818 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000012819 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012820 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
12821 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000012822 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012823 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000012824 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012825 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
paul718e3742002-12-13 20:15:29 +000012826 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12827 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012828 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012829 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012830 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012831 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012832 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012833 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012834 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12835 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012836 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012837 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012838 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012839 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012840 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012841 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012842
12843 /* BGP dampening clear commands */
12844 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12845 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12846 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12847 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12848
Paul Jakmaff7924f2006-09-04 01:10:36 +000012849 /* prefix count */
12850 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12851 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12852 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012853#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012854 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12855
paul718e3742002-12-13 20:15:29 +000012856 /* New config IPv6 BGP commands. */
12857 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12858 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12859 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12860 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12861
12862 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12863 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12864 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12865 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12866
G.Balaji73bfe0b2011-09-23 22:36:20 +053012867 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12868 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12869
paul718e3742002-12-13 20:15:29 +000012870 /* Old config IPv6 BGP commands. */
12871 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12872 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12873
12874 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12875 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12876 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12877 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12878
12879 install_element (VIEW_NODE, &show_bgp_cmd);
12880 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012881 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012882 install_element (VIEW_NODE, &show_bgp_route_cmd);
12883 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012884 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012885 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12886 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012887 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012888 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12889 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12890 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12891 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12892 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12893 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12894 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12895 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12896 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12897 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12898 install_element (VIEW_NODE, &show_bgp_community_cmd);
12899 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12900 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12901 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12902 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12903 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12904 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12905 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12906 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12907 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12908 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12909 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12910 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12911 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12912 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12913 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12914 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12915 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12916 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12917 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12918 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12919 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12920 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12921 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12922 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12923 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12924 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12925 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12926 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12927 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012928 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12929 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12930 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12931 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012932 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012933 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012934 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012935 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012936 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012937 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012938 install_element (VIEW_NODE, &show_bgp_view_cmd);
12939 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12940 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12941 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12942 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12943 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12944 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12945 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12946 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12947 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12948 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12949 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12950 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12951 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12952 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12953 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12954 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12955 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012956 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012957 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012958 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012959 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012960 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012961 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012962
12963 /* Restricted:
12964 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12965 */
12966 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12967 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012968 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012969 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12970 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012971 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012972 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12973 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12974 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12975 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12976 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12977 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12978 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12979 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12980 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12981 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12982 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12983 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12984 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12985 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12986 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12987 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12988 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012989 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012990 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012991 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012992 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12993 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12994 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12995 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12996 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12997 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12998 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012999 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013000 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013001 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013002
13003 install_element (ENABLE_NODE, &show_bgp_cmd);
13004 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013005 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000013006 install_element (ENABLE_NODE, &show_bgp_route_cmd);
13007 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013008 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000013009 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
13010 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013011 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013012 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
13013 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
13014 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
13015 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
13016 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
13017 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
13018 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
13019 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
13020 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
13021 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
13022 install_element (ENABLE_NODE, &show_bgp_community_cmd);
13023 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
13024 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
13025 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
13026 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
13027 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
13028 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
13029 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
13030 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
13031 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
13032 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
13033 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
13034 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
13035 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
13036 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
13037 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
13038 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
13039 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
13040 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
13041 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
13042 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
13043 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
13044 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
13045 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
13046 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
13047 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
13048 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
13049 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
13050 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
13051 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000013052 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
13053 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
13054 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
13055 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013056 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013057 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013058 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013059 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013060 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013061 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000013062 install_element (ENABLE_NODE, &show_bgp_view_cmd);
13063 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
13064 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
13065 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
13066 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
13067 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
13068 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
13069 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
13070 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
13071 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
13072 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
13073 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
13074 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13075 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13076 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
13077 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
13078 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
13079 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013080 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013081 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013082 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013083 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013084 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013085 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000013086
13087 /* Statistics */
13088 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
13089 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
13090 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
13091 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
13092
paul718e3742002-12-13 20:15:29 +000013093 /* old command */
13094 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
13095 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
13096 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
13097 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
13098 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
13099 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
13100 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
13101 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
13102 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
13103 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
13104 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
13105 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
13106 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
13107 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
13108 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
13109 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
13110 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13111 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13112 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
13113 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
13114 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
13115 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
13116 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13117 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
13118 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
13119 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
13120 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
13121 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
13122 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
13123 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
13124 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13125 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13126 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13127 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
13128 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13129 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000013130
paul718e3742002-12-13 20:15:29 +000013131 /* old command */
13132 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
13133 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
13134 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
13135 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
13136 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
13137 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
13138 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
13139 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
13140 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
13141 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
13142 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13143 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13144 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13145 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13146 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13147 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13148 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13149 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13150 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13151 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13152 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13153 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13154 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13155 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13156 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13157 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13158 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13159 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13160 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13161 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13162 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13163 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13164 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13165 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13166 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13167 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13168
13169 /* old command */
13170 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13171 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13172 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13173 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13174
13175 /* old command */
13176 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13177 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13178 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13179 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13180
13181 /* old command */
13182 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13183 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13184 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13185 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13186#endif /* HAVE_IPV6 */
13187
13188 install_element (BGP_NODE, &bgp_distance_cmd);
13189 install_element (BGP_NODE, &no_bgp_distance_cmd);
13190 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13191 install_element (BGP_NODE, &bgp_distance_source_cmd);
13192 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13193 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13194 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13195
13196 install_element (BGP_NODE, &bgp_damp_set_cmd);
13197 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13198 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13199 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13200 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13201 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13202 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13203 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13204 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13205 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013206
13207 /* Deprecated AS-Pathlimit commands */
13208 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13209 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13210 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13211 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13212 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13213 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13214
13215 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13216 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13217 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13218 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13219 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13220 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13221
13222 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13223 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13224 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13225 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13226 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13227 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13228
13229 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13230 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13231 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13232 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13233 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13234 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13235
13236 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13237 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13238 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13239 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13240 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13241 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13242
13243 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13244 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13245 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13246 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13247 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13248 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013249
13250#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013251 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13252 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013253#endif
paul718e3742002-12-13 20:15:29 +000013254}
Chris Caputo228da422009-07-18 05:44:03 +000013255
13256void
13257bgp_route_finish (void)
13258{
13259 bgp_table_unlock (bgp_distance_table);
13260 bgp_distance_table = NULL;
13261}