blob: 1ea4d2169002007d4ae20e5ffcbc1b79d03aa264 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* BGP routing information
2 Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
23#include "prefix.h"
24#include "linklist.h"
25#include "memory.h"
26#include "command.h"
27#include "stream.h"
28#include "filter.h"
29#include "str.h"
30#include "log.h"
31#include "routemap.h"
32#include "buffer.h"
33#include "sockunion.h"
34#include "plist.h"
35#include "thread.h"
paul200df112005-06-01 11:17:05 +000036#include "workqueue.h"
paul718e3742002-12-13 20:15:29 +000037
38#include "bgpd/bgpd.h"
39#include "bgpd/bgp_table.h"
40#include "bgpd/bgp_route.h"
41#include "bgpd/bgp_attr.h"
42#include "bgpd/bgp_debug.h"
43#include "bgpd/bgp_aspath.h"
44#include "bgpd/bgp_regex.h"
45#include "bgpd/bgp_community.h"
46#include "bgpd/bgp_ecommunity.h"
47#include "bgpd/bgp_clist.h"
48#include "bgpd/bgp_packet.h"
49#include "bgpd/bgp_filter.h"
50#include "bgpd/bgp_fsm.h"
51#include "bgpd/bgp_mplsvpn.h"
52#include "bgpd/bgp_nexthop.h"
53#include "bgpd/bgp_damp.h"
54#include "bgpd/bgp_advertise.h"
55#include "bgpd/bgp_zebra.h"
hasso0a486e52005-02-01 20:57:17 +000056#include "bgpd/bgp_vty.h"
Josh Bailey96450fa2011-07-20 20:45:12 -070057#include "bgpd/bgp_mpath.h"
paul718e3742002-12-13 20:15:29 +000058
59/* Extern from bgp_dump.c */
Stephen Hemmingerdde72582009-05-08 15:19:07 -070060extern const char *bgp_origin_str[];
61extern const char *bgp_origin_long_str[];
David Lamparter6b0655a2014-06-04 06:53:35 +020062
paul94f2b392005-06-28 12:44:16 +000063static struct bgp_node *
paulfee0f4c2004-09-13 05:12:46 +000064bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
paul718e3742002-12-13 20:15:29 +000065 struct prefix_rd *prd)
66{
67 struct bgp_node *rn;
68 struct bgp_node *prn = NULL;
Paul Jakmada5b30f2006-05-08 14:37:17 +000069
70 assert (table);
71 if (!table)
72 return NULL;
73
paul718e3742002-12-13 20:15:29 +000074 if (safi == SAFI_MPLS_VPN)
75 {
paulfee0f4c2004-09-13 05:12:46 +000076 prn = bgp_node_get (table, (struct prefix *) prd);
paul718e3742002-12-13 20:15:29 +000077
78 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +000079 prn->info = bgp_table_init (afi, safi);
paul718e3742002-12-13 20:15:29 +000080 else
81 bgp_unlock_node (prn);
82 table = prn->info;
83 }
paul718e3742002-12-13 20:15:29 +000084
85 rn = bgp_node_get (table, p);
86
87 if (safi == SAFI_MPLS_VPN)
88 rn->prn = prn;
89
90 return rn;
91}
David Lamparter6b0655a2014-06-04 06:53:35 +020092
Paul Jakmafb982c22007-05-04 20:15:47 +000093/* Allocate bgp_info_extra */
94static struct bgp_info_extra *
95bgp_info_extra_new (void)
96{
97 struct bgp_info_extra *new;
98 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
99 return new;
100}
101
102static void
103bgp_info_extra_free (struct bgp_info_extra **extra)
104{
105 if (extra && *extra)
106 {
107 if ((*extra)->damp_info)
108 bgp_damp_info_free ((*extra)->damp_info, 0);
109
110 (*extra)->damp_info = NULL;
111
112 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
113
114 *extra = NULL;
115 }
116}
117
118/* Get bgp_info extra information for the given bgp_info, lazy allocated
119 * if required.
120 */
121struct bgp_info_extra *
122bgp_info_extra_get (struct bgp_info *ri)
123{
124 if (!ri->extra)
125 ri->extra = bgp_info_extra_new();
126 return ri->extra;
127}
128
paul718e3742002-12-13 20:15:29 +0000129/* Allocate new bgp info structure. */
paul200df112005-06-01 11:17:05 +0000130static struct bgp_info *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -0800131bgp_info_new (void)
paul718e3742002-12-13 20:15:29 +0000132{
Stephen Hemminger393deb92008-08-18 14:13:29 -0700133 return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
paul718e3742002-12-13 20:15:29 +0000134}
135
136/* Free bgp route information. */
paul200df112005-06-01 11:17:05 +0000137static void
paul718e3742002-12-13 20:15:29 +0000138bgp_info_free (struct bgp_info *binfo)
139{
140 if (binfo->attr)
Paul Jakmaf6f434b2010-11-23 21:28:03 +0000141 bgp_attr_unintern (&binfo->attr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000142
143 bgp_info_extra_free (&binfo->extra);
Josh Baileyde8d5df2011-07-20 20:46:01 -0700144 bgp_info_mpath_free (&binfo->mpath);
paul718e3742002-12-13 20:15:29 +0000145
paul200df112005-06-01 11:17:05 +0000146 peer_unlock (binfo->peer); /* bgp_info peer reference */
147
paul718e3742002-12-13 20:15:29 +0000148 XFREE (MTYPE_BGP_ROUTE, binfo);
149}
150
paul200df112005-06-01 11:17:05 +0000151struct bgp_info *
152bgp_info_lock (struct bgp_info *binfo)
153{
154 binfo->lock++;
155 return binfo;
156}
157
158struct bgp_info *
159bgp_info_unlock (struct bgp_info *binfo)
160{
161 assert (binfo && binfo->lock > 0);
162 binfo->lock--;
163
164 if (binfo->lock == 0)
165 {
166#if 0
167 zlog_debug ("%s: unlocked and freeing", __func__);
168 zlog_backtrace (LOG_DEBUG);
169#endif
170 bgp_info_free (binfo);
171 return NULL;
172 }
173
174#if 0
175 if (binfo->lock == 1)
176 {
177 zlog_debug ("%s: unlocked to 1", __func__);
178 zlog_backtrace (LOG_DEBUG);
179 }
180#endif
181
182 return binfo;
183}
184
paul718e3742002-12-13 20:15:29 +0000185void
186bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
187{
188 struct bgp_info *top;
189
190 top = rn->info;
paul200df112005-06-01 11:17:05 +0000191
paul718e3742002-12-13 20:15:29 +0000192 ri->next = rn->info;
193 ri->prev = NULL;
194 if (top)
195 top->prev = ri;
196 rn->info = ri;
paul200df112005-06-01 11:17:05 +0000197
198 bgp_info_lock (ri);
199 bgp_lock_node (rn);
200 peer_lock (ri->peer); /* bgp_info peer reference */
paul718e3742002-12-13 20:15:29 +0000201}
202
paulb40d9392005-08-22 22:34:41 +0000203/* Do the actual removal of info from RIB, for use by bgp_process
204 completion callback *only* */
205static void
206bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
paul718e3742002-12-13 20:15:29 +0000207{
208 if (ri->next)
209 ri->next->prev = ri->prev;
210 if (ri->prev)
211 ri->prev->next = ri->next;
212 else
213 rn->info = ri->next;
paul200df112005-06-01 11:17:05 +0000214
Josh Baileyde8d5df2011-07-20 20:46:01 -0700215 bgp_info_mpath_dequeue (ri);
paul200df112005-06-01 11:17:05 +0000216 bgp_info_unlock (ri);
217 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000218}
219
paulb40d9392005-08-22 22:34:41 +0000220void
221bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
222{
Paul Jakma1a392d42006-09-07 00:24:49 +0000223 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
224 /* set of previous already took care of pcount */
paulb40d9392005-08-22 22:34:41 +0000225 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
226}
227
Andrew J. Schorr8d452102006-11-28 19:50:46 +0000228/* undo the effects of a previous call to bgp_info_delete; typically
229 called when a route is deleted and then quickly re-added before the
230 deletion has been processed */
231static void
232bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
233{
234 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
235 /* unset of previous already took care of pcount */
236 SET_FLAG (ri->flags, BGP_INFO_VALID);
237}
238
Paul Jakma1a392d42006-09-07 00:24:49 +0000239/* Adjust pcount as required */
240static void
241bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
242{
Avneesh Sachdev67174042012-08-17 08:19:49 -0700243 struct bgp_table *table;
244
245 assert (rn && bgp_node_table (rn));
Paul Jakma6f585442006-10-22 19:13:07 +0000246 assert (ri && ri->peer && ri->peer->bgp);
247
Avneesh Sachdev67174042012-08-17 08:19:49 -0700248 table = bgp_node_table (rn);
249
Paul Jakma1a392d42006-09-07 00:24:49 +0000250 /* Ignore 'pcount' for RS-client tables */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700251 if (table->type != BGP_TABLE_MAIN
Paul Jakma1a392d42006-09-07 00:24:49 +0000252 || ri->peer == ri->peer->bgp->peer_self)
253 return;
254
255 if (BGP_INFO_HOLDDOWN (ri)
256 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
257 {
258
259 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
260
261 /* slight hack, but more robust against errors. */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700262 if (ri->peer->pcount[table->afi][table->safi])
263 ri->peer->pcount[table->afi][table->safi]--;
Paul Jakma1a392d42006-09-07 00:24:49 +0000264 else
265 {
266 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
267 __func__, ri->peer->host);
268 zlog_backtrace (LOG_WARNING);
269 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
270 }
271 }
272 else if (!BGP_INFO_HOLDDOWN (ri)
273 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
274 {
275 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
Avneesh Sachdev67174042012-08-17 08:19:49 -0700276 ri->peer->pcount[table->afi][table->safi]++;
Paul Jakma1a392d42006-09-07 00:24:49 +0000277 }
278}
279
280
281/* Set/unset bgp_info flags, adjusting any other state as needed.
282 * This is here primarily to keep prefix-count in check.
283 */
284void
285bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
286{
287 SET_FLAG (ri->flags, flag);
288
289 /* early bath if we know it's not a flag that changes useability state */
290 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
291 return;
292
293 bgp_pcount_adjust (rn, ri);
294}
295
296void
297bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
298{
299 UNSET_FLAG (ri->flags, flag);
300
301 /* early bath if we know it's not a flag that changes useability state */
302 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
303 return;
304
305 bgp_pcount_adjust (rn, ri);
306}
307
paul718e3742002-12-13 20:15:29 +0000308/* Get MED value. If MED value is missing and "bgp bestpath
309 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000310static u_int32_t
paul718e3742002-12-13 20:15:29 +0000311bgp_med_value (struct attr *attr, struct bgp *bgp)
312{
313 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
314 return attr->med;
315 else
316 {
317 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000318 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000319 else
320 return 0;
321 }
322}
323
324/* Compare two bgp route entity. br is preferable then return 1. */
paul94f2b392005-06-28 12:44:16 +0000325static int
Josh Bailey96450fa2011-07-20 20:45:12 -0700326bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
327 int *paths_eq)
paul718e3742002-12-13 20:15:29 +0000328{
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000329 struct attr *newattr, *existattr;
330 struct attr_extra *newattre, *existattre;
331 bgp_peer_sort_t new_sort;
332 bgp_peer_sort_t exist_sort;
paul718e3742002-12-13 20:15:29 +0000333 u_int32_t new_pref;
334 u_int32_t exist_pref;
335 u_int32_t new_med;
336 u_int32_t exist_med;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000337 u_int32_t new_weight;
338 u_int32_t exist_weight;
339 uint32_t newm, existm;
paul718e3742002-12-13 20:15:29 +0000340 struct in_addr new_id;
341 struct in_addr exist_id;
342 int new_cluster;
343 int exist_cluster;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000344 int internal_as_route;
345 int confed_as_route;
paul718e3742002-12-13 20:15:29 +0000346 int ret;
Josh Bailey96450fa2011-07-20 20:45:12 -0700347
348 *paths_eq = 0;
paul718e3742002-12-13 20:15:29 +0000349
350 /* 0. Null check. */
351 if (new == NULL)
352 return 0;
353 if (exist == NULL)
354 return 1;
355
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000356 newattr = new->attr;
357 existattr = exist->attr;
358 newattre = newattr->extra;
359 existattre = existattr->extra;
360
paul718e3742002-12-13 20:15:29 +0000361 /* 1. Weight check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000362 new_weight = exist_weight = 0;
363
364 if (newattre)
365 new_weight = newattre->weight;
366 if (existattre)
367 exist_weight = existattre->weight;
368
Paul Jakmafb982c22007-05-04 20:15:47 +0000369 if (new_weight > exist_weight)
paul718e3742002-12-13 20:15:29 +0000370 return 1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000371 if (new_weight < exist_weight)
paul718e3742002-12-13 20:15:29 +0000372 return 0;
373
374 /* 2. Local preference check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000375 new_pref = exist_pref = bgp->default_local_pref;
paul718e3742002-12-13 20:15:29 +0000376
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000377 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
378 new_pref = newattr->local_pref;
379 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
380 exist_pref = existattr->local_pref;
381
paul718e3742002-12-13 20:15:29 +0000382 if (new_pref > exist_pref)
383 return 1;
384 if (new_pref < exist_pref)
385 return 0;
386
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000387 /* 3. Local route check. We prefer:
388 * - BGP_ROUTE_STATIC
389 * - BGP_ROUTE_AGGREGATE
390 * - BGP_ROUTE_REDISTRIBUTE
391 */
392 if (! (new->sub_type == BGP_ROUTE_NORMAL))
393 return 1;
394 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
395 return 0;
paul718e3742002-12-13 20:15:29 +0000396
397 /* 4. AS path length check. */
398 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
399 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000400 int exist_hops = aspath_count_hops (existattr->aspath);
401 int exist_confeds = aspath_count_confeds (existattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000402
hasso68118452005-04-08 15:40:36 +0000403 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
404 {
paulfe69a502005-09-10 16:55:02 +0000405 int aspath_hops;
406
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000407 aspath_hops = aspath_count_hops (newattr->aspath);
408 aspath_hops += aspath_count_confeds (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000409
410 if ( aspath_hops < (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000411 return 1;
paulfe69a502005-09-10 16:55:02 +0000412 if ( aspath_hops > (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000413 return 0;
414 }
415 else
416 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000417 int newhops = aspath_count_hops (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000418
419 if (newhops < exist_hops)
hasso68118452005-04-08 15:40:36 +0000420 return 1;
paulfe69a502005-09-10 16:55:02 +0000421 if (newhops > exist_hops)
hasso68118452005-04-08 15:40:36 +0000422 return 0;
423 }
paul718e3742002-12-13 20:15:29 +0000424 }
425
426 /* 5. Origin check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000427 if (newattr->origin < existattr->origin)
paul718e3742002-12-13 20:15:29 +0000428 return 1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000429 if (newattr->origin > existattr->origin)
paul718e3742002-12-13 20:15:29 +0000430 return 0;
431
432 /* 6. MED check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000433 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
434 && aspath_count_hops (existattr->aspath) == 0);
435 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
436 && aspath_count_confeds (existattr->aspath) > 0
437 && aspath_count_hops (newattr->aspath) == 0
438 && aspath_count_hops (existattr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000439
440 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
441 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
442 && confed_as_route)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000443 || aspath_cmp_left (newattr->aspath, existattr->aspath)
444 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
paul718e3742002-12-13 20:15:29 +0000445 || internal_as_route)
446 {
447 new_med = bgp_med_value (new->attr, bgp);
448 exist_med = bgp_med_value (exist->attr, bgp);
449
450 if (new_med < exist_med)
451 return 1;
452 if (new_med > exist_med)
453 return 0;
454 }
455
456 /* 7. Peer type check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000457 new_sort = new->peer->sort;
458 exist_sort = exist->peer->sort;
459
460 if (new_sort == BGP_PEER_EBGP
461 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
paul718e3742002-12-13 20:15:29 +0000462 return 1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000463 if (exist_sort == BGP_PEER_EBGP
464 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
paul718e3742002-12-13 20:15:29 +0000465 return 0;
466
467 /* 8. IGP metric check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000468 newm = existm = 0;
469
470 if (new->extra)
471 newm = new->extra->igpmetric;
472 if (exist->extra)
473 existm = exist->extra->igpmetric;
474
Josh Bailey96450fa2011-07-20 20:45:12 -0700475 if (newm < existm)
476 ret = 1;
477 if (newm > existm)
478 ret = 0;
paul718e3742002-12-13 20:15:29 +0000479
480 /* 9. Maximum path check. */
Josh Bailey96450fa2011-07-20 20:45:12 -0700481 if (newm == existm)
482 {
Pradosh Mohapatra2fdd4552013-09-07 07:02:36 +0000483 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
484 {
485
486 /*
487 * For the two paths, all comparison steps till IGP metric
488 * have succeeded - including AS_PATH hop count. Since 'bgp
489 * bestpath as-path multipath-relax' knob is on, we don't need
490 * an exact match of AS_PATH. Thus, mark the paths are equal.
491 * That will trigger both these paths to get into the multipath
492 * array.
493 */
494 *paths_eq = 1;
495 }
496 else if (new->peer->sort == BGP_PEER_IBGP)
Josh Bailey96450fa2011-07-20 20:45:12 -0700497 {
498 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
499 *paths_eq = 1;
500 }
501 else if (new->peer->as == exist->peer->as)
502 *paths_eq = 1;
503 }
504 else
505 {
506 /*
507 * TODO: If unequal cost ibgp multipath is enabled we can
508 * mark the paths as equal here instead of returning
509 */
510 return ret;
511 }
paul718e3742002-12-13 20:15:29 +0000512
513 /* 10. If both paths are external, prefer the path that was received
514 first (the oldest one). This step minimizes route-flap, since a
515 newer path won't displace an older one, even if it was the
516 preferred route based on the additional decision criteria below. */
517 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000518 && new_sort == BGP_PEER_EBGP
519 && exist_sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +0000520 {
521 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
522 return 1;
523 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
524 return 0;
525 }
526
527 /* 11. Rourter-ID comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000528 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
529 new_id.s_addr = newattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000530 else
531 new_id.s_addr = new->peer->remote_id.s_addr;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000532 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
533 exist_id.s_addr = existattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000534 else
535 exist_id.s_addr = exist->peer->remote_id.s_addr;
536
537 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
538 return 1;
539 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
540 return 0;
541
542 /* 12. Cluster length comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000543 new_cluster = exist_cluster = 0;
544
545 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
546 new_cluster = newattre->cluster->length;
547 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
548 exist_cluster = existattre->cluster->length;
paul718e3742002-12-13 20:15:29 +0000549
550 if (new_cluster < exist_cluster)
551 return 1;
552 if (new_cluster > exist_cluster)
553 return 0;
554
555 /* 13. Neighbor address comparision. */
556 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
557
558 if (ret == 1)
559 return 0;
560 if (ret == -1)
561 return 1;
562
563 return 1;
564}
565
paul94f2b392005-06-28 12:44:16 +0000566static enum filter_type
paul718e3742002-12-13 20:15:29 +0000567bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
568 afi_t afi, safi_t safi)
569{
570 struct bgp_filter *filter;
571
572 filter = &peer->filter[afi][safi];
573
Paul Jakma650f76c2009-06-25 18:06:31 +0100574#define FILTER_EXIST_WARN(F,f,filter) \
575 if (BGP_DEBUG (update, UPDATE_IN) \
576 && !(F ## _IN (filter))) \
577 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
578 peer->host, #f, F ## _IN_NAME(filter));
579
580 if (DISTRIBUTE_IN_NAME (filter)) {
581 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
582
paul718e3742002-12-13 20:15:29 +0000583 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
584 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100585 }
paul718e3742002-12-13 20:15:29 +0000586
Paul Jakma650f76c2009-06-25 18:06:31 +0100587 if (PREFIX_LIST_IN_NAME (filter)) {
588 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
589
paul718e3742002-12-13 20:15:29 +0000590 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
591 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100592 }
paul718e3742002-12-13 20:15:29 +0000593
Paul Jakma650f76c2009-06-25 18:06:31 +0100594 if (FILTER_LIST_IN_NAME (filter)) {
595 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
596
paul718e3742002-12-13 20:15:29 +0000597 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
598 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100599 }
600
paul718e3742002-12-13 20:15:29 +0000601 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100602#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000603}
604
paul94f2b392005-06-28 12:44:16 +0000605static enum filter_type
paul718e3742002-12-13 20:15:29 +0000606bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
607 afi_t afi, safi_t safi)
608{
609 struct bgp_filter *filter;
610
611 filter = &peer->filter[afi][safi];
612
Paul Jakma650f76c2009-06-25 18:06:31 +0100613#define FILTER_EXIST_WARN(F,f,filter) \
614 if (BGP_DEBUG (update, UPDATE_OUT) \
615 && !(F ## _OUT (filter))) \
616 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
617 peer->host, #f, F ## _OUT_NAME(filter));
618
619 if (DISTRIBUTE_OUT_NAME (filter)) {
620 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
621
paul718e3742002-12-13 20:15:29 +0000622 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
623 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100624 }
paul718e3742002-12-13 20:15:29 +0000625
Paul Jakma650f76c2009-06-25 18:06:31 +0100626 if (PREFIX_LIST_OUT_NAME (filter)) {
627 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
628
paul718e3742002-12-13 20:15:29 +0000629 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
630 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100631 }
paul718e3742002-12-13 20:15:29 +0000632
Paul Jakma650f76c2009-06-25 18:06:31 +0100633 if (FILTER_LIST_OUT_NAME (filter)) {
634 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
635
paul718e3742002-12-13 20:15:29 +0000636 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
637 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100638 }
paul718e3742002-12-13 20:15:29 +0000639
640 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100641#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000642}
643
644/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000645static int
paul718e3742002-12-13 20:15:29 +0000646bgp_community_filter (struct peer *peer, struct attr *attr)
647{
648 if (attr->community)
649 {
650 /* NO_ADVERTISE check. */
651 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
652 return 1;
653
654 /* NO_EXPORT check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000655 if (peer->sort == BGP_PEER_EBGP &&
paul718e3742002-12-13 20:15:29 +0000656 community_include (attr->community, COMMUNITY_NO_EXPORT))
657 return 1;
658
659 /* NO_EXPORT_SUBCONFED check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000660 if (peer->sort == BGP_PEER_EBGP
661 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000662 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
663 return 1;
664 }
665 return 0;
666}
667
668/* Route reflection loop check. */
669static int
670bgp_cluster_filter (struct peer *peer, struct attr *attr)
671{
672 struct in_addr cluster_id;
673
Paul Jakmafb982c22007-05-04 20:15:47 +0000674 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000675 {
676 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
677 cluster_id = peer->bgp->cluster_id;
678 else
679 cluster_id = peer->bgp->router_id;
680
Paul Jakmafb982c22007-05-04 20:15:47 +0000681 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000682 return 1;
683 }
684 return 0;
685}
David Lamparter6b0655a2014-06-04 06:53:35 +0200686
paul94f2b392005-06-28 12:44:16 +0000687static int
paul718e3742002-12-13 20:15:29 +0000688bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
689 afi_t afi, safi_t safi)
690{
691 struct bgp_filter *filter;
692 struct bgp_info info;
693 route_map_result_t ret;
694
695 filter = &peer->filter[afi][safi];
696
697 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000698 if (peer->weight)
699 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000700
701 /* Route map apply. */
702 if (ROUTE_MAP_IN_NAME (filter))
703 {
704 /* Duplicate current value to new strucutre for modification. */
705 info.peer = peer;
706 info.attr = attr;
707
paulac41b2a2003-08-12 05:32:27 +0000708 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
709
paul718e3742002-12-13 20:15:29 +0000710 /* Apply BGP route map to the attribute. */
711 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000712
713 peer->rmap_type = 0;
714
paul718e3742002-12-13 20:15:29 +0000715 if (ret == RMAP_DENYMATCH)
David Lamparterc460e572014-06-04 00:54:58 +0200716 /* caller has multiple error paths with bgp_attr_flush() */
717 return RMAP_DENY;
paul718e3742002-12-13 20:15:29 +0000718 }
719 return RMAP_PERMIT;
720}
David Lamparter6b0655a2014-06-04 06:53:35 +0200721
paul94f2b392005-06-28 12:44:16 +0000722static int
paulfee0f4c2004-09-13 05:12:46 +0000723bgp_export_modifier (struct peer *rsclient, struct peer *peer,
724 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
725{
726 struct bgp_filter *filter;
727 struct bgp_info info;
728 route_map_result_t ret;
729
730 filter = &peer->filter[afi][safi];
731
732 /* Route map apply. */
733 if (ROUTE_MAP_EXPORT_NAME (filter))
734 {
735 /* Duplicate current value to new strucutre for modification. */
736 info.peer = rsclient;
737 info.attr = attr;
738
739 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
740
741 /* Apply BGP route map to the attribute. */
742 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
743
744 rsclient->rmap_type = 0;
745
746 if (ret == RMAP_DENYMATCH)
747 {
748 /* Free newly generated AS path and community by route-map. */
749 bgp_attr_flush (attr);
750 return RMAP_DENY;
751 }
752 }
753 return RMAP_PERMIT;
754}
755
paul94f2b392005-06-28 12:44:16 +0000756static int
paulfee0f4c2004-09-13 05:12:46 +0000757bgp_import_modifier (struct peer *rsclient, struct peer *peer,
758 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
759{
760 struct bgp_filter *filter;
761 struct bgp_info info;
762 route_map_result_t ret;
763
764 filter = &rsclient->filter[afi][safi];
765
766 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000767 if (peer->weight)
768 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000769
770 /* Route map apply. */
771 if (ROUTE_MAP_IMPORT_NAME (filter))
772 {
773 /* Duplicate current value to new strucutre for modification. */
774 info.peer = peer;
775 info.attr = attr;
776
777 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
778
779 /* Apply BGP route map to the attribute. */
780 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
781
782 peer->rmap_type = 0;
783
784 if (ret == RMAP_DENYMATCH)
785 {
786 /* Free newly generated AS path and community by route-map. */
787 bgp_attr_flush (attr);
788 return RMAP_DENY;
789 }
790 }
791 return RMAP_PERMIT;
792}
David Lamparter6b0655a2014-06-04 06:53:35 +0200793
paul94f2b392005-06-28 12:44:16 +0000794static int
paul718e3742002-12-13 20:15:29 +0000795bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
796 struct attr *attr, afi_t afi, safi_t safi)
797{
798 int ret;
799 char buf[SU_ADDRSTRLEN];
800 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000801 struct peer *from;
802 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000803 int transparent;
804 int reflect;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700805 struct attr *riattr;
paul718e3742002-12-13 20:15:29 +0000806
807 from = ri->peer;
808 filter = &peer->filter[afi][safi];
809 bgp = peer->bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700810 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paul718e3742002-12-13 20:15:29 +0000811
Paul Jakma750e8142008-07-22 21:11:48 +0000812 if (DISABLE_BGP_ANNOUNCE)
813 return 0;
paul718e3742002-12-13 20:15:29 +0000814
paulfee0f4c2004-09-13 05:12:46 +0000815 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
816 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
817 return 0;
818
paul718e3742002-12-13 20:15:29 +0000819 /* Do not send back route to sender. */
820 if (from == peer)
821 return 0;
822
823 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000824 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000825 if (! UNSUPPRESS_MAP_NAME (filter))
826 return 0;
827
828 /* Default route check. */
829 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
830 {
831 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
832 return 0;
833#ifdef HAVE_IPV6
834 else if (p->family == AF_INET6 && p->prefixlen == 0)
835 return 0;
836#endif /* HAVE_IPV6 */
837 }
838
paul286e1e72003-08-08 00:24:31 +0000839 /* Transparency check. */
840 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
841 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
842 transparent = 1;
843 else
844 transparent = 0;
845
paul718e3742002-12-13 20:15:29 +0000846 /* If community is not disabled check the no-export and local. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700847 if (! transparent && bgp_community_filter (peer, riattr))
paul718e3742002-12-13 20:15:29 +0000848 return 0;
849
850 /* If the attribute has originator-id and it is same as remote
851 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700852 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paul718e3742002-12-13 20:15:29 +0000853 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700854 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000855 {
856 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000857 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000858 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
859 peer->host,
860 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
861 p->prefixlen);
862 return 0;
863 }
864 }
865
866 /* ORF prefix-list filter check */
867 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
868 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
869 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
870 if (peer->orf_plist[afi][safi])
871 {
872 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
873 return 0;
874 }
875
876 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700877 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
paul718e3742002-12-13 20:15:29 +0000878 {
879 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000880 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000881 "%s [Update:SEND] %s/%d is filtered",
882 peer->host,
883 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
884 p->prefixlen);
885 return 0;
886 }
887
888#ifdef BGP_SEND_ASPATH_CHECK
889 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700890 if (aspath_loop_check (riattr->aspath, peer->as))
paul718e3742002-12-13 20:15:29 +0000891 {
892 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000893 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400894 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000895 peer->host, peer->as);
896 return 0;
897 }
898#endif /* BGP_SEND_ASPATH_CHECK */
899
900 /* If we're a CONFED we need to loop check the CONFED ID too */
901 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
902 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700903 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
paul718e3742002-12-13 20:15:29 +0000904 {
905 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000906 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400907 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000908 peer->host,
909 bgp->confed_id);
910 return 0;
911 }
912 }
913
914 /* Route-Reflect check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000915 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +0000916 reflect = 1;
917 else
918 reflect = 0;
919
920 /* IBGP reflection check. */
921 if (reflect)
922 {
923 /* A route from a Client peer. */
924 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
925 {
926 /* Reflect to all the Non-Client peers and also to the
927 Client peers other than the originator. Originator check
928 is already done. So there is noting to do. */
929 /* no bgp client-to-client reflection check. */
930 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
931 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
932 return 0;
933 }
934 else
935 {
936 /* A route from a Non-client peer. Reflect to all other
937 clients. */
938 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
939 return 0;
940 }
941 }
Paul Jakma41367172007-08-06 15:24:51 +0000942
paul718e3742002-12-13 20:15:29 +0000943 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700944 bgp_attr_dup (attr, riattr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000945
paul718e3742002-12-13 20:15:29 +0000946 /* If local-preference is not set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000947 if ((peer->sort == BGP_PEER_IBGP
948 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000949 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
950 {
951 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
952 attr->local_pref = bgp->default_local_pref;
953 }
954
Pradosh Mohapatra689bb662013-09-07 07:13:37 +0000955 /* If originator-id is not set and the route is to be reflected,
956 set the originator id */
957 if (peer && from && peer->sort == BGP_PEER_IBGP &&
958 from->sort == BGP_PEER_IBGP &&
959 (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
960 {
961 attr->extra = bgp_attr_extra_get(attr);
962 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
963 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
964 }
965
paul718e3742002-12-13 20:15:29 +0000966 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000967 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000968 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
969 {
970 if (ri->peer != bgp->peer_self && ! transparent
971 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
972 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
973 }
974
975 /* next-hop-set */
Timo Teräs9e7a53c2014-04-24 10:22:37 +0300976 if (transparent
977 || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
paul718e3742002-12-13 20:15:29 +0000978 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
979 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000980#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000981 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000982 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000983#endif /* HAVE_IPV6 */
984 )))
paul718e3742002-12-13 20:15:29 +0000985 {
986 /* NEXT-HOP Unchanged. */
987 }
988 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
989 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
990#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000991 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000992 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000993#endif /* HAVE_IPV6 */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000994 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000995 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
996 {
997 /* Set IPv4 nexthop. */
998 if (p->family == AF_INET)
999 {
1000 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001001 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1002 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +00001003 else
1004 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1005 }
1006#ifdef HAVE_IPV6
1007 /* Set IPv6 nexthop. */
1008 if (p->family == AF_INET6)
1009 {
1010 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001011 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001012 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001013 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001014 }
1015#endif /* HAVE_IPV6 */
1016 }
1017
1018#ifdef HAVE_IPV6
1019 if (p->family == AF_INET6)
1020 {
paulfee0f4c2004-09-13 05:12:46 +00001021 /* Left nexthop_local unchanged if so configured. */
1022 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1023 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1024 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001025 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1026 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001027 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001028 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001029 }
1030
1031 /* Default nexthop_local treatment for non-RS-Clients */
1032 else
1033 {
paul718e3742002-12-13 20:15:29 +00001034 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001035 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001036
1037 /* Set link-local address for shared network peer. */
1038 if (peer->shared_network
1039 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1040 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001041 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001042 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001043 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001044 }
1045
1046 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1047 address.*/
1048 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001049 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001050
1051 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1052 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001053 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001054 }
paulfee0f4c2004-09-13 05:12:46 +00001055
1056 }
paul718e3742002-12-13 20:15:29 +00001057#endif /* HAVE_IPV6 */
1058
1059 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001060 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001061 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1062 && aspath_private_as_check (attr->aspath))
1063 attr->aspath = aspath_empty_get ();
1064
1065 /* Route map & unsuppress-map apply. */
1066 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001067 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001068 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001069 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001070 struct attr dummy_attr;
1071 struct attr_extra dummy_extra;
1072
1073 dummy_attr.extra = &dummy_extra;
1074
paul718e3742002-12-13 20:15:29 +00001075 info.peer = peer;
1076 info.attr = attr;
1077
1078 /* The route reflector is not allowed to modify the attributes
1079 of the reflected IBGP routes. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001080 if (from->sort == BGP_PEER_IBGP
1081 && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +00001082 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001083 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001084 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001085 }
paulac41b2a2003-08-12 05:32:27 +00001086
1087 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1088
Paul Jakmafb982c22007-05-04 20:15:47 +00001089 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001090 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1091 else
1092 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1093
paulac41b2a2003-08-12 05:32:27 +00001094 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001095
paul718e3742002-12-13 20:15:29 +00001096 if (ret == RMAP_DENYMATCH)
1097 {
1098 bgp_attr_flush (attr);
1099 return 0;
1100 }
1101 }
1102 return 1;
1103}
1104
paul94f2b392005-06-28 12:44:16 +00001105static int
paulfee0f4c2004-09-13 05:12:46 +00001106bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1107 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001108{
paulfee0f4c2004-09-13 05:12:46 +00001109 int ret;
1110 char buf[SU_ADDRSTRLEN];
1111 struct bgp_filter *filter;
1112 struct bgp_info info;
1113 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001114 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001115
1116 from = ri->peer;
1117 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001118 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001119
Paul Jakma750e8142008-07-22 21:11:48 +00001120 if (DISABLE_BGP_ANNOUNCE)
1121 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001122
1123 /* Do not send back route to sender. */
1124 if (from == rsclient)
1125 return 0;
1126
1127 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001128 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001129 if (! UNSUPPRESS_MAP_NAME (filter))
1130 return 0;
1131
1132 /* Default route check. */
1133 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1134 PEER_STATUS_DEFAULT_ORIGINATE))
1135 {
1136 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1137 return 0;
1138#ifdef HAVE_IPV6
1139 else if (p->family == AF_INET6 && p->prefixlen == 0)
1140 return 0;
1141#endif /* HAVE_IPV6 */
1142 }
1143
1144 /* If the attribute has originator-id and it is same as remote
1145 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001146 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001147 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001148 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001149 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001150 {
1151 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001152 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001153 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1154 rsclient->host,
1155 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1156 p->prefixlen);
1157 return 0;
1158 }
1159 }
1160
1161 /* ORF prefix-list filter check */
1162 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1163 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1164 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1165 if (rsclient->orf_plist[afi][safi])
1166 {
1167 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1168 return 0;
1169 }
1170
1171 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001172 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001173 {
1174 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001175 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001176 "%s [Update:SEND] %s/%d is filtered",
1177 rsclient->host,
1178 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1179 p->prefixlen);
1180 return 0;
1181 }
1182
1183#ifdef BGP_SEND_ASPATH_CHECK
1184 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001185 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001186 {
1187 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001188 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001189 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001190 rsclient->host, rsclient->as);
1191 return 0;
1192 }
1193#endif /* BGP_SEND_ASPATH_CHECK */
1194
1195 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001196 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001197
1198 /* next-hop-set */
1199 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1200#ifdef HAVE_IPV6
1201 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001202 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001203#endif /* HAVE_IPV6 */
1204 )
1205 {
1206 /* Set IPv4 nexthop. */
1207 if (p->family == AF_INET)
1208 {
1209 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001210 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001211 IPV4_MAX_BYTELEN);
1212 else
1213 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1214 }
1215#ifdef HAVE_IPV6
1216 /* Set IPv6 nexthop. */
1217 if (p->family == AF_INET6)
1218 {
1219 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001220 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001221 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001222 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001223 }
1224#endif /* HAVE_IPV6 */
1225 }
1226
1227#ifdef HAVE_IPV6
1228 if (p->family == AF_INET6)
1229 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001230 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001231
paulfee0f4c2004-09-13 05:12:46 +00001232 /* Left nexthop_local unchanged if so configured. */
1233 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1234 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1235 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001236 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1237 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001238 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001239 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001240 }
1241
1242 /* Default nexthop_local treatment for RS-Clients */
1243 else
1244 {
1245 /* Announcer and RS-Client are both in the same network */
1246 if (rsclient->shared_network && from->shared_network &&
1247 (rsclient->ifindex == from->ifindex))
1248 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001249 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1250 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001251 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001252 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001253 }
1254
1255 /* Set link-local address for shared network peer. */
1256 else if (rsclient->shared_network
1257 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1258 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001259 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001260 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001261 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001262 }
1263
1264 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001265 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001266 }
1267
1268 }
1269#endif /* HAVE_IPV6 */
1270
1271
1272 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001273 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001274 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1275 && aspath_private_as_check (attr->aspath))
1276 attr->aspath = aspath_empty_get ();
1277
1278 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001279 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001280 {
1281 info.peer = rsclient;
1282 info.attr = attr;
1283
1284 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1285
Paul Jakmafb982c22007-05-04 20:15:47 +00001286 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001287 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1288 else
1289 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1290
1291 rsclient->rmap_type = 0;
1292
1293 if (ret == RMAP_DENYMATCH)
1294 {
1295 bgp_attr_flush (attr);
1296 return 0;
1297 }
1298 }
1299
1300 return 1;
1301}
1302
1303struct bgp_info_pair
1304{
1305 struct bgp_info *old;
1306 struct bgp_info *new;
1307};
1308
paul94f2b392005-06-28 12:44:16 +00001309static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001310bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1311 struct bgp_maxpaths_cfg *mpath_cfg,
1312 struct bgp_info_pair *result)
paulfee0f4c2004-09-13 05:12:46 +00001313{
paul718e3742002-12-13 20:15:29 +00001314 struct bgp_info *new_select;
1315 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001316 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001317 struct bgp_info *ri1;
1318 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001319 struct bgp_info *nextri = NULL;
Josh Bailey96450fa2011-07-20 20:45:12 -07001320 int paths_eq, do_mpath;
1321 struct list mp_list;
1322
1323 bgp_mp_list_init (&mp_list);
1324 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1325 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1326
paul718e3742002-12-13 20:15:29 +00001327 /* bgp deterministic-med */
1328 new_select = NULL;
1329 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1330 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1331 {
1332 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1333 continue;
1334 if (BGP_INFO_HOLDDOWN (ri1))
1335 continue;
1336
1337 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001338 if (do_mpath)
1339 bgp_mp_list_add (&mp_list, ri1);
1340 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001341 if (ri1->next)
1342 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1343 {
1344 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1345 continue;
1346 if (BGP_INFO_HOLDDOWN (ri2))
1347 continue;
1348
1349 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1350 || aspath_cmp_left_confed (ri1->attr->aspath,
1351 ri2->attr->aspath))
1352 {
Josh Bailey6918e742011-07-20 20:48:20 -07001353 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1354 old_select = ri2;
Josh Bailey96450fa2011-07-20 20:45:12 -07001355 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
paul718e3742002-12-13 20:15:29 +00001356 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001357 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001358 new_select = ri2;
Josh Bailey6918e742011-07-20 20:48:20 -07001359 if (do_mpath && !paths_eq)
1360 {
1361 bgp_mp_list_clear (&mp_list);
1362 bgp_mp_list_add (&mp_list, ri2);
1363 }
paul718e3742002-12-13 20:15:29 +00001364 }
1365
Josh Bailey6918e742011-07-20 20:48:20 -07001366 if (do_mpath && paths_eq)
1367 bgp_mp_list_add (&mp_list, ri2);
1368
Paul Jakma1a392d42006-09-07 00:24:49 +00001369 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001370 }
1371 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001372 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1373 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001374
1375 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1376 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001377 }
1378
1379 /* Check old selected route and new selected route. */
1380 old_select = NULL;
1381 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001382 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001383 {
1384 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1385 old_select = ri;
1386
1387 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001388 {
1389 /* reap REMOVED routes, if needs be
1390 * selected route must stay for a while longer though
1391 */
1392 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1393 && (ri != old_select))
1394 bgp_info_reap (rn, ri);
1395
1396 continue;
1397 }
paul718e3742002-12-13 20:15:29 +00001398
1399 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1400 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1401 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001402 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001403 continue;
1404 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001405 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1406 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001407
Josh Bailey96450fa2011-07-20 20:45:12 -07001408 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1409 {
Josh Bailey6918e742011-07-20 20:48:20 -07001410 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1411 bgp_mp_dmed_deselect (new_select);
1412
Josh Bailey96450fa2011-07-20 20:45:12 -07001413 new_select = ri;
1414
1415 if (do_mpath && !paths_eq)
1416 {
1417 bgp_mp_list_clear (&mp_list);
1418 bgp_mp_list_add (&mp_list, ri);
1419 }
1420 }
Josh Bailey6918e742011-07-20 20:48:20 -07001421 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1422 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001423
1424 if (do_mpath && paths_eq)
1425 bgp_mp_list_add (&mp_list, ri);
paul718e3742002-12-13 20:15:29 +00001426 }
paulb40d9392005-08-22 22:34:41 +00001427
paulfee0f4c2004-09-13 05:12:46 +00001428
Josh Bailey6918e742011-07-20 20:48:20 -07001429 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1430 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
Josh Bailey96450fa2011-07-20 20:45:12 -07001431
Josh Bailey0b597ef2011-07-20 20:49:11 -07001432 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001433 bgp_mp_list_clear (&mp_list);
1434
1435 result->old = old_select;
1436 result->new = new_select;
1437
1438 return;
paulfee0f4c2004-09-13 05:12:46 +00001439}
1440
paul94f2b392005-06-28 12:44:16 +00001441static int
paulfee0f4c2004-09-13 05:12:46 +00001442bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001443 struct bgp_node *rn, afi_t afi, safi_t safi)
1444{
paulfee0f4c2004-09-13 05:12:46 +00001445 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001446 struct attr attr;
1447 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001448
1449 p = &rn->p;
1450
Paul Jakma9eda90c2007-08-30 13:36:17 +00001451 /* Announce route to Established peer. */
1452 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001453 return 0;
1454
Paul Jakma9eda90c2007-08-30 13:36:17 +00001455 /* Address family configuration check. */
1456 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001457 return 0;
1458
Paul Jakma9eda90c2007-08-30 13:36:17 +00001459 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001460 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1461 PEER_STATUS_ORF_WAIT_REFRESH))
1462 return 0;
1463
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001464 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1465 attr.extra = &extra;
1466
Avneesh Sachdev67174042012-08-17 08:19:49 -07001467 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001468 {
1469 case BGP_TABLE_MAIN:
1470 /* Announcement to peer->conf. If the route is filtered,
1471 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001472 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1473 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001474 else
1475 bgp_adj_out_unset (rn, peer, p, afi, safi);
1476 break;
1477 case BGP_TABLE_RSCLIENT:
1478 /* Announcement to peer->conf. If the route is filtered,
1479 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001480 if (selected &&
1481 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1482 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1483 else
1484 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001485 break;
1486 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001487
paulfee0f4c2004-09-13 05:12:46 +00001488 return 0;
paul200df112005-06-01 11:17:05 +00001489}
paulfee0f4c2004-09-13 05:12:46 +00001490
paul200df112005-06-01 11:17:05 +00001491struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001492{
paul200df112005-06-01 11:17:05 +00001493 struct bgp *bgp;
1494 struct bgp_node *rn;
1495 afi_t afi;
1496 safi_t safi;
1497};
1498
1499static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001500bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001501{
paul0fb58d52005-11-14 14:31:49 +00001502 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001503 struct bgp *bgp = pq->bgp;
1504 struct bgp_node *rn = pq->rn;
1505 afi_t afi = pq->afi;
1506 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001507 struct bgp_info *new_select;
1508 struct bgp_info *old_select;
1509 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001510 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001511 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001512
paulfee0f4c2004-09-13 05:12:46 +00001513 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001514 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001515 new_select = old_and_new.new;
1516 old_select = old_and_new.old;
1517
paul200df112005-06-01 11:17:05 +00001518 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1519 {
Chris Caputo228da422009-07-18 05:44:03 +00001520 if (rsclient->group)
1521 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1522 {
1523 /* Nothing to do. */
1524 if (old_select && old_select == new_select)
1525 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1526 continue;
paulfee0f4c2004-09-13 05:12:46 +00001527
Chris Caputo228da422009-07-18 05:44:03 +00001528 if (old_select)
1529 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1530 if (new_select)
1531 {
1532 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1533 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001534 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1535 }
paulfee0f4c2004-09-13 05:12:46 +00001536
Chris Caputo228da422009-07-18 05:44:03 +00001537 bgp_process_announce_selected (rsclient, new_select, rn,
1538 afi, safi);
1539 }
paul200df112005-06-01 11:17:05 +00001540 }
1541 else
1542 {
hassob7395792005-08-26 12:58:38 +00001543 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001544 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001545 if (new_select)
1546 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001547 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1548 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001549 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001550 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001551 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001552 }
paulfee0f4c2004-09-13 05:12:46 +00001553
paulb40d9392005-08-22 22:34:41 +00001554 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1555 bgp_info_reap (rn, old_select);
1556
paul200df112005-06-01 11:17:05 +00001557 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1558 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001559}
1560
paul200df112005-06-01 11:17:05 +00001561static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001562bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001563{
paul0fb58d52005-11-14 14:31:49 +00001564 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001565 struct bgp *bgp = pq->bgp;
1566 struct bgp_node *rn = pq->rn;
1567 afi_t afi = pq->afi;
1568 safi_t safi = pq->safi;
1569 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001570 struct bgp_info *new_select;
1571 struct bgp_info *old_select;
1572 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001573 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001574 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001575
paulfee0f4c2004-09-13 05:12:46 +00001576 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001577 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001578 old_select = old_and_new.old;
1579 new_select = old_and_new.new;
1580
1581 /* Nothing to do. */
1582 if (old_select && old_select == new_select)
1583 {
1584 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001585 {
Josh Bailey8196f132011-07-20 20:47:07 -07001586 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1587 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001588 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001589
Josh Bailey8196f132011-07-20 20:47:07 -07001590 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001591 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1592 return WQ_SUCCESS;
1593 }
paulfee0f4c2004-09-13 05:12:46 +00001594 }
paul718e3742002-12-13 20:15:29 +00001595
hasso338b3422005-02-23 14:27:24 +00001596 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001597 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001598 if (new_select)
1599 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001600 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1601 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001602 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001603 }
1604
1605
paul718e3742002-12-13 20:15:29 +00001606 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001607 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001608 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001609 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001610 }
1611
1612 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001613 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1614 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001615 {
1616 if (new_select
1617 && new_select->type == ZEBRA_ROUTE_BGP
1618 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001619 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001620 else
1621 {
1622 /* Withdraw the route from the kernel. */
1623 if (old_select
1624 && old_select->type == ZEBRA_ROUTE_BGP
1625 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001626 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001627 }
1628 }
paulb40d9392005-08-22 22:34:41 +00001629
1630 /* Reap old select bgp_info, it it has been removed */
1631 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1632 bgp_info_reap (rn, old_select);
1633
paul200df112005-06-01 11:17:05 +00001634 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1635 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001636}
1637
paul200df112005-06-01 11:17:05 +00001638static void
paul0fb58d52005-11-14 14:31:49 +00001639bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001640{
paul0fb58d52005-11-14 14:31:49 +00001641 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001642 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001643
Chris Caputo228da422009-07-18 05:44:03 +00001644 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001645 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001646 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001647 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1648}
1649
1650static void
1651bgp_process_queue_init (void)
1652{
1653 bm->process_main_queue
1654 = work_queue_new (bm->master, "process_main_queue");
1655 bm->process_rsclient_queue
1656 = work_queue_new (bm->master, "process_rsclient_queue");
1657
1658 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1659 {
1660 zlog_err ("%s: Failed to allocate work queue", __func__);
1661 exit (1);
1662 }
1663
1664 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001665 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001666 bm->process_main_queue->spec.max_retries = 0;
1667 bm->process_main_queue->spec.hold = 50;
1668
Paul Jakma838bbde2010-01-08 14:05:32 +00001669 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
David Lamparterd43f8b32015-03-03 08:54:54 +01001670 bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del;
1671 bm->process_rsclient_queue->spec.max_retries = 0;
1672 bm->process_rsclient_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001673}
1674
1675void
paulfee0f4c2004-09-13 05:12:46 +00001676bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1677{
paul200df112005-06-01 11:17:05 +00001678 struct bgp_process_queue *pqnode;
1679
1680 /* already scheduled for processing? */
1681 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1682 return;
1683
1684 if ( (bm->process_main_queue == NULL) ||
1685 (bm->process_rsclient_queue == NULL) )
1686 bgp_process_queue_init ();
1687
1688 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1689 sizeof (struct bgp_process_queue));
1690 if (!pqnode)
1691 return;
Chris Caputo228da422009-07-18 05:44:03 +00001692
1693 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001694 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001695 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001696 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001697 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001698 pqnode->afi = afi;
1699 pqnode->safi = safi;
1700
Avneesh Sachdev67174042012-08-17 08:19:49 -07001701 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001702 {
paul200df112005-06-01 11:17:05 +00001703 case BGP_TABLE_MAIN:
1704 work_queue_add (bm->process_main_queue, pqnode);
1705 break;
1706 case BGP_TABLE_RSCLIENT:
1707 work_queue_add (bm->process_rsclient_queue, pqnode);
1708 break;
paulfee0f4c2004-09-13 05:12:46 +00001709 }
paul200df112005-06-01 11:17:05 +00001710
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001711 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001712 return;
paulfee0f4c2004-09-13 05:12:46 +00001713}
hasso0a486e52005-02-01 20:57:17 +00001714
paul94f2b392005-06-28 12:44:16 +00001715static int
hasso0a486e52005-02-01 20:57:17 +00001716bgp_maximum_prefix_restart_timer (struct thread *thread)
1717{
1718 struct peer *peer;
1719
1720 peer = THREAD_ARG (thread);
1721 peer->t_pmax_restart = NULL;
1722
1723 if (BGP_DEBUG (events, EVENTS))
1724 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1725 peer->host);
1726
1727 peer_clear (peer);
1728
1729 return 0;
1730}
1731
paulfee0f4c2004-09-13 05:12:46 +00001732int
paul5228ad22004-06-04 17:58:18 +00001733bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1734 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001735{
hassoe0701b72004-05-20 09:19:34 +00001736 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1737 return 0;
1738
1739 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001740 {
hassoe0701b72004-05-20 09:19:34 +00001741 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1742 && ! always)
1743 return 0;
paul718e3742002-12-13 20:15:29 +00001744
hassoe0701b72004-05-20 09:19:34 +00001745 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001746 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1747 "limit %ld", afi_safi_print (afi, safi), peer->host,
1748 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001749 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001750
hassoe0701b72004-05-20 09:19:34 +00001751 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1752 return 0;
paul718e3742002-12-13 20:15:29 +00001753
hassoe0701b72004-05-20 09:19:34 +00001754 {
paul5228ad22004-06-04 17:58:18 +00001755 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001756
1757 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001758 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001759
1760 ndata[0] = (afi >> 8);
1761 ndata[1] = afi;
1762 ndata[2] = safi;
1763 ndata[3] = (peer->pmax[afi][safi] >> 24);
1764 ndata[4] = (peer->pmax[afi][safi] >> 16);
1765 ndata[5] = (peer->pmax[afi][safi] >> 8);
1766 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001767
1768 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1769 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1770 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1771 }
hasso0a486e52005-02-01 20:57:17 +00001772
1773 /* restart timer start */
1774 if (peer->pmax_restart[afi][safi])
1775 {
1776 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1777
1778 if (BGP_DEBUG (events, EVENTS))
1779 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1780 peer->host, peer->v_pmax_restart);
1781
1782 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1783 peer->v_pmax_restart);
1784 }
1785
hassoe0701b72004-05-20 09:19:34 +00001786 return 1;
paul718e3742002-12-13 20:15:29 +00001787 }
hassoe0701b72004-05-20 09:19:34 +00001788 else
1789 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1790
1791 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1792 {
1793 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1794 && ! always)
1795 return 0;
1796
1797 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001798 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1799 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1800 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001801 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1802 }
1803 else
1804 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001805 return 0;
1806}
1807
paulb40d9392005-08-22 22:34:41 +00001808/* Unconditionally remove the route from the RIB, without taking
1809 * damping into consideration (eg, because the session went down)
1810 */
paul94f2b392005-06-28 12:44:16 +00001811static void
paul718e3742002-12-13 20:15:29 +00001812bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1813 afi_t afi, safi_t safi)
1814{
paul902212c2006-02-05 17:51:19 +00001815 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1816
1817 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1818 bgp_info_delete (rn, ri); /* keep historical info */
1819
paulb40d9392005-08-22 22:34:41 +00001820 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001821}
1822
paul94f2b392005-06-28 12:44:16 +00001823static void
paul718e3742002-12-13 20:15:29 +00001824bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001825 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001826{
paul718e3742002-12-13 20:15:29 +00001827 int status = BGP_DAMP_NONE;
1828
paulb40d9392005-08-22 22:34:41 +00001829 /* apply dampening, if result is suppressed, we'll be retaining
1830 * the bgp_info in the RIB for historical reference.
1831 */
1832 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001833 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001834 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1835 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001836 {
paul902212c2006-02-05 17:51:19 +00001837 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1838 return;
1839 }
1840
1841 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001842}
1843
paul94f2b392005-06-28 12:44:16 +00001844static void
paulfee0f4c2004-09-13 05:12:46 +00001845bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1846 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1847 int sub_type, struct prefix_rd *prd, u_char *tag)
1848{
1849 struct bgp_node *rn;
1850 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001851 struct attr new_attr;
1852 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001853 struct attr *attr_new;
1854 struct attr *attr_new2;
1855 struct bgp_info *ri;
1856 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001857 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001858 char buf[SU_ADDRSTRLEN];
1859
1860 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1861 if (peer == rsclient)
1862 return;
1863
1864 bgp = peer->bgp;
1865 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1866
1867 /* Check previously received route. */
1868 for (ri = rn->info; ri; ri = ri->next)
1869 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1870 break;
1871
1872 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001873 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001874 {
1875 reason = "as-path contains our own AS;";
1876 goto filtered;
1877 }
1878
1879 /* Route reflector originator ID check. */
1880 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001881 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001882 {
1883 reason = "originator is us;";
1884 goto filtered;
1885 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001886
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001887 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001888 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001889
1890 /* Apply export policy. */
1891 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1892 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1893 {
1894 reason = "export-policy;";
1895 goto filtered;
1896 }
1897
1898 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001899
paulfee0f4c2004-09-13 05:12:46 +00001900 /* Apply import policy. */
1901 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1902 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001903 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001904
1905 reason = "import-policy;";
1906 goto filtered;
1907 }
1908
1909 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001910 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001911
1912 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001913 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001914 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001915 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001916 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001917 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001918 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001919 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001920
1921 reason = "martian next-hop;";
1922 goto filtered;
1923 }
1924 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001925
paulfee0f4c2004-09-13 05:12:46 +00001926 /* If the update is implicit withdraw. */
1927 if (ri)
1928 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001929 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001930
1931 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001932 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1933 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001934 {
1935
Paul Jakma1a392d42006-09-07 00:24:49 +00001936 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001937
1938 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001939 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001940 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1941 peer->host,
1942 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1943 p->prefixlen, rsclient->host);
1944
Chris Caputo228da422009-07-18 05:44:03 +00001945 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001946 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001947
Chris Caputo228da422009-07-18 05:44:03 +00001948 return;
paulfee0f4c2004-09-13 05:12:46 +00001949 }
1950
Paul Jakma16d2e242007-04-10 19:32:10 +00001951 /* Withdraw/Announce before we fully processed the withdraw */
1952 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1953 bgp_info_restore (rn, ri);
1954
paulfee0f4c2004-09-13 05:12:46 +00001955 /* Received Logging. */
1956 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001957 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001958 peer->host,
1959 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1960 p->prefixlen, rsclient->host);
1961
1962 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001963 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001964
1965 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001966 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001967 ri->attr = attr_new;
1968
1969 /* Update MPLS tag. */
1970 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001971 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001972
Paul Jakma1a392d42006-09-07 00:24:49 +00001973 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001974
1975 /* Process change. */
1976 bgp_process (bgp, rn, afi, safi);
1977 bgp_unlock_node (rn);
1978
1979 return;
1980 }
1981
1982 /* Received Logging. */
1983 if (BGP_DEBUG (update, UPDATE_IN))
1984 {
ajsd2c1f162004-12-08 21:10:20 +00001985 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001986 peer->host,
1987 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1988 p->prefixlen, rsclient->host);
1989 }
1990
1991 /* Make new BGP info. */
1992 new = bgp_info_new ();
1993 new->type = type;
1994 new->sub_type = sub_type;
1995 new->peer = peer;
1996 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03001997 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001998
1999 /* Update MPLS tag. */
2000 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002001 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002002
Paul Jakma1a392d42006-09-07 00:24:49 +00002003 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002004
2005 /* Register new BGP information. */
2006 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002007
2008 /* route_node_get lock */
2009 bgp_unlock_node (rn);
2010
paulfee0f4c2004-09-13 05:12:46 +00002011 /* Process change. */
2012 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002013
paulfee0f4c2004-09-13 05:12:46 +00002014 return;
2015
2016 filtered:
2017
2018 /* This BGP update is filtered. Log the reason then update BGP entry. */
2019 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002020 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002021 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2022 peer->host,
2023 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2024 p->prefixlen, rsclient->host, reason);
2025
2026 if (ri)
paulb40d9392005-08-22 22:34:41 +00002027 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002028
2029 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002030
paulfee0f4c2004-09-13 05:12:46 +00002031 return;
2032}
2033
paul94f2b392005-06-28 12:44:16 +00002034static void
paulfee0f4c2004-09-13 05:12:46 +00002035bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2036 struct peer *peer, struct prefix *p, int type, int sub_type,
2037 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002038{
paulfee0f4c2004-09-13 05:12:46 +00002039 struct bgp_node *rn;
2040 struct bgp_info *ri;
2041 char buf[SU_ADDRSTRLEN];
2042
2043 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002044 return;
paulfee0f4c2004-09-13 05:12:46 +00002045
2046 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2047
2048 /* Lookup withdrawn route. */
2049 for (ri = rn->info; ri; ri = ri->next)
2050 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2051 break;
2052
2053 /* Withdraw specified route from routing table. */
2054 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002055 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002056 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002057 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002058 "%s Can't find the route %s/%d", peer->host,
2059 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2060 p->prefixlen);
2061
2062 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002063 bgp_unlock_node (rn);
2064}
paulfee0f4c2004-09-13 05:12:46 +00002065
paul94f2b392005-06-28 12:44:16 +00002066static int
paulfee0f4c2004-09-13 05:12:46 +00002067bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002068 afi_t afi, safi_t safi, int type, int sub_type,
2069 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2070{
2071 int ret;
2072 int aspath_loop_count = 0;
2073 struct bgp_node *rn;
2074 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002075 struct attr new_attr;
2076 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002077 struct attr *attr_new;
2078 struct bgp_info *ri;
2079 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002080 const char *reason;
paul718e3742002-12-13 20:15:29 +00002081 char buf[SU_ADDRSTRLEN];
2082
2083 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002084 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002085
paul718e3742002-12-13 20:15:29 +00002086 /* When peer's soft reconfiguration enabled. Record input packet in
2087 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002088 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2089 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002090 bgp_adj_in_set (rn, peer, attr);
2091
2092 /* Check previously received route. */
2093 for (ri = rn->info; ri; ri = ri->next)
2094 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2095 break;
2096
2097 /* AS path local-as loop check. */
2098 if (peer->change_local_as)
2099 {
2100 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2101 aspath_loop_count = 1;
2102
2103 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2104 {
2105 reason = "as-path contains our own AS;";
2106 goto filtered;
2107 }
2108 }
2109
2110 /* AS path loop check. */
2111 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2112 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2113 && aspath_loop_check(attr->aspath, bgp->confed_id)
2114 > peer->allowas_in[afi][safi]))
2115 {
2116 reason = "as-path contains our own AS;";
2117 goto filtered;
2118 }
2119
2120 /* Route reflector originator ID check. */
2121 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002122 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002123 {
2124 reason = "originator is us;";
2125 goto filtered;
2126 }
2127
2128 /* Route reflector cluster ID check. */
2129 if (bgp_cluster_filter (peer, attr))
2130 {
2131 reason = "reflected from the same cluster;";
2132 goto filtered;
2133 }
2134
2135 /* Apply incoming filter. */
2136 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2137 {
2138 reason = "filter;";
2139 goto filtered;
2140 }
2141
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002142 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002143 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002144
David Lamparterc460e572014-06-04 00:54:58 +02002145 /* Apply incoming route-map.
2146 * NB: new_attr may now contain newly allocated values from route-map "set"
2147 * commands, so we need bgp_attr_flush in the error paths, until we intern
2148 * the attr (which takes over the memory references) */
paul718e3742002-12-13 20:15:29 +00002149 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2150 {
2151 reason = "route-map;";
David Lamparterc460e572014-06-04 00:54:58 +02002152 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002153 goto filtered;
2154 }
2155
2156 /* IPv4 unicast next hop check. */
2157 if (afi == AFI_IP && safi == SAFI_UNICAST)
2158 {
2159 /* If the peer is EBGP and nexthop is not on connected route,
2160 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002161 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002162 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002163 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002164 {
2165 reason = "non-connected next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002166 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002167 goto filtered;
2168 }
2169
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002170 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002171 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002172 if (new_attr.nexthop.s_addr == 0
2173 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2174 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002175 {
2176 reason = "martian next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002177 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002178 goto filtered;
2179 }
2180 }
2181
2182 attr_new = bgp_attr_intern (&new_attr);
2183
2184 /* If the update is implicit withdraw. */
2185 if (ri)
2186 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002187 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002188
2189 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002190 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2191 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002192 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002193 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002194
2195 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002196 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002197 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2198 {
2199 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002200 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002201 peer->host,
2202 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2203 p->prefixlen);
2204
paul902212c2006-02-05 17:51:19 +00002205 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2206 {
2207 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2208 bgp_process (bgp, rn, afi, safi);
2209 }
paul718e3742002-12-13 20:15:29 +00002210 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002211 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002212 {
2213 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002214 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002215 "%s rcvd %s/%d...duplicate ignored",
2216 peer->host,
2217 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2218 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002219
2220 /* graceful restart STALE flag unset. */
2221 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2222 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002223 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002224 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002225 }
paul718e3742002-12-13 20:15:29 +00002226 }
2227
2228 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002229 bgp_attr_unintern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002230
paul718e3742002-12-13 20:15:29 +00002231 return 0;
2232 }
2233
Paul Jakma16d2e242007-04-10 19:32:10 +00002234 /* Withdraw/Announce before we fully processed the withdraw */
2235 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2236 {
2237 if (BGP_DEBUG (update, UPDATE_IN))
2238 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2239 peer->host,
2240 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2241 p->prefixlen);
2242 bgp_info_restore (rn, ri);
2243 }
2244
paul718e3742002-12-13 20:15:29 +00002245 /* Received Logging. */
2246 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002247 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002248 peer->host,
2249 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2250 p->prefixlen);
2251
hasso93406d82005-02-02 14:40:33 +00002252 /* graceful restart STALE flag unset. */
2253 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002254 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002255
paul718e3742002-12-13 20:15:29 +00002256 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002257 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002258
2259 /* implicit withdraw, decrement aggregate and pcount here.
2260 * only if update is accepted, they'll increment below.
2261 */
paul902212c2006-02-05 17:51:19 +00002262 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2263
paul718e3742002-12-13 20:15:29 +00002264 /* Update bgp route dampening information. */
2265 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002266 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002267 {
2268 /* This is implicit withdraw so we should update dampening
2269 information. */
2270 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2271 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002272 }
2273
paul718e3742002-12-13 20:15:29 +00002274 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002275 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002276 ri->attr = attr_new;
2277
2278 /* Update MPLS tag. */
2279 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002280 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002281
2282 /* Update bgp route dampening information. */
2283 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002284 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002285 {
2286 /* Now we do normal update dampening. */
2287 ret = bgp_damp_update (ri, rn, afi, safi);
2288 if (ret == BGP_DAMP_SUPPRESSED)
2289 {
2290 bgp_unlock_node (rn);
2291 return 0;
2292 }
2293 }
2294
2295 /* Nexthop reachability check. */
2296 if ((afi == AFI_IP || afi == AFI_IP6)
2297 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002298 && (peer->sort == BGP_PEER_IBGP
2299 || peer->sort == BGP_PEER_CONFED
2300 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002301 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002302 {
2303 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002304 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002305 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002306 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002307 }
2308 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002309 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002310
2311 /* Process change. */
2312 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2313
2314 bgp_process (bgp, rn, afi, safi);
2315 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002316
paul718e3742002-12-13 20:15:29 +00002317 return 0;
2318 }
2319
2320 /* Received Logging. */
2321 if (BGP_DEBUG (update, UPDATE_IN))
2322 {
ajsd2c1f162004-12-08 21:10:20 +00002323 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002324 peer->host,
2325 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2326 p->prefixlen);
2327 }
2328
paul718e3742002-12-13 20:15:29 +00002329 /* Make new BGP info. */
2330 new = bgp_info_new ();
2331 new->type = type;
2332 new->sub_type = sub_type;
2333 new->peer = peer;
2334 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002335 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002336
2337 /* Update MPLS tag. */
2338 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002339 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002340
2341 /* Nexthop reachability check. */
2342 if ((afi == AFI_IP || afi == AFI_IP6)
2343 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002344 && (peer->sort == BGP_PEER_IBGP
2345 || peer->sort == BGP_PEER_CONFED
2346 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002347 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002348 {
2349 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002350 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002351 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002352 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002353 }
2354 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002355 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002356
paul902212c2006-02-05 17:51:19 +00002357 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002358 bgp_aggregate_increment (bgp, p, new, afi, safi);
2359
2360 /* Register new BGP information. */
2361 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002362
2363 /* route_node_get lock */
2364 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002365
paul718e3742002-12-13 20:15:29 +00002366 /* If maximum prefix count is configured and current prefix
2367 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002368 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2369 return -1;
paul718e3742002-12-13 20:15:29 +00002370
2371 /* Process change. */
2372 bgp_process (bgp, rn, afi, safi);
2373
2374 return 0;
2375
2376 /* This BGP update is filtered. Log the reason then update BGP
2377 entry. */
2378 filtered:
2379 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002380 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002381 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2382 peer->host,
2383 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2384 p->prefixlen, reason);
2385
2386 if (ri)
paulb40d9392005-08-22 22:34:41 +00002387 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002388
2389 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002390
paul718e3742002-12-13 20:15:29 +00002391 return 0;
2392}
2393
2394int
paulfee0f4c2004-09-13 05:12:46 +00002395bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2396 afi_t afi, safi_t safi, int type, int sub_type,
2397 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2398{
2399 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002400 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002401 struct bgp *bgp;
2402 int ret;
2403
2404 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2405 soft_reconfig);
2406
2407 bgp = peer->bgp;
2408
2409 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002410 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002411 {
2412 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2413 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2414 sub_type, prd, tag);
2415 }
2416
2417 return ret;
2418}
2419
2420int
paul718e3742002-12-13 20:15:29 +00002421bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002422 afi_t afi, safi_t safi, int type, int sub_type,
2423 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002424{
2425 struct bgp *bgp;
2426 char buf[SU_ADDRSTRLEN];
2427 struct bgp_node *rn;
2428 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002429 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002430 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002431
2432 bgp = peer->bgp;
2433
paulfee0f4c2004-09-13 05:12:46 +00002434 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002435 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002436 {
2437 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2438 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2439 }
2440
paul718e3742002-12-13 20:15:29 +00002441 /* Logging. */
2442 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002443 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002444 peer->host,
2445 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2446 p->prefixlen);
2447
2448 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002449 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002450
2451 /* If peer is soft reconfiguration enabled. Record input packet for
2452 further calculation. */
2453 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2454 && peer != bgp->peer_self)
2455 bgp_adj_in_unset (rn, peer);
2456
2457 /* Lookup withdrawn route. */
2458 for (ri = rn->info; ri; ri = ri->next)
2459 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2460 break;
2461
2462 /* Withdraw specified route from routing table. */
2463 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002464 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002465 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002466 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002467 "%s Can't find the route %s/%d", peer->host,
2468 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2469 p->prefixlen);
2470
2471 /* Unlock bgp_node_get() lock. */
2472 bgp_unlock_node (rn);
2473
2474 return 0;
2475}
David Lamparter6b0655a2014-06-04 06:53:35 +02002476
paul718e3742002-12-13 20:15:29 +00002477void
2478bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2479{
2480 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002481 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002482 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002483 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002484 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002485 struct bgp_node *rn;
2486 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002487 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002488
Paul Jakmab2497022007-06-14 11:17:58 +00002489 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002490 return;
2491
paul718e3742002-12-13 20:15:29 +00002492 bgp = peer->bgp;
2493 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002494
paul718e3742002-12-13 20:15:29 +00002495 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2496 aspath = attr.aspath;
2497 attr.local_pref = bgp->default_local_pref;
2498 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2499
2500 if (afi == AFI_IP)
2501 str2prefix ("0.0.0.0/0", &p);
2502#ifdef HAVE_IPV6
2503 else if (afi == AFI_IP6)
2504 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002505 struct attr_extra *ae = attr.extra;
2506
paul718e3742002-12-13 20:15:29 +00002507 str2prefix ("::/0", &p);
2508
2509 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002510 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002511 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002512 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002513
2514 /* If the peer is on shared nextwork and we have link-local
2515 nexthop set it. */
2516 if (peer->shared_network
2517 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2518 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002519 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002520 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002521 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002522 }
2523 }
2524#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002525
2526 if (peer->default_rmap[afi][safi].name)
2527 {
paulfee0f4c2004-09-13 05:12:46 +00002528 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002529 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2530 {
2531 for (ri = rn->info; ri; ri = ri->next)
2532 {
2533 struct attr dummy_attr;
2534 struct attr_extra dummy_extra;
2535 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002536
Christian Frankedcab1bb2012-12-07 16:45:52 +00002537 /* Provide dummy so the route-map can't modify the attributes */
2538 dummy_attr.extra = &dummy_extra;
2539 bgp_attr_dup(&dummy_attr, ri->attr);
2540 info.peer = ri->peer;
2541 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002542
Christian Frankedcab1bb2012-12-07 16:45:52 +00002543 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2544 RMAP_BGP, &info);
2545
2546 /* The route map might have set attributes. If we don't flush them
2547 * here, they will be leaked. */
2548 bgp_attr_flush(&dummy_attr);
2549 if (ret != RMAP_DENYMATCH)
2550 break;
2551 }
2552 if (ret != RMAP_DENYMATCH)
2553 break;
2554 }
paulfee0f4c2004-09-13 05:12:46 +00002555 bgp->peer_self->rmap_type = 0;
2556
paul718e3742002-12-13 20:15:29 +00002557 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002558 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002559 }
2560
2561 if (withdraw)
2562 {
2563 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2564 bgp_default_withdraw_send (peer, afi, safi);
2565 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2566 }
2567 else
2568 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002569 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2570 {
2571 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2572 bgp_default_update_send (peer, &attr, afi, safi, from);
2573 }
paul718e3742002-12-13 20:15:29 +00002574 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002575
2576 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002577 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002578}
David Lamparter6b0655a2014-06-04 06:53:35 +02002579
paul718e3742002-12-13 20:15:29 +00002580static void
2581bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002582 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002583{
2584 struct bgp_node *rn;
2585 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002586 struct attr attr;
2587 struct attr_extra extra;
2588
paul718e3742002-12-13 20:15:29 +00002589 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002590 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002591
2592 if (safi != SAFI_MPLS_VPN
2593 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2594 bgp_default_originate (peer, afi, safi, 0);
2595
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002596 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2597 attr.extra = &extra;
2598
paul718e3742002-12-13 20:15:29 +00002599 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2600 for (ri = rn->info; ri; ri = ri->next)
2601 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2602 {
paulfee0f4c2004-09-13 05:12:46 +00002603 if ( (rsclient) ?
2604 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2605 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002606 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2607 else
2608 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2609 }
2610}
2611
2612void
2613bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2614{
2615 struct bgp_node *rn;
2616 struct bgp_table *table;
2617
2618 if (peer->status != Established)
2619 return;
2620
2621 if (! peer->afc_nego[afi][safi])
2622 return;
2623
2624 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2625 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2626 return;
2627
2628 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002629 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002630 else
2631 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2632 rn = bgp_route_next(rn))
2633 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002634 bgp_announce_table (peer, afi, safi, table, 0);
2635
2636 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2637 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002638}
2639
2640void
2641bgp_announce_route_all (struct peer *peer)
2642{
2643 afi_t afi;
2644 safi_t safi;
2645
2646 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2647 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2648 bgp_announce_route (peer, afi, safi);
2649}
David Lamparter6b0655a2014-06-04 06:53:35 +02002650
paul718e3742002-12-13 20:15:29 +00002651static void
paulfee0f4c2004-09-13 05:12:46 +00002652bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002653 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002654{
2655 struct bgp_node *rn;
2656 struct bgp_adj_in *ain;
2657
2658 if (! table)
2659 table = rsclient->bgp->rib[afi][safi];
2660
2661 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2662 for (ain = rn->adj_in; ain; ain = ain->next)
2663 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002664 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002665 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002666
paulfee0f4c2004-09-13 05:12:46 +00002667 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002668 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002669 }
2670}
2671
2672void
2673bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2674{
2675 struct bgp_table *table;
2676 struct bgp_node *rn;
2677
2678 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002679 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002680
2681 else
2682 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2683 rn = bgp_route_next (rn))
2684 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002685 {
2686 struct prefix_rd prd;
2687 prd.family = AF_UNSPEC;
2688 prd.prefixlen = 64;
2689 memcpy(&prd.val, rn->p.u.val, 8);
2690
2691 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2692 }
paulfee0f4c2004-09-13 05:12:46 +00002693}
David Lamparter6b0655a2014-06-04 06:53:35 +02002694
paulfee0f4c2004-09-13 05:12:46 +00002695static void
paul718e3742002-12-13 20:15:29 +00002696bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002697 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002698{
2699 int ret;
2700 struct bgp_node *rn;
2701 struct bgp_adj_in *ain;
2702
2703 if (! table)
2704 table = peer->bgp->rib[afi][safi];
2705
2706 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2707 for (ain = rn->adj_in; ain; ain = ain->next)
2708 {
2709 if (ain->peer == peer)
2710 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002711 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002712 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002713
paul718e3742002-12-13 20:15:29 +00002714 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2715 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002716 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002717
paul718e3742002-12-13 20:15:29 +00002718 if (ret < 0)
2719 {
2720 bgp_unlock_node (rn);
2721 return;
2722 }
2723 continue;
2724 }
2725 }
2726}
2727
2728void
2729bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2730{
2731 struct bgp_node *rn;
2732 struct bgp_table *table;
2733
2734 if (peer->status != Established)
2735 return;
2736
2737 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002738 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002739 else
2740 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2741 rn = bgp_route_next (rn))
2742 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002743 {
2744 struct prefix_rd prd;
2745 prd.family = AF_UNSPEC;
2746 prd.prefixlen = 64;
2747 memcpy(&prd.val, rn->p.u.val, 8);
2748
2749 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2750 }
paul718e3742002-12-13 20:15:29 +00002751}
David Lamparter6b0655a2014-06-04 06:53:35 +02002752
Chris Caputo228da422009-07-18 05:44:03 +00002753
2754struct bgp_clear_node_queue
2755{
2756 struct bgp_node *rn;
2757 enum bgp_clear_route_type purpose;
2758};
2759
paul200df112005-06-01 11:17:05 +00002760static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002761bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002762{
Chris Caputo228da422009-07-18 05:44:03 +00002763 struct bgp_clear_node_queue *cnq = data;
2764 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002765 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002766 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002767 afi_t afi = bgp_node_table (rn)->afi;
2768 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002769
Paul Jakma64e580a2006-02-21 01:09:01 +00002770 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002771
Paul Jakma64e580a2006-02-21 01:09:01 +00002772 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002773 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002774 {
2775 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002776 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2777 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002778 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002779 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2780 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002781 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002782 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002783 break;
2784 }
paul200df112005-06-01 11:17:05 +00002785 return WQ_SUCCESS;
2786}
2787
2788static void
paul0fb58d52005-11-14 14:31:49 +00002789bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002790{
Chris Caputo228da422009-07-18 05:44:03 +00002791 struct bgp_clear_node_queue *cnq = data;
2792 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002793 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002794
2795 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002796 bgp_table_unlock (table);
2797 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002798}
2799
2800static void
paul94f2b392005-06-28 12:44:16 +00002801bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002802{
Paul Jakma64e580a2006-02-21 01:09:01 +00002803 struct peer *peer = wq->spec.data;
2804
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002805 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002806 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002807
2808 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002809}
2810
2811static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002812bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002813{
Paul Jakmaa2943652009-07-21 14:02:04 +01002814 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002815
Paul Jakmaa2943652009-07-21 14:02:04 +01002816 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002817#undef CLEAR_QUEUE_NAME_LEN
2818
2819 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002820 {
2821 zlog_err ("%s: Failed to allocate work queue", __func__);
2822 exit (1);
2823 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002824 peer->clear_node_queue->spec.hold = 10;
2825 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2826 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2827 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2828 peer->clear_node_queue->spec.max_retries = 0;
2829
2830 /* we only 'lock' this peer reference when the queue is actually active */
2831 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002832}
2833
paul718e3742002-12-13 20:15:29 +00002834static void
2835bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002836 struct bgp_table *table, struct peer *rsclient,
2837 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002838{
2839 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002840
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002841
paul718e3742002-12-13 20:15:29 +00002842 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002843 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002844
hasso6cf159b2005-03-21 10:28:14 +00002845 /* If still no table => afi/safi isn't configured at all or smth. */
2846 if (! table)
2847 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002848
2849 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2850 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002851 struct bgp_info *ri;
2852 struct bgp_adj_in *ain;
2853 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002854
2855 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2856 * queued for every clearing peer, regardless of whether it is
2857 * relevant to the peer at hand.
2858 *
2859 * Overview: There are 3 different indices which need to be
2860 * scrubbed, potentially, when a peer is removed:
2861 *
2862 * 1 peer's routes visible via the RIB (ie accepted routes)
2863 * 2 peer's routes visible by the (optional) peer's adj-in index
2864 * 3 other routes visible by the peer's adj-out index
2865 *
2866 * 3 there is no hurry in scrubbing, once the struct peer is
2867 * removed from bgp->peer, we could just GC such deleted peer's
2868 * adj-outs at our leisure.
2869 *
2870 * 1 and 2 must be 'scrubbed' in some way, at least made
2871 * invisible via RIB index before peer session is allowed to be
2872 * brought back up. So one needs to know when such a 'search' is
2873 * complete.
2874 *
2875 * Ideally:
2876 *
2877 * - there'd be a single global queue or a single RIB walker
2878 * - rather than tracking which route_nodes still need to be
2879 * examined on a peer basis, we'd track which peers still
2880 * aren't cleared
2881 *
2882 * Given that our per-peer prefix-counts now should be reliable,
2883 * this may actually be achievable. It doesn't seem to be a huge
2884 * problem at this time,
2885 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002886 for (ain = rn->adj_in; ain; ain = ain->next)
2887 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2888 {
2889 bgp_adj_in_remove (rn, ain);
2890 bgp_unlock_node (rn);
2891 break;
2892 }
2893 for (aout = rn->adj_out; aout; aout = aout->next)
2894 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2895 {
2896 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2897 bgp_unlock_node (rn);
2898 break;
2899 }
2900
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002901 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002902 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002903 {
Chris Caputo228da422009-07-18 05:44:03 +00002904 struct bgp_clear_node_queue *cnq;
2905
2906 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002907 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002908 bgp_lock_node (rn);
2909 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2910 sizeof (struct bgp_clear_node_queue));
2911 cnq->rn = rn;
2912 cnq->purpose = purpose;
2913 work_queue_add (peer->clear_node_queue, cnq);
2914 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002915 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002916 }
2917 return;
2918}
2919
2920void
Chris Caputo228da422009-07-18 05:44:03 +00002921bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2922 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002923{
2924 struct bgp_node *rn;
2925 struct bgp_table *table;
2926 struct peer *rsclient;
2927 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002928
Paul Jakma64e580a2006-02-21 01:09:01 +00002929 if (peer->clear_node_queue == NULL)
2930 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002931
Paul Jakmaca058a32006-09-14 02:58:49 +00002932 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2933 * Idle until it receives a Clearing_Completed event. This protects
2934 * against peers which flap faster than we can we clear, which could
2935 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002936 *
2937 * a) race with routes from the new session being installed before
2938 * clear_route_node visits the node (to delete the route of that
2939 * peer)
2940 * b) resource exhaustion, clear_route_node likely leads to an entry
2941 * on the process_main queue. Fast-flapping could cause that queue
2942 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002943 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002944 if (!peer->clear_node_queue->thread)
2945 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002946
Chris Caputo228da422009-07-18 05:44:03 +00002947 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002948 {
Chris Caputo228da422009-07-18 05:44:03 +00002949 case BGP_CLEAR_ROUTE_NORMAL:
2950 if (safi != SAFI_MPLS_VPN)
2951 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2952 else
2953 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2954 rn = bgp_route_next (rn))
2955 if ((table = rn->info) != NULL)
2956 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2957
2958 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2959 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2960 PEER_FLAG_RSERVER_CLIENT))
2961 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2962 break;
2963
2964 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2965 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2966 break;
2967
2968 default:
2969 assert (0);
2970 break;
paulfee0f4c2004-09-13 05:12:46 +00002971 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002972
Paul Jakmaca058a32006-09-14 02:58:49 +00002973 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002974 * completion function won't be run by workqueue code - call it here.
2975 * XXX: Actually, this assumption doesn't hold, see
2976 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002977 *
2978 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002979 * really needed if peer state is Established - peers in
2980 * pre-Established states shouldn't have any route-update state
2981 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002982 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002983 * We still can get here in pre-Established though, through
2984 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2985 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002986 *
2987 * At some future point, this check could be move to the top of the
2988 * function, and do a quick early-return when state is
2989 * pre-Established, avoiding above list and table scans. Once we're
2990 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002991 */
2992 if (!peer->clear_node_queue->thread)
2993 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002994}
2995
2996void
2997bgp_clear_route_all (struct peer *peer)
2998{
2999 afi_t afi;
3000 safi_t safi;
3001
3002 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3003 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003004 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003005}
3006
3007void
3008bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3009{
3010 struct bgp_table *table;
3011 struct bgp_node *rn;
3012 struct bgp_adj_in *ain;
3013
3014 table = peer->bgp->rib[afi][safi];
3015
3016 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3017 for (ain = rn->adj_in; ain ; ain = ain->next)
3018 if (ain->peer == peer)
3019 {
3020 bgp_adj_in_remove (rn, ain);
3021 bgp_unlock_node (rn);
3022 break;
3023 }
3024}
hasso93406d82005-02-02 14:40:33 +00003025
3026void
3027bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3028{
3029 struct bgp_node *rn;
3030 struct bgp_info *ri;
3031 struct bgp_table *table;
3032
3033 table = peer->bgp->rib[afi][safi];
3034
3035 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3036 {
3037 for (ri = rn->info; ri; ri = ri->next)
3038 if (ri->peer == peer)
3039 {
3040 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3041 bgp_rib_remove (rn, ri, peer, afi, safi);
3042 break;
3043 }
3044 }
3045}
David Lamparter6b0655a2014-06-04 06:53:35 +02003046
paul718e3742002-12-13 20:15:29 +00003047/* Delete all kernel routes. */
3048void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003049bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003050{
3051 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003052 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003053 struct bgp_node *rn;
3054 struct bgp_table *table;
3055 struct bgp_info *ri;
3056
paul1eb8ef22005-04-07 07:30:20 +00003057 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003058 {
3059 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3060
3061 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3062 for (ri = rn->info; ri; ri = ri->next)
3063 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3064 && ri->type == ZEBRA_ROUTE_BGP
3065 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003066 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003067
3068 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3069
3070 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3071 for (ri = rn->info; ri; ri = ri->next)
3072 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3073 && ri->type == ZEBRA_ROUTE_BGP
3074 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003075 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003076 }
3077}
3078
3079void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003080bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003081{
3082 vty_reset ();
3083 bgp_zclient_reset ();
3084 access_list_reset ();
3085 prefix_list_reset ();
3086}
David Lamparter6b0655a2014-06-04 06:53:35 +02003087
paul718e3742002-12-13 20:15:29 +00003088/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3089 value. */
3090int
3091bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3092{
3093 u_char *pnt;
3094 u_char *lim;
3095 struct prefix p;
3096 int psize;
3097 int ret;
3098
3099 /* Check peer status. */
3100 if (peer->status != Established)
3101 return 0;
3102
3103 pnt = packet->nlri;
3104 lim = pnt + packet->length;
3105
3106 for (; pnt < lim; pnt += psize)
3107 {
3108 /* Clear prefix structure. */
3109 memset (&p, 0, sizeof (struct prefix));
3110
3111 /* Fetch prefix length. */
3112 p.prefixlen = *pnt++;
3113 p.family = afi2family (packet->afi);
3114
3115 /* Already checked in nlri_sanity_check(). We do double check
3116 here. */
3117 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3118 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3119 return -1;
3120
3121 /* Packet size overflow check. */
3122 psize = PSIZE (p.prefixlen);
3123
3124 /* When packet overflow occur return immediately. */
3125 if (pnt + psize > lim)
3126 return -1;
3127
3128 /* Fetch prefix from NLRI packet. */
3129 memcpy (&p.u.prefix, pnt, psize);
3130
3131 /* Check address. */
3132 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3133 {
3134 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3135 {
paulf5ba3872004-07-09 12:11:31 +00003136 /*
3137 * From draft-ietf-idr-bgp4-22, Section 6.3:
3138 * If a BGP router receives an UPDATE message with a
3139 * semantically incorrect NLRI field, in which a prefix is
3140 * semantically incorrect (eg. an unexpected multicast IP
3141 * address), it should ignore the prefix.
3142 */
paul718e3742002-12-13 20:15:29 +00003143 zlog (peer->log, LOG_ERR,
3144 "IPv4 unicast NLRI is multicast address %s",
3145 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003146
paul718e3742002-12-13 20:15:29 +00003147 return -1;
3148 }
3149 }
3150
3151#ifdef HAVE_IPV6
3152 /* Check address. */
3153 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3154 {
3155 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3156 {
3157 char buf[BUFSIZ];
3158
3159 zlog (peer->log, LOG_WARNING,
3160 "IPv6 link-local NLRI received %s ignore this NLRI",
3161 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3162
3163 continue;
3164 }
3165 }
3166#endif /* HAVE_IPV6 */
3167
3168 /* Normal process. */
3169 if (attr)
3170 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3171 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3172 else
3173 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3174 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3175
3176 /* Address family configuration mismatch or maximum-prefix count
3177 overflow. */
3178 if (ret < 0)
3179 return -1;
3180 }
3181
3182 /* Packet length consistency check. */
3183 if (pnt != lim)
3184 return -1;
3185
3186 return 0;
3187}
3188
3189/* NLRI encode syntax check routine. */
3190int
3191bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3192 bgp_size_t length)
3193{
3194 u_char *end;
3195 u_char prefixlen;
3196 int psize;
3197
3198 end = pnt + length;
3199
3200 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3201 syntactic validity. If the field is syntactically incorrect,
3202 then the Error Subcode is set to Invalid Network Field. */
3203
3204 while (pnt < end)
3205 {
3206 prefixlen = *pnt++;
3207
3208 /* Prefix length check. */
3209 if ((afi == AFI_IP && prefixlen > 32)
3210 || (afi == AFI_IP6 && prefixlen > 128))
3211 {
3212 plog_err (peer->log,
3213 "%s [Error] Update packet error (wrong prefix length %d)",
3214 peer->host, prefixlen);
3215 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3216 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3217 return -1;
3218 }
3219
3220 /* Packet size overflow check. */
3221 psize = PSIZE (prefixlen);
3222
3223 if (pnt + psize > end)
3224 {
3225 plog_err (peer->log,
3226 "%s [Error] Update packet error"
3227 " (prefix data overflow prefix size is %d)",
3228 peer->host, psize);
3229 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3230 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3231 return -1;
3232 }
3233
3234 pnt += psize;
3235 }
3236
3237 /* Packet length consistency check. */
3238 if (pnt != end)
3239 {
3240 plog_err (peer->log,
3241 "%s [Error] Update packet error"
3242 " (prefix length mismatch with total length)",
3243 peer->host);
3244 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3245 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3246 return -1;
3247 }
3248 return 0;
3249}
David Lamparter6b0655a2014-06-04 06:53:35 +02003250
paul94f2b392005-06-28 12:44:16 +00003251static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003252bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003253{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003254 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003255}
3256
paul94f2b392005-06-28 12:44:16 +00003257static void
paul718e3742002-12-13 20:15:29 +00003258bgp_static_free (struct bgp_static *bgp_static)
3259{
3260 if (bgp_static->rmap.name)
3261 free (bgp_static->rmap.name);
3262 XFREE (MTYPE_BGP_STATIC, bgp_static);
3263}
3264
paul94f2b392005-06-28 12:44:16 +00003265static void
paulfee0f4c2004-09-13 05:12:46 +00003266bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3267 struct prefix *p, afi_t afi, safi_t safi)
3268{
3269 struct bgp_node *rn;
3270 struct bgp_info *ri;
3271
3272 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3273
3274 /* Check selected route and self inserted route. */
3275 for (ri = rn->info; ri; ri = ri->next)
3276 if (ri->peer == bgp->peer_self
3277 && ri->type == ZEBRA_ROUTE_BGP
3278 && ri->sub_type == BGP_ROUTE_STATIC)
3279 break;
3280
3281 /* Withdraw static BGP route from routing table. */
3282 if (ri)
3283 {
paulfee0f4c2004-09-13 05:12:46 +00003284 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003285 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003286 }
3287
3288 /* Unlock bgp_node_lookup. */
3289 bgp_unlock_node (rn);
3290}
3291
paul94f2b392005-06-28 12:44:16 +00003292static void
paulfee0f4c2004-09-13 05:12:46 +00003293bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003294 struct bgp_static *bgp_static,
3295 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003296{
3297 struct bgp_node *rn;
3298 struct bgp_info *ri;
3299 struct bgp_info *new;
3300 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003301 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003302 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003303 struct attr new_attr;
3304 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003305 struct bgp *bgp;
3306 int ret;
3307 char buf[SU_ADDRSTRLEN];
3308
3309 bgp = rsclient->bgp;
3310
Paul Jakma06e110f2006-05-12 23:29:22 +00003311 assert (bgp_static);
3312 if (!bgp_static)
3313 return;
3314
paulfee0f4c2004-09-13 05:12:46 +00003315 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3316
3317 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003318
3319 attr.nexthop = bgp_static->igpnexthop;
3320 attr.med = bgp_static->igpmetric;
3321 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003322
Paul Jakma41367172007-08-06 15:24:51 +00003323 if (bgp_static->atomic)
3324 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3325
paulfee0f4c2004-09-13 05:12:46 +00003326 /* Apply network route-map for export to this rsclient. */
3327 if (bgp_static->rmap.name)
3328 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003329 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003330 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003331 info.attr = &attr_tmp;
3332
paulfee0f4c2004-09-13 05:12:46 +00003333 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3334 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3335
3336 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3337
3338 rsclient->rmap_type = 0;
3339
3340 if (ret == RMAP_DENYMATCH)
3341 {
3342 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003343 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003344
3345 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003346 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003347 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003348 bgp_attr_extra_free (&attr);
3349
paulfee0f4c2004-09-13 05:12:46 +00003350 return;
3351 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003352 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003353 }
3354 else
3355 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003356
3357 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003358 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003359
paulfee0f4c2004-09-13 05:12:46 +00003360 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3361
Paul Jakmafb982c22007-05-04 20:15:47 +00003362 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3363 == RMAP_DENY)
3364 {
paulfee0f4c2004-09-13 05:12:46 +00003365 /* This BGP update is filtered. Log the reason then update BGP entry. */
3366 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003367 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003368 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3369 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3370 p->prefixlen, rsclient->host);
3371
3372 bgp->peer_self->rmap_type = 0;
3373
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003374 bgp_attr_unintern (&attr_new);
3375 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003376 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003377
3378 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3379
3380 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003381 }
paulfee0f4c2004-09-13 05:12:46 +00003382
3383 bgp->peer_self->rmap_type = 0;
3384
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003385 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003386 attr_new = bgp_attr_intern (&new_attr);
3387
3388 for (ri = rn->info; ri; ri = ri->next)
3389 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3390 && ri->sub_type == BGP_ROUTE_STATIC)
3391 break;
3392
3393 if (ri)
3394 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003395 if (attrhash_cmp (ri->attr, attr_new) &&
3396 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003397 {
3398 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003399 bgp_attr_unintern (&attr_new);
3400 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003401 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003402 return;
3403 }
3404 else
3405 {
3406 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003407 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003408
3409 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003410 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3411 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003412 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003413 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003414 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003415
3416 /* Process change. */
3417 bgp_process (bgp, rn, afi, safi);
3418 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003419 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003420 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003421 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003422 }
paulfee0f4c2004-09-13 05:12:46 +00003423 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003424
paulfee0f4c2004-09-13 05:12:46 +00003425 /* Make new BGP info. */
3426 new = bgp_info_new ();
3427 new->type = ZEBRA_ROUTE_BGP;
3428 new->sub_type = BGP_ROUTE_STATIC;
3429 new->peer = bgp->peer_self;
3430 SET_FLAG (new->flags, BGP_INFO_VALID);
3431 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003432 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003433
3434 /* Register new BGP information. */
3435 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003436
3437 /* route_node_get lock */
3438 bgp_unlock_node (rn);
3439
paulfee0f4c2004-09-13 05:12:46 +00003440 /* Process change. */
3441 bgp_process (bgp, rn, afi, safi);
3442
3443 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003444 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003445 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003446}
3447
paul94f2b392005-06-28 12:44:16 +00003448static void
paulfee0f4c2004-09-13 05:12:46 +00003449bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003450 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3451{
3452 struct bgp_node *rn;
3453 struct bgp_info *ri;
3454 struct bgp_info *new;
3455 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003456 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003457 struct attr *attr_new;
3458 int ret;
3459
Paul Jakmadd8103a2006-05-12 23:27:30 +00003460 assert (bgp_static);
3461 if (!bgp_static)
3462 return;
3463
paulfee0f4c2004-09-13 05:12:46 +00003464 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003465
3466 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003467
3468 attr.nexthop = bgp_static->igpnexthop;
3469 attr.med = bgp_static->igpmetric;
3470 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003471
Paul Jakma41367172007-08-06 15:24:51 +00003472 if (bgp_static->atomic)
3473 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3474
paul718e3742002-12-13 20:15:29 +00003475 /* Apply route-map. */
3476 if (bgp_static->rmap.name)
3477 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003478 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003479 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003480 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003481
paulfee0f4c2004-09-13 05:12:46 +00003482 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3483
paul718e3742002-12-13 20:15:29 +00003484 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003485
paulfee0f4c2004-09-13 05:12:46 +00003486 bgp->peer_self->rmap_type = 0;
3487
paul718e3742002-12-13 20:15:29 +00003488 if (ret == RMAP_DENYMATCH)
3489 {
3490 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003491 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003492
3493 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003494 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003495 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003496 bgp_static_withdraw (bgp, p, afi, safi);
3497 return;
3498 }
paul286e1e72003-08-08 00:24:31 +00003499 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003500 }
paul286e1e72003-08-08 00:24:31 +00003501 else
3502 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003503
3504 for (ri = rn->info; ri; ri = ri->next)
3505 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3506 && ri->sub_type == BGP_ROUTE_STATIC)
3507 break;
3508
3509 if (ri)
3510 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003511 if (attrhash_cmp (ri->attr, attr_new) &&
3512 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003513 {
3514 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003515 bgp_attr_unintern (&attr_new);
3516 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003517 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003518 return;
3519 }
3520 else
3521 {
3522 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003523 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003524
3525 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003526 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3527 bgp_info_restore(rn, ri);
3528 else
3529 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003530 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003531 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003532 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003533
3534 /* Process change. */
3535 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3536 bgp_process (bgp, rn, afi, safi);
3537 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003538 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003539 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003540 return;
3541 }
3542 }
3543
3544 /* Make new BGP info. */
3545 new = bgp_info_new ();
3546 new->type = ZEBRA_ROUTE_BGP;
3547 new->sub_type = BGP_ROUTE_STATIC;
3548 new->peer = bgp->peer_self;
3549 SET_FLAG (new->flags, BGP_INFO_VALID);
3550 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003551 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003552
3553 /* Aggregate address increment. */
3554 bgp_aggregate_increment (bgp, p, new, afi, safi);
3555
3556 /* Register new BGP information. */
3557 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003558
3559 /* route_node_get lock */
3560 bgp_unlock_node (rn);
3561
paul718e3742002-12-13 20:15:29 +00003562 /* Process change. */
3563 bgp_process (bgp, rn, afi, safi);
3564
3565 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003566 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003567 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003568}
3569
3570void
paulfee0f4c2004-09-13 05:12:46 +00003571bgp_static_update (struct bgp *bgp, struct prefix *p,
3572 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3573{
3574 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003575 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003576
3577 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3578
paul1eb8ef22005-04-07 07:30:20 +00003579 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003580 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003581 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3582 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003583 }
3584}
3585
paul94f2b392005-06-28 12:44:16 +00003586static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003587bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3588 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003589{
3590 struct bgp_node *rn;
3591 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003592
paulfee0f4c2004-09-13 05:12:46 +00003593 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003594
3595 /* Make new BGP info. */
3596 new = bgp_info_new ();
3597 new->type = ZEBRA_ROUTE_BGP;
3598 new->sub_type = BGP_ROUTE_STATIC;
3599 new->peer = bgp->peer_self;
3600 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3601 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003602 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003603 new->extra = bgp_info_extra_new();
3604 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003605
3606 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003607 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003608
3609 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003610 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003611
paul200df112005-06-01 11:17:05 +00003612 /* route_node_get lock */
3613 bgp_unlock_node (rn);
3614
paul718e3742002-12-13 20:15:29 +00003615 /* Process change. */
3616 bgp_process (bgp, rn, afi, safi);
3617}
3618
3619void
3620bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3621 safi_t safi)
3622{
3623 struct bgp_node *rn;
3624 struct bgp_info *ri;
3625
paulfee0f4c2004-09-13 05:12:46 +00003626 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003627
3628 /* Check selected route and self inserted route. */
3629 for (ri = rn->info; ri; ri = ri->next)
3630 if (ri->peer == bgp->peer_self
3631 && ri->type == ZEBRA_ROUTE_BGP
3632 && ri->sub_type == BGP_ROUTE_STATIC)
3633 break;
3634
3635 /* Withdraw static BGP route from routing table. */
3636 if (ri)
3637 {
3638 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003639 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003640 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003641 }
3642
3643 /* Unlock bgp_node_lookup. */
3644 bgp_unlock_node (rn);
3645}
3646
3647void
paulfee0f4c2004-09-13 05:12:46 +00003648bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3649{
3650 struct bgp_static *bgp_static;
3651 struct bgp *bgp;
3652 struct bgp_node *rn;
3653 struct prefix *p;
3654
3655 bgp = rsclient->bgp;
3656
3657 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3658 if ((bgp_static = rn->info) != NULL)
3659 {
3660 p = &rn->p;
3661
3662 bgp_static_update_rsclient (rsclient, p, bgp_static,
3663 afi, safi);
3664 }
3665}
3666
paul94f2b392005-06-28 12:44:16 +00003667static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003668bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3669 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003670{
3671 struct bgp_node *rn;
3672 struct bgp_info *ri;
3673
paulfee0f4c2004-09-13 05:12:46 +00003674 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003675
3676 /* Check selected route and self inserted route. */
3677 for (ri = rn->info; ri; ri = ri->next)
3678 if (ri->peer == bgp->peer_self
3679 && ri->type == ZEBRA_ROUTE_BGP
3680 && ri->sub_type == BGP_ROUTE_STATIC)
3681 break;
3682
3683 /* Withdraw static BGP route from routing table. */
3684 if (ri)
3685 {
3686 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003687 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003688 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003689 }
3690
3691 /* Unlock bgp_node_lookup. */
3692 bgp_unlock_node (rn);
3693}
3694
3695/* Configure static BGP network. When user don't run zebra, static
3696 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003697static int
paulfd79ac92004-10-13 05:06:08 +00003698bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003699 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003700{
3701 int ret;
3702 struct prefix p;
3703 struct bgp_static *bgp_static;
3704 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003705 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003706
3707 /* Convert IP prefix string to struct prefix. */
3708 ret = str2prefix (ip_str, &p);
3709 if (! ret)
3710 {
3711 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3712 return CMD_WARNING;
3713 }
3714#ifdef HAVE_IPV6
3715 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3716 {
3717 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3718 VTY_NEWLINE);
3719 return CMD_WARNING;
3720 }
3721#endif /* HAVE_IPV6 */
3722
3723 apply_mask (&p);
3724
3725 /* Set BGP static route configuration. */
3726 rn = bgp_node_get (bgp->route[afi][safi], &p);
3727
3728 if (rn->info)
3729 {
3730 /* Configuration change. */
3731 bgp_static = rn->info;
3732
3733 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003734 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3735 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003736
paul718e3742002-12-13 20:15:29 +00003737 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003738
paul718e3742002-12-13 20:15:29 +00003739 if (rmap)
3740 {
3741 if (bgp_static->rmap.name)
3742 free (bgp_static->rmap.name);
3743 bgp_static->rmap.name = strdup (rmap);
3744 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3745 }
3746 else
3747 {
3748 if (bgp_static->rmap.name)
3749 free (bgp_static->rmap.name);
3750 bgp_static->rmap.name = NULL;
3751 bgp_static->rmap.map = NULL;
3752 bgp_static->valid = 0;
3753 }
3754 bgp_unlock_node (rn);
3755 }
3756 else
3757 {
3758 /* New configuration. */
3759 bgp_static = bgp_static_new ();
3760 bgp_static->backdoor = backdoor;
3761 bgp_static->valid = 0;
3762 bgp_static->igpmetric = 0;
3763 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003764
paul718e3742002-12-13 20:15:29 +00003765 if (rmap)
3766 {
3767 if (bgp_static->rmap.name)
3768 free (bgp_static->rmap.name);
3769 bgp_static->rmap.name = strdup (rmap);
3770 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3771 }
3772 rn->info = bgp_static;
3773 }
3774
3775 /* If BGP scan is not enabled, we should install this route here. */
3776 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3777 {
3778 bgp_static->valid = 1;
3779
3780 if (need_update)
3781 bgp_static_withdraw (bgp, &p, afi, safi);
3782
3783 if (! bgp_static->backdoor)
3784 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3785 }
3786
3787 return CMD_SUCCESS;
3788}
3789
3790/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003791static int
paulfd79ac92004-10-13 05:06:08 +00003792bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003793 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003794{
3795 int ret;
3796 struct prefix p;
3797 struct bgp_static *bgp_static;
3798 struct bgp_node *rn;
3799
3800 /* Convert IP prefix string to struct prefix. */
3801 ret = str2prefix (ip_str, &p);
3802 if (! ret)
3803 {
3804 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3805 return CMD_WARNING;
3806 }
3807#ifdef HAVE_IPV6
3808 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3809 {
3810 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3811 VTY_NEWLINE);
3812 return CMD_WARNING;
3813 }
3814#endif /* HAVE_IPV6 */
3815
3816 apply_mask (&p);
3817
3818 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3819 if (! rn)
3820 {
3821 vty_out (vty, "%% Can't find specified static route configuration.%s",
3822 VTY_NEWLINE);
3823 return CMD_WARNING;
3824 }
3825
3826 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003827
paul718e3742002-12-13 20:15:29 +00003828 /* Update BGP RIB. */
3829 if (! bgp_static->backdoor)
3830 bgp_static_withdraw (bgp, &p, afi, safi);
3831
3832 /* Clear configuration. */
3833 bgp_static_free (bgp_static);
3834 rn->info = NULL;
3835 bgp_unlock_node (rn);
3836 bgp_unlock_node (rn);
3837
3838 return CMD_SUCCESS;
3839}
3840
3841/* Called from bgp_delete(). Delete all static routes from the BGP
3842 instance. */
3843void
3844bgp_static_delete (struct bgp *bgp)
3845{
3846 afi_t afi;
3847 safi_t safi;
3848 struct bgp_node *rn;
3849 struct bgp_node *rm;
3850 struct bgp_table *table;
3851 struct bgp_static *bgp_static;
3852
3853 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3854 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3855 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3856 if (rn->info != NULL)
3857 {
3858 if (safi == SAFI_MPLS_VPN)
3859 {
3860 table = rn->info;
3861
3862 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3863 {
3864 bgp_static = rn->info;
3865 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3866 AFI_IP, SAFI_MPLS_VPN,
3867 (struct prefix_rd *)&rn->p,
3868 bgp_static->tag);
3869 bgp_static_free (bgp_static);
3870 rn->info = NULL;
3871 bgp_unlock_node (rn);
3872 }
3873 }
3874 else
3875 {
3876 bgp_static = rn->info;
3877 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3878 bgp_static_free (bgp_static);
3879 rn->info = NULL;
3880 bgp_unlock_node (rn);
3881 }
3882 }
3883}
3884
3885int
paulfd79ac92004-10-13 05:06:08 +00003886bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3887 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003888{
3889 int ret;
3890 struct prefix p;
3891 struct prefix_rd prd;
3892 struct bgp *bgp;
3893 struct bgp_node *prn;
3894 struct bgp_node *rn;
3895 struct bgp_table *table;
3896 struct bgp_static *bgp_static;
3897 u_char tag[3];
3898
3899 bgp = vty->index;
3900
3901 ret = str2prefix (ip_str, &p);
3902 if (! ret)
3903 {
3904 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3905 return CMD_WARNING;
3906 }
3907 apply_mask (&p);
3908
3909 ret = str2prefix_rd (rd_str, &prd);
3910 if (! ret)
3911 {
3912 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3913 return CMD_WARNING;
3914 }
3915
3916 ret = str2tag (tag_str, tag);
3917 if (! ret)
3918 {
3919 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3920 return CMD_WARNING;
3921 }
3922
3923 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3924 (struct prefix *)&prd);
3925 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003926 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003927 else
3928 bgp_unlock_node (prn);
3929 table = prn->info;
3930
3931 rn = bgp_node_get (table, &p);
3932
3933 if (rn->info)
3934 {
3935 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3936 bgp_unlock_node (rn);
3937 }
3938 else
3939 {
3940 /* New configuration. */
3941 bgp_static = bgp_static_new ();
3942 bgp_static->valid = 1;
3943 memcpy (bgp_static->tag, tag, 3);
3944 rn->info = bgp_static;
3945
3946 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3947 }
3948
3949 return CMD_SUCCESS;
3950}
3951
3952/* Configure static BGP network. */
3953int
paulfd79ac92004-10-13 05:06:08 +00003954bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3955 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003956{
3957 int ret;
3958 struct bgp *bgp;
3959 struct prefix p;
3960 struct prefix_rd prd;
3961 struct bgp_node *prn;
3962 struct bgp_node *rn;
3963 struct bgp_table *table;
3964 struct bgp_static *bgp_static;
3965 u_char tag[3];
3966
3967 bgp = vty->index;
3968
3969 /* Convert IP prefix string to struct prefix. */
3970 ret = str2prefix (ip_str, &p);
3971 if (! ret)
3972 {
3973 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3974 return CMD_WARNING;
3975 }
3976 apply_mask (&p);
3977
3978 ret = str2prefix_rd (rd_str, &prd);
3979 if (! ret)
3980 {
3981 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3982 return CMD_WARNING;
3983 }
3984
3985 ret = str2tag (tag_str, tag);
3986 if (! ret)
3987 {
3988 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3989 return CMD_WARNING;
3990 }
3991
3992 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3993 (struct prefix *)&prd);
3994 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003995 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003996 else
3997 bgp_unlock_node (prn);
3998 table = prn->info;
3999
4000 rn = bgp_node_lookup (table, &p);
4001
4002 if (rn)
4003 {
4004 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4005
4006 bgp_static = rn->info;
4007 bgp_static_free (bgp_static);
4008 rn->info = NULL;
4009 bgp_unlock_node (rn);
4010 bgp_unlock_node (rn);
4011 }
4012 else
4013 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4014
4015 return CMD_SUCCESS;
4016}
David Lamparter6b0655a2014-06-04 06:53:35 +02004017
paul718e3742002-12-13 20:15:29 +00004018DEFUN (bgp_network,
4019 bgp_network_cmd,
4020 "network A.B.C.D/M",
4021 "Specify a network to announce via BGP\n"
4022 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4023{
4024 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004025 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004026}
4027
4028DEFUN (bgp_network_route_map,
4029 bgp_network_route_map_cmd,
4030 "network A.B.C.D/M route-map WORD",
4031 "Specify a network to announce via BGP\n"
4032 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4033 "Route-map to modify the attributes\n"
4034 "Name of the route map\n")
4035{
4036 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004037 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004038}
4039
4040DEFUN (bgp_network_backdoor,
4041 bgp_network_backdoor_cmd,
4042 "network A.B.C.D/M backdoor",
4043 "Specify a network to announce via BGP\n"
4044 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4045 "Specify a BGP backdoor route\n")
4046{
Paul Jakma41367172007-08-06 15:24:51 +00004047 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004048 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004049}
4050
4051DEFUN (bgp_network_mask,
4052 bgp_network_mask_cmd,
4053 "network A.B.C.D mask A.B.C.D",
4054 "Specify a network to announce via BGP\n"
4055 "Network number\n"
4056 "Network mask\n"
4057 "Network mask\n")
4058{
4059 int ret;
4060 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004061
paul718e3742002-12-13 20:15:29 +00004062 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4063 if (! ret)
4064 {
4065 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4066 return CMD_WARNING;
4067 }
4068
4069 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004070 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004071}
4072
4073DEFUN (bgp_network_mask_route_map,
4074 bgp_network_mask_route_map_cmd,
4075 "network A.B.C.D mask A.B.C.D route-map WORD",
4076 "Specify a network to announce via BGP\n"
4077 "Network number\n"
4078 "Network mask\n"
4079 "Network mask\n"
4080 "Route-map to modify the attributes\n"
4081 "Name of the route map\n")
4082{
4083 int ret;
4084 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004085
paul718e3742002-12-13 20:15:29 +00004086 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4087 if (! ret)
4088 {
4089 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4090 return CMD_WARNING;
4091 }
4092
4093 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004094 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004095}
4096
4097DEFUN (bgp_network_mask_backdoor,
4098 bgp_network_mask_backdoor_cmd,
4099 "network A.B.C.D mask A.B.C.D backdoor",
4100 "Specify a network to announce via BGP\n"
4101 "Network number\n"
4102 "Network mask\n"
4103 "Network mask\n"
4104 "Specify a BGP backdoor route\n")
4105{
4106 int ret;
4107 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004108
paul718e3742002-12-13 20:15:29 +00004109 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4110 if (! ret)
4111 {
4112 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4113 return CMD_WARNING;
4114 }
4115
Paul Jakma41367172007-08-06 15:24:51 +00004116 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004117 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004118}
4119
4120DEFUN (bgp_network_mask_natural,
4121 bgp_network_mask_natural_cmd,
4122 "network A.B.C.D",
4123 "Specify a network to announce via BGP\n"
4124 "Network number\n")
4125{
4126 int ret;
4127 char prefix_str[BUFSIZ];
4128
4129 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4130 if (! ret)
4131 {
4132 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4133 return CMD_WARNING;
4134 }
4135
4136 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004137 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004138}
4139
4140DEFUN (bgp_network_mask_natural_route_map,
4141 bgp_network_mask_natural_route_map_cmd,
4142 "network A.B.C.D route-map WORD",
4143 "Specify a network to announce via BGP\n"
4144 "Network number\n"
4145 "Route-map to modify the attributes\n"
4146 "Name of the route map\n")
4147{
4148 int ret;
4149 char prefix_str[BUFSIZ];
4150
4151 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4152 if (! ret)
4153 {
4154 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4155 return CMD_WARNING;
4156 }
4157
4158 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004159 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004160}
4161
4162DEFUN (bgp_network_mask_natural_backdoor,
4163 bgp_network_mask_natural_backdoor_cmd,
4164 "network A.B.C.D backdoor",
4165 "Specify a network to announce via BGP\n"
4166 "Network number\n"
4167 "Specify a BGP backdoor route\n")
4168{
4169 int ret;
4170 char prefix_str[BUFSIZ];
4171
4172 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4173 if (! ret)
4174 {
4175 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4176 return CMD_WARNING;
4177 }
4178
Paul Jakma41367172007-08-06 15:24:51 +00004179 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004180 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004181}
4182
4183DEFUN (no_bgp_network,
4184 no_bgp_network_cmd,
4185 "no network A.B.C.D/M",
4186 NO_STR
4187 "Specify a network to announce via BGP\n"
4188 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4189{
4190 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4191 bgp_node_safi (vty));
4192}
4193
4194ALIAS (no_bgp_network,
4195 no_bgp_network_route_map_cmd,
4196 "no network A.B.C.D/M route-map WORD",
4197 NO_STR
4198 "Specify a network to announce via BGP\n"
4199 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4200 "Route-map to modify the attributes\n"
4201 "Name of the route map\n")
4202
4203ALIAS (no_bgp_network,
4204 no_bgp_network_backdoor_cmd,
4205 "no network A.B.C.D/M backdoor",
4206 NO_STR
4207 "Specify a network to announce via BGP\n"
4208 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4209 "Specify a BGP backdoor route\n")
4210
4211DEFUN (no_bgp_network_mask,
4212 no_bgp_network_mask_cmd,
4213 "no network A.B.C.D mask A.B.C.D",
4214 NO_STR
4215 "Specify a network to announce via BGP\n"
4216 "Network number\n"
4217 "Network mask\n"
4218 "Network mask\n")
4219{
4220 int ret;
4221 char prefix_str[BUFSIZ];
4222
4223 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4224 if (! ret)
4225 {
4226 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4227 return CMD_WARNING;
4228 }
4229
4230 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4231 bgp_node_safi (vty));
4232}
4233
4234ALIAS (no_bgp_network_mask,
4235 no_bgp_network_mask_route_map_cmd,
4236 "no network A.B.C.D mask A.B.C.D route-map WORD",
4237 NO_STR
4238 "Specify a network to announce via BGP\n"
4239 "Network number\n"
4240 "Network mask\n"
4241 "Network mask\n"
4242 "Route-map to modify the attributes\n"
4243 "Name of the route map\n")
4244
4245ALIAS (no_bgp_network_mask,
4246 no_bgp_network_mask_backdoor_cmd,
4247 "no network A.B.C.D mask A.B.C.D backdoor",
4248 NO_STR
4249 "Specify a network to announce via BGP\n"
4250 "Network number\n"
4251 "Network mask\n"
4252 "Network mask\n"
4253 "Specify a BGP backdoor route\n")
4254
4255DEFUN (no_bgp_network_mask_natural,
4256 no_bgp_network_mask_natural_cmd,
4257 "no network A.B.C.D",
4258 NO_STR
4259 "Specify a network to announce via BGP\n"
4260 "Network number\n")
4261{
4262 int ret;
4263 char prefix_str[BUFSIZ];
4264
4265 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4266 if (! ret)
4267 {
4268 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4269 return CMD_WARNING;
4270 }
4271
4272 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4273 bgp_node_safi (vty));
4274}
4275
4276ALIAS (no_bgp_network_mask_natural,
4277 no_bgp_network_mask_natural_route_map_cmd,
4278 "no network A.B.C.D route-map WORD",
4279 NO_STR
4280 "Specify a network to announce via BGP\n"
4281 "Network number\n"
4282 "Route-map to modify the attributes\n"
4283 "Name of the route map\n")
4284
4285ALIAS (no_bgp_network_mask_natural,
4286 no_bgp_network_mask_natural_backdoor_cmd,
4287 "no network A.B.C.D backdoor",
4288 NO_STR
4289 "Specify a network to announce via BGP\n"
4290 "Network number\n"
4291 "Specify a BGP backdoor route\n")
4292
4293#ifdef HAVE_IPV6
4294DEFUN (ipv6_bgp_network,
4295 ipv6_bgp_network_cmd,
4296 "network X:X::X:X/M",
4297 "Specify a network to announce via BGP\n"
4298 "IPv6 prefix <network>/<length>\n")
4299{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304300 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004301 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004302}
4303
4304DEFUN (ipv6_bgp_network_route_map,
4305 ipv6_bgp_network_route_map_cmd,
4306 "network X:X::X:X/M route-map WORD",
4307 "Specify a network to announce via BGP\n"
4308 "IPv6 prefix <network>/<length>\n"
4309 "Route-map to modify the attributes\n"
4310 "Name of the route map\n")
4311{
4312 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004313 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004314}
4315
4316DEFUN (no_ipv6_bgp_network,
4317 no_ipv6_bgp_network_cmd,
4318 "no network X:X::X:X/M",
4319 NO_STR
4320 "Specify a network to announce via BGP\n"
4321 "IPv6 prefix <network>/<length>\n")
4322{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304323 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004324}
4325
4326ALIAS (no_ipv6_bgp_network,
4327 no_ipv6_bgp_network_route_map_cmd,
4328 "no network X:X::X:X/M route-map WORD",
4329 NO_STR
4330 "Specify a network to announce via BGP\n"
4331 "IPv6 prefix <network>/<length>\n"
4332 "Route-map to modify the attributes\n"
4333 "Name of the route map\n")
4334
4335ALIAS (ipv6_bgp_network,
4336 old_ipv6_bgp_network_cmd,
4337 "ipv6 bgp network X:X::X:X/M",
4338 IPV6_STR
4339 BGP_STR
4340 "Specify a network to announce via BGP\n"
4341 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4342
4343ALIAS (no_ipv6_bgp_network,
4344 old_no_ipv6_bgp_network_cmd,
4345 "no ipv6 bgp network X:X::X:X/M",
4346 NO_STR
4347 IPV6_STR
4348 BGP_STR
4349 "Specify a network to announce via BGP\n"
4350 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4351#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004352
4353/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4354ALIAS_DEPRECATED (bgp_network,
4355 bgp_network_ttl_cmd,
4356 "network A.B.C.D/M pathlimit <0-255>",
4357 "Specify a network to announce via BGP\n"
4358 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4359 "AS-Path hopcount limit attribute\n"
4360 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4361ALIAS_DEPRECATED (bgp_network_backdoor,
4362 bgp_network_backdoor_ttl_cmd,
4363 "network A.B.C.D/M backdoor pathlimit <0-255>",
4364 "Specify a network to announce via BGP\n"
4365 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4366 "Specify a BGP backdoor route\n"
4367 "AS-Path hopcount limit attribute\n"
4368 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4369ALIAS_DEPRECATED (bgp_network_mask,
4370 bgp_network_mask_ttl_cmd,
4371 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4372 "Specify a network to announce via BGP\n"
4373 "Network number\n"
4374 "Network mask\n"
4375 "Network mask\n"
4376 "AS-Path hopcount limit attribute\n"
4377 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4378ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4379 bgp_network_mask_backdoor_ttl_cmd,
4380 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4381 "Specify a network to announce via BGP\n"
4382 "Network number\n"
4383 "Network mask\n"
4384 "Network mask\n"
4385 "Specify a BGP backdoor route\n"
4386 "AS-Path hopcount limit attribute\n"
4387 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4388ALIAS_DEPRECATED (bgp_network_mask_natural,
4389 bgp_network_mask_natural_ttl_cmd,
4390 "network A.B.C.D pathlimit <0-255>",
4391 "Specify a network to announce via BGP\n"
4392 "Network number\n"
4393 "AS-Path hopcount limit attribute\n"
4394 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4395ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4396 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004397 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004398 "Specify a network to announce via BGP\n"
4399 "Network number\n"
4400 "Specify a BGP backdoor route\n"
4401 "AS-Path hopcount limit attribute\n"
4402 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4403ALIAS_DEPRECATED (no_bgp_network,
4404 no_bgp_network_ttl_cmd,
4405 "no network A.B.C.D/M pathlimit <0-255>",
4406 NO_STR
4407 "Specify a network to announce via BGP\n"
4408 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4409 "AS-Path hopcount limit attribute\n"
4410 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4411ALIAS_DEPRECATED (no_bgp_network,
4412 no_bgp_network_backdoor_ttl_cmd,
4413 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4414 NO_STR
4415 "Specify a network to announce via BGP\n"
4416 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4417 "Specify a BGP backdoor route\n"
4418 "AS-Path hopcount limit attribute\n"
4419 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4420ALIAS_DEPRECATED (no_bgp_network,
4421 no_bgp_network_mask_ttl_cmd,
4422 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4423 NO_STR
4424 "Specify a network to announce via BGP\n"
4425 "Network number\n"
4426 "Network mask\n"
4427 "Network mask\n"
4428 "AS-Path hopcount limit attribute\n"
4429 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4430ALIAS_DEPRECATED (no_bgp_network_mask,
4431 no_bgp_network_mask_backdoor_ttl_cmd,
4432 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4433 NO_STR
4434 "Specify a network to announce via BGP\n"
4435 "Network number\n"
4436 "Network mask\n"
4437 "Network mask\n"
4438 "Specify a BGP backdoor route\n"
4439 "AS-Path hopcount limit attribute\n"
4440 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4441ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4442 no_bgp_network_mask_natural_ttl_cmd,
4443 "no network A.B.C.D pathlimit <0-255>",
4444 NO_STR
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 (no_bgp_network_mask_natural,
4450 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4451 "no network A.B.C.D backdoor pathlimit <0-255>",
4452 NO_STR
4453 "Specify a network to announce via BGP\n"
4454 "Network number\n"
4455 "Specify a BGP backdoor route\n"
4456 "AS-Path hopcount limit attribute\n"
4457 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004458#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004459ALIAS_DEPRECATED (ipv6_bgp_network,
4460 ipv6_bgp_network_ttl_cmd,
4461 "network X:X::X:X/M pathlimit <0-255>",
4462 "Specify a network to announce via BGP\n"
4463 "IPv6 prefix <network>/<length>\n"
4464 "AS-Path hopcount limit attribute\n"
4465 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4466ALIAS_DEPRECATED (no_ipv6_bgp_network,
4467 no_ipv6_bgp_network_ttl_cmd,
4468 "no network X:X::X:X/M pathlimit <0-255>",
4469 NO_STR
4470 "Specify a network to announce via BGP\n"
4471 "IPv6 prefix <network>/<length>\n"
4472 "AS-Path hopcount limit attribute\n"
4473 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004474#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02004475
paul718e3742002-12-13 20:15:29 +00004476/* Aggreagete address:
4477
4478 advertise-map Set condition to advertise attribute
4479 as-set Generate AS set path information
4480 attribute-map Set attributes of aggregate
4481 route-map Set parameters of aggregate
4482 summary-only Filter more specific routes from updates
4483 suppress-map Conditionally filter more specific routes from updates
4484 <cr>
4485 */
4486struct bgp_aggregate
4487{
4488 /* Summary-only flag. */
4489 u_char summary_only;
4490
4491 /* AS set generation. */
4492 u_char as_set;
4493
4494 /* Route-map for aggregated route. */
4495 struct route_map *map;
4496
4497 /* Suppress-count. */
4498 unsigned long count;
4499
4500 /* SAFI configuration. */
4501 safi_t safi;
4502};
4503
paul94f2b392005-06-28 12:44:16 +00004504static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004505bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004506{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004507 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004508}
4509
paul94f2b392005-06-28 12:44:16 +00004510static void
paul718e3742002-12-13 20:15:29 +00004511bgp_aggregate_free (struct bgp_aggregate *aggregate)
4512{
4513 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4514}
4515
paul94f2b392005-06-28 12:44:16 +00004516static void
paul718e3742002-12-13 20:15:29 +00004517bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4518 afi_t afi, safi_t safi, struct bgp_info *del,
4519 struct bgp_aggregate *aggregate)
4520{
4521 struct bgp_table *table;
4522 struct bgp_node *top;
4523 struct bgp_node *rn;
4524 u_char origin;
4525 struct aspath *aspath = NULL;
4526 struct aspath *asmerge = NULL;
4527 struct community *community = NULL;
4528 struct community *commerge = NULL;
paul718e3742002-12-13 20:15:29 +00004529 struct bgp_info *ri;
4530 struct bgp_info *new;
4531 int first = 1;
4532 unsigned long match = 0;
4533
paul718e3742002-12-13 20:15:29 +00004534 /* ORIGIN attribute: If at least one route among routes that are
4535 aggregated has ORIGIN with the value INCOMPLETE, then the
4536 aggregated route must have the ORIGIN attribute with the value
4537 INCOMPLETE. Otherwise, if at least one route among routes that
4538 are aggregated has ORIGIN with the value EGP, then the aggregated
4539 route must have the origin attribute with the value EGP. In all
4540 other case the value of the ORIGIN attribute of the aggregated
4541 route is INTERNAL. */
4542 origin = BGP_ORIGIN_IGP;
4543
4544 table = bgp->rib[afi][safi];
4545
4546 top = bgp_node_get (table, p);
4547 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4548 if (rn->p.prefixlen > p->prefixlen)
4549 {
4550 match = 0;
4551
4552 for (ri = rn->info; ri; ri = ri->next)
4553 {
4554 if (BGP_INFO_HOLDDOWN (ri))
4555 continue;
4556
4557 if (del && ri == del)
4558 continue;
4559
4560 if (! rinew && first)
Paul Jakma7aa9dce2014-09-19 14:42:23 +01004561 first = 0;
paul718e3742002-12-13 20:15:29 +00004562
4563#ifdef AGGREGATE_NEXTHOP_CHECK
4564 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4565 || ri->attr->med != med)
4566 {
4567 if (aspath)
4568 aspath_free (aspath);
4569 if (community)
4570 community_free (community);
4571 bgp_unlock_node (rn);
4572 bgp_unlock_node (top);
4573 return;
4574 }
4575#endif /* AGGREGATE_NEXTHOP_CHECK */
4576
4577 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4578 {
4579 if (aggregate->summary_only)
4580 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004581 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004582 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004583 match++;
4584 }
4585
4586 aggregate->count++;
4587
4588 if (aggregate->as_set)
4589 {
4590 if (origin < ri->attr->origin)
4591 origin = ri->attr->origin;
4592
4593 if (aspath)
4594 {
4595 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4596 aspath_free (aspath);
4597 aspath = asmerge;
4598 }
4599 else
4600 aspath = aspath_dup (ri->attr->aspath);
4601
4602 if (ri->attr->community)
4603 {
4604 if (community)
4605 {
4606 commerge = community_merge (community,
4607 ri->attr->community);
4608 community = community_uniq_sort (commerge);
4609 community_free (commerge);
4610 }
4611 else
4612 community = community_dup (ri->attr->community);
4613 }
4614 }
4615 }
4616 }
4617 if (match)
4618 bgp_process (bgp, rn, afi, safi);
4619 }
4620 bgp_unlock_node (top);
4621
4622 if (rinew)
4623 {
4624 aggregate->count++;
4625
4626 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004627 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004628
4629 if (aggregate->as_set)
4630 {
4631 if (origin < rinew->attr->origin)
4632 origin = rinew->attr->origin;
4633
4634 if (aspath)
4635 {
4636 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4637 aspath_free (aspath);
4638 aspath = asmerge;
4639 }
4640 else
4641 aspath = aspath_dup (rinew->attr->aspath);
4642
4643 if (rinew->attr->community)
4644 {
4645 if (community)
4646 {
4647 commerge = community_merge (community,
4648 rinew->attr->community);
4649 community = community_uniq_sort (commerge);
4650 community_free (commerge);
4651 }
4652 else
4653 community = community_dup (rinew->attr->community);
4654 }
4655 }
4656 }
4657
4658 if (aggregate->count > 0)
4659 {
4660 rn = bgp_node_get (table, p);
4661 new = bgp_info_new ();
4662 new->type = ZEBRA_ROUTE_BGP;
4663 new->sub_type = BGP_ROUTE_AGGREGATE;
4664 new->peer = bgp->peer_self;
4665 SET_FLAG (new->flags, BGP_INFO_VALID);
4666 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004667 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004668
4669 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004670 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004671 bgp_process (bgp, rn, afi, safi);
4672 }
4673 else
4674 {
4675 if (aspath)
4676 aspath_free (aspath);
4677 if (community)
4678 community_free (community);
4679 }
4680}
4681
4682void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4683 struct bgp_aggregate *);
4684
4685void
4686bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4687 struct bgp_info *ri, afi_t afi, safi_t safi)
4688{
4689 struct bgp_node *child;
4690 struct bgp_node *rn;
4691 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004692 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004693
4694 /* MPLS-VPN aggregation is not yet supported. */
4695 if (safi == SAFI_MPLS_VPN)
4696 return;
4697
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004698 table = bgp->aggregate[afi][safi];
4699
4700 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004701 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004702 return;
4703
paul718e3742002-12-13 20:15:29 +00004704 if (p->prefixlen == 0)
4705 return;
4706
4707 if (BGP_INFO_HOLDDOWN (ri))
4708 return;
4709
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004710 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004711
4712 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004713 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004714 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4715 {
4716 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004717 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004718 }
4719 bgp_unlock_node (child);
4720}
4721
4722void
4723bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4724 struct bgp_info *del, afi_t afi, safi_t safi)
4725{
4726 struct bgp_node *child;
4727 struct bgp_node *rn;
4728 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004729 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004730
4731 /* MPLS-VPN aggregation is not yet supported. */
4732 if (safi == SAFI_MPLS_VPN)
4733 return;
4734
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004735 table = bgp->aggregate[afi][safi];
4736
4737 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004738 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004739 return;
4740
paul718e3742002-12-13 20:15:29 +00004741 if (p->prefixlen == 0)
4742 return;
4743
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004744 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004745
4746 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004747 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004748 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4749 {
4750 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004751 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004752 }
4753 bgp_unlock_node (child);
4754}
4755
paul94f2b392005-06-28 12:44:16 +00004756static void
paul718e3742002-12-13 20:15:29 +00004757bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4758 struct bgp_aggregate *aggregate)
4759{
4760 struct bgp_table *table;
4761 struct bgp_node *top;
4762 struct bgp_node *rn;
4763 struct bgp_info *new;
4764 struct bgp_info *ri;
4765 unsigned long match;
4766 u_char origin = BGP_ORIGIN_IGP;
4767 struct aspath *aspath = NULL;
4768 struct aspath *asmerge = NULL;
4769 struct community *community = NULL;
4770 struct community *commerge = NULL;
4771
4772 table = bgp->rib[afi][safi];
4773
4774 /* Sanity check. */
4775 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4776 return;
4777 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4778 return;
4779
4780 /* If routes exists below this node, generate aggregate routes. */
4781 top = bgp_node_get (table, p);
4782 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4783 if (rn->p.prefixlen > p->prefixlen)
4784 {
4785 match = 0;
4786
4787 for (ri = rn->info; ri; ri = ri->next)
4788 {
4789 if (BGP_INFO_HOLDDOWN (ri))
4790 continue;
4791
4792 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4793 {
4794 /* summary-only aggregate route suppress aggregated
4795 route announcement. */
4796 if (aggregate->summary_only)
4797 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004798 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004799 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004800 match++;
4801 }
4802 /* as-set aggregate route generate origin, as path,
4803 community aggregation. */
4804 if (aggregate->as_set)
4805 {
4806 if (origin < ri->attr->origin)
4807 origin = ri->attr->origin;
4808
4809 if (aspath)
4810 {
4811 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4812 aspath_free (aspath);
4813 aspath = asmerge;
4814 }
4815 else
4816 aspath = aspath_dup (ri->attr->aspath);
4817
4818 if (ri->attr->community)
4819 {
4820 if (community)
4821 {
4822 commerge = community_merge (community,
4823 ri->attr->community);
4824 community = community_uniq_sort (commerge);
4825 community_free (commerge);
4826 }
4827 else
4828 community = community_dup (ri->attr->community);
4829 }
4830 }
4831 aggregate->count++;
4832 }
4833 }
4834
4835 /* If this node is suppressed, process the change. */
4836 if (match)
4837 bgp_process (bgp, rn, afi, safi);
4838 }
4839 bgp_unlock_node (top);
4840
4841 /* Add aggregate route to BGP table. */
4842 if (aggregate->count)
4843 {
4844 rn = bgp_node_get (table, p);
4845
4846 new = bgp_info_new ();
4847 new->type = ZEBRA_ROUTE_BGP;
4848 new->sub_type = BGP_ROUTE_AGGREGATE;
4849 new->peer = bgp->peer_self;
4850 SET_FLAG (new->flags, BGP_INFO_VALID);
4851 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004852 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004853
4854 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004855 bgp_unlock_node (rn);
4856
paul718e3742002-12-13 20:15:29 +00004857 /* Process change. */
4858 bgp_process (bgp, rn, afi, safi);
4859 }
4860}
4861
4862void
4863bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4864 safi_t safi, struct bgp_aggregate *aggregate)
4865{
4866 struct bgp_table *table;
4867 struct bgp_node *top;
4868 struct bgp_node *rn;
4869 struct bgp_info *ri;
4870 unsigned long match;
4871
4872 table = bgp->rib[afi][safi];
4873
4874 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4875 return;
4876 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4877 return;
4878
4879 /* If routes exists below this node, generate aggregate routes. */
4880 top = bgp_node_get (table, p);
4881 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4882 if (rn->p.prefixlen > p->prefixlen)
4883 {
4884 match = 0;
4885
4886 for (ri = rn->info; ri; ri = ri->next)
4887 {
4888 if (BGP_INFO_HOLDDOWN (ri))
4889 continue;
4890
4891 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4892 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004893 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004894 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004895 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004896
Paul Jakmafb982c22007-05-04 20:15:47 +00004897 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004898 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004899 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004900 match++;
4901 }
4902 }
4903 aggregate->count--;
4904 }
4905 }
4906
Paul Jakmafb982c22007-05-04 20:15:47 +00004907 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004908 if (match)
4909 bgp_process (bgp, rn, afi, safi);
4910 }
4911 bgp_unlock_node (top);
4912
4913 /* Delete aggregate route from BGP table. */
4914 rn = bgp_node_get (table, p);
4915
4916 for (ri = rn->info; ri; ri = ri->next)
4917 if (ri->peer == bgp->peer_self
4918 && ri->type == ZEBRA_ROUTE_BGP
4919 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4920 break;
4921
4922 /* Withdraw static BGP route from routing table. */
4923 if (ri)
4924 {
paul718e3742002-12-13 20:15:29 +00004925 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004926 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004927 }
4928
4929 /* Unlock bgp_node_lookup. */
4930 bgp_unlock_node (rn);
4931}
4932
4933/* Aggregate route attribute. */
4934#define AGGREGATE_SUMMARY_ONLY 1
4935#define AGGREGATE_AS_SET 1
4936
paul94f2b392005-06-28 12:44:16 +00004937static int
Robert Baysf6269b42010-08-05 10:26:28 -07004938bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4939 afi_t afi, safi_t safi)
4940{
4941 int ret;
4942 struct prefix p;
4943 struct bgp_node *rn;
4944 struct bgp *bgp;
4945 struct bgp_aggregate *aggregate;
4946
4947 /* Convert string to prefix structure. */
4948 ret = str2prefix (prefix_str, &p);
4949 if (!ret)
4950 {
4951 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4952 return CMD_WARNING;
4953 }
4954 apply_mask (&p);
4955
4956 /* Get BGP structure. */
4957 bgp = vty->index;
4958
4959 /* Old configuration check. */
4960 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4961 if (! rn)
4962 {
4963 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4964 VTY_NEWLINE);
4965 return CMD_WARNING;
4966 }
4967
4968 aggregate = rn->info;
4969 if (aggregate->safi & SAFI_UNICAST)
4970 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4971 if (aggregate->safi & SAFI_MULTICAST)
4972 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4973
4974 /* Unlock aggregate address configuration. */
4975 rn->info = NULL;
4976 bgp_aggregate_free (aggregate);
4977 bgp_unlock_node (rn);
4978 bgp_unlock_node (rn);
4979
4980 return CMD_SUCCESS;
4981}
4982
4983static int
4984bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00004985 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004986 u_char summary_only, u_char as_set)
4987{
4988 int ret;
4989 struct prefix p;
4990 struct bgp_node *rn;
4991 struct bgp *bgp;
4992 struct bgp_aggregate *aggregate;
4993
4994 /* Convert string to prefix structure. */
4995 ret = str2prefix (prefix_str, &p);
4996 if (!ret)
4997 {
4998 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4999 return CMD_WARNING;
5000 }
5001 apply_mask (&p);
5002
5003 /* Get BGP structure. */
5004 bgp = vty->index;
5005
5006 /* Old configuration check. */
5007 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5008
5009 if (rn->info)
5010 {
5011 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005012 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005013 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5014 if (ret)
5015 {
Robert Bays368473f2010-08-05 10:26:29 -07005016 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5017 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005018 return CMD_WARNING;
5019 }
paul718e3742002-12-13 20:15:29 +00005020 }
5021
5022 /* Make aggregate address structure. */
5023 aggregate = bgp_aggregate_new ();
5024 aggregate->summary_only = summary_only;
5025 aggregate->as_set = as_set;
5026 aggregate->safi = safi;
5027 rn->info = aggregate;
5028
5029 /* Aggregate address insert into BGP routing table. */
5030 if (safi & SAFI_UNICAST)
5031 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5032 if (safi & SAFI_MULTICAST)
5033 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5034
5035 return CMD_SUCCESS;
5036}
5037
paul718e3742002-12-13 20:15:29 +00005038DEFUN (aggregate_address,
5039 aggregate_address_cmd,
5040 "aggregate-address A.B.C.D/M",
5041 "Configure BGP aggregate entries\n"
5042 "Aggregate prefix\n")
5043{
5044 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5045}
5046
5047DEFUN (aggregate_address_mask,
5048 aggregate_address_mask_cmd,
5049 "aggregate-address A.B.C.D A.B.C.D",
5050 "Configure BGP aggregate entries\n"
5051 "Aggregate address\n"
5052 "Aggregate mask\n")
5053{
5054 int ret;
5055 char prefix_str[BUFSIZ];
5056
5057 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5058
5059 if (! ret)
5060 {
5061 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5062 return CMD_WARNING;
5063 }
5064
5065 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5066 0, 0);
5067}
5068
5069DEFUN (aggregate_address_summary_only,
5070 aggregate_address_summary_only_cmd,
5071 "aggregate-address A.B.C.D/M summary-only",
5072 "Configure BGP aggregate entries\n"
5073 "Aggregate prefix\n"
5074 "Filter more specific routes from updates\n")
5075{
5076 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5077 AGGREGATE_SUMMARY_ONLY, 0);
5078}
5079
5080DEFUN (aggregate_address_mask_summary_only,
5081 aggregate_address_mask_summary_only_cmd,
5082 "aggregate-address A.B.C.D A.B.C.D summary-only",
5083 "Configure BGP aggregate entries\n"
5084 "Aggregate address\n"
5085 "Aggregate mask\n"
5086 "Filter more specific routes from updates\n")
5087{
5088 int ret;
5089 char prefix_str[BUFSIZ];
5090
5091 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5092
5093 if (! ret)
5094 {
5095 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5096 return CMD_WARNING;
5097 }
5098
5099 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5100 AGGREGATE_SUMMARY_ONLY, 0);
5101}
5102
5103DEFUN (aggregate_address_as_set,
5104 aggregate_address_as_set_cmd,
5105 "aggregate-address A.B.C.D/M as-set",
5106 "Configure BGP aggregate entries\n"
5107 "Aggregate prefix\n"
5108 "Generate AS set path information\n")
5109{
5110 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5111 0, AGGREGATE_AS_SET);
5112}
5113
5114DEFUN (aggregate_address_mask_as_set,
5115 aggregate_address_mask_as_set_cmd,
5116 "aggregate-address A.B.C.D A.B.C.D as-set",
5117 "Configure BGP aggregate entries\n"
5118 "Aggregate address\n"
5119 "Aggregate mask\n"
5120 "Generate AS set path information\n")
5121{
5122 int ret;
5123 char prefix_str[BUFSIZ];
5124
5125 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5126
5127 if (! ret)
5128 {
5129 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5130 return CMD_WARNING;
5131 }
5132
5133 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5134 0, AGGREGATE_AS_SET);
5135}
5136
5137
5138DEFUN (aggregate_address_as_set_summary,
5139 aggregate_address_as_set_summary_cmd,
5140 "aggregate-address A.B.C.D/M as-set summary-only",
5141 "Configure BGP aggregate entries\n"
5142 "Aggregate prefix\n"
5143 "Generate AS set path information\n"
5144 "Filter more specific routes from updates\n")
5145{
5146 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5147 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5148}
5149
5150ALIAS (aggregate_address_as_set_summary,
5151 aggregate_address_summary_as_set_cmd,
5152 "aggregate-address A.B.C.D/M summary-only as-set",
5153 "Configure BGP aggregate entries\n"
5154 "Aggregate prefix\n"
5155 "Filter more specific routes from updates\n"
5156 "Generate AS set path information\n")
5157
5158DEFUN (aggregate_address_mask_as_set_summary,
5159 aggregate_address_mask_as_set_summary_cmd,
5160 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5161 "Configure BGP aggregate entries\n"
5162 "Aggregate address\n"
5163 "Aggregate mask\n"
5164 "Generate AS set path information\n"
5165 "Filter more specific routes from updates\n")
5166{
5167 int ret;
5168 char prefix_str[BUFSIZ];
5169
5170 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5171
5172 if (! ret)
5173 {
5174 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5175 return CMD_WARNING;
5176 }
5177
5178 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5179 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5180}
5181
5182ALIAS (aggregate_address_mask_as_set_summary,
5183 aggregate_address_mask_summary_as_set_cmd,
5184 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5185 "Configure BGP aggregate entries\n"
5186 "Aggregate address\n"
5187 "Aggregate mask\n"
5188 "Filter more specific routes from updates\n"
5189 "Generate AS set path information\n")
5190
5191DEFUN (no_aggregate_address,
5192 no_aggregate_address_cmd,
5193 "no aggregate-address A.B.C.D/M",
5194 NO_STR
5195 "Configure BGP aggregate entries\n"
5196 "Aggregate prefix\n")
5197{
5198 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5199}
5200
5201ALIAS (no_aggregate_address,
5202 no_aggregate_address_summary_only_cmd,
5203 "no aggregate-address A.B.C.D/M summary-only",
5204 NO_STR
5205 "Configure BGP aggregate entries\n"
5206 "Aggregate prefix\n"
5207 "Filter more specific routes from updates\n")
5208
5209ALIAS (no_aggregate_address,
5210 no_aggregate_address_as_set_cmd,
5211 "no aggregate-address A.B.C.D/M as-set",
5212 NO_STR
5213 "Configure BGP aggregate entries\n"
5214 "Aggregate prefix\n"
5215 "Generate AS set path information\n")
5216
5217ALIAS (no_aggregate_address,
5218 no_aggregate_address_as_set_summary_cmd,
5219 "no aggregate-address A.B.C.D/M as-set summary-only",
5220 NO_STR
5221 "Configure BGP aggregate entries\n"
5222 "Aggregate prefix\n"
5223 "Generate AS set path information\n"
5224 "Filter more specific routes from updates\n")
5225
5226ALIAS (no_aggregate_address,
5227 no_aggregate_address_summary_as_set_cmd,
5228 "no aggregate-address A.B.C.D/M summary-only as-set",
5229 NO_STR
5230 "Configure BGP aggregate entries\n"
5231 "Aggregate prefix\n"
5232 "Filter more specific routes from updates\n"
5233 "Generate AS set path information\n")
5234
5235DEFUN (no_aggregate_address_mask,
5236 no_aggregate_address_mask_cmd,
5237 "no aggregate-address A.B.C.D A.B.C.D",
5238 NO_STR
5239 "Configure BGP aggregate entries\n"
5240 "Aggregate address\n"
5241 "Aggregate mask\n")
5242{
5243 int ret;
5244 char prefix_str[BUFSIZ];
5245
5246 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5247
5248 if (! ret)
5249 {
5250 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5251 return CMD_WARNING;
5252 }
5253
5254 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5255}
5256
5257ALIAS (no_aggregate_address_mask,
5258 no_aggregate_address_mask_summary_only_cmd,
5259 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5260 NO_STR
5261 "Configure BGP aggregate entries\n"
5262 "Aggregate address\n"
5263 "Aggregate mask\n"
5264 "Filter more specific routes from updates\n")
5265
5266ALIAS (no_aggregate_address_mask,
5267 no_aggregate_address_mask_as_set_cmd,
5268 "no aggregate-address A.B.C.D A.B.C.D as-set",
5269 NO_STR
5270 "Configure BGP aggregate entries\n"
5271 "Aggregate address\n"
5272 "Aggregate mask\n"
5273 "Generate AS set path information\n")
5274
5275ALIAS (no_aggregate_address_mask,
5276 no_aggregate_address_mask_as_set_summary_cmd,
5277 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5278 NO_STR
5279 "Configure BGP aggregate entries\n"
5280 "Aggregate address\n"
5281 "Aggregate mask\n"
5282 "Generate AS set path information\n"
5283 "Filter more specific routes from updates\n")
5284
5285ALIAS (no_aggregate_address_mask,
5286 no_aggregate_address_mask_summary_as_set_cmd,
5287 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5288 NO_STR
5289 "Configure BGP aggregate entries\n"
5290 "Aggregate address\n"
5291 "Aggregate mask\n"
5292 "Filter more specific routes from updates\n"
5293 "Generate AS set path information\n")
5294
5295#ifdef HAVE_IPV6
5296DEFUN (ipv6_aggregate_address,
5297 ipv6_aggregate_address_cmd,
5298 "aggregate-address X:X::X:X/M",
5299 "Configure BGP aggregate entries\n"
5300 "Aggregate prefix\n")
5301{
5302 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5303}
5304
5305DEFUN (ipv6_aggregate_address_summary_only,
5306 ipv6_aggregate_address_summary_only_cmd,
5307 "aggregate-address X:X::X:X/M summary-only",
5308 "Configure BGP aggregate entries\n"
5309 "Aggregate prefix\n"
5310 "Filter more specific routes from updates\n")
5311{
5312 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5313 AGGREGATE_SUMMARY_ONLY, 0);
5314}
5315
5316DEFUN (no_ipv6_aggregate_address,
5317 no_ipv6_aggregate_address_cmd,
5318 "no aggregate-address X:X::X:X/M",
5319 NO_STR
5320 "Configure BGP aggregate entries\n"
5321 "Aggregate prefix\n")
5322{
5323 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5324}
5325
5326DEFUN (no_ipv6_aggregate_address_summary_only,
5327 no_ipv6_aggregate_address_summary_only_cmd,
5328 "no aggregate-address X:X::X:X/M summary-only",
5329 NO_STR
5330 "Configure BGP aggregate entries\n"
5331 "Aggregate prefix\n"
5332 "Filter more specific routes from updates\n")
5333{
5334 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5335}
5336
5337ALIAS (ipv6_aggregate_address,
5338 old_ipv6_aggregate_address_cmd,
5339 "ipv6 bgp aggregate-address X:X::X:X/M",
5340 IPV6_STR
5341 BGP_STR
5342 "Configure BGP aggregate entries\n"
5343 "Aggregate prefix\n")
5344
5345ALIAS (ipv6_aggregate_address_summary_only,
5346 old_ipv6_aggregate_address_summary_only_cmd,
5347 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5348 IPV6_STR
5349 BGP_STR
5350 "Configure BGP aggregate entries\n"
5351 "Aggregate prefix\n"
5352 "Filter more specific routes from updates\n")
5353
5354ALIAS (no_ipv6_aggregate_address,
5355 old_no_ipv6_aggregate_address_cmd,
5356 "no ipv6 bgp aggregate-address X:X::X:X/M",
5357 NO_STR
5358 IPV6_STR
5359 BGP_STR
5360 "Configure BGP aggregate entries\n"
5361 "Aggregate prefix\n")
5362
5363ALIAS (no_ipv6_aggregate_address_summary_only,
5364 old_no_ipv6_aggregate_address_summary_only_cmd,
5365 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5366 NO_STR
5367 IPV6_STR
5368 BGP_STR
5369 "Configure BGP aggregate entries\n"
5370 "Aggregate prefix\n"
5371 "Filter more specific routes from updates\n")
5372#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02005373
paul718e3742002-12-13 20:15:29 +00005374/* Redistribute route treatment. */
5375void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005376bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5377 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005378 u_int32_t metric, u_char type)
5379{
5380 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005381 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005382 struct bgp_info *new;
5383 struct bgp_info *bi;
5384 struct bgp_info info;
5385 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005386 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005387 struct attr *new_attr;
5388 afi_t afi;
5389 int ret;
5390
5391 /* Make default attribute. */
5392 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5393 if (nexthop)
5394 attr.nexthop = *nexthop;
5395
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005396#ifdef HAVE_IPV6
5397 if (nexthop6)
5398 {
5399 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5400 extra->mp_nexthop_global = *nexthop6;
5401 extra->mp_nexthop_len = 16;
5402 }
5403#endif
5404
paul718e3742002-12-13 20:15:29 +00005405 attr.med = metric;
5406 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5407
paul1eb8ef22005-04-07 07:30:20 +00005408 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005409 {
5410 afi = family2afi (p->family);
5411
5412 if (bgp->redist[afi][type])
5413 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005414 struct attr attr_new;
5415 struct attr_extra extra_new;
5416
paul718e3742002-12-13 20:15:29 +00005417 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005418 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005419 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005420
5421 if (bgp->redist_metric_flag[afi][type])
5422 attr_new.med = bgp->redist_metric[afi][type];
5423
5424 /* Apply route-map. */
5425 if (bgp->rmap[afi][type].map)
5426 {
5427 info.peer = bgp->peer_self;
5428 info.attr = &attr_new;
5429
paulfee0f4c2004-09-13 05:12:46 +00005430 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5431
paul718e3742002-12-13 20:15:29 +00005432 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5433 &info);
paulfee0f4c2004-09-13 05:12:46 +00005434
5435 bgp->peer_self->rmap_type = 0;
5436
paul718e3742002-12-13 20:15:29 +00005437 if (ret == RMAP_DENYMATCH)
5438 {
5439 /* Free uninterned attribute. */
5440 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005441
paul718e3742002-12-13 20:15:29 +00005442 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005443 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005444 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005445 bgp_redistribute_delete (p, type);
5446 return;
5447 }
5448 }
5449
Paul Jakmafb982c22007-05-04 20:15:47 +00005450 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5451 afi, SAFI_UNICAST, p, NULL);
5452
paul718e3742002-12-13 20:15:29 +00005453 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005454
paul718e3742002-12-13 20:15:29 +00005455 for (bi = bn->info; bi; bi = bi->next)
5456 if (bi->peer == bgp->peer_self
5457 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5458 break;
5459
5460 if (bi)
5461 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005462 if (attrhash_cmp (bi->attr, new_attr) &&
5463 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005464 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005465 bgp_attr_unintern (&new_attr);
5466 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005467 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005468 bgp_unlock_node (bn);
5469 return;
5470 }
5471 else
5472 {
5473 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005474 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005475
5476 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005477 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5478 bgp_info_restore(bn, bi);
5479 else
5480 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005481 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005482 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005483 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005484
5485 /* Process change. */
5486 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5487 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5488 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005489 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005490 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005491 return;
5492 }
5493 }
5494
5495 new = bgp_info_new ();
5496 new->type = type;
5497 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5498 new->peer = bgp->peer_self;
5499 SET_FLAG (new->flags, BGP_INFO_VALID);
5500 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005501 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005502
5503 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5504 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005505 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005506 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5507 }
5508 }
5509
5510 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005511 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005512 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005513}
5514
5515void
5516bgp_redistribute_delete (struct prefix *p, u_char type)
5517{
5518 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005519 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005520 afi_t afi;
5521 struct bgp_node *rn;
5522 struct bgp_info *ri;
5523
paul1eb8ef22005-04-07 07:30:20 +00005524 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005525 {
5526 afi = family2afi (p->family);
5527
5528 if (bgp->redist[afi][type])
5529 {
paulfee0f4c2004-09-13 05:12:46 +00005530 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005531
5532 for (ri = rn->info; ri; ri = ri->next)
5533 if (ri->peer == bgp->peer_self
5534 && ri->type == type)
5535 break;
5536
5537 if (ri)
5538 {
5539 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005540 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005541 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005542 }
5543 bgp_unlock_node (rn);
5544 }
5545 }
5546}
5547
5548/* Withdraw specified route type's route. */
5549void
5550bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5551{
5552 struct bgp_node *rn;
5553 struct bgp_info *ri;
5554 struct bgp_table *table;
5555
5556 table = bgp->rib[afi][SAFI_UNICAST];
5557
5558 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5559 {
5560 for (ri = rn->info; ri; ri = ri->next)
5561 if (ri->peer == bgp->peer_self
5562 && ri->type == type)
5563 break;
5564
5565 if (ri)
5566 {
5567 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005568 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005569 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005570 }
5571 }
5572}
David Lamparter6b0655a2014-06-04 06:53:35 +02005573
paul718e3742002-12-13 20:15:29 +00005574/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005575static void
paul718e3742002-12-13 20:15:29 +00005576route_vty_out_route (struct prefix *p, struct vty *vty)
5577{
5578 int len;
5579 u_int32_t destination;
5580 char buf[BUFSIZ];
5581
5582 if (p->family == AF_INET)
5583 {
5584 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5585 destination = ntohl (p->u.prefix4.s_addr);
5586
5587 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5588 || (IN_CLASSB (destination) && p->prefixlen == 16)
5589 || (IN_CLASSA (destination) && p->prefixlen == 8)
5590 || p->u.prefix4.s_addr == 0)
5591 {
5592 /* When mask is natural, mask is not displayed. */
5593 }
5594 else
5595 len += vty_out (vty, "/%d", p->prefixlen);
5596 }
5597 else
5598 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5599 p->prefixlen);
5600
5601 len = 17 - len;
5602 if (len < 1)
5603 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5604 else
5605 vty_out (vty, "%*s", len, " ");
5606}
5607
paul718e3742002-12-13 20:15:29 +00005608enum bgp_display_type
5609{
5610 normal_list,
5611};
5612
paulb40d9392005-08-22 22:34:41 +00005613/* Print the short form route status for a bgp_info */
5614static void
5615route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005616{
paulb40d9392005-08-22 22:34:41 +00005617 /* Route status display. */
5618 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5619 vty_out (vty, "R");
5620 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005621 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005622 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005623 vty_out (vty, "s");
5624 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5625 vty_out (vty, "*");
5626 else
5627 vty_out (vty, " ");
5628
5629 /* Selected */
5630 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5631 vty_out (vty, "h");
5632 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5633 vty_out (vty, "d");
5634 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5635 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005636 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5637 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005638 else
5639 vty_out (vty, " ");
5640
5641 /* Internal route. */
5642 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5643 vty_out (vty, "i");
5644 else
paulb40d9392005-08-22 22:34:41 +00005645 vty_out (vty, " ");
5646}
5647
5648/* called from terminal list command */
5649void
5650route_vty_out (struct vty *vty, struct prefix *p,
5651 struct bgp_info *binfo, int display, safi_t safi)
5652{
5653 struct attr *attr;
5654
5655 /* short status lead text */
5656 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005657
5658 /* print prefix and mask */
5659 if (! display)
5660 route_vty_out_route (p, vty);
5661 else
5662 vty_out (vty, "%*s", 17, " ");
5663
5664 /* Print attribute */
5665 attr = binfo->attr;
5666 if (attr)
5667 {
5668 if (p->family == AF_INET)
5669 {
5670 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005671 vty_out (vty, "%-16s",
5672 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005673 else
5674 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5675 }
5676#ifdef HAVE_IPV6
5677 else if (p->family == AF_INET6)
5678 {
5679 int len;
5680 char buf[BUFSIZ];
5681
5682 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005683 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5684 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005685 len = 16 - len;
5686 if (len < 1)
5687 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5688 else
5689 vty_out (vty, "%*s", len, " ");
5690 }
5691#endif /* HAVE_IPV6 */
5692
5693 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005694 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005695 else
5696 vty_out (vty, " ");
5697
5698 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005699 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005700 else
5701 vty_out (vty, " ");
5702
Paul Jakmafb982c22007-05-04 20:15:47 +00005703 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005704
Paul Jakmab2518c12006-05-12 23:48:40 +00005705 /* Print aspath */
5706 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005707 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005708
Paul Jakmab2518c12006-05-12 23:48:40 +00005709 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005710 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005711 }
paul718e3742002-12-13 20:15:29 +00005712 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005713}
5714
5715/* called from terminal list command */
5716void
5717route_vty_out_tmp (struct vty *vty, struct prefix *p,
5718 struct attr *attr, safi_t safi)
5719{
5720 /* Route status display. */
5721 vty_out (vty, "*");
5722 vty_out (vty, ">");
5723 vty_out (vty, " ");
5724
5725 /* print prefix and mask */
5726 route_vty_out_route (p, vty);
5727
5728 /* Print attribute */
5729 if (attr)
5730 {
5731 if (p->family == AF_INET)
5732 {
5733 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005734 vty_out (vty, "%-16s",
5735 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005736 else
5737 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5738 }
5739#ifdef HAVE_IPV6
5740 else if (p->family == AF_INET6)
5741 {
5742 int len;
5743 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005744
5745 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005746
5747 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005748 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5749 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005750 len = 16 - len;
5751 if (len < 1)
5752 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5753 else
5754 vty_out (vty, "%*s", len, " ");
5755 }
5756#endif /* HAVE_IPV6 */
5757
5758 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005759 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005760 else
5761 vty_out (vty, " ");
5762
5763 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005764 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005765 else
5766 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005767
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005768 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005769
Paul Jakmab2518c12006-05-12 23:48:40 +00005770 /* Print aspath */
5771 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005772 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005773
Paul Jakmab2518c12006-05-12 23:48:40 +00005774 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005775 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005776 }
paul718e3742002-12-13 20:15:29 +00005777
5778 vty_out (vty, "%s", VTY_NEWLINE);
5779}
5780
ajs5a646652004-11-05 01:25:55 +00005781void
paul718e3742002-12-13 20:15:29 +00005782route_vty_out_tag (struct vty *vty, struct prefix *p,
5783 struct bgp_info *binfo, int display, safi_t safi)
5784{
5785 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005786 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005787
5788 if (!binfo->extra)
5789 return;
5790
paulb40d9392005-08-22 22:34:41 +00005791 /* short status lead text */
5792 route_vty_short_status_out (vty, binfo);
5793
paul718e3742002-12-13 20:15:29 +00005794 /* print prefix and mask */
5795 if (! display)
5796 route_vty_out_route (p, vty);
5797 else
5798 vty_out (vty, "%*s", 17, " ");
5799
5800 /* Print attribute */
5801 attr = binfo->attr;
5802 if (attr)
5803 {
5804 if (p->family == AF_INET)
5805 {
5806 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005807 vty_out (vty, "%-16s",
5808 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005809 else
5810 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5811 }
5812#ifdef HAVE_IPV6
5813 else if (p->family == AF_INET6)
5814 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005815 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005816 char buf[BUFSIZ];
5817 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005818 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005819 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005820 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5821 buf, BUFSIZ));
5822 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005823 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005824 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5825 buf, BUFSIZ),
5826 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5827 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005828
5829 }
5830#endif /* HAVE_IPV6 */
5831 }
5832
Paul Jakmafb982c22007-05-04 20:15:47 +00005833 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005834
5835 vty_out (vty, "notag/%d", label);
5836
5837 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005838}
5839
5840/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005841static void
paul718e3742002-12-13 20:15:29 +00005842damp_route_vty_out (struct vty *vty, struct prefix *p,
5843 struct bgp_info *binfo, int display, safi_t safi)
5844{
5845 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005846 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005847 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005848
paulb40d9392005-08-22 22:34:41 +00005849 /* short status lead text */
5850 route_vty_short_status_out (vty, binfo);
5851
paul718e3742002-12-13 20:15:29 +00005852 /* print prefix and mask */
5853 if (! display)
5854 route_vty_out_route (p, vty);
5855 else
5856 vty_out (vty, "%*s", 17, " ");
5857
5858 len = vty_out (vty, "%s", binfo->peer->host);
5859 len = 17 - len;
5860 if (len < 1)
5861 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5862 else
5863 vty_out (vty, "%*s", len, " ");
5864
Chris Caputo50aef6f2009-06-23 06:06:49 +00005865 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005866
5867 /* Print attribute */
5868 attr = binfo->attr;
5869 if (attr)
5870 {
5871 /* Print aspath */
5872 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005873 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005874
5875 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005876 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005877 }
5878 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005879}
5880
paul718e3742002-12-13 20:15:29 +00005881/* flap route */
ajs5a646652004-11-05 01:25:55 +00005882static void
paul718e3742002-12-13 20:15:29 +00005883flap_route_vty_out (struct vty *vty, struct prefix *p,
5884 struct bgp_info *binfo, int display, safi_t safi)
5885{
5886 struct attr *attr;
5887 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005888 char timebuf[BGP_UPTIME_LEN];
5889 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005890
5891 if (!binfo->extra)
5892 return;
5893
5894 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005895
paulb40d9392005-08-22 22:34:41 +00005896 /* short status lead text */
5897 route_vty_short_status_out (vty, binfo);
5898
paul718e3742002-12-13 20:15:29 +00005899 /* print prefix and mask */
5900 if (! display)
5901 route_vty_out_route (p, vty);
5902 else
5903 vty_out (vty, "%*s", 17, " ");
5904
5905 len = vty_out (vty, "%s", binfo->peer->host);
5906 len = 16 - len;
5907 if (len < 1)
5908 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5909 else
5910 vty_out (vty, "%*s", len, " ");
5911
5912 len = vty_out (vty, "%d", bdi->flap);
5913 len = 5 - len;
5914 if (len < 1)
5915 vty_out (vty, " ");
5916 else
5917 vty_out (vty, "%*s ", len, " ");
5918
5919 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5920 timebuf, BGP_UPTIME_LEN));
5921
5922 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5923 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005924 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005925 else
5926 vty_out (vty, "%*s ", 8, " ");
5927
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
paul94f2b392005-06-28 12:44:16 +00005942static void
paul718e3742002-12-13 20:15:29 +00005943route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5944 struct bgp_info *binfo, afi_t afi, safi_t safi)
5945{
5946 char buf[INET6_ADDRSTRLEN];
5947 char buf1[BUFSIZ];
5948 struct attr *attr;
5949 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005950#ifdef HAVE_CLOCK_MONOTONIC
5951 time_t tbuf;
5952#endif
paul718e3742002-12-13 20:15:29 +00005953
5954 attr = binfo->attr;
5955
5956 if (attr)
5957 {
5958 /* Line1 display AS-path, Aggregator */
5959 if (attr->aspath)
5960 {
5961 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005962 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005963 vty_out (vty, "Local");
5964 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005965 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005966 }
5967
paulb40d9392005-08-22 22:34:41 +00005968 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5969 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005970 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5971 vty_out (vty, ", (stale)");
5972 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005973 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005974 attr->extra->aggregator_as,
5975 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005976 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5977 vty_out (vty, ", (Received from a RR-client)");
5978 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5979 vty_out (vty, ", (Received from a RS-client)");
5980 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5981 vty_out (vty, ", (history entry)");
5982 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5983 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005984 vty_out (vty, "%s", VTY_NEWLINE);
5985
5986 /* Line2 display Next-hop, Neighbor, Router-id */
5987 if (p->family == AF_INET)
5988 {
5989 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005990 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005991 inet_ntoa (attr->nexthop));
5992 }
5993#ifdef HAVE_IPV6
5994 else
5995 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005996 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005997 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005998 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005999 buf, INET6_ADDRSTRLEN));
6000 }
6001#endif /* HAVE_IPV6 */
6002
6003 if (binfo->peer == bgp->peer_self)
6004 {
6005 vty_out (vty, " from %s ",
6006 p->family == AF_INET ? "0.0.0.0" : "::");
6007 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6008 }
6009 else
6010 {
6011 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6012 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006013 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006014 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006015 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006016 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006017 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006018 else
6019 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6020 }
6021 vty_out (vty, "%s", VTY_NEWLINE);
6022
6023#ifdef HAVE_IPV6
6024 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006025 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006026 {
6027 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006028 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006029 buf, INET6_ADDRSTRLEN),
6030 VTY_NEWLINE);
6031 }
6032#endif /* HAVE_IPV6 */
6033
6034 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6035 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6036
6037 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006038 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006039
6040 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006041 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006042 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006043 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006044
Paul Jakmafb982c22007-05-04 20:15:47 +00006045 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006046 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006047
6048 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6049 vty_out (vty, ", valid");
6050
6051 if (binfo->peer != bgp->peer_self)
6052 {
6053 if (binfo->peer->as == binfo->peer->local_as)
6054 vty_out (vty, ", internal");
6055 else
6056 vty_out (vty, ", %s",
6057 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6058 }
6059 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6060 vty_out (vty, ", aggregated, local");
6061 else if (binfo->type != ZEBRA_ROUTE_BGP)
6062 vty_out (vty, ", sourced");
6063 else
6064 vty_out (vty, ", sourced, local");
6065
6066 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6067 vty_out (vty, ", atomic-aggregate");
6068
Josh Baileyde8d5df2011-07-20 20:46:01 -07006069 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6070 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6071 bgp_info_mpath_count (binfo)))
6072 vty_out (vty, ", multipath");
6073
paul718e3742002-12-13 20:15:29 +00006074 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6075 vty_out (vty, ", best");
6076
6077 vty_out (vty, "%s", VTY_NEWLINE);
6078
6079 /* Line 4 display Community */
6080 if (attr->community)
6081 vty_out (vty, " Community: %s%s", attr->community->str,
6082 VTY_NEWLINE);
6083
6084 /* Line 5 display Extended-community */
6085 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006086 vty_out (vty, " Extended Community: %s%s",
6087 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006088
6089 /* Line 6 display Originator, Cluster-id */
6090 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6091 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6092 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006093 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006094 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006095 vty_out (vty, " Originator: %s",
6096 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006097
6098 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6099 {
6100 int i;
6101 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006102 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6103 vty_out (vty, "%s ",
6104 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006105 }
6106 vty_out (vty, "%s", VTY_NEWLINE);
6107 }
Paul Jakma41367172007-08-06 15:24:51 +00006108
Paul Jakmafb982c22007-05-04 20:15:47 +00006109 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006110 bgp_damp_info_vty (vty, binfo);
6111
6112 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006113#ifdef HAVE_CLOCK_MONOTONIC
6114 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006115 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006116#else
6117 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6118#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006119 }
6120 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006121}
6122
6123#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6124 "h history, * valid, > best, = multipath,%s"\
6125 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006126#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006127#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6128#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6129#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6130
6131enum bgp_show_type
6132{
6133 bgp_show_type_normal,
6134 bgp_show_type_regexp,
6135 bgp_show_type_prefix_list,
6136 bgp_show_type_filter_list,
6137 bgp_show_type_route_map,
6138 bgp_show_type_neighbor,
6139 bgp_show_type_cidr_only,
6140 bgp_show_type_prefix_longer,
6141 bgp_show_type_community_all,
6142 bgp_show_type_community,
6143 bgp_show_type_community_exact,
6144 bgp_show_type_community_list,
6145 bgp_show_type_community_list_exact,
6146 bgp_show_type_flap_statistics,
6147 bgp_show_type_flap_address,
6148 bgp_show_type_flap_prefix,
6149 bgp_show_type_flap_cidr_only,
6150 bgp_show_type_flap_regexp,
6151 bgp_show_type_flap_filter_list,
6152 bgp_show_type_flap_prefix_list,
6153 bgp_show_type_flap_prefix_longer,
6154 bgp_show_type_flap_route_map,
6155 bgp_show_type_flap_neighbor,
6156 bgp_show_type_dampend_paths,
6157 bgp_show_type_damp_neighbor
6158};
6159
ajs5a646652004-11-05 01:25:55 +00006160static int
paulfee0f4c2004-09-13 05:12:46 +00006161bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006162 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006163{
paul718e3742002-12-13 20:15:29 +00006164 struct bgp_info *ri;
6165 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006166 int header = 1;
paul718e3742002-12-13 20:15:29 +00006167 int display;
ajs5a646652004-11-05 01:25:55 +00006168 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006169
6170 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006171 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006172
paul718e3742002-12-13 20:15:29 +00006173 /* Start processing of routes. */
6174 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6175 if (rn->info != NULL)
6176 {
6177 display = 0;
6178
6179 for (ri = rn->info; ri; ri = ri->next)
6180 {
ajs5a646652004-11-05 01:25:55 +00006181 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006182 || type == bgp_show_type_flap_address
6183 || type == bgp_show_type_flap_prefix
6184 || type == bgp_show_type_flap_cidr_only
6185 || type == bgp_show_type_flap_regexp
6186 || type == bgp_show_type_flap_filter_list
6187 || type == bgp_show_type_flap_prefix_list
6188 || type == bgp_show_type_flap_prefix_longer
6189 || type == bgp_show_type_flap_route_map
6190 || type == bgp_show_type_flap_neighbor
6191 || type == bgp_show_type_dampend_paths
6192 || type == bgp_show_type_damp_neighbor)
6193 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006194 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006195 continue;
6196 }
6197 if (type == bgp_show_type_regexp
6198 || type == bgp_show_type_flap_regexp)
6199 {
ajs5a646652004-11-05 01:25:55 +00006200 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006201
6202 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6203 continue;
6204 }
6205 if (type == bgp_show_type_prefix_list
6206 || type == bgp_show_type_flap_prefix_list)
6207 {
ajs5a646652004-11-05 01:25:55 +00006208 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006209
6210 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6211 continue;
6212 }
6213 if (type == bgp_show_type_filter_list
6214 || type == bgp_show_type_flap_filter_list)
6215 {
ajs5a646652004-11-05 01:25:55 +00006216 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006217
6218 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6219 continue;
6220 }
6221 if (type == bgp_show_type_route_map
6222 || type == bgp_show_type_flap_route_map)
6223 {
ajs5a646652004-11-05 01:25:55 +00006224 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006225 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006226 struct attr dummy_attr;
6227 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006228 int ret;
6229
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006230 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006231 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006232
paul718e3742002-12-13 20:15:29 +00006233 binfo.peer = ri->peer;
6234 binfo.attr = &dummy_attr;
6235
6236 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006237 if (ret == RMAP_DENYMATCH)
6238 continue;
6239 }
6240 if (type == bgp_show_type_neighbor
6241 || type == bgp_show_type_flap_neighbor
6242 || type == bgp_show_type_damp_neighbor)
6243 {
ajs5a646652004-11-05 01:25:55 +00006244 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006245
6246 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6247 continue;
6248 }
6249 if (type == bgp_show_type_cidr_only
6250 || type == bgp_show_type_flap_cidr_only)
6251 {
6252 u_int32_t destination;
6253
6254 destination = ntohl (rn->p.u.prefix4.s_addr);
6255 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6256 continue;
6257 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6258 continue;
6259 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6260 continue;
6261 }
6262 if (type == bgp_show_type_prefix_longer
6263 || type == bgp_show_type_flap_prefix_longer)
6264 {
ajs5a646652004-11-05 01:25:55 +00006265 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006266
6267 if (! prefix_match (p, &rn->p))
6268 continue;
6269 }
6270 if (type == bgp_show_type_community_all)
6271 {
6272 if (! ri->attr->community)
6273 continue;
6274 }
6275 if (type == bgp_show_type_community)
6276 {
ajs5a646652004-11-05 01:25:55 +00006277 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006278
6279 if (! ri->attr->community ||
6280 ! community_match (ri->attr->community, com))
6281 continue;
6282 }
6283 if (type == bgp_show_type_community_exact)
6284 {
ajs5a646652004-11-05 01:25:55 +00006285 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006286
6287 if (! ri->attr->community ||
6288 ! community_cmp (ri->attr->community, com))
6289 continue;
6290 }
6291 if (type == bgp_show_type_community_list)
6292 {
ajs5a646652004-11-05 01:25:55 +00006293 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006294
6295 if (! community_list_match (ri->attr->community, list))
6296 continue;
6297 }
6298 if (type == bgp_show_type_community_list_exact)
6299 {
ajs5a646652004-11-05 01:25:55 +00006300 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006301
6302 if (! community_list_exact_match (ri->attr->community, list))
6303 continue;
6304 }
6305 if (type == bgp_show_type_flap_address
6306 || type == bgp_show_type_flap_prefix)
6307 {
ajs5a646652004-11-05 01:25:55 +00006308 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006309
6310 if (! prefix_match (&rn->p, p))
6311 continue;
6312
6313 if (type == bgp_show_type_flap_prefix)
6314 if (p->prefixlen != rn->p.prefixlen)
6315 continue;
6316 }
6317 if (type == bgp_show_type_dampend_paths
6318 || type == bgp_show_type_damp_neighbor)
6319 {
6320 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6321 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6322 continue;
6323 }
6324
6325 if (header)
6326 {
hasso93406d82005-02-02 14:40:33 +00006327 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6328 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6329 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006330 if (type == bgp_show_type_dampend_paths
6331 || type == bgp_show_type_damp_neighbor)
6332 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6333 else if (type == bgp_show_type_flap_statistics
6334 || type == bgp_show_type_flap_address
6335 || type == bgp_show_type_flap_prefix
6336 || type == bgp_show_type_flap_cidr_only
6337 || type == bgp_show_type_flap_regexp
6338 || type == bgp_show_type_flap_filter_list
6339 || type == bgp_show_type_flap_prefix_list
6340 || type == bgp_show_type_flap_prefix_longer
6341 || type == bgp_show_type_flap_route_map
6342 || type == bgp_show_type_flap_neighbor)
6343 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6344 else
6345 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006346 header = 0;
6347 }
6348
6349 if (type == bgp_show_type_dampend_paths
6350 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006351 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006352 else if (type == bgp_show_type_flap_statistics
6353 || type == bgp_show_type_flap_address
6354 || type == bgp_show_type_flap_prefix
6355 || type == bgp_show_type_flap_cidr_only
6356 || type == bgp_show_type_flap_regexp
6357 || type == bgp_show_type_flap_filter_list
6358 || type == bgp_show_type_flap_prefix_list
6359 || type == bgp_show_type_flap_prefix_longer
6360 || type == bgp_show_type_flap_route_map
6361 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006362 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006363 else
ajs5a646652004-11-05 01:25:55 +00006364 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006365 display++;
6366 }
6367 if (display)
ajs5a646652004-11-05 01:25:55 +00006368 output_count++;
paul718e3742002-12-13 20:15:29 +00006369 }
6370
6371 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006372 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006373 {
6374 if (type == bgp_show_type_normal)
6375 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6376 }
6377 else
6378 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006379 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006380
6381 return CMD_SUCCESS;
6382}
6383
ajs5a646652004-11-05 01:25:55 +00006384static int
paulfee0f4c2004-09-13 05:12:46 +00006385bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006386 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006387{
6388 struct bgp_table *table;
6389
6390 if (bgp == NULL) {
6391 bgp = bgp_get_default ();
6392 }
6393
6394 if (bgp == NULL)
6395 {
6396 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6397 return CMD_WARNING;
6398 }
6399
6400
6401 table = bgp->rib[afi][safi];
6402
ajs5a646652004-11-05 01:25:55 +00006403 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006404}
6405
paul718e3742002-12-13 20:15:29 +00006406/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006407static void
paul718e3742002-12-13 20:15:29 +00006408route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6409 struct bgp_node *rn,
6410 struct prefix_rd *prd, afi_t afi, safi_t safi)
6411{
6412 struct bgp_info *ri;
6413 struct prefix *p;
6414 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006415 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006416 char buf1[INET6_ADDRSTRLEN];
6417 char buf2[INET6_ADDRSTRLEN];
6418 int count = 0;
6419 int best = 0;
6420 int suppress = 0;
6421 int no_export = 0;
6422 int no_advertise = 0;
6423 int local_as = 0;
6424 int first = 0;
6425
6426 p = &rn->p;
6427 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6428 (safi == SAFI_MPLS_VPN ?
6429 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6430 safi == SAFI_MPLS_VPN ? ":" : "",
6431 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6432 p->prefixlen, VTY_NEWLINE);
6433
6434 for (ri = rn->info; ri; ri = ri->next)
6435 {
6436 count++;
6437 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6438 {
6439 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006440 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006441 suppress = 1;
6442 if (ri->attr->community != NULL)
6443 {
6444 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6445 no_advertise = 1;
6446 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6447 no_export = 1;
6448 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6449 local_as = 1;
6450 }
6451 }
6452 }
6453
6454 vty_out (vty, "Paths: (%d available", count);
6455 if (best)
6456 {
6457 vty_out (vty, ", best #%d", best);
6458 if (safi == SAFI_UNICAST)
6459 vty_out (vty, ", table Default-IP-Routing-Table");
6460 }
6461 else
6462 vty_out (vty, ", no best path");
6463 if (no_advertise)
6464 vty_out (vty, ", not advertised to any peer");
6465 else if (no_export)
6466 vty_out (vty, ", not advertised to EBGP peer");
6467 else if (local_as)
6468 vty_out (vty, ", not advertised outside local AS");
6469 if (suppress)
6470 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6471 vty_out (vty, ")%s", VTY_NEWLINE);
6472
6473 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006474 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006475 {
6476 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6477 {
6478 if (! first)
6479 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6480 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6481 first = 1;
6482 }
6483 }
6484 if (! first)
6485 vty_out (vty, " Not advertised to any peer");
6486 vty_out (vty, "%s", VTY_NEWLINE);
6487}
6488
6489/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006490static int
paulfee0f4c2004-09-13 05:12:46 +00006491bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006492 struct bgp_table *rib, const char *ip_str,
6493 afi_t afi, safi_t safi, struct prefix_rd *prd,
6494 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006495{
6496 int ret;
6497 int header;
6498 int display = 0;
6499 struct prefix match;
6500 struct bgp_node *rn;
6501 struct bgp_node *rm;
6502 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006503 struct bgp_table *table;
6504
paul718e3742002-12-13 20:15:29 +00006505 /* Check IP address argument. */
6506 ret = str2prefix (ip_str, &match);
6507 if (! ret)
6508 {
6509 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6510 return CMD_WARNING;
6511 }
6512
6513 match.family = afi2family (afi);
6514
6515 if (safi == SAFI_MPLS_VPN)
6516 {
paulfee0f4c2004-09-13 05:12:46 +00006517 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006518 {
6519 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6520 continue;
6521
6522 if ((table = rn->info) != NULL)
6523 {
6524 header = 1;
6525
6526 if ((rm = bgp_node_match (table, &match)) != NULL)
6527 {
6528 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006529 {
6530 bgp_unlock_node (rm);
6531 continue;
6532 }
paul718e3742002-12-13 20:15:29 +00006533
6534 for (ri = rm->info; ri; ri = ri->next)
6535 {
6536 if (header)
6537 {
6538 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6539 AFI_IP, SAFI_MPLS_VPN);
6540
6541 header = 0;
6542 }
6543 display++;
6544 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6545 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006546
6547 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006548 }
6549 }
6550 }
6551 }
6552 else
6553 {
6554 header = 1;
6555
paulfee0f4c2004-09-13 05:12:46 +00006556 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006557 {
6558 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6559 {
6560 for (ri = rn->info; ri; ri = ri->next)
6561 {
6562 if (header)
6563 {
6564 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6565 header = 0;
6566 }
6567 display++;
6568 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6569 }
6570 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006571
6572 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006573 }
6574 }
6575
6576 if (! display)
6577 {
6578 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6579 return CMD_WARNING;
6580 }
6581
6582 return CMD_SUCCESS;
6583}
6584
paulfee0f4c2004-09-13 05:12:46 +00006585/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006586static int
paulfd79ac92004-10-13 05:06:08 +00006587bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006588 afi_t afi, safi_t safi, struct prefix_rd *prd,
6589 int prefix_check)
6590{
6591 struct bgp *bgp;
6592
6593 /* BGP structure lookup. */
6594 if (view_name)
6595 {
6596 bgp = bgp_lookup_by_name (view_name);
6597 if (bgp == NULL)
6598 {
6599 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6600 return CMD_WARNING;
6601 }
6602 }
6603 else
6604 {
6605 bgp = bgp_get_default ();
6606 if (bgp == NULL)
6607 {
6608 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6609 return CMD_WARNING;
6610 }
6611 }
6612
6613 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6614 afi, safi, prd, prefix_check);
6615}
6616
paul718e3742002-12-13 20:15:29 +00006617/* BGP route print out function. */
6618DEFUN (show_ip_bgp,
6619 show_ip_bgp_cmd,
6620 "show ip bgp",
6621 SHOW_STR
6622 IP_STR
6623 BGP_STR)
6624{
ajs5a646652004-11-05 01:25:55 +00006625 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006626}
6627
6628DEFUN (show_ip_bgp_ipv4,
6629 show_ip_bgp_ipv4_cmd,
6630 "show ip bgp ipv4 (unicast|multicast)",
6631 SHOW_STR
6632 IP_STR
6633 BGP_STR
6634 "Address family\n"
6635 "Address Family modifier\n"
6636 "Address Family modifier\n")
6637{
6638 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006639 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6640 NULL);
paul718e3742002-12-13 20:15:29 +00006641
ajs5a646652004-11-05 01:25:55 +00006642 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006643}
6644
Michael Lambert95cbbd22010-07-23 14:43:04 -04006645ALIAS (show_ip_bgp_ipv4,
6646 show_bgp_ipv4_safi_cmd,
6647 "show bgp ipv4 (unicast|multicast)",
6648 SHOW_STR
6649 BGP_STR
6650 "Address family\n"
6651 "Address Family modifier\n"
6652 "Address Family modifier\n")
6653
paul718e3742002-12-13 20:15:29 +00006654DEFUN (show_ip_bgp_route,
6655 show_ip_bgp_route_cmd,
6656 "show ip bgp A.B.C.D",
6657 SHOW_STR
6658 IP_STR
6659 BGP_STR
6660 "Network in the BGP routing table to display\n")
6661{
6662 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6663}
6664
6665DEFUN (show_ip_bgp_ipv4_route,
6666 show_ip_bgp_ipv4_route_cmd,
6667 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6668 SHOW_STR
6669 IP_STR
6670 BGP_STR
6671 "Address family\n"
6672 "Address Family modifier\n"
6673 "Address Family modifier\n"
6674 "Network in the BGP routing table to display\n")
6675{
6676 if (strncmp (argv[0], "m", 1) == 0)
6677 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6678
6679 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6680}
6681
Michael Lambert95cbbd22010-07-23 14:43:04 -04006682ALIAS (show_ip_bgp_ipv4_route,
6683 show_bgp_ipv4_safi_route_cmd,
6684 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6685 SHOW_STR
6686 BGP_STR
6687 "Address family\n"
6688 "Address Family modifier\n"
6689 "Address Family modifier\n"
6690 "Network in the BGP routing table to display\n")
6691
paul718e3742002-12-13 20:15:29 +00006692DEFUN (show_ip_bgp_vpnv4_all_route,
6693 show_ip_bgp_vpnv4_all_route_cmd,
6694 "show ip bgp vpnv4 all A.B.C.D",
6695 SHOW_STR
6696 IP_STR
6697 BGP_STR
6698 "Display VPNv4 NLRI specific information\n"
6699 "Display information about all VPNv4 NLRIs\n"
6700 "Network in the BGP routing table to display\n")
6701{
6702 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6703}
6704
6705DEFUN (show_ip_bgp_vpnv4_rd_route,
6706 show_ip_bgp_vpnv4_rd_route_cmd,
6707 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6708 SHOW_STR
6709 IP_STR
6710 BGP_STR
6711 "Display VPNv4 NLRI specific information\n"
6712 "Display information for a route distinguisher\n"
6713 "VPN Route Distinguisher\n"
6714 "Network in the BGP routing table to display\n")
6715{
6716 int ret;
6717 struct prefix_rd prd;
6718
6719 ret = str2prefix_rd (argv[0], &prd);
6720 if (! ret)
6721 {
6722 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6723 return CMD_WARNING;
6724 }
6725 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6726}
6727
6728DEFUN (show_ip_bgp_prefix,
6729 show_ip_bgp_prefix_cmd,
6730 "show ip bgp A.B.C.D/M",
6731 SHOW_STR
6732 IP_STR
6733 BGP_STR
6734 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6735{
6736 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6737}
6738
6739DEFUN (show_ip_bgp_ipv4_prefix,
6740 show_ip_bgp_ipv4_prefix_cmd,
6741 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6742 SHOW_STR
6743 IP_STR
6744 BGP_STR
6745 "Address family\n"
6746 "Address Family modifier\n"
6747 "Address Family modifier\n"
6748 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6749{
6750 if (strncmp (argv[0], "m", 1) == 0)
6751 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6752
6753 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6754}
6755
Michael Lambert95cbbd22010-07-23 14:43:04 -04006756ALIAS (show_ip_bgp_ipv4_prefix,
6757 show_bgp_ipv4_safi_prefix_cmd,
6758 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6759 SHOW_STR
6760 BGP_STR
6761 "Address family\n"
6762 "Address Family modifier\n"
6763 "Address Family modifier\n"
6764 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6765
paul718e3742002-12-13 20:15:29 +00006766DEFUN (show_ip_bgp_vpnv4_all_prefix,
6767 show_ip_bgp_vpnv4_all_prefix_cmd,
6768 "show ip bgp vpnv4 all A.B.C.D/M",
6769 SHOW_STR
6770 IP_STR
6771 BGP_STR
6772 "Display VPNv4 NLRI specific information\n"
6773 "Display information about all VPNv4 NLRIs\n"
6774 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6775{
6776 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6777}
6778
6779DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6780 show_ip_bgp_vpnv4_rd_prefix_cmd,
6781 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6782 SHOW_STR
6783 IP_STR
6784 BGP_STR
6785 "Display VPNv4 NLRI specific information\n"
6786 "Display information for a route distinguisher\n"
6787 "VPN Route Distinguisher\n"
6788 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6789{
6790 int ret;
6791 struct prefix_rd prd;
6792
6793 ret = str2prefix_rd (argv[0], &prd);
6794 if (! ret)
6795 {
6796 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6797 return CMD_WARNING;
6798 }
6799 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6800}
6801
6802DEFUN (show_ip_bgp_view,
6803 show_ip_bgp_view_cmd,
6804 "show ip bgp view WORD",
6805 SHOW_STR
6806 IP_STR
6807 BGP_STR
6808 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006809 "View name\n")
paul718e3742002-12-13 20:15:29 +00006810{
paulbb46e942003-10-24 19:02:03 +00006811 struct bgp *bgp;
6812
6813 /* BGP structure lookup. */
6814 bgp = bgp_lookup_by_name (argv[0]);
6815 if (bgp == NULL)
6816 {
6817 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6818 return CMD_WARNING;
6819 }
6820
ajs5a646652004-11-05 01:25:55 +00006821 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006822}
6823
6824DEFUN (show_ip_bgp_view_route,
6825 show_ip_bgp_view_route_cmd,
6826 "show ip bgp view WORD A.B.C.D",
6827 SHOW_STR
6828 IP_STR
6829 BGP_STR
6830 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006831 "View name\n"
paul718e3742002-12-13 20:15:29 +00006832 "Network in the BGP routing table to display\n")
6833{
6834 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6835}
6836
6837DEFUN (show_ip_bgp_view_prefix,
6838 show_ip_bgp_view_prefix_cmd,
6839 "show ip bgp view WORD A.B.C.D/M",
6840 SHOW_STR
6841 IP_STR
6842 BGP_STR
6843 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006844 "View name\n"
paul718e3742002-12-13 20:15:29 +00006845 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6846{
6847 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6848}
6849
6850#ifdef HAVE_IPV6
6851DEFUN (show_bgp,
6852 show_bgp_cmd,
6853 "show bgp",
6854 SHOW_STR
6855 BGP_STR)
6856{
ajs5a646652004-11-05 01:25:55 +00006857 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6858 NULL);
paul718e3742002-12-13 20:15:29 +00006859}
6860
6861ALIAS (show_bgp,
6862 show_bgp_ipv6_cmd,
6863 "show bgp ipv6",
6864 SHOW_STR
6865 BGP_STR
6866 "Address family\n")
6867
Michael Lambert95cbbd22010-07-23 14:43:04 -04006868DEFUN (show_bgp_ipv6_safi,
6869 show_bgp_ipv6_safi_cmd,
6870 "show bgp ipv6 (unicast|multicast)",
6871 SHOW_STR
6872 BGP_STR
6873 "Address family\n"
6874 "Address Family modifier\n"
6875 "Address Family modifier\n")
6876{
6877 if (strncmp (argv[0], "m", 1) == 0)
6878 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6879 NULL);
6880
6881 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6882}
6883
paul718e3742002-12-13 20:15:29 +00006884/* old command */
6885DEFUN (show_ipv6_bgp,
6886 show_ipv6_bgp_cmd,
6887 "show ipv6 bgp",
6888 SHOW_STR
6889 IP_STR
6890 BGP_STR)
6891{
ajs5a646652004-11-05 01:25:55 +00006892 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6893 NULL);
paul718e3742002-12-13 20:15:29 +00006894}
6895
6896DEFUN (show_bgp_route,
6897 show_bgp_route_cmd,
6898 "show bgp X:X::X:X",
6899 SHOW_STR
6900 BGP_STR
6901 "Network in the BGP routing table to display\n")
6902{
6903 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6904}
6905
6906ALIAS (show_bgp_route,
6907 show_bgp_ipv6_route_cmd,
6908 "show bgp ipv6 X:X::X:X",
6909 SHOW_STR
6910 BGP_STR
6911 "Address family\n"
6912 "Network in the BGP routing table to display\n")
6913
Michael Lambert95cbbd22010-07-23 14:43:04 -04006914DEFUN (show_bgp_ipv6_safi_route,
6915 show_bgp_ipv6_safi_route_cmd,
6916 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6917 SHOW_STR
6918 BGP_STR
6919 "Address family\n"
6920 "Address Family modifier\n"
6921 "Address Family modifier\n"
6922 "Network in the BGP routing table to display\n")
6923{
6924 if (strncmp (argv[0], "m", 1) == 0)
6925 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6926
6927 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6928}
6929
paul718e3742002-12-13 20:15:29 +00006930/* old command */
6931DEFUN (show_ipv6_bgp_route,
6932 show_ipv6_bgp_route_cmd,
6933 "show ipv6 bgp X:X::X:X",
6934 SHOW_STR
6935 IP_STR
6936 BGP_STR
6937 "Network in the BGP routing table to display\n")
6938{
6939 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6940}
6941
6942DEFUN (show_bgp_prefix,
6943 show_bgp_prefix_cmd,
6944 "show bgp X:X::X:X/M",
6945 SHOW_STR
6946 BGP_STR
6947 "IPv6 prefix <network>/<length>\n")
6948{
6949 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6950}
6951
6952ALIAS (show_bgp_prefix,
6953 show_bgp_ipv6_prefix_cmd,
6954 "show bgp ipv6 X:X::X:X/M",
6955 SHOW_STR
6956 BGP_STR
6957 "Address family\n"
6958 "IPv6 prefix <network>/<length>\n")
6959
Michael Lambert95cbbd22010-07-23 14:43:04 -04006960DEFUN (show_bgp_ipv6_safi_prefix,
6961 show_bgp_ipv6_safi_prefix_cmd,
6962 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6963 SHOW_STR
6964 BGP_STR
6965 "Address family\n"
6966 "Address Family modifier\n"
6967 "Address Family modifier\n"
6968 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6969{
6970 if (strncmp (argv[0], "m", 1) == 0)
6971 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6972
6973 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6974}
6975
paul718e3742002-12-13 20:15:29 +00006976/* old command */
6977DEFUN (show_ipv6_bgp_prefix,
6978 show_ipv6_bgp_prefix_cmd,
6979 "show ipv6 bgp X:X::X:X/M",
6980 SHOW_STR
6981 IP_STR
6982 BGP_STR
6983 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6984{
6985 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6986}
6987
paulbb46e942003-10-24 19:02:03 +00006988DEFUN (show_bgp_view,
6989 show_bgp_view_cmd,
6990 "show bgp view WORD",
6991 SHOW_STR
6992 BGP_STR
6993 "BGP view\n"
6994 "View name\n")
6995{
6996 struct bgp *bgp;
6997
6998 /* BGP structure lookup. */
6999 bgp = bgp_lookup_by_name (argv[0]);
7000 if (bgp == NULL)
7001 {
7002 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7003 return CMD_WARNING;
7004 }
7005
ajs5a646652004-11-05 01:25:55 +00007006 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007007}
7008
7009ALIAS (show_bgp_view,
7010 show_bgp_view_ipv6_cmd,
7011 "show bgp view WORD ipv6",
7012 SHOW_STR
7013 BGP_STR
7014 "BGP view\n"
7015 "View name\n"
7016 "Address family\n")
7017
7018DEFUN (show_bgp_view_route,
7019 show_bgp_view_route_cmd,
7020 "show bgp view WORD X:X::X:X",
7021 SHOW_STR
7022 BGP_STR
7023 "BGP view\n"
7024 "View name\n"
7025 "Network in the BGP routing table to display\n")
7026{
7027 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7028}
7029
7030ALIAS (show_bgp_view_route,
7031 show_bgp_view_ipv6_route_cmd,
7032 "show bgp view WORD ipv6 X:X::X:X",
7033 SHOW_STR
7034 BGP_STR
7035 "BGP view\n"
7036 "View name\n"
7037 "Address family\n"
7038 "Network in the BGP routing table to display\n")
7039
7040DEFUN (show_bgp_view_prefix,
7041 show_bgp_view_prefix_cmd,
7042 "show bgp view WORD X:X::X:X/M",
7043 SHOW_STR
7044 BGP_STR
7045 "BGP view\n"
7046 "View name\n"
7047 "IPv6 prefix <network>/<length>\n")
7048{
7049 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7050}
7051
7052ALIAS (show_bgp_view_prefix,
7053 show_bgp_view_ipv6_prefix_cmd,
7054 "show bgp view WORD ipv6 X:X::X:X/M",
7055 SHOW_STR
7056 BGP_STR
7057 "BGP view\n"
7058 "View name\n"
7059 "Address family\n"
7060 "IPv6 prefix <network>/<length>\n")
7061
paul718e3742002-12-13 20:15:29 +00007062/* old command */
7063DEFUN (show_ipv6_mbgp,
7064 show_ipv6_mbgp_cmd,
7065 "show ipv6 mbgp",
7066 SHOW_STR
7067 IP_STR
7068 MBGP_STR)
7069{
ajs5a646652004-11-05 01:25:55 +00007070 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7071 NULL);
paul718e3742002-12-13 20:15:29 +00007072}
7073
7074/* old command */
7075DEFUN (show_ipv6_mbgp_route,
7076 show_ipv6_mbgp_route_cmd,
7077 "show ipv6 mbgp X:X::X:X",
7078 SHOW_STR
7079 IP_STR
7080 MBGP_STR
7081 "Network in the MBGP routing table to display\n")
7082{
7083 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7084}
7085
7086/* old command */
7087DEFUN (show_ipv6_mbgp_prefix,
7088 show_ipv6_mbgp_prefix_cmd,
7089 "show ipv6 mbgp X:X::X:X/M",
7090 SHOW_STR
7091 IP_STR
7092 MBGP_STR
7093 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7094{
7095 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7096}
7097#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02007098
paul718e3742002-12-13 20:15:29 +00007099
paul94f2b392005-06-28 12:44:16 +00007100static int
paulfd79ac92004-10-13 05:06:08 +00007101bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007102 safi_t safi, enum bgp_show_type type)
7103{
7104 int i;
7105 struct buffer *b;
7106 char *regstr;
7107 int first;
7108 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007109 int rc;
paul718e3742002-12-13 20:15:29 +00007110
7111 first = 0;
7112 b = buffer_new (1024);
7113 for (i = 0; i < argc; i++)
7114 {
7115 if (first)
7116 buffer_putc (b, ' ');
7117 else
7118 {
7119 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7120 continue;
7121 first = 1;
7122 }
7123
7124 buffer_putstr (b, argv[i]);
7125 }
7126 buffer_putc (b, '\0');
7127
7128 regstr = buffer_getstr (b);
7129 buffer_free (b);
7130
7131 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007132 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007133 if (! regex)
7134 {
7135 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7136 VTY_NEWLINE);
7137 return CMD_WARNING;
7138 }
7139
ajs5a646652004-11-05 01:25:55 +00007140 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7141 bgp_regex_free (regex);
7142 return rc;
paul718e3742002-12-13 20:15:29 +00007143}
7144
7145DEFUN (show_ip_bgp_regexp,
7146 show_ip_bgp_regexp_cmd,
7147 "show ip bgp regexp .LINE",
7148 SHOW_STR
7149 IP_STR
7150 BGP_STR
7151 "Display routes matching the AS path regular expression\n"
7152 "A regular-expression to match the BGP AS paths\n")
7153{
7154 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7155 bgp_show_type_regexp);
7156}
7157
7158DEFUN (show_ip_bgp_flap_regexp,
7159 show_ip_bgp_flap_regexp_cmd,
7160 "show ip bgp flap-statistics regexp .LINE",
7161 SHOW_STR
7162 IP_STR
7163 BGP_STR
7164 "Display flap statistics of routes\n"
7165 "Display routes matching the AS path regular expression\n"
7166 "A regular-expression to match the BGP AS paths\n")
7167{
7168 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7169 bgp_show_type_flap_regexp);
7170}
7171
7172DEFUN (show_ip_bgp_ipv4_regexp,
7173 show_ip_bgp_ipv4_regexp_cmd,
7174 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7175 SHOW_STR
7176 IP_STR
7177 BGP_STR
7178 "Address family\n"
7179 "Address Family modifier\n"
7180 "Address Family modifier\n"
7181 "Display routes matching the AS path regular expression\n"
7182 "A regular-expression to match the BGP AS paths\n")
7183{
7184 if (strncmp (argv[0], "m", 1) == 0)
7185 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7186 bgp_show_type_regexp);
7187
7188 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7189 bgp_show_type_regexp);
7190}
7191
7192#ifdef HAVE_IPV6
7193DEFUN (show_bgp_regexp,
7194 show_bgp_regexp_cmd,
7195 "show bgp regexp .LINE",
7196 SHOW_STR
7197 BGP_STR
7198 "Display routes matching the AS path regular expression\n"
7199 "A regular-expression to match the BGP AS paths\n")
7200{
7201 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7202 bgp_show_type_regexp);
7203}
7204
7205ALIAS (show_bgp_regexp,
7206 show_bgp_ipv6_regexp_cmd,
7207 "show bgp ipv6 regexp .LINE",
7208 SHOW_STR
7209 BGP_STR
7210 "Address family\n"
7211 "Display routes matching the AS path regular expression\n"
7212 "A regular-expression to match the BGP AS paths\n")
7213
7214/* old command */
7215DEFUN (show_ipv6_bgp_regexp,
7216 show_ipv6_bgp_regexp_cmd,
7217 "show ipv6 bgp regexp .LINE",
7218 SHOW_STR
7219 IP_STR
7220 BGP_STR
7221 "Display routes matching the AS path regular expression\n"
7222 "A regular-expression to match the BGP AS paths\n")
7223{
7224 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7225 bgp_show_type_regexp);
7226}
7227
7228/* old command */
7229DEFUN (show_ipv6_mbgp_regexp,
7230 show_ipv6_mbgp_regexp_cmd,
7231 "show ipv6 mbgp regexp .LINE",
7232 SHOW_STR
7233 IP_STR
7234 BGP_STR
7235 "Display routes matching the AS path regular expression\n"
7236 "A regular-expression to match the MBGP AS paths\n")
7237{
7238 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7239 bgp_show_type_regexp);
7240}
7241#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007242
paul94f2b392005-06-28 12:44:16 +00007243static int
paulfd79ac92004-10-13 05:06:08 +00007244bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007245 safi_t safi, enum bgp_show_type type)
7246{
7247 struct prefix_list *plist;
7248
7249 plist = prefix_list_lookup (afi, prefix_list_str);
7250 if (plist == NULL)
7251 {
7252 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7253 prefix_list_str, VTY_NEWLINE);
7254 return CMD_WARNING;
7255 }
7256
ajs5a646652004-11-05 01:25:55 +00007257 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007258}
7259
7260DEFUN (show_ip_bgp_prefix_list,
7261 show_ip_bgp_prefix_list_cmd,
7262 "show ip bgp prefix-list WORD",
7263 SHOW_STR
7264 IP_STR
7265 BGP_STR
7266 "Display routes conforming to the prefix-list\n"
7267 "IP prefix-list name\n")
7268{
7269 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7270 bgp_show_type_prefix_list);
7271}
7272
7273DEFUN (show_ip_bgp_flap_prefix_list,
7274 show_ip_bgp_flap_prefix_list_cmd,
7275 "show ip bgp flap-statistics prefix-list WORD",
7276 SHOW_STR
7277 IP_STR
7278 BGP_STR
7279 "Display flap statistics of routes\n"
7280 "Display routes conforming to the prefix-list\n"
7281 "IP prefix-list name\n")
7282{
7283 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7284 bgp_show_type_flap_prefix_list);
7285}
7286
7287DEFUN (show_ip_bgp_ipv4_prefix_list,
7288 show_ip_bgp_ipv4_prefix_list_cmd,
7289 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7290 SHOW_STR
7291 IP_STR
7292 BGP_STR
7293 "Address family\n"
7294 "Address Family modifier\n"
7295 "Address Family modifier\n"
7296 "Display routes conforming to the prefix-list\n"
7297 "IP prefix-list name\n")
7298{
7299 if (strncmp (argv[0], "m", 1) == 0)
7300 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7301 bgp_show_type_prefix_list);
7302
7303 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7304 bgp_show_type_prefix_list);
7305}
7306
7307#ifdef HAVE_IPV6
7308DEFUN (show_bgp_prefix_list,
7309 show_bgp_prefix_list_cmd,
7310 "show bgp prefix-list WORD",
7311 SHOW_STR
7312 BGP_STR
7313 "Display routes conforming to the prefix-list\n"
7314 "IPv6 prefix-list name\n")
7315{
7316 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7317 bgp_show_type_prefix_list);
7318}
7319
7320ALIAS (show_bgp_prefix_list,
7321 show_bgp_ipv6_prefix_list_cmd,
7322 "show bgp ipv6 prefix-list WORD",
7323 SHOW_STR
7324 BGP_STR
7325 "Address family\n"
7326 "Display routes conforming to the prefix-list\n"
7327 "IPv6 prefix-list name\n")
7328
7329/* old command */
7330DEFUN (show_ipv6_bgp_prefix_list,
7331 show_ipv6_bgp_prefix_list_cmd,
7332 "show ipv6 bgp prefix-list WORD",
7333 SHOW_STR
7334 IPV6_STR
7335 BGP_STR
7336 "Display routes matching the prefix-list\n"
7337 "IPv6 prefix-list name\n")
7338{
7339 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7340 bgp_show_type_prefix_list);
7341}
7342
7343/* old command */
7344DEFUN (show_ipv6_mbgp_prefix_list,
7345 show_ipv6_mbgp_prefix_list_cmd,
7346 "show ipv6 mbgp prefix-list WORD",
7347 SHOW_STR
7348 IPV6_STR
7349 MBGP_STR
7350 "Display routes matching the prefix-list\n"
7351 "IPv6 prefix-list name\n")
7352{
7353 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7354 bgp_show_type_prefix_list);
7355}
7356#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007357
paul94f2b392005-06-28 12:44:16 +00007358static int
paulfd79ac92004-10-13 05:06:08 +00007359bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007360 safi_t safi, enum bgp_show_type type)
7361{
7362 struct as_list *as_list;
7363
7364 as_list = as_list_lookup (filter);
7365 if (as_list == NULL)
7366 {
7367 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7368 return CMD_WARNING;
7369 }
7370
ajs5a646652004-11-05 01:25:55 +00007371 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007372}
7373
7374DEFUN (show_ip_bgp_filter_list,
7375 show_ip_bgp_filter_list_cmd,
7376 "show ip bgp filter-list WORD",
7377 SHOW_STR
7378 IP_STR
7379 BGP_STR
7380 "Display routes conforming to the filter-list\n"
7381 "Regular expression access list name\n")
7382{
7383 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7384 bgp_show_type_filter_list);
7385}
7386
7387DEFUN (show_ip_bgp_flap_filter_list,
7388 show_ip_bgp_flap_filter_list_cmd,
7389 "show ip bgp flap-statistics filter-list WORD",
7390 SHOW_STR
7391 IP_STR
7392 BGP_STR
7393 "Display flap statistics of routes\n"
7394 "Display routes conforming to the filter-list\n"
7395 "Regular expression access list name\n")
7396{
7397 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7398 bgp_show_type_flap_filter_list);
7399}
7400
7401DEFUN (show_ip_bgp_ipv4_filter_list,
7402 show_ip_bgp_ipv4_filter_list_cmd,
7403 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7404 SHOW_STR
7405 IP_STR
7406 BGP_STR
7407 "Address family\n"
7408 "Address Family modifier\n"
7409 "Address Family modifier\n"
7410 "Display routes conforming to the filter-list\n"
7411 "Regular expression access list name\n")
7412{
7413 if (strncmp (argv[0], "m", 1) == 0)
7414 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7415 bgp_show_type_filter_list);
7416
7417 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7418 bgp_show_type_filter_list);
7419}
7420
7421#ifdef HAVE_IPV6
7422DEFUN (show_bgp_filter_list,
7423 show_bgp_filter_list_cmd,
7424 "show bgp filter-list WORD",
7425 SHOW_STR
7426 BGP_STR
7427 "Display routes conforming to the filter-list\n"
7428 "Regular expression access list name\n")
7429{
7430 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7431 bgp_show_type_filter_list);
7432}
7433
7434ALIAS (show_bgp_filter_list,
7435 show_bgp_ipv6_filter_list_cmd,
7436 "show bgp ipv6 filter-list WORD",
7437 SHOW_STR
7438 BGP_STR
7439 "Address family\n"
7440 "Display routes conforming to the filter-list\n"
7441 "Regular expression access list name\n")
7442
7443/* old command */
7444DEFUN (show_ipv6_bgp_filter_list,
7445 show_ipv6_bgp_filter_list_cmd,
7446 "show ipv6 bgp filter-list WORD",
7447 SHOW_STR
7448 IPV6_STR
7449 BGP_STR
7450 "Display routes conforming to the filter-list\n"
7451 "Regular expression access list name\n")
7452{
7453 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7454 bgp_show_type_filter_list);
7455}
7456
7457/* old command */
7458DEFUN (show_ipv6_mbgp_filter_list,
7459 show_ipv6_mbgp_filter_list_cmd,
7460 "show ipv6 mbgp filter-list WORD",
7461 SHOW_STR
7462 IPV6_STR
7463 MBGP_STR
7464 "Display routes conforming to the filter-list\n"
7465 "Regular expression access list name\n")
7466{
7467 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7468 bgp_show_type_filter_list);
7469}
7470#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007471
paul94f2b392005-06-28 12:44:16 +00007472static int
paulfd79ac92004-10-13 05:06:08 +00007473bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007474 safi_t safi, enum bgp_show_type type)
7475{
7476 struct route_map *rmap;
7477
7478 rmap = route_map_lookup_by_name (rmap_str);
7479 if (! rmap)
7480 {
7481 vty_out (vty, "%% %s is not a valid route-map name%s",
7482 rmap_str, VTY_NEWLINE);
7483 return CMD_WARNING;
7484 }
7485
ajs5a646652004-11-05 01:25:55 +00007486 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007487}
7488
7489DEFUN (show_ip_bgp_route_map,
7490 show_ip_bgp_route_map_cmd,
7491 "show ip bgp route-map WORD",
7492 SHOW_STR
7493 IP_STR
7494 BGP_STR
7495 "Display routes matching the route-map\n"
7496 "A route-map to match on\n")
7497{
7498 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7499 bgp_show_type_route_map);
7500}
7501
7502DEFUN (show_ip_bgp_flap_route_map,
7503 show_ip_bgp_flap_route_map_cmd,
7504 "show ip bgp flap-statistics route-map WORD",
7505 SHOW_STR
7506 IP_STR
7507 BGP_STR
7508 "Display flap statistics of routes\n"
7509 "Display routes matching the route-map\n"
7510 "A route-map to match on\n")
7511{
7512 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7513 bgp_show_type_flap_route_map);
7514}
7515
7516DEFUN (show_ip_bgp_ipv4_route_map,
7517 show_ip_bgp_ipv4_route_map_cmd,
7518 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7519 SHOW_STR
7520 IP_STR
7521 BGP_STR
7522 "Address family\n"
7523 "Address Family modifier\n"
7524 "Address Family modifier\n"
7525 "Display routes matching the route-map\n"
7526 "A route-map to match on\n")
7527{
7528 if (strncmp (argv[0], "m", 1) == 0)
7529 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7530 bgp_show_type_route_map);
7531
7532 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7533 bgp_show_type_route_map);
7534}
7535
7536DEFUN (show_bgp_route_map,
7537 show_bgp_route_map_cmd,
7538 "show bgp route-map WORD",
7539 SHOW_STR
7540 BGP_STR
7541 "Display routes matching the route-map\n"
7542 "A route-map to match on\n")
7543{
7544 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7545 bgp_show_type_route_map);
7546}
7547
7548ALIAS (show_bgp_route_map,
7549 show_bgp_ipv6_route_map_cmd,
7550 "show bgp ipv6 route-map WORD",
7551 SHOW_STR
7552 BGP_STR
7553 "Address family\n"
7554 "Display routes matching the route-map\n"
7555 "A route-map to match on\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02007556
paul718e3742002-12-13 20:15:29 +00007557DEFUN (show_ip_bgp_cidr_only,
7558 show_ip_bgp_cidr_only_cmd,
7559 "show ip bgp cidr-only",
7560 SHOW_STR
7561 IP_STR
7562 BGP_STR
7563 "Display only routes with non-natural netmasks\n")
7564{
7565 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007566 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007567}
7568
7569DEFUN (show_ip_bgp_flap_cidr_only,
7570 show_ip_bgp_flap_cidr_only_cmd,
7571 "show ip bgp flap-statistics cidr-only",
7572 SHOW_STR
7573 IP_STR
7574 BGP_STR
7575 "Display flap statistics of routes\n"
7576 "Display only routes with non-natural netmasks\n")
7577{
7578 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007579 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007580}
7581
7582DEFUN (show_ip_bgp_ipv4_cidr_only,
7583 show_ip_bgp_ipv4_cidr_only_cmd,
7584 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7585 SHOW_STR
7586 IP_STR
7587 BGP_STR
7588 "Address family\n"
7589 "Address Family modifier\n"
7590 "Address Family modifier\n"
7591 "Display only routes with non-natural netmasks\n")
7592{
7593 if (strncmp (argv[0], "m", 1) == 0)
7594 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007595 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007596
7597 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007598 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007599}
David Lamparter6b0655a2014-06-04 06:53:35 +02007600
paul718e3742002-12-13 20:15:29 +00007601DEFUN (show_ip_bgp_community_all,
7602 show_ip_bgp_community_all_cmd,
7603 "show ip bgp community",
7604 SHOW_STR
7605 IP_STR
7606 BGP_STR
7607 "Display routes matching the communities\n")
7608{
7609 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007610 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007611}
7612
7613DEFUN (show_ip_bgp_ipv4_community_all,
7614 show_ip_bgp_ipv4_community_all_cmd,
7615 "show ip bgp ipv4 (unicast|multicast) community",
7616 SHOW_STR
7617 IP_STR
7618 BGP_STR
7619 "Address family\n"
7620 "Address Family modifier\n"
7621 "Address Family modifier\n"
7622 "Display routes matching the communities\n")
7623{
7624 if (strncmp (argv[0], "m", 1) == 0)
7625 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007626 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007627
7628 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007629 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007630}
7631
7632#ifdef HAVE_IPV6
7633DEFUN (show_bgp_community_all,
7634 show_bgp_community_all_cmd,
7635 "show bgp community",
7636 SHOW_STR
7637 BGP_STR
7638 "Display routes matching the communities\n")
7639{
7640 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007641 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007642}
7643
7644ALIAS (show_bgp_community_all,
7645 show_bgp_ipv6_community_all_cmd,
7646 "show bgp ipv6 community",
7647 SHOW_STR
7648 BGP_STR
7649 "Address family\n"
7650 "Display routes matching the communities\n")
7651
7652/* old command */
7653DEFUN (show_ipv6_bgp_community_all,
7654 show_ipv6_bgp_community_all_cmd,
7655 "show ipv6 bgp community",
7656 SHOW_STR
7657 IPV6_STR
7658 BGP_STR
7659 "Display routes matching the communities\n")
7660{
7661 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007662 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007663}
7664
7665/* old command */
7666DEFUN (show_ipv6_mbgp_community_all,
7667 show_ipv6_mbgp_community_all_cmd,
7668 "show ipv6 mbgp community",
7669 SHOW_STR
7670 IPV6_STR
7671 MBGP_STR
7672 "Display routes matching the communities\n")
7673{
7674 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007675 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007676}
7677#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007678
paul94f2b392005-06-28 12:44:16 +00007679static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007680bgp_show_community (struct vty *vty, const char *view_name, int argc,
7681 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007682{
7683 struct community *com;
7684 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007685 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007686 int i;
7687 char *str;
7688 int first = 0;
7689
Michael Lambert95cbbd22010-07-23 14:43:04 -04007690 /* BGP structure lookup */
7691 if (view_name)
7692 {
7693 bgp = bgp_lookup_by_name (view_name);
7694 if (bgp == NULL)
7695 {
7696 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7697 return CMD_WARNING;
7698 }
7699 }
7700 else
7701 {
7702 bgp = bgp_get_default ();
7703 if (bgp == NULL)
7704 {
7705 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7706 return CMD_WARNING;
7707 }
7708 }
7709
paul718e3742002-12-13 20:15:29 +00007710 b = buffer_new (1024);
7711 for (i = 0; i < argc; i++)
7712 {
7713 if (first)
7714 buffer_putc (b, ' ');
7715 else
7716 {
7717 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7718 continue;
7719 first = 1;
7720 }
7721
7722 buffer_putstr (b, argv[i]);
7723 }
7724 buffer_putc (b, '\0');
7725
7726 str = buffer_getstr (b);
7727 buffer_free (b);
7728
7729 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007730 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007731 if (! com)
7732 {
7733 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7734 return CMD_WARNING;
7735 }
7736
Michael Lambert95cbbd22010-07-23 14:43:04 -04007737 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007738 (exact ? bgp_show_type_community_exact :
7739 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007740}
7741
7742DEFUN (show_ip_bgp_community,
7743 show_ip_bgp_community_cmd,
7744 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7745 SHOW_STR
7746 IP_STR
7747 BGP_STR
7748 "Display routes matching the communities\n"
7749 "community number\n"
7750 "Do not send outside local AS (well-known community)\n"
7751 "Do not advertise to any peer (well-known community)\n"
7752 "Do not export to next AS (well-known community)\n")
7753{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007754 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007755}
7756
7757ALIAS (show_ip_bgp_community,
7758 show_ip_bgp_community2_cmd,
7759 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7760 SHOW_STR
7761 IP_STR
7762 BGP_STR
7763 "Display routes matching the communities\n"
7764 "community number\n"
7765 "Do not send outside local AS (well-known community)\n"
7766 "Do not advertise to any peer (well-known community)\n"
7767 "Do not export to next AS (well-known community)\n"
7768 "community number\n"
7769 "Do not send outside local AS (well-known community)\n"
7770 "Do not advertise to any peer (well-known community)\n"
7771 "Do not export to next AS (well-known community)\n")
7772
7773ALIAS (show_ip_bgp_community,
7774 show_ip_bgp_community3_cmd,
7775 "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)",
7776 SHOW_STR
7777 IP_STR
7778 BGP_STR
7779 "Display routes matching the communities\n"
7780 "community number\n"
7781 "Do not send outside local AS (well-known community)\n"
7782 "Do not advertise to any peer (well-known community)\n"
7783 "Do not export to next AS (well-known community)\n"
7784 "community number\n"
7785 "Do not send outside local AS (well-known community)\n"
7786 "Do not advertise to any peer (well-known community)\n"
7787 "Do not export to next AS (well-known community)\n"
7788 "community number\n"
7789 "Do not send outside local AS (well-known community)\n"
7790 "Do not advertise to any peer (well-known community)\n"
7791 "Do not export to next AS (well-known community)\n")
7792
7793ALIAS (show_ip_bgp_community,
7794 show_ip_bgp_community4_cmd,
7795 "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)",
7796 SHOW_STR
7797 IP_STR
7798 BGP_STR
7799 "Display routes matching the communities\n"
7800 "community number\n"
7801 "Do not send outside local AS (well-known community)\n"
7802 "Do not advertise to any peer (well-known community)\n"
7803 "Do not export to next AS (well-known community)\n"
7804 "community number\n"
7805 "Do not send outside local AS (well-known community)\n"
7806 "Do not advertise to any peer (well-known community)\n"
7807 "Do not export to next AS (well-known community)\n"
7808 "community number\n"
7809 "Do not send outside local AS (well-known community)\n"
7810 "Do not advertise to any peer (well-known community)\n"
7811 "Do not export to next AS (well-known community)\n"
7812 "community number\n"
7813 "Do not send outside local AS (well-known community)\n"
7814 "Do not advertise to any peer (well-known community)\n"
7815 "Do not export to next AS (well-known community)\n")
7816
7817DEFUN (show_ip_bgp_ipv4_community,
7818 show_ip_bgp_ipv4_community_cmd,
7819 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7820 SHOW_STR
7821 IP_STR
7822 BGP_STR
7823 "Address family\n"
7824 "Address Family modifier\n"
7825 "Address Family modifier\n"
7826 "Display routes matching the communities\n"
7827 "community number\n"
7828 "Do not send outside local AS (well-known community)\n"
7829 "Do not advertise to any peer (well-known community)\n"
7830 "Do not export to next AS (well-known community)\n")
7831{
7832 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007833 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007834
Michael Lambert95cbbd22010-07-23 14:43:04 -04007835 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007836}
7837
7838ALIAS (show_ip_bgp_ipv4_community,
7839 show_ip_bgp_ipv4_community2_cmd,
7840 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7841 SHOW_STR
7842 IP_STR
7843 BGP_STR
7844 "Address family\n"
7845 "Address Family modifier\n"
7846 "Address Family modifier\n"
7847 "Display routes matching the communities\n"
7848 "community number\n"
7849 "Do not send outside local AS (well-known community)\n"
7850 "Do not advertise to any peer (well-known community)\n"
7851 "Do not export to next AS (well-known community)\n"
7852 "community number\n"
7853 "Do not send outside local AS (well-known community)\n"
7854 "Do not advertise to any peer (well-known community)\n"
7855 "Do not export to next AS (well-known community)\n")
7856
7857ALIAS (show_ip_bgp_ipv4_community,
7858 show_ip_bgp_ipv4_community3_cmd,
7859 "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)",
7860 SHOW_STR
7861 IP_STR
7862 BGP_STR
7863 "Address family\n"
7864 "Address Family modifier\n"
7865 "Address Family modifier\n"
7866 "Display routes matching the communities\n"
7867 "community number\n"
7868 "Do not send outside local AS (well-known community)\n"
7869 "Do not advertise to any peer (well-known community)\n"
7870 "Do not export to next AS (well-known community)\n"
7871 "community number\n"
7872 "Do not send outside local AS (well-known community)\n"
7873 "Do not advertise to any peer (well-known community)\n"
7874 "Do not export to next AS (well-known community)\n"
7875 "community number\n"
7876 "Do not send outside local AS (well-known community)\n"
7877 "Do not advertise to any peer (well-known community)\n"
7878 "Do not export to next AS (well-known community)\n")
7879
7880ALIAS (show_ip_bgp_ipv4_community,
7881 show_ip_bgp_ipv4_community4_cmd,
7882 "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)",
7883 SHOW_STR
7884 IP_STR
7885 BGP_STR
7886 "Address family\n"
7887 "Address Family modifier\n"
7888 "Address Family modifier\n"
7889 "Display routes matching the communities\n"
7890 "community number\n"
7891 "Do not send outside local AS (well-known community)\n"
7892 "Do not advertise to any peer (well-known community)\n"
7893 "Do not export to next AS (well-known community)\n"
7894 "community number\n"
7895 "Do not send outside local AS (well-known community)\n"
7896 "Do not advertise to any peer (well-known community)\n"
7897 "Do not export to next AS (well-known community)\n"
7898 "community number\n"
7899 "Do not send outside local AS (well-known community)\n"
7900 "Do not advertise to any peer (well-known community)\n"
7901 "Do not export to next AS (well-known community)\n"
7902 "community number\n"
7903 "Do not send outside local AS (well-known community)\n"
7904 "Do not advertise to any peer (well-known community)\n"
7905 "Do not export to next AS (well-known community)\n")
7906
Michael Lambert95cbbd22010-07-23 14:43:04 -04007907DEFUN (show_bgp_view_afi_safi_community_all,
7908 show_bgp_view_afi_safi_community_all_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04007909 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007910 SHOW_STR
7911 BGP_STR
7912 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007913 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007914 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007915 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007916 "Address Family modifier\n"
7917 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00007918 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007919{
7920 int afi;
7921 int safi;
7922 struct bgp *bgp;
7923
7924 /* BGP structure lookup. */
7925 bgp = bgp_lookup_by_name (argv[0]);
7926 if (bgp == NULL)
7927 {
7928 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7929 return CMD_WARNING;
7930 }
7931
Michael Lambert95cbbd22010-07-23 14:43:04 -04007932 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7933 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007934 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7935}
7936
7937DEFUN (show_bgp_view_afi_safi_community,
7938 show_bgp_view_afi_safi_community_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04007939 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007940 SHOW_STR
7941 BGP_STR
7942 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007943 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007944 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007945 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007946 "Address family modifier\n"
7947 "Address family modifier\n"
7948 "Display routes matching the communities\n"
7949 "community number\n"
7950 "Do not send outside local AS (well-known community)\n"
7951 "Do not advertise to any peer (well-known community)\n"
7952 "Do not export to next AS (well-known community)\n")
7953{
7954 int afi;
7955 int safi;
7956
Michael Lambert95cbbd22010-07-23 14:43:04 -04007957 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7958 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7959 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007960}
7961
7962ALIAS (show_bgp_view_afi_safi_community,
7963 show_bgp_view_afi_safi_community2_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04007964 "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 -04007965 SHOW_STR
7966 BGP_STR
7967 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007968 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007969 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007970 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007971 "Address family modifier\n"
7972 "Address family modifier\n"
7973 "Display routes matching the communities\n"
7974 "community number\n"
7975 "Do not send outside local AS (well-known community)\n"
7976 "Do not advertise to any peer (well-known community)\n"
7977 "Do not export to next AS (well-known community)\n"
7978 "community number\n"
7979 "Do not send outside local AS (well-known community)\n"
7980 "Do not advertise to any peer (well-known community)\n"
7981 "Do not export to next AS (well-known community)\n")
7982
7983ALIAS (show_bgp_view_afi_safi_community,
7984 show_bgp_view_afi_safi_community3_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04007985 "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 -04007986 SHOW_STR
7987 BGP_STR
7988 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007989 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007990 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007991 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007992 "Address family modifier\n"
7993 "Address family modifier\n"
7994 "Display routes matching the communities\n"
7995 "community number\n"
7996 "Do not send outside local AS (well-known community)\n"
7997 "Do not advertise to any peer (well-known community)\n"
7998 "Do not export to next AS (well-known community)\n"
7999 "community number\n"
8000 "Do not send outside local AS (well-known community)\n"
8001 "Do not advertise to any peer (well-known community)\n"
8002 "Do not export to next AS (well-known community)\n"
8003 "community number\n"
8004 "Do not send outside local AS (well-known community)\n"
8005 "Do not advertise to any peer (well-known community)\n"
8006 "Do not export to next AS (well-known community)\n")
8007
8008ALIAS (show_bgp_view_afi_safi_community,
8009 show_bgp_view_afi_safi_community4_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008010 "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 -04008011 SHOW_STR
8012 BGP_STR
8013 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008014 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008015 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008016 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008017 "Address family modifier\n"
8018 "Address family modifier\n"
8019 "Display routes matching the communities\n"
8020 "community number\n"
8021 "Do not send outside local AS (well-known community)\n"
8022 "Do not advertise to any peer (well-known community)\n"
8023 "Do not export to next AS (well-known community)\n"
8024 "community number\n"
8025 "Do not send outside local AS (well-known community)\n"
8026 "Do not advertise to any peer (well-known community)\n"
8027 "Do not export to next AS (well-known community)\n"
8028 "community number\n"
8029 "Do not send outside local AS (well-known community)\n"
8030 "Do not advertise to any peer (well-known community)\n"
8031 "Do not export to next AS (well-known community)\n"
8032 "community number\n"
8033 "Do not send outside local AS (well-known community)\n"
8034 "Do not advertise to any peer (well-known community)\n"
8035 "Do not export to next AS (well-known community)\n")
8036
paul718e3742002-12-13 20:15:29 +00008037DEFUN (show_ip_bgp_community_exact,
8038 show_ip_bgp_community_exact_cmd,
8039 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8040 SHOW_STR
8041 IP_STR
8042 BGP_STR
8043 "Display routes matching the communities\n"
8044 "community number\n"
8045 "Do not send outside local AS (well-known community)\n"
8046 "Do not advertise to any peer (well-known community)\n"
8047 "Do not export to next AS (well-known community)\n"
8048 "Exact match of the communities")
8049{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008050 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008051}
8052
8053ALIAS (show_ip_bgp_community_exact,
8054 show_ip_bgp_community2_exact_cmd,
8055 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8056 SHOW_STR
8057 IP_STR
8058 BGP_STR
8059 "Display routes matching the communities\n"
8060 "community number\n"
8061 "Do not send outside local AS (well-known community)\n"
8062 "Do not advertise to any peer (well-known community)\n"
8063 "Do not export to next AS (well-known community)\n"
8064 "community number\n"
8065 "Do not send outside local AS (well-known community)\n"
8066 "Do not advertise to any peer (well-known community)\n"
8067 "Do not export to next AS (well-known community)\n"
8068 "Exact match of the communities")
8069
8070ALIAS (show_ip_bgp_community_exact,
8071 show_ip_bgp_community3_exact_cmd,
8072 "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",
8073 SHOW_STR
8074 IP_STR
8075 BGP_STR
8076 "Display routes matching the communities\n"
8077 "community number\n"
8078 "Do not send outside local AS (well-known community)\n"
8079 "Do not advertise to any peer (well-known community)\n"
8080 "Do not export to next AS (well-known community)\n"
8081 "community number\n"
8082 "Do not send outside local AS (well-known community)\n"
8083 "Do not advertise to any peer (well-known community)\n"
8084 "Do not export to next AS (well-known community)\n"
8085 "community number\n"
8086 "Do not send outside local AS (well-known community)\n"
8087 "Do not advertise to any peer (well-known community)\n"
8088 "Do not export to next AS (well-known community)\n"
8089 "Exact match of the communities")
8090
8091ALIAS (show_ip_bgp_community_exact,
8092 show_ip_bgp_community4_exact_cmd,
8093 "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",
8094 SHOW_STR
8095 IP_STR
8096 BGP_STR
8097 "Display routes matching the communities\n"
8098 "community number\n"
8099 "Do not send outside local AS (well-known community)\n"
8100 "Do not advertise to any peer (well-known community)\n"
8101 "Do not export to next AS (well-known community)\n"
8102 "community number\n"
8103 "Do not send outside local AS (well-known community)\n"
8104 "Do not advertise to any peer (well-known community)\n"
8105 "Do not export to next AS (well-known community)\n"
8106 "community number\n"
8107 "Do not send outside local AS (well-known community)\n"
8108 "Do not advertise to any peer (well-known community)\n"
8109 "Do not export to next AS (well-known community)\n"
8110 "community number\n"
8111 "Do not send outside local AS (well-known community)\n"
8112 "Do not advertise to any peer (well-known community)\n"
8113 "Do not export to next AS (well-known community)\n"
8114 "Exact match of the communities")
8115
8116DEFUN (show_ip_bgp_ipv4_community_exact,
8117 show_ip_bgp_ipv4_community_exact_cmd,
8118 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8119 SHOW_STR
8120 IP_STR
8121 BGP_STR
8122 "Address family\n"
8123 "Address Family modifier\n"
8124 "Address Family modifier\n"
8125 "Display routes matching the communities\n"
8126 "community number\n"
8127 "Do not send outside local AS (well-known community)\n"
8128 "Do not advertise to any peer (well-known community)\n"
8129 "Do not export to next AS (well-known community)\n"
8130 "Exact match of the communities")
8131{
8132 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008133 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008134
Michael Lambert95cbbd22010-07-23 14:43:04 -04008135 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008136}
8137
8138ALIAS (show_ip_bgp_ipv4_community_exact,
8139 show_ip_bgp_ipv4_community2_exact_cmd,
8140 "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",
8141 SHOW_STR
8142 IP_STR
8143 BGP_STR
8144 "Address family\n"
8145 "Address Family modifier\n"
8146 "Address Family modifier\n"
8147 "Display routes matching the communities\n"
8148 "community number\n"
8149 "Do not send outside local AS (well-known community)\n"
8150 "Do not advertise to any peer (well-known community)\n"
8151 "Do not export to next AS (well-known community)\n"
8152 "community number\n"
8153 "Do not send outside local AS (well-known community)\n"
8154 "Do not advertise to any peer (well-known community)\n"
8155 "Do not export to next AS (well-known community)\n"
8156 "Exact match of the communities")
8157
8158ALIAS (show_ip_bgp_ipv4_community_exact,
8159 show_ip_bgp_ipv4_community3_exact_cmd,
8160 "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",
8161 SHOW_STR
8162 IP_STR
8163 BGP_STR
8164 "Address family\n"
8165 "Address Family modifier\n"
8166 "Address Family modifier\n"
8167 "Display routes matching the communities\n"
8168 "community number\n"
8169 "Do not send outside local AS (well-known community)\n"
8170 "Do not advertise to any peer (well-known community)\n"
8171 "Do not export to next AS (well-known community)\n"
8172 "community number\n"
8173 "Do not send outside local AS (well-known community)\n"
8174 "Do not advertise to any peer (well-known community)\n"
8175 "Do not export to next AS (well-known community)\n"
8176 "community number\n"
8177 "Do not send outside local AS (well-known community)\n"
8178 "Do not advertise to any peer (well-known community)\n"
8179 "Do not export to next AS (well-known community)\n"
8180 "Exact match of the communities")
8181
8182ALIAS (show_ip_bgp_ipv4_community_exact,
8183 show_ip_bgp_ipv4_community4_exact_cmd,
8184 "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",
8185 SHOW_STR
8186 IP_STR
8187 BGP_STR
8188 "Address family\n"
8189 "Address Family modifier\n"
8190 "Address Family modifier\n"
8191 "Display routes matching the communities\n"
8192 "community number\n"
8193 "Do not send outside local AS (well-known community)\n"
8194 "Do not advertise to any peer (well-known community)\n"
8195 "Do not export to next AS (well-known community)\n"
8196 "community number\n"
8197 "Do not send outside local AS (well-known community)\n"
8198 "Do not advertise to any peer (well-known community)\n"
8199 "Do not export to next AS (well-known community)\n"
8200 "community number\n"
8201 "Do not send outside local AS (well-known community)\n"
8202 "Do not advertise to any peer (well-known community)\n"
8203 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8209
8210#ifdef HAVE_IPV6
8211DEFUN (show_bgp_community,
8212 show_bgp_community_cmd,
8213 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8214 SHOW_STR
8215 BGP_STR
8216 "Display routes matching the communities\n"
8217 "community number\n"
8218 "Do not send outside local AS (well-known community)\n"
8219 "Do not advertise to any peer (well-known community)\n"
8220 "Do not export to next AS (well-known community)\n")
8221{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008222 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008223}
8224
8225ALIAS (show_bgp_community,
8226 show_bgp_ipv6_community_cmd,
8227 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8228 SHOW_STR
8229 BGP_STR
8230 "Address family\n"
8231 "Display routes matching the communities\n"
8232 "community number\n"
8233 "Do not send outside local AS (well-known community)\n"
8234 "Do not advertise to any peer (well-known community)\n"
8235 "Do not export to next AS (well-known community)\n")
8236
8237ALIAS (show_bgp_community,
8238 show_bgp_community2_cmd,
8239 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8240 SHOW_STR
8241 BGP_STR
8242 "Display routes matching the communities\n"
8243 "community number\n"
8244 "Do not send outside local AS (well-known community)\n"
8245 "Do not advertise to any peer (well-known community)\n"
8246 "Do not export to next AS (well-known community)\n"
8247 "community number\n"
8248 "Do not send outside local AS (well-known community)\n"
8249 "Do not advertise to any peer (well-known community)\n"
8250 "Do not export to next AS (well-known community)\n")
8251
8252ALIAS (show_bgp_community,
8253 show_bgp_ipv6_community2_cmd,
8254 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8255 SHOW_STR
8256 BGP_STR
8257 "Address family\n"
8258 "Display routes matching the communities\n"
8259 "community number\n"
8260 "Do not send outside local AS (well-known community)\n"
8261 "Do not advertise to any peer (well-known community)\n"
8262 "Do not export to next AS (well-known community)\n"
8263 "community number\n"
8264 "Do not send outside local AS (well-known community)\n"
8265 "Do not advertise to any peer (well-known community)\n"
8266 "Do not export to next AS (well-known community)\n")
8267
8268ALIAS (show_bgp_community,
8269 show_bgp_community3_cmd,
8270 "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)",
8271 SHOW_STR
8272 BGP_STR
8273 "Display routes matching the communities\n"
8274 "community number\n"
8275 "Do not send outside local AS (well-known community)\n"
8276 "Do not advertise to any peer (well-known community)\n"
8277 "Do not export to next AS (well-known community)\n"
8278 "community number\n"
8279 "Do not send outside local AS (well-known community)\n"
8280 "Do not advertise to any peer (well-known community)\n"
8281 "Do not export to next AS (well-known community)\n"
8282 "community number\n"
8283 "Do not send outside local AS (well-known community)\n"
8284 "Do not advertise to any peer (well-known community)\n"
8285 "Do not export to next AS (well-known community)\n")
8286
8287ALIAS (show_bgp_community,
8288 show_bgp_ipv6_community3_cmd,
8289 "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)",
8290 SHOW_STR
8291 BGP_STR
8292 "Address family\n"
8293 "Display routes matching the communities\n"
8294 "community number\n"
8295 "Do not send outside local AS (well-known community)\n"
8296 "Do not advertise to any peer (well-known community)\n"
8297 "Do not export to next AS (well-known community)\n"
8298 "community number\n"
8299 "Do not send outside local AS (well-known community)\n"
8300 "Do not advertise to any peer (well-known community)\n"
8301 "Do not export to next AS (well-known community)\n"
8302 "community number\n"
8303 "Do not send outside local AS (well-known community)\n"
8304 "Do not advertise to any peer (well-known community)\n"
8305 "Do not export to next AS (well-known community)\n")
8306
8307ALIAS (show_bgp_community,
8308 show_bgp_community4_cmd,
8309 "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)",
8310 SHOW_STR
8311 BGP_STR
8312 "Display routes matching the communities\n"
8313 "community number\n"
8314 "Do not send outside local AS (well-known community)\n"
8315 "Do not advertise to any peer (well-known community)\n"
8316 "Do not export to next AS (well-known community)\n"
8317 "community number\n"
8318 "Do not send outside local AS (well-known community)\n"
8319 "Do not advertise to any peer (well-known community)\n"
8320 "Do not export to next AS (well-known community)\n"
8321 "community number\n"
8322 "Do not send outside local AS (well-known community)\n"
8323 "Do not advertise to any peer (well-known community)\n"
8324 "Do not export to next AS (well-known community)\n"
8325 "community number\n"
8326 "Do not send outside local AS (well-known community)\n"
8327 "Do not advertise to any peer (well-known community)\n"
8328 "Do not export to next AS (well-known community)\n")
8329
8330ALIAS (show_bgp_community,
8331 show_bgp_ipv6_community4_cmd,
8332 "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)",
8333 SHOW_STR
8334 BGP_STR
8335 "Address family\n"
8336 "Display routes matching the communities\n"
8337 "community number\n"
8338 "Do not send outside local AS (well-known community)\n"
8339 "Do not advertise to any peer (well-known community)\n"
8340 "Do not export to next AS (well-known community)\n"
8341 "community number\n"
8342 "Do not send outside local AS (well-known community)\n"
8343 "Do not advertise to any peer (well-known community)\n"
8344 "Do not export to next AS (well-known community)\n"
8345 "community number\n"
8346 "Do not send outside local AS (well-known community)\n"
8347 "Do not advertise to any peer (well-known community)\n"
8348 "Do not export to next AS (well-known community)\n"
8349 "community number\n"
8350 "Do not send outside local AS (well-known community)\n"
8351 "Do not advertise to any peer (well-known community)\n"
8352 "Do not export to next AS (well-known community)\n")
8353
8354/* old command */
8355DEFUN (show_ipv6_bgp_community,
8356 show_ipv6_bgp_community_cmd,
8357 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8358 SHOW_STR
8359 IPV6_STR
8360 BGP_STR
8361 "Display routes matching the communities\n"
8362 "community number\n"
8363 "Do not send outside local AS (well-known community)\n"
8364 "Do not advertise to any peer (well-known community)\n"
8365 "Do not export to next AS (well-known community)\n")
8366{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008367 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008368}
8369
8370/* old command */
8371ALIAS (show_ipv6_bgp_community,
8372 show_ipv6_bgp_community2_cmd,
8373 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8374 SHOW_STR
8375 IPV6_STR
8376 BGP_STR
8377 "Display routes matching the communities\n"
8378 "community number\n"
8379 "Do not send outside local AS (well-known community)\n"
8380 "Do not advertise to any peer (well-known community)\n"
8381 "Do not export to next AS (well-known community)\n"
8382 "community number\n"
8383 "Do not send outside local AS (well-known community)\n"
8384 "Do not advertise to any peer (well-known community)\n"
8385 "Do not export to next AS (well-known community)\n")
8386
8387/* old command */
8388ALIAS (show_ipv6_bgp_community,
8389 show_ipv6_bgp_community3_cmd,
8390 "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)",
8391 SHOW_STR
8392 IPV6_STR
8393 BGP_STR
8394 "Display routes matching the communities\n"
8395 "community number\n"
8396 "Do not send outside local AS (well-known community)\n"
8397 "Do not advertise to any peer (well-known community)\n"
8398 "Do not export to next AS (well-known community)\n"
8399 "community number\n"
8400 "Do not send outside local AS (well-known community)\n"
8401 "Do not advertise to any peer (well-known community)\n"
8402 "Do not export to next AS (well-known community)\n"
8403 "community number\n"
8404 "Do not send outside local AS (well-known community)\n"
8405 "Do not advertise to any peer (well-known community)\n"
8406 "Do not export to next AS (well-known community)\n")
8407
8408/* old command */
8409ALIAS (show_ipv6_bgp_community,
8410 show_ipv6_bgp_community4_cmd,
8411 "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)",
8412 SHOW_STR
8413 IPV6_STR
8414 BGP_STR
8415 "Display routes matching the communities\n"
8416 "community number\n"
8417 "Do not send outside local AS (well-known community)\n"
8418 "Do not advertise to any peer (well-known community)\n"
8419 "Do not export to next AS (well-known community)\n"
8420 "community number\n"
8421 "Do not send outside local AS (well-known community)\n"
8422 "Do not advertise to any peer (well-known community)\n"
8423 "Do not export to next AS (well-known community)\n"
8424 "community number\n"
8425 "Do not send outside local AS (well-known community)\n"
8426 "Do not advertise to any peer (well-known community)\n"
8427 "Do not export to next AS (well-known community)\n"
8428 "community number\n"
8429 "Do not send outside local AS (well-known community)\n"
8430 "Do not advertise to any peer (well-known community)\n"
8431 "Do not export to next AS (well-known community)\n")
8432
8433DEFUN (show_bgp_community_exact,
8434 show_bgp_community_exact_cmd,
8435 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8436 SHOW_STR
8437 BGP_STR
8438 "Display routes matching the communities\n"
8439 "community number\n"
8440 "Do not send outside local AS (well-known community)\n"
8441 "Do not advertise to any peer (well-known community)\n"
8442 "Do not export to next AS (well-known community)\n"
8443 "Exact match of the communities")
8444{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008445 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008446}
8447
8448ALIAS (show_bgp_community_exact,
8449 show_bgp_ipv6_community_exact_cmd,
8450 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8451 SHOW_STR
8452 BGP_STR
8453 "Address family\n"
8454 "Display routes matching the communities\n"
8455 "community number\n"
8456 "Do not send outside local AS (well-known community)\n"
8457 "Do not advertise to any peer (well-known community)\n"
8458 "Do not export to next AS (well-known community)\n"
8459 "Exact match of the communities")
8460
8461ALIAS (show_bgp_community_exact,
8462 show_bgp_community2_exact_cmd,
8463 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8464 SHOW_STR
8465 BGP_STR
8466 "Display routes matching the communities\n"
8467 "community number\n"
8468 "Do not send outside local AS (well-known community)\n"
8469 "Do not advertise to any peer (well-known community)\n"
8470 "Do not export to next AS (well-known community)\n"
8471 "community number\n"
8472 "Do not send outside local AS (well-known community)\n"
8473 "Do not advertise to any peer (well-known community)\n"
8474 "Do not export to next AS (well-known community)\n"
8475 "Exact match of the communities")
8476
8477ALIAS (show_bgp_community_exact,
8478 show_bgp_ipv6_community2_exact_cmd,
8479 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8480 SHOW_STR
8481 BGP_STR
8482 "Address family\n"
8483 "Display routes matching the communities\n"
8484 "community number\n"
8485 "Do not send outside local AS (well-known community)\n"
8486 "Do not advertise to any peer (well-known community)\n"
8487 "Do not export to next AS (well-known community)\n"
8488 "community number\n"
8489 "Do not send outside local AS (well-known community)\n"
8490 "Do not advertise to any peer (well-known community)\n"
8491 "Do not export to next AS (well-known community)\n"
8492 "Exact match of the communities")
8493
8494ALIAS (show_bgp_community_exact,
8495 show_bgp_community3_exact_cmd,
8496 "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",
8497 SHOW_STR
8498 BGP_STR
8499 "Display routes matching the communities\n"
8500 "community number\n"
8501 "Do not send outside local AS (well-known community)\n"
8502 "Do not advertise to any peer (well-known community)\n"
8503 "Do not export to next AS (well-known community)\n"
8504 "community number\n"
8505 "Do not send outside local AS (well-known community)\n"
8506 "Do not advertise to any peer (well-known community)\n"
8507 "Do not export to next AS (well-known community)\n"
8508 "community number\n"
8509 "Do not send outside local AS (well-known community)\n"
8510 "Do not advertise to any peer (well-known community)\n"
8511 "Do not export to next AS (well-known community)\n"
8512 "Exact match of the communities")
8513
8514ALIAS (show_bgp_community_exact,
8515 show_bgp_ipv6_community3_exact_cmd,
8516 "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",
8517 SHOW_STR
8518 BGP_STR
8519 "Address family\n"
8520 "Display routes matching the communities\n"
8521 "community number\n"
8522 "Do not send outside local AS (well-known community)\n"
8523 "Do not advertise to any peer (well-known community)\n"
8524 "Do not export to next AS (well-known community)\n"
8525 "community number\n"
8526 "Do not send outside local AS (well-known community)\n"
8527 "Do not advertise to any peer (well-known community)\n"
8528 "Do not export to next AS (well-known community)\n"
8529 "community number\n"
8530 "Do not send outside local AS (well-known community)\n"
8531 "Do not advertise to any peer (well-known community)\n"
8532 "Do not export to next AS (well-known community)\n"
8533 "Exact match of the communities")
8534
8535ALIAS (show_bgp_community_exact,
8536 show_bgp_community4_exact_cmd,
8537 "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",
8538 SHOW_STR
8539 BGP_STR
8540 "Display routes matching the communities\n"
8541 "community number\n"
8542 "Do not send outside local AS (well-known community)\n"
8543 "Do not advertise to any peer (well-known community)\n"
8544 "Do not export to next AS (well-known community)\n"
8545 "community number\n"
8546 "Do not send outside local AS (well-known community)\n"
8547 "Do not advertise to any peer (well-known community)\n"
8548 "Do not export to next AS (well-known community)\n"
8549 "community number\n"
8550 "Do not send outside local AS (well-known community)\n"
8551 "Do not advertise to any peer (well-known community)\n"
8552 "Do not export to next AS (well-known community)\n"
8553 "community number\n"
8554 "Do not send outside local AS (well-known community)\n"
8555 "Do not advertise to any peer (well-known community)\n"
8556 "Do not export to next AS (well-known community)\n"
8557 "Exact match of the communities")
8558
8559ALIAS (show_bgp_community_exact,
8560 show_bgp_ipv6_community4_exact_cmd,
8561 "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",
8562 SHOW_STR
8563 BGP_STR
8564 "Address family\n"
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 "community number\n"
8571 "Do not send outside local AS (well-known community)\n"
8572 "Do not advertise to any peer (well-known community)\n"
8573 "Do not export to next AS (well-known community)\n"
8574 "community number\n"
8575 "Do not send outside local AS (well-known community)\n"
8576 "Do not advertise to any peer (well-known community)\n"
8577 "Do not export to next AS (well-known community)\n"
8578 "community number\n"
8579 "Do not send outside local AS (well-known community)\n"
8580 "Do not advertise to any peer (well-known community)\n"
8581 "Do not export to next AS (well-known community)\n"
8582 "Exact match of the communities")
8583
8584/* old command */
8585DEFUN (show_ipv6_bgp_community_exact,
8586 show_ipv6_bgp_community_exact_cmd,
8587 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8588 SHOW_STR
8589 IPV6_STR
8590 BGP_STR
8591 "Display routes matching the communities\n"
8592 "community number\n"
8593 "Do not send outside local AS (well-known community)\n"
8594 "Do not advertise to any peer (well-known community)\n"
8595 "Do not export to next AS (well-known community)\n"
8596 "Exact match of the communities")
8597{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008598 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008599}
8600
8601/* old command */
8602ALIAS (show_ipv6_bgp_community_exact,
8603 show_ipv6_bgp_community2_exact_cmd,
8604 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8605 SHOW_STR
8606 IPV6_STR
8607 BGP_STR
8608 "Display routes matching the communities\n"
8609 "community number\n"
8610 "Do not send outside local AS (well-known community)\n"
8611 "Do not advertise to any peer (well-known community)\n"
8612 "Do not export to next AS (well-known community)\n"
8613 "community number\n"
8614 "Do not send outside local AS (well-known community)\n"
8615 "Do not advertise to any peer (well-known community)\n"
8616 "Do not export to next AS (well-known community)\n"
8617 "Exact match of the communities")
8618
8619/* old command */
8620ALIAS (show_ipv6_bgp_community_exact,
8621 show_ipv6_bgp_community3_exact_cmd,
8622 "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",
8623 SHOW_STR
8624 IPV6_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
8641/* old command */
8642ALIAS (show_ipv6_bgp_community_exact,
8643 show_ipv6_bgp_community4_exact_cmd,
8644 "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",
8645 SHOW_STR
8646 IPV6_STR
8647 BGP_STR
8648 "Display routes matching the communities\n"
8649 "community number\n"
8650 "Do not send outside local AS (well-known community)\n"
8651 "Do not advertise to any peer (well-known community)\n"
8652 "Do not export to next AS (well-known community)\n"
8653 "community number\n"
8654 "Do not send outside local AS (well-known community)\n"
8655 "Do not advertise to any peer (well-known community)\n"
8656 "Do not export to next AS (well-known community)\n"
8657 "community number\n"
8658 "Do not send outside local AS (well-known community)\n"
8659 "Do not advertise to any peer (well-known community)\n"
8660 "Do not export to next AS (well-known community)\n"
8661 "community number\n"
8662 "Do not send outside local AS (well-known community)\n"
8663 "Do not advertise to any peer (well-known community)\n"
8664 "Do not export to next AS (well-known community)\n"
8665 "Exact match of the communities")
8666
8667/* old command */
8668DEFUN (show_ipv6_mbgp_community,
8669 show_ipv6_mbgp_community_cmd,
8670 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8671 SHOW_STR
8672 IPV6_STR
8673 MBGP_STR
8674 "Display routes matching the communities\n"
8675 "community number\n"
8676 "Do not send outside local AS (well-known community)\n"
8677 "Do not advertise to any peer (well-known community)\n"
8678 "Do not export to next AS (well-known community)\n")
8679{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008680 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008681}
8682
8683/* old command */
8684ALIAS (show_ipv6_mbgp_community,
8685 show_ipv6_mbgp_community2_cmd,
8686 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8687 SHOW_STR
8688 IPV6_STR
8689 MBGP_STR
8690 "Display routes matching the communities\n"
8691 "community number\n"
8692 "Do not send outside local AS (well-known community)\n"
8693 "Do not advertise to any peer (well-known community)\n"
8694 "Do not export to next AS (well-known community)\n"
8695 "community number\n"
8696 "Do not send outside local AS (well-known community)\n"
8697 "Do not advertise to any peer (well-known community)\n"
8698 "Do not export to next AS (well-known community)\n")
8699
8700/* old command */
8701ALIAS (show_ipv6_mbgp_community,
8702 show_ipv6_mbgp_community3_cmd,
8703 "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)",
8704 SHOW_STR
8705 IPV6_STR
8706 MBGP_STR
8707 "Display routes matching the communities\n"
8708 "community number\n"
8709 "Do not send outside local AS (well-known community)\n"
8710 "Do not advertise to any peer (well-known community)\n"
8711 "Do not export to next AS (well-known community)\n"
8712 "community number\n"
8713 "Do not send outside local AS (well-known community)\n"
8714 "Do not advertise to any peer (well-known community)\n"
8715 "Do not export to next AS (well-known community)\n"
8716 "community number\n"
8717 "Do not send outside local AS (well-known community)\n"
8718 "Do not advertise to any peer (well-known community)\n"
8719 "Do not export to next AS (well-known community)\n")
8720
8721/* old command */
8722ALIAS (show_ipv6_mbgp_community,
8723 show_ipv6_mbgp_community4_cmd,
8724 "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)",
8725 SHOW_STR
8726 IPV6_STR
8727 MBGP_STR
8728 "Display routes matching the communities\n"
8729 "community number\n"
8730 "Do not send outside local AS (well-known community)\n"
8731 "Do not advertise to any peer (well-known community)\n"
8732 "Do not export to next AS (well-known community)\n"
8733 "community number\n"
8734 "Do not send outside local AS (well-known community)\n"
8735 "Do not advertise to any peer (well-known community)\n"
8736 "Do not export to next AS (well-known community)\n"
8737 "community number\n"
8738 "Do not send outside local AS (well-known community)\n"
8739 "Do not advertise to any peer (well-known community)\n"
8740 "Do not export to next AS (well-known community)\n"
8741 "community number\n"
8742 "Do not send outside local AS (well-known community)\n"
8743 "Do not advertise to any peer (well-known community)\n"
8744 "Do not export to next AS (well-known community)\n")
8745
8746/* old command */
8747DEFUN (show_ipv6_mbgp_community_exact,
8748 show_ipv6_mbgp_community_exact_cmd,
8749 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8750 SHOW_STR
8751 IPV6_STR
8752 MBGP_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 "Exact match of the communities")
8759{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008760 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008761}
8762
8763/* old command */
8764ALIAS (show_ipv6_mbgp_community_exact,
8765 show_ipv6_mbgp_community2_exact_cmd,
8766 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8767 SHOW_STR
8768 IPV6_STR
8769 MBGP_STR
8770 "Display routes matching the communities\n"
8771 "community number\n"
8772 "Do not send outside local AS (well-known community)\n"
8773 "Do not advertise to any peer (well-known community)\n"
8774 "Do not export to next AS (well-known community)\n"
8775 "community number\n"
8776 "Do not send outside local AS (well-known community)\n"
8777 "Do not advertise to any peer (well-known community)\n"
8778 "Do not export to next AS (well-known community)\n"
8779 "Exact match of the communities")
8780
8781/* old command */
8782ALIAS (show_ipv6_mbgp_community_exact,
8783 show_ipv6_mbgp_community3_exact_cmd,
8784 "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",
8785 SHOW_STR
8786 IPV6_STR
8787 MBGP_STR
8788 "Display routes matching the communities\n"
8789 "community number\n"
8790 "Do not send outside local AS (well-known community)\n"
8791 "Do not advertise to any peer (well-known community)\n"
8792 "Do not export to next AS (well-known community)\n"
8793 "community number\n"
8794 "Do not send outside local AS (well-known community)\n"
8795 "Do not advertise to any peer (well-known community)\n"
8796 "Do not export to next AS (well-known community)\n"
8797 "community number\n"
8798 "Do not send outside local AS (well-known community)\n"
8799 "Do not advertise to any peer (well-known community)\n"
8800 "Do not export to next AS (well-known community)\n"
8801 "Exact match of the communities")
8802
8803/* old command */
8804ALIAS (show_ipv6_mbgp_community_exact,
8805 show_ipv6_mbgp_community4_exact_cmd,
8806 "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",
8807 SHOW_STR
8808 IPV6_STR
8809 MBGP_STR
8810 "Display routes matching the communities\n"
8811 "community number\n"
8812 "Do not send outside local AS (well-known community)\n"
8813 "Do not advertise to any peer (well-known community)\n"
8814 "Do not export to next AS (well-known community)\n"
8815 "community number\n"
8816 "Do not send outside local AS (well-known community)\n"
8817 "Do not advertise to any peer (well-known community)\n"
8818 "Do not export to next AS (well-known community)\n"
8819 "community number\n"
8820 "Do not send outside local AS (well-known community)\n"
8821 "Do not advertise to any peer (well-known community)\n"
8822 "Do not export to next AS (well-known community)\n"
8823 "community number\n"
8824 "Do not send outside local AS (well-known community)\n"
8825 "Do not advertise to any peer (well-known community)\n"
8826 "Do not export to next AS (well-known community)\n"
8827 "Exact match of the communities")
8828#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02008829
paul94f2b392005-06-28 12:44:16 +00008830static int
paulfd79ac92004-10-13 05:06:08 +00008831bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008832 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008833{
8834 struct community_list *list;
8835
hassofee6e4e2005-02-02 16:29:31 +00008836 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008837 if (list == NULL)
8838 {
8839 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8840 VTY_NEWLINE);
8841 return CMD_WARNING;
8842 }
8843
ajs5a646652004-11-05 01:25:55 +00008844 return bgp_show (vty, NULL, afi, safi,
8845 (exact ? bgp_show_type_community_list_exact :
8846 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008847}
8848
8849DEFUN (show_ip_bgp_community_list,
8850 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008851 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008852 SHOW_STR
8853 IP_STR
8854 BGP_STR
8855 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008856 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008857 "community-list name\n")
8858{
8859 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8860}
8861
8862DEFUN (show_ip_bgp_ipv4_community_list,
8863 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008864 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008865 SHOW_STR
8866 IP_STR
8867 BGP_STR
8868 "Address family\n"
8869 "Address Family modifier\n"
8870 "Address Family modifier\n"
8871 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008872 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008873 "community-list name\n")
8874{
8875 if (strncmp (argv[0], "m", 1) == 0)
8876 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8877
8878 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8879}
8880
8881DEFUN (show_ip_bgp_community_list_exact,
8882 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008883 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008884 SHOW_STR
8885 IP_STR
8886 BGP_STR
8887 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008888 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008889 "community-list name\n"
8890 "Exact match of the communities\n")
8891{
8892 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8893}
8894
8895DEFUN (show_ip_bgp_ipv4_community_list_exact,
8896 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008897 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008898 SHOW_STR
8899 IP_STR
8900 BGP_STR
8901 "Address family\n"
8902 "Address Family modifier\n"
8903 "Address Family modifier\n"
8904 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008905 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008906 "community-list name\n"
8907 "Exact match of the communities\n")
8908{
8909 if (strncmp (argv[0], "m", 1) == 0)
8910 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8911
8912 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8913}
8914
8915#ifdef HAVE_IPV6
8916DEFUN (show_bgp_community_list,
8917 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008918 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008919 SHOW_STR
8920 BGP_STR
8921 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008922 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008923 "community-list name\n")
8924{
8925 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8926}
8927
8928ALIAS (show_bgp_community_list,
8929 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008930 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008931 SHOW_STR
8932 BGP_STR
8933 "Address family\n"
8934 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008935 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008936 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008937
8938/* old command */
8939DEFUN (show_ipv6_bgp_community_list,
8940 show_ipv6_bgp_community_list_cmd,
8941 "show ipv6 bgp community-list WORD",
8942 SHOW_STR
8943 IPV6_STR
8944 BGP_STR
8945 "Display routes matching the community-list\n"
8946 "community-list name\n")
8947{
8948 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8949}
8950
8951/* old command */
8952DEFUN (show_ipv6_mbgp_community_list,
8953 show_ipv6_mbgp_community_list_cmd,
8954 "show ipv6 mbgp community-list WORD",
8955 SHOW_STR
8956 IPV6_STR
8957 MBGP_STR
8958 "Display routes matching the community-list\n"
8959 "community-list name\n")
8960{
8961 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8962}
8963
8964DEFUN (show_bgp_community_list_exact,
8965 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008966 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008967 SHOW_STR
8968 BGP_STR
8969 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008970 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008971 "community-list name\n"
8972 "Exact match of the communities\n")
8973{
8974 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8975}
8976
8977ALIAS (show_bgp_community_list_exact,
8978 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008979 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008980 SHOW_STR
8981 BGP_STR
8982 "Address family\n"
8983 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008984 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008985 "community-list name\n"
8986 "Exact match of the communities\n")
8987
8988/* old command */
8989DEFUN (show_ipv6_bgp_community_list_exact,
8990 show_ipv6_bgp_community_list_exact_cmd,
8991 "show ipv6 bgp community-list WORD exact-match",
8992 SHOW_STR
8993 IPV6_STR
8994 BGP_STR
8995 "Display routes matching the community-list\n"
8996 "community-list name\n"
8997 "Exact match of the communities\n")
8998{
8999 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9000}
9001
9002/* old command */
9003DEFUN (show_ipv6_mbgp_community_list_exact,
9004 show_ipv6_mbgp_community_list_exact_cmd,
9005 "show ipv6 mbgp community-list WORD exact-match",
9006 SHOW_STR
9007 IPV6_STR
9008 MBGP_STR
9009 "Display routes matching the community-list\n"
9010 "community-list name\n"
9011 "Exact match of the communities\n")
9012{
9013 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9014}
9015#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009016
paul94f2b392005-06-28 12:44:16 +00009017static int
paulfd79ac92004-10-13 05:06:08 +00009018bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009019 safi_t safi, enum bgp_show_type type)
9020{
9021 int ret;
9022 struct prefix *p;
9023
9024 p = prefix_new();
9025
9026 ret = str2prefix (prefix, p);
9027 if (! ret)
9028 {
9029 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9030 return CMD_WARNING;
9031 }
9032
ajs5a646652004-11-05 01:25:55 +00009033 ret = bgp_show (vty, NULL, afi, safi, type, p);
9034 prefix_free(p);
9035 return ret;
paul718e3742002-12-13 20:15:29 +00009036}
9037
9038DEFUN (show_ip_bgp_prefix_longer,
9039 show_ip_bgp_prefix_longer_cmd,
9040 "show ip bgp A.B.C.D/M longer-prefixes",
9041 SHOW_STR
9042 IP_STR
9043 BGP_STR
9044 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9045 "Display route and more specific routes\n")
9046{
9047 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9048 bgp_show_type_prefix_longer);
9049}
9050
9051DEFUN (show_ip_bgp_flap_prefix_longer,
9052 show_ip_bgp_flap_prefix_longer_cmd,
9053 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9054 SHOW_STR
9055 IP_STR
9056 BGP_STR
9057 "Display flap statistics of routes\n"
9058 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9059 "Display route and more specific routes\n")
9060{
9061 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9062 bgp_show_type_flap_prefix_longer);
9063}
9064
9065DEFUN (show_ip_bgp_ipv4_prefix_longer,
9066 show_ip_bgp_ipv4_prefix_longer_cmd,
9067 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9068 SHOW_STR
9069 IP_STR
9070 BGP_STR
9071 "Address family\n"
9072 "Address Family modifier\n"
9073 "Address Family modifier\n"
9074 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9075 "Display route and more specific routes\n")
9076{
9077 if (strncmp (argv[0], "m", 1) == 0)
9078 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9079 bgp_show_type_prefix_longer);
9080
9081 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9082 bgp_show_type_prefix_longer);
9083}
9084
9085DEFUN (show_ip_bgp_flap_address,
9086 show_ip_bgp_flap_address_cmd,
9087 "show ip bgp flap-statistics A.B.C.D",
9088 SHOW_STR
9089 IP_STR
9090 BGP_STR
9091 "Display flap statistics of routes\n"
9092 "Network in the BGP routing table to display\n")
9093{
9094 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9095 bgp_show_type_flap_address);
9096}
9097
9098DEFUN (show_ip_bgp_flap_prefix,
9099 show_ip_bgp_flap_prefix_cmd,
9100 "show ip bgp flap-statistics A.B.C.D/M",
9101 SHOW_STR
9102 IP_STR
9103 BGP_STR
9104 "Display flap statistics of routes\n"
9105 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9106{
9107 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9108 bgp_show_type_flap_prefix);
9109}
9110#ifdef HAVE_IPV6
9111DEFUN (show_bgp_prefix_longer,
9112 show_bgp_prefix_longer_cmd,
9113 "show bgp X:X::X:X/M longer-prefixes",
9114 SHOW_STR
9115 BGP_STR
9116 "IPv6 prefix <network>/<length>\n"
9117 "Display route and more specific routes\n")
9118{
9119 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9120 bgp_show_type_prefix_longer);
9121}
9122
9123ALIAS (show_bgp_prefix_longer,
9124 show_bgp_ipv6_prefix_longer_cmd,
9125 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9126 SHOW_STR
9127 BGP_STR
9128 "Address family\n"
9129 "IPv6 prefix <network>/<length>\n"
9130 "Display route and more specific routes\n")
9131
9132/* old command */
9133DEFUN (show_ipv6_bgp_prefix_longer,
9134 show_ipv6_bgp_prefix_longer_cmd,
9135 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9136 SHOW_STR
9137 IPV6_STR
9138 BGP_STR
9139 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9140 "Display route and more specific routes\n")
9141{
9142 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9143 bgp_show_type_prefix_longer);
9144}
9145
9146/* old command */
9147DEFUN (show_ipv6_mbgp_prefix_longer,
9148 show_ipv6_mbgp_prefix_longer_cmd,
9149 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9150 SHOW_STR
9151 IPV6_STR
9152 MBGP_STR
9153 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9154 "Display route and more specific routes\n")
9155{
9156 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9157 bgp_show_type_prefix_longer);
9158}
9159#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009160
paul94f2b392005-06-28 12:44:16 +00009161static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009162peer_lookup_in_view (struct vty *vty, const char *view_name,
9163 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009164{
9165 int ret;
9166 struct bgp *bgp;
9167 struct peer *peer;
9168 union sockunion su;
9169
9170 /* BGP structure lookup. */
9171 if (view_name)
9172 {
9173 bgp = bgp_lookup_by_name (view_name);
9174 if (! bgp)
9175 {
9176 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9177 return NULL;
9178 }
9179 }
paul5228ad22004-06-04 17:58:18 +00009180 else
paulbb46e942003-10-24 19:02:03 +00009181 {
9182 bgp = bgp_get_default ();
9183 if (! bgp)
9184 {
9185 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9186 return NULL;
9187 }
9188 }
9189
9190 /* Get peer sockunion. */
9191 ret = str2sockunion (ip_str, &su);
9192 if (ret < 0)
9193 {
9194 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9195 return NULL;
9196 }
9197
9198 /* Peer structure lookup. */
9199 peer = peer_lookup (bgp, &su);
9200 if (! peer)
9201 {
9202 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9203 return NULL;
9204 }
9205
9206 return peer;
9207}
David Lamparter6b0655a2014-06-04 06:53:35 +02009208
Paul Jakma2815e612006-09-14 02:56:07 +00009209enum bgp_stats
9210{
9211 BGP_STATS_MAXBITLEN = 0,
9212 BGP_STATS_RIB,
9213 BGP_STATS_PREFIXES,
9214 BGP_STATS_TOTPLEN,
9215 BGP_STATS_UNAGGREGATEABLE,
9216 BGP_STATS_MAX_AGGREGATEABLE,
9217 BGP_STATS_AGGREGATES,
9218 BGP_STATS_SPACE,
9219 BGP_STATS_ASPATH_COUNT,
9220 BGP_STATS_ASPATH_MAXHOPS,
9221 BGP_STATS_ASPATH_TOTHOPS,
9222 BGP_STATS_ASPATH_MAXSIZE,
9223 BGP_STATS_ASPATH_TOTSIZE,
9224 BGP_STATS_ASN_HIGHEST,
9225 BGP_STATS_MAX,
9226};
paulbb46e942003-10-24 19:02:03 +00009227
Paul Jakma2815e612006-09-14 02:56:07 +00009228static const char *table_stats_strs[] =
9229{
9230 [BGP_STATS_PREFIXES] = "Total Prefixes",
9231 [BGP_STATS_TOTPLEN] = "Average prefix length",
9232 [BGP_STATS_RIB] = "Total Advertisements",
9233 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9234 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9235 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9236 [BGP_STATS_SPACE] = "Address space advertised",
9237 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9238 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9239 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9240 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9241 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9242 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9243 [BGP_STATS_MAX] = NULL,
9244};
9245
9246struct bgp_table_stats
9247{
9248 struct bgp_table *table;
9249 unsigned long long counts[BGP_STATS_MAX];
9250};
9251
9252#if 0
9253#define TALLY_SIGFIG 100000
9254static unsigned long
9255ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9256{
9257 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9258 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9259 unsigned long ret = newtot / count;
9260
9261 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9262 return ret + 1;
9263 else
9264 return ret;
9265}
9266#endif
9267
9268static int
9269bgp_table_stats_walker (struct thread *t)
9270{
9271 struct bgp_node *rn;
9272 struct bgp_node *top;
9273 struct bgp_table_stats *ts = THREAD_ARG (t);
9274 unsigned int space = 0;
9275
Paul Jakma53d9f672006-10-15 23:41:16 +00009276 if (!(top = bgp_table_top (ts->table)))
9277 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009278
9279 switch (top->p.family)
9280 {
9281 case AF_INET:
9282 space = IPV4_MAX_BITLEN;
9283 break;
9284 case AF_INET6:
9285 space = IPV6_MAX_BITLEN;
9286 break;
9287 }
9288
9289 ts->counts[BGP_STATS_MAXBITLEN] = space;
9290
9291 for (rn = top; rn; rn = bgp_route_next (rn))
9292 {
9293 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009294 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009295 unsigned int rinum = 0;
9296
9297 if (rn == top)
9298 continue;
9299
9300 if (!rn->info)
9301 continue;
9302
9303 ts->counts[BGP_STATS_PREFIXES]++;
9304 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9305
9306#if 0
9307 ts->counts[BGP_STATS_AVGPLEN]
9308 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9309 ts->counts[BGP_STATS_AVGPLEN],
9310 rn->p.prefixlen);
9311#endif
9312
9313 /* check if the prefix is included by any other announcements */
9314 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009315 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009316
9317 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009318 {
9319 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9320 /* announced address space */
9321 if (space)
9322 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9323 }
Paul Jakma2815e612006-09-14 02:56:07 +00009324 else if (prn->info)
9325 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9326
Paul Jakma2815e612006-09-14 02:56:07 +00009327 for (ri = rn->info; ri; ri = ri->next)
9328 {
9329 rinum++;
9330 ts->counts[BGP_STATS_RIB]++;
9331
9332 if (ri->attr &&
9333 (CHECK_FLAG (ri->attr->flag,
9334 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9335 ts->counts[BGP_STATS_AGGREGATES]++;
9336
9337 /* as-path stats */
9338 if (ri->attr && ri->attr->aspath)
9339 {
9340 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9341 unsigned int size = aspath_size (ri->attr->aspath);
9342 as_t highest = aspath_highest (ri->attr->aspath);
9343
9344 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9345
9346 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9347 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9348
9349 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9350 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9351
9352 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9353 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9354#if 0
9355 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9356 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9357 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9358 hops);
9359 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9360 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9361 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9362 size);
9363#endif
9364 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9365 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9366 }
9367 }
9368 }
9369 return 0;
9370}
9371
9372static int
9373bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9374{
9375 struct bgp_table_stats ts;
9376 unsigned int i;
9377
9378 if (!bgp->rib[afi][safi])
9379 {
9380 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9381 return CMD_WARNING;
9382 }
9383
9384 memset (&ts, 0, sizeof (ts));
9385 ts.table = bgp->rib[afi][safi];
9386 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9387
9388 vty_out (vty, "BGP %s RIB statistics%s%s",
9389 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9390
9391 for (i = 0; i < BGP_STATS_MAX; i++)
9392 {
9393 if (!table_stats_strs[i])
9394 continue;
9395
9396 switch (i)
9397 {
9398#if 0
9399 case BGP_STATS_ASPATH_AVGHOPS:
9400 case BGP_STATS_ASPATH_AVGSIZE:
9401 case BGP_STATS_AVGPLEN:
9402 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9403 vty_out (vty, "%12.2f",
9404 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9405 break;
9406#endif
9407 case BGP_STATS_ASPATH_TOTHOPS:
9408 case BGP_STATS_ASPATH_TOTSIZE:
9409 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9410 vty_out (vty, "%12.2f",
9411 ts.counts[i] ?
9412 (float)ts.counts[i] /
9413 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9414 : 0);
9415 break;
9416 case BGP_STATS_TOTPLEN:
9417 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9418 vty_out (vty, "%12.2f",
9419 ts.counts[i] ?
9420 (float)ts.counts[i] /
9421 (float)ts.counts[BGP_STATS_PREFIXES]
9422 : 0);
9423 break;
9424 case BGP_STATS_SPACE:
9425 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9426 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9427 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9428 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009429 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009430 vty_out (vty, "%12.2f%s",
9431 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009432 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009433 VTY_NEWLINE);
9434 vty_out (vty, "%30s: ", "/8 equivalent ");
9435 vty_out (vty, "%12.2f%s",
9436 (float)ts.counts[BGP_STATS_SPACE] /
9437 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9438 VTY_NEWLINE);
9439 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9440 break;
9441 vty_out (vty, "%30s: ", "/24 equivalent ");
9442 vty_out (vty, "%12.2f",
9443 (float)ts.counts[BGP_STATS_SPACE] /
9444 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9445 break;
9446 default:
9447 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9448 vty_out (vty, "%12llu", ts.counts[i]);
9449 }
9450
9451 vty_out (vty, "%s", VTY_NEWLINE);
9452 }
9453 return CMD_SUCCESS;
9454}
9455
9456static int
9457bgp_table_stats_vty (struct vty *vty, const char *name,
9458 const char *afi_str, const char *safi_str)
9459{
9460 struct bgp *bgp;
9461 afi_t afi;
9462 safi_t safi;
9463
9464 if (name)
9465 bgp = bgp_lookup_by_name (name);
9466 else
9467 bgp = bgp_get_default ();
9468
9469 if (!bgp)
9470 {
9471 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9472 return CMD_WARNING;
9473 }
9474 if (strncmp (afi_str, "ipv", 3) == 0)
9475 {
9476 if (strncmp (afi_str, "ipv4", 4) == 0)
9477 afi = AFI_IP;
9478 else if (strncmp (afi_str, "ipv6", 4) == 0)
9479 afi = AFI_IP6;
9480 else
9481 {
9482 vty_out (vty, "%% Invalid address family %s%s",
9483 afi_str, VTY_NEWLINE);
9484 return CMD_WARNING;
9485 }
9486 if (strncmp (safi_str, "m", 1) == 0)
9487 safi = SAFI_MULTICAST;
9488 else if (strncmp (safi_str, "u", 1) == 0)
9489 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009490 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9491 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009492 else
9493 {
9494 vty_out (vty, "%% Invalid subsequent address family %s%s",
9495 safi_str, VTY_NEWLINE);
9496 return CMD_WARNING;
9497 }
9498 }
9499 else
9500 {
9501 vty_out (vty, "%% Invalid address family %s%s",
9502 afi_str, VTY_NEWLINE);
9503 return CMD_WARNING;
9504 }
9505
Paul Jakma2815e612006-09-14 02:56:07 +00009506 return bgp_table_stats (vty, bgp, afi, safi);
9507}
9508
9509DEFUN (show_bgp_statistics,
9510 show_bgp_statistics_cmd,
9511 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9512 SHOW_STR
9513 BGP_STR
9514 "Address family\n"
9515 "Address family\n"
9516 "Address Family modifier\n"
9517 "Address Family modifier\n"
9518 "BGP RIB advertisement statistics\n")
9519{
9520 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9521}
9522
9523ALIAS (show_bgp_statistics,
9524 show_bgp_statistics_vpnv4_cmd,
9525 "show bgp (ipv4) (vpnv4) statistics",
9526 SHOW_STR
9527 BGP_STR
9528 "Address family\n"
9529 "Address Family modifier\n"
9530 "BGP RIB advertisement statistics\n")
9531
9532DEFUN (show_bgp_statistics_view,
9533 show_bgp_statistics_view_cmd,
9534 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9535 SHOW_STR
9536 BGP_STR
9537 "BGP view\n"
9538 "Address family\n"
9539 "Address family\n"
9540 "Address Family modifier\n"
9541 "Address Family modifier\n"
9542 "BGP RIB advertisement statistics\n")
9543{
9544 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9545}
9546
9547ALIAS (show_bgp_statistics_view,
9548 show_bgp_statistics_view_vpnv4_cmd,
9549 "show bgp view WORD (ipv4) (vpnv4) statistics",
9550 SHOW_STR
9551 BGP_STR
9552 "BGP view\n"
9553 "Address family\n"
9554 "Address Family modifier\n"
9555 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02009556
Paul Jakmaff7924f2006-09-04 01:10:36 +00009557enum bgp_pcounts
9558{
9559 PCOUNT_ADJ_IN = 0,
9560 PCOUNT_DAMPED,
9561 PCOUNT_REMOVED,
9562 PCOUNT_HISTORY,
9563 PCOUNT_STALE,
9564 PCOUNT_VALID,
9565 PCOUNT_ALL,
9566 PCOUNT_COUNTED,
9567 PCOUNT_PFCNT, /* the figure we display to users */
9568 PCOUNT_MAX,
9569};
9570
9571static const char *pcount_strs[] =
9572{
9573 [PCOUNT_ADJ_IN] = "Adj-in",
9574 [PCOUNT_DAMPED] = "Damped",
9575 [PCOUNT_REMOVED] = "Removed",
9576 [PCOUNT_HISTORY] = "History",
9577 [PCOUNT_STALE] = "Stale",
9578 [PCOUNT_VALID] = "Valid",
9579 [PCOUNT_ALL] = "All RIB",
9580 [PCOUNT_COUNTED] = "PfxCt counted",
9581 [PCOUNT_PFCNT] = "Useable",
9582 [PCOUNT_MAX] = NULL,
9583};
9584
Paul Jakma2815e612006-09-14 02:56:07 +00009585struct peer_pcounts
9586{
9587 unsigned int count[PCOUNT_MAX];
9588 const struct peer *peer;
9589 const struct bgp_table *table;
9590};
9591
Paul Jakmaff7924f2006-09-04 01:10:36 +00009592static int
Paul Jakma2815e612006-09-14 02:56:07 +00009593bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009594{
9595 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009596 struct peer_pcounts *pc = THREAD_ARG (t);
9597 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009598
Paul Jakma2815e612006-09-14 02:56:07 +00009599 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009600 {
9601 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009602 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009603
9604 for (ain = rn->adj_in; ain; ain = ain->next)
9605 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009606 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009607
Paul Jakmaff7924f2006-09-04 01:10:36 +00009608 for (ri = rn->info; ri; ri = ri->next)
9609 {
9610 char buf[SU_ADDRSTRLEN];
9611
9612 if (ri->peer != peer)
9613 continue;
9614
Paul Jakma2815e612006-09-14 02:56:07 +00009615 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009616
9617 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009618 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009619 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009620 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009621 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009622 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009623 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009624 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009625 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009626 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009627 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009628 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009629
9630 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9631 {
Paul Jakma2815e612006-09-14 02:56:07 +00009632 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009633 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009634 plog_warn (peer->log,
9635 "%s [pcount] %s/%d is counted but flags 0x%x",
9636 peer->host,
9637 inet_ntop(rn->p.family, &rn->p.u.prefix,
9638 buf, SU_ADDRSTRLEN),
9639 rn->p.prefixlen,
9640 ri->flags);
9641 }
9642 else
9643 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009644 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009645 plog_warn (peer->log,
9646 "%s [pcount] %s/%d not counted but flags 0x%x",
9647 peer->host,
9648 inet_ntop(rn->p.family, &rn->p.u.prefix,
9649 buf, SU_ADDRSTRLEN),
9650 rn->p.prefixlen,
9651 ri->flags);
9652 }
9653 }
9654 }
Paul Jakma2815e612006-09-14 02:56:07 +00009655 return 0;
9656}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009657
Paul Jakma2815e612006-09-14 02:56:07 +00009658static int
9659bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9660{
9661 struct peer_pcounts pcounts = { .peer = peer };
9662 unsigned int i;
9663
9664 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9665 || !peer->bgp->rib[afi][safi])
9666 {
9667 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9668 return CMD_WARNING;
9669 }
9670
9671 memset (&pcounts, 0, sizeof(pcounts));
9672 pcounts.peer = peer;
9673 pcounts.table = peer->bgp->rib[afi][safi];
9674
9675 /* in-place call via thread subsystem so as to record execution time
9676 * stats for the thread-walk (i.e. ensure this can't be blamed on
9677 * on just vty_read()).
9678 */
9679 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9680
Paul Jakmaff7924f2006-09-04 01:10:36 +00009681 vty_out (vty, "Prefix counts for %s, %s%s",
9682 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9683 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9684 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9685 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9686
9687 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009688 vty_out (vty, "%20s: %-10d%s",
9689 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009690
Paul Jakma2815e612006-09-14 02:56:07 +00009691 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009692 {
9693 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9694 peer->host, VTY_NEWLINE);
9695 vty_out (vty, "Please report this bug, with the above command output%s",
9696 VTY_NEWLINE);
9697 }
9698
9699 return CMD_SUCCESS;
9700}
9701
9702DEFUN (show_ip_bgp_neighbor_prefix_counts,
9703 show_ip_bgp_neighbor_prefix_counts_cmd,
9704 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9705 SHOW_STR
9706 IP_STR
9707 BGP_STR
9708 "Detailed information on TCP and BGP neighbor connections\n"
9709 "Neighbor to display information about\n"
9710 "Neighbor to display information about\n"
9711 "Display detailed prefix count information\n")
9712{
9713 struct peer *peer;
9714
9715 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9716 if (! peer)
9717 return CMD_WARNING;
9718
9719 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9720}
9721
9722DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9723 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9724 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9725 SHOW_STR
9726 BGP_STR
9727 "Address family\n"
9728 "Detailed information on TCP and BGP neighbor connections\n"
9729 "Neighbor to display information about\n"
9730 "Neighbor to display information about\n"
9731 "Display detailed prefix count information\n")
9732{
9733 struct peer *peer;
9734
9735 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9736 if (! peer)
9737 return CMD_WARNING;
9738
9739 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9740}
9741
9742DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9743 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9744 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9745 SHOW_STR
9746 IP_STR
9747 BGP_STR
9748 "Address family\n"
9749 "Address Family modifier\n"
9750 "Address Family modifier\n"
9751 "Detailed information on TCP and BGP neighbor connections\n"
9752 "Neighbor to display information about\n"
9753 "Neighbor to display information about\n"
9754 "Display detailed prefix count information\n")
9755{
9756 struct peer *peer;
9757
9758 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9759 if (! peer)
9760 return CMD_WARNING;
9761
9762 if (strncmp (argv[0], "m", 1) == 0)
9763 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9764
9765 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9766}
9767
9768DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9769 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9770 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9771 SHOW_STR
9772 IP_STR
9773 BGP_STR
9774 "Address family\n"
9775 "Address Family modifier\n"
9776 "Address Family modifier\n"
9777 "Detailed information on TCP and BGP neighbor connections\n"
9778 "Neighbor to display information about\n"
9779 "Neighbor to display information about\n"
9780 "Display detailed prefix count information\n")
9781{
9782 struct peer *peer;
9783
9784 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9785 if (! peer)
9786 return CMD_WARNING;
9787
9788 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9789}
9790
9791
paul94f2b392005-06-28 12:44:16 +00009792static void
paul718e3742002-12-13 20:15:29 +00009793show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9794 int in)
9795{
9796 struct bgp_table *table;
9797 struct bgp_adj_in *ain;
9798 struct bgp_adj_out *adj;
9799 unsigned long output_count;
9800 struct bgp_node *rn;
9801 int header1 = 1;
9802 struct bgp *bgp;
9803 int header2 = 1;
9804
paulbb46e942003-10-24 19:02:03 +00009805 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009806
9807 if (! bgp)
9808 return;
9809
9810 table = bgp->rib[afi][safi];
9811
9812 output_count = 0;
9813
9814 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9815 PEER_STATUS_DEFAULT_ORIGINATE))
9816 {
9817 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 +00009818 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9819 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009820
9821 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9822 VTY_NEWLINE, VTY_NEWLINE);
9823 header1 = 0;
9824 }
9825
9826 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9827 if (in)
9828 {
9829 for (ain = rn->adj_in; ain; ain = ain->next)
9830 if (ain->peer == peer)
9831 {
9832 if (header1)
9833 {
9834 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 +00009835 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9836 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009837 header1 = 0;
9838 }
9839 if (header2)
9840 {
9841 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9842 header2 = 0;
9843 }
9844 if (ain->attr)
9845 {
9846 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9847 output_count++;
9848 }
9849 }
9850 }
9851 else
9852 {
9853 for (adj = rn->adj_out; adj; adj = adj->next)
9854 if (adj->peer == peer)
9855 {
9856 if (header1)
9857 {
9858 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 +00009859 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9860 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009861 header1 = 0;
9862 }
9863 if (header2)
9864 {
9865 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9866 header2 = 0;
9867 }
9868 if (adj->attr)
9869 {
9870 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9871 output_count++;
9872 }
9873 }
9874 }
9875
9876 if (output_count != 0)
9877 vty_out (vty, "%sTotal number of prefixes %ld%s",
9878 VTY_NEWLINE, output_count, VTY_NEWLINE);
9879}
9880
paul94f2b392005-06-28 12:44:16 +00009881static int
paulbb46e942003-10-24 19:02:03 +00009882peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9883{
paul718e3742002-12-13 20:15:29 +00009884 if (! peer || ! peer->afc[afi][safi])
9885 {
9886 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9887 return CMD_WARNING;
9888 }
9889
9890 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9891 {
9892 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9893 VTY_NEWLINE);
9894 return CMD_WARNING;
9895 }
9896
9897 show_adj_route (vty, peer, afi, safi, in);
9898
9899 return CMD_SUCCESS;
9900}
9901
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009902DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9903 show_ip_bgp_view_neighbor_advertised_route_cmd,
9904 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9905 SHOW_STR
9906 IP_STR
9907 BGP_STR
9908 "BGP view\n"
9909 "View name\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 the routes advertised to a BGP neighbor\n")
9914{
9915 struct peer *peer;
9916
9917 if (argc == 2)
9918 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9919 else
9920 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9921
9922 if (! peer)
9923 return CMD_WARNING;
9924
9925 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9926}
9927
9928ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009929 show_ip_bgp_neighbor_advertised_route_cmd,
9930 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9931 SHOW_STR
9932 IP_STR
9933 BGP_STR
9934 "Detailed information on TCP and BGP neighbor connections\n"
9935 "Neighbor to display information about\n"
9936 "Neighbor to display information about\n"
9937 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009938
9939DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9940 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9941 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9942 SHOW_STR
9943 IP_STR
9944 BGP_STR
9945 "Address family\n"
9946 "Address Family modifier\n"
9947 "Address Family modifier\n"
9948 "Detailed information on TCP and BGP neighbor connections\n"
9949 "Neighbor to display information about\n"
9950 "Neighbor to display information about\n"
9951 "Display the routes advertised to a BGP neighbor\n")
9952{
paulbb46e942003-10-24 19:02:03 +00009953 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009954
paulbb46e942003-10-24 19:02:03 +00009955 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9956 if (! peer)
9957 return CMD_WARNING;
9958
9959 if (strncmp (argv[0], "m", 1) == 0)
9960 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9961
9962 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009963}
9964
9965#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009966DEFUN (show_bgp_view_neighbor_advertised_route,
9967 show_bgp_view_neighbor_advertised_route_cmd,
9968 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9969 SHOW_STR
9970 BGP_STR
9971 "BGP view\n"
9972 "View name\n"
9973 "Detailed information on TCP and BGP neighbor connections\n"
9974 "Neighbor to display information about\n"
9975 "Neighbor to display information about\n"
9976 "Display the routes advertised to a BGP neighbor\n")
9977{
9978 struct peer *peer;
9979
9980 if (argc == 2)
9981 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9982 else
9983 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9984
9985 if (! peer)
9986 return CMD_WARNING;
9987
9988 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9989}
9990
9991ALIAS (show_bgp_view_neighbor_advertised_route,
9992 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9993 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9994 SHOW_STR
9995 BGP_STR
9996 "BGP view\n"
9997 "View name\n"
9998 "Address family\n"
9999 "Detailed information on TCP and BGP neighbor connections\n"
10000 "Neighbor to display information about\n"
10001 "Neighbor to display information about\n"
10002 "Display the routes advertised to a BGP neighbor\n")
10003
10004DEFUN (show_bgp_view_neighbor_received_routes,
10005 show_bgp_view_neighbor_received_routes_cmd,
10006 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10007 SHOW_STR
10008 BGP_STR
10009 "BGP view\n"
10010 "View name\n"
10011 "Detailed information on TCP and BGP neighbor connections\n"
10012 "Neighbor to display information about\n"
10013 "Neighbor to display information about\n"
10014 "Display the received routes from neighbor\n")
10015{
10016 struct peer *peer;
10017
10018 if (argc == 2)
10019 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10020 else
10021 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10022
10023 if (! peer)
10024 return CMD_WARNING;
10025
10026 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10027}
10028
10029ALIAS (show_bgp_view_neighbor_received_routes,
10030 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10031 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10032 SHOW_STR
10033 BGP_STR
10034 "BGP view\n"
10035 "View name\n"
10036 "Address family\n"
10037 "Detailed information on TCP and BGP neighbor connections\n"
10038 "Neighbor to display information about\n"
10039 "Neighbor to display information about\n"
10040 "Display the received routes from neighbor\n")
10041
10042ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010043 show_bgp_neighbor_advertised_route_cmd,
10044 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10045 SHOW_STR
10046 BGP_STR
10047 "Detailed information on TCP and BGP neighbor connections\n"
10048 "Neighbor to display information about\n"
10049 "Neighbor to display information about\n"
10050 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010051
10052ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010053 show_bgp_ipv6_neighbor_advertised_route_cmd,
10054 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10055 SHOW_STR
10056 BGP_STR
10057 "Address family\n"
10058 "Detailed information on TCP and BGP neighbor connections\n"
10059 "Neighbor to display information about\n"
10060 "Neighbor to display information about\n"
10061 "Display the routes advertised to a BGP neighbor\n")
10062
10063/* old command */
paulbb46e942003-10-24 19:02:03 +000010064ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010065 ipv6_bgp_neighbor_advertised_route_cmd,
10066 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10067 SHOW_STR
10068 IPV6_STR
10069 BGP_STR
10070 "Detailed information on TCP and BGP neighbor connections\n"
10071 "Neighbor to display information about\n"
10072 "Neighbor to display information about\n"
10073 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010074
paul718e3742002-12-13 20:15:29 +000010075/* old command */
10076DEFUN (ipv6_mbgp_neighbor_advertised_route,
10077 ipv6_mbgp_neighbor_advertised_route_cmd,
10078 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10079 SHOW_STR
10080 IPV6_STR
10081 MBGP_STR
10082 "Detailed information on TCP and BGP neighbor connections\n"
10083 "Neighbor to display information about\n"
10084 "Neighbor to display information about\n"
10085 "Display the routes advertised to a BGP neighbor\n")
10086{
paulbb46e942003-10-24 19:02:03 +000010087 struct peer *peer;
10088
10089 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10090 if (! peer)
10091 return CMD_WARNING;
10092
10093 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010094}
10095#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010096
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010097DEFUN (show_ip_bgp_view_neighbor_received_routes,
10098 show_ip_bgp_view_neighbor_received_routes_cmd,
10099 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10100 SHOW_STR
10101 IP_STR
10102 BGP_STR
10103 "BGP view\n"
10104 "View name\n"
10105 "Detailed information on TCP and BGP neighbor connections\n"
10106 "Neighbor to display information about\n"
10107 "Neighbor to display information about\n"
10108 "Display the received routes from neighbor\n")
10109{
10110 struct peer *peer;
10111
10112 if (argc == 2)
10113 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10114 else
10115 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10116
10117 if (! peer)
10118 return CMD_WARNING;
10119
10120 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10121}
10122
10123ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010124 show_ip_bgp_neighbor_received_routes_cmd,
10125 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10126 SHOW_STR
10127 IP_STR
10128 BGP_STR
10129 "Detailed information on TCP and BGP neighbor connections\n"
10130 "Neighbor to display information about\n"
10131 "Neighbor to display information about\n"
10132 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010133
10134DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10135 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10136 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10137 SHOW_STR
10138 IP_STR
10139 BGP_STR
10140 "Address family\n"
10141 "Address Family modifier\n"
10142 "Address Family modifier\n"
10143 "Detailed information on TCP and BGP neighbor connections\n"
10144 "Neighbor to display information about\n"
10145 "Neighbor to display information about\n"
10146 "Display the received routes from neighbor\n")
10147{
paulbb46e942003-10-24 19:02:03 +000010148 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010149
paulbb46e942003-10-24 19:02:03 +000010150 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10151 if (! peer)
10152 return CMD_WARNING;
10153
10154 if (strncmp (argv[0], "m", 1) == 0)
10155 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10156
10157 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010158}
10159
Michael Lambert95cbbd22010-07-23 14:43:04 -040010160DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10161 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010162 "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 -040010163 SHOW_STR
10164 BGP_STR
10165 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010166 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010167 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010168 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010169 "Address family modifier\n"
10170 "Address family modifier\n"
10171 "Detailed information on TCP and BGP neighbor connections\n"
10172 "Neighbor to display information about\n"
10173 "Neighbor to display information about\n"
10174 "Display the advertised routes to neighbor\n"
10175 "Display the received routes from neighbor\n")
10176{
10177 int afi;
10178 int safi;
10179 int in;
10180 struct peer *peer;
10181
David Lamparter94bad672015-03-03 08:52:22 +010010182 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010183
10184 if (! peer)
10185 return CMD_WARNING;
10186
Michael Lambert95cbbd22010-07-23 14:43:04 -040010187 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10188 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10189 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010190
10191 return peer_adj_routes (vty, peer, afi, safi, in);
10192}
10193
paul718e3742002-12-13 20:15:29 +000010194DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10195 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10196 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10197 SHOW_STR
10198 IP_STR
10199 BGP_STR
10200 "Detailed information on TCP and BGP neighbor connections\n"
10201 "Neighbor to display information about\n"
10202 "Neighbor to display information about\n"
10203 "Display information received from a BGP neighbor\n"
10204 "Display the prefixlist filter\n")
10205{
10206 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010207 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010208 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010209 int count, ret;
paul718e3742002-12-13 20:15:29 +000010210
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010211 ret = str2sockunion (argv[0], &su);
10212 if (ret < 0)
10213 {
10214 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10215 return CMD_WARNING;
10216 }
paul718e3742002-12-13 20:15:29 +000010217
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010218 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010219 if (! peer)
10220 return CMD_WARNING;
10221
10222 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10223 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10224 if (count)
10225 {
10226 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10227 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10228 }
10229
10230 return CMD_SUCCESS;
10231}
10232
10233DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10234 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10235 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10236 SHOW_STR
10237 IP_STR
10238 BGP_STR
10239 "Address family\n"
10240 "Address Family modifier\n"
10241 "Address Family modifier\n"
10242 "Detailed information on TCP and BGP neighbor connections\n"
10243 "Neighbor to display information about\n"
10244 "Neighbor to display information about\n"
10245 "Display information received from a BGP neighbor\n"
10246 "Display the prefixlist filter\n")
10247{
10248 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010249 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010250 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010251 int count, ret;
paul718e3742002-12-13 20:15:29 +000010252
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010253 ret = str2sockunion (argv[1], &su);
10254 if (ret < 0)
10255 {
10256 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10257 return CMD_WARNING;
10258 }
paul718e3742002-12-13 20:15:29 +000010259
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010260 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010261 if (! peer)
10262 return CMD_WARNING;
10263
10264 if (strncmp (argv[0], "m", 1) == 0)
10265 {
10266 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10267 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10268 if (count)
10269 {
10270 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10271 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10272 }
10273 }
10274 else
10275 {
10276 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10277 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10278 if (count)
10279 {
10280 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10281 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10282 }
10283 }
10284
10285 return CMD_SUCCESS;
10286}
10287
10288
10289#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010290ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010291 show_bgp_neighbor_received_routes_cmd,
10292 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10293 SHOW_STR
10294 BGP_STR
10295 "Detailed information on TCP and BGP neighbor connections\n"
10296 "Neighbor to display information about\n"
10297 "Neighbor to display information about\n"
10298 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010299
paulbb46e942003-10-24 19:02:03 +000010300ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010301 show_bgp_ipv6_neighbor_received_routes_cmd,
10302 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10303 SHOW_STR
10304 BGP_STR
10305 "Address family\n"
10306 "Detailed information on TCP and BGP neighbor connections\n"
10307 "Neighbor to display information about\n"
10308 "Neighbor to display information about\n"
10309 "Display the received routes from neighbor\n")
10310
10311DEFUN (show_bgp_neighbor_received_prefix_filter,
10312 show_bgp_neighbor_received_prefix_filter_cmd,
10313 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10314 SHOW_STR
10315 BGP_STR
10316 "Detailed information on TCP and BGP neighbor connections\n"
10317 "Neighbor to display information about\n"
10318 "Neighbor to display information about\n"
10319 "Display information received from a BGP neighbor\n"
10320 "Display the prefixlist filter\n")
10321{
10322 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010323 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010324 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010325 int count, ret;
paul718e3742002-12-13 20:15:29 +000010326
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010327 ret = str2sockunion (argv[0], &su);
10328 if (ret < 0)
10329 {
10330 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10331 return CMD_WARNING;
10332 }
paul718e3742002-12-13 20:15:29 +000010333
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010334 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010335 if (! peer)
10336 return CMD_WARNING;
10337
10338 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10339 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10340 if (count)
10341 {
10342 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10343 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10344 }
10345
10346 return CMD_SUCCESS;
10347}
10348
10349ALIAS (show_bgp_neighbor_received_prefix_filter,
10350 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10351 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10352 SHOW_STR
10353 BGP_STR
10354 "Address family\n"
10355 "Detailed information on TCP and BGP neighbor connections\n"
10356 "Neighbor to display information about\n"
10357 "Neighbor to display information about\n"
10358 "Display information received from a BGP neighbor\n"
10359 "Display the prefixlist filter\n")
10360
10361/* old command */
paulbb46e942003-10-24 19:02:03 +000010362ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010363 ipv6_bgp_neighbor_received_routes_cmd,
10364 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10365 SHOW_STR
10366 IPV6_STR
10367 BGP_STR
10368 "Detailed information on TCP and BGP neighbor connections\n"
10369 "Neighbor to display information about\n"
10370 "Neighbor to display information about\n"
10371 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010372
10373/* old command */
10374DEFUN (ipv6_mbgp_neighbor_received_routes,
10375 ipv6_mbgp_neighbor_received_routes_cmd,
10376 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10377 SHOW_STR
10378 IPV6_STR
10379 MBGP_STR
10380 "Detailed information on TCP and BGP neighbor connections\n"
10381 "Neighbor to display information about\n"
10382 "Neighbor to display information about\n"
10383 "Display the received routes from neighbor\n")
10384{
paulbb46e942003-10-24 19:02:03 +000010385 struct peer *peer;
10386
10387 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10388 if (! peer)
10389 return CMD_WARNING;
10390
10391 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010392}
paulbb46e942003-10-24 19:02:03 +000010393
10394DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10395 show_bgp_view_neighbor_received_prefix_filter_cmd,
10396 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10397 SHOW_STR
10398 BGP_STR
10399 "BGP view\n"
10400 "View name\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;
paulbb46e942003-10-24 19:02:03 +000010409 struct peer *peer;
10410 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010411 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010412
10413 /* BGP structure lookup. */
10414 bgp = bgp_lookup_by_name (argv[0]);
10415 if (bgp == NULL)
10416 {
10417 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10418 return CMD_WARNING;
10419 }
10420
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010421 ret = str2sockunion (argv[1], &su);
10422 if (ret < 0)
10423 {
10424 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10425 return CMD_WARNING;
10426 }
paulbb46e942003-10-24 19:02:03 +000010427
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010428 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010429 if (! peer)
10430 return CMD_WARNING;
10431
10432 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10433 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10434 if (count)
10435 {
10436 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10437 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10438 }
10439
10440 return CMD_SUCCESS;
10441}
10442
10443ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10444 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10445 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10446 SHOW_STR
10447 BGP_STR
10448 "BGP view\n"
10449 "View name\n"
10450 "Address family\n"
10451 "Detailed information on TCP and BGP neighbor connections\n"
10452 "Neighbor to display information about\n"
10453 "Neighbor to display information about\n"
10454 "Display information received from a BGP neighbor\n"
10455 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010456#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010457
paul94f2b392005-06-28 12:44:16 +000010458static int
paulbb46e942003-10-24 19:02:03 +000010459bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010460 safi_t safi, enum bgp_show_type type)
10461{
paul718e3742002-12-13 20:15:29 +000010462 if (! peer || ! peer->afc[afi][safi])
10463 {
10464 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010465 return CMD_WARNING;
10466 }
10467
ajs5a646652004-11-05 01:25:55 +000010468 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010469}
10470
10471DEFUN (show_ip_bgp_neighbor_routes,
10472 show_ip_bgp_neighbor_routes_cmd,
10473 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10474 SHOW_STR
10475 IP_STR
10476 BGP_STR
10477 "Detailed information on TCP and BGP neighbor connections\n"
10478 "Neighbor to display information about\n"
10479 "Neighbor to display information about\n"
10480 "Display routes learned from neighbor\n")
10481{
paulbb46e942003-10-24 19:02:03 +000010482 struct peer *peer;
10483
10484 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10485 if (! peer)
10486 return CMD_WARNING;
10487
10488 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010489 bgp_show_type_neighbor);
10490}
10491
10492DEFUN (show_ip_bgp_neighbor_flap,
10493 show_ip_bgp_neighbor_flap_cmd,
10494 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10495 SHOW_STR
10496 IP_STR
10497 BGP_STR
10498 "Detailed information on TCP and BGP neighbor connections\n"
10499 "Neighbor to display information about\n"
10500 "Neighbor to display information about\n"
10501 "Display flap statistics of the routes learned from neighbor\n")
10502{
paulbb46e942003-10-24 19:02:03 +000010503 struct peer *peer;
10504
10505 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10506 if (! peer)
10507 return CMD_WARNING;
10508
10509 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010510 bgp_show_type_flap_neighbor);
10511}
10512
10513DEFUN (show_ip_bgp_neighbor_damp,
10514 show_ip_bgp_neighbor_damp_cmd,
10515 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10516 SHOW_STR
10517 IP_STR
10518 BGP_STR
10519 "Detailed information on TCP and BGP neighbor connections\n"
10520 "Neighbor to display information about\n"
10521 "Neighbor to display information about\n"
10522 "Display the dampened routes received from neighbor\n")
10523{
paulbb46e942003-10-24 19:02:03 +000010524 struct peer *peer;
10525
10526 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10527 if (! peer)
10528 return CMD_WARNING;
10529
10530 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010531 bgp_show_type_damp_neighbor);
10532}
10533
10534DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10535 show_ip_bgp_ipv4_neighbor_routes_cmd,
10536 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10537 SHOW_STR
10538 IP_STR
10539 BGP_STR
10540 "Address family\n"
10541 "Address Family modifier\n"
10542 "Address Family modifier\n"
10543 "Detailed information on TCP and BGP neighbor connections\n"
10544 "Neighbor to display information about\n"
10545 "Neighbor to display information about\n"
10546 "Display routes learned from neighbor\n")
10547{
paulbb46e942003-10-24 19:02:03 +000010548 struct peer *peer;
10549
10550 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10551 if (! peer)
10552 return CMD_WARNING;
10553
paul718e3742002-12-13 20:15:29 +000010554 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010555 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010556 bgp_show_type_neighbor);
10557
paulbb46e942003-10-24 19:02:03 +000010558 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010559 bgp_show_type_neighbor);
10560}
paulbb46e942003-10-24 19:02:03 +000010561
paulfee0f4c2004-09-13 05:12:46 +000010562DEFUN (show_ip_bgp_view_rsclient,
10563 show_ip_bgp_view_rsclient_cmd,
10564 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10565 SHOW_STR
10566 IP_STR
10567 BGP_STR
10568 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010569 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010570 "Information about Route Server Client\n"
10571 NEIGHBOR_ADDR_STR)
10572{
10573 struct bgp_table *table;
10574 struct peer *peer;
10575
10576 if (argc == 2)
10577 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10578 else
10579 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10580
10581 if (! peer)
10582 return CMD_WARNING;
10583
10584 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10585 {
10586 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10587 VTY_NEWLINE);
10588 return CMD_WARNING;
10589 }
10590
10591 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10592 PEER_FLAG_RSERVER_CLIENT))
10593 {
10594 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10595 VTY_NEWLINE);
10596 return CMD_WARNING;
10597 }
10598
10599 table = peer->rib[AFI_IP][SAFI_UNICAST];
10600
ajs5a646652004-11-05 01:25:55 +000010601 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010602}
10603
10604ALIAS (show_ip_bgp_view_rsclient,
10605 show_ip_bgp_rsclient_cmd,
10606 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10607 SHOW_STR
10608 IP_STR
10609 BGP_STR
10610 "Information about Route Server Client\n"
10611 NEIGHBOR_ADDR_STR)
10612
Michael Lambert95cbbd22010-07-23 14:43:04 -040010613DEFUN (show_bgp_view_ipv4_safi_rsclient,
10614 show_bgp_view_ipv4_safi_rsclient_cmd,
10615 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10616 SHOW_STR
10617 BGP_STR
10618 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010619 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010620 "Address family\n"
10621 "Address Family modifier\n"
10622 "Address Family modifier\n"
10623 "Information about Route Server Client\n"
10624 NEIGHBOR_ADDR_STR)
10625{
10626 struct bgp_table *table;
10627 struct peer *peer;
10628 safi_t safi;
10629
10630 if (argc == 3) {
10631 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10632 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10633 } else {
10634 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10635 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10636 }
10637
10638 if (! peer)
10639 return CMD_WARNING;
10640
10641 if (! peer->afc[AFI_IP][safi])
10642 {
10643 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10644 VTY_NEWLINE);
10645 return CMD_WARNING;
10646 }
10647
10648 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10649 PEER_FLAG_RSERVER_CLIENT))
10650 {
10651 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10652 VTY_NEWLINE);
10653 return CMD_WARNING;
10654 }
10655
10656 table = peer->rib[AFI_IP][safi];
10657
10658 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10659}
10660
10661ALIAS (show_bgp_view_ipv4_safi_rsclient,
10662 show_bgp_ipv4_safi_rsclient_cmd,
10663 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10664 SHOW_STR
10665 BGP_STR
10666 "Address family\n"
10667 "Address Family modifier\n"
10668 "Address Family modifier\n"
10669 "Information about Route Server Client\n"
10670 NEIGHBOR_ADDR_STR)
10671
paulfee0f4c2004-09-13 05:12:46 +000010672DEFUN (show_ip_bgp_view_rsclient_route,
10673 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010674 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010675 SHOW_STR
10676 IP_STR
10677 BGP_STR
10678 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010679 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010680 "Information about Route Server Client\n"
10681 NEIGHBOR_ADDR_STR
10682 "Network in the BGP routing table to display\n")
10683{
10684 struct bgp *bgp;
10685 struct peer *peer;
10686
10687 /* BGP structure lookup. */
10688 if (argc == 3)
10689 {
10690 bgp = bgp_lookup_by_name (argv[0]);
10691 if (bgp == NULL)
10692 {
10693 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10694 return CMD_WARNING;
10695 }
10696 }
10697 else
10698 {
10699 bgp = bgp_get_default ();
10700 if (bgp == NULL)
10701 {
10702 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10703 return CMD_WARNING;
10704 }
10705 }
10706
10707 if (argc == 3)
10708 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10709 else
10710 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10711
10712 if (! peer)
10713 return CMD_WARNING;
10714
10715 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10716 {
10717 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10718 VTY_NEWLINE);
10719 return CMD_WARNING;
10720}
10721
10722 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10723 PEER_FLAG_RSERVER_CLIENT))
10724 {
10725 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10726 VTY_NEWLINE);
10727 return CMD_WARNING;
10728 }
10729
10730 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10731 (argc == 3) ? argv[2] : argv[1],
10732 AFI_IP, SAFI_UNICAST, NULL, 0);
10733}
10734
10735ALIAS (show_ip_bgp_view_rsclient_route,
10736 show_ip_bgp_rsclient_route_cmd,
10737 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10738 SHOW_STR
10739 IP_STR
10740 BGP_STR
10741 "Information about Route Server Client\n"
10742 NEIGHBOR_ADDR_STR
10743 "Network in the BGP routing table to display\n")
10744
Michael Lambert95cbbd22010-07-23 14:43:04 -040010745DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10746 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10747 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10748 SHOW_STR
10749 BGP_STR
10750 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010751 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010752 "Address family\n"
10753 "Address Family modifier\n"
10754 "Address Family modifier\n"
10755 "Information about Route Server Client\n"
10756 NEIGHBOR_ADDR_STR
10757 "Network in the BGP routing table to display\n")
10758{
10759 struct bgp *bgp;
10760 struct peer *peer;
10761 safi_t safi;
10762
10763 /* BGP structure lookup. */
10764 if (argc == 4)
10765 {
10766 bgp = bgp_lookup_by_name (argv[0]);
10767 if (bgp == NULL)
10768 {
10769 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10770 return CMD_WARNING;
10771 }
10772 }
10773 else
10774 {
10775 bgp = bgp_get_default ();
10776 if (bgp == NULL)
10777 {
10778 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10779 return CMD_WARNING;
10780 }
10781 }
10782
10783 if (argc == 4) {
10784 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10785 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10786 } else {
10787 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10788 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10789 }
10790
10791 if (! peer)
10792 return CMD_WARNING;
10793
10794 if (! peer->afc[AFI_IP][safi])
10795 {
10796 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10797 VTY_NEWLINE);
10798 return CMD_WARNING;
10799}
10800
10801 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10802 PEER_FLAG_RSERVER_CLIENT))
10803 {
10804 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10805 VTY_NEWLINE);
10806 return CMD_WARNING;
10807 }
10808
10809 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10810 (argc == 4) ? argv[3] : argv[2],
10811 AFI_IP, safi, NULL, 0);
10812}
10813
10814ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10815 show_bgp_ipv4_safi_rsclient_route_cmd,
10816 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10817 SHOW_STR
10818 BGP_STR
10819 "Address family\n"
10820 "Address Family modifier\n"
10821 "Address Family modifier\n"
10822 "Information about Route Server Client\n"
10823 NEIGHBOR_ADDR_STR
10824 "Network in the BGP routing table to display\n")
10825
paulfee0f4c2004-09-13 05:12:46 +000010826DEFUN (show_ip_bgp_view_rsclient_prefix,
10827 show_ip_bgp_view_rsclient_prefix_cmd,
10828 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10829 SHOW_STR
10830 IP_STR
10831 BGP_STR
10832 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010833 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010834 "Information about Route Server Client\n"
10835 NEIGHBOR_ADDR_STR
10836 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10837{
10838 struct bgp *bgp;
10839 struct peer *peer;
10840
10841 /* BGP structure lookup. */
10842 if (argc == 3)
10843 {
10844 bgp = bgp_lookup_by_name (argv[0]);
10845 if (bgp == NULL)
10846 {
10847 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10848 return CMD_WARNING;
10849 }
10850 }
10851 else
10852 {
10853 bgp = bgp_get_default ();
10854 if (bgp == NULL)
10855 {
10856 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10857 return CMD_WARNING;
10858 }
10859 }
10860
10861 if (argc == 3)
10862 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10863 else
10864 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10865
10866 if (! peer)
10867 return CMD_WARNING;
10868
10869 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10870 {
10871 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10872 VTY_NEWLINE);
10873 return CMD_WARNING;
10874}
10875
10876 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10877 PEER_FLAG_RSERVER_CLIENT))
10878{
10879 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10880 VTY_NEWLINE);
10881 return CMD_WARNING;
10882 }
10883
10884 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10885 (argc == 3) ? argv[2] : argv[1],
10886 AFI_IP, SAFI_UNICAST, NULL, 1);
10887}
10888
10889ALIAS (show_ip_bgp_view_rsclient_prefix,
10890 show_ip_bgp_rsclient_prefix_cmd,
10891 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10892 SHOW_STR
10893 IP_STR
10894 BGP_STR
10895 "Information about Route Server Client\n"
10896 NEIGHBOR_ADDR_STR
10897 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10898
Michael Lambert95cbbd22010-07-23 14:43:04 -040010899DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10900 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10901 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10902 SHOW_STR
10903 BGP_STR
10904 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010905 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010906 "Address family\n"
10907 "Address Family modifier\n"
10908 "Address Family modifier\n"
10909 "Information about Route Server Client\n"
10910 NEIGHBOR_ADDR_STR
10911 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10912{
10913 struct bgp *bgp;
10914 struct peer *peer;
10915 safi_t safi;
10916
10917 /* BGP structure lookup. */
10918 if (argc == 4)
10919 {
10920 bgp = bgp_lookup_by_name (argv[0]);
10921 if (bgp == NULL)
10922 {
10923 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10924 return CMD_WARNING;
10925 }
10926 }
10927 else
10928 {
10929 bgp = bgp_get_default ();
10930 if (bgp == NULL)
10931 {
10932 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10933 return CMD_WARNING;
10934 }
10935 }
10936
10937 if (argc == 4) {
10938 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10939 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10940 } else {
10941 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10942 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10943 }
10944
10945 if (! peer)
10946 return CMD_WARNING;
10947
10948 if (! peer->afc[AFI_IP][safi])
10949 {
10950 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10951 VTY_NEWLINE);
10952 return CMD_WARNING;
10953}
10954
10955 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10956 PEER_FLAG_RSERVER_CLIENT))
10957{
10958 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10959 VTY_NEWLINE);
10960 return CMD_WARNING;
10961 }
10962
10963 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10964 (argc == 4) ? argv[3] : argv[2],
10965 AFI_IP, safi, NULL, 1);
10966}
10967
10968ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
10969 show_bgp_ipv4_safi_rsclient_prefix_cmd,
10970 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10971 SHOW_STR
10972 BGP_STR
10973 "Address family\n"
10974 "Address Family modifier\n"
10975 "Address Family modifier\n"
10976 "Information about Route Server Client\n"
10977 NEIGHBOR_ADDR_STR
10978 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000010979
paul718e3742002-12-13 20:15:29 +000010980#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010981DEFUN (show_bgp_view_neighbor_routes,
10982 show_bgp_view_neighbor_routes_cmd,
10983 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10984 SHOW_STR
10985 BGP_STR
10986 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010987 "View name\n"
paulbb46e942003-10-24 19:02:03 +000010988 "Detailed information on TCP and BGP neighbor connections\n"
10989 "Neighbor to display information about\n"
10990 "Neighbor to display information about\n"
10991 "Display routes learned from neighbor\n")
10992{
10993 struct peer *peer;
10994
10995 if (argc == 2)
10996 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10997 else
10998 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10999
11000 if (! peer)
11001 return CMD_WARNING;
11002
11003 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11004 bgp_show_type_neighbor);
11005}
11006
11007ALIAS (show_bgp_view_neighbor_routes,
11008 show_bgp_view_ipv6_neighbor_routes_cmd,
11009 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11010 SHOW_STR
11011 BGP_STR
11012 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011013 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011014 "Address family\n"
11015 "Detailed information on TCP and BGP neighbor connections\n"
11016 "Neighbor to display information about\n"
11017 "Neighbor to display information about\n"
11018 "Display routes learned from neighbor\n")
11019
11020DEFUN (show_bgp_view_neighbor_damp,
11021 show_bgp_view_neighbor_damp_cmd,
11022 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11023 SHOW_STR
11024 BGP_STR
11025 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011026 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011027 "Detailed information on TCP and BGP neighbor connections\n"
11028 "Neighbor to display information about\n"
11029 "Neighbor to display information about\n"
11030 "Display the dampened routes received from neighbor\n")
11031{
11032 struct peer *peer;
11033
11034 if (argc == 2)
11035 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11036 else
11037 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11038
11039 if (! peer)
11040 return CMD_WARNING;
11041
11042 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11043 bgp_show_type_damp_neighbor);
11044}
11045
11046ALIAS (show_bgp_view_neighbor_damp,
11047 show_bgp_view_ipv6_neighbor_damp_cmd,
11048 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11049 SHOW_STR
11050 BGP_STR
11051 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011052 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011053 "Address family\n"
11054 "Detailed information on TCP and BGP neighbor connections\n"
11055 "Neighbor to display information about\n"
11056 "Neighbor to display information about\n"
11057 "Display the dampened routes received from neighbor\n")
11058
11059DEFUN (show_bgp_view_neighbor_flap,
11060 show_bgp_view_neighbor_flap_cmd,
11061 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11062 SHOW_STR
11063 BGP_STR
11064 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011065 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011066 "Detailed information on TCP and BGP neighbor connections\n"
11067 "Neighbor to display information about\n"
11068 "Neighbor to display information about\n"
11069 "Display flap statistics of the routes learned from neighbor\n")
11070{
11071 struct peer *peer;
11072
11073 if (argc == 2)
11074 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11075 else
11076 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11077
11078 if (! peer)
11079 return CMD_WARNING;
11080
11081 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11082 bgp_show_type_flap_neighbor);
11083}
11084
11085ALIAS (show_bgp_view_neighbor_flap,
11086 show_bgp_view_ipv6_neighbor_flap_cmd,
11087 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11088 SHOW_STR
11089 BGP_STR
11090 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011091 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011092 "Address family\n"
11093 "Detailed information on TCP and BGP neighbor connections\n"
11094 "Neighbor to display information about\n"
11095 "Neighbor to display information about\n"
11096 "Display flap statistics of the routes learned from neighbor\n")
11097
11098ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011099 show_bgp_neighbor_routes_cmd,
11100 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11101 SHOW_STR
11102 BGP_STR
11103 "Detailed information on TCP and BGP neighbor connections\n"
11104 "Neighbor to display information about\n"
11105 "Neighbor to display information about\n"
11106 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011107
paulbb46e942003-10-24 19:02:03 +000011108
11109ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011110 show_bgp_ipv6_neighbor_routes_cmd,
11111 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11112 SHOW_STR
11113 BGP_STR
11114 "Address family\n"
11115 "Detailed information on TCP and BGP neighbor connections\n"
11116 "Neighbor to display information about\n"
11117 "Neighbor to display information about\n"
11118 "Display routes learned from neighbor\n")
11119
11120/* old command */
paulbb46e942003-10-24 19:02:03 +000011121ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011122 ipv6_bgp_neighbor_routes_cmd,
11123 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11124 SHOW_STR
11125 IPV6_STR
11126 BGP_STR
11127 "Detailed information on TCP and BGP neighbor connections\n"
11128 "Neighbor to display information about\n"
11129 "Neighbor to display information about\n"
11130 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011131
11132/* old command */
11133DEFUN (ipv6_mbgp_neighbor_routes,
11134 ipv6_mbgp_neighbor_routes_cmd,
11135 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11136 SHOW_STR
11137 IPV6_STR
11138 MBGP_STR
11139 "Detailed information on TCP and BGP neighbor connections\n"
11140 "Neighbor to display information about\n"
11141 "Neighbor to display information about\n"
11142 "Display routes learned from neighbor\n")
11143{
paulbb46e942003-10-24 19:02:03 +000011144 struct peer *peer;
11145
11146 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11147 if (! peer)
11148 return CMD_WARNING;
11149
11150 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011151 bgp_show_type_neighbor);
11152}
paulbb46e942003-10-24 19:02:03 +000011153
11154ALIAS (show_bgp_view_neighbor_flap,
11155 show_bgp_neighbor_flap_cmd,
11156 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11157 SHOW_STR
11158 BGP_STR
11159 "Detailed information on TCP and BGP neighbor connections\n"
11160 "Neighbor to display information about\n"
11161 "Neighbor to display information about\n"
11162 "Display flap statistics of the routes learned from neighbor\n")
11163
11164ALIAS (show_bgp_view_neighbor_flap,
11165 show_bgp_ipv6_neighbor_flap_cmd,
11166 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11167 SHOW_STR
11168 BGP_STR
11169 "Address family\n"
11170 "Detailed information on TCP and BGP neighbor connections\n"
11171 "Neighbor to display information about\n"
11172 "Neighbor to display information about\n"
11173 "Display flap statistics of the routes learned from neighbor\n")
11174
11175ALIAS (show_bgp_view_neighbor_damp,
11176 show_bgp_neighbor_damp_cmd,
11177 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11178 SHOW_STR
11179 BGP_STR
11180 "Detailed information on TCP and BGP neighbor connections\n"
11181 "Neighbor to display information about\n"
11182 "Neighbor to display information about\n"
11183 "Display the dampened routes received from neighbor\n")
11184
11185ALIAS (show_bgp_view_neighbor_damp,
11186 show_bgp_ipv6_neighbor_damp_cmd,
11187 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11188 SHOW_STR
11189 BGP_STR
11190 "Address family\n"
11191 "Detailed information on TCP and BGP neighbor connections\n"
11192 "Neighbor to display information about\n"
11193 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011194 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011195
11196DEFUN (show_bgp_view_rsclient,
11197 show_bgp_view_rsclient_cmd,
11198 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11199 SHOW_STR
11200 BGP_STR
11201 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011202 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011203 "Information about Route Server Client\n"
11204 NEIGHBOR_ADDR_STR)
11205{
11206 struct bgp_table *table;
11207 struct peer *peer;
11208
11209 if (argc == 2)
11210 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11211 else
11212 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11213
11214 if (! peer)
11215 return CMD_WARNING;
11216
11217 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11218 {
11219 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11220 VTY_NEWLINE);
11221 return CMD_WARNING;
11222 }
11223
11224 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11225 PEER_FLAG_RSERVER_CLIENT))
11226 {
11227 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11228 VTY_NEWLINE);
11229 return CMD_WARNING;
11230 }
11231
11232 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11233
ajs5a646652004-11-05 01:25:55 +000011234 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011235}
11236
11237ALIAS (show_bgp_view_rsclient,
11238 show_bgp_rsclient_cmd,
11239 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11240 SHOW_STR
11241 BGP_STR
11242 "Information about Route Server Client\n"
11243 NEIGHBOR_ADDR_STR)
11244
Michael Lambert95cbbd22010-07-23 14:43:04 -040011245DEFUN (show_bgp_view_ipv6_safi_rsclient,
11246 show_bgp_view_ipv6_safi_rsclient_cmd,
11247 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11248 SHOW_STR
11249 BGP_STR
11250 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011251 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011252 "Address family\n"
11253 "Address Family modifier\n"
11254 "Address Family modifier\n"
11255 "Information about Route Server Client\n"
11256 NEIGHBOR_ADDR_STR)
11257{
11258 struct bgp_table *table;
11259 struct peer *peer;
11260 safi_t safi;
11261
11262 if (argc == 3) {
11263 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11264 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11265 } else {
11266 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11267 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11268 }
11269
11270 if (! peer)
11271 return CMD_WARNING;
11272
11273 if (! peer->afc[AFI_IP6][safi])
11274 {
11275 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11276 VTY_NEWLINE);
11277 return CMD_WARNING;
11278 }
11279
11280 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11281 PEER_FLAG_RSERVER_CLIENT))
11282 {
11283 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11284 VTY_NEWLINE);
11285 return CMD_WARNING;
11286 }
11287
11288 table = peer->rib[AFI_IP6][safi];
11289
11290 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11291}
11292
11293ALIAS (show_bgp_view_ipv6_safi_rsclient,
11294 show_bgp_ipv6_safi_rsclient_cmd,
11295 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11296 SHOW_STR
11297 BGP_STR
11298 "Address family\n"
11299 "Address Family modifier\n"
11300 "Address Family modifier\n"
11301 "Information about Route Server Client\n"
11302 NEIGHBOR_ADDR_STR)
11303
paulfee0f4c2004-09-13 05:12:46 +000011304DEFUN (show_bgp_view_rsclient_route,
11305 show_bgp_view_rsclient_route_cmd,
11306 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11307 SHOW_STR
11308 BGP_STR
11309 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011310 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011311 "Information about Route Server Client\n"
11312 NEIGHBOR_ADDR_STR
11313 "Network in the BGP routing table to display\n")
11314{
11315 struct bgp *bgp;
11316 struct peer *peer;
11317
11318 /* BGP structure lookup. */
11319 if (argc == 3)
11320 {
11321 bgp = bgp_lookup_by_name (argv[0]);
11322 if (bgp == NULL)
11323 {
11324 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11325 return CMD_WARNING;
11326 }
11327 }
11328 else
11329 {
11330 bgp = bgp_get_default ();
11331 if (bgp == NULL)
11332 {
11333 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11334 return CMD_WARNING;
11335 }
11336 }
11337
11338 if (argc == 3)
11339 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11340 else
11341 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11342
11343 if (! peer)
11344 return CMD_WARNING;
11345
11346 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11347 {
11348 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11349 VTY_NEWLINE);
11350 return CMD_WARNING;
11351 }
11352
11353 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11354 PEER_FLAG_RSERVER_CLIENT))
11355 {
11356 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11357 VTY_NEWLINE);
11358 return CMD_WARNING;
11359 }
11360
11361 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11362 (argc == 3) ? argv[2] : argv[1],
11363 AFI_IP6, SAFI_UNICAST, NULL, 0);
11364}
11365
11366ALIAS (show_bgp_view_rsclient_route,
11367 show_bgp_rsclient_route_cmd,
11368 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11369 SHOW_STR
11370 BGP_STR
11371 "Information about Route Server Client\n"
11372 NEIGHBOR_ADDR_STR
11373 "Network in the BGP routing table to display\n")
11374
Michael Lambert95cbbd22010-07-23 14:43:04 -040011375DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11376 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11377 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11378 SHOW_STR
11379 BGP_STR
11380 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011381 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011382 "Address family\n"
11383 "Address Family modifier\n"
11384 "Address Family modifier\n"
11385 "Information about Route Server Client\n"
11386 NEIGHBOR_ADDR_STR
11387 "Network in the BGP routing table to display\n")
11388{
11389 struct bgp *bgp;
11390 struct peer *peer;
11391 safi_t safi;
11392
11393 /* BGP structure lookup. */
11394 if (argc == 4)
11395 {
11396 bgp = bgp_lookup_by_name (argv[0]);
11397 if (bgp == NULL)
11398 {
11399 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11400 return CMD_WARNING;
11401 }
11402 }
11403 else
11404 {
11405 bgp = bgp_get_default ();
11406 if (bgp == NULL)
11407 {
11408 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11409 return CMD_WARNING;
11410 }
11411 }
11412
11413 if (argc == 4) {
11414 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11415 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11416 } else {
11417 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11418 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11419 }
11420
11421 if (! peer)
11422 return CMD_WARNING;
11423
11424 if (! peer->afc[AFI_IP6][safi])
11425 {
11426 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11427 VTY_NEWLINE);
11428 return CMD_WARNING;
11429}
11430
11431 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11432 PEER_FLAG_RSERVER_CLIENT))
11433 {
11434 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11435 VTY_NEWLINE);
11436 return CMD_WARNING;
11437 }
11438
11439 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11440 (argc == 4) ? argv[3] : argv[2],
11441 AFI_IP6, safi, NULL, 0);
11442}
11443
11444ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11445 show_bgp_ipv6_safi_rsclient_route_cmd,
11446 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11447 SHOW_STR
11448 BGP_STR
11449 "Address family\n"
11450 "Address Family modifier\n"
11451 "Address Family modifier\n"
11452 "Information about Route Server Client\n"
11453 NEIGHBOR_ADDR_STR
11454 "Network in the BGP routing table to display\n")
11455
paulfee0f4c2004-09-13 05:12:46 +000011456DEFUN (show_bgp_view_rsclient_prefix,
11457 show_bgp_view_rsclient_prefix_cmd,
11458 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11459 SHOW_STR
11460 BGP_STR
11461 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011462 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011463 "Information about Route Server Client\n"
11464 NEIGHBOR_ADDR_STR
11465 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11466{
11467 struct bgp *bgp;
11468 struct peer *peer;
11469
11470 /* BGP structure lookup. */
11471 if (argc == 3)
11472 {
11473 bgp = bgp_lookup_by_name (argv[0]);
11474 if (bgp == NULL)
11475 {
11476 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11477 return CMD_WARNING;
11478 }
11479 }
11480 else
11481 {
11482 bgp = bgp_get_default ();
11483 if (bgp == NULL)
11484 {
11485 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11486 return CMD_WARNING;
11487 }
11488 }
11489
11490 if (argc == 3)
11491 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11492 else
11493 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11494
11495 if (! peer)
11496 return CMD_WARNING;
11497
11498 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11499 {
11500 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11501 VTY_NEWLINE);
11502 return CMD_WARNING;
11503 }
11504
11505 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11506 PEER_FLAG_RSERVER_CLIENT))
11507 {
11508 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11509 VTY_NEWLINE);
11510 return CMD_WARNING;
11511 }
11512
11513 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11514 (argc == 3) ? argv[2] : argv[1],
11515 AFI_IP6, SAFI_UNICAST, NULL, 1);
11516}
11517
11518ALIAS (show_bgp_view_rsclient_prefix,
11519 show_bgp_rsclient_prefix_cmd,
11520 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11521 SHOW_STR
11522 BGP_STR
11523 "Information about Route Server Client\n"
11524 NEIGHBOR_ADDR_STR
11525 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11526
Michael Lambert95cbbd22010-07-23 14:43:04 -040011527DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11528 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11529 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11530 SHOW_STR
11531 BGP_STR
11532 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011533 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011534 "Address family\n"
11535 "Address Family modifier\n"
11536 "Address Family modifier\n"
11537 "Information about Route Server Client\n"
11538 NEIGHBOR_ADDR_STR
11539 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11540{
11541 struct bgp *bgp;
11542 struct peer *peer;
11543 safi_t safi;
11544
11545 /* BGP structure lookup. */
11546 if (argc == 4)
11547 {
11548 bgp = bgp_lookup_by_name (argv[0]);
11549 if (bgp == NULL)
11550 {
11551 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11552 return CMD_WARNING;
11553 }
11554 }
11555 else
11556 {
11557 bgp = bgp_get_default ();
11558 if (bgp == NULL)
11559 {
11560 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11561 return CMD_WARNING;
11562 }
11563 }
11564
11565 if (argc == 4) {
11566 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11567 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11568 } else {
11569 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11570 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11571 }
11572
11573 if (! peer)
11574 return CMD_WARNING;
11575
11576 if (! peer->afc[AFI_IP6][safi])
11577 {
11578 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11579 VTY_NEWLINE);
11580 return CMD_WARNING;
11581}
11582
11583 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11584 PEER_FLAG_RSERVER_CLIENT))
11585{
11586 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11587 VTY_NEWLINE);
11588 return CMD_WARNING;
11589 }
11590
11591 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11592 (argc == 4) ? argv[3] : argv[2],
11593 AFI_IP6, safi, NULL, 1);
11594}
11595
11596ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11597 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11598 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11599 SHOW_STR
11600 BGP_STR
11601 "Address family\n"
11602 "Address Family modifier\n"
11603 "Address Family modifier\n"
11604 "Information about Route Server Client\n"
11605 NEIGHBOR_ADDR_STR
11606 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11607
paul718e3742002-12-13 20:15:29 +000011608#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020011609
paul718e3742002-12-13 20:15:29 +000011610struct bgp_table *bgp_distance_table;
11611
11612struct bgp_distance
11613{
11614 /* Distance value for the IP source prefix. */
11615 u_char distance;
11616
11617 /* Name of the access-list to be matched. */
11618 char *access_list;
11619};
11620
paul94f2b392005-06-28 12:44:16 +000011621static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011622bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011623{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011624 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011625}
11626
paul94f2b392005-06-28 12:44:16 +000011627static void
paul718e3742002-12-13 20:15:29 +000011628bgp_distance_free (struct bgp_distance *bdistance)
11629{
11630 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11631}
11632
paul94f2b392005-06-28 12:44:16 +000011633static int
paulfd79ac92004-10-13 05:06:08 +000011634bgp_distance_set (struct vty *vty, const char *distance_str,
11635 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011636{
11637 int ret;
11638 struct prefix_ipv4 p;
11639 u_char distance;
11640 struct bgp_node *rn;
11641 struct bgp_distance *bdistance;
11642
11643 ret = str2prefix_ipv4 (ip_str, &p);
11644 if (ret == 0)
11645 {
11646 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11647 return CMD_WARNING;
11648 }
11649
11650 distance = atoi (distance_str);
11651
11652 /* Get BGP distance node. */
11653 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11654 if (rn->info)
11655 {
11656 bdistance = rn->info;
11657 bgp_unlock_node (rn);
11658 }
11659 else
11660 {
11661 bdistance = bgp_distance_new ();
11662 rn->info = bdistance;
11663 }
11664
11665 /* Set distance value. */
11666 bdistance->distance = distance;
11667
11668 /* Reset access-list configuration. */
11669 if (bdistance->access_list)
11670 {
11671 free (bdistance->access_list);
11672 bdistance->access_list = NULL;
11673 }
11674 if (access_list_str)
11675 bdistance->access_list = strdup (access_list_str);
11676
11677 return CMD_SUCCESS;
11678}
11679
paul94f2b392005-06-28 12:44:16 +000011680static int
paulfd79ac92004-10-13 05:06:08 +000011681bgp_distance_unset (struct vty *vty, const char *distance_str,
11682 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011683{
11684 int ret;
11685 struct prefix_ipv4 p;
11686 u_char distance;
11687 struct bgp_node *rn;
11688 struct bgp_distance *bdistance;
11689
11690 ret = str2prefix_ipv4 (ip_str, &p);
11691 if (ret == 0)
11692 {
11693 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11694 return CMD_WARNING;
11695 }
11696
11697 distance = atoi (distance_str);
11698
11699 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11700 if (! rn)
11701 {
11702 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11703 return CMD_WARNING;
11704 }
11705
11706 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010011707
11708 if (bdistance->distance != distance)
11709 {
11710 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
11711 return CMD_WARNING;
11712 }
11713
paul718e3742002-12-13 20:15:29 +000011714 if (bdistance->access_list)
11715 free (bdistance->access_list);
11716 bgp_distance_free (bdistance);
11717
11718 rn->info = NULL;
11719 bgp_unlock_node (rn);
11720 bgp_unlock_node (rn);
11721
11722 return CMD_SUCCESS;
11723}
11724
paul718e3742002-12-13 20:15:29 +000011725/* Apply BGP information to distance method. */
11726u_char
11727bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11728{
11729 struct bgp_node *rn;
11730 struct prefix_ipv4 q;
11731 struct peer *peer;
11732 struct bgp_distance *bdistance;
11733 struct access_list *alist;
11734 struct bgp_static *bgp_static;
11735
11736 if (! bgp)
11737 return 0;
11738
11739 if (p->family != AF_INET)
11740 return 0;
11741
11742 peer = rinfo->peer;
11743
11744 if (peer->su.sa.sa_family != AF_INET)
11745 return 0;
11746
11747 memset (&q, 0, sizeof (struct prefix_ipv4));
11748 q.family = AF_INET;
11749 q.prefix = peer->su.sin.sin_addr;
11750 q.prefixlen = IPV4_MAX_BITLEN;
11751
11752 /* Check source address. */
11753 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11754 if (rn)
11755 {
11756 bdistance = rn->info;
11757 bgp_unlock_node (rn);
11758
11759 if (bdistance->access_list)
11760 {
11761 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11762 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11763 return bdistance->distance;
11764 }
11765 else
11766 return bdistance->distance;
11767 }
11768
11769 /* Backdoor check. */
11770 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11771 if (rn)
11772 {
11773 bgp_static = rn->info;
11774 bgp_unlock_node (rn);
11775
11776 if (bgp_static->backdoor)
11777 {
11778 if (bgp->distance_local)
11779 return bgp->distance_local;
11780 else
11781 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11782 }
11783 }
11784
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011785 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011786 {
11787 if (bgp->distance_ebgp)
11788 return bgp->distance_ebgp;
11789 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11790 }
11791 else
11792 {
11793 if (bgp->distance_ibgp)
11794 return bgp->distance_ibgp;
11795 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11796 }
11797}
11798
11799DEFUN (bgp_distance,
11800 bgp_distance_cmd,
11801 "distance bgp <1-255> <1-255> <1-255>",
11802 "Define an administrative distance\n"
11803 "BGP distance\n"
11804 "Distance for routes external to the AS\n"
11805 "Distance for routes internal to the AS\n"
11806 "Distance for local routes\n")
11807{
11808 struct bgp *bgp;
11809
11810 bgp = vty->index;
11811
11812 bgp->distance_ebgp = atoi (argv[0]);
11813 bgp->distance_ibgp = atoi (argv[1]);
11814 bgp->distance_local = atoi (argv[2]);
11815 return CMD_SUCCESS;
11816}
11817
11818DEFUN (no_bgp_distance,
11819 no_bgp_distance_cmd,
11820 "no distance bgp <1-255> <1-255> <1-255>",
11821 NO_STR
11822 "Define an administrative distance\n"
11823 "BGP distance\n"
11824 "Distance for routes external to the AS\n"
11825 "Distance for routes internal to the AS\n"
11826 "Distance for local routes\n")
11827{
11828 struct bgp *bgp;
11829
11830 bgp = vty->index;
11831
11832 bgp->distance_ebgp= 0;
11833 bgp->distance_ibgp = 0;
11834 bgp->distance_local = 0;
11835 return CMD_SUCCESS;
11836}
11837
11838ALIAS (no_bgp_distance,
11839 no_bgp_distance2_cmd,
11840 "no distance bgp",
11841 NO_STR
11842 "Define an administrative distance\n"
11843 "BGP distance\n")
11844
11845DEFUN (bgp_distance_source,
11846 bgp_distance_source_cmd,
11847 "distance <1-255> A.B.C.D/M",
11848 "Define an administrative distance\n"
11849 "Administrative distance\n"
11850 "IP source prefix\n")
11851{
11852 bgp_distance_set (vty, argv[0], argv[1], NULL);
11853 return CMD_SUCCESS;
11854}
11855
11856DEFUN (no_bgp_distance_source,
11857 no_bgp_distance_source_cmd,
11858 "no distance <1-255> A.B.C.D/M",
11859 NO_STR
11860 "Define an administrative distance\n"
11861 "Administrative distance\n"
11862 "IP source prefix\n")
11863{
11864 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11865 return CMD_SUCCESS;
11866}
11867
11868DEFUN (bgp_distance_source_access_list,
11869 bgp_distance_source_access_list_cmd,
11870 "distance <1-255> A.B.C.D/M WORD",
11871 "Define an administrative distance\n"
11872 "Administrative distance\n"
11873 "IP source prefix\n"
11874 "Access list name\n")
11875{
11876 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11877 return CMD_SUCCESS;
11878}
11879
11880DEFUN (no_bgp_distance_source_access_list,
11881 no_bgp_distance_source_access_list_cmd,
11882 "no distance <1-255> A.B.C.D/M WORD",
11883 NO_STR
11884 "Define an administrative distance\n"
11885 "Administrative distance\n"
11886 "IP source prefix\n"
11887 "Access list name\n")
11888{
11889 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11890 return CMD_SUCCESS;
11891}
David Lamparter6b0655a2014-06-04 06:53:35 +020011892
paul718e3742002-12-13 20:15:29 +000011893DEFUN (bgp_damp_set,
11894 bgp_damp_set_cmd,
11895 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11896 "BGP Specific commands\n"
11897 "Enable route-flap dampening\n"
11898 "Half-life time for the penalty\n"
11899 "Value to start reusing a route\n"
11900 "Value to start suppressing a route\n"
11901 "Maximum duration to suppress a stable route\n")
11902{
11903 struct bgp *bgp;
11904 int half = DEFAULT_HALF_LIFE * 60;
11905 int reuse = DEFAULT_REUSE;
11906 int suppress = DEFAULT_SUPPRESS;
11907 int max = 4 * half;
11908
11909 if (argc == 4)
11910 {
11911 half = atoi (argv[0]) * 60;
11912 reuse = atoi (argv[1]);
11913 suppress = atoi (argv[2]);
11914 max = atoi (argv[3]) * 60;
11915 }
11916 else if (argc == 1)
11917 {
11918 half = atoi (argv[0]) * 60;
11919 max = 4 * half;
11920 }
11921
11922 bgp = vty->index;
11923 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11924 half, reuse, suppress, max);
11925}
11926
11927ALIAS (bgp_damp_set,
11928 bgp_damp_set2_cmd,
11929 "bgp dampening <1-45>",
11930 "BGP Specific commands\n"
11931 "Enable route-flap dampening\n"
11932 "Half-life time for the penalty\n")
11933
11934ALIAS (bgp_damp_set,
11935 bgp_damp_set3_cmd,
11936 "bgp dampening",
11937 "BGP Specific commands\n"
11938 "Enable route-flap dampening\n")
11939
11940DEFUN (bgp_damp_unset,
11941 bgp_damp_unset_cmd,
11942 "no bgp dampening",
11943 NO_STR
11944 "BGP Specific commands\n"
11945 "Enable route-flap dampening\n")
11946{
11947 struct bgp *bgp;
11948
11949 bgp = vty->index;
11950 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11951}
11952
11953ALIAS (bgp_damp_unset,
11954 bgp_damp_unset2_cmd,
11955 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11956 NO_STR
11957 "BGP Specific commands\n"
11958 "Enable route-flap dampening\n"
11959 "Half-life time for the penalty\n"
11960 "Value to start reusing a route\n"
11961 "Value to start suppressing a route\n"
11962 "Maximum duration to suppress a stable route\n")
11963
11964DEFUN (show_ip_bgp_dampened_paths,
11965 show_ip_bgp_dampened_paths_cmd,
11966 "show ip bgp dampened-paths",
11967 SHOW_STR
11968 IP_STR
11969 BGP_STR
11970 "Display paths suppressed due to dampening\n")
11971{
ajs5a646652004-11-05 01:25:55 +000011972 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11973 NULL);
paul718e3742002-12-13 20:15:29 +000011974}
11975
11976DEFUN (show_ip_bgp_flap_statistics,
11977 show_ip_bgp_flap_statistics_cmd,
11978 "show ip bgp flap-statistics",
11979 SHOW_STR
11980 IP_STR
11981 BGP_STR
11982 "Display flap statistics of routes\n")
11983{
ajs5a646652004-11-05 01:25:55 +000011984 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11985 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000011986}
David Lamparter6b0655a2014-06-04 06:53:35 +020011987
paul718e3742002-12-13 20:15:29 +000011988/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000011989static int
paulfd79ac92004-10-13 05:06:08 +000011990bgp_clear_damp_route (struct vty *vty, const char *view_name,
11991 const char *ip_str, afi_t afi, safi_t safi,
11992 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000011993{
11994 int ret;
11995 struct prefix match;
11996 struct bgp_node *rn;
11997 struct bgp_node *rm;
11998 struct bgp_info *ri;
11999 struct bgp_info *ri_temp;
12000 struct bgp *bgp;
12001 struct bgp_table *table;
12002
12003 /* BGP structure lookup. */
12004 if (view_name)
12005 {
12006 bgp = bgp_lookup_by_name (view_name);
12007 if (bgp == NULL)
12008 {
12009 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12010 return CMD_WARNING;
12011 }
12012 }
12013 else
12014 {
12015 bgp = bgp_get_default ();
12016 if (bgp == NULL)
12017 {
12018 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12019 return CMD_WARNING;
12020 }
12021 }
12022
12023 /* Check IP address argument. */
12024 ret = str2prefix (ip_str, &match);
12025 if (! ret)
12026 {
12027 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12028 return CMD_WARNING;
12029 }
12030
12031 match.family = afi2family (afi);
12032
12033 if (safi == SAFI_MPLS_VPN)
12034 {
12035 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12036 {
12037 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12038 continue;
12039
12040 if ((table = rn->info) != NULL)
12041 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012042 {
12043 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12044 {
12045 ri = rm->info;
12046 while (ri)
12047 {
12048 if (ri->extra && ri->extra->damp_info)
12049 {
12050 ri_temp = ri->next;
12051 bgp_damp_info_free (ri->extra->damp_info, 1);
12052 ri = ri_temp;
12053 }
12054 else
12055 ri = ri->next;
12056 }
12057 }
12058
12059 bgp_unlock_node (rm);
12060 }
paul718e3742002-12-13 20:15:29 +000012061 }
12062 }
12063 else
12064 {
12065 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012066 {
12067 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12068 {
12069 ri = rn->info;
12070 while (ri)
12071 {
12072 if (ri->extra && ri->extra->damp_info)
12073 {
12074 ri_temp = ri->next;
12075 bgp_damp_info_free (ri->extra->damp_info, 1);
12076 ri = ri_temp;
12077 }
12078 else
12079 ri = ri->next;
12080 }
12081 }
12082
12083 bgp_unlock_node (rn);
12084 }
paul718e3742002-12-13 20:15:29 +000012085 }
12086
12087 return CMD_SUCCESS;
12088}
12089
12090DEFUN (clear_ip_bgp_dampening,
12091 clear_ip_bgp_dampening_cmd,
12092 "clear ip bgp dampening",
12093 CLEAR_STR
12094 IP_STR
12095 BGP_STR
12096 "Clear route flap dampening information\n")
12097{
12098 bgp_damp_info_clean ();
12099 return CMD_SUCCESS;
12100}
12101
12102DEFUN (clear_ip_bgp_dampening_prefix,
12103 clear_ip_bgp_dampening_prefix_cmd,
12104 "clear ip bgp dampening A.B.C.D/M",
12105 CLEAR_STR
12106 IP_STR
12107 BGP_STR
12108 "Clear route flap dampening information\n"
12109 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12110{
12111 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12112 SAFI_UNICAST, NULL, 1);
12113}
12114
12115DEFUN (clear_ip_bgp_dampening_address,
12116 clear_ip_bgp_dampening_address_cmd,
12117 "clear ip bgp dampening A.B.C.D",
12118 CLEAR_STR
12119 IP_STR
12120 BGP_STR
12121 "Clear route flap dampening information\n"
12122 "Network to clear damping information\n")
12123{
12124 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12125 SAFI_UNICAST, NULL, 0);
12126}
12127
12128DEFUN (clear_ip_bgp_dampening_address_mask,
12129 clear_ip_bgp_dampening_address_mask_cmd,
12130 "clear ip bgp dampening A.B.C.D A.B.C.D",
12131 CLEAR_STR
12132 IP_STR
12133 BGP_STR
12134 "Clear route flap dampening information\n"
12135 "Network to clear damping information\n"
12136 "Network mask\n")
12137{
12138 int ret;
12139 char prefix_str[BUFSIZ];
12140
12141 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12142 if (! ret)
12143 {
12144 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12145 return CMD_WARNING;
12146 }
12147
12148 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12149 SAFI_UNICAST, NULL, 0);
12150}
David Lamparter6b0655a2014-06-04 06:53:35 +020012151
paul94f2b392005-06-28 12:44:16 +000012152static int
paul718e3742002-12-13 20:15:29 +000012153bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12154 afi_t afi, safi_t safi, int *write)
12155{
12156 struct bgp_node *prn;
12157 struct bgp_node *rn;
12158 struct bgp_table *table;
12159 struct prefix *p;
12160 struct prefix_rd *prd;
12161 struct bgp_static *bgp_static;
12162 u_int32_t label;
12163 char buf[SU_ADDRSTRLEN];
12164 char rdbuf[RD_ADDRSTRLEN];
12165
12166 /* Network configuration. */
12167 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12168 if ((table = prn->info) != NULL)
12169 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12170 if ((bgp_static = rn->info) != NULL)
12171 {
12172 p = &rn->p;
12173 prd = (struct prefix_rd *) &prn->p;
12174
12175 /* "address-family" display. */
12176 bgp_config_write_family_header (vty, afi, safi, write);
12177
12178 /* "network" configuration display. */
12179 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12180 label = decode_label (bgp_static->tag);
12181
12182 vty_out (vty, " network %s/%d rd %s tag %d",
12183 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12184 p->prefixlen,
12185 rdbuf, label);
12186 vty_out (vty, "%s", VTY_NEWLINE);
12187 }
12188 return 0;
12189}
12190
12191/* Configuration of static route announcement and aggregate
12192 information. */
12193int
12194bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12195 afi_t afi, safi_t safi, int *write)
12196{
12197 struct bgp_node *rn;
12198 struct prefix *p;
12199 struct bgp_static *bgp_static;
12200 struct bgp_aggregate *bgp_aggregate;
12201 char buf[SU_ADDRSTRLEN];
12202
12203 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12204 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12205
12206 /* Network configuration. */
12207 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12208 if ((bgp_static = rn->info) != NULL)
12209 {
12210 p = &rn->p;
12211
12212 /* "address-family" display. */
12213 bgp_config_write_family_header (vty, afi, safi, write);
12214
12215 /* "network" configuration display. */
12216 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12217 {
12218 u_int32_t destination;
12219 struct in_addr netmask;
12220
12221 destination = ntohl (p->u.prefix4.s_addr);
12222 masklen2ip (p->prefixlen, &netmask);
12223 vty_out (vty, " network %s",
12224 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12225
12226 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12227 || (IN_CLASSB (destination) && p->prefixlen == 16)
12228 || (IN_CLASSA (destination) && p->prefixlen == 8)
12229 || p->u.prefix4.s_addr == 0)
12230 {
12231 /* Natural mask is not display. */
12232 }
12233 else
12234 vty_out (vty, " mask %s", inet_ntoa (netmask));
12235 }
12236 else
12237 {
12238 vty_out (vty, " network %s/%d",
12239 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12240 p->prefixlen);
12241 }
12242
12243 if (bgp_static->rmap.name)
12244 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012245 else
12246 {
12247 if (bgp_static->backdoor)
12248 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012249 }
paul718e3742002-12-13 20:15:29 +000012250
12251 vty_out (vty, "%s", VTY_NEWLINE);
12252 }
12253
12254 /* Aggregate-address configuration. */
12255 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12256 if ((bgp_aggregate = rn->info) != NULL)
12257 {
12258 p = &rn->p;
12259
12260 /* "address-family" display. */
12261 bgp_config_write_family_header (vty, afi, safi, write);
12262
12263 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12264 {
12265 struct in_addr netmask;
12266
12267 masklen2ip (p->prefixlen, &netmask);
12268 vty_out (vty, " aggregate-address %s %s",
12269 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12270 inet_ntoa (netmask));
12271 }
12272 else
12273 {
12274 vty_out (vty, " aggregate-address %s/%d",
12275 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12276 p->prefixlen);
12277 }
12278
12279 if (bgp_aggregate->as_set)
12280 vty_out (vty, " as-set");
12281
12282 if (bgp_aggregate->summary_only)
12283 vty_out (vty, " summary-only");
12284
12285 vty_out (vty, "%s", VTY_NEWLINE);
12286 }
12287
12288 return 0;
12289}
12290
12291int
12292bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12293{
12294 struct bgp_node *rn;
12295 struct bgp_distance *bdistance;
12296
12297 /* Distance configuration. */
12298 if (bgp->distance_ebgp
12299 && bgp->distance_ibgp
12300 && bgp->distance_local
12301 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12302 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12303 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12304 vty_out (vty, " distance bgp %d %d %d%s",
12305 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12306 VTY_NEWLINE);
12307
12308 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12309 if ((bdistance = rn->info) != NULL)
12310 {
12311 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12312 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12313 bdistance->access_list ? bdistance->access_list : "",
12314 VTY_NEWLINE);
12315 }
12316
12317 return 0;
12318}
12319
12320/* Allocate routing table structure and install commands. */
12321void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012322bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012323{
12324 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012325 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012326
12327 /* IPv4 BGP commands. */
12328 install_element (BGP_NODE, &bgp_network_cmd);
12329 install_element (BGP_NODE, &bgp_network_mask_cmd);
12330 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12331 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12332 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12333 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12334 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12335 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12336 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12337 install_element (BGP_NODE, &no_bgp_network_cmd);
12338 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12339 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12340 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12341 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12342 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12343 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12344 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12345 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12346
12347 install_element (BGP_NODE, &aggregate_address_cmd);
12348 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12349 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12350 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12351 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12352 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12353 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12354 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12355 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12356 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12357 install_element (BGP_NODE, &no_aggregate_address_cmd);
12358 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12359 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12360 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12361 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12362 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12363 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12364 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12365 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12366 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12367
12368 /* IPv4 unicast configuration. */
12369 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12370 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12371 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12372 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12373 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12374 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012375 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012376 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12377 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12378 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12379 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12380 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012381
paul718e3742002-12-13 20:15:29 +000012382 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12383 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12384 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12385 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12386 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12387 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12388 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12389 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12390 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12391 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12392 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12393 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12394 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12395 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12396 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12397 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12398 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12399 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12400 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12401 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12402
12403 /* IPv4 multicast configuration. */
12404 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12405 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12406 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12407 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12408 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12409 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12410 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12411 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12412 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12413 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12414 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12415 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12416 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12417 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12418 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12419 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12420 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12421 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12422 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12423 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12424 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12425 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12426 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12427 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12428 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12429 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12430 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12431 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12432 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12433 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12434 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12435 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12436
12437 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12438 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012439 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012440 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12441 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012442 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012443 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12444 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12445 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12446 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012447 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012448 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12449 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12450 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12451 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12452 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12453 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12454 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12455 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12456 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12457 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12458 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12459 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12460 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12461 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12462 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12463 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12464 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12465 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12466 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12467 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12468 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12469 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12470 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12471 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12472 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012473 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12474 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12475 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12476 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12477 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012478 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12479 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12480 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12481 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12482 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12483 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12484 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12485 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12486 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12487 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12488 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12489 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12490 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12491 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12492 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12493 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12494 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12495 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012496 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012497 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12498 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12499 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12500 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12501 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12502 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12503 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12504 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12505 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12506 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12507 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12508 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12509 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12510 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12511 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12512 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012513 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012514 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012515 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012516 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012517 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012518 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012519 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12520 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012521 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012522 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012523 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012524 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012525 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012526 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012527
12528 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12529 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12530 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012531 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012532 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12533 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12534 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012535 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012536 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12537 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12538 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12539 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12540 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12541 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12542 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12543 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12544 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12545 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12546 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12547 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012548 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12549 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12550 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12551 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12552 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012553 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12554 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12555 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12556 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12557 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12558 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12559 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12560 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12561 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012562 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012563 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012564 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012565 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012566 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012567 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012568 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012569
12570 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12571 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012572 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012573 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12574 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012575 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012576 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12577 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12578 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12579 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012580 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012581 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12582 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12583 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12584 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12585 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12586 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12587 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12588 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12589 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12590 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12591 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12592 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12593 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12594 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12595 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12596 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12597 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12598 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12599 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12600 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12601 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12602 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12603 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12604 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12605 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012606 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12607 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12608 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12609 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12610 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012611 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12612 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12613 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12614 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12615 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12616 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12617 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12618 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12619 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12620 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12621 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12622 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12623 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12624 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12625 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12626 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12627 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12628 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012629 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012630 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12631 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12632 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12633 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12634 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12635 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12636 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12637 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12638 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12639 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12640 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12641 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12642 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12643 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12644 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12645 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012646 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012647 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012648 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012649 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012650 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012651 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012652 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12653 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012654 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012655 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012656 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012657 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012658 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012659 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012660
12661 /* BGP dampening clear commands */
12662 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12663 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12664 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12665 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12666
Paul Jakmaff7924f2006-09-04 01:10:36 +000012667 /* prefix count */
12668 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12669 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12670 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012671#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012672 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12673
paul718e3742002-12-13 20:15:29 +000012674 /* New config IPv6 BGP commands. */
12675 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12676 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12677 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12678 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12679
12680 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12681 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12682 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12683 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12684
G.Balaji73bfe0b2011-09-23 22:36:20 +053012685 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12686 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12687
paul718e3742002-12-13 20:15:29 +000012688 /* Old config IPv6 BGP commands. */
12689 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12690 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12691
12692 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12693 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12694 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12695 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12696
12697 install_element (VIEW_NODE, &show_bgp_cmd);
12698 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012699 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012700 install_element (VIEW_NODE, &show_bgp_route_cmd);
12701 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012702 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012703 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12704 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012705 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012706 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12707 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12708 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12709 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12710 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12711 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12712 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12713 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12714 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12715 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12716 install_element (VIEW_NODE, &show_bgp_community_cmd);
12717 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12718 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12719 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12720 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12721 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12722 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12723 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12724 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12725 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12726 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12727 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12728 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12729 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12730 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12731 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12732 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12733 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12734 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12735 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12736 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12737 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12738 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12739 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12740 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12741 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12742 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12743 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12744 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12745 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012746 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12747 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12748 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12749 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012750 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012751 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012752 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012753 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012754 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012755 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012756 install_element (VIEW_NODE, &show_bgp_view_cmd);
12757 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12758 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12759 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12760 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12761 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12762 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12763 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12764 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12765 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12766 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12767 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12768 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12769 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12770 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12771 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12772 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12773 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012774 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012775 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012776 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012777 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012778 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012779 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012780
12781 /* Restricted:
12782 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12783 */
12784 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12785 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012786 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012787 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12788 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012789 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012790 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12791 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12792 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12793 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12794 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12795 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12796 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12797 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12798 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12799 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12800 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12801 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12802 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12803 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12804 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12805 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12806 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012807 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012808 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012809 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012810 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12811 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12812 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12813 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12814 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12815 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12816 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012817 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012818 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012819 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012820
12821 install_element (ENABLE_NODE, &show_bgp_cmd);
12822 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012823 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012824 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12825 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012826 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012827 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12828 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012829 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012830 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12831 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12832 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12833 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12834 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12835 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12836 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12837 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12838 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12839 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12840 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12841 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12842 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12843 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12844 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12845 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12846 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12847 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12848 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12849 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12850 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12851 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12852 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12853 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12854 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12855 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12856 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12857 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12858 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12859 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12860 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12861 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12862 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12863 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12864 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12865 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12866 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12867 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12868 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12869 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012870 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12871 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12872 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12873 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012874 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012875 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012876 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012877 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012878 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012879 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012880 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12881 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12882 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12883 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12884 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12885 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12886 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12887 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12888 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12889 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12890 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12891 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12892 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12893 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12894 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12895 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12896 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12897 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012898 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012899 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012900 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012901 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012902 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012903 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012904
12905 /* Statistics */
12906 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12907 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12908 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12909 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12910
paul718e3742002-12-13 20:15:29 +000012911 /* old command */
12912 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12913 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12914 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12915 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12916 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12917 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12918 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12919 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12920 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12921 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12922 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12923 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12924 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12925 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12926 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12927 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12928 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12929 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12930 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12931 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12932 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12933 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12934 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12935 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12936 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12937 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12938 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12939 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12940 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12941 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12942 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12943 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12944 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12945 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12946 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12947 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012948
paul718e3742002-12-13 20:15:29 +000012949 /* old command */
12950 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12951 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12952 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12953 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12954 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12955 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12956 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12957 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12958 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12959 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12960 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12961 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12962 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12963 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12964 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12965 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12966 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12967 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12968 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12969 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12970 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12971 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12972 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12973 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12974 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12975 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12976 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12977 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12978 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12979 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12980 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12981 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12982 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12983 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12984 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12985 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12986
12987 /* old command */
12988 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12989 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12990 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12991 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12992
12993 /* old command */
12994 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12995 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12996 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12997 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12998
12999 /* old command */
13000 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13001 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13002 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13003 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13004#endif /* HAVE_IPV6 */
13005
13006 install_element (BGP_NODE, &bgp_distance_cmd);
13007 install_element (BGP_NODE, &no_bgp_distance_cmd);
13008 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13009 install_element (BGP_NODE, &bgp_distance_source_cmd);
13010 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13011 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13012 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13013
13014 install_element (BGP_NODE, &bgp_damp_set_cmd);
13015 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13016 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13017 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13018 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13019 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13020 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13021 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13022 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13023 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013024
13025 /* Deprecated AS-Pathlimit commands */
13026 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13027 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13028 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13029 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13030 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13031 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13032
13033 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13034 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13035 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13036 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13037 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13038 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13039
13040 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13041 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13042 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13043 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13044 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13045 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13046
13047 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13048 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13049 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13050 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13051 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13052 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13053
13054 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13055 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13056 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13057 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13058 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13059 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13060
13061 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13062 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13063 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13064 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13065 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13066 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013067
13068#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013069 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13070 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013071#endif
paul718e3742002-12-13 20:15:29 +000013072}
Chris Caputo228da422009-07-18 05:44:03 +000013073
13074void
13075bgp_route_finish (void)
13076{
13077 bgp_table_unlock (bgp_distance_table);
13078 bgp_distance_table = NULL;
13079}