blob: cd2737c8bdab1ad25cbfc3ed10c75cde5f200772 [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,
7909#ifdef HAVE_IPV6
7910 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7911#else
7912 "show bgp view WORD ipv4 (unicast|multicast) community",
7913#endif
7914 SHOW_STR
7915 BGP_STR
7916 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007917 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007918 "Address family\n"
7919#ifdef HAVE_IPV6
7920 "Address family\n"
7921#endif
7922 "Address Family modifier\n"
7923 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00007924 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007925{
7926 int afi;
7927 int safi;
7928 struct bgp *bgp;
7929
7930 /* BGP structure lookup. */
7931 bgp = bgp_lookup_by_name (argv[0]);
7932 if (bgp == NULL)
7933 {
7934 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7935 return CMD_WARNING;
7936 }
7937
7938#ifdef HAVE_IPV6
7939 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7940 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7941#else
7942 afi = AFI_IP;
7943 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7944#endif
7945 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7946}
7947
7948DEFUN (show_bgp_view_afi_safi_community,
7949 show_bgp_view_afi_safi_community_cmd,
7950#ifdef HAVE_IPV6
7951 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7952#else
7953 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7954#endif
7955 SHOW_STR
7956 BGP_STR
7957 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007958 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007959 "Address family\n"
7960#ifdef HAVE_IPV6
7961 "Address family\n"
7962#endif
7963 "Address family modifier\n"
7964 "Address family modifier\n"
7965 "Display routes matching the communities\n"
7966 "community number\n"
7967 "Do not send outside local AS (well-known community)\n"
7968 "Do not advertise to any peer (well-known community)\n"
7969 "Do not export to next AS (well-known community)\n")
7970{
7971 int afi;
7972 int safi;
7973
7974#ifdef HAVE_IPV6
7975 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7976 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7977 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7978#else
7979 afi = AFI_IP;
7980 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7981 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
7982#endif
7983}
7984
7985ALIAS (show_bgp_view_afi_safi_community,
7986 show_bgp_view_afi_safi_community2_cmd,
7987#ifdef HAVE_IPV6
7988 "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)",
7989#else
7990 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7991#endif
7992 SHOW_STR
7993 BGP_STR
7994 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007995 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007996 "Address family\n"
7997#ifdef HAVE_IPV6
7998 "Address family\n"
7999#endif
8000 "Address family modifier\n"
8001 "Address family modifier\n"
8002 "Display routes matching the communities\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 "community number\n"
8008 "Do not send outside local AS (well-known community)\n"
8009 "Do not advertise to any peer (well-known community)\n"
8010 "Do not export to next AS (well-known community)\n")
8011
8012ALIAS (show_bgp_view_afi_safi_community,
8013 show_bgp_view_afi_safi_community3_cmd,
8014#ifdef HAVE_IPV6
8015 "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)",
8016#else
8017 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8018#endif
8019 SHOW_STR
8020 BGP_STR
8021 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008022 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008023 "Address family\n"
8024#ifdef HAVE_IPV6
8025 "Address family\n"
8026#endif
8027 "Address family modifier\n"
8028 "Address family modifier\n"
8029 "Display routes matching the communities\n"
8030 "community number\n"
8031 "Do not send outside local AS (well-known community)\n"
8032 "Do not advertise to any peer (well-known community)\n"
8033 "Do not export to next AS (well-known community)\n"
8034 "community number\n"
8035 "Do not send outside local AS (well-known community)\n"
8036 "Do not advertise to any peer (well-known community)\n"
8037 "Do not export to next AS (well-known community)\n"
8038 "community number\n"
8039 "Do not send outside local AS (well-known community)\n"
8040 "Do not advertise to any peer (well-known community)\n"
8041 "Do not export to next AS (well-known community)\n")
8042
8043ALIAS (show_bgp_view_afi_safi_community,
8044 show_bgp_view_afi_safi_community4_cmd,
8045#ifdef HAVE_IPV6
8046 "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)",
8047#else
8048 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8049#endif
8050 SHOW_STR
8051 BGP_STR
8052 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008053 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008054 "Address family\n"
8055#ifdef HAVE_IPV6
8056 "Address family\n"
8057#endif
8058 "Address family modifier\n"
8059 "Address family modifier\n"
8060 "Display routes matching the communities\n"
8061 "community number\n"
8062 "Do not send outside local AS (well-known community)\n"
8063 "Do not advertise to any peer (well-known community)\n"
8064 "Do not export to next AS (well-known community)\n"
8065 "community number\n"
8066 "Do not send outside local AS (well-known community)\n"
8067 "Do not advertise to any peer (well-known community)\n"
8068 "Do not export to next AS (well-known community)\n"
8069 "community number\n"
8070 "Do not send outside local AS (well-known community)\n"
8071 "Do not advertise to any peer (well-known community)\n"
8072 "Do not export to next AS (well-known community)\n"
8073 "community number\n"
8074 "Do not send outside local AS (well-known community)\n"
8075 "Do not advertise to any peer (well-known community)\n"
8076 "Do not export to next AS (well-known community)\n")
8077
paul718e3742002-12-13 20:15:29 +00008078DEFUN (show_ip_bgp_community_exact,
8079 show_ip_bgp_community_exact_cmd,
8080 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8081 SHOW_STR
8082 IP_STR
8083 BGP_STR
8084 "Display routes matching the communities\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{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008091 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008092}
8093
8094ALIAS (show_ip_bgp_community_exact,
8095 show_ip_bgp_community2_exact_cmd,
8096 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8097 SHOW_STR
8098 IP_STR
8099 BGP_STR
8100 "Display routes matching the communities\n"
8101 "community number\n"
8102 "Do not send outside local AS (well-known community)\n"
8103 "Do not advertise to any peer (well-known community)\n"
8104 "Do not export to next AS (well-known community)\n"
8105 "community number\n"
8106 "Do not send outside local AS (well-known community)\n"
8107 "Do not advertise to any peer (well-known community)\n"
8108 "Do not export to next AS (well-known community)\n"
8109 "Exact match of the communities")
8110
8111ALIAS (show_ip_bgp_community_exact,
8112 show_ip_bgp_community3_exact_cmd,
8113 "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",
8114 SHOW_STR
8115 IP_STR
8116 BGP_STR
8117 "Display routes matching the communities\n"
8118 "community number\n"
8119 "Do not send outside local AS (well-known community)\n"
8120 "Do not advertise to any peer (well-known community)\n"
8121 "Do not export to next AS (well-known community)\n"
8122 "community number\n"
8123 "Do not send outside local AS (well-known community)\n"
8124 "Do not advertise to any peer (well-known community)\n"
8125 "Do not export to next AS (well-known community)\n"
8126 "community number\n"
8127 "Do not send outside local AS (well-known community)\n"
8128 "Do not advertise to any peer (well-known community)\n"
8129 "Do not export to next AS (well-known community)\n"
8130 "Exact match of the communities")
8131
8132ALIAS (show_ip_bgp_community_exact,
8133 show_ip_bgp_community4_exact_cmd,
8134 "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",
8135 SHOW_STR
8136 IP_STR
8137 BGP_STR
8138 "Display routes matching the communities\n"
8139 "community number\n"
8140 "Do not send outside local AS (well-known community)\n"
8141 "Do not advertise to any peer (well-known community)\n"
8142 "Do not export to next AS (well-known community)\n"
8143 "community number\n"
8144 "Do not send outside local AS (well-known community)\n"
8145 "Do not advertise to any peer (well-known community)\n"
8146 "Do not export to next AS (well-known community)\n"
8147 "community number\n"
8148 "Do not send outside local AS (well-known community)\n"
8149 "Do not advertise to any peer (well-known community)\n"
8150 "Do not export to next AS (well-known community)\n"
8151 "community number\n"
8152 "Do not send outside local AS (well-known community)\n"
8153 "Do not advertise to any peer (well-known community)\n"
8154 "Do not export to next AS (well-known community)\n"
8155 "Exact match of the communities")
8156
8157DEFUN (show_ip_bgp_ipv4_community_exact,
8158 show_ip_bgp_ipv4_community_exact_cmd,
8159 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8160 SHOW_STR
8161 IP_STR
8162 BGP_STR
8163 "Address family\n"
8164 "Address Family modifier\n"
8165 "Address Family modifier\n"
8166 "Display routes matching the communities\n"
8167 "community number\n"
8168 "Do not send outside local AS (well-known community)\n"
8169 "Do not advertise to any peer (well-known community)\n"
8170 "Do not export to next AS (well-known community)\n"
8171 "Exact match of the communities")
8172{
8173 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008174 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008175
Michael Lambert95cbbd22010-07-23 14:43:04 -04008176 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008177}
8178
8179ALIAS (show_ip_bgp_ipv4_community_exact,
8180 show_ip_bgp_ipv4_community2_exact_cmd,
8181 "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",
8182 SHOW_STR
8183 IP_STR
8184 BGP_STR
8185 "Address family\n"
8186 "Address Family modifier\n"
8187 "Address Family modifier\n"
8188 "Display routes matching the communities\n"
8189 "community number\n"
8190 "Do not send outside local AS (well-known community)\n"
8191 "Do not advertise to any peer (well-known community)\n"
8192 "Do not export to next AS (well-known community)\n"
8193 "community number\n"
8194 "Do not send outside local AS (well-known community)\n"
8195 "Do not advertise to any peer (well-known community)\n"
8196 "Do not export to next AS (well-known community)\n"
8197 "Exact match of the communities")
8198
8199ALIAS (show_ip_bgp_ipv4_community_exact,
8200 show_ip_bgp_ipv4_community3_exact_cmd,
8201 "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",
8202 SHOW_STR
8203 IP_STR
8204 BGP_STR
8205 "Address family\n"
8206 "Address Family modifier\n"
8207 "Address Family modifier\n"
8208 "Display routes matching the communities\n"
8209 "community number\n"
8210 "Do not send outside local AS (well-known community)\n"
8211 "Do not advertise to any peer (well-known community)\n"
8212 "Do not export to next AS (well-known community)\n"
8213 "community number\n"
8214 "Do not send outside local AS (well-known community)\n"
8215 "Do not advertise to any peer (well-known community)\n"
8216 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8222
8223ALIAS (show_ip_bgp_ipv4_community_exact,
8224 show_ip_bgp_ipv4_community4_exact_cmd,
8225 "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",
8226 SHOW_STR
8227 IP_STR
8228 BGP_STR
8229 "Address family\n"
8230 "Address Family modifier\n"
8231 "Address Family modifier\n"
8232 "Display routes matching the communities\n"
8233 "community number\n"
8234 "Do not send outside local AS (well-known community)\n"
8235 "Do not advertise to any peer (well-known community)\n"
8236 "Do not export to next AS (well-known community)\n"
8237 "community number\n"
8238 "Do not send outside local AS (well-known community)\n"
8239 "Do not advertise to any peer (well-known community)\n"
8240 "Do not export to next AS (well-known community)\n"
8241 "community number\n"
8242 "Do not send outside local AS (well-known community)\n"
8243 "Do not advertise to any peer (well-known community)\n"
8244 "Do not export to next AS (well-known community)\n"
8245 "community number\n"
8246 "Do not send outside local AS (well-known community)\n"
8247 "Do not advertise to any peer (well-known community)\n"
8248 "Do not export to next AS (well-known community)\n"
8249 "Exact match of the communities")
8250
8251#ifdef HAVE_IPV6
8252DEFUN (show_bgp_community,
8253 show_bgp_community_cmd,
8254 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8255 SHOW_STR
8256 BGP_STR
8257 "Display routes matching the communities\n"
8258 "community number\n"
8259 "Do not send outside local AS (well-known community)\n"
8260 "Do not advertise to any peer (well-known community)\n"
8261 "Do not export to next AS (well-known community)\n")
8262{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008263 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008264}
8265
8266ALIAS (show_bgp_community,
8267 show_bgp_ipv6_community_cmd,
8268 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8269 SHOW_STR
8270 BGP_STR
8271 "Address family\n"
8272 "Display routes matching the communities\n"
8273 "community number\n"
8274 "Do not send outside local AS (well-known community)\n"
8275 "Do not advertise to any peer (well-known community)\n"
8276 "Do not export to next AS (well-known community)\n")
8277
8278ALIAS (show_bgp_community,
8279 show_bgp_community2_cmd,
8280 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8281 SHOW_STR
8282 BGP_STR
8283 "Display routes matching the communities\n"
8284 "community number\n"
8285 "Do not send outside local AS (well-known community)\n"
8286 "Do not advertise to any peer (well-known community)\n"
8287 "Do not export to next AS (well-known community)\n"
8288 "community number\n"
8289 "Do not send outside local AS (well-known community)\n"
8290 "Do not advertise to any peer (well-known community)\n"
8291 "Do not export to next AS (well-known community)\n")
8292
8293ALIAS (show_bgp_community,
8294 show_bgp_ipv6_community2_cmd,
8295 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8296 SHOW_STR
8297 BGP_STR
8298 "Address family\n"
8299 "Display routes matching the communities\n"
8300 "community number\n"
8301 "Do not send outside local AS (well-known community)\n"
8302 "Do not advertise to any peer (well-known community)\n"
8303 "Do not export to next AS (well-known community)\n"
8304 "community number\n"
8305 "Do not send outside local AS (well-known community)\n"
8306 "Do not advertise to any peer (well-known community)\n"
8307 "Do not export to next AS (well-known community)\n")
8308
8309ALIAS (show_bgp_community,
8310 show_bgp_community3_cmd,
8311 "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)",
8312 SHOW_STR
8313 BGP_STR
8314 "Display routes matching the communities\n"
8315 "community number\n"
8316 "Do not send outside local AS (well-known community)\n"
8317 "Do not advertise to any peer (well-known community)\n"
8318 "Do not export to next AS (well-known community)\n"
8319 "community number\n"
8320 "Do not send outside local AS (well-known community)\n"
8321 "Do not advertise to any peer (well-known community)\n"
8322 "Do not export to next AS (well-known community)\n"
8323 "community number\n"
8324 "Do not send outside local AS (well-known community)\n"
8325 "Do not advertise to any peer (well-known community)\n"
8326 "Do not export to next AS (well-known community)\n")
8327
8328ALIAS (show_bgp_community,
8329 show_bgp_ipv6_community3_cmd,
8330 "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)",
8331 SHOW_STR
8332 BGP_STR
8333 "Address family\n"
8334 "Display routes matching the communities\n"
8335 "community number\n"
8336 "Do not send outside local AS (well-known community)\n"
8337 "Do not advertise to any peer (well-known community)\n"
8338 "Do not export to next AS (well-known community)\n"
8339 "community number\n"
8340 "Do not send outside local AS (well-known community)\n"
8341 "Do not advertise to any peer (well-known community)\n"
8342 "Do not export to next AS (well-known community)\n"
8343 "community number\n"
8344 "Do not send outside local AS (well-known community)\n"
8345 "Do not advertise to any peer (well-known community)\n"
8346 "Do not export to next AS (well-known community)\n")
8347
8348ALIAS (show_bgp_community,
8349 show_bgp_community4_cmd,
8350 "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)",
8351 SHOW_STR
8352 BGP_STR
8353 "Display routes matching the communities\n"
8354 "community number\n"
8355 "Do not send outside local AS (well-known community)\n"
8356 "Do not advertise to any peer (well-known community)\n"
8357 "Do not export to next AS (well-known community)\n"
8358 "community number\n"
8359 "Do not send outside local AS (well-known community)\n"
8360 "Do not advertise to any peer (well-known community)\n"
8361 "Do not export to next AS (well-known community)\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 "community number\n"
8367 "Do not send outside local AS (well-known community)\n"
8368 "Do not advertise to any peer (well-known community)\n"
8369 "Do not export to next AS (well-known community)\n")
8370
8371ALIAS (show_bgp_community,
8372 show_bgp_ipv6_community4_cmd,
8373 "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)",
8374 SHOW_STR
8375 BGP_STR
8376 "Address family\n"
8377 "Display routes matching the communities\n"
8378 "community number\n"
8379 "Do not send outside local AS (well-known community)\n"
8380 "Do not advertise to any peer (well-known community)\n"
8381 "Do not export to next AS (well-known community)\n"
8382 "community number\n"
8383 "Do not send outside local AS (well-known community)\n"
8384 "Do not advertise to any peer (well-known community)\n"
8385 "Do not export to next AS (well-known community)\n"
8386 "community number\n"
8387 "Do not send outside local AS (well-known community)\n"
8388 "Do not advertise to any peer (well-known community)\n"
8389 "Do not export to next AS (well-known community)\n"
8390 "community number\n"
8391 "Do not send outside local AS (well-known community)\n"
8392 "Do not advertise to any peer (well-known community)\n"
8393 "Do not export to next AS (well-known community)\n")
8394
8395/* old command */
8396DEFUN (show_ipv6_bgp_community,
8397 show_ipv6_bgp_community_cmd,
8398 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8399 SHOW_STR
8400 IPV6_STR
8401 BGP_STR
8402 "Display routes matching the communities\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{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008408 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008409}
8410
8411/* old command */
8412ALIAS (show_ipv6_bgp_community,
8413 show_ipv6_bgp_community2_cmd,
8414 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8415 SHOW_STR
8416 IPV6_STR
8417 BGP_STR
8418 "Display routes matching the communities\n"
8419 "community number\n"
8420 "Do not send outside local AS (well-known community)\n"
8421 "Do not advertise to any peer (well-known community)\n"
8422 "Do not export to next AS (well-known community)\n"
8423 "community number\n"
8424 "Do not send outside local AS (well-known community)\n"
8425 "Do not advertise to any peer (well-known community)\n"
8426 "Do not export to next AS (well-known community)\n")
8427
8428/* old command */
8429ALIAS (show_ipv6_bgp_community,
8430 show_ipv6_bgp_community3_cmd,
8431 "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)",
8432 SHOW_STR
8433 IPV6_STR
8434 BGP_STR
8435 "Display routes matching the communities\n"
8436 "community number\n"
8437 "Do not send outside local AS (well-known community)\n"
8438 "Do not advertise to any peer (well-known community)\n"
8439 "Do not export to next AS (well-known community)\n"
8440 "community number\n"
8441 "Do not send outside local AS (well-known community)\n"
8442 "Do not advertise to any peer (well-known community)\n"
8443 "Do not export to next AS (well-known community)\n"
8444 "community number\n"
8445 "Do not send outside local AS (well-known community)\n"
8446 "Do not advertise to any peer (well-known community)\n"
8447 "Do not export to next AS (well-known community)\n")
8448
8449/* old command */
8450ALIAS (show_ipv6_bgp_community,
8451 show_ipv6_bgp_community4_cmd,
8452 "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)",
8453 SHOW_STR
8454 IPV6_STR
8455 BGP_STR
8456 "Display routes matching the communities\n"
8457 "community number\n"
8458 "Do not send outside local AS (well-known community)\n"
8459 "Do not advertise to any peer (well-known community)\n"
8460 "Do not export to next AS (well-known community)\n"
8461 "community number\n"
8462 "Do not send outside local AS (well-known community)\n"
8463 "Do not advertise to any peer (well-known community)\n"
8464 "Do not export to next AS (well-known community)\n"
8465 "community number\n"
8466 "Do not send outside local AS (well-known community)\n"
8467 "Do not advertise to any peer (well-known community)\n"
8468 "Do not export to next AS (well-known community)\n"
8469 "community number\n"
8470 "Do not send outside local AS (well-known community)\n"
8471 "Do not advertise to any peer (well-known community)\n"
8472 "Do not export to next AS (well-known community)\n")
8473
8474DEFUN (show_bgp_community_exact,
8475 show_bgp_community_exact_cmd,
8476 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8477 SHOW_STR
8478 BGP_STR
8479 "Display routes matching the communities\n"
8480 "community number\n"
8481 "Do not send outside local AS (well-known community)\n"
8482 "Do not advertise to any peer (well-known community)\n"
8483 "Do not export to next AS (well-known community)\n"
8484 "Exact match of the communities")
8485{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008486 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008487}
8488
8489ALIAS (show_bgp_community_exact,
8490 show_bgp_ipv6_community_exact_cmd,
8491 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8492 SHOW_STR
8493 BGP_STR
8494 "Address family\n"
8495 "Display routes matching the communities\n"
8496 "community number\n"
8497 "Do not send outside local AS (well-known community)\n"
8498 "Do not advertise to any peer (well-known community)\n"
8499 "Do not export to next AS (well-known community)\n"
8500 "Exact match of the communities")
8501
8502ALIAS (show_bgp_community_exact,
8503 show_bgp_community2_exact_cmd,
8504 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8505 SHOW_STR
8506 BGP_STR
8507 "Display routes matching the communities\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 "community number\n"
8513 "Do not send outside local AS (well-known community)\n"
8514 "Do not advertise to any peer (well-known community)\n"
8515 "Do not export to next AS (well-known community)\n"
8516 "Exact match of the communities")
8517
8518ALIAS (show_bgp_community_exact,
8519 show_bgp_ipv6_community2_exact_cmd,
8520 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8521 SHOW_STR
8522 BGP_STR
8523 "Address family\n"
8524 "Display routes matching the communities\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_community3_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) 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 "Exact match of the communities")
8554
8555ALIAS (show_bgp_community_exact,
8556 show_bgp_ipv6_community3_exact_cmd,
8557 "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",
8558 SHOW_STR
8559 BGP_STR
8560 "Address family\n"
8561 "Display routes matching the communities\n"
8562 "community number\n"
8563 "Do not send outside local AS (well-known community)\n"
8564 "Do not advertise to any peer (well-known community)\n"
8565 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8575
8576ALIAS (show_bgp_community_exact,
8577 show_bgp_community4_exact_cmd,
8578 "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",
8579 SHOW_STR
8580 BGP_STR
8581 "Display routes matching the communities\n"
8582 "community number\n"
8583 "Do not send outside local AS (well-known community)\n"
8584 "Do not advertise to any peer (well-known community)\n"
8585 "Do not export to next AS (well-known community)\n"
8586 "community number\n"
8587 "Do not send outside local AS (well-known community)\n"
8588 "Do not advertise to any peer (well-known community)\n"
8589 "Do not export to next AS (well-known community)\n"
8590 "community number\n"
8591 "Do not send outside local AS (well-known community)\n"
8592 "Do not advertise to any peer (well-known community)\n"
8593 "Do not export to next AS (well-known community)\n"
8594 "community number\n"
8595 "Do not send outside local AS (well-known community)\n"
8596 "Do not advertise to any peer (well-known community)\n"
8597 "Do not export to next AS (well-known community)\n"
8598 "Exact match of the communities")
8599
8600ALIAS (show_bgp_community_exact,
8601 show_bgp_ipv6_community4_exact_cmd,
8602 "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",
8603 SHOW_STR
8604 BGP_STR
8605 "Address family\n"
8606 "Display routes matching the communities\n"
8607 "community number\n"
8608 "Do not send outside local AS (well-known community)\n"
8609 "Do not advertise to any peer (well-known community)\n"
8610 "Do not export to next AS (well-known community)\n"
8611 "community number\n"
8612 "Do not send outside local AS (well-known community)\n"
8613 "Do not advertise to any peer (well-known community)\n"
8614 "Do not export to next AS (well-known community)\n"
8615 "community number\n"
8616 "Do not send outside local AS (well-known community)\n"
8617 "Do not advertise to any peer (well-known community)\n"
8618 "Do not export to next AS (well-known community)\n"
8619 "community number\n"
8620 "Do not send outside local AS (well-known community)\n"
8621 "Do not advertise to any peer (well-known community)\n"
8622 "Do not export to next AS (well-known community)\n"
8623 "Exact match of the communities")
8624
8625/* old command */
8626DEFUN (show_ipv6_bgp_community_exact,
8627 show_ipv6_bgp_community_exact_cmd,
8628 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8629 SHOW_STR
8630 IPV6_STR
8631 BGP_STR
8632 "Display routes matching the communities\n"
8633 "community number\n"
8634 "Do not send outside local AS (well-known community)\n"
8635 "Do not advertise to any peer (well-known community)\n"
8636 "Do not export to next AS (well-known community)\n"
8637 "Exact match of the communities")
8638{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008639 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008640}
8641
8642/* old command */
8643ALIAS (show_ipv6_bgp_community_exact,
8644 show_ipv6_bgp_community2_exact_cmd,
8645 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8646 SHOW_STR
8647 IPV6_STR
8648 BGP_STR
8649 "Display routes matching the communities\n"
8650 "community number\n"
8651 "Do not send outside local AS (well-known community)\n"
8652 "Do not advertise to any peer (well-known community)\n"
8653 "Do not export to next AS (well-known community)\n"
8654 "community number\n"
8655 "Do not send outside local AS (well-known community)\n"
8656 "Do not advertise to any peer (well-known community)\n"
8657 "Do not export to next AS (well-known community)\n"
8658 "Exact match of the communities")
8659
8660/* old command */
8661ALIAS (show_ipv6_bgp_community_exact,
8662 show_ipv6_bgp_community3_exact_cmd,
8663 "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",
8664 SHOW_STR
8665 IPV6_STR
8666 BGP_STR
8667 "Display routes matching the communities\n"
8668 "community number\n"
8669 "Do not send outside local AS (well-known community)\n"
8670 "Do not advertise to any peer (well-known community)\n"
8671 "Do not export to next AS (well-known community)\n"
8672 "community number\n"
8673 "Do not send outside local AS (well-known community)\n"
8674 "Do not advertise to any peer (well-known community)\n"
8675 "Do not export to next AS (well-known community)\n"
8676 "community number\n"
8677 "Do not send outside local AS (well-known community)\n"
8678 "Do not advertise to any peer (well-known community)\n"
8679 "Do not export to next AS (well-known community)\n"
8680 "Exact match of the communities")
8681
8682/* old command */
8683ALIAS (show_ipv6_bgp_community_exact,
8684 show_ipv6_bgp_community4_exact_cmd,
8685 "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",
8686 SHOW_STR
8687 IPV6_STR
8688 BGP_STR
8689 "Display routes matching the communities\n"
8690 "community number\n"
8691 "Do not send outside local AS (well-known community)\n"
8692 "Do not advertise to any peer (well-known community)\n"
8693 "Do not export to next AS (well-known community)\n"
8694 "community number\n"
8695 "Do not send outside local AS (well-known community)\n"
8696 "Do not advertise to any peer (well-known community)\n"
8697 "Do not export to next AS (well-known community)\n"
8698 "community number\n"
8699 "Do not send outside local AS (well-known community)\n"
8700 "Do not advertise to any peer (well-known community)\n"
8701 "Do not export to next AS (well-known community)\n"
8702 "community number\n"
8703 "Do not send outside local AS (well-known community)\n"
8704 "Do not advertise to any peer (well-known community)\n"
8705 "Do not export to next AS (well-known community)\n"
8706 "Exact match of the communities")
8707
8708/* old command */
8709DEFUN (show_ipv6_mbgp_community,
8710 show_ipv6_mbgp_community_cmd,
8711 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8712 SHOW_STR
8713 IPV6_STR
8714 MBGP_STR
8715 "Display routes matching the communities\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{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008721 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008722}
8723
8724/* old command */
8725ALIAS (show_ipv6_mbgp_community,
8726 show_ipv6_mbgp_community2_cmd,
8727 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8728 SHOW_STR
8729 IPV6_STR
8730 MBGP_STR
8731 "Display routes matching the communities\n"
8732 "community number\n"
8733 "Do not send outside local AS (well-known community)\n"
8734 "Do not advertise to any peer (well-known community)\n"
8735 "Do not export to next AS (well-known community)\n"
8736 "community number\n"
8737 "Do not send outside local AS (well-known community)\n"
8738 "Do not advertise to any peer (well-known community)\n"
8739 "Do not export to next AS (well-known community)\n")
8740
8741/* old command */
8742ALIAS (show_ipv6_mbgp_community,
8743 show_ipv6_mbgp_community3_cmd,
8744 "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)",
8745 SHOW_STR
8746 IPV6_STR
8747 MBGP_STR
8748 "Display routes matching the communities\n"
8749 "community number\n"
8750 "Do not send outside local AS (well-known community)\n"
8751 "Do not advertise to any peer (well-known community)\n"
8752 "Do not export to next AS (well-known community)\n"
8753 "community number\n"
8754 "Do not send outside local AS (well-known community)\n"
8755 "Do not advertise to any peer (well-known community)\n"
8756 "Do not export to next AS (well-known community)\n"
8757 "community number\n"
8758 "Do not send outside local AS (well-known community)\n"
8759 "Do not advertise to any peer (well-known community)\n"
8760 "Do not export to next AS (well-known community)\n")
8761
8762/* old command */
8763ALIAS (show_ipv6_mbgp_community,
8764 show_ipv6_mbgp_community4_cmd,
8765 "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)",
8766 SHOW_STR
8767 IPV6_STR
8768 MBGP_STR
8769 "Display routes matching the communities\n"
8770 "community number\n"
8771 "Do not send outside local AS (well-known community)\n"
8772 "Do not advertise to any peer (well-known community)\n"
8773 "Do not export to next AS (well-known community)\n"
8774 "community number\n"
8775 "Do not send outside local AS (well-known community)\n"
8776 "Do not advertise to any peer (well-known community)\n"
8777 "Do not export to next AS (well-known community)\n"
8778 "community number\n"
8779 "Do not send outside local AS (well-known community)\n"
8780 "Do not advertise to any peer (well-known community)\n"
8781 "Do not export to next AS (well-known community)\n"
8782 "community number\n"
8783 "Do not send outside local AS (well-known community)\n"
8784 "Do not advertise to any peer (well-known community)\n"
8785 "Do not export to next AS (well-known community)\n")
8786
8787/* old command */
8788DEFUN (show_ipv6_mbgp_community_exact,
8789 show_ipv6_mbgp_community_exact_cmd,
8790 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8791 SHOW_STR
8792 IPV6_STR
8793 MBGP_STR
8794 "Display routes matching the communities\n"
8795 "community number\n"
8796 "Do not send outside local AS (well-known community)\n"
8797 "Do not advertise to any peer (well-known community)\n"
8798 "Do not export to next AS (well-known community)\n"
8799 "Exact match of the communities")
8800{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008801 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008802}
8803
8804/* old command */
8805ALIAS (show_ipv6_mbgp_community_exact,
8806 show_ipv6_mbgp_community2_exact_cmd,
8807 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8808 SHOW_STR
8809 IPV6_STR
8810 MBGP_STR
8811 "Display routes matching the communities\n"
8812 "community number\n"
8813 "Do not send outside local AS (well-known community)\n"
8814 "Do not advertise to any peer (well-known community)\n"
8815 "Do not export to next AS (well-known community)\n"
8816 "community number\n"
8817 "Do not send outside local AS (well-known community)\n"
8818 "Do not advertise to any peer (well-known community)\n"
8819 "Do not export to next AS (well-known community)\n"
8820 "Exact match of the communities")
8821
8822/* old command */
8823ALIAS (show_ipv6_mbgp_community_exact,
8824 show_ipv6_mbgp_community3_exact_cmd,
8825 "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",
8826 SHOW_STR
8827 IPV6_STR
8828 MBGP_STR
8829 "Display routes matching the communities\n"
8830 "community number\n"
8831 "Do not send outside local AS (well-known community)\n"
8832 "Do not advertise to any peer (well-known community)\n"
8833 "Do not export to next AS (well-known community)\n"
8834 "community number\n"
8835 "Do not send outside local AS (well-known community)\n"
8836 "Do not advertise to any peer (well-known community)\n"
8837 "Do not export to next AS (well-known community)\n"
8838 "community number\n"
8839 "Do not send outside local AS (well-known community)\n"
8840 "Do not advertise to any peer (well-known community)\n"
8841 "Do not export to next AS (well-known community)\n"
8842 "Exact match of the communities")
8843
8844/* old command */
8845ALIAS (show_ipv6_mbgp_community_exact,
8846 show_ipv6_mbgp_community4_exact_cmd,
8847 "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",
8848 SHOW_STR
8849 IPV6_STR
8850 MBGP_STR
8851 "Display routes matching the communities\n"
8852 "community number\n"
8853 "Do not send outside local AS (well-known community)\n"
8854 "Do not advertise to any peer (well-known community)\n"
8855 "Do not export to next AS (well-known community)\n"
8856 "community number\n"
8857 "Do not send outside local AS (well-known community)\n"
8858 "Do not advertise to any peer (well-known community)\n"
8859 "Do not export to next AS (well-known community)\n"
8860 "community number\n"
8861 "Do not send outside local AS (well-known community)\n"
8862 "Do not advertise to any peer (well-known community)\n"
8863 "Do not export to next AS (well-known community)\n"
8864 "community number\n"
8865 "Do not send outside local AS (well-known community)\n"
8866 "Do not advertise to any peer (well-known community)\n"
8867 "Do not export to next AS (well-known community)\n"
8868 "Exact match of the communities")
8869#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02008870
paul94f2b392005-06-28 12:44:16 +00008871static int
paulfd79ac92004-10-13 05:06:08 +00008872bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008873 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008874{
8875 struct community_list *list;
8876
hassofee6e4e2005-02-02 16:29:31 +00008877 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008878 if (list == NULL)
8879 {
8880 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8881 VTY_NEWLINE);
8882 return CMD_WARNING;
8883 }
8884
ajs5a646652004-11-05 01:25:55 +00008885 return bgp_show (vty, NULL, afi, safi,
8886 (exact ? bgp_show_type_community_list_exact :
8887 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008888}
8889
8890DEFUN (show_ip_bgp_community_list,
8891 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008892 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008893 SHOW_STR
8894 IP_STR
8895 BGP_STR
8896 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008897 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008898 "community-list name\n")
8899{
8900 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8901}
8902
8903DEFUN (show_ip_bgp_ipv4_community_list,
8904 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008905 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008906 SHOW_STR
8907 IP_STR
8908 BGP_STR
8909 "Address family\n"
8910 "Address Family modifier\n"
8911 "Address Family modifier\n"
8912 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008913 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008914 "community-list name\n")
8915{
8916 if (strncmp (argv[0], "m", 1) == 0)
8917 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8918
8919 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8920}
8921
8922DEFUN (show_ip_bgp_community_list_exact,
8923 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008924 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008925 SHOW_STR
8926 IP_STR
8927 BGP_STR
8928 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008929 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008930 "community-list name\n"
8931 "Exact match of the communities\n")
8932{
8933 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8934}
8935
8936DEFUN (show_ip_bgp_ipv4_community_list_exact,
8937 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008938 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008939 SHOW_STR
8940 IP_STR
8941 BGP_STR
8942 "Address family\n"
8943 "Address Family modifier\n"
8944 "Address Family modifier\n"
8945 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008946 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008947 "community-list name\n"
8948 "Exact match of the communities\n")
8949{
8950 if (strncmp (argv[0], "m", 1) == 0)
8951 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8952
8953 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8954}
8955
8956#ifdef HAVE_IPV6
8957DEFUN (show_bgp_community_list,
8958 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008959 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008960 SHOW_STR
8961 BGP_STR
8962 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008963 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008964 "community-list name\n")
8965{
8966 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8967}
8968
8969ALIAS (show_bgp_community_list,
8970 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008971 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008972 SHOW_STR
8973 BGP_STR
8974 "Address family\n"
8975 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008976 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008977 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008978
8979/* old command */
8980DEFUN (show_ipv6_bgp_community_list,
8981 show_ipv6_bgp_community_list_cmd,
8982 "show ipv6 bgp community-list WORD",
8983 SHOW_STR
8984 IPV6_STR
8985 BGP_STR
8986 "Display routes matching the community-list\n"
8987 "community-list name\n")
8988{
8989 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8990}
8991
8992/* old command */
8993DEFUN (show_ipv6_mbgp_community_list,
8994 show_ipv6_mbgp_community_list_cmd,
8995 "show ipv6 mbgp community-list WORD",
8996 SHOW_STR
8997 IPV6_STR
8998 MBGP_STR
8999 "Display routes matching the community-list\n"
9000 "community-list name\n")
9001{
9002 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
9003}
9004
9005DEFUN (show_bgp_community_list_exact,
9006 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009007 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009008 SHOW_STR
9009 BGP_STR
9010 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009011 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009012 "community-list name\n"
9013 "Exact match of the communities\n")
9014{
9015 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9016}
9017
9018ALIAS (show_bgp_community_list_exact,
9019 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009020 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009021 SHOW_STR
9022 BGP_STR
9023 "Address family\n"
9024 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009025 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009026 "community-list name\n"
9027 "Exact match of the communities\n")
9028
9029/* old command */
9030DEFUN (show_ipv6_bgp_community_list_exact,
9031 show_ipv6_bgp_community_list_exact_cmd,
9032 "show ipv6 bgp community-list WORD exact-match",
9033 SHOW_STR
9034 IPV6_STR
9035 BGP_STR
9036 "Display routes matching the community-list\n"
9037 "community-list name\n"
9038 "Exact match of the communities\n")
9039{
9040 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9041}
9042
9043/* old command */
9044DEFUN (show_ipv6_mbgp_community_list_exact,
9045 show_ipv6_mbgp_community_list_exact_cmd,
9046 "show ipv6 mbgp community-list WORD exact-match",
9047 SHOW_STR
9048 IPV6_STR
9049 MBGP_STR
9050 "Display routes matching the community-list\n"
9051 "community-list name\n"
9052 "Exact match of the communities\n")
9053{
9054 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9055}
9056#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009057
paul94f2b392005-06-28 12:44:16 +00009058static int
paulfd79ac92004-10-13 05:06:08 +00009059bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009060 safi_t safi, enum bgp_show_type type)
9061{
9062 int ret;
9063 struct prefix *p;
9064
9065 p = prefix_new();
9066
9067 ret = str2prefix (prefix, p);
9068 if (! ret)
9069 {
9070 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9071 return CMD_WARNING;
9072 }
9073
ajs5a646652004-11-05 01:25:55 +00009074 ret = bgp_show (vty, NULL, afi, safi, type, p);
9075 prefix_free(p);
9076 return ret;
paul718e3742002-12-13 20:15:29 +00009077}
9078
9079DEFUN (show_ip_bgp_prefix_longer,
9080 show_ip_bgp_prefix_longer_cmd,
9081 "show ip bgp A.B.C.D/M longer-prefixes",
9082 SHOW_STR
9083 IP_STR
9084 BGP_STR
9085 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9086 "Display route and more specific routes\n")
9087{
9088 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9089 bgp_show_type_prefix_longer);
9090}
9091
9092DEFUN (show_ip_bgp_flap_prefix_longer,
9093 show_ip_bgp_flap_prefix_longer_cmd,
9094 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9095 SHOW_STR
9096 IP_STR
9097 BGP_STR
9098 "Display flap statistics of routes\n"
9099 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9100 "Display route and more specific routes\n")
9101{
9102 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9103 bgp_show_type_flap_prefix_longer);
9104}
9105
9106DEFUN (show_ip_bgp_ipv4_prefix_longer,
9107 show_ip_bgp_ipv4_prefix_longer_cmd,
9108 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9109 SHOW_STR
9110 IP_STR
9111 BGP_STR
9112 "Address family\n"
9113 "Address Family modifier\n"
9114 "Address Family modifier\n"
9115 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9116 "Display route and more specific routes\n")
9117{
9118 if (strncmp (argv[0], "m", 1) == 0)
9119 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9120 bgp_show_type_prefix_longer);
9121
9122 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9123 bgp_show_type_prefix_longer);
9124}
9125
9126DEFUN (show_ip_bgp_flap_address,
9127 show_ip_bgp_flap_address_cmd,
9128 "show ip bgp flap-statistics A.B.C.D",
9129 SHOW_STR
9130 IP_STR
9131 BGP_STR
9132 "Display flap statistics of routes\n"
9133 "Network in the BGP routing table to display\n")
9134{
9135 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9136 bgp_show_type_flap_address);
9137}
9138
9139DEFUN (show_ip_bgp_flap_prefix,
9140 show_ip_bgp_flap_prefix_cmd,
9141 "show ip bgp flap-statistics A.B.C.D/M",
9142 SHOW_STR
9143 IP_STR
9144 BGP_STR
9145 "Display flap statistics of routes\n"
9146 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9147{
9148 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9149 bgp_show_type_flap_prefix);
9150}
9151#ifdef HAVE_IPV6
9152DEFUN (show_bgp_prefix_longer,
9153 show_bgp_prefix_longer_cmd,
9154 "show bgp X:X::X:X/M longer-prefixes",
9155 SHOW_STR
9156 BGP_STR
9157 "IPv6 prefix <network>/<length>\n"
9158 "Display route and more specific routes\n")
9159{
9160 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9161 bgp_show_type_prefix_longer);
9162}
9163
9164ALIAS (show_bgp_prefix_longer,
9165 show_bgp_ipv6_prefix_longer_cmd,
9166 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9167 SHOW_STR
9168 BGP_STR
9169 "Address family\n"
9170 "IPv6 prefix <network>/<length>\n"
9171 "Display route and more specific routes\n")
9172
9173/* old command */
9174DEFUN (show_ipv6_bgp_prefix_longer,
9175 show_ipv6_bgp_prefix_longer_cmd,
9176 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9177 SHOW_STR
9178 IPV6_STR
9179 BGP_STR
9180 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9181 "Display route and more specific routes\n")
9182{
9183 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9184 bgp_show_type_prefix_longer);
9185}
9186
9187/* old command */
9188DEFUN (show_ipv6_mbgp_prefix_longer,
9189 show_ipv6_mbgp_prefix_longer_cmd,
9190 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9191 SHOW_STR
9192 IPV6_STR
9193 MBGP_STR
9194 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9195 "Display route and more specific routes\n")
9196{
9197 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9198 bgp_show_type_prefix_longer);
9199}
9200#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009201
paul94f2b392005-06-28 12:44:16 +00009202static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009203peer_lookup_in_view (struct vty *vty, const char *view_name,
9204 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009205{
9206 int ret;
9207 struct bgp *bgp;
9208 struct peer *peer;
9209 union sockunion su;
9210
9211 /* BGP structure lookup. */
9212 if (view_name)
9213 {
9214 bgp = bgp_lookup_by_name (view_name);
9215 if (! bgp)
9216 {
9217 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9218 return NULL;
9219 }
9220 }
paul5228ad22004-06-04 17:58:18 +00009221 else
paulbb46e942003-10-24 19:02:03 +00009222 {
9223 bgp = bgp_get_default ();
9224 if (! bgp)
9225 {
9226 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9227 return NULL;
9228 }
9229 }
9230
9231 /* Get peer sockunion. */
9232 ret = str2sockunion (ip_str, &su);
9233 if (ret < 0)
9234 {
9235 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9236 return NULL;
9237 }
9238
9239 /* Peer structure lookup. */
9240 peer = peer_lookup (bgp, &su);
9241 if (! peer)
9242 {
9243 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9244 return NULL;
9245 }
9246
9247 return peer;
9248}
David Lamparter6b0655a2014-06-04 06:53:35 +02009249
Paul Jakma2815e612006-09-14 02:56:07 +00009250enum bgp_stats
9251{
9252 BGP_STATS_MAXBITLEN = 0,
9253 BGP_STATS_RIB,
9254 BGP_STATS_PREFIXES,
9255 BGP_STATS_TOTPLEN,
9256 BGP_STATS_UNAGGREGATEABLE,
9257 BGP_STATS_MAX_AGGREGATEABLE,
9258 BGP_STATS_AGGREGATES,
9259 BGP_STATS_SPACE,
9260 BGP_STATS_ASPATH_COUNT,
9261 BGP_STATS_ASPATH_MAXHOPS,
9262 BGP_STATS_ASPATH_TOTHOPS,
9263 BGP_STATS_ASPATH_MAXSIZE,
9264 BGP_STATS_ASPATH_TOTSIZE,
9265 BGP_STATS_ASN_HIGHEST,
9266 BGP_STATS_MAX,
9267};
paulbb46e942003-10-24 19:02:03 +00009268
Paul Jakma2815e612006-09-14 02:56:07 +00009269static const char *table_stats_strs[] =
9270{
9271 [BGP_STATS_PREFIXES] = "Total Prefixes",
9272 [BGP_STATS_TOTPLEN] = "Average prefix length",
9273 [BGP_STATS_RIB] = "Total Advertisements",
9274 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9275 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9276 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9277 [BGP_STATS_SPACE] = "Address space advertised",
9278 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9279 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9280 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9281 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9282 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9283 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9284 [BGP_STATS_MAX] = NULL,
9285};
9286
9287struct bgp_table_stats
9288{
9289 struct bgp_table *table;
9290 unsigned long long counts[BGP_STATS_MAX];
9291};
9292
9293#if 0
9294#define TALLY_SIGFIG 100000
9295static unsigned long
9296ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9297{
9298 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9299 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9300 unsigned long ret = newtot / count;
9301
9302 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9303 return ret + 1;
9304 else
9305 return ret;
9306}
9307#endif
9308
9309static int
9310bgp_table_stats_walker (struct thread *t)
9311{
9312 struct bgp_node *rn;
9313 struct bgp_node *top;
9314 struct bgp_table_stats *ts = THREAD_ARG (t);
9315 unsigned int space = 0;
9316
Paul Jakma53d9f672006-10-15 23:41:16 +00009317 if (!(top = bgp_table_top (ts->table)))
9318 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009319
9320 switch (top->p.family)
9321 {
9322 case AF_INET:
9323 space = IPV4_MAX_BITLEN;
9324 break;
9325 case AF_INET6:
9326 space = IPV6_MAX_BITLEN;
9327 break;
9328 }
9329
9330 ts->counts[BGP_STATS_MAXBITLEN] = space;
9331
9332 for (rn = top; rn; rn = bgp_route_next (rn))
9333 {
9334 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009335 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009336 unsigned int rinum = 0;
9337
9338 if (rn == top)
9339 continue;
9340
9341 if (!rn->info)
9342 continue;
9343
9344 ts->counts[BGP_STATS_PREFIXES]++;
9345 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9346
9347#if 0
9348 ts->counts[BGP_STATS_AVGPLEN]
9349 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9350 ts->counts[BGP_STATS_AVGPLEN],
9351 rn->p.prefixlen);
9352#endif
9353
9354 /* check if the prefix is included by any other announcements */
9355 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009356 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009357
9358 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009359 {
9360 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9361 /* announced address space */
9362 if (space)
9363 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9364 }
Paul Jakma2815e612006-09-14 02:56:07 +00009365 else if (prn->info)
9366 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9367
Paul Jakma2815e612006-09-14 02:56:07 +00009368 for (ri = rn->info; ri; ri = ri->next)
9369 {
9370 rinum++;
9371 ts->counts[BGP_STATS_RIB]++;
9372
9373 if (ri->attr &&
9374 (CHECK_FLAG (ri->attr->flag,
9375 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9376 ts->counts[BGP_STATS_AGGREGATES]++;
9377
9378 /* as-path stats */
9379 if (ri->attr && ri->attr->aspath)
9380 {
9381 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9382 unsigned int size = aspath_size (ri->attr->aspath);
9383 as_t highest = aspath_highest (ri->attr->aspath);
9384
9385 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9386
9387 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9388 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9389
9390 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9391 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9392
9393 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9394 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9395#if 0
9396 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9397 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9398 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9399 hops);
9400 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9401 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9402 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9403 size);
9404#endif
9405 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9406 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9407 }
9408 }
9409 }
9410 return 0;
9411}
9412
9413static int
9414bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9415{
9416 struct bgp_table_stats ts;
9417 unsigned int i;
9418
9419 if (!bgp->rib[afi][safi])
9420 {
9421 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9422 return CMD_WARNING;
9423 }
9424
9425 memset (&ts, 0, sizeof (ts));
9426 ts.table = bgp->rib[afi][safi];
9427 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9428
9429 vty_out (vty, "BGP %s RIB statistics%s%s",
9430 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9431
9432 for (i = 0; i < BGP_STATS_MAX; i++)
9433 {
9434 if (!table_stats_strs[i])
9435 continue;
9436
9437 switch (i)
9438 {
9439#if 0
9440 case BGP_STATS_ASPATH_AVGHOPS:
9441 case BGP_STATS_ASPATH_AVGSIZE:
9442 case BGP_STATS_AVGPLEN:
9443 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9444 vty_out (vty, "%12.2f",
9445 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9446 break;
9447#endif
9448 case BGP_STATS_ASPATH_TOTHOPS:
9449 case BGP_STATS_ASPATH_TOTSIZE:
9450 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9451 vty_out (vty, "%12.2f",
9452 ts.counts[i] ?
9453 (float)ts.counts[i] /
9454 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9455 : 0);
9456 break;
9457 case BGP_STATS_TOTPLEN:
9458 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9459 vty_out (vty, "%12.2f",
9460 ts.counts[i] ?
9461 (float)ts.counts[i] /
9462 (float)ts.counts[BGP_STATS_PREFIXES]
9463 : 0);
9464 break;
9465 case BGP_STATS_SPACE:
9466 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9467 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9468 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9469 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009470 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009471 vty_out (vty, "%12.2f%s",
9472 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009473 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009474 VTY_NEWLINE);
9475 vty_out (vty, "%30s: ", "/8 equivalent ");
9476 vty_out (vty, "%12.2f%s",
9477 (float)ts.counts[BGP_STATS_SPACE] /
9478 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9479 VTY_NEWLINE);
9480 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9481 break;
9482 vty_out (vty, "%30s: ", "/24 equivalent ");
9483 vty_out (vty, "%12.2f",
9484 (float)ts.counts[BGP_STATS_SPACE] /
9485 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9486 break;
9487 default:
9488 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9489 vty_out (vty, "%12llu", ts.counts[i]);
9490 }
9491
9492 vty_out (vty, "%s", VTY_NEWLINE);
9493 }
9494 return CMD_SUCCESS;
9495}
9496
9497static int
9498bgp_table_stats_vty (struct vty *vty, const char *name,
9499 const char *afi_str, const char *safi_str)
9500{
9501 struct bgp *bgp;
9502 afi_t afi;
9503 safi_t safi;
9504
9505 if (name)
9506 bgp = bgp_lookup_by_name (name);
9507 else
9508 bgp = bgp_get_default ();
9509
9510 if (!bgp)
9511 {
9512 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9513 return CMD_WARNING;
9514 }
9515 if (strncmp (afi_str, "ipv", 3) == 0)
9516 {
9517 if (strncmp (afi_str, "ipv4", 4) == 0)
9518 afi = AFI_IP;
9519 else if (strncmp (afi_str, "ipv6", 4) == 0)
9520 afi = AFI_IP6;
9521 else
9522 {
9523 vty_out (vty, "%% Invalid address family %s%s",
9524 afi_str, VTY_NEWLINE);
9525 return CMD_WARNING;
9526 }
9527 if (strncmp (safi_str, "m", 1) == 0)
9528 safi = SAFI_MULTICAST;
9529 else if (strncmp (safi_str, "u", 1) == 0)
9530 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009531 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9532 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009533 else
9534 {
9535 vty_out (vty, "%% Invalid subsequent address family %s%s",
9536 safi_str, VTY_NEWLINE);
9537 return CMD_WARNING;
9538 }
9539 }
9540 else
9541 {
9542 vty_out (vty, "%% Invalid address family %s%s",
9543 afi_str, VTY_NEWLINE);
9544 return CMD_WARNING;
9545 }
9546
Paul Jakma2815e612006-09-14 02:56:07 +00009547 return bgp_table_stats (vty, bgp, afi, safi);
9548}
9549
9550DEFUN (show_bgp_statistics,
9551 show_bgp_statistics_cmd,
9552 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9553 SHOW_STR
9554 BGP_STR
9555 "Address family\n"
9556 "Address family\n"
9557 "Address Family modifier\n"
9558 "Address Family modifier\n"
9559 "BGP RIB advertisement statistics\n")
9560{
9561 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9562}
9563
9564ALIAS (show_bgp_statistics,
9565 show_bgp_statistics_vpnv4_cmd,
9566 "show bgp (ipv4) (vpnv4) statistics",
9567 SHOW_STR
9568 BGP_STR
9569 "Address family\n"
9570 "Address Family modifier\n"
9571 "BGP RIB advertisement statistics\n")
9572
9573DEFUN (show_bgp_statistics_view,
9574 show_bgp_statistics_view_cmd,
9575 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9576 SHOW_STR
9577 BGP_STR
9578 "BGP view\n"
9579 "Address family\n"
9580 "Address family\n"
9581 "Address Family modifier\n"
9582 "Address Family modifier\n"
9583 "BGP RIB advertisement statistics\n")
9584{
9585 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9586}
9587
9588ALIAS (show_bgp_statistics_view,
9589 show_bgp_statistics_view_vpnv4_cmd,
9590 "show bgp view WORD (ipv4) (vpnv4) statistics",
9591 SHOW_STR
9592 BGP_STR
9593 "BGP view\n"
9594 "Address family\n"
9595 "Address Family modifier\n"
9596 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02009597
Paul Jakmaff7924f2006-09-04 01:10:36 +00009598enum bgp_pcounts
9599{
9600 PCOUNT_ADJ_IN = 0,
9601 PCOUNT_DAMPED,
9602 PCOUNT_REMOVED,
9603 PCOUNT_HISTORY,
9604 PCOUNT_STALE,
9605 PCOUNT_VALID,
9606 PCOUNT_ALL,
9607 PCOUNT_COUNTED,
9608 PCOUNT_PFCNT, /* the figure we display to users */
9609 PCOUNT_MAX,
9610};
9611
9612static const char *pcount_strs[] =
9613{
9614 [PCOUNT_ADJ_IN] = "Adj-in",
9615 [PCOUNT_DAMPED] = "Damped",
9616 [PCOUNT_REMOVED] = "Removed",
9617 [PCOUNT_HISTORY] = "History",
9618 [PCOUNT_STALE] = "Stale",
9619 [PCOUNT_VALID] = "Valid",
9620 [PCOUNT_ALL] = "All RIB",
9621 [PCOUNT_COUNTED] = "PfxCt counted",
9622 [PCOUNT_PFCNT] = "Useable",
9623 [PCOUNT_MAX] = NULL,
9624};
9625
Paul Jakma2815e612006-09-14 02:56:07 +00009626struct peer_pcounts
9627{
9628 unsigned int count[PCOUNT_MAX];
9629 const struct peer *peer;
9630 const struct bgp_table *table;
9631};
9632
Paul Jakmaff7924f2006-09-04 01:10:36 +00009633static int
Paul Jakma2815e612006-09-14 02:56:07 +00009634bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009635{
9636 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009637 struct peer_pcounts *pc = THREAD_ARG (t);
9638 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009639
Paul Jakma2815e612006-09-14 02:56:07 +00009640 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009641 {
9642 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009643 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009644
9645 for (ain = rn->adj_in; ain; ain = ain->next)
9646 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009647 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009648
Paul Jakmaff7924f2006-09-04 01:10:36 +00009649 for (ri = rn->info; ri; ri = ri->next)
9650 {
9651 char buf[SU_ADDRSTRLEN];
9652
9653 if (ri->peer != peer)
9654 continue;
9655
Paul Jakma2815e612006-09-14 02:56:07 +00009656 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009657
9658 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009659 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009660 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009661 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009662 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009663 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009664 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009665 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009666 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009667 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009668 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009669 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009670
9671 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9672 {
Paul Jakma2815e612006-09-14 02:56:07 +00009673 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009674 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009675 plog_warn (peer->log,
9676 "%s [pcount] %s/%d is counted but flags 0x%x",
9677 peer->host,
9678 inet_ntop(rn->p.family, &rn->p.u.prefix,
9679 buf, SU_ADDRSTRLEN),
9680 rn->p.prefixlen,
9681 ri->flags);
9682 }
9683 else
9684 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009685 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009686 plog_warn (peer->log,
9687 "%s [pcount] %s/%d not counted but flags 0x%x",
9688 peer->host,
9689 inet_ntop(rn->p.family, &rn->p.u.prefix,
9690 buf, SU_ADDRSTRLEN),
9691 rn->p.prefixlen,
9692 ri->flags);
9693 }
9694 }
9695 }
Paul Jakma2815e612006-09-14 02:56:07 +00009696 return 0;
9697}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009698
Paul Jakma2815e612006-09-14 02:56:07 +00009699static int
9700bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9701{
9702 struct peer_pcounts pcounts = { .peer = peer };
9703 unsigned int i;
9704
9705 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9706 || !peer->bgp->rib[afi][safi])
9707 {
9708 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9709 return CMD_WARNING;
9710 }
9711
9712 memset (&pcounts, 0, sizeof(pcounts));
9713 pcounts.peer = peer;
9714 pcounts.table = peer->bgp->rib[afi][safi];
9715
9716 /* in-place call via thread subsystem so as to record execution time
9717 * stats for the thread-walk (i.e. ensure this can't be blamed on
9718 * on just vty_read()).
9719 */
9720 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9721
Paul Jakmaff7924f2006-09-04 01:10:36 +00009722 vty_out (vty, "Prefix counts for %s, %s%s",
9723 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9724 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9725 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9726 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9727
9728 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009729 vty_out (vty, "%20s: %-10d%s",
9730 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009731
Paul Jakma2815e612006-09-14 02:56:07 +00009732 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009733 {
9734 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9735 peer->host, VTY_NEWLINE);
9736 vty_out (vty, "Please report this bug, with the above command output%s",
9737 VTY_NEWLINE);
9738 }
9739
9740 return CMD_SUCCESS;
9741}
9742
9743DEFUN (show_ip_bgp_neighbor_prefix_counts,
9744 show_ip_bgp_neighbor_prefix_counts_cmd,
9745 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9746 SHOW_STR
9747 IP_STR
9748 BGP_STR
9749 "Detailed information on TCP and BGP neighbor connections\n"
9750 "Neighbor to display information about\n"
9751 "Neighbor to display information about\n"
9752 "Display detailed prefix count information\n")
9753{
9754 struct peer *peer;
9755
9756 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9757 if (! peer)
9758 return CMD_WARNING;
9759
9760 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9761}
9762
9763DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9764 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9765 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9766 SHOW_STR
9767 BGP_STR
9768 "Address family\n"
9769 "Detailed information on TCP and BGP neighbor connections\n"
9770 "Neighbor to display information about\n"
9771 "Neighbor to display information about\n"
9772 "Display detailed prefix count information\n")
9773{
9774 struct peer *peer;
9775
9776 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9777 if (! peer)
9778 return CMD_WARNING;
9779
9780 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9781}
9782
9783DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9784 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9785 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9786 SHOW_STR
9787 IP_STR
9788 BGP_STR
9789 "Address family\n"
9790 "Address Family modifier\n"
9791 "Address Family modifier\n"
9792 "Detailed information on TCP and BGP neighbor connections\n"
9793 "Neighbor to display information about\n"
9794 "Neighbor to display information about\n"
9795 "Display detailed prefix count information\n")
9796{
9797 struct peer *peer;
9798
9799 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9800 if (! peer)
9801 return CMD_WARNING;
9802
9803 if (strncmp (argv[0], "m", 1) == 0)
9804 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9805
9806 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9807}
9808
9809DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9810 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9811 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9812 SHOW_STR
9813 IP_STR
9814 BGP_STR
9815 "Address family\n"
9816 "Address Family modifier\n"
9817 "Address Family modifier\n"
9818 "Detailed information on TCP and BGP neighbor connections\n"
9819 "Neighbor to display information about\n"
9820 "Neighbor to display information about\n"
9821 "Display detailed prefix count information\n")
9822{
9823 struct peer *peer;
9824
9825 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9826 if (! peer)
9827 return CMD_WARNING;
9828
9829 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9830}
9831
9832
paul94f2b392005-06-28 12:44:16 +00009833static void
paul718e3742002-12-13 20:15:29 +00009834show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9835 int in)
9836{
9837 struct bgp_table *table;
9838 struct bgp_adj_in *ain;
9839 struct bgp_adj_out *adj;
9840 unsigned long output_count;
9841 struct bgp_node *rn;
9842 int header1 = 1;
9843 struct bgp *bgp;
9844 int header2 = 1;
9845
paulbb46e942003-10-24 19:02:03 +00009846 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009847
9848 if (! bgp)
9849 return;
9850
9851 table = bgp->rib[afi][safi];
9852
9853 output_count = 0;
9854
9855 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9856 PEER_STATUS_DEFAULT_ORIGINATE))
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
9862 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9863 VTY_NEWLINE, VTY_NEWLINE);
9864 header1 = 0;
9865 }
9866
9867 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9868 if (in)
9869 {
9870 for (ain = rn->adj_in; ain; ain = ain->next)
9871 if (ain->peer == peer)
9872 {
9873 if (header1)
9874 {
9875 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 +00009876 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9877 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009878 header1 = 0;
9879 }
9880 if (header2)
9881 {
9882 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9883 header2 = 0;
9884 }
9885 if (ain->attr)
9886 {
9887 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9888 output_count++;
9889 }
9890 }
9891 }
9892 else
9893 {
9894 for (adj = rn->adj_out; adj; adj = adj->next)
9895 if (adj->peer == peer)
9896 {
9897 if (header1)
9898 {
9899 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 +00009900 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9901 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009902 header1 = 0;
9903 }
9904 if (header2)
9905 {
9906 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9907 header2 = 0;
9908 }
9909 if (adj->attr)
9910 {
9911 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9912 output_count++;
9913 }
9914 }
9915 }
9916
9917 if (output_count != 0)
9918 vty_out (vty, "%sTotal number of prefixes %ld%s",
9919 VTY_NEWLINE, output_count, VTY_NEWLINE);
9920}
9921
paul94f2b392005-06-28 12:44:16 +00009922static int
paulbb46e942003-10-24 19:02:03 +00009923peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9924{
paul718e3742002-12-13 20:15:29 +00009925 if (! peer || ! peer->afc[afi][safi])
9926 {
9927 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9928 return CMD_WARNING;
9929 }
9930
9931 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9932 {
9933 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9934 VTY_NEWLINE);
9935 return CMD_WARNING;
9936 }
9937
9938 show_adj_route (vty, peer, afi, safi, in);
9939
9940 return CMD_SUCCESS;
9941}
9942
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009943DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9944 show_ip_bgp_view_neighbor_advertised_route_cmd,
9945 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9946 SHOW_STR
9947 IP_STR
9948 BGP_STR
9949 "BGP view\n"
9950 "View name\n"
9951 "Detailed information on TCP and BGP neighbor connections\n"
9952 "Neighbor to display information about\n"
9953 "Neighbor to display information about\n"
9954 "Display the routes advertised to a BGP neighbor\n")
9955{
9956 struct peer *peer;
9957
9958 if (argc == 2)
9959 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9960 else
9961 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9962
9963 if (! peer)
9964 return CMD_WARNING;
9965
9966 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9967}
9968
9969ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009970 show_ip_bgp_neighbor_advertised_route_cmd,
9971 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9972 SHOW_STR
9973 IP_STR
9974 BGP_STR
9975 "Detailed information on TCP and BGP neighbor connections\n"
9976 "Neighbor to display information about\n"
9977 "Neighbor to display information about\n"
9978 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009979
9980DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9981 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9982 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9983 SHOW_STR
9984 IP_STR
9985 BGP_STR
9986 "Address family\n"
9987 "Address Family modifier\n"
9988 "Address Family modifier\n"
9989 "Detailed information on TCP and BGP neighbor connections\n"
9990 "Neighbor to display information about\n"
9991 "Neighbor to display information about\n"
9992 "Display the routes advertised to a BGP neighbor\n")
9993{
paulbb46e942003-10-24 19:02:03 +00009994 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009995
paulbb46e942003-10-24 19:02:03 +00009996 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9997 if (! peer)
9998 return CMD_WARNING;
9999
10000 if (strncmp (argv[0], "m", 1) == 0)
10001 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
10002
10003 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +000010004}
10005
10006#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010007DEFUN (show_bgp_view_neighbor_advertised_route,
10008 show_bgp_view_neighbor_advertised_route_cmd,
10009 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10010 SHOW_STR
10011 BGP_STR
10012 "BGP view\n"
10013 "View name\n"
10014 "Detailed information on TCP and BGP neighbor connections\n"
10015 "Neighbor to display information about\n"
10016 "Neighbor to display information about\n"
10017 "Display the routes advertised to a BGP neighbor\n")
10018{
10019 struct peer *peer;
10020
10021 if (argc == 2)
10022 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10023 else
10024 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10025
10026 if (! peer)
10027 return CMD_WARNING;
10028
10029 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10030}
10031
10032ALIAS (show_bgp_view_neighbor_advertised_route,
10033 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10034 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10035 SHOW_STR
10036 BGP_STR
10037 "BGP view\n"
10038 "View name\n"
10039 "Address family\n"
10040 "Detailed information on TCP and BGP neighbor connections\n"
10041 "Neighbor to display information about\n"
10042 "Neighbor to display information about\n"
10043 "Display the routes advertised to a BGP neighbor\n")
10044
10045DEFUN (show_bgp_view_neighbor_received_routes,
10046 show_bgp_view_neighbor_received_routes_cmd,
10047 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10048 SHOW_STR
10049 BGP_STR
10050 "BGP view\n"
10051 "View name\n"
10052 "Detailed information on TCP and BGP neighbor connections\n"
10053 "Neighbor to display information about\n"
10054 "Neighbor to display information about\n"
10055 "Display the received routes from neighbor\n")
10056{
10057 struct peer *peer;
10058
10059 if (argc == 2)
10060 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10061 else
10062 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10063
10064 if (! peer)
10065 return CMD_WARNING;
10066
10067 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10068}
10069
10070ALIAS (show_bgp_view_neighbor_received_routes,
10071 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10072 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10073 SHOW_STR
10074 BGP_STR
10075 "BGP view\n"
10076 "View name\n"
10077 "Address family\n"
10078 "Detailed information on TCP and BGP neighbor connections\n"
10079 "Neighbor to display information about\n"
10080 "Neighbor to display information about\n"
10081 "Display the received routes from neighbor\n")
10082
10083ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010084 show_bgp_neighbor_advertised_route_cmd,
10085 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10086 SHOW_STR
10087 BGP_STR
10088 "Detailed information on TCP and BGP neighbor connections\n"
10089 "Neighbor to display information about\n"
10090 "Neighbor to display information about\n"
10091 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010092
10093ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010094 show_bgp_ipv6_neighbor_advertised_route_cmd,
10095 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10096 SHOW_STR
10097 BGP_STR
10098 "Address family\n"
10099 "Detailed information on TCP and BGP neighbor connections\n"
10100 "Neighbor to display information about\n"
10101 "Neighbor to display information about\n"
10102 "Display the routes advertised to a BGP neighbor\n")
10103
10104/* old command */
paulbb46e942003-10-24 19:02:03 +000010105ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010106 ipv6_bgp_neighbor_advertised_route_cmd,
10107 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10108 SHOW_STR
10109 IPV6_STR
10110 BGP_STR
10111 "Detailed information on TCP and BGP neighbor connections\n"
10112 "Neighbor to display information about\n"
10113 "Neighbor to display information about\n"
10114 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010115
paul718e3742002-12-13 20:15:29 +000010116/* old command */
10117DEFUN (ipv6_mbgp_neighbor_advertised_route,
10118 ipv6_mbgp_neighbor_advertised_route_cmd,
10119 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10120 SHOW_STR
10121 IPV6_STR
10122 MBGP_STR
10123 "Detailed information on TCP and BGP neighbor connections\n"
10124 "Neighbor to display information about\n"
10125 "Neighbor to display information about\n"
10126 "Display the routes advertised to a BGP neighbor\n")
10127{
paulbb46e942003-10-24 19:02:03 +000010128 struct peer *peer;
10129
10130 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10131 if (! peer)
10132 return CMD_WARNING;
10133
10134 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010135}
10136#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010137
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010138DEFUN (show_ip_bgp_view_neighbor_received_routes,
10139 show_ip_bgp_view_neighbor_received_routes_cmd,
10140 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10141 SHOW_STR
10142 IP_STR
10143 BGP_STR
10144 "BGP view\n"
10145 "View name\n"
10146 "Detailed information on TCP and BGP neighbor connections\n"
10147 "Neighbor to display information about\n"
10148 "Neighbor to display information about\n"
10149 "Display the received routes from neighbor\n")
10150{
10151 struct peer *peer;
10152
10153 if (argc == 2)
10154 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10155 else
10156 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10157
10158 if (! peer)
10159 return CMD_WARNING;
10160
10161 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10162}
10163
10164ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010165 show_ip_bgp_neighbor_received_routes_cmd,
10166 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10167 SHOW_STR
10168 IP_STR
10169 BGP_STR
10170 "Detailed information on TCP and BGP neighbor connections\n"
10171 "Neighbor to display information about\n"
10172 "Neighbor to display information about\n"
10173 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010174
10175DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10176 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10177 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10178 SHOW_STR
10179 IP_STR
10180 BGP_STR
10181 "Address family\n"
10182 "Address Family modifier\n"
10183 "Address Family modifier\n"
10184 "Detailed information on TCP and BGP neighbor connections\n"
10185 "Neighbor to display information about\n"
10186 "Neighbor to display information about\n"
10187 "Display the received routes from neighbor\n")
10188{
paulbb46e942003-10-24 19:02:03 +000010189 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010190
paulbb46e942003-10-24 19:02:03 +000010191 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10192 if (! peer)
10193 return CMD_WARNING;
10194
10195 if (strncmp (argv[0], "m", 1) == 0)
10196 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10197
10198 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010199}
10200
Michael Lambert95cbbd22010-07-23 14:43:04 -040010201DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10202 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10203#ifdef HAVE_IPV6
10204 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10205#else
10206 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10207#endif
10208 SHOW_STR
10209 BGP_STR
10210 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010211 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010212 "Address family\n"
10213#ifdef HAVE_IPV6
10214 "Address family\n"
10215#endif
10216 "Address family modifier\n"
10217 "Address family modifier\n"
10218 "Detailed information on TCP and BGP neighbor connections\n"
10219 "Neighbor to display information about\n"
10220 "Neighbor to display information about\n"
10221 "Display the advertised routes to neighbor\n"
10222 "Display the received routes from neighbor\n")
10223{
10224 int afi;
10225 int safi;
10226 int in;
10227 struct peer *peer;
10228
10229#ifdef HAVE_IPV6
10230 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10231#else
10232 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10233#endif
10234
10235 if (! peer)
10236 return CMD_WARNING;
10237
10238#ifdef HAVE_IPV6
10239 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10240 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10241 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10242#else
10243 afi = AFI_IP;
10244 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10245 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10246#endif
10247
10248 return peer_adj_routes (vty, peer, afi, safi, in);
10249}
10250
paul718e3742002-12-13 20:15:29 +000010251DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10252 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10253 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10254 SHOW_STR
10255 IP_STR
10256 BGP_STR
10257 "Detailed information on TCP and BGP neighbor connections\n"
10258 "Neighbor to display information about\n"
10259 "Neighbor to display information about\n"
10260 "Display information received from a BGP neighbor\n"
10261 "Display the prefixlist filter\n")
10262{
10263 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010264 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010265 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010266 int count, ret;
paul718e3742002-12-13 20:15:29 +000010267
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010268 ret = str2sockunion (argv[0], &su);
10269 if (ret < 0)
10270 {
10271 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10272 return CMD_WARNING;
10273 }
paul718e3742002-12-13 20:15:29 +000010274
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010275 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010276 if (! peer)
10277 return CMD_WARNING;
10278
10279 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10280 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10281 if (count)
10282 {
10283 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10284 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10285 }
10286
10287 return CMD_SUCCESS;
10288}
10289
10290DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10291 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10292 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10293 SHOW_STR
10294 IP_STR
10295 BGP_STR
10296 "Address family\n"
10297 "Address Family modifier\n"
10298 "Address Family modifier\n"
10299 "Detailed information on TCP and BGP neighbor connections\n"
10300 "Neighbor to display information about\n"
10301 "Neighbor to display information about\n"
10302 "Display information received from a BGP neighbor\n"
10303 "Display the prefixlist filter\n")
10304{
10305 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010306 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010307 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010308 int count, ret;
paul718e3742002-12-13 20:15:29 +000010309
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010310 ret = str2sockunion (argv[1], &su);
10311 if (ret < 0)
10312 {
10313 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10314 return CMD_WARNING;
10315 }
paul718e3742002-12-13 20:15:29 +000010316
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010317 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010318 if (! peer)
10319 return CMD_WARNING;
10320
10321 if (strncmp (argv[0], "m", 1) == 0)
10322 {
10323 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10324 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10325 if (count)
10326 {
10327 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10328 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10329 }
10330 }
10331 else
10332 {
10333 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10334 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10335 if (count)
10336 {
10337 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10338 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10339 }
10340 }
10341
10342 return CMD_SUCCESS;
10343}
10344
10345
10346#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010347ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010348 show_bgp_neighbor_received_routes_cmd,
10349 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10350 SHOW_STR
10351 BGP_STR
10352 "Detailed information on TCP and BGP neighbor connections\n"
10353 "Neighbor to display information about\n"
10354 "Neighbor to display information about\n"
10355 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010356
paulbb46e942003-10-24 19:02:03 +000010357ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010358 show_bgp_ipv6_neighbor_received_routes_cmd,
10359 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10360 SHOW_STR
10361 BGP_STR
10362 "Address family\n"
10363 "Detailed information on TCP and BGP neighbor connections\n"
10364 "Neighbor to display information about\n"
10365 "Neighbor to display information about\n"
10366 "Display the received routes from neighbor\n")
10367
10368DEFUN (show_bgp_neighbor_received_prefix_filter,
10369 show_bgp_neighbor_received_prefix_filter_cmd,
10370 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10371 SHOW_STR
10372 BGP_STR
10373 "Detailed information on TCP and BGP neighbor connections\n"
10374 "Neighbor to display information about\n"
10375 "Neighbor to display information about\n"
10376 "Display information received from a BGP neighbor\n"
10377 "Display the prefixlist filter\n")
10378{
10379 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010380 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010381 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010382 int count, ret;
paul718e3742002-12-13 20:15:29 +000010383
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010384 ret = str2sockunion (argv[0], &su);
10385 if (ret < 0)
10386 {
10387 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10388 return CMD_WARNING;
10389 }
paul718e3742002-12-13 20:15:29 +000010390
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010391 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010392 if (! peer)
10393 return CMD_WARNING;
10394
10395 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10396 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10397 if (count)
10398 {
10399 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10400 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10401 }
10402
10403 return CMD_SUCCESS;
10404}
10405
10406ALIAS (show_bgp_neighbor_received_prefix_filter,
10407 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10408 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10409 SHOW_STR
10410 BGP_STR
10411 "Address family\n"
10412 "Detailed information on TCP and BGP neighbor connections\n"
10413 "Neighbor to display information about\n"
10414 "Neighbor to display information about\n"
10415 "Display information received from a BGP neighbor\n"
10416 "Display the prefixlist filter\n")
10417
10418/* old command */
paulbb46e942003-10-24 19:02:03 +000010419ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010420 ipv6_bgp_neighbor_received_routes_cmd,
10421 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10422 SHOW_STR
10423 IPV6_STR
10424 BGP_STR
10425 "Detailed information on TCP and BGP neighbor connections\n"
10426 "Neighbor to display information about\n"
10427 "Neighbor to display information about\n"
10428 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010429
10430/* old command */
10431DEFUN (ipv6_mbgp_neighbor_received_routes,
10432 ipv6_mbgp_neighbor_received_routes_cmd,
10433 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10434 SHOW_STR
10435 IPV6_STR
10436 MBGP_STR
10437 "Detailed information on TCP and BGP neighbor connections\n"
10438 "Neighbor to display information about\n"
10439 "Neighbor to display information about\n"
10440 "Display the received routes from neighbor\n")
10441{
paulbb46e942003-10-24 19:02:03 +000010442 struct peer *peer;
10443
10444 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10445 if (! peer)
10446 return CMD_WARNING;
10447
10448 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010449}
paulbb46e942003-10-24 19:02:03 +000010450
10451DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10452 show_bgp_view_neighbor_received_prefix_filter_cmd,
10453 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10454 SHOW_STR
10455 BGP_STR
10456 "BGP view\n"
10457 "View name\n"
10458 "Detailed information on TCP and BGP neighbor connections\n"
10459 "Neighbor to display information about\n"
10460 "Neighbor to display information about\n"
10461 "Display information received from a BGP neighbor\n"
10462 "Display the prefixlist filter\n")
10463{
10464 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010465 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010466 struct peer *peer;
10467 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010468 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010469
10470 /* BGP structure lookup. */
10471 bgp = bgp_lookup_by_name (argv[0]);
10472 if (bgp == NULL)
10473 {
10474 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10475 return CMD_WARNING;
10476 }
10477
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010478 ret = str2sockunion (argv[1], &su);
10479 if (ret < 0)
10480 {
10481 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10482 return CMD_WARNING;
10483 }
paulbb46e942003-10-24 19:02:03 +000010484
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010485 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010486 if (! peer)
10487 return CMD_WARNING;
10488
10489 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10490 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10491 if (count)
10492 {
10493 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10494 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10495 }
10496
10497 return CMD_SUCCESS;
10498}
10499
10500ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10501 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10502 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10503 SHOW_STR
10504 BGP_STR
10505 "BGP view\n"
10506 "View name\n"
10507 "Address family\n"
10508 "Detailed information on TCP and BGP neighbor connections\n"
10509 "Neighbor to display information about\n"
10510 "Neighbor to display information about\n"
10511 "Display information received from a BGP neighbor\n"
10512 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010513#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010514
paul94f2b392005-06-28 12:44:16 +000010515static int
paulbb46e942003-10-24 19:02:03 +000010516bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010517 safi_t safi, enum bgp_show_type type)
10518{
paul718e3742002-12-13 20:15:29 +000010519 if (! peer || ! peer->afc[afi][safi])
10520 {
10521 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010522 return CMD_WARNING;
10523 }
10524
ajs5a646652004-11-05 01:25:55 +000010525 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010526}
10527
10528DEFUN (show_ip_bgp_neighbor_routes,
10529 show_ip_bgp_neighbor_routes_cmd,
10530 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10531 SHOW_STR
10532 IP_STR
10533 BGP_STR
10534 "Detailed information on TCP and BGP neighbor connections\n"
10535 "Neighbor to display information about\n"
10536 "Neighbor to display information about\n"
10537 "Display routes learned from neighbor\n")
10538{
paulbb46e942003-10-24 19:02:03 +000010539 struct peer *peer;
10540
10541 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10542 if (! peer)
10543 return CMD_WARNING;
10544
10545 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010546 bgp_show_type_neighbor);
10547}
10548
10549DEFUN (show_ip_bgp_neighbor_flap,
10550 show_ip_bgp_neighbor_flap_cmd,
10551 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10552 SHOW_STR
10553 IP_STR
10554 BGP_STR
10555 "Detailed information on TCP and BGP neighbor connections\n"
10556 "Neighbor to display information about\n"
10557 "Neighbor to display information about\n"
10558 "Display flap statistics of the routes learned from neighbor\n")
10559{
paulbb46e942003-10-24 19:02:03 +000010560 struct peer *peer;
10561
10562 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10563 if (! peer)
10564 return CMD_WARNING;
10565
10566 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010567 bgp_show_type_flap_neighbor);
10568}
10569
10570DEFUN (show_ip_bgp_neighbor_damp,
10571 show_ip_bgp_neighbor_damp_cmd,
10572 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10573 SHOW_STR
10574 IP_STR
10575 BGP_STR
10576 "Detailed information on TCP and BGP neighbor connections\n"
10577 "Neighbor to display information about\n"
10578 "Neighbor to display information about\n"
10579 "Display the dampened routes received from neighbor\n")
10580{
paulbb46e942003-10-24 19:02:03 +000010581 struct peer *peer;
10582
10583 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10584 if (! peer)
10585 return CMD_WARNING;
10586
10587 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010588 bgp_show_type_damp_neighbor);
10589}
10590
10591DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10592 show_ip_bgp_ipv4_neighbor_routes_cmd,
10593 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10594 SHOW_STR
10595 IP_STR
10596 BGP_STR
10597 "Address family\n"
10598 "Address Family modifier\n"
10599 "Address Family modifier\n"
10600 "Detailed information on TCP and BGP neighbor connections\n"
10601 "Neighbor to display information about\n"
10602 "Neighbor to display information about\n"
10603 "Display routes learned from neighbor\n")
10604{
paulbb46e942003-10-24 19:02:03 +000010605 struct peer *peer;
10606
10607 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10608 if (! peer)
10609 return CMD_WARNING;
10610
paul718e3742002-12-13 20:15:29 +000010611 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010612 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010613 bgp_show_type_neighbor);
10614
paulbb46e942003-10-24 19:02:03 +000010615 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010616 bgp_show_type_neighbor);
10617}
paulbb46e942003-10-24 19:02:03 +000010618
paulfee0f4c2004-09-13 05:12:46 +000010619DEFUN (show_ip_bgp_view_rsclient,
10620 show_ip_bgp_view_rsclient_cmd,
10621 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10622 SHOW_STR
10623 IP_STR
10624 BGP_STR
10625 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010626 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010627 "Information about Route Server Client\n"
10628 NEIGHBOR_ADDR_STR)
10629{
10630 struct bgp_table *table;
10631 struct peer *peer;
10632
10633 if (argc == 2)
10634 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10635 else
10636 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10637
10638 if (! peer)
10639 return CMD_WARNING;
10640
10641 if (! peer->afc[AFI_IP][SAFI_UNICAST])
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_UNICAST],
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_UNICAST];
10657
ajs5a646652004-11-05 01:25:55 +000010658 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010659}
10660
10661ALIAS (show_ip_bgp_view_rsclient,
10662 show_ip_bgp_rsclient_cmd,
10663 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10664 SHOW_STR
10665 IP_STR
10666 BGP_STR
10667 "Information about Route Server Client\n"
10668 NEIGHBOR_ADDR_STR)
10669
Michael Lambert95cbbd22010-07-23 14:43:04 -040010670DEFUN (show_bgp_view_ipv4_safi_rsclient,
10671 show_bgp_view_ipv4_safi_rsclient_cmd,
10672 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10673 SHOW_STR
10674 BGP_STR
10675 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010676 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010677 "Address family\n"
10678 "Address Family modifier\n"
10679 "Address Family modifier\n"
10680 "Information about Route Server Client\n"
10681 NEIGHBOR_ADDR_STR)
10682{
10683 struct bgp_table *table;
10684 struct peer *peer;
10685 safi_t safi;
10686
10687 if (argc == 3) {
10688 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10689 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10690 } else {
10691 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10692 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10693 }
10694
10695 if (! peer)
10696 return CMD_WARNING;
10697
10698 if (! peer->afc[AFI_IP][safi])
10699 {
10700 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10701 VTY_NEWLINE);
10702 return CMD_WARNING;
10703 }
10704
10705 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10706 PEER_FLAG_RSERVER_CLIENT))
10707 {
10708 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10709 VTY_NEWLINE);
10710 return CMD_WARNING;
10711 }
10712
10713 table = peer->rib[AFI_IP][safi];
10714
10715 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10716}
10717
10718ALIAS (show_bgp_view_ipv4_safi_rsclient,
10719 show_bgp_ipv4_safi_rsclient_cmd,
10720 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10721 SHOW_STR
10722 BGP_STR
10723 "Address family\n"
10724 "Address Family modifier\n"
10725 "Address Family modifier\n"
10726 "Information about Route Server Client\n"
10727 NEIGHBOR_ADDR_STR)
10728
paulfee0f4c2004-09-13 05:12:46 +000010729DEFUN (show_ip_bgp_view_rsclient_route,
10730 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010731 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010732 SHOW_STR
10733 IP_STR
10734 BGP_STR
10735 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010736 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010737 "Information about Route Server Client\n"
10738 NEIGHBOR_ADDR_STR
10739 "Network in the BGP routing table to display\n")
10740{
10741 struct bgp *bgp;
10742 struct peer *peer;
10743
10744 /* BGP structure lookup. */
10745 if (argc == 3)
10746 {
10747 bgp = bgp_lookup_by_name (argv[0]);
10748 if (bgp == NULL)
10749 {
10750 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10751 return CMD_WARNING;
10752 }
10753 }
10754 else
10755 {
10756 bgp = bgp_get_default ();
10757 if (bgp == NULL)
10758 {
10759 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10760 return CMD_WARNING;
10761 }
10762 }
10763
10764 if (argc == 3)
10765 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10766 else
10767 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10768
10769 if (! peer)
10770 return CMD_WARNING;
10771
10772 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10773 {
10774 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10775 VTY_NEWLINE);
10776 return CMD_WARNING;
10777}
10778
10779 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10780 PEER_FLAG_RSERVER_CLIENT))
10781 {
10782 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10783 VTY_NEWLINE);
10784 return CMD_WARNING;
10785 }
10786
10787 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10788 (argc == 3) ? argv[2] : argv[1],
10789 AFI_IP, SAFI_UNICAST, NULL, 0);
10790}
10791
10792ALIAS (show_ip_bgp_view_rsclient_route,
10793 show_ip_bgp_rsclient_route_cmd,
10794 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10795 SHOW_STR
10796 IP_STR
10797 BGP_STR
10798 "Information about Route Server Client\n"
10799 NEIGHBOR_ADDR_STR
10800 "Network in the BGP routing table to display\n")
10801
Michael Lambert95cbbd22010-07-23 14:43:04 -040010802DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10803 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10804 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10805 SHOW_STR
10806 BGP_STR
10807 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010808 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010809 "Address family\n"
10810 "Address Family modifier\n"
10811 "Address Family modifier\n"
10812 "Information about Route Server Client\n"
10813 NEIGHBOR_ADDR_STR
10814 "Network in the BGP routing table to display\n")
10815{
10816 struct bgp *bgp;
10817 struct peer *peer;
10818 safi_t safi;
10819
10820 /* BGP structure lookup. */
10821 if (argc == 4)
10822 {
10823 bgp = bgp_lookup_by_name (argv[0]);
10824 if (bgp == NULL)
10825 {
10826 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10827 return CMD_WARNING;
10828 }
10829 }
10830 else
10831 {
10832 bgp = bgp_get_default ();
10833 if (bgp == NULL)
10834 {
10835 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10836 return CMD_WARNING;
10837 }
10838 }
10839
10840 if (argc == 4) {
10841 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10842 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10843 } else {
10844 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10845 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10846 }
10847
10848 if (! peer)
10849 return CMD_WARNING;
10850
10851 if (! peer->afc[AFI_IP][safi])
10852 {
10853 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10854 VTY_NEWLINE);
10855 return CMD_WARNING;
10856}
10857
10858 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10859 PEER_FLAG_RSERVER_CLIENT))
10860 {
10861 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10862 VTY_NEWLINE);
10863 return CMD_WARNING;
10864 }
10865
10866 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10867 (argc == 4) ? argv[3] : argv[2],
10868 AFI_IP, safi, NULL, 0);
10869}
10870
10871ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10872 show_bgp_ipv4_safi_rsclient_route_cmd,
10873 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10874 SHOW_STR
10875 BGP_STR
10876 "Address family\n"
10877 "Address Family modifier\n"
10878 "Address Family modifier\n"
10879 "Information about Route Server Client\n"
10880 NEIGHBOR_ADDR_STR
10881 "Network in the BGP routing table to display\n")
10882
paulfee0f4c2004-09-13 05:12:46 +000010883DEFUN (show_ip_bgp_view_rsclient_prefix,
10884 show_ip_bgp_view_rsclient_prefix_cmd,
10885 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10886 SHOW_STR
10887 IP_STR
10888 BGP_STR
10889 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010890 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010891 "Information about Route Server Client\n"
10892 NEIGHBOR_ADDR_STR
10893 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10894{
10895 struct bgp *bgp;
10896 struct peer *peer;
10897
10898 /* BGP structure lookup. */
10899 if (argc == 3)
10900 {
10901 bgp = bgp_lookup_by_name (argv[0]);
10902 if (bgp == NULL)
10903 {
10904 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10905 return CMD_WARNING;
10906 }
10907 }
10908 else
10909 {
10910 bgp = bgp_get_default ();
10911 if (bgp == NULL)
10912 {
10913 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10914 return CMD_WARNING;
10915 }
10916 }
10917
10918 if (argc == 3)
10919 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10920 else
10921 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10922
10923 if (! peer)
10924 return CMD_WARNING;
10925
10926 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10927 {
10928 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10929 VTY_NEWLINE);
10930 return CMD_WARNING;
10931}
10932
10933 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10934 PEER_FLAG_RSERVER_CLIENT))
10935{
10936 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10937 VTY_NEWLINE);
10938 return CMD_WARNING;
10939 }
10940
10941 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10942 (argc == 3) ? argv[2] : argv[1],
10943 AFI_IP, SAFI_UNICAST, NULL, 1);
10944}
10945
10946ALIAS (show_ip_bgp_view_rsclient_prefix,
10947 show_ip_bgp_rsclient_prefix_cmd,
10948 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10949 SHOW_STR
10950 IP_STR
10951 BGP_STR
10952 "Information about Route Server Client\n"
10953 NEIGHBOR_ADDR_STR
10954 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10955
Michael Lambert95cbbd22010-07-23 14:43:04 -040010956DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10957 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10958 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10959 SHOW_STR
10960 BGP_STR
10961 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010962 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010963 "Address family\n"
10964 "Address Family modifier\n"
10965 "Address Family modifier\n"
10966 "Information about Route Server Client\n"
10967 NEIGHBOR_ADDR_STR
10968 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10969{
10970 struct bgp *bgp;
10971 struct peer *peer;
10972 safi_t safi;
10973
10974 /* BGP structure lookup. */
10975 if (argc == 4)
10976 {
10977 bgp = bgp_lookup_by_name (argv[0]);
10978 if (bgp == NULL)
10979 {
10980 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10981 return CMD_WARNING;
10982 }
10983 }
10984 else
10985 {
10986 bgp = bgp_get_default ();
10987 if (bgp == NULL)
10988 {
10989 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10990 return CMD_WARNING;
10991 }
10992 }
10993
10994 if (argc == 4) {
10995 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10996 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10997 } else {
10998 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10999 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11000 }
11001
11002 if (! peer)
11003 return CMD_WARNING;
11004
11005 if (! peer->afc[AFI_IP][safi])
11006 {
11007 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11008 VTY_NEWLINE);
11009 return CMD_WARNING;
11010}
11011
11012 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11013 PEER_FLAG_RSERVER_CLIENT))
11014{
11015 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11016 VTY_NEWLINE);
11017 return CMD_WARNING;
11018 }
11019
11020 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11021 (argc == 4) ? argv[3] : argv[2],
11022 AFI_IP, safi, NULL, 1);
11023}
11024
11025ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11026 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11027 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11028 SHOW_STR
11029 BGP_STR
11030 "Address family\n"
11031 "Address Family modifier\n"
11032 "Address Family modifier\n"
11033 "Information about Route Server Client\n"
11034 NEIGHBOR_ADDR_STR
11035 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011036
paul718e3742002-12-13 20:15:29 +000011037#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011038DEFUN (show_bgp_view_neighbor_routes,
11039 show_bgp_view_neighbor_routes_cmd,
11040 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11041 SHOW_STR
11042 BGP_STR
11043 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011044 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011045 "Detailed information on TCP and BGP neighbor connections\n"
11046 "Neighbor to display information about\n"
11047 "Neighbor to display information about\n"
11048 "Display routes learned from neighbor\n")
11049{
11050 struct peer *peer;
11051
11052 if (argc == 2)
11053 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11054 else
11055 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11056
11057 if (! peer)
11058 return CMD_WARNING;
11059
11060 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11061 bgp_show_type_neighbor);
11062}
11063
11064ALIAS (show_bgp_view_neighbor_routes,
11065 show_bgp_view_ipv6_neighbor_routes_cmd,
11066 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11067 SHOW_STR
11068 BGP_STR
11069 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011070 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011071 "Address family\n"
11072 "Detailed information on TCP and BGP neighbor connections\n"
11073 "Neighbor to display information about\n"
11074 "Neighbor to display information about\n"
11075 "Display routes learned from neighbor\n")
11076
11077DEFUN (show_bgp_view_neighbor_damp,
11078 show_bgp_view_neighbor_damp_cmd,
11079 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11080 SHOW_STR
11081 BGP_STR
11082 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011083 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011084 "Detailed information on TCP and BGP neighbor connections\n"
11085 "Neighbor to display information about\n"
11086 "Neighbor to display information about\n"
11087 "Display the dampened routes received from neighbor\n")
11088{
11089 struct peer *peer;
11090
11091 if (argc == 2)
11092 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11093 else
11094 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11095
11096 if (! peer)
11097 return CMD_WARNING;
11098
11099 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11100 bgp_show_type_damp_neighbor);
11101}
11102
11103ALIAS (show_bgp_view_neighbor_damp,
11104 show_bgp_view_ipv6_neighbor_damp_cmd,
11105 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11106 SHOW_STR
11107 BGP_STR
11108 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011109 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011110 "Address family\n"
11111 "Detailed information on TCP and BGP neighbor connections\n"
11112 "Neighbor to display information about\n"
11113 "Neighbor to display information about\n"
11114 "Display the dampened routes received from neighbor\n")
11115
11116DEFUN (show_bgp_view_neighbor_flap,
11117 show_bgp_view_neighbor_flap_cmd,
11118 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11119 SHOW_STR
11120 BGP_STR
11121 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011122 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011123 "Detailed information on TCP and BGP neighbor connections\n"
11124 "Neighbor to display information about\n"
11125 "Neighbor to display information about\n"
11126 "Display flap statistics of the routes learned from neighbor\n")
11127{
11128 struct peer *peer;
11129
11130 if (argc == 2)
11131 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11132 else
11133 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11134
11135 if (! peer)
11136 return CMD_WARNING;
11137
11138 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11139 bgp_show_type_flap_neighbor);
11140}
11141
11142ALIAS (show_bgp_view_neighbor_flap,
11143 show_bgp_view_ipv6_neighbor_flap_cmd,
11144 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11145 SHOW_STR
11146 BGP_STR
11147 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011148 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011149 "Address family\n"
11150 "Detailed information on TCP and BGP neighbor connections\n"
11151 "Neighbor to display information about\n"
11152 "Neighbor to display information about\n"
11153 "Display flap statistics of the routes learned from neighbor\n")
11154
11155ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011156 show_bgp_neighbor_routes_cmd,
11157 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11158 SHOW_STR
11159 BGP_STR
11160 "Detailed information on TCP and BGP neighbor connections\n"
11161 "Neighbor to display information about\n"
11162 "Neighbor to display information about\n"
11163 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011164
paulbb46e942003-10-24 19:02:03 +000011165
11166ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011167 show_bgp_ipv6_neighbor_routes_cmd,
11168 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11169 SHOW_STR
11170 BGP_STR
11171 "Address family\n"
11172 "Detailed information on TCP and BGP neighbor connections\n"
11173 "Neighbor to display information about\n"
11174 "Neighbor to display information about\n"
11175 "Display routes learned from neighbor\n")
11176
11177/* old command */
paulbb46e942003-10-24 19:02:03 +000011178ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011179 ipv6_bgp_neighbor_routes_cmd,
11180 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11181 SHOW_STR
11182 IPV6_STR
11183 BGP_STR
11184 "Detailed information on TCP and BGP neighbor connections\n"
11185 "Neighbor to display information about\n"
11186 "Neighbor to display information about\n"
11187 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011188
11189/* old command */
11190DEFUN (ipv6_mbgp_neighbor_routes,
11191 ipv6_mbgp_neighbor_routes_cmd,
11192 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11193 SHOW_STR
11194 IPV6_STR
11195 MBGP_STR
11196 "Detailed information on TCP and BGP neighbor connections\n"
11197 "Neighbor to display information about\n"
11198 "Neighbor to display information about\n"
11199 "Display routes learned from neighbor\n")
11200{
paulbb46e942003-10-24 19:02:03 +000011201 struct peer *peer;
11202
11203 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11204 if (! peer)
11205 return CMD_WARNING;
11206
11207 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011208 bgp_show_type_neighbor);
11209}
paulbb46e942003-10-24 19:02:03 +000011210
11211ALIAS (show_bgp_view_neighbor_flap,
11212 show_bgp_neighbor_flap_cmd,
11213 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11214 SHOW_STR
11215 BGP_STR
11216 "Detailed information on TCP and BGP neighbor connections\n"
11217 "Neighbor to display information about\n"
11218 "Neighbor to display information about\n"
11219 "Display flap statistics of the routes learned from neighbor\n")
11220
11221ALIAS (show_bgp_view_neighbor_flap,
11222 show_bgp_ipv6_neighbor_flap_cmd,
11223 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11224 SHOW_STR
11225 BGP_STR
11226 "Address family\n"
11227 "Detailed information on TCP and BGP neighbor connections\n"
11228 "Neighbor to display information about\n"
11229 "Neighbor to display information about\n"
11230 "Display flap statistics of the routes learned from neighbor\n")
11231
11232ALIAS (show_bgp_view_neighbor_damp,
11233 show_bgp_neighbor_damp_cmd,
11234 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11235 SHOW_STR
11236 BGP_STR
11237 "Detailed information on TCP and BGP neighbor connections\n"
11238 "Neighbor to display information about\n"
11239 "Neighbor to display information about\n"
11240 "Display the dampened routes received from neighbor\n")
11241
11242ALIAS (show_bgp_view_neighbor_damp,
11243 show_bgp_ipv6_neighbor_damp_cmd,
11244 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11245 SHOW_STR
11246 BGP_STR
11247 "Address family\n"
11248 "Detailed information on TCP and BGP neighbor connections\n"
11249 "Neighbor to display information about\n"
11250 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011251 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011252
11253DEFUN (show_bgp_view_rsclient,
11254 show_bgp_view_rsclient_cmd,
11255 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11256 SHOW_STR
11257 BGP_STR
11258 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011259 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011260 "Information about Route Server Client\n"
11261 NEIGHBOR_ADDR_STR)
11262{
11263 struct bgp_table *table;
11264 struct peer *peer;
11265
11266 if (argc == 2)
11267 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11268 else
11269 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11270
11271 if (! peer)
11272 return CMD_WARNING;
11273
11274 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11275 {
11276 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11277 VTY_NEWLINE);
11278 return CMD_WARNING;
11279 }
11280
11281 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11282 PEER_FLAG_RSERVER_CLIENT))
11283 {
11284 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11285 VTY_NEWLINE);
11286 return CMD_WARNING;
11287 }
11288
11289 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11290
ajs5a646652004-11-05 01:25:55 +000011291 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011292}
11293
11294ALIAS (show_bgp_view_rsclient,
11295 show_bgp_rsclient_cmd,
11296 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11297 SHOW_STR
11298 BGP_STR
11299 "Information about Route Server Client\n"
11300 NEIGHBOR_ADDR_STR)
11301
Michael Lambert95cbbd22010-07-23 14:43:04 -040011302DEFUN (show_bgp_view_ipv6_safi_rsclient,
11303 show_bgp_view_ipv6_safi_rsclient_cmd,
11304 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11305 SHOW_STR
11306 BGP_STR
11307 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011308 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011309 "Address family\n"
11310 "Address Family modifier\n"
11311 "Address Family modifier\n"
11312 "Information about Route Server Client\n"
11313 NEIGHBOR_ADDR_STR)
11314{
11315 struct bgp_table *table;
11316 struct peer *peer;
11317 safi_t safi;
11318
11319 if (argc == 3) {
11320 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11321 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11322 } else {
11323 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11324 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11325 }
11326
11327 if (! peer)
11328 return CMD_WARNING;
11329
11330 if (! peer->afc[AFI_IP6][safi])
11331 {
11332 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11333 VTY_NEWLINE);
11334 return CMD_WARNING;
11335 }
11336
11337 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11338 PEER_FLAG_RSERVER_CLIENT))
11339 {
11340 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11341 VTY_NEWLINE);
11342 return CMD_WARNING;
11343 }
11344
11345 table = peer->rib[AFI_IP6][safi];
11346
11347 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11348}
11349
11350ALIAS (show_bgp_view_ipv6_safi_rsclient,
11351 show_bgp_ipv6_safi_rsclient_cmd,
11352 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11353 SHOW_STR
11354 BGP_STR
11355 "Address family\n"
11356 "Address Family modifier\n"
11357 "Address Family modifier\n"
11358 "Information about Route Server Client\n"
11359 NEIGHBOR_ADDR_STR)
11360
paulfee0f4c2004-09-13 05:12:46 +000011361DEFUN (show_bgp_view_rsclient_route,
11362 show_bgp_view_rsclient_route_cmd,
11363 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11364 SHOW_STR
11365 BGP_STR
11366 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011367 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011368 "Information about Route Server Client\n"
11369 NEIGHBOR_ADDR_STR
11370 "Network in the BGP routing table to display\n")
11371{
11372 struct bgp *bgp;
11373 struct peer *peer;
11374
11375 /* BGP structure lookup. */
11376 if (argc == 3)
11377 {
11378 bgp = bgp_lookup_by_name (argv[0]);
11379 if (bgp == NULL)
11380 {
11381 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11382 return CMD_WARNING;
11383 }
11384 }
11385 else
11386 {
11387 bgp = bgp_get_default ();
11388 if (bgp == NULL)
11389 {
11390 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11391 return CMD_WARNING;
11392 }
11393 }
11394
11395 if (argc == 3)
11396 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11397 else
11398 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11399
11400 if (! peer)
11401 return CMD_WARNING;
11402
11403 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11404 {
11405 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11406 VTY_NEWLINE);
11407 return CMD_WARNING;
11408 }
11409
11410 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11411 PEER_FLAG_RSERVER_CLIENT))
11412 {
11413 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11414 VTY_NEWLINE);
11415 return CMD_WARNING;
11416 }
11417
11418 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11419 (argc == 3) ? argv[2] : argv[1],
11420 AFI_IP6, SAFI_UNICAST, NULL, 0);
11421}
11422
11423ALIAS (show_bgp_view_rsclient_route,
11424 show_bgp_rsclient_route_cmd,
11425 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11426 SHOW_STR
11427 BGP_STR
11428 "Information about Route Server Client\n"
11429 NEIGHBOR_ADDR_STR
11430 "Network in the BGP routing table to display\n")
11431
Michael Lambert95cbbd22010-07-23 14:43:04 -040011432DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11433 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11434 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11435 SHOW_STR
11436 BGP_STR
11437 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011438 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011439 "Address family\n"
11440 "Address Family modifier\n"
11441 "Address Family modifier\n"
11442 "Information about Route Server Client\n"
11443 NEIGHBOR_ADDR_STR
11444 "Network in the BGP routing table to display\n")
11445{
11446 struct bgp *bgp;
11447 struct peer *peer;
11448 safi_t safi;
11449
11450 /* BGP structure lookup. */
11451 if (argc == 4)
11452 {
11453 bgp = bgp_lookup_by_name (argv[0]);
11454 if (bgp == NULL)
11455 {
11456 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11457 return CMD_WARNING;
11458 }
11459 }
11460 else
11461 {
11462 bgp = bgp_get_default ();
11463 if (bgp == NULL)
11464 {
11465 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11466 return CMD_WARNING;
11467 }
11468 }
11469
11470 if (argc == 4) {
11471 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11472 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11473 } else {
11474 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11475 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11476 }
11477
11478 if (! peer)
11479 return CMD_WARNING;
11480
11481 if (! peer->afc[AFI_IP6][safi])
11482 {
11483 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11484 VTY_NEWLINE);
11485 return CMD_WARNING;
11486}
11487
11488 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11489 PEER_FLAG_RSERVER_CLIENT))
11490 {
11491 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11492 VTY_NEWLINE);
11493 return CMD_WARNING;
11494 }
11495
11496 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11497 (argc == 4) ? argv[3] : argv[2],
11498 AFI_IP6, safi, NULL, 0);
11499}
11500
11501ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11502 show_bgp_ipv6_safi_rsclient_route_cmd,
11503 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11504 SHOW_STR
11505 BGP_STR
11506 "Address family\n"
11507 "Address Family modifier\n"
11508 "Address Family modifier\n"
11509 "Information about Route Server Client\n"
11510 NEIGHBOR_ADDR_STR
11511 "Network in the BGP routing table to display\n")
11512
paulfee0f4c2004-09-13 05:12:46 +000011513DEFUN (show_bgp_view_rsclient_prefix,
11514 show_bgp_view_rsclient_prefix_cmd,
11515 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11516 SHOW_STR
11517 BGP_STR
11518 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011519 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011520 "Information about Route Server Client\n"
11521 NEIGHBOR_ADDR_STR
11522 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11523{
11524 struct bgp *bgp;
11525 struct peer *peer;
11526
11527 /* BGP structure lookup. */
11528 if (argc == 3)
11529 {
11530 bgp = bgp_lookup_by_name (argv[0]);
11531 if (bgp == NULL)
11532 {
11533 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11534 return CMD_WARNING;
11535 }
11536 }
11537 else
11538 {
11539 bgp = bgp_get_default ();
11540 if (bgp == NULL)
11541 {
11542 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11543 return CMD_WARNING;
11544 }
11545 }
11546
11547 if (argc == 3)
11548 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11549 else
11550 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11551
11552 if (! peer)
11553 return CMD_WARNING;
11554
11555 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11556 {
11557 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11558 VTY_NEWLINE);
11559 return CMD_WARNING;
11560 }
11561
11562 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11563 PEER_FLAG_RSERVER_CLIENT))
11564 {
11565 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11566 VTY_NEWLINE);
11567 return CMD_WARNING;
11568 }
11569
11570 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11571 (argc == 3) ? argv[2] : argv[1],
11572 AFI_IP6, SAFI_UNICAST, NULL, 1);
11573}
11574
11575ALIAS (show_bgp_view_rsclient_prefix,
11576 show_bgp_rsclient_prefix_cmd,
11577 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11578 SHOW_STR
11579 BGP_STR
11580 "Information about Route Server Client\n"
11581 NEIGHBOR_ADDR_STR
11582 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11583
Michael Lambert95cbbd22010-07-23 14:43:04 -040011584DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11585 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11586 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11587 SHOW_STR
11588 BGP_STR
11589 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011590 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011591 "Address family\n"
11592 "Address Family modifier\n"
11593 "Address Family modifier\n"
11594 "Information about Route Server Client\n"
11595 NEIGHBOR_ADDR_STR
11596 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11597{
11598 struct bgp *bgp;
11599 struct peer *peer;
11600 safi_t safi;
11601
11602 /* BGP structure lookup. */
11603 if (argc == 4)
11604 {
11605 bgp = bgp_lookup_by_name (argv[0]);
11606 if (bgp == NULL)
11607 {
11608 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11609 return CMD_WARNING;
11610 }
11611 }
11612 else
11613 {
11614 bgp = bgp_get_default ();
11615 if (bgp == NULL)
11616 {
11617 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11618 return CMD_WARNING;
11619 }
11620 }
11621
11622 if (argc == 4) {
11623 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11624 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11625 } else {
11626 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11627 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11628 }
11629
11630 if (! peer)
11631 return CMD_WARNING;
11632
11633 if (! peer->afc[AFI_IP6][safi])
11634 {
11635 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11636 VTY_NEWLINE);
11637 return CMD_WARNING;
11638}
11639
11640 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11641 PEER_FLAG_RSERVER_CLIENT))
11642{
11643 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11644 VTY_NEWLINE);
11645 return CMD_WARNING;
11646 }
11647
11648 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11649 (argc == 4) ? argv[3] : argv[2],
11650 AFI_IP6, safi, NULL, 1);
11651}
11652
11653ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11654 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11655 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11656 SHOW_STR
11657 BGP_STR
11658 "Address family\n"
11659 "Address Family modifier\n"
11660 "Address Family modifier\n"
11661 "Information about Route Server Client\n"
11662 NEIGHBOR_ADDR_STR
11663 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11664
paul718e3742002-12-13 20:15:29 +000011665#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020011666
paul718e3742002-12-13 20:15:29 +000011667struct bgp_table *bgp_distance_table;
11668
11669struct bgp_distance
11670{
11671 /* Distance value for the IP source prefix. */
11672 u_char distance;
11673
11674 /* Name of the access-list to be matched. */
11675 char *access_list;
11676};
11677
paul94f2b392005-06-28 12:44:16 +000011678static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011679bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011680{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011681 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011682}
11683
paul94f2b392005-06-28 12:44:16 +000011684static void
paul718e3742002-12-13 20:15:29 +000011685bgp_distance_free (struct bgp_distance *bdistance)
11686{
11687 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11688}
11689
paul94f2b392005-06-28 12:44:16 +000011690static int
paulfd79ac92004-10-13 05:06:08 +000011691bgp_distance_set (struct vty *vty, const char *distance_str,
11692 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011693{
11694 int ret;
11695 struct prefix_ipv4 p;
11696 u_char distance;
11697 struct bgp_node *rn;
11698 struct bgp_distance *bdistance;
11699
11700 ret = str2prefix_ipv4 (ip_str, &p);
11701 if (ret == 0)
11702 {
11703 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11704 return CMD_WARNING;
11705 }
11706
11707 distance = atoi (distance_str);
11708
11709 /* Get BGP distance node. */
11710 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11711 if (rn->info)
11712 {
11713 bdistance = rn->info;
11714 bgp_unlock_node (rn);
11715 }
11716 else
11717 {
11718 bdistance = bgp_distance_new ();
11719 rn->info = bdistance;
11720 }
11721
11722 /* Set distance value. */
11723 bdistance->distance = distance;
11724
11725 /* Reset access-list configuration. */
11726 if (bdistance->access_list)
11727 {
11728 free (bdistance->access_list);
11729 bdistance->access_list = NULL;
11730 }
11731 if (access_list_str)
11732 bdistance->access_list = strdup (access_list_str);
11733
11734 return CMD_SUCCESS;
11735}
11736
paul94f2b392005-06-28 12:44:16 +000011737static int
paulfd79ac92004-10-13 05:06:08 +000011738bgp_distance_unset (struct vty *vty, const char *distance_str,
11739 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011740{
11741 int ret;
11742 struct prefix_ipv4 p;
11743 u_char distance;
11744 struct bgp_node *rn;
11745 struct bgp_distance *bdistance;
11746
11747 ret = str2prefix_ipv4 (ip_str, &p);
11748 if (ret == 0)
11749 {
11750 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11751 return CMD_WARNING;
11752 }
11753
11754 distance = atoi (distance_str);
11755
11756 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11757 if (! rn)
11758 {
11759 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11760 return CMD_WARNING;
11761 }
11762
11763 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010011764
11765 if (bdistance->distance != distance)
11766 {
11767 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
11768 return CMD_WARNING;
11769 }
11770
paul718e3742002-12-13 20:15:29 +000011771 if (bdistance->access_list)
11772 free (bdistance->access_list);
11773 bgp_distance_free (bdistance);
11774
11775 rn->info = NULL;
11776 bgp_unlock_node (rn);
11777 bgp_unlock_node (rn);
11778
11779 return CMD_SUCCESS;
11780}
11781
paul718e3742002-12-13 20:15:29 +000011782/* Apply BGP information to distance method. */
11783u_char
11784bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11785{
11786 struct bgp_node *rn;
11787 struct prefix_ipv4 q;
11788 struct peer *peer;
11789 struct bgp_distance *bdistance;
11790 struct access_list *alist;
11791 struct bgp_static *bgp_static;
11792
11793 if (! bgp)
11794 return 0;
11795
11796 if (p->family != AF_INET)
11797 return 0;
11798
11799 peer = rinfo->peer;
11800
11801 if (peer->su.sa.sa_family != AF_INET)
11802 return 0;
11803
11804 memset (&q, 0, sizeof (struct prefix_ipv4));
11805 q.family = AF_INET;
11806 q.prefix = peer->su.sin.sin_addr;
11807 q.prefixlen = IPV4_MAX_BITLEN;
11808
11809 /* Check source address. */
11810 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11811 if (rn)
11812 {
11813 bdistance = rn->info;
11814 bgp_unlock_node (rn);
11815
11816 if (bdistance->access_list)
11817 {
11818 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11819 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11820 return bdistance->distance;
11821 }
11822 else
11823 return bdistance->distance;
11824 }
11825
11826 /* Backdoor check. */
11827 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11828 if (rn)
11829 {
11830 bgp_static = rn->info;
11831 bgp_unlock_node (rn);
11832
11833 if (bgp_static->backdoor)
11834 {
11835 if (bgp->distance_local)
11836 return bgp->distance_local;
11837 else
11838 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11839 }
11840 }
11841
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011842 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011843 {
11844 if (bgp->distance_ebgp)
11845 return bgp->distance_ebgp;
11846 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11847 }
11848 else
11849 {
11850 if (bgp->distance_ibgp)
11851 return bgp->distance_ibgp;
11852 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11853 }
11854}
11855
11856DEFUN (bgp_distance,
11857 bgp_distance_cmd,
11858 "distance bgp <1-255> <1-255> <1-255>",
11859 "Define an administrative distance\n"
11860 "BGP distance\n"
11861 "Distance for routes external to the AS\n"
11862 "Distance for routes internal to the AS\n"
11863 "Distance for local routes\n")
11864{
11865 struct bgp *bgp;
11866
11867 bgp = vty->index;
11868
11869 bgp->distance_ebgp = atoi (argv[0]);
11870 bgp->distance_ibgp = atoi (argv[1]);
11871 bgp->distance_local = atoi (argv[2]);
11872 return CMD_SUCCESS;
11873}
11874
11875DEFUN (no_bgp_distance,
11876 no_bgp_distance_cmd,
11877 "no distance bgp <1-255> <1-255> <1-255>",
11878 NO_STR
11879 "Define an administrative distance\n"
11880 "BGP distance\n"
11881 "Distance for routes external to the AS\n"
11882 "Distance for routes internal to the AS\n"
11883 "Distance for local routes\n")
11884{
11885 struct bgp *bgp;
11886
11887 bgp = vty->index;
11888
11889 bgp->distance_ebgp= 0;
11890 bgp->distance_ibgp = 0;
11891 bgp->distance_local = 0;
11892 return CMD_SUCCESS;
11893}
11894
11895ALIAS (no_bgp_distance,
11896 no_bgp_distance2_cmd,
11897 "no distance bgp",
11898 NO_STR
11899 "Define an administrative distance\n"
11900 "BGP distance\n")
11901
11902DEFUN (bgp_distance_source,
11903 bgp_distance_source_cmd,
11904 "distance <1-255> A.B.C.D/M",
11905 "Define an administrative distance\n"
11906 "Administrative distance\n"
11907 "IP source prefix\n")
11908{
11909 bgp_distance_set (vty, argv[0], argv[1], NULL);
11910 return CMD_SUCCESS;
11911}
11912
11913DEFUN (no_bgp_distance_source,
11914 no_bgp_distance_source_cmd,
11915 "no distance <1-255> A.B.C.D/M",
11916 NO_STR
11917 "Define an administrative distance\n"
11918 "Administrative distance\n"
11919 "IP source prefix\n")
11920{
11921 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11922 return CMD_SUCCESS;
11923}
11924
11925DEFUN (bgp_distance_source_access_list,
11926 bgp_distance_source_access_list_cmd,
11927 "distance <1-255> A.B.C.D/M WORD",
11928 "Define an administrative distance\n"
11929 "Administrative distance\n"
11930 "IP source prefix\n"
11931 "Access list name\n")
11932{
11933 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11934 return CMD_SUCCESS;
11935}
11936
11937DEFUN (no_bgp_distance_source_access_list,
11938 no_bgp_distance_source_access_list_cmd,
11939 "no distance <1-255> A.B.C.D/M WORD",
11940 NO_STR
11941 "Define an administrative distance\n"
11942 "Administrative distance\n"
11943 "IP source prefix\n"
11944 "Access list name\n")
11945{
11946 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11947 return CMD_SUCCESS;
11948}
David Lamparter6b0655a2014-06-04 06:53:35 +020011949
paul718e3742002-12-13 20:15:29 +000011950DEFUN (bgp_damp_set,
11951 bgp_damp_set_cmd,
11952 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11953 "BGP Specific commands\n"
11954 "Enable route-flap dampening\n"
11955 "Half-life time for the penalty\n"
11956 "Value to start reusing a route\n"
11957 "Value to start suppressing a route\n"
11958 "Maximum duration to suppress a stable route\n")
11959{
11960 struct bgp *bgp;
11961 int half = DEFAULT_HALF_LIFE * 60;
11962 int reuse = DEFAULT_REUSE;
11963 int suppress = DEFAULT_SUPPRESS;
11964 int max = 4 * half;
11965
11966 if (argc == 4)
11967 {
11968 half = atoi (argv[0]) * 60;
11969 reuse = atoi (argv[1]);
11970 suppress = atoi (argv[2]);
11971 max = atoi (argv[3]) * 60;
11972 }
11973 else if (argc == 1)
11974 {
11975 half = atoi (argv[0]) * 60;
11976 max = 4 * half;
11977 }
11978
11979 bgp = vty->index;
11980 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11981 half, reuse, suppress, max);
11982}
11983
11984ALIAS (bgp_damp_set,
11985 bgp_damp_set2_cmd,
11986 "bgp dampening <1-45>",
11987 "BGP Specific commands\n"
11988 "Enable route-flap dampening\n"
11989 "Half-life time for the penalty\n")
11990
11991ALIAS (bgp_damp_set,
11992 bgp_damp_set3_cmd,
11993 "bgp dampening",
11994 "BGP Specific commands\n"
11995 "Enable route-flap dampening\n")
11996
11997DEFUN (bgp_damp_unset,
11998 bgp_damp_unset_cmd,
11999 "no bgp dampening",
12000 NO_STR
12001 "BGP Specific commands\n"
12002 "Enable route-flap dampening\n")
12003{
12004 struct bgp *bgp;
12005
12006 bgp = vty->index;
12007 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
12008}
12009
12010ALIAS (bgp_damp_unset,
12011 bgp_damp_unset2_cmd,
12012 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12013 NO_STR
12014 "BGP Specific commands\n"
12015 "Enable route-flap dampening\n"
12016 "Half-life time for the penalty\n"
12017 "Value to start reusing a route\n"
12018 "Value to start suppressing a route\n"
12019 "Maximum duration to suppress a stable route\n")
12020
12021DEFUN (show_ip_bgp_dampened_paths,
12022 show_ip_bgp_dampened_paths_cmd,
12023 "show ip bgp dampened-paths",
12024 SHOW_STR
12025 IP_STR
12026 BGP_STR
12027 "Display paths suppressed due to dampening\n")
12028{
ajs5a646652004-11-05 01:25:55 +000012029 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
12030 NULL);
paul718e3742002-12-13 20:15:29 +000012031}
12032
12033DEFUN (show_ip_bgp_flap_statistics,
12034 show_ip_bgp_flap_statistics_cmd,
12035 "show ip bgp flap-statistics",
12036 SHOW_STR
12037 IP_STR
12038 BGP_STR
12039 "Display flap statistics of routes\n")
12040{
ajs5a646652004-11-05 01:25:55 +000012041 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12042 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012043}
David Lamparter6b0655a2014-06-04 06:53:35 +020012044
paul718e3742002-12-13 20:15:29 +000012045/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012046static int
paulfd79ac92004-10-13 05:06:08 +000012047bgp_clear_damp_route (struct vty *vty, const char *view_name,
12048 const char *ip_str, afi_t afi, safi_t safi,
12049 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012050{
12051 int ret;
12052 struct prefix match;
12053 struct bgp_node *rn;
12054 struct bgp_node *rm;
12055 struct bgp_info *ri;
12056 struct bgp_info *ri_temp;
12057 struct bgp *bgp;
12058 struct bgp_table *table;
12059
12060 /* BGP structure lookup. */
12061 if (view_name)
12062 {
12063 bgp = bgp_lookup_by_name (view_name);
12064 if (bgp == NULL)
12065 {
12066 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12067 return CMD_WARNING;
12068 }
12069 }
12070 else
12071 {
12072 bgp = bgp_get_default ();
12073 if (bgp == NULL)
12074 {
12075 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12076 return CMD_WARNING;
12077 }
12078 }
12079
12080 /* Check IP address argument. */
12081 ret = str2prefix (ip_str, &match);
12082 if (! ret)
12083 {
12084 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12085 return CMD_WARNING;
12086 }
12087
12088 match.family = afi2family (afi);
12089
12090 if (safi == SAFI_MPLS_VPN)
12091 {
12092 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12093 {
12094 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12095 continue;
12096
12097 if ((table = rn->info) != NULL)
12098 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012099 {
12100 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12101 {
12102 ri = rm->info;
12103 while (ri)
12104 {
12105 if (ri->extra && ri->extra->damp_info)
12106 {
12107 ri_temp = ri->next;
12108 bgp_damp_info_free (ri->extra->damp_info, 1);
12109 ri = ri_temp;
12110 }
12111 else
12112 ri = ri->next;
12113 }
12114 }
12115
12116 bgp_unlock_node (rm);
12117 }
paul718e3742002-12-13 20:15:29 +000012118 }
12119 }
12120 else
12121 {
12122 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012123 {
12124 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12125 {
12126 ri = rn->info;
12127 while (ri)
12128 {
12129 if (ri->extra && ri->extra->damp_info)
12130 {
12131 ri_temp = ri->next;
12132 bgp_damp_info_free (ri->extra->damp_info, 1);
12133 ri = ri_temp;
12134 }
12135 else
12136 ri = ri->next;
12137 }
12138 }
12139
12140 bgp_unlock_node (rn);
12141 }
paul718e3742002-12-13 20:15:29 +000012142 }
12143
12144 return CMD_SUCCESS;
12145}
12146
12147DEFUN (clear_ip_bgp_dampening,
12148 clear_ip_bgp_dampening_cmd,
12149 "clear ip bgp dampening",
12150 CLEAR_STR
12151 IP_STR
12152 BGP_STR
12153 "Clear route flap dampening information\n")
12154{
12155 bgp_damp_info_clean ();
12156 return CMD_SUCCESS;
12157}
12158
12159DEFUN (clear_ip_bgp_dampening_prefix,
12160 clear_ip_bgp_dampening_prefix_cmd,
12161 "clear ip bgp dampening A.B.C.D/M",
12162 CLEAR_STR
12163 IP_STR
12164 BGP_STR
12165 "Clear route flap dampening information\n"
12166 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12167{
12168 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12169 SAFI_UNICAST, NULL, 1);
12170}
12171
12172DEFUN (clear_ip_bgp_dampening_address,
12173 clear_ip_bgp_dampening_address_cmd,
12174 "clear ip bgp dampening A.B.C.D",
12175 CLEAR_STR
12176 IP_STR
12177 BGP_STR
12178 "Clear route flap dampening information\n"
12179 "Network to clear damping information\n")
12180{
12181 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12182 SAFI_UNICAST, NULL, 0);
12183}
12184
12185DEFUN (clear_ip_bgp_dampening_address_mask,
12186 clear_ip_bgp_dampening_address_mask_cmd,
12187 "clear ip bgp dampening A.B.C.D A.B.C.D",
12188 CLEAR_STR
12189 IP_STR
12190 BGP_STR
12191 "Clear route flap dampening information\n"
12192 "Network to clear damping information\n"
12193 "Network mask\n")
12194{
12195 int ret;
12196 char prefix_str[BUFSIZ];
12197
12198 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12199 if (! ret)
12200 {
12201 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12202 return CMD_WARNING;
12203 }
12204
12205 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12206 SAFI_UNICAST, NULL, 0);
12207}
David Lamparter6b0655a2014-06-04 06:53:35 +020012208
paul94f2b392005-06-28 12:44:16 +000012209static int
paul718e3742002-12-13 20:15:29 +000012210bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12211 afi_t afi, safi_t safi, int *write)
12212{
12213 struct bgp_node *prn;
12214 struct bgp_node *rn;
12215 struct bgp_table *table;
12216 struct prefix *p;
12217 struct prefix_rd *prd;
12218 struct bgp_static *bgp_static;
12219 u_int32_t label;
12220 char buf[SU_ADDRSTRLEN];
12221 char rdbuf[RD_ADDRSTRLEN];
12222
12223 /* Network configuration. */
12224 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12225 if ((table = prn->info) != NULL)
12226 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12227 if ((bgp_static = rn->info) != NULL)
12228 {
12229 p = &rn->p;
12230 prd = (struct prefix_rd *) &prn->p;
12231
12232 /* "address-family" display. */
12233 bgp_config_write_family_header (vty, afi, safi, write);
12234
12235 /* "network" configuration display. */
12236 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12237 label = decode_label (bgp_static->tag);
12238
12239 vty_out (vty, " network %s/%d rd %s tag %d",
12240 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12241 p->prefixlen,
12242 rdbuf, label);
12243 vty_out (vty, "%s", VTY_NEWLINE);
12244 }
12245 return 0;
12246}
12247
12248/* Configuration of static route announcement and aggregate
12249 information. */
12250int
12251bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12252 afi_t afi, safi_t safi, int *write)
12253{
12254 struct bgp_node *rn;
12255 struct prefix *p;
12256 struct bgp_static *bgp_static;
12257 struct bgp_aggregate *bgp_aggregate;
12258 char buf[SU_ADDRSTRLEN];
12259
12260 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12261 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12262
12263 /* Network configuration. */
12264 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12265 if ((bgp_static = rn->info) != NULL)
12266 {
12267 p = &rn->p;
12268
12269 /* "address-family" display. */
12270 bgp_config_write_family_header (vty, afi, safi, write);
12271
12272 /* "network" configuration display. */
12273 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12274 {
12275 u_int32_t destination;
12276 struct in_addr netmask;
12277
12278 destination = ntohl (p->u.prefix4.s_addr);
12279 masklen2ip (p->prefixlen, &netmask);
12280 vty_out (vty, " network %s",
12281 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12282
12283 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12284 || (IN_CLASSB (destination) && p->prefixlen == 16)
12285 || (IN_CLASSA (destination) && p->prefixlen == 8)
12286 || p->u.prefix4.s_addr == 0)
12287 {
12288 /* Natural mask is not display. */
12289 }
12290 else
12291 vty_out (vty, " mask %s", inet_ntoa (netmask));
12292 }
12293 else
12294 {
12295 vty_out (vty, " network %s/%d",
12296 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12297 p->prefixlen);
12298 }
12299
12300 if (bgp_static->rmap.name)
12301 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012302 else
12303 {
12304 if (bgp_static->backdoor)
12305 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012306 }
paul718e3742002-12-13 20:15:29 +000012307
12308 vty_out (vty, "%s", VTY_NEWLINE);
12309 }
12310
12311 /* Aggregate-address configuration. */
12312 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12313 if ((bgp_aggregate = rn->info) != NULL)
12314 {
12315 p = &rn->p;
12316
12317 /* "address-family" display. */
12318 bgp_config_write_family_header (vty, afi, safi, write);
12319
12320 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12321 {
12322 struct in_addr netmask;
12323
12324 masklen2ip (p->prefixlen, &netmask);
12325 vty_out (vty, " aggregate-address %s %s",
12326 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12327 inet_ntoa (netmask));
12328 }
12329 else
12330 {
12331 vty_out (vty, " aggregate-address %s/%d",
12332 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12333 p->prefixlen);
12334 }
12335
12336 if (bgp_aggregate->as_set)
12337 vty_out (vty, " as-set");
12338
12339 if (bgp_aggregate->summary_only)
12340 vty_out (vty, " summary-only");
12341
12342 vty_out (vty, "%s", VTY_NEWLINE);
12343 }
12344
12345 return 0;
12346}
12347
12348int
12349bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12350{
12351 struct bgp_node *rn;
12352 struct bgp_distance *bdistance;
12353
12354 /* Distance configuration. */
12355 if (bgp->distance_ebgp
12356 && bgp->distance_ibgp
12357 && bgp->distance_local
12358 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12359 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12360 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12361 vty_out (vty, " distance bgp %d %d %d%s",
12362 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12363 VTY_NEWLINE);
12364
12365 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12366 if ((bdistance = rn->info) != NULL)
12367 {
12368 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12369 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12370 bdistance->access_list ? bdistance->access_list : "",
12371 VTY_NEWLINE);
12372 }
12373
12374 return 0;
12375}
12376
12377/* Allocate routing table structure and install commands. */
12378void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012379bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012380{
12381 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012382 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012383
12384 /* IPv4 BGP commands. */
12385 install_element (BGP_NODE, &bgp_network_cmd);
12386 install_element (BGP_NODE, &bgp_network_mask_cmd);
12387 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12388 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12389 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12390 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12391 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12392 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12393 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12394 install_element (BGP_NODE, &no_bgp_network_cmd);
12395 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12396 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12397 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12398 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12399 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12400 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12401 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12402 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12403
12404 install_element (BGP_NODE, &aggregate_address_cmd);
12405 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12406 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12407 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12408 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12409 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12410 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12411 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12412 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12413 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12414 install_element (BGP_NODE, &no_aggregate_address_cmd);
12415 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12416 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12417 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12418 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12419 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12420 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12421 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12422 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12423 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12424
12425 /* IPv4 unicast configuration. */
12426 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12427 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12428 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12429 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12430 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12431 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012432 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012433 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12434 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12435 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12436 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12437 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012438
paul718e3742002-12-13 20:15:29 +000012439 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12440 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12441 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12442 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12443 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12444 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12445 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12446 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12447 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12448 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12449 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12450 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12451 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12452 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12453 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12454 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12455 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12456 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12457 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12458 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12459
12460 /* IPv4 multicast configuration. */
12461 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12462 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12463 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12464 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12465 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12466 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12467 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12468 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12469 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12470 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12471 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12472 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12473 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12474 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12475 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12476 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12477 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12478 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12479 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12480 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12481 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12482 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12483 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12484 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12485 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12486 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12487 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12488 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12489 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12490 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12491 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12492 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12493
12494 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12495 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012496 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012497 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12498 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012499 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012500 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12501 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12502 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12503 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012504 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012505 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12506 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12507 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12508 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12509 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12510 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12511 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12512 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12513 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12514 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12515 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12516 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12517 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12518 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12519 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12520 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12521 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12522 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12523 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12524 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12525 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12526 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12527 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12528 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12529 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012530 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12531 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12532 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12533 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12534 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012535 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12536 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12537 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12538 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12539 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12540 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12541 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12542 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12543 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12544 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12545 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12546 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12547 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12548 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12549 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12550 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12551 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12552 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012553 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012554 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12555 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12556 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12557 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12558 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12559 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12560 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12561 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12562 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12563 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12564 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12565 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12566 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12567 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12568 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12569 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012570 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012571 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012572 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012573 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012574 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012575 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012576 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12577 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012578 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012579 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012580 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012581 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012582 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012583 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012584
12585 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12586 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12587 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012588 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012589 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12590 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12591 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012592 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012593 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12594 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12595 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12596 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12597 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12598 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12599 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12600 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12601 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12602 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12603 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12604 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012605 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12606 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12607 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12608 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12609 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012610 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12611 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12612 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12613 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12614 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12615 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12616 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12617 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12618 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012619 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012620 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012621 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012622 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012623 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012624 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012625 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012626
12627 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12628 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012629 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012630 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12631 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012632 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012633 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12634 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12635 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12636 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012637 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012638 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12639 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12640 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12641 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12642 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12643 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12644 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12645 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12646 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12647 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12648 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12649 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12650 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12651 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12652 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12653 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12654 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12655 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12656 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12657 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12658 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12659 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12660 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12661 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12662 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012663 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12664 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12665 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12666 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12667 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012668 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12669 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12670 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12671 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12672 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12673 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12674 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12675 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12676 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12677 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12678 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12679 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12680 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12681 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12682 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12683 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12684 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12685 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012686 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012687 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12688 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12689 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12690 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12691 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12692 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12693 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12694 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12695 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12696 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12697 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12698 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12699 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12700 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12701 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12702 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012703 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012704 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012705 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012706 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012707 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012708 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012709 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12710 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012711 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012712 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012713 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012714 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012715 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012716 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012717
12718 /* BGP dampening clear commands */
12719 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12720 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12721 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12722 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12723
Paul Jakmaff7924f2006-09-04 01:10:36 +000012724 /* prefix count */
12725 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12726 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12727 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012728#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012729 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12730
paul718e3742002-12-13 20:15:29 +000012731 /* New config IPv6 BGP commands. */
12732 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12733 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12734 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12735 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12736
12737 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12738 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12739 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12740 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12741
G.Balaji73bfe0b2011-09-23 22:36:20 +053012742 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12743 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12744
paul718e3742002-12-13 20:15:29 +000012745 /* Old config IPv6 BGP commands. */
12746 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12747 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12748
12749 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12750 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12751 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12752 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12753
12754 install_element (VIEW_NODE, &show_bgp_cmd);
12755 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012756 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012757 install_element (VIEW_NODE, &show_bgp_route_cmd);
12758 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012759 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012760 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12761 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012762 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012763 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12764 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12765 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12766 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12767 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12768 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12769 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12770 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12771 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12772 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12773 install_element (VIEW_NODE, &show_bgp_community_cmd);
12774 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12775 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12776 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12777 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12778 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12779 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12780 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12781 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12782 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12783 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12784 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12785 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12786 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12787 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12788 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12789 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12790 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12791 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12792 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12793 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12794 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12795 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12796 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12797 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12798 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12799 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12800 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12801 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12802 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012803 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12804 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12805 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12806 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012807 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012808 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012809 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012810 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012811 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012812 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012813 install_element (VIEW_NODE, &show_bgp_view_cmd);
12814 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12815 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12816 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12817 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12818 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12819 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12820 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12821 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12822 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12823 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12824 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12825 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12826 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12827 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12828 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12829 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12830 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012831 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012832 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012833 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012834 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012835 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012836 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012837
12838 /* Restricted:
12839 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12840 */
12841 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12842 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012843 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012844 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12845 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012846 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012847 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12848 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12849 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12850 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12851 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12852 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12853 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12854 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12855 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12856 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12857 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12858 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12859 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12860 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12861 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12862 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12863 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012864 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012865 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012866 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012867 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12868 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12869 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12870 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12871 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12872 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12873 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012874 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012875 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012876 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012877
12878 install_element (ENABLE_NODE, &show_bgp_cmd);
12879 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012880 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012881 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12882 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012883 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012884 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12885 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012886 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012887 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12888 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12889 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12890 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12891 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12892 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12893 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12894 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12895 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12896 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12897 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12898 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12899 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12900 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12901 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12902 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12903 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12904 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12905 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12906 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12907 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12908 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12909 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12910 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12911 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12912 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12913 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12914 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12915 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12916 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12917 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12918 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12919 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12920 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12921 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12922 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12923 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12924 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12925 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12926 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012927 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12928 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12929 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12930 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012931 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012932 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012933 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012934 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012935 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012936 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012937 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12938 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12939 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12940 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12941 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12942 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12943 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12944 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12945 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12946 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12947 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12948 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12949 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12950 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12951 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12952 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12953 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12954 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012955 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012956 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012957 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012958 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012959 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012960 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012961
12962 /* Statistics */
12963 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12964 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12965 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12966 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12967
paul718e3742002-12-13 20:15:29 +000012968 /* old command */
12969 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12970 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12971 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12972 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12973 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12974 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12975 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12976 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12977 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12978 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12979 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12980 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12981 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12982 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12983 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12984 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12985 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12986 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12987 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12988 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12989 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12990 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12991 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12992 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12993 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12994 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12995 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12996 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12997 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12998 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12999 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13000 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13001 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13002 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
13003 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13004 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000013005
paul718e3742002-12-13 20:15:29 +000013006 /* old command */
13007 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
13008 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
13009 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
13010 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
13011 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
13012 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
13013 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
13014 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
13015 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
13016 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
13017 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13018 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13019 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13020 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13021 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13022 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13023 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13024 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13025 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13026 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13027 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13028 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13029 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13030 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13031 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13032 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13033 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13034 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13035 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13036 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13037 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13038 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13039 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13040 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13041 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13042 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13043
13044 /* old command */
13045 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13046 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13047 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13048 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13049
13050 /* old command */
13051 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13052 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13053 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13054 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13055
13056 /* old command */
13057 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13058 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13059 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13060 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13061#endif /* HAVE_IPV6 */
13062
13063 install_element (BGP_NODE, &bgp_distance_cmd);
13064 install_element (BGP_NODE, &no_bgp_distance_cmd);
13065 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13066 install_element (BGP_NODE, &bgp_distance_source_cmd);
13067 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13068 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13069 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13070
13071 install_element (BGP_NODE, &bgp_damp_set_cmd);
13072 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13073 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13074 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13075 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13076 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13077 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13078 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13079 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13080 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013081
13082 /* Deprecated AS-Pathlimit commands */
13083 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13084 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13085 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13086 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13087 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13088 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13089
13090 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13091 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13092 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13093 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13094 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13095 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13096
13097 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13098 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13099 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13100 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13101 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13102 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13103
13104 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13105 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13106 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13107 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13108 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13109 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13110
13111 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13112 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13113 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13114 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13115 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13116 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13117
13118 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13119 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13120 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13121 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13122 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13123 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013124
13125#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013126 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13127 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013128#endif
paul718e3742002-12-13 20:15:29 +000013129}
Chris Caputo228da422009-07-18 05:44:03 +000013130
13131void
13132bgp_route_finish (void)
13133{
13134 bgp_table_unlock (bgp_distance_table);
13135 bgp_distance_table = NULL;
13136}