blob: e0e14eca712154b7859adb55f87a31fc7bf828ef [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;
Paul Jakma91b9e852015-12-01 14:32:11 +00001339
1340 result->old = result->new = NULL;
1341
1342 if (rn->info == NULL)
1343 {
1344 char buf[PREFIX_STRLEN];
1345 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1346 __func__,
1347 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1348 return;
1349 }
1350
Josh Bailey96450fa2011-07-20 20:45:12 -07001351 bgp_mp_list_init (&mp_list);
1352 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1353 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1354
paul718e3742002-12-13 20:15:29 +00001355 /* bgp deterministic-med */
1356 new_select = NULL;
1357 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1358 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1359 {
1360 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1361 continue;
1362 if (BGP_INFO_HOLDDOWN (ri1))
1363 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001364 if (ri1->peer && ri1->peer != bgp->peer_self)
1365 if (ri1->peer->status != Established)
1366 continue;
paul718e3742002-12-13 20:15:29 +00001367
1368 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001369 if (do_mpath)
1370 bgp_mp_list_add (&mp_list, ri1);
1371 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001372 if (ri1->next)
1373 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1374 {
1375 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1376 continue;
1377 if (BGP_INFO_HOLDDOWN (ri2))
1378 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001379 if (ri2->peer &&
1380 ri2->peer != bgp->peer_self &&
1381 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1382 if (ri2->peer->status != Established)
1383 continue;
paul718e3742002-12-13 20:15:29 +00001384
1385 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1386 || aspath_cmp_left_confed (ri1->attr->aspath,
1387 ri2->attr->aspath))
1388 {
Josh Bailey6918e742011-07-20 20:48:20 -07001389 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1390 old_select = ri2;
Josh Bailey96450fa2011-07-20 20:45:12 -07001391 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
paul718e3742002-12-13 20:15:29 +00001392 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001393 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001394 new_select = ri2;
Josh Bailey6918e742011-07-20 20:48:20 -07001395 if (do_mpath && !paths_eq)
1396 {
1397 bgp_mp_list_clear (&mp_list);
1398 bgp_mp_list_add (&mp_list, ri2);
1399 }
paul718e3742002-12-13 20:15:29 +00001400 }
1401
Josh Bailey6918e742011-07-20 20:48:20 -07001402 if (do_mpath && paths_eq)
1403 bgp_mp_list_add (&mp_list, ri2);
1404
Paul Jakma1a392d42006-09-07 00:24:49 +00001405 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001406 }
1407 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001408 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1409 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001410
1411 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1412 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001413 }
1414
1415 /* Check old selected route and new selected route. */
1416 old_select = NULL;
1417 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001418 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001419 {
1420 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1421 old_select = ri;
1422
1423 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001424 {
1425 /* reap REMOVED routes, if needs be
1426 * selected route must stay for a while longer though
1427 */
1428 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1429 && (ri != old_select))
1430 bgp_info_reap (rn, ri);
1431
1432 continue;
1433 }
paul718e3742002-12-13 20:15:29 +00001434
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001435 if (ri->peer &&
1436 ri->peer != bgp->peer_self &&
1437 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1438 if (ri->peer->status != Established)
1439 continue;
1440
paul718e3742002-12-13 20:15:29 +00001441 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1442 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1443 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001444 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001445 continue;
1446 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001447 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1448 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001449
Josh Bailey96450fa2011-07-20 20:45:12 -07001450 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1451 {
Josh Bailey6918e742011-07-20 20:48:20 -07001452 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1453 bgp_mp_dmed_deselect (new_select);
1454
Josh Bailey96450fa2011-07-20 20:45:12 -07001455 new_select = ri;
1456
1457 if (do_mpath && !paths_eq)
1458 {
1459 bgp_mp_list_clear (&mp_list);
1460 bgp_mp_list_add (&mp_list, ri);
1461 }
1462 }
Josh Bailey6918e742011-07-20 20:48:20 -07001463 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1464 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001465
1466 if (do_mpath && paths_eq)
1467 bgp_mp_list_add (&mp_list, ri);
paul718e3742002-12-13 20:15:29 +00001468 }
paulfee0f4c2004-09-13 05:12:46 +00001469
Josh Bailey6918e742011-07-20 20:48:20 -07001470 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1471 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
Josh Bailey96450fa2011-07-20 20:45:12 -07001472
Josh Bailey0b597ef2011-07-20 20:49:11 -07001473 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001474 bgp_mp_list_clear (&mp_list);
1475
1476 result->old = old_select;
1477 result->new = new_select;
1478
1479 return;
paulfee0f4c2004-09-13 05:12:46 +00001480}
1481
paul94f2b392005-06-28 12:44:16 +00001482static int
paulfee0f4c2004-09-13 05:12:46 +00001483bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001484 struct bgp_node *rn, afi_t afi, safi_t safi)
1485{
paulfee0f4c2004-09-13 05:12:46 +00001486 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001487 struct attr attr;
1488 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001489
1490 p = &rn->p;
1491
Paul Jakma9eda90c2007-08-30 13:36:17 +00001492 /* Announce route to Established peer. */
1493 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001494 return 0;
1495
Paul Jakma9eda90c2007-08-30 13:36:17 +00001496 /* Address family configuration check. */
1497 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001498 return 0;
1499
Paul Jakma9eda90c2007-08-30 13:36:17 +00001500 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001501 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1502 PEER_STATUS_ORF_WAIT_REFRESH))
1503 return 0;
1504
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001505 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1506 attr.extra = &extra;
1507
Avneesh Sachdev67174042012-08-17 08:19:49 -07001508 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001509 {
1510 case BGP_TABLE_MAIN:
1511 /* Announcement to peer->conf. If the route is filtered,
1512 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001513 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1514 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001515 else
1516 bgp_adj_out_unset (rn, peer, p, afi, safi);
1517 break;
1518 case BGP_TABLE_RSCLIENT:
1519 /* Announcement to peer->conf. If the route is filtered,
1520 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001521 if (selected &&
1522 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1523 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1524 else
1525 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001526 break;
1527 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001528
paulfee0f4c2004-09-13 05:12:46 +00001529 return 0;
paul200df112005-06-01 11:17:05 +00001530}
paulfee0f4c2004-09-13 05:12:46 +00001531
paul200df112005-06-01 11:17:05 +00001532struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001533{
paul200df112005-06-01 11:17:05 +00001534 struct bgp *bgp;
1535 struct bgp_node *rn;
1536 afi_t afi;
1537 safi_t safi;
1538};
1539
1540static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001541bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001542{
paul0fb58d52005-11-14 14:31:49 +00001543 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001544 struct bgp *bgp = pq->bgp;
1545 struct bgp_node *rn = pq->rn;
1546 afi_t afi = pq->afi;
1547 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001548 struct bgp_info *new_select;
1549 struct bgp_info *old_select;
1550 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001551 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001552 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001553
paulfee0f4c2004-09-13 05:12:46 +00001554 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001555 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001556 new_select = old_and_new.new;
1557 old_select = old_and_new.old;
1558
paul200df112005-06-01 11:17:05 +00001559 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1560 {
Chris Caputo228da422009-07-18 05:44:03 +00001561 if (rsclient->group)
1562 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1563 {
1564 /* Nothing to do. */
1565 if (old_select && old_select == new_select)
1566 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1567 continue;
paulfee0f4c2004-09-13 05:12:46 +00001568
Chris Caputo228da422009-07-18 05:44:03 +00001569 if (old_select)
1570 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1571 if (new_select)
1572 {
1573 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1574 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001575 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1576 }
paulfee0f4c2004-09-13 05:12:46 +00001577
Chris Caputo228da422009-07-18 05:44:03 +00001578 bgp_process_announce_selected (rsclient, new_select, rn,
1579 afi, safi);
1580 }
paul200df112005-06-01 11:17:05 +00001581 }
1582 else
1583 {
hassob7395792005-08-26 12:58:38 +00001584 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001585 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001586 if (new_select)
1587 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001588 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1589 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001590 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001591 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001592 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001593 }
paulfee0f4c2004-09-13 05:12:46 +00001594
paulb40d9392005-08-22 22:34:41 +00001595 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1596 bgp_info_reap (rn, old_select);
1597
paul200df112005-06-01 11:17:05 +00001598 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1599 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001600}
1601
paul200df112005-06-01 11:17:05 +00001602static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001603bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001604{
paul0fb58d52005-11-14 14:31:49 +00001605 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001606 struct bgp *bgp = pq->bgp;
1607 struct bgp_node *rn = pq->rn;
1608 afi_t afi = pq->afi;
1609 safi_t safi = pq->safi;
1610 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001611 struct bgp_info *new_select;
1612 struct bgp_info *old_select;
1613 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001614 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001615 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001616
paulfee0f4c2004-09-13 05:12:46 +00001617 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001618 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001619 old_select = old_and_new.old;
1620 new_select = old_and_new.new;
1621
1622 /* Nothing to do. */
1623 if (old_select && old_select == new_select)
1624 {
1625 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001626 {
Josh Bailey8196f132011-07-20 20:47:07 -07001627 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1628 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001629 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001630
Josh Bailey8196f132011-07-20 20:47:07 -07001631 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001632 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1633 return WQ_SUCCESS;
1634 }
paulfee0f4c2004-09-13 05:12:46 +00001635 }
paul718e3742002-12-13 20:15:29 +00001636
hasso338b3422005-02-23 14:27:24 +00001637 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001638 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001639 if (new_select)
1640 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001641 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1642 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001643 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001644 }
1645
1646
paul718e3742002-12-13 20:15:29 +00001647 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001648 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001649 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001650 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001651 }
1652
1653 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001654 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1655 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001656 {
1657 if (new_select
1658 && new_select->type == ZEBRA_ROUTE_BGP
1659 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001660 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001661 else
1662 {
1663 /* Withdraw the route from the kernel. */
1664 if (old_select
1665 && old_select->type == ZEBRA_ROUTE_BGP
1666 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001667 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001668 }
1669 }
paulb40d9392005-08-22 22:34:41 +00001670
1671 /* Reap old select bgp_info, it it has been removed */
1672 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1673 bgp_info_reap (rn, old_select);
1674
paul200df112005-06-01 11:17:05 +00001675 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1676 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001677}
1678
paul200df112005-06-01 11:17:05 +00001679static void
paul0fb58d52005-11-14 14:31:49 +00001680bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001681{
paul0fb58d52005-11-14 14:31:49 +00001682 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001683 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001684
Chris Caputo228da422009-07-18 05:44:03 +00001685 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001686 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001687 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001688 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1689}
1690
1691static void
1692bgp_process_queue_init (void)
1693{
1694 bm->process_main_queue
1695 = work_queue_new (bm->master, "process_main_queue");
1696 bm->process_rsclient_queue
1697 = work_queue_new (bm->master, "process_rsclient_queue");
1698
1699 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1700 {
1701 zlog_err ("%s: Failed to allocate work queue", __func__);
1702 exit (1);
1703 }
1704
1705 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001706 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001707 bm->process_main_queue->spec.max_retries = 0;
1708 bm->process_main_queue->spec.hold = 50;
1709
Paul Jakma838bbde2010-01-08 14:05:32 +00001710 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
David Lamparterd43f8b32015-03-03 08:54:54 +01001711 bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del;
1712 bm->process_rsclient_queue->spec.max_retries = 0;
1713 bm->process_rsclient_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001714}
1715
1716void
paulfee0f4c2004-09-13 05:12:46 +00001717bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1718{
paul200df112005-06-01 11:17:05 +00001719 struct bgp_process_queue *pqnode;
1720
1721 /* already scheduled for processing? */
1722 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1723 return;
1724
Paul Jakma91b9e852015-12-01 14:32:11 +00001725 if (rn->info == NULL)
1726 {
1727 /* XXX: Perhaps remove before next release, after we've flushed out
1728 * any obvious cases
1729 */
1730 assert (rn->info != NULL);
1731 char buf[PREFIX_STRLEN];
1732 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1733 __func__,
1734 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1735 return;
1736 }
1737
paul200df112005-06-01 11:17:05 +00001738 if ( (bm->process_main_queue == NULL) ||
1739 (bm->process_rsclient_queue == NULL) )
1740 bgp_process_queue_init ();
1741
1742 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1743 sizeof (struct bgp_process_queue));
1744 if (!pqnode)
1745 return;
Chris Caputo228da422009-07-18 05:44:03 +00001746
1747 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001748 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001749 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001750 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001751 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001752 pqnode->afi = afi;
1753 pqnode->safi = safi;
1754
Avneesh Sachdev67174042012-08-17 08:19:49 -07001755 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001756 {
paul200df112005-06-01 11:17:05 +00001757 case BGP_TABLE_MAIN:
1758 work_queue_add (bm->process_main_queue, pqnode);
1759 break;
1760 case BGP_TABLE_RSCLIENT:
1761 work_queue_add (bm->process_rsclient_queue, pqnode);
1762 break;
paulfee0f4c2004-09-13 05:12:46 +00001763 }
paul200df112005-06-01 11:17:05 +00001764
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001765 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001766 return;
paulfee0f4c2004-09-13 05:12:46 +00001767}
hasso0a486e52005-02-01 20:57:17 +00001768
paul94f2b392005-06-28 12:44:16 +00001769static int
hasso0a486e52005-02-01 20:57:17 +00001770bgp_maximum_prefix_restart_timer (struct thread *thread)
1771{
1772 struct peer *peer;
1773
1774 peer = THREAD_ARG (thread);
1775 peer->t_pmax_restart = NULL;
1776
1777 if (BGP_DEBUG (events, EVENTS))
1778 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1779 peer->host);
1780
1781 peer_clear (peer);
1782
1783 return 0;
1784}
1785
paulfee0f4c2004-09-13 05:12:46 +00001786int
paul5228ad22004-06-04 17:58:18 +00001787bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1788 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001789{
hassoe0701b72004-05-20 09:19:34 +00001790 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1791 return 0;
1792
1793 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001794 {
hassoe0701b72004-05-20 09:19:34 +00001795 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1796 && ! always)
1797 return 0;
paul718e3742002-12-13 20:15:29 +00001798
hassoe0701b72004-05-20 09:19:34 +00001799 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001800 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1801 "limit %ld", afi_safi_print (afi, safi), peer->host,
1802 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001803 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001804
hassoe0701b72004-05-20 09:19:34 +00001805 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1806 return 0;
paul718e3742002-12-13 20:15:29 +00001807
hassoe0701b72004-05-20 09:19:34 +00001808 {
paul5228ad22004-06-04 17:58:18 +00001809 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001810
1811 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001812 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001813
1814 ndata[0] = (afi >> 8);
1815 ndata[1] = afi;
1816 ndata[2] = safi;
1817 ndata[3] = (peer->pmax[afi][safi] >> 24);
1818 ndata[4] = (peer->pmax[afi][safi] >> 16);
1819 ndata[5] = (peer->pmax[afi][safi] >> 8);
1820 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001821
1822 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1823 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1824 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1825 }
hasso0a486e52005-02-01 20:57:17 +00001826
1827 /* restart timer start */
1828 if (peer->pmax_restart[afi][safi])
1829 {
1830 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1831
1832 if (BGP_DEBUG (events, EVENTS))
1833 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1834 peer->host, peer->v_pmax_restart);
1835
1836 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1837 peer->v_pmax_restart);
1838 }
1839
hassoe0701b72004-05-20 09:19:34 +00001840 return 1;
paul718e3742002-12-13 20:15:29 +00001841 }
hassoe0701b72004-05-20 09:19:34 +00001842 else
1843 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1844
1845 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1846 {
1847 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1848 && ! always)
1849 return 0;
1850
1851 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001852 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1853 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1854 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001855 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1856 }
1857 else
1858 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001859 return 0;
1860}
1861
paulb40d9392005-08-22 22:34:41 +00001862/* Unconditionally remove the route from the RIB, without taking
1863 * damping into consideration (eg, because the session went down)
1864 */
paul94f2b392005-06-28 12:44:16 +00001865static void
paul718e3742002-12-13 20:15:29 +00001866bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1867 afi_t afi, safi_t safi)
1868{
paul902212c2006-02-05 17:51:19 +00001869 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1870
1871 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1872 bgp_info_delete (rn, ri); /* keep historical info */
1873
paulb40d9392005-08-22 22:34:41 +00001874 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001875}
1876
paul94f2b392005-06-28 12:44:16 +00001877static void
paul718e3742002-12-13 20:15:29 +00001878bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001879 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001880{
paul718e3742002-12-13 20:15:29 +00001881 int status = BGP_DAMP_NONE;
1882
paulb40d9392005-08-22 22:34:41 +00001883 /* apply dampening, if result is suppressed, we'll be retaining
1884 * the bgp_info in the RIB for historical reference.
1885 */
1886 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001887 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001888 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1889 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001890 {
paul902212c2006-02-05 17:51:19 +00001891 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1892 return;
1893 }
1894
1895 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001896}
1897
paul94f2b392005-06-28 12:44:16 +00001898static void
paulfee0f4c2004-09-13 05:12:46 +00001899bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1900 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1901 int sub_type, struct prefix_rd *prd, u_char *tag)
1902{
1903 struct bgp_node *rn;
1904 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001905 struct attr new_attr;
1906 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001907 struct attr *attr_new;
1908 struct attr *attr_new2;
1909 struct bgp_info *ri;
1910 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001911 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001912 char buf[SU_ADDRSTRLEN];
1913
1914 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1915 if (peer == rsclient)
1916 return;
1917
1918 bgp = peer->bgp;
1919 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1920
1921 /* Check previously received route. */
1922 for (ri = rn->info; ri; ri = ri->next)
1923 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1924 break;
1925
1926 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001927 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001928 {
1929 reason = "as-path contains our own AS;";
1930 goto filtered;
1931 }
1932
1933 /* Route reflector originator ID check. */
1934 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001935 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001936 {
1937 reason = "originator is us;";
1938 goto filtered;
1939 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001940
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001941 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001942 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001943
1944 /* Apply export policy. */
1945 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1946 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1947 {
1948 reason = "export-policy;";
1949 goto filtered;
1950 }
1951
1952 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001953
paulfee0f4c2004-09-13 05:12:46 +00001954 /* Apply import policy. */
1955 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1956 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001957 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001958
1959 reason = "import-policy;";
1960 goto filtered;
1961 }
1962
1963 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001964 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001965
1966 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001967 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001968 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001969 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001970 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001971 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001972 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001973 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001974
1975 reason = "martian next-hop;";
1976 goto filtered;
1977 }
1978 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001979
paulfee0f4c2004-09-13 05:12:46 +00001980 /* If the update is implicit withdraw. */
1981 if (ri)
1982 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001983 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001984
1985 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001986 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1987 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001988 {
1989
Paul Jakma1a392d42006-09-07 00:24:49 +00001990 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001991
1992 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001993 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001994 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1995 peer->host,
1996 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1997 p->prefixlen, rsclient->host);
1998
Chris Caputo228da422009-07-18 05:44:03 +00001999 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002000 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00002001
Chris Caputo228da422009-07-18 05:44:03 +00002002 return;
paulfee0f4c2004-09-13 05:12:46 +00002003 }
2004
Paul Jakma16d2e242007-04-10 19:32:10 +00002005 /* Withdraw/Announce before we fully processed the withdraw */
2006 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2007 bgp_info_restore (rn, ri);
2008
paulfee0f4c2004-09-13 05:12:46 +00002009 /* Received Logging. */
2010 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002011 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002012 peer->host,
2013 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2014 p->prefixlen, rsclient->host);
2015
2016 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002017 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00002018
2019 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002020 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00002021 ri->attr = attr_new;
2022
2023 /* Update MPLS tag. */
2024 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002025 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002026
Paul Jakma1a392d42006-09-07 00:24:49 +00002027 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002028
2029 /* Process change. */
2030 bgp_process (bgp, rn, afi, safi);
2031 bgp_unlock_node (rn);
2032
2033 return;
2034 }
2035
2036 /* Received Logging. */
2037 if (BGP_DEBUG (update, UPDATE_IN))
2038 {
ajsd2c1f162004-12-08 21:10:20 +00002039 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002040 peer->host,
2041 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2042 p->prefixlen, rsclient->host);
2043 }
2044
2045 /* Make new BGP info. */
2046 new = bgp_info_new ();
2047 new->type = type;
2048 new->sub_type = sub_type;
2049 new->peer = peer;
2050 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002051 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00002052
2053 /* Update MPLS tag. */
2054 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002055 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002056
Paul Jakma1a392d42006-09-07 00:24:49 +00002057 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002058
2059 /* Register new BGP information. */
2060 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002061
2062 /* route_node_get lock */
2063 bgp_unlock_node (rn);
2064
paulfee0f4c2004-09-13 05:12:46 +00002065 /* Process change. */
2066 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002067
paulfee0f4c2004-09-13 05:12:46 +00002068 return;
2069
2070 filtered:
2071
2072 /* This BGP update is filtered. Log the reason then update BGP entry. */
2073 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002074 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002075 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2076 peer->host,
2077 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2078 p->prefixlen, rsclient->host, reason);
2079
2080 if (ri)
paulb40d9392005-08-22 22:34:41 +00002081 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002082
2083 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002084
paulfee0f4c2004-09-13 05:12:46 +00002085 return;
2086}
2087
paul94f2b392005-06-28 12:44:16 +00002088static void
paulfee0f4c2004-09-13 05:12:46 +00002089bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2090 struct peer *peer, struct prefix *p, int type, int sub_type,
2091 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002092{
paulfee0f4c2004-09-13 05:12:46 +00002093 struct bgp_node *rn;
2094 struct bgp_info *ri;
2095 char buf[SU_ADDRSTRLEN];
2096
2097 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002098 return;
paulfee0f4c2004-09-13 05:12:46 +00002099
2100 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2101
2102 /* Lookup withdrawn route. */
2103 for (ri = rn->info; ri; ri = ri->next)
2104 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2105 break;
2106
2107 /* Withdraw specified route from routing table. */
2108 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002109 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002110 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002111 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002112 "%s Can't find the route %s/%d", peer->host,
2113 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2114 p->prefixlen);
2115
2116 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002117 bgp_unlock_node (rn);
2118}
paulfee0f4c2004-09-13 05:12:46 +00002119
paul94f2b392005-06-28 12:44:16 +00002120static int
paulfee0f4c2004-09-13 05:12:46 +00002121bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002122 afi_t afi, safi_t safi, int type, int sub_type,
2123 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2124{
2125 int ret;
2126 int aspath_loop_count = 0;
2127 struct bgp_node *rn;
2128 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002129 struct attr new_attr;
2130 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002131 struct attr *attr_new;
2132 struct bgp_info *ri;
2133 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002134 const char *reason;
paul718e3742002-12-13 20:15:29 +00002135 char buf[SU_ADDRSTRLEN];
2136
2137 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002138 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002139
paul718e3742002-12-13 20:15:29 +00002140 /* When peer's soft reconfiguration enabled. Record input packet in
2141 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002142 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2143 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002144 bgp_adj_in_set (rn, peer, attr);
2145
2146 /* Check previously received route. */
2147 for (ri = rn->info; ri; ri = ri->next)
2148 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2149 break;
2150
2151 /* AS path local-as loop check. */
2152 if (peer->change_local_as)
2153 {
2154 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2155 aspath_loop_count = 1;
2156
2157 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2158 {
2159 reason = "as-path contains our own AS;";
2160 goto filtered;
2161 }
2162 }
2163
2164 /* AS path loop check. */
2165 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2166 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2167 && aspath_loop_check(attr->aspath, bgp->confed_id)
2168 > peer->allowas_in[afi][safi]))
2169 {
2170 reason = "as-path contains our own AS;";
2171 goto filtered;
2172 }
2173
2174 /* Route reflector originator ID check. */
2175 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002176 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002177 {
2178 reason = "originator is us;";
2179 goto filtered;
2180 }
2181
2182 /* Route reflector cluster ID check. */
2183 if (bgp_cluster_filter (peer, attr))
2184 {
2185 reason = "reflected from the same cluster;";
2186 goto filtered;
2187 }
2188
2189 /* Apply incoming filter. */
2190 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2191 {
2192 reason = "filter;";
2193 goto filtered;
2194 }
2195
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002196 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002197 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002198
David Lamparterc460e572014-06-04 00:54:58 +02002199 /* Apply incoming route-map.
2200 * NB: new_attr may now contain newly allocated values from route-map "set"
2201 * commands, so we need bgp_attr_flush in the error paths, until we intern
2202 * the attr (which takes over the memory references) */
paul718e3742002-12-13 20:15:29 +00002203 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2204 {
2205 reason = "route-map;";
David Lamparterc460e572014-06-04 00:54:58 +02002206 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002207 goto filtered;
2208 }
2209
2210 /* IPv4 unicast next hop check. */
2211 if (afi == AFI_IP && safi == SAFI_UNICAST)
2212 {
2213 /* If the peer is EBGP and nexthop is not on connected route,
2214 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002215 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002216 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002217 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002218 {
2219 reason = "non-connected next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002220 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002221 goto filtered;
2222 }
2223
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002224 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002225 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002226 if (new_attr.nexthop.s_addr == 0
2227 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2228 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002229 {
2230 reason = "martian next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002231 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002232 goto filtered;
2233 }
2234 }
2235
2236 attr_new = bgp_attr_intern (&new_attr);
2237
2238 /* If the update is implicit withdraw. */
2239 if (ri)
2240 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002241 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002242
2243 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002244 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2245 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002246 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002247 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002248
2249 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002250 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002251 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2252 {
2253 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002254 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002255 peer->host,
2256 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2257 p->prefixlen);
2258
paul902212c2006-02-05 17:51:19 +00002259 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2260 {
2261 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2262 bgp_process (bgp, rn, afi, safi);
2263 }
paul718e3742002-12-13 20:15:29 +00002264 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002265 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002266 {
2267 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002268 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002269 "%s rcvd %s/%d...duplicate ignored",
2270 peer->host,
2271 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2272 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002273
2274 /* graceful restart STALE flag unset. */
2275 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2276 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002277 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002278 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002279 }
paul718e3742002-12-13 20:15:29 +00002280 }
2281
2282 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002283 bgp_attr_unintern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002284
paul718e3742002-12-13 20:15:29 +00002285 return 0;
2286 }
2287
Paul Jakma16d2e242007-04-10 19:32:10 +00002288 /* Withdraw/Announce before we fully processed the withdraw */
2289 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2290 {
2291 if (BGP_DEBUG (update, UPDATE_IN))
2292 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2293 peer->host,
2294 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2295 p->prefixlen);
2296 bgp_info_restore (rn, ri);
2297 }
2298
paul718e3742002-12-13 20:15:29 +00002299 /* Received Logging. */
2300 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002301 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002302 peer->host,
2303 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2304 p->prefixlen);
2305
hasso93406d82005-02-02 14:40:33 +00002306 /* graceful restart STALE flag unset. */
2307 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002308 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002309
paul718e3742002-12-13 20:15:29 +00002310 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002311 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002312
2313 /* implicit withdraw, decrement aggregate and pcount here.
2314 * only if update is accepted, they'll increment below.
2315 */
paul902212c2006-02-05 17:51:19 +00002316 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2317
paul718e3742002-12-13 20:15:29 +00002318 /* Update bgp route dampening information. */
2319 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002320 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002321 {
2322 /* This is implicit withdraw so we should update dampening
2323 information. */
2324 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2325 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002326 }
2327
paul718e3742002-12-13 20:15:29 +00002328 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002329 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002330 ri->attr = attr_new;
2331
2332 /* Update MPLS tag. */
2333 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002334 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002335
2336 /* Update bgp route dampening information. */
2337 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002338 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002339 {
2340 /* Now we do normal update dampening. */
2341 ret = bgp_damp_update (ri, rn, afi, safi);
2342 if (ret == BGP_DAMP_SUPPRESSED)
2343 {
2344 bgp_unlock_node (rn);
2345 return 0;
2346 }
2347 }
2348
2349 /* Nexthop reachability check. */
2350 if ((afi == AFI_IP || afi == AFI_IP6)
2351 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002352 && (peer->sort == BGP_PEER_IBGP
2353 || peer->sort == BGP_PEER_CONFED
2354 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002355 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002356 {
2357 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002358 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002359 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002360 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002361 }
2362 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002363 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002364
2365 /* Process change. */
2366 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2367
2368 bgp_process (bgp, rn, afi, safi);
2369 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002370
paul718e3742002-12-13 20:15:29 +00002371 return 0;
2372 }
2373
2374 /* Received Logging. */
2375 if (BGP_DEBUG (update, UPDATE_IN))
2376 {
ajsd2c1f162004-12-08 21:10:20 +00002377 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002378 peer->host,
2379 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2380 p->prefixlen);
2381 }
2382
paul718e3742002-12-13 20:15:29 +00002383 /* Make new BGP info. */
2384 new = bgp_info_new ();
2385 new->type = type;
2386 new->sub_type = sub_type;
2387 new->peer = peer;
2388 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002389 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002390
2391 /* Update MPLS tag. */
2392 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002393 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002394
2395 /* Nexthop reachability check. */
2396 if ((afi == AFI_IP || afi == AFI_IP6)
2397 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002398 && (peer->sort == BGP_PEER_IBGP
2399 || peer->sort == BGP_PEER_CONFED
2400 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002401 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002402 {
2403 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002404 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002405 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002406 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002407 }
2408 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002409 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002410
paul902212c2006-02-05 17:51:19 +00002411 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002412 bgp_aggregate_increment (bgp, p, new, afi, safi);
2413
2414 /* Register new BGP information. */
2415 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002416
2417 /* route_node_get lock */
2418 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002419
paul718e3742002-12-13 20:15:29 +00002420 /* If maximum prefix count is configured and current prefix
2421 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002422 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2423 return -1;
paul718e3742002-12-13 20:15:29 +00002424
2425 /* Process change. */
2426 bgp_process (bgp, rn, afi, safi);
2427
2428 return 0;
2429
2430 /* This BGP update is filtered. Log the reason then update BGP
2431 entry. */
2432 filtered:
2433 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002434 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002435 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2436 peer->host,
2437 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2438 p->prefixlen, reason);
2439
2440 if (ri)
paulb40d9392005-08-22 22:34:41 +00002441 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002442
2443 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002444
paul718e3742002-12-13 20:15:29 +00002445 return 0;
2446}
2447
2448int
paulfee0f4c2004-09-13 05:12:46 +00002449bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2450 afi_t afi, safi_t safi, int type, int sub_type,
2451 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2452{
2453 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002454 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002455 struct bgp *bgp;
2456 int ret;
2457
2458 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2459 soft_reconfig);
2460
2461 bgp = peer->bgp;
2462
2463 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002464 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002465 {
2466 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2467 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2468 sub_type, prd, tag);
2469 }
2470
2471 return ret;
2472}
2473
2474int
paul718e3742002-12-13 20:15:29 +00002475bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002476 afi_t afi, safi_t safi, int type, int sub_type,
2477 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002478{
2479 struct bgp *bgp;
2480 char buf[SU_ADDRSTRLEN];
2481 struct bgp_node *rn;
2482 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002483 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002484 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002485
2486 bgp = peer->bgp;
2487
David Lamparter4584c232015-04-13 09:50:00 +02002488 /* Lookup node. */
2489 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2490
2491 /* Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2492 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2493 * the iteration over all RS clients.
2494 * Since we need to remove the entry from adj_in anyway, do that first and
2495 * if there was no entry, we don't need to do anything more. */
2496 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2497 && peer != bgp->peer_self)
2498 if (!bgp_adj_in_unset (rn, peer))
2499 {
2500 if (BGP_DEBUG (update, UPDATE_IN))
2501 zlog (peer->log, LOG_DEBUG, "%s withdrawing route %s/%d "
2502 "not in adj-in", peer->host,
2503 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2504 p->prefixlen);
2505 bgp_unlock_node (rn);
2506 return 0;
2507 }
2508
paulfee0f4c2004-09-13 05:12:46 +00002509 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002510 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002511 {
2512 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2513 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2514 }
2515
paul718e3742002-12-13 20:15:29 +00002516 /* Logging. */
2517 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002518 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002519 peer->host,
2520 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2521 p->prefixlen);
2522
paul718e3742002-12-13 20:15:29 +00002523 /* Lookup withdrawn route. */
2524 for (ri = rn->info; ri; ri = ri->next)
2525 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2526 break;
2527
2528 /* Withdraw specified route from routing table. */
2529 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002530 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002531 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002532 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002533 "%s Can't find the route %s/%d", peer->host,
2534 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2535 p->prefixlen);
2536
2537 /* Unlock bgp_node_get() lock. */
2538 bgp_unlock_node (rn);
2539
2540 return 0;
2541}
David Lamparter6b0655a2014-06-04 06:53:35 +02002542
paul718e3742002-12-13 20:15:29 +00002543void
2544bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2545{
2546 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002547 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002548 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002549 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002550 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002551 struct bgp_node *rn;
2552 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002553 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002554
Paul Jakmab2497022007-06-14 11:17:58 +00002555 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002556 return;
2557
paul718e3742002-12-13 20:15:29 +00002558 bgp = peer->bgp;
2559 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002560
paul718e3742002-12-13 20:15:29 +00002561 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2562 aspath = attr.aspath;
2563 attr.local_pref = bgp->default_local_pref;
2564 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2565
2566 if (afi == AFI_IP)
2567 str2prefix ("0.0.0.0/0", &p);
2568#ifdef HAVE_IPV6
2569 else if (afi == AFI_IP6)
2570 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002571 struct attr_extra *ae = attr.extra;
2572
paul718e3742002-12-13 20:15:29 +00002573 str2prefix ("::/0", &p);
2574
2575 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002576 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002577 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002578 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002579
2580 /* If the peer is on shared nextwork and we have link-local
2581 nexthop set it. */
2582 if (peer->shared_network
2583 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2584 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002585 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002586 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002587 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002588 }
2589 }
2590#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002591
2592 if (peer->default_rmap[afi][safi].name)
2593 {
paulfee0f4c2004-09-13 05:12:46 +00002594 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002595 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2596 {
2597 for (ri = rn->info; ri; ri = ri->next)
2598 {
2599 struct attr dummy_attr;
2600 struct attr_extra dummy_extra;
2601 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002602
Christian Frankedcab1bb2012-12-07 16:45:52 +00002603 /* Provide dummy so the route-map can't modify the attributes */
2604 dummy_attr.extra = &dummy_extra;
2605 bgp_attr_dup(&dummy_attr, ri->attr);
2606 info.peer = ri->peer;
2607 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002608
Christian Frankedcab1bb2012-12-07 16:45:52 +00002609 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2610 RMAP_BGP, &info);
2611
2612 /* The route map might have set attributes. If we don't flush them
2613 * here, they will be leaked. */
2614 bgp_attr_flush(&dummy_attr);
2615 if (ret != RMAP_DENYMATCH)
2616 break;
2617 }
2618 if (ret != RMAP_DENYMATCH)
2619 break;
2620 }
paulfee0f4c2004-09-13 05:12:46 +00002621 bgp->peer_self->rmap_type = 0;
2622
paul718e3742002-12-13 20:15:29 +00002623 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002624 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002625 }
2626
2627 if (withdraw)
2628 {
2629 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2630 bgp_default_withdraw_send (peer, afi, safi);
2631 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2632 }
2633 else
2634 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002635 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2636 {
2637 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2638 bgp_default_update_send (peer, &attr, afi, safi, from);
2639 }
paul718e3742002-12-13 20:15:29 +00002640 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002641
2642 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002643 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002644}
David Lamparter6b0655a2014-06-04 06:53:35 +02002645
paul718e3742002-12-13 20:15:29 +00002646static void
2647bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002648 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002649{
2650 struct bgp_node *rn;
2651 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002652 struct attr attr;
2653 struct attr_extra extra;
2654
paul718e3742002-12-13 20:15:29 +00002655 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002656 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002657
2658 if (safi != SAFI_MPLS_VPN
2659 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2660 bgp_default_originate (peer, afi, safi, 0);
2661
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002662 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2663 attr.extra = &extra;
2664
paul718e3742002-12-13 20:15:29 +00002665 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2666 for (ri = rn->info; ri; ri = ri->next)
2667 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2668 {
paulfee0f4c2004-09-13 05:12:46 +00002669 if ( (rsclient) ?
2670 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2671 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002672 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2673 else
2674 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2675 }
2676}
2677
2678void
2679bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2680{
2681 struct bgp_node *rn;
2682 struct bgp_table *table;
2683
2684 if (peer->status != Established)
2685 return;
2686
2687 if (! peer->afc_nego[afi][safi])
2688 return;
2689
2690 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2691 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2692 return;
2693
2694 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002695 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002696 else
2697 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2698 rn = bgp_route_next(rn))
2699 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002700 bgp_announce_table (peer, afi, safi, table, 0);
2701
2702 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2703 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002704}
2705
2706void
2707bgp_announce_route_all (struct peer *peer)
2708{
2709 afi_t afi;
2710 safi_t safi;
2711
2712 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2713 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2714 bgp_announce_route (peer, afi, safi);
2715}
David Lamparter6b0655a2014-06-04 06:53:35 +02002716
paul718e3742002-12-13 20:15:29 +00002717static void
paulfee0f4c2004-09-13 05:12:46 +00002718bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002719 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002720{
2721 struct bgp_node *rn;
2722 struct bgp_adj_in *ain;
2723
2724 if (! table)
2725 table = rsclient->bgp->rib[afi][safi];
2726
2727 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2728 for (ain = rn->adj_in; ain; ain = ain->next)
2729 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002730 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002731 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002732
paulfee0f4c2004-09-13 05:12:46 +00002733 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002734 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002735 }
2736}
2737
2738void
2739bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2740{
2741 struct bgp_table *table;
2742 struct bgp_node *rn;
2743
2744 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002745 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002746
2747 else
2748 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2749 rn = bgp_route_next (rn))
2750 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002751 {
2752 struct prefix_rd prd;
2753 prd.family = AF_UNSPEC;
2754 prd.prefixlen = 64;
2755 memcpy(&prd.val, rn->p.u.val, 8);
2756
2757 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2758 }
paulfee0f4c2004-09-13 05:12:46 +00002759}
David Lamparter6b0655a2014-06-04 06:53:35 +02002760
paulfee0f4c2004-09-13 05:12:46 +00002761static void
paul718e3742002-12-13 20:15:29 +00002762bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002763 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002764{
2765 int ret;
2766 struct bgp_node *rn;
2767 struct bgp_adj_in *ain;
2768
2769 if (! table)
2770 table = peer->bgp->rib[afi][safi];
2771
2772 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2773 for (ain = rn->adj_in; ain; ain = ain->next)
2774 {
2775 if (ain->peer == peer)
2776 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002777 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002778 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002779
paul718e3742002-12-13 20:15:29 +00002780 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2781 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002782 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002783
paul718e3742002-12-13 20:15:29 +00002784 if (ret < 0)
2785 {
2786 bgp_unlock_node (rn);
2787 return;
2788 }
2789 continue;
2790 }
2791 }
2792}
2793
2794void
2795bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2796{
2797 struct bgp_node *rn;
2798 struct bgp_table *table;
2799
2800 if (peer->status != Established)
2801 return;
2802
2803 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002804 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002805 else
2806 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2807 rn = bgp_route_next (rn))
2808 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002809 {
2810 struct prefix_rd prd;
2811 prd.family = AF_UNSPEC;
2812 prd.prefixlen = 64;
2813 memcpy(&prd.val, rn->p.u.val, 8);
2814
2815 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2816 }
paul718e3742002-12-13 20:15:29 +00002817}
David Lamparter6b0655a2014-06-04 06:53:35 +02002818
Chris Caputo228da422009-07-18 05:44:03 +00002819
2820struct bgp_clear_node_queue
2821{
2822 struct bgp_node *rn;
2823 enum bgp_clear_route_type purpose;
2824};
2825
paul200df112005-06-01 11:17:05 +00002826static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002827bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002828{
Chris Caputo228da422009-07-18 05:44:03 +00002829 struct bgp_clear_node_queue *cnq = data;
2830 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002831 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002832 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002833 afi_t afi = bgp_node_table (rn)->afi;
2834 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002835
Paul Jakma64e580a2006-02-21 01:09:01 +00002836 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002837
Paul Jakma64e580a2006-02-21 01:09:01 +00002838 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002839 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002840 {
2841 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002842 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2843 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002844 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002845 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2846 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002847 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002848 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002849 break;
2850 }
paul200df112005-06-01 11:17:05 +00002851 return WQ_SUCCESS;
2852}
2853
2854static void
paul0fb58d52005-11-14 14:31:49 +00002855bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002856{
Chris Caputo228da422009-07-18 05:44:03 +00002857 struct bgp_clear_node_queue *cnq = data;
2858 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002859 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002860
2861 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002862 bgp_table_unlock (table);
2863 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002864}
2865
2866static void
paul94f2b392005-06-28 12:44:16 +00002867bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002868{
Paul Jakma64e580a2006-02-21 01:09:01 +00002869 struct peer *peer = wq->spec.data;
2870
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002871 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002872 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002873
2874 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002875}
2876
2877static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002878bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002879{
Paul Jakmaa2943652009-07-21 14:02:04 +01002880 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002881
Paul Jakmaa2943652009-07-21 14:02:04 +01002882 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002883#undef CLEAR_QUEUE_NAME_LEN
2884
2885 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002886 {
2887 zlog_err ("%s: Failed to allocate work queue", __func__);
2888 exit (1);
2889 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002890 peer->clear_node_queue->spec.hold = 10;
2891 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2892 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2893 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2894 peer->clear_node_queue->spec.max_retries = 0;
2895
2896 /* we only 'lock' this peer reference when the queue is actually active */
2897 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002898}
2899
paul718e3742002-12-13 20:15:29 +00002900static void
2901bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002902 struct bgp_table *table, struct peer *rsclient,
2903 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002904{
2905 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002906
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002907
paul718e3742002-12-13 20:15:29 +00002908 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002909 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002910
hasso6cf159b2005-03-21 10:28:14 +00002911 /* If still no table => afi/safi isn't configured at all or smth. */
2912 if (! table)
2913 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002914
2915 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2916 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002917 struct bgp_info *ri;
2918 struct bgp_adj_in *ain;
2919 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002920
2921 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2922 * queued for every clearing peer, regardless of whether it is
2923 * relevant to the peer at hand.
2924 *
2925 * Overview: There are 3 different indices which need to be
2926 * scrubbed, potentially, when a peer is removed:
2927 *
2928 * 1 peer's routes visible via the RIB (ie accepted routes)
2929 * 2 peer's routes visible by the (optional) peer's adj-in index
2930 * 3 other routes visible by the peer's adj-out index
2931 *
2932 * 3 there is no hurry in scrubbing, once the struct peer is
2933 * removed from bgp->peer, we could just GC such deleted peer's
2934 * adj-outs at our leisure.
2935 *
2936 * 1 and 2 must be 'scrubbed' in some way, at least made
2937 * invisible via RIB index before peer session is allowed to be
2938 * brought back up. So one needs to know when such a 'search' is
2939 * complete.
2940 *
2941 * Ideally:
2942 *
2943 * - there'd be a single global queue or a single RIB walker
2944 * - rather than tracking which route_nodes still need to be
2945 * examined on a peer basis, we'd track which peers still
2946 * aren't cleared
2947 *
2948 * Given that our per-peer prefix-counts now should be reliable,
2949 * this may actually be achievable. It doesn't seem to be a huge
2950 * problem at this time,
2951 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002952 for (ain = rn->adj_in; ain; ain = ain->next)
2953 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2954 {
2955 bgp_adj_in_remove (rn, ain);
2956 bgp_unlock_node (rn);
2957 break;
2958 }
2959 for (aout = rn->adj_out; aout; aout = aout->next)
2960 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2961 {
2962 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2963 bgp_unlock_node (rn);
2964 break;
2965 }
2966
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002967 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002968 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002969 {
Chris Caputo228da422009-07-18 05:44:03 +00002970 struct bgp_clear_node_queue *cnq;
2971
2972 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002973 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002974 bgp_lock_node (rn);
2975 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2976 sizeof (struct bgp_clear_node_queue));
2977 cnq->rn = rn;
2978 cnq->purpose = purpose;
2979 work_queue_add (peer->clear_node_queue, cnq);
2980 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002981 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002982 }
2983 return;
2984}
2985
2986void
Chris Caputo228da422009-07-18 05:44:03 +00002987bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2988 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002989{
2990 struct bgp_node *rn;
2991 struct bgp_table *table;
2992 struct peer *rsclient;
2993 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002994
Paul Jakma64e580a2006-02-21 01:09:01 +00002995 if (peer->clear_node_queue == NULL)
2996 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002997
Paul Jakmaca058a32006-09-14 02:58:49 +00002998 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2999 * Idle until it receives a Clearing_Completed event. This protects
3000 * against peers which flap faster than we can we clear, which could
3001 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00003002 *
3003 * a) race with routes from the new session being installed before
3004 * clear_route_node visits the node (to delete the route of that
3005 * peer)
3006 * b) resource exhaustion, clear_route_node likely leads to an entry
3007 * on the process_main queue. Fast-flapping could cause that queue
3008 * to grow and grow.
paul200df112005-06-01 11:17:05 +00003009 */
Donald Sharp7ef42212015-03-30 06:32:52 -07003010
3011 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3012 * the unlock will happen upon work-queue completion; other wise, the
3013 * unlock happens at the end of this function.
3014 */
Paul Jakmaca058a32006-09-14 02:58:49 +00003015 if (!peer->clear_node_queue->thread)
Donald Sharp7ef42212015-03-30 06:32:52 -07003016 peer_lock (peer);
paulfee0f4c2004-09-13 05:12:46 +00003017
Chris Caputo228da422009-07-18 05:44:03 +00003018 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00003019 {
Chris Caputo228da422009-07-18 05:44:03 +00003020 case BGP_CLEAR_ROUTE_NORMAL:
3021 if (safi != SAFI_MPLS_VPN)
3022 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
3023 else
3024 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3025 rn = bgp_route_next (rn))
3026 if ((table = rn->info) != NULL)
3027 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3028
3029 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
3030 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
3031 PEER_FLAG_RSERVER_CLIENT))
3032 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3033 break;
3034
3035 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
3036 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3037 break;
3038
3039 default:
3040 assert (0);
3041 break;
paulfee0f4c2004-09-13 05:12:46 +00003042 }
Donald Sharp7ef42212015-03-30 06:32:52 -07003043
3044 /* unlock if no nodes got added to the clear-node-queue. */
Paul Jakma65ca75e2006-05-04 08:08:15 +00003045 if (!peer->clear_node_queue->thread)
Donald Sharp7ef42212015-03-30 06:32:52 -07003046 peer_unlock (peer);
3047
paul718e3742002-12-13 20:15:29 +00003048}
3049
3050void
3051bgp_clear_route_all (struct peer *peer)
3052{
3053 afi_t afi;
3054 safi_t safi;
3055
3056 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3057 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003058 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003059}
3060
3061void
3062bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3063{
3064 struct bgp_table *table;
3065 struct bgp_node *rn;
3066 struct bgp_adj_in *ain;
3067
3068 table = peer->bgp->rib[afi][safi];
3069
3070 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3071 for (ain = rn->adj_in; ain ; ain = ain->next)
3072 if (ain->peer == peer)
3073 {
3074 bgp_adj_in_remove (rn, ain);
3075 bgp_unlock_node (rn);
3076 break;
3077 }
3078}
hasso93406d82005-02-02 14:40:33 +00003079
3080void
3081bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3082{
3083 struct bgp_node *rn;
3084 struct bgp_info *ri;
3085 struct bgp_table *table;
3086
3087 table = peer->bgp->rib[afi][safi];
3088
3089 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3090 {
3091 for (ri = rn->info; ri; ri = ri->next)
3092 if (ri->peer == peer)
3093 {
3094 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3095 bgp_rib_remove (rn, ri, peer, afi, safi);
3096 break;
3097 }
3098 }
3099}
David Lamparter6b0655a2014-06-04 06:53:35 +02003100
paul718e3742002-12-13 20:15:29 +00003101/* Delete all kernel routes. */
3102void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003103bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003104{
3105 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003106 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003107 struct bgp_node *rn;
3108 struct bgp_table *table;
3109 struct bgp_info *ri;
3110
paul1eb8ef22005-04-07 07:30:20 +00003111 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003112 {
3113 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3114
3115 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3116 for (ri = rn->info; ri; ri = ri->next)
3117 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3118 && ri->type == ZEBRA_ROUTE_BGP
3119 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003120 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003121
3122 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3123
3124 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3125 for (ri = rn->info; ri; ri = ri->next)
3126 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3127 && ri->type == ZEBRA_ROUTE_BGP
3128 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003129 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003130 }
3131}
3132
3133void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003134bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003135{
3136 vty_reset ();
3137 bgp_zclient_reset ();
3138 access_list_reset ();
3139 prefix_list_reset ();
3140}
David Lamparter6b0655a2014-06-04 06:53:35 +02003141
paul718e3742002-12-13 20:15:29 +00003142/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3143 value. */
3144int
3145bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3146{
3147 u_char *pnt;
3148 u_char *lim;
3149 struct prefix p;
3150 int psize;
3151 int ret;
3152
3153 /* Check peer status. */
3154 if (peer->status != Established)
3155 return 0;
3156
3157 pnt = packet->nlri;
3158 lim = pnt + packet->length;
3159
3160 for (; pnt < lim; pnt += psize)
3161 {
3162 /* Clear prefix structure. */
3163 memset (&p, 0, sizeof (struct prefix));
3164
3165 /* Fetch prefix length. */
3166 p.prefixlen = *pnt++;
3167 p.family = afi2family (packet->afi);
3168
3169 /* Already checked in nlri_sanity_check(). We do double check
3170 here. */
3171 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3172 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3173 return -1;
3174
3175 /* Packet size overflow check. */
3176 psize = PSIZE (p.prefixlen);
3177
3178 /* When packet overflow occur return immediately. */
3179 if (pnt + psize > lim)
3180 return -1;
3181
3182 /* Fetch prefix from NLRI packet. */
3183 memcpy (&p.u.prefix, pnt, psize);
3184
3185 /* Check address. */
3186 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3187 {
3188 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3189 {
paulf5ba3872004-07-09 12:11:31 +00003190 /*
3191 * From draft-ietf-idr-bgp4-22, Section 6.3:
3192 * If a BGP router receives an UPDATE message with a
3193 * semantically incorrect NLRI field, in which a prefix is
3194 * semantically incorrect (eg. an unexpected multicast IP
3195 * address), it should ignore the prefix.
3196 */
paul718e3742002-12-13 20:15:29 +00003197 zlog (peer->log, LOG_ERR,
3198 "IPv4 unicast NLRI is multicast address %s",
3199 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003200
paul718e3742002-12-13 20:15:29 +00003201 return -1;
3202 }
3203 }
3204
3205#ifdef HAVE_IPV6
3206 /* Check address. */
3207 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3208 {
3209 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3210 {
3211 char buf[BUFSIZ];
3212
3213 zlog (peer->log, LOG_WARNING,
3214 "IPv6 link-local NLRI received %s ignore this NLRI",
3215 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3216
3217 continue;
3218 }
3219 }
3220#endif /* HAVE_IPV6 */
3221
3222 /* Normal process. */
3223 if (attr)
3224 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3225 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3226 else
3227 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3228 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3229
3230 /* Address family configuration mismatch or maximum-prefix count
3231 overflow. */
3232 if (ret < 0)
3233 return -1;
3234 }
3235
3236 /* Packet length consistency check. */
3237 if (pnt != lim)
3238 return -1;
3239
3240 return 0;
3241}
3242
3243/* NLRI encode syntax check routine. */
3244int
3245bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3246 bgp_size_t length)
3247{
3248 u_char *end;
3249 u_char prefixlen;
3250 int psize;
3251
3252 end = pnt + length;
3253
3254 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3255 syntactic validity. If the field is syntactically incorrect,
3256 then the Error Subcode is set to Invalid Network Field. */
3257
3258 while (pnt < end)
3259 {
3260 prefixlen = *pnt++;
3261
3262 /* Prefix length check. */
3263 if ((afi == AFI_IP && prefixlen > 32)
3264 || (afi == AFI_IP6 && prefixlen > 128))
3265 {
3266 plog_err (peer->log,
3267 "%s [Error] Update packet error (wrong prefix length %d)",
3268 peer->host, prefixlen);
3269 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3270 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3271 return -1;
3272 }
3273
3274 /* Packet size overflow check. */
3275 psize = PSIZE (prefixlen);
3276
3277 if (pnt + psize > end)
3278 {
3279 plog_err (peer->log,
3280 "%s [Error] Update packet error"
3281 " (prefix data overflow prefix size is %d)",
3282 peer->host, psize);
3283 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3284 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3285 return -1;
3286 }
3287
3288 pnt += psize;
3289 }
3290
3291 /* Packet length consistency check. */
3292 if (pnt != end)
3293 {
3294 plog_err (peer->log,
3295 "%s [Error] Update packet error"
3296 " (prefix length mismatch with total length)",
3297 peer->host);
3298 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3299 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3300 return -1;
3301 }
3302 return 0;
3303}
David Lamparter6b0655a2014-06-04 06:53:35 +02003304
paul94f2b392005-06-28 12:44:16 +00003305static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003306bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003307{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003308 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003309}
3310
paul94f2b392005-06-28 12:44:16 +00003311static void
paul718e3742002-12-13 20:15:29 +00003312bgp_static_free (struct bgp_static *bgp_static)
3313{
3314 if (bgp_static->rmap.name)
3315 free (bgp_static->rmap.name);
3316 XFREE (MTYPE_BGP_STATIC, bgp_static);
3317}
3318
paul94f2b392005-06-28 12:44:16 +00003319static void
paulfee0f4c2004-09-13 05:12:46 +00003320bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3321 struct prefix *p, afi_t afi, safi_t safi)
3322{
3323 struct bgp_node *rn;
3324 struct bgp_info *ri;
3325
3326 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3327
3328 /* Check selected route and self inserted route. */
3329 for (ri = rn->info; ri; ri = ri->next)
3330 if (ri->peer == bgp->peer_self
3331 && ri->type == ZEBRA_ROUTE_BGP
3332 && ri->sub_type == BGP_ROUTE_STATIC)
3333 break;
3334
3335 /* Withdraw static BGP route from routing table. */
3336 if (ri)
3337 {
paulfee0f4c2004-09-13 05:12:46 +00003338 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003339 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003340 }
3341
3342 /* Unlock bgp_node_lookup. */
3343 bgp_unlock_node (rn);
3344}
3345
paul94f2b392005-06-28 12:44:16 +00003346static void
paulfee0f4c2004-09-13 05:12:46 +00003347bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003348 struct bgp_static *bgp_static,
3349 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003350{
3351 struct bgp_node *rn;
3352 struct bgp_info *ri;
3353 struct bgp_info *new;
3354 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003355 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003356 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003357 struct attr new_attr;
3358 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003359 struct bgp *bgp;
3360 int ret;
3361 char buf[SU_ADDRSTRLEN];
3362
3363 bgp = rsclient->bgp;
3364
Paul Jakma06e110f2006-05-12 23:29:22 +00003365 assert (bgp_static);
3366 if (!bgp_static)
3367 return;
3368
paulfee0f4c2004-09-13 05:12:46 +00003369 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3370
3371 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003372
3373 attr.nexthop = bgp_static->igpnexthop;
3374 attr.med = bgp_static->igpmetric;
3375 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003376
Paul Jakma41367172007-08-06 15:24:51 +00003377 if (bgp_static->atomic)
3378 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3379
paulfee0f4c2004-09-13 05:12:46 +00003380 /* Apply network route-map for export to this rsclient. */
3381 if (bgp_static->rmap.name)
3382 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003383 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003384 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003385 info.attr = &attr_tmp;
3386
paulfee0f4c2004-09-13 05:12:46 +00003387 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3388 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3389
3390 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3391
3392 rsclient->rmap_type = 0;
3393
3394 if (ret == RMAP_DENYMATCH)
3395 {
3396 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003397 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003398
3399 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003400 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003401 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003402 bgp_attr_extra_free (&attr);
3403
paulfee0f4c2004-09-13 05:12:46 +00003404 return;
3405 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003406 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003407 }
3408 else
3409 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003410
3411 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003412 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003413
paulfee0f4c2004-09-13 05:12:46 +00003414 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3415
Paul Jakmafb982c22007-05-04 20:15:47 +00003416 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3417 == RMAP_DENY)
3418 {
paulfee0f4c2004-09-13 05:12:46 +00003419 /* This BGP update is filtered. Log the reason then update BGP entry. */
3420 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003421 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003422 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3423 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3424 p->prefixlen, rsclient->host);
3425
3426 bgp->peer_self->rmap_type = 0;
3427
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003428 bgp_attr_unintern (&attr_new);
3429 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003430 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003431
3432 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3433
3434 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003435 }
paulfee0f4c2004-09-13 05:12:46 +00003436
3437 bgp->peer_self->rmap_type = 0;
3438
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003439 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003440 attr_new = bgp_attr_intern (&new_attr);
3441
3442 for (ri = rn->info; ri; ri = ri->next)
3443 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3444 && ri->sub_type == BGP_ROUTE_STATIC)
3445 break;
3446
3447 if (ri)
3448 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003449 if (attrhash_cmp (ri->attr, attr_new) &&
3450 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003451 {
3452 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003453 bgp_attr_unintern (&attr_new);
3454 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003455 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003456 return;
3457 }
3458 else
3459 {
3460 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003461 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003462
3463 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003464 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3465 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003466 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003467 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003468 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003469
3470 /* Process change. */
3471 bgp_process (bgp, rn, afi, safi);
3472 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003473 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003474 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003475 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003476 }
paulfee0f4c2004-09-13 05:12:46 +00003477 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003478
paulfee0f4c2004-09-13 05:12:46 +00003479 /* Make new BGP info. */
3480 new = bgp_info_new ();
3481 new->type = ZEBRA_ROUTE_BGP;
3482 new->sub_type = BGP_ROUTE_STATIC;
3483 new->peer = bgp->peer_self;
3484 SET_FLAG (new->flags, BGP_INFO_VALID);
3485 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003486 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003487
3488 /* Register new BGP information. */
3489 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003490
3491 /* route_node_get lock */
3492 bgp_unlock_node (rn);
3493
paulfee0f4c2004-09-13 05:12:46 +00003494 /* Process change. */
3495 bgp_process (bgp, rn, afi, safi);
3496
3497 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003498 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003499 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003500}
3501
paul94f2b392005-06-28 12:44:16 +00003502static void
paulfee0f4c2004-09-13 05:12:46 +00003503bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003504 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3505{
3506 struct bgp_node *rn;
3507 struct bgp_info *ri;
3508 struct bgp_info *new;
3509 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003510 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003511 struct attr *attr_new;
3512 int ret;
3513
Paul Jakmadd8103a2006-05-12 23:27:30 +00003514 assert (bgp_static);
3515 if (!bgp_static)
3516 return;
3517
paulfee0f4c2004-09-13 05:12:46 +00003518 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003519
3520 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003521
3522 attr.nexthop = bgp_static->igpnexthop;
3523 attr.med = bgp_static->igpmetric;
3524 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003525
Paul Jakma41367172007-08-06 15:24:51 +00003526 if (bgp_static->atomic)
3527 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3528
paul718e3742002-12-13 20:15:29 +00003529 /* Apply route-map. */
3530 if (bgp_static->rmap.name)
3531 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003532 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003533 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003534 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003535
paulfee0f4c2004-09-13 05:12:46 +00003536 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3537
paul718e3742002-12-13 20:15:29 +00003538 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003539
paulfee0f4c2004-09-13 05:12:46 +00003540 bgp->peer_self->rmap_type = 0;
3541
paul718e3742002-12-13 20:15:29 +00003542 if (ret == RMAP_DENYMATCH)
3543 {
3544 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003545 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003546
3547 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003548 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003549 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003550 bgp_static_withdraw (bgp, p, afi, safi);
3551 return;
3552 }
paul286e1e72003-08-08 00:24:31 +00003553 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003554 }
paul286e1e72003-08-08 00:24:31 +00003555 else
3556 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003557
3558 for (ri = rn->info; ri; ri = ri->next)
3559 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3560 && ri->sub_type == BGP_ROUTE_STATIC)
3561 break;
3562
3563 if (ri)
3564 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003565 if (attrhash_cmp (ri->attr, attr_new) &&
3566 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003567 {
3568 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003569 bgp_attr_unintern (&attr_new);
3570 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003571 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003572 return;
3573 }
3574 else
3575 {
3576 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003577 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003578
3579 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003580 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3581 bgp_info_restore(rn, ri);
3582 else
3583 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003584 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003585 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003586 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003587
3588 /* Process change. */
3589 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3590 bgp_process (bgp, rn, afi, safi);
3591 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003592 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003593 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003594 return;
3595 }
3596 }
3597
3598 /* Make new BGP info. */
3599 new = bgp_info_new ();
3600 new->type = ZEBRA_ROUTE_BGP;
3601 new->sub_type = BGP_ROUTE_STATIC;
3602 new->peer = bgp->peer_self;
3603 SET_FLAG (new->flags, BGP_INFO_VALID);
3604 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003605 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003606
3607 /* Aggregate address increment. */
3608 bgp_aggregate_increment (bgp, p, new, afi, safi);
3609
3610 /* Register new BGP information. */
3611 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003612
3613 /* route_node_get lock */
3614 bgp_unlock_node (rn);
3615
paul718e3742002-12-13 20:15:29 +00003616 /* Process change. */
3617 bgp_process (bgp, rn, afi, safi);
3618
3619 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003620 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003621 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003622}
3623
3624void
paulfee0f4c2004-09-13 05:12:46 +00003625bgp_static_update (struct bgp *bgp, struct prefix *p,
3626 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3627{
3628 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003629 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003630
3631 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3632
paul1eb8ef22005-04-07 07:30:20 +00003633 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003634 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003635 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3636 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003637 }
3638}
3639
paul94f2b392005-06-28 12:44:16 +00003640static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003641bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3642 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003643{
3644 struct bgp_node *rn;
3645 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003646
paulfee0f4c2004-09-13 05:12:46 +00003647 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003648
3649 /* Make new BGP info. */
3650 new = bgp_info_new ();
3651 new->type = ZEBRA_ROUTE_BGP;
3652 new->sub_type = BGP_ROUTE_STATIC;
3653 new->peer = bgp->peer_self;
3654 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3655 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003656 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003657 new->extra = bgp_info_extra_new();
3658 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003659
3660 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003661 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003662
3663 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003664 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003665
paul200df112005-06-01 11:17:05 +00003666 /* route_node_get lock */
3667 bgp_unlock_node (rn);
3668
paul718e3742002-12-13 20:15:29 +00003669 /* Process change. */
3670 bgp_process (bgp, rn, afi, safi);
3671}
3672
3673void
3674bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3675 safi_t safi)
3676{
3677 struct bgp_node *rn;
3678 struct bgp_info *ri;
3679
paulfee0f4c2004-09-13 05:12:46 +00003680 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003681
3682 /* Check selected route and self inserted route. */
3683 for (ri = rn->info; ri; ri = ri->next)
3684 if (ri->peer == bgp->peer_self
3685 && ri->type == ZEBRA_ROUTE_BGP
3686 && ri->sub_type == BGP_ROUTE_STATIC)
3687 break;
3688
3689 /* Withdraw static BGP route from routing table. */
3690 if (ri)
3691 {
3692 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003693 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003694 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003695 }
3696
3697 /* Unlock bgp_node_lookup. */
3698 bgp_unlock_node (rn);
3699}
3700
3701void
paulfee0f4c2004-09-13 05:12:46 +00003702bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3703{
3704 struct bgp_static *bgp_static;
3705 struct bgp *bgp;
3706 struct bgp_node *rn;
3707 struct prefix *p;
3708
3709 bgp = rsclient->bgp;
3710
3711 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3712 if ((bgp_static = rn->info) != NULL)
3713 {
3714 p = &rn->p;
3715
3716 bgp_static_update_rsclient (rsclient, p, bgp_static,
3717 afi, safi);
3718 }
3719}
3720
paul94f2b392005-06-28 12:44:16 +00003721static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003722bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3723 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003724{
3725 struct bgp_node *rn;
3726 struct bgp_info *ri;
3727
paulfee0f4c2004-09-13 05:12:46 +00003728 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003729
3730 /* Check selected route and self inserted route. */
3731 for (ri = rn->info; ri; ri = ri->next)
3732 if (ri->peer == bgp->peer_self
3733 && ri->type == ZEBRA_ROUTE_BGP
3734 && ri->sub_type == BGP_ROUTE_STATIC)
3735 break;
3736
3737 /* Withdraw static BGP route from routing table. */
3738 if (ri)
3739 {
3740 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003741 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003742 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003743 }
3744
3745 /* Unlock bgp_node_lookup. */
3746 bgp_unlock_node (rn);
3747}
3748
3749/* Configure static BGP network. When user don't run zebra, static
3750 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003751static int
paulfd79ac92004-10-13 05:06:08 +00003752bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003753 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003754{
3755 int ret;
3756 struct prefix p;
3757 struct bgp_static *bgp_static;
3758 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003759 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003760
3761 /* Convert IP prefix string to struct prefix. */
3762 ret = str2prefix (ip_str, &p);
3763 if (! ret)
3764 {
3765 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3766 return CMD_WARNING;
3767 }
3768#ifdef HAVE_IPV6
3769 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3770 {
3771 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3772 VTY_NEWLINE);
3773 return CMD_WARNING;
3774 }
3775#endif /* HAVE_IPV6 */
3776
3777 apply_mask (&p);
3778
3779 /* Set BGP static route configuration. */
3780 rn = bgp_node_get (bgp->route[afi][safi], &p);
3781
3782 if (rn->info)
3783 {
3784 /* Configuration change. */
3785 bgp_static = rn->info;
3786
3787 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003788 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3789 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003790
paul718e3742002-12-13 20:15:29 +00003791 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003792
paul718e3742002-12-13 20:15:29 +00003793 if (rmap)
3794 {
3795 if (bgp_static->rmap.name)
3796 free (bgp_static->rmap.name);
3797 bgp_static->rmap.name = strdup (rmap);
3798 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3799 }
3800 else
3801 {
3802 if (bgp_static->rmap.name)
3803 free (bgp_static->rmap.name);
3804 bgp_static->rmap.name = NULL;
3805 bgp_static->rmap.map = NULL;
3806 bgp_static->valid = 0;
3807 }
3808 bgp_unlock_node (rn);
3809 }
3810 else
3811 {
3812 /* New configuration. */
3813 bgp_static = bgp_static_new ();
3814 bgp_static->backdoor = backdoor;
3815 bgp_static->valid = 0;
3816 bgp_static->igpmetric = 0;
3817 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003818
paul718e3742002-12-13 20:15:29 +00003819 if (rmap)
3820 {
3821 if (bgp_static->rmap.name)
3822 free (bgp_static->rmap.name);
3823 bgp_static->rmap.name = strdup (rmap);
3824 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3825 }
3826 rn->info = bgp_static;
3827 }
3828
3829 /* If BGP scan is not enabled, we should install this route here. */
3830 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3831 {
3832 bgp_static->valid = 1;
3833
3834 if (need_update)
3835 bgp_static_withdraw (bgp, &p, afi, safi);
3836
3837 if (! bgp_static->backdoor)
3838 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3839 }
3840
3841 return CMD_SUCCESS;
3842}
3843
3844/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003845static int
paulfd79ac92004-10-13 05:06:08 +00003846bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003847 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003848{
3849 int ret;
3850 struct prefix p;
3851 struct bgp_static *bgp_static;
3852 struct bgp_node *rn;
3853
3854 /* Convert IP prefix string to struct prefix. */
3855 ret = str2prefix (ip_str, &p);
3856 if (! ret)
3857 {
3858 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3859 return CMD_WARNING;
3860 }
3861#ifdef HAVE_IPV6
3862 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3863 {
3864 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3865 VTY_NEWLINE);
3866 return CMD_WARNING;
3867 }
3868#endif /* HAVE_IPV6 */
3869
3870 apply_mask (&p);
3871
3872 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3873 if (! rn)
3874 {
3875 vty_out (vty, "%% Can't find specified static route configuration.%s",
3876 VTY_NEWLINE);
3877 return CMD_WARNING;
3878 }
3879
3880 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003881
paul718e3742002-12-13 20:15:29 +00003882 /* Update BGP RIB. */
3883 if (! bgp_static->backdoor)
3884 bgp_static_withdraw (bgp, &p, afi, safi);
3885
3886 /* Clear configuration. */
3887 bgp_static_free (bgp_static);
3888 rn->info = NULL;
3889 bgp_unlock_node (rn);
3890 bgp_unlock_node (rn);
3891
3892 return CMD_SUCCESS;
3893}
3894
3895/* Called from bgp_delete(). Delete all static routes from the BGP
3896 instance. */
3897void
3898bgp_static_delete (struct bgp *bgp)
3899{
3900 afi_t afi;
3901 safi_t safi;
3902 struct bgp_node *rn;
3903 struct bgp_node *rm;
3904 struct bgp_table *table;
3905 struct bgp_static *bgp_static;
3906
3907 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3908 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3909 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3910 if (rn->info != NULL)
3911 {
3912 if (safi == SAFI_MPLS_VPN)
3913 {
3914 table = rn->info;
3915
3916 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3917 {
3918 bgp_static = rn->info;
3919 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3920 AFI_IP, SAFI_MPLS_VPN,
3921 (struct prefix_rd *)&rn->p,
3922 bgp_static->tag);
3923 bgp_static_free (bgp_static);
3924 rn->info = NULL;
3925 bgp_unlock_node (rn);
3926 }
3927 }
3928 else
3929 {
3930 bgp_static = rn->info;
3931 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3932 bgp_static_free (bgp_static);
3933 rn->info = NULL;
3934 bgp_unlock_node (rn);
3935 }
3936 }
3937}
3938
3939int
paulfd79ac92004-10-13 05:06:08 +00003940bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3941 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003942{
3943 int ret;
3944 struct prefix p;
3945 struct prefix_rd prd;
3946 struct bgp *bgp;
3947 struct bgp_node *prn;
3948 struct bgp_node *rn;
3949 struct bgp_table *table;
3950 struct bgp_static *bgp_static;
3951 u_char tag[3];
3952
3953 bgp = vty->index;
3954
3955 ret = str2prefix (ip_str, &p);
3956 if (! ret)
3957 {
3958 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3959 return CMD_WARNING;
3960 }
3961 apply_mask (&p);
3962
3963 ret = str2prefix_rd (rd_str, &prd);
3964 if (! ret)
3965 {
3966 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3967 return CMD_WARNING;
3968 }
3969
3970 ret = str2tag (tag_str, tag);
3971 if (! ret)
3972 {
3973 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3974 return CMD_WARNING;
3975 }
3976
3977 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3978 (struct prefix *)&prd);
3979 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003980 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003981 else
3982 bgp_unlock_node (prn);
3983 table = prn->info;
3984
3985 rn = bgp_node_get (table, &p);
3986
3987 if (rn->info)
3988 {
3989 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3990 bgp_unlock_node (rn);
3991 }
3992 else
3993 {
3994 /* New configuration. */
3995 bgp_static = bgp_static_new ();
3996 bgp_static->valid = 1;
3997 memcpy (bgp_static->tag, tag, 3);
3998 rn->info = bgp_static;
3999
4000 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4001 }
4002
4003 return CMD_SUCCESS;
4004}
4005
4006/* Configure static BGP network. */
4007int
paulfd79ac92004-10-13 05:06:08 +00004008bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
4009 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00004010{
4011 int ret;
4012 struct bgp *bgp;
4013 struct prefix p;
4014 struct prefix_rd prd;
4015 struct bgp_node *prn;
4016 struct bgp_node *rn;
4017 struct bgp_table *table;
4018 struct bgp_static *bgp_static;
4019 u_char tag[3];
4020
4021 bgp = vty->index;
4022
4023 /* Convert IP prefix string to struct prefix. */
4024 ret = str2prefix (ip_str, &p);
4025 if (! ret)
4026 {
4027 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4028 return CMD_WARNING;
4029 }
4030 apply_mask (&p);
4031
4032 ret = str2prefix_rd (rd_str, &prd);
4033 if (! ret)
4034 {
4035 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4036 return CMD_WARNING;
4037 }
4038
4039 ret = str2tag (tag_str, tag);
4040 if (! ret)
4041 {
4042 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4043 return CMD_WARNING;
4044 }
4045
4046 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4047 (struct prefix *)&prd);
4048 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00004049 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00004050 else
4051 bgp_unlock_node (prn);
4052 table = prn->info;
4053
4054 rn = bgp_node_lookup (table, &p);
4055
4056 if (rn)
4057 {
4058 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4059
4060 bgp_static = rn->info;
4061 bgp_static_free (bgp_static);
4062 rn->info = NULL;
4063 bgp_unlock_node (rn);
4064 bgp_unlock_node (rn);
4065 }
4066 else
4067 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4068
4069 return CMD_SUCCESS;
4070}
David Lamparter6b0655a2014-06-04 06:53:35 +02004071
paul718e3742002-12-13 20:15:29 +00004072DEFUN (bgp_network,
4073 bgp_network_cmd,
4074 "network A.B.C.D/M",
4075 "Specify a network to announce via BGP\n"
4076 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4077{
4078 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004079 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004080}
4081
4082DEFUN (bgp_network_route_map,
4083 bgp_network_route_map_cmd,
4084 "network A.B.C.D/M route-map WORD",
4085 "Specify a network to announce via BGP\n"
4086 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4087 "Route-map to modify the attributes\n"
4088 "Name of the route map\n")
4089{
4090 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004091 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004092}
4093
4094DEFUN (bgp_network_backdoor,
4095 bgp_network_backdoor_cmd,
4096 "network A.B.C.D/M backdoor",
4097 "Specify a network to announce via BGP\n"
4098 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4099 "Specify a BGP backdoor route\n")
4100{
Paul Jakma41367172007-08-06 15:24:51 +00004101 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004102 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004103}
4104
4105DEFUN (bgp_network_mask,
4106 bgp_network_mask_cmd,
4107 "network A.B.C.D mask A.B.C.D",
4108 "Specify a network to announce via BGP\n"
4109 "Network number\n"
4110 "Network mask\n"
4111 "Network mask\n")
4112{
4113 int ret;
4114 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004115
paul718e3742002-12-13 20:15:29 +00004116 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4117 if (! ret)
4118 {
4119 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4120 return CMD_WARNING;
4121 }
4122
4123 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004124 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004125}
4126
4127DEFUN (bgp_network_mask_route_map,
4128 bgp_network_mask_route_map_cmd,
4129 "network A.B.C.D mask A.B.C.D route-map WORD",
4130 "Specify a network to announce via BGP\n"
4131 "Network number\n"
4132 "Network mask\n"
4133 "Network mask\n"
4134 "Route-map to modify the attributes\n"
4135 "Name of the route map\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
4147 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004148 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004149}
4150
4151DEFUN (bgp_network_mask_backdoor,
4152 bgp_network_mask_backdoor_cmd,
4153 "network A.B.C.D mask A.B.C.D backdoor",
4154 "Specify a network to announce via BGP\n"
4155 "Network number\n"
4156 "Network mask\n"
4157 "Network mask\n"
4158 "Specify a BGP backdoor route\n")
4159{
4160 int ret;
4161 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004162
paul718e3742002-12-13 20:15:29 +00004163 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4164 if (! ret)
4165 {
4166 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4167 return CMD_WARNING;
4168 }
4169
Paul Jakma41367172007-08-06 15:24:51 +00004170 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004171 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004172}
4173
4174DEFUN (bgp_network_mask_natural,
4175 bgp_network_mask_natural_cmd,
4176 "network A.B.C.D",
4177 "Specify a network to announce via BGP\n"
4178 "Network number\n")
4179{
4180 int ret;
4181 char prefix_str[BUFSIZ];
4182
4183 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4184 if (! ret)
4185 {
4186 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4187 return CMD_WARNING;
4188 }
4189
4190 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004191 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004192}
4193
4194DEFUN (bgp_network_mask_natural_route_map,
4195 bgp_network_mask_natural_route_map_cmd,
4196 "network A.B.C.D route-map WORD",
4197 "Specify a network to announce via BGP\n"
4198 "Network number\n"
4199 "Route-map to modify the attributes\n"
4200 "Name of the route map\n")
4201{
4202 int ret;
4203 char prefix_str[BUFSIZ];
4204
4205 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4206 if (! ret)
4207 {
4208 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4209 return CMD_WARNING;
4210 }
4211
4212 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004213 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004214}
4215
4216DEFUN (bgp_network_mask_natural_backdoor,
4217 bgp_network_mask_natural_backdoor_cmd,
4218 "network A.B.C.D backdoor",
4219 "Specify a network to announce via BGP\n"
4220 "Network number\n"
4221 "Specify a BGP backdoor route\n")
4222{
4223 int ret;
4224 char prefix_str[BUFSIZ];
4225
4226 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4227 if (! ret)
4228 {
4229 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4230 return CMD_WARNING;
4231 }
4232
Paul Jakma41367172007-08-06 15:24:51 +00004233 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004234 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004235}
4236
4237DEFUN (no_bgp_network,
4238 no_bgp_network_cmd,
4239 "no network A.B.C.D/M",
4240 NO_STR
4241 "Specify a network to announce via BGP\n"
4242 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4243{
4244 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4245 bgp_node_safi (vty));
4246}
4247
4248ALIAS (no_bgp_network,
4249 no_bgp_network_route_map_cmd,
4250 "no network A.B.C.D/M route-map WORD",
4251 NO_STR
4252 "Specify a network to announce via BGP\n"
4253 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4254 "Route-map to modify the attributes\n"
4255 "Name of the route map\n")
4256
4257ALIAS (no_bgp_network,
4258 no_bgp_network_backdoor_cmd,
4259 "no network A.B.C.D/M backdoor",
4260 NO_STR
4261 "Specify a network to announce via BGP\n"
4262 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4263 "Specify a BGP backdoor route\n")
4264
4265DEFUN (no_bgp_network_mask,
4266 no_bgp_network_mask_cmd,
4267 "no network A.B.C.D mask A.B.C.D",
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{
4274 int ret;
4275 char prefix_str[BUFSIZ];
4276
4277 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4278 if (! ret)
4279 {
4280 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4281 return CMD_WARNING;
4282 }
4283
4284 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4285 bgp_node_safi (vty));
4286}
4287
4288ALIAS (no_bgp_network_mask,
4289 no_bgp_network_mask_route_map_cmd,
4290 "no network A.B.C.D mask A.B.C.D route-map WORD",
4291 NO_STR
4292 "Specify a network to announce via BGP\n"
4293 "Network number\n"
4294 "Network mask\n"
4295 "Network mask\n"
4296 "Route-map to modify the attributes\n"
4297 "Name of the route map\n")
4298
4299ALIAS (no_bgp_network_mask,
4300 no_bgp_network_mask_backdoor_cmd,
4301 "no network A.B.C.D mask A.B.C.D backdoor",
4302 NO_STR
4303 "Specify a network to announce via BGP\n"
4304 "Network number\n"
4305 "Network mask\n"
4306 "Network mask\n"
4307 "Specify a BGP backdoor route\n")
4308
4309DEFUN (no_bgp_network_mask_natural,
4310 no_bgp_network_mask_natural_cmd,
4311 "no network A.B.C.D",
4312 NO_STR
4313 "Specify a network to announce via BGP\n"
4314 "Network number\n")
4315{
4316 int ret;
4317 char prefix_str[BUFSIZ];
4318
4319 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4320 if (! ret)
4321 {
4322 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4323 return CMD_WARNING;
4324 }
4325
4326 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4327 bgp_node_safi (vty));
4328}
4329
4330ALIAS (no_bgp_network_mask_natural,
4331 no_bgp_network_mask_natural_route_map_cmd,
4332 "no network A.B.C.D route-map WORD",
4333 NO_STR
4334 "Specify a network to announce via BGP\n"
4335 "Network number\n"
4336 "Route-map to modify the attributes\n"
4337 "Name of the route map\n")
4338
4339ALIAS (no_bgp_network_mask_natural,
4340 no_bgp_network_mask_natural_backdoor_cmd,
4341 "no network A.B.C.D backdoor",
4342 NO_STR
4343 "Specify a network to announce via BGP\n"
4344 "Network number\n"
4345 "Specify a BGP backdoor route\n")
4346
4347#ifdef HAVE_IPV6
4348DEFUN (ipv6_bgp_network,
4349 ipv6_bgp_network_cmd,
4350 "network X:X::X:X/M",
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_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004355 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004356}
4357
4358DEFUN (ipv6_bgp_network_route_map,
4359 ipv6_bgp_network_route_map_cmd,
4360 "network X:X::X:X/M route-map WORD",
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{
4366 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004367 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004368}
4369
4370DEFUN (no_ipv6_bgp_network,
4371 no_ipv6_bgp_network_cmd,
4372 "no network X:X::X:X/M",
4373 NO_STR
4374 "Specify a network to announce via BGP\n"
4375 "IPv6 prefix <network>/<length>\n")
4376{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304377 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004378}
4379
4380ALIAS (no_ipv6_bgp_network,
4381 no_ipv6_bgp_network_route_map_cmd,
4382 "no network X:X::X:X/M route-map WORD",
4383 NO_STR
4384 "Specify a network to announce via BGP\n"
4385 "IPv6 prefix <network>/<length>\n"
4386 "Route-map to modify the attributes\n"
4387 "Name of the route map\n")
4388
4389ALIAS (ipv6_bgp_network,
4390 old_ipv6_bgp_network_cmd,
4391 "ipv6 bgp network X:X::X:X/M",
4392 IPV6_STR
4393 BGP_STR
4394 "Specify a network to announce via BGP\n"
4395 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4396
4397ALIAS (no_ipv6_bgp_network,
4398 old_no_ipv6_bgp_network_cmd,
4399 "no ipv6 bgp network X:X::X:X/M",
4400 NO_STR
4401 IPV6_STR
4402 BGP_STR
4403 "Specify a network to announce via BGP\n"
4404 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4405#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004406
4407/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4408ALIAS_DEPRECATED (bgp_network,
4409 bgp_network_ttl_cmd,
4410 "network A.B.C.D/M pathlimit <0-255>",
4411 "Specify a network to announce via BGP\n"
4412 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4413 "AS-Path hopcount limit attribute\n"
4414 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4415ALIAS_DEPRECATED (bgp_network_backdoor,
4416 bgp_network_backdoor_ttl_cmd,
4417 "network A.B.C.D/M backdoor pathlimit <0-255>",
4418 "Specify a network to announce via BGP\n"
4419 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4420 "Specify a BGP backdoor route\n"
4421 "AS-Path hopcount limit attribute\n"
4422 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4423ALIAS_DEPRECATED (bgp_network_mask,
4424 bgp_network_mask_ttl_cmd,
4425 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4426 "Specify a network to announce via BGP\n"
4427 "Network number\n"
4428 "Network mask\n"
4429 "Network mask\n"
4430 "AS-Path hopcount limit attribute\n"
4431 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4432ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4433 bgp_network_mask_backdoor_ttl_cmd,
4434 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4435 "Specify a network to announce via BGP\n"
4436 "Network number\n"
4437 "Network mask\n"
4438 "Network mask\n"
4439 "Specify a BGP backdoor route\n"
4440 "AS-Path hopcount limit attribute\n"
4441 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4442ALIAS_DEPRECATED (bgp_network_mask_natural,
4443 bgp_network_mask_natural_ttl_cmd,
4444 "network A.B.C.D pathlimit <0-255>",
4445 "Specify a network to announce via BGP\n"
4446 "Network number\n"
4447 "AS-Path hopcount limit attribute\n"
4448 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4449ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4450 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004451 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004452 "Specify a network to announce via BGP\n"
4453 "Network number\n"
4454 "Specify a BGP backdoor route\n"
4455 "AS-Path hopcount limit attribute\n"
4456 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4457ALIAS_DEPRECATED (no_bgp_network,
4458 no_bgp_network_ttl_cmd,
4459 "no network A.B.C.D/M pathlimit <0-255>",
4460 NO_STR
4461 "Specify a network to announce via BGP\n"
4462 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4463 "AS-Path hopcount limit attribute\n"
4464 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4465ALIAS_DEPRECATED (no_bgp_network,
4466 no_bgp_network_backdoor_ttl_cmd,
4467 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4468 NO_STR
4469 "Specify a network to announce via BGP\n"
4470 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4471 "Specify a BGP backdoor route\n"
4472 "AS-Path hopcount limit attribute\n"
4473 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4474ALIAS_DEPRECATED (no_bgp_network,
4475 no_bgp_network_mask_ttl_cmd,
4476 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4477 NO_STR
4478 "Specify a network to announce via BGP\n"
4479 "Network number\n"
4480 "Network mask\n"
4481 "Network mask\n"
4482 "AS-Path hopcount limit attribute\n"
4483 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4484ALIAS_DEPRECATED (no_bgp_network_mask,
4485 no_bgp_network_mask_backdoor_ttl_cmd,
4486 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4487 NO_STR
4488 "Specify a network to announce via BGP\n"
4489 "Network number\n"
4490 "Network mask\n"
4491 "Network mask\n"
4492 "Specify a BGP backdoor route\n"
4493 "AS-Path hopcount limit attribute\n"
4494 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4495ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4496 no_bgp_network_mask_natural_ttl_cmd,
4497 "no network A.B.C.D pathlimit <0-255>",
4498 NO_STR
4499 "Specify a network to announce via BGP\n"
4500 "Network number\n"
4501 "AS-Path hopcount limit attribute\n"
4502 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4503ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4504 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4505 "no network A.B.C.D backdoor pathlimit <0-255>",
4506 NO_STR
4507 "Specify a network to announce via BGP\n"
4508 "Network number\n"
4509 "Specify a BGP backdoor route\n"
4510 "AS-Path hopcount limit attribute\n"
4511 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004512#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004513ALIAS_DEPRECATED (ipv6_bgp_network,
4514 ipv6_bgp_network_ttl_cmd,
4515 "network X:X::X:X/M pathlimit <0-255>",
4516 "Specify a network to announce via BGP\n"
4517 "IPv6 prefix <network>/<length>\n"
4518 "AS-Path hopcount limit attribute\n"
4519 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4520ALIAS_DEPRECATED (no_ipv6_bgp_network,
4521 no_ipv6_bgp_network_ttl_cmd,
4522 "no network X:X::X:X/M pathlimit <0-255>",
4523 NO_STR
4524 "Specify a network to announce via BGP\n"
4525 "IPv6 prefix <network>/<length>\n"
4526 "AS-Path hopcount limit attribute\n"
4527 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004528#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02004529
paul718e3742002-12-13 20:15:29 +00004530/* Aggreagete address:
4531
4532 advertise-map Set condition to advertise attribute
4533 as-set Generate AS set path information
4534 attribute-map Set attributes of aggregate
4535 route-map Set parameters of aggregate
4536 summary-only Filter more specific routes from updates
4537 suppress-map Conditionally filter more specific routes from updates
4538 <cr>
4539 */
4540struct bgp_aggregate
4541{
4542 /* Summary-only flag. */
4543 u_char summary_only;
4544
4545 /* AS set generation. */
4546 u_char as_set;
4547
4548 /* Route-map for aggregated route. */
4549 struct route_map *map;
4550
4551 /* Suppress-count. */
4552 unsigned long count;
4553
4554 /* SAFI configuration. */
4555 safi_t safi;
4556};
4557
paul94f2b392005-06-28 12:44:16 +00004558static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004559bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004560{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004561 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004562}
4563
paul94f2b392005-06-28 12:44:16 +00004564static void
paul718e3742002-12-13 20:15:29 +00004565bgp_aggregate_free (struct bgp_aggregate *aggregate)
4566{
4567 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4568}
4569
paul94f2b392005-06-28 12:44:16 +00004570static void
paul718e3742002-12-13 20:15:29 +00004571bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4572 afi_t afi, safi_t safi, struct bgp_info *del,
4573 struct bgp_aggregate *aggregate)
4574{
4575 struct bgp_table *table;
4576 struct bgp_node *top;
4577 struct bgp_node *rn;
4578 u_char origin;
4579 struct aspath *aspath = NULL;
4580 struct aspath *asmerge = NULL;
4581 struct community *community = NULL;
4582 struct community *commerge = NULL;
paul718e3742002-12-13 20:15:29 +00004583 struct bgp_info *ri;
4584 struct bgp_info *new;
4585 int first = 1;
4586 unsigned long match = 0;
4587
paul718e3742002-12-13 20:15:29 +00004588 /* ORIGIN attribute: If at least one route among routes that are
4589 aggregated has ORIGIN with the value INCOMPLETE, then the
4590 aggregated route must have the ORIGIN attribute with the value
4591 INCOMPLETE. Otherwise, if at least one route among routes that
4592 are aggregated has ORIGIN with the value EGP, then the aggregated
4593 route must have the origin attribute with the value EGP. In all
4594 other case the value of the ORIGIN attribute of the aggregated
4595 route is INTERNAL. */
4596 origin = BGP_ORIGIN_IGP;
4597
4598 table = bgp->rib[afi][safi];
4599
4600 top = bgp_node_get (table, p);
4601 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4602 if (rn->p.prefixlen > p->prefixlen)
4603 {
4604 match = 0;
4605
4606 for (ri = rn->info; ri; ri = ri->next)
4607 {
4608 if (BGP_INFO_HOLDDOWN (ri))
4609 continue;
4610
4611 if (del && ri == del)
4612 continue;
4613
4614 if (! rinew && first)
Paul Jakma7aa9dce2014-09-19 14:42:23 +01004615 first = 0;
paul718e3742002-12-13 20:15:29 +00004616
4617#ifdef AGGREGATE_NEXTHOP_CHECK
4618 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4619 || ri->attr->med != med)
4620 {
4621 if (aspath)
4622 aspath_free (aspath);
4623 if (community)
4624 community_free (community);
4625 bgp_unlock_node (rn);
4626 bgp_unlock_node (top);
4627 return;
4628 }
4629#endif /* AGGREGATE_NEXTHOP_CHECK */
4630
4631 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4632 {
4633 if (aggregate->summary_only)
4634 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004635 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004636 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004637 match++;
4638 }
4639
4640 aggregate->count++;
4641
4642 if (aggregate->as_set)
4643 {
4644 if (origin < ri->attr->origin)
4645 origin = ri->attr->origin;
4646
4647 if (aspath)
4648 {
4649 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4650 aspath_free (aspath);
4651 aspath = asmerge;
4652 }
4653 else
4654 aspath = aspath_dup (ri->attr->aspath);
4655
4656 if (ri->attr->community)
4657 {
4658 if (community)
4659 {
4660 commerge = community_merge (community,
4661 ri->attr->community);
4662 community = community_uniq_sort (commerge);
4663 community_free (commerge);
4664 }
4665 else
4666 community = community_dup (ri->attr->community);
4667 }
4668 }
4669 }
4670 }
4671 if (match)
4672 bgp_process (bgp, rn, afi, safi);
4673 }
4674 bgp_unlock_node (top);
4675
4676 if (rinew)
4677 {
4678 aggregate->count++;
4679
4680 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004681 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004682
4683 if (aggregate->as_set)
4684 {
4685 if (origin < rinew->attr->origin)
4686 origin = rinew->attr->origin;
4687
4688 if (aspath)
4689 {
4690 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4691 aspath_free (aspath);
4692 aspath = asmerge;
4693 }
4694 else
4695 aspath = aspath_dup (rinew->attr->aspath);
4696
4697 if (rinew->attr->community)
4698 {
4699 if (community)
4700 {
4701 commerge = community_merge (community,
4702 rinew->attr->community);
4703 community = community_uniq_sort (commerge);
4704 community_free (commerge);
4705 }
4706 else
4707 community = community_dup (rinew->attr->community);
4708 }
4709 }
4710 }
4711
4712 if (aggregate->count > 0)
4713 {
4714 rn = bgp_node_get (table, p);
4715 new = bgp_info_new ();
4716 new->type = ZEBRA_ROUTE_BGP;
4717 new->sub_type = BGP_ROUTE_AGGREGATE;
4718 new->peer = bgp->peer_self;
4719 SET_FLAG (new->flags, BGP_INFO_VALID);
4720 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004721 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004722
4723 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004724 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004725 bgp_process (bgp, rn, afi, safi);
4726 }
4727 else
4728 {
4729 if (aspath)
4730 aspath_free (aspath);
4731 if (community)
4732 community_free (community);
4733 }
4734}
4735
4736void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4737 struct bgp_aggregate *);
4738
4739void
4740bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4741 struct bgp_info *ri, afi_t afi, safi_t safi)
4742{
4743 struct bgp_node *child;
4744 struct bgp_node *rn;
4745 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004746 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004747
4748 /* MPLS-VPN aggregation is not yet supported. */
4749 if (safi == SAFI_MPLS_VPN)
4750 return;
4751
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004752 table = bgp->aggregate[afi][safi];
4753
4754 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004755 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004756 return;
4757
paul718e3742002-12-13 20:15:29 +00004758 if (p->prefixlen == 0)
4759 return;
4760
4761 if (BGP_INFO_HOLDDOWN (ri))
4762 return;
4763
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004764 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004765
4766 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004767 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004768 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4769 {
4770 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004771 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004772 }
4773 bgp_unlock_node (child);
4774}
4775
4776void
4777bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4778 struct bgp_info *del, afi_t afi, safi_t safi)
4779{
4780 struct bgp_node *child;
4781 struct bgp_node *rn;
4782 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004783 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004784
4785 /* MPLS-VPN aggregation is not yet supported. */
4786 if (safi == SAFI_MPLS_VPN)
4787 return;
4788
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004789 table = bgp->aggregate[afi][safi];
4790
4791 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004792 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004793 return;
4794
paul718e3742002-12-13 20:15:29 +00004795 if (p->prefixlen == 0)
4796 return;
4797
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004798 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004799
4800 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004801 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004802 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4803 {
4804 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004805 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004806 }
4807 bgp_unlock_node (child);
4808}
4809
paul94f2b392005-06-28 12:44:16 +00004810static void
paul718e3742002-12-13 20:15:29 +00004811bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4812 struct bgp_aggregate *aggregate)
4813{
4814 struct bgp_table *table;
4815 struct bgp_node *top;
4816 struct bgp_node *rn;
4817 struct bgp_info *new;
4818 struct bgp_info *ri;
4819 unsigned long match;
4820 u_char origin = BGP_ORIGIN_IGP;
4821 struct aspath *aspath = NULL;
4822 struct aspath *asmerge = NULL;
4823 struct community *community = NULL;
4824 struct community *commerge = NULL;
4825
4826 table = bgp->rib[afi][safi];
4827
4828 /* Sanity check. */
4829 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4830 return;
4831 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4832 return;
4833
4834 /* If routes exists below this node, generate aggregate routes. */
4835 top = bgp_node_get (table, p);
4836 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4837 if (rn->p.prefixlen > p->prefixlen)
4838 {
4839 match = 0;
4840
4841 for (ri = rn->info; ri; ri = ri->next)
4842 {
4843 if (BGP_INFO_HOLDDOWN (ri))
4844 continue;
4845
4846 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4847 {
4848 /* summary-only aggregate route suppress aggregated
4849 route announcement. */
4850 if (aggregate->summary_only)
4851 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004852 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004853 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004854 match++;
4855 }
4856 /* as-set aggregate route generate origin, as path,
4857 community aggregation. */
4858 if (aggregate->as_set)
4859 {
4860 if (origin < ri->attr->origin)
4861 origin = ri->attr->origin;
4862
4863 if (aspath)
4864 {
4865 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4866 aspath_free (aspath);
4867 aspath = asmerge;
4868 }
4869 else
4870 aspath = aspath_dup (ri->attr->aspath);
4871
4872 if (ri->attr->community)
4873 {
4874 if (community)
4875 {
4876 commerge = community_merge (community,
4877 ri->attr->community);
4878 community = community_uniq_sort (commerge);
4879 community_free (commerge);
4880 }
4881 else
4882 community = community_dup (ri->attr->community);
4883 }
4884 }
4885 aggregate->count++;
4886 }
4887 }
4888
4889 /* If this node is suppressed, process the change. */
4890 if (match)
4891 bgp_process (bgp, rn, afi, safi);
4892 }
4893 bgp_unlock_node (top);
4894
4895 /* Add aggregate route to BGP table. */
4896 if (aggregate->count)
4897 {
4898 rn = bgp_node_get (table, p);
4899
4900 new = bgp_info_new ();
4901 new->type = ZEBRA_ROUTE_BGP;
4902 new->sub_type = BGP_ROUTE_AGGREGATE;
4903 new->peer = bgp->peer_self;
4904 SET_FLAG (new->flags, BGP_INFO_VALID);
4905 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004906 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004907
4908 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004909 bgp_unlock_node (rn);
4910
paul718e3742002-12-13 20:15:29 +00004911 /* Process change. */
4912 bgp_process (bgp, rn, afi, safi);
4913 }
Denil Virae2a92582015-08-11 13:34:59 -07004914 else
4915 {
4916 if (aspath)
4917 aspath_free (aspath);
4918 if (community)
4919 community_free (community);
4920 }
paul718e3742002-12-13 20:15:29 +00004921}
4922
4923void
4924bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4925 safi_t safi, struct bgp_aggregate *aggregate)
4926{
4927 struct bgp_table *table;
4928 struct bgp_node *top;
4929 struct bgp_node *rn;
4930 struct bgp_info *ri;
4931 unsigned long match;
4932
4933 table = bgp->rib[afi][safi];
4934
4935 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4936 return;
4937 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4938 return;
4939
4940 /* If routes exists below this node, generate aggregate routes. */
4941 top = bgp_node_get (table, p);
4942 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4943 if (rn->p.prefixlen > p->prefixlen)
4944 {
4945 match = 0;
4946
4947 for (ri = rn->info; ri; ri = ri->next)
4948 {
4949 if (BGP_INFO_HOLDDOWN (ri))
4950 continue;
4951
4952 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4953 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004954 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004955 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004956 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004957
Paul Jakmafb982c22007-05-04 20:15:47 +00004958 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004959 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004960 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004961 match++;
4962 }
4963 }
4964 aggregate->count--;
4965 }
4966 }
4967
Paul Jakmafb982c22007-05-04 20:15:47 +00004968 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004969 if (match)
4970 bgp_process (bgp, rn, afi, safi);
4971 }
4972 bgp_unlock_node (top);
4973
4974 /* Delete aggregate route from BGP table. */
4975 rn = bgp_node_get (table, p);
4976
4977 for (ri = rn->info; ri; ri = ri->next)
4978 if (ri->peer == bgp->peer_self
4979 && ri->type == ZEBRA_ROUTE_BGP
4980 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4981 break;
4982
4983 /* Withdraw static BGP route from routing table. */
4984 if (ri)
4985 {
paul718e3742002-12-13 20:15:29 +00004986 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004987 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004988 }
4989
4990 /* Unlock bgp_node_lookup. */
4991 bgp_unlock_node (rn);
4992}
4993
4994/* Aggregate route attribute. */
4995#define AGGREGATE_SUMMARY_ONLY 1
4996#define AGGREGATE_AS_SET 1
4997
paul94f2b392005-06-28 12:44:16 +00004998static int
Robert Baysf6269b42010-08-05 10:26:28 -07004999bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5000 afi_t afi, safi_t safi)
5001{
5002 int ret;
5003 struct prefix p;
5004 struct bgp_node *rn;
5005 struct bgp *bgp;
5006 struct bgp_aggregate *aggregate;
5007
5008 /* Convert string to prefix structure. */
5009 ret = str2prefix (prefix_str, &p);
5010 if (!ret)
5011 {
5012 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5013 return CMD_WARNING;
5014 }
5015 apply_mask (&p);
5016
5017 /* Get BGP structure. */
5018 bgp = vty->index;
5019
5020 /* Old configuration check. */
5021 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5022 if (! rn)
5023 {
5024 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5025 VTY_NEWLINE);
5026 return CMD_WARNING;
5027 }
5028
5029 aggregate = rn->info;
5030 if (aggregate->safi & SAFI_UNICAST)
5031 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5032 if (aggregate->safi & SAFI_MULTICAST)
5033 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5034
5035 /* Unlock aggregate address configuration. */
5036 rn->info = NULL;
5037 bgp_aggregate_free (aggregate);
5038 bgp_unlock_node (rn);
5039 bgp_unlock_node (rn);
5040
5041 return CMD_SUCCESS;
5042}
5043
5044static int
5045bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00005046 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00005047 u_char summary_only, u_char as_set)
5048{
5049 int ret;
5050 struct prefix p;
5051 struct bgp_node *rn;
5052 struct bgp *bgp;
5053 struct bgp_aggregate *aggregate;
5054
5055 /* Convert string to prefix structure. */
5056 ret = str2prefix (prefix_str, &p);
5057 if (!ret)
5058 {
5059 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5060 return CMD_WARNING;
5061 }
5062 apply_mask (&p);
5063
5064 /* Get BGP structure. */
5065 bgp = vty->index;
5066
5067 /* Old configuration check. */
5068 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5069
5070 if (rn->info)
5071 {
5072 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005073 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005074 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5075 if (ret)
5076 {
Robert Bays368473f2010-08-05 10:26:29 -07005077 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5078 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005079 return CMD_WARNING;
5080 }
paul718e3742002-12-13 20:15:29 +00005081 }
5082
5083 /* Make aggregate address structure. */
5084 aggregate = bgp_aggregate_new ();
5085 aggregate->summary_only = summary_only;
5086 aggregate->as_set = as_set;
5087 aggregate->safi = safi;
5088 rn->info = aggregate;
5089
5090 /* Aggregate address insert into BGP routing table. */
5091 if (safi & SAFI_UNICAST)
5092 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5093 if (safi & SAFI_MULTICAST)
5094 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5095
5096 return CMD_SUCCESS;
5097}
5098
paul718e3742002-12-13 20:15:29 +00005099DEFUN (aggregate_address,
5100 aggregate_address_cmd,
5101 "aggregate-address A.B.C.D/M",
5102 "Configure BGP aggregate entries\n"
5103 "Aggregate prefix\n")
5104{
5105 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5106}
5107
5108DEFUN (aggregate_address_mask,
5109 aggregate_address_mask_cmd,
5110 "aggregate-address A.B.C.D A.B.C.D",
5111 "Configure BGP aggregate entries\n"
5112 "Aggregate address\n"
5113 "Aggregate mask\n")
5114{
5115 int ret;
5116 char prefix_str[BUFSIZ];
5117
5118 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5119
5120 if (! ret)
5121 {
5122 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5123 return CMD_WARNING;
5124 }
5125
5126 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5127 0, 0);
5128}
5129
5130DEFUN (aggregate_address_summary_only,
5131 aggregate_address_summary_only_cmd,
5132 "aggregate-address A.B.C.D/M summary-only",
5133 "Configure BGP aggregate entries\n"
5134 "Aggregate prefix\n"
5135 "Filter more specific routes from updates\n")
5136{
5137 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5138 AGGREGATE_SUMMARY_ONLY, 0);
5139}
5140
5141DEFUN (aggregate_address_mask_summary_only,
5142 aggregate_address_mask_summary_only_cmd,
5143 "aggregate-address A.B.C.D A.B.C.D summary-only",
5144 "Configure BGP aggregate entries\n"
5145 "Aggregate address\n"
5146 "Aggregate mask\n"
5147 "Filter more specific routes from updates\n")
5148{
5149 int ret;
5150 char prefix_str[BUFSIZ];
5151
5152 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5153
5154 if (! ret)
5155 {
5156 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5157 return CMD_WARNING;
5158 }
5159
5160 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5161 AGGREGATE_SUMMARY_ONLY, 0);
5162}
5163
5164DEFUN (aggregate_address_as_set,
5165 aggregate_address_as_set_cmd,
5166 "aggregate-address A.B.C.D/M as-set",
5167 "Configure BGP aggregate entries\n"
5168 "Aggregate prefix\n"
5169 "Generate AS set path information\n")
5170{
5171 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5172 0, AGGREGATE_AS_SET);
5173}
5174
5175DEFUN (aggregate_address_mask_as_set,
5176 aggregate_address_mask_as_set_cmd,
5177 "aggregate-address A.B.C.D A.B.C.D as-set",
5178 "Configure BGP aggregate entries\n"
5179 "Aggregate address\n"
5180 "Aggregate mask\n"
5181 "Generate AS set path information\n")
5182{
5183 int ret;
5184 char prefix_str[BUFSIZ];
5185
5186 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5187
5188 if (! ret)
5189 {
5190 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5191 return CMD_WARNING;
5192 }
5193
5194 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5195 0, AGGREGATE_AS_SET);
5196}
5197
5198
5199DEFUN (aggregate_address_as_set_summary,
5200 aggregate_address_as_set_summary_cmd,
5201 "aggregate-address A.B.C.D/M as-set summary-only",
5202 "Configure BGP aggregate entries\n"
5203 "Aggregate prefix\n"
5204 "Generate AS set path information\n"
5205 "Filter more specific routes from updates\n")
5206{
5207 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5208 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5209}
5210
5211ALIAS (aggregate_address_as_set_summary,
5212 aggregate_address_summary_as_set_cmd,
5213 "aggregate-address A.B.C.D/M summary-only as-set",
5214 "Configure BGP aggregate entries\n"
5215 "Aggregate prefix\n"
5216 "Filter more specific routes from updates\n"
5217 "Generate AS set path information\n")
5218
5219DEFUN (aggregate_address_mask_as_set_summary,
5220 aggregate_address_mask_as_set_summary_cmd,
5221 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5222 "Configure BGP aggregate entries\n"
5223 "Aggregate address\n"
5224 "Aggregate mask\n"
5225 "Generate AS set path information\n"
5226 "Filter more specific routes from updates\n")
5227{
5228 int ret;
5229 char prefix_str[BUFSIZ];
5230
5231 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5232
5233 if (! ret)
5234 {
5235 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5236 return CMD_WARNING;
5237 }
5238
5239 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5240 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5241}
5242
5243ALIAS (aggregate_address_mask_as_set_summary,
5244 aggregate_address_mask_summary_as_set_cmd,
5245 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5246 "Configure BGP aggregate entries\n"
5247 "Aggregate address\n"
5248 "Aggregate mask\n"
5249 "Filter more specific routes from updates\n"
5250 "Generate AS set path information\n")
5251
5252DEFUN (no_aggregate_address,
5253 no_aggregate_address_cmd,
5254 "no aggregate-address A.B.C.D/M",
5255 NO_STR
5256 "Configure BGP aggregate entries\n"
5257 "Aggregate prefix\n")
5258{
5259 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5260}
5261
5262ALIAS (no_aggregate_address,
5263 no_aggregate_address_summary_only_cmd,
5264 "no aggregate-address A.B.C.D/M summary-only",
5265 NO_STR
5266 "Configure BGP aggregate entries\n"
5267 "Aggregate prefix\n"
5268 "Filter more specific routes from updates\n")
5269
5270ALIAS (no_aggregate_address,
5271 no_aggregate_address_as_set_cmd,
5272 "no aggregate-address A.B.C.D/M as-set",
5273 NO_STR
5274 "Configure BGP aggregate entries\n"
5275 "Aggregate prefix\n"
5276 "Generate AS set path information\n")
5277
5278ALIAS (no_aggregate_address,
5279 no_aggregate_address_as_set_summary_cmd,
5280 "no aggregate-address A.B.C.D/M as-set summary-only",
5281 NO_STR
5282 "Configure BGP aggregate entries\n"
5283 "Aggregate prefix\n"
5284 "Generate AS set path information\n"
5285 "Filter more specific routes from updates\n")
5286
5287ALIAS (no_aggregate_address,
5288 no_aggregate_address_summary_as_set_cmd,
5289 "no aggregate-address A.B.C.D/M summary-only as-set",
5290 NO_STR
5291 "Configure BGP aggregate entries\n"
5292 "Aggregate prefix\n"
5293 "Filter more specific routes from updates\n"
5294 "Generate AS set path information\n")
5295
5296DEFUN (no_aggregate_address_mask,
5297 no_aggregate_address_mask_cmd,
5298 "no aggregate-address A.B.C.D A.B.C.D",
5299 NO_STR
5300 "Configure BGP aggregate entries\n"
5301 "Aggregate address\n"
5302 "Aggregate mask\n")
5303{
5304 int ret;
5305 char prefix_str[BUFSIZ];
5306
5307 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5308
5309 if (! ret)
5310 {
5311 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5312 return CMD_WARNING;
5313 }
5314
5315 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5316}
5317
5318ALIAS (no_aggregate_address_mask,
5319 no_aggregate_address_mask_summary_only_cmd,
5320 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5321 NO_STR
5322 "Configure BGP aggregate entries\n"
5323 "Aggregate address\n"
5324 "Aggregate mask\n"
5325 "Filter more specific routes from updates\n")
5326
5327ALIAS (no_aggregate_address_mask,
5328 no_aggregate_address_mask_as_set_cmd,
5329 "no aggregate-address A.B.C.D A.B.C.D as-set",
5330 NO_STR
5331 "Configure BGP aggregate entries\n"
5332 "Aggregate address\n"
5333 "Aggregate mask\n"
5334 "Generate AS set path information\n")
5335
5336ALIAS (no_aggregate_address_mask,
5337 no_aggregate_address_mask_as_set_summary_cmd,
5338 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5339 NO_STR
5340 "Configure BGP aggregate entries\n"
5341 "Aggregate address\n"
5342 "Aggregate mask\n"
5343 "Generate AS set path information\n"
5344 "Filter more specific routes from updates\n")
5345
5346ALIAS (no_aggregate_address_mask,
5347 no_aggregate_address_mask_summary_as_set_cmd,
5348 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5349 NO_STR
5350 "Configure BGP aggregate entries\n"
5351 "Aggregate address\n"
5352 "Aggregate mask\n"
5353 "Filter more specific routes from updates\n"
5354 "Generate AS set path information\n")
5355
5356#ifdef HAVE_IPV6
5357DEFUN (ipv6_aggregate_address,
5358 ipv6_aggregate_address_cmd,
5359 "aggregate-address X:X::X:X/M",
5360 "Configure BGP aggregate entries\n"
5361 "Aggregate prefix\n")
5362{
5363 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5364}
5365
5366DEFUN (ipv6_aggregate_address_summary_only,
5367 ipv6_aggregate_address_summary_only_cmd,
5368 "aggregate-address X:X::X:X/M summary-only",
5369 "Configure BGP aggregate entries\n"
5370 "Aggregate prefix\n"
5371 "Filter more specific routes from updates\n")
5372{
5373 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5374 AGGREGATE_SUMMARY_ONLY, 0);
5375}
5376
5377DEFUN (no_ipv6_aggregate_address,
5378 no_ipv6_aggregate_address_cmd,
5379 "no aggregate-address X:X::X:X/M",
5380 NO_STR
5381 "Configure BGP aggregate entries\n"
5382 "Aggregate prefix\n")
5383{
5384 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5385}
5386
5387DEFUN (no_ipv6_aggregate_address_summary_only,
5388 no_ipv6_aggregate_address_summary_only_cmd,
5389 "no aggregate-address X:X::X:X/M summary-only",
5390 NO_STR
5391 "Configure BGP aggregate entries\n"
5392 "Aggregate prefix\n"
5393 "Filter more specific routes from updates\n")
5394{
5395 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5396}
5397
5398ALIAS (ipv6_aggregate_address,
5399 old_ipv6_aggregate_address_cmd,
5400 "ipv6 bgp aggregate-address X:X::X:X/M",
5401 IPV6_STR
5402 BGP_STR
5403 "Configure BGP aggregate entries\n"
5404 "Aggregate prefix\n")
5405
5406ALIAS (ipv6_aggregate_address_summary_only,
5407 old_ipv6_aggregate_address_summary_only_cmd,
5408 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5409 IPV6_STR
5410 BGP_STR
5411 "Configure BGP aggregate entries\n"
5412 "Aggregate prefix\n"
5413 "Filter more specific routes from updates\n")
5414
5415ALIAS (no_ipv6_aggregate_address,
5416 old_no_ipv6_aggregate_address_cmd,
5417 "no ipv6 bgp aggregate-address X:X::X:X/M",
5418 NO_STR
5419 IPV6_STR
5420 BGP_STR
5421 "Configure BGP aggregate entries\n"
5422 "Aggregate prefix\n")
5423
5424ALIAS (no_ipv6_aggregate_address_summary_only,
5425 old_no_ipv6_aggregate_address_summary_only_cmd,
5426 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5427 NO_STR
5428 IPV6_STR
5429 BGP_STR
5430 "Configure BGP aggregate entries\n"
5431 "Aggregate prefix\n"
5432 "Filter more specific routes from updates\n")
5433#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02005434
paul718e3742002-12-13 20:15:29 +00005435/* Redistribute route treatment. */
5436void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005437bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5438 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005439 u_int32_t metric, u_char type)
5440{
5441 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005442 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005443 struct bgp_info *new;
5444 struct bgp_info *bi;
5445 struct bgp_info info;
5446 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005447 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005448 struct attr *new_attr;
5449 afi_t afi;
5450 int ret;
5451
5452 /* Make default attribute. */
5453 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5454 if (nexthop)
5455 attr.nexthop = *nexthop;
5456
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005457#ifdef HAVE_IPV6
5458 if (nexthop6)
5459 {
5460 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5461 extra->mp_nexthop_global = *nexthop6;
5462 extra->mp_nexthop_len = 16;
5463 }
5464#endif
5465
paul718e3742002-12-13 20:15:29 +00005466 attr.med = metric;
5467 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5468
paul1eb8ef22005-04-07 07:30:20 +00005469 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005470 {
5471 afi = family2afi (p->family);
5472
5473 if (bgp->redist[afi][type])
5474 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005475 struct attr attr_new;
5476 struct attr_extra extra_new;
5477
paul718e3742002-12-13 20:15:29 +00005478 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005479 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005480 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005481
5482 if (bgp->redist_metric_flag[afi][type])
5483 attr_new.med = bgp->redist_metric[afi][type];
5484
5485 /* Apply route-map. */
Daniel Walton1994dc82015-09-17 10:15:59 -04005486 if (bgp->rmap[afi][type].name)
paul718e3742002-12-13 20:15:29 +00005487 {
5488 info.peer = bgp->peer_self;
5489 info.attr = &attr_new;
5490
paulfee0f4c2004-09-13 05:12:46 +00005491 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5492
paul718e3742002-12-13 20:15:29 +00005493 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5494 &info);
paulfee0f4c2004-09-13 05:12:46 +00005495
5496 bgp->peer_self->rmap_type = 0;
5497
paul718e3742002-12-13 20:15:29 +00005498 if (ret == RMAP_DENYMATCH)
5499 {
5500 /* Free uninterned attribute. */
5501 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005502
paul718e3742002-12-13 20:15:29 +00005503 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005504 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_redistribute_delete (p, type);
5507 return;
5508 }
5509 }
5510
Paul Jakmafb982c22007-05-04 20:15:47 +00005511 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5512 afi, SAFI_UNICAST, p, NULL);
5513
paul718e3742002-12-13 20:15:29 +00005514 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005515
paul718e3742002-12-13 20:15:29 +00005516 for (bi = bn->info; bi; bi = bi->next)
5517 if (bi->peer == bgp->peer_self
5518 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5519 break;
5520
5521 if (bi)
5522 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005523 if (attrhash_cmp (bi->attr, new_attr) &&
5524 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005525 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005526 bgp_attr_unintern (&new_attr);
5527 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005528 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005529 bgp_unlock_node (bn);
5530 return;
5531 }
5532 else
5533 {
5534 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005535 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005536
5537 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005538 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5539 bgp_info_restore(bn, bi);
5540 else
5541 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005542 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005543 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005544 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005545
5546 /* Process change. */
5547 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5548 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5549 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005550 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005551 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005552 return;
5553 }
5554 }
5555
5556 new = bgp_info_new ();
5557 new->type = type;
5558 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5559 new->peer = bgp->peer_self;
5560 SET_FLAG (new->flags, BGP_INFO_VALID);
5561 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005562 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005563
5564 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5565 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005566 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005567 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5568 }
5569 }
5570
5571 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005572 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005573 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005574}
5575
5576void
5577bgp_redistribute_delete (struct prefix *p, u_char type)
5578{
5579 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005580 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005581 afi_t afi;
5582 struct bgp_node *rn;
5583 struct bgp_info *ri;
5584
paul1eb8ef22005-04-07 07:30:20 +00005585 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005586 {
5587 afi = family2afi (p->family);
5588
5589 if (bgp->redist[afi][type])
5590 {
paulfee0f4c2004-09-13 05:12:46 +00005591 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005592
5593 for (ri = rn->info; ri; ri = ri->next)
5594 if (ri->peer == bgp->peer_self
5595 && ri->type == type)
5596 break;
5597
5598 if (ri)
5599 {
5600 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005601 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005602 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005603 }
5604 bgp_unlock_node (rn);
5605 }
5606 }
5607}
5608
5609/* Withdraw specified route type's route. */
5610void
5611bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5612{
5613 struct bgp_node *rn;
5614 struct bgp_info *ri;
5615 struct bgp_table *table;
5616
5617 table = bgp->rib[afi][SAFI_UNICAST];
5618
5619 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5620 {
5621 for (ri = rn->info; ri; ri = ri->next)
5622 if (ri->peer == bgp->peer_self
5623 && ri->type == type)
5624 break;
5625
5626 if (ri)
5627 {
5628 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005629 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005630 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005631 }
5632 }
5633}
David Lamparter6b0655a2014-06-04 06:53:35 +02005634
paul718e3742002-12-13 20:15:29 +00005635/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005636static void
paul718e3742002-12-13 20:15:29 +00005637route_vty_out_route (struct prefix *p, struct vty *vty)
5638{
5639 int len;
5640 u_int32_t destination;
5641 char buf[BUFSIZ];
5642
5643 if (p->family == AF_INET)
5644 {
5645 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5646 destination = ntohl (p->u.prefix4.s_addr);
5647
5648 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5649 || (IN_CLASSB (destination) && p->prefixlen == 16)
5650 || (IN_CLASSA (destination) && p->prefixlen == 8)
5651 || p->u.prefix4.s_addr == 0)
5652 {
5653 /* When mask is natural, mask is not displayed. */
5654 }
5655 else
5656 len += vty_out (vty, "/%d", p->prefixlen);
5657 }
5658 else
5659 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5660 p->prefixlen);
5661
5662 len = 17 - len;
5663 if (len < 1)
5664 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5665 else
5666 vty_out (vty, "%*s", len, " ");
5667}
5668
paul718e3742002-12-13 20:15:29 +00005669enum bgp_display_type
5670{
5671 normal_list,
5672};
5673
paulb40d9392005-08-22 22:34:41 +00005674/* Print the short form route status for a bgp_info */
5675static void
5676route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005677{
paulb40d9392005-08-22 22:34:41 +00005678 /* Route status display. */
5679 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5680 vty_out (vty, "R");
5681 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005682 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005683 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005684 vty_out (vty, "s");
5685 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5686 vty_out (vty, "*");
5687 else
5688 vty_out (vty, " ");
5689
5690 /* Selected */
5691 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5692 vty_out (vty, "h");
5693 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5694 vty_out (vty, "d");
5695 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5696 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005697 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5698 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005699 else
5700 vty_out (vty, " ");
5701
5702 /* Internal route. */
5703 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5704 vty_out (vty, "i");
5705 else
paulb40d9392005-08-22 22:34:41 +00005706 vty_out (vty, " ");
5707}
5708
5709/* called from terminal list command */
5710void
5711route_vty_out (struct vty *vty, struct prefix *p,
5712 struct bgp_info *binfo, int display, safi_t safi)
5713{
5714 struct attr *attr;
5715
5716 /* short status lead text */
5717 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005718
5719 /* print prefix and mask */
5720 if (! display)
5721 route_vty_out_route (p, vty);
5722 else
5723 vty_out (vty, "%*s", 17, " ");
5724
5725 /* Print attribute */
5726 attr = binfo->attr;
5727 if (attr)
5728 {
5729 if (p->family == AF_INET)
5730 {
5731 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005732 vty_out (vty, "%-16s",
5733 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005734 else
5735 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5736 }
5737#ifdef HAVE_IPV6
5738 else if (p->family == AF_INET6)
5739 {
5740 int len;
5741 char buf[BUFSIZ];
5742
5743 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005744 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5745 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005746 len = 16 - len;
5747 if (len < 1)
5748 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5749 else
5750 vty_out (vty, "%*s", len, " ");
5751 }
5752#endif /* HAVE_IPV6 */
5753
5754 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005755 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005756 else
5757 vty_out (vty, " ");
5758
5759 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005760 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005761 else
5762 vty_out (vty, " ");
5763
Paul Jakmafb982c22007-05-04 20:15:47 +00005764 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005765
Paul Jakmab2518c12006-05-12 23:48:40 +00005766 /* Print aspath */
5767 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005768 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005769
Paul Jakmab2518c12006-05-12 23:48:40 +00005770 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005771 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005772 }
paul718e3742002-12-13 20:15:29 +00005773 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005774}
5775
5776/* called from terminal list command */
5777void
5778route_vty_out_tmp (struct vty *vty, struct prefix *p,
5779 struct attr *attr, safi_t safi)
5780{
5781 /* Route status display. */
5782 vty_out (vty, "*");
5783 vty_out (vty, ">");
5784 vty_out (vty, " ");
5785
5786 /* print prefix and mask */
5787 route_vty_out_route (p, vty);
5788
5789 /* Print attribute */
5790 if (attr)
5791 {
5792 if (p->family == AF_INET)
5793 {
5794 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005795 vty_out (vty, "%-16s",
5796 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005797 else
5798 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5799 }
5800#ifdef HAVE_IPV6
5801 else if (p->family == AF_INET6)
5802 {
5803 int len;
5804 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005805
5806 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005807
5808 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005809 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5810 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005811 len = 16 - len;
5812 if (len < 1)
5813 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5814 else
5815 vty_out (vty, "%*s", len, " ");
5816 }
5817#endif /* HAVE_IPV6 */
5818
5819 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005820 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005821 else
5822 vty_out (vty, " ");
5823
5824 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005825 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005826 else
5827 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005828
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005829 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005830
Paul Jakmab2518c12006-05-12 23:48:40 +00005831 /* Print aspath */
5832 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005833 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005834
Paul Jakmab2518c12006-05-12 23:48:40 +00005835 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005836 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005837 }
paul718e3742002-12-13 20:15:29 +00005838
5839 vty_out (vty, "%s", VTY_NEWLINE);
5840}
5841
ajs5a646652004-11-05 01:25:55 +00005842void
paul718e3742002-12-13 20:15:29 +00005843route_vty_out_tag (struct vty *vty, struct prefix *p,
5844 struct bgp_info *binfo, int display, safi_t safi)
5845{
5846 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005847 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005848
5849 if (!binfo->extra)
5850 return;
5851
paulb40d9392005-08-22 22:34:41 +00005852 /* short status lead text */
5853 route_vty_short_status_out (vty, binfo);
5854
paul718e3742002-12-13 20:15:29 +00005855 /* print prefix and mask */
5856 if (! display)
5857 route_vty_out_route (p, vty);
5858 else
5859 vty_out (vty, "%*s", 17, " ");
5860
5861 /* Print attribute */
5862 attr = binfo->attr;
5863 if (attr)
5864 {
5865 if (p->family == AF_INET)
5866 {
5867 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005868 vty_out (vty, "%-16s",
5869 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005870 else
5871 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5872 }
5873#ifdef HAVE_IPV6
5874 else if (p->family == AF_INET6)
5875 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005876 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005877 char buf[BUFSIZ];
5878 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005879 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005880 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005881 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5882 buf, BUFSIZ));
5883 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005884 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005885 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5886 buf, BUFSIZ),
5887 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5888 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005889
5890 }
5891#endif /* HAVE_IPV6 */
5892 }
5893
Paul Jakmafb982c22007-05-04 20:15:47 +00005894 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005895
5896 vty_out (vty, "notag/%d", label);
5897
5898 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005899}
5900
5901/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005902static void
paul718e3742002-12-13 20:15:29 +00005903damp_route_vty_out (struct vty *vty, struct prefix *p,
5904 struct bgp_info *binfo, int display, safi_t safi)
5905{
5906 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005907 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005908 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005909
paulb40d9392005-08-22 22:34:41 +00005910 /* short status lead text */
5911 route_vty_short_status_out (vty, binfo);
5912
paul718e3742002-12-13 20:15:29 +00005913 /* print prefix and mask */
5914 if (! display)
5915 route_vty_out_route (p, vty);
5916 else
5917 vty_out (vty, "%*s", 17, " ");
5918
5919 len = vty_out (vty, "%s", binfo->peer->host);
5920 len = 17 - len;
5921 if (len < 1)
5922 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5923 else
5924 vty_out (vty, "%*s", len, " ");
5925
Chris Caputo50aef6f2009-06-23 06:06:49 +00005926 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005927
5928 /* Print attribute */
5929 attr = binfo->attr;
5930 if (attr)
5931 {
5932 /* Print aspath */
5933 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005934 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005935
5936 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005937 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005938 }
5939 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005940}
5941
paul718e3742002-12-13 20:15:29 +00005942/* flap route */
ajs5a646652004-11-05 01:25:55 +00005943static void
paul718e3742002-12-13 20:15:29 +00005944flap_route_vty_out (struct vty *vty, struct prefix *p,
5945 struct bgp_info *binfo, int display, safi_t safi)
5946{
5947 struct attr *attr;
5948 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005949 char timebuf[BGP_UPTIME_LEN];
5950 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005951
5952 if (!binfo->extra)
5953 return;
5954
5955 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005956
paulb40d9392005-08-22 22:34:41 +00005957 /* short status lead text */
5958 route_vty_short_status_out (vty, binfo);
5959
paul718e3742002-12-13 20:15:29 +00005960 /* print prefix and mask */
5961 if (! display)
5962 route_vty_out_route (p, vty);
5963 else
5964 vty_out (vty, "%*s", 17, " ");
5965
5966 len = vty_out (vty, "%s", binfo->peer->host);
5967 len = 16 - len;
5968 if (len < 1)
5969 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5970 else
5971 vty_out (vty, "%*s", len, " ");
5972
5973 len = vty_out (vty, "%d", bdi->flap);
5974 len = 5 - len;
5975 if (len < 1)
5976 vty_out (vty, " ");
5977 else
5978 vty_out (vty, "%*s ", len, " ");
5979
5980 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5981 timebuf, BGP_UPTIME_LEN));
5982
5983 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5984 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005985 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005986 else
5987 vty_out (vty, "%*s ", 8, " ");
5988
5989 /* Print attribute */
5990 attr = binfo->attr;
5991 if (attr)
5992 {
5993 /* Print aspath */
5994 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005995 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005996
5997 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005998 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005999 }
6000 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006001}
6002
paul94f2b392005-06-28 12:44:16 +00006003static void
paul718e3742002-12-13 20:15:29 +00006004route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6005 struct bgp_info *binfo, afi_t afi, safi_t safi)
6006{
6007 char buf[INET6_ADDRSTRLEN];
6008 char buf1[BUFSIZ];
6009 struct attr *attr;
6010 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03006011#ifdef HAVE_CLOCK_MONOTONIC
6012 time_t tbuf;
6013#endif
paul718e3742002-12-13 20:15:29 +00006014
6015 attr = binfo->attr;
6016
6017 if (attr)
6018 {
6019 /* Line1 display AS-path, Aggregator */
6020 if (attr->aspath)
6021 {
6022 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00006023 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00006024 vty_out (vty, "Local");
6025 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006026 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00006027 }
6028
paulb40d9392005-08-22 22:34:41 +00006029 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6030 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00006031 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6032 vty_out (vty, ", (stale)");
6033 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006034 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006035 attr->extra->aggregator_as,
6036 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006037 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6038 vty_out (vty, ", (Received from a RR-client)");
6039 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6040 vty_out (vty, ", (Received from a RS-client)");
6041 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6042 vty_out (vty, ", (history entry)");
6043 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6044 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006045 vty_out (vty, "%s", VTY_NEWLINE);
6046
6047 /* Line2 display Next-hop, Neighbor, Router-id */
6048 if (p->family == AF_INET)
6049 {
6050 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006051 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006052 inet_ntoa (attr->nexthop));
6053 }
6054#ifdef HAVE_IPV6
6055 else
6056 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006057 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006058 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006059 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006060 buf, INET6_ADDRSTRLEN));
6061 }
6062#endif /* HAVE_IPV6 */
6063
6064 if (binfo->peer == bgp->peer_self)
6065 {
6066 vty_out (vty, " from %s ",
6067 p->family == AF_INET ? "0.0.0.0" : "::");
6068 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6069 }
6070 else
6071 {
6072 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6073 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006074 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006075 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006076 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006077 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006078 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006079 else
6080 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6081 }
6082 vty_out (vty, "%s", VTY_NEWLINE);
6083
6084#ifdef HAVE_IPV6
6085 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006086 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006087 {
6088 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006089 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006090 buf, INET6_ADDRSTRLEN),
6091 VTY_NEWLINE);
6092 }
6093#endif /* HAVE_IPV6 */
6094
6095 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6096 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6097
6098 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006099 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006100
6101 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006102 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006103 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006104 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006105
Paul Jakmafb982c22007-05-04 20:15:47 +00006106 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006107 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006108
6109 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6110 vty_out (vty, ", valid");
6111
6112 if (binfo->peer != bgp->peer_self)
6113 {
6114 if (binfo->peer->as == binfo->peer->local_as)
6115 vty_out (vty, ", internal");
6116 else
6117 vty_out (vty, ", %s",
6118 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6119 }
6120 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6121 vty_out (vty, ", aggregated, local");
6122 else if (binfo->type != ZEBRA_ROUTE_BGP)
6123 vty_out (vty, ", sourced");
6124 else
6125 vty_out (vty, ", sourced, local");
6126
6127 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6128 vty_out (vty, ", atomic-aggregate");
6129
Josh Baileyde8d5df2011-07-20 20:46:01 -07006130 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6131 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6132 bgp_info_mpath_count (binfo)))
6133 vty_out (vty, ", multipath");
6134
paul718e3742002-12-13 20:15:29 +00006135 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6136 vty_out (vty, ", best");
6137
6138 vty_out (vty, "%s", VTY_NEWLINE);
6139
6140 /* Line 4 display Community */
6141 if (attr->community)
6142 vty_out (vty, " Community: %s%s", attr->community->str,
6143 VTY_NEWLINE);
6144
6145 /* Line 5 display Extended-community */
6146 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006147 vty_out (vty, " Extended Community: %s%s",
6148 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006149
6150 /* Line 6 display Originator, Cluster-id */
6151 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6152 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6153 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006154 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006155 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006156 vty_out (vty, " Originator: %s",
6157 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006158
6159 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6160 {
6161 int i;
6162 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006163 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6164 vty_out (vty, "%s ",
6165 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006166 }
6167 vty_out (vty, "%s", VTY_NEWLINE);
6168 }
Paul Jakma41367172007-08-06 15:24:51 +00006169
Paul Jakmafb982c22007-05-04 20:15:47 +00006170 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006171 bgp_damp_info_vty (vty, binfo);
6172
6173 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006174#ifdef HAVE_CLOCK_MONOTONIC
6175 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006176 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006177#else
6178 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6179#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006180 }
6181 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006182}
6183
6184#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6185 "h history, * valid, > best, = multipath,%s"\
6186 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006187#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006188#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6189#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6190#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6191
6192enum bgp_show_type
6193{
6194 bgp_show_type_normal,
6195 bgp_show_type_regexp,
6196 bgp_show_type_prefix_list,
6197 bgp_show_type_filter_list,
6198 bgp_show_type_route_map,
6199 bgp_show_type_neighbor,
6200 bgp_show_type_cidr_only,
6201 bgp_show_type_prefix_longer,
6202 bgp_show_type_community_all,
6203 bgp_show_type_community,
6204 bgp_show_type_community_exact,
6205 bgp_show_type_community_list,
6206 bgp_show_type_community_list_exact,
6207 bgp_show_type_flap_statistics,
6208 bgp_show_type_flap_address,
6209 bgp_show_type_flap_prefix,
6210 bgp_show_type_flap_cidr_only,
6211 bgp_show_type_flap_regexp,
6212 bgp_show_type_flap_filter_list,
6213 bgp_show_type_flap_prefix_list,
6214 bgp_show_type_flap_prefix_longer,
6215 bgp_show_type_flap_route_map,
6216 bgp_show_type_flap_neighbor,
6217 bgp_show_type_dampend_paths,
6218 bgp_show_type_damp_neighbor
6219};
6220
ajs5a646652004-11-05 01:25:55 +00006221static int
paulfee0f4c2004-09-13 05:12:46 +00006222bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006223 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006224{
paul718e3742002-12-13 20:15:29 +00006225 struct bgp_info *ri;
6226 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006227 int header = 1;
paul718e3742002-12-13 20:15:29 +00006228 int display;
ajs5a646652004-11-05 01:25:55 +00006229 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006230
6231 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006232 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006233
paul718e3742002-12-13 20:15:29 +00006234 /* Start processing of routes. */
6235 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6236 if (rn->info != NULL)
6237 {
6238 display = 0;
6239
6240 for (ri = rn->info; ri; ri = ri->next)
6241 {
ajs5a646652004-11-05 01:25:55 +00006242 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006243 || type == bgp_show_type_flap_address
6244 || type == bgp_show_type_flap_prefix
6245 || type == bgp_show_type_flap_cidr_only
6246 || type == bgp_show_type_flap_regexp
6247 || type == bgp_show_type_flap_filter_list
6248 || type == bgp_show_type_flap_prefix_list
6249 || type == bgp_show_type_flap_prefix_longer
6250 || type == bgp_show_type_flap_route_map
6251 || type == bgp_show_type_flap_neighbor
6252 || type == bgp_show_type_dampend_paths
6253 || type == bgp_show_type_damp_neighbor)
6254 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006255 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006256 continue;
6257 }
6258 if (type == bgp_show_type_regexp
6259 || type == bgp_show_type_flap_regexp)
6260 {
ajs5a646652004-11-05 01:25:55 +00006261 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006262
6263 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6264 continue;
6265 }
6266 if (type == bgp_show_type_prefix_list
6267 || type == bgp_show_type_flap_prefix_list)
6268 {
ajs5a646652004-11-05 01:25:55 +00006269 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006270
6271 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6272 continue;
6273 }
6274 if (type == bgp_show_type_filter_list
6275 || type == bgp_show_type_flap_filter_list)
6276 {
ajs5a646652004-11-05 01:25:55 +00006277 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006278
6279 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6280 continue;
6281 }
6282 if (type == bgp_show_type_route_map
6283 || type == bgp_show_type_flap_route_map)
6284 {
ajs5a646652004-11-05 01:25:55 +00006285 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006286 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006287 struct attr dummy_attr;
6288 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006289 int ret;
6290
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006291 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006292 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006293
paul718e3742002-12-13 20:15:29 +00006294 binfo.peer = ri->peer;
6295 binfo.attr = &dummy_attr;
6296
6297 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006298 if (ret == RMAP_DENYMATCH)
6299 continue;
6300 }
6301 if (type == bgp_show_type_neighbor
6302 || type == bgp_show_type_flap_neighbor
6303 || type == bgp_show_type_damp_neighbor)
6304 {
ajs5a646652004-11-05 01:25:55 +00006305 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006306
6307 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6308 continue;
6309 }
6310 if (type == bgp_show_type_cidr_only
6311 || type == bgp_show_type_flap_cidr_only)
6312 {
6313 u_int32_t destination;
6314
6315 destination = ntohl (rn->p.u.prefix4.s_addr);
6316 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6317 continue;
6318 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6319 continue;
6320 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6321 continue;
6322 }
6323 if (type == bgp_show_type_prefix_longer
6324 || type == bgp_show_type_flap_prefix_longer)
6325 {
ajs5a646652004-11-05 01:25:55 +00006326 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006327
6328 if (! prefix_match (p, &rn->p))
6329 continue;
6330 }
6331 if (type == bgp_show_type_community_all)
6332 {
6333 if (! ri->attr->community)
6334 continue;
6335 }
6336 if (type == bgp_show_type_community)
6337 {
ajs5a646652004-11-05 01:25:55 +00006338 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006339
6340 if (! ri->attr->community ||
6341 ! community_match (ri->attr->community, com))
6342 continue;
6343 }
6344 if (type == bgp_show_type_community_exact)
6345 {
ajs5a646652004-11-05 01:25:55 +00006346 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006347
6348 if (! ri->attr->community ||
6349 ! community_cmp (ri->attr->community, com))
6350 continue;
6351 }
6352 if (type == bgp_show_type_community_list)
6353 {
ajs5a646652004-11-05 01:25:55 +00006354 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006355
6356 if (! community_list_match (ri->attr->community, list))
6357 continue;
6358 }
6359 if (type == bgp_show_type_community_list_exact)
6360 {
ajs5a646652004-11-05 01:25:55 +00006361 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006362
6363 if (! community_list_exact_match (ri->attr->community, list))
6364 continue;
6365 }
6366 if (type == bgp_show_type_flap_address
6367 || type == bgp_show_type_flap_prefix)
6368 {
ajs5a646652004-11-05 01:25:55 +00006369 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006370
6371 if (! prefix_match (&rn->p, p))
6372 continue;
6373
6374 if (type == bgp_show_type_flap_prefix)
6375 if (p->prefixlen != rn->p.prefixlen)
6376 continue;
6377 }
6378 if (type == bgp_show_type_dampend_paths
6379 || type == bgp_show_type_damp_neighbor)
6380 {
6381 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6382 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6383 continue;
6384 }
6385
6386 if (header)
6387 {
hasso93406d82005-02-02 14:40:33 +00006388 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6389 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6390 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006391 if (type == bgp_show_type_dampend_paths
6392 || type == bgp_show_type_damp_neighbor)
6393 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6394 else if (type == bgp_show_type_flap_statistics
6395 || type == bgp_show_type_flap_address
6396 || type == bgp_show_type_flap_prefix
6397 || type == bgp_show_type_flap_cidr_only
6398 || type == bgp_show_type_flap_regexp
6399 || type == bgp_show_type_flap_filter_list
6400 || type == bgp_show_type_flap_prefix_list
6401 || type == bgp_show_type_flap_prefix_longer
6402 || type == bgp_show_type_flap_route_map
6403 || type == bgp_show_type_flap_neighbor)
6404 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6405 else
6406 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006407 header = 0;
6408 }
6409
6410 if (type == bgp_show_type_dampend_paths
6411 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006412 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006413 else if (type == bgp_show_type_flap_statistics
6414 || type == bgp_show_type_flap_address
6415 || type == bgp_show_type_flap_prefix
6416 || type == bgp_show_type_flap_cidr_only
6417 || type == bgp_show_type_flap_regexp
6418 || type == bgp_show_type_flap_filter_list
6419 || type == bgp_show_type_flap_prefix_list
6420 || type == bgp_show_type_flap_prefix_longer
6421 || type == bgp_show_type_flap_route_map
6422 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006423 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006424 else
ajs5a646652004-11-05 01:25:55 +00006425 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006426 display++;
6427 }
6428 if (display)
ajs5a646652004-11-05 01:25:55 +00006429 output_count++;
paul718e3742002-12-13 20:15:29 +00006430 }
6431
6432 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006433 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006434 {
6435 if (type == bgp_show_type_normal)
6436 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6437 }
6438 else
6439 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006440 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006441
6442 return CMD_SUCCESS;
6443}
6444
ajs5a646652004-11-05 01:25:55 +00006445static int
paulfee0f4c2004-09-13 05:12:46 +00006446bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006447 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006448{
6449 struct bgp_table *table;
6450
6451 if (bgp == NULL) {
6452 bgp = bgp_get_default ();
6453 }
6454
6455 if (bgp == NULL)
6456 {
6457 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6458 return CMD_WARNING;
6459 }
6460
6461
6462 table = bgp->rib[afi][safi];
6463
ajs5a646652004-11-05 01:25:55 +00006464 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006465}
6466
paul718e3742002-12-13 20:15:29 +00006467/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006468static void
paul718e3742002-12-13 20:15:29 +00006469route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6470 struct bgp_node *rn,
6471 struct prefix_rd *prd, afi_t afi, safi_t safi)
6472{
6473 struct bgp_info *ri;
6474 struct prefix *p;
6475 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006476 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006477 char buf1[INET6_ADDRSTRLEN];
6478 char buf2[INET6_ADDRSTRLEN];
6479 int count = 0;
6480 int best = 0;
6481 int suppress = 0;
6482 int no_export = 0;
6483 int no_advertise = 0;
6484 int local_as = 0;
6485 int first = 0;
6486
6487 p = &rn->p;
6488 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6489 (safi == SAFI_MPLS_VPN ?
6490 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6491 safi == SAFI_MPLS_VPN ? ":" : "",
6492 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6493 p->prefixlen, VTY_NEWLINE);
6494
6495 for (ri = rn->info; ri; ri = ri->next)
6496 {
6497 count++;
6498 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6499 {
6500 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006501 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006502 suppress = 1;
6503 if (ri->attr->community != NULL)
6504 {
6505 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6506 no_advertise = 1;
6507 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6508 no_export = 1;
6509 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6510 local_as = 1;
6511 }
6512 }
6513 }
6514
6515 vty_out (vty, "Paths: (%d available", count);
6516 if (best)
6517 {
6518 vty_out (vty, ", best #%d", best);
6519 if (safi == SAFI_UNICAST)
6520 vty_out (vty, ", table Default-IP-Routing-Table");
6521 }
6522 else
6523 vty_out (vty, ", no best path");
6524 if (no_advertise)
6525 vty_out (vty, ", not advertised to any peer");
6526 else if (no_export)
6527 vty_out (vty, ", not advertised to EBGP peer");
6528 else if (local_as)
6529 vty_out (vty, ", not advertised outside local AS");
6530 if (suppress)
6531 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6532 vty_out (vty, ")%s", VTY_NEWLINE);
6533
6534 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006535 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006536 {
6537 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6538 {
6539 if (! first)
6540 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6541 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6542 first = 1;
6543 }
6544 }
6545 if (! first)
6546 vty_out (vty, " Not advertised to any peer");
6547 vty_out (vty, "%s", VTY_NEWLINE);
6548}
6549
6550/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006551static int
paulfee0f4c2004-09-13 05:12:46 +00006552bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006553 struct bgp_table *rib, const char *ip_str,
6554 afi_t afi, safi_t safi, struct prefix_rd *prd,
6555 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006556{
6557 int ret;
6558 int header;
6559 int display = 0;
6560 struct prefix match;
6561 struct bgp_node *rn;
6562 struct bgp_node *rm;
6563 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006564 struct bgp_table *table;
6565
paul718e3742002-12-13 20:15:29 +00006566 /* Check IP address argument. */
6567 ret = str2prefix (ip_str, &match);
6568 if (! ret)
6569 {
6570 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6571 return CMD_WARNING;
6572 }
6573
6574 match.family = afi2family (afi);
6575
6576 if (safi == SAFI_MPLS_VPN)
6577 {
paulfee0f4c2004-09-13 05:12:46 +00006578 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006579 {
6580 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6581 continue;
6582
6583 if ((table = rn->info) != NULL)
6584 {
6585 header = 1;
6586
6587 if ((rm = bgp_node_match (table, &match)) != NULL)
6588 {
6589 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006590 {
6591 bgp_unlock_node (rm);
6592 continue;
6593 }
paul718e3742002-12-13 20:15:29 +00006594
6595 for (ri = rm->info; ri; ri = ri->next)
6596 {
6597 if (header)
6598 {
6599 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6600 AFI_IP, SAFI_MPLS_VPN);
6601
6602 header = 0;
6603 }
6604 display++;
6605 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6606 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006607
6608 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006609 }
6610 }
6611 }
6612 }
6613 else
6614 {
6615 header = 1;
6616
paulfee0f4c2004-09-13 05:12:46 +00006617 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006618 {
6619 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6620 {
6621 for (ri = rn->info; ri; ri = ri->next)
6622 {
6623 if (header)
6624 {
6625 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6626 header = 0;
6627 }
6628 display++;
6629 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6630 }
6631 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006632
6633 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006634 }
6635 }
6636
6637 if (! display)
6638 {
6639 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6640 return CMD_WARNING;
6641 }
6642
6643 return CMD_SUCCESS;
6644}
6645
paulfee0f4c2004-09-13 05:12:46 +00006646/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006647static int
paulfd79ac92004-10-13 05:06:08 +00006648bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006649 afi_t afi, safi_t safi, struct prefix_rd *prd,
6650 int prefix_check)
6651{
6652 struct bgp *bgp;
6653
6654 /* BGP structure lookup. */
6655 if (view_name)
6656 {
6657 bgp = bgp_lookup_by_name (view_name);
6658 if (bgp == NULL)
6659 {
6660 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6661 return CMD_WARNING;
6662 }
6663 }
6664 else
6665 {
6666 bgp = bgp_get_default ();
6667 if (bgp == NULL)
6668 {
6669 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6670 return CMD_WARNING;
6671 }
6672 }
6673
6674 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6675 afi, safi, prd, prefix_check);
6676}
6677
paul718e3742002-12-13 20:15:29 +00006678/* BGP route print out function. */
6679DEFUN (show_ip_bgp,
6680 show_ip_bgp_cmd,
6681 "show ip bgp",
6682 SHOW_STR
6683 IP_STR
6684 BGP_STR)
6685{
ajs5a646652004-11-05 01:25:55 +00006686 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006687}
6688
6689DEFUN (show_ip_bgp_ipv4,
6690 show_ip_bgp_ipv4_cmd,
6691 "show ip bgp ipv4 (unicast|multicast)",
6692 SHOW_STR
6693 IP_STR
6694 BGP_STR
6695 "Address family\n"
6696 "Address Family modifier\n"
6697 "Address Family modifier\n")
6698{
6699 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006700 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6701 NULL);
paul718e3742002-12-13 20:15:29 +00006702
ajs5a646652004-11-05 01:25:55 +00006703 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006704}
6705
Michael Lambert95cbbd22010-07-23 14:43:04 -04006706ALIAS (show_ip_bgp_ipv4,
6707 show_bgp_ipv4_safi_cmd,
6708 "show bgp ipv4 (unicast|multicast)",
6709 SHOW_STR
6710 BGP_STR
6711 "Address family\n"
6712 "Address Family modifier\n"
6713 "Address Family modifier\n")
6714
paul718e3742002-12-13 20:15:29 +00006715DEFUN (show_ip_bgp_route,
6716 show_ip_bgp_route_cmd,
6717 "show ip bgp A.B.C.D",
6718 SHOW_STR
6719 IP_STR
6720 BGP_STR
6721 "Network in the BGP routing table to display\n")
6722{
6723 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6724}
6725
6726DEFUN (show_ip_bgp_ipv4_route,
6727 show_ip_bgp_ipv4_route_cmd,
6728 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6729 SHOW_STR
6730 IP_STR
6731 BGP_STR
6732 "Address family\n"
6733 "Address Family modifier\n"
6734 "Address Family modifier\n"
6735 "Network in the BGP routing table to display\n")
6736{
6737 if (strncmp (argv[0], "m", 1) == 0)
6738 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6739
6740 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6741}
6742
Michael Lambert95cbbd22010-07-23 14:43:04 -04006743ALIAS (show_ip_bgp_ipv4_route,
6744 show_bgp_ipv4_safi_route_cmd,
6745 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6746 SHOW_STR
6747 BGP_STR
6748 "Address family\n"
6749 "Address Family modifier\n"
6750 "Address Family modifier\n"
6751 "Network in the BGP routing table to display\n")
6752
paul718e3742002-12-13 20:15:29 +00006753DEFUN (show_ip_bgp_vpnv4_all_route,
6754 show_ip_bgp_vpnv4_all_route_cmd,
6755 "show ip bgp vpnv4 all A.B.C.D",
6756 SHOW_STR
6757 IP_STR
6758 BGP_STR
6759 "Display VPNv4 NLRI specific information\n"
6760 "Display information about all VPNv4 NLRIs\n"
6761 "Network in the BGP routing table to display\n")
6762{
6763 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6764}
6765
6766DEFUN (show_ip_bgp_vpnv4_rd_route,
6767 show_ip_bgp_vpnv4_rd_route_cmd,
6768 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6769 SHOW_STR
6770 IP_STR
6771 BGP_STR
6772 "Display VPNv4 NLRI specific information\n"
6773 "Display information for a route distinguisher\n"
6774 "VPN Route Distinguisher\n"
6775 "Network in the BGP routing table to display\n")
6776{
6777 int ret;
6778 struct prefix_rd prd;
6779
6780 ret = str2prefix_rd (argv[0], &prd);
6781 if (! ret)
6782 {
6783 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6784 return CMD_WARNING;
6785 }
6786 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6787}
6788
6789DEFUN (show_ip_bgp_prefix,
6790 show_ip_bgp_prefix_cmd,
6791 "show ip bgp A.B.C.D/M",
6792 SHOW_STR
6793 IP_STR
6794 BGP_STR
6795 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6796{
6797 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6798}
6799
6800DEFUN (show_ip_bgp_ipv4_prefix,
6801 show_ip_bgp_ipv4_prefix_cmd,
6802 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6803 SHOW_STR
6804 IP_STR
6805 BGP_STR
6806 "Address family\n"
6807 "Address Family modifier\n"
6808 "Address Family modifier\n"
6809 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6810{
6811 if (strncmp (argv[0], "m", 1) == 0)
6812 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6813
6814 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6815}
6816
Michael Lambert95cbbd22010-07-23 14:43:04 -04006817ALIAS (show_ip_bgp_ipv4_prefix,
6818 show_bgp_ipv4_safi_prefix_cmd,
6819 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6820 SHOW_STR
6821 BGP_STR
6822 "Address family\n"
6823 "Address Family modifier\n"
6824 "Address Family modifier\n"
6825 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6826
paul718e3742002-12-13 20:15:29 +00006827DEFUN (show_ip_bgp_vpnv4_all_prefix,
6828 show_ip_bgp_vpnv4_all_prefix_cmd,
6829 "show ip bgp vpnv4 all A.B.C.D/M",
6830 SHOW_STR
6831 IP_STR
6832 BGP_STR
6833 "Display VPNv4 NLRI specific information\n"
6834 "Display information about all VPNv4 NLRIs\n"
6835 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6836{
6837 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6838}
6839
6840DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6841 show_ip_bgp_vpnv4_rd_prefix_cmd,
6842 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6843 SHOW_STR
6844 IP_STR
6845 BGP_STR
6846 "Display VPNv4 NLRI specific information\n"
6847 "Display information for a route distinguisher\n"
6848 "VPN Route Distinguisher\n"
6849 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6850{
6851 int ret;
6852 struct prefix_rd prd;
6853
6854 ret = str2prefix_rd (argv[0], &prd);
6855 if (! ret)
6856 {
6857 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6858 return CMD_WARNING;
6859 }
6860 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6861}
6862
6863DEFUN (show_ip_bgp_view,
6864 show_ip_bgp_view_cmd,
6865 "show ip bgp view WORD",
6866 SHOW_STR
6867 IP_STR
6868 BGP_STR
6869 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006870 "View name\n")
paul718e3742002-12-13 20:15:29 +00006871{
paulbb46e942003-10-24 19:02:03 +00006872 struct bgp *bgp;
6873
6874 /* BGP structure lookup. */
6875 bgp = bgp_lookup_by_name (argv[0]);
6876 if (bgp == NULL)
6877 {
6878 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6879 return CMD_WARNING;
6880 }
6881
ajs5a646652004-11-05 01:25:55 +00006882 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006883}
6884
6885DEFUN (show_ip_bgp_view_route,
6886 show_ip_bgp_view_route_cmd,
6887 "show ip bgp view WORD A.B.C.D",
6888 SHOW_STR
6889 IP_STR
6890 BGP_STR
6891 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006892 "View name\n"
paul718e3742002-12-13 20:15:29 +00006893 "Network in the BGP routing table to display\n")
6894{
6895 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6896}
6897
6898DEFUN (show_ip_bgp_view_prefix,
6899 show_ip_bgp_view_prefix_cmd,
6900 "show ip bgp view WORD A.B.C.D/M",
6901 SHOW_STR
6902 IP_STR
6903 BGP_STR
6904 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006905 "View name\n"
paul718e3742002-12-13 20:15:29 +00006906 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6907{
6908 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6909}
6910
6911#ifdef HAVE_IPV6
6912DEFUN (show_bgp,
6913 show_bgp_cmd,
6914 "show bgp",
6915 SHOW_STR
6916 BGP_STR)
6917{
ajs5a646652004-11-05 01:25:55 +00006918 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6919 NULL);
paul718e3742002-12-13 20:15:29 +00006920}
6921
6922ALIAS (show_bgp,
6923 show_bgp_ipv6_cmd,
6924 "show bgp ipv6",
6925 SHOW_STR
6926 BGP_STR
6927 "Address family\n")
6928
Michael Lambert95cbbd22010-07-23 14:43:04 -04006929DEFUN (show_bgp_ipv6_safi,
6930 show_bgp_ipv6_safi_cmd,
6931 "show bgp ipv6 (unicast|multicast)",
6932 SHOW_STR
6933 BGP_STR
6934 "Address family\n"
6935 "Address Family modifier\n"
6936 "Address Family modifier\n")
6937{
6938 if (strncmp (argv[0], "m", 1) == 0)
6939 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6940 NULL);
6941
6942 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6943}
6944
paul718e3742002-12-13 20:15:29 +00006945/* old command */
6946DEFUN (show_ipv6_bgp,
6947 show_ipv6_bgp_cmd,
6948 "show ipv6 bgp",
6949 SHOW_STR
6950 IP_STR
6951 BGP_STR)
6952{
ajs5a646652004-11-05 01:25:55 +00006953 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6954 NULL);
paul718e3742002-12-13 20:15:29 +00006955}
6956
6957DEFUN (show_bgp_route,
6958 show_bgp_route_cmd,
6959 "show bgp X:X::X:X",
6960 SHOW_STR
6961 BGP_STR
6962 "Network in the BGP routing table to display\n")
6963{
6964 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6965}
6966
6967ALIAS (show_bgp_route,
6968 show_bgp_ipv6_route_cmd,
6969 "show bgp ipv6 X:X::X:X",
6970 SHOW_STR
6971 BGP_STR
6972 "Address family\n"
6973 "Network in the BGP routing table to display\n")
6974
Michael Lambert95cbbd22010-07-23 14:43:04 -04006975DEFUN (show_bgp_ipv6_safi_route,
6976 show_bgp_ipv6_safi_route_cmd,
6977 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6978 SHOW_STR
6979 BGP_STR
6980 "Address family\n"
6981 "Address Family modifier\n"
6982 "Address Family modifier\n"
6983 "Network in the BGP routing table to display\n")
6984{
6985 if (strncmp (argv[0], "m", 1) == 0)
6986 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6987
6988 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6989}
6990
paul718e3742002-12-13 20:15:29 +00006991/* old command */
6992DEFUN (show_ipv6_bgp_route,
6993 show_ipv6_bgp_route_cmd,
6994 "show ipv6 bgp X:X::X:X",
6995 SHOW_STR
6996 IP_STR
6997 BGP_STR
6998 "Network in the BGP routing table to display\n")
6999{
7000 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7001}
7002
7003DEFUN (show_bgp_prefix,
7004 show_bgp_prefix_cmd,
7005 "show bgp X:X::X:X/M",
7006 SHOW_STR
7007 BGP_STR
7008 "IPv6 prefix <network>/<length>\n")
7009{
7010 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7011}
7012
7013ALIAS (show_bgp_prefix,
7014 show_bgp_ipv6_prefix_cmd,
7015 "show bgp ipv6 X:X::X:X/M",
7016 SHOW_STR
7017 BGP_STR
7018 "Address family\n"
7019 "IPv6 prefix <network>/<length>\n")
7020
Michael Lambert95cbbd22010-07-23 14:43:04 -04007021DEFUN (show_bgp_ipv6_safi_prefix,
7022 show_bgp_ipv6_safi_prefix_cmd,
7023 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
7024 SHOW_STR
7025 BGP_STR
7026 "Address family\n"
7027 "Address Family modifier\n"
7028 "Address Family modifier\n"
7029 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7030{
7031 if (strncmp (argv[0], "m", 1) == 0)
7032 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7033
7034 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7035}
7036
paul718e3742002-12-13 20:15:29 +00007037/* old command */
7038DEFUN (show_ipv6_bgp_prefix,
7039 show_ipv6_bgp_prefix_cmd,
7040 "show ipv6 bgp X:X::X:X/M",
7041 SHOW_STR
7042 IP_STR
7043 BGP_STR
7044 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7045{
7046 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7047}
7048
paulbb46e942003-10-24 19:02:03 +00007049DEFUN (show_bgp_view,
7050 show_bgp_view_cmd,
7051 "show bgp view WORD",
7052 SHOW_STR
7053 BGP_STR
7054 "BGP view\n"
7055 "View name\n")
7056{
7057 struct bgp *bgp;
7058
7059 /* BGP structure lookup. */
7060 bgp = bgp_lookup_by_name (argv[0]);
7061 if (bgp == NULL)
7062 {
7063 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7064 return CMD_WARNING;
7065 }
7066
ajs5a646652004-11-05 01:25:55 +00007067 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007068}
7069
7070ALIAS (show_bgp_view,
7071 show_bgp_view_ipv6_cmd,
7072 "show bgp view WORD ipv6",
7073 SHOW_STR
7074 BGP_STR
7075 "BGP view\n"
7076 "View name\n"
7077 "Address family\n")
7078
7079DEFUN (show_bgp_view_route,
7080 show_bgp_view_route_cmd,
7081 "show bgp view WORD X:X::X:X",
7082 SHOW_STR
7083 BGP_STR
7084 "BGP view\n"
7085 "View name\n"
7086 "Network in the BGP routing table to display\n")
7087{
7088 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7089}
7090
7091ALIAS (show_bgp_view_route,
7092 show_bgp_view_ipv6_route_cmd,
7093 "show bgp view WORD ipv6 X:X::X:X",
7094 SHOW_STR
7095 BGP_STR
7096 "BGP view\n"
7097 "View name\n"
7098 "Address family\n"
7099 "Network in the BGP routing table to display\n")
7100
7101DEFUN (show_bgp_view_prefix,
7102 show_bgp_view_prefix_cmd,
7103 "show bgp view WORD X:X::X:X/M",
7104 SHOW_STR
7105 BGP_STR
7106 "BGP view\n"
7107 "View name\n"
7108 "IPv6 prefix <network>/<length>\n")
7109{
7110 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7111}
7112
7113ALIAS (show_bgp_view_prefix,
7114 show_bgp_view_ipv6_prefix_cmd,
7115 "show bgp view WORD ipv6 X:X::X:X/M",
7116 SHOW_STR
7117 BGP_STR
7118 "BGP view\n"
7119 "View name\n"
7120 "Address family\n"
7121 "IPv6 prefix <network>/<length>\n")
7122
paul718e3742002-12-13 20:15:29 +00007123/* old command */
7124DEFUN (show_ipv6_mbgp,
7125 show_ipv6_mbgp_cmd,
7126 "show ipv6 mbgp",
7127 SHOW_STR
7128 IP_STR
7129 MBGP_STR)
7130{
ajs5a646652004-11-05 01:25:55 +00007131 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7132 NULL);
paul718e3742002-12-13 20:15:29 +00007133}
7134
7135/* old command */
7136DEFUN (show_ipv6_mbgp_route,
7137 show_ipv6_mbgp_route_cmd,
7138 "show ipv6 mbgp X:X::X:X",
7139 SHOW_STR
7140 IP_STR
7141 MBGP_STR
7142 "Network in the MBGP routing table to display\n")
7143{
7144 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7145}
7146
7147/* old command */
7148DEFUN (show_ipv6_mbgp_prefix,
7149 show_ipv6_mbgp_prefix_cmd,
7150 "show ipv6 mbgp X:X::X:X/M",
7151 SHOW_STR
7152 IP_STR
7153 MBGP_STR
7154 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7155{
7156 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7157}
7158#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02007159
paul718e3742002-12-13 20:15:29 +00007160
paul94f2b392005-06-28 12:44:16 +00007161static int
paulfd79ac92004-10-13 05:06:08 +00007162bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007163 safi_t safi, enum bgp_show_type type)
7164{
7165 int i;
7166 struct buffer *b;
7167 char *regstr;
7168 int first;
7169 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007170 int rc;
paul718e3742002-12-13 20:15:29 +00007171
7172 first = 0;
7173 b = buffer_new (1024);
7174 for (i = 0; i < argc; i++)
7175 {
7176 if (first)
7177 buffer_putc (b, ' ');
7178 else
7179 {
7180 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7181 continue;
7182 first = 1;
7183 }
7184
7185 buffer_putstr (b, argv[i]);
7186 }
7187 buffer_putc (b, '\0');
7188
7189 regstr = buffer_getstr (b);
7190 buffer_free (b);
7191
7192 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007193 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007194 if (! regex)
7195 {
7196 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7197 VTY_NEWLINE);
7198 return CMD_WARNING;
7199 }
7200
ajs5a646652004-11-05 01:25:55 +00007201 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7202 bgp_regex_free (regex);
7203 return rc;
paul718e3742002-12-13 20:15:29 +00007204}
7205
7206DEFUN (show_ip_bgp_regexp,
7207 show_ip_bgp_regexp_cmd,
7208 "show ip bgp regexp .LINE",
7209 SHOW_STR
7210 IP_STR
7211 BGP_STR
7212 "Display routes matching the AS path regular expression\n"
7213 "A regular-expression to match the BGP AS paths\n")
7214{
7215 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7216 bgp_show_type_regexp);
7217}
7218
7219DEFUN (show_ip_bgp_flap_regexp,
7220 show_ip_bgp_flap_regexp_cmd,
7221 "show ip bgp flap-statistics regexp .LINE",
7222 SHOW_STR
7223 IP_STR
7224 BGP_STR
7225 "Display flap statistics of routes\n"
7226 "Display routes matching the AS path regular expression\n"
7227 "A regular-expression to match the BGP AS paths\n")
7228{
7229 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7230 bgp_show_type_flap_regexp);
7231}
7232
Balaji3921cc52015-05-16 23:12:17 +05307233ALIAS (show_ip_bgp_flap_regexp,
7234 show_ip_bgp_damp_flap_regexp_cmd,
7235 "show ip bgp dampening flap-statistics regexp .LINE",
7236 SHOW_STR
7237 IP_STR
7238 BGP_STR
7239 "Display detailed information about dampening\n"
7240 "Display flap statistics of routes\n"
7241 "Display routes matching the AS path regular expression\n"
7242 "A regular-expression to match the BGP AS paths\n")
7243
paul718e3742002-12-13 20:15:29 +00007244DEFUN (show_ip_bgp_ipv4_regexp,
7245 show_ip_bgp_ipv4_regexp_cmd,
7246 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7247 SHOW_STR
7248 IP_STR
7249 BGP_STR
7250 "Address family\n"
7251 "Address Family modifier\n"
7252 "Address Family modifier\n"
7253 "Display routes matching the AS path regular expression\n"
7254 "A regular-expression to match the BGP AS paths\n")
7255{
7256 if (strncmp (argv[0], "m", 1) == 0)
7257 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7258 bgp_show_type_regexp);
7259
7260 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7261 bgp_show_type_regexp);
7262}
7263
7264#ifdef HAVE_IPV6
7265DEFUN (show_bgp_regexp,
7266 show_bgp_regexp_cmd,
7267 "show bgp regexp .LINE",
7268 SHOW_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
7277ALIAS (show_bgp_regexp,
7278 show_bgp_ipv6_regexp_cmd,
7279 "show bgp ipv6 regexp .LINE",
7280 SHOW_STR
7281 BGP_STR
7282 "Address family\n"
7283 "Display routes matching the AS path regular expression\n"
7284 "A regular-expression to match the BGP AS paths\n")
7285
7286/* old command */
7287DEFUN (show_ipv6_bgp_regexp,
7288 show_ipv6_bgp_regexp_cmd,
7289 "show ipv6 bgp regexp .LINE",
7290 SHOW_STR
7291 IP_STR
7292 BGP_STR
7293 "Display routes matching the AS path regular expression\n"
7294 "A regular-expression to match the BGP AS paths\n")
7295{
7296 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7297 bgp_show_type_regexp);
7298}
7299
7300/* old command */
7301DEFUN (show_ipv6_mbgp_regexp,
7302 show_ipv6_mbgp_regexp_cmd,
7303 "show ipv6 mbgp regexp .LINE",
7304 SHOW_STR
7305 IP_STR
7306 BGP_STR
7307 "Display routes matching the AS path regular expression\n"
7308 "A regular-expression to match the MBGP AS paths\n")
7309{
7310 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7311 bgp_show_type_regexp);
7312}
7313#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007314
paul94f2b392005-06-28 12:44:16 +00007315static int
paulfd79ac92004-10-13 05:06:08 +00007316bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007317 safi_t safi, enum bgp_show_type type)
7318{
7319 struct prefix_list *plist;
7320
7321 plist = prefix_list_lookup (afi, prefix_list_str);
7322 if (plist == NULL)
7323 {
7324 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7325 prefix_list_str, VTY_NEWLINE);
7326 return CMD_WARNING;
7327 }
7328
ajs5a646652004-11-05 01:25:55 +00007329 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007330}
7331
7332DEFUN (show_ip_bgp_prefix_list,
7333 show_ip_bgp_prefix_list_cmd,
7334 "show ip bgp prefix-list WORD",
7335 SHOW_STR
7336 IP_STR
7337 BGP_STR
7338 "Display routes conforming to the prefix-list\n"
7339 "IP prefix-list name\n")
7340{
7341 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7342 bgp_show_type_prefix_list);
7343}
7344
7345DEFUN (show_ip_bgp_flap_prefix_list,
7346 show_ip_bgp_flap_prefix_list_cmd,
7347 "show ip bgp flap-statistics prefix-list WORD",
7348 SHOW_STR
7349 IP_STR
7350 BGP_STR
7351 "Display flap statistics of routes\n"
7352 "Display routes conforming to the prefix-list\n"
7353 "IP prefix-list name\n")
7354{
7355 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7356 bgp_show_type_flap_prefix_list);
7357}
7358
Balaji3921cc52015-05-16 23:12:17 +05307359ALIAS (show_ip_bgp_flap_prefix_list,
7360 show_ip_bgp_damp_flap_prefix_list_cmd,
7361 "show ip bgp dampening flap-statistics prefix-list WORD",
7362 SHOW_STR
7363 IP_STR
7364 BGP_STR
7365 "Display detailed information about dampening\n"
7366 "Display flap statistics of routes\n"
7367 "Display routes conforming to the prefix-list\n"
7368 "IP prefix-list name\n")
7369
paul718e3742002-12-13 20:15:29 +00007370DEFUN (show_ip_bgp_ipv4_prefix_list,
7371 show_ip_bgp_ipv4_prefix_list_cmd,
7372 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7373 SHOW_STR
7374 IP_STR
7375 BGP_STR
7376 "Address family\n"
7377 "Address Family modifier\n"
7378 "Address Family modifier\n"
7379 "Display routes conforming to the prefix-list\n"
7380 "IP prefix-list name\n")
7381{
7382 if (strncmp (argv[0], "m", 1) == 0)
7383 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7384 bgp_show_type_prefix_list);
7385
7386 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7387 bgp_show_type_prefix_list);
7388}
7389
7390#ifdef HAVE_IPV6
7391DEFUN (show_bgp_prefix_list,
7392 show_bgp_prefix_list_cmd,
7393 "show bgp prefix-list WORD",
7394 SHOW_STR
7395 BGP_STR
7396 "Display routes conforming to 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
7403ALIAS (show_bgp_prefix_list,
7404 show_bgp_ipv6_prefix_list_cmd,
7405 "show bgp ipv6 prefix-list WORD",
7406 SHOW_STR
7407 BGP_STR
7408 "Address family\n"
7409 "Display routes conforming to the prefix-list\n"
7410 "IPv6 prefix-list name\n")
7411
7412/* old command */
7413DEFUN (show_ipv6_bgp_prefix_list,
7414 show_ipv6_bgp_prefix_list_cmd,
7415 "show ipv6 bgp prefix-list WORD",
7416 SHOW_STR
7417 IPV6_STR
7418 BGP_STR
7419 "Display routes matching the prefix-list\n"
7420 "IPv6 prefix-list name\n")
7421{
7422 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7423 bgp_show_type_prefix_list);
7424}
7425
7426/* old command */
7427DEFUN (show_ipv6_mbgp_prefix_list,
7428 show_ipv6_mbgp_prefix_list_cmd,
7429 "show ipv6 mbgp prefix-list WORD",
7430 SHOW_STR
7431 IPV6_STR
7432 MBGP_STR
7433 "Display routes matching the prefix-list\n"
7434 "IPv6 prefix-list name\n")
7435{
7436 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7437 bgp_show_type_prefix_list);
7438}
7439#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007440
paul94f2b392005-06-28 12:44:16 +00007441static int
paulfd79ac92004-10-13 05:06:08 +00007442bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007443 safi_t safi, enum bgp_show_type type)
7444{
7445 struct as_list *as_list;
7446
7447 as_list = as_list_lookup (filter);
7448 if (as_list == NULL)
7449 {
7450 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7451 return CMD_WARNING;
7452 }
7453
ajs5a646652004-11-05 01:25:55 +00007454 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007455}
7456
7457DEFUN (show_ip_bgp_filter_list,
7458 show_ip_bgp_filter_list_cmd,
7459 "show ip bgp filter-list WORD",
7460 SHOW_STR
7461 IP_STR
7462 BGP_STR
7463 "Display routes conforming to the filter-list\n"
7464 "Regular expression access list name\n")
7465{
7466 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7467 bgp_show_type_filter_list);
7468}
7469
7470DEFUN (show_ip_bgp_flap_filter_list,
7471 show_ip_bgp_flap_filter_list_cmd,
7472 "show ip bgp flap-statistics filter-list WORD",
7473 SHOW_STR
7474 IP_STR
7475 BGP_STR
7476 "Display flap statistics of routes\n"
7477 "Display routes conforming to the filter-list\n"
7478 "Regular expression access list name\n")
7479{
7480 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7481 bgp_show_type_flap_filter_list);
7482}
7483
Balaji3921cc52015-05-16 23:12:17 +05307484ALIAS (show_ip_bgp_flap_filter_list,
7485 show_ip_bgp_damp_flap_filter_list_cmd,
7486 "show ip bgp dampening flap-statistics filter-list WORD",
7487 SHOW_STR
7488 IP_STR
7489 BGP_STR
7490 "Display detailed information about dampening\n"
7491 "Display flap statistics of routes\n"
7492 "Display routes conforming to the filter-list\n"
7493 "Regular expression access list name\n")
7494
paul718e3742002-12-13 20:15:29 +00007495DEFUN (show_ip_bgp_ipv4_filter_list,
7496 show_ip_bgp_ipv4_filter_list_cmd,
7497 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7498 SHOW_STR
7499 IP_STR
7500 BGP_STR
7501 "Address family\n"
7502 "Address Family modifier\n"
7503 "Address Family modifier\n"
7504 "Display routes conforming to the filter-list\n"
7505 "Regular expression access list name\n")
7506{
7507 if (strncmp (argv[0], "m", 1) == 0)
7508 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7509 bgp_show_type_filter_list);
7510
7511 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7512 bgp_show_type_filter_list);
7513}
7514
7515#ifdef HAVE_IPV6
7516DEFUN (show_bgp_filter_list,
7517 show_bgp_filter_list_cmd,
7518 "show bgp filter-list WORD",
7519 SHOW_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
7528ALIAS (show_bgp_filter_list,
7529 show_bgp_ipv6_filter_list_cmd,
7530 "show bgp ipv6 filter-list WORD",
7531 SHOW_STR
7532 BGP_STR
7533 "Address family\n"
7534 "Display routes conforming to the filter-list\n"
7535 "Regular expression access list name\n")
7536
7537/* old command */
7538DEFUN (show_ipv6_bgp_filter_list,
7539 show_ipv6_bgp_filter_list_cmd,
7540 "show ipv6 bgp filter-list WORD",
7541 SHOW_STR
7542 IPV6_STR
7543 BGP_STR
7544 "Display routes conforming to the filter-list\n"
7545 "Regular expression access list name\n")
7546{
7547 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7548 bgp_show_type_filter_list);
7549}
7550
7551/* old command */
7552DEFUN (show_ipv6_mbgp_filter_list,
7553 show_ipv6_mbgp_filter_list_cmd,
7554 "show ipv6 mbgp filter-list WORD",
7555 SHOW_STR
7556 IPV6_STR
7557 MBGP_STR
7558 "Display routes conforming to the filter-list\n"
7559 "Regular expression access list name\n")
7560{
7561 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7562 bgp_show_type_filter_list);
7563}
7564#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007565
Balaji3921cc52015-05-16 23:12:17 +05307566DEFUN (show_ip_bgp_dampening_info,
7567 show_ip_bgp_dampening_params_cmd,
7568 "show ip bgp dampening parameters",
7569 SHOW_STR
7570 IP_STR
7571 BGP_STR
7572 "Display detailed information about dampening\n"
7573 "Display detail of configured dampening parameters\n")
7574{
7575 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
7576}
7577
paul94f2b392005-06-28 12:44:16 +00007578static int
paulfd79ac92004-10-13 05:06:08 +00007579bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007580 safi_t safi, enum bgp_show_type type)
7581{
7582 struct route_map *rmap;
7583
7584 rmap = route_map_lookup_by_name (rmap_str);
7585 if (! rmap)
7586 {
7587 vty_out (vty, "%% %s is not a valid route-map name%s",
7588 rmap_str, VTY_NEWLINE);
7589 return CMD_WARNING;
7590 }
7591
ajs5a646652004-11-05 01:25:55 +00007592 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007593}
7594
7595DEFUN (show_ip_bgp_route_map,
7596 show_ip_bgp_route_map_cmd,
7597 "show ip bgp route-map WORD",
7598 SHOW_STR
7599 IP_STR
7600 BGP_STR
7601 "Display routes matching the route-map\n"
7602 "A route-map to match on\n")
7603{
7604 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7605 bgp_show_type_route_map);
7606}
7607
7608DEFUN (show_ip_bgp_flap_route_map,
7609 show_ip_bgp_flap_route_map_cmd,
7610 "show ip bgp flap-statistics route-map WORD",
7611 SHOW_STR
7612 IP_STR
7613 BGP_STR
7614 "Display flap statistics of routes\n"
7615 "Display routes matching the route-map\n"
7616 "A route-map to match on\n")
7617{
7618 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7619 bgp_show_type_flap_route_map);
7620}
7621
Balaji3921cc52015-05-16 23:12:17 +05307622ALIAS (show_ip_bgp_flap_route_map,
7623 show_ip_bgp_damp_flap_route_map_cmd,
7624 "show ip bgp dampening flap-statistics route-map WORD",
7625 SHOW_STR
7626 IP_STR
7627 BGP_STR
7628 "Display detailed information about dampening\n"
7629 "Display flap statistics of routes\n"
7630 "Display routes matching the route-map\n"
7631 "A route-map to match on\n")
7632
paul718e3742002-12-13 20:15:29 +00007633DEFUN (show_ip_bgp_ipv4_route_map,
7634 show_ip_bgp_ipv4_route_map_cmd,
7635 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7636 SHOW_STR
7637 IP_STR
7638 BGP_STR
7639 "Address family\n"
7640 "Address Family modifier\n"
7641 "Address Family modifier\n"
7642 "Display routes matching the route-map\n"
7643 "A route-map to match on\n")
7644{
7645 if (strncmp (argv[0], "m", 1) == 0)
7646 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7647 bgp_show_type_route_map);
7648
7649 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7650 bgp_show_type_route_map);
7651}
7652
7653DEFUN (show_bgp_route_map,
7654 show_bgp_route_map_cmd,
7655 "show bgp route-map WORD",
7656 SHOW_STR
7657 BGP_STR
7658 "Display routes matching the route-map\n"
7659 "A route-map to match on\n")
7660{
7661 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7662 bgp_show_type_route_map);
7663}
7664
7665ALIAS (show_bgp_route_map,
7666 show_bgp_ipv6_route_map_cmd,
7667 "show bgp ipv6 route-map WORD",
7668 SHOW_STR
7669 BGP_STR
7670 "Address family\n"
7671 "Display routes matching the route-map\n"
7672 "A route-map to match on\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02007673
paul718e3742002-12-13 20:15:29 +00007674DEFUN (show_ip_bgp_cidr_only,
7675 show_ip_bgp_cidr_only_cmd,
7676 "show ip bgp cidr-only",
7677 SHOW_STR
7678 IP_STR
7679 BGP_STR
7680 "Display only routes with non-natural netmasks\n")
7681{
7682 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007683 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007684}
7685
7686DEFUN (show_ip_bgp_flap_cidr_only,
7687 show_ip_bgp_flap_cidr_only_cmd,
7688 "show ip bgp flap-statistics cidr-only",
7689 SHOW_STR
7690 IP_STR
7691 BGP_STR
7692 "Display flap statistics of routes\n"
7693 "Display only routes with non-natural netmasks\n")
7694{
7695 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007696 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007697}
7698
Balaji3921cc52015-05-16 23:12:17 +05307699ALIAS (show_ip_bgp_flap_cidr_only,
7700 show_ip_bgp_damp_flap_cidr_only_cmd,
7701 "show ip bgp dampening flap-statistics cidr-only",
7702 SHOW_STR
7703 IP_STR
7704 BGP_STR
7705 "Display detailed information about dampening\n"
7706 "Display flap statistics of routes\n"
7707 "Display only routes with non-natural netmasks\n")
7708
paul718e3742002-12-13 20:15:29 +00007709DEFUN (show_ip_bgp_ipv4_cidr_only,
7710 show_ip_bgp_ipv4_cidr_only_cmd,
7711 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7712 SHOW_STR
7713 IP_STR
7714 BGP_STR
7715 "Address family\n"
7716 "Address Family modifier\n"
7717 "Address Family modifier\n"
7718 "Display only routes with non-natural netmasks\n")
7719{
7720 if (strncmp (argv[0], "m", 1) == 0)
7721 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007722 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007723
7724 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007725 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007726}
David Lamparter6b0655a2014-06-04 06:53:35 +02007727
paul718e3742002-12-13 20:15:29 +00007728DEFUN (show_ip_bgp_community_all,
7729 show_ip_bgp_community_all_cmd,
7730 "show ip bgp community",
7731 SHOW_STR
7732 IP_STR
7733 BGP_STR
7734 "Display routes matching the communities\n")
7735{
7736 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007737 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007738}
7739
7740DEFUN (show_ip_bgp_ipv4_community_all,
7741 show_ip_bgp_ipv4_community_all_cmd,
7742 "show ip bgp ipv4 (unicast|multicast) community",
7743 SHOW_STR
7744 IP_STR
7745 BGP_STR
7746 "Address family\n"
7747 "Address Family modifier\n"
7748 "Address Family modifier\n"
7749 "Display routes matching the communities\n")
7750{
7751 if (strncmp (argv[0], "m", 1) == 0)
7752 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007753 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007754
7755 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007756 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007757}
7758
7759#ifdef HAVE_IPV6
7760DEFUN (show_bgp_community_all,
7761 show_bgp_community_all_cmd,
7762 "show bgp community",
7763 SHOW_STR
7764 BGP_STR
7765 "Display routes matching the communities\n")
7766{
7767 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007768 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007769}
7770
7771ALIAS (show_bgp_community_all,
7772 show_bgp_ipv6_community_all_cmd,
7773 "show bgp ipv6 community",
7774 SHOW_STR
7775 BGP_STR
7776 "Address family\n"
7777 "Display routes matching the communities\n")
7778
7779/* old command */
7780DEFUN (show_ipv6_bgp_community_all,
7781 show_ipv6_bgp_community_all_cmd,
7782 "show ipv6 bgp community",
7783 SHOW_STR
7784 IPV6_STR
7785 BGP_STR
7786 "Display routes matching the communities\n")
7787{
7788 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007789 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007790}
7791
7792/* old command */
7793DEFUN (show_ipv6_mbgp_community_all,
7794 show_ipv6_mbgp_community_all_cmd,
7795 "show ipv6 mbgp community",
7796 SHOW_STR
7797 IPV6_STR
7798 MBGP_STR
7799 "Display routes matching the communities\n")
7800{
7801 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007802 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007803}
7804#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007805
paul94f2b392005-06-28 12:44:16 +00007806static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007807bgp_show_community (struct vty *vty, const char *view_name, int argc,
7808 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007809{
7810 struct community *com;
7811 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007812 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007813 int i;
7814 char *str;
7815 int first = 0;
7816
Michael Lambert95cbbd22010-07-23 14:43:04 -04007817 /* BGP structure lookup */
7818 if (view_name)
7819 {
7820 bgp = bgp_lookup_by_name (view_name);
7821 if (bgp == NULL)
7822 {
7823 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7824 return CMD_WARNING;
7825 }
7826 }
7827 else
7828 {
7829 bgp = bgp_get_default ();
7830 if (bgp == NULL)
7831 {
7832 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7833 return CMD_WARNING;
7834 }
7835 }
7836
paul718e3742002-12-13 20:15:29 +00007837 b = buffer_new (1024);
7838 for (i = 0; i < argc; i++)
7839 {
7840 if (first)
7841 buffer_putc (b, ' ');
7842 else
7843 {
7844 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7845 continue;
7846 first = 1;
7847 }
7848
7849 buffer_putstr (b, argv[i]);
7850 }
7851 buffer_putc (b, '\0');
7852
7853 str = buffer_getstr (b);
7854 buffer_free (b);
7855
7856 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007857 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007858 if (! com)
7859 {
7860 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7861 return CMD_WARNING;
7862 }
7863
Michael Lambert95cbbd22010-07-23 14:43:04 -04007864 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007865 (exact ? bgp_show_type_community_exact :
7866 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007867}
7868
7869DEFUN (show_ip_bgp_community,
7870 show_ip_bgp_community_cmd,
7871 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7872 SHOW_STR
7873 IP_STR
7874 BGP_STR
7875 "Display routes matching the communities\n"
7876 "community number\n"
7877 "Do not send outside local AS (well-known community)\n"
7878 "Do not advertise to any peer (well-known community)\n"
7879 "Do not export to next AS (well-known community)\n")
7880{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007881 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007882}
7883
7884ALIAS (show_ip_bgp_community,
7885 show_ip_bgp_community2_cmd,
7886 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7887 SHOW_STR
7888 IP_STR
7889 BGP_STR
7890 "Display routes matching the communities\n"
7891 "community number\n"
7892 "Do not send outside local AS (well-known community)\n"
7893 "Do not advertise to any peer (well-known community)\n"
7894 "Do not export to next AS (well-known community)\n"
7895 "community number\n"
7896 "Do not send outside local AS (well-known community)\n"
7897 "Do not advertise to any peer (well-known community)\n"
7898 "Do not export to next AS (well-known community)\n")
7899
7900ALIAS (show_ip_bgp_community,
7901 show_ip_bgp_community3_cmd,
7902 "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)",
7903 SHOW_STR
7904 IP_STR
7905 BGP_STR
7906 "Display routes matching the communities\n"
7907 "community number\n"
7908 "Do not send outside local AS (well-known community)\n"
7909 "Do not advertise to any peer (well-known community)\n"
7910 "Do not export to next AS (well-known community)\n"
7911 "community number\n"
7912 "Do not send outside local AS (well-known community)\n"
7913 "Do not advertise to any peer (well-known community)\n"
7914 "Do not export to next AS (well-known community)\n"
7915 "community number\n"
7916 "Do not send outside local AS (well-known community)\n"
7917 "Do not advertise to any peer (well-known community)\n"
7918 "Do not export to next AS (well-known community)\n")
7919
7920ALIAS (show_ip_bgp_community,
7921 show_ip_bgp_community4_cmd,
7922 "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)",
7923 SHOW_STR
7924 IP_STR
7925 BGP_STR
7926 "Display routes matching the communities\n"
7927 "community number\n"
7928 "Do not send outside local AS (well-known community)\n"
7929 "Do not advertise to any peer (well-known community)\n"
7930 "Do not export to next AS (well-known community)\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 "community number\n"
7936 "Do not send outside local AS (well-known community)\n"
7937 "Do not advertise to any peer (well-known community)\n"
7938 "Do not export to next AS (well-known community)\n"
7939 "community number\n"
7940 "Do not send outside local AS (well-known community)\n"
7941 "Do not advertise to any peer (well-known community)\n"
7942 "Do not export to next AS (well-known community)\n")
7943
7944DEFUN (show_ip_bgp_ipv4_community,
7945 show_ip_bgp_ipv4_community_cmd,
7946 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7947 SHOW_STR
7948 IP_STR
7949 BGP_STR
7950 "Address family\n"
7951 "Address Family modifier\n"
7952 "Address Family modifier\n"
7953 "Display routes matching the communities\n"
7954 "community number\n"
7955 "Do not send outside local AS (well-known community)\n"
7956 "Do not advertise to any peer (well-known community)\n"
7957 "Do not export to next AS (well-known community)\n")
7958{
7959 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007960 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007961
Michael Lambert95cbbd22010-07-23 14:43:04 -04007962 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007963}
7964
7965ALIAS (show_ip_bgp_ipv4_community,
7966 show_ip_bgp_ipv4_community2_cmd,
7967 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7968 SHOW_STR
7969 IP_STR
7970 BGP_STR
7971 "Address family\n"
7972 "Address Family modifier\n"
7973 "Address Family modifier\n"
7974 "Display routes matching the communities\n"
7975 "community number\n"
7976 "Do not send outside local AS (well-known community)\n"
7977 "Do not advertise to any peer (well-known community)\n"
7978 "Do not export to next AS (well-known community)\n"
7979 "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_community3_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)",
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
8007ALIAS (show_ip_bgp_ipv4_community,
8008 show_ip_bgp_ipv4_community4_cmd,
8009 "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)",
8010 SHOW_STR
8011 IP_STR
8012 BGP_STR
8013 "Address family\n"
8014 "Address Family modifier\n"
8015 "Address Family modifier\n"
8016 "Display routes matching the communities\n"
8017 "community number\n"
8018 "Do not send outside local AS (well-known community)\n"
8019 "Do not advertise to any peer (well-known community)\n"
8020 "Do not export to next AS (well-known community)\n"
8021 "community number\n"
8022 "Do not send outside local AS (well-known community)\n"
8023 "Do not advertise to any peer (well-known community)\n"
8024 "Do not export to next AS (well-known community)\n"
8025 "community number\n"
8026 "Do not send outside local AS (well-known community)\n"
8027 "Do not advertise to any peer (well-known community)\n"
8028 "Do not export to next AS (well-known community)\n"
8029 "community number\n"
8030 "Do not send outside local AS (well-known community)\n"
8031 "Do not advertise to any peer (well-known community)\n"
8032 "Do not export to next AS (well-known community)\n")
8033
Michael Lambert95cbbd22010-07-23 14:43:04 -04008034DEFUN (show_bgp_view_afi_safi_community_all,
8035 show_bgp_view_afi_safi_community_all_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008036 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008037 SHOW_STR
8038 BGP_STR
8039 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008040 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008041 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008042 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008043 "Address Family modifier\n"
8044 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00008045 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04008046{
8047 int afi;
8048 int safi;
8049 struct bgp *bgp;
8050
8051 /* BGP structure lookup. */
8052 bgp = bgp_lookup_by_name (argv[0]);
8053 if (bgp == NULL)
8054 {
8055 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8056 return CMD_WARNING;
8057 }
8058
Michael Lambert95cbbd22010-07-23 14:43:04 -04008059 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8060 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Michael Lambert95cbbd22010-07-23 14:43:04 -04008061 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
8062}
8063
8064DEFUN (show_bgp_view_afi_safi_community,
8065 show_bgp_view_afi_safi_community_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008066 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008067 SHOW_STR
8068 BGP_STR
8069 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008070 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008071 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008072 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008073 "Address family modifier\n"
8074 "Address family modifier\n"
8075 "Display routes matching the communities\n"
8076 "community number\n"
8077 "Do not send outside local AS (well-known community)\n"
8078 "Do not advertise to any peer (well-known community)\n"
8079 "Do not export to next AS (well-known community)\n")
8080{
8081 int afi;
8082 int safi;
8083
Michael Lambert95cbbd22010-07-23 14:43:04 -04008084 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8085 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8086 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Michael Lambert95cbbd22010-07-23 14:43:04 -04008087}
8088
8089ALIAS (show_bgp_view_afi_safi_community,
8090 show_bgp_view_afi_safi_community2_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008091 "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 -04008092 SHOW_STR
8093 BGP_STR
8094 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008095 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008096 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008097 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008098 "Address family modifier\n"
8099 "Address family modifier\n"
8100 "Display routes matching the communities\n"
8101 "community number\n"
8102 "Do not send outside local AS (well-known community)\n"
8103 "Do not advertise to any peer (well-known community)\n"
8104 "Do not export to next AS (well-known community)\n"
8105 "community number\n"
8106 "Do not send outside local AS (well-known community)\n"
8107 "Do not advertise to any peer (well-known community)\n"
8108 "Do not export to next AS (well-known community)\n")
8109
8110ALIAS (show_bgp_view_afi_safi_community,
8111 show_bgp_view_afi_safi_community3_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008112 "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 -04008113 SHOW_STR
8114 BGP_STR
8115 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008116 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008117 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008118 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008119 "Address family modifier\n"
8120 "Address family modifier\n"
8121 "Display routes matching the communities\n"
8122 "community number\n"
8123 "Do not send outside local AS (well-known community)\n"
8124 "Do not advertise to any peer (well-known community)\n"
8125 "Do not export to next AS (well-known community)\n"
8126 "community number\n"
8127 "Do not send outside local AS (well-known community)\n"
8128 "Do not advertise to any peer (well-known community)\n"
8129 "Do not export to next AS (well-known community)\n"
8130 "community number\n"
8131 "Do not send outside local AS (well-known community)\n"
8132 "Do not advertise to any peer (well-known community)\n"
8133 "Do not export to next AS (well-known community)\n")
8134
8135ALIAS (show_bgp_view_afi_safi_community,
8136 show_bgp_view_afi_safi_community4_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008137 "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 -04008138 SHOW_STR
8139 BGP_STR
8140 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008141 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008142 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008143 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008144 "Address family modifier\n"
8145 "Address family modifier\n"
8146 "Display routes matching the communities\n"
8147 "community number\n"
8148 "Do not send outside local AS (well-known community)\n"
8149 "Do not advertise to any peer (well-known community)\n"
8150 "Do not export to next AS (well-known community)\n"
8151 "community number\n"
8152 "Do not send outside local AS (well-known community)\n"
8153 "Do not advertise to any peer (well-known community)\n"
8154 "Do not export to next AS (well-known community)\n"
8155 "community number\n"
8156 "Do not send outside local AS (well-known community)\n"
8157 "Do not advertise to any peer (well-known community)\n"
8158 "Do not export to next AS (well-known community)\n"
8159 "community number\n"
8160 "Do not send outside local AS (well-known community)\n"
8161 "Do not advertise to any peer (well-known community)\n"
8162 "Do not export to next AS (well-known community)\n")
8163
paul718e3742002-12-13 20:15:29 +00008164DEFUN (show_ip_bgp_community_exact,
8165 show_ip_bgp_community_exact_cmd,
8166 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8167 SHOW_STR
8168 IP_STR
8169 BGP_STR
8170 "Display routes matching the communities\n"
8171 "community number\n"
8172 "Do not send outside local AS (well-known community)\n"
8173 "Do not advertise to any peer (well-known community)\n"
8174 "Do not export to next AS (well-known community)\n"
8175 "Exact match of the communities")
8176{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008177 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008178}
8179
8180ALIAS (show_ip_bgp_community_exact,
8181 show_ip_bgp_community2_exact_cmd,
8182 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8183 SHOW_STR
8184 IP_STR
8185 BGP_STR
8186 "Display routes matching the communities\n"
8187 "community number\n"
8188 "Do not send outside local AS (well-known community)\n"
8189 "Do not advertise to any peer (well-known community)\n"
8190 "Do not export to next AS (well-known community)\n"
8191 "community number\n"
8192 "Do not send outside local AS (well-known community)\n"
8193 "Do not advertise to any peer (well-known community)\n"
8194 "Do not export to next AS (well-known community)\n"
8195 "Exact match of the communities")
8196
8197ALIAS (show_ip_bgp_community_exact,
8198 show_ip_bgp_community3_exact_cmd,
8199 "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",
8200 SHOW_STR
8201 IP_STR
8202 BGP_STR
8203 "Display routes matching the communities\n"
8204 "community number\n"
8205 "Do not send outside local AS (well-known community)\n"
8206 "Do not advertise to any peer (well-known community)\n"
8207 "Do not export to next AS (well-known community)\n"
8208 "community number\n"
8209 "Do not send outside local AS (well-known community)\n"
8210 "Do not advertise to any peer (well-known community)\n"
8211 "Do not export to next AS (well-known community)\n"
8212 "community number\n"
8213 "Do not send outside local AS (well-known community)\n"
8214 "Do not advertise to any peer (well-known community)\n"
8215 "Do not export to next AS (well-known community)\n"
8216 "Exact match of the communities")
8217
8218ALIAS (show_ip_bgp_community_exact,
8219 show_ip_bgp_community4_exact_cmd,
8220 "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",
8221 SHOW_STR
8222 IP_STR
8223 BGP_STR
8224 "Display routes matching the communities\n"
8225 "community number\n"
8226 "Do not send outside local AS (well-known community)\n"
8227 "Do not advertise to any peer (well-known community)\n"
8228 "Do not export to next AS (well-known community)\n"
8229 "community number\n"
8230 "Do not send outside local AS (well-known community)\n"
8231 "Do not advertise to any peer (well-known community)\n"
8232 "Do not export to next AS (well-known community)\n"
8233 "community number\n"
8234 "Do not send outside local AS (well-known community)\n"
8235 "Do not advertise to any peer (well-known community)\n"
8236 "Do not export to next AS (well-known community)\n"
8237 "community number\n"
8238 "Do not send outside local AS (well-known community)\n"
8239 "Do not advertise to any peer (well-known community)\n"
8240 "Do not export to next AS (well-known community)\n"
8241 "Exact match of the communities")
8242
8243DEFUN (show_ip_bgp_ipv4_community_exact,
8244 show_ip_bgp_ipv4_community_exact_cmd,
8245 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8246 SHOW_STR
8247 IP_STR
8248 BGP_STR
8249 "Address family\n"
8250 "Address Family modifier\n"
8251 "Address Family modifier\n"
8252 "Display routes matching the communities\n"
8253 "community number\n"
8254 "Do not send outside local AS (well-known community)\n"
8255 "Do not advertise to any peer (well-known community)\n"
8256 "Do not export to next AS (well-known community)\n"
8257 "Exact match of the communities")
8258{
8259 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008260 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008261
Michael Lambert95cbbd22010-07-23 14:43:04 -04008262 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008263}
8264
8265ALIAS (show_ip_bgp_ipv4_community_exact,
8266 show_ip_bgp_ipv4_community2_exact_cmd,
8267 "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",
8268 SHOW_STR
8269 IP_STR
8270 BGP_STR
8271 "Address family\n"
8272 "Address Family modifier\n"
8273 "Address Family modifier\n"
8274 "Display routes matching the communities\n"
8275 "community number\n"
8276 "Do not send outside local AS (well-known community)\n"
8277 "Do not advertise to any peer (well-known community)\n"
8278 "Do not export to next AS (well-known community)\n"
8279 "community number\n"
8280 "Do not send outside local AS (well-known community)\n"
8281 "Do not advertise to any peer (well-known community)\n"
8282 "Do not export to next AS (well-known community)\n"
8283 "Exact match of the communities")
8284
8285ALIAS (show_ip_bgp_ipv4_community_exact,
8286 show_ip_bgp_ipv4_community3_exact_cmd,
8287 "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",
8288 SHOW_STR
8289 IP_STR
8290 BGP_STR
8291 "Address family\n"
8292 "Address Family modifier\n"
8293 "Address Family modifier\n"
8294 "Display routes matching the communities\n"
8295 "community number\n"
8296 "Do not send outside local AS (well-known community)\n"
8297 "Do not advertise to any peer (well-known community)\n"
8298 "Do not export to next AS (well-known community)\n"
8299 "community number\n"
8300 "Do not send outside local AS (well-known community)\n"
8301 "Do not advertise to any peer (well-known community)\n"
8302 "Do not export to next AS (well-known community)\n"
8303 "community number\n"
8304 "Do not send outside local AS (well-known community)\n"
8305 "Do not advertise to any peer (well-known community)\n"
8306 "Do not export to next AS (well-known community)\n"
8307 "Exact match of the communities")
8308
8309ALIAS (show_ip_bgp_ipv4_community_exact,
8310 show_ip_bgp_ipv4_community4_exact_cmd,
8311 "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",
8312 SHOW_STR
8313 IP_STR
8314 BGP_STR
8315 "Address family\n"
8316 "Address Family modifier\n"
8317 "Address Family modifier\n"
8318 "Display routes matching the communities\n"
8319 "community number\n"
8320 "Do not send outside local AS (well-known community)\n"
8321 "Do not advertise to any peer (well-known community)\n"
8322 "Do not export to next AS (well-known community)\n"
8323 "community number\n"
8324 "Do not send outside local AS (well-known community)\n"
8325 "Do not advertise to any peer (well-known community)\n"
8326 "Do not export to next AS (well-known community)\n"
8327 "community number\n"
8328 "Do not send outside local AS (well-known community)\n"
8329 "Do not advertise to any peer (well-known community)\n"
8330 "Do not export to next AS (well-known community)\n"
8331 "community number\n"
8332 "Do not send outside local AS (well-known community)\n"
8333 "Do not advertise to any peer (well-known community)\n"
8334 "Do not export to next AS (well-known community)\n"
8335 "Exact match of the communities")
8336
8337#ifdef HAVE_IPV6
8338DEFUN (show_bgp_community,
8339 show_bgp_community_cmd,
8340 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8341 SHOW_STR
8342 BGP_STR
8343 "Display routes matching the communities\n"
8344 "community number\n"
8345 "Do not send outside local AS (well-known community)\n"
8346 "Do not advertise to any peer (well-known community)\n"
8347 "Do not export to next AS (well-known community)\n")
8348{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008349 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008350}
8351
8352ALIAS (show_bgp_community,
8353 show_bgp_ipv6_community_cmd,
8354 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8355 SHOW_STR
8356 BGP_STR
8357 "Address family\n"
8358 "Display routes matching the communities\n"
8359 "community number\n"
8360 "Do not send outside local AS (well-known community)\n"
8361 "Do not advertise to any peer (well-known community)\n"
8362 "Do not export to next AS (well-known community)\n")
8363
8364ALIAS (show_bgp_community,
8365 show_bgp_community2_cmd,
8366 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8367 SHOW_STR
8368 BGP_STR
8369 "Display routes matching the communities\n"
8370 "community number\n"
8371 "Do not send outside local AS (well-known community)\n"
8372 "Do not advertise to any peer (well-known community)\n"
8373 "Do not export to next AS (well-known community)\n"
8374 "community number\n"
8375 "Do not send outside local AS (well-known community)\n"
8376 "Do not advertise to any peer (well-known community)\n"
8377 "Do not export to next AS (well-known community)\n")
8378
8379ALIAS (show_bgp_community,
8380 show_bgp_ipv6_community2_cmd,
8381 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8382 SHOW_STR
8383 BGP_STR
8384 "Address family\n"
8385 "Display routes matching the communities\n"
8386 "community number\n"
8387 "Do not send outside local AS (well-known community)\n"
8388 "Do not advertise to any peer (well-known community)\n"
8389 "Do not export to next AS (well-known community)\n"
8390 "community number\n"
8391 "Do not send outside local AS (well-known community)\n"
8392 "Do not advertise to any peer (well-known community)\n"
8393 "Do not export to next AS (well-known community)\n")
8394
8395ALIAS (show_bgp_community,
8396 show_bgp_community3_cmd,
8397 "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)",
8398 SHOW_STR
8399 BGP_STR
8400 "Display routes matching the communities\n"
8401 "community number\n"
8402 "Do not send outside local AS (well-known community)\n"
8403 "Do not advertise to any peer (well-known community)\n"
8404 "Do not export to next AS (well-known community)\n"
8405 "community number\n"
8406 "Do not send outside local AS (well-known community)\n"
8407 "Do not advertise to any peer (well-known community)\n"
8408 "Do not export to next AS (well-known community)\n"
8409 "community number\n"
8410 "Do not send outside local AS (well-known community)\n"
8411 "Do not advertise to any peer (well-known community)\n"
8412 "Do not export to next AS (well-known community)\n")
8413
8414ALIAS (show_bgp_community,
8415 show_bgp_ipv6_community3_cmd,
8416 "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)",
8417 SHOW_STR
8418 BGP_STR
8419 "Address family\n"
8420 "Display routes matching the communities\n"
8421 "community number\n"
8422 "Do not send outside local AS (well-known community)\n"
8423 "Do not advertise to any peer (well-known community)\n"
8424 "Do not export to next AS (well-known community)\n"
8425 "community number\n"
8426 "Do not send outside local AS (well-known community)\n"
8427 "Do not advertise to any peer (well-known community)\n"
8428 "Do not export to next AS (well-known community)\n"
8429 "community number\n"
8430 "Do not send outside local AS (well-known community)\n"
8431 "Do not advertise to any peer (well-known community)\n"
8432 "Do not export to next AS (well-known community)\n")
8433
8434ALIAS (show_bgp_community,
8435 show_bgp_community4_cmd,
8436 "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)",
8437 SHOW_STR
8438 BGP_STR
8439 "Display routes matching the communities\n"
8440 "community number\n"
8441 "Do not send outside local AS (well-known community)\n"
8442 "Do not advertise to any peer (well-known community)\n"
8443 "Do not export to next AS (well-known community)\n"
8444 "community number\n"
8445 "Do not send outside local AS (well-known community)\n"
8446 "Do not advertise to any peer (well-known community)\n"
8447 "Do not export to next AS (well-known community)\n"
8448 "community number\n"
8449 "Do not send outside local AS (well-known community)\n"
8450 "Do not advertise to any peer (well-known community)\n"
8451 "Do not export to next AS (well-known community)\n"
8452 "community number\n"
8453 "Do not send outside local AS (well-known community)\n"
8454 "Do not advertise to any peer (well-known community)\n"
8455 "Do not export to next AS (well-known community)\n")
8456
8457ALIAS (show_bgp_community,
8458 show_bgp_ipv6_community4_cmd,
8459 "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)",
8460 SHOW_STR
8461 BGP_STR
8462 "Address family\n"
8463 "Display routes matching the communities\n"
8464 "community number\n"
8465 "Do not send outside local AS (well-known community)\n"
8466 "Do not advertise to any peer (well-known community)\n"
8467 "Do not export to next AS (well-known community)\n"
8468 "community number\n"
8469 "Do not send outside local AS (well-known community)\n"
8470 "Do not advertise to any peer (well-known community)\n"
8471 "Do not export to next AS (well-known community)\n"
8472 "community number\n"
8473 "Do not send outside local AS (well-known community)\n"
8474 "Do not advertise to any peer (well-known community)\n"
8475 "Do not export to next AS (well-known community)\n"
8476 "community number\n"
8477 "Do not send outside local AS (well-known community)\n"
8478 "Do not advertise to any peer (well-known community)\n"
8479 "Do not export to next AS (well-known community)\n")
8480
8481/* old command */
8482DEFUN (show_ipv6_bgp_community,
8483 show_ipv6_bgp_community_cmd,
8484 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8485 SHOW_STR
8486 IPV6_STR
8487 BGP_STR
8488 "Display routes matching the communities\n"
8489 "community number\n"
8490 "Do not send outside local AS (well-known community)\n"
8491 "Do not advertise to any peer (well-known community)\n"
8492 "Do not export to next AS (well-known community)\n")
8493{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008494 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008495}
8496
8497/* old command */
8498ALIAS (show_ipv6_bgp_community,
8499 show_ipv6_bgp_community2_cmd,
8500 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8501 SHOW_STR
8502 IPV6_STR
8503 BGP_STR
8504 "Display routes matching the communities\n"
8505 "community number\n"
8506 "Do not send outside local AS (well-known community)\n"
8507 "Do not advertise to any peer (well-known community)\n"
8508 "Do not export to next AS (well-known community)\n"
8509 "community number\n"
8510 "Do not send outside local AS (well-known community)\n"
8511 "Do not advertise to any peer (well-known community)\n"
8512 "Do not export to next AS (well-known community)\n")
8513
8514/* old command */
8515ALIAS (show_ipv6_bgp_community,
8516 show_ipv6_bgp_community3_cmd,
8517 "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)",
8518 SHOW_STR
8519 IPV6_STR
8520 BGP_STR
8521 "Display routes matching the communities\n"
8522 "community number\n"
8523 "Do not send outside local AS (well-known community)\n"
8524 "Do not advertise to any peer (well-known community)\n"
8525 "Do not export to next AS (well-known community)\n"
8526 "community number\n"
8527 "Do not send outside local AS (well-known community)\n"
8528 "Do not advertise to any peer (well-known community)\n"
8529 "Do not export to next AS (well-known community)\n"
8530 "community number\n"
8531 "Do not send outside local AS (well-known community)\n"
8532 "Do not advertise to any peer (well-known community)\n"
8533 "Do not export to next AS (well-known community)\n")
8534
8535/* old command */
8536ALIAS (show_ipv6_bgp_community,
8537 show_ipv6_bgp_community4_cmd,
8538 "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)",
8539 SHOW_STR
8540 IPV6_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 "community number\n"
8548 "Do not send outside local AS (well-known community)\n"
8549 "Do not advertise to any peer (well-known community)\n"
8550 "Do not export to next AS (well-known community)\n"
8551 "community number\n"
8552 "Do not send outside local AS (well-known community)\n"
8553 "Do not advertise to any peer (well-known community)\n"
8554 "Do not export to next AS (well-known community)\n"
8555 "community number\n"
8556 "Do not send outside local AS (well-known community)\n"
8557 "Do not advertise to any peer (well-known community)\n"
8558 "Do not export to next AS (well-known community)\n")
8559
8560DEFUN (show_bgp_community_exact,
8561 show_bgp_community_exact_cmd,
8562 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8563 SHOW_STR
8564 BGP_STR
8565 "Display routes matching the communities\n"
8566 "community number\n"
8567 "Do not send outside local AS (well-known community)\n"
8568 "Do not advertise to any peer (well-known community)\n"
8569 "Do not export to next AS (well-known community)\n"
8570 "Exact match of the communities")
8571{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008572 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008573}
8574
8575ALIAS (show_bgp_community_exact,
8576 show_bgp_ipv6_community_exact_cmd,
8577 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8578 SHOW_STR
8579 BGP_STR
8580 "Address family\n"
8581 "Display routes matching the communities\n"
8582 "community number\n"
8583 "Do not send outside local AS (well-known community)\n"
8584 "Do not advertise to any peer (well-known community)\n"
8585 "Do not export to next AS (well-known community)\n"
8586 "Exact match of the communities")
8587
8588ALIAS (show_bgp_community_exact,
8589 show_bgp_community2_exact_cmd,
8590 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8591 SHOW_STR
8592 BGP_STR
8593 "Display routes matching the communities\n"
8594 "community number\n"
8595 "Do not send outside local AS (well-known community)\n"
8596 "Do not advertise to any peer (well-known community)\n"
8597 "Do not export to next AS (well-known community)\n"
8598 "community number\n"
8599 "Do not send outside local AS (well-known community)\n"
8600 "Do not advertise to any peer (well-known community)\n"
8601 "Do not export to next AS (well-known community)\n"
8602 "Exact match of the communities")
8603
8604ALIAS (show_bgp_community_exact,
8605 show_bgp_ipv6_community2_exact_cmd,
8606 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8607 SHOW_STR
8608 BGP_STR
8609 "Address family\n"
8610 "Display routes matching the communities\n"
8611 "community number\n"
8612 "Do not send outside local AS (well-known community)\n"
8613 "Do not advertise to any peer (well-known community)\n"
8614 "Do not export to next AS (well-known community)\n"
8615 "community number\n"
8616 "Do not send outside local AS (well-known community)\n"
8617 "Do not advertise to any peer (well-known community)\n"
8618 "Do not export to next AS (well-known community)\n"
8619 "Exact match of the communities")
8620
8621ALIAS (show_bgp_community_exact,
8622 show_bgp_community3_exact_cmd,
8623 "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",
8624 SHOW_STR
8625 BGP_STR
8626 "Display routes matching the communities\n"
8627 "community number\n"
8628 "Do not send outside local AS (well-known community)\n"
8629 "Do not advertise to any peer (well-known community)\n"
8630 "Do not export to next AS (well-known community)\n"
8631 "community number\n"
8632 "Do not send outside local AS (well-known community)\n"
8633 "Do not advertise to any peer (well-known community)\n"
8634 "Do not export to next AS (well-known community)\n"
8635 "community number\n"
8636 "Do not send outside local AS (well-known community)\n"
8637 "Do not advertise to any peer (well-known community)\n"
8638 "Do not export to next AS (well-known community)\n"
8639 "Exact match of the communities")
8640
8641ALIAS (show_bgp_community_exact,
8642 show_bgp_ipv6_community3_exact_cmd,
8643 "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",
8644 SHOW_STR
8645 BGP_STR
8646 "Address family\n"
8647 "Display routes matching the communities\n"
8648 "community number\n"
8649 "Do not send outside local AS (well-known community)\n"
8650 "Do not advertise to any peer (well-known community)\n"
8651 "Do not export to next AS (well-known community)\n"
8652 "community number\n"
8653 "Do not send outside local AS (well-known community)\n"
8654 "Do not advertise to any peer (well-known community)\n"
8655 "Do not export to next AS (well-known community)\n"
8656 "community number\n"
8657 "Do not send outside local AS (well-known community)\n"
8658 "Do not advertise to any peer (well-known community)\n"
8659 "Do not export to next AS (well-known community)\n"
8660 "Exact match of the communities")
8661
8662ALIAS (show_bgp_community_exact,
8663 show_bgp_community4_exact_cmd,
8664 "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",
8665 SHOW_STR
8666 BGP_STR
8667 "Display routes matching the communities\n"
8668 "community number\n"
8669 "Do not send outside local AS (well-known community)\n"
8670 "Do not advertise to any peer (well-known community)\n"
8671 "Do not export to next AS (well-known community)\n"
8672 "community number\n"
8673 "Do not send outside local AS (well-known community)\n"
8674 "Do not advertise to any peer (well-known community)\n"
8675 "Do not export to next AS (well-known community)\n"
8676 "community number\n"
8677 "Do not send outside local AS (well-known community)\n"
8678 "Do not advertise to any peer (well-known community)\n"
8679 "Do not export to next AS (well-known community)\n"
8680 "community number\n"
8681 "Do not send outside local AS (well-known community)\n"
8682 "Do not advertise to any peer (well-known community)\n"
8683 "Do not export to next AS (well-known community)\n"
8684 "Exact match of the communities")
8685
8686ALIAS (show_bgp_community_exact,
8687 show_bgp_ipv6_community4_exact_cmd,
8688 "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",
8689 SHOW_STR
8690 BGP_STR
8691 "Address family\n"
8692 "Display routes matching the communities\n"
8693 "community number\n"
8694 "Do not send outside local AS (well-known community)\n"
8695 "Do not advertise to any peer (well-known community)\n"
8696 "Do not export to next AS (well-known community)\n"
8697 "community number\n"
8698 "Do not send outside local AS (well-known community)\n"
8699 "Do not advertise to any peer (well-known community)\n"
8700 "Do not export to next AS (well-known community)\n"
8701 "community number\n"
8702 "Do not send outside local AS (well-known community)\n"
8703 "Do not advertise to any peer (well-known community)\n"
8704 "Do not export to next AS (well-known community)\n"
8705 "community number\n"
8706 "Do not send outside local AS (well-known community)\n"
8707 "Do not advertise to any peer (well-known community)\n"
8708 "Do not export to next AS (well-known community)\n"
8709 "Exact match of the communities")
8710
8711/* old command */
8712DEFUN (show_ipv6_bgp_community_exact,
8713 show_ipv6_bgp_community_exact_cmd,
8714 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8715 SHOW_STR
8716 IPV6_STR
8717 BGP_STR
8718 "Display routes matching the communities\n"
8719 "community number\n"
8720 "Do not send outside local AS (well-known community)\n"
8721 "Do not advertise to any peer (well-known community)\n"
8722 "Do not export to next AS (well-known community)\n"
8723 "Exact match of the communities")
8724{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008725 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008726}
8727
8728/* old command */
8729ALIAS (show_ipv6_bgp_community_exact,
8730 show_ipv6_bgp_community2_exact_cmd,
8731 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8732 SHOW_STR
8733 IPV6_STR
8734 BGP_STR
8735 "Display routes matching the communities\n"
8736 "community number\n"
8737 "Do not send outside local AS (well-known community)\n"
8738 "Do not advertise to any peer (well-known community)\n"
8739 "Do not export to next AS (well-known community)\n"
8740 "community number\n"
8741 "Do not send outside local AS (well-known community)\n"
8742 "Do not advertise to any peer (well-known community)\n"
8743 "Do not export to next AS (well-known community)\n"
8744 "Exact match of the communities")
8745
8746/* old command */
8747ALIAS (show_ipv6_bgp_community_exact,
8748 show_ipv6_bgp_community3_exact_cmd,
8749 "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",
8750 SHOW_STR
8751 IPV6_STR
8752 BGP_STR
8753 "Display routes matching the communities\n"
8754 "community number\n"
8755 "Do not send outside local AS (well-known community)\n"
8756 "Do not advertise to any peer (well-known community)\n"
8757 "Do not export to next AS (well-known community)\n"
8758 "community number\n"
8759 "Do not send outside local AS (well-known community)\n"
8760 "Do not advertise to any peer (well-known community)\n"
8761 "Do not export to next AS (well-known community)\n"
8762 "community number\n"
8763 "Do not send outside local AS (well-known community)\n"
8764 "Do not advertise to any peer (well-known community)\n"
8765 "Do not export to next AS (well-known community)\n"
8766 "Exact match of the communities")
8767
8768/* old command */
8769ALIAS (show_ipv6_bgp_community_exact,
8770 show_ipv6_bgp_community4_exact_cmd,
8771 "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",
8772 SHOW_STR
8773 IPV6_STR
8774 BGP_STR
8775 "Display routes matching the communities\n"
8776 "community number\n"
8777 "Do not send outside local AS (well-known community)\n"
8778 "Do not advertise to any peer (well-known community)\n"
8779 "Do not export to next AS (well-known community)\n"
8780 "community number\n"
8781 "Do not send outside local AS (well-known community)\n"
8782 "Do not advertise to any peer (well-known community)\n"
8783 "Do not export to next AS (well-known community)\n"
8784 "community number\n"
8785 "Do not send outside local AS (well-known community)\n"
8786 "Do not advertise to any peer (well-known community)\n"
8787 "Do not export to next AS (well-known community)\n"
8788 "community number\n"
8789 "Do not send outside local AS (well-known community)\n"
8790 "Do not advertise to any peer (well-known community)\n"
8791 "Do not export to next AS (well-known community)\n"
8792 "Exact match of the communities")
8793
8794/* old command */
8795DEFUN (show_ipv6_mbgp_community,
8796 show_ipv6_mbgp_community_cmd,
8797 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8798 SHOW_STR
8799 IPV6_STR
8800 MBGP_STR
8801 "Display routes matching the communities\n"
8802 "community number\n"
8803 "Do not send outside local AS (well-known community)\n"
8804 "Do not advertise to any peer (well-known community)\n"
8805 "Do not export to next AS (well-known community)\n")
8806{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008807 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008808}
8809
8810/* old command */
8811ALIAS (show_ipv6_mbgp_community,
8812 show_ipv6_mbgp_community2_cmd,
8813 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8814 SHOW_STR
8815 IPV6_STR
8816 MBGP_STR
8817 "Display routes matching the communities\n"
8818 "community number\n"
8819 "Do not send outside local AS (well-known community)\n"
8820 "Do not advertise to any peer (well-known community)\n"
8821 "Do not export to next AS (well-known community)\n"
8822 "community number\n"
8823 "Do not send outside local AS (well-known community)\n"
8824 "Do not advertise to any peer (well-known community)\n"
8825 "Do not export to next AS (well-known community)\n")
8826
8827/* old command */
8828ALIAS (show_ipv6_mbgp_community,
8829 show_ipv6_mbgp_community3_cmd,
8830 "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)",
8831 SHOW_STR
8832 IPV6_STR
8833 MBGP_STR
8834 "Display routes matching the communities\n"
8835 "community number\n"
8836 "Do not send outside local AS (well-known community)\n"
8837 "Do not advertise to any peer (well-known community)\n"
8838 "Do not export to next AS (well-known community)\n"
8839 "community number\n"
8840 "Do not send outside local AS (well-known community)\n"
8841 "Do not advertise to any peer (well-known community)\n"
8842 "Do not export to next AS (well-known community)\n"
8843 "community number\n"
8844 "Do not send outside local AS (well-known community)\n"
8845 "Do not advertise to any peer (well-known community)\n"
8846 "Do not export to next AS (well-known community)\n")
8847
8848/* old command */
8849ALIAS (show_ipv6_mbgp_community,
8850 show_ipv6_mbgp_community4_cmd,
8851 "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)",
8852 SHOW_STR
8853 IPV6_STR
8854 MBGP_STR
8855 "Display routes matching the communities\n"
8856 "community number\n"
8857 "Do not send outside local AS (well-known community)\n"
8858 "Do not advertise to any peer (well-known community)\n"
8859 "Do not export to next AS (well-known community)\n"
8860 "community number\n"
8861 "Do not send outside local AS (well-known community)\n"
8862 "Do not advertise to any peer (well-known community)\n"
8863 "Do not export to next AS (well-known community)\n"
8864 "community number\n"
8865 "Do not send outside local AS (well-known community)\n"
8866 "Do not advertise to any peer (well-known community)\n"
8867 "Do not export to next AS (well-known community)\n"
8868 "community number\n"
8869 "Do not send outside local AS (well-known community)\n"
8870 "Do not advertise to any peer (well-known community)\n"
8871 "Do not export to next AS (well-known community)\n")
8872
8873/* old command */
8874DEFUN (show_ipv6_mbgp_community_exact,
8875 show_ipv6_mbgp_community_exact_cmd,
8876 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8877 SHOW_STR
8878 IPV6_STR
8879 MBGP_STR
8880 "Display routes matching the communities\n"
8881 "community number\n"
8882 "Do not send outside local AS (well-known community)\n"
8883 "Do not advertise to any peer (well-known community)\n"
8884 "Do not export to next AS (well-known community)\n"
8885 "Exact match of the communities")
8886{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008887 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008888}
8889
8890/* old command */
8891ALIAS (show_ipv6_mbgp_community_exact,
8892 show_ipv6_mbgp_community2_exact_cmd,
8893 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8894 SHOW_STR
8895 IPV6_STR
8896 MBGP_STR
8897 "Display routes matching the communities\n"
8898 "community number\n"
8899 "Do not send outside local AS (well-known community)\n"
8900 "Do not advertise to any peer (well-known community)\n"
8901 "Do not export to next AS (well-known community)\n"
8902 "community number\n"
8903 "Do not send outside local AS (well-known community)\n"
8904 "Do not advertise to any peer (well-known community)\n"
8905 "Do not export to next AS (well-known community)\n"
8906 "Exact match of the communities")
8907
8908/* old command */
8909ALIAS (show_ipv6_mbgp_community_exact,
8910 show_ipv6_mbgp_community3_exact_cmd,
8911 "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",
8912 SHOW_STR
8913 IPV6_STR
8914 MBGP_STR
8915 "Display routes matching the communities\n"
8916 "community number\n"
8917 "Do not send outside local AS (well-known community)\n"
8918 "Do not advertise to any peer (well-known community)\n"
8919 "Do not export to next AS (well-known community)\n"
8920 "community number\n"
8921 "Do not send outside local AS (well-known community)\n"
8922 "Do not advertise to any peer (well-known community)\n"
8923 "Do not export to next AS (well-known community)\n"
8924 "community number\n"
8925 "Do not send outside local AS (well-known community)\n"
8926 "Do not advertise to any peer (well-known community)\n"
8927 "Do not export to next AS (well-known community)\n"
8928 "Exact match of the communities")
8929
8930/* old command */
8931ALIAS (show_ipv6_mbgp_community_exact,
8932 show_ipv6_mbgp_community4_exact_cmd,
8933 "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",
8934 SHOW_STR
8935 IPV6_STR
8936 MBGP_STR
8937 "Display routes matching the communities\n"
8938 "community number\n"
8939 "Do not send outside local AS (well-known community)\n"
8940 "Do not advertise to any peer (well-known community)\n"
8941 "Do not export to next AS (well-known community)\n"
8942 "community number\n"
8943 "Do not send outside local AS (well-known community)\n"
8944 "Do not advertise to any peer (well-known community)\n"
8945 "Do not export to next AS (well-known community)\n"
8946 "community number\n"
8947 "Do not send outside local AS (well-known community)\n"
8948 "Do not advertise to any peer (well-known community)\n"
8949 "Do not export to next AS (well-known community)\n"
8950 "community number\n"
8951 "Do not send outside local AS (well-known community)\n"
8952 "Do not advertise to any peer (well-known community)\n"
8953 "Do not export to next AS (well-known community)\n"
8954 "Exact match of the communities")
8955#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02008956
paul94f2b392005-06-28 12:44:16 +00008957static int
paulfd79ac92004-10-13 05:06:08 +00008958bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008959 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008960{
8961 struct community_list *list;
8962
hassofee6e4e2005-02-02 16:29:31 +00008963 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008964 if (list == NULL)
8965 {
8966 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8967 VTY_NEWLINE);
8968 return CMD_WARNING;
8969 }
8970
ajs5a646652004-11-05 01:25:55 +00008971 return bgp_show (vty, NULL, afi, safi,
8972 (exact ? bgp_show_type_community_list_exact :
8973 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008974}
8975
8976DEFUN (show_ip_bgp_community_list,
8977 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008978 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008979 SHOW_STR
8980 IP_STR
8981 BGP_STR
8982 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008983 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008984 "community-list name\n")
8985{
8986 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8987}
8988
8989DEFUN (show_ip_bgp_ipv4_community_list,
8990 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008991 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008992 SHOW_STR
8993 IP_STR
8994 BGP_STR
8995 "Address family\n"
8996 "Address Family modifier\n"
8997 "Address Family modifier\n"
8998 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008999 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009000 "community-list name\n")
9001{
9002 if (strncmp (argv[0], "m", 1) == 0)
9003 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
9004
9005 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
9006}
9007
9008DEFUN (show_ip_bgp_community_list_exact,
9009 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009010 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009011 SHOW_STR
9012 IP_STR
9013 BGP_STR
9014 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009015 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009016 "community-list name\n"
9017 "Exact match of the communities\n")
9018{
9019 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
9020}
9021
9022DEFUN (show_ip_bgp_ipv4_community_list_exact,
9023 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009024 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009025 SHOW_STR
9026 IP_STR
9027 BGP_STR
9028 "Address family\n"
9029 "Address Family modifier\n"
9030 "Address Family modifier\n"
9031 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009032 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009033 "community-list name\n"
9034 "Exact match of the communities\n")
9035{
9036 if (strncmp (argv[0], "m", 1) == 0)
9037 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
9038
9039 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
9040}
9041
9042#ifdef HAVE_IPV6
9043DEFUN (show_bgp_community_list,
9044 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009045 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009046 SHOW_STR
9047 BGP_STR
9048 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009049 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009050 "community-list name\n")
9051{
9052 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9053}
9054
9055ALIAS (show_bgp_community_list,
9056 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009057 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009058 SHOW_STR
9059 BGP_STR
9060 "Address family\n"
9061 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009062 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00009063 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00009064
9065/* old command */
9066DEFUN (show_ipv6_bgp_community_list,
9067 show_ipv6_bgp_community_list_cmd,
9068 "show ipv6 bgp community-list WORD",
9069 SHOW_STR
9070 IPV6_STR
9071 BGP_STR
9072 "Display routes matching the community-list\n"
9073 "community-list name\n")
9074{
9075 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9076}
9077
9078/* old command */
9079DEFUN (show_ipv6_mbgp_community_list,
9080 show_ipv6_mbgp_community_list_cmd,
9081 "show ipv6 mbgp community-list WORD",
9082 SHOW_STR
9083 IPV6_STR
9084 MBGP_STR
9085 "Display routes matching the community-list\n"
9086 "community-list name\n")
9087{
9088 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
9089}
9090
9091DEFUN (show_bgp_community_list_exact,
9092 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009093 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009094 SHOW_STR
9095 BGP_STR
9096 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009097 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009098 "community-list name\n"
9099 "Exact match of the communities\n")
9100{
9101 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9102}
9103
9104ALIAS (show_bgp_community_list_exact,
9105 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009106 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009107 SHOW_STR
9108 BGP_STR
9109 "Address family\n"
9110 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009111 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009112 "community-list name\n"
9113 "Exact match of the communities\n")
9114
9115/* old command */
9116DEFUN (show_ipv6_bgp_community_list_exact,
9117 show_ipv6_bgp_community_list_exact_cmd,
9118 "show ipv6 bgp community-list WORD exact-match",
9119 SHOW_STR
9120 IPV6_STR
9121 BGP_STR
9122 "Display routes matching the community-list\n"
9123 "community-list name\n"
9124 "Exact match of the communities\n")
9125{
9126 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9127}
9128
9129/* old command */
9130DEFUN (show_ipv6_mbgp_community_list_exact,
9131 show_ipv6_mbgp_community_list_exact_cmd,
9132 "show ipv6 mbgp community-list WORD exact-match",
9133 SHOW_STR
9134 IPV6_STR
9135 MBGP_STR
9136 "Display routes matching the community-list\n"
9137 "community-list name\n"
9138 "Exact match of the communities\n")
9139{
9140 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9141}
9142#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009143
paul94f2b392005-06-28 12:44:16 +00009144static int
paulfd79ac92004-10-13 05:06:08 +00009145bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009146 safi_t safi, enum bgp_show_type type)
9147{
9148 int ret;
9149 struct prefix *p;
9150
9151 p = prefix_new();
9152
9153 ret = str2prefix (prefix, p);
9154 if (! ret)
9155 {
9156 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9157 return CMD_WARNING;
9158 }
9159
ajs5a646652004-11-05 01:25:55 +00009160 ret = bgp_show (vty, NULL, afi, safi, type, p);
9161 prefix_free(p);
9162 return ret;
paul718e3742002-12-13 20:15:29 +00009163}
9164
9165DEFUN (show_ip_bgp_prefix_longer,
9166 show_ip_bgp_prefix_longer_cmd,
9167 "show ip bgp A.B.C.D/M longer-prefixes",
9168 SHOW_STR
9169 IP_STR
9170 BGP_STR
9171 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9172 "Display route and more specific routes\n")
9173{
9174 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9175 bgp_show_type_prefix_longer);
9176}
9177
9178DEFUN (show_ip_bgp_flap_prefix_longer,
9179 show_ip_bgp_flap_prefix_longer_cmd,
9180 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9181 SHOW_STR
9182 IP_STR
9183 BGP_STR
9184 "Display flap statistics of routes\n"
9185 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9186 "Display route and more specific routes\n")
9187{
9188 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9189 bgp_show_type_flap_prefix_longer);
9190}
9191
Balaji3921cc52015-05-16 23:12:17 +05309192ALIAS (show_ip_bgp_flap_prefix_longer,
9193 show_ip_bgp_damp_flap_prefix_longer_cmd,
9194 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
9195 SHOW_STR
9196 IP_STR
9197 BGP_STR
9198 "Display detailed information about dampening\n"
9199 "Display flap statistics of routes\n"
9200 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9201 "Display route and more specific routes\n")
9202
paul718e3742002-12-13 20:15:29 +00009203DEFUN (show_ip_bgp_ipv4_prefix_longer,
9204 show_ip_bgp_ipv4_prefix_longer_cmd,
9205 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9206 SHOW_STR
9207 IP_STR
9208 BGP_STR
9209 "Address family\n"
9210 "Address Family modifier\n"
9211 "Address Family modifier\n"
9212 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9213 "Display route and more specific routes\n")
9214{
9215 if (strncmp (argv[0], "m", 1) == 0)
9216 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9217 bgp_show_type_prefix_longer);
9218
9219 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9220 bgp_show_type_prefix_longer);
9221}
9222
9223DEFUN (show_ip_bgp_flap_address,
9224 show_ip_bgp_flap_address_cmd,
9225 "show ip bgp flap-statistics A.B.C.D",
9226 SHOW_STR
9227 IP_STR
9228 BGP_STR
9229 "Display flap statistics of routes\n"
9230 "Network in the BGP routing table to display\n")
9231{
9232 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9233 bgp_show_type_flap_address);
9234}
9235
Balaji3921cc52015-05-16 23:12:17 +05309236ALIAS (show_ip_bgp_flap_address,
9237 show_ip_bgp_damp_flap_address_cmd,
9238 "show ip bgp dampening flap-statistics A.B.C.D",
9239 SHOW_STR
9240 IP_STR
9241 BGP_STR
9242 "Display detailed information about dampening\n"
9243 "Display flap statistics of routes\n"
9244 "Network in the BGP routing table to display\n")
9245
paul718e3742002-12-13 20:15:29 +00009246DEFUN (show_ip_bgp_flap_prefix,
9247 show_ip_bgp_flap_prefix_cmd,
9248 "show ip bgp flap-statistics A.B.C.D/M",
9249 SHOW_STR
9250 IP_STR
9251 BGP_STR
9252 "Display flap statistics of routes\n"
9253 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9254{
9255 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9256 bgp_show_type_flap_prefix);
9257}
Balaji3921cc52015-05-16 23:12:17 +05309258
9259ALIAS (show_ip_bgp_flap_prefix,
9260 show_ip_bgp_damp_flap_prefix_cmd,
9261 "show ip bgp dampening flap-statistics A.B.C.D/M",
9262 SHOW_STR
9263 IP_STR
9264 BGP_STR
9265 "Display detailed information about dampening\n"
9266 "Display flap statistics of routes\n"
9267 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9268
paul718e3742002-12-13 20:15:29 +00009269#ifdef HAVE_IPV6
9270DEFUN (show_bgp_prefix_longer,
9271 show_bgp_prefix_longer_cmd,
9272 "show bgp X:X::X:X/M longer-prefixes",
9273 SHOW_STR
9274 BGP_STR
9275 "IPv6 prefix <network>/<length>\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
9282ALIAS (show_bgp_prefix_longer,
9283 show_bgp_ipv6_prefix_longer_cmd,
9284 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9285 SHOW_STR
9286 BGP_STR
9287 "Address family\n"
9288 "IPv6 prefix <network>/<length>\n"
9289 "Display route and more specific routes\n")
9290
9291/* old command */
9292DEFUN (show_ipv6_bgp_prefix_longer,
9293 show_ipv6_bgp_prefix_longer_cmd,
9294 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9295 SHOW_STR
9296 IPV6_STR
9297 BGP_STR
9298 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9299 "Display route and more specific routes\n")
9300{
9301 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9302 bgp_show_type_prefix_longer);
9303}
9304
9305/* old command */
9306DEFUN (show_ipv6_mbgp_prefix_longer,
9307 show_ipv6_mbgp_prefix_longer_cmd,
9308 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9309 SHOW_STR
9310 IPV6_STR
9311 MBGP_STR
9312 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9313 "Display route and more specific routes\n")
9314{
9315 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9316 bgp_show_type_prefix_longer);
9317}
9318#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009319
paul94f2b392005-06-28 12:44:16 +00009320static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009321peer_lookup_in_view (struct vty *vty, const char *view_name,
9322 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009323{
9324 int ret;
9325 struct bgp *bgp;
9326 struct peer *peer;
9327 union sockunion su;
9328
9329 /* BGP structure lookup. */
9330 if (view_name)
9331 {
9332 bgp = bgp_lookup_by_name (view_name);
9333 if (! bgp)
9334 {
9335 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9336 return NULL;
9337 }
9338 }
paul5228ad22004-06-04 17:58:18 +00009339 else
paulbb46e942003-10-24 19:02:03 +00009340 {
9341 bgp = bgp_get_default ();
9342 if (! bgp)
9343 {
9344 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9345 return NULL;
9346 }
9347 }
9348
9349 /* Get peer sockunion. */
9350 ret = str2sockunion (ip_str, &su);
9351 if (ret < 0)
9352 {
9353 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9354 return NULL;
9355 }
9356
9357 /* Peer structure lookup. */
9358 peer = peer_lookup (bgp, &su);
9359 if (! peer)
9360 {
9361 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9362 return NULL;
9363 }
9364
9365 return peer;
9366}
David Lamparter6b0655a2014-06-04 06:53:35 +02009367
Paul Jakma2815e612006-09-14 02:56:07 +00009368enum bgp_stats
9369{
9370 BGP_STATS_MAXBITLEN = 0,
9371 BGP_STATS_RIB,
9372 BGP_STATS_PREFIXES,
9373 BGP_STATS_TOTPLEN,
9374 BGP_STATS_UNAGGREGATEABLE,
9375 BGP_STATS_MAX_AGGREGATEABLE,
9376 BGP_STATS_AGGREGATES,
9377 BGP_STATS_SPACE,
9378 BGP_STATS_ASPATH_COUNT,
9379 BGP_STATS_ASPATH_MAXHOPS,
9380 BGP_STATS_ASPATH_TOTHOPS,
9381 BGP_STATS_ASPATH_MAXSIZE,
9382 BGP_STATS_ASPATH_TOTSIZE,
9383 BGP_STATS_ASN_HIGHEST,
9384 BGP_STATS_MAX,
9385};
paulbb46e942003-10-24 19:02:03 +00009386
Paul Jakma2815e612006-09-14 02:56:07 +00009387static const char *table_stats_strs[] =
9388{
9389 [BGP_STATS_PREFIXES] = "Total Prefixes",
9390 [BGP_STATS_TOTPLEN] = "Average prefix length",
9391 [BGP_STATS_RIB] = "Total Advertisements",
9392 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9393 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9394 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9395 [BGP_STATS_SPACE] = "Address space advertised",
9396 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9397 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9398 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9399 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9400 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9401 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9402 [BGP_STATS_MAX] = NULL,
9403};
9404
9405struct bgp_table_stats
9406{
9407 struct bgp_table *table;
9408 unsigned long long counts[BGP_STATS_MAX];
9409};
9410
9411#if 0
9412#define TALLY_SIGFIG 100000
9413static unsigned long
9414ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9415{
9416 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9417 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9418 unsigned long ret = newtot / count;
9419
9420 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9421 return ret + 1;
9422 else
9423 return ret;
9424}
9425#endif
9426
9427static int
9428bgp_table_stats_walker (struct thread *t)
9429{
9430 struct bgp_node *rn;
9431 struct bgp_node *top;
9432 struct bgp_table_stats *ts = THREAD_ARG (t);
9433 unsigned int space = 0;
9434
Paul Jakma53d9f672006-10-15 23:41:16 +00009435 if (!(top = bgp_table_top (ts->table)))
9436 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009437
9438 switch (top->p.family)
9439 {
9440 case AF_INET:
9441 space = IPV4_MAX_BITLEN;
9442 break;
9443 case AF_INET6:
9444 space = IPV6_MAX_BITLEN;
9445 break;
9446 }
9447
9448 ts->counts[BGP_STATS_MAXBITLEN] = space;
9449
9450 for (rn = top; rn; rn = bgp_route_next (rn))
9451 {
9452 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009453 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009454 unsigned int rinum = 0;
9455
9456 if (rn == top)
9457 continue;
9458
9459 if (!rn->info)
9460 continue;
9461
9462 ts->counts[BGP_STATS_PREFIXES]++;
9463 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9464
9465#if 0
9466 ts->counts[BGP_STATS_AVGPLEN]
9467 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9468 ts->counts[BGP_STATS_AVGPLEN],
9469 rn->p.prefixlen);
9470#endif
9471
9472 /* check if the prefix is included by any other announcements */
9473 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009474 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009475
9476 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009477 {
9478 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9479 /* announced address space */
9480 if (space)
9481 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9482 }
Paul Jakma2815e612006-09-14 02:56:07 +00009483 else if (prn->info)
9484 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9485
Paul Jakma2815e612006-09-14 02:56:07 +00009486 for (ri = rn->info; ri; ri = ri->next)
9487 {
9488 rinum++;
9489 ts->counts[BGP_STATS_RIB]++;
9490
9491 if (ri->attr &&
9492 (CHECK_FLAG (ri->attr->flag,
9493 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9494 ts->counts[BGP_STATS_AGGREGATES]++;
9495
9496 /* as-path stats */
9497 if (ri->attr && ri->attr->aspath)
9498 {
9499 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9500 unsigned int size = aspath_size (ri->attr->aspath);
9501 as_t highest = aspath_highest (ri->attr->aspath);
9502
9503 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9504
9505 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9506 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9507
9508 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9509 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9510
9511 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9512 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9513#if 0
9514 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9515 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9516 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9517 hops);
9518 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9519 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9520 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9521 size);
9522#endif
9523 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9524 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9525 }
9526 }
9527 }
9528 return 0;
9529}
9530
9531static int
9532bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9533{
9534 struct bgp_table_stats ts;
9535 unsigned int i;
9536
9537 if (!bgp->rib[afi][safi])
9538 {
9539 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9540 return CMD_WARNING;
9541 }
9542
9543 memset (&ts, 0, sizeof (ts));
9544 ts.table = bgp->rib[afi][safi];
9545 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9546
9547 vty_out (vty, "BGP %s RIB statistics%s%s",
9548 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9549
9550 for (i = 0; i < BGP_STATS_MAX; i++)
9551 {
9552 if (!table_stats_strs[i])
9553 continue;
9554
9555 switch (i)
9556 {
9557#if 0
9558 case BGP_STATS_ASPATH_AVGHOPS:
9559 case BGP_STATS_ASPATH_AVGSIZE:
9560 case BGP_STATS_AVGPLEN:
9561 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9562 vty_out (vty, "%12.2f",
9563 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9564 break;
9565#endif
9566 case BGP_STATS_ASPATH_TOTHOPS:
9567 case BGP_STATS_ASPATH_TOTSIZE:
9568 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9569 vty_out (vty, "%12.2f",
9570 ts.counts[i] ?
9571 (float)ts.counts[i] /
9572 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9573 : 0);
9574 break;
9575 case BGP_STATS_TOTPLEN:
9576 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9577 vty_out (vty, "%12.2f",
9578 ts.counts[i] ?
9579 (float)ts.counts[i] /
9580 (float)ts.counts[BGP_STATS_PREFIXES]
9581 : 0);
9582 break;
9583 case BGP_STATS_SPACE:
9584 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9585 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9586 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9587 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009588 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009589 vty_out (vty, "%12.2f%s",
9590 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009591 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009592 VTY_NEWLINE);
9593 vty_out (vty, "%30s: ", "/8 equivalent ");
9594 vty_out (vty, "%12.2f%s",
9595 (float)ts.counts[BGP_STATS_SPACE] /
9596 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9597 VTY_NEWLINE);
9598 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9599 break;
9600 vty_out (vty, "%30s: ", "/24 equivalent ");
9601 vty_out (vty, "%12.2f",
9602 (float)ts.counts[BGP_STATS_SPACE] /
9603 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9604 break;
9605 default:
9606 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9607 vty_out (vty, "%12llu", ts.counts[i]);
9608 }
9609
9610 vty_out (vty, "%s", VTY_NEWLINE);
9611 }
9612 return CMD_SUCCESS;
9613}
9614
9615static int
9616bgp_table_stats_vty (struct vty *vty, const char *name,
9617 const char *afi_str, const char *safi_str)
9618{
9619 struct bgp *bgp;
9620 afi_t afi;
9621 safi_t safi;
9622
9623 if (name)
9624 bgp = bgp_lookup_by_name (name);
9625 else
9626 bgp = bgp_get_default ();
9627
9628 if (!bgp)
9629 {
9630 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9631 return CMD_WARNING;
9632 }
9633 if (strncmp (afi_str, "ipv", 3) == 0)
9634 {
9635 if (strncmp (afi_str, "ipv4", 4) == 0)
9636 afi = AFI_IP;
9637 else if (strncmp (afi_str, "ipv6", 4) == 0)
9638 afi = AFI_IP6;
9639 else
9640 {
9641 vty_out (vty, "%% Invalid address family %s%s",
9642 afi_str, VTY_NEWLINE);
9643 return CMD_WARNING;
9644 }
9645 if (strncmp (safi_str, "m", 1) == 0)
9646 safi = SAFI_MULTICAST;
9647 else if (strncmp (safi_str, "u", 1) == 0)
9648 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009649 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9650 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009651 else
9652 {
9653 vty_out (vty, "%% Invalid subsequent address family %s%s",
9654 safi_str, VTY_NEWLINE);
9655 return CMD_WARNING;
9656 }
9657 }
9658 else
9659 {
9660 vty_out (vty, "%% Invalid address family %s%s",
9661 afi_str, VTY_NEWLINE);
9662 return CMD_WARNING;
9663 }
9664
Paul Jakma2815e612006-09-14 02:56:07 +00009665 return bgp_table_stats (vty, bgp, afi, safi);
9666}
9667
9668DEFUN (show_bgp_statistics,
9669 show_bgp_statistics_cmd,
9670 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9671 SHOW_STR
9672 BGP_STR
9673 "Address family\n"
9674 "Address family\n"
9675 "Address Family modifier\n"
9676 "Address Family modifier\n"
9677 "BGP RIB advertisement statistics\n")
9678{
9679 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9680}
9681
9682ALIAS (show_bgp_statistics,
9683 show_bgp_statistics_vpnv4_cmd,
9684 "show bgp (ipv4) (vpnv4) statistics",
9685 SHOW_STR
9686 BGP_STR
9687 "Address family\n"
9688 "Address Family modifier\n"
9689 "BGP RIB advertisement statistics\n")
9690
9691DEFUN (show_bgp_statistics_view,
9692 show_bgp_statistics_view_cmd,
9693 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9694 SHOW_STR
9695 BGP_STR
9696 "BGP view\n"
9697 "Address family\n"
9698 "Address family\n"
9699 "Address Family modifier\n"
9700 "Address Family modifier\n"
9701 "BGP RIB advertisement statistics\n")
9702{
9703 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9704}
9705
9706ALIAS (show_bgp_statistics_view,
9707 show_bgp_statistics_view_vpnv4_cmd,
9708 "show bgp view WORD (ipv4) (vpnv4) statistics",
9709 SHOW_STR
9710 BGP_STR
9711 "BGP view\n"
9712 "Address family\n"
9713 "Address Family modifier\n"
9714 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02009715
Paul Jakmaff7924f2006-09-04 01:10:36 +00009716enum bgp_pcounts
9717{
9718 PCOUNT_ADJ_IN = 0,
9719 PCOUNT_DAMPED,
9720 PCOUNT_REMOVED,
9721 PCOUNT_HISTORY,
9722 PCOUNT_STALE,
9723 PCOUNT_VALID,
9724 PCOUNT_ALL,
9725 PCOUNT_COUNTED,
9726 PCOUNT_PFCNT, /* the figure we display to users */
9727 PCOUNT_MAX,
9728};
9729
9730static const char *pcount_strs[] =
9731{
9732 [PCOUNT_ADJ_IN] = "Adj-in",
9733 [PCOUNT_DAMPED] = "Damped",
9734 [PCOUNT_REMOVED] = "Removed",
9735 [PCOUNT_HISTORY] = "History",
9736 [PCOUNT_STALE] = "Stale",
9737 [PCOUNT_VALID] = "Valid",
9738 [PCOUNT_ALL] = "All RIB",
9739 [PCOUNT_COUNTED] = "PfxCt counted",
9740 [PCOUNT_PFCNT] = "Useable",
9741 [PCOUNT_MAX] = NULL,
9742};
9743
Paul Jakma2815e612006-09-14 02:56:07 +00009744struct peer_pcounts
9745{
9746 unsigned int count[PCOUNT_MAX];
9747 const struct peer *peer;
9748 const struct bgp_table *table;
9749};
9750
Paul Jakmaff7924f2006-09-04 01:10:36 +00009751static int
Paul Jakma2815e612006-09-14 02:56:07 +00009752bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009753{
9754 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009755 struct peer_pcounts *pc = THREAD_ARG (t);
9756 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009757
Paul Jakma2815e612006-09-14 02:56:07 +00009758 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009759 {
9760 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009761 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009762
9763 for (ain = rn->adj_in; ain; ain = ain->next)
9764 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009765 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009766
Paul Jakmaff7924f2006-09-04 01:10:36 +00009767 for (ri = rn->info; ri; ri = ri->next)
9768 {
9769 char buf[SU_ADDRSTRLEN];
9770
9771 if (ri->peer != peer)
9772 continue;
9773
Paul Jakma2815e612006-09-14 02:56:07 +00009774 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009775
9776 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009777 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009778 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009779 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009780 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009781 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009782 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009783 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009784 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009785 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009786 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009787 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009788
9789 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9790 {
Paul Jakma2815e612006-09-14 02:56:07 +00009791 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009792 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009793 plog_warn (peer->log,
9794 "%s [pcount] %s/%d is counted but flags 0x%x",
9795 peer->host,
9796 inet_ntop(rn->p.family, &rn->p.u.prefix,
9797 buf, SU_ADDRSTRLEN),
9798 rn->p.prefixlen,
9799 ri->flags);
9800 }
9801 else
9802 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009803 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009804 plog_warn (peer->log,
9805 "%s [pcount] %s/%d not counted but flags 0x%x",
9806 peer->host,
9807 inet_ntop(rn->p.family, &rn->p.u.prefix,
9808 buf, SU_ADDRSTRLEN),
9809 rn->p.prefixlen,
9810 ri->flags);
9811 }
9812 }
9813 }
Paul Jakma2815e612006-09-14 02:56:07 +00009814 return 0;
9815}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009816
Paul Jakma2815e612006-09-14 02:56:07 +00009817static int
9818bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9819{
9820 struct peer_pcounts pcounts = { .peer = peer };
9821 unsigned int i;
9822
9823 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9824 || !peer->bgp->rib[afi][safi])
9825 {
9826 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9827 return CMD_WARNING;
9828 }
9829
9830 memset (&pcounts, 0, sizeof(pcounts));
9831 pcounts.peer = peer;
9832 pcounts.table = peer->bgp->rib[afi][safi];
9833
9834 /* in-place call via thread subsystem so as to record execution time
9835 * stats for the thread-walk (i.e. ensure this can't be blamed on
9836 * on just vty_read()).
9837 */
9838 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9839
Paul Jakmaff7924f2006-09-04 01:10:36 +00009840 vty_out (vty, "Prefix counts for %s, %s%s",
9841 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9842 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9843 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9844 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9845
9846 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009847 vty_out (vty, "%20s: %-10d%s",
9848 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009849
Paul Jakma2815e612006-09-14 02:56:07 +00009850 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009851 {
9852 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9853 peer->host, VTY_NEWLINE);
9854 vty_out (vty, "Please report this bug, with the above command output%s",
9855 VTY_NEWLINE);
9856 }
9857
9858 return CMD_SUCCESS;
9859}
9860
9861DEFUN (show_ip_bgp_neighbor_prefix_counts,
9862 show_ip_bgp_neighbor_prefix_counts_cmd,
9863 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9864 SHOW_STR
9865 IP_STR
9866 BGP_STR
9867 "Detailed information on TCP and BGP neighbor connections\n"
9868 "Neighbor to display information about\n"
9869 "Neighbor to display information about\n"
9870 "Display detailed prefix count information\n")
9871{
9872 struct peer *peer;
9873
9874 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9875 if (! peer)
9876 return CMD_WARNING;
9877
9878 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9879}
9880
9881DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9882 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9883 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9884 SHOW_STR
9885 BGP_STR
9886 "Address family\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[0]);
9895 if (! peer)
9896 return CMD_WARNING;
9897
9898 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9899}
9900
9901DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9902 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9903 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9904 SHOW_STR
9905 IP_STR
9906 BGP_STR
9907 "Address family\n"
9908 "Address Family modifier\n"
9909 "Address Family modifier\n"
9910 "Detailed information on TCP and BGP neighbor connections\n"
9911 "Neighbor to display information about\n"
9912 "Neighbor to display information about\n"
9913 "Display detailed prefix count information\n")
9914{
9915 struct peer *peer;
9916
9917 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9918 if (! peer)
9919 return CMD_WARNING;
9920
9921 if (strncmp (argv[0], "m", 1) == 0)
9922 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9923
9924 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9925}
9926
9927DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9928 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9929 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9930 SHOW_STR
9931 IP_STR
9932 BGP_STR
9933 "Address family\n"
9934 "Address Family modifier\n"
9935 "Address Family modifier\n"
9936 "Detailed information on TCP and BGP neighbor connections\n"
9937 "Neighbor to display information about\n"
9938 "Neighbor to display information about\n"
9939 "Display detailed prefix count information\n")
9940{
9941 struct peer *peer;
9942
9943 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9944 if (! peer)
9945 return CMD_WARNING;
9946
9947 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9948}
9949
9950
paul94f2b392005-06-28 12:44:16 +00009951static void
paul718e3742002-12-13 20:15:29 +00009952show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9953 int in)
9954{
9955 struct bgp_table *table;
9956 struct bgp_adj_in *ain;
9957 struct bgp_adj_out *adj;
9958 unsigned long output_count;
9959 struct bgp_node *rn;
9960 int header1 = 1;
9961 struct bgp *bgp;
9962 int header2 = 1;
9963
paulbb46e942003-10-24 19:02:03 +00009964 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009965
9966 if (! bgp)
9967 return;
9968
9969 table = bgp->rib[afi][safi];
9970
9971 output_count = 0;
9972
9973 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9974 PEER_STATUS_DEFAULT_ORIGINATE))
9975 {
9976 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 +00009977 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9978 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009979
9980 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9981 VTY_NEWLINE, VTY_NEWLINE);
9982 header1 = 0;
9983 }
9984
9985 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9986 if (in)
9987 {
9988 for (ain = rn->adj_in; ain; ain = ain->next)
9989 if (ain->peer == peer)
9990 {
9991 if (header1)
9992 {
9993 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 +00009994 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9995 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009996 header1 = 0;
9997 }
9998 if (header2)
9999 {
10000 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
10001 header2 = 0;
10002 }
10003 if (ain->attr)
10004 {
10005 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
10006 output_count++;
10007 }
10008 }
10009 }
10010 else
10011 {
10012 for (adj = rn->adj_out; adj; adj = adj->next)
10013 if (adj->peer == peer)
10014 {
10015 if (header1)
10016 {
10017 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 +000010018 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10019 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010020 header1 = 0;
10021 }
10022 if (header2)
10023 {
10024 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
10025 header2 = 0;
10026 }
10027 if (adj->attr)
10028 {
10029 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
10030 output_count++;
10031 }
10032 }
10033 }
10034
10035 if (output_count != 0)
10036 vty_out (vty, "%sTotal number of prefixes %ld%s",
10037 VTY_NEWLINE, output_count, VTY_NEWLINE);
10038}
10039
paul94f2b392005-06-28 12:44:16 +000010040static int
paulbb46e942003-10-24 19:02:03 +000010041peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
10042{
paul718e3742002-12-13 20:15:29 +000010043 if (! peer || ! peer->afc[afi][safi])
10044 {
10045 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10046 return CMD_WARNING;
10047 }
10048
10049 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10050 {
10051 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
10052 VTY_NEWLINE);
10053 return CMD_WARNING;
10054 }
10055
10056 show_adj_route (vty, peer, afi, safi, in);
10057
10058 return CMD_SUCCESS;
10059}
10060
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010061DEFUN (show_ip_bgp_view_neighbor_advertised_route,
10062 show_ip_bgp_view_neighbor_advertised_route_cmd,
10063 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10064 SHOW_STR
10065 IP_STR
10066 BGP_STR
10067 "BGP view\n"
10068 "View name\n"
10069 "Detailed information on TCP and BGP neighbor connections\n"
10070 "Neighbor to display information about\n"
10071 "Neighbor to display information about\n"
10072 "Display the routes advertised to a BGP neighbor\n")
10073{
10074 struct peer *peer;
10075
10076 if (argc == 2)
10077 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10078 else
10079 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10080
10081 if (! peer)
10082 return CMD_WARNING;
10083
10084 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
10085}
10086
10087ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010088 show_ip_bgp_neighbor_advertised_route_cmd,
10089 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10090 SHOW_STR
10091 IP_STR
10092 BGP_STR
10093 "Detailed information on TCP and BGP neighbor connections\n"
10094 "Neighbor to display information about\n"
10095 "Neighbor to display information about\n"
10096 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +000010097
10098DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
10099 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
10100 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10101 SHOW_STR
10102 IP_STR
10103 BGP_STR
10104 "Address family\n"
10105 "Address Family modifier\n"
10106 "Address Family modifier\n"
10107 "Detailed information on TCP and BGP neighbor connections\n"
10108 "Neighbor to display information about\n"
10109 "Neighbor to display information about\n"
10110 "Display the routes advertised to a BGP neighbor\n")
10111{
paulbb46e942003-10-24 19:02:03 +000010112 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010113
paulbb46e942003-10-24 19:02:03 +000010114 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10115 if (! peer)
10116 return CMD_WARNING;
10117
10118 if (strncmp (argv[0], "m", 1) == 0)
10119 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
10120
10121 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +000010122}
10123
10124#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010125DEFUN (show_bgp_view_neighbor_advertised_route,
10126 show_bgp_view_neighbor_advertised_route_cmd,
10127 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10128 SHOW_STR
10129 BGP_STR
10130 "BGP view\n"
10131 "View name\n"
10132 "Detailed information on TCP and BGP neighbor connections\n"
10133 "Neighbor to display information about\n"
10134 "Neighbor to display information about\n"
10135 "Display the routes advertised to a BGP neighbor\n")
10136{
10137 struct peer *peer;
10138
10139 if (argc == 2)
10140 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10141 else
10142 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10143
10144 if (! peer)
10145 return CMD_WARNING;
10146
10147 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10148}
10149
10150ALIAS (show_bgp_view_neighbor_advertised_route,
10151 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10152 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10153 SHOW_STR
10154 BGP_STR
10155 "BGP view\n"
10156 "View name\n"
10157 "Address family\n"
10158 "Detailed information on TCP and BGP neighbor connections\n"
10159 "Neighbor to display information about\n"
10160 "Neighbor to display information about\n"
10161 "Display the routes advertised to a BGP neighbor\n")
10162
10163DEFUN (show_bgp_view_neighbor_received_routes,
10164 show_bgp_view_neighbor_received_routes_cmd,
10165 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10166 SHOW_STR
10167 BGP_STR
10168 "BGP view\n"
10169 "View name\n"
10170 "Detailed information on TCP and BGP neighbor connections\n"
10171 "Neighbor to display information about\n"
10172 "Neighbor to display information about\n"
10173 "Display the received routes from neighbor\n")
10174{
10175 struct peer *peer;
10176
10177 if (argc == 2)
10178 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10179 else
10180 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10181
10182 if (! peer)
10183 return CMD_WARNING;
10184
10185 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10186}
10187
10188ALIAS (show_bgp_view_neighbor_received_routes,
10189 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10190 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10191 SHOW_STR
10192 BGP_STR
10193 "BGP view\n"
10194 "View name\n"
10195 "Address family\n"
10196 "Detailed information on TCP and BGP neighbor connections\n"
10197 "Neighbor to display information about\n"
10198 "Neighbor to display information about\n"
10199 "Display the received routes from neighbor\n")
10200
10201ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010202 show_bgp_neighbor_advertised_route_cmd,
10203 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10204 SHOW_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
10211ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010212 show_bgp_ipv6_neighbor_advertised_route_cmd,
10213 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10214 SHOW_STR
10215 BGP_STR
10216 "Address family\n"
10217 "Detailed information on TCP and BGP neighbor connections\n"
10218 "Neighbor to display information about\n"
10219 "Neighbor to display information about\n"
10220 "Display the routes advertised to a BGP neighbor\n")
10221
10222/* old command */
paulbb46e942003-10-24 19:02:03 +000010223ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010224 ipv6_bgp_neighbor_advertised_route_cmd,
10225 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10226 SHOW_STR
10227 IPV6_STR
10228 BGP_STR
10229 "Detailed information on TCP and BGP neighbor connections\n"
10230 "Neighbor to display information about\n"
10231 "Neighbor to display information about\n"
10232 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010233
paul718e3742002-12-13 20:15:29 +000010234/* old command */
10235DEFUN (ipv6_mbgp_neighbor_advertised_route,
10236 ipv6_mbgp_neighbor_advertised_route_cmd,
10237 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10238 SHOW_STR
10239 IPV6_STR
10240 MBGP_STR
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 routes advertised to a BGP neighbor\n")
10245{
paulbb46e942003-10-24 19:02:03 +000010246 struct peer *peer;
10247
10248 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10249 if (! peer)
10250 return CMD_WARNING;
10251
10252 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010253}
10254#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010255
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010256DEFUN (show_ip_bgp_view_neighbor_received_routes,
10257 show_ip_bgp_view_neighbor_received_routes_cmd,
10258 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10259 SHOW_STR
10260 IP_STR
10261 BGP_STR
10262 "BGP view\n"
10263 "View name\n"
10264 "Detailed information on TCP and BGP neighbor connections\n"
10265 "Neighbor to display information about\n"
10266 "Neighbor to display information about\n"
10267 "Display the received routes from neighbor\n")
10268{
10269 struct peer *peer;
10270
10271 if (argc == 2)
10272 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10273 else
10274 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10275
10276 if (! peer)
10277 return CMD_WARNING;
10278
10279 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10280}
10281
10282ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010283 show_ip_bgp_neighbor_received_routes_cmd,
10284 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10285 SHOW_STR
10286 IP_STR
10287 BGP_STR
10288 "Detailed information on TCP and BGP neighbor connections\n"
10289 "Neighbor to display information about\n"
10290 "Neighbor to display information about\n"
10291 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010292
10293DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10294 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10295 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10296 SHOW_STR
10297 IP_STR
10298 BGP_STR
10299 "Address family\n"
10300 "Address Family modifier\n"
10301 "Address Family modifier\n"
10302 "Detailed information on TCP and BGP neighbor connections\n"
10303 "Neighbor to display information about\n"
10304 "Neighbor to display information about\n"
10305 "Display the received routes from neighbor\n")
10306{
paulbb46e942003-10-24 19:02:03 +000010307 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010308
paulbb46e942003-10-24 19:02:03 +000010309 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10310 if (! peer)
10311 return CMD_WARNING;
10312
10313 if (strncmp (argv[0], "m", 1) == 0)
10314 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10315
10316 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010317}
10318
Michael Lambert95cbbd22010-07-23 14:43:04 -040010319DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10320 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010321 "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 -040010322 SHOW_STR
10323 BGP_STR
10324 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010325 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010326 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010327 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010328 "Address family modifier\n"
10329 "Address family modifier\n"
10330 "Detailed information on TCP and BGP neighbor connections\n"
10331 "Neighbor to display information about\n"
10332 "Neighbor to display information about\n"
10333 "Display the advertised routes to neighbor\n"
10334 "Display the received routes from neighbor\n")
10335{
10336 int afi;
10337 int safi;
10338 int in;
10339 struct peer *peer;
10340
David Lamparter94bad672015-03-03 08:52:22 +010010341 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010342
10343 if (! peer)
10344 return CMD_WARNING;
10345
Michael Lambert95cbbd22010-07-23 14:43:04 -040010346 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10347 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10348 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010349
10350 return peer_adj_routes (vty, peer, afi, safi, in);
10351}
10352
paul718e3742002-12-13 20:15:29 +000010353DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10354 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10355 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10356 SHOW_STR
10357 IP_STR
10358 BGP_STR
10359 "Detailed information on TCP and BGP neighbor connections\n"
10360 "Neighbor to display information about\n"
10361 "Neighbor to display information about\n"
10362 "Display information received from a BGP neighbor\n"
10363 "Display the prefixlist filter\n")
10364{
10365 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010366 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010367 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010368 int count, ret;
paul718e3742002-12-13 20:15:29 +000010369
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010370 ret = str2sockunion (argv[0], &su);
10371 if (ret < 0)
10372 {
10373 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10374 return CMD_WARNING;
10375 }
paul718e3742002-12-13 20:15:29 +000010376
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010377 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010378 if (! peer)
10379 return CMD_WARNING;
10380
10381 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10382 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10383 if (count)
10384 {
10385 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10386 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10387 }
10388
10389 return CMD_SUCCESS;
10390}
10391
10392DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10393 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10394 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10395 SHOW_STR
10396 IP_STR
10397 BGP_STR
10398 "Address family\n"
10399 "Address Family modifier\n"
10400 "Address Family modifier\n"
10401 "Detailed information on TCP and BGP neighbor connections\n"
10402 "Neighbor to display information about\n"
10403 "Neighbor to display information about\n"
10404 "Display information received from a BGP neighbor\n"
10405 "Display the prefixlist filter\n")
10406{
10407 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010408 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010409 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010410 int count, ret;
paul718e3742002-12-13 20:15:29 +000010411
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010412 ret = str2sockunion (argv[1], &su);
10413 if (ret < 0)
10414 {
10415 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10416 return CMD_WARNING;
10417 }
paul718e3742002-12-13 20:15:29 +000010418
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010419 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010420 if (! peer)
10421 return CMD_WARNING;
10422
10423 if (strncmp (argv[0], "m", 1) == 0)
10424 {
10425 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10426 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10427 if (count)
10428 {
10429 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10430 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10431 }
10432 }
10433 else
10434 {
10435 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10436 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10437 if (count)
10438 {
10439 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10440 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10441 }
10442 }
10443
10444 return CMD_SUCCESS;
10445}
10446
10447
10448#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010449ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010450 show_bgp_neighbor_received_routes_cmd,
10451 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10452 SHOW_STR
10453 BGP_STR
10454 "Detailed information on TCP and BGP neighbor connections\n"
10455 "Neighbor to display information about\n"
10456 "Neighbor to display information about\n"
10457 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010458
paulbb46e942003-10-24 19:02:03 +000010459ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010460 show_bgp_ipv6_neighbor_received_routes_cmd,
10461 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10462 SHOW_STR
10463 BGP_STR
10464 "Address family\n"
10465 "Detailed information on TCP and BGP neighbor connections\n"
10466 "Neighbor to display information about\n"
10467 "Neighbor to display information about\n"
10468 "Display the received routes from neighbor\n")
10469
10470DEFUN (show_bgp_neighbor_received_prefix_filter,
10471 show_bgp_neighbor_received_prefix_filter_cmd,
10472 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10473 SHOW_STR
10474 BGP_STR
10475 "Detailed information on TCP and BGP neighbor connections\n"
10476 "Neighbor to display information about\n"
10477 "Neighbor to display information about\n"
10478 "Display information received from a BGP neighbor\n"
10479 "Display the prefixlist filter\n")
10480{
10481 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010482 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010483 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010484 int count, ret;
paul718e3742002-12-13 20:15:29 +000010485
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010486 ret = str2sockunion (argv[0], &su);
10487 if (ret < 0)
10488 {
10489 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10490 return CMD_WARNING;
10491 }
paul718e3742002-12-13 20:15:29 +000010492
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010493 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010494 if (! peer)
10495 return CMD_WARNING;
10496
10497 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10498 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10499 if (count)
10500 {
10501 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10502 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10503 }
10504
10505 return CMD_SUCCESS;
10506}
10507
10508ALIAS (show_bgp_neighbor_received_prefix_filter,
10509 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10510 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10511 SHOW_STR
10512 BGP_STR
10513 "Address family\n"
10514 "Detailed information on TCP and BGP neighbor connections\n"
10515 "Neighbor to display information about\n"
10516 "Neighbor to display information about\n"
10517 "Display information received from a BGP neighbor\n"
10518 "Display the prefixlist filter\n")
10519
10520/* old command */
paulbb46e942003-10-24 19:02:03 +000010521ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010522 ipv6_bgp_neighbor_received_routes_cmd,
10523 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10524 SHOW_STR
10525 IPV6_STR
10526 BGP_STR
10527 "Detailed information on TCP and BGP neighbor connections\n"
10528 "Neighbor to display information about\n"
10529 "Neighbor to display information about\n"
10530 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010531
10532/* old command */
10533DEFUN (ipv6_mbgp_neighbor_received_routes,
10534 ipv6_mbgp_neighbor_received_routes_cmd,
10535 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10536 SHOW_STR
10537 IPV6_STR
10538 MBGP_STR
10539 "Detailed information on TCP and BGP neighbor connections\n"
10540 "Neighbor to display information about\n"
10541 "Neighbor to display information about\n"
10542 "Display the received routes from neighbor\n")
10543{
paulbb46e942003-10-24 19:02:03 +000010544 struct peer *peer;
10545
10546 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10547 if (! peer)
10548 return CMD_WARNING;
10549
10550 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010551}
paulbb46e942003-10-24 19:02:03 +000010552
10553DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10554 show_bgp_view_neighbor_received_prefix_filter_cmd,
10555 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10556 SHOW_STR
10557 BGP_STR
10558 "BGP view\n"
10559 "View name\n"
10560 "Detailed information on TCP and BGP neighbor connections\n"
10561 "Neighbor to display information about\n"
10562 "Neighbor to display information about\n"
10563 "Display information received from a BGP neighbor\n"
10564 "Display the prefixlist filter\n")
10565{
10566 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010567 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010568 struct peer *peer;
10569 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010570 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010571
10572 /* BGP structure lookup. */
10573 bgp = bgp_lookup_by_name (argv[0]);
10574 if (bgp == NULL)
10575 {
10576 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10577 return CMD_WARNING;
10578 }
10579
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010580 ret = str2sockunion (argv[1], &su);
10581 if (ret < 0)
10582 {
10583 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10584 return CMD_WARNING;
10585 }
paulbb46e942003-10-24 19:02:03 +000010586
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010587 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010588 if (! peer)
10589 return CMD_WARNING;
10590
10591 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10592 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10593 if (count)
10594 {
10595 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10596 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10597 }
10598
10599 return CMD_SUCCESS;
10600}
10601
10602ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10603 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10604 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10605 SHOW_STR
10606 BGP_STR
10607 "BGP view\n"
10608 "View name\n"
10609 "Address family\n"
10610 "Detailed information on TCP and BGP neighbor connections\n"
10611 "Neighbor to display information about\n"
10612 "Neighbor to display information about\n"
10613 "Display information received from a BGP neighbor\n"
10614 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010615#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010616
paul94f2b392005-06-28 12:44:16 +000010617static int
paulbb46e942003-10-24 19:02:03 +000010618bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010619 safi_t safi, enum bgp_show_type type)
10620{
paul718e3742002-12-13 20:15:29 +000010621 if (! peer || ! peer->afc[afi][safi])
10622 {
10623 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010624 return CMD_WARNING;
10625 }
10626
ajs5a646652004-11-05 01:25:55 +000010627 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010628}
10629
10630DEFUN (show_ip_bgp_neighbor_routes,
10631 show_ip_bgp_neighbor_routes_cmd,
10632 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10633 SHOW_STR
10634 IP_STR
10635 BGP_STR
10636 "Detailed information on TCP and BGP neighbor connections\n"
10637 "Neighbor to display information about\n"
10638 "Neighbor to display information about\n"
10639 "Display routes learned from neighbor\n")
10640{
paulbb46e942003-10-24 19:02:03 +000010641 struct peer *peer;
10642
10643 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10644 if (! peer)
10645 return CMD_WARNING;
10646
10647 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010648 bgp_show_type_neighbor);
10649}
10650
10651DEFUN (show_ip_bgp_neighbor_flap,
10652 show_ip_bgp_neighbor_flap_cmd,
10653 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10654 SHOW_STR
10655 IP_STR
10656 BGP_STR
10657 "Detailed information on TCP and BGP neighbor connections\n"
10658 "Neighbor to display information about\n"
10659 "Neighbor to display information about\n"
10660 "Display flap statistics of the routes learned from neighbor\n")
10661{
paulbb46e942003-10-24 19:02:03 +000010662 struct peer *peer;
10663
10664 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10665 if (! peer)
10666 return CMD_WARNING;
10667
10668 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010669 bgp_show_type_flap_neighbor);
10670}
10671
10672DEFUN (show_ip_bgp_neighbor_damp,
10673 show_ip_bgp_neighbor_damp_cmd,
10674 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10675 SHOW_STR
10676 IP_STR
10677 BGP_STR
10678 "Detailed information on TCP and BGP neighbor connections\n"
10679 "Neighbor to display information about\n"
10680 "Neighbor to display information about\n"
10681 "Display the dampened routes received from neighbor\n")
10682{
paulbb46e942003-10-24 19:02:03 +000010683 struct peer *peer;
10684
10685 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10686 if (! peer)
10687 return CMD_WARNING;
10688
10689 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010690 bgp_show_type_damp_neighbor);
10691}
10692
10693DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10694 show_ip_bgp_ipv4_neighbor_routes_cmd,
10695 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10696 SHOW_STR
10697 IP_STR
10698 BGP_STR
10699 "Address family\n"
10700 "Address Family modifier\n"
10701 "Address Family modifier\n"
10702 "Detailed information on TCP and BGP neighbor connections\n"
10703 "Neighbor to display information about\n"
10704 "Neighbor to display information about\n"
10705 "Display routes learned from neighbor\n")
10706{
paulbb46e942003-10-24 19:02:03 +000010707 struct peer *peer;
10708
10709 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10710 if (! peer)
10711 return CMD_WARNING;
10712
paul718e3742002-12-13 20:15:29 +000010713 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010714 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010715 bgp_show_type_neighbor);
10716
paulbb46e942003-10-24 19:02:03 +000010717 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010718 bgp_show_type_neighbor);
10719}
paulbb46e942003-10-24 19:02:03 +000010720
paulfee0f4c2004-09-13 05:12:46 +000010721DEFUN (show_ip_bgp_view_rsclient,
10722 show_ip_bgp_view_rsclient_cmd,
10723 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10724 SHOW_STR
10725 IP_STR
10726 BGP_STR
10727 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010728 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010729 "Information about Route Server Client\n"
10730 NEIGHBOR_ADDR_STR)
10731{
10732 struct bgp_table *table;
10733 struct peer *peer;
10734
10735 if (argc == 2)
10736 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10737 else
10738 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10739
10740 if (! peer)
10741 return CMD_WARNING;
10742
10743 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10744 {
10745 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10746 VTY_NEWLINE);
10747 return CMD_WARNING;
10748 }
10749
10750 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10751 PEER_FLAG_RSERVER_CLIENT))
10752 {
10753 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10754 VTY_NEWLINE);
10755 return CMD_WARNING;
10756 }
10757
10758 table = peer->rib[AFI_IP][SAFI_UNICAST];
10759
ajs5a646652004-11-05 01:25:55 +000010760 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010761}
10762
10763ALIAS (show_ip_bgp_view_rsclient,
10764 show_ip_bgp_rsclient_cmd,
10765 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10766 SHOW_STR
10767 IP_STR
10768 BGP_STR
10769 "Information about Route Server Client\n"
10770 NEIGHBOR_ADDR_STR)
10771
Michael Lambert95cbbd22010-07-23 14:43:04 -040010772DEFUN (show_bgp_view_ipv4_safi_rsclient,
10773 show_bgp_view_ipv4_safi_rsclient_cmd,
10774 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10775 SHOW_STR
10776 BGP_STR
10777 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010778 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010779 "Address family\n"
10780 "Address Family modifier\n"
10781 "Address Family modifier\n"
10782 "Information about Route Server Client\n"
10783 NEIGHBOR_ADDR_STR)
10784{
10785 struct bgp_table *table;
10786 struct peer *peer;
10787 safi_t safi;
10788
10789 if (argc == 3) {
10790 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10791 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10792 } else {
10793 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10794 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10795 }
10796
10797 if (! peer)
10798 return CMD_WARNING;
10799
10800 if (! peer->afc[AFI_IP][safi])
10801 {
10802 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10803 VTY_NEWLINE);
10804 return CMD_WARNING;
10805 }
10806
10807 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10808 PEER_FLAG_RSERVER_CLIENT))
10809 {
10810 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10811 VTY_NEWLINE);
10812 return CMD_WARNING;
10813 }
10814
10815 table = peer->rib[AFI_IP][safi];
10816
10817 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10818}
10819
10820ALIAS (show_bgp_view_ipv4_safi_rsclient,
10821 show_bgp_ipv4_safi_rsclient_cmd,
10822 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10823 SHOW_STR
10824 BGP_STR
10825 "Address family\n"
10826 "Address Family modifier\n"
10827 "Address Family modifier\n"
10828 "Information about Route Server Client\n"
10829 NEIGHBOR_ADDR_STR)
10830
paulfee0f4c2004-09-13 05:12:46 +000010831DEFUN (show_ip_bgp_view_rsclient_route,
10832 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010833 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010834 SHOW_STR
10835 IP_STR
10836 BGP_STR
10837 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010838 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010839 "Information about Route Server Client\n"
10840 NEIGHBOR_ADDR_STR
10841 "Network in the BGP routing table to display\n")
10842{
10843 struct bgp *bgp;
10844 struct peer *peer;
10845
10846 /* BGP structure lookup. */
10847 if (argc == 3)
10848 {
10849 bgp = bgp_lookup_by_name (argv[0]);
10850 if (bgp == NULL)
10851 {
10852 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10853 return CMD_WARNING;
10854 }
10855 }
10856 else
10857 {
10858 bgp = bgp_get_default ();
10859 if (bgp == NULL)
10860 {
10861 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10862 return CMD_WARNING;
10863 }
10864 }
10865
10866 if (argc == 3)
10867 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10868 else
10869 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10870
10871 if (! peer)
10872 return CMD_WARNING;
10873
10874 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10875 {
10876 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10877 VTY_NEWLINE);
10878 return CMD_WARNING;
10879}
10880
10881 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10882 PEER_FLAG_RSERVER_CLIENT))
10883 {
10884 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10885 VTY_NEWLINE);
10886 return CMD_WARNING;
10887 }
10888
10889 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10890 (argc == 3) ? argv[2] : argv[1],
10891 AFI_IP, SAFI_UNICAST, NULL, 0);
10892}
10893
10894ALIAS (show_ip_bgp_view_rsclient_route,
10895 show_ip_bgp_rsclient_route_cmd,
10896 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10897 SHOW_STR
10898 IP_STR
10899 BGP_STR
10900 "Information about Route Server Client\n"
10901 NEIGHBOR_ADDR_STR
10902 "Network in the BGP routing table to display\n")
10903
Michael Lambert95cbbd22010-07-23 14:43:04 -040010904DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10905 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10906 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10907 SHOW_STR
10908 BGP_STR
10909 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010910 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010911 "Address family\n"
10912 "Address Family modifier\n"
10913 "Address Family modifier\n"
10914 "Information about Route Server Client\n"
10915 NEIGHBOR_ADDR_STR
10916 "Network in the BGP routing table to display\n")
10917{
10918 struct bgp *bgp;
10919 struct peer *peer;
10920 safi_t safi;
10921
10922 /* BGP structure lookup. */
10923 if (argc == 4)
10924 {
10925 bgp = bgp_lookup_by_name (argv[0]);
10926 if (bgp == NULL)
10927 {
10928 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10929 return CMD_WARNING;
10930 }
10931 }
10932 else
10933 {
10934 bgp = bgp_get_default ();
10935 if (bgp == NULL)
10936 {
10937 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10938 return CMD_WARNING;
10939 }
10940 }
10941
10942 if (argc == 4) {
10943 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10944 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10945 } else {
10946 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10947 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10948 }
10949
10950 if (! peer)
10951 return CMD_WARNING;
10952
10953 if (! peer->afc[AFI_IP][safi])
10954 {
10955 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10956 VTY_NEWLINE);
10957 return CMD_WARNING;
10958}
10959
10960 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10961 PEER_FLAG_RSERVER_CLIENT))
10962 {
10963 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10964 VTY_NEWLINE);
10965 return CMD_WARNING;
10966 }
10967
10968 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10969 (argc == 4) ? argv[3] : argv[2],
10970 AFI_IP, safi, NULL, 0);
10971}
10972
10973ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10974 show_bgp_ipv4_safi_rsclient_route_cmd,
10975 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10976 SHOW_STR
10977 BGP_STR
10978 "Address family\n"
10979 "Address Family modifier\n"
10980 "Address Family modifier\n"
10981 "Information about Route Server Client\n"
10982 NEIGHBOR_ADDR_STR
10983 "Network in the BGP routing table to display\n")
10984
paulfee0f4c2004-09-13 05:12:46 +000010985DEFUN (show_ip_bgp_view_rsclient_prefix,
10986 show_ip_bgp_view_rsclient_prefix_cmd,
10987 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10988 SHOW_STR
10989 IP_STR
10990 BGP_STR
10991 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010992 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010993 "Information about Route Server Client\n"
10994 NEIGHBOR_ADDR_STR
10995 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10996{
10997 struct bgp *bgp;
10998 struct peer *peer;
10999
11000 /* BGP structure lookup. */
11001 if (argc == 3)
11002 {
11003 bgp = bgp_lookup_by_name (argv[0]);
11004 if (bgp == NULL)
11005 {
11006 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11007 return CMD_WARNING;
11008 }
11009 }
11010 else
11011 {
11012 bgp = bgp_get_default ();
11013 if (bgp == NULL)
11014 {
11015 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11016 return CMD_WARNING;
11017 }
11018 }
11019
11020 if (argc == 3)
11021 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11022 else
11023 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11024
11025 if (! peer)
11026 return CMD_WARNING;
11027
11028 if (! peer->afc[AFI_IP][SAFI_UNICAST])
11029 {
11030 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11031 VTY_NEWLINE);
11032 return CMD_WARNING;
11033}
11034
11035 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
11036 PEER_FLAG_RSERVER_CLIENT))
11037{
11038 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11039 VTY_NEWLINE);
11040 return CMD_WARNING;
11041 }
11042
11043 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
11044 (argc == 3) ? argv[2] : argv[1],
11045 AFI_IP, SAFI_UNICAST, NULL, 1);
11046}
11047
11048ALIAS (show_ip_bgp_view_rsclient_prefix,
11049 show_ip_bgp_rsclient_prefix_cmd,
11050 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11051 SHOW_STR
11052 IP_STR
11053 BGP_STR
11054 "Information about Route Server Client\n"
11055 NEIGHBOR_ADDR_STR
11056 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11057
Michael Lambert95cbbd22010-07-23 14:43:04 -040011058DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
11059 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
11060 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11061 SHOW_STR
11062 BGP_STR
11063 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011064 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011065 "Address family\n"
11066 "Address Family modifier\n"
11067 "Address Family modifier\n"
11068 "Information about Route Server Client\n"
11069 NEIGHBOR_ADDR_STR
11070 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11071{
11072 struct bgp *bgp;
11073 struct peer *peer;
11074 safi_t safi;
11075
11076 /* BGP structure lookup. */
11077 if (argc == 4)
11078 {
11079 bgp = bgp_lookup_by_name (argv[0]);
11080 if (bgp == NULL)
11081 {
11082 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11083 return CMD_WARNING;
11084 }
11085 }
11086 else
11087 {
11088 bgp = bgp_get_default ();
11089 if (bgp == NULL)
11090 {
11091 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11092 return CMD_WARNING;
11093 }
11094 }
11095
11096 if (argc == 4) {
11097 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11098 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11099 } else {
11100 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11101 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11102 }
11103
11104 if (! peer)
11105 return CMD_WARNING;
11106
11107 if (! peer->afc[AFI_IP][safi])
11108 {
11109 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11110 VTY_NEWLINE);
11111 return CMD_WARNING;
11112}
11113
11114 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11115 PEER_FLAG_RSERVER_CLIENT))
11116{
11117 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11118 VTY_NEWLINE);
11119 return CMD_WARNING;
11120 }
11121
11122 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11123 (argc == 4) ? argv[3] : argv[2],
11124 AFI_IP, safi, NULL, 1);
11125}
11126
11127ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11128 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11129 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11130 SHOW_STR
11131 BGP_STR
11132 "Address family\n"
11133 "Address Family modifier\n"
11134 "Address Family modifier\n"
11135 "Information about Route Server Client\n"
11136 NEIGHBOR_ADDR_STR
11137 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011138
paul718e3742002-12-13 20:15:29 +000011139#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011140DEFUN (show_bgp_view_neighbor_routes,
11141 show_bgp_view_neighbor_routes_cmd,
11142 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11143 SHOW_STR
11144 BGP_STR
11145 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011146 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011147 "Detailed information on TCP and BGP neighbor connections\n"
11148 "Neighbor to display information about\n"
11149 "Neighbor to display information about\n"
11150 "Display routes learned from neighbor\n")
11151{
11152 struct peer *peer;
11153
11154 if (argc == 2)
11155 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11156 else
11157 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11158
11159 if (! peer)
11160 return CMD_WARNING;
11161
11162 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11163 bgp_show_type_neighbor);
11164}
11165
11166ALIAS (show_bgp_view_neighbor_routes,
11167 show_bgp_view_ipv6_neighbor_routes_cmd,
11168 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11169 SHOW_STR
11170 BGP_STR
11171 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011172 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011173 "Address family\n"
11174 "Detailed information on TCP and BGP neighbor connections\n"
11175 "Neighbor to display information about\n"
11176 "Neighbor to display information about\n"
11177 "Display routes learned from neighbor\n")
11178
11179DEFUN (show_bgp_view_neighbor_damp,
11180 show_bgp_view_neighbor_damp_cmd,
11181 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11182 SHOW_STR
11183 BGP_STR
11184 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011185 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011186 "Detailed information on TCP and BGP neighbor connections\n"
11187 "Neighbor to display information about\n"
11188 "Neighbor to display information about\n"
11189 "Display the dampened routes received from neighbor\n")
11190{
11191 struct peer *peer;
11192
11193 if (argc == 2)
11194 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11195 else
11196 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11197
11198 if (! peer)
11199 return CMD_WARNING;
11200
11201 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11202 bgp_show_type_damp_neighbor);
11203}
11204
11205ALIAS (show_bgp_view_neighbor_damp,
11206 show_bgp_view_ipv6_neighbor_damp_cmd,
11207 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11208 SHOW_STR
11209 BGP_STR
11210 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011211 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011212 "Address family\n"
11213 "Detailed information on TCP and BGP neighbor connections\n"
11214 "Neighbor to display information about\n"
11215 "Neighbor to display information about\n"
11216 "Display the dampened routes received from neighbor\n")
11217
11218DEFUN (show_bgp_view_neighbor_flap,
11219 show_bgp_view_neighbor_flap_cmd,
11220 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11221 SHOW_STR
11222 BGP_STR
11223 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011224 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011225 "Detailed information on TCP and BGP neighbor connections\n"
11226 "Neighbor to display information about\n"
11227 "Neighbor to display information about\n"
11228 "Display flap statistics of the routes learned from neighbor\n")
11229{
11230 struct peer *peer;
11231
11232 if (argc == 2)
11233 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11234 else
11235 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11236
11237 if (! peer)
11238 return CMD_WARNING;
11239
11240 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11241 bgp_show_type_flap_neighbor);
11242}
11243
11244ALIAS (show_bgp_view_neighbor_flap,
11245 show_bgp_view_ipv6_neighbor_flap_cmd,
11246 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11247 SHOW_STR
11248 BGP_STR
11249 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011250 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011251 "Address family\n"
11252 "Detailed information on TCP and BGP neighbor connections\n"
11253 "Neighbor to display information about\n"
11254 "Neighbor to display information about\n"
11255 "Display flap statistics of the routes learned from neighbor\n")
11256
11257ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011258 show_bgp_neighbor_routes_cmd,
11259 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11260 SHOW_STR
11261 BGP_STR
11262 "Detailed information on TCP and BGP neighbor connections\n"
11263 "Neighbor to display information about\n"
11264 "Neighbor to display information about\n"
11265 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011266
paulbb46e942003-10-24 19:02:03 +000011267
11268ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011269 show_bgp_ipv6_neighbor_routes_cmd,
11270 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11271 SHOW_STR
11272 BGP_STR
11273 "Address family\n"
11274 "Detailed information on TCP and BGP neighbor connections\n"
11275 "Neighbor to display information about\n"
11276 "Neighbor to display information about\n"
11277 "Display routes learned from neighbor\n")
11278
11279/* old command */
paulbb46e942003-10-24 19:02:03 +000011280ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011281 ipv6_bgp_neighbor_routes_cmd,
11282 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11283 SHOW_STR
11284 IPV6_STR
11285 BGP_STR
11286 "Detailed information on TCP and BGP neighbor connections\n"
11287 "Neighbor to display information about\n"
11288 "Neighbor to display information about\n"
11289 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011290
11291/* old command */
11292DEFUN (ipv6_mbgp_neighbor_routes,
11293 ipv6_mbgp_neighbor_routes_cmd,
11294 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11295 SHOW_STR
11296 IPV6_STR
11297 MBGP_STR
11298 "Detailed information on TCP and BGP neighbor connections\n"
11299 "Neighbor to display information about\n"
11300 "Neighbor to display information about\n"
11301 "Display routes learned from neighbor\n")
11302{
paulbb46e942003-10-24 19:02:03 +000011303 struct peer *peer;
11304
11305 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11306 if (! peer)
11307 return CMD_WARNING;
11308
11309 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011310 bgp_show_type_neighbor);
11311}
paulbb46e942003-10-24 19:02:03 +000011312
11313ALIAS (show_bgp_view_neighbor_flap,
11314 show_bgp_neighbor_flap_cmd,
11315 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11316 SHOW_STR
11317 BGP_STR
11318 "Detailed information on TCP and BGP neighbor connections\n"
11319 "Neighbor to display information about\n"
11320 "Neighbor to display information about\n"
11321 "Display flap statistics of the routes learned from neighbor\n")
11322
11323ALIAS (show_bgp_view_neighbor_flap,
11324 show_bgp_ipv6_neighbor_flap_cmd,
11325 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11326 SHOW_STR
11327 BGP_STR
11328 "Address family\n"
11329 "Detailed information on TCP and BGP neighbor connections\n"
11330 "Neighbor to display information about\n"
11331 "Neighbor to display information about\n"
11332 "Display flap statistics of the routes learned from neighbor\n")
11333
11334ALIAS (show_bgp_view_neighbor_damp,
11335 show_bgp_neighbor_damp_cmd,
11336 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11337 SHOW_STR
11338 BGP_STR
11339 "Detailed information on TCP and BGP neighbor connections\n"
11340 "Neighbor to display information about\n"
11341 "Neighbor to display information about\n"
11342 "Display the dampened routes received from neighbor\n")
11343
11344ALIAS (show_bgp_view_neighbor_damp,
11345 show_bgp_ipv6_neighbor_damp_cmd,
11346 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11347 SHOW_STR
11348 BGP_STR
11349 "Address family\n"
11350 "Detailed information on TCP and BGP neighbor connections\n"
11351 "Neighbor to display information about\n"
11352 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011353 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011354
11355DEFUN (show_bgp_view_rsclient,
11356 show_bgp_view_rsclient_cmd,
11357 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11358 SHOW_STR
11359 BGP_STR
11360 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011361 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011362 "Information about Route Server Client\n"
11363 NEIGHBOR_ADDR_STR)
11364{
11365 struct bgp_table *table;
11366 struct peer *peer;
11367
11368 if (argc == 2)
11369 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11370 else
11371 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11372
11373 if (! peer)
11374 return CMD_WARNING;
11375
11376 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11377 {
11378 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11379 VTY_NEWLINE);
11380 return CMD_WARNING;
11381 }
11382
11383 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11384 PEER_FLAG_RSERVER_CLIENT))
11385 {
11386 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11387 VTY_NEWLINE);
11388 return CMD_WARNING;
11389 }
11390
11391 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11392
ajs5a646652004-11-05 01:25:55 +000011393 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011394}
11395
11396ALIAS (show_bgp_view_rsclient,
11397 show_bgp_rsclient_cmd,
11398 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11399 SHOW_STR
11400 BGP_STR
11401 "Information about Route Server Client\n"
11402 NEIGHBOR_ADDR_STR)
11403
Michael Lambert95cbbd22010-07-23 14:43:04 -040011404DEFUN (show_bgp_view_ipv6_safi_rsclient,
11405 show_bgp_view_ipv6_safi_rsclient_cmd,
11406 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11407 SHOW_STR
11408 BGP_STR
11409 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011410 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011411 "Address family\n"
11412 "Address Family modifier\n"
11413 "Address Family modifier\n"
11414 "Information about Route Server Client\n"
11415 NEIGHBOR_ADDR_STR)
11416{
11417 struct bgp_table *table;
11418 struct peer *peer;
11419 safi_t safi;
11420
11421 if (argc == 3) {
11422 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11423 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11424 } else {
11425 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11426 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11427 }
11428
11429 if (! peer)
11430 return CMD_WARNING;
11431
11432 if (! peer->afc[AFI_IP6][safi])
11433 {
11434 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11435 VTY_NEWLINE);
11436 return CMD_WARNING;
11437 }
11438
11439 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11440 PEER_FLAG_RSERVER_CLIENT))
11441 {
11442 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11443 VTY_NEWLINE);
11444 return CMD_WARNING;
11445 }
11446
11447 table = peer->rib[AFI_IP6][safi];
11448
11449 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11450}
11451
11452ALIAS (show_bgp_view_ipv6_safi_rsclient,
11453 show_bgp_ipv6_safi_rsclient_cmd,
11454 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11455 SHOW_STR
11456 BGP_STR
11457 "Address family\n"
11458 "Address Family modifier\n"
11459 "Address Family modifier\n"
11460 "Information about Route Server Client\n"
11461 NEIGHBOR_ADDR_STR)
11462
paulfee0f4c2004-09-13 05:12:46 +000011463DEFUN (show_bgp_view_rsclient_route,
11464 show_bgp_view_rsclient_route_cmd,
11465 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11466 SHOW_STR
11467 BGP_STR
11468 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011469 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011470 "Information about Route Server Client\n"
11471 NEIGHBOR_ADDR_STR
11472 "Network in the BGP routing table to display\n")
11473{
11474 struct bgp *bgp;
11475 struct peer *peer;
11476
11477 /* BGP structure lookup. */
11478 if (argc == 3)
11479 {
11480 bgp = bgp_lookup_by_name (argv[0]);
11481 if (bgp == NULL)
11482 {
11483 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11484 return CMD_WARNING;
11485 }
11486 }
11487 else
11488 {
11489 bgp = bgp_get_default ();
11490 if (bgp == NULL)
11491 {
11492 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11493 return CMD_WARNING;
11494 }
11495 }
11496
11497 if (argc == 3)
11498 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11499 else
11500 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11501
11502 if (! peer)
11503 return CMD_WARNING;
11504
11505 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11506 {
11507 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11508 VTY_NEWLINE);
11509 return CMD_WARNING;
11510 }
11511
11512 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11513 PEER_FLAG_RSERVER_CLIENT))
11514 {
11515 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11516 VTY_NEWLINE);
11517 return CMD_WARNING;
11518 }
11519
11520 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11521 (argc == 3) ? argv[2] : argv[1],
11522 AFI_IP6, SAFI_UNICAST, NULL, 0);
11523}
11524
11525ALIAS (show_bgp_view_rsclient_route,
11526 show_bgp_rsclient_route_cmd,
11527 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11528 SHOW_STR
11529 BGP_STR
11530 "Information about Route Server Client\n"
11531 NEIGHBOR_ADDR_STR
11532 "Network in the BGP routing table to display\n")
11533
Michael Lambert95cbbd22010-07-23 14:43:04 -040011534DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11535 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11536 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11537 SHOW_STR
11538 BGP_STR
11539 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011540 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011541 "Address family\n"
11542 "Address Family modifier\n"
11543 "Address Family modifier\n"
11544 "Information about Route Server Client\n"
11545 NEIGHBOR_ADDR_STR
11546 "Network in the BGP routing table to display\n")
11547{
11548 struct bgp *bgp;
11549 struct peer *peer;
11550 safi_t safi;
11551
11552 /* BGP structure lookup. */
11553 if (argc == 4)
11554 {
11555 bgp = bgp_lookup_by_name (argv[0]);
11556 if (bgp == NULL)
11557 {
11558 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11559 return CMD_WARNING;
11560 }
11561 }
11562 else
11563 {
11564 bgp = bgp_get_default ();
11565 if (bgp == NULL)
11566 {
11567 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11568 return CMD_WARNING;
11569 }
11570 }
11571
11572 if (argc == 4) {
11573 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11574 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11575 } else {
11576 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11577 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11578 }
11579
11580 if (! peer)
11581 return CMD_WARNING;
11582
11583 if (! peer->afc[AFI_IP6][safi])
11584 {
11585 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11586 VTY_NEWLINE);
11587 return CMD_WARNING;
11588}
11589
11590 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11591 PEER_FLAG_RSERVER_CLIENT))
11592 {
11593 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11594 VTY_NEWLINE);
11595 return CMD_WARNING;
11596 }
11597
11598 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11599 (argc == 4) ? argv[3] : argv[2],
11600 AFI_IP6, safi, NULL, 0);
11601}
11602
11603ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11604 show_bgp_ipv6_safi_rsclient_route_cmd,
11605 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11606 SHOW_STR
11607 BGP_STR
11608 "Address family\n"
11609 "Address Family modifier\n"
11610 "Address Family modifier\n"
11611 "Information about Route Server Client\n"
11612 NEIGHBOR_ADDR_STR
11613 "Network in the BGP routing table to display\n")
11614
paulfee0f4c2004-09-13 05:12:46 +000011615DEFUN (show_bgp_view_rsclient_prefix,
11616 show_bgp_view_rsclient_prefix_cmd,
11617 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11618 SHOW_STR
11619 BGP_STR
11620 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011621 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011622 "Information about Route Server Client\n"
11623 NEIGHBOR_ADDR_STR
11624 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11625{
11626 struct bgp *bgp;
11627 struct peer *peer;
11628
11629 /* BGP structure lookup. */
11630 if (argc == 3)
11631 {
11632 bgp = bgp_lookup_by_name (argv[0]);
11633 if (bgp == NULL)
11634 {
11635 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11636 return CMD_WARNING;
11637 }
11638 }
11639 else
11640 {
11641 bgp = bgp_get_default ();
11642 if (bgp == NULL)
11643 {
11644 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11645 return CMD_WARNING;
11646 }
11647 }
11648
11649 if (argc == 3)
11650 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11651 else
11652 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11653
11654 if (! peer)
11655 return CMD_WARNING;
11656
11657 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11658 {
11659 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11660 VTY_NEWLINE);
11661 return CMD_WARNING;
11662 }
11663
11664 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11665 PEER_FLAG_RSERVER_CLIENT))
11666 {
11667 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11668 VTY_NEWLINE);
11669 return CMD_WARNING;
11670 }
11671
11672 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11673 (argc == 3) ? argv[2] : argv[1],
11674 AFI_IP6, SAFI_UNICAST, NULL, 1);
11675}
11676
11677ALIAS (show_bgp_view_rsclient_prefix,
11678 show_bgp_rsclient_prefix_cmd,
11679 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11680 SHOW_STR
11681 BGP_STR
11682 "Information about Route Server Client\n"
11683 NEIGHBOR_ADDR_STR
11684 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11685
Michael Lambert95cbbd22010-07-23 14:43:04 -040011686DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11687 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11688 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11689 SHOW_STR
11690 BGP_STR
11691 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011692 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011693 "Address family\n"
11694 "Address Family modifier\n"
11695 "Address Family modifier\n"
11696 "Information about Route Server Client\n"
11697 NEIGHBOR_ADDR_STR
11698 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11699{
11700 struct bgp *bgp;
11701 struct peer *peer;
11702 safi_t safi;
11703
11704 /* BGP structure lookup. */
11705 if (argc == 4)
11706 {
11707 bgp = bgp_lookup_by_name (argv[0]);
11708 if (bgp == NULL)
11709 {
11710 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11711 return CMD_WARNING;
11712 }
11713 }
11714 else
11715 {
11716 bgp = bgp_get_default ();
11717 if (bgp == NULL)
11718 {
11719 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11720 return CMD_WARNING;
11721 }
11722 }
11723
11724 if (argc == 4) {
11725 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11726 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11727 } else {
11728 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11729 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11730 }
11731
11732 if (! peer)
11733 return CMD_WARNING;
11734
11735 if (! peer->afc[AFI_IP6][safi])
11736 {
11737 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11738 VTY_NEWLINE);
11739 return CMD_WARNING;
11740}
11741
11742 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11743 PEER_FLAG_RSERVER_CLIENT))
11744{
11745 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11746 VTY_NEWLINE);
11747 return CMD_WARNING;
11748 }
11749
11750 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11751 (argc == 4) ? argv[3] : argv[2],
11752 AFI_IP6, safi, NULL, 1);
11753}
11754
11755ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11756 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11757 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11758 SHOW_STR
11759 BGP_STR
11760 "Address family\n"
11761 "Address Family modifier\n"
11762 "Address Family modifier\n"
11763 "Information about Route Server Client\n"
11764 NEIGHBOR_ADDR_STR
11765 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11766
paul718e3742002-12-13 20:15:29 +000011767#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020011768
paul718e3742002-12-13 20:15:29 +000011769struct bgp_table *bgp_distance_table;
11770
11771struct bgp_distance
11772{
11773 /* Distance value for the IP source prefix. */
11774 u_char distance;
11775
11776 /* Name of the access-list to be matched. */
11777 char *access_list;
11778};
11779
paul94f2b392005-06-28 12:44:16 +000011780static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011781bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011782{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011783 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011784}
11785
paul94f2b392005-06-28 12:44:16 +000011786static void
paul718e3742002-12-13 20:15:29 +000011787bgp_distance_free (struct bgp_distance *bdistance)
11788{
11789 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11790}
11791
paul94f2b392005-06-28 12:44:16 +000011792static int
paulfd79ac92004-10-13 05:06:08 +000011793bgp_distance_set (struct vty *vty, const char *distance_str,
11794 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011795{
11796 int ret;
11797 struct prefix_ipv4 p;
11798 u_char distance;
11799 struct bgp_node *rn;
11800 struct bgp_distance *bdistance;
11801
11802 ret = str2prefix_ipv4 (ip_str, &p);
11803 if (ret == 0)
11804 {
11805 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11806 return CMD_WARNING;
11807 }
11808
11809 distance = atoi (distance_str);
11810
11811 /* Get BGP distance node. */
11812 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11813 if (rn->info)
11814 {
11815 bdistance = rn->info;
11816 bgp_unlock_node (rn);
11817 }
11818 else
11819 {
11820 bdistance = bgp_distance_new ();
11821 rn->info = bdistance;
11822 }
11823
11824 /* Set distance value. */
11825 bdistance->distance = distance;
11826
11827 /* Reset access-list configuration. */
11828 if (bdistance->access_list)
11829 {
11830 free (bdistance->access_list);
11831 bdistance->access_list = NULL;
11832 }
11833 if (access_list_str)
11834 bdistance->access_list = strdup (access_list_str);
11835
11836 return CMD_SUCCESS;
11837}
11838
paul94f2b392005-06-28 12:44:16 +000011839static int
paulfd79ac92004-10-13 05:06:08 +000011840bgp_distance_unset (struct vty *vty, const char *distance_str,
11841 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011842{
11843 int ret;
11844 struct prefix_ipv4 p;
11845 u_char distance;
11846 struct bgp_node *rn;
11847 struct bgp_distance *bdistance;
11848
11849 ret = str2prefix_ipv4 (ip_str, &p);
11850 if (ret == 0)
11851 {
11852 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11853 return CMD_WARNING;
11854 }
11855
11856 distance = atoi (distance_str);
11857
11858 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11859 if (! rn)
11860 {
11861 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11862 return CMD_WARNING;
11863 }
11864
11865 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010011866
11867 if (bdistance->distance != distance)
11868 {
11869 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
11870 return CMD_WARNING;
11871 }
11872
paul718e3742002-12-13 20:15:29 +000011873 if (bdistance->access_list)
11874 free (bdistance->access_list);
11875 bgp_distance_free (bdistance);
11876
11877 rn->info = NULL;
11878 bgp_unlock_node (rn);
11879 bgp_unlock_node (rn);
11880
11881 return CMD_SUCCESS;
11882}
11883
paul718e3742002-12-13 20:15:29 +000011884/* Apply BGP information to distance method. */
11885u_char
11886bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11887{
11888 struct bgp_node *rn;
11889 struct prefix_ipv4 q;
11890 struct peer *peer;
11891 struct bgp_distance *bdistance;
11892 struct access_list *alist;
11893 struct bgp_static *bgp_static;
11894
11895 if (! bgp)
11896 return 0;
11897
11898 if (p->family != AF_INET)
11899 return 0;
11900
11901 peer = rinfo->peer;
11902
11903 if (peer->su.sa.sa_family != AF_INET)
11904 return 0;
11905
11906 memset (&q, 0, sizeof (struct prefix_ipv4));
11907 q.family = AF_INET;
11908 q.prefix = peer->su.sin.sin_addr;
11909 q.prefixlen = IPV4_MAX_BITLEN;
11910
11911 /* Check source address. */
11912 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11913 if (rn)
11914 {
11915 bdistance = rn->info;
11916 bgp_unlock_node (rn);
11917
11918 if (bdistance->access_list)
11919 {
11920 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11921 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11922 return bdistance->distance;
11923 }
11924 else
11925 return bdistance->distance;
11926 }
11927
11928 /* Backdoor check. */
11929 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11930 if (rn)
11931 {
11932 bgp_static = rn->info;
11933 bgp_unlock_node (rn);
11934
11935 if (bgp_static->backdoor)
11936 {
11937 if (bgp->distance_local)
11938 return bgp->distance_local;
11939 else
11940 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11941 }
11942 }
11943
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011944 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011945 {
11946 if (bgp->distance_ebgp)
11947 return bgp->distance_ebgp;
11948 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11949 }
11950 else
11951 {
11952 if (bgp->distance_ibgp)
11953 return bgp->distance_ibgp;
11954 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11955 }
11956}
11957
11958DEFUN (bgp_distance,
11959 bgp_distance_cmd,
11960 "distance bgp <1-255> <1-255> <1-255>",
11961 "Define an administrative distance\n"
11962 "BGP distance\n"
11963 "Distance for routes external to the AS\n"
11964 "Distance for routes internal to the AS\n"
11965 "Distance for local routes\n")
11966{
11967 struct bgp *bgp;
11968
11969 bgp = vty->index;
11970
11971 bgp->distance_ebgp = atoi (argv[0]);
11972 bgp->distance_ibgp = atoi (argv[1]);
11973 bgp->distance_local = atoi (argv[2]);
11974 return CMD_SUCCESS;
11975}
11976
11977DEFUN (no_bgp_distance,
11978 no_bgp_distance_cmd,
11979 "no distance bgp <1-255> <1-255> <1-255>",
11980 NO_STR
11981 "Define an administrative distance\n"
11982 "BGP distance\n"
11983 "Distance for routes external to the AS\n"
11984 "Distance for routes internal to the AS\n"
11985 "Distance for local routes\n")
11986{
11987 struct bgp *bgp;
11988
11989 bgp = vty->index;
11990
11991 bgp->distance_ebgp= 0;
11992 bgp->distance_ibgp = 0;
11993 bgp->distance_local = 0;
11994 return CMD_SUCCESS;
11995}
11996
11997ALIAS (no_bgp_distance,
11998 no_bgp_distance2_cmd,
11999 "no distance bgp",
12000 NO_STR
12001 "Define an administrative distance\n"
12002 "BGP distance\n")
12003
12004DEFUN (bgp_distance_source,
12005 bgp_distance_source_cmd,
12006 "distance <1-255> A.B.C.D/M",
12007 "Define an administrative distance\n"
12008 "Administrative distance\n"
12009 "IP source prefix\n")
12010{
12011 bgp_distance_set (vty, argv[0], argv[1], NULL);
12012 return CMD_SUCCESS;
12013}
12014
12015DEFUN (no_bgp_distance_source,
12016 no_bgp_distance_source_cmd,
12017 "no distance <1-255> A.B.C.D/M",
12018 NO_STR
12019 "Define an administrative distance\n"
12020 "Administrative distance\n"
12021 "IP source prefix\n")
12022{
12023 bgp_distance_unset (vty, argv[0], argv[1], NULL);
12024 return CMD_SUCCESS;
12025}
12026
12027DEFUN (bgp_distance_source_access_list,
12028 bgp_distance_source_access_list_cmd,
12029 "distance <1-255> A.B.C.D/M WORD",
12030 "Define an administrative distance\n"
12031 "Administrative distance\n"
12032 "IP source prefix\n"
12033 "Access list name\n")
12034{
12035 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
12036 return CMD_SUCCESS;
12037}
12038
12039DEFUN (no_bgp_distance_source_access_list,
12040 no_bgp_distance_source_access_list_cmd,
12041 "no distance <1-255> A.B.C.D/M WORD",
12042 NO_STR
12043 "Define an administrative distance\n"
12044 "Administrative distance\n"
12045 "IP source prefix\n"
12046 "Access list name\n")
12047{
12048 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
12049 return CMD_SUCCESS;
12050}
David Lamparter6b0655a2014-06-04 06:53:35 +020012051
paul718e3742002-12-13 20:15:29 +000012052DEFUN (bgp_damp_set,
12053 bgp_damp_set_cmd,
12054 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12055 "BGP Specific commands\n"
12056 "Enable route-flap dampening\n"
12057 "Half-life time for the penalty\n"
12058 "Value to start reusing a route\n"
12059 "Value to start suppressing a route\n"
12060 "Maximum duration to suppress a stable route\n")
12061{
12062 struct bgp *bgp;
12063 int half = DEFAULT_HALF_LIFE * 60;
12064 int reuse = DEFAULT_REUSE;
12065 int suppress = DEFAULT_SUPPRESS;
12066 int max = 4 * half;
12067
12068 if (argc == 4)
12069 {
12070 half = atoi (argv[0]) * 60;
12071 reuse = atoi (argv[1]);
12072 suppress = atoi (argv[2]);
12073 max = atoi (argv[3]) * 60;
12074 }
12075 else if (argc == 1)
12076 {
12077 half = atoi (argv[0]) * 60;
12078 max = 4 * half;
12079 }
12080
12081 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000012082
12083 if (suppress < reuse)
12084 {
12085 vty_out (vty, "Suppress value cannot be less than reuse value %s",
12086 VTY_NEWLINE);
12087 return 0;
12088 }
12089
paul718e3742002-12-13 20:15:29 +000012090 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
12091 half, reuse, suppress, max);
12092}
12093
12094ALIAS (bgp_damp_set,
12095 bgp_damp_set2_cmd,
12096 "bgp dampening <1-45>",
12097 "BGP Specific commands\n"
12098 "Enable route-flap dampening\n"
12099 "Half-life time for the penalty\n")
12100
12101ALIAS (bgp_damp_set,
12102 bgp_damp_set3_cmd,
12103 "bgp dampening",
12104 "BGP Specific commands\n"
12105 "Enable route-flap dampening\n")
12106
12107DEFUN (bgp_damp_unset,
12108 bgp_damp_unset_cmd,
12109 "no bgp dampening",
12110 NO_STR
12111 "BGP Specific commands\n"
12112 "Enable route-flap dampening\n")
12113{
12114 struct bgp *bgp;
12115
12116 bgp = vty->index;
12117 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
12118}
12119
12120ALIAS (bgp_damp_unset,
12121 bgp_damp_unset2_cmd,
12122 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12123 NO_STR
12124 "BGP Specific commands\n"
12125 "Enable route-flap dampening\n"
12126 "Half-life time for the penalty\n"
12127 "Value to start reusing a route\n"
12128 "Value to start suppressing a route\n"
12129 "Maximum duration to suppress a stable route\n")
12130
12131DEFUN (show_ip_bgp_dampened_paths,
12132 show_ip_bgp_dampened_paths_cmd,
12133 "show ip bgp dampened-paths",
12134 SHOW_STR
12135 IP_STR
12136 BGP_STR
12137 "Display paths suppressed due to dampening\n")
12138{
ajs5a646652004-11-05 01:25:55 +000012139 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
12140 NULL);
paul718e3742002-12-13 20:15:29 +000012141}
12142
Balaji3921cc52015-05-16 23:12:17 +053012143ALIAS (show_ip_bgp_dampened_paths,
12144 show_ip_bgp_damp_dampened_paths_cmd,
12145 "show ip bgp dampening dampened-paths",
12146 SHOW_STR
12147 IP_STR
12148 BGP_STR
12149 "Display detailed information about dampening\n"
12150 "Display paths suppressed due to dampening\n")
12151
paul718e3742002-12-13 20:15:29 +000012152DEFUN (show_ip_bgp_flap_statistics,
12153 show_ip_bgp_flap_statistics_cmd,
12154 "show ip bgp flap-statistics",
12155 SHOW_STR
12156 IP_STR
12157 BGP_STR
12158 "Display flap statistics of routes\n")
12159{
ajs5a646652004-11-05 01:25:55 +000012160 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12161 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012162}
David Lamparter6b0655a2014-06-04 06:53:35 +020012163
Balaji3921cc52015-05-16 23:12:17 +053012164ALIAS (show_ip_bgp_flap_statistics,
12165 show_ip_bgp_damp_flap_statistics_cmd,
12166 "show ip bgp dampening flap-statistics",
12167 SHOW_STR
12168 IP_STR
12169 BGP_STR
12170 "Display detailed information about dampening\n"
12171 "Display flap statistics of routes\n")
12172
paul718e3742002-12-13 20:15:29 +000012173/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012174static int
paulfd79ac92004-10-13 05:06:08 +000012175bgp_clear_damp_route (struct vty *vty, const char *view_name,
12176 const char *ip_str, afi_t afi, safi_t safi,
12177 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012178{
12179 int ret;
12180 struct prefix match;
12181 struct bgp_node *rn;
12182 struct bgp_node *rm;
12183 struct bgp_info *ri;
12184 struct bgp_info *ri_temp;
12185 struct bgp *bgp;
12186 struct bgp_table *table;
12187
12188 /* BGP structure lookup. */
12189 if (view_name)
12190 {
12191 bgp = bgp_lookup_by_name (view_name);
12192 if (bgp == NULL)
12193 {
12194 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12195 return CMD_WARNING;
12196 }
12197 }
12198 else
12199 {
12200 bgp = bgp_get_default ();
12201 if (bgp == NULL)
12202 {
12203 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12204 return CMD_WARNING;
12205 }
12206 }
12207
12208 /* Check IP address argument. */
12209 ret = str2prefix (ip_str, &match);
12210 if (! ret)
12211 {
12212 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12213 return CMD_WARNING;
12214 }
12215
12216 match.family = afi2family (afi);
12217
12218 if (safi == SAFI_MPLS_VPN)
12219 {
12220 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12221 {
12222 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12223 continue;
12224
12225 if ((table = rn->info) != NULL)
12226 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012227 {
12228 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12229 {
12230 ri = rm->info;
12231 while (ri)
12232 {
12233 if (ri->extra && ri->extra->damp_info)
12234 {
12235 ri_temp = ri->next;
12236 bgp_damp_info_free (ri->extra->damp_info, 1);
12237 ri = ri_temp;
12238 }
12239 else
12240 ri = ri->next;
12241 }
12242 }
12243
12244 bgp_unlock_node (rm);
12245 }
paul718e3742002-12-13 20:15:29 +000012246 }
12247 }
12248 else
12249 {
12250 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012251 {
12252 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12253 {
12254 ri = rn->info;
12255 while (ri)
12256 {
12257 if (ri->extra && ri->extra->damp_info)
12258 {
12259 ri_temp = ri->next;
12260 bgp_damp_info_free (ri->extra->damp_info, 1);
12261 ri = ri_temp;
12262 }
12263 else
12264 ri = ri->next;
12265 }
12266 }
12267
12268 bgp_unlock_node (rn);
12269 }
paul718e3742002-12-13 20:15:29 +000012270 }
12271
12272 return CMD_SUCCESS;
12273}
12274
12275DEFUN (clear_ip_bgp_dampening,
12276 clear_ip_bgp_dampening_cmd,
12277 "clear ip bgp dampening",
12278 CLEAR_STR
12279 IP_STR
12280 BGP_STR
12281 "Clear route flap dampening information\n")
12282{
12283 bgp_damp_info_clean ();
12284 return CMD_SUCCESS;
12285}
12286
12287DEFUN (clear_ip_bgp_dampening_prefix,
12288 clear_ip_bgp_dampening_prefix_cmd,
12289 "clear ip bgp dampening A.B.C.D/M",
12290 CLEAR_STR
12291 IP_STR
12292 BGP_STR
12293 "Clear route flap dampening information\n"
12294 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12295{
12296 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12297 SAFI_UNICAST, NULL, 1);
12298}
12299
12300DEFUN (clear_ip_bgp_dampening_address,
12301 clear_ip_bgp_dampening_address_cmd,
12302 "clear ip bgp dampening A.B.C.D",
12303 CLEAR_STR
12304 IP_STR
12305 BGP_STR
12306 "Clear route flap dampening information\n"
12307 "Network to clear damping information\n")
12308{
12309 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12310 SAFI_UNICAST, NULL, 0);
12311}
12312
12313DEFUN (clear_ip_bgp_dampening_address_mask,
12314 clear_ip_bgp_dampening_address_mask_cmd,
12315 "clear ip bgp dampening A.B.C.D A.B.C.D",
12316 CLEAR_STR
12317 IP_STR
12318 BGP_STR
12319 "Clear route flap dampening information\n"
12320 "Network to clear damping information\n"
12321 "Network mask\n")
12322{
12323 int ret;
12324 char prefix_str[BUFSIZ];
12325
12326 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12327 if (! ret)
12328 {
12329 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12330 return CMD_WARNING;
12331 }
12332
12333 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12334 SAFI_UNICAST, NULL, 0);
12335}
David Lamparter6b0655a2014-06-04 06:53:35 +020012336
paul94f2b392005-06-28 12:44:16 +000012337static int
paul718e3742002-12-13 20:15:29 +000012338bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12339 afi_t afi, safi_t safi, int *write)
12340{
12341 struct bgp_node *prn;
12342 struct bgp_node *rn;
12343 struct bgp_table *table;
12344 struct prefix *p;
12345 struct prefix_rd *prd;
12346 struct bgp_static *bgp_static;
12347 u_int32_t label;
12348 char buf[SU_ADDRSTRLEN];
12349 char rdbuf[RD_ADDRSTRLEN];
12350
12351 /* Network configuration. */
12352 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12353 if ((table = prn->info) != NULL)
12354 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12355 if ((bgp_static = rn->info) != NULL)
12356 {
12357 p = &rn->p;
12358 prd = (struct prefix_rd *) &prn->p;
12359
12360 /* "address-family" display. */
12361 bgp_config_write_family_header (vty, afi, safi, write);
12362
12363 /* "network" configuration display. */
12364 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12365 label = decode_label (bgp_static->tag);
12366
12367 vty_out (vty, " network %s/%d rd %s tag %d",
12368 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12369 p->prefixlen,
12370 rdbuf, label);
12371 vty_out (vty, "%s", VTY_NEWLINE);
12372 }
12373 return 0;
12374}
12375
12376/* Configuration of static route announcement and aggregate
12377 information. */
12378int
12379bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12380 afi_t afi, safi_t safi, int *write)
12381{
12382 struct bgp_node *rn;
12383 struct prefix *p;
12384 struct bgp_static *bgp_static;
12385 struct bgp_aggregate *bgp_aggregate;
12386 char buf[SU_ADDRSTRLEN];
12387
12388 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12389 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12390
12391 /* Network configuration. */
12392 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12393 if ((bgp_static = rn->info) != NULL)
12394 {
12395 p = &rn->p;
12396
12397 /* "address-family" display. */
12398 bgp_config_write_family_header (vty, afi, safi, write);
12399
12400 /* "network" configuration display. */
12401 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12402 {
12403 u_int32_t destination;
12404 struct in_addr netmask;
12405
12406 destination = ntohl (p->u.prefix4.s_addr);
12407 masklen2ip (p->prefixlen, &netmask);
12408 vty_out (vty, " network %s",
12409 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12410
12411 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12412 || (IN_CLASSB (destination) && p->prefixlen == 16)
12413 || (IN_CLASSA (destination) && p->prefixlen == 8)
12414 || p->u.prefix4.s_addr == 0)
12415 {
12416 /* Natural mask is not display. */
12417 }
12418 else
12419 vty_out (vty, " mask %s", inet_ntoa (netmask));
12420 }
12421 else
12422 {
12423 vty_out (vty, " network %s/%d",
12424 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12425 p->prefixlen);
12426 }
12427
12428 if (bgp_static->rmap.name)
12429 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012430 else
12431 {
12432 if (bgp_static->backdoor)
12433 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012434 }
paul718e3742002-12-13 20:15:29 +000012435
12436 vty_out (vty, "%s", VTY_NEWLINE);
12437 }
12438
12439 /* Aggregate-address configuration. */
12440 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12441 if ((bgp_aggregate = rn->info) != NULL)
12442 {
12443 p = &rn->p;
12444
12445 /* "address-family" display. */
12446 bgp_config_write_family_header (vty, afi, safi, write);
12447
12448 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12449 {
12450 struct in_addr netmask;
12451
12452 masklen2ip (p->prefixlen, &netmask);
12453 vty_out (vty, " aggregate-address %s %s",
12454 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12455 inet_ntoa (netmask));
12456 }
12457 else
12458 {
12459 vty_out (vty, " aggregate-address %s/%d",
12460 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12461 p->prefixlen);
12462 }
12463
12464 if (bgp_aggregate->as_set)
12465 vty_out (vty, " as-set");
12466
12467 if (bgp_aggregate->summary_only)
12468 vty_out (vty, " summary-only");
12469
12470 vty_out (vty, "%s", VTY_NEWLINE);
12471 }
12472
12473 return 0;
12474}
12475
12476int
12477bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12478{
12479 struct bgp_node *rn;
12480 struct bgp_distance *bdistance;
12481
12482 /* Distance configuration. */
12483 if (bgp->distance_ebgp
12484 && bgp->distance_ibgp
12485 && bgp->distance_local
12486 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12487 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12488 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12489 vty_out (vty, " distance bgp %d %d %d%s",
12490 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12491 VTY_NEWLINE);
12492
12493 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12494 if ((bdistance = rn->info) != NULL)
12495 {
12496 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12497 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12498 bdistance->access_list ? bdistance->access_list : "",
12499 VTY_NEWLINE);
12500 }
12501
12502 return 0;
12503}
12504
12505/* Allocate routing table structure and install commands. */
12506void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012507bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012508{
12509 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012510 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012511
12512 /* IPv4 BGP commands. */
12513 install_element (BGP_NODE, &bgp_network_cmd);
12514 install_element (BGP_NODE, &bgp_network_mask_cmd);
12515 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12516 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12517 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12518 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12519 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12520 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12521 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12522 install_element (BGP_NODE, &no_bgp_network_cmd);
12523 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12524 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12525 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12526 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12527 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12528 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12529 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12530 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12531
12532 install_element (BGP_NODE, &aggregate_address_cmd);
12533 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12534 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12535 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12536 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12537 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12538 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12539 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12540 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12541 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12542 install_element (BGP_NODE, &no_aggregate_address_cmd);
12543 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12544 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12545 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12546 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12547 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12548 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12549 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12550 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12551 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12552
12553 /* IPv4 unicast configuration. */
12554 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12555 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12556 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12557 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12558 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12559 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012560 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012561 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12562 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12563 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12564 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12565 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012566
paul718e3742002-12-13 20:15:29 +000012567 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12568 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12569 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12570 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12571 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12572 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12573 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12574 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12575 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12576 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12577 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12578 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12579 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12580 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12581 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12582 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12583 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12584 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12585 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12586 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12587
12588 /* IPv4 multicast configuration. */
12589 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12590 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12591 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12592 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12593 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12594 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12595 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12596 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12597 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12598 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12599 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12600 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12601 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12602 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12603 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12604 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12605 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12606 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12607 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12608 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12609 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12610 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12611 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12612 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12613 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12614 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12615 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12616 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12617 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12618 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12619 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12620 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12621
12622 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12623 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012624 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012625 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12626 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012627 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012628 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12629 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12630 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12631 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012632 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012633 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12634 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12635 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12636 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12637 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12638 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12639 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12640 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12641 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12642 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12643 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12644 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12645 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12646 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12647 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12648 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12649 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12650 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12651 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12652 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12653 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12654 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12655 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12656 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12657 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012658 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12659 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12660 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12661 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12662 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012663 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12664 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12665 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12666 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12667 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12668 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12669 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12670 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12671 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12672 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12673 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12674 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12675 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12676 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12677 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12678 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12679 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12680 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012681 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012682 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12683 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12684 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12685 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012686 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
paul718e3742002-12-13 20:15:29 +000012687 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012688 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
paul718e3742002-12-13 20:15:29 +000012689 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012690 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
paul718e3742002-12-13 20:15:29 +000012691 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012692 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
paul718e3742002-12-13 20:15:29 +000012693 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12694 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012695 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
paul718e3742002-12-13 20:15:29 +000012696 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12697 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012698 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000012699 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012700 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000012701 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012702 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000012703 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012704 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
paul718e3742002-12-13 20:15:29 +000012705 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12706 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012707 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012708 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012709 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012710 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012711 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012712 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012713 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12714 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012715 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012716 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012717 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012718 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012719 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012720 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012721
12722 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12723 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12724 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012725 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012726 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12727 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12728 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012729 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012730 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12731 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12732 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12733 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12734 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12735 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12736 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12737 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12738 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12739 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12740 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12741 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012742 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12743 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12744 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12745 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12746 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012747 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12748 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12749 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12750 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12751 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12752 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12753 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12754 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12755 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012756 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012757 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012758 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012759 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012760 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012761 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012762 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012763
12764 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12765 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012766 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012767 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12768 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012769 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012770 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12771 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12772 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12773 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012774 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012775 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12776 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12777 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12778 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12779 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12780 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12781 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12782 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12783 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12784 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12785 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12786 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12787 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12788 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12789 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12790 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12791 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12792 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12793 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12794 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12795 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12796 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12797 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12798 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12799 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012800 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12801 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12802 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12803 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12804 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012805 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12806 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12807 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12808 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12809 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12810 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12811 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12812 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12813 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12814 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12815 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12816 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12817 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12818 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12819 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12820 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12821 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12822 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012823 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012824 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12825 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12826 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12827 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012828 install_element (ENABLE_NODE, &show_ip_bgp_dampening_params_cmd);
paul718e3742002-12-13 20:15:29 +000012829 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012830 install_element (ENABLE_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
paul718e3742002-12-13 20:15:29 +000012831 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012832 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
paul718e3742002-12-13 20:15:29 +000012833 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012834 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_address_cmd);
paul718e3742002-12-13 20:15:29 +000012835 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12836 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012837 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
paul718e3742002-12-13 20:15:29 +000012838 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012839 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_regexp_cmd);
paul718e3742002-12-13 20:15:29 +000012840 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012841 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000012842 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012843 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
12844 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000012845 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012846 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000012847 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012848 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
paul718e3742002-12-13 20:15:29 +000012849 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12850 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012851 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012852 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012853 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012854 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012855 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012856 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012857 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12858 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012859 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012860 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012861 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012862 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012863 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012864 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012865
12866 /* BGP dampening clear commands */
12867 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12868 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12869 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12870 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12871
Paul Jakmaff7924f2006-09-04 01:10:36 +000012872 /* prefix count */
12873 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12874 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12875 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012876#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012877 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12878
paul718e3742002-12-13 20:15:29 +000012879 /* New config IPv6 BGP commands. */
12880 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12881 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12882 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12883 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12884
12885 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12886 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12887 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12888 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12889
G.Balaji73bfe0b2011-09-23 22:36:20 +053012890 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12891 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12892
paul718e3742002-12-13 20:15:29 +000012893 /* Old config IPv6 BGP commands. */
12894 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12895 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12896
12897 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12898 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12899 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12900 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12901
12902 install_element (VIEW_NODE, &show_bgp_cmd);
12903 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012904 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012905 install_element (VIEW_NODE, &show_bgp_route_cmd);
12906 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012907 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012908 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12909 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012910 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012911 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12912 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12913 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12914 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12915 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12916 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12917 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12918 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12919 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12920 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12921 install_element (VIEW_NODE, &show_bgp_community_cmd);
12922 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12923 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12924 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12925 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12926 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12927 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12928 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12929 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12930 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12931 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12932 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12933 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12934 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12935 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12936 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12937 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12938 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12939 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12940 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12941 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12942 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12943 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12944 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12945 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12946 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12947 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12948 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12949 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12950 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012951 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12952 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12953 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12954 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012955 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012956 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012957 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012958 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012959 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012960 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012961 install_element (VIEW_NODE, &show_bgp_view_cmd);
12962 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12963 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12964 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12965 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12966 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12967 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12968 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12969 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12970 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12971 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12972 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12973 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12974 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12975 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12976 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12977 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12978 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012979 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012980 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012981 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012982 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012983 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012984 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012985
12986 /* Restricted:
12987 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12988 */
12989 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12990 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012991 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012992 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12993 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012994 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012995 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12996 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12997 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12998 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12999 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
13000 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
13001 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
13002 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
13003 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
13004 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
13005 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
13006 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
13007 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
13008 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
13009 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
13010 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
13011 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013012 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013013 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013014 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013015 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
13016 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
13017 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
13018 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
13019 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13020 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13021 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013022 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013023 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013024 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013025
13026 install_element (ENABLE_NODE, &show_bgp_cmd);
13027 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013028 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000013029 install_element (ENABLE_NODE, &show_bgp_route_cmd);
13030 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013031 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000013032 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
13033 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013034 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013035 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
13036 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
13037 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
13038 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
13039 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
13040 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
13041 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
13042 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
13043 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
13044 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
13045 install_element (ENABLE_NODE, &show_bgp_community_cmd);
13046 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
13047 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
13048 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
13049 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
13050 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
13051 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
13052 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
13053 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
13054 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
13055 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
13056 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
13057 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
13058 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
13059 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
13060 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
13061 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
13062 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
13063 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
13064 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
13065 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
13066 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
13067 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
13068 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
13069 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
13070 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
13071 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
13072 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
13073 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
13074 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000013075 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
13076 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
13077 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
13078 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013079 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013080 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013081 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013082 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013083 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013084 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000013085 install_element (ENABLE_NODE, &show_bgp_view_cmd);
13086 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
13087 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
13088 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
13089 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
13090 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
13091 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
13092 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
13093 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
13094 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
13095 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
13096 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
13097 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13098 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13099 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
13100 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
13101 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
13102 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013103 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013104 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013105 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013106 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013107 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013108 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000013109
13110 /* Statistics */
13111 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
13112 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
13113 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
13114 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
13115
paul718e3742002-12-13 20:15:29 +000013116 /* old command */
13117 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
13118 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
13119 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
13120 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
13121 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
13122 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
13123 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
13124 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
13125 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
13126 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
13127 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
13128 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
13129 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
13130 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
13131 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
13132 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
13133 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13134 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13135 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
13136 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
13137 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
13138 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
13139 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13140 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
13141 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
13142 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
13143 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
13144 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
13145 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
13146 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
13147 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13148 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13149 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13150 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
13151 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13152 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000013153
paul718e3742002-12-13 20:15:29 +000013154 /* old command */
13155 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
13156 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
13157 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
13158 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
13159 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
13160 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
13161 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
13162 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
13163 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
13164 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
13165 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13166 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13167 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13168 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13169 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13170 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13171 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13172 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13173 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13174 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13175 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13176 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13177 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13178 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13179 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13180 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13181 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13182 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13183 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13184 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13185 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13186 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13187 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13188 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13189 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13190 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13191
13192 /* old command */
13193 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13194 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13195 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13196 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13197
13198 /* old command */
13199 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13200 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13201 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13202 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13203
13204 /* old command */
13205 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13206 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13207 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13208 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13209#endif /* HAVE_IPV6 */
13210
13211 install_element (BGP_NODE, &bgp_distance_cmd);
13212 install_element (BGP_NODE, &no_bgp_distance_cmd);
13213 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13214 install_element (BGP_NODE, &bgp_distance_source_cmd);
13215 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13216 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13217 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13218
13219 install_element (BGP_NODE, &bgp_damp_set_cmd);
13220 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13221 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13222 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13223 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13224 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13225 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13226 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13227 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13228 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013229
13230 /* Deprecated AS-Pathlimit commands */
13231 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13232 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13233 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13234 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13235 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13236 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13237
13238 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13239 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13240 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13241 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13242 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13243 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13244
13245 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13246 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13247 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13248 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13249 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13250 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13251
13252 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13253 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13254 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13255 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13256 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13257 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13258
13259 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13260 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13261 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13262 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13263 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13264 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13265
13266 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13267 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13268 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13269 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13270 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13271 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013272
13273#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013274 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13275 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013276#endif
paul718e3742002-12-13 20:15:29 +000013277}
Chris Caputo228da422009-07-18 05:44:03 +000013278
13279void
13280bgp_route_finish (void)
13281{
13282 bgp_table_unlock (bgp_distance_table);
13283 bgp_distance_table = NULL;
13284}