blob: 40012ac265ad46995f9b5423de22dcd0208724cd [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* BGP routing information
2 Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
23#include "prefix.h"
24#include "linklist.h"
25#include "memory.h"
26#include "command.h"
27#include "stream.h"
28#include "filter.h"
29#include "str.h"
30#include "log.h"
31#include "routemap.h"
32#include "buffer.h"
33#include "sockunion.h"
34#include "plist.h"
35#include "thread.h"
paul200df112005-06-01 11:17:05 +000036#include "workqueue.h"
paul718e3742002-12-13 20:15:29 +000037
38#include "bgpd/bgpd.h"
39#include "bgpd/bgp_table.h"
40#include "bgpd/bgp_route.h"
41#include "bgpd/bgp_attr.h"
42#include "bgpd/bgp_debug.h"
43#include "bgpd/bgp_aspath.h"
44#include "bgpd/bgp_regex.h"
45#include "bgpd/bgp_community.h"
46#include "bgpd/bgp_ecommunity.h"
47#include "bgpd/bgp_clist.h"
48#include "bgpd/bgp_packet.h"
49#include "bgpd/bgp_filter.h"
50#include "bgpd/bgp_fsm.h"
51#include "bgpd/bgp_mplsvpn.h"
52#include "bgpd/bgp_nexthop.h"
53#include "bgpd/bgp_damp.h"
54#include "bgpd/bgp_advertise.h"
55#include "bgpd/bgp_zebra.h"
hasso0a486e52005-02-01 20:57:17 +000056#include "bgpd/bgp_vty.h"
Josh Bailey96450fa2011-07-20 20:45:12 -070057#include "bgpd/bgp_mpath.h"
paul718e3742002-12-13 20:15:29 +000058
59/* Extern from bgp_dump.c */
Stephen Hemmingerdde72582009-05-08 15:19:07 -070060extern const char *bgp_origin_str[];
61extern const char *bgp_origin_long_str[];
David Lamparter6b0655a2014-06-04 06:53:35 +020062
paul94f2b392005-06-28 12:44:16 +000063static struct bgp_node *
paulfee0f4c2004-09-13 05:12:46 +000064bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
paul718e3742002-12-13 20:15:29 +000065 struct prefix_rd *prd)
66{
67 struct bgp_node *rn;
68 struct bgp_node *prn = NULL;
Paul Jakmada5b30f2006-05-08 14:37:17 +000069
70 assert (table);
71 if (!table)
72 return NULL;
73
paul718e3742002-12-13 20:15:29 +000074 if (safi == SAFI_MPLS_VPN)
75 {
paulfee0f4c2004-09-13 05:12:46 +000076 prn = bgp_node_get (table, (struct prefix *) prd);
paul718e3742002-12-13 20:15:29 +000077
78 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +000079 prn->info = bgp_table_init (afi, safi);
paul718e3742002-12-13 20:15:29 +000080 else
81 bgp_unlock_node (prn);
82 table = prn->info;
83 }
paul718e3742002-12-13 20:15:29 +000084
85 rn = bgp_node_get (table, p);
86
87 if (safi == SAFI_MPLS_VPN)
88 rn->prn = prn;
89
90 return rn;
91}
David Lamparter6b0655a2014-06-04 06:53:35 +020092
Paul Jakmafb982c22007-05-04 20:15:47 +000093/* Allocate bgp_info_extra */
94static struct bgp_info_extra *
95bgp_info_extra_new (void)
96{
97 struct bgp_info_extra *new;
98 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
99 return new;
100}
101
102static void
103bgp_info_extra_free (struct bgp_info_extra **extra)
104{
105 if (extra && *extra)
106 {
107 if ((*extra)->damp_info)
108 bgp_damp_info_free ((*extra)->damp_info, 0);
109
110 (*extra)->damp_info = NULL;
111
112 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
113
114 *extra = NULL;
115 }
116}
117
118/* Get bgp_info extra information for the given bgp_info, lazy allocated
119 * if required.
120 */
121struct bgp_info_extra *
122bgp_info_extra_get (struct bgp_info *ri)
123{
124 if (!ri->extra)
125 ri->extra = bgp_info_extra_new();
126 return ri->extra;
127}
128
paul718e3742002-12-13 20:15:29 +0000129/* Allocate new bgp info structure. */
paul200df112005-06-01 11:17:05 +0000130static struct bgp_info *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -0800131bgp_info_new (void)
paul718e3742002-12-13 20:15:29 +0000132{
Stephen Hemminger393deb92008-08-18 14:13:29 -0700133 return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
paul718e3742002-12-13 20:15:29 +0000134}
135
136/* Free bgp route information. */
paul200df112005-06-01 11:17:05 +0000137static void
paul718e3742002-12-13 20:15:29 +0000138bgp_info_free (struct bgp_info *binfo)
139{
140 if (binfo->attr)
Paul Jakmaf6f434b2010-11-23 21:28:03 +0000141 bgp_attr_unintern (&binfo->attr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000142
143 bgp_info_extra_free (&binfo->extra);
Josh Baileyde8d5df2011-07-20 20:46:01 -0700144 bgp_info_mpath_free (&binfo->mpath);
paul718e3742002-12-13 20:15:29 +0000145
paul200df112005-06-01 11:17:05 +0000146 peer_unlock (binfo->peer); /* bgp_info peer reference */
147
paul718e3742002-12-13 20:15:29 +0000148 XFREE (MTYPE_BGP_ROUTE, binfo);
149}
150
paul200df112005-06-01 11:17:05 +0000151struct bgp_info *
152bgp_info_lock (struct bgp_info *binfo)
153{
154 binfo->lock++;
155 return binfo;
156}
157
158struct bgp_info *
159bgp_info_unlock (struct bgp_info *binfo)
160{
161 assert (binfo && binfo->lock > 0);
162 binfo->lock--;
163
164 if (binfo->lock == 0)
165 {
166#if 0
167 zlog_debug ("%s: unlocked and freeing", __func__);
168 zlog_backtrace (LOG_DEBUG);
169#endif
170 bgp_info_free (binfo);
171 return NULL;
172 }
173
174#if 0
175 if (binfo->lock == 1)
176 {
177 zlog_debug ("%s: unlocked to 1", __func__);
178 zlog_backtrace (LOG_DEBUG);
179 }
180#endif
181
182 return binfo;
183}
184
paul718e3742002-12-13 20:15:29 +0000185void
186bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
187{
188 struct bgp_info *top;
189
190 top = rn->info;
paul200df112005-06-01 11:17:05 +0000191
paul718e3742002-12-13 20:15:29 +0000192 ri->next = rn->info;
193 ri->prev = NULL;
194 if (top)
195 top->prev = ri;
196 rn->info = ri;
paul200df112005-06-01 11:17:05 +0000197
198 bgp_info_lock (ri);
199 bgp_lock_node (rn);
200 peer_lock (ri->peer); /* bgp_info peer reference */
paul718e3742002-12-13 20:15:29 +0000201}
202
paulb40d9392005-08-22 22:34:41 +0000203/* Do the actual removal of info from RIB, for use by bgp_process
204 completion callback *only* */
205static void
206bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
paul718e3742002-12-13 20:15:29 +0000207{
208 if (ri->next)
209 ri->next->prev = ri->prev;
210 if (ri->prev)
211 ri->prev->next = ri->next;
212 else
213 rn->info = ri->next;
paul200df112005-06-01 11:17:05 +0000214
Josh Baileyde8d5df2011-07-20 20:46:01 -0700215 bgp_info_mpath_dequeue (ri);
paul200df112005-06-01 11:17:05 +0000216 bgp_info_unlock (ri);
217 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000218}
219
paulb40d9392005-08-22 22:34:41 +0000220void
221bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
222{
Paul Jakma1a392d42006-09-07 00:24:49 +0000223 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
224 /* set of previous already took care of pcount */
paulb40d9392005-08-22 22:34:41 +0000225 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
226}
227
Andrew J. Schorr8d452102006-11-28 19:50:46 +0000228/* undo the effects of a previous call to bgp_info_delete; typically
229 called when a route is deleted and then quickly re-added before the
230 deletion has been processed */
231static void
232bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
233{
234 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
235 /* unset of previous already took care of pcount */
236 SET_FLAG (ri->flags, BGP_INFO_VALID);
237}
238
Paul Jakma1a392d42006-09-07 00:24:49 +0000239/* Adjust pcount as required */
240static void
241bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
242{
Avneesh Sachdev67174042012-08-17 08:19:49 -0700243 struct bgp_table *table;
244
245 assert (rn && bgp_node_table (rn));
Paul Jakma6f585442006-10-22 19:13:07 +0000246 assert (ri && ri->peer && ri->peer->bgp);
247
Avneesh Sachdev67174042012-08-17 08:19:49 -0700248 table = bgp_node_table (rn);
249
Paul Jakma1a392d42006-09-07 00:24:49 +0000250 /* Ignore 'pcount' for RS-client tables */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700251 if (table->type != BGP_TABLE_MAIN
Paul Jakma1a392d42006-09-07 00:24:49 +0000252 || ri->peer == ri->peer->bgp->peer_self)
253 return;
254
255 if (BGP_INFO_HOLDDOWN (ri)
256 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
257 {
258
259 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
260
261 /* slight hack, but more robust against errors. */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700262 if (ri->peer->pcount[table->afi][table->safi])
263 ri->peer->pcount[table->afi][table->safi]--;
Paul Jakma1a392d42006-09-07 00:24:49 +0000264 else
265 {
266 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
267 __func__, ri->peer->host);
268 zlog_backtrace (LOG_WARNING);
269 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
270 }
271 }
272 else if (!BGP_INFO_HOLDDOWN (ri)
273 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
274 {
275 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
Avneesh Sachdev67174042012-08-17 08:19:49 -0700276 ri->peer->pcount[table->afi][table->safi]++;
Paul Jakma1a392d42006-09-07 00:24:49 +0000277 }
278}
279
280
281/* Set/unset bgp_info flags, adjusting any other state as needed.
282 * This is here primarily to keep prefix-count in check.
283 */
284void
285bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
286{
287 SET_FLAG (ri->flags, flag);
288
289 /* early bath if we know it's not a flag that changes useability state */
290 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
291 return;
292
293 bgp_pcount_adjust (rn, ri);
294}
295
296void
297bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
298{
299 UNSET_FLAG (ri->flags, flag);
300
301 /* early bath if we know it's not a flag that changes useability state */
302 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
303 return;
304
305 bgp_pcount_adjust (rn, ri);
306}
307
paul718e3742002-12-13 20:15:29 +0000308/* Get MED value. If MED value is missing and "bgp bestpath
309 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000310static u_int32_t
paul718e3742002-12-13 20:15:29 +0000311bgp_med_value (struct attr *attr, struct bgp *bgp)
312{
313 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
314 return attr->med;
315 else
316 {
317 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000318 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000319 else
320 return 0;
321 }
322}
323
324/* Compare two bgp route entity. br is preferable then return 1. */
paul94f2b392005-06-28 12:44:16 +0000325static int
Josh Bailey96450fa2011-07-20 20:45:12 -0700326bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
327 int *paths_eq)
paul718e3742002-12-13 20:15:29 +0000328{
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000329 struct attr *newattr, *existattr;
330 struct attr_extra *newattre, *existattre;
331 bgp_peer_sort_t new_sort;
332 bgp_peer_sort_t exist_sort;
paul718e3742002-12-13 20:15:29 +0000333 u_int32_t new_pref;
334 u_int32_t exist_pref;
335 u_int32_t new_med;
336 u_int32_t exist_med;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000337 u_int32_t new_weight;
338 u_int32_t exist_weight;
339 uint32_t newm, existm;
paul718e3742002-12-13 20:15:29 +0000340 struct in_addr new_id;
341 struct in_addr exist_id;
342 int new_cluster;
343 int exist_cluster;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000344 int internal_as_route;
345 int confed_as_route;
paul718e3742002-12-13 20:15:29 +0000346 int ret;
Josh Bailey96450fa2011-07-20 20:45:12 -0700347
348 *paths_eq = 0;
paul718e3742002-12-13 20:15:29 +0000349
350 /* 0. Null check. */
351 if (new == NULL)
352 return 0;
353 if (exist == NULL)
354 return 1;
355
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000356 newattr = new->attr;
357 existattr = exist->attr;
358 newattre = newattr->extra;
359 existattre = existattr->extra;
360
paul718e3742002-12-13 20:15:29 +0000361 /* 1. Weight check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000362 new_weight = exist_weight = 0;
363
364 if (newattre)
365 new_weight = newattre->weight;
366 if (existattre)
367 exist_weight = existattre->weight;
368
Paul Jakmafb982c22007-05-04 20:15:47 +0000369 if (new_weight > exist_weight)
paul718e3742002-12-13 20:15:29 +0000370 return 1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000371 if (new_weight < exist_weight)
paul718e3742002-12-13 20:15:29 +0000372 return 0;
373
374 /* 2. Local preference check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000375 new_pref = exist_pref = bgp->default_local_pref;
paul718e3742002-12-13 20:15:29 +0000376
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000377 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
378 new_pref = newattr->local_pref;
379 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
380 exist_pref = existattr->local_pref;
381
paul718e3742002-12-13 20:15:29 +0000382 if (new_pref > exist_pref)
383 return 1;
384 if (new_pref < exist_pref)
385 return 0;
386
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000387 /* 3. Local route check. We prefer:
388 * - BGP_ROUTE_STATIC
389 * - BGP_ROUTE_AGGREGATE
390 * - BGP_ROUTE_REDISTRIBUTE
391 */
392 if (! (new->sub_type == BGP_ROUTE_NORMAL))
393 return 1;
394 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
395 return 0;
paul718e3742002-12-13 20:15:29 +0000396
397 /* 4. AS path length check. */
398 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
399 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000400 int exist_hops = aspath_count_hops (existattr->aspath);
401 int exist_confeds = aspath_count_confeds (existattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000402
hasso68118452005-04-08 15:40:36 +0000403 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
404 {
paulfe69a502005-09-10 16:55:02 +0000405 int aspath_hops;
406
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000407 aspath_hops = aspath_count_hops (newattr->aspath);
408 aspath_hops += aspath_count_confeds (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000409
410 if ( aspath_hops < (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000411 return 1;
paulfe69a502005-09-10 16:55:02 +0000412 if ( aspath_hops > (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000413 return 0;
414 }
415 else
416 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000417 int newhops = aspath_count_hops (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000418
419 if (newhops < exist_hops)
hasso68118452005-04-08 15:40:36 +0000420 return 1;
paulfe69a502005-09-10 16:55:02 +0000421 if (newhops > exist_hops)
hasso68118452005-04-08 15:40:36 +0000422 return 0;
423 }
paul718e3742002-12-13 20:15:29 +0000424 }
425
426 /* 5. Origin check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000427 if (newattr->origin < existattr->origin)
paul718e3742002-12-13 20:15:29 +0000428 return 1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000429 if (newattr->origin > existattr->origin)
paul718e3742002-12-13 20:15:29 +0000430 return 0;
431
432 /* 6. MED check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000433 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
434 && aspath_count_hops (existattr->aspath) == 0);
435 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
436 && aspath_count_confeds (existattr->aspath) > 0
437 && aspath_count_hops (newattr->aspath) == 0
438 && aspath_count_hops (existattr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000439
440 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
441 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
442 && confed_as_route)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000443 || aspath_cmp_left (newattr->aspath, existattr->aspath)
444 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
paul718e3742002-12-13 20:15:29 +0000445 || internal_as_route)
446 {
447 new_med = bgp_med_value (new->attr, bgp);
448 exist_med = bgp_med_value (exist->attr, bgp);
449
450 if (new_med < exist_med)
451 return 1;
452 if (new_med > exist_med)
453 return 0;
454 }
455
456 /* 7. Peer type check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000457 new_sort = new->peer->sort;
458 exist_sort = exist->peer->sort;
459
460 if (new_sort == BGP_PEER_EBGP
461 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
paul718e3742002-12-13 20:15:29 +0000462 return 1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000463 if (exist_sort == BGP_PEER_EBGP
464 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
paul718e3742002-12-13 20:15:29 +0000465 return 0;
466
467 /* 8. IGP metric check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000468 newm = existm = 0;
469
470 if (new->extra)
471 newm = new->extra->igpmetric;
472 if (exist->extra)
473 existm = exist->extra->igpmetric;
474
Josh Bailey96450fa2011-07-20 20:45:12 -0700475 if (newm < existm)
476 ret = 1;
477 if (newm > existm)
478 ret = 0;
paul718e3742002-12-13 20:15:29 +0000479
480 /* 9. Maximum path check. */
Josh Bailey96450fa2011-07-20 20:45:12 -0700481 if (newm == existm)
482 {
Pradosh Mohapatra2fdd4552013-09-07 07:02:36 +0000483 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
484 {
485
486 /*
487 * For the two paths, all comparison steps till IGP metric
488 * have succeeded - including AS_PATH hop count. Since 'bgp
489 * bestpath as-path multipath-relax' knob is on, we don't need
490 * an exact match of AS_PATH. Thus, mark the paths are equal.
491 * That will trigger both these paths to get into the multipath
492 * array.
493 */
494 *paths_eq = 1;
495 }
496 else if (new->peer->sort == BGP_PEER_IBGP)
Josh Bailey96450fa2011-07-20 20:45:12 -0700497 {
498 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
499 *paths_eq = 1;
500 }
501 else if (new->peer->as == exist->peer->as)
502 *paths_eq = 1;
503 }
504 else
505 {
506 /*
507 * TODO: If unequal cost ibgp multipath is enabled we can
508 * mark the paths as equal here instead of returning
509 */
510 return ret;
511 }
paul718e3742002-12-13 20:15:29 +0000512
513 /* 10. If both paths are external, prefer the path that was received
514 first (the oldest one). This step minimizes route-flap, since a
515 newer path won't displace an older one, even if it was the
516 preferred route based on the additional decision criteria below. */
517 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000518 && new_sort == BGP_PEER_EBGP
519 && exist_sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +0000520 {
521 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
522 return 1;
523 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
524 return 0;
525 }
526
vivekbd4b7f12014-09-30 15:54:45 -0700527 /* 11. Router-ID comparision. */
528 /* If one of the paths is "stale", the corresponding peer router-id will
529 * be 0 and would always win over the other path. If originator id is
530 * used for the comparision, it will decide which path is better.
531 */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000532 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
533 new_id.s_addr = newattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000534 else
535 new_id.s_addr = new->peer->remote_id.s_addr;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000536 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
537 exist_id.s_addr = existattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000538 else
539 exist_id.s_addr = exist->peer->remote_id.s_addr;
540
541 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
542 return 1;
543 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
544 return 0;
545
546 /* 12. Cluster length comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000547 new_cluster = exist_cluster = 0;
548
549 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
550 new_cluster = newattre->cluster->length;
551 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
552 exist_cluster = existattre->cluster->length;
paul718e3742002-12-13 20:15:29 +0000553
554 if (new_cluster < exist_cluster)
555 return 1;
556 if (new_cluster > exist_cluster)
557 return 0;
558
559 /* 13. Neighbor address comparision. */
vivekbd4b7f12014-09-30 15:54:45 -0700560 /* Do this only if neither path is "stale" as stale paths do not have
561 * valid peer information (as the connection may or may not be up).
562 */
563 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
564 return 1;
565 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
566 return 0;
Timo Teräs2820a012015-06-24 15:27:21 +0300567 /* locally configured routes to advertise do not have su_remote */
568 if (new->peer->su_remote == NULL)
569 return 0;
570 if (exist->peer->su_remote == NULL)
571 return 1;
572
paul718e3742002-12-13 20:15:29 +0000573 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
574
575 if (ret == 1)
576 return 0;
577 if (ret == -1)
578 return 1;
579
580 return 1;
581}
582
paul94f2b392005-06-28 12:44:16 +0000583static enum filter_type
paul718e3742002-12-13 20:15:29 +0000584bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
585 afi_t afi, safi_t safi)
586{
587 struct bgp_filter *filter;
588
589 filter = &peer->filter[afi][safi];
590
Paul Jakma650f76c2009-06-25 18:06:31 +0100591#define FILTER_EXIST_WARN(F,f,filter) \
592 if (BGP_DEBUG (update, UPDATE_IN) \
593 && !(F ## _IN (filter))) \
594 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
595 peer->host, #f, F ## _IN_NAME(filter));
596
597 if (DISTRIBUTE_IN_NAME (filter)) {
598 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
599
paul718e3742002-12-13 20:15:29 +0000600 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
601 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100602 }
paul718e3742002-12-13 20:15:29 +0000603
Paul Jakma650f76c2009-06-25 18:06:31 +0100604 if (PREFIX_LIST_IN_NAME (filter)) {
605 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
606
paul718e3742002-12-13 20:15:29 +0000607 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
608 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100609 }
paul718e3742002-12-13 20:15:29 +0000610
Paul Jakma650f76c2009-06-25 18:06:31 +0100611 if (FILTER_LIST_IN_NAME (filter)) {
612 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
613
paul718e3742002-12-13 20:15:29 +0000614 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
615 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100616 }
617
paul718e3742002-12-13 20:15:29 +0000618 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100619#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000620}
621
paul94f2b392005-06-28 12:44:16 +0000622static enum filter_type
paul718e3742002-12-13 20:15:29 +0000623bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
624 afi_t afi, safi_t safi)
625{
626 struct bgp_filter *filter;
627
628 filter = &peer->filter[afi][safi];
629
Paul Jakma650f76c2009-06-25 18:06:31 +0100630#define FILTER_EXIST_WARN(F,f,filter) \
631 if (BGP_DEBUG (update, UPDATE_OUT) \
632 && !(F ## _OUT (filter))) \
633 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
634 peer->host, #f, F ## _OUT_NAME(filter));
635
636 if (DISTRIBUTE_OUT_NAME (filter)) {
637 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
638
paul718e3742002-12-13 20:15:29 +0000639 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
640 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100641 }
paul718e3742002-12-13 20:15:29 +0000642
Paul Jakma650f76c2009-06-25 18:06:31 +0100643 if (PREFIX_LIST_OUT_NAME (filter)) {
644 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
645
paul718e3742002-12-13 20:15:29 +0000646 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
647 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100648 }
paul718e3742002-12-13 20:15:29 +0000649
Paul Jakma650f76c2009-06-25 18:06:31 +0100650 if (FILTER_LIST_OUT_NAME (filter)) {
651 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
652
paul718e3742002-12-13 20:15:29 +0000653 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
654 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100655 }
paul718e3742002-12-13 20:15:29 +0000656
657 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100658#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000659}
660
661/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000662static int
paul718e3742002-12-13 20:15:29 +0000663bgp_community_filter (struct peer *peer, struct attr *attr)
664{
665 if (attr->community)
666 {
667 /* NO_ADVERTISE check. */
668 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
669 return 1;
670
671 /* NO_EXPORT check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000672 if (peer->sort == BGP_PEER_EBGP &&
paul718e3742002-12-13 20:15:29 +0000673 community_include (attr->community, COMMUNITY_NO_EXPORT))
674 return 1;
675
676 /* NO_EXPORT_SUBCONFED check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000677 if (peer->sort == BGP_PEER_EBGP
678 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000679 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
680 return 1;
681 }
682 return 0;
683}
684
685/* Route reflection loop check. */
686static int
687bgp_cluster_filter (struct peer *peer, struct attr *attr)
688{
689 struct in_addr cluster_id;
690
Paul Jakmafb982c22007-05-04 20:15:47 +0000691 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000692 {
693 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
694 cluster_id = peer->bgp->cluster_id;
695 else
696 cluster_id = peer->bgp->router_id;
697
Paul Jakmafb982c22007-05-04 20:15:47 +0000698 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000699 return 1;
700 }
701 return 0;
702}
David Lamparter6b0655a2014-06-04 06:53:35 +0200703
paul94f2b392005-06-28 12:44:16 +0000704static int
paul718e3742002-12-13 20:15:29 +0000705bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
706 afi_t afi, safi_t safi)
707{
708 struct bgp_filter *filter;
709 struct bgp_info info;
710 route_map_result_t ret;
711
712 filter = &peer->filter[afi][safi];
713
714 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000715 if (peer->weight)
716 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000717
718 /* Route map apply. */
719 if (ROUTE_MAP_IN_NAME (filter))
720 {
721 /* Duplicate current value to new strucutre for modification. */
722 info.peer = peer;
723 info.attr = attr;
724
paulac41b2a2003-08-12 05:32:27 +0000725 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
726
paul718e3742002-12-13 20:15:29 +0000727 /* Apply BGP route map to the attribute. */
728 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000729
730 peer->rmap_type = 0;
731
paul718e3742002-12-13 20:15:29 +0000732 if (ret == RMAP_DENYMATCH)
David Lamparterc460e572014-06-04 00:54:58 +0200733 /* caller has multiple error paths with bgp_attr_flush() */
734 return RMAP_DENY;
paul718e3742002-12-13 20:15:29 +0000735 }
736 return RMAP_PERMIT;
737}
David Lamparter6b0655a2014-06-04 06:53:35 +0200738
paul94f2b392005-06-28 12:44:16 +0000739static int
paulfee0f4c2004-09-13 05:12:46 +0000740bgp_export_modifier (struct peer *rsclient, struct peer *peer,
741 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
742{
743 struct bgp_filter *filter;
744 struct bgp_info info;
745 route_map_result_t ret;
746
747 filter = &peer->filter[afi][safi];
748
749 /* Route map apply. */
750 if (ROUTE_MAP_EXPORT_NAME (filter))
751 {
752 /* Duplicate current value to new strucutre for modification. */
753 info.peer = rsclient;
754 info.attr = attr;
755
756 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
757
758 /* Apply BGP route map to the attribute. */
759 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
760
761 rsclient->rmap_type = 0;
762
763 if (ret == RMAP_DENYMATCH)
764 {
765 /* Free newly generated AS path and community by route-map. */
766 bgp_attr_flush (attr);
767 return RMAP_DENY;
768 }
769 }
770 return RMAP_PERMIT;
771}
772
paul94f2b392005-06-28 12:44:16 +0000773static int
paulfee0f4c2004-09-13 05:12:46 +0000774bgp_import_modifier (struct peer *rsclient, struct peer *peer,
775 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
776{
777 struct bgp_filter *filter;
778 struct bgp_info info;
779 route_map_result_t ret;
780
781 filter = &rsclient->filter[afi][safi];
782
783 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000784 if (peer->weight)
785 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000786
787 /* Route map apply. */
788 if (ROUTE_MAP_IMPORT_NAME (filter))
789 {
790 /* Duplicate current value to new strucutre for modification. */
791 info.peer = peer;
792 info.attr = attr;
793
794 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
795
796 /* Apply BGP route map to the attribute. */
797 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
798
799 peer->rmap_type = 0;
800
801 if (ret == RMAP_DENYMATCH)
802 {
803 /* Free newly generated AS path and community by route-map. */
804 bgp_attr_flush (attr);
805 return RMAP_DENY;
806 }
807 }
808 return RMAP_PERMIT;
809}
David Lamparter6b0655a2014-06-04 06:53:35 +0200810
paul94f2b392005-06-28 12:44:16 +0000811static int
paul718e3742002-12-13 20:15:29 +0000812bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
813 struct attr *attr, afi_t afi, safi_t safi)
814{
815 int ret;
816 char buf[SU_ADDRSTRLEN];
817 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000818 struct peer *from;
819 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000820 int transparent;
821 int reflect;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700822 struct attr *riattr;
paul718e3742002-12-13 20:15:29 +0000823
824 from = ri->peer;
825 filter = &peer->filter[afi][safi];
826 bgp = peer->bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700827 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paul718e3742002-12-13 20:15:29 +0000828
Paul Jakma750e8142008-07-22 21:11:48 +0000829 if (DISABLE_BGP_ANNOUNCE)
830 return 0;
paul718e3742002-12-13 20:15:29 +0000831
paulfee0f4c2004-09-13 05:12:46 +0000832 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
833 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
834 return 0;
835
paul718e3742002-12-13 20:15:29 +0000836 /* Do not send back route to sender. */
837 if (from == peer)
838 return 0;
839
840 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000841 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000842 if (! UNSUPPRESS_MAP_NAME (filter))
843 return 0;
844
845 /* Default route check. */
846 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
847 {
848 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
849 return 0;
850#ifdef HAVE_IPV6
851 else if (p->family == AF_INET6 && p->prefixlen == 0)
852 return 0;
853#endif /* HAVE_IPV6 */
854 }
855
paul286e1e72003-08-08 00:24:31 +0000856 /* Transparency check. */
857 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
858 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
859 transparent = 1;
860 else
861 transparent = 0;
862
paul718e3742002-12-13 20:15:29 +0000863 /* If community is not disabled check the no-export and local. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700864 if (! transparent && bgp_community_filter (peer, riattr))
paul718e3742002-12-13 20:15:29 +0000865 return 0;
866
867 /* If the attribute has originator-id and it is same as remote
868 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700869 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paul718e3742002-12-13 20:15:29 +0000870 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700871 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000872 {
873 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000874 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000875 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
876 peer->host,
877 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
878 p->prefixlen);
879 return 0;
880 }
881 }
882
883 /* ORF prefix-list filter check */
884 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
885 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
886 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
887 if (peer->orf_plist[afi][safi])
888 {
889 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
890 return 0;
891 }
892
893 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700894 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
paul718e3742002-12-13 20:15:29 +0000895 {
896 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000897 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000898 "%s [Update:SEND] %s/%d is filtered",
899 peer->host,
900 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
901 p->prefixlen);
902 return 0;
903 }
904
905#ifdef BGP_SEND_ASPATH_CHECK
906 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700907 if (aspath_loop_check (riattr->aspath, peer->as))
paul718e3742002-12-13 20:15:29 +0000908 {
909 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000910 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400911 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000912 peer->host, peer->as);
913 return 0;
914 }
915#endif /* BGP_SEND_ASPATH_CHECK */
916
917 /* If we're a CONFED we need to loop check the CONFED ID too */
918 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
919 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700920 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
paul718e3742002-12-13 20:15:29 +0000921 {
922 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000923 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400924 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000925 peer->host,
926 bgp->confed_id);
927 return 0;
928 }
929 }
930
931 /* Route-Reflect check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000932 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +0000933 reflect = 1;
934 else
935 reflect = 0;
936
937 /* IBGP reflection check. */
938 if (reflect)
939 {
940 /* A route from a Client peer. */
941 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
942 {
943 /* Reflect to all the Non-Client peers and also to the
944 Client peers other than the originator. Originator check
945 is already done. So there is noting to do. */
946 /* no bgp client-to-client reflection check. */
947 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
948 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
949 return 0;
950 }
951 else
952 {
953 /* A route from a Non-client peer. Reflect to all other
954 clients. */
955 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
956 return 0;
957 }
958 }
Paul Jakma41367172007-08-06 15:24:51 +0000959
paul718e3742002-12-13 20:15:29 +0000960 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700961 bgp_attr_dup (attr, riattr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000962
paul718e3742002-12-13 20:15:29 +0000963 /* If local-preference is not set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000964 if ((peer->sort == BGP_PEER_IBGP
965 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000966 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
967 {
968 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
969 attr->local_pref = bgp->default_local_pref;
970 }
971
Pradosh Mohapatra689bb662013-09-07 07:13:37 +0000972 /* If originator-id is not set and the route is to be reflected,
973 set the originator id */
974 if (peer && from && peer->sort == BGP_PEER_IBGP &&
975 from->sort == BGP_PEER_IBGP &&
976 (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
977 {
978 attr->extra = bgp_attr_extra_get(attr);
979 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
980 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
981 }
982
paul718e3742002-12-13 20:15:29 +0000983 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000984 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000985 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
986 {
987 if (ri->peer != bgp->peer_self && ! transparent
988 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
989 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
990 }
991
992 /* next-hop-set */
Timo Teräs9e7a53c2014-04-24 10:22:37 +0300993 if (transparent
994 || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
paul718e3742002-12-13 20:15:29 +0000995 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
996 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000997#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000998 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000999 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +00001000#endif /* HAVE_IPV6 */
1001 )))
paul718e3742002-12-13 20:15:29 +00001002 {
1003 /* NEXT-HOP Unchanged. */
1004 }
1005 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
1006 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
1007#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +00001008 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001009 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +00001010#endif /* HAVE_IPV6 */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001011 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001012 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
1013 {
1014 /* Set IPv4 nexthop. */
1015 if (p->family == AF_INET)
1016 {
1017 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001018 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1019 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +00001020 else
1021 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1022 }
1023#ifdef HAVE_IPV6
1024 /* Set IPv6 nexthop. */
1025 if (p->family == AF_INET6)
1026 {
1027 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001028 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001029 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001030 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001031 }
1032#endif /* HAVE_IPV6 */
1033 }
1034
1035#ifdef HAVE_IPV6
1036 if (p->family == AF_INET6)
1037 {
paulfee0f4c2004-09-13 05:12:46 +00001038 /* Left nexthop_local unchanged if so configured. */
1039 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1040 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1041 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001042 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1043 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001044 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001045 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001046 }
1047
1048 /* Default nexthop_local treatment for non-RS-Clients */
1049 else
1050 {
paul718e3742002-12-13 20:15:29 +00001051 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001052 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001053
1054 /* Set link-local address for shared network peer. */
1055 if (peer->shared_network
1056 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1057 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001058 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001059 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001060 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001061 }
1062
1063 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1064 address.*/
1065 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001066 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001067
1068 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1069 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001070 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001071 }
paulfee0f4c2004-09-13 05:12:46 +00001072
1073 }
paul718e3742002-12-13 20:15:29 +00001074#endif /* HAVE_IPV6 */
1075
1076 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001077 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001078 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1079 && aspath_private_as_check (attr->aspath))
1080 attr->aspath = aspath_empty_get ();
1081
1082 /* Route map & unsuppress-map apply. */
1083 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001084 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001085 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001086 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001087 struct attr dummy_attr;
1088 struct attr_extra dummy_extra;
1089
1090 dummy_attr.extra = &dummy_extra;
1091
paul718e3742002-12-13 20:15:29 +00001092 info.peer = peer;
1093 info.attr = attr;
1094
1095 /* The route reflector is not allowed to modify the attributes
1096 of the reflected IBGP routes. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001097 if (from->sort == BGP_PEER_IBGP
1098 && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +00001099 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001100 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001101 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001102 }
paulac41b2a2003-08-12 05:32:27 +00001103
1104 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1105
Paul Jakmafb982c22007-05-04 20:15:47 +00001106 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001107 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1108 else
1109 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1110
paulac41b2a2003-08-12 05:32:27 +00001111 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001112
paul718e3742002-12-13 20:15:29 +00001113 if (ret == RMAP_DENYMATCH)
1114 {
1115 bgp_attr_flush (attr);
1116 return 0;
1117 }
1118 }
1119 return 1;
1120}
1121
paul94f2b392005-06-28 12:44:16 +00001122static int
paulfee0f4c2004-09-13 05:12:46 +00001123bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1124 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001125{
paulfee0f4c2004-09-13 05:12:46 +00001126 int ret;
1127 char buf[SU_ADDRSTRLEN];
1128 struct bgp_filter *filter;
1129 struct bgp_info info;
1130 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001131 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001132
1133 from = ri->peer;
1134 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001135 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001136
Paul Jakma750e8142008-07-22 21:11:48 +00001137 if (DISABLE_BGP_ANNOUNCE)
1138 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001139
1140 /* Do not send back route to sender. */
1141 if (from == rsclient)
1142 return 0;
1143
1144 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001145 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001146 if (! UNSUPPRESS_MAP_NAME (filter))
1147 return 0;
1148
1149 /* Default route check. */
1150 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1151 PEER_STATUS_DEFAULT_ORIGINATE))
1152 {
1153 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1154 return 0;
1155#ifdef HAVE_IPV6
1156 else if (p->family == AF_INET6 && p->prefixlen == 0)
1157 return 0;
1158#endif /* HAVE_IPV6 */
1159 }
1160
1161 /* If the attribute has originator-id and it is same as remote
1162 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001163 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001164 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001165 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001166 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001167 {
1168 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001169 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001170 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1171 rsclient->host,
1172 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1173 p->prefixlen);
1174 return 0;
1175 }
1176 }
1177
1178 /* ORF prefix-list filter check */
1179 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1180 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1181 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1182 if (rsclient->orf_plist[afi][safi])
1183 {
1184 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1185 return 0;
1186 }
1187
1188 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001189 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001190 {
1191 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001192 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001193 "%s [Update:SEND] %s/%d is filtered",
1194 rsclient->host,
1195 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1196 p->prefixlen);
1197 return 0;
1198 }
1199
1200#ifdef BGP_SEND_ASPATH_CHECK
1201 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001202 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001203 {
1204 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001205 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001206 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001207 rsclient->host, rsclient->as);
1208 return 0;
1209 }
1210#endif /* BGP_SEND_ASPATH_CHECK */
1211
1212 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001213 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001214
1215 /* next-hop-set */
1216 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1217#ifdef HAVE_IPV6
1218 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001219 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001220#endif /* HAVE_IPV6 */
1221 )
1222 {
1223 /* Set IPv4 nexthop. */
1224 if (p->family == AF_INET)
1225 {
1226 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001227 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001228 IPV4_MAX_BYTELEN);
1229 else
1230 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1231 }
1232#ifdef HAVE_IPV6
1233 /* Set IPv6 nexthop. */
1234 if (p->family == AF_INET6)
1235 {
1236 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001237 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001238 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001239 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001240 }
1241#endif /* HAVE_IPV6 */
1242 }
1243
1244#ifdef HAVE_IPV6
1245 if (p->family == AF_INET6)
1246 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001247 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001248
paulfee0f4c2004-09-13 05:12:46 +00001249 /* Left nexthop_local unchanged if so configured. */
1250 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1251 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1252 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001253 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1254 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001255 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001256 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001257 }
1258
1259 /* Default nexthop_local treatment for RS-Clients */
1260 else
1261 {
1262 /* Announcer and RS-Client are both in the same network */
1263 if (rsclient->shared_network && from->shared_network &&
1264 (rsclient->ifindex == from->ifindex))
1265 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001266 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1267 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001268 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001269 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001270 }
1271
1272 /* Set link-local address for shared network peer. */
1273 else if (rsclient->shared_network
1274 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1275 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001276 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001277 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001278 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001279 }
1280
1281 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001282 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001283 }
1284
1285 }
1286#endif /* HAVE_IPV6 */
1287
1288
1289 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001290 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001291 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1292 && aspath_private_as_check (attr->aspath))
1293 attr->aspath = aspath_empty_get ();
1294
1295 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001296 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001297 {
1298 info.peer = rsclient;
1299 info.attr = attr;
1300
1301 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1302
Paul Jakmafb982c22007-05-04 20:15:47 +00001303 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001304 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1305 else
1306 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1307
1308 rsclient->rmap_type = 0;
1309
1310 if (ret == RMAP_DENYMATCH)
1311 {
1312 bgp_attr_flush (attr);
1313 return 0;
1314 }
1315 }
1316
1317 return 1;
1318}
1319
1320struct bgp_info_pair
1321{
1322 struct bgp_info *old;
1323 struct bgp_info *new;
1324};
1325
paul94f2b392005-06-28 12:44:16 +00001326static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001327bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1328 struct bgp_maxpaths_cfg *mpath_cfg,
1329 struct bgp_info_pair *result)
paulfee0f4c2004-09-13 05:12:46 +00001330{
paul718e3742002-12-13 20:15:29 +00001331 struct bgp_info *new_select;
1332 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001333 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001334 struct bgp_info *ri1;
1335 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001336 struct bgp_info *nextri = NULL;
Josh Bailey96450fa2011-07-20 20:45:12 -07001337 int paths_eq, do_mpath;
1338 struct list mp_list;
1339
1340 bgp_mp_list_init (&mp_list);
1341 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1342 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1343
paul718e3742002-12-13 20:15:29 +00001344 /* bgp deterministic-med */
1345 new_select = NULL;
1346 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1347 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1348 {
1349 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1350 continue;
1351 if (BGP_INFO_HOLDDOWN (ri1))
1352 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001353 if (ri1->peer && ri1->peer != bgp->peer_self)
1354 if (ri1->peer->status != Established)
1355 continue;
paul718e3742002-12-13 20:15:29 +00001356
1357 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001358 if (do_mpath)
1359 bgp_mp_list_add (&mp_list, ri1);
1360 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001361 if (ri1->next)
1362 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1363 {
1364 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1365 continue;
1366 if (BGP_INFO_HOLDDOWN (ri2))
1367 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001368 if (ri2->peer &&
1369 ri2->peer != bgp->peer_self &&
1370 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1371 if (ri2->peer->status != Established)
1372 continue;
paul718e3742002-12-13 20:15:29 +00001373
1374 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1375 || aspath_cmp_left_confed (ri1->attr->aspath,
1376 ri2->attr->aspath))
1377 {
Josh Bailey6918e742011-07-20 20:48:20 -07001378 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1379 old_select = ri2;
Josh Bailey96450fa2011-07-20 20:45:12 -07001380 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
paul718e3742002-12-13 20:15:29 +00001381 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001382 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001383 new_select = ri2;
Josh Bailey6918e742011-07-20 20:48:20 -07001384 if (do_mpath && !paths_eq)
1385 {
1386 bgp_mp_list_clear (&mp_list);
1387 bgp_mp_list_add (&mp_list, ri2);
1388 }
paul718e3742002-12-13 20:15:29 +00001389 }
1390
Josh Bailey6918e742011-07-20 20:48:20 -07001391 if (do_mpath && paths_eq)
1392 bgp_mp_list_add (&mp_list, ri2);
1393
Paul Jakma1a392d42006-09-07 00:24:49 +00001394 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001395 }
1396 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001397 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1398 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001399
1400 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1401 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001402 }
1403
1404 /* Check old selected route and new selected route. */
1405 old_select = NULL;
1406 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001407 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001408 {
1409 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1410 old_select = ri;
1411
1412 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001413 {
1414 /* reap REMOVED routes, if needs be
1415 * selected route must stay for a while longer though
1416 */
1417 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1418 && (ri != old_select))
1419 bgp_info_reap (rn, ri);
1420
1421 continue;
1422 }
paul718e3742002-12-13 20:15:29 +00001423
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001424 if (ri->peer &&
1425 ri->peer != bgp->peer_self &&
1426 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1427 if (ri->peer->status != Established)
1428 continue;
1429
paul718e3742002-12-13 20:15:29 +00001430 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1431 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1432 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001433 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001434 continue;
1435 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001436 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1437 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001438
Josh Bailey96450fa2011-07-20 20:45:12 -07001439 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1440 {
Josh Bailey6918e742011-07-20 20:48:20 -07001441 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1442 bgp_mp_dmed_deselect (new_select);
1443
Josh Bailey96450fa2011-07-20 20:45:12 -07001444 new_select = ri;
1445
1446 if (do_mpath && !paths_eq)
1447 {
1448 bgp_mp_list_clear (&mp_list);
1449 bgp_mp_list_add (&mp_list, ri);
1450 }
1451 }
Josh Bailey6918e742011-07-20 20:48:20 -07001452 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1453 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001454
1455 if (do_mpath && paths_eq)
1456 bgp_mp_list_add (&mp_list, ri);
paul718e3742002-12-13 20:15:29 +00001457 }
paulb40d9392005-08-22 22:34:41 +00001458
paulfee0f4c2004-09-13 05:12:46 +00001459
Josh Bailey6918e742011-07-20 20:48:20 -07001460 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1461 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
Josh Bailey96450fa2011-07-20 20:45:12 -07001462
Josh Bailey0b597ef2011-07-20 20:49:11 -07001463 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001464 bgp_mp_list_clear (&mp_list);
1465
1466 result->old = old_select;
1467 result->new = new_select;
1468
1469 return;
paulfee0f4c2004-09-13 05:12:46 +00001470}
1471
paul94f2b392005-06-28 12:44:16 +00001472static int
paulfee0f4c2004-09-13 05:12:46 +00001473bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001474 struct bgp_node *rn, afi_t afi, safi_t safi)
1475{
paulfee0f4c2004-09-13 05:12:46 +00001476 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001477 struct attr attr;
1478 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001479
1480 p = &rn->p;
1481
Paul Jakma9eda90c2007-08-30 13:36:17 +00001482 /* Announce route to Established peer. */
1483 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001484 return 0;
1485
Paul Jakma9eda90c2007-08-30 13:36:17 +00001486 /* Address family configuration check. */
1487 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001488 return 0;
1489
Paul Jakma9eda90c2007-08-30 13:36:17 +00001490 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001491 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1492 PEER_STATUS_ORF_WAIT_REFRESH))
1493 return 0;
1494
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001495 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1496 attr.extra = &extra;
1497
Avneesh Sachdev67174042012-08-17 08:19:49 -07001498 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001499 {
1500 case BGP_TABLE_MAIN:
1501 /* Announcement to peer->conf. If the route is filtered,
1502 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001503 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1504 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001505 else
1506 bgp_adj_out_unset (rn, peer, p, afi, safi);
1507 break;
1508 case BGP_TABLE_RSCLIENT:
1509 /* Announcement to peer->conf. If the route is filtered,
1510 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001511 if (selected &&
1512 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1513 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1514 else
1515 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001516 break;
1517 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001518
paulfee0f4c2004-09-13 05:12:46 +00001519 return 0;
paul200df112005-06-01 11:17:05 +00001520}
paulfee0f4c2004-09-13 05:12:46 +00001521
paul200df112005-06-01 11:17:05 +00001522struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001523{
paul200df112005-06-01 11:17:05 +00001524 struct bgp *bgp;
1525 struct bgp_node *rn;
1526 afi_t afi;
1527 safi_t safi;
1528};
1529
1530static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001531bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001532{
paul0fb58d52005-11-14 14:31:49 +00001533 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001534 struct bgp *bgp = pq->bgp;
1535 struct bgp_node *rn = pq->rn;
1536 afi_t afi = pq->afi;
1537 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001538 struct bgp_info *new_select;
1539 struct bgp_info *old_select;
1540 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001541 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001542 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001543
paulfee0f4c2004-09-13 05:12:46 +00001544 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001545 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001546 new_select = old_and_new.new;
1547 old_select = old_and_new.old;
1548
paul200df112005-06-01 11:17:05 +00001549 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1550 {
Chris Caputo228da422009-07-18 05:44:03 +00001551 if (rsclient->group)
1552 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1553 {
1554 /* Nothing to do. */
1555 if (old_select && old_select == new_select)
1556 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1557 continue;
paulfee0f4c2004-09-13 05:12:46 +00001558
Chris Caputo228da422009-07-18 05:44:03 +00001559 if (old_select)
1560 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1561 if (new_select)
1562 {
1563 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1564 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001565 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1566 }
paulfee0f4c2004-09-13 05:12:46 +00001567
Chris Caputo228da422009-07-18 05:44:03 +00001568 bgp_process_announce_selected (rsclient, new_select, rn,
1569 afi, safi);
1570 }
paul200df112005-06-01 11:17:05 +00001571 }
1572 else
1573 {
hassob7395792005-08-26 12:58:38 +00001574 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001575 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001576 if (new_select)
1577 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001578 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1579 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001580 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001581 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001582 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001583 }
paulfee0f4c2004-09-13 05:12:46 +00001584
paulb40d9392005-08-22 22:34:41 +00001585 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1586 bgp_info_reap (rn, old_select);
1587
paul200df112005-06-01 11:17:05 +00001588 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1589 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001590}
1591
paul200df112005-06-01 11:17:05 +00001592static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001593bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001594{
paul0fb58d52005-11-14 14:31:49 +00001595 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001596 struct bgp *bgp = pq->bgp;
1597 struct bgp_node *rn = pq->rn;
1598 afi_t afi = pq->afi;
1599 safi_t safi = pq->safi;
1600 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001601 struct bgp_info *new_select;
1602 struct bgp_info *old_select;
1603 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001604 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001605 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001606
paulfee0f4c2004-09-13 05:12:46 +00001607 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001608 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001609 old_select = old_and_new.old;
1610 new_select = old_and_new.new;
1611
1612 /* Nothing to do. */
1613 if (old_select && old_select == new_select)
1614 {
1615 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001616 {
Josh Bailey8196f132011-07-20 20:47:07 -07001617 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1618 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001619 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001620
Josh Bailey8196f132011-07-20 20:47:07 -07001621 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001622 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1623 return WQ_SUCCESS;
1624 }
paulfee0f4c2004-09-13 05:12:46 +00001625 }
paul718e3742002-12-13 20:15:29 +00001626
hasso338b3422005-02-23 14:27:24 +00001627 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001628 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001629 if (new_select)
1630 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001631 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1632 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001633 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001634 }
1635
1636
paul718e3742002-12-13 20:15:29 +00001637 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001638 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001639 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001640 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001641 }
1642
1643 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001644 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1645 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001646 {
1647 if (new_select
1648 && new_select->type == ZEBRA_ROUTE_BGP
1649 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001650 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001651 else
1652 {
1653 /* Withdraw the route from the kernel. */
1654 if (old_select
1655 && old_select->type == ZEBRA_ROUTE_BGP
1656 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001657 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001658 }
1659 }
paulb40d9392005-08-22 22:34:41 +00001660
1661 /* Reap old select bgp_info, it it has been removed */
1662 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1663 bgp_info_reap (rn, old_select);
1664
paul200df112005-06-01 11:17:05 +00001665 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1666 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001667}
1668
paul200df112005-06-01 11:17:05 +00001669static void
paul0fb58d52005-11-14 14:31:49 +00001670bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001671{
paul0fb58d52005-11-14 14:31:49 +00001672 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001673 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001674
Chris Caputo228da422009-07-18 05:44:03 +00001675 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001676 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001677 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001678 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1679}
1680
1681static void
1682bgp_process_queue_init (void)
1683{
1684 bm->process_main_queue
1685 = work_queue_new (bm->master, "process_main_queue");
1686 bm->process_rsclient_queue
1687 = work_queue_new (bm->master, "process_rsclient_queue");
1688
1689 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1690 {
1691 zlog_err ("%s: Failed to allocate work queue", __func__);
1692 exit (1);
1693 }
1694
1695 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001696 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001697 bm->process_main_queue->spec.max_retries = 0;
1698 bm->process_main_queue->spec.hold = 50;
1699
Paul Jakma838bbde2010-01-08 14:05:32 +00001700 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
David Lamparterd43f8b32015-03-03 08:54:54 +01001701 bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del;
1702 bm->process_rsclient_queue->spec.max_retries = 0;
1703 bm->process_rsclient_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001704}
1705
1706void
paulfee0f4c2004-09-13 05:12:46 +00001707bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1708{
paul200df112005-06-01 11:17:05 +00001709 struct bgp_process_queue *pqnode;
1710
1711 /* already scheduled for processing? */
1712 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1713 return;
1714
1715 if ( (bm->process_main_queue == NULL) ||
1716 (bm->process_rsclient_queue == NULL) )
1717 bgp_process_queue_init ();
1718
1719 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1720 sizeof (struct bgp_process_queue));
1721 if (!pqnode)
1722 return;
Chris Caputo228da422009-07-18 05:44:03 +00001723
1724 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001725 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001726 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001727 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001728 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001729 pqnode->afi = afi;
1730 pqnode->safi = safi;
1731
Avneesh Sachdev67174042012-08-17 08:19:49 -07001732 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001733 {
paul200df112005-06-01 11:17:05 +00001734 case BGP_TABLE_MAIN:
1735 work_queue_add (bm->process_main_queue, pqnode);
1736 break;
1737 case BGP_TABLE_RSCLIENT:
1738 work_queue_add (bm->process_rsclient_queue, pqnode);
1739 break;
paulfee0f4c2004-09-13 05:12:46 +00001740 }
paul200df112005-06-01 11:17:05 +00001741
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001742 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001743 return;
paulfee0f4c2004-09-13 05:12:46 +00001744}
hasso0a486e52005-02-01 20:57:17 +00001745
paul94f2b392005-06-28 12:44:16 +00001746static int
hasso0a486e52005-02-01 20:57:17 +00001747bgp_maximum_prefix_restart_timer (struct thread *thread)
1748{
1749 struct peer *peer;
1750
1751 peer = THREAD_ARG (thread);
1752 peer->t_pmax_restart = NULL;
1753
1754 if (BGP_DEBUG (events, EVENTS))
1755 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1756 peer->host);
1757
1758 peer_clear (peer);
1759
1760 return 0;
1761}
1762
paulfee0f4c2004-09-13 05:12:46 +00001763int
paul5228ad22004-06-04 17:58:18 +00001764bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1765 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001766{
hassoe0701b72004-05-20 09:19:34 +00001767 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1768 return 0;
1769
1770 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001771 {
hassoe0701b72004-05-20 09:19:34 +00001772 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1773 && ! always)
1774 return 0;
paul718e3742002-12-13 20:15:29 +00001775
hassoe0701b72004-05-20 09:19:34 +00001776 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001777 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1778 "limit %ld", afi_safi_print (afi, safi), peer->host,
1779 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001780 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001781
hassoe0701b72004-05-20 09:19:34 +00001782 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1783 return 0;
paul718e3742002-12-13 20:15:29 +00001784
hassoe0701b72004-05-20 09:19:34 +00001785 {
paul5228ad22004-06-04 17:58:18 +00001786 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001787
1788 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001789 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001790
1791 ndata[0] = (afi >> 8);
1792 ndata[1] = afi;
1793 ndata[2] = safi;
1794 ndata[3] = (peer->pmax[afi][safi] >> 24);
1795 ndata[4] = (peer->pmax[afi][safi] >> 16);
1796 ndata[5] = (peer->pmax[afi][safi] >> 8);
1797 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001798
1799 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1800 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1801 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1802 }
hasso0a486e52005-02-01 20:57:17 +00001803
1804 /* restart timer start */
1805 if (peer->pmax_restart[afi][safi])
1806 {
1807 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1808
1809 if (BGP_DEBUG (events, EVENTS))
1810 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1811 peer->host, peer->v_pmax_restart);
1812
1813 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1814 peer->v_pmax_restart);
1815 }
1816
hassoe0701b72004-05-20 09:19:34 +00001817 return 1;
paul718e3742002-12-13 20:15:29 +00001818 }
hassoe0701b72004-05-20 09:19:34 +00001819 else
1820 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1821
1822 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1823 {
1824 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1825 && ! always)
1826 return 0;
1827
1828 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001829 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1830 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1831 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001832 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1833 }
1834 else
1835 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001836 return 0;
1837}
1838
paulb40d9392005-08-22 22:34:41 +00001839/* Unconditionally remove the route from the RIB, without taking
1840 * damping into consideration (eg, because the session went down)
1841 */
paul94f2b392005-06-28 12:44:16 +00001842static void
paul718e3742002-12-13 20:15:29 +00001843bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1844 afi_t afi, safi_t safi)
1845{
paul902212c2006-02-05 17:51:19 +00001846 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1847
1848 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1849 bgp_info_delete (rn, ri); /* keep historical info */
1850
paulb40d9392005-08-22 22:34:41 +00001851 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001852}
1853
paul94f2b392005-06-28 12:44:16 +00001854static void
paul718e3742002-12-13 20:15:29 +00001855bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001856 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001857{
paul718e3742002-12-13 20:15:29 +00001858 int status = BGP_DAMP_NONE;
1859
paulb40d9392005-08-22 22:34:41 +00001860 /* apply dampening, if result is suppressed, we'll be retaining
1861 * the bgp_info in the RIB for historical reference.
1862 */
1863 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001864 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001865 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1866 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001867 {
paul902212c2006-02-05 17:51:19 +00001868 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1869 return;
1870 }
1871
1872 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001873}
1874
paul94f2b392005-06-28 12:44:16 +00001875static void
paulfee0f4c2004-09-13 05:12:46 +00001876bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1877 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1878 int sub_type, struct prefix_rd *prd, u_char *tag)
1879{
1880 struct bgp_node *rn;
1881 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001882 struct attr new_attr;
1883 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001884 struct attr *attr_new;
1885 struct attr *attr_new2;
1886 struct bgp_info *ri;
1887 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001888 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001889 char buf[SU_ADDRSTRLEN];
1890
1891 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1892 if (peer == rsclient)
1893 return;
1894
1895 bgp = peer->bgp;
1896 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1897
1898 /* Check previously received route. */
1899 for (ri = rn->info; ri; ri = ri->next)
1900 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1901 break;
1902
1903 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001904 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001905 {
1906 reason = "as-path contains our own AS;";
1907 goto filtered;
1908 }
1909
1910 /* Route reflector originator ID check. */
1911 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001912 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001913 {
1914 reason = "originator is us;";
1915 goto filtered;
1916 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001917
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001918 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001919 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001920
1921 /* Apply export policy. */
1922 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1923 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1924 {
1925 reason = "export-policy;";
1926 goto filtered;
1927 }
1928
1929 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001930
paulfee0f4c2004-09-13 05:12:46 +00001931 /* Apply import policy. */
1932 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1933 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001934 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001935
1936 reason = "import-policy;";
1937 goto filtered;
1938 }
1939
1940 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001941 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001942
1943 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001944 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001945 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001946 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001947 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001948 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001949 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001950 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001951
1952 reason = "martian next-hop;";
1953 goto filtered;
1954 }
1955 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001956
paulfee0f4c2004-09-13 05:12:46 +00001957 /* If the update is implicit withdraw. */
1958 if (ri)
1959 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001960 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001961
1962 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001963 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1964 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001965 {
1966
Paul Jakma1a392d42006-09-07 00:24:49 +00001967 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001968
1969 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001970 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001971 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1972 peer->host,
1973 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1974 p->prefixlen, rsclient->host);
1975
Chris Caputo228da422009-07-18 05:44:03 +00001976 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001977 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001978
Chris Caputo228da422009-07-18 05:44:03 +00001979 return;
paulfee0f4c2004-09-13 05:12:46 +00001980 }
1981
Paul Jakma16d2e242007-04-10 19:32:10 +00001982 /* Withdraw/Announce before we fully processed the withdraw */
1983 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1984 bgp_info_restore (rn, ri);
1985
paulfee0f4c2004-09-13 05:12:46 +00001986 /* Received Logging. */
1987 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001988 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001989 peer->host,
1990 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1991 p->prefixlen, rsclient->host);
1992
1993 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001994 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001995
1996 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001997 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001998 ri->attr = attr_new;
1999
2000 /* Update MPLS tag. */
2001 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002002 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002003
Paul Jakma1a392d42006-09-07 00:24:49 +00002004 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002005
2006 /* Process change. */
2007 bgp_process (bgp, rn, afi, safi);
2008 bgp_unlock_node (rn);
2009
2010 return;
2011 }
2012
2013 /* Received Logging. */
2014 if (BGP_DEBUG (update, UPDATE_IN))
2015 {
ajsd2c1f162004-12-08 21:10:20 +00002016 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002017 peer->host,
2018 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2019 p->prefixlen, rsclient->host);
2020 }
2021
2022 /* Make new BGP info. */
2023 new = bgp_info_new ();
2024 new->type = type;
2025 new->sub_type = sub_type;
2026 new->peer = peer;
2027 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002028 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00002029
2030 /* Update MPLS tag. */
2031 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002032 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002033
Paul Jakma1a392d42006-09-07 00:24:49 +00002034 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002035
2036 /* Register new BGP information. */
2037 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002038
2039 /* route_node_get lock */
2040 bgp_unlock_node (rn);
2041
paulfee0f4c2004-09-13 05:12:46 +00002042 /* Process change. */
2043 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002044
paulfee0f4c2004-09-13 05:12:46 +00002045 return;
2046
2047 filtered:
2048
2049 /* This BGP update is filtered. Log the reason then update BGP entry. */
2050 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002051 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002052 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2053 peer->host,
2054 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2055 p->prefixlen, rsclient->host, reason);
2056
2057 if (ri)
paulb40d9392005-08-22 22:34:41 +00002058 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002059
2060 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002061
paulfee0f4c2004-09-13 05:12:46 +00002062 return;
2063}
2064
paul94f2b392005-06-28 12:44:16 +00002065static void
paulfee0f4c2004-09-13 05:12:46 +00002066bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2067 struct peer *peer, struct prefix *p, int type, int sub_type,
2068 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002069{
paulfee0f4c2004-09-13 05:12:46 +00002070 struct bgp_node *rn;
2071 struct bgp_info *ri;
2072 char buf[SU_ADDRSTRLEN];
2073
2074 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002075 return;
paulfee0f4c2004-09-13 05:12:46 +00002076
2077 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2078
2079 /* Lookup withdrawn route. */
2080 for (ri = rn->info; ri; ri = ri->next)
2081 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2082 break;
2083
2084 /* Withdraw specified route from routing table. */
2085 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002086 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002087 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002088 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002089 "%s Can't find the route %s/%d", peer->host,
2090 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2091 p->prefixlen);
2092
2093 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002094 bgp_unlock_node (rn);
2095}
paulfee0f4c2004-09-13 05:12:46 +00002096
paul94f2b392005-06-28 12:44:16 +00002097static int
paulfee0f4c2004-09-13 05:12:46 +00002098bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002099 afi_t afi, safi_t safi, int type, int sub_type,
2100 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2101{
2102 int ret;
2103 int aspath_loop_count = 0;
2104 struct bgp_node *rn;
2105 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002106 struct attr new_attr;
2107 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002108 struct attr *attr_new;
2109 struct bgp_info *ri;
2110 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002111 const char *reason;
paul718e3742002-12-13 20:15:29 +00002112 char buf[SU_ADDRSTRLEN];
2113
2114 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002115 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002116
paul718e3742002-12-13 20:15:29 +00002117 /* When peer's soft reconfiguration enabled. Record input packet in
2118 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002119 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2120 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002121 bgp_adj_in_set (rn, peer, attr);
2122
2123 /* Check previously received route. */
2124 for (ri = rn->info; ri; ri = ri->next)
2125 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2126 break;
2127
2128 /* AS path local-as loop check. */
2129 if (peer->change_local_as)
2130 {
2131 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2132 aspath_loop_count = 1;
2133
2134 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2135 {
2136 reason = "as-path contains our own AS;";
2137 goto filtered;
2138 }
2139 }
2140
2141 /* AS path loop check. */
2142 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2143 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2144 && aspath_loop_check(attr->aspath, bgp->confed_id)
2145 > peer->allowas_in[afi][safi]))
2146 {
2147 reason = "as-path contains our own AS;";
2148 goto filtered;
2149 }
2150
2151 /* Route reflector originator ID check. */
2152 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002153 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002154 {
2155 reason = "originator is us;";
2156 goto filtered;
2157 }
2158
2159 /* Route reflector cluster ID check. */
2160 if (bgp_cluster_filter (peer, attr))
2161 {
2162 reason = "reflected from the same cluster;";
2163 goto filtered;
2164 }
2165
2166 /* Apply incoming filter. */
2167 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2168 {
2169 reason = "filter;";
2170 goto filtered;
2171 }
2172
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002173 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002174 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002175
David Lamparterc460e572014-06-04 00:54:58 +02002176 /* Apply incoming route-map.
2177 * NB: new_attr may now contain newly allocated values from route-map "set"
2178 * commands, so we need bgp_attr_flush in the error paths, until we intern
2179 * the attr (which takes over the memory references) */
paul718e3742002-12-13 20:15:29 +00002180 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2181 {
2182 reason = "route-map;";
David Lamparterc460e572014-06-04 00:54:58 +02002183 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002184 goto filtered;
2185 }
2186
2187 /* IPv4 unicast next hop check. */
2188 if (afi == AFI_IP && safi == SAFI_UNICAST)
2189 {
2190 /* If the peer is EBGP and nexthop is not on connected route,
2191 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002192 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002193 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002194 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002195 {
2196 reason = "non-connected next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002197 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002198 goto filtered;
2199 }
2200
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002201 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002202 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002203 if (new_attr.nexthop.s_addr == 0
2204 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2205 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002206 {
2207 reason = "martian next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002208 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002209 goto filtered;
2210 }
2211 }
2212
2213 attr_new = bgp_attr_intern (&new_attr);
2214
2215 /* If the update is implicit withdraw. */
2216 if (ri)
2217 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002218 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002219
2220 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002221 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2222 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002223 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002224 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002225
2226 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002227 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002228 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2229 {
2230 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002231 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002232 peer->host,
2233 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2234 p->prefixlen);
2235
paul902212c2006-02-05 17:51:19 +00002236 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2237 {
2238 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2239 bgp_process (bgp, rn, afi, safi);
2240 }
paul718e3742002-12-13 20:15:29 +00002241 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002242 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002243 {
2244 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002245 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002246 "%s rcvd %s/%d...duplicate ignored",
2247 peer->host,
2248 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2249 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002250
2251 /* graceful restart STALE flag unset. */
2252 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2253 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002254 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002255 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002256 }
paul718e3742002-12-13 20:15:29 +00002257 }
2258
2259 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002260 bgp_attr_unintern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002261
paul718e3742002-12-13 20:15:29 +00002262 return 0;
2263 }
2264
Paul Jakma16d2e242007-04-10 19:32:10 +00002265 /* Withdraw/Announce before we fully processed the withdraw */
2266 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2267 {
2268 if (BGP_DEBUG (update, UPDATE_IN))
2269 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2270 peer->host,
2271 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2272 p->prefixlen);
2273 bgp_info_restore (rn, ri);
2274 }
2275
paul718e3742002-12-13 20:15:29 +00002276 /* Received Logging. */
2277 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002278 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002279 peer->host,
2280 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2281 p->prefixlen);
2282
hasso93406d82005-02-02 14:40:33 +00002283 /* graceful restart STALE flag unset. */
2284 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002285 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002286
paul718e3742002-12-13 20:15:29 +00002287 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002288 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002289
2290 /* implicit withdraw, decrement aggregate and pcount here.
2291 * only if update is accepted, they'll increment below.
2292 */
paul902212c2006-02-05 17:51:19 +00002293 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2294
paul718e3742002-12-13 20:15:29 +00002295 /* Update bgp route dampening information. */
2296 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002297 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002298 {
2299 /* This is implicit withdraw so we should update dampening
2300 information. */
2301 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2302 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002303 }
2304
paul718e3742002-12-13 20:15:29 +00002305 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002306 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002307 ri->attr = attr_new;
2308
2309 /* Update MPLS tag. */
2310 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002311 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002312
2313 /* Update bgp route dampening information. */
2314 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002315 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002316 {
2317 /* Now we do normal update dampening. */
2318 ret = bgp_damp_update (ri, rn, afi, safi);
2319 if (ret == BGP_DAMP_SUPPRESSED)
2320 {
2321 bgp_unlock_node (rn);
2322 return 0;
2323 }
2324 }
2325
2326 /* Nexthop reachability check. */
2327 if ((afi == AFI_IP || afi == AFI_IP6)
2328 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002329 && (peer->sort == BGP_PEER_IBGP
2330 || peer->sort == BGP_PEER_CONFED
2331 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002332 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002333 {
2334 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002335 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002336 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002337 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002338 }
2339 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002340 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002341
2342 /* Process change. */
2343 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2344
2345 bgp_process (bgp, rn, afi, safi);
2346 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002347
paul718e3742002-12-13 20:15:29 +00002348 return 0;
2349 }
2350
2351 /* Received Logging. */
2352 if (BGP_DEBUG (update, UPDATE_IN))
2353 {
ajsd2c1f162004-12-08 21:10:20 +00002354 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002355 peer->host,
2356 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2357 p->prefixlen);
2358 }
2359
paul718e3742002-12-13 20:15:29 +00002360 /* Make new BGP info. */
2361 new = bgp_info_new ();
2362 new->type = type;
2363 new->sub_type = sub_type;
2364 new->peer = peer;
2365 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002366 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002367
2368 /* Update MPLS tag. */
2369 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002370 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002371
2372 /* Nexthop reachability check. */
2373 if ((afi == AFI_IP || afi == AFI_IP6)
2374 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002375 && (peer->sort == BGP_PEER_IBGP
2376 || peer->sort == BGP_PEER_CONFED
2377 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002378 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002379 {
2380 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002381 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002382 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002383 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002384 }
2385 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002386 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002387
paul902212c2006-02-05 17:51:19 +00002388 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002389 bgp_aggregate_increment (bgp, p, new, afi, safi);
2390
2391 /* Register new BGP information. */
2392 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002393
2394 /* route_node_get lock */
2395 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002396
paul718e3742002-12-13 20:15:29 +00002397 /* If maximum prefix count is configured and current prefix
2398 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002399 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2400 return -1;
paul718e3742002-12-13 20:15:29 +00002401
2402 /* Process change. */
2403 bgp_process (bgp, rn, afi, safi);
2404
2405 return 0;
2406
2407 /* This BGP update is filtered. Log the reason then update BGP
2408 entry. */
2409 filtered:
2410 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002411 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002412 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2413 peer->host,
2414 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2415 p->prefixlen, reason);
2416
2417 if (ri)
paulb40d9392005-08-22 22:34:41 +00002418 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002419
2420 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002421
paul718e3742002-12-13 20:15:29 +00002422 return 0;
2423}
2424
2425int
paulfee0f4c2004-09-13 05:12:46 +00002426bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2427 afi_t afi, safi_t safi, int type, int sub_type,
2428 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2429{
2430 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002431 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002432 struct bgp *bgp;
2433 int ret;
2434
2435 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2436 soft_reconfig);
2437
2438 bgp = peer->bgp;
2439
2440 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002441 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002442 {
2443 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2444 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2445 sub_type, prd, tag);
2446 }
2447
2448 return ret;
2449}
2450
2451int
paul718e3742002-12-13 20:15:29 +00002452bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002453 afi_t afi, safi_t safi, int type, int sub_type,
2454 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002455{
2456 struct bgp *bgp;
2457 char buf[SU_ADDRSTRLEN];
2458 struct bgp_node *rn;
2459 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002460 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002461 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002462
2463 bgp = peer->bgp;
2464
David Lamparter4584c232015-04-13 09:50:00 +02002465 /* Lookup node. */
2466 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2467
2468 /* Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2469 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2470 * the iteration over all RS clients.
2471 * Since we need to remove the entry from adj_in anyway, do that first and
2472 * if there was no entry, we don't need to do anything more. */
2473 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2474 && peer != bgp->peer_self)
2475 if (!bgp_adj_in_unset (rn, peer))
2476 {
2477 if (BGP_DEBUG (update, UPDATE_IN))
2478 zlog (peer->log, LOG_DEBUG, "%s withdrawing route %s/%d "
2479 "not in adj-in", peer->host,
2480 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2481 p->prefixlen);
2482 bgp_unlock_node (rn);
2483 return 0;
2484 }
2485
paulfee0f4c2004-09-13 05:12:46 +00002486 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002487 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002488 {
2489 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2490 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2491 }
2492
paul718e3742002-12-13 20:15:29 +00002493 /* Logging. */
2494 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002495 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002496 peer->host,
2497 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2498 p->prefixlen);
2499
paul718e3742002-12-13 20:15:29 +00002500 /* Lookup withdrawn route. */
2501 for (ri = rn->info; ri; ri = ri->next)
2502 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2503 break;
2504
2505 /* Withdraw specified route from routing table. */
2506 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002507 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002508 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002509 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002510 "%s Can't find the route %s/%d", peer->host,
2511 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2512 p->prefixlen);
2513
2514 /* Unlock bgp_node_get() lock. */
2515 bgp_unlock_node (rn);
2516
2517 return 0;
2518}
David Lamparter6b0655a2014-06-04 06:53:35 +02002519
paul718e3742002-12-13 20:15:29 +00002520void
2521bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2522{
2523 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002524 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002525 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002526 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002527 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002528 struct bgp_node *rn;
2529 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002530 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002531
Paul Jakmab2497022007-06-14 11:17:58 +00002532 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002533 return;
2534
paul718e3742002-12-13 20:15:29 +00002535 bgp = peer->bgp;
2536 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002537
paul718e3742002-12-13 20:15:29 +00002538 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2539 aspath = attr.aspath;
2540 attr.local_pref = bgp->default_local_pref;
2541 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2542
2543 if (afi == AFI_IP)
2544 str2prefix ("0.0.0.0/0", &p);
2545#ifdef HAVE_IPV6
2546 else if (afi == AFI_IP6)
2547 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002548 struct attr_extra *ae = attr.extra;
2549
paul718e3742002-12-13 20:15:29 +00002550 str2prefix ("::/0", &p);
2551
2552 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002553 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002554 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002555 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002556
2557 /* If the peer is on shared nextwork and we have link-local
2558 nexthop set it. */
2559 if (peer->shared_network
2560 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2561 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002562 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002563 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002564 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002565 }
2566 }
2567#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002568
2569 if (peer->default_rmap[afi][safi].name)
2570 {
paulfee0f4c2004-09-13 05:12:46 +00002571 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002572 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2573 {
2574 for (ri = rn->info; ri; ri = ri->next)
2575 {
2576 struct attr dummy_attr;
2577 struct attr_extra dummy_extra;
2578 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002579
Christian Frankedcab1bb2012-12-07 16:45:52 +00002580 /* Provide dummy so the route-map can't modify the attributes */
2581 dummy_attr.extra = &dummy_extra;
2582 bgp_attr_dup(&dummy_attr, ri->attr);
2583 info.peer = ri->peer;
2584 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002585
Christian Frankedcab1bb2012-12-07 16:45:52 +00002586 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2587 RMAP_BGP, &info);
2588
2589 /* The route map might have set attributes. If we don't flush them
2590 * here, they will be leaked. */
2591 bgp_attr_flush(&dummy_attr);
2592 if (ret != RMAP_DENYMATCH)
2593 break;
2594 }
2595 if (ret != RMAP_DENYMATCH)
2596 break;
2597 }
paulfee0f4c2004-09-13 05:12:46 +00002598 bgp->peer_self->rmap_type = 0;
2599
paul718e3742002-12-13 20:15:29 +00002600 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002601 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002602 }
2603
2604 if (withdraw)
2605 {
2606 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2607 bgp_default_withdraw_send (peer, afi, safi);
2608 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2609 }
2610 else
2611 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002612 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2613 {
2614 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2615 bgp_default_update_send (peer, &attr, afi, safi, from);
2616 }
paul718e3742002-12-13 20:15:29 +00002617 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002618
2619 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002620 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002621}
David Lamparter6b0655a2014-06-04 06:53:35 +02002622
paul718e3742002-12-13 20:15:29 +00002623static void
2624bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002625 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002626{
2627 struct bgp_node *rn;
2628 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002629 struct attr attr;
2630 struct attr_extra extra;
2631
paul718e3742002-12-13 20:15:29 +00002632 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002633 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002634
2635 if (safi != SAFI_MPLS_VPN
2636 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2637 bgp_default_originate (peer, afi, safi, 0);
2638
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002639 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2640 attr.extra = &extra;
2641
paul718e3742002-12-13 20:15:29 +00002642 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2643 for (ri = rn->info; ri; ri = ri->next)
2644 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2645 {
paulfee0f4c2004-09-13 05:12:46 +00002646 if ( (rsclient) ?
2647 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2648 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002649 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2650 else
2651 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2652 }
2653}
2654
2655void
2656bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2657{
2658 struct bgp_node *rn;
2659 struct bgp_table *table;
2660
2661 if (peer->status != Established)
2662 return;
2663
2664 if (! peer->afc_nego[afi][safi])
2665 return;
2666
2667 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2668 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2669 return;
2670
2671 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002672 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002673 else
2674 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2675 rn = bgp_route_next(rn))
2676 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002677 bgp_announce_table (peer, afi, safi, table, 0);
2678
2679 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2680 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002681}
2682
2683void
2684bgp_announce_route_all (struct peer *peer)
2685{
2686 afi_t afi;
2687 safi_t safi;
2688
2689 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2690 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2691 bgp_announce_route (peer, afi, safi);
2692}
David Lamparter6b0655a2014-06-04 06:53:35 +02002693
paul718e3742002-12-13 20:15:29 +00002694static void
paulfee0f4c2004-09-13 05:12:46 +00002695bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002696 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002697{
2698 struct bgp_node *rn;
2699 struct bgp_adj_in *ain;
2700
2701 if (! table)
2702 table = rsclient->bgp->rib[afi][safi];
2703
2704 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2705 for (ain = rn->adj_in; ain; ain = ain->next)
2706 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002707 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002708 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002709
paulfee0f4c2004-09-13 05:12:46 +00002710 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002711 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002712 }
2713}
2714
2715void
2716bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2717{
2718 struct bgp_table *table;
2719 struct bgp_node *rn;
2720
2721 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002722 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002723
2724 else
2725 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2726 rn = bgp_route_next (rn))
2727 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002728 {
2729 struct prefix_rd prd;
2730 prd.family = AF_UNSPEC;
2731 prd.prefixlen = 64;
2732 memcpy(&prd.val, rn->p.u.val, 8);
2733
2734 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2735 }
paulfee0f4c2004-09-13 05:12:46 +00002736}
David Lamparter6b0655a2014-06-04 06:53:35 +02002737
paulfee0f4c2004-09-13 05:12:46 +00002738static void
paul718e3742002-12-13 20:15:29 +00002739bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002740 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002741{
2742 int ret;
2743 struct bgp_node *rn;
2744 struct bgp_adj_in *ain;
2745
2746 if (! table)
2747 table = peer->bgp->rib[afi][safi];
2748
2749 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2750 for (ain = rn->adj_in; ain; ain = ain->next)
2751 {
2752 if (ain->peer == peer)
2753 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002754 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002755 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002756
paul718e3742002-12-13 20:15:29 +00002757 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2758 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002759 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002760
paul718e3742002-12-13 20:15:29 +00002761 if (ret < 0)
2762 {
2763 bgp_unlock_node (rn);
2764 return;
2765 }
2766 continue;
2767 }
2768 }
2769}
2770
2771void
2772bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2773{
2774 struct bgp_node *rn;
2775 struct bgp_table *table;
2776
2777 if (peer->status != Established)
2778 return;
2779
2780 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002781 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002782 else
2783 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2784 rn = bgp_route_next (rn))
2785 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002786 {
2787 struct prefix_rd prd;
2788 prd.family = AF_UNSPEC;
2789 prd.prefixlen = 64;
2790 memcpy(&prd.val, rn->p.u.val, 8);
2791
2792 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2793 }
paul718e3742002-12-13 20:15:29 +00002794}
David Lamparter6b0655a2014-06-04 06:53:35 +02002795
Chris Caputo228da422009-07-18 05:44:03 +00002796
2797struct bgp_clear_node_queue
2798{
2799 struct bgp_node *rn;
2800 enum bgp_clear_route_type purpose;
2801};
2802
paul200df112005-06-01 11:17:05 +00002803static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002804bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002805{
Chris Caputo228da422009-07-18 05:44:03 +00002806 struct bgp_clear_node_queue *cnq = data;
2807 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002808 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002809 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002810 afi_t afi = bgp_node_table (rn)->afi;
2811 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002812
Paul Jakma64e580a2006-02-21 01:09:01 +00002813 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002814
Paul Jakma64e580a2006-02-21 01:09:01 +00002815 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002816 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002817 {
2818 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002819 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2820 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002821 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002822 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2823 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002824 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002825 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002826 break;
2827 }
paul200df112005-06-01 11:17:05 +00002828 return WQ_SUCCESS;
2829}
2830
2831static void
paul0fb58d52005-11-14 14:31:49 +00002832bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002833{
Chris Caputo228da422009-07-18 05:44:03 +00002834 struct bgp_clear_node_queue *cnq = data;
2835 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002836 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002837
2838 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002839 bgp_table_unlock (table);
2840 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002841}
2842
2843static void
paul94f2b392005-06-28 12:44:16 +00002844bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002845{
Paul Jakma64e580a2006-02-21 01:09:01 +00002846 struct peer *peer = wq->spec.data;
2847
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002848 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002849 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002850
2851 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002852}
2853
2854static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002855bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002856{
Paul Jakmaa2943652009-07-21 14:02:04 +01002857 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002858
Paul Jakmaa2943652009-07-21 14:02:04 +01002859 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002860#undef CLEAR_QUEUE_NAME_LEN
2861
2862 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002863 {
2864 zlog_err ("%s: Failed to allocate work queue", __func__);
2865 exit (1);
2866 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002867 peer->clear_node_queue->spec.hold = 10;
2868 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2869 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2870 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2871 peer->clear_node_queue->spec.max_retries = 0;
2872
2873 /* we only 'lock' this peer reference when the queue is actually active */
2874 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002875}
2876
paul718e3742002-12-13 20:15:29 +00002877static void
2878bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002879 struct bgp_table *table, struct peer *rsclient,
2880 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002881{
2882 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002883
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002884
paul718e3742002-12-13 20:15:29 +00002885 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002886 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002887
hasso6cf159b2005-03-21 10:28:14 +00002888 /* If still no table => afi/safi isn't configured at all or smth. */
2889 if (! table)
2890 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002891
2892 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2893 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002894 struct bgp_info *ri;
2895 struct bgp_adj_in *ain;
2896 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002897
2898 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2899 * queued for every clearing peer, regardless of whether it is
2900 * relevant to the peer at hand.
2901 *
2902 * Overview: There are 3 different indices which need to be
2903 * scrubbed, potentially, when a peer is removed:
2904 *
2905 * 1 peer's routes visible via the RIB (ie accepted routes)
2906 * 2 peer's routes visible by the (optional) peer's adj-in index
2907 * 3 other routes visible by the peer's adj-out index
2908 *
2909 * 3 there is no hurry in scrubbing, once the struct peer is
2910 * removed from bgp->peer, we could just GC such deleted peer's
2911 * adj-outs at our leisure.
2912 *
2913 * 1 and 2 must be 'scrubbed' in some way, at least made
2914 * invisible via RIB index before peer session is allowed to be
2915 * brought back up. So one needs to know when such a 'search' is
2916 * complete.
2917 *
2918 * Ideally:
2919 *
2920 * - there'd be a single global queue or a single RIB walker
2921 * - rather than tracking which route_nodes still need to be
2922 * examined on a peer basis, we'd track which peers still
2923 * aren't cleared
2924 *
2925 * Given that our per-peer prefix-counts now should be reliable,
2926 * this may actually be achievable. It doesn't seem to be a huge
2927 * problem at this time,
2928 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002929 for (ain = rn->adj_in; ain; ain = ain->next)
2930 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2931 {
2932 bgp_adj_in_remove (rn, ain);
2933 bgp_unlock_node (rn);
2934 break;
2935 }
2936 for (aout = rn->adj_out; aout; aout = aout->next)
2937 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2938 {
2939 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2940 bgp_unlock_node (rn);
2941 break;
2942 }
2943
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002944 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002945 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002946 {
Chris Caputo228da422009-07-18 05:44:03 +00002947 struct bgp_clear_node_queue *cnq;
2948
2949 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002950 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002951 bgp_lock_node (rn);
2952 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2953 sizeof (struct bgp_clear_node_queue));
2954 cnq->rn = rn;
2955 cnq->purpose = purpose;
2956 work_queue_add (peer->clear_node_queue, cnq);
2957 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002958 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002959 }
2960 return;
2961}
2962
2963void
Chris Caputo228da422009-07-18 05:44:03 +00002964bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2965 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002966{
2967 struct bgp_node *rn;
2968 struct bgp_table *table;
2969 struct peer *rsclient;
2970 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002971
Paul Jakma64e580a2006-02-21 01:09:01 +00002972 if (peer->clear_node_queue == NULL)
2973 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002974
Paul Jakmaca058a32006-09-14 02:58:49 +00002975 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2976 * Idle until it receives a Clearing_Completed event. This protects
2977 * against peers which flap faster than we can we clear, which could
2978 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002979 *
2980 * a) race with routes from the new session being installed before
2981 * clear_route_node visits the node (to delete the route of that
2982 * peer)
2983 * b) resource exhaustion, clear_route_node likely leads to an entry
2984 * on the process_main queue. Fast-flapping could cause that queue
2985 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002986 */
Donald Sharp7ef42212015-03-30 06:32:52 -07002987
2988 /* lock peer in assumption that clear-node-queue will get nodes; if so,
2989 * the unlock will happen upon work-queue completion; other wise, the
2990 * unlock happens at the end of this function.
2991 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002992 if (!peer->clear_node_queue->thread)
Donald Sharp7ef42212015-03-30 06:32:52 -07002993 peer_lock (peer);
paulfee0f4c2004-09-13 05:12:46 +00002994
Chris Caputo228da422009-07-18 05:44:03 +00002995 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002996 {
Chris Caputo228da422009-07-18 05:44:03 +00002997 case BGP_CLEAR_ROUTE_NORMAL:
2998 if (safi != SAFI_MPLS_VPN)
2999 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
3000 else
3001 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3002 rn = bgp_route_next (rn))
3003 if ((table = rn->info) != NULL)
3004 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3005
3006 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
3007 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
3008 PEER_FLAG_RSERVER_CLIENT))
3009 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3010 break;
3011
3012 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
3013 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3014 break;
3015
3016 default:
3017 assert (0);
3018 break;
paulfee0f4c2004-09-13 05:12:46 +00003019 }
Donald Sharp7ef42212015-03-30 06:32:52 -07003020
3021 /* unlock if no nodes got added to the clear-node-queue. */
Paul Jakma65ca75e2006-05-04 08:08:15 +00003022 if (!peer->clear_node_queue->thread)
Donald Sharp7ef42212015-03-30 06:32:52 -07003023 peer_unlock (peer);
3024
paul718e3742002-12-13 20:15:29 +00003025}
3026
3027void
3028bgp_clear_route_all (struct peer *peer)
3029{
3030 afi_t afi;
3031 safi_t safi;
3032
3033 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3034 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003035 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003036}
3037
3038void
3039bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3040{
3041 struct bgp_table *table;
3042 struct bgp_node *rn;
3043 struct bgp_adj_in *ain;
3044
3045 table = peer->bgp->rib[afi][safi];
3046
3047 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3048 for (ain = rn->adj_in; ain ; ain = ain->next)
3049 if (ain->peer == peer)
3050 {
3051 bgp_adj_in_remove (rn, ain);
3052 bgp_unlock_node (rn);
3053 break;
3054 }
3055}
hasso93406d82005-02-02 14:40:33 +00003056
3057void
3058bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3059{
3060 struct bgp_node *rn;
3061 struct bgp_info *ri;
3062 struct bgp_table *table;
3063
3064 table = peer->bgp->rib[afi][safi];
3065
3066 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3067 {
3068 for (ri = rn->info; ri; ri = ri->next)
3069 if (ri->peer == peer)
3070 {
3071 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3072 bgp_rib_remove (rn, ri, peer, afi, safi);
3073 break;
3074 }
3075 }
3076}
David Lamparter6b0655a2014-06-04 06:53:35 +02003077
paul718e3742002-12-13 20:15:29 +00003078/* Delete all kernel routes. */
3079void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003080bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003081{
3082 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003083 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003084 struct bgp_node *rn;
3085 struct bgp_table *table;
3086 struct bgp_info *ri;
3087
paul1eb8ef22005-04-07 07:30:20 +00003088 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003089 {
3090 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3091
3092 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3093 for (ri = rn->info; ri; ri = ri->next)
3094 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3095 && ri->type == ZEBRA_ROUTE_BGP
3096 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003097 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003098
3099 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3100
3101 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3102 for (ri = rn->info; ri; ri = ri->next)
3103 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3104 && ri->type == ZEBRA_ROUTE_BGP
3105 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003106 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003107 }
3108}
3109
3110void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003111bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003112{
3113 vty_reset ();
3114 bgp_zclient_reset ();
3115 access_list_reset ();
3116 prefix_list_reset ();
3117}
David Lamparter6b0655a2014-06-04 06:53:35 +02003118
paul718e3742002-12-13 20:15:29 +00003119/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3120 value. */
3121int
3122bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3123{
3124 u_char *pnt;
3125 u_char *lim;
3126 struct prefix p;
3127 int psize;
3128 int ret;
3129
3130 /* Check peer status. */
3131 if (peer->status != Established)
3132 return 0;
3133
3134 pnt = packet->nlri;
3135 lim = pnt + packet->length;
3136
3137 for (; pnt < lim; pnt += psize)
3138 {
3139 /* Clear prefix structure. */
3140 memset (&p, 0, sizeof (struct prefix));
3141
3142 /* Fetch prefix length. */
3143 p.prefixlen = *pnt++;
3144 p.family = afi2family (packet->afi);
3145
3146 /* Already checked in nlri_sanity_check(). We do double check
3147 here. */
3148 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3149 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3150 return -1;
3151
3152 /* Packet size overflow check. */
3153 psize = PSIZE (p.prefixlen);
3154
3155 /* When packet overflow occur return immediately. */
3156 if (pnt + psize > lim)
3157 return -1;
3158
3159 /* Fetch prefix from NLRI packet. */
3160 memcpy (&p.u.prefix, pnt, psize);
3161
3162 /* Check address. */
3163 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3164 {
3165 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3166 {
paulf5ba3872004-07-09 12:11:31 +00003167 /*
3168 * From draft-ietf-idr-bgp4-22, Section 6.3:
3169 * If a BGP router receives an UPDATE message with a
3170 * semantically incorrect NLRI field, in which a prefix is
3171 * semantically incorrect (eg. an unexpected multicast IP
3172 * address), it should ignore the prefix.
3173 */
paul718e3742002-12-13 20:15:29 +00003174 zlog (peer->log, LOG_ERR,
3175 "IPv4 unicast NLRI is multicast address %s",
3176 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003177
paul718e3742002-12-13 20:15:29 +00003178 return -1;
3179 }
3180 }
3181
3182#ifdef HAVE_IPV6
3183 /* Check address. */
3184 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3185 {
3186 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3187 {
3188 char buf[BUFSIZ];
3189
3190 zlog (peer->log, LOG_WARNING,
3191 "IPv6 link-local NLRI received %s ignore this NLRI",
3192 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3193
3194 continue;
3195 }
3196 }
3197#endif /* HAVE_IPV6 */
3198
3199 /* Normal process. */
3200 if (attr)
3201 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3202 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3203 else
3204 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3205 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3206
3207 /* Address family configuration mismatch or maximum-prefix count
3208 overflow. */
3209 if (ret < 0)
3210 return -1;
3211 }
3212
3213 /* Packet length consistency check. */
3214 if (pnt != lim)
3215 return -1;
3216
3217 return 0;
3218}
3219
3220/* NLRI encode syntax check routine. */
3221int
3222bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3223 bgp_size_t length)
3224{
3225 u_char *end;
3226 u_char prefixlen;
3227 int psize;
3228
3229 end = pnt + length;
3230
3231 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3232 syntactic validity. If the field is syntactically incorrect,
3233 then the Error Subcode is set to Invalid Network Field. */
3234
3235 while (pnt < end)
3236 {
3237 prefixlen = *pnt++;
3238
3239 /* Prefix length check. */
3240 if ((afi == AFI_IP && prefixlen > 32)
3241 || (afi == AFI_IP6 && prefixlen > 128))
3242 {
3243 plog_err (peer->log,
3244 "%s [Error] Update packet error (wrong prefix length %d)",
3245 peer->host, prefixlen);
3246 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3247 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3248 return -1;
3249 }
3250
3251 /* Packet size overflow check. */
3252 psize = PSIZE (prefixlen);
3253
3254 if (pnt + psize > end)
3255 {
3256 plog_err (peer->log,
3257 "%s [Error] Update packet error"
3258 " (prefix data overflow prefix size is %d)",
3259 peer->host, psize);
3260 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3261 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3262 return -1;
3263 }
3264
3265 pnt += psize;
3266 }
3267
3268 /* Packet length consistency check. */
3269 if (pnt != end)
3270 {
3271 plog_err (peer->log,
3272 "%s [Error] Update packet error"
3273 " (prefix length mismatch with total length)",
3274 peer->host);
3275 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3276 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3277 return -1;
3278 }
3279 return 0;
3280}
David Lamparter6b0655a2014-06-04 06:53:35 +02003281
paul94f2b392005-06-28 12:44:16 +00003282static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003283bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003284{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003285 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003286}
3287
paul94f2b392005-06-28 12:44:16 +00003288static void
paul718e3742002-12-13 20:15:29 +00003289bgp_static_free (struct bgp_static *bgp_static)
3290{
3291 if (bgp_static->rmap.name)
3292 free (bgp_static->rmap.name);
3293 XFREE (MTYPE_BGP_STATIC, bgp_static);
3294}
3295
paul94f2b392005-06-28 12:44:16 +00003296static void
paulfee0f4c2004-09-13 05:12:46 +00003297bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3298 struct prefix *p, afi_t afi, safi_t safi)
3299{
3300 struct bgp_node *rn;
3301 struct bgp_info *ri;
3302
3303 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3304
3305 /* Check selected route and self inserted route. */
3306 for (ri = rn->info; ri; ri = ri->next)
3307 if (ri->peer == bgp->peer_self
3308 && ri->type == ZEBRA_ROUTE_BGP
3309 && ri->sub_type == BGP_ROUTE_STATIC)
3310 break;
3311
3312 /* Withdraw static BGP route from routing table. */
3313 if (ri)
3314 {
paulfee0f4c2004-09-13 05:12:46 +00003315 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003316 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003317 }
3318
3319 /* Unlock bgp_node_lookup. */
3320 bgp_unlock_node (rn);
3321}
3322
paul94f2b392005-06-28 12:44:16 +00003323static void
paulfee0f4c2004-09-13 05:12:46 +00003324bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003325 struct bgp_static *bgp_static,
3326 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003327{
3328 struct bgp_node *rn;
3329 struct bgp_info *ri;
3330 struct bgp_info *new;
3331 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003332 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003333 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003334 struct attr new_attr;
3335 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003336 struct bgp *bgp;
3337 int ret;
3338 char buf[SU_ADDRSTRLEN];
3339
3340 bgp = rsclient->bgp;
3341
Paul Jakma06e110f2006-05-12 23:29:22 +00003342 assert (bgp_static);
3343 if (!bgp_static)
3344 return;
3345
paulfee0f4c2004-09-13 05:12:46 +00003346 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3347
3348 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003349
3350 attr.nexthop = bgp_static->igpnexthop;
3351 attr.med = bgp_static->igpmetric;
3352 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003353
Paul Jakma41367172007-08-06 15:24:51 +00003354 if (bgp_static->atomic)
3355 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3356
paulfee0f4c2004-09-13 05:12:46 +00003357 /* Apply network route-map for export to this rsclient. */
3358 if (bgp_static->rmap.name)
3359 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003360 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003361 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003362 info.attr = &attr_tmp;
3363
paulfee0f4c2004-09-13 05:12:46 +00003364 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3365 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3366
3367 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3368
3369 rsclient->rmap_type = 0;
3370
3371 if (ret == RMAP_DENYMATCH)
3372 {
3373 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003374 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003375
3376 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003377 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003378 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003379 bgp_attr_extra_free (&attr);
3380
paulfee0f4c2004-09-13 05:12:46 +00003381 return;
3382 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003383 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003384 }
3385 else
3386 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003387
3388 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003389 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003390
paulfee0f4c2004-09-13 05:12:46 +00003391 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3392
Paul Jakmafb982c22007-05-04 20:15:47 +00003393 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3394 == RMAP_DENY)
3395 {
paulfee0f4c2004-09-13 05:12:46 +00003396 /* This BGP update is filtered. Log the reason then update BGP entry. */
3397 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003398 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003399 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3400 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3401 p->prefixlen, rsclient->host);
3402
3403 bgp->peer_self->rmap_type = 0;
3404
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003405 bgp_attr_unintern (&attr_new);
3406 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003407 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003408
3409 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3410
3411 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003412 }
paulfee0f4c2004-09-13 05:12:46 +00003413
3414 bgp->peer_self->rmap_type = 0;
3415
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003416 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003417 attr_new = bgp_attr_intern (&new_attr);
3418
3419 for (ri = rn->info; ri; ri = ri->next)
3420 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3421 && ri->sub_type == BGP_ROUTE_STATIC)
3422 break;
3423
3424 if (ri)
3425 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003426 if (attrhash_cmp (ri->attr, attr_new) &&
3427 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003428 {
3429 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003430 bgp_attr_unintern (&attr_new);
3431 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003432 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003433 return;
3434 }
3435 else
3436 {
3437 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003438 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003439
3440 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003441 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3442 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003443 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003444 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003445 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003446
3447 /* Process change. */
3448 bgp_process (bgp, rn, afi, safi);
3449 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003450 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003451 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003452 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003453 }
paulfee0f4c2004-09-13 05:12:46 +00003454 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003455
paulfee0f4c2004-09-13 05:12:46 +00003456 /* Make new BGP info. */
3457 new = bgp_info_new ();
3458 new->type = ZEBRA_ROUTE_BGP;
3459 new->sub_type = BGP_ROUTE_STATIC;
3460 new->peer = bgp->peer_self;
3461 SET_FLAG (new->flags, BGP_INFO_VALID);
3462 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003463 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003464
3465 /* Register new BGP information. */
3466 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003467
3468 /* route_node_get lock */
3469 bgp_unlock_node (rn);
3470
paulfee0f4c2004-09-13 05:12:46 +00003471 /* Process change. */
3472 bgp_process (bgp, rn, afi, safi);
3473
3474 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003475 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003476 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003477}
3478
paul94f2b392005-06-28 12:44:16 +00003479static void
paulfee0f4c2004-09-13 05:12:46 +00003480bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003481 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3482{
3483 struct bgp_node *rn;
3484 struct bgp_info *ri;
3485 struct bgp_info *new;
3486 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003487 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003488 struct attr *attr_new;
3489 int ret;
3490
Paul Jakmadd8103a2006-05-12 23:27:30 +00003491 assert (bgp_static);
3492 if (!bgp_static)
3493 return;
3494
paulfee0f4c2004-09-13 05:12:46 +00003495 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003496
3497 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003498
3499 attr.nexthop = bgp_static->igpnexthop;
3500 attr.med = bgp_static->igpmetric;
3501 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003502
Paul Jakma41367172007-08-06 15:24:51 +00003503 if (bgp_static->atomic)
3504 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3505
paul718e3742002-12-13 20:15:29 +00003506 /* Apply route-map. */
3507 if (bgp_static->rmap.name)
3508 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003509 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003510 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003511 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003512
paulfee0f4c2004-09-13 05:12:46 +00003513 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3514
paul718e3742002-12-13 20:15:29 +00003515 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003516
paulfee0f4c2004-09-13 05:12:46 +00003517 bgp->peer_self->rmap_type = 0;
3518
paul718e3742002-12-13 20:15:29 +00003519 if (ret == RMAP_DENYMATCH)
3520 {
3521 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003522 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003523
3524 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003525 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003526 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003527 bgp_static_withdraw (bgp, p, afi, safi);
3528 return;
3529 }
paul286e1e72003-08-08 00:24:31 +00003530 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003531 }
paul286e1e72003-08-08 00:24:31 +00003532 else
3533 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003534
3535 for (ri = rn->info; ri; ri = ri->next)
3536 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3537 && ri->sub_type == BGP_ROUTE_STATIC)
3538 break;
3539
3540 if (ri)
3541 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003542 if (attrhash_cmp (ri->attr, attr_new) &&
3543 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003544 {
3545 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003546 bgp_attr_unintern (&attr_new);
3547 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003548 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003549 return;
3550 }
3551 else
3552 {
3553 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003554 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003555
3556 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003557 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3558 bgp_info_restore(rn, ri);
3559 else
3560 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003561 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003562 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003563 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003564
3565 /* Process change. */
3566 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3567 bgp_process (bgp, rn, afi, safi);
3568 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003569 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003570 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003571 return;
3572 }
3573 }
3574
3575 /* Make new BGP info. */
3576 new = bgp_info_new ();
3577 new->type = ZEBRA_ROUTE_BGP;
3578 new->sub_type = BGP_ROUTE_STATIC;
3579 new->peer = bgp->peer_self;
3580 SET_FLAG (new->flags, BGP_INFO_VALID);
3581 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003582 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003583
3584 /* Aggregate address increment. */
3585 bgp_aggregate_increment (bgp, p, new, afi, safi);
3586
3587 /* Register new BGP information. */
3588 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003589
3590 /* route_node_get lock */
3591 bgp_unlock_node (rn);
3592
paul718e3742002-12-13 20:15:29 +00003593 /* Process change. */
3594 bgp_process (bgp, rn, afi, safi);
3595
3596 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003597 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003598 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003599}
3600
3601void
paulfee0f4c2004-09-13 05:12:46 +00003602bgp_static_update (struct bgp *bgp, struct prefix *p,
3603 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3604{
3605 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003606 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003607
3608 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3609
paul1eb8ef22005-04-07 07:30:20 +00003610 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003611 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003612 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3613 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003614 }
3615}
3616
paul94f2b392005-06-28 12:44:16 +00003617static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003618bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3619 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003620{
3621 struct bgp_node *rn;
3622 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003623
paulfee0f4c2004-09-13 05:12:46 +00003624 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003625
3626 /* Make new BGP info. */
3627 new = bgp_info_new ();
3628 new->type = ZEBRA_ROUTE_BGP;
3629 new->sub_type = BGP_ROUTE_STATIC;
3630 new->peer = bgp->peer_self;
3631 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3632 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003633 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003634 new->extra = bgp_info_extra_new();
3635 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003636
3637 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003638 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003639
3640 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003641 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003642
paul200df112005-06-01 11:17:05 +00003643 /* route_node_get lock */
3644 bgp_unlock_node (rn);
3645
paul718e3742002-12-13 20:15:29 +00003646 /* Process change. */
3647 bgp_process (bgp, rn, afi, safi);
3648}
3649
3650void
3651bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3652 safi_t safi)
3653{
3654 struct bgp_node *rn;
3655 struct bgp_info *ri;
3656
paulfee0f4c2004-09-13 05:12:46 +00003657 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003658
3659 /* Check selected route and self inserted route. */
3660 for (ri = rn->info; ri; ri = ri->next)
3661 if (ri->peer == bgp->peer_self
3662 && ri->type == ZEBRA_ROUTE_BGP
3663 && ri->sub_type == BGP_ROUTE_STATIC)
3664 break;
3665
3666 /* Withdraw static BGP route from routing table. */
3667 if (ri)
3668 {
3669 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003670 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003671 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003672 }
3673
3674 /* Unlock bgp_node_lookup. */
3675 bgp_unlock_node (rn);
3676}
3677
3678void
paulfee0f4c2004-09-13 05:12:46 +00003679bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3680{
3681 struct bgp_static *bgp_static;
3682 struct bgp *bgp;
3683 struct bgp_node *rn;
3684 struct prefix *p;
3685
3686 bgp = rsclient->bgp;
3687
3688 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3689 if ((bgp_static = rn->info) != NULL)
3690 {
3691 p = &rn->p;
3692
3693 bgp_static_update_rsclient (rsclient, p, bgp_static,
3694 afi, safi);
3695 }
3696}
3697
paul94f2b392005-06-28 12:44:16 +00003698static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003699bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3700 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003701{
3702 struct bgp_node *rn;
3703 struct bgp_info *ri;
3704
paulfee0f4c2004-09-13 05:12:46 +00003705 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003706
3707 /* Check selected route and self inserted route. */
3708 for (ri = rn->info; ri; ri = ri->next)
3709 if (ri->peer == bgp->peer_self
3710 && ri->type == ZEBRA_ROUTE_BGP
3711 && ri->sub_type == BGP_ROUTE_STATIC)
3712 break;
3713
3714 /* Withdraw static BGP route from routing table. */
3715 if (ri)
3716 {
3717 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003718 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003719 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003720 }
3721
3722 /* Unlock bgp_node_lookup. */
3723 bgp_unlock_node (rn);
3724}
3725
3726/* Configure static BGP network. When user don't run zebra, static
3727 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003728static int
paulfd79ac92004-10-13 05:06:08 +00003729bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003730 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003731{
3732 int ret;
3733 struct prefix p;
3734 struct bgp_static *bgp_static;
3735 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003736 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003737
3738 /* Convert IP prefix string to struct prefix. */
3739 ret = str2prefix (ip_str, &p);
3740 if (! ret)
3741 {
3742 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3743 return CMD_WARNING;
3744 }
3745#ifdef HAVE_IPV6
3746 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3747 {
3748 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3749 VTY_NEWLINE);
3750 return CMD_WARNING;
3751 }
3752#endif /* HAVE_IPV6 */
3753
3754 apply_mask (&p);
3755
3756 /* Set BGP static route configuration. */
3757 rn = bgp_node_get (bgp->route[afi][safi], &p);
3758
3759 if (rn->info)
3760 {
3761 /* Configuration change. */
3762 bgp_static = rn->info;
3763
3764 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003765 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3766 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003767
paul718e3742002-12-13 20:15:29 +00003768 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003769
paul718e3742002-12-13 20:15:29 +00003770 if (rmap)
3771 {
3772 if (bgp_static->rmap.name)
3773 free (bgp_static->rmap.name);
3774 bgp_static->rmap.name = strdup (rmap);
3775 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3776 }
3777 else
3778 {
3779 if (bgp_static->rmap.name)
3780 free (bgp_static->rmap.name);
3781 bgp_static->rmap.name = NULL;
3782 bgp_static->rmap.map = NULL;
3783 bgp_static->valid = 0;
3784 }
3785 bgp_unlock_node (rn);
3786 }
3787 else
3788 {
3789 /* New configuration. */
3790 bgp_static = bgp_static_new ();
3791 bgp_static->backdoor = backdoor;
3792 bgp_static->valid = 0;
3793 bgp_static->igpmetric = 0;
3794 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003795
paul718e3742002-12-13 20:15:29 +00003796 if (rmap)
3797 {
3798 if (bgp_static->rmap.name)
3799 free (bgp_static->rmap.name);
3800 bgp_static->rmap.name = strdup (rmap);
3801 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3802 }
3803 rn->info = bgp_static;
3804 }
3805
3806 /* If BGP scan is not enabled, we should install this route here. */
3807 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3808 {
3809 bgp_static->valid = 1;
3810
3811 if (need_update)
3812 bgp_static_withdraw (bgp, &p, afi, safi);
3813
3814 if (! bgp_static->backdoor)
3815 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3816 }
3817
3818 return CMD_SUCCESS;
3819}
3820
3821/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003822static int
paulfd79ac92004-10-13 05:06:08 +00003823bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003824 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003825{
3826 int ret;
3827 struct prefix p;
3828 struct bgp_static *bgp_static;
3829 struct bgp_node *rn;
3830
3831 /* Convert IP prefix string to struct prefix. */
3832 ret = str2prefix (ip_str, &p);
3833 if (! ret)
3834 {
3835 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3836 return CMD_WARNING;
3837 }
3838#ifdef HAVE_IPV6
3839 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3840 {
3841 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3842 VTY_NEWLINE);
3843 return CMD_WARNING;
3844 }
3845#endif /* HAVE_IPV6 */
3846
3847 apply_mask (&p);
3848
3849 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3850 if (! rn)
3851 {
3852 vty_out (vty, "%% Can't find specified static route configuration.%s",
3853 VTY_NEWLINE);
3854 return CMD_WARNING;
3855 }
3856
3857 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003858
paul718e3742002-12-13 20:15:29 +00003859 /* Update BGP RIB. */
3860 if (! bgp_static->backdoor)
3861 bgp_static_withdraw (bgp, &p, afi, safi);
3862
3863 /* Clear configuration. */
3864 bgp_static_free (bgp_static);
3865 rn->info = NULL;
3866 bgp_unlock_node (rn);
3867 bgp_unlock_node (rn);
3868
3869 return CMD_SUCCESS;
3870}
3871
3872/* Called from bgp_delete(). Delete all static routes from the BGP
3873 instance. */
3874void
3875bgp_static_delete (struct bgp *bgp)
3876{
3877 afi_t afi;
3878 safi_t safi;
3879 struct bgp_node *rn;
3880 struct bgp_node *rm;
3881 struct bgp_table *table;
3882 struct bgp_static *bgp_static;
3883
3884 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3885 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3886 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3887 if (rn->info != NULL)
3888 {
3889 if (safi == SAFI_MPLS_VPN)
3890 {
3891 table = rn->info;
3892
3893 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3894 {
3895 bgp_static = rn->info;
3896 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3897 AFI_IP, SAFI_MPLS_VPN,
3898 (struct prefix_rd *)&rn->p,
3899 bgp_static->tag);
3900 bgp_static_free (bgp_static);
3901 rn->info = NULL;
3902 bgp_unlock_node (rn);
3903 }
3904 }
3905 else
3906 {
3907 bgp_static = rn->info;
3908 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3909 bgp_static_free (bgp_static);
3910 rn->info = NULL;
3911 bgp_unlock_node (rn);
3912 }
3913 }
3914}
3915
3916int
paulfd79ac92004-10-13 05:06:08 +00003917bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3918 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003919{
3920 int ret;
3921 struct prefix p;
3922 struct prefix_rd prd;
3923 struct bgp *bgp;
3924 struct bgp_node *prn;
3925 struct bgp_node *rn;
3926 struct bgp_table *table;
3927 struct bgp_static *bgp_static;
3928 u_char tag[3];
3929
3930 bgp = vty->index;
3931
3932 ret = str2prefix (ip_str, &p);
3933 if (! ret)
3934 {
3935 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3936 return CMD_WARNING;
3937 }
3938 apply_mask (&p);
3939
3940 ret = str2prefix_rd (rd_str, &prd);
3941 if (! ret)
3942 {
3943 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3944 return CMD_WARNING;
3945 }
3946
3947 ret = str2tag (tag_str, tag);
3948 if (! ret)
3949 {
3950 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3951 return CMD_WARNING;
3952 }
3953
3954 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3955 (struct prefix *)&prd);
3956 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003957 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003958 else
3959 bgp_unlock_node (prn);
3960 table = prn->info;
3961
3962 rn = bgp_node_get (table, &p);
3963
3964 if (rn->info)
3965 {
3966 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3967 bgp_unlock_node (rn);
3968 }
3969 else
3970 {
3971 /* New configuration. */
3972 bgp_static = bgp_static_new ();
3973 bgp_static->valid = 1;
3974 memcpy (bgp_static->tag, tag, 3);
3975 rn->info = bgp_static;
3976
3977 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3978 }
3979
3980 return CMD_SUCCESS;
3981}
3982
3983/* Configure static BGP network. */
3984int
paulfd79ac92004-10-13 05:06:08 +00003985bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3986 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003987{
3988 int ret;
3989 struct bgp *bgp;
3990 struct prefix p;
3991 struct prefix_rd prd;
3992 struct bgp_node *prn;
3993 struct bgp_node *rn;
3994 struct bgp_table *table;
3995 struct bgp_static *bgp_static;
3996 u_char tag[3];
3997
3998 bgp = vty->index;
3999
4000 /* Convert IP prefix string to struct prefix. */
4001 ret = str2prefix (ip_str, &p);
4002 if (! ret)
4003 {
4004 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4005 return CMD_WARNING;
4006 }
4007 apply_mask (&p);
4008
4009 ret = str2prefix_rd (rd_str, &prd);
4010 if (! ret)
4011 {
4012 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4013 return CMD_WARNING;
4014 }
4015
4016 ret = str2tag (tag_str, tag);
4017 if (! ret)
4018 {
4019 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4020 return CMD_WARNING;
4021 }
4022
4023 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4024 (struct prefix *)&prd);
4025 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00004026 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00004027 else
4028 bgp_unlock_node (prn);
4029 table = prn->info;
4030
4031 rn = bgp_node_lookup (table, &p);
4032
4033 if (rn)
4034 {
4035 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4036
4037 bgp_static = rn->info;
4038 bgp_static_free (bgp_static);
4039 rn->info = NULL;
4040 bgp_unlock_node (rn);
4041 bgp_unlock_node (rn);
4042 }
4043 else
4044 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4045
4046 return CMD_SUCCESS;
4047}
David Lamparter6b0655a2014-06-04 06:53:35 +02004048
paul718e3742002-12-13 20:15:29 +00004049DEFUN (bgp_network,
4050 bgp_network_cmd,
4051 "network A.B.C.D/M",
4052 "Specify a network to announce via BGP\n"
4053 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4054{
4055 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004056 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004057}
4058
4059DEFUN (bgp_network_route_map,
4060 bgp_network_route_map_cmd,
4061 "network A.B.C.D/M route-map WORD",
4062 "Specify a network to announce via BGP\n"
4063 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4064 "Route-map to modify the attributes\n"
4065 "Name of the route map\n")
4066{
4067 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004068 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004069}
4070
4071DEFUN (bgp_network_backdoor,
4072 bgp_network_backdoor_cmd,
4073 "network A.B.C.D/M backdoor",
4074 "Specify a network to announce via BGP\n"
4075 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4076 "Specify a BGP backdoor route\n")
4077{
Paul Jakma41367172007-08-06 15:24:51 +00004078 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004079 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004080}
4081
4082DEFUN (bgp_network_mask,
4083 bgp_network_mask_cmd,
4084 "network A.B.C.D mask A.B.C.D",
4085 "Specify a network to announce via BGP\n"
4086 "Network number\n"
4087 "Network mask\n"
4088 "Network mask\n")
4089{
4090 int ret;
4091 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004092
paul718e3742002-12-13 20:15:29 +00004093 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4094 if (! ret)
4095 {
4096 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4097 return CMD_WARNING;
4098 }
4099
4100 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004101 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004102}
4103
4104DEFUN (bgp_network_mask_route_map,
4105 bgp_network_mask_route_map_cmd,
4106 "network A.B.C.D mask A.B.C.D route-map WORD",
4107 "Specify a network to announce via BGP\n"
4108 "Network number\n"
4109 "Network mask\n"
4110 "Network mask\n"
4111 "Route-map to modify the attributes\n"
4112 "Name of the route map\n")
4113{
4114 int ret;
4115 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004116
paul718e3742002-12-13 20:15:29 +00004117 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4118 if (! ret)
4119 {
4120 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4121 return CMD_WARNING;
4122 }
4123
4124 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004125 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004126}
4127
4128DEFUN (bgp_network_mask_backdoor,
4129 bgp_network_mask_backdoor_cmd,
4130 "network A.B.C.D mask A.B.C.D backdoor",
4131 "Specify a network to announce via BGP\n"
4132 "Network number\n"
4133 "Network mask\n"
4134 "Network mask\n"
4135 "Specify a BGP backdoor route\n")
4136{
4137 int ret;
4138 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004139
paul718e3742002-12-13 20:15:29 +00004140 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4141 if (! ret)
4142 {
4143 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4144 return CMD_WARNING;
4145 }
4146
Paul Jakma41367172007-08-06 15:24:51 +00004147 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004148 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004149}
4150
4151DEFUN (bgp_network_mask_natural,
4152 bgp_network_mask_natural_cmd,
4153 "network A.B.C.D",
4154 "Specify a network to announce via BGP\n"
4155 "Network number\n")
4156{
4157 int ret;
4158 char prefix_str[BUFSIZ];
4159
4160 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4161 if (! ret)
4162 {
4163 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4164 return CMD_WARNING;
4165 }
4166
4167 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004168 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004169}
4170
4171DEFUN (bgp_network_mask_natural_route_map,
4172 bgp_network_mask_natural_route_map_cmd,
4173 "network A.B.C.D route-map WORD",
4174 "Specify a network to announce via BGP\n"
4175 "Network number\n"
4176 "Route-map to modify the attributes\n"
4177 "Name of the route map\n")
4178{
4179 int ret;
4180 char prefix_str[BUFSIZ];
4181
4182 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4183 if (! ret)
4184 {
4185 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4186 return CMD_WARNING;
4187 }
4188
4189 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004190 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004191}
4192
4193DEFUN (bgp_network_mask_natural_backdoor,
4194 bgp_network_mask_natural_backdoor_cmd,
4195 "network A.B.C.D backdoor",
4196 "Specify a network to announce via BGP\n"
4197 "Network number\n"
4198 "Specify a BGP backdoor route\n")
4199{
4200 int ret;
4201 char prefix_str[BUFSIZ];
4202
4203 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4204 if (! ret)
4205 {
4206 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4207 return CMD_WARNING;
4208 }
4209
Paul Jakma41367172007-08-06 15:24:51 +00004210 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004211 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004212}
4213
4214DEFUN (no_bgp_network,
4215 no_bgp_network_cmd,
4216 "no network A.B.C.D/M",
4217 NO_STR
4218 "Specify a network to announce via BGP\n"
4219 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4220{
4221 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4222 bgp_node_safi (vty));
4223}
4224
4225ALIAS (no_bgp_network,
4226 no_bgp_network_route_map_cmd,
4227 "no network A.B.C.D/M route-map WORD",
4228 NO_STR
4229 "Specify a network to announce via BGP\n"
4230 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4231 "Route-map to modify the attributes\n"
4232 "Name of the route map\n")
4233
4234ALIAS (no_bgp_network,
4235 no_bgp_network_backdoor_cmd,
4236 "no network A.B.C.D/M backdoor",
4237 NO_STR
4238 "Specify a network to announce via BGP\n"
4239 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4240 "Specify a BGP backdoor route\n")
4241
4242DEFUN (no_bgp_network_mask,
4243 no_bgp_network_mask_cmd,
4244 "no network A.B.C.D mask A.B.C.D",
4245 NO_STR
4246 "Specify a network to announce via BGP\n"
4247 "Network number\n"
4248 "Network mask\n"
4249 "Network mask\n")
4250{
4251 int ret;
4252 char prefix_str[BUFSIZ];
4253
4254 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4255 if (! ret)
4256 {
4257 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4258 return CMD_WARNING;
4259 }
4260
4261 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4262 bgp_node_safi (vty));
4263}
4264
4265ALIAS (no_bgp_network_mask,
4266 no_bgp_network_mask_route_map_cmd,
4267 "no network A.B.C.D mask A.B.C.D route-map WORD",
4268 NO_STR
4269 "Specify a network to announce via BGP\n"
4270 "Network number\n"
4271 "Network mask\n"
4272 "Network mask\n"
4273 "Route-map to modify the attributes\n"
4274 "Name of the route map\n")
4275
4276ALIAS (no_bgp_network_mask,
4277 no_bgp_network_mask_backdoor_cmd,
4278 "no network A.B.C.D mask A.B.C.D backdoor",
4279 NO_STR
4280 "Specify a network to announce via BGP\n"
4281 "Network number\n"
4282 "Network mask\n"
4283 "Network mask\n"
4284 "Specify a BGP backdoor route\n")
4285
4286DEFUN (no_bgp_network_mask_natural,
4287 no_bgp_network_mask_natural_cmd,
4288 "no network A.B.C.D",
4289 NO_STR
4290 "Specify a network to announce via BGP\n"
4291 "Network number\n")
4292{
4293 int ret;
4294 char prefix_str[BUFSIZ];
4295
4296 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4297 if (! ret)
4298 {
4299 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4300 return CMD_WARNING;
4301 }
4302
4303 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4304 bgp_node_safi (vty));
4305}
4306
4307ALIAS (no_bgp_network_mask_natural,
4308 no_bgp_network_mask_natural_route_map_cmd,
4309 "no network A.B.C.D route-map WORD",
4310 NO_STR
4311 "Specify a network to announce via BGP\n"
4312 "Network number\n"
4313 "Route-map to modify the attributes\n"
4314 "Name of the route map\n")
4315
4316ALIAS (no_bgp_network_mask_natural,
4317 no_bgp_network_mask_natural_backdoor_cmd,
4318 "no network A.B.C.D backdoor",
4319 NO_STR
4320 "Specify a network to announce via BGP\n"
4321 "Network number\n"
4322 "Specify a BGP backdoor route\n")
4323
4324#ifdef HAVE_IPV6
4325DEFUN (ipv6_bgp_network,
4326 ipv6_bgp_network_cmd,
4327 "network X:X::X:X/M",
4328 "Specify a network to announce via BGP\n"
4329 "IPv6 prefix <network>/<length>\n")
4330{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304331 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004332 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004333}
4334
4335DEFUN (ipv6_bgp_network_route_map,
4336 ipv6_bgp_network_route_map_cmd,
4337 "network X:X::X:X/M route-map WORD",
4338 "Specify a network to announce via BGP\n"
4339 "IPv6 prefix <network>/<length>\n"
4340 "Route-map to modify the attributes\n"
4341 "Name of the route map\n")
4342{
4343 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004344 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004345}
4346
4347DEFUN (no_ipv6_bgp_network,
4348 no_ipv6_bgp_network_cmd,
4349 "no network X:X::X:X/M",
4350 NO_STR
4351 "Specify a network to announce via BGP\n"
4352 "IPv6 prefix <network>/<length>\n")
4353{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304354 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004355}
4356
4357ALIAS (no_ipv6_bgp_network,
4358 no_ipv6_bgp_network_route_map_cmd,
4359 "no network X:X::X:X/M route-map WORD",
4360 NO_STR
4361 "Specify a network to announce via BGP\n"
4362 "IPv6 prefix <network>/<length>\n"
4363 "Route-map to modify the attributes\n"
4364 "Name of the route map\n")
4365
4366ALIAS (ipv6_bgp_network,
4367 old_ipv6_bgp_network_cmd,
4368 "ipv6 bgp network X:X::X:X/M",
4369 IPV6_STR
4370 BGP_STR
4371 "Specify a network to announce via BGP\n"
4372 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4373
4374ALIAS (no_ipv6_bgp_network,
4375 old_no_ipv6_bgp_network_cmd,
4376 "no ipv6 bgp network X:X::X:X/M",
4377 NO_STR
4378 IPV6_STR
4379 BGP_STR
4380 "Specify a network to announce via BGP\n"
4381 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4382#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004383
4384/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4385ALIAS_DEPRECATED (bgp_network,
4386 bgp_network_ttl_cmd,
4387 "network A.B.C.D/M pathlimit <0-255>",
4388 "Specify a network to announce via BGP\n"
4389 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4390 "AS-Path hopcount limit attribute\n"
4391 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4392ALIAS_DEPRECATED (bgp_network_backdoor,
4393 bgp_network_backdoor_ttl_cmd,
4394 "network A.B.C.D/M backdoor pathlimit <0-255>",
4395 "Specify a network to announce via BGP\n"
4396 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4397 "Specify a BGP backdoor route\n"
4398 "AS-Path hopcount limit attribute\n"
4399 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4400ALIAS_DEPRECATED (bgp_network_mask,
4401 bgp_network_mask_ttl_cmd,
4402 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4403 "Specify a network to announce via BGP\n"
4404 "Network number\n"
4405 "Network mask\n"
4406 "Network mask\n"
4407 "AS-Path hopcount limit attribute\n"
4408 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4409ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4410 bgp_network_mask_backdoor_ttl_cmd,
4411 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4412 "Specify a network to announce via BGP\n"
4413 "Network number\n"
4414 "Network mask\n"
4415 "Network mask\n"
4416 "Specify a BGP backdoor route\n"
4417 "AS-Path hopcount limit attribute\n"
4418 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4419ALIAS_DEPRECATED (bgp_network_mask_natural,
4420 bgp_network_mask_natural_ttl_cmd,
4421 "network A.B.C.D pathlimit <0-255>",
4422 "Specify a network to announce via BGP\n"
4423 "Network number\n"
4424 "AS-Path hopcount limit attribute\n"
4425 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4426ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4427 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004428 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004429 "Specify a network to announce via BGP\n"
4430 "Network number\n"
4431 "Specify a BGP backdoor route\n"
4432 "AS-Path hopcount limit attribute\n"
4433 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4434ALIAS_DEPRECATED (no_bgp_network,
4435 no_bgp_network_ttl_cmd,
4436 "no network A.B.C.D/M pathlimit <0-255>",
4437 NO_STR
4438 "Specify a network to announce via BGP\n"
4439 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4440 "AS-Path hopcount limit attribute\n"
4441 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4442ALIAS_DEPRECATED (no_bgp_network,
4443 no_bgp_network_backdoor_ttl_cmd,
4444 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4445 NO_STR
4446 "Specify a network to announce via BGP\n"
4447 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4448 "Specify a BGP backdoor route\n"
4449 "AS-Path hopcount limit attribute\n"
4450 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4451ALIAS_DEPRECATED (no_bgp_network,
4452 no_bgp_network_mask_ttl_cmd,
4453 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4454 NO_STR
4455 "Specify a network to announce via BGP\n"
4456 "Network number\n"
4457 "Network mask\n"
4458 "Network mask\n"
4459 "AS-Path hopcount limit attribute\n"
4460 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4461ALIAS_DEPRECATED (no_bgp_network_mask,
4462 no_bgp_network_mask_backdoor_ttl_cmd,
4463 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4464 NO_STR
4465 "Specify a network to announce via BGP\n"
4466 "Network number\n"
4467 "Network mask\n"
4468 "Network mask\n"
4469 "Specify a BGP backdoor route\n"
4470 "AS-Path hopcount limit attribute\n"
4471 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4472ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4473 no_bgp_network_mask_natural_ttl_cmd,
4474 "no network A.B.C.D pathlimit <0-255>",
4475 NO_STR
4476 "Specify a network to announce via BGP\n"
4477 "Network number\n"
4478 "AS-Path hopcount limit attribute\n"
4479 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4480ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4481 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4482 "no network A.B.C.D backdoor pathlimit <0-255>",
4483 NO_STR
4484 "Specify a network to announce via BGP\n"
4485 "Network number\n"
4486 "Specify a BGP backdoor route\n"
4487 "AS-Path hopcount limit attribute\n"
4488 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004489#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004490ALIAS_DEPRECATED (ipv6_bgp_network,
4491 ipv6_bgp_network_ttl_cmd,
4492 "network X:X::X:X/M pathlimit <0-255>",
4493 "Specify a network to announce via BGP\n"
4494 "IPv6 prefix <network>/<length>\n"
4495 "AS-Path hopcount limit attribute\n"
4496 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4497ALIAS_DEPRECATED (no_ipv6_bgp_network,
4498 no_ipv6_bgp_network_ttl_cmd,
4499 "no network X:X::X:X/M pathlimit <0-255>",
4500 NO_STR
4501 "Specify a network to announce via BGP\n"
4502 "IPv6 prefix <network>/<length>\n"
4503 "AS-Path hopcount limit attribute\n"
4504 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004505#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02004506
paul718e3742002-12-13 20:15:29 +00004507/* Aggreagete address:
4508
4509 advertise-map Set condition to advertise attribute
4510 as-set Generate AS set path information
4511 attribute-map Set attributes of aggregate
4512 route-map Set parameters of aggregate
4513 summary-only Filter more specific routes from updates
4514 suppress-map Conditionally filter more specific routes from updates
4515 <cr>
4516 */
4517struct bgp_aggregate
4518{
4519 /* Summary-only flag. */
4520 u_char summary_only;
4521
4522 /* AS set generation. */
4523 u_char as_set;
4524
4525 /* Route-map for aggregated route. */
4526 struct route_map *map;
4527
4528 /* Suppress-count. */
4529 unsigned long count;
4530
4531 /* SAFI configuration. */
4532 safi_t safi;
4533};
4534
paul94f2b392005-06-28 12:44:16 +00004535static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004536bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004537{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004538 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004539}
4540
paul94f2b392005-06-28 12:44:16 +00004541static void
paul718e3742002-12-13 20:15:29 +00004542bgp_aggregate_free (struct bgp_aggregate *aggregate)
4543{
4544 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4545}
4546
paul94f2b392005-06-28 12:44:16 +00004547static void
paul718e3742002-12-13 20:15:29 +00004548bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4549 afi_t afi, safi_t safi, struct bgp_info *del,
4550 struct bgp_aggregate *aggregate)
4551{
4552 struct bgp_table *table;
4553 struct bgp_node *top;
4554 struct bgp_node *rn;
4555 u_char origin;
4556 struct aspath *aspath = NULL;
4557 struct aspath *asmerge = NULL;
4558 struct community *community = NULL;
4559 struct community *commerge = NULL;
paul718e3742002-12-13 20:15:29 +00004560 struct bgp_info *ri;
4561 struct bgp_info *new;
4562 int first = 1;
4563 unsigned long match = 0;
4564
paul718e3742002-12-13 20:15:29 +00004565 /* ORIGIN attribute: If at least one route among routes that are
4566 aggregated has ORIGIN with the value INCOMPLETE, then the
4567 aggregated route must have the ORIGIN attribute with the value
4568 INCOMPLETE. Otherwise, if at least one route among routes that
4569 are aggregated has ORIGIN with the value EGP, then the aggregated
4570 route must have the origin attribute with the value EGP. In all
4571 other case the value of the ORIGIN attribute of the aggregated
4572 route is INTERNAL. */
4573 origin = BGP_ORIGIN_IGP;
4574
4575 table = bgp->rib[afi][safi];
4576
4577 top = bgp_node_get (table, p);
4578 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4579 if (rn->p.prefixlen > p->prefixlen)
4580 {
4581 match = 0;
4582
4583 for (ri = rn->info; ri; ri = ri->next)
4584 {
4585 if (BGP_INFO_HOLDDOWN (ri))
4586 continue;
4587
4588 if (del && ri == del)
4589 continue;
4590
4591 if (! rinew && first)
Paul Jakma7aa9dce2014-09-19 14:42:23 +01004592 first = 0;
paul718e3742002-12-13 20:15:29 +00004593
4594#ifdef AGGREGATE_NEXTHOP_CHECK
4595 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4596 || ri->attr->med != med)
4597 {
4598 if (aspath)
4599 aspath_free (aspath);
4600 if (community)
4601 community_free (community);
4602 bgp_unlock_node (rn);
4603 bgp_unlock_node (top);
4604 return;
4605 }
4606#endif /* AGGREGATE_NEXTHOP_CHECK */
4607
4608 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4609 {
4610 if (aggregate->summary_only)
4611 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004612 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004613 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004614 match++;
4615 }
4616
4617 aggregate->count++;
4618
4619 if (aggregate->as_set)
4620 {
4621 if (origin < ri->attr->origin)
4622 origin = ri->attr->origin;
4623
4624 if (aspath)
4625 {
4626 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4627 aspath_free (aspath);
4628 aspath = asmerge;
4629 }
4630 else
4631 aspath = aspath_dup (ri->attr->aspath);
4632
4633 if (ri->attr->community)
4634 {
4635 if (community)
4636 {
4637 commerge = community_merge (community,
4638 ri->attr->community);
4639 community = community_uniq_sort (commerge);
4640 community_free (commerge);
4641 }
4642 else
4643 community = community_dup (ri->attr->community);
4644 }
4645 }
4646 }
4647 }
4648 if (match)
4649 bgp_process (bgp, rn, afi, safi);
4650 }
4651 bgp_unlock_node (top);
4652
4653 if (rinew)
4654 {
4655 aggregate->count++;
4656
4657 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004658 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004659
4660 if (aggregate->as_set)
4661 {
4662 if (origin < rinew->attr->origin)
4663 origin = rinew->attr->origin;
4664
4665 if (aspath)
4666 {
4667 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4668 aspath_free (aspath);
4669 aspath = asmerge;
4670 }
4671 else
4672 aspath = aspath_dup (rinew->attr->aspath);
4673
4674 if (rinew->attr->community)
4675 {
4676 if (community)
4677 {
4678 commerge = community_merge (community,
4679 rinew->attr->community);
4680 community = community_uniq_sort (commerge);
4681 community_free (commerge);
4682 }
4683 else
4684 community = community_dup (rinew->attr->community);
4685 }
4686 }
4687 }
4688
4689 if (aggregate->count > 0)
4690 {
4691 rn = bgp_node_get (table, p);
4692 new = bgp_info_new ();
4693 new->type = ZEBRA_ROUTE_BGP;
4694 new->sub_type = BGP_ROUTE_AGGREGATE;
4695 new->peer = bgp->peer_self;
4696 SET_FLAG (new->flags, BGP_INFO_VALID);
4697 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004698 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004699
4700 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004701 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004702 bgp_process (bgp, rn, afi, safi);
4703 }
4704 else
4705 {
4706 if (aspath)
4707 aspath_free (aspath);
4708 if (community)
4709 community_free (community);
4710 }
4711}
4712
4713void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4714 struct bgp_aggregate *);
4715
4716void
4717bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4718 struct bgp_info *ri, afi_t afi, safi_t safi)
4719{
4720 struct bgp_node *child;
4721 struct bgp_node *rn;
4722 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004723 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004724
4725 /* MPLS-VPN aggregation is not yet supported. */
4726 if (safi == SAFI_MPLS_VPN)
4727 return;
4728
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004729 table = bgp->aggregate[afi][safi];
4730
4731 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004732 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004733 return;
4734
paul718e3742002-12-13 20:15:29 +00004735 if (p->prefixlen == 0)
4736 return;
4737
4738 if (BGP_INFO_HOLDDOWN (ri))
4739 return;
4740
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004741 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004742
4743 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004744 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004745 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4746 {
4747 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004748 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004749 }
4750 bgp_unlock_node (child);
4751}
4752
4753void
4754bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4755 struct bgp_info *del, afi_t afi, safi_t safi)
4756{
4757 struct bgp_node *child;
4758 struct bgp_node *rn;
4759 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004760 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004761
4762 /* MPLS-VPN aggregation is not yet supported. */
4763 if (safi == SAFI_MPLS_VPN)
4764 return;
4765
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004766 table = bgp->aggregate[afi][safi];
4767
4768 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004769 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004770 return;
4771
paul718e3742002-12-13 20:15:29 +00004772 if (p->prefixlen == 0)
4773 return;
4774
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004775 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004776
4777 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004778 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004779 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4780 {
4781 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004782 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004783 }
4784 bgp_unlock_node (child);
4785}
4786
paul94f2b392005-06-28 12:44:16 +00004787static void
paul718e3742002-12-13 20:15:29 +00004788bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4789 struct bgp_aggregate *aggregate)
4790{
4791 struct bgp_table *table;
4792 struct bgp_node *top;
4793 struct bgp_node *rn;
4794 struct bgp_info *new;
4795 struct bgp_info *ri;
4796 unsigned long match;
4797 u_char origin = BGP_ORIGIN_IGP;
4798 struct aspath *aspath = NULL;
4799 struct aspath *asmerge = NULL;
4800 struct community *community = NULL;
4801 struct community *commerge = NULL;
4802
4803 table = bgp->rib[afi][safi];
4804
4805 /* Sanity check. */
4806 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4807 return;
4808 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4809 return;
4810
4811 /* If routes exists below this node, generate aggregate routes. */
4812 top = bgp_node_get (table, p);
4813 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4814 if (rn->p.prefixlen > p->prefixlen)
4815 {
4816 match = 0;
4817
4818 for (ri = rn->info; ri; ri = ri->next)
4819 {
4820 if (BGP_INFO_HOLDDOWN (ri))
4821 continue;
4822
4823 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4824 {
4825 /* summary-only aggregate route suppress aggregated
4826 route announcement. */
4827 if (aggregate->summary_only)
4828 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004829 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004830 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004831 match++;
4832 }
4833 /* as-set aggregate route generate origin, as path,
4834 community aggregation. */
4835 if (aggregate->as_set)
4836 {
4837 if (origin < ri->attr->origin)
4838 origin = ri->attr->origin;
4839
4840 if (aspath)
4841 {
4842 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4843 aspath_free (aspath);
4844 aspath = asmerge;
4845 }
4846 else
4847 aspath = aspath_dup (ri->attr->aspath);
4848
4849 if (ri->attr->community)
4850 {
4851 if (community)
4852 {
4853 commerge = community_merge (community,
4854 ri->attr->community);
4855 community = community_uniq_sort (commerge);
4856 community_free (commerge);
4857 }
4858 else
4859 community = community_dup (ri->attr->community);
4860 }
4861 }
4862 aggregate->count++;
4863 }
4864 }
4865
4866 /* If this node is suppressed, process the change. */
4867 if (match)
4868 bgp_process (bgp, rn, afi, safi);
4869 }
4870 bgp_unlock_node (top);
4871
4872 /* Add aggregate route to BGP table. */
4873 if (aggregate->count)
4874 {
4875 rn = bgp_node_get (table, p);
4876
4877 new = bgp_info_new ();
4878 new->type = ZEBRA_ROUTE_BGP;
4879 new->sub_type = BGP_ROUTE_AGGREGATE;
4880 new->peer = bgp->peer_self;
4881 SET_FLAG (new->flags, BGP_INFO_VALID);
4882 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004883 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004884
4885 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004886 bgp_unlock_node (rn);
4887
paul718e3742002-12-13 20:15:29 +00004888 /* Process change. */
4889 bgp_process (bgp, rn, afi, safi);
4890 }
4891}
4892
4893void
4894bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4895 safi_t safi, struct bgp_aggregate *aggregate)
4896{
4897 struct bgp_table *table;
4898 struct bgp_node *top;
4899 struct bgp_node *rn;
4900 struct bgp_info *ri;
4901 unsigned long match;
4902
4903 table = bgp->rib[afi][safi];
4904
4905 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4906 return;
4907 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4908 return;
4909
4910 /* If routes exists below this node, generate aggregate routes. */
4911 top = bgp_node_get (table, p);
4912 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4913 if (rn->p.prefixlen > p->prefixlen)
4914 {
4915 match = 0;
4916
4917 for (ri = rn->info; ri; ri = ri->next)
4918 {
4919 if (BGP_INFO_HOLDDOWN (ri))
4920 continue;
4921
4922 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4923 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004924 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004925 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004926 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004927
Paul Jakmafb982c22007-05-04 20:15:47 +00004928 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004929 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004930 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004931 match++;
4932 }
4933 }
4934 aggregate->count--;
4935 }
4936 }
4937
Paul Jakmafb982c22007-05-04 20:15:47 +00004938 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004939 if (match)
4940 bgp_process (bgp, rn, afi, safi);
4941 }
4942 bgp_unlock_node (top);
4943
4944 /* Delete aggregate route from BGP table. */
4945 rn = bgp_node_get (table, p);
4946
4947 for (ri = rn->info; ri; ri = ri->next)
4948 if (ri->peer == bgp->peer_self
4949 && ri->type == ZEBRA_ROUTE_BGP
4950 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4951 break;
4952
4953 /* Withdraw static BGP route from routing table. */
4954 if (ri)
4955 {
paul718e3742002-12-13 20:15:29 +00004956 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004957 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004958 }
4959
4960 /* Unlock bgp_node_lookup. */
4961 bgp_unlock_node (rn);
4962}
4963
4964/* Aggregate route attribute. */
4965#define AGGREGATE_SUMMARY_ONLY 1
4966#define AGGREGATE_AS_SET 1
4967
paul94f2b392005-06-28 12:44:16 +00004968static int
Robert Baysf6269b42010-08-05 10:26:28 -07004969bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4970 afi_t afi, safi_t safi)
4971{
4972 int ret;
4973 struct prefix p;
4974 struct bgp_node *rn;
4975 struct bgp *bgp;
4976 struct bgp_aggregate *aggregate;
4977
4978 /* Convert string to prefix structure. */
4979 ret = str2prefix (prefix_str, &p);
4980 if (!ret)
4981 {
4982 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4983 return CMD_WARNING;
4984 }
4985 apply_mask (&p);
4986
4987 /* Get BGP structure. */
4988 bgp = vty->index;
4989
4990 /* Old configuration check. */
4991 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4992 if (! rn)
4993 {
4994 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4995 VTY_NEWLINE);
4996 return CMD_WARNING;
4997 }
4998
4999 aggregate = rn->info;
5000 if (aggregate->safi & SAFI_UNICAST)
5001 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5002 if (aggregate->safi & SAFI_MULTICAST)
5003 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5004
5005 /* Unlock aggregate address configuration. */
5006 rn->info = NULL;
5007 bgp_aggregate_free (aggregate);
5008 bgp_unlock_node (rn);
5009 bgp_unlock_node (rn);
5010
5011 return CMD_SUCCESS;
5012}
5013
5014static int
5015bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00005016 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00005017 u_char summary_only, u_char as_set)
5018{
5019 int ret;
5020 struct prefix p;
5021 struct bgp_node *rn;
5022 struct bgp *bgp;
5023 struct bgp_aggregate *aggregate;
5024
5025 /* Convert string to prefix structure. */
5026 ret = str2prefix (prefix_str, &p);
5027 if (!ret)
5028 {
5029 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5030 return CMD_WARNING;
5031 }
5032 apply_mask (&p);
5033
5034 /* Get BGP structure. */
5035 bgp = vty->index;
5036
5037 /* Old configuration check. */
5038 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5039
5040 if (rn->info)
5041 {
5042 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005043 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005044 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5045 if (ret)
5046 {
Robert Bays368473f2010-08-05 10:26:29 -07005047 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5048 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005049 return CMD_WARNING;
5050 }
paul718e3742002-12-13 20:15:29 +00005051 }
5052
5053 /* Make aggregate address structure. */
5054 aggregate = bgp_aggregate_new ();
5055 aggregate->summary_only = summary_only;
5056 aggregate->as_set = as_set;
5057 aggregate->safi = safi;
5058 rn->info = aggregate;
5059
5060 /* Aggregate address insert into BGP routing table. */
5061 if (safi & SAFI_UNICAST)
5062 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5063 if (safi & SAFI_MULTICAST)
5064 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5065
5066 return CMD_SUCCESS;
5067}
5068
paul718e3742002-12-13 20:15:29 +00005069DEFUN (aggregate_address,
5070 aggregate_address_cmd,
5071 "aggregate-address A.B.C.D/M",
5072 "Configure BGP aggregate entries\n"
5073 "Aggregate prefix\n")
5074{
5075 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5076}
5077
5078DEFUN (aggregate_address_mask,
5079 aggregate_address_mask_cmd,
5080 "aggregate-address A.B.C.D A.B.C.D",
5081 "Configure BGP aggregate entries\n"
5082 "Aggregate address\n"
5083 "Aggregate mask\n")
5084{
5085 int ret;
5086 char prefix_str[BUFSIZ];
5087
5088 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5089
5090 if (! ret)
5091 {
5092 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5093 return CMD_WARNING;
5094 }
5095
5096 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5097 0, 0);
5098}
5099
5100DEFUN (aggregate_address_summary_only,
5101 aggregate_address_summary_only_cmd,
5102 "aggregate-address A.B.C.D/M summary-only",
5103 "Configure BGP aggregate entries\n"
5104 "Aggregate prefix\n"
5105 "Filter more specific routes from updates\n")
5106{
5107 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5108 AGGREGATE_SUMMARY_ONLY, 0);
5109}
5110
5111DEFUN (aggregate_address_mask_summary_only,
5112 aggregate_address_mask_summary_only_cmd,
5113 "aggregate-address A.B.C.D A.B.C.D summary-only",
5114 "Configure BGP aggregate entries\n"
5115 "Aggregate address\n"
5116 "Aggregate mask\n"
5117 "Filter more specific routes from updates\n")
5118{
5119 int ret;
5120 char prefix_str[BUFSIZ];
5121
5122 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5123
5124 if (! ret)
5125 {
5126 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5127 return CMD_WARNING;
5128 }
5129
5130 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5131 AGGREGATE_SUMMARY_ONLY, 0);
5132}
5133
5134DEFUN (aggregate_address_as_set,
5135 aggregate_address_as_set_cmd,
5136 "aggregate-address A.B.C.D/M as-set",
5137 "Configure BGP aggregate entries\n"
5138 "Aggregate prefix\n"
5139 "Generate AS set path information\n")
5140{
5141 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5142 0, AGGREGATE_AS_SET);
5143}
5144
5145DEFUN (aggregate_address_mask_as_set,
5146 aggregate_address_mask_as_set_cmd,
5147 "aggregate-address A.B.C.D A.B.C.D as-set",
5148 "Configure BGP aggregate entries\n"
5149 "Aggregate address\n"
5150 "Aggregate mask\n"
5151 "Generate AS set path information\n")
5152{
5153 int ret;
5154 char prefix_str[BUFSIZ];
5155
5156 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5157
5158 if (! ret)
5159 {
5160 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5161 return CMD_WARNING;
5162 }
5163
5164 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5165 0, AGGREGATE_AS_SET);
5166}
5167
5168
5169DEFUN (aggregate_address_as_set_summary,
5170 aggregate_address_as_set_summary_cmd,
5171 "aggregate-address A.B.C.D/M as-set summary-only",
5172 "Configure BGP aggregate entries\n"
5173 "Aggregate prefix\n"
5174 "Generate AS set path information\n"
5175 "Filter more specific routes from updates\n")
5176{
5177 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5178 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5179}
5180
5181ALIAS (aggregate_address_as_set_summary,
5182 aggregate_address_summary_as_set_cmd,
5183 "aggregate-address A.B.C.D/M summary-only as-set",
5184 "Configure BGP aggregate entries\n"
5185 "Aggregate prefix\n"
5186 "Filter more specific routes from updates\n"
5187 "Generate AS set path information\n")
5188
5189DEFUN (aggregate_address_mask_as_set_summary,
5190 aggregate_address_mask_as_set_summary_cmd,
5191 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5192 "Configure BGP aggregate entries\n"
5193 "Aggregate address\n"
5194 "Aggregate mask\n"
5195 "Generate AS set path information\n"
5196 "Filter more specific routes from updates\n")
5197{
5198 int ret;
5199 char prefix_str[BUFSIZ];
5200
5201 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5202
5203 if (! ret)
5204 {
5205 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5206 return CMD_WARNING;
5207 }
5208
5209 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5210 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5211}
5212
5213ALIAS (aggregate_address_mask_as_set_summary,
5214 aggregate_address_mask_summary_as_set_cmd,
5215 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5216 "Configure BGP aggregate entries\n"
5217 "Aggregate address\n"
5218 "Aggregate mask\n"
5219 "Filter more specific routes from updates\n"
5220 "Generate AS set path information\n")
5221
5222DEFUN (no_aggregate_address,
5223 no_aggregate_address_cmd,
5224 "no aggregate-address A.B.C.D/M",
5225 NO_STR
5226 "Configure BGP aggregate entries\n"
5227 "Aggregate prefix\n")
5228{
5229 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5230}
5231
5232ALIAS (no_aggregate_address,
5233 no_aggregate_address_summary_only_cmd,
5234 "no aggregate-address A.B.C.D/M summary-only",
5235 NO_STR
5236 "Configure BGP aggregate entries\n"
5237 "Aggregate prefix\n"
5238 "Filter more specific routes from updates\n")
5239
5240ALIAS (no_aggregate_address,
5241 no_aggregate_address_as_set_cmd,
5242 "no aggregate-address A.B.C.D/M as-set",
5243 NO_STR
5244 "Configure BGP aggregate entries\n"
5245 "Aggregate prefix\n"
5246 "Generate AS set path information\n")
5247
5248ALIAS (no_aggregate_address,
5249 no_aggregate_address_as_set_summary_cmd,
5250 "no aggregate-address A.B.C.D/M as-set summary-only",
5251 NO_STR
5252 "Configure BGP aggregate entries\n"
5253 "Aggregate prefix\n"
5254 "Generate AS set path information\n"
5255 "Filter more specific routes from updates\n")
5256
5257ALIAS (no_aggregate_address,
5258 no_aggregate_address_summary_as_set_cmd,
5259 "no aggregate-address A.B.C.D/M summary-only as-set",
5260 NO_STR
5261 "Configure BGP aggregate entries\n"
5262 "Aggregate prefix\n"
5263 "Filter more specific routes from updates\n"
5264 "Generate AS set path information\n")
5265
5266DEFUN (no_aggregate_address_mask,
5267 no_aggregate_address_mask_cmd,
5268 "no aggregate-address A.B.C.D A.B.C.D",
5269 NO_STR
5270 "Configure BGP aggregate entries\n"
5271 "Aggregate address\n"
5272 "Aggregate mask\n")
5273{
5274 int ret;
5275 char prefix_str[BUFSIZ];
5276
5277 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5278
5279 if (! ret)
5280 {
5281 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5282 return CMD_WARNING;
5283 }
5284
5285 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5286}
5287
5288ALIAS (no_aggregate_address_mask,
5289 no_aggregate_address_mask_summary_only_cmd,
5290 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5291 NO_STR
5292 "Configure BGP aggregate entries\n"
5293 "Aggregate address\n"
5294 "Aggregate mask\n"
5295 "Filter more specific routes from updates\n")
5296
5297ALIAS (no_aggregate_address_mask,
5298 no_aggregate_address_mask_as_set_cmd,
5299 "no aggregate-address A.B.C.D A.B.C.D as-set",
5300 NO_STR
5301 "Configure BGP aggregate entries\n"
5302 "Aggregate address\n"
5303 "Aggregate mask\n"
5304 "Generate AS set path information\n")
5305
5306ALIAS (no_aggregate_address_mask,
5307 no_aggregate_address_mask_as_set_summary_cmd,
5308 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5309 NO_STR
5310 "Configure BGP aggregate entries\n"
5311 "Aggregate address\n"
5312 "Aggregate mask\n"
5313 "Generate AS set path information\n"
5314 "Filter more specific routes from updates\n")
5315
5316ALIAS (no_aggregate_address_mask,
5317 no_aggregate_address_mask_summary_as_set_cmd,
5318 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5319 NO_STR
5320 "Configure BGP aggregate entries\n"
5321 "Aggregate address\n"
5322 "Aggregate mask\n"
5323 "Filter more specific routes from updates\n"
5324 "Generate AS set path information\n")
5325
5326#ifdef HAVE_IPV6
5327DEFUN (ipv6_aggregate_address,
5328 ipv6_aggregate_address_cmd,
5329 "aggregate-address X:X::X:X/M",
5330 "Configure BGP aggregate entries\n"
5331 "Aggregate prefix\n")
5332{
5333 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5334}
5335
5336DEFUN (ipv6_aggregate_address_summary_only,
5337 ipv6_aggregate_address_summary_only_cmd,
5338 "aggregate-address X:X::X:X/M summary-only",
5339 "Configure BGP aggregate entries\n"
5340 "Aggregate prefix\n"
5341 "Filter more specific routes from updates\n")
5342{
5343 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5344 AGGREGATE_SUMMARY_ONLY, 0);
5345}
5346
5347DEFUN (no_ipv6_aggregate_address,
5348 no_ipv6_aggregate_address_cmd,
5349 "no aggregate-address X:X::X:X/M",
5350 NO_STR
5351 "Configure BGP aggregate entries\n"
5352 "Aggregate prefix\n")
5353{
5354 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5355}
5356
5357DEFUN (no_ipv6_aggregate_address_summary_only,
5358 no_ipv6_aggregate_address_summary_only_cmd,
5359 "no aggregate-address X:X::X:X/M summary-only",
5360 NO_STR
5361 "Configure BGP aggregate entries\n"
5362 "Aggregate prefix\n"
5363 "Filter more specific routes from updates\n")
5364{
5365 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5366}
5367
5368ALIAS (ipv6_aggregate_address,
5369 old_ipv6_aggregate_address_cmd,
5370 "ipv6 bgp aggregate-address X:X::X:X/M",
5371 IPV6_STR
5372 BGP_STR
5373 "Configure BGP aggregate entries\n"
5374 "Aggregate prefix\n")
5375
5376ALIAS (ipv6_aggregate_address_summary_only,
5377 old_ipv6_aggregate_address_summary_only_cmd,
5378 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5379 IPV6_STR
5380 BGP_STR
5381 "Configure BGP aggregate entries\n"
5382 "Aggregate prefix\n"
5383 "Filter more specific routes from updates\n")
5384
5385ALIAS (no_ipv6_aggregate_address,
5386 old_no_ipv6_aggregate_address_cmd,
5387 "no ipv6 bgp aggregate-address X:X::X:X/M",
5388 NO_STR
5389 IPV6_STR
5390 BGP_STR
5391 "Configure BGP aggregate entries\n"
5392 "Aggregate prefix\n")
5393
5394ALIAS (no_ipv6_aggregate_address_summary_only,
5395 old_no_ipv6_aggregate_address_summary_only_cmd,
5396 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5397 NO_STR
5398 IPV6_STR
5399 BGP_STR
5400 "Configure BGP aggregate entries\n"
5401 "Aggregate prefix\n"
5402 "Filter more specific routes from updates\n")
5403#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02005404
paul718e3742002-12-13 20:15:29 +00005405/* Redistribute route treatment. */
5406void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005407bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5408 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005409 u_int32_t metric, u_char type)
5410{
5411 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005412 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005413 struct bgp_info *new;
5414 struct bgp_info *bi;
5415 struct bgp_info info;
5416 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005417 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005418 struct attr *new_attr;
5419 afi_t afi;
5420 int ret;
5421
5422 /* Make default attribute. */
5423 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5424 if (nexthop)
5425 attr.nexthop = *nexthop;
5426
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005427#ifdef HAVE_IPV6
5428 if (nexthop6)
5429 {
5430 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5431 extra->mp_nexthop_global = *nexthop6;
5432 extra->mp_nexthop_len = 16;
5433 }
5434#endif
5435
paul718e3742002-12-13 20:15:29 +00005436 attr.med = metric;
5437 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5438
paul1eb8ef22005-04-07 07:30:20 +00005439 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005440 {
5441 afi = family2afi (p->family);
5442
5443 if (bgp->redist[afi][type])
5444 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005445 struct attr attr_new;
5446 struct attr_extra extra_new;
5447
paul718e3742002-12-13 20:15:29 +00005448 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005449 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005450 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005451
5452 if (bgp->redist_metric_flag[afi][type])
5453 attr_new.med = bgp->redist_metric[afi][type];
5454
5455 /* Apply route-map. */
5456 if (bgp->rmap[afi][type].map)
5457 {
5458 info.peer = bgp->peer_self;
5459 info.attr = &attr_new;
5460
paulfee0f4c2004-09-13 05:12:46 +00005461 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5462
paul718e3742002-12-13 20:15:29 +00005463 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5464 &info);
paulfee0f4c2004-09-13 05:12:46 +00005465
5466 bgp->peer_self->rmap_type = 0;
5467
paul718e3742002-12-13 20:15:29 +00005468 if (ret == RMAP_DENYMATCH)
5469 {
5470 /* Free uninterned attribute. */
5471 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005472
paul718e3742002-12-13 20:15:29 +00005473 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005474 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005475 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005476 bgp_redistribute_delete (p, type);
5477 return;
5478 }
5479 }
5480
Paul Jakmafb982c22007-05-04 20:15:47 +00005481 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5482 afi, SAFI_UNICAST, p, NULL);
5483
paul718e3742002-12-13 20:15:29 +00005484 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005485
paul718e3742002-12-13 20:15:29 +00005486 for (bi = bn->info; bi; bi = bi->next)
5487 if (bi->peer == bgp->peer_self
5488 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5489 break;
5490
5491 if (bi)
5492 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005493 if (attrhash_cmp (bi->attr, new_attr) &&
5494 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005495 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005496 bgp_attr_unintern (&new_attr);
5497 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005498 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005499 bgp_unlock_node (bn);
5500 return;
5501 }
5502 else
5503 {
5504 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005505 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005506
5507 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005508 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5509 bgp_info_restore(bn, bi);
5510 else
5511 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005512 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005513 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005514 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005515
5516 /* Process change. */
5517 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5518 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5519 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005520 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005521 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005522 return;
5523 }
5524 }
5525
5526 new = bgp_info_new ();
5527 new->type = type;
5528 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5529 new->peer = bgp->peer_self;
5530 SET_FLAG (new->flags, BGP_INFO_VALID);
5531 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005532 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005533
5534 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5535 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005536 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005537 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5538 }
5539 }
5540
5541 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005542 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005543 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005544}
5545
5546void
5547bgp_redistribute_delete (struct prefix *p, u_char type)
5548{
5549 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005550 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005551 afi_t afi;
5552 struct bgp_node *rn;
5553 struct bgp_info *ri;
5554
paul1eb8ef22005-04-07 07:30:20 +00005555 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005556 {
5557 afi = family2afi (p->family);
5558
5559 if (bgp->redist[afi][type])
5560 {
paulfee0f4c2004-09-13 05:12:46 +00005561 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005562
5563 for (ri = rn->info; ri; ri = ri->next)
5564 if (ri->peer == bgp->peer_self
5565 && ri->type == type)
5566 break;
5567
5568 if (ri)
5569 {
5570 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005571 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005572 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005573 }
5574 bgp_unlock_node (rn);
5575 }
5576 }
5577}
5578
5579/* Withdraw specified route type's route. */
5580void
5581bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5582{
5583 struct bgp_node *rn;
5584 struct bgp_info *ri;
5585 struct bgp_table *table;
5586
5587 table = bgp->rib[afi][SAFI_UNICAST];
5588
5589 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5590 {
5591 for (ri = rn->info; ri; ri = ri->next)
5592 if (ri->peer == bgp->peer_self
5593 && ri->type == type)
5594 break;
5595
5596 if (ri)
5597 {
5598 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005599 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005600 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005601 }
5602 }
5603}
David Lamparter6b0655a2014-06-04 06:53:35 +02005604
paul718e3742002-12-13 20:15:29 +00005605/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005606static void
paul718e3742002-12-13 20:15:29 +00005607route_vty_out_route (struct prefix *p, struct vty *vty)
5608{
5609 int len;
5610 u_int32_t destination;
5611 char buf[BUFSIZ];
5612
5613 if (p->family == AF_INET)
5614 {
5615 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5616 destination = ntohl (p->u.prefix4.s_addr);
5617
5618 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5619 || (IN_CLASSB (destination) && p->prefixlen == 16)
5620 || (IN_CLASSA (destination) && p->prefixlen == 8)
5621 || p->u.prefix4.s_addr == 0)
5622 {
5623 /* When mask is natural, mask is not displayed. */
5624 }
5625 else
5626 len += vty_out (vty, "/%d", p->prefixlen);
5627 }
5628 else
5629 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5630 p->prefixlen);
5631
5632 len = 17 - len;
5633 if (len < 1)
5634 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5635 else
5636 vty_out (vty, "%*s", len, " ");
5637}
5638
paul718e3742002-12-13 20:15:29 +00005639enum bgp_display_type
5640{
5641 normal_list,
5642};
5643
paulb40d9392005-08-22 22:34:41 +00005644/* Print the short form route status for a bgp_info */
5645static void
5646route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005647{
paulb40d9392005-08-22 22:34:41 +00005648 /* Route status display. */
5649 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5650 vty_out (vty, "R");
5651 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005652 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005653 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005654 vty_out (vty, "s");
5655 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5656 vty_out (vty, "*");
5657 else
5658 vty_out (vty, " ");
5659
5660 /* Selected */
5661 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5662 vty_out (vty, "h");
5663 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5664 vty_out (vty, "d");
5665 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5666 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005667 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5668 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005669 else
5670 vty_out (vty, " ");
5671
5672 /* Internal route. */
5673 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5674 vty_out (vty, "i");
5675 else
paulb40d9392005-08-22 22:34:41 +00005676 vty_out (vty, " ");
5677}
5678
5679/* called from terminal list command */
5680void
5681route_vty_out (struct vty *vty, struct prefix *p,
5682 struct bgp_info *binfo, int display, safi_t safi)
5683{
5684 struct attr *attr;
5685
5686 /* short status lead text */
5687 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005688
5689 /* print prefix and mask */
5690 if (! display)
5691 route_vty_out_route (p, vty);
5692 else
5693 vty_out (vty, "%*s", 17, " ");
5694
5695 /* Print attribute */
5696 attr = binfo->attr;
5697 if (attr)
5698 {
5699 if (p->family == AF_INET)
5700 {
5701 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005702 vty_out (vty, "%-16s",
5703 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005704 else
5705 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5706 }
5707#ifdef HAVE_IPV6
5708 else if (p->family == AF_INET6)
5709 {
5710 int len;
5711 char buf[BUFSIZ];
5712
5713 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005714 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5715 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005716 len = 16 - len;
5717 if (len < 1)
5718 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5719 else
5720 vty_out (vty, "%*s", len, " ");
5721 }
5722#endif /* HAVE_IPV6 */
5723
5724 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005725 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005726 else
5727 vty_out (vty, " ");
5728
5729 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005730 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005731 else
5732 vty_out (vty, " ");
5733
Paul Jakmafb982c22007-05-04 20:15:47 +00005734 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005735
Paul Jakmab2518c12006-05-12 23:48:40 +00005736 /* Print aspath */
5737 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005738 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005739
Paul Jakmab2518c12006-05-12 23:48:40 +00005740 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005741 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005742 }
paul718e3742002-12-13 20:15:29 +00005743 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005744}
5745
5746/* called from terminal list command */
5747void
5748route_vty_out_tmp (struct vty *vty, struct prefix *p,
5749 struct attr *attr, safi_t safi)
5750{
5751 /* Route status display. */
5752 vty_out (vty, "*");
5753 vty_out (vty, ">");
5754 vty_out (vty, " ");
5755
5756 /* print prefix and mask */
5757 route_vty_out_route (p, vty);
5758
5759 /* Print attribute */
5760 if (attr)
5761 {
5762 if (p->family == AF_INET)
5763 {
5764 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005765 vty_out (vty, "%-16s",
5766 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005767 else
5768 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5769 }
5770#ifdef HAVE_IPV6
5771 else if (p->family == AF_INET6)
5772 {
5773 int len;
5774 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005775
5776 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005777
5778 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005779 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5780 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005781 len = 16 - len;
5782 if (len < 1)
5783 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5784 else
5785 vty_out (vty, "%*s", len, " ");
5786 }
5787#endif /* HAVE_IPV6 */
5788
5789 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005790 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005791 else
5792 vty_out (vty, " ");
5793
5794 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005795 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005796 else
5797 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005798
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005799 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005800
Paul Jakmab2518c12006-05-12 23:48:40 +00005801 /* Print aspath */
5802 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005803 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005804
Paul Jakmab2518c12006-05-12 23:48:40 +00005805 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005806 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005807 }
paul718e3742002-12-13 20:15:29 +00005808
5809 vty_out (vty, "%s", VTY_NEWLINE);
5810}
5811
ajs5a646652004-11-05 01:25:55 +00005812void
paul718e3742002-12-13 20:15:29 +00005813route_vty_out_tag (struct vty *vty, struct prefix *p,
5814 struct bgp_info *binfo, int display, safi_t safi)
5815{
5816 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005817 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005818
5819 if (!binfo->extra)
5820 return;
5821
paulb40d9392005-08-22 22:34:41 +00005822 /* short status lead text */
5823 route_vty_short_status_out (vty, binfo);
5824
paul718e3742002-12-13 20:15:29 +00005825 /* print prefix and mask */
5826 if (! display)
5827 route_vty_out_route (p, vty);
5828 else
5829 vty_out (vty, "%*s", 17, " ");
5830
5831 /* Print attribute */
5832 attr = binfo->attr;
5833 if (attr)
5834 {
5835 if (p->family == AF_INET)
5836 {
5837 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005838 vty_out (vty, "%-16s",
5839 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005840 else
5841 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5842 }
5843#ifdef HAVE_IPV6
5844 else if (p->family == AF_INET6)
5845 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005846 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005847 char buf[BUFSIZ];
5848 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005849 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005850 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005851 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5852 buf, BUFSIZ));
5853 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005854 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005855 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5856 buf, BUFSIZ),
5857 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5858 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005859
5860 }
5861#endif /* HAVE_IPV6 */
5862 }
5863
Paul Jakmafb982c22007-05-04 20:15:47 +00005864 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005865
5866 vty_out (vty, "notag/%d", label);
5867
5868 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005869}
5870
5871/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005872static void
paul718e3742002-12-13 20:15:29 +00005873damp_route_vty_out (struct vty *vty, struct prefix *p,
5874 struct bgp_info *binfo, int display, safi_t safi)
5875{
5876 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005877 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005878 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005879
paulb40d9392005-08-22 22:34:41 +00005880 /* short status lead text */
5881 route_vty_short_status_out (vty, binfo);
5882
paul718e3742002-12-13 20:15:29 +00005883 /* print prefix and mask */
5884 if (! display)
5885 route_vty_out_route (p, vty);
5886 else
5887 vty_out (vty, "%*s", 17, " ");
5888
5889 len = vty_out (vty, "%s", binfo->peer->host);
5890 len = 17 - len;
5891 if (len < 1)
5892 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5893 else
5894 vty_out (vty, "%*s", len, " ");
5895
Chris Caputo50aef6f2009-06-23 06:06:49 +00005896 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005897
5898 /* Print attribute */
5899 attr = binfo->attr;
5900 if (attr)
5901 {
5902 /* Print aspath */
5903 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005904 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005905
5906 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005907 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005908 }
5909 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005910}
5911
paul718e3742002-12-13 20:15:29 +00005912/* flap route */
ajs5a646652004-11-05 01:25:55 +00005913static void
paul718e3742002-12-13 20:15:29 +00005914flap_route_vty_out (struct vty *vty, struct prefix *p,
5915 struct bgp_info *binfo, int display, safi_t safi)
5916{
5917 struct attr *attr;
5918 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005919 char timebuf[BGP_UPTIME_LEN];
5920 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005921
5922 if (!binfo->extra)
5923 return;
5924
5925 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005926
paulb40d9392005-08-22 22:34:41 +00005927 /* short status lead text */
5928 route_vty_short_status_out (vty, binfo);
5929
paul718e3742002-12-13 20:15:29 +00005930 /* print prefix and mask */
5931 if (! display)
5932 route_vty_out_route (p, vty);
5933 else
5934 vty_out (vty, "%*s", 17, " ");
5935
5936 len = vty_out (vty, "%s", binfo->peer->host);
5937 len = 16 - len;
5938 if (len < 1)
5939 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5940 else
5941 vty_out (vty, "%*s", len, " ");
5942
5943 len = vty_out (vty, "%d", bdi->flap);
5944 len = 5 - len;
5945 if (len < 1)
5946 vty_out (vty, " ");
5947 else
5948 vty_out (vty, "%*s ", len, " ");
5949
5950 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5951 timebuf, BGP_UPTIME_LEN));
5952
5953 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5954 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005955 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005956 else
5957 vty_out (vty, "%*s ", 8, " ");
5958
5959 /* Print attribute */
5960 attr = binfo->attr;
5961 if (attr)
5962 {
5963 /* Print aspath */
5964 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005965 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005966
5967 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005968 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005969 }
5970 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005971}
5972
paul94f2b392005-06-28 12:44:16 +00005973static void
paul718e3742002-12-13 20:15:29 +00005974route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5975 struct bgp_info *binfo, afi_t afi, safi_t safi)
5976{
5977 char buf[INET6_ADDRSTRLEN];
5978 char buf1[BUFSIZ];
5979 struct attr *attr;
5980 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005981#ifdef HAVE_CLOCK_MONOTONIC
5982 time_t tbuf;
5983#endif
paul718e3742002-12-13 20:15:29 +00005984
5985 attr = binfo->attr;
5986
5987 if (attr)
5988 {
5989 /* Line1 display AS-path, Aggregator */
5990 if (attr->aspath)
5991 {
5992 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005993 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005994 vty_out (vty, "Local");
5995 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005996 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005997 }
5998
paulb40d9392005-08-22 22:34:41 +00005999 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6000 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00006001 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6002 vty_out (vty, ", (stale)");
6003 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006004 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006005 attr->extra->aggregator_as,
6006 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006007 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6008 vty_out (vty, ", (Received from a RR-client)");
6009 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6010 vty_out (vty, ", (Received from a RS-client)");
6011 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6012 vty_out (vty, ", (history entry)");
6013 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6014 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006015 vty_out (vty, "%s", VTY_NEWLINE);
6016
6017 /* Line2 display Next-hop, Neighbor, Router-id */
6018 if (p->family == AF_INET)
6019 {
6020 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006021 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006022 inet_ntoa (attr->nexthop));
6023 }
6024#ifdef HAVE_IPV6
6025 else
6026 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006027 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006028 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006029 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006030 buf, INET6_ADDRSTRLEN));
6031 }
6032#endif /* HAVE_IPV6 */
6033
6034 if (binfo->peer == bgp->peer_self)
6035 {
6036 vty_out (vty, " from %s ",
6037 p->family == AF_INET ? "0.0.0.0" : "::");
6038 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6039 }
6040 else
6041 {
6042 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6043 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006044 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006045 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006046 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006047 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006048 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006049 else
6050 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6051 }
6052 vty_out (vty, "%s", VTY_NEWLINE);
6053
6054#ifdef HAVE_IPV6
6055 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006056 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006057 {
6058 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006059 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006060 buf, INET6_ADDRSTRLEN),
6061 VTY_NEWLINE);
6062 }
6063#endif /* HAVE_IPV6 */
6064
6065 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6066 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6067
6068 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006069 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006070
6071 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006072 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006073 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006074 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006075
Paul Jakmafb982c22007-05-04 20:15:47 +00006076 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006077 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006078
6079 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6080 vty_out (vty, ", valid");
6081
6082 if (binfo->peer != bgp->peer_self)
6083 {
6084 if (binfo->peer->as == binfo->peer->local_as)
6085 vty_out (vty, ", internal");
6086 else
6087 vty_out (vty, ", %s",
6088 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6089 }
6090 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6091 vty_out (vty, ", aggregated, local");
6092 else if (binfo->type != ZEBRA_ROUTE_BGP)
6093 vty_out (vty, ", sourced");
6094 else
6095 vty_out (vty, ", sourced, local");
6096
6097 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6098 vty_out (vty, ", atomic-aggregate");
6099
Josh Baileyde8d5df2011-07-20 20:46:01 -07006100 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6101 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6102 bgp_info_mpath_count (binfo)))
6103 vty_out (vty, ", multipath");
6104
paul718e3742002-12-13 20:15:29 +00006105 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6106 vty_out (vty, ", best");
6107
6108 vty_out (vty, "%s", VTY_NEWLINE);
6109
6110 /* Line 4 display Community */
6111 if (attr->community)
6112 vty_out (vty, " Community: %s%s", attr->community->str,
6113 VTY_NEWLINE);
6114
6115 /* Line 5 display Extended-community */
6116 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006117 vty_out (vty, " Extended Community: %s%s",
6118 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006119
6120 /* Line 6 display Originator, Cluster-id */
6121 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6122 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6123 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006124 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006125 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006126 vty_out (vty, " Originator: %s",
6127 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006128
6129 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6130 {
6131 int i;
6132 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006133 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6134 vty_out (vty, "%s ",
6135 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006136 }
6137 vty_out (vty, "%s", VTY_NEWLINE);
6138 }
Paul Jakma41367172007-08-06 15:24:51 +00006139
Paul Jakmafb982c22007-05-04 20:15:47 +00006140 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006141 bgp_damp_info_vty (vty, binfo);
6142
6143 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006144#ifdef HAVE_CLOCK_MONOTONIC
6145 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006146 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006147#else
6148 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6149#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006150 }
6151 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006152}
6153
6154#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6155 "h history, * valid, > best, = multipath,%s"\
6156 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006157#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006158#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6159#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6160#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6161
6162enum bgp_show_type
6163{
6164 bgp_show_type_normal,
6165 bgp_show_type_regexp,
6166 bgp_show_type_prefix_list,
6167 bgp_show_type_filter_list,
6168 bgp_show_type_route_map,
6169 bgp_show_type_neighbor,
6170 bgp_show_type_cidr_only,
6171 bgp_show_type_prefix_longer,
6172 bgp_show_type_community_all,
6173 bgp_show_type_community,
6174 bgp_show_type_community_exact,
6175 bgp_show_type_community_list,
6176 bgp_show_type_community_list_exact,
6177 bgp_show_type_flap_statistics,
6178 bgp_show_type_flap_address,
6179 bgp_show_type_flap_prefix,
6180 bgp_show_type_flap_cidr_only,
6181 bgp_show_type_flap_regexp,
6182 bgp_show_type_flap_filter_list,
6183 bgp_show_type_flap_prefix_list,
6184 bgp_show_type_flap_prefix_longer,
6185 bgp_show_type_flap_route_map,
6186 bgp_show_type_flap_neighbor,
6187 bgp_show_type_dampend_paths,
6188 bgp_show_type_damp_neighbor
6189};
6190
ajs5a646652004-11-05 01:25:55 +00006191static int
paulfee0f4c2004-09-13 05:12:46 +00006192bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006193 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006194{
paul718e3742002-12-13 20:15:29 +00006195 struct bgp_info *ri;
6196 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006197 int header = 1;
paul718e3742002-12-13 20:15:29 +00006198 int display;
ajs5a646652004-11-05 01:25:55 +00006199 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006200
6201 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006202 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006203
paul718e3742002-12-13 20:15:29 +00006204 /* Start processing of routes. */
6205 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6206 if (rn->info != NULL)
6207 {
6208 display = 0;
6209
6210 for (ri = rn->info; ri; ri = ri->next)
6211 {
ajs5a646652004-11-05 01:25:55 +00006212 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006213 || type == bgp_show_type_flap_address
6214 || type == bgp_show_type_flap_prefix
6215 || type == bgp_show_type_flap_cidr_only
6216 || type == bgp_show_type_flap_regexp
6217 || type == bgp_show_type_flap_filter_list
6218 || type == bgp_show_type_flap_prefix_list
6219 || type == bgp_show_type_flap_prefix_longer
6220 || type == bgp_show_type_flap_route_map
6221 || type == bgp_show_type_flap_neighbor
6222 || type == bgp_show_type_dampend_paths
6223 || type == bgp_show_type_damp_neighbor)
6224 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006225 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006226 continue;
6227 }
6228 if (type == bgp_show_type_regexp
6229 || type == bgp_show_type_flap_regexp)
6230 {
ajs5a646652004-11-05 01:25:55 +00006231 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006232
6233 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6234 continue;
6235 }
6236 if (type == bgp_show_type_prefix_list
6237 || type == bgp_show_type_flap_prefix_list)
6238 {
ajs5a646652004-11-05 01:25:55 +00006239 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006240
6241 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6242 continue;
6243 }
6244 if (type == bgp_show_type_filter_list
6245 || type == bgp_show_type_flap_filter_list)
6246 {
ajs5a646652004-11-05 01:25:55 +00006247 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006248
6249 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6250 continue;
6251 }
6252 if (type == bgp_show_type_route_map
6253 || type == bgp_show_type_flap_route_map)
6254 {
ajs5a646652004-11-05 01:25:55 +00006255 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006256 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006257 struct attr dummy_attr;
6258 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006259 int ret;
6260
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006261 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006262 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006263
paul718e3742002-12-13 20:15:29 +00006264 binfo.peer = ri->peer;
6265 binfo.attr = &dummy_attr;
6266
6267 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006268 if (ret == RMAP_DENYMATCH)
6269 continue;
6270 }
6271 if (type == bgp_show_type_neighbor
6272 || type == bgp_show_type_flap_neighbor
6273 || type == bgp_show_type_damp_neighbor)
6274 {
ajs5a646652004-11-05 01:25:55 +00006275 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006276
6277 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6278 continue;
6279 }
6280 if (type == bgp_show_type_cidr_only
6281 || type == bgp_show_type_flap_cidr_only)
6282 {
6283 u_int32_t destination;
6284
6285 destination = ntohl (rn->p.u.prefix4.s_addr);
6286 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6287 continue;
6288 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6289 continue;
6290 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6291 continue;
6292 }
6293 if (type == bgp_show_type_prefix_longer
6294 || type == bgp_show_type_flap_prefix_longer)
6295 {
ajs5a646652004-11-05 01:25:55 +00006296 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006297
6298 if (! prefix_match (p, &rn->p))
6299 continue;
6300 }
6301 if (type == bgp_show_type_community_all)
6302 {
6303 if (! ri->attr->community)
6304 continue;
6305 }
6306 if (type == bgp_show_type_community)
6307 {
ajs5a646652004-11-05 01:25:55 +00006308 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006309
6310 if (! ri->attr->community ||
6311 ! community_match (ri->attr->community, com))
6312 continue;
6313 }
6314 if (type == bgp_show_type_community_exact)
6315 {
ajs5a646652004-11-05 01:25:55 +00006316 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006317
6318 if (! ri->attr->community ||
6319 ! community_cmp (ri->attr->community, com))
6320 continue;
6321 }
6322 if (type == bgp_show_type_community_list)
6323 {
ajs5a646652004-11-05 01:25:55 +00006324 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006325
6326 if (! community_list_match (ri->attr->community, list))
6327 continue;
6328 }
6329 if (type == bgp_show_type_community_list_exact)
6330 {
ajs5a646652004-11-05 01:25:55 +00006331 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006332
6333 if (! community_list_exact_match (ri->attr->community, list))
6334 continue;
6335 }
6336 if (type == bgp_show_type_flap_address
6337 || type == bgp_show_type_flap_prefix)
6338 {
ajs5a646652004-11-05 01:25:55 +00006339 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006340
6341 if (! prefix_match (&rn->p, p))
6342 continue;
6343
6344 if (type == bgp_show_type_flap_prefix)
6345 if (p->prefixlen != rn->p.prefixlen)
6346 continue;
6347 }
6348 if (type == bgp_show_type_dampend_paths
6349 || type == bgp_show_type_damp_neighbor)
6350 {
6351 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6352 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6353 continue;
6354 }
6355
6356 if (header)
6357 {
hasso93406d82005-02-02 14:40:33 +00006358 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6359 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6360 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006361 if (type == bgp_show_type_dampend_paths
6362 || type == bgp_show_type_damp_neighbor)
6363 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6364 else if (type == bgp_show_type_flap_statistics
6365 || type == bgp_show_type_flap_address
6366 || type == bgp_show_type_flap_prefix
6367 || type == bgp_show_type_flap_cidr_only
6368 || type == bgp_show_type_flap_regexp
6369 || type == bgp_show_type_flap_filter_list
6370 || type == bgp_show_type_flap_prefix_list
6371 || type == bgp_show_type_flap_prefix_longer
6372 || type == bgp_show_type_flap_route_map
6373 || type == bgp_show_type_flap_neighbor)
6374 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6375 else
6376 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006377 header = 0;
6378 }
6379
6380 if (type == bgp_show_type_dampend_paths
6381 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006382 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006383 else if (type == bgp_show_type_flap_statistics
6384 || type == bgp_show_type_flap_address
6385 || type == bgp_show_type_flap_prefix
6386 || type == bgp_show_type_flap_cidr_only
6387 || type == bgp_show_type_flap_regexp
6388 || type == bgp_show_type_flap_filter_list
6389 || type == bgp_show_type_flap_prefix_list
6390 || type == bgp_show_type_flap_prefix_longer
6391 || type == bgp_show_type_flap_route_map
6392 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006393 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006394 else
ajs5a646652004-11-05 01:25:55 +00006395 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006396 display++;
6397 }
6398 if (display)
ajs5a646652004-11-05 01:25:55 +00006399 output_count++;
paul718e3742002-12-13 20:15:29 +00006400 }
6401
6402 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006403 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006404 {
6405 if (type == bgp_show_type_normal)
6406 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6407 }
6408 else
6409 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006410 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006411
6412 return CMD_SUCCESS;
6413}
6414
ajs5a646652004-11-05 01:25:55 +00006415static int
paulfee0f4c2004-09-13 05:12:46 +00006416bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006417 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006418{
6419 struct bgp_table *table;
6420
6421 if (bgp == NULL) {
6422 bgp = bgp_get_default ();
6423 }
6424
6425 if (bgp == NULL)
6426 {
6427 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6428 return CMD_WARNING;
6429 }
6430
6431
6432 table = bgp->rib[afi][safi];
6433
ajs5a646652004-11-05 01:25:55 +00006434 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006435}
6436
paul718e3742002-12-13 20:15:29 +00006437/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006438static void
paul718e3742002-12-13 20:15:29 +00006439route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6440 struct bgp_node *rn,
6441 struct prefix_rd *prd, afi_t afi, safi_t safi)
6442{
6443 struct bgp_info *ri;
6444 struct prefix *p;
6445 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006446 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006447 char buf1[INET6_ADDRSTRLEN];
6448 char buf2[INET6_ADDRSTRLEN];
6449 int count = 0;
6450 int best = 0;
6451 int suppress = 0;
6452 int no_export = 0;
6453 int no_advertise = 0;
6454 int local_as = 0;
6455 int first = 0;
6456
6457 p = &rn->p;
6458 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6459 (safi == SAFI_MPLS_VPN ?
6460 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6461 safi == SAFI_MPLS_VPN ? ":" : "",
6462 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6463 p->prefixlen, VTY_NEWLINE);
6464
6465 for (ri = rn->info; ri; ri = ri->next)
6466 {
6467 count++;
6468 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6469 {
6470 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006471 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006472 suppress = 1;
6473 if (ri->attr->community != NULL)
6474 {
6475 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6476 no_advertise = 1;
6477 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6478 no_export = 1;
6479 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6480 local_as = 1;
6481 }
6482 }
6483 }
6484
6485 vty_out (vty, "Paths: (%d available", count);
6486 if (best)
6487 {
6488 vty_out (vty, ", best #%d", best);
6489 if (safi == SAFI_UNICAST)
6490 vty_out (vty, ", table Default-IP-Routing-Table");
6491 }
6492 else
6493 vty_out (vty, ", no best path");
6494 if (no_advertise)
6495 vty_out (vty, ", not advertised to any peer");
6496 else if (no_export)
6497 vty_out (vty, ", not advertised to EBGP peer");
6498 else if (local_as)
6499 vty_out (vty, ", not advertised outside local AS");
6500 if (suppress)
6501 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6502 vty_out (vty, ")%s", VTY_NEWLINE);
6503
6504 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006505 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006506 {
6507 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6508 {
6509 if (! first)
6510 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6511 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6512 first = 1;
6513 }
6514 }
6515 if (! first)
6516 vty_out (vty, " Not advertised to any peer");
6517 vty_out (vty, "%s", VTY_NEWLINE);
6518}
6519
6520/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006521static int
paulfee0f4c2004-09-13 05:12:46 +00006522bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006523 struct bgp_table *rib, const char *ip_str,
6524 afi_t afi, safi_t safi, struct prefix_rd *prd,
6525 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006526{
6527 int ret;
6528 int header;
6529 int display = 0;
6530 struct prefix match;
6531 struct bgp_node *rn;
6532 struct bgp_node *rm;
6533 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006534 struct bgp_table *table;
6535
paul718e3742002-12-13 20:15:29 +00006536 /* Check IP address argument. */
6537 ret = str2prefix (ip_str, &match);
6538 if (! ret)
6539 {
6540 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6541 return CMD_WARNING;
6542 }
6543
6544 match.family = afi2family (afi);
6545
6546 if (safi == SAFI_MPLS_VPN)
6547 {
paulfee0f4c2004-09-13 05:12:46 +00006548 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006549 {
6550 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6551 continue;
6552
6553 if ((table = rn->info) != NULL)
6554 {
6555 header = 1;
6556
6557 if ((rm = bgp_node_match (table, &match)) != NULL)
6558 {
6559 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006560 {
6561 bgp_unlock_node (rm);
6562 continue;
6563 }
paul718e3742002-12-13 20:15:29 +00006564
6565 for (ri = rm->info; ri; ri = ri->next)
6566 {
6567 if (header)
6568 {
6569 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6570 AFI_IP, SAFI_MPLS_VPN);
6571
6572 header = 0;
6573 }
6574 display++;
6575 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6576 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006577
6578 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006579 }
6580 }
6581 }
6582 }
6583 else
6584 {
6585 header = 1;
6586
paulfee0f4c2004-09-13 05:12:46 +00006587 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006588 {
6589 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6590 {
6591 for (ri = rn->info; ri; ri = ri->next)
6592 {
6593 if (header)
6594 {
6595 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6596 header = 0;
6597 }
6598 display++;
6599 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6600 }
6601 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006602
6603 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006604 }
6605 }
6606
6607 if (! display)
6608 {
6609 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6610 return CMD_WARNING;
6611 }
6612
6613 return CMD_SUCCESS;
6614}
6615
paulfee0f4c2004-09-13 05:12:46 +00006616/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006617static int
paulfd79ac92004-10-13 05:06:08 +00006618bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006619 afi_t afi, safi_t safi, struct prefix_rd *prd,
6620 int prefix_check)
6621{
6622 struct bgp *bgp;
6623
6624 /* BGP structure lookup. */
6625 if (view_name)
6626 {
6627 bgp = bgp_lookup_by_name (view_name);
6628 if (bgp == NULL)
6629 {
6630 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6631 return CMD_WARNING;
6632 }
6633 }
6634 else
6635 {
6636 bgp = bgp_get_default ();
6637 if (bgp == NULL)
6638 {
6639 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6640 return CMD_WARNING;
6641 }
6642 }
6643
6644 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6645 afi, safi, prd, prefix_check);
6646}
6647
paul718e3742002-12-13 20:15:29 +00006648/* BGP route print out function. */
6649DEFUN (show_ip_bgp,
6650 show_ip_bgp_cmd,
6651 "show ip bgp",
6652 SHOW_STR
6653 IP_STR
6654 BGP_STR)
6655{
ajs5a646652004-11-05 01:25:55 +00006656 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006657}
6658
6659DEFUN (show_ip_bgp_ipv4,
6660 show_ip_bgp_ipv4_cmd,
6661 "show ip bgp ipv4 (unicast|multicast)",
6662 SHOW_STR
6663 IP_STR
6664 BGP_STR
6665 "Address family\n"
6666 "Address Family modifier\n"
6667 "Address Family modifier\n")
6668{
6669 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006670 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6671 NULL);
paul718e3742002-12-13 20:15:29 +00006672
ajs5a646652004-11-05 01:25:55 +00006673 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006674}
6675
Michael Lambert95cbbd22010-07-23 14:43:04 -04006676ALIAS (show_ip_bgp_ipv4,
6677 show_bgp_ipv4_safi_cmd,
6678 "show bgp ipv4 (unicast|multicast)",
6679 SHOW_STR
6680 BGP_STR
6681 "Address family\n"
6682 "Address Family modifier\n"
6683 "Address Family modifier\n")
6684
paul718e3742002-12-13 20:15:29 +00006685DEFUN (show_ip_bgp_route,
6686 show_ip_bgp_route_cmd,
6687 "show ip bgp A.B.C.D",
6688 SHOW_STR
6689 IP_STR
6690 BGP_STR
6691 "Network in the BGP routing table to display\n")
6692{
6693 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6694}
6695
6696DEFUN (show_ip_bgp_ipv4_route,
6697 show_ip_bgp_ipv4_route_cmd,
6698 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6699 SHOW_STR
6700 IP_STR
6701 BGP_STR
6702 "Address family\n"
6703 "Address Family modifier\n"
6704 "Address Family modifier\n"
6705 "Network in the BGP routing table to display\n")
6706{
6707 if (strncmp (argv[0], "m", 1) == 0)
6708 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6709
6710 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6711}
6712
Michael Lambert95cbbd22010-07-23 14:43:04 -04006713ALIAS (show_ip_bgp_ipv4_route,
6714 show_bgp_ipv4_safi_route_cmd,
6715 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6716 SHOW_STR
6717 BGP_STR
6718 "Address family\n"
6719 "Address Family modifier\n"
6720 "Address Family modifier\n"
6721 "Network in the BGP routing table to display\n")
6722
paul718e3742002-12-13 20:15:29 +00006723DEFUN (show_ip_bgp_vpnv4_all_route,
6724 show_ip_bgp_vpnv4_all_route_cmd,
6725 "show ip bgp vpnv4 all A.B.C.D",
6726 SHOW_STR
6727 IP_STR
6728 BGP_STR
6729 "Display VPNv4 NLRI specific information\n"
6730 "Display information about all VPNv4 NLRIs\n"
6731 "Network in the BGP routing table to display\n")
6732{
6733 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6734}
6735
6736DEFUN (show_ip_bgp_vpnv4_rd_route,
6737 show_ip_bgp_vpnv4_rd_route_cmd,
6738 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6739 SHOW_STR
6740 IP_STR
6741 BGP_STR
6742 "Display VPNv4 NLRI specific information\n"
6743 "Display information for a route distinguisher\n"
6744 "VPN Route Distinguisher\n"
6745 "Network in the BGP routing table to display\n")
6746{
6747 int ret;
6748 struct prefix_rd prd;
6749
6750 ret = str2prefix_rd (argv[0], &prd);
6751 if (! ret)
6752 {
6753 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6754 return CMD_WARNING;
6755 }
6756 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6757}
6758
6759DEFUN (show_ip_bgp_prefix,
6760 show_ip_bgp_prefix_cmd,
6761 "show ip bgp A.B.C.D/M",
6762 SHOW_STR
6763 IP_STR
6764 BGP_STR
6765 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6766{
6767 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6768}
6769
6770DEFUN (show_ip_bgp_ipv4_prefix,
6771 show_ip_bgp_ipv4_prefix_cmd,
6772 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6773 SHOW_STR
6774 IP_STR
6775 BGP_STR
6776 "Address family\n"
6777 "Address Family modifier\n"
6778 "Address Family modifier\n"
6779 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6780{
6781 if (strncmp (argv[0], "m", 1) == 0)
6782 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6783
6784 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6785}
6786
Michael Lambert95cbbd22010-07-23 14:43:04 -04006787ALIAS (show_ip_bgp_ipv4_prefix,
6788 show_bgp_ipv4_safi_prefix_cmd,
6789 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6790 SHOW_STR
6791 BGP_STR
6792 "Address family\n"
6793 "Address Family modifier\n"
6794 "Address Family modifier\n"
6795 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6796
paul718e3742002-12-13 20:15:29 +00006797DEFUN (show_ip_bgp_vpnv4_all_prefix,
6798 show_ip_bgp_vpnv4_all_prefix_cmd,
6799 "show ip bgp vpnv4 all A.B.C.D/M",
6800 SHOW_STR
6801 IP_STR
6802 BGP_STR
6803 "Display VPNv4 NLRI specific information\n"
6804 "Display information about all VPNv4 NLRIs\n"
6805 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6806{
6807 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6808}
6809
6810DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6811 show_ip_bgp_vpnv4_rd_prefix_cmd,
6812 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6813 SHOW_STR
6814 IP_STR
6815 BGP_STR
6816 "Display VPNv4 NLRI specific information\n"
6817 "Display information for a route distinguisher\n"
6818 "VPN Route Distinguisher\n"
6819 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6820{
6821 int ret;
6822 struct prefix_rd prd;
6823
6824 ret = str2prefix_rd (argv[0], &prd);
6825 if (! ret)
6826 {
6827 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6828 return CMD_WARNING;
6829 }
6830 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6831}
6832
6833DEFUN (show_ip_bgp_view,
6834 show_ip_bgp_view_cmd,
6835 "show ip bgp view WORD",
6836 SHOW_STR
6837 IP_STR
6838 BGP_STR
6839 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006840 "View name\n")
paul718e3742002-12-13 20:15:29 +00006841{
paulbb46e942003-10-24 19:02:03 +00006842 struct bgp *bgp;
6843
6844 /* BGP structure lookup. */
6845 bgp = bgp_lookup_by_name (argv[0]);
6846 if (bgp == NULL)
6847 {
6848 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6849 return CMD_WARNING;
6850 }
6851
ajs5a646652004-11-05 01:25:55 +00006852 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006853}
6854
6855DEFUN (show_ip_bgp_view_route,
6856 show_ip_bgp_view_route_cmd,
6857 "show ip bgp view WORD A.B.C.D",
6858 SHOW_STR
6859 IP_STR
6860 BGP_STR
6861 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006862 "View name\n"
paul718e3742002-12-13 20:15:29 +00006863 "Network in the BGP routing table to display\n")
6864{
6865 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6866}
6867
6868DEFUN (show_ip_bgp_view_prefix,
6869 show_ip_bgp_view_prefix_cmd,
6870 "show ip bgp view WORD A.B.C.D/M",
6871 SHOW_STR
6872 IP_STR
6873 BGP_STR
6874 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006875 "View name\n"
paul718e3742002-12-13 20:15:29 +00006876 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6877{
6878 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6879}
6880
6881#ifdef HAVE_IPV6
6882DEFUN (show_bgp,
6883 show_bgp_cmd,
6884 "show bgp",
6885 SHOW_STR
6886 BGP_STR)
6887{
ajs5a646652004-11-05 01:25:55 +00006888 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6889 NULL);
paul718e3742002-12-13 20:15:29 +00006890}
6891
6892ALIAS (show_bgp,
6893 show_bgp_ipv6_cmd,
6894 "show bgp ipv6",
6895 SHOW_STR
6896 BGP_STR
6897 "Address family\n")
6898
Michael Lambert95cbbd22010-07-23 14:43:04 -04006899DEFUN (show_bgp_ipv6_safi,
6900 show_bgp_ipv6_safi_cmd,
6901 "show bgp ipv6 (unicast|multicast)",
6902 SHOW_STR
6903 BGP_STR
6904 "Address family\n"
6905 "Address Family modifier\n"
6906 "Address Family modifier\n")
6907{
6908 if (strncmp (argv[0], "m", 1) == 0)
6909 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6910 NULL);
6911
6912 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6913}
6914
paul718e3742002-12-13 20:15:29 +00006915/* old command */
6916DEFUN (show_ipv6_bgp,
6917 show_ipv6_bgp_cmd,
6918 "show ipv6 bgp",
6919 SHOW_STR
6920 IP_STR
6921 BGP_STR)
6922{
ajs5a646652004-11-05 01:25:55 +00006923 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6924 NULL);
paul718e3742002-12-13 20:15:29 +00006925}
6926
6927DEFUN (show_bgp_route,
6928 show_bgp_route_cmd,
6929 "show bgp X:X::X:X",
6930 SHOW_STR
6931 BGP_STR
6932 "Network in the BGP routing table to display\n")
6933{
6934 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6935}
6936
6937ALIAS (show_bgp_route,
6938 show_bgp_ipv6_route_cmd,
6939 "show bgp ipv6 X:X::X:X",
6940 SHOW_STR
6941 BGP_STR
6942 "Address family\n"
6943 "Network in the BGP routing table to display\n")
6944
Michael Lambert95cbbd22010-07-23 14:43:04 -04006945DEFUN (show_bgp_ipv6_safi_route,
6946 show_bgp_ipv6_safi_route_cmd,
6947 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6948 SHOW_STR
6949 BGP_STR
6950 "Address family\n"
6951 "Address Family modifier\n"
6952 "Address Family modifier\n"
6953 "Network in the BGP routing table to display\n")
6954{
6955 if (strncmp (argv[0], "m", 1) == 0)
6956 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6957
6958 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6959}
6960
paul718e3742002-12-13 20:15:29 +00006961/* old command */
6962DEFUN (show_ipv6_bgp_route,
6963 show_ipv6_bgp_route_cmd,
6964 "show ipv6 bgp X:X::X:X",
6965 SHOW_STR
6966 IP_STR
6967 BGP_STR
6968 "Network in the BGP routing table to display\n")
6969{
6970 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6971}
6972
6973DEFUN (show_bgp_prefix,
6974 show_bgp_prefix_cmd,
6975 "show bgp X:X::X:X/M",
6976 SHOW_STR
6977 BGP_STR
6978 "IPv6 prefix <network>/<length>\n")
6979{
6980 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6981}
6982
6983ALIAS (show_bgp_prefix,
6984 show_bgp_ipv6_prefix_cmd,
6985 "show bgp ipv6 X:X::X:X/M",
6986 SHOW_STR
6987 BGP_STR
6988 "Address family\n"
6989 "IPv6 prefix <network>/<length>\n")
6990
Michael Lambert95cbbd22010-07-23 14:43:04 -04006991DEFUN (show_bgp_ipv6_safi_prefix,
6992 show_bgp_ipv6_safi_prefix_cmd,
6993 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6994 SHOW_STR
6995 BGP_STR
6996 "Address family\n"
6997 "Address Family modifier\n"
6998 "Address Family modifier\n"
6999 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7000{
7001 if (strncmp (argv[0], "m", 1) == 0)
7002 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7003
7004 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7005}
7006
paul718e3742002-12-13 20:15:29 +00007007/* old command */
7008DEFUN (show_ipv6_bgp_prefix,
7009 show_ipv6_bgp_prefix_cmd,
7010 "show ipv6 bgp X:X::X:X/M",
7011 SHOW_STR
7012 IP_STR
7013 BGP_STR
7014 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7015{
7016 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7017}
7018
paulbb46e942003-10-24 19:02:03 +00007019DEFUN (show_bgp_view,
7020 show_bgp_view_cmd,
7021 "show bgp view WORD",
7022 SHOW_STR
7023 BGP_STR
7024 "BGP view\n"
7025 "View name\n")
7026{
7027 struct bgp *bgp;
7028
7029 /* BGP structure lookup. */
7030 bgp = bgp_lookup_by_name (argv[0]);
7031 if (bgp == NULL)
7032 {
7033 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7034 return CMD_WARNING;
7035 }
7036
ajs5a646652004-11-05 01:25:55 +00007037 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007038}
7039
7040ALIAS (show_bgp_view,
7041 show_bgp_view_ipv6_cmd,
7042 "show bgp view WORD ipv6",
7043 SHOW_STR
7044 BGP_STR
7045 "BGP view\n"
7046 "View name\n"
7047 "Address family\n")
7048
7049DEFUN (show_bgp_view_route,
7050 show_bgp_view_route_cmd,
7051 "show bgp view WORD X:X::X:X",
7052 SHOW_STR
7053 BGP_STR
7054 "BGP view\n"
7055 "View name\n"
7056 "Network in the BGP routing table to display\n")
7057{
7058 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7059}
7060
7061ALIAS (show_bgp_view_route,
7062 show_bgp_view_ipv6_route_cmd,
7063 "show bgp view WORD ipv6 X:X::X:X",
7064 SHOW_STR
7065 BGP_STR
7066 "BGP view\n"
7067 "View name\n"
7068 "Address family\n"
7069 "Network in the BGP routing table to display\n")
7070
7071DEFUN (show_bgp_view_prefix,
7072 show_bgp_view_prefix_cmd,
7073 "show bgp view WORD X:X::X:X/M",
7074 SHOW_STR
7075 BGP_STR
7076 "BGP view\n"
7077 "View name\n"
7078 "IPv6 prefix <network>/<length>\n")
7079{
7080 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7081}
7082
7083ALIAS (show_bgp_view_prefix,
7084 show_bgp_view_ipv6_prefix_cmd,
7085 "show bgp view WORD ipv6 X:X::X:X/M",
7086 SHOW_STR
7087 BGP_STR
7088 "BGP view\n"
7089 "View name\n"
7090 "Address family\n"
7091 "IPv6 prefix <network>/<length>\n")
7092
paul718e3742002-12-13 20:15:29 +00007093/* old command */
7094DEFUN (show_ipv6_mbgp,
7095 show_ipv6_mbgp_cmd,
7096 "show ipv6 mbgp",
7097 SHOW_STR
7098 IP_STR
7099 MBGP_STR)
7100{
ajs5a646652004-11-05 01:25:55 +00007101 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7102 NULL);
paul718e3742002-12-13 20:15:29 +00007103}
7104
7105/* old command */
7106DEFUN (show_ipv6_mbgp_route,
7107 show_ipv6_mbgp_route_cmd,
7108 "show ipv6 mbgp X:X::X:X",
7109 SHOW_STR
7110 IP_STR
7111 MBGP_STR
7112 "Network in the MBGP routing table to display\n")
7113{
7114 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7115}
7116
7117/* old command */
7118DEFUN (show_ipv6_mbgp_prefix,
7119 show_ipv6_mbgp_prefix_cmd,
7120 "show ipv6 mbgp X:X::X:X/M",
7121 SHOW_STR
7122 IP_STR
7123 MBGP_STR
7124 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7125{
7126 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7127}
7128#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02007129
paul718e3742002-12-13 20:15:29 +00007130
paul94f2b392005-06-28 12:44:16 +00007131static int
paulfd79ac92004-10-13 05:06:08 +00007132bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007133 safi_t safi, enum bgp_show_type type)
7134{
7135 int i;
7136 struct buffer *b;
7137 char *regstr;
7138 int first;
7139 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007140 int rc;
paul718e3742002-12-13 20:15:29 +00007141
7142 first = 0;
7143 b = buffer_new (1024);
7144 for (i = 0; i < argc; i++)
7145 {
7146 if (first)
7147 buffer_putc (b, ' ');
7148 else
7149 {
7150 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7151 continue;
7152 first = 1;
7153 }
7154
7155 buffer_putstr (b, argv[i]);
7156 }
7157 buffer_putc (b, '\0');
7158
7159 regstr = buffer_getstr (b);
7160 buffer_free (b);
7161
7162 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007163 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007164 if (! regex)
7165 {
7166 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7167 VTY_NEWLINE);
7168 return CMD_WARNING;
7169 }
7170
ajs5a646652004-11-05 01:25:55 +00007171 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7172 bgp_regex_free (regex);
7173 return rc;
paul718e3742002-12-13 20:15:29 +00007174}
7175
7176DEFUN (show_ip_bgp_regexp,
7177 show_ip_bgp_regexp_cmd,
7178 "show ip bgp regexp .LINE",
7179 SHOW_STR
7180 IP_STR
7181 BGP_STR
7182 "Display routes matching the AS path regular expression\n"
7183 "A regular-expression to match the BGP AS paths\n")
7184{
7185 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7186 bgp_show_type_regexp);
7187}
7188
7189DEFUN (show_ip_bgp_flap_regexp,
7190 show_ip_bgp_flap_regexp_cmd,
7191 "show ip bgp flap-statistics regexp .LINE",
7192 SHOW_STR
7193 IP_STR
7194 BGP_STR
7195 "Display flap statistics of routes\n"
7196 "Display routes matching the AS path regular expression\n"
7197 "A regular-expression to match the BGP AS paths\n")
7198{
7199 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7200 bgp_show_type_flap_regexp);
7201}
7202
7203DEFUN (show_ip_bgp_ipv4_regexp,
7204 show_ip_bgp_ipv4_regexp_cmd,
7205 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7206 SHOW_STR
7207 IP_STR
7208 BGP_STR
7209 "Address family\n"
7210 "Address Family modifier\n"
7211 "Address Family modifier\n"
7212 "Display routes matching the AS path regular expression\n"
7213 "A regular-expression to match the BGP AS paths\n")
7214{
7215 if (strncmp (argv[0], "m", 1) == 0)
7216 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7217 bgp_show_type_regexp);
7218
7219 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7220 bgp_show_type_regexp);
7221}
7222
7223#ifdef HAVE_IPV6
7224DEFUN (show_bgp_regexp,
7225 show_bgp_regexp_cmd,
7226 "show bgp regexp .LINE",
7227 SHOW_STR
7228 BGP_STR
7229 "Display routes matching the AS path regular expression\n"
7230 "A regular-expression to match the BGP AS paths\n")
7231{
7232 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7233 bgp_show_type_regexp);
7234}
7235
7236ALIAS (show_bgp_regexp,
7237 show_bgp_ipv6_regexp_cmd,
7238 "show bgp ipv6 regexp .LINE",
7239 SHOW_STR
7240 BGP_STR
7241 "Address family\n"
7242 "Display routes matching the AS path regular expression\n"
7243 "A regular-expression to match the BGP AS paths\n")
7244
7245/* old command */
7246DEFUN (show_ipv6_bgp_regexp,
7247 show_ipv6_bgp_regexp_cmd,
7248 "show ipv6 bgp regexp .LINE",
7249 SHOW_STR
7250 IP_STR
7251 BGP_STR
7252 "Display routes matching the AS path regular expression\n"
7253 "A regular-expression to match the BGP AS paths\n")
7254{
7255 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7256 bgp_show_type_regexp);
7257}
7258
7259/* old command */
7260DEFUN (show_ipv6_mbgp_regexp,
7261 show_ipv6_mbgp_regexp_cmd,
7262 "show ipv6 mbgp regexp .LINE",
7263 SHOW_STR
7264 IP_STR
7265 BGP_STR
7266 "Display routes matching the AS path regular expression\n"
7267 "A regular-expression to match the MBGP AS paths\n")
7268{
7269 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7270 bgp_show_type_regexp);
7271}
7272#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007273
paul94f2b392005-06-28 12:44:16 +00007274static int
paulfd79ac92004-10-13 05:06:08 +00007275bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007276 safi_t safi, enum bgp_show_type type)
7277{
7278 struct prefix_list *plist;
7279
7280 plist = prefix_list_lookup (afi, prefix_list_str);
7281 if (plist == NULL)
7282 {
7283 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7284 prefix_list_str, VTY_NEWLINE);
7285 return CMD_WARNING;
7286 }
7287
ajs5a646652004-11-05 01:25:55 +00007288 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007289}
7290
7291DEFUN (show_ip_bgp_prefix_list,
7292 show_ip_bgp_prefix_list_cmd,
7293 "show ip bgp prefix-list WORD",
7294 SHOW_STR
7295 IP_STR
7296 BGP_STR
7297 "Display routes conforming to the prefix-list\n"
7298 "IP prefix-list name\n")
7299{
7300 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7301 bgp_show_type_prefix_list);
7302}
7303
7304DEFUN (show_ip_bgp_flap_prefix_list,
7305 show_ip_bgp_flap_prefix_list_cmd,
7306 "show ip bgp flap-statistics prefix-list WORD",
7307 SHOW_STR
7308 IP_STR
7309 BGP_STR
7310 "Display flap statistics of routes\n"
7311 "Display routes conforming to the prefix-list\n"
7312 "IP prefix-list name\n")
7313{
7314 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7315 bgp_show_type_flap_prefix_list);
7316}
7317
7318DEFUN (show_ip_bgp_ipv4_prefix_list,
7319 show_ip_bgp_ipv4_prefix_list_cmd,
7320 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7321 SHOW_STR
7322 IP_STR
7323 BGP_STR
7324 "Address family\n"
7325 "Address Family modifier\n"
7326 "Address Family modifier\n"
7327 "Display routes conforming to the prefix-list\n"
7328 "IP prefix-list name\n")
7329{
7330 if (strncmp (argv[0], "m", 1) == 0)
7331 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7332 bgp_show_type_prefix_list);
7333
7334 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7335 bgp_show_type_prefix_list);
7336}
7337
7338#ifdef HAVE_IPV6
7339DEFUN (show_bgp_prefix_list,
7340 show_bgp_prefix_list_cmd,
7341 "show bgp prefix-list WORD",
7342 SHOW_STR
7343 BGP_STR
7344 "Display routes conforming to the prefix-list\n"
7345 "IPv6 prefix-list name\n")
7346{
7347 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7348 bgp_show_type_prefix_list);
7349}
7350
7351ALIAS (show_bgp_prefix_list,
7352 show_bgp_ipv6_prefix_list_cmd,
7353 "show bgp ipv6 prefix-list WORD",
7354 SHOW_STR
7355 BGP_STR
7356 "Address family\n"
7357 "Display routes conforming to the prefix-list\n"
7358 "IPv6 prefix-list name\n")
7359
7360/* old command */
7361DEFUN (show_ipv6_bgp_prefix_list,
7362 show_ipv6_bgp_prefix_list_cmd,
7363 "show ipv6 bgp prefix-list WORD",
7364 SHOW_STR
7365 IPV6_STR
7366 BGP_STR
7367 "Display routes matching the prefix-list\n"
7368 "IPv6 prefix-list name\n")
7369{
7370 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7371 bgp_show_type_prefix_list);
7372}
7373
7374/* old command */
7375DEFUN (show_ipv6_mbgp_prefix_list,
7376 show_ipv6_mbgp_prefix_list_cmd,
7377 "show ipv6 mbgp prefix-list WORD",
7378 SHOW_STR
7379 IPV6_STR
7380 MBGP_STR
7381 "Display routes matching the prefix-list\n"
7382 "IPv6 prefix-list name\n")
7383{
7384 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7385 bgp_show_type_prefix_list);
7386}
7387#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007388
paul94f2b392005-06-28 12:44:16 +00007389static int
paulfd79ac92004-10-13 05:06:08 +00007390bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007391 safi_t safi, enum bgp_show_type type)
7392{
7393 struct as_list *as_list;
7394
7395 as_list = as_list_lookup (filter);
7396 if (as_list == NULL)
7397 {
7398 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7399 return CMD_WARNING;
7400 }
7401
ajs5a646652004-11-05 01:25:55 +00007402 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007403}
7404
7405DEFUN (show_ip_bgp_filter_list,
7406 show_ip_bgp_filter_list_cmd,
7407 "show ip bgp filter-list WORD",
7408 SHOW_STR
7409 IP_STR
7410 BGP_STR
7411 "Display routes conforming to the filter-list\n"
7412 "Regular expression access list name\n")
7413{
7414 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7415 bgp_show_type_filter_list);
7416}
7417
7418DEFUN (show_ip_bgp_flap_filter_list,
7419 show_ip_bgp_flap_filter_list_cmd,
7420 "show ip bgp flap-statistics filter-list WORD",
7421 SHOW_STR
7422 IP_STR
7423 BGP_STR
7424 "Display flap statistics of routes\n"
7425 "Display routes conforming to the filter-list\n"
7426 "Regular expression access list name\n")
7427{
7428 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7429 bgp_show_type_flap_filter_list);
7430}
7431
7432DEFUN (show_ip_bgp_ipv4_filter_list,
7433 show_ip_bgp_ipv4_filter_list_cmd,
7434 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7435 SHOW_STR
7436 IP_STR
7437 BGP_STR
7438 "Address family\n"
7439 "Address Family modifier\n"
7440 "Address Family modifier\n"
7441 "Display routes conforming to the filter-list\n"
7442 "Regular expression access list name\n")
7443{
7444 if (strncmp (argv[0], "m", 1) == 0)
7445 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7446 bgp_show_type_filter_list);
7447
7448 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7449 bgp_show_type_filter_list);
7450}
7451
7452#ifdef HAVE_IPV6
7453DEFUN (show_bgp_filter_list,
7454 show_bgp_filter_list_cmd,
7455 "show bgp filter-list WORD",
7456 SHOW_STR
7457 BGP_STR
7458 "Display routes conforming to the filter-list\n"
7459 "Regular expression access list name\n")
7460{
7461 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7462 bgp_show_type_filter_list);
7463}
7464
7465ALIAS (show_bgp_filter_list,
7466 show_bgp_ipv6_filter_list_cmd,
7467 "show bgp ipv6 filter-list WORD",
7468 SHOW_STR
7469 BGP_STR
7470 "Address family\n"
7471 "Display routes conforming to the filter-list\n"
7472 "Regular expression access list name\n")
7473
7474/* old command */
7475DEFUN (show_ipv6_bgp_filter_list,
7476 show_ipv6_bgp_filter_list_cmd,
7477 "show ipv6 bgp filter-list WORD",
7478 SHOW_STR
7479 IPV6_STR
7480 BGP_STR
7481 "Display routes conforming to the filter-list\n"
7482 "Regular expression access list name\n")
7483{
7484 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7485 bgp_show_type_filter_list);
7486}
7487
7488/* old command */
7489DEFUN (show_ipv6_mbgp_filter_list,
7490 show_ipv6_mbgp_filter_list_cmd,
7491 "show ipv6 mbgp filter-list WORD",
7492 SHOW_STR
7493 IPV6_STR
7494 MBGP_STR
7495 "Display routes conforming to the filter-list\n"
7496 "Regular expression access list name\n")
7497{
7498 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7499 bgp_show_type_filter_list);
7500}
7501#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007502
paul94f2b392005-06-28 12:44:16 +00007503static int
paulfd79ac92004-10-13 05:06:08 +00007504bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007505 safi_t safi, enum bgp_show_type type)
7506{
7507 struct route_map *rmap;
7508
7509 rmap = route_map_lookup_by_name (rmap_str);
7510 if (! rmap)
7511 {
7512 vty_out (vty, "%% %s is not a valid route-map name%s",
7513 rmap_str, VTY_NEWLINE);
7514 return CMD_WARNING;
7515 }
7516
ajs5a646652004-11-05 01:25:55 +00007517 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007518}
7519
7520DEFUN (show_ip_bgp_route_map,
7521 show_ip_bgp_route_map_cmd,
7522 "show ip bgp route-map WORD",
7523 SHOW_STR
7524 IP_STR
7525 BGP_STR
7526 "Display routes matching the route-map\n"
7527 "A route-map to match on\n")
7528{
7529 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7530 bgp_show_type_route_map);
7531}
7532
7533DEFUN (show_ip_bgp_flap_route_map,
7534 show_ip_bgp_flap_route_map_cmd,
7535 "show ip bgp flap-statistics route-map WORD",
7536 SHOW_STR
7537 IP_STR
7538 BGP_STR
7539 "Display flap statistics of routes\n"
7540 "Display routes matching the route-map\n"
7541 "A route-map to match on\n")
7542{
7543 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7544 bgp_show_type_flap_route_map);
7545}
7546
7547DEFUN (show_ip_bgp_ipv4_route_map,
7548 show_ip_bgp_ipv4_route_map_cmd,
7549 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7550 SHOW_STR
7551 IP_STR
7552 BGP_STR
7553 "Address family\n"
7554 "Address Family modifier\n"
7555 "Address Family modifier\n"
7556 "Display routes matching the route-map\n"
7557 "A route-map to match on\n")
7558{
7559 if (strncmp (argv[0], "m", 1) == 0)
7560 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7561 bgp_show_type_route_map);
7562
7563 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7564 bgp_show_type_route_map);
7565}
7566
7567DEFUN (show_bgp_route_map,
7568 show_bgp_route_map_cmd,
7569 "show bgp route-map WORD",
7570 SHOW_STR
7571 BGP_STR
7572 "Display routes matching the route-map\n"
7573 "A route-map to match on\n")
7574{
7575 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7576 bgp_show_type_route_map);
7577}
7578
7579ALIAS (show_bgp_route_map,
7580 show_bgp_ipv6_route_map_cmd,
7581 "show bgp ipv6 route-map WORD",
7582 SHOW_STR
7583 BGP_STR
7584 "Address family\n"
7585 "Display routes matching the route-map\n"
7586 "A route-map to match on\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02007587
paul718e3742002-12-13 20:15:29 +00007588DEFUN (show_ip_bgp_cidr_only,
7589 show_ip_bgp_cidr_only_cmd,
7590 "show ip bgp cidr-only",
7591 SHOW_STR
7592 IP_STR
7593 BGP_STR
7594 "Display only routes with non-natural netmasks\n")
7595{
7596 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007597 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007598}
7599
7600DEFUN (show_ip_bgp_flap_cidr_only,
7601 show_ip_bgp_flap_cidr_only_cmd,
7602 "show ip bgp flap-statistics cidr-only",
7603 SHOW_STR
7604 IP_STR
7605 BGP_STR
7606 "Display flap statistics of routes\n"
7607 "Display only routes with non-natural netmasks\n")
7608{
7609 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007610 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007611}
7612
7613DEFUN (show_ip_bgp_ipv4_cidr_only,
7614 show_ip_bgp_ipv4_cidr_only_cmd,
7615 "show ip bgp ipv4 (unicast|multicast) cidr-only",
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 only routes with non-natural netmasks\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_cidr_only, 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_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007630}
David Lamparter6b0655a2014-06-04 06:53:35 +02007631
paul718e3742002-12-13 20:15:29 +00007632DEFUN (show_ip_bgp_community_all,
7633 show_ip_bgp_community_all_cmd,
7634 "show ip bgp community",
7635 SHOW_STR
7636 IP_STR
7637 BGP_STR
7638 "Display routes matching the communities\n")
7639{
7640 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007641 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007642}
7643
7644DEFUN (show_ip_bgp_ipv4_community_all,
7645 show_ip_bgp_ipv4_community_all_cmd,
7646 "show ip bgp ipv4 (unicast|multicast) community",
7647 SHOW_STR
7648 IP_STR
7649 BGP_STR
7650 "Address family\n"
7651 "Address Family modifier\n"
7652 "Address Family modifier\n"
7653 "Display routes matching the communities\n")
7654{
7655 if (strncmp (argv[0], "m", 1) == 0)
7656 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007657 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007658
7659 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007660 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007661}
7662
7663#ifdef HAVE_IPV6
7664DEFUN (show_bgp_community_all,
7665 show_bgp_community_all_cmd,
7666 "show bgp community",
7667 SHOW_STR
7668 BGP_STR
7669 "Display routes matching the communities\n")
7670{
7671 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007672 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007673}
7674
7675ALIAS (show_bgp_community_all,
7676 show_bgp_ipv6_community_all_cmd,
7677 "show bgp ipv6 community",
7678 SHOW_STR
7679 BGP_STR
7680 "Address family\n"
7681 "Display routes matching the communities\n")
7682
7683/* old command */
7684DEFUN (show_ipv6_bgp_community_all,
7685 show_ipv6_bgp_community_all_cmd,
7686 "show ipv6 bgp community",
7687 SHOW_STR
7688 IPV6_STR
7689 BGP_STR
7690 "Display routes matching the communities\n")
7691{
7692 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007693 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007694}
7695
7696/* old command */
7697DEFUN (show_ipv6_mbgp_community_all,
7698 show_ipv6_mbgp_community_all_cmd,
7699 "show ipv6 mbgp community",
7700 SHOW_STR
7701 IPV6_STR
7702 MBGP_STR
7703 "Display routes matching the communities\n")
7704{
7705 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007706 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007707}
7708#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007709
paul94f2b392005-06-28 12:44:16 +00007710static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007711bgp_show_community (struct vty *vty, const char *view_name, int argc,
7712 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007713{
7714 struct community *com;
7715 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007716 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007717 int i;
7718 char *str;
7719 int first = 0;
7720
Michael Lambert95cbbd22010-07-23 14:43:04 -04007721 /* BGP structure lookup */
7722 if (view_name)
7723 {
7724 bgp = bgp_lookup_by_name (view_name);
7725 if (bgp == NULL)
7726 {
7727 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7728 return CMD_WARNING;
7729 }
7730 }
7731 else
7732 {
7733 bgp = bgp_get_default ();
7734 if (bgp == NULL)
7735 {
7736 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7737 return CMD_WARNING;
7738 }
7739 }
7740
paul718e3742002-12-13 20:15:29 +00007741 b = buffer_new (1024);
7742 for (i = 0; i < argc; i++)
7743 {
7744 if (first)
7745 buffer_putc (b, ' ');
7746 else
7747 {
7748 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7749 continue;
7750 first = 1;
7751 }
7752
7753 buffer_putstr (b, argv[i]);
7754 }
7755 buffer_putc (b, '\0');
7756
7757 str = buffer_getstr (b);
7758 buffer_free (b);
7759
7760 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007761 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007762 if (! com)
7763 {
7764 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7765 return CMD_WARNING;
7766 }
7767
Michael Lambert95cbbd22010-07-23 14:43:04 -04007768 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007769 (exact ? bgp_show_type_community_exact :
7770 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007771}
7772
7773DEFUN (show_ip_bgp_community,
7774 show_ip_bgp_community_cmd,
7775 "show ip bgp community (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{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007785 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007786}
7787
7788ALIAS (show_ip_bgp_community,
7789 show_ip_bgp_community2_cmd,
7790 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7791 SHOW_STR
7792 IP_STR
7793 BGP_STR
7794 "Display routes matching the communities\n"
7795 "community number\n"
7796 "Do not send outside local AS (well-known community)\n"
7797 "Do not advertise to any peer (well-known community)\n"
7798 "Do not export to next AS (well-known community)\n"
7799 "community number\n"
7800 "Do not send outside local AS (well-known community)\n"
7801 "Do not advertise to any peer (well-known community)\n"
7802 "Do not export to next AS (well-known community)\n")
7803
7804ALIAS (show_ip_bgp_community,
7805 show_ip_bgp_community3_cmd,
7806 "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)",
7807 SHOW_STR
7808 IP_STR
7809 BGP_STR
7810 "Display routes matching the communities\n"
7811 "community number\n"
7812 "Do not send outside local AS (well-known community)\n"
7813 "Do not advertise to any peer (well-known community)\n"
7814 "Do not export to next AS (well-known community)\n"
7815 "community number\n"
7816 "Do not send outside local AS (well-known community)\n"
7817 "Do not advertise to any peer (well-known community)\n"
7818 "Do not export to next AS (well-known community)\n"
7819 "community number\n"
7820 "Do not send outside local AS (well-known community)\n"
7821 "Do not advertise to any peer (well-known community)\n"
7822 "Do not export to next AS (well-known community)\n")
7823
7824ALIAS (show_ip_bgp_community,
7825 show_ip_bgp_community4_cmd,
7826 "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)",
7827 SHOW_STR
7828 IP_STR
7829 BGP_STR
7830 "Display routes matching the communities\n"
7831 "community number\n"
7832 "Do not send outside local AS (well-known community)\n"
7833 "Do not advertise to any peer (well-known community)\n"
7834 "Do not export to next AS (well-known community)\n"
7835 "community number\n"
7836 "Do not send outside local AS (well-known community)\n"
7837 "Do not advertise to any peer (well-known community)\n"
7838 "Do not export to next AS (well-known community)\n"
7839 "community number\n"
7840 "Do not send outside local AS (well-known community)\n"
7841 "Do not advertise to any peer (well-known community)\n"
7842 "Do not export to next AS (well-known community)\n"
7843 "community number\n"
7844 "Do not send outside local AS (well-known community)\n"
7845 "Do not advertise to any peer (well-known community)\n"
7846 "Do not export to next AS (well-known community)\n")
7847
7848DEFUN (show_ip_bgp_ipv4_community,
7849 show_ip_bgp_ipv4_community_cmd,
7850 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7851 SHOW_STR
7852 IP_STR
7853 BGP_STR
7854 "Address family\n"
7855 "Address Family modifier\n"
7856 "Address Family modifier\n"
7857 "Display routes matching the communities\n"
7858 "community number\n"
7859 "Do not send outside local AS (well-known community)\n"
7860 "Do not advertise to any peer (well-known community)\n"
7861 "Do not export to next AS (well-known community)\n")
7862{
7863 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007864 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007865
Michael Lambert95cbbd22010-07-23 14:43:04 -04007866 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007867}
7868
7869ALIAS (show_ip_bgp_ipv4_community,
7870 show_ip_bgp_ipv4_community2_cmd,
7871 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7872 SHOW_STR
7873 IP_STR
7874 BGP_STR
7875 "Address family\n"
7876 "Address Family modifier\n"
7877 "Address Family modifier\n"
7878 "Display routes matching the communities\n"
7879 "community number\n"
7880 "Do not send outside local AS (well-known community)\n"
7881 "Do not advertise to any peer (well-known community)\n"
7882 "Do not export to next AS (well-known community)\n"
7883 "community number\n"
7884 "Do not send outside local AS (well-known community)\n"
7885 "Do not advertise to any peer (well-known community)\n"
7886 "Do not export to next AS (well-known community)\n")
7887
7888ALIAS (show_ip_bgp_ipv4_community,
7889 show_ip_bgp_ipv4_community3_cmd,
7890 "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)",
7891 SHOW_STR
7892 IP_STR
7893 BGP_STR
7894 "Address family\n"
7895 "Address Family modifier\n"
7896 "Address Family modifier\n"
7897 "Display routes matching the communities\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 "community number\n"
7907 "Do not send outside local AS (well-known community)\n"
7908 "Do not advertise to any peer (well-known community)\n"
7909 "Do not export to next AS (well-known community)\n")
7910
7911ALIAS (show_ip_bgp_ipv4_community,
7912 show_ip_bgp_ipv4_community4_cmd,
7913 "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)",
7914 SHOW_STR
7915 IP_STR
7916 BGP_STR
7917 "Address family\n"
7918 "Address Family modifier\n"
7919 "Address Family modifier\n"
7920 "Display routes matching the communities\n"
7921 "community number\n"
7922 "Do not send outside local AS (well-known community)\n"
7923 "Do not advertise to any peer (well-known community)\n"
7924 "Do not export to next AS (well-known community)\n"
7925 "community number\n"
7926 "Do not send outside local AS (well-known community)\n"
7927 "Do not advertise to any peer (well-known community)\n"
7928 "Do not export to next AS (well-known community)\n"
7929 "community number\n"
7930 "Do not send outside local AS (well-known community)\n"
7931 "Do not advertise to any peer (well-known community)\n"
7932 "Do not export to next AS (well-known community)\n"
7933 "community number\n"
7934 "Do not send outside local AS (well-known community)\n"
7935 "Do not advertise to any peer (well-known community)\n"
7936 "Do not export to next AS (well-known community)\n")
7937
Michael Lambert95cbbd22010-07-23 14:43:04 -04007938DEFUN (show_bgp_view_afi_safi_community_all,
7939 show_bgp_view_afi_safi_community_all_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04007940 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007941 SHOW_STR
7942 BGP_STR
7943 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007944 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007945 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007946 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007947 "Address Family modifier\n"
7948 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00007949 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007950{
7951 int afi;
7952 int safi;
7953 struct bgp *bgp;
7954
7955 /* BGP structure lookup. */
7956 bgp = bgp_lookup_by_name (argv[0]);
7957 if (bgp == NULL)
7958 {
7959 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7960 return CMD_WARNING;
7961 }
7962
Michael Lambert95cbbd22010-07-23 14:43:04 -04007963 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7964 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007965 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7966}
7967
7968DEFUN (show_bgp_view_afi_safi_community,
7969 show_bgp_view_afi_safi_community_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04007970 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007971 SHOW_STR
7972 BGP_STR
7973 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007974 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007975 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007976 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007977 "Address family modifier\n"
7978 "Address family modifier\n"
7979 "Display routes matching the communities\n"
7980 "community number\n"
7981 "Do not send outside local AS (well-known community)\n"
7982 "Do not advertise to any peer (well-known community)\n"
7983 "Do not export to next AS (well-known community)\n")
7984{
7985 int afi;
7986 int safi;
7987
Michael Lambert95cbbd22010-07-23 14:43:04 -04007988 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7989 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7990 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007991}
7992
7993ALIAS (show_bgp_view_afi_safi_community,
7994 show_bgp_view_afi_safi_community2_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04007995 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007996 SHOW_STR
7997 BGP_STR
7998 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007999 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008000 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008001 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008002 "Address family modifier\n"
8003 "Address family modifier\n"
8004 "Display routes matching the communities\n"
8005 "community number\n"
8006 "Do not send outside local AS (well-known community)\n"
8007 "Do not advertise to any peer (well-known community)\n"
8008 "Do not export to next AS (well-known community)\n"
8009 "community number\n"
8010 "Do not send outside local AS (well-known community)\n"
8011 "Do not advertise to any peer (well-known community)\n"
8012 "Do not export to next AS (well-known community)\n")
8013
8014ALIAS (show_bgp_view_afi_safi_community,
8015 show_bgp_view_afi_safi_community3_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008016 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008017 SHOW_STR
8018 BGP_STR
8019 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008020 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008021 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008022 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008023 "Address family modifier\n"
8024 "Address family modifier\n"
8025 "Display routes matching the communities\n"
8026 "community number\n"
8027 "Do not send outside local AS (well-known community)\n"
8028 "Do not advertise to any peer (well-known community)\n"
8029 "Do not export to next AS (well-known community)\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
8039ALIAS (show_bgp_view_afi_safi_community,
8040 show_bgp_view_afi_safi_community4_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008041 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008042 SHOW_STR
8043 BGP_STR
8044 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008045 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008046 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008047 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008048 "Address family modifier\n"
8049 "Address family modifier\n"
8050 "Display routes matching the communities\n"
8051 "community number\n"
8052 "Do not send outside local AS (well-known community)\n"
8053 "Do not advertise to any peer (well-known community)\n"
8054 "Do not export to next AS (well-known community)\n"
8055 "community number\n"
8056 "Do not send outside local AS (well-known community)\n"
8057 "Do not advertise to any peer (well-known community)\n"
8058 "Do not export to next AS (well-known community)\n"
8059 "community number\n"
8060 "Do not send outside local AS (well-known community)\n"
8061 "Do not advertise to any peer (well-known community)\n"
8062 "Do not export to next AS (well-known community)\n"
8063 "community number\n"
8064 "Do not send outside local AS (well-known community)\n"
8065 "Do not advertise to any peer (well-known community)\n"
8066 "Do not export to next AS (well-known community)\n")
8067
paul718e3742002-12-13 20:15:29 +00008068DEFUN (show_ip_bgp_community_exact,
8069 show_ip_bgp_community_exact_cmd,
8070 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8071 SHOW_STR
8072 IP_STR
8073 BGP_STR
8074 "Display routes matching the communities\n"
8075 "community number\n"
8076 "Do not send outside local AS (well-known community)\n"
8077 "Do not advertise to any peer (well-known community)\n"
8078 "Do not export to next AS (well-known community)\n"
8079 "Exact match of the communities")
8080{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008081 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008082}
8083
8084ALIAS (show_ip_bgp_community_exact,
8085 show_ip_bgp_community2_exact_cmd,
8086 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8087 SHOW_STR
8088 IP_STR
8089 BGP_STR
8090 "Display routes matching the communities\n"
8091 "community number\n"
8092 "Do not send outside local AS (well-known community)\n"
8093 "Do not advertise to any peer (well-known community)\n"
8094 "Do not export to next AS (well-known community)\n"
8095 "community number\n"
8096 "Do not send outside local AS (well-known community)\n"
8097 "Do not advertise to any peer (well-known community)\n"
8098 "Do not export to next AS (well-known community)\n"
8099 "Exact match of the communities")
8100
8101ALIAS (show_ip_bgp_community_exact,
8102 show_ip_bgp_community3_exact_cmd,
8103 "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",
8104 SHOW_STR
8105 IP_STR
8106 BGP_STR
8107 "Display routes matching the communities\n"
8108 "community number\n"
8109 "Do not send outside local AS (well-known community)\n"
8110 "Do not advertise to any peer (well-known community)\n"
8111 "Do not export to next AS (well-known community)\n"
8112 "community number\n"
8113 "Do not send outside local AS (well-known community)\n"
8114 "Do not advertise to any peer (well-known community)\n"
8115 "Do not export to next AS (well-known community)\n"
8116 "community number\n"
8117 "Do not send outside local AS (well-known community)\n"
8118 "Do not advertise to any peer (well-known community)\n"
8119 "Do not export to next AS (well-known community)\n"
8120 "Exact match of the communities")
8121
8122ALIAS (show_ip_bgp_community_exact,
8123 show_ip_bgp_community4_exact_cmd,
8124 "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",
8125 SHOW_STR
8126 IP_STR
8127 BGP_STR
8128 "Display routes matching the communities\n"
8129 "community number\n"
8130 "Do not send outside local AS (well-known community)\n"
8131 "Do not advertise to any peer (well-known community)\n"
8132 "Do not export to next AS (well-known community)\n"
8133 "community number\n"
8134 "Do not send outside local AS (well-known community)\n"
8135 "Do not advertise to any peer (well-known community)\n"
8136 "Do not export to next AS (well-known community)\n"
8137 "community number\n"
8138 "Do not send outside local AS (well-known community)\n"
8139 "Do not advertise to any peer (well-known community)\n"
8140 "Do not export to next AS (well-known community)\n"
8141 "community number\n"
8142 "Do not send outside local AS (well-known community)\n"
8143 "Do not advertise to any peer (well-known community)\n"
8144 "Do not export to next AS (well-known community)\n"
8145 "Exact match of the communities")
8146
8147DEFUN (show_ip_bgp_ipv4_community_exact,
8148 show_ip_bgp_ipv4_community_exact_cmd,
8149 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8150 SHOW_STR
8151 IP_STR
8152 BGP_STR
8153 "Address family\n"
8154 "Address Family modifier\n"
8155 "Address Family modifier\n"
8156 "Display routes matching the communities\n"
8157 "community number\n"
8158 "Do not send outside local AS (well-known community)\n"
8159 "Do not advertise to any peer (well-known community)\n"
8160 "Do not export to next AS (well-known community)\n"
8161 "Exact match of the communities")
8162{
8163 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008164 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008165
Michael Lambert95cbbd22010-07-23 14:43:04 -04008166 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008167}
8168
8169ALIAS (show_ip_bgp_ipv4_community_exact,
8170 show_ip_bgp_ipv4_community2_exact_cmd,
8171 "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",
8172 SHOW_STR
8173 IP_STR
8174 BGP_STR
8175 "Address family\n"
8176 "Address Family modifier\n"
8177 "Address Family modifier\n"
8178 "Display routes matching the communities\n"
8179 "community number\n"
8180 "Do not send outside local AS (well-known community)\n"
8181 "Do not advertise to any peer (well-known community)\n"
8182 "Do not export to next AS (well-known community)\n"
8183 "community number\n"
8184 "Do not send outside local AS (well-known community)\n"
8185 "Do not advertise to any peer (well-known community)\n"
8186 "Do not export to next AS (well-known community)\n"
8187 "Exact match of the communities")
8188
8189ALIAS (show_ip_bgp_ipv4_community_exact,
8190 show_ip_bgp_ipv4_community3_exact_cmd,
8191 "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",
8192 SHOW_STR
8193 IP_STR
8194 BGP_STR
8195 "Address family\n"
8196 "Address Family modifier\n"
8197 "Address Family modifier\n"
8198 "Display routes matching the communities\n"
8199 "community number\n"
8200 "Do not send outside local AS (well-known community)\n"
8201 "Do not advertise to any peer (well-known community)\n"
8202 "Do not export to next AS (well-known community)\n"
8203 "community number\n"
8204 "Do not send outside local AS (well-known community)\n"
8205 "Do not advertise to any peer (well-known community)\n"
8206 "Do not export to next AS (well-known community)\n"
8207 "community number\n"
8208 "Do not send outside local AS (well-known community)\n"
8209 "Do not advertise to any peer (well-known community)\n"
8210 "Do not export to next AS (well-known community)\n"
8211 "Exact match of the communities")
8212
8213ALIAS (show_ip_bgp_ipv4_community_exact,
8214 show_ip_bgp_ipv4_community4_exact_cmd,
8215 "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",
8216 SHOW_STR
8217 IP_STR
8218 BGP_STR
8219 "Address family\n"
8220 "Address Family modifier\n"
8221 "Address Family modifier\n"
8222 "Display routes matching the communities\n"
8223 "community number\n"
8224 "Do not send outside local AS (well-known community)\n"
8225 "Do not advertise to any peer (well-known community)\n"
8226 "Do not export to next AS (well-known community)\n"
8227 "community number\n"
8228 "Do not send outside local AS (well-known community)\n"
8229 "Do not advertise to any peer (well-known community)\n"
8230 "Do not export to next AS (well-known community)\n"
8231 "community number\n"
8232 "Do not send outside local AS (well-known community)\n"
8233 "Do not advertise to any peer (well-known community)\n"
8234 "Do not export to next AS (well-known community)\n"
8235 "community number\n"
8236 "Do not send outside local AS (well-known community)\n"
8237 "Do not advertise to any peer (well-known community)\n"
8238 "Do not export to next AS (well-known community)\n"
8239 "Exact match of the communities")
8240
8241#ifdef HAVE_IPV6
8242DEFUN (show_bgp_community,
8243 show_bgp_community_cmd,
8244 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8245 SHOW_STR
8246 BGP_STR
8247 "Display routes matching the communities\n"
8248 "community number\n"
8249 "Do not send outside local AS (well-known community)\n"
8250 "Do not advertise to any peer (well-known community)\n"
8251 "Do not export to next AS (well-known community)\n")
8252{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008253 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008254}
8255
8256ALIAS (show_bgp_community,
8257 show_bgp_ipv6_community_cmd,
8258 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8259 SHOW_STR
8260 BGP_STR
8261 "Address family\n"
8262 "Display routes matching the communities\n"
8263 "community number\n"
8264 "Do not send outside local AS (well-known community)\n"
8265 "Do not advertise to any peer (well-known community)\n"
8266 "Do not export to next AS (well-known community)\n")
8267
8268ALIAS (show_bgp_community,
8269 show_bgp_community2_cmd,
8270 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8271 SHOW_STR
8272 BGP_STR
8273 "Display routes matching the communities\n"
8274 "community number\n"
8275 "Do not send outside local AS (well-known community)\n"
8276 "Do not advertise to any peer (well-known community)\n"
8277 "Do not export to next AS (well-known community)\n"
8278 "community number\n"
8279 "Do not send outside local AS (well-known community)\n"
8280 "Do not advertise to any peer (well-known community)\n"
8281 "Do not export to next AS (well-known community)\n")
8282
8283ALIAS (show_bgp_community,
8284 show_bgp_ipv6_community2_cmd,
8285 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8286 SHOW_STR
8287 BGP_STR
8288 "Address family\n"
8289 "Display routes matching the communities\n"
8290 "community number\n"
8291 "Do not send outside local AS (well-known community)\n"
8292 "Do not advertise to any peer (well-known community)\n"
8293 "Do not export to next AS (well-known community)\n"
8294 "community number\n"
8295 "Do not send outside local AS (well-known community)\n"
8296 "Do not advertise to any peer (well-known community)\n"
8297 "Do not export to next AS (well-known community)\n")
8298
8299ALIAS (show_bgp_community,
8300 show_bgp_community3_cmd,
8301 "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)",
8302 SHOW_STR
8303 BGP_STR
8304 "Display routes matching the communities\n"
8305 "community number\n"
8306 "Do not send outside local AS (well-known community)\n"
8307 "Do not advertise to any peer (well-known community)\n"
8308 "Do not export to next AS (well-known community)\n"
8309 "community number\n"
8310 "Do not send outside local AS (well-known community)\n"
8311 "Do not advertise to any peer (well-known community)\n"
8312 "Do not export to next AS (well-known community)\n"
8313 "community number\n"
8314 "Do not send outside local AS (well-known community)\n"
8315 "Do not advertise to any peer (well-known community)\n"
8316 "Do not export to next AS (well-known community)\n")
8317
8318ALIAS (show_bgp_community,
8319 show_bgp_ipv6_community3_cmd,
8320 "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)",
8321 SHOW_STR
8322 BGP_STR
8323 "Address family\n"
8324 "Display routes matching the communities\n"
8325 "community number\n"
8326 "Do not send outside local AS (well-known community)\n"
8327 "Do not advertise to any peer (well-known community)\n"
8328 "Do not export to next AS (well-known community)\n"
8329 "community number\n"
8330 "Do not send outside local AS (well-known community)\n"
8331 "Do not advertise to any peer (well-known community)\n"
8332 "Do not export to next AS (well-known community)\n"
8333 "community number\n"
8334 "Do not send outside local AS (well-known community)\n"
8335 "Do not advertise to any peer (well-known community)\n"
8336 "Do not export to next AS (well-known community)\n")
8337
8338ALIAS (show_bgp_community,
8339 show_bgp_community4_cmd,
8340 "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)",
8341 SHOW_STR
8342 BGP_STR
8343 "Display routes matching the communities\n"
8344 "community number\n"
8345 "Do not send outside local AS (well-known community)\n"
8346 "Do not advertise to any peer (well-known community)\n"
8347 "Do not export to next AS (well-known community)\n"
8348 "community number\n"
8349 "Do not send outside local AS (well-known community)\n"
8350 "Do not advertise to any peer (well-known community)\n"
8351 "Do not export to next AS (well-known community)\n"
8352 "community number\n"
8353 "Do not send outside local AS (well-known community)\n"
8354 "Do not advertise to any peer (well-known community)\n"
8355 "Do not export to next AS (well-known community)\n"
8356 "community number\n"
8357 "Do not send outside local AS (well-known community)\n"
8358 "Do not advertise to any peer (well-known community)\n"
8359 "Do not export to next AS (well-known community)\n")
8360
8361ALIAS (show_bgp_community,
8362 show_bgp_ipv6_community4_cmd,
8363 "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)",
8364 SHOW_STR
8365 BGP_STR
8366 "Address family\n"
8367 "Display routes matching the communities\n"
8368 "community number\n"
8369 "Do not send outside local AS (well-known community)\n"
8370 "Do not advertise to any peer (well-known community)\n"
8371 "Do not export to next AS (well-known community)\n"
8372 "community number\n"
8373 "Do not send outside local AS (well-known community)\n"
8374 "Do not advertise to any peer (well-known community)\n"
8375 "Do not export to next AS (well-known community)\n"
8376 "community number\n"
8377 "Do not send outside local AS (well-known community)\n"
8378 "Do not advertise to any peer (well-known community)\n"
8379 "Do not export to next AS (well-known community)\n"
8380 "community number\n"
8381 "Do not send outside local AS (well-known community)\n"
8382 "Do not advertise to any peer (well-known community)\n"
8383 "Do not export to next AS (well-known community)\n")
8384
8385/* old command */
8386DEFUN (show_ipv6_bgp_community,
8387 show_ipv6_bgp_community_cmd,
8388 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8389 SHOW_STR
8390 IPV6_STR
8391 BGP_STR
8392 "Display routes matching the communities\n"
8393 "community number\n"
8394 "Do not send outside local AS (well-known community)\n"
8395 "Do not advertise to any peer (well-known community)\n"
8396 "Do not export to next AS (well-known community)\n")
8397{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008398 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008399}
8400
8401/* old command */
8402ALIAS (show_ipv6_bgp_community,
8403 show_ipv6_bgp_community2_cmd,
8404 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8405 SHOW_STR
8406 IPV6_STR
8407 BGP_STR
8408 "Display routes matching the communities\n"
8409 "community number\n"
8410 "Do not send outside local AS (well-known community)\n"
8411 "Do not advertise to any peer (well-known community)\n"
8412 "Do not export to next AS (well-known community)\n"
8413 "community number\n"
8414 "Do not send outside local AS (well-known community)\n"
8415 "Do not advertise to any peer (well-known community)\n"
8416 "Do not export to next AS (well-known community)\n")
8417
8418/* old command */
8419ALIAS (show_ipv6_bgp_community,
8420 show_ipv6_bgp_community3_cmd,
8421 "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)",
8422 SHOW_STR
8423 IPV6_STR
8424 BGP_STR
8425 "Display routes matching the communities\n"
8426 "community number\n"
8427 "Do not send outside local AS (well-known community)\n"
8428 "Do not advertise to any peer (well-known community)\n"
8429 "Do not export to next AS (well-known community)\n"
8430 "community number\n"
8431 "Do not send outside local AS (well-known community)\n"
8432 "Do not advertise to any peer (well-known community)\n"
8433 "Do not export to next AS (well-known community)\n"
8434 "community number\n"
8435 "Do not send outside local AS (well-known community)\n"
8436 "Do not advertise to any peer (well-known community)\n"
8437 "Do not export to next AS (well-known community)\n")
8438
8439/* old command */
8440ALIAS (show_ipv6_bgp_community,
8441 show_ipv6_bgp_community4_cmd,
8442 "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)",
8443 SHOW_STR
8444 IPV6_STR
8445 BGP_STR
8446 "Display routes matching the communities\n"
8447 "community number\n"
8448 "Do not send outside local AS (well-known community)\n"
8449 "Do not advertise to any peer (well-known community)\n"
8450 "Do not export to next AS (well-known community)\n"
8451 "community number\n"
8452 "Do not send outside local AS (well-known community)\n"
8453 "Do not advertise to any peer (well-known community)\n"
8454 "Do not export to next AS (well-known community)\n"
8455 "community number\n"
8456 "Do not send outside local AS (well-known community)\n"
8457 "Do not advertise to any peer (well-known community)\n"
8458 "Do not export to next AS (well-known community)\n"
8459 "community number\n"
8460 "Do not send outside local AS (well-known community)\n"
8461 "Do not advertise to any peer (well-known community)\n"
8462 "Do not export to next AS (well-known community)\n")
8463
8464DEFUN (show_bgp_community_exact,
8465 show_bgp_community_exact_cmd,
8466 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8467 SHOW_STR
8468 BGP_STR
8469 "Display routes matching the communities\n"
8470 "community number\n"
8471 "Do not send outside local AS (well-known community)\n"
8472 "Do not advertise to any peer (well-known community)\n"
8473 "Do not export to next AS (well-known community)\n"
8474 "Exact match of the communities")
8475{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008476 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008477}
8478
8479ALIAS (show_bgp_community_exact,
8480 show_bgp_ipv6_community_exact_cmd,
8481 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8482 SHOW_STR
8483 BGP_STR
8484 "Address family\n"
8485 "Display routes matching the communities\n"
8486 "community number\n"
8487 "Do not send outside local AS (well-known community)\n"
8488 "Do not advertise to any peer (well-known community)\n"
8489 "Do not export to next AS (well-known community)\n"
8490 "Exact match of the communities")
8491
8492ALIAS (show_bgp_community_exact,
8493 show_bgp_community2_exact_cmd,
8494 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8495 SHOW_STR
8496 BGP_STR
8497 "Display routes matching the communities\n"
8498 "community number\n"
8499 "Do not send outside local AS (well-known community)\n"
8500 "Do not advertise to any peer (well-known community)\n"
8501 "Do not export to next AS (well-known community)\n"
8502 "community number\n"
8503 "Do not send outside local AS (well-known community)\n"
8504 "Do not advertise to any peer (well-known community)\n"
8505 "Do not export to next AS (well-known community)\n"
8506 "Exact match of the communities")
8507
8508ALIAS (show_bgp_community_exact,
8509 show_bgp_ipv6_community2_exact_cmd,
8510 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8511 SHOW_STR
8512 BGP_STR
8513 "Address family\n"
8514 "Display routes matching the communities\n"
8515 "community number\n"
8516 "Do not send outside local AS (well-known community)\n"
8517 "Do not advertise to any peer (well-known community)\n"
8518 "Do not export to next AS (well-known community)\n"
8519 "community number\n"
8520 "Do not send outside local AS (well-known community)\n"
8521 "Do not advertise to any peer (well-known community)\n"
8522 "Do not export to next AS (well-known community)\n"
8523 "Exact match of the communities")
8524
8525ALIAS (show_bgp_community_exact,
8526 show_bgp_community3_exact_cmd,
8527 "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",
8528 SHOW_STR
8529 BGP_STR
8530 "Display routes matching the communities\n"
8531 "community number\n"
8532 "Do not send outside local AS (well-known community)\n"
8533 "Do not advertise to any peer (well-known community)\n"
8534 "Do not export to next AS (well-known community)\n"
8535 "community number\n"
8536 "Do not send outside local AS (well-known community)\n"
8537 "Do not advertise to any peer (well-known community)\n"
8538 "Do not export to next AS (well-known community)\n"
8539 "community number\n"
8540 "Do not send outside local AS (well-known community)\n"
8541 "Do not advertise to any peer (well-known community)\n"
8542 "Do not export to next AS (well-known community)\n"
8543 "Exact match of the communities")
8544
8545ALIAS (show_bgp_community_exact,
8546 show_bgp_ipv6_community3_exact_cmd,
8547 "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",
8548 SHOW_STR
8549 BGP_STR
8550 "Address family\n"
8551 "Display routes matching the communities\n"
8552 "community number\n"
8553 "Do not send outside local AS (well-known community)\n"
8554 "Do not advertise to any peer (well-known community)\n"
8555 "Do not export to next AS (well-known community)\n"
8556 "community number\n"
8557 "Do not send outside local AS (well-known community)\n"
8558 "Do not advertise to any peer (well-known community)\n"
8559 "Do not export to next AS (well-known community)\n"
8560 "community number\n"
8561 "Do not send outside local AS (well-known community)\n"
8562 "Do not advertise to any peer (well-known community)\n"
8563 "Do not export to next AS (well-known community)\n"
8564 "Exact match of the communities")
8565
8566ALIAS (show_bgp_community_exact,
8567 show_bgp_community4_exact_cmd,
8568 "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",
8569 SHOW_STR
8570 BGP_STR
8571 "Display routes matching the communities\n"
8572 "community number\n"
8573 "Do not send outside local AS (well-known community)\n"
8574 "Do not advertise to any peer (well-known community)\n"
8575 "Do not export to next AS (well-known community)\n"
8576 "community number\n"
8577 "Do not send outside local AS (well-known community)\n"
8578 "Do not advertise to any peer (well-known community)\n"
8579 "Do not export to next AS (well-known community)\n"
8580 "community number\n"
8581 "Do not send outside local AS (well-known community)\n"
8582 "Do not advertise to any peer (well-known community)\n"
8583 "Do not export to next AS (well-known community)\n"
8584 "community number\n"
8585 "Do not send outside local AS (well-known community)\n"
8586 "Do not advertise to any peer (well-known community)\n"
8587 "Do not export to next AS (well-known community)\n"
8588 "Exact match of the communities")
8589
8590ALIAS (show_bgp_community_exact,
8591 show_bgp_ipv6_community4_exact_cmd,
8592 "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",
8593 SHOW_STR
8594 BGP_STR
8595 "Address family\n"
8596 "Display routes matching the communities\n"
8597 "community number\n"
8598 "Do not send outside local AS (well-known community)\n"
8599 "Do not advertise to any peer (well-known community)\n"
8600 "Do not export to next AS (well-known community)\n"
8601 "community number\n"
8602 "Do not send outside local AS (well-known community)\n"
8603 "Do not advertise to any peer (well-known community)\n"
8604 "Do not export to next AS (well-known community)\n"
8605 "community number\n"
8606 "Do not send outside local AS (well-known community)\n"
8607 "Do not advertise to any peer (well-known community)\n"
8608 "Do not export to next AS (well-known community)\n"
8609 "community number\n"
8610 "Do not send outside local AS (well-known community)\n"
8611 "Do not advertise to any peer (well-known community)\n"
8612 "Do not export to next AS (well-known community)\n"
8613 "Exact match of the communities")
8614
8615/* old command */
8616DEFUN (show_ipv6_bgp_community_exact,
8617 show_ipv6_bgp_community_exact_cmd,
8618 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8619 SHOW_STR
8620 IPV6_STR
8621 BGP_STR
8622 "Display routes matching the communities\n"
8623 "community number\n"
8624 "Do not send outside local AS (well-known community)\n"
8625 "Do not advertise to any peer (well-known community)\n"
8626 "Do not export to next AS (well-known community)\n"
8627 "Exact match of the communities")
8628{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008629 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008630}
8631
8632/* old command */
8633ALIAS (show_ipv6_bgp_community_exact,
8634 show_ipv6_bgp_community2_exact_cmd,
8635 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8636 SHOW_STR
8637 IPV6_STR
8638 BGP_STR
8639 "Display routes matching the communities\n"
8640 "community number\n"
8641 "Do not send outside local AS (well-known community)\n"
8642 "Do not advertise to any peer (well-known community)\n"
8643 "Do not export to next AS (well-known community)\n"
8644 "community number\n"
8645 "Do not send outside local AS (well-known community)\n"
8646 "Do not advertise to any peer (well-known community)\n"
8647 "Do not export to next AS (well-known community)\n"
8648 "Exact match of the communities")
8649
8650/* old command */
8651ALIAS (show_ipv6_bgp_community_exact,
8652 show_ipv6_bgp_community3_exact_cmd,
8653 "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",
8654 SHOW_STR
8655 IPV6_STR
8656 BGP_STR
8657 "Display routes matching the communities\n"
8658 "community number\n"
8659 "Do not send outside local AS (well-known community)\n"
8660 "Do not advertise to any peer (well-known community)\n"
8661 "Do not export to next AS (well-known community)\n"
8662 "community number\n"
8663 "Do not send outside local AS (well-known community)\n"
8664 "Do not advertise to any peer (well-known community)\n"
8665 "Do not export to next AS (well-known community)\n"
8666 "community number\n"
8667 "Do not send outside local AS (well-known community)\n"
8668 "Do not advertise to any peer (well-known community)\n"
8669 "Do not export to next AS (well-known community)\n"
8670 "Exact match of the communities")
8671
8672/* old command */
8673ALIAS (show_ipv6_bgp_community_exact,
8674 show_ipv6_bgp_community4_exact_cmd,
8675 "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",
8676 SHOW_STR
8677 IPV6_STR
8678 BGP_STR
8679 "Display routes matching the communities\n"
8680 "community number\n"
8681 "Do not send outside local AS (well-known community)\n"
8682 "Do not advertise to any peer (well-known community)\n"
8683 "Do not export to next AS (well-known community)\n"
8684 "community number\n"
8685 "Do not send outside local AS (well-known community)\n"
8686 "Do not advertise to any peer (well-known community)\n"
8687 "Do not export to next AS (well-known community)\n"
8688 "community number\n"
8689 "Do not send outside local AS (well-known community)\n"
8690 "Do not advertise to any peer (well-known community)\n"
8691 "Do not export to next AS (well-known community)\n"
8692 "community number\n"
8693 "Do not send outside local AS (well-known community)\n"
8694 "Do not advertise to any peer (well-known community)\n"
8695 "Do not export to next AS (well-known community)\n"
8696 "Exact match of the communities")
8697
8698/* old command */
8699DEFUN (show_ipv6_mbgp_community,
8700 show_ipv6_mbgp_community_cmd,
8701 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8702 SHOW_STR
8703 IPV6_STR
8704 MBGP_STR
8705 "Display routes matching the communities\n"
8706 "community number\n"
8707 "Do not send outside local AS (well-known community)\n"
8708 "Do not advertise to any peer (well-known community)\n"
8709 "Do not export to next AS (well-known community)\n")
8710{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008711 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008712}
8713
8714/* old command */
8715ALIAS (show_ipv6_mbgp_community,
8716 show_ipv6_mbgp_community2_cmd,
8717 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8718 SHOW_STR
8719 IPV6_STR
8720 MBGP_STR
8721 "Display routes matching the communities\n"
8722 "community number\n"
8723 "Do not send outside local AS (well-known community)\n"
8724 "Do not advertise to any peer (well-known community)\n"
8725 "Do not export to next AS (well-known community)\n"
8726 "community number\n"
8727 "Do not send outside local AS (well-known community)\n"
8728 "Do not advertise to any peer (well-known community)\n"
8729 "Do not export to next AS (well-known community)\n")
8730
8731/* old command */
8732ALIAS (show_ipv6_mbgp_community,
8733 show_ipv6_mbgp_community3_cmd,
8734 "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)",
8735 SHOW_STR
8736 IPV6_STR
8737 MBGP_STR
8738 "Display routes matching the communities\n"
8739 "community number\n"
8740 "Do not send outside local AS (well-known community)\n"
8741 "Do not advertise to any peer (well-known community)\n"
8742 "Do not export to next AS (well-known community)\n"
8743 "community number\n"
8744 "Do not send outside local AS (well-known community)\n"
8745 "Do not advertise to any peer (well-known community)\n"
8746 "Do not export to next AS (well-known community)\n"
8747 "community number\n"
8748 "Do not send outside local AS (well-known community)\n"
8749 "Do not advertise to any peer (well-known community)\n"
8750 "Do not export to next AS (well-known community)\n")
8751
8752/* old command */
8753ALIAS (show_ipv6_mbgp_community,
8754 show_ipv6_mbgp_community4_cmd,
8755 "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)",
8756 SHOW_STR
8757 IPV6_STR
8758 MBGP_STR
8759 "Display routes matching the communities\n"
8760 "community number\n"
8761 "Do not send outside local AS (well-known community)\n"
8762 "Do not advertise to any peer (well-known community)\n"
8763 "Do not export to next AS (well-known community)\n"
8764 "community number\n"
8765 "Do not send outside local AS (well-known community)\n"
8766 "Do not advertise to any peer (well-known community)\n"
8767 "Do not export to next AS (well-known community)\n"
8768 "community number\n"
8769 "Do not send outside local AS (well-known community)\n"
8770 "Do not advertise to any peer (well-known community)\n"
8771 "Do not export to next AS (well-known community)\n"
8772 "community number\n"
8773 "Do not send outside local AS (well-known community)\n"
8774 "Do not advertise to any peer (well-known community)\n"
8775 "Do not export to next AS (well-known community)\n")
8776
8777/* old command */
8778DEFUN (show_ipv6_mbgp_community_exact,
8779 show_ipv6_mbgp_community_exact_cmd,
8780 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8781 SHOW_STR
8782 IPV6_STR
8783 MBGP_STR
8784 "Display routes matching the communities\n"
8785 "community number\n"
8786 "Do not send outside local AS (well-known community)\n"
8787 "Do not advertise to any peer (well-known community)\n"
8788 "Do not export to next AS (well-known community)\n"
8789 "Exact match of the communities")
8790{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008791 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008792}
8793
8794/* old command */
8795ALIAS (show_ipv6_mbgp_community_exact,
8796 show_ipv6_mbgp_community2_exact_cmd,
8797 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8798 SHOW_STR
8799 IPV6_STR
8800 MBGP_STR
8801 "Display routes matching the communities\n"
8802 "community number\n"
8803 "Do not send outside local AS (well-known community)\n"
8804 "Do not advertise to any peer (well-known community)\n"
8805 "Do not export to next AS (well-known community)\n"
8806 "community number\n"
8807 "Do not send outside local AS (well-known community)\n"
8808 "Do not advertise to any peer (well-known community)\n"
8809 "Do not export to next AS (well-known community)\n"
8810 "Exact match of the communities")
8811
8812/* old command */
8813ALIAS (show_ipv6_mbgp_community_exact,
8814 show_ipv6_mbgp_community3_exact_cmd,
8815 "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",
8816 SHOW_STR
8817 IPV6_STR
8818 MBGP_STR
8819 "Display routes matching the communities\n"
8820 "community number\n"
8821 "Do not send outside local AS (well-known community)\n"
8822 "Do not advertise to any peer (well-known community)\n"
8823 "Do not export to next AS (well-known community)\n"
8824 "community number\n"
8825 "Do not send outside local AS (well-known community)\n"
8826 "Do not advertise to any peer (well-known community)\n"
8827 "Do not export to next AS (well-known community)\n"
8828 "community number\n"
8829 "Do not send outside local AS (well-known community)\n"
8830 "Do not advertise to any peer (well-known community)\n"
8831 "Do not export to next AS (well-known community)\n"
8832 "Exact match of the communities")
8833
8834/* old command */
8835ALIAS (show_ipv6_mbgp_community_exact,
8836 show_ipv6_mbgp_community4_exact_cmd,
8837 "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",
8838 SHOW_STR
8839 IPV6_STR
8840 MBGP_STR
8841 "Display routes matching the communities\n"
8842 "community number\n"
8843 "Do not send outside local AS (well-known community)\n"
8844 "Do not advertise to any peer (well-known community)\n"
8845 "Do not export to next AS (well-known community)\n"
8846 "community number\n"
8847 "Do not send outside local AS (well-known community)\n"
8848 "Do not advertise to any peer (well-known community)\n"
8849 "Do not export to next AS (well-known community)\n"
8850 "community number\n"
8851 "Do not send outside local AS (well-known community)\n"
8852 "Do not advertise to any peer (well-known community)\n"
8853 "Do not export to next AS (well-known community)\n"
8854 "community number\n"
8855 "Do not send outside local AS (well-known community)\n"
8856 "Do not advertise to any peer (well-known community)\n"
8857 "Do not export to next AS (well-known community)\n"
8858 "Exact match of the communities")
8859#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02008860
paul94f2b392005-06-28 12:44:16 +00008861static int
paulfd79ac92004-10-13 05:06:08 +00008862bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008863 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008864{
8865 struct community_list *list;
8866
hassofee6e4e2005-02-02 16:29:31 +00008867 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008868 if (list == NULL)
8869 {
8870 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8871 VTY_NEWLINE);
8872 return CMD_WARNING;
8873 }
8874
ajs5a646652004-11-05 01:25:55 +00008875 return bgp_show (vty, NULL, afi, safi,
8876 (exact ? bgp_show_type_community_list_exact :
8877 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008878}
8879
8880DEFUN (show_ip_bgp_community_list,
8881 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008882 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008883 SHOW_STR
8884 IP_STR
8885 BGP_STR
8886 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008887 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008888 "community-list name\n")
8889{
8890 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8891}
8892
8893DEFUN (show_ip_bgp_ipv4_community_list,
8894 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008895 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008896 SHOW_STR
8897 IP_STR
8898 BGP_STR
8899 "Address family\n"
8900 "Address Family modifier\n"
8901 "Address Family modifier\n"
8902 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008903 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008904 "community-list name\n")
8905{
8906 if (strncmp (argv[0], "m", 1) == 0)
8907 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8908
8909 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8910}
8911
8912DEFUN (show_ip_bgp_community_list_exact,
8913 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008914 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008915 SHOW_STR
8916 IP_STR
8917 BGP_STR
8918 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008919 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008920 "community-list name\n"
8921 "Exact match of the communities\n")
8922{
8923 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8924}
8925
8926DEFUN (show_ip_bgp_ipv4_community_list_exact,
8927 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008928 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008929 SHOW_STR
8930 IP_STR
8931 BGP_STR
8932 "Address family\n"
8933 "Address Family modifier\n"
8934 "Address Family modifier\n"
8935 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008936 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008937 "community-list name\n"
8938 "Exact match of the communities\n")
8939{
8940 if (strncmp (argv[0], "m", 1) == 0)
8941 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8942
8943 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8944}
8945
8946#ifdef HAVE_IPV6
8947DEFUN (show_bgp_community_list,
8948 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008949 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008950 SHOW_STR
8951 BGP_STR
8952 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008953 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008954 "community-list name\n")
8955{
8956 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8957}
8958
8959ALIAS (show_bgp_community_list,
8960 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008961 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008962 SHOW_STR
8963 BGP_STR
8964 "Address family\n"
8965 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008966 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008967 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008968
8969/* old command */
8970DEFUN (show_ipv6_bgp_community_list,
8971 show_ipv6_bgp_community_list_cmd,
8972 "show ipv6 bgp community-list WORD",
8973 SHOW_STR
8974 IPV6_STR
8975 BGP_STR
8976 "Display routes matching the community-list\n"
8977 "community-list name\n")
8978{
8979 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8980}
8981
8982/* old command */
8983DEFUN (show_ipv6_mbgp_community_list,
8984 show_ipv6_mbgp_community_list_cmd,
8985 "show ipv6 mbgp community-list WORD",
8986 SHOW_STR
8987 IPV6_STR
8988 MBGP_STR
8989 "Display routes matching the community-list\n"
8990 "community-list name\n")
8991{
8992 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8993}
8994
8995DEFUN (show_bgp_community_list_exact,
8996 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008997 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008998 SHOW_STR
8999 BGP_STR
9000 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009001 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009002 "community-list name\n"
9003 "Exact match of the communities\n")
9004{
9005 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9006}
9007
9008ALIAS (show_bgp_community_list_exact,
9009 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009010 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009011 SHOW_STR
9012 BGP_STR
9013 "Address family\n"
9014 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009015 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009016 "community-list name\n"
9017 "Exact match of the communities\n")
9018
9019/* old command */
9020DEFUN (show_ipv6_bgp_community_list_exact,
9021 show_ipv6_bgp_community_list_exact_cmd,
9022 "show ipv6 bgp community-list WORD exact-match",
9023 SHOW_STR
9024 IPV6_STR
9025 BGP_STR
9026 "Display routes matching the community-list\n"
9027 "community-list name\n"
9028 "Exact match of the communities\n")
9029{
9030 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9031}
9032
9033/* old command */
9034DEFUN (show_ipv6_mbgp_community_list_exact,
9035 show_ipv6_mbgp_community_list_exact_cmd,
9036 "show ipv6 mbgp community-list WORD exact-match",
9037 SHOW_STR
9038 IPV6_STR
9039 MBGP_STR
9040 "Display routes matching the community-list\n"
9041 "community-list name\n"
9042 "Exact match of the communities\n")
9043{
9044 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9045}
9046#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009047
paul94f2b392005-06-28 12:44:16 +00009048static int
paulfd79ac92004-10-13 05:06:08 +00009049bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009050 safi_t safi, enum bgp_show_type type)
9051{
9052 int ret;
9053 struct prefix *p;
9054
9055 p = prefix_new();
9056
9057 ret = str2prefix (prefix, p);
9058 if (! ret)
9059 {
9060 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9061 return CMD_WARNING;
9062 }
9063
ajs5a646652004-11-05 01:25:55 +00009064 ret = bgp_show (vty, NULL, afi, safi, type, p);
9065 prefix_free(p);
9066 return ret;
paul718e3742002-12-13 20:15:29 +00009067}
9068
9069DEFUN (show_ip_bgp_prefix_longer,
9070 show_ip_bgp_prefix_longer_cmd,
9071 "show ip bgp A.B.C.D/M longer-prefixes",
9072 SHOW_STR
9073 IP_STR
9074 BGP_STR
9075 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9076 "Display route and more specific routes\n")
9077{
9078 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9079 bgp_show_type_prefix_longer);
9080}
9081
9082DEFUN (show_ip_bgp_flap_prefix_longer,
9083 show_ip_bgp_flap_prefix_longer_cmd,
9084 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9085 SHOW_STR
9086 IP_STR
9087 BGP_STR
9088 "Display flap statistics of routes\n"
9089 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9090 "Display route and more specific routes\n")
9091{
9092 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9093 bgp_show_type_flap_prefix_longer);
9094}
9095
9096DEFUN (show_ip_bgp_ipv4_prefix_longer,
9097 show_ip_bgp_ipv4_prefix_longer_cmd,
9098 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9099 SHOW_STR
9100 IP_STR
9101 BGP_STR
9102 "Address family\n"
9103 "Address Family modifier\n"
9104 "Address Family modifier\n"
9105 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9106 "Display route and more specific routes\n")
9107{
9108 if (strncmp (argv[0], "m", 1) == 0)
9109 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9110 bgp_show_type_prefix_longer);
9111
9112 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9113 bgp_show_type_prefix_longer);
9114}
9115
9116DEFUN (show_ip_bgp_flap_address,
9117 show_ip_bgp_flap_address_cmd,
9118 "show ip bgp flap-statistics A.B.C.D",
9119 SHOW_STR
9120 IP_STR
9121 BGP_STR
9122 "Display flap statistics of routes\n"
9123 "Network in the BGP routing table to display\n")
9124{
9125 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9126 bgp_show_type_flap_address);
9127}
9128
9129DEFUN (show_ip_bgp_flap_prefix,
9130 show_ip_bgp_flap_prefix_cmd,
9131 "show ip bgp flap-statistics A.B.C.D/M",
9132 SHOW_STR
9133 IP_STR
9134 BGP_STR
9135 "Display flap statistics of routes\n"
9136 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9137{
9138 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9139 bgp_show_type_flap_prefix);
9140}
9141#ifdef HAVE_IPV6
9142DEFUN (show_bgp_prefix_longer,
9143 show_bgp_prefix_longer_cmd,
9144 "show bgp X:X::X:X/M longer-prefixes",
9145 SHOW_STR
9146 BGP_STR
9147 "IPv6 prefix <network>/<length>\n"
9148 "Display route and more specific routes\n")
9149{
9150 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9151 bgp_show_type_prefix_longer);
9152}
9153
9154ALIAS (show_bgp_prefix_longer,
9155 show_bgp_ipv6_prefix_longer_cmd,
9156 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9157 SHOW_STR
9158 BGP_STR
9159 "Address family\n"
9160 "IPv6 prefix <network>/<length>\n"
9161 "Display route and more specific routes\n")
9162
9163/* old command */
9164DEFUN (show_ipv6_bgp_prefix_longer,
9165 show_ipv6_bgp_prefix_longer_cmd,
9166 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9167 SHOW_STR
9168 IPV6_STR
9169 BGP_STR
9170 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9171 "Display route and more specific routes\n")
9172{
9173 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9174 bgp_show_type_prefix_longer);
9175}
9176
9177/* old command */
9178DEFUN (show_ipv6_mbgp_prefix_longer,
9179 show_ipv6_mbgp_prefix_longer_cmd,
9180 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9181 SHOW_STR
9182 IPV6_STR
9183 MBGP_STR
9184 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9185 "Display route and more specific routes\n")
9186{
9187 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9188 bgp_show_type_prefix_longer);
9189}
9190#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009191
paul94f2b392005-06-28 12:44:16 +00009192static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009193peer_lookup_in_view (struct vty *vty, const char *view_name,
9194 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009195{
9196 int ret;
9197 struct bgp *bgp;
9198 struct peer *peer;
9199 union sockunion su;
9200
9201 /* BGP structure lookup. */
9202 if (view_name)
9203 {
9204 bgp = bgp_lookup_by_name (view_name);
9205 if (! bgp)
9206 {
9207 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9208 return NULL;
9209 }
9210 }
paul5228ad22004-06-04 17:58:18 +00009211 else
paulbb46e942003-10-24 19:02:03 +00009212 {
9213 bgp = bgp_get_default ();
9214 if (! bgp)
9215 {
9216 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9217 return NULL;
9218 }
9219 }
9220
9221 /* Get peer sockunion. */
9222 ret = str2sockunion (ip_str, &su);
9223 if (ret < 0)
9224 {
9225 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9226 return NULL;
9227 }
9228
9229 /* Peer structure lookup. */
9230 peer = peer_lookup (bgp, &su);
9231 if (! peer)
9232 {
9233 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9234 return NULL;
9235 }
9236
9237 return peer;
9238}
David Lamparter6b0655a2014-06-04 06:53:35 +02009239
Paul Jakma2815e612006-09-14 02:56:07 +00009240enum bgp_stats
9241{
9242 BGP_STATS_MAXBITLEN = 0,
9243 BGP_STATS_RIB,
9244 BGP_STATS_PREFIXES,
9245 BGP_STATS_TOTPLEN,
9246 BGP_STATS_UNAGGREGATEABLE,
9247 BGP_STATS_MAX_AGGREGATEABLE,
9248 BGP_STATS_AGGREGATES,
9249 BGP_STATS_SPACE,
9250 BGP_STATS_ASPATH_COUNT,
9251 BGP_STATS_ASPATH_MAXHOPS,
9252 BGP_STATS_ASPATH_TOTHOPS,
9253 BGP_STATS_ASPATH_MAXSIZE,
9254 BGP_STATS_ASPATH_TOTSIZE,
9255 BGP_STATS_ASN_HIGHEST,
9256 BGP_STATS_MAX,
9257};
paulbb46e942003-10-24 19:02:03 +00009258
Paul Jakma2815e612006-09-14 02:56:07 +00009259static const char *table_stats_strs[] =
9260{
9261 [BGP_STATS_PREFIXES] = "Total Prefixes",
9262 [BGP_STATS_TOTPLEN] = "Average prefix length",
9263 [BGP_STATS_RIB] = "Total Advertisements",
9264 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9265 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9266 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9267 [BGP_STATS_SPACE] = "Address space advertised",
9268 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9269 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9270 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9271 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9272 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9273 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9274 [BGP_STATS_MAX] = NULL,
9275};
9276
9277struct bgp_table_stats
9278{
9279 struct bgp_table *table;
9280 unsigned long long counts[BGP_STATS_MAX];
9281};
9282
9283#if 0
9284#define TALLY_SIGFIG 100000
9285static unsigned long
9286ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9287{
9288 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9289 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9290 unsigned long ret = newtot / count;
9291
9292 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9293 return ret + 1;
9294 else
9295 return ret;
9296}
9297#endif
9298
9299static int
9300bgp_table_stats_walker (struct thread *t)
9301{
9302 struct bgp_node *rn;
9303 struct bgp_node *top;
9304 struct bgp_table_stats *ts = THREAD_ARG (t);
9305 unsigned int space = 0;
9306
Paul Jakma53d9f672006-10-15 23:41:16 +00009307 if (!(top = bgp_table_top (ts->table)))
9308 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009309
9310 switch (top->p.family)
9311 {
9312 case AF_INET:
9313 space = IPV4_MAX_BITLEN;
9314 break;
9315 case AF_INET6:
9316 space = IPV6_MAX_BITLEN;
9317 break;
9318 }
9319
9320 ts->counts[BGP_STATS_MAXBITLEN] = space;
9321
9322 for (rn = top; rn; rn = bgp_route_next (rn))
9323 {
9324 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009325 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009326 unsigned int rinum = 0;
9327
9328 if (rn == top)
9329 continue;
9330
9331 if (!rn->info)
9332 continue;
9333
9334 ts->counts[BGP_STATS_PREFIXES]++;
9335 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9336
9337#if 0
9338 ts->counts[BGP_STATS_AVGPLEN]
9339 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9340 ts->counts[BGP_STATS_AVGPLEN],
9341 rn->p.prefixlen);
9342#endif
9343
9344 /* check if the prefix is included by any other announcements */
9345 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009346 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009347
9348 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009349 {
9350 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9351 /* announced address space */
9352 if (space)
9353 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9354 }
Paul Jakma2815e612006-09-14 02:56:07 +00009355 else if (prn->info)
9356 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9357
Paul Jakma2815e612006-09-14 02:56:07 +00009358 for (ri = rn->info; ri; ri = ri->next)
9359 {
9360 rinum++;
9361 ts->counts[BGP_STATS_RIB]++;
9362
9363 if (ri->attr &&
9364 (CHECK_FLAG (ri->attr->flag,
9365 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9366 ts->counts[BGP_STATS_AGGREGATES]++;
9367
9368 /* as-path stats */
9369 if (ri->attr && ri->attr->aspath)
9370 {
9371 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9372 unsigned int size = aspath_size (ri->attr->aspath);
9373 as_t highest = aspath_highest (ri->attr->aspath);
9374
9375 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9376
9377 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9378 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9379
9380 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9381 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9382
9383 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9384 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9385#if 0
9386 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9387 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9388 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9389 hops);
9390 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9391 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9392 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9393 size);
9394#endif
9395 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9396 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9397 }
9398 }
9399 }
9400 return 0;
9401}
9402
9403static int
9404bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9405{
9406 struct bgp_table_stats ts;
9407 unsigned int i;
9408
9409 if (!bgp->rib[afi][safi])
9410 {
9411 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9412 return CMD_WARNING;
9413 }
9414
9415 memset (&ts, 0, sizeof (ts));
9416 ts.table = bgp->rib[afi][safi];
9417 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9418
9419 vty_out (vty, "BGP %s RIB statistics%s%s",
9420 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9421
9422 for (i = 0; i < BGP_STATS_MAX; i++)
9423 {
9424 if (!table_stats_strs[i])
9425 continue;
9426
9427 switch (i)
9428 {
9429#if 0
9430 case BGP_STATS_ASPATH_AVGHOPS:
9431 case BGP_STATS_ASPATH_AVGSIZE:
9432 case BGP_STATS_AVGPLEN:
9433 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9434 vty_out (vty, "%12.2f",
9435 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9436 break;
9437#endif
9438 case BGP_STATS_ASPATH_TOTHOPS:
9439 case BGP_STATS_ASPATH_TOTSIZE:
9440 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9441 vty_out (vty, "%12.2f",
9442 ts.counts[i] ?
9443 (float)ts.counts[i] /
9444 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9445 : 0);
9446 break;
9447 case BGP_STATS_TOTPLEN:
9448 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9449 vty_out (vty, "%12.2f",
9450 ts.counts[i] ?
9451 (float)ts.counts[i] /
9452 (float)ts.counts[BGP_STATS_PREFIXES]
9453 : 0);
9454 break;
9455 case BGP_STATS_SPACE:
9456 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9457 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9458 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9459 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009460 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009461 vty_out (vty, "%12.2f%s",
9462 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009463 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009464 VTY_NEWLINE);
9465 vty_out (vty, "%30s: ", "/8 equivalent ");
9466 vty_out (vty, "%12.2f%s",
9467 (float)ts.counts[BGP_STATS_SPACE] /
9468 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9469 VTY_NEWLINE);
9470 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9471 break;
9472 vty_out (vty, "%30s: ", "/24 equivalent ");
9473 vty_out (vty, "%12.2f",
9474 (float)ts.counts[BGP_STATS_SPACE] /
9475 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9476 break;
9477 default:
9478 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9479 vty_out (vty, "%12llu", ts.counts[i]);
9480 }
9481
9482 vty_out (vty, "%s", VTY_NEWLINE);
9483 }
9484 return CMD_SUCCESS;
9485}
9486
9487static int
9488bgp_table_stats_vty (struct vty *vty, const char *name,
9489 const char *afi_str, const char *safi_str)
9490{
9491 struct bgp *bgp;
9492 afi_t afi;
9493 safi_t safi;
9494
9495 if (name)
9496 bgp = bgp_lookup_by_name (name);
9497 else
9498 bgp = bgp_get_default ();
9499
9500 if (!bgp)
9501 {
9502 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9503 return CMD_WARNING;
9504 }
9505 if (strncmp (afi_str, "ipv", 3) == 0)
9506 {
9507 if (strncmp (afi_str, "ipv4", 4) == 0)
9508 afi = AFI_IP;
9509 else if (strncmp (afi_str, "ipv6", 4) == 0)
9510 afi = AFI_IP6;
9511 else
9512 {
9513 vty_out (vty, "%% Invalid address family %s%s",
9514 afi_str, VTY_NEWLINE);
9515 return CMD_WARNING;
9516 }
9517 if (strncmp (safi_str, "m", 1) == 0)
9518 safi = SAFI_MULTICAST;
9519 else if (strncmp (safi_str, "u", 1) == 0)
9520 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009521 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9522 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009523 else
9524 {
9525 vty_out (vty, "%% Invalid subsequent address family %s%s",
9526 safi_str, VTY_NEWLINE);
9527 return CMD_WARNING;
9528 }
9529 }
9530 else
9531 {
9532 vty_out (vty, "%% Invalid address family %s%s",
9533 afi_str, VTY_NEWLINE);
9534 return CMD_WARNING;
9535 }
9536
Paul Jakma2815e612006-09-14 02:56:07 +00009537 return bgp_table_stats (vty, bgp, afi, safi);
9538}
9539
9540DEFUN (show_bgp_statistics,
9541 show_bgp_statistics_cmd,
9542 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9543 SHOW_STR
9544 BGP_STR
9545 "Address family\n"
9546 "Address family\n"
9547 "Address Family modifier\n"
9548 "Address Family modifier\n"
9549 "BGP RIB advertisement statistics\n")
9550{
9551 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9552}
9553
9554ALIAS (show_bgp_statistics,
9555 show_bgp_statistics_vpnv4_cmd,
9556 "show bgp (ipv4) (vpnv4) statistics",
9557 SHOW_STR
9558 BGP_STR
9559 "Address family\n"
9560 "Address Family modifier\n"
9561 "BGP RIB advertisement statistics\n")
9562
9563DEFUN (show_bgp_statistics_view,
9564 show_bgp_statistics_view_cmd,
9565 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9566 SHOW_STR
9567 BGP_STR
9568 "BGP view\n"
9569 "Address family\n"
9570 "Address family\n"
9571 "Address Family modifier\n"
9572 "Address Family modifier\n"
9573 "BGP RIB advertisement statistics\n")
9574{
9575 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9576}
9577
9578ALIAS (show_bgp_statistics_view,
9579 show_bgp_statistics_view_vpnv4_cmd,
9580 "show bgp view WORD (ipv4) (vpnv4) statistics",
9581 SHOW_STR
9582 BGP_STR
9583 "BGP view\n"
9584 "Address family\n"
9585 "Address Family modifier\n"
9586 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02009587
Paul Jakmaff7924f2006-09-04 01:10:36 +00009588enum bgp_pcounts
9589{
9590 PCOUNT_ADJ_IN = 0,
9591 PCOUNT_DAMPED,
9592 PCOUNT_REMOVED,
9593 PCOUNT_HISTORY,
9594 PCOUNT_STALE,
9595 PCOUNT_VALID,
9596 PCOUNT_ALL,
9597 PCOUNT_COUNTED,
9598 PCOUNT_PFCNT, /* the figure we display to users */
9599 PCOUNT_MAX,
9600};
9601
9602static const char *pcount_strs[] =
9603{
9604 [PCOUNT_ADJ_IN] = "Adj-in",
9605 [PCOUNT_DAMPED] = "Damped",
9606 [PCOUNT_REMOVED] = "Removed",
9607 [PCOUNT_HISTORY] = "History",
9608 [PCOUNT_STALE] = "Stale",
9609 [PCOUNT_VALID] = "Valid",
9610 [PCOUNT_ALL] = "All RIB",
9611 [PCOUNT_COUNTED] = "PfxCt counted",
9612 [PCOUNT_PFCNT] = "Useable",
9613 [PCOUNT_MAX] = NULL,
9614};
9615
Paul Jakma2815e612006-09-14 02:56:07 +00009616struct peer_pcounts
9617{
9618 unsigned int count[PCOUNT_MAX];
9619 const struct peer *peer;
9620 const struct bgp_table *table;
9621};
9622
Paul Jakmaff7924f2006-09-04 01:10:36 +00009623static int
Paul Jakma2815e612006-09-14 02:56:07 +00009624bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009625{
9626 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009627 struct peer_pcounts *pc = THREAD_ARG (t);
9628 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009629
Paul Jakma2815e612006-09-14 02:56:07 +00009630 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009631 {
9632 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009633 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009634
9635 for (ain = rn->adj_in; ain; ain = ain->next)
9636 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009637 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009638
Paul Jakmaff7924f2006-09-04 01:10:36 +00009639 for (ri = rn->info; ri; ri = ri->next)
9640 {
9641 char buf[SU_ADDRSTRLEN];
9642
9643 if (ri->peer != peer)
9644 continue;
9645
Paul Jakma2815e612006-09-14 02:56:07 +00009646 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009647
9648 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009649 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009650 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009651 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009652 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009653 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009654 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009655 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009656 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009657 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009658 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009659 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009660
9661 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9662 {
Paul Jakma2815e612006-09-14 02:56:07 +00009663 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009664 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009665 plog_warn (peer->log,
9666 "%s [pcount] %s/%d is counted but flags 0x%x",
9667 peer->host,
9668 inet_ntop(rn->p.family, &rn->p.u.prefix,
9669 buf, SU_ADDRSTRLEN),
9670 rn->p.prefixlen,
9671 ri->flags);
9672 }
9673 else
9674 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009675 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009676 plog_warn (peer->log,
9677 "%s [pcount] %s/%d not counted but flags 0x%x",
9678 peer->host,
9679 inet_ntop(rn->p.family, &rn->p.u.prefix,
9680 buf, SU_ADDRSTRLEN),
9681 rn->p.prefixlen,
9682 ri->flags);
9683 }
9684 }
9685 }
Paul Jakma2815e612006-09-14 02:56:07 +00009686 return 0;
9687}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009688
Paul Jakma2815e612006-09-14 02:56:07 +00009689static int
9690bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9691{
9692 struct peer_pcounts pcounts = { .peer = peer };
9693 unsigned int i;
9694
9695 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9696 || !peer->bgp->rib[afi][safi])
9697 {
9698 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9699 return CMD_WARNING;
9700 }
9701
9702 memset (&pcounts, 0, sizeof(pcounts));
9703 pcounts.peer = peer;
9704 pcounts.table = peer->bgp->rib[afi][safi];
9705
9706 /* in-place call via thread subsystem so as to record execution time
9707 * stats for the thread-walk (i.e. ensure this can't be blamed on
9708 * on just vty_read()).
9709 */
9710 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9711
Paul Jakmaff7924f2006-09-04 01:10:36 +00009712 vty_out (vty, "Prefix counts for %s, %s%s",
9713 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9714 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9715 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9716 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9717
9718 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009719 vty_out (vty, "%20s: %-10d%s",
9720 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009721
Paul Jakma2815e612006-09-14 02:56:07 +00009722 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009723 {
9724 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9725 peer->host, VTY_NEWLINE);
9726 vty_out (vty, "Please report this bug, with the above command output%s",
9727 VTY_NEWLINE);
9728 }
9729
9730 return CMD_SUCCESS;
9731}
9732
9733DEFUN (show_ip_bgp_neighbor_prefix_counts,
9734 show_ip_bgp_neighbor_prefix_counts_cmd,
9735 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9736 SHOW_STR
9737 IP_STR
9738 BGP_STR
9739 "Detailed information on TCP and BGP neighbor connections\n"
9740 "Neighbor to display information about\n"
9741 "Neighbor to display information about\n"
9742 "Display detailed prefix count information\n")
9743{
9744 struct peer *peer;
9745
9746 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9747 if (! peer)
9748 return CMD_WARNING;
9749
9750 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9751}
9752
9753DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9754 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9755 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9756 SHOW_STR
9757 BGP_STR
9758 "Address family\n"
9759 "Detailed information on TCP and BGP neighbor connections\n"
9760 "Neighbor to display information about\n"
9761 "Neighbor to display information about\n"
9762 "Display detailed prefix count information\n")
9763{
9764 struct peer *peer;
9765
9766 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9767 if (! peer)
9768 return CMD_WARNING;
9769
9770 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9771}
9772
9773DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9774 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9775 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9776 SHOW_STR
9777 IP_STR
9778 BGP_STR
9779 "Address family\n"
9780 "Address Family modifier\n"
9781 "Address Family modifier\n"
9782 "Detailed information on TCP and BGP neighbor connections\n"
9783 "Neighbor to display information about\n"
9784 "Neighbor to display information about\n"
9785 "Display detailed prefix count information\n")
9786{
9787 struct peer *peer;
9788
9789 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9790 if (! peer)
9791 return CMD_WARNING;
9792
9793 if (strncmp (argv[0], "m", 1) == 0)
9794 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9795
9796 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9797}
9798
9799DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9800 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9801 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9802 SHOW_STR
9803 IP_STR
9804 BGP_STR
9805 "Address family\n"
9806 "Address Family modifier\n"
9807 "Address Family modifier\n"
9808 "Detailed information on TCP and BGP neighbor connections\n"
9809 "Neighbor to display information about\n"
9810 "Neighbor to display information about\n"
9811 "Display detailed prefix count information\n")
9812{
9813 struct peer *peer;
9814
9815 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9816 if (! peer)
9817 return CMD_WARNING;
9818
9819 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9820}
9821
9822
paul94f2b392005-06-28 12:44:16 +00009823static void
paul718e3742002-12-13 20:15:29 +00009824show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9825 int in)
9826{
9827 struct bgp_table *table;
9828 struct bgp_adj_in *ain;
9829 struct bgp_adj_out *adj;
9830 unsigned long output_count;
9831 struct bgp_node *rn;
9832 int header1 = 1;
9833 struct bgp *bgp;
9834 int header2 = 1;
9835
paulbb46e942003-10-24 19:02:03 +00009836 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009837
9838 if (! bgp)
9839 return;
9840
9841 table = bgp->rib[afi][safi];
9842
9843 output_count = 0;
9844
9845 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9846 PEER_STATUS_DEFAULT_ORIGINATE))
9847 {
9848 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 +00009849 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9850 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009851
9852 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9853 VTY_NEWLINE, VTY_NEWLINE);
9854 header1 = 0;
9855 }
9856
9857 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9858 if (in)
9859 {
9860 for (ain = rn->adj_in; ain; ain = ain->next)
9861 if (ain->peer == peer)
9862 {
9863 if (header1)
9864 {
9865 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 +00009866 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9867 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009868 header1 = 0;
9869 }
9870 if (header2)
9871 {
9872 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9873 header2 = 0;
9874 }
9875 if (ain->attr)
9876 {
9877 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9878 output_count++;
9879 }
9880 }
9881 }
9882 else
9883 {
9884 for (adj = rn->adj_out; adj; adj = adj->next)
9885 if (adj->peer == peer)
9886 {
9887 if (header1)
9888 {
9889 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 +00009890 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9891 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009892 header1 = 0;
9893 }
9894 if (header2)
9895 {
9896 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9897 header2 = 0;
9898 }
9899 if (adj->attr)
9900 {
9901 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9902 output_count++;
9903 }
9904 }
9905 }
9906
9907 if (output_count != 0)
9908 vty_out (vty, "%sTotal number of prefixes %ld%s",
9909 VTY_NEWLINE, output_count, VTY_NEWLINE);
9910}
9911
paul94f2b392005-06-28 12:44:16 +00009912static int
paulbb46e942003-10-24 19:02:03 +00009913peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9914{
paul718e3742002-12-13 20:15:29 +00009915 if (! peer || ! peer->afc[afi][safi])
9916 {
9917 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9918 return CMD_WARNING;
9919 }
9920
9921 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9922 {
9923 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9924 VTY_NEWLINE);
9925 return CMD_WARNING;
9926 }
9927
9928 show_adj_route (vty, peer, afi, safi, in);
9929
9930 return CMD_SUCCESS;
9931}
9932
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009933DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9934 show_ip_bgp_view_neighbor_advertised_route_cmd,
9935 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9936 SHOW_STR
9937 IP_STR
9938 BGP_STR
9939 "BGP view\n"
9940 "View name\n"
9941 "Detailed information on TCP and BGP neighbor connections\n"
9942 "Neighbor to display information about\n"
9943 "Neighbor to display information about\n"
9944 "Display the routes advertised to a BGP neighbor\n")
9945{
9946 struct peer *peer;
9947
9948 if (argc == 2)
9949 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9950 else
9951 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9952
9953 if (! peer)
9954 return CMD_WARNING;
9955
9956 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9957}
9958
9959ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009960 show_ip_bgp_neighbor_advertised_route_cmd,
9961 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9962 SHOW_STR
9963 IP_STR
9964 BGP_STR
9965 "Detailed information on TCP and BGP neighbor connections\n"
9966 "Neighbor to display information about\n"
9967 "Neighbor to display information about\n"
9968 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009969
9970DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9971 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9972 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9973 SHOW_STR
9974 IP_STR
9975 BGP_STR
9976 "Address family\n"
9977 "Address Family modifier\n"
9978 "Address Family modifier\n"
9979 "Detailed information on TCP and BGP neighbor connections\n"
9980 "Neighbor to display information about\n"
9981 "Neighbor to display information about\n"
9982 "Display the routes advertised to a BGP neighbor\n")
9983{
paulbb46e942003-10-24 19:02:03 +00009984 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009985
paulbb46e942003-10-24 19:02:03 +00009986 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9987 if (! peer)
9988 return CMD_WARNING;
9989
9990 if (strncmp (argv[0], "m", 1) == 0)
9991 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9992
9993 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009994}
9995
9996#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009997DEFUN (show_bgp_view_neighbor_advertised_route,
9998 show_bgp_view_neighbor_advertised_route_cmd,
9999 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10000 SHOW_STR
10001 BGP_STR
10002 "BGP view\n"
10003 "View name\n"
10004 "Detailed information on TCP and BGP neighbor connections\n"
10005 "Neighbor to display information about\n"
10006 "Neighbor to display information about\n"
10007 "Display the routes advertised to a BGP neighbor\n")
10008{
10009 struct peer *peer;
10010
10011 if (argc == 2)
10012 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10013 else
10014 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10015
10016 if (! peer)
10017 return CMD_WARNING;
10018
10019 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10020}
10021
10022ALIAS (show_bgp_view_neighbor_advertised_route,
10023 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10024 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10025 SHOW_STR
10026 BGP_STR
10027 "BGP view\n"
10028 "View name\n"
10029 "Address family\n"
10030 "Detailed information on TCP and BGP neighbor connections\n"
10031 "Neighbor to display information about\n"
10032 "Neighbor to display information about\n"
10033 "Display the routes advertised to a BGP neighbor\n")
10034
10035DEFUN (show_bgp_view_neighbor_received_routes,
10036 show_bgp_view_neighbor_received_routes_cmd,
10037 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10038 SHOW_STR
10039 BGP_STR
10040 "BGP view\n"
10041 "View name\n"
10042 "Detailed information on TCP and BGP neighbor connections\n"
10043 "Neighbor to display information about\n"
10044 "Neighbor to display information about\n"
10045 "Display the received routes from neighbor\n")
10046{
10047 struct peer *peer;
10048
10049 if (argc == 2)
10050 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10051 else
10052 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10053
10054 if (! peer)
10055 return CMD_WARNING;
10056
10057 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10058}
10059
10060ALIAS (show_bgp_view_neighbor_received_routes,
10061 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10062 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10063 SHOW_STR
10064 BGP_STR
10065 "BGP view\n"
10066 "View name\n"
10067 "Address family\n"
10068 "Detailed information on TCP and BGP neighbor connections\n"
10069 "Neighbor to display information about\n"
10070 "Neighbor to display information about\n"
10071 "Display the received routes from neighbor\n")
10072
10073ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010074 show_bgp_neighbor_advertised_route_cmd,
10075 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10076 SHOW_STR
10077 BGP_STR
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 routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010082
10083ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010084 show_bgp_ipv6_neighbor_advertised_route_cmd,
10085 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10086 SHOW_STR
10087 BGP_STR
10088 "Address family\n"
10089 "Detailed information on TCP and BGP neighbor connections\n"
10090 "Neighbor to display information about\n"
10091 "Neighbor to display information about\n"
10092 "Display the routes advertised to a BGP neighbor\n")
10093
10094/* old command */
paulbb46e942003-10-24 19:02:03 +000010095ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010096 ipv6_bgp_neighbor_advertised_route_cmd,
10097 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10098 SHOW_STR
10099 IPV6_STR
10100 BGP_STR
10101 "Detailed information on TCP and BGP neighbor connections\n"
10102 "Neighbor to display information about\n"
10103 "Neighbor to display information about\n"
10104 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010105
paul718e3742002-12-13 20:15:29 +000010106/* old command */
10107DEFUN (ipv6_mbgp_neighbor_advertised_route,
10108 ipv6_mbgp_neighbor_advertised_route_cmd,
10109 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10110 SHOW_STR
10111 IPV6_STR
10112 MBGP_STR
10113 "Detailed information on TCP and BGP neighbor connections\n"
10114 "Neighbor to display information about\n"
10115 "Neighbor to display information about\n"
10116 "Display the routes advertised to a BGP neighbor\n")
10117{
paulbb46e942003-10-24 19:02:03 +000010118 struct peer *peer;
10119
10120 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10121 if (! peer)
10122 return CMD_WARNING;
10123
10124 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010125}
10126#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010127
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010128DEFUN (show_ip_bgp_view_neighbor_received_routes,
10129 show_ip_bgp_view_neighbor_received_routes_cmd,
10130 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10131 SHOW_STR
10132 IP_STR
10133 BGP_STR
10134 "BGP view\n"
10135 "View name\n"
10136 "Detailed information on TCP and BGP neighbor connections\n"
10137 "Neighbor to display information about\n"
10138 "Neighbor to display information about\n"
10139 "Display the received routes from neighbor\n")
10140{
10141 struct peer *peer;
10142
10143 if (argc == 2)
10144 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10145 else
10146 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10147
10148 if (! peer)
10149 return CMD_WARNING;
10150
10151 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10152}
10153
10154ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010155 show_ip_bgp_neighbor_received_routes_cmd,
10156 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10157 SHOW_STR
10158 IP_STR
10159 BGP_STR
10160 "Detailed information on TCP and BGP neighbor connections\n"
10161 "Neighbor to display information about\n"
10162 "Neighbor to display information about\n"
10163 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010164
10165DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10166 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10167 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10168 SHOW_STR
10169 IP_STR
10170 BGP_STR
10171 "Address family\n"
10172 "Address Family modifier\n"
10173 "Address Family modifier\n"
10174 "Detailed information on TCP and BGP neighbor connections\n"
10175 "Neighbor to display information about\n"
10176 "Neighbor to display information about\n"
10177 "Display the received routes from neighbor\n")
10178{
paulbb46e942003-10-24 19:02:03 +000010179 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010180
paulbb46e942003-10-24 19:02:03 +000010181 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10182 if (! peer)
10183 return CMD_WARNING;
10184
10185 if (strncmp (argv[0], "m", 1) == 0)
10186 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10187
10188 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010189}
10190
Michael Lambert95cbbd22010-07-23 14:43:04 -040010191DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10192 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010193 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
Michael Lambert95cbbd22010-07-23 14:43:04 -040010194 SHOW_STR
10195 BGP_STR
10196 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010197 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010198 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010199 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010200 "Address family modifier\n"
10201 "Address family modifier\n"
10202 "Detailed information on TCP and BGP neighbor connections\n"
10203 "Neighbor to display information about\n"
10204 "Neighbor to display information about\n"
10205 "Display the advertised routes to neighbor\n"
10206 "Display the received routes from neighbor\n")
10207{
10208 int afi;
10209 int safi;
10210 int in;
10211 struct peer *peer;
10212
David Lamparter94bad672015-03-03 08:52:22 +010010213 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010214
10215 if (! peer)
10216 return CMD_WARNING;
10217
Michael Lambert95cbbd22010-07-23 14:43:04 -040010218 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10219 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10220 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010221
10222 return peer_adj_routes (vty, peer, afi, safi, in);
10223}
10224
paul718e3742002-12-13 20:15:29 +000010225DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10226 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10227 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10228 SHOW_STR
10229 IP_STR
10230 BGP_STR
10231 "Detailed information on TCP and BGP neighbor connections\n"
10232 "Neighbor to display information about\n"
10233 "Neighbor to display information about\n"
10234 "Display information received from a BGP neighbor\n"
10235 "Display the prefixlist filter\n")
10236{
10237 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010238 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010239 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010240 int count, ret;
paul718e3742002-12-13 20:15:29 +000010241
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010242 ret = str2sockunion (argv[0], &su);
10243 if (ret < 0)
10244 {
10245 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10246 return CMD_WARNING;
10247 }
paul718e3742002-12-13 20:15:29 +000010248
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010249 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010250 if (! peer)
10251 return CMD_WARNING;
10252
10253 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10254 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10255 if (count)
10256 {
10257 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10258 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10259 }
10260
10261 return CMD_SUCCESS;
10262}
10263
10264DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10265 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10266 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10267 SHOW_STR
10268 IP_STR
10269 BGP_STR
10270 "Address family\n"
10271 "Address Family modifier\n"
10272 "Address Family modifier\n"
10273 "Detailed information on TCP and BGP neighbor connections\n"
10274 "Neighbor to display information about\n"
10275 "Neighbor to display information about\n"
10276 "Display information received from a BGP neighbor\n"
10277 "Display the prefixlist filter\n")
10278{
10279 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010280 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010281 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010282 int count, ret;
paul718e3742002-12-13 20:15:29 +000010283
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010284 ret = str2sockunion (argv[1], &su);
10285 if (ret < 0)
10286 {
10287 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10288 return CMD_WARNING;
10289 }
paul718e3742002-12-13 20:15:29 +000010290
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010291 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010292 if (! peer)
10293 return CMD_WARNING;
10294
10295 if (strncmp (argv[0], "m", 1) == 0)
10296 {
10297 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10298 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10299 if (count)
10300 {
10301 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10302 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10303 }
10304 }
10305 else
10306 {
10307 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10308 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10309 if (count)
10310 {
10311 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10312 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10313 }
10314 }
10315
10316 return CMD_SUCCESS;
10317}
10318
10319
10320#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010321ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010322 show_bgp_neighbor_received_routes_cmd,
10323 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10324 SHOW_STR
10325 BGP_STR
10326 "Detailed information on TCP and BGP neighbor connections\n"
10327 "Neighbor to display information about\n"
10328 "Neighbor to display information about\n"
10329 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010330
paulbb46e942003-10-24 19:02:03 +000010331ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010332 show_bgp_ipv6_neighbor_received_routes_cmd,
10333 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10334 SHOW_STR
10335 BGP_STR
10336 "Address family\n"
10337 "Detailed information on TCP and BGP neighbor connections\n"
10338 "Neighbor to display information about\n"
10339 "Neighbor to display information about\n"
10340 "Display the received routes from neighbor\n")
10341
10342DEFUN (show_bgp_neighbor_received_prefix_filter,
10343 show_bgp_neighbor_received_prefix_filter_cmd,
10344 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10345 SHOW_STR
10346 BGP_STR
10347 "Detailed information on TCP and BGP neighbor connections\n"
10348 "Neighbor to display information about\n"
10349 "Neighbor to display information about\n"
10350 "Display information received from a BGP neighbor\n"
10351 "Display the prefixlist filter\n")
10352{
10353 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010354 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010355 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010356 int count, ret;
paul718e3742002-12-13 20:15:29 +000010357
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010358 ret = str2sockunion (argv[0], &su);
10359 if (ret < 0)
10360 {
10361 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10362 return CMD_WARNING;
10363 }
paul718e3742002-12-13 20:15:29 +000010364
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010365 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010366 if (! peer)
10367 return CMD_WARNING;
10368
10369 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10370 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10371 if (count)
10372 {
10373 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10374 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10375 }
10376
10377 return CMD_SUCCESS;
10378}
10379
10380ALIAS (show_bgp_neighbor_received_prefix_filter,
10381 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10382 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10383 SHOW_STR
10384 BGP_STR
10385 "Address family\n"
10386 "Detailed information on TCP and BGP neighbor connections\n"
10387 "Neighbor to display information about\n"
10388 "Neighbor to display information about\n"
10389 "Display information received from a BGP neighbor\n"
10390 "Display the prefixlist filter\n")
10391
10392/* old command */
paulbb46e942003-10-24 19:02:03 +000010393ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010394 ipv6_bgp_neighbor_received_routes_cmd,
10395 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10396 SHOW_STR
10397 IPV6_STR
10398 BGP_STR
10399 "Detailed information on TCP and BGP neighbor connections\n"
10400 "Neighbor to display information about\n"
10401 "Neighbor to display information about\n"
10402 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010403
10404/* old command */
10405DEFUN (ipv6_mbgp_neighbor_received_routes,
10406 ipv6_mbgp_neighbor_received_routes_cmd,
10407 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10408 SHOW_STR
10409 IPV6_STR
10410 MBGP_STR
10411 "Detailed information on TCP and BGP neighbor connections\n"
10412 "Neighbor to display information about\n"
10413 "Neighbor to display information about\n"
10414 "Display the received routes from neighbor\n")
10415{
paulbb46e942003-10-24 19:02:03 +000010416 struct peer *peer;
10417
10418 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10419 if (! peer)
10420 return CMD_WARNING;
10421
10422 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010423}
paulbb46e942003-10-24 19:02:03 +000010424
10425DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10426 show_bgp_view_neighbor_received_prefix_filter_cmd,
10427 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10428 SHOW_STR
10429 BGP_STR
10430 "BGP view\n"
10431 "View name\n"
10432 "Detailed information on TCP and BGP neighbor connections\n"
10433 "Neighbor to display information about\n"
10434 "Neighbor to display information about\n"
10435 "Display information received from a BGP neighbor\n"
10436 "Display the prefixlist filter\n")
10437{
10438 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010439 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010440 struct peer *peer;
10441 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010442 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010443
10444 /* BGP structure lookup. */
10445 bgp = bgp_lookup_by_name (argv[0]);
10446 if (bgp == NULL)
10447 {
10448 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10449 return CMD_WARNING;
10450 }
10451
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010452 ret = str2sockunion (argv[1], &su);
10453 if (ret < 0)
10454 {
10455 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10456 return CMD_WARNING;
10457 }
paulbb46e942003-10-24 19:02:03 +000010458
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010459 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010460 if (! peer)
10461 return CMD_WARNING;
10462
10463 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10464 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10465 if (count)
10466 {
10467 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10468 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10469 }
10470
10471 return CMD_SUCCESS;
10472}
10473
10474ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10475 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10476 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10477 SHOW_STR
10478 BGP_STR
10479 "BGP view\n"
10480 "View name\n"
10481 "Address family\n"
10482 "Detailed information on TCP and BGP neighbor connections\n"
10483 "Neighbor to display information about\n"
10484 "Neighbor to display information about\n"
10485 "Display information received from a BGP neighbor\n"
10486 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010487#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010488
paul94f2b392005-06-28 12:44:16 +000010489static int
paulbb46e942003-10-24 19:02:03 +000010490bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010491 safi_t safi, enum bgp_show_type type)
10492{
paul718e3742002-12-13 20:15:29 +000010493 if (! peer || ! peer->afc[afi][safi])
10494 {
10495 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010496 return CMD_WARNING;
10497 }
10498
ajs5a646652004-11-05 01:25:55 +000010499 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010500}
10501
10502DEFUN (show_ip_bgp_neighbor_routes,
10503 show_ip_bgp_neighbor_routes_cmd,
10504 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10505 SHOW_STR
10506 IP_STR
10507 BGP_STR
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 routes learned from neighbor\n")
10512{
paulbb46e942003-10-24 19:02:03 +000010513 struct peer *peer;
10514
10515 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10516 if (! peer)
10517 return CMD_WARNING;
10518
10519 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010520 bgp_show_type_neighbor);
10521}
10522
10523DEFUN (show_ip_bgp_neighbor_flap,
10524 show_ip_bgp_neighbor_flap_cmd,
10525 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10526 SHOW_STR
10527 IP_STR
10528 BGP_STR
10529 "Detailed information on TCP and BGP neighbor connections\n"
10530 "Neighbor to display information about\n"
10531 "Neighbor to display information about\n"
10532 "Display flap statistics of the routes learned from neighbor\n")
10533{
paulbb46e942003-10-24 19:02:03 +000010534 struct peer *peer;
10535
10536 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10537 if (! peer)
10538 return CMD_WARNING;
10539
10540 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010541 bgp_show_type_flap_neighbor);
10542}
10543
10544DEFUN (show_ip_bgp_neighbor_damp,
10545 show_ip_bgp_neighbor_damp_cmd,
10546 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10547 SHOW_STR
10548 IP_STR
10549 BGP_STR
10550 "Detailed information on TCP and BGP neighbor connections\n"
10551 "Neighbor to display information about\n"
10552 "Neighbor to display information about\n"
10553 "Display the dampened routes received from neighbor\n")
10554{
paulbb46e942003-10-24 19:02:03 +000010555 struct peer *peer;
10556
10557 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10558 if (! peer)
10559 return CMD_WARNING;
10560
10561 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010562 bgp_show_type_damp_neighbor);
10563}
10564
10565DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10566 show_ip_bgp_ipv4_neighbor_routes_cmd,
10567 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10568 SHOW_STR
10569 IP_STR
10570 BGP_STR
10571 "Address family\n"
10572 "Address Family modifier\n"
10573 "Address Family modifier\n"
10574 "Detailed information on TCP and BGP neighbor connections\n"
10575 "Neighbor to display information about\n"
10576 "Neighbor to display information about\n"
10577 "Display routes learned from neighbor\n")
10578{
paulbb46e942003-10-24 19:02:03 +000010579 struct peer *peer;
10580
10581 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10582 if (! peer)
10583 return CMD_WARNING;
10584
paul718e3742002-12-13 20:15:29 +000010585 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010586 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010587 bgp_show_type_neighbor);
10588
paulbb46e942003-10-24 19:02:03 +000010589 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010590 bgp_show_type_neighbor);
10591}
paulbb46e942003-10-24 19:02:03 +000010592
paulfee0f4c2004-09-13 05:12:46 +000010593DEFUN (show_ip_bgp_view_rsclient,
10594 show_ip_bgp_view_rsclient_cmd,
10595 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10596 SHOW_STR
10597 IP_STR
10598 BGP_STR
10599 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010600 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010601 "Information about Route Server Client\n"
10602 NEIGHBOR_ADDR_STR)
10603{
10604 struct bgp_table *table;
10605 struct peer *peer;
10606
10607 if (argc == 2)
10608 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10609 else
10610 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10611
10612 if (! peer)
10613 return CMD_WARNING;
10614
10615 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10616 {
10617 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10618 VTY_NEWLINE);
10619 return CMD_WARNING;
10620 }
10621
10622 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10623 PEER_FLAG_RSERVER_CLIENT))
10624 {
10625 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10626 VTY_NEWLINE);
10627 return CMD_WARNING;
10628 }
10629
10630 table = peer->rib[AFI_IP][SAFI_UNICAST];
10631
ajs5a646652004-11-05 01:25:55 +000010632 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010633}
10634
10635ALIAS (show_ip_bgp_view_rsclient,
10636 show_ip_bgp_rsclient_cmd,
10637 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10638 SHOW_STR
10639 IP_STR
10640 BGP_STR
10641 "Information about Route Server Client\n"
10642 NEIGHBOR_ADDR_STR)
10643
Michael Lambert95cbbd22010-07-23 14:43:04 -040010644DEFUN (show_bgp_view_ipv4_safi_rsclient,
10645 show_bgp_view_ipv4_safi_rsclient_cmd,
10646 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10647 SHOW_STR
10648 BGP_STR
10649 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010650 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010651 "Address family\n"
10652 "Address Family modifier\n"
10653 "Address Family modifier\n"
10654 "Information about Route Server Client\n"
10655 NEIGHBOR_ADDR_STR)
10656{
10657 struct bgp_table *table;
10658 struct peer *peer;
10659 safi_t safi;
10660
10661 if (argc == 3) {
10662 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10663 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10664 } else {
10665 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10666 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10667 }
10668
10669 if (! peer)
10670 return CMD_WARNING;
10671
10672 if (! peer->afc[AFI_IP][safi])
10673 {
10674 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10675 VTY_NEWLINE);
10676 return CMD_WARNING;
10677 }
10678
10679 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10680 PEER_FLAG_RSERVER_CLIENT))
10681 {
10682 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10683 VTY_NEWLINE);
10684 return CMD_WARNING;
10685 }
10686
10687 table = peer->rib[AFI_IP][safi];
10688
10689 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10690}
10691
10692ALIAS (show_bgp_view_ipv4_safi_rsclient,
10693 show_bgp_ipv4_safi_rsclient_cmd,
10694 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10695 SHOW_STR
10696 BGP_STR
10697 "Address family\n"
10698 "Address Family modifier\n"
10699 "Address Family modifier\n"
10700 "Information about Route Server Client\n"
10701 NEIGHBOR_ADDR_STR)
10702
paulfee0f4c2004-09-13 05:12:46 +000010703DEFUN (show_ip_bgp_view_rsclient_route,
10704 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010705 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010706 SHOW_STR
10707 IP_STR
10708 BGP_STR
10709 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010710 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010711 "Information about Route Server Client\n"
10712 NEIGHBOR_ADDR_STR
10713 "Network in the BGP routing table to display\n")
10714{
10715 struct bgp *bgp;
10716 struct peer *peer;
10717
10718 /* BGP structure lookup. */
10719 if (argc == 3)
10720 {
10721 bgp = bgp_lookup_by_name (argv[0]);
10722 if (bgp == NULL)
10723 {
10724 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10725 return CMD_WARNING;
10726 }
10727 }
10728 else
10729 {
10730 bgp = bgp_get_default ();
10731 if (bgp == NULL)
10732 {
10733 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10734 return CMD_WARNING;
10735 }
10736 }
10737
10738 if (argc == 3)
10739 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10740 else
10741 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10742
10743 if (! peer)
10744 return CMD_WARNING;
10745
10746 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10747 {
10748 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10749 VTY_NEWLINE);
10750 return CMD_WARNING;
10751}
10752
10753 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10754 PEER_FLAG_RSERVER_CLIENT))
10755 {
10756 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10757 VTY_NEWLINE);
10758 return CMD_WARNING;
10759 }
10760
10761 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10762 (argc == 3) ? argv[2] : argv[1],
10763 AFI_IP, SAFI_UNICAST, NULL, 0);
10764}
10765
10766ALIAS (show_ip_bgp_view_rsclient_route,
10767 show_ip_bgp_rsclient_route_cmd,
10768 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10769 SHOW_STR
10770 IP_STR
10771 BGP_STR
10772 "Information about Route Server Client\n"
10773 NEIGHBOR_ADDR_STR
10774 "Network in the BGP routing table to display\n")
10775
Michael Lambert95cbbd22010-07-23 14:43:04 -040010776DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10777 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10778 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10779 SHOW_STR
10780 BGP_STR
10781 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010782 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010783 "Address family\n"
10784 "Address Family modifier\n"
10785 "Address Family modifier\n"
10786 "Information about Route Server Client\n"
10787 NEIGHBOR_ADDR_STR
10788 "Network in the BGP routing table to display\n")
10789{
10790 struct bgp *bgp;
10791 struct peer *peer;
10792 safi_t safi;
10793
10794 /* BGP structure lookup. */
10795 if (argc == 4)
10796 {
10797 bgp = bgp_lookup_by_name (argv[0]);
10798 if (bgp == NULL)
10799 {
10800 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10801 return CMD_WARNING;
10802 }
10803 }
10804 else
10805 {
10806 bgp = bgp_get_default ();
10807 if (bgp == NULL)
10808 {
10809 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10810 return CMD_WARNING;
10811 }
10812 }
10813
10814 if (argc == 4) {
10815 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10816 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10817 } else {
10818 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10819 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10820 }
10821
10822 if (! peer)
10823 return CMD_WARNING;
10824
10825 if (! peer->afc[AFI_IP][safi])
10826 {
10827 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10828 VTY_NEWLINE);
10829 return CMD_WARNING;
10830}
10831
10832 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10833 PEER_FLAG_RSERVER_CLIENT))
10834 {
10835 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10836 VTY_NEWLINE);
10837 return CMD_WARNING;
10838 }
10839
10840 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10841 (argc == 4) ? argv[3] : argv[2],
10842 AFI_IP, safi, NULL, 0);
10843}
10844
10845ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10846 show_bgp_ipv4_safi_rsclient_route_cmd,
10847 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10848 SHOW_STR
10849 BGP_STR
10850 "Address family\n"
10851 "Address Family modifier\n"
10852 "Address Family modifier\n"
10853 "Information about Route Server Client\n"
10854 NEIGHBOR_ADDR_STR
10855 "Network in the BGP routing table to display\n")
10856
paulfee0f4c2004-09-13 05:12:46 +000010857DEFUN (show_ip_bgp_view_rsclient_prefix,
10858 show_ip_bgp_view_rsclient_prefix_cmd,
10859 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10860 SHOW_STR
10861 IP_STR
10862 BGP_STR
10863 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010864 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010865 "Information about Route Server Client\n"
10866 NEIGHBOR_ADDR_STR
10867 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10868{
10869 struct bgp *bgp;
10870 struct peer *peer;
10871
10872 /* BGP structure lookup. */
10873 if (argc == 3)
10874 {
10875 bgp = bgp_lookup_by_name (argv[0]);
10876 if (bgp == NULL)
10877 {
10878 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10879 return CMD_WARNING;
10880 }
10881 }
10882 else
10883 {
10884 bgp = bgp_get_default ();
10885 if (bgp == NULL)
10886 {
10887 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10888 return CMD_WARNING;
10889 }
10890 }
10891
10892 if (argc == 3)
10893 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10894 else
10895 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10896
10897 if (! peer)
10898 return CMD_WARNING;
10899
10900 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10901 {
10902 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10903 VTY_NEWLINE);
10904 return CMD_WARNING;
10905}
10906
10907 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10908 PEER_FLAG_RSERVER_CLIENT))
10909{
10910 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10911 VTY_NEWLINE);
10912 return CMD_WARNING;
10913 }
10914
10915 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10916 (argc == 3) ? argv[2] : argv[1],
10917 AFI_IP, SAFI_UNICAST, NULL, 1);
10918}
10919
10920ALIAS (show_ip_bgp_view_rsclient_prefix,
10921 show_ip_bgp_rsclient_prefix_cmd,
10922 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10923 SHOW_STR
10924 IP_STR
10925 BGP_STR
10926 "Information about Route Server Client\n"
10927 NEIGHBOR_ADDR_STR
10928 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10929
Michael Lambert95cbbd22010-07-23 14:43:04 -040010930DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10931 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10932 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10933 SHOW_STR
10934 BGP_STR
10935 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010936 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010937 "Address family\n"
10938 "Address Family modifier\n"
10939 "Address Family modifier\n"
10940 "Information about Route Server Client\n"
10941 NEIGHBOR_ADDR_STR
10942 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10943{
10944 struct bgp *bgp;
10945 struct peer *peer;
10946 safi_t safi;
10947
10948 /* BGP structure lookup. */
10949 if (argc == 4)
10950 {
10951 bgp = bgp_lookup_by_name (argv[0]);
10952 if (bgp == NULL)
10953 {
10954 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10955 return CMD_WARNING;
10956 }
10957 }
10958 else
10959 {
10960 bgp = bgp_get_default ();
10961 if (bgp == NULL)
10962 {
10963 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10964 return CMD_WARNING;
10965 }
10966 }
10967
10968 if (argc == 4) {
10969 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10970 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10971 } else {
10972 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10973 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10974 }
10975
10976 if (! peer)
10977 return CMD_WARNING;
10978
10979 if (! peer->afc[AFI_IP][safi])
10980 {
10981 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10982 VTY_NEWLINE);
10983 return CMD_WARNING;
10984}
10985
10986 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10987 PEER_FLAG_RSERVER_CLIENT))
10988{
10989 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10990 VTY_NEWLINE);
10991 return CMD_WARNING;
10992 }
10993
10994 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10995 (argc == 4) ? argv[3] : argv[2],
10996 AFI_IP, safi, NULL, 1);
10997}
10998
10999ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11000 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11001 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11002 SHOW_STR
11003 BGP_STR
11004 "Address family\n"
11005 "Address Family modifier\n"
11006 "Address Family modifier\n"
11007 "Information about Route Server Client\n"
11008 NEIGHBOR_ADDR_STR
11009 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011010
paul718e3742002-12-13 20:15:29 +000011011#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011012DEFUN (show_bgp_view_neighbor_routes,
11013 show_bgp_view_neighbor_routes_cmd,
11014 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11015 SHOW_STR
11016 BGP_STR
11017 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011018 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011019 "Detailed information on TCP and BGP neighbor connections\n"
11020 "Neighbor to display information about\n"
11021 "Neighbor to display information about\n"
11022 "Display routes learned from neighbor\n")
11023{
11024 struct peer *peer;
11025
11026 if (argc == 2)
11027 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11028 else
11029 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11030
11031 if (! peer)
11032 return CMD_WARNING;
11033
11034 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11035 bgp_show_type_neighbor);
11036}
11037
11038ALIAS (show_bgp_view_neighbor_routes,
11039 show_bgp_view_ipv6_neighbor_routes_cmd,
11040 "show bgp view WORD ipv6 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 "Address family\n"
11046 "Detailed information on TCP and BGP neighbor connections\n"
11047 "Neighbor to display information about\n"
11048 "Neighbor to display information about\n"
11049 "Display routes learned from neighbor\n")
11050
11051DEFUN (show_bgp_view_neighbor_damp,
11052 show_bgp_view_neighbor_damp_cmd,
11053 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11054 SHOW_STR
11055 BGP_STR
11056 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011057 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011058 "Detailed information on TCP and BGP neighbor connections\n"
11059 "Neighbor to display information about\n"
11060 "Neighbor to display information about\n"
11061 "Display the dampened routes received from neighbor\n")
11062{
11063 struct peer *peer;
11064
11065 if (argc == 2)
11066 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11067 else
11068 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11069
11070 if (! peer)
11071 return CMD_WARNING;
11072
11073 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11074 bgp_show_type_damp_neighbor);
11075}
11076
11077ALIAS (show_bgp_view_neighbor_damp,
11078 show_bgp_view_ipv6_neighbor_damp_cmd,
11079 "show bgp view WORD ipv6 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 "Address family\n"
11085 "Detailed information on TCP and BGP neighbor connections\n"
11086 "Neighbor to display information about\n"
11087 "Neighbor to display information about\n"
11088 "Display the dampened routes received from neighbor\n")
11089
11090DEFUN (show_bgp_view_neighbor_flap,
11091 show_bgp_view_neighbor_flap_cmd,
11092 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11093 SHOW_STR
11094 BGP_STR
11095 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011096 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011097 "Detailed information on TCP and BGP neighbor connections\n"
11098 "Neighbor to display information about\n"
11099 "Neighbor to display information about\n"
11100 "Display flap statistics of the routes learned from neighbor\n")
11101{
11102 struct peer *peer;
11103
11104 if (argc == 2)
11105 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11106 else
11107 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11108
11109 if (! peer)
11110 return CMD_WARNING;
11111
11112 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11113 bgp_show_type_flap_neighbor);
11114}
11115
11116ALIAS (show_bgp_view_neighbor_flap,
11117 show_bgp_view_ipv6_neighbor_flap_cmd,
11118 "show bgp view WORD ipv6 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 "Address family\n"
11124 "Detailed information on TCP and BGP neighbor connections\n"
11125 "Neighbor to display information about\n"
11126 "Neighbor to display information about\n"
11127 "Display flap statistics of the routes learned from neighbor\n")
11128
11129ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011130 show_bgp_neighbor_routes_cmd,
11131 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11132 SHOW_STR
11133 BGP_STR
11134 "Detailed information on TCP and BGP neighbor connections\n"
11135 "Neighbor to display information about\n"
11136 "Neighbor to display information about\n"
11137 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011138
paulbb46e942003-10-24 19:02:03 +000011139
11140ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011141 show_bgp_ipv6_neighbor_routes_cmd,
11142 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11143 SHOW_STR
11144 BGP_STR
11145 "Address family\n"
11146 "Detailed information on TCP and BGP neighbor connections\n"
11147 "Neighbor to display information about\n"
11148 "Neighbor to display information about\n"
11149 "Display routes learned from neighbor\n")
11150
11151/* old command */
paulbb46e942003-10-24 19:02:03 +000011152ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011153 ipv6_bgp_neighbor_routes_cmd,
11154 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11155 SHOW_STR
11156 IPV6_STR
11157 BGP_STR
11158 "Detailed information on TCP and BGP neighbor connections\n"
11159 "Neighbor to display information about\n"
11160 "Neighbor to display information about\n"
11161 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011162
11163/* old command */
11164DEFUN (ipv6_mbgp_neighbor_routes,
11165 ipv6_mbgp_neighbor_routes_cmd,
11166 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11167 SHOW_STR
11168 IPV6_STR
11169 MBGP_STR
11170 "Detailed information on TCP and BGP neighbor connections\n"
11171 "Neighbor to display information about\n"
11172 "Neighbor to display information about\n"
11173 "Display routes learned from neighbor\n")
11174{
paulbb46e942003-10-24 19:02:03 +000011175 struct peer *peer;
11176
11177 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11178 if (! peer)
11179 return CMD_WARNING;
11180
11181 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011182 bgp_show_type_neighbor);
11183}
paulbb46e942003-10-24 19:02:03 +000011184
11185ALIAS (show_bgp_view_neighbor_flap,
11186 show_bgp_neighbor_flap_cmd,
11187 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11188 SHOW_STR
11189 BGP_STR
11190 "Detailed information on TCP and BGP neighbor connections\n"
11191 "Neighbor to display information about\n"
11192 "Neighbor to display information about\n"
11193 "Display flap statistics of the routes learned from neighbor\n")
11194
11195ALIAS (show_bgp_view_neighbor_flap,
11196 show_bgp_ipv6_neighbor_flap_cmd,
11197 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11198 SHOW_STR
11199 BGP_STR
11200 "Address family\n"
11201 "Detailed information on TCP and BGP neighbor connections\n"
11202 "Neighbor to display information about\n"
11203 "Neighbor to display information about\n"
11204 "Display flap statistics of the routes learned from neighbor\n")
11205
11206ALIAS (show_bgp_view_neighbor_damp,
11207 show_bgp_neighbor_damp_cmd,
11208 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11209 SHOW_STR
11210 BGP_STR
11211 "Detailed information on TCP and BGP neighbor connections\n"
11212 "Neighbor to display information about\n"
11213 "Neighbor to display information about\n"
11214 "Display the dampened routes received from neighbor\n")
11215
11216ALIAS (show_bgp_view_neighbor_damp,
11217 show_bgp_ipv6_neighbor_damp_cmd,
11218 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11219 SHOW_STR
11220 BGP_STR
11221 "Address family\n"
11222 "Detailed information on TCP and BGP neighbor connections\n"
11223 "Neighbor to display information about\n"
11224 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011225 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011226
11227DEFUN (show_bgp_view_rsclient,
11228 show_bgp_view_rsclient_cmd,
11229 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11230 SHOW_STR
11231 BGP_STR
11232 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011233 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011234 "Information about Route Server Client\n"
11235 NEIGHBOR_ADDR_STR)
11236{
11237 struct bgp_table *table;
11238 struct peer *peer;
11239
11240 if (argc == 2)
11241 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11242 else
11243 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11244
11245 if (! peer)
11246 return CMD_WARNING;
11247
11248 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11249 {
11250 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11251 VTY_NEWLINE);
11252 return CMD_WARNING;
11253 }
11254
11255 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11256 PEER_FLAG_RSERVER_CLIENT))
11257 {
11258 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11259 VTY_NEWLINE);
11260 return CMD_WARNING;
11261 }
11262
11263 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11264
ajs5a646652004-11-05 01:25:55 +000011265 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011266}
11267
11268ALIAS (show_bgp_view_rsclient,
11269 show_bgp_rsclient_cmd,
11270 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11271 SHOW_STR
11272 BGP_STR
11273 "Information about Route Server Client\n"
11274 NEIGHBOR_ADDR_STR)
11275
Michael Lambert95cbbd22010-07-23 14:43:04 -040011276DEFUN (show_bgp_view_ipv6_safi_rsclient,
11277 show_bgp_view_ipv6_safi_rsclient_cmd,
11278 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11279 SHOW_STR
11280 BGP_STR
11281 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011282 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011283 "Address family\n"
11284 "Address Family modifier\n"
11285 "Address Family modifier\n"
11286 "Information about Route Server Client\n"
11287 NEIGHBOR_ADDR_STR)
11288{
11289 struct bgp_table *table;
11290 struct peer *peer;
11291 safi_t safi;
11292
11293 if (argc == 3) {
11294 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11295 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11296 } else {
11297 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11298 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11299 }
11300
11301 if (! peer)
11302 return CMD_WARNING;
11303
11304 if (! peer->afc[AFI_IP6][safi])
11305 {
11306 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11307 VTY_NEWLINE);
11308 return CMD_WARNING;
11309 }
11310
11311 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11312 PEER_FLAG_RSERVER_CLIENT))
11313 {
11314 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11315 VTY_NEWLINE);
11316 return CMD_WARNING;
11317 }
11318
11319 table = peer->rib[AFI_IP6][safi];
11320
11321 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11322}
11323
11324ALIAS (show_bgp_view_ipv6_safi_rsclient,
11325 show_bgp_ipv6_safi_rsclient_cmd,
11326 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11327 SHOW_STR
11328 BGP_STR
11329 "Address family\n"
11330 "Address Family modifier\n"
11331 "Address Family modifier\n"
11332 "Information about Route Server Client\n"
11333 NEIGHBOR_ADDR_STR)
11334
paulfee0f4c2004-09-13 05:12:46 +000011335DEFUN (show_bgp_view_rsclient_route,
11336 show_bgp_view_rsclient_route_cmd,
11337 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11338 SHOW_STR
11339 BGP_STR
11340 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011341 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011342 "Information about Route Server Client\n"
11343 NEIGHBOR_ADDR_STR
11344 "Network in the BGP routing table to display\n")
11345{
11346 struct bgp *bgp;
11347 struct peer *peer;
11348
11349 /* BGP structure lookup. */
11350 if (argc == 3)
11351 {
11352 bgp = bgp_lookup_by_name (argv[0]);
11353 if (bgp == NULL)
11354 {
11355 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11356 return CMD_WARNING;
11357 }
11358 }
11359 else
11360 {
11361 bgp = bgp_get_default ();
11362 if (bgp == NULL)
11363 {
11364 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11365 return CMD_WARNING;
11366 }
11367 }
11368
11369 if (argc == 3)
11370 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11371 else
11372 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11373
11374 if (! peer)
11375 return CMD_WARNING;
11376
11377 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11378 {
11379 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11380 VTY_NEWLINE);
11381 return CMD_WARNING;
11382 }
11383
11384 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11385 PEER_FLAG_RSERVER_CLIENT))
11386 {
11387 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11388 VTY_NEWLINE);
11389 return CMD_WARNING;
11390 }
11391
11392 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11393 (argc == 3) ? argv[2] : argv[1],
11394 AFI_IP6, SAFI_UNICAST, NULL, 0);
11395}
11396
11397ALIAS (show_bgp_view_rsclient_route,
11398 show_bgp_rsclient_route_cmd,
11399 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11400 SHOW_STR
11401 BGP_STR
11402 "Information about Route Server Client\n"
11403 NEIGHBOR_ADDR_STR
11404 "Network in the BGP routing table to display\n")
11405
Michael Lambert95cbbd22010-07-23 14:43:04 -040011406DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11407 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11408 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11409 SHOW_STR
11410 BGP_STR
11411 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011412 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011413 "Address family\n"
11414 "Address Family modifier\n"
11415 "Address Family modifier\n"
11416 "Information about Route Server Client\n"
11417 NEIGHBOR_ADDR_STR
11418 "Network in the BGP routing table to display\n")
11419{
11420 struct bgp *bgp;
11421 struct peer *peer;
11422 safi_t safi;
11423
11424 /* BGP structure lookup. */
11425 if (argc == 4)
11426 {
11427 bgp = bgp_lookup_by_name (argv[0]);
11428 if (bgp == NULL)
11429 {
11430 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11431 return CMD_WARNING;
11432 }
11433 }
11434 else
11435 {
11436 bgp = bgp_get_default ();
11437 if (bgp == NULL)
11438 {
11439 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11440 return CMD_WARNING;
11441 }
11442 }
11443
11444 if (argc == 4) {
11445 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11446 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11447 } else {
11448 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11449 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11450 }
11451
11452 if (! peer)
11453 return CMD_WARNING;
11454
11455 if (! peer->afc[AFI_IP6][safi])
11456 {
11457 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11458 VTY_NEWLINE);
11459 return CMD_WARNING;
11460}
11461
11462 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11463 PEER_FLAG_RSERVER_CLIENT))
11464 {
11465 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11466 VTY_NEWLINE);
11467 return CMD_WARNING;
11468 }
11469
11470 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11471 (argc == 4) ? argv[3] : argv[2],
11472 AFI_IP6, safi, NULL, 0);
11473}
11474
11475ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11476 show_bgp_ipv6_safi_rsclient_route_cmd,
11477 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11478 SHOW_STR
11479 BGP_STR
11480 "Address family\n"
11481 "Address Family modifier\n"
11482 "Address Family modifier\n"
11483 "Information about Route Server Client\n"
11484 NEIGHBOR_ADDR_STR
11485 "Network in the BGP routing table to display\n")
11486
paulfee0f4c2004-09-13 05:12:46 +000011487DEFUN (show_bgp_view_rsclient_prefix,
11488 show_bgp_view_rsclient_prefix_cmd,
11489 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11490 SHOW_STR
11491 BGP_STR
11492 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011493 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011494 "Information about Route Server Client\n"
11495 NEIGHBOR_ADDR_STR
11496 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11497{
11498 struct bgp *bgp;
11499 struct peer *peer;
11500
11501 /* BGP structure lookup. */
11502 if (argc == 3)
11503 {
11504 bgp = bgp_lookup_by_name (argv[0]);
11505 if (bgp == NULL)
11506 {
11507 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11508 return CMD_WARNING;
11509 }
11510 }
11511 else
11512 {
11513 bgp = bgp_get_default ();
11514 if (bgp == NULL)
11515 {
11516 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11517 return CMD_WARNING;
11518 }
11519 }
11520
11521 if (argc == 3)
11522 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11523 else
11524 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11525
11526 if (! peer)
11527 return CMD_WARNING;
11528
11529 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11530 {
11531 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11532 VTY_NEWLINE);
11533 return CMD_WARNING;
11534 }
11535
11536 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11537 PEER_FLAG_RSERVER_CLIENT))
11538 {
11539 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11540 VTY_NEWLINE);
11541 return CMD_WARNING;
11542 }
11543
11544 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11545 (argc == 3) ? argv[2] : argv[1],
11546 AFI_IP6, SAFI_UNICAST, NULL, 1);
11547}
11548
11549ALIAS (show_bgp_view_rsclient_prefix,
11550 show_bgp_rsclient_prefix_cmd,
11551 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11552 SHOW_STR
11553 BGP_STR
11554 "Information about Route Server Client\n"
11555 NEIGHBOR_ADDR_STR
11556 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11557
Michael Lambert95cbbd22010-07-23 14:43:04 -040011558DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11559 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11560 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11561 SHOW_STR
11562 BGP_STR
11563 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011564 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011565 "Address family\n"
11566 "Address Family modifier\n"
11567 "Address Family modifier\n"
11568 "Information about Route Server Client\n"
11569 NEIGHBOR_ADDR_STR
11570 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11571{
11572 struct bgp *bgp;
11573 struct peer *peer;
11574 safi_t safi;
11575
11576 /* BGP structure lookup. */
11577 if (argc == 4)
11578 {
11579 bgp = bgp_lookup_by_name (argv[0]);
11580 if (bgp == NULL)
11581 {
11582 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11583 return CMD_WARNING;
11584 }
11585 }
11586 else
11587 {
11588 bgp = bgp_get_default ();
11589 if (bgp == NULL)
11590 {
11591 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11592 return CMD_WARNING;
11593 }
11594 }
11595
11596 if (argc == 4) {
11597 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11598 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11599 } else {
11600 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11601 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11602 }
11603
11604 if (! peer)
11605 return CMD_WARNING;
11606
11607 if (! peer->afc[AFI_IP6][safi])
11608 {
11609 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11610 VTY_NEWLINE);
11611 return CMD_WARNING;
11612}
11613
11614 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11615 PEER_FLAG_RSERVER_CLIENT))
11616{
11617 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11618 VTY_NEWLINE);
11619 return CMD_WARNING;
11620 }
11621
11622 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11623 (argc == 4) ? argv[3] : argv[2],
11624 AFI_IP6, safi, NULL, 1);
11625}
11626
11627ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11628 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11629 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11630 SHOW_STR
11631 BGP_STR
11632 "Address family\n"
11633 "Address Family modifier\n"
11634 "Address Family modifier\n"
11635 "Information about Route Server Client\n"
11636 NEIGHBOR_ADDR_STR
11637 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11638
paul718e3742002-12-13 20:15:29 +000011639#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020011640
paul718e3742002-12-13 20:15:29 +000011641struct bgp_table *bgp_distance_table;
11642
11643struct bgp_distance
11644{
11645 /* Distance value for the IP source prefix. */
11646 u_char distance;
11647
11648 /* Name of the access-list to be matched. */
11649 char *access_list;
11650};
11651
paul94f2b392005-06-28 12:44:16 +000011652static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011653bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011654{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011655 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011656}
11657
paul94f2b392005-06-28 12:44:16 +000011658static void
paul718e3742002-12-13 20:15:29 +000011659bgp_distance_free (struct bgp_distance *bdistance)
11660{
11661 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11662}
11663
paul94f2b392005-06-28 12:44:16 +000011664static int
paulfd79ac92004-10-13 05:06:08 +000011665bgp_distance_set (struct vty *vty, const char *distance_str,
11666 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011667{
11668 int ret;
11669 struct prefix_ipv4 p;
11670 u_char distance;
11671 struct bgp_node *rn;
11672 struct bgp_distance *bdistance;
11673
11674 ret = str2prefix_ipv4 (ip_str, &p);
11675 if (ret == 0)
11676 {
11677 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11678 return CMD_WARNING;
11679 }
11680
11681 distance = atoi (distance_str);
11682
11683 /* Get BGP distance node. */
11684 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11685 if (rn->info)
11686 {
11687 bdistance = rn->info;
11688 bgp_unlock_node (rn);
11689 }
11690 else
11691 {
11692 bdistance = bgp_distance_new ();
11693 rn->info = bdistance;
11694 }
11695
11696 /* Set distance value. */
11697 bdistance->distance = distance;
11698
11699 /* Reset access-list configuration. */
11700 if (bdistance->access_list)
11701 {
11702 free (bdistance->access_list);
11703 bdistance->access_list = NULL;
11704 }
11705 if (access_list_str)
11706 bdistance->access_list = strdup (access_list_str);
11707
11708 return CMD_SUCCESS;
11709}
11710
paul94f2b392005-06-28 12:44:16 +000011711static int
paulfd79ac92004-10-13 05:06:08 +000011712bgp_distance_unset (struct vty *vty, const char *distance_str,
11713 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011714{
11715 int ret;
11716 struct prefix_ipv4 p;
11717 u_char distance;
11718 struct bgp_node *rn;
11719 struct bgp_distance *bdistance;
11720
11721 ret = str2prefix_ipv4 (ip_str, &p);
11722 if (ret == 0)
11723 {
11724 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11725 return CMD_WARNING;
11726 }
11727
11728 distance = atoi (distance_str);
11729
11730 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11731 if (! rn)
11732 {
11733 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11734 return CMD_WARNING;
11735 }
11736
11737 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010011738
11739 if (bdistance->distance != distance)
11740 {
11741 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
11742 return CMD_WARNING;
11743 }
11744
paul718e3742002-12-13 20:15:29 +000011745 if (bdistance->access_list)
11746 free (bdistance->access_list);
11747 bgp_distance_free (bdistance);
11748
11749 rn->info = NULL;
11750 bgp_unlock_node (rn);
11751 bgp_unlock_node (rn);
11752
11753 return CMD_SUCCESS;
11754}
11755
paul718e3742002-12-13 20:15:29 +000011756/* Apply BGP information to distance method. */
11757u_char
11758bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11759{
11760 struct bgp_node *rn;
11761 struct prefix_ipv4 q;
11762 struct peer *peer;
11763 struct bgp_distance *bdistance;
11764 struct access_list *alist;
11765 struct bgp_static *bgp_static;
11766
11767 if (! bgp)
11768 return 0;
11769
11770 if (p->family != AF_INET)
11771 return 0;
11772
11773 peer = rinfo->peer;
11774
11775 if (peer->su.sa.sa_family != AF_INET)
11776 return 0;
11777
11778 memset (&q, 0, sizeof (struct prefix_ipv4));
11779 q.family = AF_INET;
11780 q.prefix = peer->su.sin.sin_addr;
11781 q.prefixlen = IPV4_MAX_BITLEN;
11782
11783 /* Check source address. */
11784 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11785 if (rn)
11786 {
11787 bdistance = rn->info;
11788 bgp_unlock_node (rn);
11789
11790 if (bdistance->access_list)
11791 {
11792 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11793 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11794 return bdistance->distance;
11795 }
11796 else
11797 return bdistance->distance;
11798 }
11799
11800 /* Backdoor check. */
11801 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11802 if (rn)
11803 {
11804 bgp_static = rn->info;
11805 bgp_unlock_node (rn);
11806
11807 if (bgp_static->backdoor)
11808 {
11809 if (bgp->distance_local)
11810 return bgp->distance_local;
11811 else
11812 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11813 }
11814 }
11815
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011816 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011817 {
11818 if (bgp->distance_ebgp)
11819 return bgp->distance_ebgp;
11820 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11821 }
11822 else
11823 {
11824 if (bgp->distance_ibgp)
11825 return bgp->distance_ibgp;
11826 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11827 }
11828}
11829
11830DEFUN (bgp_distance,
11831 bgp_distance_cmd,
11832 "distance bgp <1-255> <1-255> <1-255>",
11833 "Define an administrative distance\n"
11834 "BGP distance\n"
11835 "Distance for routes external to the AS\n"
11836 "Distance for routes internal to the AS\n"
11837 "Distance for local routes\n")
11838{
11839 struct bgp *bgp;
11840
11841 bgp = vty->index;
11842
11843 bgp->distance_ebgp = atoi (argv[0]);
11844 bgp->distance_ibgp = atoi (argv[1]);
11845 bgp->distance_local = atoi (argv[2]);
11846 return CMD_SUCCESS;
11847}
11848
11849DEFUN (no_bgp_distance,
11850 no_bgp_distance_cmd,
11851 "no distance bgp <1-255> <1-255> <1-255>",
11852 NO_STR
11853 "Define an administrative distance\n"
11854 "BGP distance\n"
11855 "Distance for routes external to the AS\n"
11856 "Distance for routes internal to the AS\n"
11857 "Distance for local routes\n")
11858{
11859 struct bgp *bgp;
11860
11861 bgp = vty->index;
11862
11863 bgp->distance_ebgp= 0;
11864 bgp->distance_ibgp = 0;
11865 bgp->distance_local = 0;
11866 return CMD_SUCCESS;
11867}
11868
11869ALIAS (no_bgp_distance,
11870 no_bgp_distance2_cmd,
11871 "no distance bgp",
11872 NO_STR
11873 "Define an administrative distance\n"
11874 "BGP distance\n")
11875
11876DEFUN (bgp_distance_source,
11877 bgp_distance_source_cmd,
11878 "distance <1-255> A.B.C.D/M",
11879 "Define an administrative distance\n"
11880 "Administrative distance\n"
11881 "IP source prefix\n")
11882{
11883 bgp_distance_set (vty, argv[0], argv[1], NULL);
11884 return CMD_SUCCESS;
11885}
11886
11887DEFUN (no_bgp_distance_source,
11888 no_bgp_distance_source_cmd,
11889 "no distance <1-255> A.B.C.D/M",
11890 NO_STR
11891 "Define an administrative distance\n"
11892 "Administrative distance\n"
11893 "IP source prefix\n")
11894{
11895 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11896 return CMD_SUCCESS;
11897}
11898
11899DEFUN (bgp_distance_source_access_list,
11900 bgp_distance_source_access_list_cmd,
11901 "distance <1-255> A.B.C.D/M WORD",
11902 "Define an administrative distance\n"
11903 "Administrative distance\n"
11904 "IP source prefix\n"
11905 "Access list name\n")
11906{
11907 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11908 return CMD_SUCCESS;
11909}
11910
11911DEFUN (no_bgp_distance_source_access_list,
11912 no_bgp_distance_source_access_list_cmd,
11913 "no distance <1-255> A.B.C.D/M WORD",
11914 NO_STR
11915 "Define an administrative distance\n"
11916 "Administrative distance\n"
11917 "IP source prefix\n"
11918 "Access list name\n")
11919{
11920 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11921 return CMD_SUCCESS;
11922}
David Lamparter6b0655a2014-06-04 06:53:35 +020011923
paul718e3742002-12-13 20:15:29 +000011924DEFUN (bgp_damp_set,
11925 bgp_damp_set_cmd,
11926 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11927 "BGP Specific commands\n"
11928 "Enable route-flap dampening\n"
11929 "Half-life time for the penalty\n"
11930 "Value to start reusing a route\n"
11931 "Value to start suppressing a route\n"
11932 "Maximum duration to suppress a stable route\n")
11933{
11934 struct bgp *bgp;
11935 int half = DEFAULT_HALF_LIFE * 60;
11936 int reuse = DEFAULT_REUSE;
11937 int suppress = DEFAULT_SUPPRESS;
11938 int max = 4 * half;
11939
11940 if (argc == 4)
11941 {
11942 half = atoi (argv[0]) * 60;
11943 reuse = atoi (argv[1]);
11944 suppress = atoi (argv[2]);
11945 max = atoi (argv[3]) * 60;
11946 }
11947 else if (argc == 1)
11948 {
11949 half = atoi (argv[0]) * 60;
11950 max = 4 * half;
11951 }
11952
11953 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000011954
11955 if (suppress < reuse)
11956 {
11957 vty_out (vty, "Suppress value cannot be less than reuse value %s",
11958 VTY_NEWLINE);
11959 return 0;
11960 }
11961
paul718e3742002-12-13 20:15:29 +000011962 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11963 half, reuse, suppress, max);
11964}
11965
11966ALIAS (bgp_damp_set,
11967 bgp_damp_set2_cmd,
11968 "bgp dampening <1-45>",
11969 "BGP Specific commands\n"
11970 "Enable route-flap dampening\n"
11971 "Half-life time for the penalty\n")
11972
11973ALIAS (bgp_damp_set,
11974 bgp_damp_set3_cmd,
11975 "bgp dampening",
11976 "BGP Specific commands\n"
11977 "Enable route-flap dampening\n")
11978
11979DEFUN (bgp_damp_unset,
11980 bgp_damp_unset_cmd,
11981 "no bgp dampening",
11982 NO_STR
11983 "BGP Specific commands\n"
11984 "Enable route-flap dampening\n")
11985{
11986 struct bgp *bgp;
11987
11988 bgp = vty->index;
11989 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11990}
11991
11992ALIAS (bgp_damp_unset,
11993 bgp_damp_unset2_cmd,
11994 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11995 NO_STR
11996 "BGP Specific commands\n"
11997 "Enable route-flap dampening\n"
11998 "Half-life time for the penalty\n"
11999 "Value to start reusing a route\n"
12000 "Value to start suppressing a route\n"
12001 "Maximum duration to suppress a stable route\n")
12002
12003DEFUN (show_ip_bgp_dampened_paths,
12004 show_ip_bgp_dampened_paths_cmd,
12005 "show ip bgp dampened-paths",
12006 SHOW_STR
12007 IP_STR
12008 BGP_STR
12009 "Display paths suppressed due to dampening\n")
12010{
ajs5a646652004-11-05 01:25:55 +000012011 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
12012 NULL);
paul718e3742002-12-13 20:15:29 +000012013}
12014
12015DEFUN (show_ip_bgp_flap_statistics,
12016 show_ip_bgp_flap_statistics_cmd,
12017 "show ip bgp flap-statistics",
12018 SHOW_STR
12019 IP_STR
12020 BGP_STR
12021 "Display flap statistics of routes\n")
12022{
ajs5a646652004-11-05 01:25:55 +000012023 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12024 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012025}
David Lamparter6b0655a2014-06-04 06:53:35 +020012026
paul718e3742002-12-13 20:15:29 +000012027/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012028static int
paulfd79ac92004-10-13 05:06:08 +000012029bgp_clear_damp_route (struct vty *vty, const char *view_name,
12030 const char *ip_str, afi_t afi, safi_t safi,
12031 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012032{
12033 int ret;
12034 struct prefix match;
12035 struct bgp_node *rn;
12036 struct bgp_node *rm;
12037 struct bgp_info *ri;
12038 struct bgp_info *ri_temp;
12039 struct bgp *bgp;
12040 struct bgp_table *table;
12041
12042 /* BGP structure lookup. */
12043 if (view_name)
12044 {
12045 bgp = bgp_lookup_by_name (view_name);
12046 if (bgp == NULL)
12047 {
12048 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12049 return CMD_WARNING;
12050 }
12051 }
12052 else
12053 {
12054 bgp = bgp_get_default ();
12055 if (bgp == NULL)
12056 {
12057 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12058 return CMD_WARNING;
12059 }
12060 }
12061
12062 /* Check IP address argument. */
12063 ret = str2prefix (ip_str, &match);
12064 if (! ret)
12065 {
12066 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12067 return CMD_WARNING;
12068 }
12069
12070 match.family = afi2family (afi);
12071
12072 if (safi == SAFI_MPLS_VPN)
12073 {
12074 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12075 {
12076 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12077 continue;
12078
12079 if ((table = rn->info) != NULL)
12080 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012081 {
12082 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12083 {
12084 ri = rm->info;
12085 while (ri)
12086 {
12087 if (ri->extra && ri->extra->damp_info)
12088 {
12089 ri_temp = ri->next;
12090 bgp_damp_info_free (ri->extra->damp_info, 1);
12091 ri = ri_temp;
12092 }
12093 else
12094 ri = ri->next;
12095 }
12096 }
12097
12098 bgp_unlock_node (rm);
12099 }
paul718e3742002-12-13 20:15:29 +000012100 }
12101 }
12102 else
12103 {
12104 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012105 {
12106 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12107 {
12108 ri = rn->info;
12109 while (ri)
12110 {
12111 if (ri->extra && ri->extra->damp_info)
12112 {
12113 ri_temp = ri->next;
12114 bgp_damp_info_free (ri->extra->damp_info, 1);
12115 ri = ri_temp;
12116 }
12117 else
12118 ri = ri->next;
12119 }
12120 }
12121
12122 bgp_unlock_node (rn);
12123 }
paul718e3742002-12-13 20:15:29 +000012124 }
12125
12126 return CMD_SUCCESS;
12127}
12128
12129DEFUN (clear_ip_bgp_dampening,
12130 clear_ip_bgp_dampening_cmd,
12131 "clear ip bgp dampening",
12132 CLEAR_STR
12133 IP_STR
12134 BGP_STR
12135 "Clear route flap dampening information\n")
12136{
12137 bgp_damp_info_clean ();
12138 return CMD_SUCCESS;
12139}
12140
12141DEFUN (clear_ip_bgp_dampening_prefix,
12142 clear_ip_bgp_dampening_prefix_cmd,
12143 "clear ip bgp dampening A.B.C.D/M",
12144 CLEAR_STR
12145 IP_STR
12146 BGP_STR
12147 "Clear route flap dampening information\n"
12148 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12149{
12150 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12151 SAFI_UNICAST, NULL, 1);
12152}
12153
12154DEFUN (clear_ip_bgp_dampening_address,
12155 clear_ip_bgp_dampening_address_cmd,
12156 "clear ip bgp dampening A.B.C.D",
12157 CLEAR_STR
12158 IP_STR
12159 BGP_STR
12160 "Clear route flap dampening information\n"
12161 "Network to clear damping information\n")
12162{
12163 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12164 SAFI_UNICAST, NULL, 0);
12165}
12166
12167DEFUN (clear_ip_bgp_dampening_address_mask,
12168 clear_ip_bgp_dampening_address_mask_cmd,
12169 "clear ip bgp dampening A.B.C.D A.B.C.D",
12170 CLEAR_STR
12171 IP_STR
12172 BGP_STR
12173 "Clear route flap dampening information\n"
12174 "Network to clear damping information\n"
12175 "Network mask\n")
12176{
12177 int ret;
12178 char prefix_str[BUFSIZ];
12179
12180 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12181 if (! ret)
12182 {
12183 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12184 return CMD_WARNING;
12185 }
12186
12187 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12188 SAFI_UNICAST, NULL, 0);
12189}
David Lamparter6b0655a2014-06-04 06:53:35 +020012190
paul94f2b392005-06-28 12:44:16 +000012191static int
paul718e3742002-12-13 20:15:29 +000012192bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12193 afi_t afi, safi_t safi, int *write)
12194{
12195 struct bgp_node *prn;
12196 struct bgp_node *rn;
12197 struct bgp_table *table;
12198 struct prefix *p;
12199 struct prefix_rd *prd;
12200 struct bgp_static *bgp_static;
12201 u_int32_t label;
12202 char buf[SU_ADDRSTRLEN];
12203 char rdbuf[RD_ADDRSTRLEN];
12204
12205 /* Network configuration. */
12206 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12207 if ((table = prn->info) != NULL)
12208 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12209 if ((bgp_static = rn->info) != NULL)
12210 {
12211 p = &rn->p;
12212 prd = (struct prefix_rd *) &prn->p;
12213
12214 /* "address-family" display. */
12215 bgp_config_write_family_header (vty, afi, safi, write);
12216
12217 /* "network" configuration display. */
12218 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12219 label = decode_label (bgp_static->tag);
12220
12221 vty_out (vty, " network %s/%d rd %s tag %d",
12222 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12223 p->prefixlen,
12224 rdbuf, label);
12225 vty_out (vty, "%s", VTY_NEWLINE);
12226 }
12227 return 0;
12228}
12229
12230/* Configuration of static route announcement and aggregate
12231 information. */
12232int
12233bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12234 afi_t afi, safi_t safi, int *write)
12235{
12236 struct bgp_node *rn;
12237 struct prefix *p;
12238 struct bgp_static *bgp_static;
12239 struct bgp_aggregate *bgp_aggregate;
12240 char buf[SU_ADDRSTRLEN];
12241
12242 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12243 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12244
12245 /* Network configuration. */
12246 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12247 if ((bgp_static = rn->info) != NULL)
12248 {
12249 p = &rn->p;
12250
12251 /* "address-family" display. */
12252 bgp_config_write_family_header (vty, afi, safi, write);
12253
12254 /* "network" configuration display. */
12255 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12256 {
12257 u_int32_t destination;
12258 struct in_addr netmask;
12259
12260 destination = ntohl (p->u.prefix4.s_addr);
12261 masklen2ip (p->prefixlen, &netmask);
12262 vty_out (vty, " network %s",
12263 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12264
12265 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12266 || (IN_CLASSB (destination) && p->prefixlen == 16)
12267 || (IN_CLASSA (destination) && p->prefixlen == 8)
12268 || p->u.prefix4.s_addr == 0)
12269 {
12270 /* Natural mask is not display. */
12271 }
12272 else
12273 vty_out (vty, " mask %s", inet_ntoa (netmask));
12274 }
12275 else
12276 {
12277 vty_out (vty, " network %s/%d",
12278 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12279 p->prefixlen);
12280 }
12281
12282 if (bgp_static->rmap.name)
12283 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012284 else
12285 {
12286 if (bgp_static->backdoor)
12287 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012288 }
paul718e3742002-12-13 20:15:29 +000012289
12290 vty_out (vty, "%s", VTY_NEWLINE);
12291 }
12292
12293 /* Aggregate-address configuration. */
12294 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12295 if ((bgp_aggregate = rn->info) != NULL)
12296 {
12297 p = &rn->p;
12298
12299 /* "address-family" display. */
12300 bgp_config_write_family_header (vty, afi, safi, write);
12301
12302 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12303 {
12304 struct in_addr netmask;
12305
12306 masklen2ip (p->prefixlen, &netmask);
12307 vty_out (vty, " aggregate-address %s %s",
12308 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12309 inet_ntoa (netmask));
12310 }
12311 else
12312 {
12313 vty_out (vty, " aggregate-address %s/%d",
12314 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12315 p->prefixlen);
12316 }
12317
12318 if (bgp_aggregate->as_set)
12319 vty_out (vty, " as-set");
12320
12321 if (bgp_aggregate->summary_only)
12322 vty_out (vty, " summary-only");
12323
12324 vty_out (vty, "%s", VTY_NEWLINE);
12325 }
12326
12327 return 0;
12328}
12329
12330int
12331bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12332{
12333 struct bgp_node *rn;
12334 struct bgp_distance *bdistance;
12335
12336 /* Distance configuration. */
12337 if (bgp->distance_ebgp
12338 && bgp->distance_ibgp
12339 && bgp->distance_local
12340 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12341 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12342 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12343 vty_out (vty, " distance bgp %d %d %d%s",
12344 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12345 VTY_NEWLINE);
12346
12347 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12348 if ((bdistance = rn->info) != NULL)
12349 {
12350 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12351 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12352 bdistance->access_list ? bdistance->access_list : "",
12353 VTY_NEWLINE);
12354 }
12355
12356 return 0;
12357}
12358
12359/* Allocate routing table structure and install commands. */
12360void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012361bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012362{
12363 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012364 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012365
12366 /* IPv4 BGP commands. */
12367 install_element (BGP_NODE, &bgp_network_cmd);
12368 install_element (BGP_NODE, &bgp_network_mask_cmd);
12369 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12370 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12371 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12372 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12373 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12374 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12375 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12376 install_element (BGP_NODE, &no_bgp_network_cmd);
12377 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12378 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12379 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12380 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12381 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12382 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12383 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12384 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12385
12386 install_element (BGP_NODE, &aggregate_address_cmd);
12387 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12388 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12389 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12390 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12391 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12392 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12393 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12394 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12395 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12396 install_element (BGP_NODE, &no_aggregate_address_cmd);
12397 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12398 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12399 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12400 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12401 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12402 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12403 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12404 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12405 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12406
12407 /* IPv4 unicast configuration. */
12408 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12409 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12410 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12411 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12412 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12413 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012414 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012415 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12416 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12417 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12418 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12419 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012420
paul718e3742002-12-13 20:15:29 +000012421 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12422 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12423 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12424 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12425 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12426 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12427 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12428 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12429 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12430 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12431 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12432 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12433 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12434 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12435 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12436 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12437 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12438 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12439 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12440 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12441
12442 /* IPv4 multicast configuration. */
12443 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12444 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12445 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12446 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12447 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12448 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12449 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12450 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12451 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12452 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12453 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12454 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12455 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12456 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12457 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12458 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12459 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12460 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12461 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12462 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12463 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12464 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12465 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12466 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12467 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12468 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12469 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12470 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12471 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12472 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12473 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12474 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12475
12476 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12477 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012478 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012479 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12480 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012481 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012482 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12483 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12484 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12485 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012486 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012487 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12488 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12489 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12490 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12491 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12492 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12493 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12494 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12495 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12496 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12497 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12498 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12499 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12500 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12501 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12502 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12503 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12504 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12505 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12506 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12507 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12508 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12509 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12510 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12511 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012512 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12513 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12514 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12515 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12516 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012517 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12518 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12519 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12520 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12521 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12522 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12523 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12524 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12525 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12526 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12527 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12528 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12529 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12530 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12531 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12532 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12533 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12534 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012535 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012536 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12537 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12538 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12539 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12540 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12541 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12542 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12543 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12544 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12545 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12546 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12547 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12548 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12549 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12550 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12551 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012552 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012553 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012554 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012555 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012556 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012557 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012558 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12559 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012560 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012561 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012562 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012563 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012564 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012565 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012566
12567 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12568 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12569 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012570 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012571 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12572 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12573 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012574 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012575 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12576 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12577 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12578 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12579 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12580 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12581 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12582 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12583 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12584 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12585 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12586 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012587 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12588 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12589 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12590 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12591 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012592 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12593 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12594 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12595 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12596 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12597 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12598 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12599 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12600 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012601 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012602 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012603 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012604 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012605 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012606 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012607 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012608
12609 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12610 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012611 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012612 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12613 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012614 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012615 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12616 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12617 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12618 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012619 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012620 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12621 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12622 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12623 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12624 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12625 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12626 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12627 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12628 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12629 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12630 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12631 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12632 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12633 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12634 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12635 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12636 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12637 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12638 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12639 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12640 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12641 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12642 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12643 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12644 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012645 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12646 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12647 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12648 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12649 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012650 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12651 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12652 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12653 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12654 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12655 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12656 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12657 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12658 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12659 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12660 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12661 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12662 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12663 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12664 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12665 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12666 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12667 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012668 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012669 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12670 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12671 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12672 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12673 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12674 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12675 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12676 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12677 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12678 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12679 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12680 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12681 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12682 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12683 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12684 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012685 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012686 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012687 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012688 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012689 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012690 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012691 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12692 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012693 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012694 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012695 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012696 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012697 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012698 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012699
12700 /* BGP dampening clear commands */
12701 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12702 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12703 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12704 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12705
Paul Jakmaff7924f2006-09-04 01:10:36 +000012706 /* prefix count */
12707 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12708 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12709 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012710#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012711 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12712
paul718e3742002-12-13 20:15:29 +000012713 /* New config IPv6 BGP commands. */
12714 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12715 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12716 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12717 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12718
12719 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12720 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12721 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12722 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12723
G.Balaji73bfe0b2011-09-23 22:36:20 +053012724 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12725 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12726
paul718e3742002-12-13 20:15:29 +000012727 /* Old config IPv6 BGP commands. */
12728 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12729 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12730
12731 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12732 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12733 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12734 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12735
12736 install_element (VIEW_NODE, &show_bgp_cmd);
12737 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012738 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012739 install_element (VIEW_NODE, &show_bgp_route_cmd);
12740 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012741 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012742 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12743 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012744 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012745 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12746 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12747 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12748 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12749 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12750 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12751 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12752 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12753 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12754 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12755 install_element (VIEW_NODE, &show_bgp_community_cmd);
12756 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12757 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12758 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12759 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12760 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12761 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12762 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12763 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12764 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12765 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12766 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12767 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12768 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12769 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12770 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12771 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12772 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12773 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12774 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12775 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12776 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12777 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12778 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12779 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12780 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12781 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12782 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12783 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12784 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012785 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12786 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12787 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12788 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012789 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012790 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012791 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012792 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012793 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012794 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012795 install_element (VIEW_NODE, &show_bgp_view_cmd);
12796 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12797 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12798 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12799 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12800 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12801 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12802 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12803 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12804 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12805 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12806 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12807 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12808 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12809 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12810 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12811 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12812 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012813 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012814 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012815 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012816 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012817 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012818 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012819
12820 /* Restricted:
12821 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12822 */
12823 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12824 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012825 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012826 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12827 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012828 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012829 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12830 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12831 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12832 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12833 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12834 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12835 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12836 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12837 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12838 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12839 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12840 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12841 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12842 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12843 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12844 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12845 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012846 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012847 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012848 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012849 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12850 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12851 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12852 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12853 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12854 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12855 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012856 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012857 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012858 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012859
12860 install_element (ENABLE_NODE, &show_bgp_cmd);
12861 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012862 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012863 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12864 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012865 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012866 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12867 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012868 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012869 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12870 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12871 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12872 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12873 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12874 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12875 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12876 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12877 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12878 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12879 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12880 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12881 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12882 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12883 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12884 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12885 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12886 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12887 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12888 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12889 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12890 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12891 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12892 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12893 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12894 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12895 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12896 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12897 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12898 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12899 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12900 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12901 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12902 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12903 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12904 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12905 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12906 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12907 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12908 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012909 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12910 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12911 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12912 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012913 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012914 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012915 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012916 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012917 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012918 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012919 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12920 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12921 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12922 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12923 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12924 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12925 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12926 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12927 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12928 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12929 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12930 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12931 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12932 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12933 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12934 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12935 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12936 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012937 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012938 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012939 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012940 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012941 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012942 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012943
12944 /* Statistics */
12945 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12946 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12947 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12948 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12949
paul718e3742002-12-13 20:15:29 +000012950 /* old command */
12951 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12952 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12953 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12954 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12955 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12956 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12957 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12958 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12959 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12960 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12961 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12962 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12963 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12964 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12965 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12966 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12967 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12968 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12969 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12970 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12971 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12972 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12973 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12974 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12975 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12976 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12977 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12978 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12979 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12980 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12981 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12982 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12983 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12984 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12985 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12986 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012987
paul718e3742002-12-13 20:15:29 +000012988 /* old command */
12989 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12990 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12991 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12992 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12993 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12994 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12995 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12996 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12997 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12998 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12999 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13000 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13001 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13002 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13003 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13004 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13005 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13006 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13007 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13008 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13009 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13010 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13011 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13012 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13013 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13014 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13015 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13016 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13017 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13018 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13019 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13020 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13021 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13022 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13023 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13024 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13025
13026 /* old command */
13027 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13028 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13029 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13030 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13031
13032 /* old command */
13033 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13034 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13035 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13036 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13037
13038 /* old command */
13039 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13040 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13041 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13042 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13043#endif /* HAVE_IPV6 */
13044
13045 install_element (BGP_NODE, &bgp_distance_cmd);
13046 install_element (BGP_NODE, &no_bgp_distance_cmd);
13047 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13048 install_element (BGP_NODE, &bgp_distance_source_cmd);
13049 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13050 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13051 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13052
13053 install_element (BGP_NODE, &bgp_damp_set_cmd);
13054 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13055 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13056 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13057 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13058 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13059 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13060 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13061 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13062 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013063
13064 /* Deprecated AS-Pathlimit commands */
13065 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13066 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13067 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13068 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13069 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13070 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13071
13072 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13073 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13074 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13075 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13076 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13077 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13078
13079 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13080 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13081 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13082 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13083 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13084 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13085
13086 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13087 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13088 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13089 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13090 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13091 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13092
13093 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13094 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13095 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13096 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13097 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13098 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13099
13100 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13101 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13102 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13103 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13104 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13105 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013106
13107#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013108 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13109 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013110#endif
paul718e3742002-12-13 20:15:29 +000013111}
Chris Caputo228da422009-07-18 05:44:03 +000013112
13113void
13114bgp_route_finish (void)
13115{
13116 bgp_table_unlock (bgp_distance_table);
13117 bgp_distance_table = NULL;
13118}