blob: 34ba1abe6a3d7c7cbcdfd05beba56cb4c204ece0 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* BGP routing information
2 Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
23#include "prefix.h"
24#include "linklist.h"
25#include "memory.h"
26#include "command.h"
27#include "stream.h"
28#include "filter.h"
29#include "str.h"
30#include "log.h"
31#include "routemap.h"
32#include "buffer.h"
33#include "sockunion.h"
34#include "plist.h"
35#include "thread.h"
paul200df112005-06-01 11:17:05 +000036#include "workqueue.h"
paul718e3742002-12-13 20:15:29 +000037
38#include "bgpd/bgpd.h"
39#include "bgpd/bgp_table.h"
40#include "bgpd/bgp_route.h"
41#include "bgpd/bgp_attr.h"
42#include "bgpd/bgp_debug.h"
43#include "bgpd/bgp_aspath.h"
44#include "bgpd/bgp_regex.h"
45#include "bgpd/bgp_community.h"
46#include "bgpd/bgp_ecommunity.h"
47#include "bgpd/bgp_clist.h"
48#include "bgpd/bgp_packet.h"
49#include "bgpd/bgp_filter.h"
50#include "bgpd/bgp_fsm.h"
51#include "bgpd/bgp_mplsvpn.h"
52#include "bgpd/bgp_nexthop.h"
53#include "bgpd/bgp_damp.h"
54#include "bgpd/bgp_advertise.h"
55#include "bgpd/bgp_zebra.h"
hasso0a486e52005-02-01 20:57:17 +000056#include "bgpd/bgp_vty.h"
Josh Bailey96450fa2011-07-20 20:45:12 -070057#include "bgpd/bgp_mpath.h"
paul718e3742002-12-13 20:15:29 +000058
59/* Extern from bgp_dump.c */
Stephen Hemmingerdde72582009-05-08 15:19:07 -070060extern const char *bgp_origin_str[];
61extern const char *bgp_origin_long_str[];
David Lamparter6b0655a2014-06-04 06:53:35 +020062
paul94f2b392005-06-28 12:44:16 +000063static struct bgp_node *
paulfee0f4c2004-09-13 05:12:46 +000064bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
paul718e3742002-12-13 20:15:29 +000065 struct prefix_rd *prd)
66{
67 struct bgp_node *rn;
68 struct bgp_node *prn = NULL;
Paul Jakmada5b30f2006-05-08 14:37:17 +000069
70 assert (table);
71 if (!table)
72 return NULL;
73
paul718e3742002-12-13 20:15:29 +000074 if (safi == SAFI_MPLS_VPN)
75 {
paulfee0f4c2004-09-13 05:12:46 +000076 prn = bgp_node_get (table, (struct prefix *) prd);
paul718e3742002-12-13 20:15:29 +000077
78 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +000079 prn->info = bgp_table_init (afi, safi);
paul718e3742002-12-13 20:15:29 +000080 else
81 bgp_unlock_node (prn);
82 table = prn->info;
83 }
paul718e3742002-12-13 20:15:29 +000084
85 rn = bgp_node_get (table, p);
86
87 if (safi == SAFI_MPLS_VPN)
88 rn->prn = prn;
89
90 return rn;
91}
David Lamparter6b0655a2014-06-04 06:53:35 +020092
Paul Jakmafb982c22007-05-04 20:15:47 +000093/* Allocate bgp_info_extra */
94static struct bgp_info_extra *
95bgp_info_extra_new (void)
96{
97 struct bgp_info_extra *new;
98 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
99 return new;
100}
101
102static void
103bgp_info_extra_free (struct bgp_info_extra **extra)
104{
105 if (extra && *extra)
106 {
107 if ((*extra)->damp_info)
108 bgp_damp_info_free ((*extra)->damp_info, 0);
109
110 (*extra)->damp_info = NULL;
111
112 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
113
114 *extra = NULL;
115 }
116}
117
118/* Get bgp_info extra information for the given bgp_info, lazy allocated
119 * if required.
120 */
121struct bgp_info_extra *
122bgp_info_extra_get (struct bgp_info *ri)
123{
124 if (!ri->extra)
125 ri->extra = bgp_info_extra_new();
126 return ri->extra;
127}
128
paul718e3742002-12-13 20:15:29 +0000129/* Allocate new bgp info structure. */
paul200df112005-06-01 11:17:05 +0000130static struct bgp_info *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -0800131bgp_info_new (void)
paul718e3742002-12-13 20:15:29 +0000132{
Stephen Hemminger393deb92008-08-18 14:13:29 -0700133 return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
paul718e3742002-12-13 20:15:29 +0000134}
135
136/* Free bgp route information. */
paul200df112005-06-01 11:17:05 +0000137static void
paul718e3742002-12-13 20:15:29 +0000138bgp_info_free (struct bgp_info *binfo)
139{
140 if (binfo->attr)
Paul Jakmaf6f434b2010-11-23 21:28:03 +0000141 bgp_attr_unintern (&binfo->attr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000142
143 bgp_info_extra_free (&binfo->extra);
Josh Baileyde8d5df2011-07-20 20:46:01 -0700144 bgp_info_mpath_free (&binfo->mpath);
paul718e3742002-12-13 20:15:29 +0000145
paul200df112005-06-01 11:17:05 +0000146 peer_unlock (binfo->peer); /* bgp_info peer reference */
147
paul718e3742002-12-13 20:15:29 +0000148 XFREE (MTYPE_BGP_ROUTE, binfo);
149}
150
paul200df112005-06-01 11:17:05 +0000151struct bgp_info *
152bgp_info_lock (struct bgp_info *binfo)
153{
154 binfo->lock++;
155 return binfo;
156}
157
158struct bgp_info *
159bgp_info_unlock (struct bgp_info *binfo)
160{
161 assert (binfo && binfo->lock > 0);
162 binfo->lock--;
163
164 if (binfo->lock == 0)
165 {
166#if 0
167 zlog_debug ("%s: unlocked and freeing", __func__);
168 zlog_backtrace (LOG_DEBUG);
169#endif
170 bgp_info_free (binfo);
171 return NULL;
172 }
173
174#if 0
175 if (binfo->lock == 1)
176 {
177 zlog_debug ("%s: unlocked to 1", __func__);
178 zlog_backtrace (LOG_DEBUG);
179 }
180#endif
181
182 return binfo;
183}
184
paul718e3742002-12-13 20:15:29 +0000185void
186bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
187{
188 struct bgp_info *top;
189
190 top = rn->info;
paul200df112005-06-01 11:17:05 +0000191
paul718e3742002-12-13 20:15:29 +0000192 ri->next = rn->info;
193 ri->prev = NULL;
194 if (top)
195 top->prev = ri;
196 rn->info = ri;
paul200df112005-06-01 11:17:05 +0000197
198 bgp_info_lock (ri);
199 bgp_lock_node (rn);
200 peer_lock (ri->peer); /* bgp_info peer reference */
paul718e3742002-12-13 20:15:29 +0000201}
202
paulb40d9392005-08-22 22:34:41 +0000203/* Do the actual removal of info from RIB, for use by bgp_process
204 completion callback *only* */
205static void
206bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
paul718e3742002-12-13 20:15:29 +0000207{
208 if (ri->next)
209 ri->next->prev = ri->prev;
210 if (ri->prev)
211 ri->prev->next = ri->next;
212 else
213 rn->info = ri->next;
paul200df112005-06-01 11:17:05 +0000214
Josh Baileyde8d5df2011-07-20 20:46:01 -0700215 bgp_info_mpath_dequeue (ri);
paul200df112005-06-01 11:17:05 +0000216 bgp_info_unlock (ri);
217 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000218}
219
paulb40d9392005-08-22 22:34:41 +0000220void
221bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
222{
Paul Jakma1a392d42006-09-07 00:24:49 +0000223 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
224 /* set of previous already took care of pcount */
paulb40d9392005-08-22 22:34:41 +0000225 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
226}
227
Andrew J. Schorr8d452102006-11-28 19:50:46 +0000228/* undo the effects of a previous call to bgp_info_delete; typically
229 called when a route is deleted and then quickly re-added before the
230 deletion has been processed */
231static void
232bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
233{
234 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
235 /* unset of previous already took care of pcount */
236 SET_FLAG (ri->flags, BGP_INFO_VALID);
237}
238
Paul Jakma1a392d42006-09-07 00:24:49 +0000239/* Adjust pcount as required */
240static void
241bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
242{
Avneesh Sachdev67174042012-08-17 08:19:49 -0700243 struct bgp_table *table;
244
245 assert (rn && bgp_node_table (rn));
Paul Jakma6f585442006-10-22 19:13:07 +0000246 assert (ri && ri->peer && ri->peer->bgp);
247
Avneesh Sachdev67174042012-08-17 08:19:49 -0700248 table = bgp_node_table (rn);
249
Paul Jakma1a392d42006-09-07 00:24:49 +0000250 /* Ignore 'pcount' for RS-client tables */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700251 if (table->type != BGP_TABLE_MAIN
Paul Jakma1a392d42006-09-07 00:24:49 +0000252 || ri->peer == ri->peer->bgp->peer_self)
253 return;
254
255 if (BGP_INFO_HOLDDOWN (ri)
256 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
257 {
258
259 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
260
261 /* slight hack, but more robust against errors. */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700262 if (ri->peer->pcount[table->afi][table->safi])
263 ri->peer->pcount[table->afi][table->safi]--;
Paul Jakma1a392d42006-09-07 00:24:49 +0000264 else
265 {
266 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
267 __func__, ri->peer->host);
268 zlog_backtrace (LOG_WARNING);
269 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
270 }
271 }
272 else if (!BGP_INFO_HOLDDOWN (ri)
273 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
274 {
275 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
Avneesh Sachdev67174042012-08-17 08:19:49 -0700276 ri->peer->pcount[table->afi][table->safi]++;
Paul Jakma1a392d42006-09-07 00:24:49 +0000277 }
278}
279
280
281/* Set/unset bgp_info flags, adjusting any other state as needed.
282 * This is here primarily to keep prefix-count in check.
283 */
284void
285bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
286{
287 SET_FLAG (ri->flags, flag);
288
289 /* early bath if we know it's not a flag that changes useability state */
290 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
291 return;
292
293 bgp_pcount_adjust (rn, ri);
294}
295
296void
297bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
298{
299 UNSET_FLAG (ri->flags, flag);
300
301 /* early bath if we know it's not a flag that changes useability state */
302 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
303 return;
304
305 bgp_pcount_adjust (rn, ri);
306}
307
paul718e3742002-12-13 20:15:29 +0000308/* Get MED value. If MED value is missing and "bgp bestpath
309 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000310static u_int32_t
paul718e3742002-12-13 20:15:29 +0000311bgp_med_value (struct attr *attr, struct bgp *bgp)
312{
313 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
314 return attr->med;
315 else
316 {
317 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000318 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000319 else
320 return 0;
321 }
322}
323
324/* Compare two bgp route entity. br is preferable then return 1. */
paul94f2b392005-06-28 12:44:16 +0000325static int
Josh Bailey96450fa2011-07-20 20:45:12 -0700326bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
327 int *paths_eq)
paul718e3742002-12-13 20:15:29 +0000328{
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000329 struct attr *newattr, *existattr;
330 struct attr_extra *newattre, *existattre;
331 bgp_peer_sort_t new_sort;
332 bgp_peer_sort_t exist_sort;
paul718e3742002-12-13 20:15:29 +0000333 u_int32_t new_pref;
334 u_int32_t exist_pref;
335 u_int32_t new_med;
336 u_int32_t exist_med;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000337 u_int32_t new_weight;
338 u_int32_t exist_weight;
339 uint32_t newm, existm;
paul718e3742002-12-13 20:15:29 +0000340 struct in_addr new_id;
341 struct in_addr exist_id;
342 int new_cluster;
343 int exist_cluster;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000344 int internal_as_route;
345 int confed_as_route;
paul718e3742002-12-13 20:15:29 +0000346 int ret;
Josh Bailey96450fa2011-07-20 20:45:12 -0700347
348 *paths_eq = 0;
paul718e3742002-12-13 20:15:29 +0000349
350 /* 0. Null check. */
351 if (new == NULL)
352 return 0;
353 if (exist == NULL)
354 return 1;
355
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000356 newattr = new->attr;
357 existattr = exist->attr;
358 newattre = newattr->extra;
359 existattre = existattr->extra;
360
paul718e3742002-12-13 20:15:29 +0000361 /* 1. Weight check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000362 new_weight = exist_weight = 0;
363
364 if (newattre)
365 new_weight = newattre->weight;
366 if (existattre)
367 exist_weight = existattre->weight;
368
Paul Jakmafb982c22007-05-04 20:15:47 +0000369 if (new_weight > exist_weight)
paul718e3742002-12-13 20:15:29 +0000370 return 1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000371 if (new_weight < exist_weight)
paul718e3742002-12-13 20:15:29 +0000372 return 0;
373
374 /* 2. Local preference check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000375 new_pref = exist_pref = bgp->default_local_pref;
paul718e3742002-12-13 20:15:29 +0000376
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000377 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
378 new_pref = newattr->local_pref;
379 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
380 exist_pref = existattr->local_pref;
381
paul718e3742002-12-13 20:15:29 +0000382 if (new_pref > exist_pref)
383 return 1;
384 if (new_pref < exist_pref)
385 return 0;
386
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000387 /* 3. Local route check. We prefer:
388 * - BGP_ROUTE_STATIC
389 * - BGP_ROUTE_AGGREGATE
390 * - BGP_ROUTE_REDISTRIBUTE
391 */
392 if (! (new->sub_type == BGP_ROUTE_NORMAL))
393 return 1;
394 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
395 return 0;
paul718e3742002-12-13 20:15:29 +0000396
397 /* 4. AS path length check. */
398 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
399 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000400 int exist_hops = aspath_count_hops (existattr->aspath);
401 int exist_confeds = aspath_count_confeds (existattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000402
hasso68118452005-04-08 15:40:36 +0000403 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
404 {
paulfe69a502005-09-10 16:55:02 +0000405 int aspath_hops;
406
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000407 aspath_hops = aspath_count_hops (newattr->aspath);
408 aspath_hops += aspath_count_confeds (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000409
410 if ( aspath_hops < (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000411 return 1;
paulfe69a502005-09-10 16:55:02 +0000412 if ( aspath_hops > (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000413 return 0;
414 }
415 else
416 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000417 int newhops = aspath_count_hops (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000418
419 if (newhops < exist_hops)
hasso68118452005-04-08 15:40:36 +0000420 return 1;
paulfe69a502005-09-10 16:55:02 +0000421 if (newhops > exist_hops)
hasso68118452005-04-08 15:40:36 +0000422 return 0;
423 }
paul718e3742002-12-13 20:15:29 +0000424 }
425
426 /* 5. Origin check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000427 if (newattr->origin < existattr->origin)
paul718e3742002-12-13 20:15:29 +0000428 return 1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000429 if (newattr->origin > existattr->origin)
paul718e3742002-12-13 20:15:29 +0000430 return 0;
431
432 /* 6. MED check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000433 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
434 && aspath_count_hops (existattr->aspath) == 0);
435 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
436 && aspath_count_confeds (existattr->aspath) > 0
437 && aspath_count_hops (newattr->aspath) == 0
438 && aspath_count_hops (existattr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000439
440 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
441 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
442 && confed_as_route)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000443 || aspath_cmp_left (newattr->aspath, existattr->aspath)
444 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
paul718e3742002-12-13 20:15:29 +0000445 || internal_as_route)
446 {
447 new_med = bgp_med_value (new->attr, bgp);
448 exist_med = bgp_med_value (exist->attr, bgp);
449
450 if (new_med < exist_med)
451 return 1;
452 if (new_med > exist_med)
453 return 0;
454 }
455
456 /* 7. Peer type check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000457 new_sort = new->peer->sort;
458 exist_sort = exist->peer->sort;
459
460 if (new_sort == BGP_PEER_EBGP
461 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
paul718e3742002-12-13 20:15:29 +0000462 return 1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000463 if (exist_sort == BGP_PEER_EBGP
464 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
paul718e3742002-12-13 20:15:29 +0000465 return 0;
466
467 /* 8. IGP metric check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000468 newm = existm = 0;
469
470 if (new->extra)
471 newm = new->extra->igpmetric;
472 if (exist->extra)
473 existm = exist->extra->igpmetric;
474
Josh Bailey96450fa2011-07-20 20:45:12 -0700475 if (newm < existm)
476 ret = 1;
477 if (newm > existm)
478 ret = 0;
paul718e3742002-12-13 20:15:29 +0000479
480 /* 9. Maximum path check. */
Josh Bailey96450fa2011-07-20 20:45:12 -0700481 if (newm == existm)
482 {
Pradosh Mohapatra2fdd4552013-09-07 07:02:36 +0000483 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
484 {
485
486 /*
487 * For the two paths, all comparison steps till IGP metric
488 * have succeeded - including AS_PATH hop count. Since 'bgp
489 * bestpath as-path multipath-relax' knob is on, we don't need
490 * an exact match of AS_PATH. Thus, mark the paths are equal.
491 * That will trigger both these paths to get into the multipath
492 * array.
493 */
494 *paths_eq = 1;
495 }
496 else if (new->peer->sort == BGP_PEER_IBGP)
Josh Bailey96450fa2011-07-20 20:45:12 -0700497 {
498 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
499 *paths_eq = 1;
500 }
501 else if (new->peer->as == exist->peer->as)
502 *paths_eq = 1;
503 }
504 else
505 {
506 /*
507 * TODO: If unequal cost ibgp multipath is enabled we can
508 * mark the paths as equal here instead of returning
509 */
510 return ret;
511 }
paul718e3742002-12-13 20:15:29 +0000512
513 /* 10. If both paths are external, prefer the path that was received
514 first (the oldest one). This step minimizes route-flap, since a
515 newer path won't displace an older one, even if it was the
516 preferred route based on the additional decision criteria below. */
517 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000518 && new_sort == BGP_PEER_EBGP
519 && exist_sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +0000520 {
521 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
522 return 1;
523 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
524 return 0;
525 }
526
527 /* 11. Rourter-ID comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000528 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
529 new_id.s_addr = newattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000530 else
531 new_id.s_addr = new->peer->remote_id.s_addr;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000532 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
533 exist_id.s_addr = existattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000534 else
535 exist_id.s_addr = exist->peer->remote_id.s_addr;
536
537 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
538 return 1;
539 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
540 return 0;
541
542 /* 12. Cluster length comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000543 new_cluster = exist_cluster = 0;
544
545 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
546 new_cluster = newattre->cluster->length;
547 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
548 exist_cluster = existattre->cluster->length;
paul718e3742002-12-13 20:15:29 +0000549
550 if (new_cluster < exist_cluster)
551 return 1;
552 if (new_cluster > exist_cluster)
553 return 0;
554
555 /* 13. Neighbor address comparision. */
556 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
557
558 if (ret == 1)
559 return 0;
560 if (ret == -1)
561 return 1;
562
563 return 1;
564}
565
paul94f2b392005-06-28 12:44:16 +0000566static enum filter_type
paul718e3742002-12-13 20:15:29 +0000567bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
568 afi_t afi, safi_t safi)
569{
570 struct bgp_filter *filter;
571
572 filter = &peer->filter[afi][safi];
573
Paul Jakma650f76c2009-06-25 18:06:31 +0100574#define FILTER_EXIST_WARN(F,f,filter) \
575 if (BGP_DEBUG (update, UPDATE_IN) \
576 && !(F ## _IN (filter))) \
577 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
578 peer->host, #f, F ## _IN_NAME(filter));
579
580 if (DISTRIBUTE_IN_NAME (filter)) {
581 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
582
paul718e3742002-12-13 20:15:29 +0000583 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
584 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100585 }
paul718e3742002-12-13 20:15:29 +0000586
Paul Jakma650f76c2009-06-25 18:06:31 +0100587 if (PREFIX_LIST_IN_NAME (filter)) {
588 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
589
paul718e3742002-12-13 20:15:29 +0000590 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
591 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100592 }
paul718e3742002-12-13 20:15:29 +0000593
Paul Jakma650f76c2009-06-25 18:06:31 +0100594 if (FILTER_LIST_IN_NAME (filter)) {
595 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
596
paul718e3742002-12-13 20:15:29 +0000597 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
598 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100599 }
600
paul718e3742002-12-13 20:15:29 +0000601 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100602#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000603}
604
paul94f2b392005-06-28 12:44:16 +0000605static enum filter_type
paul718e3742002-12-13 20:15:29 +0000606bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
607 afi_t afi, safi_t safi)
608{
609 struct bgp_filter *filter;
610
611 filter = &peer->filter[afi][safi];
612
Paul Jakma650f76c2009-06-25 18:06:31 +0100613#define FILTER_EXIST_WARN(F,f,filter) \
614 if (BGP_DEBUG (update, UPDATE_OUT) \
615 && !(F ## _OUT (filter))) \
616 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
617 peer->host, #f, F ## _OUT_NAME(filter));
618
619 if (DISTRIBUTE_OUT_NAME (filter)) {
620 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
621
paul718e3742002-12-13 20:15:29 +0000622 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
623 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100624 }
paul718e3742002-12-13 20:15:29 +0000625
Paul Jakma650f76c2009-06-25 18:06:31 +0100626 if (PREFIX_LIST_OUT_NAME (filter)) {
627 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
628
paul718e3742002-12-13 20:15:29 +0000629 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
630 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100631 }
paul718e3742002-12-13 20:15:29 +0000632
Paul Jakma650f76c2009-06-25 18:06:31 +0100633 if (FILTER_LIST_OUT_NAME (filter)) {
634 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
635
paul718e3742002-12-13 20:15:29 +0000636 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
637 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100638 }
paul718e3742002-12-13 20:15:29 +0000639
640 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100641#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000642}
643
644/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000645static int
paul718e3742002-12-13 20:15:29 +0000646bgp_community_filter (struct peer *peer, struct attr *attr)
647{
648 if (attr->community)
649 {
650 /* NO_ADVERTISE check. */
651 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
652 return 1;
653
654 /* NO_EXPORT check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000655 if (peer->sort == BGP_PEER_EBGP &&
paul718e3742002-12-13 20:15:29 +0000656 community_include (attr->community, COMMUNITY_NO_EXPORT))
657 return 1;
658
659 /* NO_EXPORT_SUBCONFED check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000660 if (peer->sort == BGP_PEER_EBGP
661 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000662 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
663 return 1;
664 }
665 return 0;
666}
667
668/* Route reflection loop check. */
669static int
670bgp_cluster_filter (struct peer *peer, struct attr *attr)
671{
672 struct in_addr cluster_id;
673
Paul Jakmafb982c22007-05-04 20:15:47 +0000674 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000675 {
676 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
677 cluster_id = peer->bgp->cluster_id;
678 else
679 cluster_id = peer->bgp->router_id;
680
Paul Jakmafb982c22007-05-04 20:15:47 +0000681 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000682 return 1;
683 }
684 return 0;
685}
David Lamparter6b0655a2014-06-04 06:53:35 +0200686
paul94f2b392005-06-28 12:44:16 +0000687static int
paul718e3742002-12-13 20:15:29 +0000688bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
689 afi_t afi, safi_t safi)
690{
691 struct bgp_filter *filter;
692 struct bgp_info info;
693 route_map_result_t ret;
694
695 filter = &peer->filter[afi][safi];
696
697 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000698 if (peer->weight)
699 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000700
701 /* Route map apply. */
702 if (ROUTE_MAP_IN_NAME (filter))
703 {
704 /* Duplicate current value to new strucutre for modification. */
705 info.peer = peer;
706 info.attr = attr;
707
paulac41b2a2003-08-12 05:32:27 +0000708 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
709
paul718e3742002-12-13 20:15:29 +0000710 /* Apply BGP route map to the attribute. */
711 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000712
713 peer->rmap_type = 0;
714
paul718e3742002-12-13 20:15:29 +0000715 if (ret == RMAP_DENYMATCH)
David Lamparterc460e572014-06-04 00:54:58 +0200716 /* caller has multiple error paths with bgp_attr_flush() */
717 return RMAP_DENY;
paul718e3742002-12-13 20:15:29 +0000718 }
719 return RMAP_PERMIT;
720}
David Lamparter6b0655a2014-06-04 06:53:35 +0200721
paul94f2b392005-06-28 12:44:16 +0000722static int
paulfee0f4c2004-09-13 05:12:46 +0000723bgp_export_modifier (struct peer *rsclient, struct peer *peer,
724 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
725{
726 struct bgp_filter *filter;
727 struct bgp_info info;
728 route_map_result_t ret;
729
730 filter = &peer->filter[afi][safi];
731
732 /* Route map apply. */
733 if (ROUTE_MAP_EXPORT_NAME (filter))
734 {
735 /* Duplicate current value to new strucutre for modification. */
736 info.peer = rsclient;
737 info.attr = attr;
738
739 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
740
741 /* Apply BGP route map to the attribute. */
742 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
743
744 rsclient->rmap_type = 0;
745
746 if (ret == RMAP_DENYMATCH)
747 {
748 /* Free newly generated AS path and community by route-map. */
749 bgp_attr_flush (attr);
750 return RMAP_DENY;
751 }
752 }
753 return RMAP_PERMIT;
754}
755
paul94f2b392005-06-28 12:44:16 +0000756static int
paulfee0f4c2004-09-13 05:12:46 +0000757bgp_import_modifier (struct peer *rsclient, struct peer *peer,
758 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
759{
760 struct bgp_filter *filter;
761 struct bgp_info info;
762 route_map_result_t ret;
763
764 filter = &rsclient->filter[afi][safi];
765
766 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000767 if (peer->weight)
768 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000769
770 /* Route map apply. */
771 if (ROUTE_MAP_IMPORT_NAME (filter))
772 {
773 /* Duplicate current value to new strucutre for modification. */
774 info.peer = peer;
775 info.attr = attr;
776
777 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
778
779 /* Apply BGP route map to the attribute. */
780 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
781
782 peer->rmap_type = 0;
783
784 if (ret == RMAP_DENYMATCH)
785 {
786 /* Free newly generated AS path and community by route-map. */
787 bgp_attr_flush (attr);
788 return RMAP_DENY;
789 }
790 }
791 return RMAP_PERMIT;
792}
David Lamparter6b0655a2014-06-04 06:53:35 +0200793
paul94f2b392005-06-28 12:44:16 +0000794static int
paul718e3742002-12-13 20:15:29 +0000795bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
796 struct attr *attr, afi_t afi, safi_t safi)
797{
798 int ret;
799 char buf[SU_ADDRSTRLEN];
800 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000801 struct peer *from;
802 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000803 int transparent;
804 int reflect;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700805 struct attr *riattr;
paul718e3742002-12-13 20:15:29 +0000806
807 from = ri->peer;
808 filter = &peer->filter[afi][safi];
809 bgp = peer->bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700810 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paul718e3742002-12-13 20:15:29 +0000811
Paul Jakma750e8142008-07-22 21:11:48 +0000812 if (DISABLE_BGP_ANNOUNCE)
813 return 0;
paul718e3742002-12-13 20:15:29 +0000814
paulfee0f4c2004-09-13 05:12:46 +0000815 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
816 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
817 return 0;
818
paul718e3742002-12-13 20:15:29 +0000819 /* Do not send back route to sender. */
820 if (from == peer)
821 return 0;
822
823 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000824 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000825 if (! UNSUPPRESS_MAP_NAME (filter))
826 return 0;
827
828 /* Default route check. */
829 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
830 {
831 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
832 return 0;
833#ifdef HAVE_IPV6
834 else if (p->family == AF_INET6 && p->prefixlen == 0)
835 return 0;
836#endif /* HAVE_IPV6 */
837 }
838
paul286e1e72003-08-08 00:24:31 +0000839 /* Transparency check. */
840 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
841 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
842 transparent = 1;
843 else
844 transparent = 0;
845
paul718e3742002-12-13 20:15:29 +0000846 /* If community is not disabled check the no-export and local. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700847 if (! transparent && bgp_community_filter (peer, riattr))
paul718e3742002-12-13 20:15:29 +0000848 return 0;
849
850 /* If the attribute has originator-id and it is same as remote
851 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700852 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paul718e3742002-12-13 20:15:29 +0000853 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700854 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000855 {
856 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000857 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000858 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
859 peer->host,
860 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
861 p->prefixlen);
862 return 0;
863 }
864 }
865
866 /* ORF prefix-list filter check */
867 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
868 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
869 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
870 if (peer->orf_plist[afi][safi])
871 {
872 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
873 return 0;
874 }
875
876 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700877 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
paul718e3742002-12-13 20:15:29 +0000878 {
879 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000880 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000881 "%s [Update:SEND] %s/%d is filtered",
882 peer->host,
883 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
884 p->prefixlen);
885 return 0;
886 }
887
888#ifdef BGP_SEND_ASPATH_CHECK
889 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700890 if (aspath_loop_check (riattr->aspath, peer->as))
paul718e3742002-12-13 20:15:29 +0000891 {
892 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000893 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400894 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000895 peer->host, peer->as);
896 return 0;
897 }
898#endif /* BGP_SEND_ASPATH_CHECK */
899
900 /* If we're a CONFED we need to loop check the CONFED ID too */
901 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
902 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700903 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
paul718e3742002-12-13 20:15:29 +0000904 {
905 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000906 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400907 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000908 peer->host,
909 bgp->confed_id);
910 return 0;
911 }
912 }
913
914 /* Route-Reflect check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000915 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +0000916 reflect = 1;
917 else
918 reflect = 0;
919
920 /* IBGP reflection check. */
921 if (reflect)
922 {
923 /* A route from a Client peer. */
924 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
925 {
926 /* Reflect to all the Non-Client peers and also to the
927 Client peers other than the originator. Originator check
928 is already done. So there is noting to do. */
929 /* no bgp client-to-client reflection check. */
930 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
931 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
932 return 0;
933 }
934 else
935 {
936 /* A route from a Non-client peer. Reflect to all other
937 clients. */
938 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
939 return 0;
940 }
941 }
Paul Jakma41367172007-08-06 15:24:51 +0000942
paul718e3742002-12-13 20:15:29 +0000943 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700944 bgp_attr_dup (attr, riattr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000945
paul718e3742002-12-13 20:15:29 +0000946 /* If local-preference is not set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000947 if ((peer->sort == BGP_PEER_IBGP
948 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000949 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
950 {
951 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
952 attr->local_pref = bgp->default_local_pref;
953 }
954
Pradosh Mohapatra689bb662013-09-07 07:13:37 +0000955 /* If originator-id is not set and the route is to be reflected,
956 set the originator id */
957 if (peer && from && peer->sort == BGP_PEER_IBGP &&
958 from->sort == BGP_PEER_IBGP &&
959 (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
960 {
961 attr->extra = bgp_attr_extra_get(attr);
962 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
963 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
964 }
965
paul718e3742002-12-13 20:15:29 +0000966 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000967 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000968 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
969 {
970 if (ri->peer != bgp->peer_self && ! transparent
971 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
972 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
973 }
974
975 /* next-hop-set */
Timo Teräs9e7a53c2014-04-24 10:22:37 +0300976 if (transparent
977 || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
paul718e3742002-12-13 20:15:29 +0000978 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
979 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000980#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000981 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000982 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000983#endif /* HAVE_IPV6 */
984 )))
paul718e3742002-12-13 20:15:29 +0000985 {
986 /* NEXT-HOP Unchanged. */
987 }
988 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
989 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
990#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000991 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000992 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000993#endif /* HAVE_IPV6 */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000994 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000995 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
996 {
997 /* Set IPv4 nexthop. */
998 if (p->family == AF_INET)
999 {
1000 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001001 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1002 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +00001003 else
1004 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1005 }
1006#ifdef HAVE_IPV6
1007 /* Set IPv6 nexthop. */
1008 if (p->family == AF_INET6)
1009 {
1010 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001011 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001012 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001013 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001014 }
1015#endif /* HAVE_IPV6 */
1016 }
1017
1018#ifdef HAVE_IPV6
1019 if (p->family == AF_INET6)
1020 {
paulfee0f4c2004-09-13 05:12:46 +00001021 /* Left nexthop_local unchanged if so configured. */
1022 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1023 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1024 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001025 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1026 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001027 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001028 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001029 }
1030
1031 /* Default nexthop_local treatment for non-RS-Clients */
1032 else
1033 {
paul718e3742002-12-13 20:15:29 +00001034 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001035 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001036
1037 /* Set link-local address for shared network peer. */
1038 if (peer->shared_network
1039 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1040 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001041 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001042 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001043 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001044 }
1045
1046 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1047 address.*/
1048 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001049 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001050
1051 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1052 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001053 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001054 }
paulfee0f4c2004-09-13 05:12:46 +00001055
1056 }
paul718e3742002-12-13 20:15:29 +00001057#endif /* HAVE_IPV6 */
1058
1059 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001060 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001061 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1062 && aspath_private_as_check (attr->aspath))
1063 attr->aspath = aspath_empty_get ();
1064
1065 /* Route map & unsuppress-map apply. */
1066 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001067 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001068 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001069 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001070 struct attr dummy_attr;
1071 struct attr_extra dummy_extra;
1072
1073 dummy_attr.extra = &dummy_extra;
1074
paul718e3742002-12-13 20:15:29 +00001075 info.peer = peer;
1076 info.attr = attr;
1077
1078 /* The route reflector is not allowed to modify the attributes
1079 of the reflected IBGP routes. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001080 if (from->sort == BGP_PEER_IBGP
1081 && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +00001082 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001083 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001084 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001085 }
paulac41b2a2003-08-12 05:32:27 +00001086
1087 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1088
Paul Jakmafb982c22007-05-04 20:15:47 +00001089 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001090 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1091 else
1092 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1093
paulac41b2a2003-08-12 05:32:27 +00001094 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001095
paul718e3742002-12-13 20:15:29 +00001096 if (ret == RMAP_DENYMATCH)
1097 {
1098 bgp_attr_flush (attr);
1099 return 0;
1100 }
1101 }
1102 return 1;
1103}
1104
paul94f2b392005-06-28 12:44:16 +00001105static int
paulfee0f4c2004-09-13 05:12:46 +00001106bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1107 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001108{
paulfee0f4c2004-09-13 05:12:46 +00001109 int ret;
1110 char buf[SU_ADDRSTRLEN];
1111 struct bgp_filter *filter;
1112 struct bgp_info info;
1113 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001114 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001115
1116 from = ri->peer;
1117 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001118 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001119
Paul Jakma750e8142008-07-22 21:11:48 +00001120 if (DISABLE_BGP_ANNOUNCE)
1121 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001122
1123 /* Do not send back route to sender. */
1124 if (from == rsclient)
1125 return 0;
1126
1127 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001128 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001129 if (! UNSUPPRESS_MAP_NAME (filter))
1130 return 0;
1131
1132 /* Default route check. */
1133 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1134 PEER_STATUS_DEFAULT_ORIGINATE))
1135 {
1136 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1137 return 0;
1138#ifdef HAVE_IPV6
1139 else if (p->family == AF_INET6 && p->prefixlen == 0)
1140 return 0;
1141#endif /* HAVE_IPV6 */
1142 }
1143
1144 /* If the attribute has originator-id and it is same as remote
1145 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001146 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001147 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001148 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001149 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001150 {
1151 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001152 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001153 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1154 rsclient->host,
1155 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1156 p->prefixlen);
1157 return 0;
1158 }
1159 }
1160
1161 /* ORF prefix-list filter check */
1162 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1163 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1164 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1165 if (rsclient->orf_plist[afi][safi])
1166 {
1167 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1168 return 0;
1169 }
1170
1171 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001172 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001173 {
1174 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001175 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001176 "%s [Update:SEND] %s/%d is filtered",
1177 rsclient->host,
1178 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1179 p->prefixlen);
1180 return 0;
1181 }
1182
1183#ifdef BGP_SEND_ASPATH_CHECK
1184 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001185 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001186 {
1187 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001188 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001189 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001190 rsclient->host, rsclient->as);
1191 return 0;
1192 }
1193#endif /* BGP_SEND_ASPATH_CHECK */
1194
1195 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001196 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001197
1198 /* next-hop-set */
1199 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1200#ifdef HAVE_IPV6
1201 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001202 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001203#endif /* HAVE_IPV6 */
1204 )
1205 {
1206 /* Set IPv4 nexthop. */
1207 if (p->family == AF_INET)
1208 {
1209 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001210 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001211 IPV4_MAX_BYTELEN);
1212 else
1213 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1214 }
1215#ifdef HAVE_IPV6
1216 /* Set IPv6 nexthop. */
1217 if (p->family == AF_INET6)
1218 {
1219 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001220 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001221 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001222 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001223 }
1224#endif /* HAVE_IPV6 */
1225 }
1226
1227#ifdef HAVE_IPV6
1228 if (p->family == AF_INET6)
1229 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001230 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001231
paulfee0f4c2004-09-13 05:12:46 +00001232 /* Left nexthop_local unchanged if so configured. */
1233 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1234 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1235 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001236 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1237 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001238 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001239 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001240 }
1241
1242 /* Default nexthop_local treatment for RS-Clients */
1243 else
1244 {
1245 /* Announcer and RS-Client are both in the same network */
1246 if (rsclient->shared_network && from->shared_network &&
1247 (rsclient->ifindex == from->ifindex))
1248 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001249 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1250 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001251 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001252 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001253 }
1254
1255 /* Set link-local address for shared network peer. */
1256 else if (rsclient->shared_network
1257 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1258 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001259 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001260 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001261 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001262 }
1263
1264 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001265 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001266 }
1267
1268 }
1269#endif /* HAVE_IPV6 */
1270
1271
1272 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001273 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001274 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1275 && aspath_private_as_check (attr->aspath))
1276 attr->aspath = aspath_empty_get ();
1277
1278 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001279 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001280 {
1281 info.peer = rsclient;
1282 info.attr = attr;
1283
1284 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1285
Paul Jakmafb982c22007-05-04 20:15:47 +00001286 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001287 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1288 else
1289 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1290
1291 rsclient->rmap_type = 0;
1292
1293 if (ret == RMAP_DENYMATCH)
1294 {
1295 bgp_attr_flush (attr);
1296 return 0;
1297 }
1298 }
1299
1300 return 1;
1301}
1302
1303struct bgp_info_pair
1304{
1305 struct bgp_info *old;
1306 struct bgp_info *new;
1307};
1308
paul94f2b392005-06-28 12:44:16 +00001309static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001310bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1311 struct bgp_maxpaths_cfg *mpath_cfg,
1312 struct bgp_info_pair *result)
paulfee0f4c2004-09-13 05:12:46 +00001313{
paul718e3742002-12-13 20:15:29 +00001314 struct bgp_info *new_select;
1315 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001316 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001317 struct bgp_info *ri1;
1318 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001319 struct bgp_info *nextri = NULL;
Josh Bailey96450fa2011-07-20 20:45:12 -07001320 int paths_eq, do_mpath;
1321 struct list mp_list;
1322
1323 bgp_mp_list_init (&mp_list);
1324 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1325 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1326
paul718e3742002-12-13 20:15:29 +00001327 /* bgp deterministic-med */
1328 new_select = NULL;
1329 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1330 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1331 {
1332 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1333 continue;
1334 if (BGP_INFO_HOLDDOWN (ri1))
1335 continue;
1336
1337 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001338 if (do_mpath)
1339 bgp_mp_list_add (&mp_list, ri1);
1340 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001341 if (ri1->next)
1342 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1343 {
1344 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1345 continue;
1346 if (BGP_INFO_HOLDDOWN (ri2))
1347 continue;
1348
1349 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1350 || aspath_cmp_left_confed (ri1->attr->aspath,
1351 ri2->attr->aspath))
1352 {
Josh Bailey6918e742011-07-20 20:48:20 -07001353 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1354 old_select = ri2;
Josh Bailey96450fa2011-07-20 20:45:12 -07001355 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
paul718e3742002-12-13 20:15:29 +00001356 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001357 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001358 new_select = ri2;
Josh Bailey6918e742011-07-20 20:48:20 -07001359 if (do_mpath && !paths_eq)
1360 {
1361 bgp_mp_list_clear (&mp_list);
1362 bgp_mp_list_add (&mp_list, ri2);
1363 }
paul718e3742002-12-13 20:15:29 +00001364 }
1365
Josh Bailey6918e742011-07-20 20:48:20 -07001366 if (do_mpath && paths_eq)
1367 bgp_mp_list_add (&mp_list, ri2);
1368
Paul Jakma1a392d42006-09-07 00:24:49 +00001369 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001370 }
1371 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001372 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1373 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001374
1375 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1376 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001377 }
1378
1379 /* Check old selected route and new selected route. */
1380 old_select = NULL;
1381 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001382 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001383 {
1384 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1385 old_select = ri;
1386
1387 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001388 {
1389 /* reap REMOVED routes, if needs be
1390 * selected route must stay for a while longer though
1391 */
1392 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1393 && (ri != old_select))
1394 bgp_info_reap (rn, ri);
1395
1396 continue;
1397 }
paul718e3742002-12-13 20:15:29 +00001398
1399 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1400 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1401 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001402 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001403 continue;
1404 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001405 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1406 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001407
Josh Bailey96450fa2011-07-20 20:45:12 -07001408 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1409 {
Josh Bailey6918e742011-07-20 20:48:20 -07001410 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1411 bgp_mp_dmed_deselect (new_select);
1412
Josh Bailey96450fa2011-07-20 20:45:12 -07001413 new_select = ri;
1414
1415 if (do_mpath && !paths_eq)
1416 {
1417 bgp_mp_list_clear (&mp_list);
1418 bgp_mp_list_add (&mp_list, ri);
1419 }
1420 }
Josh Bailey6918e742011-07-20 20:48:20 -07001421 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1422 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001423
1424 if (do_mpath && paths_eq)
1425 bgp_mp_list_add (&mp_list, ri);
paul718e3742002-12-13 20:15:29 +00001426 }
paulb40d9392005-08-22 22:34:41 +00001427
paulfee0f4c2004-09-13 05:12:46 +00001428
Josh Bailey6918e742011-07-20 20:48:20 -07001429 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1430 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
Josh Bailey96450fa2011-07-20 20:45:12 -07001431
Josh Bailey0b597ef2011-07-20 20:49:11 -07001432 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001433 bgp_mp_list_clear (&mp_list);
1434
1435 result->old = old_select;
1436 result->new = new_select;
1437
1438 return;
paulfee0f4c2004-09-13 05:12:46 +00001439}
1440
paul94f2b392005-06-28 12:44:16 +00001441static int
paulfee0f4c2004-09-13 05:12:46 +00001442bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001443 struct bgp_node *rn, afi_t afi, safi_t safi)
1444{
paulfee0f4c2004-09-13 05:12:46 +00001445 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001446 struct attr attr;
1447 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001448
1449 p = &rn->p;
1450
Paul Jakma9eda90c2007-08-30 13:36:17 +00001451 /* Announce route to Established peer. */
1452 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001453 return 0;
1454
Paul Jakma9eda90c2007-08-30 13:36:17 +00001455 /* Address family configuration check. */
1456 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001457 return 0;
1458
Paul Jakma9eda90c2007-08-30 13:36:17 +00001459 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001460 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1461 PEER_STATUS_ORF_WAIT_REFRESH))
1462 return 0;
1463
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001464 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1465 attr.extra = &extra;
1466
Avneesh Sachdev67174042012-08-17 08:19:49 -07001467 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001468 {
1469 case BGP_TABLE_MAIN:
1470 /* Announcement to peer->conf. If the route is filtered,
1471 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001472 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1473 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001474 else
1475 bgp_adj_out_unset (rn, peer, p, afi, safi);
1476 break;
1477 case BGP_TABLE_RSCLIENT:
1478 /* Announcement to peer->conf. If the route is filtered,
1479 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001480 if (selected &&
1481 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1482 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1483 else
1484 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001485 break;
1486 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001487
paulfee0f4c2004-09-13 05:12:46 +00001488 return 0;
paul200df112005-06-01 11:17:05 +00001489}
paulfee0f4c2004-09-13 05:12:46 +00001490
paul200df112005-06-01 11:17:05 +00001491struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001492{
paul200df112005-06-01 11:17:05 +00001493 struct bgp *bgp;
1494 struct bgp_node *rn;
1495 afi_t afi;
1496 safi_t safi;
1497};
1498
1499static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001500bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001501{
paul0fb58d52005-11-14 14:31:49 +00001502 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001503 struct bgp *bgp = pq->bgp;
1504 struct bgp_node *rn = pq->rn;
1505 afi_t afi = pq->afi;
1506 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001507 struct bgp_info *new_select;
1508 struct bgp_info *old_select;
1509 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001510 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001511 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001512
paulfee0f4c2004-09-13 05:12:46 +00001513 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001514 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001515 new_select = old_and_new.new;
1516 old_select = old_and_new.old;
1517
paul200df112005-06-01 11:17:05 +00001518 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1519 {
Chris Caputo228da422009-07-18 05:44:03 +00001520 if (rsclient->group)
1521 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1522 {
1523 /* Nothing to do. */
1524 if (old_select && old_select == new_select)
1525 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1526 continue;
paulfee0f4c2004-09-13 05:12:46 +00001527
Chris Caputo228da422009-07-18 05:44:03 +00001528 if (old_select)
1529 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1530 if (new_select)
1531 {
1532 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1533 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001534 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1535 }
paulfee0f4c2004-09-13 05:12:46 +00001536
Chris Caputo228da422009-07-18 05:44:03 +00001537 bgp_process_announce_selected (rsclient, new_select, rn,
1538 afi, safi);
1539 }
paul200df112005-06-01 11:17:05 +00001540 }
1541 else
1542 {
hassob7395792005-08-26 12:58:38 +00001543 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001544 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001545 if (new_select)
1546 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001547 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1548 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001549 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001550 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001551 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001552 }
paulfee0f4c2004-09-13 05:12:46 +00001553
paulb40d9392005-08-22 22:34:41 +00001554 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1555 bgp_info_reap (rn, old_select);
1556
paul200df112005-06-01 11:17:05 +00001557 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1558 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001559}
1560
paul200df112005-06-01 11:17:05 +00001561static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001562bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001563{
paul0fb58d52005-11-14 14:31:49 +00001564 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001565 struct bgp *bgp = pq->bgp;
1566 struct bgp_node *rn = pq->rn;
1567 afi_t afi = pq->afi;
1568 safi_t safi = pq->safi;
1569 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001570 struct bgp_info *new_select;
1571 struct bgp_info *old_select;
1572 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001573 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001574 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001575
paulfee0f4c2004-09-13 05:12:46 +00001576 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001577 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001578 old_select = old_and_new.old;
1579 new_select = old_and_new.new;
1580
1581 /* Nothing to do. */
1582 if (old_select && old_select == new_select)
1583 {
1584 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001585 {
Josh Bailey8196f132011-07-20 20:47:07 -07001586 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1587 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001588 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001589
Josh Bailey8196f132011-07-20 20:47:07 -07001590 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001591 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1592 return WQ_SUCCESS;
1593 }
paulfee0f4c2004-09-13 05:12:46 +00001594 }
paul718e3742002-12-13 20:15:29 +00001595
hasso338b3422005-02-23 14:27:24 +00001596 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001597 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001598 if (new_select)
1599 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001600 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1601 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001602 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001603 }
1604
1605
paul718e3742002-12-13 20:15:29 +00001606 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001607 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001608 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001609 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001610 }
1611
1612 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001613 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1614 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001615 {
1616 if (new_select
1617 && new_select->type == ZEBRA_ROUTE_BGP
1618 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001619 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001620 else
1621 {
1622 /* Withdraw the route from the kernel. */
1623 if (old_select
1624 && old_select->type == ZEBRA_ROUTE_BGP
1625 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001626 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001627 }
1628 }
paulb40d9392005-08-22 22:34:41 +00001629
1630 /* Reap old select bgp_info, it it has been removed */
1631 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1632 bgp_info_reap (rn, old_select);
1633
paul200df112005-06-01 11:17:05 +00001634 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1635 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001636}
1637
paul200df112005-06-01 11:17:05 +00001638static void
paul0fb58d52005-11-14 14:31:49 +00001639bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001640{
paul0fb58d52005-11-14 14:31:49 +00001641 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001642 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001643
Chris Caputo228da422009-07-18 05:44:03 +00001644 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001645 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001646 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001647 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1648}
1649
1650static void
1651bgp_process_queue_init (void)
1652{
1653 bm->process_main_queue
1654 = work_queue_new (bm->master, "process_main_queue");
1655 bm->process_rsclient_queue
1656 = work_queue_new (bm->master, "process_rsclient_queue");
1657
1658 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1659 {
1660 zlog_err ("%s: Failed to allocate work queue", __func__);
1661 exit (1);
1662 }
1663
1664 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001665 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001666 bm->process_main_queue->spec.max_retries = 0;
1667 bm->process_main_queue->spec.hold = 50;
1668
Paul Jakma838bbde2010-01-08 14:05:32 +00001669 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
David Lamparterd43f8b32015-03-03 08:54:54 +01001670 bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del;
1671 bm->process_rsclient_queue->spec.max_retries = 0;
1672 bm->process_rsclient_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001673}
1674
1675void
paulfee0f4c2004-09-13 05:12:46 +00001676bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1677{
paul200df112005-06-01 11:17:05 +00001678 struct bgp_process_queue *pqnode;
1679
1680 /* already scheduled for processing? */
1681 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1682 return;
1683
1684 if ( (bm->process_main_queue == NULL) ||
1685 (bm->process_rsclient_queue == NULL) )
1686 bgp_process_queue_init ();
1687
1688 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1689 sizeof (struct bgp_process_queue));
1690 if (!pqnode)
1691 return;
Chris Caputo228da422009-07-18 05:44:03 +00001692
1693 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001694 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001695 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001696 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001697 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001698 pqnode->afi = afi;
1699 pqnode->safi = safi;
1700
Avneesh Sachdev67174042012-08-17 08:19:49 -07001701 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001702 {
paul200df112005-06-01 11:17:05 +00001703 case BGP_TABLE_MAIN:
1704 work_queue_add (bm->process_main_queue, pqnode);
1705 break;
1706 case BGP_TABLE_RSCLIENT:
1707 work_queue_add (bm->process_rsclient_queue, pqnode);
1708 break;
paulfee0f4c2004-09-13 05:12:46 +00001709 }
paul200df112005-06-01 11:17:05 +00001710
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001711 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001712 return;
paulfee0f4c2004-09-13 05:12:46 +00001713}
hasso0a486e52005-02-01 20:57:17 +00001714
paul94f2b392005-06-28 12:44:16 +00001715static int
hasso0a486e52005-02-01 20:57:17 +00001716bgp_maximum_prefix_restart_timer (struct thread *thread)
1717{
1718 struct peer *peer;
1719
1720 peer = THREAD_ARG (thread);
1721 peer->t_pmax_restart = NULL;
1722
1723 if (BGP_DEBUG (events, EVENTS))
1724 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1725 peer->host);
1726
1727 peer_clear (peer);
1728
1729 return 0;
1730}
1731
paulfee0f4c2004-09-13 05:12:46 +00001732int
paul5228ad22004-06-04 17:58:18 +00001733bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1734 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001735{
hassoe0701b72004-05-20 09:19:34 +00001736 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1737 return 0;
1738
1739 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001740 {
hassoe0701b72004-05-20 09:19:34 +00001741 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1742 && ! always)
1743 return 0;
paul718e3742002-12-13 20:15:29 +00001744
hassoe0701b72004-05-20 09:19:34 +00001745 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001746 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1747 "limit %ld", afi_safi_print (afi, safi), peer->host,
1748 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001749 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001750
hassoe0701b72004-05-20 09:19:34 +00001751 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1752 return 0;
paul718e3742002-12-13 20:15:29 +00001753
hassoe0701b72004-05-20 09:19:34 +00001754 {
paul5228ad22004-06-04 17:58:18 +00001755 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001756
1757 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001758 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001759
1760 ndata[0] = (afi >> 8);
1761 ndata[1] = afi;
1762 ndata[2] = safi;
1763 ndata[3] = (peer->pmax[afi][safi] >> 24);
1764 ndata[4] = (peer->pmax[afi][safi] >> 16);
1765 ndata[5] = (peer->pmax[afi][safi] >> 8);
1766 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001767
1768 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1769 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1770 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1771 }
hasso0a486e52005-02-01 20:57:17 +00001772
1773 /* restart timer start */
1774 if (peer->pmax_restart[afi][safi])
1775 {
1776 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1777
1778 if (BGP_DEBUG (events, EVENTS))
1779 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1780 peer->host, peer->v_pmax_restart);
1781
1782 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1783 peer->v_pmax_restart);
1784 }
1785
hassoe0701b72004-05-20 09:19:34 +00001786 return 1;
paul718e3742002-12-13 20:15:29 +00001787 }
hassoe0701b72004-05-20 09:19:34 +00001788 else
1789 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1790
1791 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1792 {
1793 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1794 && ! always)
1795 return 0;
1796
1797 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001798 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1799 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1800 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001801 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1802 }
1803 else
1804 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001805 return 0;
1806}
1807
paulb40d9392005-08-22 22:34:41 +00001808/* Unconditionally remove the route from the RIB, without taking
1809 * damping into consideration (eg, because the session went down)
1810 */
paul94f2b392005-06-28 12:44:16 +00001811static void
paul718e3742002-12-13 20:15:29 +00001812bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1813 afi_t afi, safi_t safi)
1814{
paul902212c2006-02-05 17:51:19 +00001815 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1816
1817 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1818 bgp_info_delete (rn, ri); /* keep historical info */
1819
paulb40d9392005-08-22 22:34:41 +00001820 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001821}
1822
paul94f2b392005-06-28 12:44:16 +00001823static void
paul718e3742002-12-13 20:15:29 +00001824bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001825 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001826{
paul718e3742002-12-13 20:15:29 +00001827 int status = BGP_DAMP_NONE;
1828
paulb40d9392005-08-22 22:34:41 +00001829 /* apply dampening, if result is suppressed, we'll be retaining
1830 * the bgp_info in the RIB for historical reference.
1831 */
1832 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001833 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001834 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1835 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001836 {
paul902212c2006-02-05 17:51:19 +00001837 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1838 return;
1839 }
1840
1841 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001842}
1843
paul94f2b392005-06-28 12:44:16 +00001844static void
paulfee0f4c2004-09-13 05:12:46 +00001845bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1846 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1847 int sub_type, struct prefix_rd *prd, u_char *tag)
1848{
1849 struct bgp_node *rn;
1850 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001851 struct attr new_attr;
1852 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001853 struct attr *attr_new;
1854 struct attr *attr_new2;
1855 struct bgp_info *ri;
1856 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001857 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001858 char buf[SU_ADDRSTRLEN];
1859
1860 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1861 if (peer == rsclient)
1862 return;
1863
1864 bgp = peer->bgp;
1865 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1866
1867 /* Check previously received route. */
1868 for (ri = rn->info; ri; ri = ri->next)
1869 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1870 break;
1871
1872 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001873 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001874 {
1875 reason = "as-path contains our own AS;";
1876 goto filtered;
1877 }
1878
1879 /* Route reflector originator ID check. */
1880 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001881 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001882 {
1883 reason = "originator is us;";
1884 goto filtered;
1885 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001886
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001887 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001888 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001889
1890 /* Apply export policy. */
1891 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1892 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1893 {
1894 reason = "export-policy;";
1895 goto filtered;
1896 }
1897
1898 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001899
paulfee0f4c2004-09-13 05:12:46 +00001900 /* Apply import policy. */
1901 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1902 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001903 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001904
1905 reason = "import-policy;";
1906 goto filtered;
1907 }
1908
1909 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001910 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001911
1912 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001913 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001914 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001915 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001916 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001917 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001918 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001919 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001920
1921 reason = "martian next-hop;";
1922 goto filtered;
1923 }
1924 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001925
paulfee0f4c2004-09-13 05:12:46 +00001926 /* If the update is implicit withdraw. */
1927 if (ri)
1928 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001929 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001930
1931 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001932 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1933 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001934 {
1935
Paul Jakma1a392d42006-09-07 00:24:49 +00001936 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001937
1938 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001939 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001940 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1941 peer->host,
1942 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1943 p->prefixlen, rsclient->host);
1944
Chris Caputo228da422009-07-18 05:44:03 +00001945 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001946 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001947
Chris Caputo228da422009-07-18 05:44:03 +00001948 return;
paulfee0f4c2004-09-13 05:12:46 +00001949 }
1950
Paul Jakma16d2e242007-04-10 19:32:10 +00001951 /* Withdraw/Announce before we fully processed the withdraw */
1952 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1953 bgp_info_restore (rn, ri);
1954
paulfee0f4c2004-09-13 05:12:46 +00001955 /* Received Logging. */
1956 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001957 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001958 peer->host,
1959 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1960 p->prefixlen, rsclient->host);
1961
1962 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001963 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001964
1965 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001966 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001967 ri->attr = attr_new;
1968
1969 /* Update MPLS tag. */
1970 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001971 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001972
Paul Jakma1a392d42006-09-07 00:24:49 +00001973 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001974
1975 /* Process change. */
1976 bgp_process (bgp, rn, afi, safi);
1977 bgp_unlock_node (rn);
1978
1979 return;
1980 }
1981
1982 /* Received Logging. */
1983 if (BGP_DEBUG (update, UPDATE_IN))
1984 {
ajsd2c1f162004-12-08 21:10:20 +00001985 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001986 peer->host,
1987 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1988 p->prefixlen, rsclient->host);
1989 }
1990
1991 /* Make new BGP info. */
1992 new = bgp_info_new ();
1993 new->type = type;
1994 new->sub_type = sub_type;
1995 new->peer = peer;
1996 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03001997 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001998
1999 /* Update MPLS tag. */
2000 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002001 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002002
Paul Jakma1a392d42006-09-07 00:24:49 +00002003 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002004
2005 /* Register new BGP information. */
2006 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002007
2008 /* route_node_get lock */
2009 bgp_unlock_node (rn);
2010
paulfee0f4c2004-09-13 05:12:46 +00002011 /* Process change. */
2012 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002013
paulfee0f4c2004-09-13 05:12:46 +00002014 return;
2015
2016 filtered:
2017
2018 /* This BGP update is filtered. Log the reason then update BGP entry. */
2019 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002020 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002021 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2022 peer->host,
2023 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2024 p->prefixlen, rsclient->host, reason);
2025
2026 if (ri)
paulb40d9392005-08-22 22:34:41 +00002027 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002028
2029 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002030
paulfee0f4c2004-09-13 05:12:46 +00002031 return;
2032}
2033
paul94f2b392005-06-28 12:44:16 +00002034static void
paulfee0f4c2004-09-13 05:12:46 +00002035bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2036 struct peer *peer, struct prefix *p, int type, int sub_type,
2037 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002038{
paulfee0f4c2004-09-13 05:12:46 +00002039 struct bgp_node *rn;
2040 struct bgp_info *ri;
2041 char buf[SU_ADDRSTRLEN];
2042
2043 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002044 return;
paulfee0f4c2004-09-13 05:12:46 +00002045
2046 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2047
2048 /* Lookup withdrawn route. */
2049 for (ri = rn->info; ri; ri = ri->next)
2050 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2051 break;
2052
2053 /* Withdraw specified route from routing table. */
2054 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002055 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002056 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002057 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002058 "%s Can't find the route %s/%d", peer->host,
2059 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2060 p->prefixlen);
2061
2062 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002063 bgp_unlock_node (rn);
2064}
paulfee0f4c2004-09-13 05:12:46 +00002065
paul94f2b392005-06-28 12:44:16 +00002066static int
paulfee0f4c2004-09-13 05:12:46 +00002067bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002068 afi_t afi, safi_t safi, int type, int sub_type,
2069 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2070{
2071 int ret;
2072 int aspath_loop_count = 0;
2073 struct bgp_node *rn;
2074 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002075 struct attr new_attr;
2076 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002077 struct attr *attr_new;
2078 struct bgp_info *ri;
2079 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002080 const char *reason;
paul718e3742002-12-13 20:15:29 +00002081 char buf[SU_ADDRSTRLEN];
2082
2083 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002084 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002085
paul718e3742002-12-13 20:15:29 +00002086 /* When peer's soft reconfiguration enabled. Record input packet in
2087 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002088 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2089 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002090 bgp_adj_in_set (rn, peer, attr);
2091
2092 /* Check previously received route. */
2093 for (ri = rn->info; ri; ri = ri->next)
2094 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2095 break;
2096
2097 /* AS path local-as loop check. */
2098 if (peer->change_local_as)
2099 {
2100 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2101 aspath_loop_count = 1;
2102
2103 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2104 {
2105 reason = "as-path contains our own AS;";
2106 goto filtered;
2107 }
2108 }
2109
2110 /* AS path loop check. */
2111 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2112 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2113 && aspath_loop_check(attr->aspath, bgp->confed_id)
2114 > peer->allowas_in[afi][safi]))
2115 {
2116 reason = "as-path contains our own AS;";
2117 goto filtered;
2118 }
2119
2120 /* Route reflector originator ID check. */
2121 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002122 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002123 {
2124 reason = "originator is us;";
2125 goto filtered;
2126 }
2127
2128 /* Route reflector cluster ID check. */
2129 if (bgp_cluster_filter (peer, attr))
2130 {
2131 reason = "reflected from the same cluster;";
2132 goto filtered;
2133 }
2134
2135 /* Apply incoming filter. */
2136 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2137 {
2138 reason = "filter;";
2139 goto filtered;
2140 }
2141
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002142 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002143 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002144
David Lamparterc460e572014-06-04 00:54:58 +02002145 /* Apply incoming route-map.
2146 * NB: new_attr may now contain newly allocated values from route-map "set"
2147 * commands, so we need bgp_attr_flush in the error paths, until we intern
2148 * the attr (which takes over the memory references) */
paul718e3742002-12-13 20:15:29 +00002149 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2150 {
2151 reason = "route-map;";
David Lamparterc460e572014-06-04 00:54:58 +02002152 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002153 goto filtered;
2154 }
2155
2156 /* IPv4 unicast next hop check. */
2157 if (afi == AFI_IP && safi == SAFI_UNICAST)
2158 {
2159 /* If the peer is EBGP and nexthop is not on connected route,
2160 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002161 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002162 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002163 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002164 {
2165 reason = "non-connected next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002166 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002167 goto filtered;
2168 }
2169
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002170 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002171 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002172 if (new_attr.nexthop.s_addr == 0
2173 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2174 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002175 {
2176 reason = "martian next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002177 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002178 goto filtered;
2179 }
2180 }
2181
2182 attr_new = bgp_attr_intern (&new_attr);
2183
2184 /* If the update is implicit withdraw. */
2185 if (ri)
2186 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002187 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002188
2189 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002190 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2191 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002192 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002193 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002194
2195 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002196 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002197 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2198 {
2199 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002200 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002201 peer->host,
2202 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2203 p->prefixlen);
2204
paul902212c2006-02-05 17:51:19 +00002205 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2206 {
2207 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2208 bgp_process (bgp, rn, afi, safi);
2209 }
paul718e3742002-12-13 20:15:29 +00002210 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002211 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002212 {
2213 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002214 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002215 "%s rcvd %s/%d...duplicate ignored",
2216 peer->host,
2217 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2218 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002219
2220 /* graceful restart STALE flag unset. */
2221 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2222 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002223 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002224 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002225 }
paul718e3742002-12-13 20:15:29 +00002226 }
2227
2228 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002229 bgp_attr_unintern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002230
paul718e3742002-12-13 20:15:29 +00002231 return 0;
2232 }
2233
Paul Jakma16d2e242007-04-10 19:32:10 +00002234 /* Withdraw/Announce before we fully processed the withdraw */
2235 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2236 {
2237 if (BGP_DEBUG (update, UPDATE_IN))
2238 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2239 peer->host,
2240 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2241 p->prefixlen);
2242 bgp_info_restore (rn, ri);
2243 }
2244
paul718e3742002-12-13 20:15:29 +00002245 /* Received Logging. */
2246 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002247 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002248 peer->host,
2249 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2250 p->prefixlen);
2251
hasso93406d82005-02-02 14:40:33 +00002252 /* graceful restart STALE flag unset. */
2253 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002254 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002255
paul718e3742002-12-13 20:15:29 +00002256 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002257 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002258
2259 /* implicit withdraw, decrement aggregate and pcount here.
2260 * only if update is accepted, they'll increment below.
2261 */
paul902212c2006-02-05 17:51:19 +00002262 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2263
paul718e3742002-12-13 20:15:29 +00002264 /* Update bgp route dampening information. */
2265 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002266 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002267 {
2268 /* This is implicit withdraw so we should update dampening
2269 information. */
2270 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2271 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002272 }
2273
paul718e3742002-12-13 20:15:29 +00002274 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002275 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002276 ri->attr = attr_new;
2277
2278 /* Update MPLS tag. */
2279 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002280 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002281
2282 /* Update bgp route dampening information. */
2283 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002284 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002285 {
2286 /* Now we do normal update dampening. */
2287 ret = bgp_damp_update (ri, rn, afi, safi);
2288 if (ret == BGP_DAMP_SUPPRESSED)
2289 {
2290 bgp_unlock_node (rn);
2291 return 0;
2292 }
2293 }
2294
2295 /* Nexthop reachability check. */
2296 if ((afi == AFI_IP || afi == AFI_IP6)
2297 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002298 && (peer->sort == BGP_PEER_IBGP
2299 || peer->sort == BGP_PEER_CONFED
2300 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002301 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002302 {
2303 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002304 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002305 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002306 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002307 }
2308 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002309 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002310
2311 /* Process change. */
2312 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2313
2314 bgp_process (bgp, rn, afi, safi);
2315 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002316
paul718e3742002-12-13 20:15:29 +00002317 return 0;
2318 }
2319
2320 /* Received Logging. */
2321 if (BGP_DEBUG (update, UPDATE_IN))
2322 {
ajsd2c1f162004-12-08 21:10:20 +00002323 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002324 peer->host,
2325 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2326 p->prefixlen);
2327 }
2328
paul718e3742002-12-13 20:15:29 +00002329 /* Make new BGP info. */
2330 new = bgp_info_new ();
2331 new->type = type;
2332 new->sub_type = sub_type;
2333 new->peer = peer;
2334 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002335 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002336
2337 /* Update MPLS tag. */
2338 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002339 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002340
2341 /* Nexthop reachability check. */
2342 if ((afi == AFI_IP || afi == AFI_IP6)
2343 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002344 && (peer->sort == BGP_PEER_IBGP
2345 || peer->sort == BGP_PEER_CONFED
2346 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002347 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002348 {
2349 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002350 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002351 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002352 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002353 }
2354 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002355 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002356
paul902212c2006-02-05 17:51:19 +00002357 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002358 bgp_aggregate_increment (bgp, p, new, afi, safi);
2359
2360 /* Register new BGP information. */
2361 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002362
2363 /* route_node_get lock */
2364 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002365
paul718e3742002-12-13 20:15:29 +00002366 /* If maximum prefix count is configured and current prefix
2367 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002368 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2369 return -1;
paul718e3742002-12-13 20:15:29 +00002370
2371 /* Process change. */
2372 bgp_process (bgp, rn, afi, safi);
2373
2374 return 0;
2375
2376 /* This BGP update is filtered. Log the reason then update BGP
2377 entry. */
2378 filtered:
2379 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002380 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002381 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2382 peer->host,
2383 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2384 p->prefixlen, reason);
2385
2386 if (ri)
paulb40d9392005-08-22 22:34:41 +00002387 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002388
2389 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002390
paul718e3742002-12-13 20:15:29 +00002391 return 0;
2392}
2393
2394int
paulfee0f4c2004-09-13 05:12:46 +00002395bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2396 afi_t afi, safi_t safi, int type, int sub_type,
2397 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2398{
2399 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002400 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002401 struct bgp *bgp;
2402 int ret;
2403
2404 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2405 soft_reconfig);
2406
2407 bgp = peer->bgp;
2408
2409 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002410 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002411 {
2412 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2413 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2414 sub_type, prd, tag);
2415 }
2416
2417 return ret;
2418}
2419
2420int
paul718e3742002-12-13 20:15:29 +00002421bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002422 afi_t afi, safi_t safi, int type, int sub_type,
2423 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002424{
2425 struct bgp *bgp;
2426 char buf[SU_ADDRSTRLEN];
2427 struct bgp_node *rn;
2428 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002429 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002430 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002431
2432 bgp = peer->bgp;
2433
David Lamparter4584c232015-04-13 09:50:00 +02002434 /* Lookup node. */
2435 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2436
2437 /* Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2438 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2439 * the iteration over all RS clients.
2440 * Since we need to remove the entry from adj_in anyway, do that first and
2441 * if there was no entry, we don't need to do anything more. */
2442 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2443 && peer != bgp->peer_self)
2444 if (!bgp_adj_in_unset (rn, peer))
2445 {
2446 if (BGP_DEBUG (update, UPDATE_IN))
2447 zlog (peer->log, LOG_DEBUG, "%s withdrawing route %s/%d "
2448 "not in adj-in", peer->host,
2449 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2450 p->prefixlen);
2451 bgp_unlock_node (rn);
2452 return 0;
2453 }
2454
paulfee0f4c2004-09-13 05:12:46 +00002455 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002456 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002457 {
2458 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2459 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2460 }
2461
paul718e3742002-12-13 20:15:29 +00002462 /* Logging. */
2463 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002464 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002465 peer->host,
2466 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2467 p->prefixlen);
2468
paul718e3742002-12-13 20:15:29 +00002469 /* Lookup withdrawn route. */
2470 for (ri = rn->info; ri; ri = ri->next)
2471 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2472 break;
2473
2474 /* Withdraw specified route from routing table. */
2475 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002476 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002477 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002478 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002479 "%s Can't find the route %s/%d", peer->host,
2480 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2481 p->prefixlen);
2482
2483 /* Unlock bgp_node_get() lock. */
2484 bgp_unlock_node (rn);
2485
2486 return 0;
2487}
David Lamparter6b0655a2014-06-04 06:53:35 +02002488
paul718e3742002-12-13 20:15:29 +00002489void
2490bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2491{
2492 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002493 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002494 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002495 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002496 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002497 struct bgp_node *rn;
2498 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002499 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002500
Paul Jakmab2497022007-06-14 11:17:58 +00002501 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002502 return;
2503
paul718e3742002-12-13 20:15:29 +00002504 bgp = peer->bgp;
2505 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002506
paul718e3742002-12-13 20:15:29 +00002507 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2508 aspath = attr.aspath;
2509 attr.local_pref = bgp->default_local_pref;
2510 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2511
2512 if (afi == AFI_IP)
2513 str2prefix ("0.0.0.0/0", &p);
2514#ifdef HAVE_IPV6
2515 else if (afi == AFI_IP6)
2516 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002517 struct attr_extra *ae = attr.extra;
2518
paul718e3742002-12-13 20:15:29 +00002519 str2prefix ("::/0", &p);
2520
2521 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002522 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002523 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002524 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002525
2526 /* If the peer is on shared nextwork and we have link-local
2527 nexthop set it. */
2528 if (peer->shared_network
2529 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2530 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002531 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002532 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002533 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002534 }
2535 }
2536#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002537
2538 if (peer->default_rmap[afi][safi].name)
2539 {
paulfee0f4c2004-09-13 05:12:46 +00002540 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002541 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2542 {
2543 for (ri = rn->info; ri; ri = ri->next)
2544 {
2545 struct attr dummy_attr;
2546 struct attr_extra dummy_extra;
2547 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002548
Christian Frankedcab1bb2012-12-07 16:45:52 +00002549 /* Provide dummy so the route-map can't modify the attributes */
2550 dummy_attr.extra = &dummy_extra;
2551 bgp_attr_dup(&dummy_attr, ri->attr);
2552 info.peer = ri->peer;
2553 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002554
Christian Frankedcab1bb2012-12-07 16:45:52 +00002555 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2556 RMAP_BGP, &info);
2557
2558 /* The route map might have set attributes. If we don't flush them
2559 * here, they will be leaked. */
2560 bgp_attr_flush(&dummy_attr);
2561 if (ret != RMAP_DENYMATCH)
2562 break;
2563 }
2564 if (ret != RMAP_DENYMATCH)
2565 break;
2566 }
paulfee0f4c2004-09-13 05:12:46 +00002567 bgp->peer_self->rmap_type = 0;
2568
paul718e3742002-12-13 20:15:29 +00002569 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002570 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002571 }
2572
2573 if (withdraw)
2574 {
2575 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2576 bgp_default_withdraw_send (peer, afi, safi);
2577 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2578 }
2579 else
2580 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002581 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2582 {
2583 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2584 bgp_default_update_send (peer, &attr, afi, safi, from);
2585 }
paul718e3742002-12-13 20:15:29 +00002586 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002587
2588 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002589 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002590}
David Lamparter6b0655a2014-06-04 06:53:35 +02002591
paul718e3742002-12-13 20:15:29 +00002592static void
2593bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002594 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002595{
2596 struct bgp_node *rn;
2597 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002598 struct attr attr;
2599 struct attr_extra extra;
2600
paul718e3742002-12-13 20:15:29 +00002601 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002602 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002603
2604 if (safi != SAFI_MPLS_VPN
2605 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2606 bgp_default_originate (peer, afi, safi, 0);
2607
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002608 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2609 attr.extra = &extra;
2610
paul718e3742002-12-13 20:15:29 +00002611 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2612 for (ri = rn->info; ri; ri = ri->next)
2613 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2614 {
paulfee0f4c2004-09-13 05:12:46 +00002615 if ( (rsclient) ?
2616 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2617 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002618 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2619 else
2620 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2621 }
2622}
2623
2624void
2625bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2626{
2627 struct bgp_node *rn;
2628 struct bgp_table *table;
2629
2630 if (peer->status != Established)
2631 return;
2632
2633 if (! peer->afc_nego[afi][safi])
2634 return;
2635
2636 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2637 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2638 return;
2639
2640 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002641 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002642 else
2643 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2644 rn = bgp_route_next(rn))
2645 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002646 bgp_announce_table (peer, afi, safi, table, 0);
2647
2648 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2649 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002650}
2651
2652void
2653bgp_announce_route_all (struct peer *peer)
2654{
2655 afi_t afi;
2656 safi_t safi;
2657
2658 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2659 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2660 bgp_announce_route (peer, afi, safi);
2661}
David Lamparter6b0655a2014-06-04 06:53:35 +02002662
paul718e3742002-12-13 20:15:29 +00002663static void
paulfee0f4c2004-09-13 05:12:46 +00002664bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002665 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002666{
2667 struct bgp_node *rn;
2668 struct bgp_adj_in *ain;
2669
2670 if (! table)
2671 table = rsclient->bgp->rib[afi][safi];
2672
2673 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2674 for (ain = rn->adj_in; ain; ain = ain->next)
2675 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002676 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002677 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002678
paulfee0f4c2004-09-13 05:12:46 +00002679 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002680 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002681 }
2682}
2683
2684void
2685bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2686{
2687 struct bgp_table *table;
2688 struct bgp_node *rn;
2689
2690 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002691 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002692
2693 else
2694 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2695 rn = bgp_route_next (rn))
2696 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002697 {
2698 struct prefix_rd prd;
2699 prd.family = AF_UNSPEC;
2700 prd.prefixlen = 64;
2701 memcpy(&prd.val, rn->p.u.val, 8);
2702
2703 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2704 }
paulfee0f4c2004-09-13 05:12:46 +00002705}
David Lamparter6b0655a2014-06-04 06:53:35 +02002706
paulfee0f4c2004-09-13 05:12:46 +00002707static void
paul718e3742002-12-13 20:15:29 +00002708bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002709 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002710{
2711 int ret;
2712 struct bgp_node *rn;
2713 struct bgp_adj_in *ain;
2714
2715 if (! table)
2716 table = peer->bgp->rib[afi][safi];
2717
2718 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2719 for (ain = rn->adj_in; ain; ain = ain->next)
2720 {
2721 if (ain->peer == peer)
2722 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002723 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002724 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002725
paul718e3742002-12-13 20:15:29 +00002726 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2727 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002728 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002729
paul718e3742002-12-13 20:15:29 +00002730 if (ret < 0)
2731 {
2732 bgp_unlock_node (rn);
2733 return;
2734 }
2735 continue;
2736 }
2737 }
2738}
2739
2740void
2741bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2742{
2743 struct bgp_node *rn;
2744 struct bgp_table *table;
2745
2746 if (peer->status != Established)
2747 return;
2748
2749 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002750 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002751 else
2752 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2753 rn = bgp_route_next (rn))
2754 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002755 {
2756 struct prefix_rd prd;
2757 prd.family = AF_UNSPEC;
2758 prd.prefixlen = 64;
2759 memcpy(&prd.val, rn->p.u.val, 8);
2760
2761 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2762 }
paul718e3742002-12-13 20:15:29 +00002763}
David Lamparter6b0655a2014-06-04 06:53:35 +02002764
Chris Caputo228da422009-07-18 05:44:03 +00002765
2766struct bgp_clear_node_queue
2767{
2768 struct bgp_node *rn;
2769 enum bgp_clear_route_type purpose;
2770};
2771
paul200df112005-06-01 11:17:05 +00002772static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002773bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002774{
Chris Caputo228da422009-07-18 05:44:03 +00002775 struct bgp_clear_node_queue *cnq = data;
2776 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002777 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002778 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002779 afi_t afi = bgp_node_table (rn)->afi;
2780 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002781
Paul Jakma64e580a2006-02-21 01:09:01 +00002782 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002783
Paul Jakma64e580a2006-02-21 01:09:01 +00002784 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002785 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002786 {
2787 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002788 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2789 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002790 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002791 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2792 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002793 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002794 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002795 break;
2796 }
paul200df112005-06-01 11:17:05 +00002797 return WQ_SUCCESS;
2798}
2799
2800static void
paul0fb58d52005-11-14 14:31:49 +00002801bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002802{
Chris Caputo228da422009-07-18 05:44:03 +00002803 struct bgp_clear_node_queue *cnq = data;
2804 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002805 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002806
2807 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002808 bgp_table_unlock (table);
2809 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002810}
2811
2812static void
paul94f2b392005-06-28 12:44:16 +00002813bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002814{
Paul Jakma64e580a2006-02-21 01:09:01 +00002815 struct peer *peer = wq->spec.data;
2816
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002817 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002818 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002819
2820 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002821}
2822
2823static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002824bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002825{
Paul Jakmaa2943652009-07-21 14:02:04 +01002826 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002827
Paul Jakmaa2943652009-07-21 14:02:04 +01002828 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002829#undef CLEAR_QUEUE_NAME_LEN
2830
2831 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002832 {
2833 zlog_err ("%s: Failed to allocate work queue", __func__);
2834 exit (1);
2835 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002836 peer->clear_node_queue->spec.hold = 10;
2837 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2838 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2839 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2840 peer->clear_node_queue->spec.max_retries = 0;
2841
2842 /* we only 'lock' this peer reference when the queue is actually active */
2843 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002844}
2845
paul718e3742002-12-13 20:15:29 +00002846static void
2847bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002848 struct bgp_table *table, struct peer *rsclient,
2849 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002850{
2851 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002852
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002853
paul718e3742002-12-13 20:15:29 +00002854 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002855 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002856
hasso6cf159b2005-03-21 10:28:14 +00002857 /* If still no table => afi/safi isn't configured at all or smth. */
2858 if (! table)
2859 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002860
2861 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2862 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002863 struct bgp_info *ri;
2864 struct bgp_adj_in *ain;
2865 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002866
2867 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2868 * queued for every clearing peer, regardless of whether it is
2869 * relevant to the peer at hand.
2870 *
2871 * Overview: There are 3 different indices which need to be
2872 * scrubbed, potentially, when a peer is removed:
2873 *
2874 * 1 peer's routes visible via the RIB (ie accepted routes)
2875 * 2 peer's routes visible by the (optional) peer's adj-in index
2876 * 3 other routes visible by the peer's adj-out index
2877 *
2878 * 3 there is no hurry in scrubbing, once the struct peer is
2879 * removed from bgp->peer, we could just GC such deleted peer's
2880 * adj-outs at our leisure.
2881 *
2882 * 1 and 2 must be 'scrubbed' in some way, at least made
2883 * invisible via RIB index before peer session is allowed to be
2884 * brought back up. So one needs to know when such a 'search' is
2885 * complete.
2886 *
2887 * Ideally:
2888 *
2889 * - there'd be a single global queue or a single RIB walker
2890 * - rather than tracking which route_nodes still need to be
2891 * examined on a peer basis, we'd track which peers still
2892 * aren't cleared
2893 *
2894 * Given that our per-peer prefix-counts now should be reliable,
2895 * this may actually be achievable. It doesn't seem to be a huge
2896 * problem at this time,
2897 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002898 for (ain = rn->adj_in; ain; ain = ain->next)
2899 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2900 {
2901 bgp_adj_in_remove (rn, ain);
2902 bgp_unlock_node (rn);
2903 break;
2904 }
2905 for (aout = rn->adj_out; aout; aout = aout->next)
2906 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2907 {
2908 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2909 bgp_unlock_node (rn);
2910 break;
2911 }
2912
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002913 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002914 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002915 {
Chris Caputo228da422009-07-18 05:44:03 +00002916 struct bgp_clear_node_queue *cnq;
2917
2918 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002919 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002920 bgp_lock_node (rn);
2921 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2922 sizeof (struct bgp_clear_node_queue));
2923 cnq->rn = rn;
2924 cnq->purpose = purpose;
2925 work_queue_add (peer->clear_node_queue, cnq);
2926 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002927 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002928 }
2929 return;
2930}
2931
2932void
Chris Caputo228da422009-07-18 05:44:03 +00002933bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2934 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002935{
2936 struct bgp_node *rn;
2937 struct bgp_table *table;
2938 struct peer *rsclient;
2939 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002940
Paul Jakma64e580a2006-02-21 01:09:01 +00002941 if (peer->clear_node_queue == NULL)
2942 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002943
Paul Jakmaca058a32006-09-14 02:58:49 +00002944 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2945 * Idle until it receives a Clearing_Completed event. This protects
2946 * against peers which flap faster than we can we clear, which could
2947 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002948 *
2949 * a) race with routes from the new session being installed before
2950 * clear_route_node visits the node (to delete the route of that
2951 * peer)
2952 * b) resource exhaustion, clear_route_node likely leads to an entry
2953 * on the process_main queue. Fast-flapping could cause that queue
2954 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002955 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002956 if (!peer->clear_node_queue->thread)
2957 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002958
Chris Caputo228da422009-07-18 05:44:03 +00002959 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002960 {
Chris Caputo228da422009-07-18 05:44:03 +00002961 case BGP_CLEAR_ROUTE_NORMAL:
2962 if (safi != SAFI_MPLS_VPN)
2963 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2964 else
2965 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2966 rn = bgp_route_next (rn))
2967 if ((table = rn->info) != NULL)
2968 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2969
2970 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2971 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2972 PEER_FLAG_RSERVER_CLIENT))
2973 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2974 break;
2975
2976 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2977 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2978 break;
2979
2980 default:
2981 assert (0);
2982 break;
paulfee0f4c2004-09-13 05:12:46 +00002983 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002984
Paul Jakmaca058a32006-09-14 02:58:49 +00002985 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002986 * completion function won't be run by workqueue code - call it here.
2987 * XXX: Actually, this assumption doesn't hold, see
2988 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002989 *
2990 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002991 * really needed if peer state is Established - peers in
2992 * pre-Established states shouldn't have any route-update state
2993 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002994 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002995 * We still can get here in pre-Established though, through
2996 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2997 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002998 *
2999 * At some future point, this check could be move to the top of the
3000 * function, and do a quick early-return when state is
3001 * pre-Established, avoiding above list and table scans. Once we're
3002 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00003003 */
3004 if (!peer->clear_node_queue->thread)
3005 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00003006}
3007
3008void
3009bgp_clear_route_all (struct peer *peer)
3010{
3011 afi_t afi;
3012 safi_t safi;
3013
3014 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3015 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003016 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003017}
3018
3019void
3020bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3021{
3022 struct bgp_table *table;
3023 struct bgp_node *rn;
3024 struct bgp_adj_in *ain;
3025
3026 table = peer->bgp->rib[afi][safi];
3027
3028 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3029 for (ain = rn->adj_in; ain ; ain = ain->next)
3030 if (ain->peer == peer)
3031 {
3032 bgp_adj_in_remove (rn, ain);
3033 bgp_unlock_node (rn);
3034 break;
3035 }
3036}
hasso93406d82005-02-02 14:40:33 +00003037
3038void
3039bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3040{
3041 struct bgp_node *rn;
3042 struct bgp_info *ri;
3043 struct bgp_table *table;
3044
3045 table = peer->bgp->rib[afi][safi];
3046
3047 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3048 {
3049 for (ri = rn->info; ri; ri = ri->next)
3050 if (ri->peer == peer)
3051 {
3052 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3053 bgp_rib_remove (rn, ri, peer, afi, safi);
3054 break;
3055 }
3056 }
3057}
David Lamparter6b0655a2014-06-04 06:53:35 +02003058
paul718e3742002-12-13 20:15:29 +00003059/* Delete all kernel routes. */
3060void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003061bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003062{
3063 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003064 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003065 struct bgp_node *rn;
3066 struct bgp_table *table;
3067 struct bgp_info *ri;
3068
paul1eb8ef22005-04-07 07:30:20 +00003069 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003070 {
3071 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3072
3073 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3074 for (ri = rn->info; ri; ri = ri->next)
3075 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3076 && ri->type == ZEBRA_ROUTE_BGP
3077 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003078 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003079
3080 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3081
3082 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3083 for (ri = rn->info; ri; ri = ri->next)
3084 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3085 && ri->type == ZEBRA_ROUTE_BGP
3086 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003087 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003088 }
3089}
3090
3091void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003092bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003093{
3094 vty_reset ();
3095 bgp_zclient_reset ();
3096 access_list_reset ();
3097 prefix_list_reset ();
3098}
David Lamparter6b0655a2014-06-04 06:53:35 +02003099
paul718e3742002-12-13 20:15:29 +00003100/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3101 value. */
3102int
3103bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3104{
3105 u_char *pnt;
3106 u_char *lim;
3107 struct prefix p;
3108 int psize;
3109 int ret;
3110
3111 /* Check peer status. */
3112 if (peer->status != Established)
3113 return 0;
3114
3115 pnt = packet->nlri;
3116 lim = pnt + packet->length;
3117
3118 for (; pnt < lim; pnt += psize)
3119 {
3120 /* Clear prefix structure. */
3121 memset (&p, 0, sizeof (struct prefix));
3122
3123 /* Fetch prefix length. */
3124 p.prefixlen = *pnt++;
3125 p.family = afi2family (packet->afi);
3126
3127 /* Already checked in nlri_sanity_check(). We do double check
3128 here. */
3129 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3130 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3131 return -1;
3132
3133 /* Packet size overflow check. */
3134 psize = PSIZE (p.prefixlen);
3135
3136 /* When packet overflow occur return immediately. */
3137 if (pnt + psize > lim)
3138 return -1;
3139
3140 /* Fetch prefix from NLRI packet. */
3141 memcpy (&p.u.prefix, pnt, psize);
3142
3143 /* Check address. */
3144 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3145 {
3146 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3147 {
paulf5ba3872004-07-09 12:11:31 +00003148 /*
3149 * From draft-ietf-idr-bgp4-22, Section 6.3:
3150 * If a BGP router receives an UPDATE message with a
3151 * semantically incorrect NLRI field, in which a prefix is
3152 * semantically incorrect (eg. an unexpected multicast IP
3153 * address), it should ignore the prefix.
3154 */
paul718e3742002-12-13 20:15:29 +00003155 zlog (peer->log, LOG_ERR,
3156 "IPv4 unicast NLRI is multicast address %s",
3157 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003158
paul718e3742002-12-13 20:15:29 +00003159 return -1;
3160 }
3161 }
3162
3163#ifdef HAVE_IPV6
3164 /* Check address. */
3165 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3166 {
3167 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3168 {
3169 char buf[BUFSIZ];
3170
3171 zlog (peer->log, LOG_WARNING,
3172 "IPv6 link-local NLRI received %s ignore this NLRI",
3173 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3174
3175 continue;
3176 }
3177 }
3178#endif /* HAVE_IPV6 */
3179
3180 /* Normal process. */
3181 if (attr)
3182 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3183 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3184 else
3185 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3186 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3187
3188 /* Address family configuration mismatch or maximum-prefix count
3189 overflow. */
3190 if (ret < 0)
3191 return -1;
3192 }
3193
3194 /* Packet length consistency check. */
3195 if (pnt != lim)
3196 return -1;
3197
3198 return 0;
3199}
3200
3201/* NLRI encode syntax check routine. */
3202int
3203bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3204 bgp_size_t length)
3205{
3206 u_char *end;
3207 u_char prefixlen;
3208 int psize;
3209
3210 end = pnt + length;
3211
3212 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3213 syntactic validity. If the field is syntactically incorrect,
3214 then the Error Subcode is set to Invalid Network Field. */
3215
3216 while (pnt < end)
3217 {
3218 prefixlen = *pnt++;
3219
3220 /* Prefix length check. */
3221 if ((afi == AFI_IP && prefixlen > 32)
3222 || (afi == AFI_IP6 && prefixlen > 128))
3223 {
3224 plog_err (peer->log,
3225 "%s [Error] Update packet error (wrong prefix length %d)",
3226 peer->host, prefixlen);
3227 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3228 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3229 return -1;
3230 }
3231
3232 /* Packet size overflow check. */
3233 psize = PSIZE (prefixlen);
3234
3235 if (pnt + psize > end)
3236 {
3237 plog_err (peer->log,
3238 "%s [Error] Update packet error"
3239 " (prefix data overflow prefix size is %d)",
3240 peer->host, psize);
3241 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3242 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3243 return -1;
3244 }
3245
3246 pnt += psize;
3247 }
3248
3249 /* Packet length consistency check. */
3250 if (pnt != end)
3251 {
3252 plog_err (peer->log,
3253 "%s [Error] Update packet error"
3254 " (prefix length mismatch with total length)",
3255 peer->host);
3256 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3257 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3258 return -1;
3259 }
3260 return 0;
3261}
David Lamparter6b0655a2014-06-04 06:53:35 +02003262
paul94f2b392005-06-28 12:44:16 +00003263static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003264bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003265{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003266 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003267}
3268
paul94f2b392005-06-28 12:44:16 +00003269static void
paul718e3742002-12-13 20:15:29 +00003270bgp_static_free (struct bgp_static *bgp_static)
3271{
3272 if (bgp_static->rmap.name)
3273 free (bgp_static->rmap.name);
3274 XFREE (MTYPE_BGP_STATIC, bgp_static);
3275}
3276
paul94f2b392005-06-28 12:44:16 +00003277static void
paulfee0f4c2004-09-13 05:12:46 +00003278bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3279 struct prefix *p, afi_t afi, safi_t safi)
3280{
3281 struct bgp_node *rn;
3282 struct bgp_info *ri;
3283
3284 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3285
3286 /* Check selected route and self inserted route. */
3287 for (ri = rn->info; ri; ri = ri->next)
3288 if (ri->peer == bgp->peer_self
3289 && ri->type == ZEBRA_ROUTE_BGP
3290 && ri->sub_type == BGP_ROUTE_STATIC)
3291 break;
3292
3293 /* Withdraw static BGP route from routing table. */
3294 if (ri)
3295 {
paulfee0f4c2004-09-13 05:12:46 +00003296 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003297 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003298 }
3299
3300 /* Unlock bgp_node_lookup. */
3301 bgp_unlock_node (rn);
3302}
3303
paul94f2b392005-06-28 12:44:16 +00003304static void
paulfee0f4c2004-09-13 05:12:46 +00003305bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003306 struct bgp_static *bgp_static,
3307 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003308{
3309 struct bgp_node *rn;
3310 struct bgp_info *ri;
3311 struct bgp_info *new;
3312 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003313 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003314 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003315 struct attr new_attr;
3316 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003317 struct bgp *bgp;
3318 int ret;
3319 char buf[SU_ADDRSTRLEN];
3320
3321 bgp = rsclient->bgp;
3322
Paul Jakma06e110f2006-05-12 23:29:22 +00003323 assert (bgp_static);
3324 if (!bgp_static)
3325 return;
3326
paulfee0f4c2004-09-13 05:12:46 +00003327 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3328
3329 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003330
3331 attr.nexthop = bgp_static->igpnexthop;
3332 attr.med = bgp_static->igpmetric;
3333 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003334
Paul Jakma41367172007-08-06 15:24:51 +00003335 if (bgp_static->atomic)
3336 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3337
paulfee0f4c2004-09-13 05:12:46 +00003338 /* Apply network route-map for export to this rsclient. */
3339 if (bgp_static->rmap.name)
3340 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003341 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003342 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003343 info.attr = &attr_tmp;
3344
paulfee0f4c2004-09-13 05:12:46 +00003345 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3346 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3347
3348 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3349
3350 rsclient->rmap_type = 0;
3351
3352 if (ret == RMAP_DENYMATCH)
3353 {
3354 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003355 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003356
3357 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003358 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003359 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003360 bgp_attr_extra_free (&attr);
3361
paulfee0f4c2004-09-13 05:12:46 +00003362 return;
3363 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003364 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003365 }
3366 else
3367 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003368
3369 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003370 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003371
paulfee0f4c2004-09-13 05:12:46 +00003372 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3373
Paul Jakmafb982c22007-05-04 20:15:47 +00003374 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3375 == RMAP_DENY)
3376 {
paulfee0f4c2004-09-13 05:12:46 +00003377 /* This BGP update is filtered. Log the reason then update BGP entry. */
3378 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003379 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003380 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3381 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3382 p->prefixlen, rsclient->host);
3383
3384 bgp->peer_self->rmap_type = 0;
3385
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003386 bgp_attr_unintern (&attr_new);
3387 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003388 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003389
3390 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3391
3392 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003393 }
paulfee0f4c2004-09-13 05:12:46 +00003394
3395 bgp->peer_self->rmap_type = 0;
3396
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003397 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003398 attr_new = bgp_attr_intern (&new_attr);
3399
3400 for (ri = rn->info; ri; ri = ri->next)
3401 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3402 && ri->sub_type == BGP_ROUTE_STATIC)
3403 break;
3404
3405 if (ri)
3406 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003407 if (attrhash_cmp (ri->attr, attr_new) &&
3408 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003409 {
3410 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003411 bgp_attr_unintern (&attr_new);
3412 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003413 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003414 return;
3415 }
3416 else
3417 {
3418 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003419 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003420
3421 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003422 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3423 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003424 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003425 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003426 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003427
3428 /* Process change. */
3429 bgp_process (bgp, rn, afi, safi);
3430 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003431 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;
Paul Jakmafb982c22007-05-04 20:15:47 +00003434 }
paulfee0f4c2004-09-13 05:12:46 +00003435 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003436
paulfee0f4c2004-09-13 05:12:46 +00003437 /* Make new BGP info. */
3438 new = bgp_info_new ();
3439 new->type = ZEBRA_ROUTE_BGP;
3440 new->sub_type = BGP_ROUTE_STATIC;
3441 new->peer = bgp->peer_self;
3442 SET_FLAG (new->flags, BGP_INFO_VALID);
3443 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003444 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003445
3446 /* Register new BGP information. */
3447 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003448
3449 /* route_node_get lock */
3450 bgp_unlock_node (rn);
3451
paulfee0f4c2004-09-13 05:12:46 +00003452 /* Process change. */
3453 bgp_process (bgp, rn, afi, safi);
3454
3455 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003456 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003457 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003458}
3459
paul94f2b392005-06-28 12:44:16 +00003460static void
paulfee0f4c2004-09-13 05:12:46 +00003461bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003462 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3463{
3464 struct bgp_node *rn;
3465 struct bgp_info *ri;
3466 struct bgp_info *new;
3467 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003468 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003469 struct attr *attr_new;
3470 int ret;
3471
Paul Jakmadd8103a2006-05-12 23:27:30 +00003472 assert (bgp_static);
3473 if (!bgp_static)
3474 return;
3475
paulfee0f4c2004-09-13 05:12:46 +00003476 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003477
3478 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003479
3480 attr.nexthop = bgp_static->igpnexthop;
3481 attr.med = bgp_static->igpmetric;
3482 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003483
Paul Jakma41367172007-08-06 15:24:51 +00003484 if (bgp_static->atomic)
3485 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3486
paul718e3742002-12-13 20:15:29 +00003487 /* Apply route-map. */
3488 if (bgp_static->rmap.name)
3489 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003490 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003491 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003492 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003493
paulfee0f4c2004-09-13 05:12:46 +00003494 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3495
paul718e3742002-12-13 20:15:29 +00003496 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003497
paulfee0f4c2004-09-13 05:12:46 +00003498 bgp->peer_self->rmap_type = 0;
3499
paul718e3742002-12-13 20:15:29 +00003500 if (ret == RMAP_DENYMATCH)
3501 {
3502 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003503 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003504
3505 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003506 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003507 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003508 bgp_static_withdraw (bgp, p, afi, safi);
3509 return;
3510 }
paul286e1e72003-08-08 00:24:31 +00003511 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003512 }
paul286e1e72003-08-08 00:24:31 +00003513 else
3514 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003515
3516 for (ri = rn->info; ri; ri = ri->next)
3517 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3518 && ri->sub_type == BGP_ROUTE_STATIC)
3519 break;
3520
3521 if (ri)
3522 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003523 if (attrhash_cmp (ri->attr, attr_new) &&
3524 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003525 {
3526 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003527 bgp_attr_unintern (&attr_new);
3528 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003529 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003530 return;
3531 }
3532 else
3533 {
3534 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003535 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003536
3537 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003538 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3539 bgp_info_restore(rn, ri);
3540 else
3541 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003542 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003543 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003544 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003545
3546 /* Process change. */
3547 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3548 bgp_process (bgp, rn, afi, safi);
3549 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003550 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003551 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003552 return;
3553 }
3554 }
3555
3556 /* Make new BGP info. */
3557 new = bgp_info_new ();
3558 new->type = ZEBRA_ROUTE_BGP;
3559 new->sub_type = BGP_ROUTE_STATIC;
3560 new->peer = bgp->peer_self;
3561 SET_FLAG (new->flags, BGP_INFO_VALID);
3562 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003563 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003564
3565 /* Aggregate address increment. */
3566 bgp_aggregate_increment (bgp, p, new, afi, safi);
3567
3568 /* Register new BGP information. */
3569 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003570
3571 /* route_node_get lock */
3572 bgp_unlock_node (rn);
3573
paul718e3742002-12-13 20:15:29 +00003574 /* Process change. */
3575 bgp_process (bgp, rn, afi, safi);
3576
3577 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003578 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003579 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003580}
3581
3582void
paulfee0f4c2004-09-13 05:12:46 +00003583bgp_static_update (struct bgp *bgp, struct prefix *p,
3584 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3585{
3586 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003587 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003588
3589 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3590
paul1eb8ef22005-04-07 07:30:20 +00003591 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003592 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003593 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3594 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003595 }
3596}
3597
paul94f2b392005-06-28 12:44:16 +00003598static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003599bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3600 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003601{
3602 struct bgp_node *rn;
3603 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003604
paulfee0f4c2004-09-13 05:12:46 +00003605 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003606
3607 /* Make new BGP info. */
3608 new = bgp_info_new ();
3609 new->type = ZEBRA_ROUTE_BGP;
3610 new->sub_type = BGP_ROUTE_STATIC;
3611 new->peer = bgp->peer_self;
3612 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3613 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003614 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003615 new->extra = bgp_info_extra_new();
3616 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003617
3618 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003619 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003620
3621 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003622 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003623
paul200df112005-06-01 11:17:05 +00003624 /* route_node_get lock */
3625 bgp_unlock_node (rn);
3626
paul718e3742002-12-13 20:15:29 +00003627 /* Process change. */
3628 bgp_process (bgp, rn, afi, safi);
3629}
3630
3631void
3632bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3633 safi_t safi)
3634{
3635 struct bgp_node *rn;
3636 struct bgp_info *ri;
3637
paulfee0f4c2004-09-13 05:12:46 +00003638 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003639
3640 /* Check selected route and self inserted route. */
3641 for (ri = rn->info; ri; ri = ri->next)
3642 if (ri->peer == bgp->peer_self
3643 && ri->type == ZEBRA_ROUTE_BGP
3644 && ri->sub_type == BGP_ROUTE_STATIC)
3645 break;
3646
3647 /* Withdraw static BGP route from routing table. */
3648 if (ri)
3649 {
3650 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003651 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003652 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003653 }
3654
3655 /* Unlock bgp_node_lookup. */
3656 bgp_unlock_node (rn);
3657}
3658
3659void
paulfee0f4c2004-09-13 05:12:46 +00003660bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3661{
3662 struct bgp_static *bgp_static;
3663 struct bgp *bgp;
3664 struct bgp_node *rn;
3665 struct prefix *p;
3666
3667 bgp = rsclient->bgp;
3668
3669 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3670 if ((bgp_static = rn->info) != NULL)
3671 {
3672 p = &rn->p;
3673
3674 bgp_static_update_rsclient (rsclient, p, bgp_static,
3675 afi, safi);
3676 }
3677}
3678
paul94f2b392005-06-28 12:44:16 +00003679static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003680bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3681 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003682{
3683 struct bgp_node *rn;
3684 struct bgp_info *ri;
3685
paulfee0f4c2004-09-13 05:12:46 +00003686 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003687
3688 /* Check selected route and self inserted route. */
3689 for (ri = rn->info; ri; ri = ri->next)
3690 if (ri->peer == bgp->peer_self
3691 && ri->type == ZEBRA_ROUTE_BGP
3692 && ri->sub_type == BGP_ROUTE_STATIC)
3693 break;
3694
3695 /* Withdraw static BGP route from routing table. */
3696 if (ri)
3697 {
3698 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003699 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003700 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003701 }
3702
3703 /* Unlock bgp_node_lookup. */
3704 bgp_unlock_node (rn);
3705}
3706
3707/* Configure static BGP network. When user don't run zebra, static
3708 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003709static int
paulfd79ac92004-10-13 05:06:08 +00003710bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003711 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003712{
3713 int ret;
3714 struct prefix p;
3715 struct bgp_static *bgp_static;
3716 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003717 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003718
3719 /* Convert IP prefix string to struct prefix. */
3720 ret = str2prefix (ip_str, &p);
3721 if (! ret)
3722 {
3723 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3724 return CMD_WARNING;
3725 }
3726#ifdef HAVE_IPV6
3727 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3728 {
3729 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3730 VTY_NEWLINE);
3731 return CMD_WARNING;
3732 }
3733#endif /* HAVE_IPV6 */
3734
3735 apply_mask (&p);
3736
3737 /* Set BGP static route configuration. */
3738 rn = bgp_node_get (bgp->route[afi][safi], &p);
3739
3740 if (rn->info)
3741 {
3742 /* Configuration change. */
3743 bgp_static = rn->info;
3744
3745 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003746 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3747 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003748
paul718e3742002-12-13 20:15:29 +00003749 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003750
paul718e3742002-12-13 20:15:29 +00003751 if (rmap)
3752 {
3753 if (bgp_static->rmap.name)
3754 free (bgp_static->rmap.name);
3755 bgp_static->rmap.name = strdup (rmap);
3756 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3757 }
3758 else
3759 {
3760 if (bgp_static->rmap.name)
3761 free (bgp_static->rmap.name);
3762 bgp_static->rmap.name = NULL;
3763 bgp_static->rmap.map = NULL;
3764 bgp_static->valid = 0;
3765 }
3766 bgp_unlock_node (rn);
3767 }
3768 else
3769 {
3770 /* New configuration. */
3771 bgp_static = bgp_static_new ();
3772 bgp_static->backdoor = backdoor;
3773 bgp_static->valid = 0;
3774 bgp_static->igpmetric = 0;
3775 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003776
paul718e3742002-12-13 20:15:29 +00003777 if (rmap)
3778 {
3779 if (bgp_static->rmap.name)
3780 free (bgp_static->rmap.name);
3781 bgp_static->rmap.name = strdup (rmap);
3782 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3783 }
3784 rn->info = bgp_static;
3785 }
3786
3787 /* If BGP scan is not enabled, we should install this route here. */
3788 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3789 {
3790 bgp_static->valid = 1;
3791
3792 if (need_update)
3793 bgp_static_withdraw (bgp, &p, afi, safi);
3794
3795 if (! bgp_static->backdoor)
3796 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3797 }
3798
3799 return CMD_SUCCESS;
3800}
3801
3802/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003803static int
paulfd79ac92004-10-13 05:06:08 +00003804bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003805 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003806{
3807 int ret;
3808 struct prefix p;
3809 struct bgp_static *bgp_static;
3810 struct bgp_node *rn;
3811
3812 /* Convert IP prefix string to struct prefix. */
3813 ret = str2prefix (ip_str, &p);
3814 if (! ret)
3815 {
3816 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3817 return CMD_WARNING;
3818 }
3819#ifdef HAVE_IPV6
3820 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3821 {
3822 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3823 VTY_NEWLINE);
3824 return CMD_WARNING;
3825 }
3826#endif /* HAVE_IPV6 */
3827
3828 apply_mask (&p);
3829
3830 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3831 if (! rn)
3832 {
3833 vty_out (vty, "%% Can't find specified static route configuration.%s",
3834 VTY_NEWLINE);
3835 return CMD_WARNING;
3836 }
3837
3838 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003839
paul718e3742002-12-13 20:15:29 +00003840 /* Update BGP RIB. */
3841 if (! bgp_static->backdoor)
3842 bgp_static_withdraw (bgp, &p, afi, safi);
3843
3844 /* Clear configuration. */
3845 bgp_static_free (bgp_static);
3846 rn->info = NULL;
3847 bgp_unlock_node (rn);
3848 bgp_unlock_node (rn);
3849
3850 return CMD_SUCCESS;
3851}
3852
3853/* Called from bgp_delete(). Delete all static routes from the BGP
3854 instance. */
3855void
3856bgp_static_delete (struct bgp *bgp)
3857{
3858 afi_t afi;
3859 safi_t safi;
3860 struct bgp_node *rn;
3861 struct bgp_node *rm;
3862 struct bgp_table *table;
3863 struct bgp_static *bgp_static;
3864
3865 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3866 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3867 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3868 if (rn->info != NULL)
3869 {
3870 if (safi == SAFI_MPLS_VPN)
3871 {
3872 table = rn->info;
3873
3874 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3875 {
3876 bgp_static = rn->info;
3877 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3878 AFI_IP, SAFI_MPLS_VPN,
3879 (struct prefix_rd *)&rn->p,
3880 bgp_static->tag);
3881 bgp_static_free (bgp_static);
3882 rn->info = NULL;
3883 bgp_unlock_node (rn);
3884 }
3885 }
3886 else
3887 {
3888 bgp_static = rn->info;
3889 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3890 bgp_static_free (bgp_static);
3891 rn->info = NULL;
3892 bgp_unlock_node (rn);
3893 }
3894 }
3895}
3896
3897int
paulfd79ac92004-10-13 05:06:08 +00003898bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3899 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003900{
3901 int ret;
3902 struct prefix p;
3903 struct prefix_rd prd;
3904 struct bgp *bgp;
3905 struct bgp_node *prn;
3906 struct bgp_node *rn;
3907 struct bgp_table *table;
3908 struct bgp_static *bgp_static;
3909 u_char tag[3];
3910
3911 bgp = vty->index;
3912
3913 ret = str2prefix (ip_str, &p);
3914 if (! ret)
3915 {
3916 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3917 return CMD_WARNING;
3918 }
3919 apply_mask (&p);
3920
3921 ret = str2prefix_rd (rd_str, &prd);
3922 if (! ret)
3923 {
3924 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3925 return CMD_WARNING;
3926 }
3927
3928 ret = str2tag (tag_str, tag);
3929 if (! ret)
3930 {
3931 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3932 return CMD_WARNING;
3933 }
3934
3935 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3936 (struct prefix *)&prd);
3937 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003938 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003939 else
3940 bgp_unlock_node (prn);
3941 table = prn->info;
3942
3943 rn = bgp_node_get (table, &p);
3944
3945 if (rn->info)
3946 {
3947 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3948 bgp_unlock_node (rn);
3949 }
3950 else
3951 {
3952 /* New configuration. */
3953 bgp_static = bgp_static_new ();
3954 bgp_static->valid = 1;
3955 memcpy (bgp_static->tag, tag, 3);
3956 rn->info = bgp_static;
3957
3958 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3959 }
3960
3961 return CMD_SUCCESS;
3962}
3963
3964/* Configure static BGP network. */
3965int
paulfd79ac92004-10-13 05:06:08 +00003966bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3967 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003968{
3969 int ret;
3970 struct bgp *bgp;
3971 struct prefix p;
3972 struct prefix_rd prd;
3973 struct bgp_node *prn;
3974 struct bgp_node *rn;
3975 struct bgp_table *table;
3976 struct bgp_static *bgp_static;
3977 u_char tag[3];
3978
3979 bgp = vty->index;
3980
3981 /* Convert IP prefix string to struct prefix. */
3982 ret = str2prefix (ip_str, &p);
3983 if (! ret)
3984 {
3985 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3986 return CMD_WARNING;
3987 }
3988 apply_mask (&p);
3989
3990 ret = str2prefix_rd (rd_str, &prd);
3991 if (! ret)
3992 {
3993 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3994 return CMD_WARNING;
3995 }
3996
3997 ret = str2tag (tag_str, tag);
3998 if (! ret)
3999 {
4000 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4001 return CMD_WARNING;
4002 }
4003
4004 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4005 (struct prefix *)&prd);
4006 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00004007 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00004008 else
4009 bgp_unlock_node (prn);
4010 table = prn->info;
4011
4012 rn = bgp_node_lookup (table, &p);
4013
4014 if (rn)
4015 {
4016 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4017
4018 bgp_static = rn->info;
4019 bgp_static_free (bgp_static);
4020 rn->info = NULL;
4021 bgp_unlock_node (rn);
4022 bgp_unlock_node (rn);
4023 }
4024 else
4025 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4026
4027 return CMD_SUCCESS;
4028}
David Lamparter6b0655a2014-06-04 06:53:35 +02004029
paul718e3742002-12-13 20:15:29 +00004030DEFUN (bgp_network,
4031 bgp_network_cmd,
4032 "network A.B.C.D/M",
4033 "Specify a network to announce via BGP\n"
4034 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4035{
4036 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004037 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004038}
4039
4040DEFUN (bgp_network_route_map,
4041 bgp_network_route_map_cmd,
4042 "network A.B.C.D/M route-map WORD",
4043 "Specify a network to announce via BGP\n"
4044 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4045 "Route-map to modify the attributes\n"
4046 "Name of the route map\n")
4047{
4048 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004049 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004050}
4051
4052DEFUN (bgp_network_backdoor,
4053 bgp_network_backdoor_cmd,
4054 "network A.B.C.D/M backdoor",
4055 "Specify a network to announce via BGP\n"
4056 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4057 "Specify a BGP backdoor route\n")
4058{
Paul Jakma41367172007-08-06 15:24:51 +00004059 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004060 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004061}
4062
4063DEFUN (bgp_network_mask,
4064 bgp_network_mask_cmd,
4065 "network A.B.C.D mask A.B.C.D",
4066 "Specify a network to announce via BGP\n"
4067 "Network number\n"
4068 "Network mask\n"
4069 "Network mask\n")
4070{
4071 int ret;
4072 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004073
paul718e3742002-12-13 20:15:29 +00004074 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4075 if (! ret)
4076 {
4077 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4078 return CMD_WARNING;
4079 }
4080
4081 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004082 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004083}
4084
4085DEFUN (bgp_network_mask_route_map,
4086 bgp_network_mask_route_map_cmd,
4087 "network A.B.C.D mask A.B.C.D route-map WORD",
4088 "Specify a network to announce via BGP\n"
4089 "Network number\n"
4090 "Network mask\n"
4091 "Network mask\n"
4092 "Route-map to modify the attributes\n"
4093 "Name of the route map\n")
4094{
4095 int ret;
4096 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004097
paul718e3742002-12-13 20:15:29 +00004098 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4099 if (! ret)
4100 {
4101 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4102 return CMD_WARNING;
4103 }
4104
4105 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004106 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004107}
4108
4109DEFUN (bgp_network_mask_backdoor,
4110 bgp_network_mask_backdoor_cmd,
4111 "network A.B.C.D mask A.B.C.D backdoor",
4112 "Specify a network to announce via BGP\n"
4113 "Network number\n"
4114 "Network mask\n"
4115 "Network mask\n"
4116 "Specify a BGP backdoor route\n")
4117{
4118 int ret;
4119 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004120
paul718e3742002-12-13 20:15:29 +00004121 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4122 if (! ret)
4123 {
4124 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4125 return CMD_WARNING;
4126 }
4127
Paul Jakma41367172007-08-06 15:24:51 +00004128 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004129 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004130}
4131
4132DEFUN (bgp_network_mask_natural,
4133 bgp_network_mask_natural_cmd,
4134 "network A.B.C.D",
4135 "Specify a network to announce via BGP\n"
4136 "Network number\n")
4137{
4138 int ret;
4139 char prefix_str[BUFSIZ];
4140
4141 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4142 if (! ret)
4143 {
4144 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4145 return CMD_WARNING;
4146 }
4147
4148 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004149 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004150}
4151
4152DEFUN (bgp_network_mask_natural_route_map,
4153 bgp_network_mask_natural_route_map_cmd,
4154 "network A.B.C.D route-map WORD",
4155 "Specify a network to announce via BGP\n"
4156 "Network number\n"
4157 "Route-map to modify the attributes\n"
4158 "Name of the route map\n")
4159{
4160 int ret;
4161 char prefix_str[BUFSIZ];
4162
4163 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4164 if (! ret)
4165 {
4166 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4167 return CMD_WARNING;
4168 }
4169
4170 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004171 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004172}
4173
4174DEFUN (bgp_network_mask_natural_backdoor,
4175 bgp_network_mask_natural_backdoor_cmd,
4176 "network A.B.C.D backdoor",
4177 "Specify a network to announce via BGP\n"
4178 "Network number\n"
4179 "Specify a BGP backdoor route\n")
4180{
4181 int ret;
4182 char prefix_str[BUFSIZ];
4183
4184 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4185 if (! ret)
4186 {
4187 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4188 return CMD_WARNING;
4189 }
4190
Paul Jakma41367172007-08-06 15:24:51 +00004191 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004192 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004193}
4194
4195DEFUN (no_bgp_network,
4196 no_bgp_network_cmd,
4197 "no network A.B.C.D/M",
4198 NO_STR
4199 "Specify a network to announce via BGP\n"
4200 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4201{
4202 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4203 bgp_node_safi (vty));
4204}
4205
4206ALIAS (no_bgp_network,
4207 no_bgp_network_route_map_cmd,
4208 "no network A.B.C.D/M route-map WORD",
4209 NO_STR
4210 "Specify a network to announce via BGP\n"
4211 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4212 "Route-map to modify the attributes\n"
4213 "Name of the route map\n")
4214
4215ALIAS (no_bgp_network,
4216 no_bgp_network_backdoor_cmd,
4217 "no network A.B.C.D/M backdoor",
4218 NO_STR
4219 "Specify a network to announce via BGP\n"
4220 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4221 "Specify a BGP backdoor route\n")
4222
4223DEFUN (no_bgp_network_mask,
4224 no_bgp_network_mask_cmd,
4225 "no network A.B.C.D mask A.B.C.D",
4226 NO_STR
4227 "Specify a network to announce via BGP\n"
4228 "Network number\n"
4229 "Network mask\n"
4230 "Network mask\n")
4231{
4232 int ret;
4233 char prefix_str[BUFSIZ];
4234
4235 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4236 if (! ret)
4237 {
4238 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4239 return CMD_WARNING;
4240 }
4241
4242 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4243 bgp_node_safi (vty));
4244}
4245
4246ALIAS (no_bgp_network_mask,
4247 no_bgp_network_mask_route_map_cmd,
4248 "no network A.B.C.D mask A.B.C.D route-map WORD",
4249 NO_STR
4250 "Specify a network to announce via BGP\n"
4251 "Network number\n"
4252 "Network mask\n"
4253 "Network mask\n"
4254 "Route-map to modify the attributes\n"
4255 "Name of the route map\n")
4256
4257ALIAS (no_bgp_network_mask,
4258 no_bgp_network_mask_backdoor_cmd,
4259 "no network A.B.C.D mask A.B.C.D backdoor",
4260 NO_STR
4261 "Specify a network to announce via BGP\n"
4262 "Network number\n"
4263 "Network mask\n"
4264 "Network mask\n"
4265 "Specify a BGP backdoor route\n")
4266
4267DEFUN (no_bgp_network_mask_natural,
4268 no_bgp_network_mask_natural_cmd,
4269 "no network A.B.C.D",
4270 NO_STR
4271 "Specify a network to announce via BGP\n"
4272 "Network number\n")
4273{
4274 int ret;
4275 char prefix_str[BUFSIZ];
4276
4277 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4278 if (! ret)
4279 {
4280 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4281 return CMD_WARNING;
4282 }
4283
4284 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4285 bgp_node_safi (vty));
4286}
4287
4288ALIAS (no_bgp_network_mask_natural,
4289 no_bgp_network_mask_natural_route_map_cmd,
4290 "no network A.B.C.D route-map WORD",
4291 NO_STR
4292 "Specify a network to announce via BGP\n"
4293 "Network number\n"
4294 "Route-map to modify the attributes\n"
4295 "Name of the route map\n")
4296
4297ALIAS (no_bgp_network_mask_natural,
4298 no_bgp_network_mask_natural_backdoor_cmd,
4299 "no network A.B.C.D backdoor",
4300 NO_STR
4301 "Specify a network to announce via BGP\n"
4302 "Network number\n"
4303 "Specify a BGP backdoor route\n")
4304
4305#ifdef HAVE_IPV6
4306DEFUN (ipv6_bgp_network,
4307 ipv6_bgp_network_cmd,
4308 "network X:X::X:X/M",
4309 "Specify a network to announce via BGP\n"
4310 "IPv6 prefix <network>/<length>\n")
4311{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304312 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004313 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004314}
4315
4316DEFUN (ipv6_bgp_network_route_map,
4317 ipv6_bgp_network_route_map_cmd,
4318 "network X:X::X:X/M route-map WORD",
4319 "Specify a network to announce via BGP\n"
4320 "IPv6 prefix <network>/<length>\n"
4321 "Route-map to modify the attributes\n"
4322 "Name of the route map\n")
4323{
4324 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004325 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004326}
4327
4328DEFUN (no_ipv6_bgp_network,
4329 no_ipv6_bgp_network_cmd,
4330 "no network X:X::X:X/M",
4331 NO_STR
4332 "Specify a network to announce via BGP\n"
4333 "IPv6 prefix <network>/<length>\n")
4334{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304335 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004336}
4337
4338ALIAS (no_ipv6_bgp_network,
4339 no_ipv6_bgp_network_route_map_cmd,
4340 "no network X:X::X:X/M route-map WORD",
4341 NO_STR
4342 "Specify a network to announce via BGP\n"
4343 "IPv6 prefix <network>/<length>\n"
4344 "Route-map to modify the attributes\n"
4345 "Name of the route map\n")
4346
4347ALIAS (ipv6_bgp_network,
4348 old_ipv6_bgp_network_cmd,
4349 "ipv6 bgp network X:X::X:X/M",
4350 IPV6_STR
4351 BGP_STR
4352 "Specify a network to announce via BGP\n"
4353 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4354
4355ALIAS (no_ipv6_bgp_network,
4356 old_no_ipv6_bgp_network_cmd,
4357 "no ipv6 bgp network X:X::X:X/M",
4358 NO_STR
4359 IPV6_STR
4360 BGP_STR
4361 "Specify a network to announce via BGP\n"
4362 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4363#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004364
4365/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4366ALIAS_DEPRECATED (bgp_network,
4367 bgp_network_ttl_cmd,
4368 "network A.B.C.D/M pathlimit <0-255>",
4369 "Specify a network to announce via BGP\n"
4370 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4371 "AS-Path hopcount limit attribute\n"
4372 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4373ALIAS_DEPRECATED (bgp_network_backdoor,
4374 bgp_network_backdoor_ttl_cmd,
4375 "network A.B.C.D/M backdoor pathlimit <0-255>",
4376 "Specify a network to announce via BGP\n"
4377 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4378 "Specify a BGP backdoor route\n"
4379 "AS-Path hopcount limit attribute\n"
4380 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4381ALIAS_DEPRECATED (bgp_network_mask,
4382 bgp_network_mask_ttl_cmd,
4383 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4384 "Specify a network to announce via BGP\n"
4385 "Network number\n"
4386 "Network mask\n"
4387 "Network mask\n"
4388 "AS-Path hopcount limit attribute\n"
4389 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4390ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4391 bgp_network_mask_backdoor_ttl_cmd,
4392 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4393 "Specify a network to announce via BGP\n"
4394 "Network number\n"
4395 "Network mask\n"
4396 "Network mask\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_natural,
4401 bgp_network_mask_natural_ttl_cmd,
4402 "network A.B.C.D pathlimit <0-255>",
4403 "Specify a network to announce via BGP\n"
4404 "Network number\n"
4405 "AS-Path hopcount limit attribute\n"
4406 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4407ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4408 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004409 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004410 "Specify a network to announce via BGP\n"
4411 "Network number\n"
4412 "Specify a BGP backdoor route\n"
4413 "AS-Path hopcount limit attribute\n"
4414 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4415ALIAS_DEPRECATED (no_bgp_network,
4416 no_bgp_network_ttl_cmd,
4417 "no network A.B.C.D/M pathlimit <0-255>",
4418 NO_STR
4419 "Specify a network to announce via BGP\n"
4420 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4421 "AS-Path hopcount limit attribute\n"
4422 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4423ALIAS_DEPRECATED (no_bgp_network,
4424 no_bgp_network_backdoor_ttl_cmd,
4425 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4426 NO_STR
4427 "Specify a network to announce via BGP\n"
4428 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4429 "Specify a BGP backdoor route\n"
4430 "AS-Path hopcount limit attribute\n"
4431 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4432ALIAS_DEPRECATED (no_bgp_network,
4433 no_bgp_network_mask_ttl_cmd,
4434 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4435 NO_STR
4436 "Specify a network to announce via BGP\n"
4437 "Network number\n"
4438 "Network mask\n"
4439 "Network mask\n"
4440 "AS-Path hopcount limit attribute\n"
4441 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4442ALIAS_DEPRECATED (no_bgp_network_mask,
4443 no_bgp_network_mask_backdoor_ttl_cmd,
4444 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4445 NO_STR
4446 "Specify a network to announce via BGP\n"
4447 "Network number\n"
4448 "Network mask\n"
4449 "Network mask\n"
4450 "Specify a BGP backdoor route\n"
4451 "AS-Path hopcount limit attribute\n"
4452 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4453ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4454 no_bgp_network_mask_natural_ttl_cmd,
4455 "no network A.B.C.D pathlimit <0-255>",
4456 NO_STR
4457 "Specify a network to announce via BGP\n"
4458 "Network number\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_natural,
4462 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4463 "no network 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 "Specify a BGP backdoor route\n"
4468 "AS-Path hopcount limit attribute\n"
4469 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004470#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004471ALIAS_DEPRECATED (ipv6_bgp_network,
4472 ipv6_bgp_network_ttl_cmd,
4473 "network X:X::X:X/M pathlimit <0-255>",
4474 "Specify a network to announce via BGP\n"
4475 "IPv6 prefix <network>/<length>\n"
4476 "AS-Path hopcount limit attribute\n"
4477 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4478ALIAS_DEPRECATED (no_ipv6_bgp_network,
4479 no_ipv6_bgp_network_ttl_cmd,
4480 "no network X:X::X:X/M pathlimit <0-255>",
4481 NO_STR
4482 "Specify a network to announce via BGP\n"
4483 "IPv6 prefix <network>/<length>\n"
4484 "AS-Path hopcount limit attribute\n"
4485 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004486#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02004487
paul718e3742002-12-13 20:15:29 +00004488/* Aggreagete address:
4489
4490 advertise-map Set condition to advertise attribute
4491 as-set Generate AS set path information
4492 attribute-map Set attributes of aggregate
4493 route-map Set parameters of aggregate
4494 summary-only Filter more specific routes from updates
4495 suppress-map Conditionally filter more specific routes from updates
4496 <cr>
4497 */
4498struct bgp_aggregate
4499{
4500 /* Summary-only flag. */
4501 u_char summary_only;
4502
4503 /* AS set generation. */
4504 u_char as_set;
4505
4506 /* Route-map for aggregated route. */
4507 struct route_map *map;
4508
4509 /* Suppress-count. */
4510 unsigned long count;
4511
4512 /* SAFI configuration. */
4513 safi_t safi;
4514};
4515
paul94f2b392005-06-28 12:44:16 +00004516static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004517bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004518{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004519 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004520}
4521
paul94f2b392005-06-28 12:44:16 +00004522static void
paul718e3742002-12-13 20:15:29 +00004523bgp_aggregate_free (struct bgp_aggregate *aggregate)
4524{
4525 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4526}
4527
paul94f2b392005-06-28 12:44:16 +00004528static void
paul718e3742002-12-13 20:15:29 +00004529bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4530 afi_t afi, safi_t safi, struct bgp_info *del,
4531 struct bgp_aggregate *aggregate)
4532{
4533 struct bgp_table *table;
4534 struct bgp_node *top;
4535 struct bgp_node *rn;
4536 u_char origin;
4537 struct aspath *aspath = NULL;
4538 struct aspath *asmerge = NULL;
4539 struct community *community = NULL;
4540 struct community *commerge = NULL;
paul718e3742002-12-13 20:15:29 +00004541 struct bgp_info *ri;
4542 struct bgp_info *new;
4543 int first = 1;
4544 unsigned long match = 0;
4545
paul718e3742002-12-13 20:15:29 +00004546 /* ORIGIN attribute: If at least one route among routes that are
4547 aggregated has ORIGIN with the value INCOMPLETE, then the
4548 aggregated route must have the ORIGIN attribute with the value
4549 INCOMPLETE. Otherwise, if at least one route among routes that
4550 are aggregated has ORIGIN with the value EGP, then the aggregated
4551 route must have the origin attribute with the value EGP. In all
4552 other case the value of the ORIGIN attribute of the aggregated
4553 route is INTERNAL. */
4554 origin = BGP_ORIGIN_IGP;
4555
4556 table = bgp->rib[afi][safi];
4557
4558 top = bgp_node_get (table, p);
4559 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4560 if (rn->p.prefixlen > p->prefixlen)
4561 {
4562 match = 0;
4563
4564 for (ri = rn->info; ri; ri = ri->next)
4565 {
4566 if (BGP_INFO_HOLDDOWN (ri))
4567 continue;
4568
4569 if (del && ri == del)
4570 continue;
4571
4572 if (! rinew && first)
Paul Jakma7aa9dce2014-09-19 14:42:23 +01004573 first = 0;
paul718e3742002-12-13 20:15:29 +00004574
4575#ifdef AGGREGATE_NEXTHOP_CHECK
4576 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4577 || ri->attr->med != med)
4578 {
4579 if (aspath)
4580 aspath_free (aspath);
4581 if (community)
4582 community_free (community);
4583 bgp_unlock_node (rn);
4584 bgp_unlock_node (top);
4585 return;
4586 }
4587#endif /* AGGREGATE_NEXTHOP_CHECK */
4588
4589 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4590 {
4591 if (aggregate->summary_only)
4592 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004593 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004594 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004595 match++;
4596 }
4597
4598 aggregate->count++;
4599
4600 if (aggregate->as_set)
4601 {
4602 if (origin < ri->attr->origin)
4603 origin = ri->attr->origin;
4604
4605 if (aspath)
4606 {
4607 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4608 aspath_free (aspath);
4609 aspath = asmerge;
4610 }
4611 else
4612 aspath = aspath_dup (ri->attr->aspath);
4613
4614 if (ri->attr->community)
4615 {
4616 if (community)
4617 {
4618 commerge = community_merge (community,
4619 ri->attr->community);
4620 community = community_uniq_sort (commerge);
4621 community_free (commerge);
4622 }
4623 else
4624 community = community_dup (ri->attr->community);
4625 }
4626 }
4627 }
4628 }
4629 if (match)
4630 bgp_process (bgp, rn, afi, safi);
4631 }
4632 bgp_unlock_node (top);
4633
4634 if (rinew)
4635 {
4636 aggregate->count++;
4637
4638 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004639 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004640
4641 if (aggregate->as_set)
4642 {
4643 if (origin < rinew->attr->origin)
4644 origin = rinew->attr->origin;
4645
4646 if (aspath)
4647 {
4648 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4649 aspath_free (aspath);
4650 aspath = asmerge;
4651 }
4652 else
4653 aspath = aspath_dup (rinew->attr->aspath);
4654
4655 if (rinew->attr->community)
4656 {
4657 if (community)
4658 {
4659 commerge = community_merge (community,
4660 rinew->attr->community);
4661 community = community_uniq_sort (commerge);
4662 community_free (commerge);
4663 }
4664 else
4665 community = community_dup (rinew->attr->community);
4666 }
4667 }
4668 }
4669
4670 if (aggregate->count > 0)
4671 {
4672 rn = bgp_node_get (table, p);
4673 new = bgp_info_new ();
4674 new->type = ZEBRA_ROUTE_BGP;
4675 new->sub_type = BGP_ROUTE_AGGREGATE;
4676 new->peer = bgp->peer_self;
4677 SET_FLAG (new->flags, BGP_INFO_VALID);
4678 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004679 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004680
4681 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004682 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004683 bgp_process (bgp, rn, afi, safi);
4684 }
4685 else
4686 {
4687 if (aspath)
4688 aspath_free (aspath);
4689 if (community)
4690 community_free (community);
4691 }
4692}
4693
4694void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4695 struct bgp_aggregate *);
4696
4697void
4698bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4699 struct bgp_info *ri, afi_t afi, safi_t safi)
4700{
4701 struct bgp_node *child;
4702 struct bgp_node *rn;
4703 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004704 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004705
4706 /* MPLS-VPN aggregation is not yet supported. */
4707 if (safi == SAFI_MPLS_VPN)
4708 return;
4709
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004710 table = bgp->aggregate[afi][safi];
4711
4712 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004713 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004714 return;
4715
paul718e3742002-12-13 20:15:29 +00004716 if (p->prefixlen == 0)
4717 return;
4718
4719 if (BGP_INFO_HOLDDOWN (ri))
4720 return;
4721
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004722 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004723
4724 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004725 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004726 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4727 {
4728 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004729 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004730 }
4731 bgp_unlock_node (child);
4732}
4733
4734void
4735bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4736 struct bgp_info *del, afi_t afi, safi_t safi)
4737{
4738 struct bgp_node *child;
4739 struct bgp_node *rn;
4740 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004741 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004742
4743 /* MPLS-VPN aggregation is not yet supported. */
4744 if (safi == SAFI_MPLS_VPN)
4745 return;
4746
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004747 table = bgp->aggregate[afi][safi];
4748
4749 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004750 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004751 return;
4752
paul718e3742002-12-13 20:15:29 +00004753 if (p->prefixlen == 0)
4754 return;
4755
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004756 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004757
4758 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004759 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004760 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4761 {
4762 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004763 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004764 }
4765 bgp_unlock_node (child);
4766}
4767
paul94f2b392005-06-28 12:44:16 +00004768static void
paul718e3742002-12-13 20:15:29 +00004769bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4770 struct bgp_aggregate *aggregate)
4771{
4772 struct bgp_table *table;
4773 struct bgp_node *top;
4774 struct bgp_node *rn;
4775 struct bgp_info *new;
4776 struct bgp_info *ri;
4777 unsigned long match;
4778 u_char origin = BGP_ORIGIN_IGP;
4779 struct aspath *aspath = NULL;
4780 struct aspath *asmerge = NULL;
4781 struct community *community = NULL;
4782 struct community *commerge = NULL;
4783
4784 table = bgp->rib[afi][safi];
4785
4786 /* Sanity check. */
4787 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4788 return;
4789 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4790 return;
4791
4792 /* If routes exists below this node, generate aggregate routes. */
4793 top = bgp_node_get (table, p);
4794 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4795 if (rn->p.prefixlen > p->prefixlen)
4796 {
4797 match = 0;
4798
4799 for (ri = rn->info; ri; ri = ri->next)
4800 {
4801 if (BGP_INFO_HOLDDOWN (ri))
4802 continue;
4803
4804 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4805 {
4806 /* summary-only aggregate route suppress aggregated
4807 route announcement. */
4808 if (aggregate->summary_only)
4809 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004810 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004811 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004812 match++;
4813 }
4814 /* as-set aggregate route generate origin, as path,
4815 community aggregation. */
4816 if (aggregate->as_set)
4817 {
4818 if (origin < ri->attr->origin)
4819 origin = ri->attr->origin;
4820
4821 if (aspath)
4822 {
4823 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4824 aspath_free (aspath);
4825 aspath = asmerge;
4826 }
4827 else
4828 aspath = aspath_dup (ri->attr->aspath);
4829
4830 if (ri->attr->community)
4831 {
4832 if (community)
4833 {
4834 commerge = community_merge (community,
4835 ri->attr->community);
4836 community = community_uniq_sort (commerge);
4837 community_free (commerge);
4838 }
4839 else
4840 community = community_dup (ri->attr->community);
4841 }
4842 }
4843 aggregate->count++;
4844 }
4845 }
4846
4847 /* If this node is suppressed, process the change. */
4848 if (match)
4849 bgp_process (bgp, rn, afi, safi);
4850 }
4851 bgp_unlock_node (top);
4852
4853 /* Add aggregate route to BGP table. */
4854 if (aggregate->count)
4855 {
4856 rn = bgp_node_get (table, p);
4857
4858 new = bgp_info_new ();
4859 new->type = ZEBRA_ROUTE_BGP;
4860 new->sub_type = BGP_ROUTE_AGGREGATE;
4861 new->peer = bgp->peer_self;
4862 SET_FLAG (new->flags, BGP_INFO_VALID);
4863 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004864 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004865
4866 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004867 bgp_unlock_node (rn);
4868
paul718e3742002-12-13 20:15:29 +00004869 /* Process change. */
4870 bgp_process (bgp, rn, afi, safi);
4871 }
4872}
4873
4874void
4875bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4876 safi_t safi, struct bgp_aggregate *aggregate)
4877{
4878 struct bgp_table *table;
4879 struct bgp_node *top;
4880 struct bgp_node *rn;
4881 struct bgp_info *ri;
4882 unsigned long match;
4883
4884 table = bgp->rib[afi][safi];
4885
4886 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4887 return;
4888 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4889 return;
4890
4891 /* If routes exists below this node, generate aggregate routes. */
4892 top = bgp_node_get (table, p);
4893 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4894 if (rn->p.prefixlen > p->prefixlen)
4895 {
4896 match = 0;
4897
4898 for (ri = rn->info; ri; ri = ri->next)
4899 {
4900 if (BGP_INFO_HOLDDOWN (ri))
4901 continue;
4902
4903 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4904 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004905 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004906 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004907 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004908
Paul Jakmafb982c22007-05-04 20:15:47 +00004909 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004910 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004911 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004912 match++;
4913 }
4914 }
4915 aggregate->count--;
4916 }
4917 }
4918
Paul Jakmafb982c22007-05-04 20:15:47 +00004919 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004920 if (match)
4921 bgp_process (bgp, rn, afi, safi);
4922 }
4923 bgp_unlock_node (top);
4924
4925 /* Delete aggregate route from BGP table. */
4926 rn = bgp_node_get (table, p);
4927
4928 for (ri = rn->info; ri; ri = ri->next)
4929 if (ri->peer == bgp->peer_self
4930 && ri->type == ZEBRA_ROUTE_BGP
4931 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4932 break;
4933
4934 /* Withdraw static BGP route from routing table. */
4935 if (ri)
4936 {
paul718e3742002-12-13 20:15:29 +00004937 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004938 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004939 }
4940
4941 /* Unlock bgp_node_lookup. */
4942 bgp_unlock_node (rn);
4943}
4944
4945/* Aggregate route attribute. */
4946#define AGGREGATE_SUMMARY_ONLY 1
4947#define AGGREGATE_AS_SET 1
4948
paul94f2b392005-06-28 12:44:16 +00004949static int
Robert Baysf6269b42010-08-05 10:26:28 -07004950bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4951 afi_t afi, safi_t safi)
4952{
4953 int ret;
4954 struct prefix p;
4955 struct bgp_node *rn;
4956 struct bgp *bgp;
4957 struct bgp_aggregate *aggregate;
4958
4959 /* Convert string to prefix structure. */
4960 ret = str2prefix (prefix_str, &p);
4961 if (!ret)
4962 {
4963 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4964 return CMD_WARNING;
4965 }
4966 apply_mask (&p);
4967
4968 /* Get BGP structure. */
4969 bgp = vty->index;
4970
4971 /* Old configuration check. */
4972 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4973 if (! rn)
4974 {
4975 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4976 VTY_NEWLINE);
4977 return CMD_WARNING;
4978 }
4979
4980 aggregate = rn->info;
4981 if (aggregate->safi & SAFI_UNICAST)
4982 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4983 if (aggregate->safi & SAFI_MULTICAST)
4984 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4985
4986 /* Unlock aggregate address configuration. */
4987 rn->info = NULL;
4988 bgp_aggregate_free (aggregate);
4989 bgp_unlock_node (rn);
4990 bgp_unlock_node (rn);
4991
4992 return CMD_SUCCESS;
4993}
4994
4995static int
4996bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00004997 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004998 u_char summary_only, u_char as_set)
4999{
5000 int ret;
5001 struct prefix p;
5002 struct bgp_node *rn;
5003 struct bgp *bgp;
5004 struct bgp_aggregate *aggregate;
5005
5006 /* Convert string to prefix structure. */
5007 ret = str2prefix (prefix_str, &p);
5008 if (!ret)
5009 {
5010 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5011 return CMD_WARNING;
5012 }
5013 apply_mask (&p);
5014
5015 /* Get BGP structure. */
5016 bgp = vty->index;
5017
5018 /* Old configuration check. */
5019 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5020
5021 if (rn->info)
5022 {
5023 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005024 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005025 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5026 if (ret)
5027 {
Robert Bays368473f2010-08-05 10:26:29 -07005028 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5029 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005030 return CMD_WARNING;
5031 }
paul718e3742002-12-13 20:15:29 +00005032 }
5033
5034 /* Make aggregate address structure. */
5035 aggregate = bgp_aggregate_new ();
5036 aggregate->summary_only = summary_only;
5037 aggregate->as_set = as_set;
5038 aggregate->safi = safi;
5039 rn->info = aggregate;
5040
5041 /* Aggregate address insert into BGP routing table. */
5042 if (safi & SAFI_UNICAST)
5043 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5044 if (safi & SAFI_MULTICAST)
5045 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5046
5047 return CMD_SUCCESS;
5048}
5049
paul718e3742002-12-13 20:15:29 +00005050DEFUN (aggregate_address,
5051 aggregate_address_cmd,
5052 "aggregate-address A.B.C.D/M",
5053 "Configure BGP aggregate entries\n"
5054 "Aggregate prefix\n")
5055{
5056 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5057}
5058
5059DEFUN (aggregate_address_mask,
5060 aggregate_address_mask_cmd,
5061 "aggregate-address A.B.C.D A.B.C.D",
5062 "Configure BGP aggregate entries\n"
5063 "Aggregate address\n"
5064 "Aggregate mask\n")
5065{
5066 int ret;
5067 char prefix_str[BUFSIZ];
5068
5069 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5070
5071 if (! ret)
5072 {
5073 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5074 return CMD_WARNING;
5075 }
5076
5077 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5078 0, 0);
5079}
5080
5081DEFUN (aggregate_address_summary_only,
5082 aggregate_address_summary_only_cmd,
5083 "aggregate-address A.B.C.D/M summary-only",
5084 "Configure BGP aggregate entries\n"
5085 "Aggregate prefix\n"
5086 "Filter more specific routes from updates\n")
5087{
5088 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5089 AGGREGATE_SUMMARY_ONLY, 0);
5090}
5091
5092DEFUN (aggregate_address_mask_summary_only,
5093 aggregate_address_mask_summary_only_cmd,
5094 "aggregate-address A.B.C.D A.B.C.D summary-only",
5095 "Configure BGP aggregate entries\n"
5096 "Aggregate address\n"
5097 "Aggregate mask\n"
5098 "Filter more specific routes from updates\n")
5099{
5100 int ret;
5101 char prefix_str[BUFSIZ];
5102
5103 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5104
5105 if (! ret)
5106 {
5107 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5108 return CMD_WARNING;
5109 }
5110
5111 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5112 AGGREGATE_SUMMARY_ONLY, 0);
5113}
5114
5115DEFUN (aggregate_address_as_set,
5116 aggregate_address_as_set_cmd,
5117 "aggregate-address A.B.C.D/M as-set",
5118 "Configure BGP aggregate entries\n"
5119 "Aggregate prefix\n"
5120 "Generate AS set path information\n")
5121{
5122 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5123 0, AGGREGATE_AS_SET);
5124}
5125
5126DEFUN (aggregate_address_mask_as_set,
5127 aggregate_address_mask_as_set_cmd,
5128 "aggregate-address A.B.C.D A.B.C.D as-set",
5129 "Configure BGP aggregate entries\n"
5130 "Aggregate address\n"
5131 "Aggregate mask\n"
5132 "Generate AS set path information\n")
5133{
5134 int ret;
5135 char prefix_str[BUFSIZ];
5136
5137 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5138
5139 if (! ret)
5140 {
5141 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5142 return CMD_WARNING;
5143 }
5144
5145 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5146 0, AGGREGATE_AS_SET);
5147}
5148
5149
5150DEFUN (aggregate_address_as_set_summary,
5151 aggregate_address_as_set_summary_cmd,
5152 "aggregate-address A.B.C.D/M as-set summary-only",
5153 "Configure BGP aggregate entries\n"
5154 "Aggregate prefix\n"
5155 "Generate AS set path information\n"
5156 "Filter more specific routes from updates\n")
5157{
5158 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5159 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5160}
5161
5162ALIAS (aggregate_address_as_set_summary,
5163 aggregate_address_summary_as_set_cmd,
5164 "aggregate-address A.B.C.D/M summary-only as-set",
5165 "Configure BGP aggregate entries\n"
5166 "Aggregate prefix\n"
5167 "Filter more specific routes from updates\n"
5168 "Generate AS set path information\n")
5169
5170DEFUN (aggregate_address_mask_as_set_summary,
5171 aggregate_address_mask_as_set_summary_cmd,
5172 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5173 "Configure BGP aggregate entries\n"
5174 "Aggregate address\n"
5175 "Aggregate mask\n"
5176 "Generate AS set path information\n"
5177 "Filter more specific routes from updates\n")
5178{
5179 int ret;
5180 char prefix_str[BUFSIZ];
5181
5182 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5183
5184 if (! ret)
5185 {
5186 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5187 return CMD_WARNING;
5188 }
5189
5190 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5191 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5192}
5193
5194ALIAS (aggregate_address_mask_as_set_summary,
5195 aggregate_address_mask_summary_as_set_cmd,
5196 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5197 "Configure BGP aggregate entries\n"
5198 "Aggregate address\n"
5199 "Aggregate mask\n"
5200 "Filter more specific routes from updates\n"
5201 "Generate AS set path information\n")
5202
5203DEFUN (no_aggregate_address,
5204 no_aggregate_address_cmd,
5205 "no aggregate-address A.B.C.D/M",
5206 NO_STR
5207 "Configure BGP aggregate entries\n"
5208 "Aggregate prefix\n")
5209{
5210 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5211}
5212
5213ALIAS (no_aggregate_address,
5214 no_aggregate_address_summary_only_cmd,
5215 "no aggregate-address A.B.C.D/M summary-only",
5216 NO_STR
5217 "Configure BGP aggregate entries\n"
5218 "Aggregate prefix\n"
5219 "Filter more specific routes from updates\n")
5220
5221ALIAS (no_aggregate_address,
5222 no_aggregate_address_as_set_cmd,
5223 "no aggregate-address A.B.C.D/M as-set",
5224 NO_STR
5225 "Configure BGP aggregate entries\n"
5226 "Aggregate prefix\n"
5227 "Generate AS set path information\n")
5228
5229ALIAS (no_aggregate_address,
5230 no_aggregate_address_as_set_summary_cmd,
5231 "no aggregate-address A.B.C.D/M as-set summary-only",
5232 NO_STR
5233 "Configure BGP aggregate entries\n"
5234 "Aggregate prefix\n"
5235 "Generate AS set path information\n"
5236 "Filter more specific routes from updates\n")
5237
5238ALIAS (no_aggregate_address,
5239 no_aggregate_address_summary_as_set_cmd,
5240 "no aggregate-address A.B.C.D/M summary-only as-set",
5241 NO_STR
5242 "Configure BGP aggregate entries\n"
5243 "Aggregate prefix\n"
5244 "Filter more specific routes from updates\n"
5245 "Generate AS set path information\n")
5246
5247DEFUN (no_aggregate_address_mask,
5248 no_aggregate_address_mask_cmd,
5249 "no aggregate-address A.B.C.D A.B.C.D",
5250 NO_STR
5251 "Configure BGP aggregate entries\n"
5252 "Aggregate address\n"
5253 "Aggregate mask\n")
5254{
5255 int ret;
5256 char prefix_str[BUFSIZ];
5257
5258 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5259
5260 if (! ret)
5261 {
5262 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5263 return CMD_WARNING;
5264 }
5265
5266 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5267}
5268
5269ALIAS (no_aggregate_address_mask,
5270 no_aggregate_address_mask_summary_only_cmd,
5271 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5272 NO_STR
5273 "Configure BGP aggregate entries\n"
5274 "Aggregate address\n"
5275 "Aggregate mask\n"
5276 "Filter more specific routes from updates\n")
5277
5278ALIAS (no_aggregate_address_mask,
5279 no_aggregate_address_mask_as_set_cmd,
5280 "no aggregate-address A.B.C.D A.B.C.D as-set",
5281 NO_STR
5282 "Configure BGP aggregate entries\n"
5283 "Aggregate address\n"
5284 "Aggregate mask\n"
5285 "Generate AS set path information\n")
5286
5287ALIAS (no_aggregate_address_mask,
5288 no_aggregate_address_mask_as_set_summary_cmd,
5289 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5290 NO_STR
5291 "Configure BGP aggregate entries\n"
5292 "Aggregate address\n"
5293 "Aggregate mask\n"
5294 "Generate AS set path information\n"
5295 "Filter more specific routes from updates\n")
5296
5297ALIAS (no_aggregate_address_mask,
5298 no_aggregate_address_mask_summary_as_set_cmd,
5299 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5300 NO_STR
5301 "Configure BGP aggregate entries\n"
5302 "Aggregate address\n"
5303 "Aggregate mask\n"
5304 "Filter more specific routes from updates\n"
5305 "Generate AS set path information\n")
5306
5307#ifdef HAVE_IPV6
5308DEFUN (ipv6_aggregate_address,
5309 ipv6_aggregate_address_cmd,
5310 "aggregate-address X:X::X:X/M",
5311 "Configure BGP aggregate entries\n"
5312 "Aggregate prefix\n")
5313{
5314 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5315}
5316
5317DEFUN (ipv6_aggregate_address_summary_only,
5318 ipv6_aggregate_address_summary_only_cmd,
5319 "aggregate-address X:X::X:X/M summary-only",
5320 "Configure BGP aggregate entries\n"
5321 "Aggregate prefix\n"
5322 "Filter more specific routes from updates\n")
5323{
5324 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5325 AGGREGATE_SUMMARY_ONLY, 0);
5326}
5327
5328DEFUN (no_ipv6_aggregate_address,
5329 no_ipv6_aggregate_address_cmd,
5330 "no aggregate-address X:X::X:X/M",
5331 NO_STR
5332 "Configure BGP aggregate entries\n"
5333 "Aggregate prefix\n")
5334{
5335 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5336}
5337
5338DEFUN (no_ipv6_aggregate_address_summary_only,
5339 no_ipv6_aggregate_address_summary_only_cmd,
5340 "no aggregate-address X:X::X:X/M summary-only",
5341 NO_STR
5342 "Configure BGP aggregate entries\n"
5343 "Aggregate prefix\n"
5344 "Filter more specific routes from updates\n")
5345{
5346 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5347}
5348
5349ALIAS (ipv6_aggregate_address,
5350 old_ipv6_aggregate_address_cmd,
5351 "ipv6 bgp aggregate-address X:X::X:X/M",
5352 IPV6_STR
5353 BGP_STR
5354 "Configure BGP aggregate entries\n"
5355 "Aggregate prefix\n")
5356
5357ALIAS (ipv6_aggregate_address_summary_only,
5358 old_ipv6_aggregate_address_summary_only_cmd,
5359 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5360 IPV6_STR
5361 BGP_STR
5362 "Configure BGP aggregate entries\n"
5363 "Aggregate prefix\n"
5364 "Filter more specific routes from updates\n")
5365
5366ALIAS (no_ipv6_aggregate_address,
5367 old_no_ipv6_aggregate_address_cmd,
5368 "no ipv6 bgp aggregate-address X:X::X:X/M",
5369 NO_STR
5370 IPV6_STR
5371 BGP_STR
5372 "Configure BGP aggregate entries\n"
5373 "Aggregate prefix\n")
5374
5375ALIAS (no_ipv6_aggregate_address_summary_only,
5376 old_no_ipv6_aggregate_address_summary_only_cmd,
5377 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5378 NO_STR
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#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02005385
paul718e3742002-12-13 20:15:29 +00005386/* Redistribute route treatment. */
5387void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005388bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5389 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005390 u_int32_t metric, u_char type)
5391{
5392 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005393 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005394 struct bgp_info *new;
5395 struct bgp_info *bi;
5396 struct bgp_info info;
5397 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005398 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005399 struct attr *new_attr;
5400 afi_t afi;
5401 int ret;
5402
5403 /* Make default attribute. */
5404 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5405 if (nexthop)
5406 attr.nexthop = *nexthop;
5407
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005408#ifdef HAVE_IPV6
5409 if (nexthop6)
5410 {
5411 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5412 extra->mp_nexthop_global = *nexthop6;
5413 extra->mp_nexthop_len = 16;
5414 }
5415#endif
5416
paul718e3742002-12-13 20:15:29 +00005417 attr.med = metric;
5418 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5419
paul1eb8ef22005-04-07 07:30:20 +00005420 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005421 {
5422 afi = family2afi (p->family);
5423
5424 if (bgp->redist[afi][type])
5425 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005426 struct attr attr_new;
5427 struct attr_extra extra_new;
5428
paul718e3742002-12-13 20:15:29 +00005429 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005430 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005431 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005432
5433 if (bgp->redist_metric_flag[afi][type])
5434 attr_new.med = bgp->redist_metric[afi][type];
5435
5436 /* Apply route-map. */
5437 if (bgp->rmap[afi][type].map)
5438 {
5439 info.peer = bgp->peer_self;
5440 info.attr = &attr_new;
5441
paulfee0f4c2004-09-13 05:12:46 +00005442 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5443
paul718e3742002-12-13 20:15:29 +00005444 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5445 &info);
paulfee0f4c2004-09-13 05:12:46 +00005446
5447 bgp->peer_self->rmap_type = 0;
5448
paul718e3742002-12-13 20:15:29 +00005449 if (ret == RMAP_DENYMATCH)
5450 {
5451 /* Free uninterned attribute. */
5452 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005453
paul718e3742002-12-13 20:15:29 +00005454 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005455 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005456 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005457 bgp_redistribute_delete (p, type);
5458 return;
5459 }
5460 }
5461
Paul Jakmafb982c22007-05-04 20:15:47 +00005462 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5463 afi, SAFI_UNICAST, p, NULL);
5464
paul718e3742002-12-13 20:15:29 +00005465 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005466
paul718e3742002-12-13 20:15:29 +00005467 for (bi = bn->info; bi; bi = bi->next)
5468 if (bi->peer == bgp->peer_self
5469 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5470 break;
5471
5472 if (bi)
5473 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005474 if (attrhash_cmp (bi->attr, new_attr) &&
5475 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005476 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005477 bgp_attr_unintern (&new_attr);
5478 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005479 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005480 bgp_unlock_node (bn);
5481 return;
5482 }
5483 else
5484 {
5485 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005486 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005487
5488 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005489 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5490 bgp_info_restore(bn, bi);
5491 else
5492 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005493 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005494 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005495 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005496
5497 /* Process change. */
5498 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5499 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5500 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005501 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005502 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005503 return;
5504 }
5505 }
5506
5507 new = bgp_info_new ();
5508 new->type = type;
5509 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5510 new->peer = bgp->peer_self;
5511 SET_FLAG (new->flags, BGP_INFO_VALID);
5512 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005513 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005514
5515 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5516 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005517 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005518 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5519 }
5520 }
5521
5522 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005523 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005524 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005525}
5526
5527void
5528bgp_redistribute_delete (struct prefix *p, u_char type)
5529{
5530 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005531 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005532 afi_t afi;
5533 struct bgp_node *rn;
5534 struct bgp_info *ri;
5535
paul1eb8ef22005-04-07 07:30:20 +00005536 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005537 {
5538 afi = family2afi (p->family);
5539
5540 if (bgp->redist[afi][type])
5541 {
paulfee0f4c2004-09-13 05:12:46 +00005542 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005543
5544 for (ri = rn->info; ri; ri = ri->next)
5545 if (ri->peer == bgp->peer_self
5546 && ri->type == type)
5547 break;
5548
5549 if (ri)
5550 {
5551 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005552 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005553 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005554 }
5555 bgp_unlock_node (rn);
5556 }
5557 }
5558}
5559
5560/* Withdraw specified route type's route. */
5561void
5562bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5563{
5564 struct bgp_node *rn;
5565 struct bgp_info *ri;
5566 struct bgp_table *table;
5567
5568 table = bgp->rib[afi][SAFI_UNICAST];
5569
5570 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5571 {
5572 for (ri = rn->info; ri; ri = ri->next)
5573 if (ri->peer == bgp->peer_self
5574 && ri->type == type)
5575 break;
5576
5577 if (ri)
5578 {
5579 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005580 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005581 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005582 }
5583 }
5584}
David Lamparter6b0655a2014-06-04 06:53:35 +02005585
paul718e3742002-12-13 20:15:29 +00005586/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005587static void
paul718e3742002-12-13 20:15:29 +00005588route_vty_out_route (struct prefix *p, struct vty *vty)
5589{
5590 int len;
5591 u_int32_t destination;
5592 char buf[BUFSIZ];
5593
5594 if (p->family == AF_INET)
5595 {
5596 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5597 destination = ntohl (p->u.prefix4.s_addr);
5598
5599 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5600 || (IN_CLASSB (destination) && p->prefixlen == 16)
5601 || (IN_CLASSA (destination) && p->prefixlen == 8)
5602 || p->u.prefix4.s_addr == 0)
5603 {
5604 /* When mask is natural, mask is not displayed. */
5605 }
5606 else
5607 len += vty_out (vty, "/%d", p->prefixlen);
5608 }
5609 else
5610 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5611 p->prefixlen);
5612
5613 len = 17 - len;
5614 if (len < 1)
5615 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5616 else
5617 vty_out (vty, "%*s", len, " ");
5618}
5619
paul718e3742002-12-13 20:15:29 +00005620enum bgp_display_type
5621{
5622 normal_list,
5623};
5624
paulb40d9392005-08-22 22:34:41 +00005625/* Print the short form route status for a bgp_info */
5626static void
5627route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005628{
paulb40d9392005-08-22 22:34:41 +00005629 /* Route status display. */
5630 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5631 vty_out (vty, "R");
5632 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005633 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005634 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005635 vty_out (vty, "s");
5636 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5637 vty_out (vty, "*");
5638 else
5639 vty_out (vty, " ");
5640
5641 /* Selected */
5642 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5643 vty_out (vty, "h");
5644 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5645 vty_out (vty, "d");
5646 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5647 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005648 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5649 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005650 else
5651 vty_out (vty, " ");
5652
5653 /* Internal route. */
5654 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5655 vty_out (vty, "i");
5656 else
paulb40d9392005-08-22 22:34:41 +00005657 vty_out (vty, " ");
5658}
5659
5660/* called from terminal list command */
5661void
5662route_vty_out (struct vty *vty, struct prefix *p,
5663 struct bgp_info *binfo, int display, safi_t safi)
5664{
5665 struct attr *attr;
5666
5667 /* short status lead text */
5668 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005669
5670 /* print prefix and mask */
5671 if (! display)
5672 route_vty_out_route (p, vty);
5673 else
5674 vty_out (vty, "%*s", 17, " ");
5675
5676 /* Print attribute */
5677 attr = binfo->attr;
5678 if (attr)
5679 {
5680 if (p->family == AF_INET)
5681 {
5682 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005683 vty_out (vty, "%-16s",
5684 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005685 else
5686 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5687 }
5688#ifdef HAVE_IPV6
5689 else if (p->family == AF_INET6)
5690 {
5691 int len;
5692 char buf[BUFSIZ];
5693
5694 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005695 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5696 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005697 len = 16 - len;
5698 if (len < 1)
5699 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5700 else
5701 vty_out (vty, "%*s", len, " ");
5702 }
5703#endif /* HAVE_IPV6 */
5704
5705 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005706 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005707 else
5708 vty_out (vty, " ");
5709
5710 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005711 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005712 else
5713 vty_out (vty, " ");
5714
Paul Jakmafb982c22007-05-04 20:15:47 +00005715 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005716
Paul Jakmab2518c12006-05-12 23:48:40 +00005717 /* Print aspath */
5718 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005719 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005720
Paul Jakmab2518c12006-05-12 23:48:40 +00005721 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005722 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005723 }
paul718e3742002-12-13 20:15:29 +00005724 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005725}
5726
5727/* called from terminal list command */
5728void
5729route_vty_out_tmp (struct vty *vty, struct prefix *p,
5730 struct attr *attr, safi_t safi)
5731{
5732 /* Route status display. */
5733 vty_out (vty, "*");
5734 vty_out (vty, ">");
5735 vty_out (vty, " ");
5736
5737 /* print prefix and mask */
5738 route_vty_out_route (p, vty);
5739
5740 /* Print attribute */
5741 if (attr)
5742 {
5743 if (p->family == AF_INET)
5744 {
5745 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005746 vty_out (vty, "%-16s",
5747 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005748 else
5749 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5750 }
5751#ifdef HAVE_IPV6
5752 else if (p->family == AF_INET6)
5753 {
5754 int len;
5755 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005756
5757 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005758
5759 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005760 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5761 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005762 len = 16 - len;
5763 if (len < 1)
5764 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5765 else
5766 vty_out (vty, "%*s", len, " ");
5767 }
5768#endif /* HAVE_IPV6 */
5769
5770 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005771 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005772 else
5773 vty_out (vty, " ");
5774
5775 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005776 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005777 else
5778 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005779
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005780 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005781
Paul Jakmab2518c12006-05-12 23:48:40 +00005782 /* Print aspath */
5783 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005784 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005785
Paul Jakmab2518c12006-05-12 23:48:40 +00005786 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005787 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005788 }
paul718e3742002-12-13 20:15:29 +00005789
5790 vty_out (vty, "%s", VTY_NEWLINE);
5791}
5792
ajs5a646652004-11-05 01:25:55 +00005793void
paul718e3742002-12-13 20:15:29 +00005794route_vty_out_tag (struct vty *vty, struct prefix *p,
5795 struct bgp_info *binfo, int display, safi_t safi)
5796{
5797 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005798 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005799
5800 if (!binfo->extra)
5801 return;
5802
paulb40d9392005-08-22 22:34:41 +00005803 /* short status lead text */
5804 route_vty_short_status_out (vty, binfo);
5805
paul718e3742002-12-13 20:15:29 +00005806 /* print prefix and mask */
5807 if (! display)
5808 route_vty_out_route (p, vty);
5809 else
5810 vty_out (vty, "%*s", 17, " ");
5811
5812 /* Print attribute */
5813 attr = binfo->attr;
5814 if (attr)
5815 {
5816 if (p->family == AF_INET)
5817 {
5818 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005819 vty_out (vty, "%-16s",
5820 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005821 else
5822 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5823 }
5824#ifdef HAVE_IPV6
5825 else if (p->family == AF_INET6)
5826 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005827 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005828 char buf[BUFSIZ];
5829 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005830 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005831 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005832 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5833 buf, BUFSIZ));
5834 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005835 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005836 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5837 buf, BUFSIZ),
5838 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5839 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005840
5841 }
5842#endif /* HAVE_IPV6 */
5843 }
5844
Paul Jakmafb982c22007-05-04 20:15:47 +00005845 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005846
5847 vty_out (vty, "notag/%d", label);
5848
5849 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005850}
5851
5852/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005853static void
paul718e3742002-12-13 20:15:29 +00005854damp_route_vty_out (struct vty *vty, struct prefix *p,
5855 struct bgp_info *binfo, int display, safi_t safi)
5856{
5857 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005858 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005859 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005860
paulb40d9392005-08-22 22:34:41 +00005861 /* short status lead text */
5862 route_vty_short_status_out (vty, binfo);
5863
paul718e3742002-12-13 20:15:29 +00005864 /* print prefix and mask */
5865 if (! display)
5866 route_vty_out_route (p, vty);
5867 else
5868 vty_out (vty, "%*s", 17, " ");
5869
5870 len = vty_out (vty, "%s", binfo->peer->host);
5871 len = 17 - len;
5872 if (len < 1)
5873 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5874 else
5875 vty_out (vty, "%*s", len, " ");
5876
Chris Caputo50aef6f2009-06-23 06:06:49 +00005877 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005878
5879 /* Print attribute */
5880 attr = binfo->attr;
5881 if (attr)
5882 {
5883 /* Print aspath */
5884 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005885 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005886
5887 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005888 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005889 }
5890 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005891}
5892
paul718e3742002-12-13 20:15:29 +00005893/* flap route */
ajs5a646652004-11-05 01:25:55 +00005894static void
paul718e3742002-12-13 20:15:29 +00005895flap_route_vty_out (struct vty *vty, struct prefix *p,
5896 struct bgp_info *binfo, int display, safi_t safi)
5897{
5898 struct attr *attr;
5899 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005900 char timebuf[BGP_UPTIME_LEN];
5901 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005902
5903 if (!binfo->extra)
5904 return;
5905
5906 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005907
paulb40d9392005-08-22 22:34:41 +00005908 /* short status lead text */
5909 route_vty_short_status_out (vty, binfo);
5910
paul718e3742002-12-13 20:15:29 +00005911 /* print prefix and mask */
5912 if (! display)
5913 route_vty_out_route (p, vty);
5914 else
5915 vty_out (vty, "%*s", 17, " ");
5916
5917 len = vty_out (vty, "%s", binfo->peer->host);
5918 len = 16 - len;
5919 if (len < 1)
5920 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5921 else
5922 vty_out (vty, "%*s", len, " ");
5923
5924 len = vty_out (vty, "%d", bdi->flap);
5925 len = 5 - len;
5926 if (len < 1)
5927 vty_out (vty, " ");
5928 else
5929 vty_out (vty, "%*s ", len, " ");
5930
5931 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5932 timebuf, BGP_UPTIME_LEN));
5933
5934 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5935 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005936 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005937 else
5938 vty_out (vty, "%*s ", 8, " ");
5939
5940 /* Print attribute */
5941 attr = binfo->attr;
5942 if (attr)
5943 {
5944 /* Print aspath */
5945 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005946 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005947
5948 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005949 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005950 }
5951 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005952}
5953
paul94f2b392005-06-28 12:44:16 +00005954static void
paul718e3742002-12-13 20:15:29 +00005955route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5956 struct bgp_info *binfo, afi_t afi, safi_t safi)
5957{
5958 char buf[INET6_ADDRSTRLEN];
5959 char buf1[BUFSIZ];
5960 struct attr *attr;
5961 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005962#ifdef HAVE_CLOCK_MONOTONIC
5963 time_t tbuf;
5964#endif
paul718e3742002-12-13 20:15:29 +00005965
5966 attr = binfo->attr;
5967
5968 if (attr)
5969 {
5970 /* Line1 display AS-path, Aggregator */
5971 if (attr->aspath)
5972 {
5973 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005974 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005975 vty_out (vty, "Local");
5976 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005977 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005978 }
5979
paulb40d9392005-08-22 22:34:41 +00005980 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5981 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005982 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5983 vty_out (vty, ", (stale)");
5984 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005985 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005986 attr->extra->aggregator_as,
5987 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005988 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5989 vty_out (vty, ", (Received from a RR-client)");
5990 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5991 vty_out (vty, ", (Received from a RS-client)");
5992 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5993 vty_out (vty, ", (history entry)");
5994 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5995 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005996 vty_out (vty, "%s", VTY_NEWLINE);
5997
5998 /* Line2 display Next-hop, Neighbor, Router-id */
5999 if (p->family == AF_INET)
6000 {
6001 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006002 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006003 inet_ntoa (attr->nexthop));
6004 }
6005#ifdef HAVE_IPV6
6006 else
6007 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006008 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006009 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006010 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006011 buf, INET6_ADDRSTRLEN));
6012 }
6013#endif /* HAVE_IPV6 */
6014
6015 if (binfo->peer == bgp->peer_self)
6016 {
6017 vty_out (vty, " from %s ",
6018 p->family == AF_INET ? "0.0.0.0" : "::");
6019 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6020 }
6021 else
6022 {
6023 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6024 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006025 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006026 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006027 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006028 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006029 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006030 else
6031 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6032 }
6033 vty_out (vty, "%s", VTY_NEWLINE);
6034
6035#ifdef HAVE_IPV6
6036 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006037 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006038 {
6039 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006040 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006041 buf, INET6_ADDRSTRLEN),
6042 VTY_NEWLINE);
6043 }
6044#endif /* HAVE_IPV6 */
6045
6046 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6047 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6048
6049 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006050 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006051
6052 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006053 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006054 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006055 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006056
Paul Jakmafb982c22007-05-04 20:15:47 +00006057 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006058 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006059
6060 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6061 vty_out (vty, ", valid");
6062
6063 if (binfo->peer != bgp->peer_self)
6064 {
6065 if (binfo->peer->as == binfo->peer->local_as)
6066 vty_out (vty, ", internal");
6067 else
6068 vty_out (vty, ", %s",
6069 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6070 }
6071 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6072 vty_out (vty, ", aggregated, local");
6073 else if (binfo->type != ZEBRA_ROUTE_BGP)
6074 vty_out (vty, ", sourced");
6075 else
6076 vty_out (vty, ", sourced, local");
6077
6078 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6079 vty_out (vty, ", atomic-aggregate");
6080
Josh Baileyde8d5df2011-07-20 20:46:01 -07006081 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6082 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6083 bgp_info_mpath_count (binfo)))
6084 vty_out (vty, ", multipath");
6085
paul718e3742002-12-13 20:15:29 +00006086 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6087 vty_out (vty, ", best");
6088
6089 vty_out (vty, "%s", VTY_NEWLINE);
6090
6091 /* Line 4 display Community */
6092 if (attr->community)
6093 vty_out (vty, " Community: %s%s", attr->community->str,
6094 VTY_NEWLINE);
6095
6096 /* Line 5 display Extended-community */
6097 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006098 vty_out (vty, " Extended Community: %s%s",
6099 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006100
6101 /* Line 6 display Originator, Cluster-id */
6102 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6103 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6104 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006105 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006106 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006107 vty_out (vty, " Originator: %s",
6108 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006109
6110 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6111 {
6112 int i;
6113 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006114 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6115 vty_out (vty, "%s ",
6116 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006117 }
6118 vty_out (vty, "%s", VTY_NEWLINE);
6119 }
Paul Jakma41367172007-08-06 15:24:51 +00006120
Paul Jakmafb982c22007-05-04 20:15:47 +00006121 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006122 bgp_damp_info_vty (vty, binfo);
6123
6124 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006125#ifdef HAVE_CLOCK_MONOTONIC
6126 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006127 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006128#else
6129 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6130#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006131 }
6132 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006133}
6134
6135#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6136 "h history, * valid, > best, = multipath,%s"\
6137 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006138#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006139#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6140#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6141#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6142
6143enum bgp_show_type
6144{
6145 bgp_show_type_normal,
6146 bgp_show_type_regexp,
6147 bgp_show_type_prefix_list,
6148 bgp_show_type_filter_list,
6149 bgp_show_type_route_map,
6150 bgp_show_type_neighbor,
6151 bgp_show_type_cidr_only,
6152 bgp_show_type_prefix_longer,
6153 bgp_show_type_community_all,
6154 bgp_show_type_community,
6155 bgp_show_type_community_exact,
6156 bgp_show_type_community_list,
6157 bgp_show_type_community_list_exact,
6158 bgp_show_type_flap_statistics,
6159 bgp_show_type_flap_address,
6160 bgp_show_type_flap_prefix,
6161 bgp_show_type_flap_cidr_only,
6162 bgp_show_type_flap_regexp,
6163 bgp_show_type_flap_filter_list,
6164 bgp_show_type_flap_prefix_list,
6165 bgp_show_type_flap_prefix_longer,
6166 bgp_show_type_flap_route_map,
6167 bgp_show_type_flap_neighbor,
6168 bgp_show_type_dampend_paths,
6169 bgp_show_type_damp_neighbor
6170};
6171
ajs5a646652004-11-05 01:25:55 +00006172static int
paulfee0f4c2004-09-13 05:12:46 +00006173bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006174 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006175{
paul718e3742002-12-13 20:15:29 +00006176 struct bgp_info *ri;
6177 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006178 int header = 1;
paul718e3742002-12-13 20:15:29 +00006179 int display;
ajs5a646652004-11-05 01:25:55 +00006180 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006181
6182 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006183 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006184
paul718e3742002-12-13 20:15:29 +00006185 /* Start processing of routes. */
6186 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6187 if (rn->info != NULL)
6188 {
6189 display = 0;
6190
6191 for (ri = rn->info; ri; ri = ri->next)
6192 {
ajs5a646652004-11-05 01:25:55 +00006193 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006194 || type == bgp_show_type_flap_address
6195 || type == bgp_show_type_flap_prefix
6196 || type == bgp_show_type_flap_cidr_only
6197 || type == bgp_show_type_flap_regexp
6198 || type == bgp_show_type_flap_filter_list
6199 || type == bgp_show_type_flap_prefix_list
6200 || type == bgp_show_type_flap_prefix_longer
6201 || type == bgp_show_type_flap_route_map
6202 || type == bgp_show_type_flap_neighbor
6203 || type == bgp_show_type_dampend_paths
6204 || type == bgp_show_type_damp_neighbor)
6205 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006206 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006207 continue;
6208 }
6209 if (type == bgp_show_type_regexp
6210 || type == bgp_show_type_flap_regexp)
6211 {
ajs5a646652004-11-05 01:25:55 +00006212 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006213
6214 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6215 continue;
6216 }
6217 if (type == bgp_show_type_prefix_list
6218 || type == bgp_show_type_flap_prefix_list)
6219 {
ajs5a646652004-11-05 01:25:55 +00006220 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006221
6222 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6223 continue;
6224 }
6225 if (type == bgp_show_type_filter_list
6226 || type == bgp_show_type_flap_filter_list)
6227 {
ajs5a646652004-11-05 01:25:55 +00006228 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006229
6230 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6231 continue;
6232 }
6233 if (type == bgp_show_type_route_map
6234 || type == bgp_show_type_flap_route_map)
6235 {
ajs5a646652004-11-05 01:25:55 +00006236 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006237 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006238 struct attr dummy_attr;
6239 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006240 int ret;
6241
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006242 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006243 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006244
paul718e3742002-12-13 20:15:29 +00006245 binfo.peer = ri->peer;
6246 binfo.attr = &dummy_attr;
6247
6248 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006249 if (ret == RMAP_DENYMATCH)
6250 continue;
6251 }
6252 if (type == bgp_show_type_neighbor
6253 || type == bgp_show_type_flap_neighbor
6254 || type == bgp_show_type_damp_neighbor)
6255 {
ajs5a646652004-11-05 01:25:55 +00006256 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006257
6258 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6259 continue;
6260 }
6261 if (type == bgp_show_type_cidr_only
6262 || type == bgp_show_type_flap_cidr_only)
6263 {
6264 u_int32_t destination;
6265
6266 destination = ntohl (rn->p.u.prefix4.s_addr);
6267 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6268 continue;
6269 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6270 continue;
6271 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6272 continue;
6273 }
6274 if (type == bgp_show_type_prefix_longer
6275 || type == bgp_show_type_flap_prefix_longer)
6276 {
ajs5a646652004-11-05 01:25:55 +00006277 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006278
6279 if (! prefix_match (p, &rn->p))
6280 continue;
6281 }
6282 if (type == bgp_show_type_community_all)
6283 {
6284 if (! ri->attr->community)
6285 continue;
6286 }
6287 if (type == bgp_show_type_community)
6288 {
ajs5a646652004-11-05 01:25:55 +00006289 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006290
6291 if (! ri->attr->community ||
6292 ! community_match (ri->attr->community, com))
6293 continue;
6294 }
6295 if (type == bgp_show_type_community_exact)
6296 {
ajs5a646652004-11-05 01:25:55 +00006297 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006298
6299 if (! ri->attr->community ||
6300 ! community_cmp (ri->attr->community, com))
6301 continue;
6302 }
6303 if (type == bgp_show_type_community_list)
6304 {
ajs5a646652004-11-05 01:25:55 +00006305 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006306
6307 if (! community_list_match (ri->attr->community, list))
6308 continue;
6309 }
6310 if (type == bgp_show_type_community_list_exact)
6311 {
ajs5a646652004-11-05 01:25:55 +00006312 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006313
6314 if (! community_list_exact_match (ri->attr->community, list))
6315 continue;
6316 }
6317 if (type == bgp_show_type_flap_address
6318 || type == bgp_show_type_flap_prefix)
6319 {
ajs5a646652004-11-05 01:25:55 +00006320 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006321
6322 if (! prefix_match (&rn->p, p))
6323 continue;
6324
6325 if (type == bgp_show_type_flap_prefix)
6326 if (p->prefixlen != rn->p.prefixlen)
6327 continue;
6328 }
6329 if (type == bgp_show_type_dampend_paths
6330 || type == bgp_show_type_damp_neighbor)
6331 {
6332 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6333 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6334 continue;
6335 }
6336
6337 if (header)
6338 {
hasso93406d82005-02-02 14:40:33 +00006339 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6340 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6341 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006342 if (type == bgp_show_type_dampend_paths
6343 || type == bgp_show_type_damp_neighbor)
6344 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6345 else if (type == bgp_show_type_flap_statistics
6346 || type == bgp_show_type_flap_address
6347 || type == bgp_show_type_flap_prefix
6348 || type == bgp_show_type_flap_cidr_only
6349 || type == bgp_show_type_flap_regexp
6350 || type == bgp_show_type_flap_filter_list
6351 || type == bgp_show_type_flap_prefix_list
6352 || type == bgp_show_type_flap_prefix_longer
6353 || type == bgp_show_type_flap_route_map
6354 || type == bgp_show_type_flap_neighbor)
6355 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6356 else
6357 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006358 header = 0;
6359 }
6360
6361 if (type == bgp_show_type_dampend_paths
6362 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006363 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006364 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)
ajs5a646652004-11-05 01:25:55 +00006374 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006375 else
ajs5a646652004-11-05 01:25:55 +00006376 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006377 display++;
6378 }
6379 if (display)
ajs5a646652004-11-05 01:25:55 +00006380 output_count++;
paul718e3742002-12-13 20:15:29 +00006381 }
6382
6383 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006384 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006385 {
6386 if (type == bgp_show_type_normal)
6387 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6388 }
6389 else
6390 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006391 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006392
6393 return CMD_SUCCESS;
6394}
6395
ajs5a646652004-11-05 01:25:55 +00006396static int
paulfee0f4c2004-09-13 05:12:46 +00006397bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006398 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006399{
6400 struct bgp_table *table;
6401
6402 if (bgp == NULL) {
6403 bgp = bgp_get_default ();
6404 }
6405
6406 if (bgp == NULL)
6407 {
6408 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6409 return CMD_WARNING;
6410 }
6411
6412
6413 table = bgp->rib[afi][safi];
6414
ajs5a646652004-11-05 01:25:55 +00006415 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006416}
6417
paul718e3742002-12-13 20:15:29 +00006418/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006419static void
paul718e3742002-12-13 20:15:29 +00006420route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6421 struct bgp_node *rn,
6422 struct prefix_rd *prd, afi_t afi, safi_t safi)
6423{
6424 struct bgp_info *ri;
6425 struct prefix *p;
6426 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006427 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006428 char buf1[INET6_ADDRSTRLEN];
6429 char buf2[INET6_ADDRSTRLEN];
6430 int count = 0;
6431 int best = 0;
6432 int suppress = 0;
6433 int no_export = 0;
6434 int no_advertise = 0;
6435 int local_as = 0;
6436 int first = 0;
6437
6438 p = &rn->p;
6439 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6440 (safi == SAFI_MPLS_VPN ?
6441 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6442 safi == SAFI_MPLS_VPN ? ":" : "",
6443 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6444 p->prefixlen, VTY_NEWLINE);
6445
6446 for (ri = rn->info; ri; ri = ri->next)
6447 {
6448 count++;
6449 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6450 {
6451 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006452 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006453 suppress = 1;
6454 if (ri->attr->community != NULL)
6455 {
6456 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6457 no_advertise = 1;
6458 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6459 no_export = 1;
6460 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6461 local_as = 1;
6462 }
6463 }
6464 }
6465
6466 vty_out (vty, "Paths: (%d available", count);
6467 if (best)
6468 {
6469 vty_out (vty, ", best #%d", best);
6470 if (safi == SAFI_UNICAST)
6471 vty_out (vty, ", table Default-IP-Routing-Table");
6472 }
6473 else
6474 vty_out (vty, ", no best path");
6475 if (no_advertise)
6476 vty_out (vty, ", not advertised to any peer");
6477 else if (no_export)
6478 vty_out (vty, ", not advertised to EBGP peer");
6479 else if (local_as)
6480 vty_out (vty, ", not advertised outside local AS");
6481 if (suppress)
6482 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6483 vty_out (vty, ")%s", VTY_NEWLINE);
6484
6485 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006486 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006487 {
6488 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6489 {
6490 if (! first)
6491 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6492 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6493 first = 1;
6494 }
6495 }
6496 if (! first)
6497 vty_out (vty, " Not advertised to any peer");
6498 vty_out (vty, "%s", VTY_NEWLINE);
6499}
6500
6501/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006502static int
paulfee0f4c2004-09-13 05:12:46 +00006503bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006504 struct bgp_table *rib, const char *ip_str,
6505 afi_t afi, safi_t safi, struct prefix_rd *prd,
6506 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006507{
6508 int ret;
6509 int header;
6510 int display = 0;
6511 struct prefix match;
6512 struct bgp_node *rn;
6513 struct bgp_node *rm;
6514 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006515 struct bgp_table *table;
6516
paul718e3742002-12-13 20:15:29 +00006517 /* Check IP address argument. */
6518 ret = str2prefix (ip_str, &match);
6519 if (! ret)
6520 {
6521 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6522 return CMD_WARNING;
6523 }
6524
6525 match.family = afi2family (afi);
6526
6527 if (safi == SAFI_MPLS_VPN)
6528 {
paulfee0f4c2004-09-13 05:12:46 +00006529 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006530 {
6531 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6532 continue;
6533
6534 if ((table = rn->info) != NULL)
6535 {
6536 header = 1;
6537
6538 if ((rm = bgp_node_match (table, &match)) != NULL)
6539 {
6540 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006541 {
6542 bgp_unlock_node (rm);
6543 continue;
6544 }
paul718e3742002-12-13 20:15:29 +00006545
6546 for (ri = rm->info; ri; ri = ri->next)
6547 {
6548 if (header)
6549 {
6550 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6551 AFI_IP, SAFI_MPLS_VPN);
6552
6553 header = 0;
6554 }
6555 display++;
6556 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6557 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006558
6559 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006560 }
6561 }
6562 }
6563 }
6564 else
6565 {
6566 header = 1;
6567
paulfee0f4c2004-09-13 05:12:46 +00006568 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006569 {
6570 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6571 {
6572 for (ri = rn->info; ri; ri = ri->next)
6573 {
6574 if (header)
6575 {
6576 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6577 header = 0;
6578 }
6579 display++;
6580 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6581 }
6582 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006583
6584 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006585 }
6586 }
6587
6588 if (! display)
6589 {
6590 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6591 return CMD_WARNING;
6592 }
6593
6594 return CMD_SUCCESS;
6595}
6596
paulfee0f4c2004-09-13 05:12:46 +00006597/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006598static int
paulfd79ac92004-10-13 05:06:08 +00006599bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006600 afi_t afi, safi_t safi, struct prefix_rd *prd,
6601 int prefix_check)
6602{
6603 struct bgp *bgp;
6604
6605 /* BGP structure lookup. */
6606 if (view_name)
6607 {
6608 bgp = bgp_lookup_by_name (view_name);
6609 if (bgp == NULL)
6610 {
6611 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6612 return CMD_WARNING;
6613 }
6614 }
6615 else
6616 {
6617 bgp = bgp_get_default ();
6618 if (bgp == NULL)
6619 {
6620 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6621 return CMD_WARNING;
6622 }
6623 }
6624
6625 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6626 afi, safi, prd, prefix_check);
6627}
6628
paul718e3742002-12-13 20:15:29 +00006629/* BGP route print out function. */
6630DEFUN (show_ip_bgp,
6631 show_ip_bgp_cmd,
6632 "show ip bgp",
6633 SHOW_STR
6634 IP_STR
6635 BGP_STR)
6636{
ajs5a646652004-11-05 01:25:55 +00006637 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006638}
6639
6640DEFUN (show_ip_bgp_ipv4,
6641 show_ip_bgp_ipv4_cmd,
6642 "show ip bgp ipv4 (unicast|multicast)",
6643 SHOW_STR
6644 IP_STR
6645 BGP_STR
6646 "Address family\n"
6647 "Address Family modifier\n"
6648 "Address Family modifier\n")
6649{
6650 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006651 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6652 NULL);
paul718e3742002-12-13 20:15:29 +00006653
ajs5a646652004-11-05 01:25:55 +00006654 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006655}
6656
Michael Lambert95cbbd22010-07-23 14:43:04 -04006657ALIAS (show_ip_bgp_ipv4,
6658 show_bgp_ipv4_safi_cmd,
6659 "show bgp ipv4 (unicast|multicast)",
6660 SHOW_STR
6661 BGP_STR
6662 "Address family\n"
6663 "Address Family modifier\n"
6664 "Address Family modifier\n")
6665
paul718e3742002-12-13 20:15:29 +00006666DEFUN (show_ip_bgp_route,
6667 show_ip_bgp_route_cmd,
6668 "show ip bgp A.B.C.D",
6669 SHOW_STR
6670 IP_STR
6671 BGP_STR
6672 "Network in the BGP routing table to display\n")
6673{
6674 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6675}
6676
6677DEFUN (show_ip_bgp_ipv4_route,
6678 show_ip_bgp_ipv4_route_cmd,
6679 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6680 SHOW_STR
6681 IP_STR
6682 BGP_STR
6683 "Address family\n"
6684 "Address Family modifier\n"
6685 "Address Family modifier\n"
6686 "Network in the BGP routing table to display\n")
6687{
6688 if (strncmp (argv[0], "m", 1) == 0)
6689 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6690
6691 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6692}
6693
Michael Lambert95cbbd22010-07-23 14:43:04 -04006694ALIAS (show_ip_bgp_ipv4_route,
6695 show_bgp_ipv4_safi_route_cmd,
6696 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6697 SHOW_STR
6698 BGP_STR
6699 "Address family\n"
6700 "Address Family modifier\n"
6701 "Address Family modifier\n"
6702 "Network in the BGP routing table to display\n")
6703
paul718e3742002-12-13 20:15:29 +00006704DEFUN (show_ip_bgp_vpnv4_all_route,
6705 show_ip_bgp_vpnv4_all_route_cmd,
6706 "show ip bgp vpnv4 all A.B.C.D",
6707 SHOW_STR
6708 IP_STR
6709 BGP_STR
6710 "Display VPNv4 NLRI specific information\n"
6711 "Display information about all VPNv4 NLRIs\n"
6712 "Network in the BGP routing table to display\n")
6713{
6714 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6715}
6716
6717DEFUN (show_ip_bgp_vpnv4_rd_route,
6718 show_ip_bgp_vpnv4_rd_route_cmd,
6719 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6720 SHOW_STR
6721 IP_STR
6722 BGP_STR
6723 "Display VPNv4 NLRI specific information\n"
6724 "Display information for a route distinguisher\n"
6725 "VPN Route Distinguisher\n"
6726 "Network in the BGP routing table to display\n")
6727{
6728 int ret;
6729 struct prefix_rd prd;
6730
6731 ret = str2prefix_rd (argv[0], &prd);
6732 if (! ret)
6733 {
6734 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6735 return CMD_WARNING;
6736 }
6737 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6738}
6739
6740DEFUN (show_ip_bgp_prefix,
6741 show_ip_bgp_prefix_cmd,
6742 "show ip bgp A.B.C.D/M",
6743 SHOW_STR
6744 IP_STR
6745 BGP_STR
6746 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6747{
6748 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6749}
6750
6751DEFUN (show_ip_bgp_ipv4_prefix,
6752 show_ip_bgp_ipv4_prefix_cmd,
6753 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6754 SHOW_STR
6755 IP_STR
6756 BGP_STR
6757 "Address family\n"
6758 "Address Family modifier\n"
6759 "Address Family modifier\n"
6760 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6761{
6762 if (strncmp (argv[0], "m", 1) == 0)
6763 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6764
6765 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6766}
6767
Michael Lambert95cbbd22010-07-23 14:43:04 -04006768ALIAS (show_ip_bgp_ipv4_prefix,
6769 show_bgp_ipv4_safi_prefix_cmd,
6770 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6771 SHOW_STR
6772 BGP_STR
6773 "Address family\n"
6774 "Address Family modifier\n"
6775 "Address Family modifier\n"
6776 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6777
paul718e3742002-12-13 20:15:29 +00006778DEFUN (show_ip_bgp_vpnv4_all_prefix,
6779 show_ip_bgp_vpnv4_all_prefix_cmd,
6780 "show ip bgp vpnv4 all A.B.C.D/M",
6781 SHOW_STR
6782 IP_STR
6783 BGP_STR
6784 "Display VPNv4 NLRI specific information\n"
6785 "Display information about all VPNv4 NLRIs\n"
6786 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6787{
6788 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6789}
6790
6791DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6792 show_ip_bgp_vpnv4_rd_prefix_cmd,
6793 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6794 SHOW_STR
6795 IP_STR
6796 BGP_STR
6797 "Display VPNv4 NLRI specific information\n"
6798 "Display information for a route distinguisher\n"
6799 "VPN Route Distinguisher\n"
6800 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6801{
6802 int ret;
6803 struct prefix_rd prd;
6804
6805 ret = str2prefix_rd (argv[0], &prd);
6806 if (! ret)
6807 {
6808 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6809 return CMD_WARNING;
6810 }
6811 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6812}
6813
6814DEFUN (show_ip_bgp_view,
6815 show_ip_bgp_view_cmd,
6816 "show ip bgp view WORD",
6817 SHOW_STR
6818 IP_STR
6819 BGP_STR
6820 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006821 "View name\n")
paul718e3742002-12-13 20:15:29 +00006822{
paulbb46e942003-10-24 19:02:03 +00006823 struct bgp *bgp;
6824
6825 /* BGP structure lookup. */
6826 bgp = bgp_lookup_by_name (argv[0]);
6827 if (bgp == NULL)
6828 {
6829 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6830 return CMD_WARNING;
6831 }
6832
ajs5a646652004-11-05 01:25:55 +00006833 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006834}
6835
6836DEFUN (show_ip_bgp_view_route,
6837 show_ip_bgp_view_route_cmd,
6838 "show ip bgp view WORD A.B.C.D",
6839 SHOW_STR
6840 IP_STR
6841 BGP_STR
6842 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006843 "View name\n"
paul718e3742002-12-13 20:15:29 +00006844 "Network in the BGP routing table to display\n")
6845{
6846 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6847}
6848
6849DEFUN (show_ip_bgp_view_prefix,
6850 show_ip_bgp_view_prefix_cmd,
6851 "show ip bgp view WORD A.B.C.D/M",
6852 SHOW_STR
6853 IP_STR
6854 BGP_STR
6855 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006856 "View name\n"
paul718e3742002-12-13 20:15:29 +00006857 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6858{
6859 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6860}
6861
6862#ifdef HAVE_IPV6
6863DEFUN (show_bgp,
6864 show_bgp_cmd,
6865 "show bgp",
6866 SHOW_STR
6867 BGP_STR)
6868{
ajs5a646652004-11-05 01:25:55 +00006869 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6870 NULL);
paul718e3742002-12-13 20:15:29 +00006871}
6872
6873ALIAS (show_bgp,
6874 show_bgp_ipv6_cmd,
6875 "show bgp ipv6",
6876 SHOW_STR
6877 BGP_STR
6878 "Address family\n")
6879
Michael Lambert95cbbd22010-07-23 14:43:04 -04006880DEFUN (show_bgp_ipv6_safi,
6881 show_bgp_ipv6_safi_cmd,
6882 "show bgp ipv6 (unicast|multicast)",
6883 SHOW_STR
6884 BGP_STR
6885 "Address family\n"
6886 "Address Family modifier\n"
6887 "Address Family modifier\n")
6888{
6889 if (strncmp (argv[0], "m", 1) == 0)
6890 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6891 NULL);
6892
6893 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6894}
6895
paul718e3742002-12-13 20:15:29 +00006896/* old command */
6897DEFUN (show_ipv6_bgp,
6898 show_ipv6_bgp_cmd,
6899 "show ipv6 bgp",
6900 SHOW_STR
6901 IP_STR
6902 BGP_STR)
6903{
ajs5a646652004-11-05 01:25:55 +00006904 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6905 NULL);
paul718e3742002-12-13 20:15:29 +00006906}
6907
6908DEFUN (show_bgp_route,
6909 show_bgp_route_cmd,
6910 "show bgp X:X::X:X",
6911 SHOW_STR
6912 BGP_STR
6913 "Network in the BGP routing table to display\n")
6914{
6915 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6916}
6917
6918ALIAS (show_bgp_route,
6919 show_bgp_ipv6_route_cmd,
6920 "show bgp ipv6 X:X::X:X",
6921 SHOW_STR
6922 BGP_STR
6923 "Address family\n"
6924 "Network in the BGP routing table to display\n")
6925
Michael Lambert95cbbd22010-07-23 14:43:04 -04006926DEFUN (show_bgp_ipv6_safi_route,
6927 show_bgp_ipv6_safi_route_cmd,
6928 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6929 SHOW_STR
6930 BGP_STR
6931 "Address family\n"
6932 "Address Family modifier\n"
6933 "Address Family modifier\n"
6934 "Network in the BGP routing table to display\n")
6935{
6936 if (strncmp (argv[0], "m", 1) == 0)
6937 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6938
6939 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6940}
6941
paul718e3742002-12-13 20:15:29 +00006942/* old command */
6943DEFUN (show_ipv6_bgp_route,
6944 show_ipv6_bgp_route_cmd,
6945 "show ipv6 bgp X:X::X:X",
6946 SHOW_STR
6947 IP_STR
6948 BGP_STR
6949 "Network in the BGP routing table to display\n")
6950{
6951 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6952}
6953
6954DEFUN (show_bgp_prefix,
6955 show_bgp_prefix_cmd,
6956 "show bgp X:X::X:X/M",
6957 SHOW_STR
6958 BGP_STR
6959 "IPv6 prefix <network>/<length>\n")
6960{
6961 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6962}
6963
6964ALIAS (show_bgp_prefix,
6965 show_bgp_ipv6_prefix_cmd,
6966 "show bgp ipv6 X:X::X:X/M",
6967 SHOW_STR
6968 BGP_STR
6969 "Address family\n"
6970 "IPv6 prefix <network>/<length>\n")
6971
Michael Lambert95cbbd22010-07-23 14:43:04 -04006972DEFUN (show_bgp_ipv6_safi_prefix,
6973 show_bgp_ipv6_safi_prefix_cmd,
6974 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6975 SHOW_STR
6976 BGP_STR
6977 "Address family\n"
6978 "Address Family modifier\n"
6979 "Address Family modifier\n"
6980 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6981{
6982 if (strncmp (argv[0], "m", 1) == 0)
6983 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6984
6985 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6986}
6987
paul718e3742002-12-13 20:15:29 +00006988/* old command */
6989DEFUN (show_ipv6_bgp_prefix,
6990 show_ipv6_bgp_prefix_cmd,
6991 "show ipv6 bgp X:X::X:X/M",
6992 SHOW_STR
6993 IP_STR
6994 BGP_STR
6995 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6996{
6997 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6998}
6999
paulbb46e942003-10-24 19:02:03 +00007000DEFUN (show_bgp_view,
7001 show_bgp_view_cmd,
7002 "show bgp view WORD",
7003 SHOW_STR
7004 BGP_STR
7005 "BGP view\n"
7006 "View name\n")
7007{
7008 struct bgp *bgp;
7009
7010 /* BGP structure lookup. */
7011 bgp = bgp_lookup_by_name (argv[0]);
7012 if (bgp == NULL)
7013 {
7014 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7015 return CMD_WARNING;
7016 }
7017
ajs5a646652004-11-05 01:25:55 +00007018 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007019}
7020
7021ALIAS (show_bgp_view,
7022 show_bgp_view_ipv6_cmd,
7023 "show bgp view WORD ipv6",
7024 SHOW_STR
7025 BGP_STR
7026 "BGP view\n"
7027 "View name\n"
7028 "Address family\n")
7029
7030DEFUN (show_bgp_view_route,
7031 show_bgp_view_route_cmd,
7032 "show bgp view WORD X:X::X:X",
7033 SHOW_STR
7034 BGP_STR
7035 "BGP view\n"
7036 "View name\n"
7037 "Network in the BGP routing table to display\n")
7038{
7039 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7040}
7041
7042ALIAS (show_bgp_view_route,
7043 show_bgp_view_ipv6_route_cmd,
7044 "show bgp view WORD ipv6 X:X::X:X",
7045 SHOW_STR
7046 BGP_STR
7047 "BGP view\n"
7048 "View name\n"
7049 "Address family\n"
7050 "Network in the BGP routing table to display\n")
7051
7052DEFUN (show_bgp_view_prefix,
7053 show_bgp_view_prefix_cmd,
7054 "show bgp view WORD X:X::X:X/M",
7055 SHOW_STR
7056 BGP_STR
7057 "BGP view\n"
7058 "View name\n"
7059 "IPv6 prefix <network>/<length>\n")
7060{
7061 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7062}
7063
7064ALIAS (show_bgp_view_prefix,
7065 show_bgp_view_ipv6_prefix_cmd,
7066 "show bgp view WORD ipv6 X:X::X:X/M",
7067 SHOW_STR
7068 BGP_STR
7069 "BGP view\n"
7070 "View name\n"
7071 "Address family\n"
7072 "IPv6 prefix <network>/<length>\n")
7073
paul718e3742002-12-13 20:15:29 +00007074/* old command */
7075DEFUN (show_ipv6_mbgp,
7076 show_ipv6_mbgp_cmd,
7077 "show ipv6 mbgp",
7078 SHOW_STR
7079 IP_STR
7080 MBGP_STR)
7081{
ajs5a646652004-11-05 01:25:55 +00007082 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7083 NULL);
paul718e3742002-12-13 20:15:29 +00007084}
7085
7086/* old command */
7087DEFUN (show_ipv6_mbgp_route,
7088 show_ipv6_mbgp_route_cmd,
7089 "show ipv6 mbgp X:X::X:X",
7090 SHOW_STR
7091 IP_STR
7092 MBGP_STR
7093 "Network in the MBGP routing table to display\n")
7094{
7095 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7096}
7097
7098/* old command */
7099DEFUN (show_ipv6_mbgp_prefix,
7100 show_ipv6_mbgp_prefix_cmd,
7101 "show ipv6 mbgp X:X::X:X/M",
7102 SHOW_STR
7103 IP_STR
7104 MBGP_STR
7105 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7106{
7107 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7108}
7109#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02007110
paul718e3742002-12-13 20:15:29 +00007111
paul94f2b392005-06-28 12:44:16 +00007112static int
paulfd79ac92004-10-13 05:06:08 +00007113bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007114 safi_t safi, enum bgp_show_type type)
7115{
7116 int i;
7117 struct buffer *b;
7118 char *regstr;
7119 int first;
7120 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007121 int rc;
paul718e3742002-12-13 20:15:29 +00007122
7123 first = 0;
7124 b = buffer_new (1024);
7125 for (i = 0; i < argc; i++)
7126 {
7127 if (first)
7128 buffer_putc (b, ' ');
7129 else
7130 {
7131 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7132 continue;
7133 first = 1;
7134 }
7135
7136 buffer_putstr (b, argv[i]);
7137 }
7138 buffer_putc (b, '\0');
7139
7140 regstr = buffer_getstr (b);
7141 buffer_free (b);
7142
7143 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007144 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007145 if (! regex)
7146 {
7147 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7148 VTY_NEWLINE);
7149 return CMD_WARNING;
7150 }
7151
ajs5a646652004-11-05 01:25:55 +00007152 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7153 bgp_regex_free (regex);
7154 return rc;
paul718e3742002-12-13 20:15:29 +00007155}
7156
7157DEFUN (show_ip_bgp_regexp,
7158 show_ip_bgp_regexp_cmd,
7159 "show ip bgp regexp .LINE",
7160 SHOW_STR
7161 IP_STR
7162 BGP_STR
7163 "Display routes matching the AS path regular expression\n"
7164 "A regular-expression to match the BGP AS paths\n")
7165{
7166 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7167 bgp_show_type_regexp);
7168}
7169
7170DEFUN (show_ip_bgp_flap_regexp,
7171 show_ip_bgp_flap_regexp_cmd,
7172 "show ip bgp flap-statistics regexp .LINE",
7173 SHOW_STR
7174 IP_STR
7175 BGP_STR
7176 "Display flap statistics of routes\n"
7177 "Display routes matching the AS path regular expression\n"
7178 "A regular-expression to match the BGP AS paths\n")
7179{
7180 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7181 bgp_show_type_flap_regexp);
7182}
7183
7184DEFUN (show_ip_bgp_ipv4_regexp,
7185 show_ip_bgp_ipv4_regexp_cmd,
7186 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7187 SHOW_STR
7188 IP_STR
7189 BGP_STR
7190 "Address family\n"
7191 "Address Family modifier\n"
7192 "Address Family modifier\n"
7193 "Display routes matching the AS path regular expression\n"
7194 "A regular-expression to match the BGP AS paths\n")
7195{
7196 if (strncmp (argv[0], "m", 1) == 0)
7197 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7198 bgp_show_type_regexp);
7199
7200 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7201 bgp_show_type_regexp);
7202}
7203
7204#ifdef HAVE_IPV6
7205DEFUN (show_bgp_regexp,
7206 show_bgp_regexp_cmd,
7207 "show bgp regexp .LINE",
7208 SHOW_STR
7209 BGP_STR
7210 "Display routes matching the AS path regular expression\n"
7211 "A regular-expression to match the BGP AS paths\n")
7212{
7213 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7214 bgp_show_type_regexp);
7215}
7216
7217ALIAS (show_bgp_regexp,
7218 show_bgp_ipv6_regexp_cmd,
7219 "show bgp ipv6 regexp .LINE",
7220 SHOW_STR
7221 BGP_STR
7222 "Address family\n"
7223 "Display routes matching the AS path regular expression\n"
7224 "A regular-expression to match the BGP AS paths\n")
7225
7226/* old command */
7227DEFUN (show_ipv6_bgp_regexp,
7228 show_ipv6_bgp_regexp_cmd,
7229 "show ipv6 bgp regexp .LINE",
7230 SHOW_STR
7231 IP_STR
7232 BGP_STR
7233 "Display routes matching the AS path regular expression\n"
7234 "A regular-expression to match the BGP AS paths\n")
7235{
7236 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7237 bgp_show_type_regexp);
7238}
7239
7240/* old command */
7241DEFUN (show_ipv6_mbgp_regexp,
7242 show_ipv6_mbgp_regexp_cmd,
7243 "show ipv6 mbgp regexp .LINE",
7244 SHOW_STR
7245 IP_STR
7246 BGP_STR
7247 "Display routes matching the AS path regular expression\n"
7248 "A regular-expression to match the MBGP AS paths\n")
7249{
7250 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7251 bgp_show_type_regexp);
7252}
7253#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007254
paul94f2b392005-06-28 12:44:16 +00007255static int
paulfd79ac92004-10-13 05:06:08 +00007256bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007257 safi_t safi, enum bgp_show_type type)
7258{
7259 struct prefix_list *plist;
7260
7261 plist = prefix_list_lookup (afi, prefix_list_str);
7262 if (plist == NULL)
7263 {
7264 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7265 prefix_list_str, VTY_NEWLINE);
7266 return CMD_WARNING;
7267 }
7268
ajs5a646652004-11-05 01:25:55 +00007269 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007270}
7271
7272DEFUN (show_ip_bgp_prefix_list,
7273 show_ip_bgp_prefix_list_cmd,
7274 "show ip bgp prefix-list WORD",
7275 SHOW_STR
7276 IP_STR
7277 BGP_STR
7278 "Display routes conforming to the prefix-list\n"
7279 "IP prefix-list name\n")
7280{
7281 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7282 bgp_show_type_prefix_list);
7283}
7284
7285DEFUN (show_ip_bgp_flap_prefix_list,
7286 show_ip_bgp_flap_prefix_list_cmd,
7287 "show ip bgp flap-statistics prefix-list WORD",
7288 SHOW_STR
7289 IP_STR
7290 BGP_STR
7291 "Display flap statistics of routes\n"
7292 "Display routes conforming to the prefix-list\n"
7293 "IP prefix-list name\n")
7294{
7295 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7296 bgp_show_type_flap_prefix_list);
7297}
7298
7299DEFUN (show_ip_bgp_ipv4_prefix_list,
7300 show_ip_bgp_ipv4_prefix_list_cmd,
7301 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7302 SHOW_STR
7303 IP_STR
7304 BGP_STR
7305 "Address family\n"
7306 "Address Family modifier\n"
7307 "Address Family modifier\n"
7308 "Display routes conforming to the prefix-list\n"
7309 "IP prefix-list name\n")
7310{
7311 if (strncmp (argv[0], "m", 1) == 0)
7312 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7313 bgp_show_type_prefix_list);
7314
7315 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7316 bgp_show_type_prefix_list);
7317}
7318
7319#ifdef HAVE_IPV6
7320DEFUN (show_bgp_prefix_list,
7321 show_bgp_prefix_list_cmd,
7322 "show bgp prefix-list WORD",
7323 SHOW_STR
7324 BGP_STR
7325 "Display routes conforming to the prefix-list\n"
7326 "IPv6 prefix-list name\n")
7327{
7328 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7329 bgp_show_type_prefix_list);
7330}
7331
7332ALIAS (show_bgp_prefix_list,
7333 show_bgp_ipv6_prefix_list_cmd,
7334 "show bgp ipv6 prefix-list WORD",
7335 SHOW_STR
7336 BGP_STR
7337 "Address family\n"
7338 "Display routes conforming to the prefix-list\n"
7339 "IPv6 prefix-list name\n")
7340
7341/* old command */
7342DEFUN (show_ipv6_bgp_prefix_list,
7343 show_ipv6_bgp_prefix_list_cmd,
7344 "show ipv6 bgp prefix-list WORD",
7345 SHOW_STR
7346 IPV6_STR
7347 BGP_STR
7348 "Display routes matching the prefix-list\n"
7349 "IPv6 prefix-list name\n")
7350{
7351 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7352 bgp_show_type_prefix_list);
7353}
7354
7355/* old command */
7356DEFUN (show_ipv6_mbgp_prefix_list,
7357 show_ipv6_mbgp_prefix_list_cmd,
7358 "show ipv6 mbgp prefix-list WORD",
7359 SHOW_STR
7360 IPV6_STR
7361 MBGP_STR
7362 "Display routes matching the prefix-list\n"
7363 "IPv6 prefix-list name\n")
7364{
7365 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7366 bgp_show_type_prefix_list);
7367}
7368#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007369
paul94f2b392005-06-28 12:44:16 +00007370static int
paulfd79ac92004-10-13 05:06:08 +00007371bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007372 safi_t safi, enum bgp_show_type type)
7373{
7374 struct as_list *as_list;
7375
7376 as_list = as_list_lookup (filter);
7377 if (as_list == NULL)
7378 {
7379 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7380 return CMD_WARNING;
7381 }
7382
ajs5a646652004-11-05 01:25:55 +00007383 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007384}
7385
7386DEFUN (show_ip_bgp_filter_list,
7387 show_ip_bgp_filter_list_cmd,
7388 "show ip bgp filter-list WORD",
7389 SHOW_STR
7390 IP_STR
7391 BGP_STR
7392 "Display routes conforming to the filter-list\n"
7393 "Regular expression access list name\n")
7394{
7395 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7396 bgp_show_type_filter_list);
7397}
7398
7399DEFUN (show_ip_bgp_flap_filter_list,
7400 show_ip_bgp_flap_filter_list_cmd,
7401 "show ip bgp flap-statistics filter-list WORD",
7402 SHOW_STR
7403 IP_STR
7404 BGP_STR
7405 "Display flap statistics of routes\n"
7406 "Display routes conforming to the filter-list\n"
7407 "Regular expression access list name\n")
7408{
7409 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7410 bgp_show_type_flap_filter_list);
7411}
7412
7413DEFUN (show_ip_bgp_ipv4_filter_list,
7414 show_ip_bgp_ipv4_filter_list_cmd,
7415 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7416 SHOW_STR
7417 IP_STR
7418 BGP_STR
7419 "Address family\n"
7420 "Address Family modifier\n"
7421 "Address Family modifier\n"
7422 "Display routes conforming to the filter-list\n"
7423 "Regular expression access list name\n")
7424{
7425 if (strncmp (argv[0], "m", 1) == 0)
7426 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7427 bgp_show_type_filter_list);
7428
7429 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7430 bgp_show_type_filter_list);
7431}
7432
7433#ifdef HAVE_IPV6
7434DEFUN (show_bgp_filter_list,
7435 show_bgp_filter_list_cmd,
7436 "show bgp filter-list WORD",
7437 SHOW_STR
7438 BGP_STR
7439 "Display routes conforming to the filter-list\n"
7440 "Regular expression access list name\n")
7441{
7442 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7443 bgp_show_type_filter_list);
7444}
7445
7446ALIAS (show_bgp_filter_list,
7447 show_bgp_ipv6_filter_list_cmd,
7448 "show bgp ipv6 filter-list WORD",
7449 SHOW_STR
7450 BGP_STR
7451 "Address family\n"
7452 "Display routes conforming to the filter-list\n"
7453 "Regular expression access list name\n")
7454
7455/* old command */
7456DEFUN (show_ipv6_bgp_filter_list,
7457 show_ipv6_bgp_filter_list_cmd,
7458 "show ipv6 bgp filter-list WORD",
7459 SHOW_STR
7460 IPV6_STR
7461 BGP_STR
7462 "Display routes conforming to the filter-list\n"
7463 "Regular expression access list name\n")
7464{
7465 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7466 bgp_show_type_filter_list);
7467}
7468
7469/* old command */
7470DEFUN (show_ipv6_mbgp_filter_list,
7471 show_ipv6_mbgp_filter_list_cmd,
7472 "show ipv6 mbgp filter-list WORD",
7473 SHOW_STR
7474 IPV6_STR
7475 MBGP_STR
7476 "Display routes conforming to the filter-list\n"
7477 "Regular expression access list name\n")
7478{
7479 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7480 bgp_show_type_filter_list);
7481}
7482#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007483
paul94f2b392005-06-28 12:44:16 +00007484static int
paulfd79ac92004-10-13 05:06:08 +00007485bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007486 safi_t safi, enum bgp_show_type type)
7487{
7488 struct route_map *rmap;
7489
7490 rmap = route_map_lookup_by_name (rmap_str);
7491 if (! rmap)
7492 {
7493 vty_out (vty, "%% %s is not a valid route-map name%s",
7494 rmap_str, VTY_NEWLINE);
7495 return CMD_WARNING;
7496 }
7497
ajs5a646652004-11-05 01:25:55 +00007498 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007499}
7500
7501DEFUN (show_ip_bgp_route_map,
7502 show_ip_bgp_route_map_cmd,
7503 "show ip bgp route-map WORD",
7504 SHOW_STR
7505 IP_STR
7506 BGP_STR
7507 "Display routes matching the route-map\n"
7508 "A route-map to match on\n")
7509{
7510 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7511 bgp_show_type_route_map);
7512}
7513
7514DEFUN (show_ip_bgp_flap_route_map,
7515 show_ip_bgp_flap_route_map_cmd,
7516 "show ip bgp flap-statistics route-map WORD",
7517 SHOW_STR
7518 IP_STR
7519 BGP_STR
7520 "Display flap statistics of routes\n"
7521 "Display routes matching the route-map\n"
7522 "A route-map to match on\n")
7523{
7524 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7525 bgp_show_type_flap_route_map);
7526}
7527
7528DEFUN (show_ip_bgp_ipv4_route_map,
7529 show_ip_bgp_ipv4_route_map_cmd,
7530 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7531 SHOW_STR
7532 IP_STR
7533 BGP_STR
7534 "Address family\n"
7535 "Address Family modifier\n"
7536 "Address Family modifier\n"
7537 "Display routes matching the route-map\n"
7538 "A route-map to match on\n")
7539{
7540 if (strncmp (argv[0], "m", 1) == 0)
7541 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7542 bgp_show_type_route_map);
7543
7544 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7545 bgp_show_type_route_map);
7546}
7547
7548DEFUN (show_bgp_route_map,
7549 show_bgp_route_map_cmd,
7550 "show bgp route-map WORD",
7551 SHOW_STR
7552 BGP_STR
7553 "Display routes matching the route-map\n"
7554 "A route-map to match on\n")
7555{
7556 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7557 bgp_show_type_route_map);
7558}
7559
7560ALIAS (show_bgp_route_map,
7561 show_bgp_ipv6_route_map_cmd,
7562 "show bgp ipv6 route-map WORD",
7563 SHOW_STR
7564 BGP_STR
7565 "Address family\n"
7566 "Display routes matching the route-map\n"
7567 "A route-map to match on\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02007568
paul718e3742002-12-13 20:15:29 +00007569DEFUN (show_ip_bgp_cidr_only,
7570 show_ip_bgp_cidr_only_cmd,
7571 "show ip bgp cidr-only",
7572 SHOW_STR
7573 IP_STR
7574 BGP_STR
7575 "Display only routes with non-natural netmasks\n")
7576{
7577 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007578 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007579}
7580
7581DEFUN (show_ip_bgp_flap_cidr_only,
7582 show_ip_bgp_flap_cidr_only_cmd,
7583 "show ip bgp flap-statistics cidr-only",
7584 SHOW_STR
7585 IP_STR
7586 BGP_STR
7587 "Display flap statistics of routes\n"
7588 "Display only routes with non-natural netmasks\n")
7589{
7590 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007591 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007592}
7593
7594DEFUN (show_ip_bgp_ipv4_cidr_only,
7595 show_ip_bgp_ipv4_cidr_only_cmd,
7596 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7597 SHOW_STR
7598 IP_STR
7599 BGP_STR
7600 "Address family\n"
7601 "Address Family modifier\n"
7602 "Address Family modifier\n"
7603 "Display only routes with non-natural netmasks\n")
7604{
7605 if (strncmp (argv[0], "m", 1) == 0)
7606 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007607 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007608
7609 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007610 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007611}
David Lamparter6b0655a2014-06-04 06:53:35 +02007612
paul718e3742002-12-13 20:15:29 +00007613DEFUN (show_ip_bgp_community_all,
7614 show_ip_bgp_community_all_cmd,
7615 "show ip bgp community",
7616 SHOW_STR
7617 IP_STR
7618 BGP_STR
7619 "Display routes matching the communities\n")
7620{
7621 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007622 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007623}
7624
7625DEFUN (show_ip_bgp_ipv4_community_all,
7626 show_ip_bgp_ipv4_community_all_cmd,
7627 "show ip bgp ipv4 (unicast|multicast) community",
7628 SHOW_STR
7629 IP_STR
7630 BGP_STR
7631 "Address family\n"
7632 "Address Family modifier\n"
7633 "Address Family modifier\n"
7634 "Display routes matching the communities\n")
7635{
7636 if (strncmp (argv[0], "m", 1) == 0)
7637 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007638 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007639
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
7644#ifdef HAVE_IPV6
7645DEFUN (show_bgp_community_all,
7646 show_bgp_community_all_cmd,
7647 "show bgp community",
7648 SHOW_STR
7649 BGP_STR
7650 "Display routes matching the communities\n")
7651{
7652 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007653 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007654}
7655
7656ALIAS (show_bgp_community_all,
7657 show_bgp_ipv6_community_all_cmd,
7658 "show bgp ipv6 community",
7659 SHOW_STR
7660 BGP_STR
7661 "Address family\n"
7662 "Display routes matching the communities\n")
7663
7664/* old command */
7665DEFUN (show_ipv6_bgp_community_all,
7666 show_ipv6_bgp_community_all_cmd,
7667 "show ipv6 bgp community",
7668 SHOW_STR
7669 IPV6_STR
7670 BGP_STR
7671 "Display routes matching the communities\n")
7672{
7673 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007674 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007675}
7676
7677/* old command */
7678DEFUN (show_ipv6_mbgp_community_all,
7679 show_ipv6_mbgp_community_all_cmd,
7680 "show ipv6 mbgp community",
7681 SHOW_STR
7682 IPV6_STR
7683 MBGP_STR
7684 "Display routes matching the communities\n")
7685{
7686 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007687 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007688}
7689#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007690
paul94f2b392005-06-28 12:44:16 +00007691static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007692bgp_show_community (struct vty *vty, const char *view_name, int argc,
7693 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007694{
7695 struct community *com;
7696 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007697 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007698 int i;
7699 char *str;
7700 int first = 0;
7701
Michael Lambert95cbbd22010-07-23 14:43:04 -04007702 /* BGP structure lookup */
7703 if (view_name)
7704 {
7705 bgp = bgp_lookup_by_name (view_name);
7706 if (bgp == NULL)
7707 {
7708 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7709 return CMD_WARNING;
7710 }
7711 }
7712 else
7713 {
7714 bgp = bgp_get_default ();
7715 if (bgp == NULL)
7716 {
7717 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7718 return CMD_WARNING;
7719 }
7720 }
7721
paul718e3742002-12-13 20:15:29 +00007722 b = buffer_new (1024);
7723 for (i = 0; i < argc; i++)
7724 {
7725 if (first)
7726 buffer_putc (b, ' ');
7727 else
7728 {
7729 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7730 continue;
7731 first = 1;
7732 }
7733
7734 buffer_putstr (b, argv[i]);
7735 }
7736 buffer_putc (b, '\0');
7737
7738 str = buffer_getstr (b);
7739 buffer_free (b);
7740
7741 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007742 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007743 if (! com)
7744 {
7745 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7746 return CMD_WARNING;
7747 }
7748
Michael Lambert95cbbd22010-07-23 14:43:04 -04007749 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007750 (exact ? bgp_show_type_community_exact :
7751 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007752}
7753
7754DEFUN (show_ip_bgp_community,
7755 show_ip_bgp_community_cmd,
7756 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7757 SHOW_STR
7758 IP_STR
7759 BGP_STR
7760 "Display routes matching the communities\n"
7761 "community number\n"
7762 "Do not send outside local AS (well-known community)\n"
7763 "Do not advertise to any peer (well-known community)\n"
7764 "Do not export to next AS (well-known community)\n")
7765{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007766 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007767}
7768
7769ALIAS (show_ip_bgp_community,
7770 show_ip_bgp_community2_cmd,
7771 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7772 SHOW_STR
7773 IP_STR
7774 BGP_STR
7775 "Display routes matching the communities\n"
7776 "community number\n"
7777 "Do not send outside local AS (well-known community)\n"
7778 "Do not advertise to any peer (well-known community)\n"
7779 "Do not export to next AS (well-known community)\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
7785ALIAS (show_ip_bgp_community,
7786 show_ip_bgp_community3_cmd,
7787 "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)",
7788 SHOW_STR
7789 IP_STR
7790 BGP_STR
7791 "Display routes matching the communities\n"
7792 "community number\n"
7793 "Do not send outside local AS (well-known community)\n"
7794 "Do not advertise to any peer (well-known community)\n"
7795 "Do not export to next AS (well-known community)\n"
7796 "community number\n"
7797 "Do not send outside local AS (well-known community)\n"
7798 "Do not advertise to any peer (well-known community)\n"
7799 "Do not export to next AS (well-known community)\n"
7800 "community number\n"
7801 "Do not send outside local AS (well-known community)\n"
7802 "Do not advertise to any peer (well-known community)\n"
7803 "Do not export to next AS (well-known community)\n")
7804
7805ALIAS (show_ip_bgp_community,
7806 show_ip_bgp_community4_cmd,
7807 "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)",
7808 SHOW_STR
7809 IP_STR
7810 BGP_STR
7811 "Display routes matching the communities\n"
7812 "community number\n"
7813 "Do not send outside local AS (well-known community)\n"
7814 "Do not advertise to any peer (well-known community)\n"
7815 "Do not export to next AS (well-known community)\n"
7816 "community number\n"
7817 "Do not send outside local AS (well-known community)\n"
7818 "Do not advertise to any peer (well-known community)\n"
7819 "Do not export to next AS (well-known community)\n"
7820 "community number\n"
7821 "Do not send outside local AS (well-known community)\n"
7822 "Do not advertise to any peer (well-known community)\n"
7823 "Do not export to next AS (well-known community)\n"
7824 "community number\n"
7825 "Do not send outside local AS (well-known community)\n"
7826 "Do not advertise to any peer (well-known community)\n"
7827 "Do not export to next AS (well-known community)\n")
7828
7829DEFUN (show_ip_bgp_ipv4_community,
7830 show_ip_bgp_ipv4_community_cmd,
7831 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7832 SHOW_STR
7833 IP_STR
7834 BGP_STR
7835 "Address family\n"
7836 "Address Family modifier\n"
7837 "Address Family modifier\n"
7838 "Display routes matching the communities\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{
7844 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007845 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007846
Michael Lambert95cbbd22010-07-23 14:43:04 -04007847 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007848}
7849
7850ALIAS (show_ip_bgp_ipv4_community,
7851 show_ip_bgp_ipv4_community2_cmd,
7852 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7853 SHOW_STR
7854 IP_STR
7855 BGP_STR
7856 "Address family\n"
7857 "Address Family modifier\n"
7858 "Address Family modifier\n"
7859 "Display routes matching the communities\n"
7860 "community number\n"
7861 "Do not send outside local AS (well-known community)\n"
7862 "Do not advertise to any peer (well-known community)\n"
7863 "Do not export to next AS (well-known community)\n"
7864 "community number\n"
7865 "Do not send outside local AS (well-known community)\n"
7866 "Do not advertise to any peer (well-known community)\n"
7867 "Do not export to next AS (well-known community)\n")
7868
7869ALIAS (show_ip_bgp_ipv4_community,
7870 show_ip_bgp_ipv4_community3_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) (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 "community number\n"
7888 "Do not send outside local AS (well-known community)\n"
7889 "Do not advertise to any peer (well-known community)\n"
7890 "Do not export to next AS (well-known community)\n")
7891
7892ALIAS (show_ip_bgp_ipv4_community,
7893 show_ip_bgp_ipv4_community4_cmd,
7894 "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)",
7895 SHOW_STR
7896 IP_STR
7897 BGP_STR
7898 "Address family\n"
7899 "Address Family modifier\n"
7900 "Address Family modifier\n"
7901 "Display routes matching the communities\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 "community number\n"
7911 "Do not send outside local AS (well-known community)\n"
7912 "Do not advertise to any peer (well-known community)\n"
7913 "Do not export to next AS (well-known community)\n"
7914 "community number\n"
7915 "Do not send outside local AS (well-known community)\n"
7916 "Do not advertise to any peer (well-known community)\n"
7917 "Do not export to next AS (well-known community)\n")
7918
Michael Lambert95cbbd22010-07-23 14:43:04 -04007919DEFUN (show_bgp_view_afi_safi_community_all,
7920 show_bgp_view_afi_safi_community_all_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04007921 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007922 SHOW_STR
7923 BGP_STR
7924 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007925 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007926 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007927 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007928 "Address Family modifier\n"
7929 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00007930 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007931{
7932 int afi;
7933 int safi;
7934 struct bgp *bgp;
7935
7936 /* BGP structure lookup. */
7937 bgp = bgp_lookup_by_name (argv[0]);
7938 if (bgp == NULL)
7939 {
7940 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7941 return CMD_WARNING;
7942 }
7943
Michael Lambert95cbbd22010-07-23 14:43:04 -04007944 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7945 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007946 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7947}
7948
7949DEFUN (show_bgp_view_afi_safi_community,
7950 show_bgp_view_afi_safi_community_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04007951 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007952 SHOW_STR
7953 BGP_STR
7954 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007955 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007956 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007957 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007958 "Address family modifier\n"
7959 "Address family modifier\n"
7960 "Display routes matching the communities\n"
7961 "community number\n"
7962 "Do not send outside local AS (well-known community)\n"
7963 "Do not advertise to any peer (well-known community)\n"
7964 "Do not export to next AS (well-known community)\n")
7965{
7966 int afi;
7967 int safi;
7968
Michael Lambert95cbbd22010-07-23 14:43:04 -04007969 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7970 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7971 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007972}
7973
7974ALIAS (show_bgp_view_afi_safi_community,
7975 show_bgp_view_afi_safi_community2_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04007976 "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 -04007977 SHOW_STR
7978 BGP_STR
7979 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007980 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007981 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007982 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007983 "Address family modifier\n"
7984 "Address family modifier\n"
7985 "Display routes matching the communities\n"
7986 "community number\n"
7987 "Do not send outside local AS (well-known community)\n"
7988 "Do not advertise to any peer (well-known community)\n"
7989 "Do not export to next AS (well-known community)\n"
7990 "community number\n"
7991 "Do not send outside local AS (well-known community)\n"
7992 "Do not advertise to any peer (well-known community)\n"
7993 "Do not export to next AS (well-known community)\n")
7994
7995ALIAS (show_bgp_view_afi_safi_community,
7996 show_bgp_view_afi_safi_community3_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04007997 "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 -04007998 SHOW_STR
7999 BGP_STR
8000 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008001 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008002 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008003 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008004 "Address family modifier\n"
8005 "Address family modifier\n"
8006 "Display routes matching the communities\n"
8007 "community number\n"
8008 "Do not send outside local AS (well-known community)\n"
8009 "Do not advertise to any peer (well-known community)\n"
8010 "Do not export to next AS (well-known community)\n"
8011 "community number\n"
8012 "Do not send outside local AS (well-known community)\n"
8013 "Do not advertise to any peer (well-known community)\n"
8014 "Do not export to next AS (well-known community)\n"
8015 "community number\n"
8016 "Do not send outside local AS (well-known community)\n"
8017 "Do not advertise to any peer (well-known community)\n"
8018 "Do not export to next AS (well-known community)\n")
8019
8020ALIAS (show_bgp_view_afi_safi_community,
8021 show_bgp_view_afi_safi_community4_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008022 "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 -04008023 SHOW_STR
8024 BGP_STR
8025 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008026 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008027 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008028 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008029 "Address family modifier\n"
8030 "Address family modifier\n"
8031 "Display routes matching the communities\n"
8032 "community number\n"
8033 "Do not send outside local AS (well-known community)\n"
8034 "Do not advertise to any peer (well-known community)\n"
8035 "Do not export to next AS (well-known community)\n"
8036 "community number\n"
8037 "Do not send outside local AS (well-known community)\n"
8038 "Do not advertise to any peer (well-known community)\n"
8039 "Do not export to next AS (well-known community)\n"
8040 "community number\n"
8041 "Do not send outside local AS (well-known community)\n"
8042 "Do not advertise to any peer (well-known community)\n"
8043 "Do not export to next AS (well-known community)\n"
8044 "community number\n"
8045 "Do not send outside local AS (well-known community)\n"
8046 "Do not advertise to any peer (well-known community)\n"
8047 "Do not export to next AS (well-known community)\n")
8048
paul718e3742002-12-13 20:15:29 +00008049DEFUN (show_ip_bgp_community_exact,
8050 show_ip_bgp_community_exact_cmd,
8051 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8052 SHOW_STR
8053 IP_STR
8054 BGP_STR
8055 "Display routes matching the communities\n"
8056 "community number\n"
8057 "Do not send outside local AS (well-known community)\n"
8058 "Do not advertise to any peer (well-known community)\n"
8059 "Do not export to next AS (well-known community)\n"
8060 "Exact match of the communities")
8061{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008062 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008063}
8064
8065ALIAS (show_ip_bgp_community_exact,
8066 show_ip_bgp_community2_exact_cmd,
8067 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8068 SHOW_STR
8069 IP_STR
8070 BGP_STR
8071 "Display routes matching the communities\n"
8072 "community number\n"
8073 "Do not send outside local AS (well-known community)\n"
8074 "Do not advertise to any peer (well-known community)\n"
8075 "Do not export to next AS (well-known community)\n"
8076 "community number\n"
8077 "Do not send outside local AS (well-known community)\n"
8078 "Do not advertise to any peer (well-known community)\n"
8079 "Do not export to next AS (well-known community)\n"
8080 "Exact match of the communities")
8081
8082ALIAS (show_ip_bgp_community_exact,
8083 show_ip_bgp_community3_exact_cmd,
8084 "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",
8085 SHOW_STR
8086 IP_STR
8087 BGP_STR
8088 "Display routes matching the communities\n"
8089 "community number\n"
8090 "Do not send outside local AS (well-known community)\n"
8091 "Do not advertise to any peer (well-known community)\n"
8092 "Do not export to next AS (well-known community)\n"
8093 "community number\n"
8094 "Do not send outside local AS (well-known community)\n"
8095 "Do not advertise to any peer (well-known community)\n"
8096 "Do not export to next AS (well-known community)\n"
8097 "community number\n"
8098 "Do not send outside local AS (well-known community)\n"
8099 "Do not advertise to any peer (well-known community)\n"
8100 "Do not export to next AS (well-known community)\n"
8101 "Exact match of the communities")
8102
8103ALIAS (show_ip_bgp_community_exact,
8104 show_ip_bgp_community4_exact_cmd,
8105 "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",
8106 SHOW_STR
8107 IP_STR
8108 BGP_STR
8109 "Display routes matching the communities\n"
8110 "community number\n"
8111 "Do not send outside local AS (well-known community)\n"
8112 "Do not advertise to any peer (well-known community)\n"
8113 "Do not export to next AS (well-known community)\n"
8114 "community number\n"
8115 "Do not send outside local AS (well-known community)\n"
8116 "Do not advertise to any peer (well-known community)\n"
8117 "Do not export to next AS (well-known community)\n"
8118 "community number\n"
8119 "Do not send outside local AS (well-known community)\n"
8120 "Do not advertise to any peer (well-known community)\n"
8121 "Do not export to next AS (well-known community)\n"
8122 "community number\n"
8123 "Do not send outside local AS (well-known community)\n"
8124 "Do not advertise to any peer (well-known community)\n"
8125 "Do not export to next AS (well-known community)\n"
8126 "Exact match of the communities")
8127
8128DEFUN (show_ip_bgp_ipv4_community_exact,
8129 show_ip_bgp_ipv4_community_exact_cmd,
8130 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8131 SHOW_STR
8132 IP_STR
8133 BGP_STR
8134 "Address family\n"
8135 "Address Family modifier\n"
8136 "Address Family modifier\n"
8137 "Display routes matching the communities\n"
8138 "community number\n"
8139 "Do not send outside local AS (well-known community)\n"
8140 "Do not advertise to any peer (well-known community)\n"
8141 "Do not export to next AS (well-known community)\n"
8142 "Exact match of the communities")
8143{
8144 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008145 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008146
Michael Lambert95cbbd22010-07-23 14:43:04 -04008147 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008148}
8149
8150ALIAS (show_ip_bgp_ipv4_community_exact,
8151 show_ip_bgp_ipv4_community2_exact_cmd,
8152 "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",
8153 SHOW_STR
8154 IP_STR
8155 BGP_STR
8156 "Address family\n"
8157 "Address Family modifier\n"
8158 "Address Family modifier\n"
8159 "Display routes matching the communities\n"
8160 "community number\n"
8161 "Do not send outside local AS (well-known community)\n"
8162 "Do not advertise to any peer (well-known community)\n"
8163 "Do not export to next AS (well-known community)\n"
8164 "community number\n"
8165 "Do not send outside local AS (well-known community)\n"
8166 "Do not advertise to any peer (well-known community)\n"
8167 "Do not export to next AS (well-known community)\n"
8168 "Exact match of the communities")
8169
8170ALIAS (show_ip_bgp_ipv4_community_exact,
8171 show_ip_bgp_ipv4_community3_exact_cmd,
8172 "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",
8173 SHOW_STR
8174 IP_STR
8175 BGP_STR
8176 "Address family\n"
8177 "Address Family modifier\n"
8178 "Address Family modifier\n"
8179 "Display routes matching the communities\n"
8180 "community number\n"
8181 "Do not send outside local AS (well-known community)\n"
8182 "Do not advertise to any peer (well-known community)\n"
8183 "Do not export to next AS (well-known community)\n"
8184 "community number\n"
8185 "Do not send outside local AS (well-known community)\n"
8186 "Do not advertise to any peer (well-known community)\n"
8187 "Do not export to next AS (well-known community)\n"
8188 "community number\n"
8189 "Do not send outside local AS (well-known community)\n"
8190 "Do not advertise to any peer (well-known community)\n"
8191 "Do not export to next AS (well-known community)\n"
8192 "Exact match of the communities")
8193
8194ALIAS (show_ip_bgp_ipv4_community_exact,
8195 show_ip_bgp_ipv4_community4_exact_cmd,
8196 "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",
8197 SHOW_STR
8198 IP_STR
8199 BGP_STR
8200 "Address family\n"
8201 "Address Family modifier\n"
8202 "Address Family modifier\n"
8203 "Display routes matching the communities\n"
8204 "community number\n"
8205 "Do not send outside local AS (well-known community)\n"
8206 "Do not advertise to any peer (well-known community)\n"
8207 "Do not export to next AS (well-known community)\n"
8208 "community number\n"
8209 "Do not send outside local AS (well-known community)\n"
8210 "Do not advertise to any peer (well-known community)\n"
8211 "Do not export to next AS (well-known community)\n"
8212 "community number\n"
8213 "Do not send outside local AS (well-known community)\n"
8214 "Do not advertise to any peer (well-known community)\n"
8215 "Do not export to next AS (well-known community)\n"
8216 "community number\n"
8217 "Do not send outside local AS (well-known community)\n"
8218 "Do not advertise to any peer (well-known community)\n"
8219 "Do not export to next AS (well-known community)\n"
8220 "Exact match of the communities")
8221
8222#ifdef HAVE_IPV6
8223DEFUN (show_bgp_community,
8224 show_bgp_community_cmd,
8225 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8226 SHOW_STR
8227 BGP_STR
8228 "Display routes matching the communities\n"
8229 "community number\n"
8230 "Do not send outside local AS (well-known community)\n"
8231 "Do not advertise to any peer (well-known community)\n"
8232 "Do not export to next AS (well-known community)\n")
8233{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008234 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008235}
8236
8237ALIAS (show_bgp_community,
8238 show_bgp_ipv6_community_cmd,
8239 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8240 SHOW_STR
8241 BGP_STR
8242 "Address family\n"
8243 "Display routes matching the communities\n"
8244 "community number\n"
8245 "Do not send outside local AS (well-known community)\n"
8246 "Do not advertise to any peer (well-known community)\n"
8247 "Do not export to next AS (well-known community)\n")
8248
8249ALIAS (show_bgp_community,
8250 show_bgp_community2_cmd,
8251 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8252 SHOW_STR
8253 BGP_STR
8254 "Display routes matching the communities\n"
8255 "community number\n"
8256 "Do not send outside local AS (well-known community)\n"
8257 "Do not advertise to any peer (well-known community)\n"
8258 "Do not export to next AS (well-known community)\n"
8259 "community number\n"
8260 "Do not send outside local AS (well-known community)\n"
8261 "Do not advertise to any peer (well-known community)\n"
8262 "Do not export to next AS (well-known community)\n")
8263
8264ALIAS (show_bgp_community,
8265 show_bgp_ipv6_community2_cmd,
8266 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8267 SHOW_STR
8268 BGP_STR
8269 "Address family\n"
8270 "Display routes matching the communities\n"
8271 "community number\n"
8272 "Do not send outside local AS (well-known community)\n"
8273 "Do not advertise to any peer (well-known community)\n"
8274 "Do not export to next AS (well-known community)\n"
8275 "community number\n"
8276 "Do not send outside local AS (well-known community)\n"
8277 "Do not advertise to any peer (well-known community)\n"
8278 "Do not export to next AS (well-known community)\n")
8279
8280ALIAS (show_bgp_community,
8281 show_bgp_community3_cmd,
8282 "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)",
8283 SHOW_STR
8284 BGP_STR
8285 "Display routes matching the communities\n"
8286 "community number\n"
8287 "Do not send outside local AS (well-known community)\n"
8288 "Do not advertise to any peer (well-known community)\n"
8289 "Do not export to next AS (well-known community)\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_ipv6_community3_cmd,
8301 "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)",
8302 SHOW_STR
8303 BGP_STR
8304 "Address family\n"
8305 "Display routes matching the communities\n"
8306 "community number\n"
8307 "Do not send outside local AS (well-known community)\n"
8308 "Do not advertise to any peer (well-known community)\n"
8309 "Do not export to next AS (well-known community)\n"
8310 "community number\n"
8311 "Do not send outside local AS (well-known community)\n"
8312 "Do not advertise to any peer (well-known community)\n"
8313 "Do not export to next AS (well-known community)\n"
8314 "community number\n"
8315 "Do not send outside local AS (well-known community)\n"
8316 "Do not advertise to any peer (well-known community)\n"
8317 "Do not export to next AS (well-known community)\n")
8318
8319ALIAS (show_bgp_community,
8320 show_bgp_community4_cmd,
8321 "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)",
8322 SHOW_STR
8323 BGP_STR
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 "community number\n"
8338 "Do not send outside local AS (well-known community)\n"
8339 "Do not advertise to any peer (well-known community)\n"
8340 "Do not export to next AS (well-known community)\n")
8341
8342ALIAS (show_bgp_community,
8343 show_bgp_ipv6_community4_cmd,
8344 "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)",
8345 SHOW_STR
8346 BGP_STR
8347 "Address family\n"
8348 "Display routes matching the communities\n"
8349 "community number\n"
8350 "Do not send outside local AS (well-known community)\n"
8351 "Do not advertise to any peer (well-known community)\n"
8352 "Do not export to next AS (well-known community)\n"
8353 "community number\n"
8354 "Do not send outside local AS (well-known community)\n"
8355 "Do not advertise to any peer (well-known community)\n"
8356 "Do not export to next AS (well-known community)\n"
8357 "community number\n"
8358 "Do not send outside local AS (well-known community)\n"
8359 "Do not advertise to any peer (well-known community)\n"
8360 "Do not export to next AS (well-known community)\n"
8361 "community number\n"
8362 "Do not send outside local AS (well-known community)\n"
8363 "Do not advertise to any peer (well-known community)\n"
8364 "Do not export to next AS (well-known community)\n")
8365
8366/* old command */
8367DEFUN (show_ipv6_bgp_community,
8368 show_ipv6_bgp_community_cmd,
8369 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8370 SHOW_STR
8371 IPV6_STR
8372 BGP_STR
8373 "Display routes matching the communities\n"
8374 "community number\n"
8375 "Do not send outside local AS (well-known community)\n"
8376 "Do not advertise to any peer (well-known community)\n"
8377 "Do not export to next AS (well-known community)\n")
8378{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008379 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008380}
8381
8382/* old command */
8383ALIAS (show_ipv6_bgp_community,
8384 show_ipv6_bgp_community2_cmd,
8385 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8386 SHOW_STR
8387 IPV6_STR
8388 BGP_STR
8389 "Display routes matching the communities\n"
8390 "community number\n"
8391 "Do not send outside local AS (well-known community)\n"
8392 "Do not advertise to any peer (well-known community)\n"
8393 "Do not export to next AS (well-known community)\n"
8394 "community number\n"
8395 "Do not send outside local AS (well-known community)\n"
8396 "Do not advertise to any peer (well-known community)\n"
8397 "Do not export to next AS (well-known community)\n")
8398
8399/* old command */
8400ALIAS (show_ipv6_bgp_community,
8401 show_ipv6_bgp_community3_cmd,
8402 "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)",
8403 SHOW_STR
8404 IPV6_STR
8405 BGP_STR
8406 "Display routes matching the communities\n"
8407 "community number\n"
8408 "Do not send outside local AS (well-known community)\n"
8409 "Do not advertise to any peer (well-known community)\n"
8410 "Do not export to next AS (well-known community)\n"
8411 "community number\n"
8412 "Do not send outside local AS (well-known community)\n"
8413 "Do not advertise to any peer (well-known community)\n"
8414 "Do not export to next AS (well-known community)\n"
8415 "community number\n"
8416 "Do not send outside local AS (well-known community)\n"
8417 "Do not advertise to any peer (well-known community)\n"
8418 "Do not export to next AS (well-known community)\n")
8419
8420/* old command */
8421ALIAS (show_ipv6_bgp_community,
8422 show_ipv6_bgp_community4_cmd,
8423 "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)",
8424 SHOW_STR
8425 IPV6_STR
8426 BGP_STR
8427 "Display routes matching the communities\n"
8428 "community number\n"
8429 "Do not send outside local AS (well-known community)\n"
8430 "Do not advertise to any peer (well-known community)\n"
8431 "Do not export to next AS (well-known community)\n"
8432 "community number\n"
8433 "Do not send outside local AS (well-known community)\n"
8434 "Do not advertise to any peer (well-known community)\n"
8435 "Do not export to next AS (well-known community)\n"
8436 "community number\n"
8437 "Do not send outside local AS (well-known community)\n"
8438 "Do not advertise to any peer (well-known community)\n"
8439 "Do not export to next AS (well-known community)\n"
8440 "community number\n"
8441 "Do not send outside local AS (well-known community)\n"
8442 "Do not advertise to any peer (well-known community)\n"
8443 "Do not export to next AS (well-known community)\n")
8444
8445DEFUN (show_bgp_community_exact,
8446 show_bgp_community_exact_cmd,
8447 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8448 SHOW_STR
8449 BGP_STR
8450 "Display routes matching the communities\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 "Exact match of the communities")
8456{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008457 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008458}
8459
8460ALIAS (show_bgp_community_exact,
8461 show_bgp_ipv6_community_exact_cmd,
8462 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8463 SHOW_STR
8464 BGP_STR
8465 "Address family\n"
8466 "Display routes matching the communities\n"
8467 "community number\n"
8468 "Do not send outside local AS (well-known community)\n"
8469 "Do not advertise to any peer (well-known community)\n"
8470 "Do not export to next AS (well-known community)\n"
8471 "Exact match of the communities")
8472
8473ALIAS (show_bgp_community_exact,
8474 show_bgp_community2_exact_cmd,
8475 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8476 SHOW_STR
8477 BGP_STR
8478 "Display routes matching the communities\n"
8479 "community number\n"
8480 "Do not send outside local AS (well-known community)\n"
8481 "Do not advertise to any peer (well-known community)\n"
8482 "Do not export to next AS (well-known community)\n"
8483 "community number\n"
8484 "Do not send outside local AS (well-known community)\n"
8485 "Do not advertise to any peer (well-known community)\n"
8486 "Do not export to next AS (well-known community)\n"
8487 "Exact match of the communities")
8488
8489ALIAS (show_bgp_community_exact,
8490 show_bgp_ipv6_community2_exact_cmd,
8491 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8492 SHOW_STR
8493 BGP_STR
8494 "Address family\n"
8495 "Display routes matching the communities\n"
8496 "community number\n"
8497 "Do not send outside local AS (well-known community)\n"
8498 "Do not advertise to any peer (well-known community)\n"
8499 "Do not export to next AS (well-known community)\n"
8500 "community number\n"
8501 "Do not send outside local AS (well-known community)\n"
8502 "Do not advertise to any peer (well-known community)\n"
8503 "Do not export to next AS (well-known community)\n"
8504 "Exact match of the communities")
8505
8506ALIAS (show_bgp_community_exact,
8507 show_bgp_community3_exact_cmd,
8508 "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",
8509 SHOW_STR
8510 BGP_STR
8511 "Display routes matching the communities\n"
8512 "community number\n"
8513 "Do not send outside local AS (well-known community)\n"
8514 "Do not advertise to any peer (well-known community)\n"
8515 "Do not export to next AS (well-known community)\n"
8516 "community number\n"
8517 "Do not send outside local AS (well-known community)\n"
8518 "Do not advertise to any peer (well-known community)\n"
8519 "Do not export to next AS (well-known community)\n"
8520 "community number\n"
8521 "Do not send outside local AS (well-known community)\n"
8522 "Do not advertise to any peer (well-known community)\n"
8523 "Do not export to next AS (well-known community)\n"
8524 "Exact match of the communities")
8525
8526ALIAS (show_bgp_community_exact,
8527 show_bgp_ipv6_community3_exact_cmd,
8528 "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",
8529 SHOW_STR
8530 BGP_STR
8531 "Address family\n"
8532 "Display routes matching the communities\n"
8533 "community number\n"
8534 "Do not send outside local AS (well-known community)\n"
8535 "Do not advertise to any peer (well-known community)\n"
8536 "Do not export to next AS (well-known community)\n"
8537 "community number\n"
8538 "Do not send outside local AS (well-known community)\n"
8539 "Do not advertise to any peer (well-known community)\n"
8540 "Do not export to next AS (well-known community)\n"
8541 "community number\n"
8542 "Do not send outside local AS (well-known community)\n"
8543 "Do not advertise to any peer (well-known community)\n"
8544 "Do not export to next AS (well-known community)\n"
8545 "Exact match of the communities")
8546
8547ALIAS (show_bgp_community_exact,
8548 show_bgp_community4_exact_cmd,
8549 "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",
8550 SHOW_STR
8551 BGP_STR
8552 "Display routes matching the communities\n"
8553 "community number\n"
8554 "Do not send outside local AS (well-known community)\n"
8555 "Do not advertise to any peer (well-known community)\n"
8556 "Do not export to next AS (well-known community)\n"
8557 "community number\n"
8558 "Do not send outside local AS (well-known community)\n"
8559 "Do not advertise to any peer (well-known community)\n"
8560 "Do not export to next AS (well-known community)\n"
8561 "community number\n"
8562 "Do not send outside local AS (well-known community)\n"
8563 "Do not advertise to any peer (well-known community)\n"
8564 "Do not export to next AS (well-known community)\n"
8565 "community number\n"
8566 "Do not send outside local AS (well-known community)\n"
8567 "Do not advertise to any peer (well-known community)\n"
8568 "Do not export to next AS (well-known community)\n"
8569 "Exact match of the communities")
8570
8571ALIAS (show_bgp_community_exact,
8572 show_bgp_ipv6_community4_exact_cmd,
8573 "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",
8574 SHOW_STR
8575 BGP_STR
8576 "Address family\n"
8577 "Display routes matching the communities\n"
8578 "community number\n"
8579 "Do not send outside local AS (well-known community)\n"
8580 "Do not advertise to any peer (well-known community)\n"
8581 "Do not export to next AS (well-known community)\n"
8582 "community number\n"
8583 "Do not send outside local AS (well-known community)\n"
8584 "Do not advertise to any peer (well-known community)\n"
8585 "Do not export to next AS (well-known community)\n"
8586 "community number\n"
8587 "Do not send outside local AS (well-known community)\n"
8588 "Do not advertise to any peer (well-known community)\n"
8589 "Do not export to next AS (well-known community)\n"
8590 "community number\n"
8591 "Do not send outside local AS (well-known community)\n"
8592 "Do not advertise to any peer (well-known community)\n"
8593 "Do not export to next AS (well-known community)\n"
8594 "Exact match of the communities")
8595
8596/* old command */
8597DEFUN (show_ipv6_bgp_community_exact,
8598 show_ipv6_bgp_community_exact_cmd,
8599 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8600 SHOW_STR
8601 IPV6_STR
8602 BGP_STR
8603 "Display routes matching the communities\n"
8604 "community number\n"
8605 "Do not send outside local AS (well-known community)\n"
8606 "Do not advertise to any peer (well-known community)\n"
8607 "Do not export to next AS (well-known community)\n"
8608 "Exact match of the communities")
8609{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008610 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008611}
8612
8613/* old command */
8614ALIAS (show_ipv6_bgp_community_exact,
8615 show_ipv6_bgp_community2_exact_cmd,
8616 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8617 SHOW_STR
8618 IPV6_STR
8619 BGP_STR
8620 "Display routes matching the communities\n"
8621 "community number\n"
8622 "Do not send outside local AS (well-known community)\n"
8623 "Do not advertise to any peer (well-known community)\n"
8624 "Do not export to next AS (well-known community)\n"
8625 "community number\n"
8626 "Do not send outside local AS (well-known community)\n"
8627 "Do not advertise to any peer (well-known community)\n"
8628 "Do not export to next AS (well-known community)\n"
8629 "Exact match of the communities")
8630
8631/* old command */
8632ALIAS (show_ipv6_bgp_community_exact,
8633 show_ipv6_bgp_community3_exact_cmd,
8634 "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",
8635 SHOW_STR
8636 IPV6_STR
8637 BGP_STR
8638 "Display routes matching the communities\n"
8639 "community number\n"
8640 "Do not send outside local AS (well-known community)\n"
8641 "Do not advertise to any peer (well-known community)\n"
8642 "Do not export to next AS (well-known community)\n"
8643 "community number\n"
8644 "Do not send outside local AS (well-known community)\n"
8645 "Do not advertise to any peer (well-known community)\n"
8646 "Do not export to next AS (well-known community)\n"
8647 "community number\n"
8648 "Do not send outside local AS (well-known community)\n"
8649 "Do not advertise to any peer (well-known community)\n"
8650 "Do not export to next AS (well-known community)\n"
8651 "Exact match of the communities")
8652
8653/* old command */
8654ALIAS (show_ipv6_bgp_community_exact,
8655 show_ipv6_bgp_community4_exact_cmd,
8656 "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",
8657 SHOW_STR
8658 IPV6_STR
8659 BGP_STR
8660 "Display routes matching the communities\n"
8661 "community number\n"
8662 "Do not send outside local AS (well-known community)\n"
8663 "Do not advertise to any peer (well-known community)\n"
8664 "Do not export to next AS (well-known community)\n"
8665 "community number\n"
8666 "Do not send outside local AS (well-known community)\n"
8667 "Do not advertise to any peer (well-known community)\n"
8668 "Do not export to next AS (well-known community)\n"
8669 "community number\n"
8670 "Do not send outside local AS (well-known community)\n"
8671 "Do not advertise to any peer (well-known community)\n"
8672 "Do not export to next AS (well-known community)\n"
8673 "community number\n"
8674 "Do not send outside local AS (well-known community)\n"
8675 "Do not advertise to any peer (well-known community)\n"
8676 "Do not export to next AS (well-known community)\n"
8677 "Exact match of the communities")
8678
8679/* old command */
8680DEFUN (show_ipv6_mbgp_community,
8681 show_ipv6_mbgp_community_cmd,
8682 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8683 SHOW_STR
8684 IPV6_STR
8685 MBGP_STR
8686 "Display routes matching the communities\n"
8687 "community number\n"
8688 "Do not send outside local AS (well-known community)\n"
8689 "Do not advertise to any peer (well-known community)\n"
8690 "Do not export to next AS (well-known community)\n")
8691{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008692 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008693}
8694
8695/* old command */
8696ALIAS (show_ipv6_mbgp_community,
8697 show_ipv6_mbgp_community2_cmd,
8698 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8699 SHOW_STR
8700 IPV6_STR
8701 MBGP_STR
8702 "Display routes matching the communities\n"
8703 "community number\n"
8704 "Do not send outside local AS (well-known community)\n"
8705 "Do not advertise to any peer (well-known community)\n"
8706 "Do not export to next AS (well-known community)\n"
8707 "community number\n"
8708 "Do not send outside local AS (well-known community)\n"
8709 "Do not advertise to any peer (well-known community)\n"
8710 "Do not export to next AS (well-known community)\n")
8711
8712/* old command */
8713ALIAS (show_ipv6_mbgp_community,
8714 show_ipv6_mbgp_community3_cmd,
8715 "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)",
8716 SHOW_STR
8717 IPV6_STR
8718 MBGP_STR
8719 "Display routes matching the communities\n"
8720 "community number\n"
8721 "Do not send outside local AS (well-known community)\n"
8722 "Do not advertise to any peer (well-known community)\n"
8723 "Do not export to next AS (well-known community)\n"
8724 "community number\n"
8725 "Do not send outside local AS (well-known community)\n"
8726 "Do not advertise to any peer (well-known community)\n"
8727 "Do not export to next AS (well-known community)\n"
8728 "community number\n"
8729 "Do not send outside local AS (well-known community)\n"
8730 "Do not advertise to any peer (well-known community)\n"
8731 "Do not export to next AS (well-known community)\n")
8732
8733/* old command */
8734ALIAS (show_ipv6_mbgp_community,
8735 show_ipv6_mbgp_community4_cmd,
8736 "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)",
8737 SHOW_STR
8738 IPV6_STR
8739 MBGP_STR
8740 "Display routes matching the communities\n"
8741 "community number\n"
8742 "Do not send outside local AS (well-known community)\n"
8743 "Do not advertise to any peer (well-known community)\n"
8744 "Do not export to next AS (well-known community)\n"
8745 "community number\n"
8746 "Do not send outside local AS (well-known community)\n"
8747 "Do not advertise to any peer (well-known community)\n"
8748 "Do not export to next AS (well-known community)\n"
8749 "community number\n"
8750 "Do not send outside local AS (well-known community)\n"
8751 "Do not advertise to any peer (well-known community)\n"
8752 "Do not export to next AS (well-known community)\n"
8753 "community number\n"
8754 "Do not send outside local AS (well-known community)\n"
8755 "Do not advertise to any peer (well-known community)\n"
8756 "Do not export to next AS (well-known community)\n")
8757
8758/* old command */
8759DEFUN (show_ipv6_mbgp_community_exact,
8760 show_ipv6_mbgp_community_exact_cmd,
8761 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8762 SHOW_STR
8763 IPV6_STR
8764 MBGP_STR
8765 "Display routes matching the communities\n"
8766 "community number\n"
8767 "Do not send outside local AS (well-known community)\n"
8768 "Do not advertise to any peer (well-known community)\n"
8769 "Do not export to next AS (well-known community)\n"
8770 "Exact match of the communities")
8771{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008772 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008773}
8774
8775/* old command */
8776ALIAS (show_ipv6_mbgp_community_exact,
8777 show_ipv6_mbgp_community2_exact_cmd,
8778 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8779 SHOW_STR
8780 IPV6_STR
8781 MBGP_STR
8782 "Display routes matching the communities\n"
8783 "community number\n"
8784 "Do not send outside local AS (well-known community)\n"
8785 "Do not advertise to any peer (well-known community)\n"
8786 "Do not export to next AS (well-known community)\n"
8787 "community number\n"
8788 "Do not send outside local AS (well-known community)\n"
8789 "Do not advertise to any peer (well-known community)\n"
8790 "Do not export to next AS (well-known community)\n"
8791 "Exact match of the communities")
8792
8793/* old command */
8794ALIAS (show_ipv6_mbgp_community_exact,
8795 show_ipv6_mbgp_community3_exact_cmd,
8796 "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",
8797 SHOW_STR
8798 IPV6_STR
8799 MBGP_STR
8800 "Display routes matching the communities\n"
8801 "community number\n"
8802 "Do not send outside local AS (well-known community)\n"
8803 "Do not advertise to any peer (well-known community)\n"
8804 "Do not export to next AS (well-known community)\n"
8805 "community number\n"
8806 "Do not send outside local AS (well-known community)\n"
8807 "Do not advertise to any peer (well-known community)\n"
8808 "Do not export to next AS (well-known community)\n"
8809 "community number\n"
8810 "Do not send outside local AS (well-known community)\n"
8811 "Do not advertise to any peer (well-known community)\n"
8812 "Do not export to next AS (well-known community)\n"
8813 "Exact match of the communities")
8814
8815/* old command */
8816ALIAS (show_ipv6_mbgp_community_exact,
8817 show_ipv6_mbgp_community4_exact_cmd,
8818 "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",
8819 SHOW_STR
8820 IPV6_STR
8821 MBGP_STR
8822 "Display routes matching the communities\n"
8823 "community number\n"
8824 "Do not send outside local AS (well-known community)\n"
8825 "Do not advertise to any peer (well-known community)\n"
8826 "Do not export to next AS (well-known community)\n"
8827 "community number\n"
8828 "Do not send outside local AS (well-known community)\n"
8829 "Do not advertise to any peer (well-known community)\n"
8830 "Do not export to next AS (well-known community)\n"
8831 "community number\n"
8832 "Do not send outside local AS (well-known community)\n"
8833 "Do not advertise to any peer (well-known community)\n"
8834 "Do not export to next AS (well-known community)\n"
8835 "community number\n"
8836 "Do not send outside local AS (well-known community)\n"
8837 "Do not advertise to any peer (well-known community)\n"
8838 "Do not export to next AS (well-known community)\n"
8839 "Exact match of the communities")
8840#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02008841
paul94f2b392005-06-28 12:44:16 +00008842static int
paulfd79ac92004-10-13 05:06:08 +00008843bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008844 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008845{
8846 struct community_list *list;
8847
hassofee6e4e2005-02-02 16:29:31 +00008848 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008849 if (list == NULL)
8850 {
8851 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8852 VTY_NEWLINE);
8853 return CMD_WARNING;
8854 }
8855
ajs5a646652004-11-05 01:25:55 +00008856 return bgp_show (vty, NULL, afi, safi,
8857 (exact ? bgp_show_type_community_list_exact :
8858 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008859}
8860
8861DEFUN (show_ip_bgp_community_list,
8862 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008863 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008864 SHOW_STR
8865 IP_STR
8866 BGP_STR
8867 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008868 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008869 "community-list name\n")
8870{
8871 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8872}
8873
8874DEFUN (show_ip_bgp_ipv4_community_list,
8875 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008876 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008877 SHOW_STR
8878 IP_STR
8879 BGP_STR
8880 "Address family\n"
8881 "Address Family modifier\n"
8882 "Address Family modifier\n"
8883 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008884 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008885 "community-list name\n")
8886{
8887 if (strncmp (argv[0], "m", 1) == 0)
8888 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8889
8890 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8891}
8892
8893DEFUN (show_ip_bgp_community_list_exact,
8894 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008895 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008896 SHOW_STR
8897 IP_STR
8898 BGP_STR
8899 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008900 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008901 "community-list name\n"
8902 "Exact match of the communities\n")
8903{
8904 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8905}
8906
8907DEFUN (show_ip_bgp_ipv4_community_list_exact,
8908 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008909 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008910 SHOW_STR
8911 IP_STR
8912 BGP_STR
8913 "Address family\n"
8914 "Address Family modifier\n"
8915 "Address Family modifier\n"
8916 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008917 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008918 "community-list name\n"
8919 "Exact match of the communities\n")
8920{
8921 if (strncmp (argv[0], "m", 1) == 0)
8922 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8923
8924 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8925}
8926
8927#ifdef HAVE_IPV6
8928DEFUN (show_bgp_community_list,
8929 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008930 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008931 SHOW_STR
8932 BGP_STR
8933 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008934 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008935 "community-list name\n")
8936{
8937 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8938}
8939
8940ALIAS (show_bgp_community_list,
8941 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008942 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008943 SHOW_STR
8944 BGP_STR
8945 "Address family\n"
8946 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008947 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008948 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008949
8950/* old command */
8951DEFUN (show_ipv6_bgp_community_list,
8952 show_ipv6_bgp_community_list_cmd,
8953 "show ipv6 bgp community-list WORD",
8954 SHOW_STR
8955 IPV6_STR
8956 BGP_STR
8957 "Display routes matching the community-list\n"
8958 "community-list name\n")
8959{
8960 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8961}
8962
8963/* old command */
8964DEFUN (show_ipv6_mbgp_community_list,
8965 show_ipv6_mbgp_community_list_cmd,
8966 "show ipv6 mbgp community-list WORD",
8967 SHOW_STR
8968 IPV6_STR
8969 MBGP_STR
8970 "Display routes matching the community-list\n"
8971 "community-list name\n")
8972{
8973 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8974}
8975
8976DEFUN (show_bgp_community_list_exact,
8977 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008978 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008979 SHOW_STR
8980 BGP_STR
8981 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008982 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008983 "community-list name\n"
8984 "Exact match of the communities\n")
8985{
8986 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8987}
8988
8989ALIAS (show_bgp_community_list_exact,
8990 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008991 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008992 SHOW_STR
8993 BGP_STR
8994 "Address family\n"
8995 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008996 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008997 "community-list name\n"
8998 "Exact match of the communities\n")
8999
9000/* old command */
9001DEFUN (show_ipv6_bgp_community_list_exact,
9002 show_ipv6_bgp_community_list_exact_cmd,
9003 "show ipv6 bgp community-list WORD exact-match",
9004 SHOW_STR
9005 IPV6_STR
9006 BGP_STR
9007 "Display routes matching the community-list\n"
9008 "community-list name\n"
9009 "Exact match of the communities\n")
9010{
9011 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9012}
9013
9014/* old command */
9015DEFUN (show_ipv6_mbgp_community_list_exact,
9016 show_ipv6_mbgp_community_list_exact_cmd,
9017 "show ipv6 mbgp community-list WORD exact-match",
9018 SHOW_STR
9019 IPV6_STR
9020 MBGP_STR
9021 "Display routes matching the community-list\n"
9022 "community-list name\n"
9023 "Exact match of the communities\n")
9024{
9025 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9026}
9027#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009028
paul94f2b392005-06-28 12:44:16 +00009029static int
paulfd79ac92004-10-13 05:06:08 +00009030bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009031 safi_t safi, enum bgp_show_type type)
9032{
9033 int ret;
9034 struct prefix *p;
9035
9036 p = prefix_new();
9037
9038 ret = str2prefix (prefix, p);
9039 if (! ret)
9040 {
9041 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9042 return CMD_WARNING;
9043 }
9044
ajs5a646652004-11-05 01:25:55 +00009045 ret = bgp_show (vty, NULL, afi, safi, type, p);
9046 prefix_free(p);
9047 return ret;
paul718e3742002-12-13 20:15:29 +00009048}
9049
9050DEFUN (show_ip_bgp_prefix_longer,
9051 show_ip_bgp_prefix_longer_cmd,
9052 "show ip bgp A.B.C.D/M longer-prefixes",
9053 SHOW_STR
9054 IP_STR
9055 BGP_STR
9056 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9057 "Display route and more specific routes\n")
9058{
9059 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9060 bgp_show_type_prefix_longer);
9061}
9062
9063DEFUN (show_ip_bgp_flap_prefix_longer,
9064 show_ip_bgp_flap_prefix_longer_cmd,
9065 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9066 SHOW_STR
9067 IP_STR
9068 BGP_STR
9069 "Display flap statistics of routes\n"
9070 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9071 "Display route and more specific routes\n")
9072{
9073 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9074 bgp_show_type_flap_prefix_longer);
9075}
9076
9077DEFUN (show_ip_bgp_ipv4_prefix_longer,
9078 show_ip_bgp_ipv4_prefix_longer_cmd,
9079 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9080 SHOW_STR
9081 IP_STR
9082 BGP_STR
9083 "Address family\n"
9084 "Address Family modifier\n"
9085 "Address Family modifier\n"
9086 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9087 "Display route and more specific routes\n")
9088{
9089 if (strncmp (argv[0], "m", 1) == 0)
9090 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9091 bgp_show_type_prefix_longer);
9092
9093 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9094 bgp_show_type_prefix_longer);
9095}
9096
9097DEFUN (show_ip_bgp_flap_address,
9098 show_ip_bgp_flap_address_cmd,
9099 "show ip bgp flap-statistics A.B.C.D",
9100 SHOW_STR
9101 IP_STR
9102 BGP_STR
9103 "Display flap statistics of routes\n"
9104 "Network in the BGP routing table to display\n")
9105{
9106 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9107 bgp_show_type_flap_address);
9108}
9109
9110DEFUN (show_ip_bgp_flap_prefix,
9111 show_ip_bgp_flap_prefix_cmd,
9112 "show ip bgp flap-statistics A.B.C.D/M",
9113 SHOW_STR
9114 IP_STR
9115 BGP_STR
9116 "Display flap statistics of routes\n"
9117 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9118{
9119 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9120 bgp_show_type_flap_prefix);
9121}
9122#ifdef HAVE_IPV6
9123DEFUN (show_bgp_prefix_longer,
9124 show_bgp_prefix_longer_cmd,
9125 "show bgp X:X::X:X/M longer-prefixes",
9126 SHOW_STR
9127 BGP_STR
9128 "IPv6 prefix <network>/<length>\n"
9129 "Display route and more specific routes\n")
9130{
9131 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9132 bgp_show_type_prefix_longer);
9133}
9134
9135ALIAS (show_bgp_prefix_longer,
9136 show_bgp_ipv6_prefix_longer_cmd,
9137 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9138 SHOW_STR
9139 BGP_STR
9140 "Address family\n"
9141 "IPv6 prefix <network>/<length>\n"
9142 "Display route and more specific routes\n")
9143
9144/* old command */
9145DEFUN (show_ipv6_bgp_prefix_longer,
9146 show_ipv6_bgp_prefix_longer_cmd,
9147 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9148 SHOW_STR
9149 IPV6_STR
9150 BGP_STR
9151 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9152 "Display route and more specific routes\n")
9153{
9154 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9155 bgp_show_type_prefix_longer);
9156}
9157
9158/* old command */
9159DEFUN (show_ipv6_mbgp_prefix_longer,
9160 show_ipv6_mbgp_prefix_longer_cmd,
9161 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9162 SHOW_STR
9163 IPV6_STR
9164 MBGP_STR
9165 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9166 "Display route and more specific routes\n")
9167{
9168 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9169 bgp_show_type_prefix_longer);
9170}
9171#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009172
paul94f2b392005-06-28 12:44:16 +00009173static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009174peer_lookup_in_view (struct vty *vty, const char *view_name,
9175 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009176{
9177 int ret;
9178 struct bgp *bgp;
9179 struct peer *peer;
9180 union sockunion su;
9181
9182 /* BGP structure lookup. */
9183 if (view_name)
9184 {
9185 bgp = bgp_lookup_by_name (view_name);
9186 if (! bgp)
9187 {
9188 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9189 return NULL;
9190 }
9191 }
paul5228ad22004-06-04 17:58:18 +00009192 else
paulbb46e942003-10-24 19:02:03 +00009193 {
9194 bgp = bgp_get_default ();
9195 if (! bgp)
9196 {
9197 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9198 return NULL;
9199 }
9200 }
9201
9202 /* Get peer sockunion. */
9203 ret = str2sockunion (ip_str, &su);
9204 if (ret < 0)
9205 {
9206 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9207 return NULL;
9208 }
9209
9210 /* Peer structure lookup. */
9211 peer = peer_lookup (bgp, &su);
9212 if (! peer)
9213 {
9214 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9215 return NULL;
9216 }
9217
9218 return peer;
9219}
David Lamparter6b0655a2014-06-04 06:53:35 +02009220
Paul Jakma2815e612006-09-14 02:56:07 +00009221enum bgp_stats
9222{
9223 BGP_STATS_MAXBITLEN = 0,
9224 BGP_STATS_RIB,
9225 BGP_STATS_PREFIXES,
9226 BGP_STATS_TOTPLEN,
9227 BGP_STATS_UNAGGREGATEABLE,
9228 BGP_STATS_MAX_AGGREGATEABLE,
9229 BGP_STATS_AGGREGATES,
9230 BGP_STATS_SPACE,
9231 BGP_STATS_ASPATH_COUNT,
9232 BGP_STATS_ASPATH_MAXHOPS,
9233 BGP_STATS_ASPATH_TOTHOPS,
9234 BGP_STATS_ASPATH_MAXSIZE,
9235 BGP_STATS_ASPATH_TOTSIZE,
9236 BGP_STATS_ASN_HIGHEST,
9237 BGP_STATS_MAX,
9238};
paulbb46e942003-10-24 19:02:03 +00009239
Paul Jakma2815e612006-09-14 02:56:07 +00009240static const char *table_stats_strs[] =
9241{
9242 [BGP_STATS_PREFIXES] = "Total Prefixes",
9243 [BGP_STATS_TOTPLEN] = "Average prefix length",
9244 [BGP_STATS_RIB] = "Total Advertisements",
9245 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9246 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9247 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9248 [BGP_STATS_SPACE] = "Address space advertised",
9249 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9250 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9251 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9252 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9253 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9254 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9255 [BGP_STATS_MAX] = NULL,
9256};
9257
9258struct bgp_table_stats
9259{
9260 struct bgp_table *table;
9261 unsigned long long counts[BGP_STATS_MAX];
9262};
9263
9264#if 0
9265#define TALLY_SIGFIG 100000
9266static unsigned long
9267ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9268{
9269 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9270 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9271 unsigned long ret = newtot / count;
9272
9273 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9274 return ret + 1;
9275 else
9276 return ret;
9277}
9278#endif
9279
9280static int
9281bgp_table_stats_walker (struct thread *t)
9282{
9283 struct bgp_node *rn;
9284 struct bgp_node *top;
9285 struct bgp_table_stats *ts = THREAD_ARG (t);
9286 unsigned int space = 0;
9287
Paul Jakma53d9f672006-10-15 23:41:16 +00009288 if (!(top = bgp_table_top (ts->table)))
9289 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009290
9291 switch (top->p.family)
9292 {
9293 case AF_INET:
9294 space = IPV4_MAX_BITLEN;
9295 break;
9296 case AF_INET6:
9297 space = IPV6_MAX_BITLEN;
9298 break;
9299 }
9300
9301 ts->counts[BGP_STATS_MAXBITLEN] = space;
9302
9303 for (rn = top; rn; rn = bgp_route_next (rn))
9304 {
9305 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009306 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009307 unsigned int rinum = 0;
9308
9309 if (rn == top)
9310 continue;
9311
9312 if (!rn->info)
9313 continue;
9314
9315 ts->counts[BGP_STATS_PREFIXES]++;
9316 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9317
9318#if 0
9319 ts->counts[BGP_STATS_AVGPLEN]
9320 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9321 ts->counts[BGP_STATS_AVGPLEN],
9322 rn->p.prefixlen);
9323#endif
9324
9325 /* check if the prefix is included by any other announcements */
9326 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009327 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009328
9329 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009330 {
9331 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9332 /* announced address space */
9333 if (space)
9334 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9335 }
Paul Jakma2815e612006-09-14 02:56:07 +00009336 else if (prn->info)
9337 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9338
Paul Jakma2815e612006-09-14 02:56:07 +00009339 for (ri = rn->info; ri; ri = ri->next)
9340 {
9341 rinum++;
9342 ts->counts[BGP_STATS_RIB]++;
9343
9344 if (ri->attr &&
9345 (CHECK_FLAG (ri->attr->flag,
9346 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9347 ts->counts[BGP_STATS_AGGREGATES]++;
9348
9349 /* as-path stats */
9350 if (ri->attr && ri->attr->aspath)
9351 {
9352 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9353 unsigned int size = aspath_size (ri->attr->aspath);
9354 as_t highest = aspath_highest (ri->attr->aspath);
9355
9356 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9357
9358 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9359 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9360
9361 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9362 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9363
9364 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9365 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9366#if 0
9367 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9368 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9369 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9370 hops);
9371 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9372 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9373 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9374 size);
9375#endif
9376 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9377 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9378 }
9379 }
9380 }
9381 return 0;
9382}
9383
9384static int
9385bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9386{
9387 struct bgp_table_stats ts;
9388 unsigned int i;
9389
9390 if (!bgp->rib[afi][safi])
9391 {
9392 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9393 return CMD_WARNING;
9394 }
9395
9396 memset (&ts, 0, sizeof (ts));
9397 ts.table = bgp->rib[afi][safi];
9398 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9399
9400 vty_out (vty, "BGP %s RIB statistics%s%s",
9401 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9402
9403 for (i = 0; i < BGP_STATS_MAX; i++)
9404 {
9405 if (!table_stats_strs[i])
9406 continue;
9407
9408 switch (i)
9409 {
9410#if 0
9411 case BGP_STATS_ASPATH_AVGHOPS:
9412 case BGP_STATS_ASPATH_AVGSIZE:
9413 case BGP_STATS_AVGPLEN:
9414 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9415 vty_out (vty, "%12.2f",
9416 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9417 break;
9418#endif
9419 case BGP_STATS_ASPATH_TOTHOPS:
9420 case BGP_STATS_ASPATH_TOTSIZE:
9421 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9422 vty_out (vty, "%12.2f",
9423 ts.counts[i] ?
9424 (float)ts.counts[i] /
9425 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9426 : 0);
9427 break;
9428 case BGP_STATS_TOTPLEN:
9429 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9430 vty_out (vty, "%12.2f",
9431 ts.counts[i] ?
9432 (float)ts.counts[i] /
9433 (float)ts.counts[BGP_STATS_PREFIXES]
9434 : 0);
9435 break;
9436 case BGP_STATS_SPACE:
9437 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9438 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9439 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9440 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009441 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009442 vty_out (vty, "%12.2f%s",
9443 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009444 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009445 VTY_NEWLINE);
9446 vty_out (vty, "%30s: ", "/8 equivalent ");
9447 vty_out (vty, "%12.2f%s",
9448 (float)ts.counts[BGP_STATS_SPACE] /
9449 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9450 VTY_NEWLINE);
9451 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9452 break;
9453 vty_out (vty, "%30s: ", "/24 equivalent ");
9454 vty_out (vty, "%12.2f",
9455 (float)ts.counts[BGP_STATS_SPACE] /
9456 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9457 break;
9458 default:
9459 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9460 vty_out (vty, "%12llu", ts.counts[i]);
9461 }
9462
9463 vty_out (vty, "%s", VTY_NEWLINE);
9464 }
9465 return CMD_SUCCESS;
9466}
9467
9468static int
9469bgp_table_stats_vty (struct vty *vty, const char *name,
9470 const char *afi_str, const char *safi_str)
9471{
9472 struct bgp *bgp;
9473 afi_t afi;
9474 safi_t safi;
9475
9476 if (name)
9477 bgp = bgp_lookup_by_name (name);
9478 else
9479 bgp = bgp_get_default ();
9480
9481 if (!bgp)
9482 {
9483 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9484 return CMD_WARNING;
9485 }
9486 if (strncmp (afi_str, "ipv", 3) == 0)
9487 {
9488 if (strncmp (afi_str, "ipv4", 4) == 0)
9489 afi = AFI_IP;
9490 else if (strncmp (afi_str, "ipv6", 4) == 0)
9491 afi = AFI_IP6;
9492 else
9493 {
9494 vty_out (vty, "%% Invalid address family %s%s",
9495 afi_str, VTY_NEWLINE);
9496 return CMD_WARNING;
9497 }
9498 if (strncmp (safi_str, "m", 1) == 0)
9499 safi = SAFI_MULTICAST;
9500 else if (strncmp (safi_str, "u", 1) == 0)
9501 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009502 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9503 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009504 else
9505 {
9506 vty_out (vty, "%% Invalid subsequent address family %s%s",
9507 safi_str, VTY_NEWLINE);
9508 return CMD_WARNING;
9509 }
9510 }
9511 else
9512 {
9513 vty_out (vty, "%% Invalid address family %s%s",
9514 afi_str, VTY_NEWLINE);
9515 return CMD_WARNING;
9516 }
9517
Paul Jakma2815e612006-09-14 02:56:07 +00009518 return bgp_table_stats (vty, bgp, afi, safi);
9519}
9520
9521DEFUN (show_bgp_statistics,
9522 show_bgp_statistics_cmd,
9523 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9524 SHOW_STR
9525 BGP_STR
9526 "Address family\n"
9527 "Address family\n"
9528 "Address Family modifier\n"
9529 "Address Family modifier\n"
9530 "BGP RIB advertisement statistics\n")
9531{
9532 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9533}
9534
9535ALIAS (show_bgp_statistics,
9536 show_bgp_statistics_vpnv4_cmd,
9537 "show bgp (ipv4) (vpnv4) statistics",
9538 SHOW_STR
9539 BGP_STR
9540 "Address family\n"
9541 "Address Family modifier\n"
9542 "BGP RIB advertisement statistics\n")
9543
9544DEFUN (show_bgp_statistics_view,
9545 show_bgp_statistics_view_cmd,
9546 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9547 SHOW_STR
9548 BGP_STR
9549 "BGP view\n"
9550 "Address family\n"
9551 "Address family\n"
9552 "Address Family modifier\n"
9553 "Address Family modifier\n"
9554 "BGP RIB advertisement statistics\n")
9555{
9556 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9557}
9558
9559ALIAS (show_bgp_statistics_view,
9560 show_bgp_statistics_view_vpnv4_cmd,
9561 "show bgp view WORD (ipv4) (vpnv4) statistics",
9562 SHOW_STR
9563 BGP_STR
9564 "BGP view\n"
9565 "Address family\n"
9566 "Address Family modifier\n"
9567 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02009568
Paul Jakmaff7924f2006-09-04 01:10:36 +00009569enum bgp_pcounts
9570{
9571 PCOUNT_ADJ_IN = 0,
9572 PCOUNT_DAMPED,
9573 PCOUNT_REMOVED,
9574 PCOUNT_HISTORY,
9575 PCOUNT_STALE,
9576 PCOUNT_VALID,
9577 PCOUNT_ALL,
9578 PCOUNT_COUNTED,
9579 PCOUNT_PFCNT, /* the figure we display to users */
9580 PCOUNT_MAX,
9581};
9582
9583static const char *pcount_strs[] =
9584{
9585 [PCOUNT_ADJ_IN] = "Adj-in",
9586 [PCOUNT_DAMPED] = "Damped",
9587 [PCOUNT_REMOVED] = "Removed",
9588 [PCOUNT_HISTORY] = "History",
9589 [PCOUNT_STALE] = "Stale",
9590 [PCOUNT_VALID] = "Valid",
9591 [PCOUNT_ALL] = "All RIB",
9592 [PCOUNT_COUNTED] = "PfxCt counted",
9593 [PCOUNT_PFCNT] = "Useable",
9594 [PCOUNT_MAX] = NULL,
9595};
9596
Paul Jakma2815e612006-09-14 02:56:07 +00009597struct peer_pcounts
9598{
9599 unsigned int count[PCOUNT_MAX];
9600 const struct peer *peer;
9601 const struct bgp_table *table;
9602};
9603
Paul Jakmaff7924f2006-09-04 01:10:36 +00009604static int
Paul Jakma2815e612006-09-14 02:56:07 +00009605bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009606{
9607 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009608 struct peer_pcounts *pc = THREAD_ARG (t);
9609 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009610
Paul Jakma2815e612006-09-14 02:56:07 +00009611 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009612 {
9613 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009614 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009615
9616 for (ain = rn->adj_in; ain; ain = ain->next)
9617 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009618 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009619
Paul Jakmaff7924f2006-09-04 01:10:36 +00009620 for (ri = rn->info; ri; ri = ri->next)
9621 {
9622 char buf[SU_ADDRSTRLEN];
9623
9624 if (ri->peer != peer)
9625 continue;
9626
Paul Jakma2815e612006-09-14 02:56:07 +00009627 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009628
9629 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009630 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009631 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009632 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009633 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009634 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009635 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009636 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009637 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009638 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009639 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009640 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009641
9642 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9643 {
Paul Jakma2815e612006-09-14 02:56:07 +00009644 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009645 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009646 plog_warn (peer->log,
9647 "%s [pcount] %s/%d is counted but flags 0x%x",
9648 peer->host,
9649 inet_ntop(rn->p.family, &rn->p.u.prefix,
9650 buf, SU_ADDRSTRLEN),
9651 rn->p.prefixlen,
9652 ri->flags);
9653 }
9654 else
9655 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009656 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009657 plog_warn (peer->log,
9658 "%s [pcount] %s/%d not counted but flags 0x%x",
9659 peer->host,
9660 inet_ntop(rn->p.family, &rn->p.u.prefix,
9661 buf, SU_ADDRSTRLEN),
9662 rn->p.prefixlen,
9663 ri->flags);
9664 }
9665 }
9666 }
Paul Jakma2815e612006-09-14 02:56:07 +00009667 return 0;
9668}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009669
Paul Jakma2815e612006-09-14 02:56:07 +00009670static int
9671bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9672{
9673 struct peer_pcounts pcounts = { .peer = peer };
9674 unsigned int i;
9675
9676 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9677 || !peer->bgp->rib[afi][safi])
9678 {
9679 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9680 return CMD_WARNING;
9681 }
9682
9683 memset (&pcounts, 0, sizeof(pcounts));
9684 pcounts.peer = peer;
9685 pcounts.table = peer->bgp->rib[afi][safi];
9686
9687 /* in-place call via thread subsystem so as to record execution time
9688 * stats for the thread-walk (i.e. ensure this can't be blamed on
9689 * on just vty_read()).
9690 */
9691 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9692
Paul Jakmaff7924f2006-09-04 01:10:36 +00009693 vty_out (vty, "Prefix counts for %s, %s%s",
9694 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9695 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9696 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9697 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9698
9699 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009700 vty_out (vty, "%20s: %-10d%s",
9701 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009702
Paul Jakma2815e612006-09-14 02:56:07 +00009703 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009704 {
9705 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9706 peer->host, VTY_NEWLINE);
9707 vty_out (vty, "Please report this bug, with the above command output%s",
9708 VTY_NEWLINE);
9709 }
9710
9711 return CMD_SUCCESS;
9712}
9713
9714DEFUN (show_ip_bgp_neighbor_prefix_counts,
9715 show_ip_bgp_neighbor_prefix_counts_cmd,
9716 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9717 SHOW_STR
9718 IP_STR
9719 BGP_STR
9720 "Detailed information on TCP and BGP neighbor connections\n"
9721 "Neighbor to display information about\n"
9722 "Neighbor to display information about\n"
9723 "Display detailed prefix count information\n")
9724{
9725 struct peer *peer;
9726
9727 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9728 if (! peer)
9729 return CMD_WARNING;
9730
9731 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9732}
9733
9734DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9735 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9736 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9737 SHOW_STR
9738 BGP_STR
9739 "Address family\n"
9740 "Detailed information on TCP and BGP neighbor connections\n"
9741 "Neighbor to display information about\n"
9742 "Neighbor to display information about\n"
9743 "Display detailed prefix count information\n")
9744{
9745 struct peer *peer;
9746
9747 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9748 if (! peer)
9749 return CMD_WARNING;
9750
9751 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9752}
9753
9754DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9755 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9756 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9757 SHOW_STR
9758 IP_STR
9759 BGP_STR
9760 "Address family\n"
9761 "Address Family modifier\n"
9762 "Address Family modifier\n"
9763 "Detailed information on TCP and BGP neighbor connections\n"
9764 "Neighbor to display information about\n"
9765 "Neighbor to display information about\n"
9766 "Display detailed prefix count information\n")
9767{
9768 struct peer *peer;
9769
9770 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9771 if (! peer)
9772 return CMD_WARNING;
9773
9774 if (strncmp (argv[0], "m", 1) == 0)
9775 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9776
9777 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9778}
9779
9780DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9781 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9782 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9783 SHOW_STR
9784 IP_STR
9785 BGP_STR
9786 "Address family\n"
9787 "Address Family modifier\n"
9788 "Address Family modifier\n"
9789 "Detailed information on TCP and BGP neighbor connections\n"
9790 "Neighbor to display information about\n"
9791 "Neighbor to display information about\n"
9792 "Display detailed prefix count information\n")
9793{
9794 struct peer *peer;
9795
9796 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9797 if (! peer)
9798 return CMD_WARNING;
9799
9800 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9801}
9802
9803
paul94f2b392005-06-28 12:44:16 +00009804static void
paul718e3742002-12-13 20:15:29 +00009805show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9806 int in)
9807{
9808 struct bgp_table *table;
9809 struct bgp_adj_in *ain;
9810 struct bgp_adj_out *adj;
9811 unsigned long output_count;
9812 struct bgp_node *rn;
9813 int header1 = 1;
9814 struct bgp *bgp;
9815 int header2 = 1;
9816
paulbb46e942003-10-24 19:02:03 +00009817 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009818
9819 if (! bgp)
9820 return;
9821
9822 table = bgp->rib[afi][safi];
9823
9824 output_count = 0;
9825
9826 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9827 PEER_STATUS_DEFAULT_ORIGINATE))
9828 {
9829 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 +00009830 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9831 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009832
9833 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9834 VTY_NEWLINE, VTY_NEWLINE);
9835 header1 = 0;
9836 }
9837
9838 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9839 if (in)
9840 {
9841 for (ain = rn->adj_in; ain; ain = ain->next)
9842 if (ain->peer == peer)
9843 {
9844 if (header1)
9845 {
9846 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 +00009847 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9848 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009849 header1 = 0;
9850 }
9851 if (header2)
9852 {
9853 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9854 header2 = 0;
9855 }
9856 if (ain->attr)
9857 {
9858 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9859 output_count++;
9860 }
9861 }
9862 }
9863 else
9864 {
9865 for (adj = rn->adj_out; adj; adj = adj->next)
9866 if (adj->peer == peer)
9867 {
9868 if (header1)
9869 {
9870 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 +00009871 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9872 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009873 header1 = 0;
9874 }
9875 if (header2)
9876 {
9877 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9878 header2 = 0;
9879 }
9880 if (adj->attr)
9881 {
9882 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9883 output_count++;
9884 }
9885 }
9886 }
9887
9888 if (output_count != 0)
9889 vty_out (vty, "%sTotal number of prefixes %ld%s",
9890 VTY_NEWLINE, output_count, VTY_NEWLINE);
9891}
9892
paul94f2b392005-06-28 12:44:16 +00009893static int
paulbb46e942003-10-24 19:02:03 +00009894peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9895{
paul718e3742002-12-13 20:15:29 +00009896 if (! peer || ! peer->afc[afi][safi])
9897 {
9898 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9899 return CMD_WARNING;
9900 }
9901
9902 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9903 {
9904 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9905 VTY_NEWLINE);
9906 return CMD_WARNING;
9907 }
9908
9909 show_adj_route (vty, peer, afi, safi, in);
9910
9911 return CMD_SUCCESS;
9912}
9913
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009914DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9915 show_ip_bgp_view_neighbor_advertised_route_cmd,
9916 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9917 SHOW_STR
9918 IP_STR
9919 BGP_STR
9920 "BGP view\n"
9921 "View name\n"
9922 "Detailed information on TCP and BGP neighbor connections\n"
9923 "Neighbor to display information about\n"
9924 "Neighbor to display information about\n"
9925 "Display the routes advertised to a BGP neighbor\n")
9926{
9927 struct peer *peer;
9928
9929 if (argc == 2)
9930 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9931 else
9932 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9933
9934 if (! peer)
9935 return CMD_WARNING;
9936
9937 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9938}
9939
9940ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009941 show_ip_bgp_neighbor_advertised_route_cmd,
9942 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9943 SHOW_STR
9944 IP_STR
9945 BGP_STR
9946 "Detailed information on TCP and BGP neighbor connections\n"
9947 "Neighbor to display information about\n"
9948 "Neighbor to display information about\n"
9949 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009950
9951DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9952 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9953 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9954 SHOW_STR
9955 IP_STR
9956 BGP_STR
9957 "Address family\n"
9958 "Address Family modifier\n"
9959 "Address Family modifier\n"
9960 "Detailed information on TCP and BGP neighbor connections\n"
9961 "Neighbor to display information about\n"
9962 "Neighbor to display information about\n"
9963 "Display the routes advertised to a BGP neighbor\n")
9964{
paulbb46e942003-10-24 19:02:03 +00009965 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009966
paulbb46e942003-10-24 19:02:03 +00009967 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9968 if (! peer)
9969 return CMD_WARNING;
9970
9971 if (strncmp (argv[0], "m", 1) == 0)
9972 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9973
9974 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009975}
9976
9977#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009978DEFUN (show_bgp_view_neighbor_advertised_route,
9979 show_bgp_view_neighbor_advertised_route_cmd,
9980 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9981 SHOW_STR
9982 BGP_STR
9983 "BGP view\n"
9984 "View name\n"
9985 "Detailed information on TCP and BGP neighbor connections\n"
9986 "Neighbor to display information about\n"
9987 "Neighbor to display information about\n"
9988 "Display the routes advertised to a BGP neighbor\n")
9989{
9990 struct peer *peer;
9991
9992 if (argc == 2)
9993 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9994 else
9995 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9996
9997 if (! peer)
9998 return CMD_WARNING;
9999
10000 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10001}
10002
10003ALIAS (show_bgp_view_neighbor_advertised_route,
10004 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10005 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10006 SHOW_STR
10007 BGP_STR
10008 "BGP view\n"
10009 "View name\n"
10010 "Address family\n"
10011 "Detailed information on TCP and BGP neighbor connections\n"
10012 "Neighbor to display information about\n"
10013 "Neighbor to display information about\n"
10014 "Display the routes advertised to a BGP neighbor\n")
10015
10016DEFUN (show_bgp_view_neighbor_received_routes,
10017 show_bgp_view_neighbor_received_routes_cmd,
10018 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10019 SHOW_STR
10020 BGP_STR
10021 "BGP view\n"
10022 "View name\n"
10023 "Detailed information on TCP and BGP neighbor connections\n"
10024 "Neighbor to display information about\n"
10025 "Neighbor to display information about\n"
10026 "Display the received routes from neighbor\n")
10027{
10028 struct peer *peer;
10029
10030 if (argc == 2)
10031 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10032 else
10033 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10034
10035 if (! peer)
10036 return CMD_WARNING;
10037
10038 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10039}
10040
10041ALIAS (show_bgp_view_neighbor_received_routes,
10042 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10043 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10044 SHOW_STR
10045 BGP_STR
10046 "BGP view\n"
10047 "View name\n"
10048 "Address family\n"
10049 "Detailed information on TCP and BGP neighbor connections\n"
10050 "Neighbor to display information about\n"
10051 "Neighbor to display information about\n"
10052 "Display the received routes from neighbor\n")
10053
10054ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010055 show_bgp_neighbor_advertised_route_cmd,
10056 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10057 SHOW_STR
10058 BGP_STR
10059 "Detailed information on TCP and BGP neighbor connections\n"
10060 "Neighbor to display information about\n"
10061 "Neighbor to display information about\n"
10062 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010063
10064ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010065 show_bgp_ipv6_neighbor_advertised_route_cmd,
10066 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10067 SHOW_STR
10068 BGP_STR
10069 "Address family\n"
10070 "Detailed information on TCP and BGP neighbor connections\n"
10071 "Neighbor to display information about\n"
10072 "Neighbor to display information about\n"
10073 "Display the routes advertised to a BGP neighbor\n")
10074
10075/* old command */
paulbb46e942003-10-24 19:02:03 +000010076ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010077 ipv6_bgp_neighbor_advertised_route_cmd,
10078 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10079 SHOW_STR
10080 IPV6_STR
10081 BGP_STR
10082 "Detailed information on TCP and BGP neighbor connections\n"
10083 "Neighbor to display information about\n"
10084 "Neighbor to display information about\n"
10085 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010086
paul718e3742002-12-13 20:15:29 +000010087/* old command */
10088DEFUN (ipv6_mbgp_neighbor_advertised_route,
10089 ipv6_mbgp_neighbor_advertised_route_cmd,
10090 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10091 SHOW_STR
10092 IPV6_STR
10093 MBGP_STR
10094 "Detailed information on TCP and BGP neighbor connections\n"
10095 "Neighbor to display information about\n"
10096 "Neighbor to display information about\n"
10097 "Display the routes advertised to a BGP neighbor\n")
10098{
paulbb46e942003-10-24 19:02:03 +000010099 struct peer *peer;
10100
10101 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10102 if (! peer)
10103 return CMD_WARNING;
10104
10105 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010106}
10107#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010108
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010109DEFUN (show_ip_bgp_view_neighbor_received_routes,
10110 show_ip_bgp_view_neighbor_received_routes_cmd,
10111 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10112 SHOW_STR
10113 IP_STR
10114 BGP_STR
10115 "BGP view\n"
10116 "View name\n"
10117 "Detailed information on TCP and BGP neighbor connections\n"
10118 "Neighbor to display information about\n"
10119 "Neighbor to display information about\n"
10120 "Display the received routes from neighbor\n")
10121{
10122 struct peer *peer;
10123
10124 if (argc == 2)
10125 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10126 else
10127 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10128
10129 if (! peer)
10130 return CMD_WARNING;
10131
10132 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10133}
10134
10135ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010136 show_ip_bgp_neighbor_received_routes_cmd,
10137 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10138 SHOW_STR
10139 IP_STR
10140 BGP_STR
10141 "Detailed information on TCP and BGP neighbor connections\n"
10142 "Neighbor to display information about\n"
10143 "Neighbor to display information about\n"
10144 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010145
10146DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10147 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10148 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10149 SHOW_STR
10150 IP_STR
10151 BGP_STR
10152 "Address family\n"
10153 "Address Family modifier\n"
10154 "Address Family modifier\n"
10155 "Detailed information on TCP and BGP neighbor connections\n"
10156 "Neighbor to display information about\n"
10157 "Neighbor to display information about\n"
10158 "Display the received routes from neighbor\n")
10159{
paulbb46e942003-10-24 19:02:03 +000010160 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010161
paulbb46e942003-10-24 19:02:03 +000010162 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10163 if (! peer)
10164 return CMD_WARNING;
10165
10166 if (strncmp (argv[0], "m", 1) == 0)
10167 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10168
10169 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010170}
10171
Michael Lambert95cbbd22010-07-23 14:43:04 -040010172DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10173 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010174 "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 -040010175 SHOW_STR
10176 BGP_STR
10177 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010178 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010179 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010180 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010181 "Address family modifier\n"
10182 "Address family modifier\n"
10183 "Detailed information on TCP and BGP neighbor connections\n"
10184 "Neighbor to display information about\n"
10185 "Neighbor to display information about\n"
10186 "Display the advertised routes to neighbor\n"
10187 "Display the received routes from neighbor\n")
10188{
10189 int afi;
10190 int safi;
10191 int in;
10192 struct peer *peer;
10193
David Lamparter94bad672015-03-03 08:52:22 +010010194 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010195
10196 if (! peer)
10197 return CMD_WARNING;
10198
Michael Lambert95cbbd22010-07-23 14:43:04 -040010199 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10200 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10201 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010202
10203 return peer_adj_routes (vty, peer, afi, safi, in);
10204}
10205
paul718e3742002-12-13 20:15:29 +000010206DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10207 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10208 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10209 SHOW_STR
10210 IP_STR
10211 BGP_STR
10212 "Detailed information on TCP and BGP neighbor connections\n"
10213 "Neighbor to display information about\n"
10214 "Neighbor to display information about\n"
10215 "Display information received from a BGP neighbor\n"
10216 "Display the prefixlist filter\n")
10217{
10218 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010219 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010220 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010221 int count, ret;
paul718e3742002-12-13 20:15:29 +000010222
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010223 ret = str2sockunion (argv[0], &su);
10224 if (ret < 0)
10225 {
10226 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10227 return CMD_WARNING;
10228 }
paul718e3742002-12-13 20:15:29 +000010229
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010230 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010231 if (! peer)
10232 return CMD_WARNING;
10233
10234 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10235 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10236 if (count)
10237 {
10238 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10239 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10240 }
10241
10242 return CMD_SUCCESS;
10243}
10244
10245DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10246 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10247 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10248 SHOW_STR
10249 IP_STR
10250 BGP_STR
10251 "Address family\n"
10252 "Address Family modifier\n"
10253 "Address Family modifier\n"
10254 "Detailed information on TCP and BGP neighbor connections\n"
10255 "Neighbor to display information about\n"
10256 "Neighbor to display information about\n"
10257 "Display information received from a BGP neighbor\n"
10258 "Display the prefixlist filter\n")
10259{
10260 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010261 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010262 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010263 int count, ret;
paul718e3742002-12-13 20:15:29 +000010264
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010265 ret = str2sockunion (argv[1], &su);
10266 if (ret < 0)
10267 {
10268 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10269 return CMD_WARNING;
10270 }
paul718e3742002-12-13 20:15:29 +000010271
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010272 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010273 if (! peer)
10274 return CMD_WARNING;
10275
10276 if (strncmp (argv[0], "m", 1) == 0)
10277 {
10278 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10279 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10280 if (count)
10281 {
10282 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10283 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10284 }
10285 }
10286 else
10287 {
10288 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10289 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10290 if (count)
10291 {
10292 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10293 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10294 }
10295 }
10296
10297 return CMD_SUCCESS;
10298}
10299
10300
10301#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010302ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010303 show_bgp_neighbor_received_routes_cmd,
10304 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10305 SHOW_STR
10306 BGP_STR
10307 "Detailed information on TCP and BGP neighbor connections\n"
10308 "Neighbor to display information about\n"
10309 "Neighbor to display information about\n"
10310 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010311
paulbb46e942003-10-24 19:02:03 +000010312ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010313 show_bgp_ipv6_neighbor_received_routes_cmd,
10314 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10315 SHOW_STR
10316 BGP_STR
10317 "Address family\n"
10318 "Detailed information on TCP and BGP neighbor connections\n"
10319 "Neighbor to display information about\n"
10320 "Neighbor to display information about\n"
10321 "Display the received routes from neighbor\n")
10322
10323DEFUN (show_bgp_neighbor_received_prefix_filter,
10324 show_bgp_neighbor_received_prefix_filter_cmd,
10325 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10326 SHOW_STR
10327 BGP_STR
10328 "Detailed information on TCP and BGP neighbor connections\n"
10329 "Neighbor to display information about\n"
10330 "Neighbor to display information about\n"
10331 "Display information received from a BGP neighbor\n"
10332 "Display the prefixlist filter\n")
10333{
10334 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010335 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010336 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010337 int count, ret;
paul718e3742002-12-13 20:15:29 +000010338
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010339 ret = str2sockunion (argv[0], &su);
10340 if (ret < 0)
10341 {
10342 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10343 return CMD_WARNING;
10344 }
paul718e3742002-12-13 20:15:29 +000010345
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010346 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010347 if (! peer)
10348 return CMD_WARNING;
10349
10350 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10351 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10352 if (count)
10353 {
10354 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10355 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10356 }
10357
10358 return CMD_SUCCESS;
10359}
10360
10361ALIAS (show_bgp_neighbor_received_prefix_filter,
10362 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10363 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10364 SHOW_STR
10365 BGP_STR
10366 "Address family\n"
10367 "Detailed information on TCP and BGP neighbor connections\n"
10368 "Neighbor to display information about\n"
10369 "Neighbor to display information about\n"
10370 "Display information received from a BGP neighbor\n"
10371 "Display the prefixlist filter\n")
10372
10373/* old command */
paulbb46e942003-10-24 19:02:03 +000010374ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010375 ipv6_bgp_neighbor_received_routes_cmd,
10376 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10377 SHOW_STR
10378 IPV6_STR
10379 BGP_STR
10380 "Detailed information on TCP and BGP neighbor connections\n"
10381 "Neighbor to display information about\n"
10382 "Neighbor to display information about\n"
10383 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010384
10385/* old command */
10386DEFUN (ipv6_mbgp_neighbor_received_routes,
10387 ipv6_mbgp_neighbor_received_routes_cmd,
10388 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10389 SHOW_STR
10390 IPV6_STR
10391 MBGP_STR
10392 "Detailed information on TCP and BGP neighbor connections\n"
10393 "Neighbor to display information about\n"
10394 "Neighbor to display information about\n"
10395 "Display the received routes from neighbor\n")
10396{
paulbb46e942003-10-24 19:02:03 +000010397 struct peer *peer;
10398
10399 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10400 if (! peer)
10401 return CMD_WARNING;
10402
10403 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010404}
paulbb46e942003-10-24 19:02:03 +000010405
10406DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10407 show_bgp_view_neighbor_received_prefix_filter_cmd,
10408 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10409 SHOW_STR
10410 BGP_STR
10411 "BGP view\n"
10412 "View name\n"
10413 "Detailed information on TCP and BGP neighbor connections\n"
10414 "Neighbor to display information about\n"
10415 "Neighbor to display information about\n"
10416 "Display information received from a BGP neighbor\n"
10417 "Display the prefixlist filter\n")
10418{
10419 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010420 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010421 struct peer *peer;
10422 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010423 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010424
10425 /* BGP structure lookup. */
10426 bgp = bgp_lookup_by_name (argv[0]);
10427 if (bgp == NULL)
10428 {
10429 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10430 return CMD_WARNING;
10431 }
10432
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010433 ret = str2sockunion (argv[1], &su);
10434 if (ret < 0)
10435 {
10436 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10437 return CMD_WARNING;
10438 }
paulbb46e942003-10-24 19:02:03 +000010439
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010440 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010441 if (! peer)
10442 return CMD_WARNING;
10443
10444 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10445 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10446 if (count)
10447 {
10448 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10449 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10450 }
10451
10452 return CMD_SUCCESS;
10453}
10454
10455ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10456 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10457 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10458 SHOW_STR
10459 BGP_STR
10460 "BGP view\n"
10461 "View name\n"
10462 "Address family\n"
10463 "Detailed information on TCP and BGP neighbor connections\n"
10464 "Neighbor to display information about\n"
10465 "Neighbor to display information about\n"
10466 "Display information received from a BGP neighbor\n"
10467 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010468#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010469
paul94f2b392005-06-28 12:44:16 +000010470static int
paulbb46e942003-10-24 19:02:03 +000010471bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010472 safi_t safi, enum bgp_show_type type)
10473{
paul718e3742002-12-13 20:15:29 +000010474 if (! peer || ! peer->afc[afi][safi])
10475 {
10476 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010477 return CMD_WARNING;
10478 }
10479
ajs5a646652004-11-05 01:25:55 +000010480 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010481}
10482
10483DEFUN (show_ip_bgp_neighbor_routes,
10484 show_ip_bgp_neighbor_routes_cmd,
10485 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10486 SHOW_STR
10487 IP_STR
10488 BGP_STR
10489 "Detailed information on TCP and BGP neighbor connections\n"
10490 "Neighbor to display information about\n"
10491 "Neighbor to display information about\n"
10492 "Display routes learned from neighbor\n")
10493{
paulbb46e942003-10-24 19:02:03 +000010494 struct peer *peer;
10495
10496 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10497 if (! peer)
10498 return CMD_WARNING;
10499
10500 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010501 bgp_show_type_neighbor);
10502}
10503
10504DEFUN (show_ip_bgp_neighbor_flap,
10505 show_ip_bgp_neighbor_flap_cmd,
10506 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10507 SHOW_STR
10508 IP_STR
10509 BGP_STR
10510 "Detailed information on TCP and BGP neighbor connections\n"
10511 "Neighbor to display information about\n"
10512 "Neighbor to display information about\n"
10513 "Display flap statistics of the routes learned from neighbor\n")
10514{
paulbb46e942003-10-24 19:02:03 +000010515 struct peer *peer;
10516
10517 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10518 if (! peer)
10519 return CMD_WARNING;
10520
10521 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010522 bgp_show_type_flap_neighbor);
10523}
10524
10525DEFUN (show_ip_bgp_neighbor_damp,
10526 show_ip_bgp_neighbor_damp_cmd,
10527 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10528 SHOW_STR
10529 IP_STR
10530 BGP_STR
10531 "Detailed information on TCP and BGP neighbor connections\n"
10532 "Neighbor to display information about\n"
10533 "Neighbor to display information about\n"
10534 "Display the dampened routes received from neighbor\n")
10535{
paulbb46e942003-10-24 19:02:03 +000010536 struct peer *peer;
10537
10538 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10539 if (! peer)
10540 return CMD_WARNING;
10541
10542 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010543 bgp_show_type_damp_neighbor);
10544}
10545
10546DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10547 show_ip_bgp_ipv4_neighbor_routes_cmd,
10548 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10549 SHOW_STR
10550 IP_STR
10551 BGP_STR
10552 "Address family\n"
10553 "Address Family modifier\n"
10554 "Address Family modifier\n"
10555 "Detailed information on TCP and BGP neighbor connections\n"
10556 "Neighbor to display information about\n"
10557 "Neighbor to display information about\n"
10558 "Display routes learned from neighbor\n")
10559{
paulbb46e942003-10-24 19:02:03 +000010560 struct peer *peer;
10561
10562 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10563 if (! peer)
10564 return CMD_WARNING;
10565
paul718e3742002-12-13 20:15:29 +000010566 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010567 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010568 bgp_show_type_neighbor);
10569
paulbb46e942003-10-24 19:02:03 +000010570 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010571 bgp_show_type_neighbor);
10572}
paulbb46e942003-10-24 19:02:03 +000010573
paulfee0f4c2004-09-13 05:12:46 +000010574DEFUN (show_ip_bgp_view_rsclient,
10575 show_ip_bgp_view_rsclient_cmd,
10576 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10577 SHOW_STR
10578 IP_STR
10579 BGP_STR
10580 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010581 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010582 "Information about Route Server Client\n"
10583 NEIGHBOR_ADDR_STR)
10584{
10585 struct bgp_table *table;
10586 struct peer *peer;
10587
10588 if (argc == 2)
10589 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10590 else
10591 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10592
10593 if (! peer)
10594 return CMD_WARNING;
10595
10596 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10597 {
10598 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10599 VTY_NEWLINE);
10600 return CMD_WARNING;
10601 }
10602
10603 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10604 PEER_FLAG_RSERVER_CLIENT))
10605 {
10606 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10607 VTY_NEWLINE);
10608 return CMD_WARNING;
10609 }
10610
10611 table = peer->rib[AFI_IP][SAFI_UNICAST];
10612
ajs5a646652004-11-05 01:25:55 +000010613 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010614}
10615
10616ALIAS (show_ip_bgp_view_rsclient,
10617 show_ip_bgp_rsclient_cmd,
10618 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10619 SHOW_STR
10620 IP_STR
10621 BGP_STR
10622 "Information about Route Server Client\n"
10623 NEIGHBOR_ADDR_STR)
10624
Michael Lambert95cbbd22010-07-23 14:43:04 -040010625DEFUN (show_bgp_view_ipv4_safi_rsclient,
10626 show_bgp_view_ipv4_safi_rsclient_cmd,
10627 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10628 SHOW_STR
10629 BGP_STR
10630 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010631 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010632 "Address family\n"
10633 "Address Family modifier\n"
10634 "Address Family modifier\n"
10635 "Information about Route Server Client\n"
10636 NEIGHBOR_ADDR_STR)
10637{
10638 struct bgp_table *table;
10639 struct peer *peer;
10640 safi_t safi;
10641
10642 if (argc == 3) {
10643 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10644 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10645 } else {
10646 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10647 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10648 }
10649
10650 if (! peer)
10651 return CMD_WARNING;
10652
10653 if (! peer->afc[AFI_IP][safi])
10654 {
10655 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10656 VTY_NEWLINE);
10657 return CMD_WARNING;
10658 }
10659
10660 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10661 PEER_FLAG_RSERVER_CLIENT))
10662 {
10663 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10664 VTY_NEWLINE);
10665 return CMD_WARNING;
10666 }
10667
10668 table = peer->rib[AFI_IP][safi];
10669
10670 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10671}
10672
10673ALIAS (show_bgp_view_ipv4_safi_rsclient,
10674 show_bgp_ipv4_safi_rsclient_cmd,
10675 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10676 SHOW_STR
10677 BGP_STR
10678 "Address family\n"
10679 "Address Family modifier\n"
10680 "Address Family modifier\n"
10681 "Information about Route Server Client\n"
10682 NEIGHBOR_ADDR_STR)
10683
paulfee0f4c2004-09-13 05:12:46 +000010684DEFUN (show_ip_bgp_view_rsclient_route,
10685 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010686 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010687 SHOW_STR
10688 IP_STR
10689 BGP_STR
10690 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010691 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010692 "Information about Route Server Client\n"
10693 NEIGHBOR_ADDR_STR
10694 "Network in the BGP routing table to display\n")
10695{
10696 struct bgp *bgp;
10697 struct peer *peer;
10698
10699 /* BGP structure lookup. */
10700 if (argc == 3)
10701 {
10702 bgp = bgp_lookup_by_name (argv[0]);
10703 if (bgp == NULL)
10704 {
10705 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10706 return CMD_WARNING;
10707 }
10708 }
10709 else
10710 {
10711 bgp = bgp_get_default ();
10712 if (bgp == NULL)
10713 {
10714 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10715 return CMD_WARNING;
10716 }
10717 }
10718
10719 if (argc == 3)
10720 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10721 else
10722 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10723
10724 if (! peer)
10725 return CMD_WARNING;
10726
10727 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10728 {
10729 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10730 VTY_NEWLINE);
10731 return CMD_WARNING;
10732}
10733
10734 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10735 PEER_FLAG_RSERVER_CLIENT))
10736 {
10737 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10738 VTY_NEWLINE);
10739 return CMD_WARNING;
10740 }
10741
10742 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10743 (argc == 3) ? argv[2] : argv[1],
10744 AFI_IP, SAFI_UNICAST, NULL, 0);
10745}
10746
10747ALIAS (show_ip_bgp_view_rsclient_route,
10748 show_ip_bgp_rsclient_route_cmd,
10749 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10750 SHOW_STR
10751 IP_STR
10752 BGP_STR
10753 "Information about Route Server Client\n"
10754 NEIGHBOR_ADDR_STR
10755 "Network in the BGP routing table to display\n")
10756
Michael Lambert95cbbd22010-07-23 14:43:04 -040010757DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10758 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10759 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10760 SHOW_STR
10761 BGP_STR
10762 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010763 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010764 "Address family\n"
10765 "Address Family modifier\n"
10766 "Address Family modifier\n"
10767 "Information about Route Server Client\n"
10768 NEIGHBOR_ADDR_STR
10769 "Network in the BGP routing table to display\n")
10770{
10771 struct bgp *bgp;
10772 struct peer *peer;
10773 safi_t safi;
10774
10775 /* BGP structure lookup. */
10776 if (argc == 4)
10777 {
10778 bgp = bgp_lookup_by_name (argv[0]);
10779 if (bgp == NULL)
10780 {
10781 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10782 return CMD_WARNING;
10783 }
10784 }
10785 else
10786 {
10787 bgp = bgp_get_default ();
10788 if (bgp == NULL)
10789 {
10790 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10791 return CMD_WARNING;
10792 }
10793 }
10794
10795 if (argc == 4) {
10796 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10797 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10798 } else {
10799 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10800 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10801 }
10802
10803 if (! peer)
10804 return CMD_WARNING;
10805
10806 if (! peer->afc[AFI_IP][safi])
10807 {
10808 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10809 VTY_NEWLINE);
10810 return CMD_WARNING;
10811}
10812
10813 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10814 PEER_FLAG_RSERVER_CLIENT))
10815 {
10816 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10817 VTY_NEWLINE);
10818 return CMD_WARNING;
10819 }
10820
10821 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10822 (argc == 4) ? argv[3] : argv[2],
10823 AFI_IP, safi, NULL, 0);
10824}
10825
10826ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10827 show_bgp_ipv4_safi_rsclient_route_cmd,
10828 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10829 SHOW_STR
10830 BGP_STR
10831 "Address family\n"
10832 "Address Family modifier\n"
10833 "Address Family modifier\n"
10834 "Information about Route Server Client\n"
10835 NEIGHBOR_ADDR_STR
10836 "Network in the BGP routing table to display\n")
10837
paulfee0f4c2004-09-13 05:12:46 +000010838DEFUN (show_ip_bgp_view_rsclient_prefix,
10839 show_ip_bgp_view_rsclient_prefix_cmd,
10840 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10841 SHOW_STR
10842 IP_STR
10843 BGP_STR
10844 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010845 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010846 "Information about Route Server Client\n"
10847 NEIGHBOR_ADDR_STR
10848 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10849{
10850 struct bgp *bgp;
10851 struct peer *peer;
10852
10853 /* BGP structure lookup. */
10854 if (argc == 3)
10855 {
10856 bgp = bgp_lookup_by_name (argv[0]);
10857 if (bgp == NULL)
10858 {
10859 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10860 return CMD_WARNING;
10861 }
10862 }
10863 else
10864 {
10865 bgp = bgp_get_default ();
10866 if (bgp == NULL)
10867 {
10868 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10869 return CMD_WARNING;
10870 }
10871 }
10872
10873 if (argc == 3)
10874 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10875 else
10876 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10877
10878 if (! peer)
10879 return CMD_WARNING;
10880
10881 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10882 {
10883 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10884 VTY_NEWLINE);
10885 return CMD_WARNING;
10886}
10887
10888 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10889 PEER_FLAG_RSERVER_CLIENT))
10890{
10891 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10892 VTY_NEWLINE);
10893 return CMD_WARNING;
10894 }
10895
10896 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10897 (argc == 3) ? argv[2] : argv[1],
10898 AFI_IP, SAFI_UNICAST, NULL, 1);
10899}
10900
10901ALIAS (show_ip_bgp_view_rsclient_prefix,
10902 show_ip_bgp_rsclient_prefix_cmd,
10903 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10904 SHOW_STR
10905 IP_STR
10906 BGP_STR
10907 "Information about Route Server Client\n"
10908 NEIGHBOR_ADDR_STR
10909 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10910
Michael Lambert95cbbd22010-07-23 14:43:04 -040010911DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10912 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10913 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10914 SHOW_STR
10915 BGP_STR
10916 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010917 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010918 "Address family\n"
10919 "Address Family modifier\n"
10920 "Address Family modifier\n"
10921 "Information about Route Server Client\n"
10922 NEIGHBOR_ADDR_STR
10923 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10924{
10925 struct bgp *bgp;
10926 struct peer *peer;
10927 safi_t safi;
10928
10929 /* BGP structure lookup. */
10930 if (argc == 4)
10931 {
10932 bgp = bgp_lookup_by_name (argv[0]);
10933 if (bgp == NULL)
10934 {
10935 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10936 return CMD_WARNING;
10937 }
10938 }
10939 else
10940 {
10941 bgp = bgp_get_default ();
10942 if (bgp == NULL)
10943 {
10944 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10945 return CMD_WARNING;
10946 }
10947 }
10948
10949 if (argc == 4) {
10950 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10951 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10952 } else {
10953 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10954 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10955 }
10956
10957 if (! peer)
10958 return CMD_WARNING;
10959
10960 if (! peer->afc[AFI_IP][safi])
10961 {
10962 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10963 VTY_NEWLINE);
10964 return CMD_WARNING;
10965}
10966
10967 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10968 PEER_FLAG_RSERVER_CLIENT))
10969{
10970 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10971 VTY_NEWLINE);
10972 return CMD_WARNING;
10973 }
10974
10975 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10976 (argc == 4) ? argv[3] : argv[2],
10977 AFI_IP, safi, NULL, 1);
10978}
10979
10980ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
10981 show_bgp_ipv4_safi_rsclient_prefix_cmd,
10982 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10983 SHOW_STR
10984 BGP_STR
10985 "Address family\n"
10986 "Address Family modifier\n"
10987 "Address Family modifier\n"
10988 "Information about Route Server Client\n"
10989 NEIGHBOR_ADDR_STR
10990 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000010991
paul718e3742002-12-13 20:15:29 +000010992#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010993DEFUN (show_bgp_view_neighbor_routes,
10994 show_bgp_view_neighbor_routes_cmd,
10995 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10996 SHOW_STR
10997 BGP_STR
10998 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010999 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011000 "Detailed information on TCP and BGP neighbor connections\n"
11001 "Neighbor to display information about\n"
11002 "Neighbor to display information about\n"
11003 "Display routes learned from neighbor\n")
11004{
11005 struct peer *peer;
11006
11007 if (argc == 2)
11008 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11009 else
11010 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11011
11012 if (! peer)
11013 return CMD_WARNING;
11014
11015 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11016 bgp_show_type_neighbor);
11017}
11018
11019ALIAS (show_bgp_view_neighbor_routes,
11020 show_bgp_view_ipv6_neighbor_routes_cmd,
11021 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11022 SHOW_STR
11023 BGP_STR
11024 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011025 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011026 "Address family\n"
11027 "Detailed information on TCP and BGP neighbor connections\n"
11028 "Neighbor to display information about\n"
11029 "Neighbor to display information about\n"
11030 "Display routes learned from neighbor\n")
11031
11032DEFUN (show_bgp_view_neighbor_damp,
11033 show_bgp_view_neighbor_damp_cmd,
11034 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11035 SHOW_STR
11036 BGP_STR
11037 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011038 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011039 "Detailed information on TCP and BGP neighbor connections\n"
11040 "Neighbor to display information about\n"
11041 "Neighbor to display information about\n"
11042 "Display the dampened routes received from neighbor\n")
11043{
11044 struct peer *peer;
11045
11046 if (argc == 2)
11047 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11048 else
11049 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11050
11051 if (! peer)
11052 return CMD_WARNING;
11053
11054 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11055 bgp_show_type_damp_neighbor);
11056}
11057
11058ALIAS (show_bgp_view_neighbor_damp,
11059 show_bgp_view_ipv6_neighbor_damp_cmd,
11060 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11061 SHOW_STR
11062 BGP_STR
11063 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011064 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011065 "Address family\n"
11066 "Detailed information on TCP and BGP neighbor connections\n"
11067 "Neighbor to display information about\n"
11068 "Neighbor to display information about\n"
11069 "Display the dampened routes received from neighbor\n")
11070
11071DEFUN (show_bgp_view_neighbor_flap,
11072 show_bgp_view_neighbor_flap_cmd,
11073 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11074 SHOW_STR
11075 BGP_STR
11076 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011077 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011078 "Detailed information on TCP and BGP neighbor connections\n"
11079 "Neighbor to display information about\n"
11080 "Neighbor to display information about\n"
11081 "Display flap statistics of the routes learned from neighbor\n")
11082{
11083 struct peer *peer;
11084
11085 if (argc == 2)
11086 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11087 else
11088 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11089
11090 if (! peer)
11091 return CMD_WARNING;
11092
11093 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11094 bgp_show_type_flap_neighbor);
11095}
11096
11097ALIAS (show_bgp_view_neighbor_flap,
11098 show_bgp_view_ipv6_neighbor_flap_cmd,
11099 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11100 SHOW_STR
11101 BGP_STR
11102 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011103 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011104 "Address family\n"
11105 "Detailed information on TCP and BGP neighbor connections\n"
11106 "Neighbor to display information about\n"
11107 "Neighbor to display information about\n"
11108 "Display flap statistics of the routes learned from neighbor\n")
11109
11110ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011111 show_bgp_neighbor_routes_cmd,
11112 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11113 SHOW_STR
11114 BGP_STR
11115 "Detailed information on TCP and BGP neighbor connections\n"
11116 "Neighbor to display information about\n"
11117 "Neighbor to display information about\n"
11118 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011119
paulbb46e942003-10-24 19:02:03 +000011120
11121ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011122 show_bgp_ipv6_neighbor_routes_cmd,
11123 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11124 SHOW_STR
11125 BGP_STR
11126 "Address family\n"
11127 "Detailed information on TCP and BGP neighbor connections\n"
11128 "Neighbor to display information about\n"
11129 "Neighbor to display information about\n"
11130 "Display routes learned from neighbor\n")
11131
11132/* old command */
paulbb46e942003-10-24 19:02:03 +000011133ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011134 ipv6_bgp_neighbor_routes_cmd,
11135 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11136 SHOW_STR
11137 IPV6_STR
11138 BGP_STR
11139 "Detailed information on TCP and BGP neighbor connections\n"
11140 "Neighbor to display information about\n"
11141 "Neighbor to display information about\n"
11142 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011143
11144/* old command */
11145DEFUN (ipv6_mbgp_neighbor_routes,
11146 ipv6_mbgp_neighbor_routes_cmd,
11147 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11148 SHOW_STR
11149 IPV6_STR
11150 MBGP_STR
11151 "Detailed information on TCP and BGP neighbor connections\n"
11152 "Neighbor to display information about\n"
11153 "Neighbor to display information about\n"
11154 "Display routes learned from neighbor\n")
11155{
paulbb46e942003-10-24 19:02:03 +000011156 struct peer *peer;
11157
11158 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11159 if (! peer)
11160 return CMD_WARNING;
11161
11162 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011163 bgp_show_type_neighbor);
11164}
paulbb46e942003-10-24 19:02:03 +000011165
11166ALIAS (show_bgp_view_neighbor_flap,
11167 show_bgp_neighbor_flap_cmd,
11168 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11169 SHOW_STR
11170 BGP_STR
11171 "Detailed information on TCP and BGP neighbor connections\n"
11172 "Neighbor to display information about\n"
11173 "Neighbor to display information about\n"
11174 "Display flap statistics of the routes learned from neighbor\n")
11175
11176ALIAS (show_bgp_view_neighbor_flap,
11177 show_bgp_ipv6_neighbor_flap_cmd,
11178 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11179 SHOW_STR
11180 BGP_STR
11181 "Address family\n"
11182 "Detailed information on TCP and BGP neighbor connections\n"
11183 "Neighbor to display information about\n"
11184 "Neighbor to display information about\n"
11185 "Display flap statistics of the routes learned from neighbor\n")
11186
11187ALIAS (show_bgp_view_neighbor_damp,
11188 show_bgp_neighbor_damp_cmd,
11189 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11190 SHOW_STR
11191 BGP_STR
11192 "Detailed information on TCP and BGP neighbor connections\n"
11193 "Neighbor to display information about\n"
11194 "Neighbor to display information about\n"
11195 "Display the dampened routes received from neighbor\n")
11196
11197ALIAS (show_bgp_view_neighbor_damp,
11198 show_bgp_ipv6_neighbor_damp_cmd,
11199 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11200 SHOW_STR
11201 BGP_STR
11202 "Address family\n"
11203 "Detailed information on TCP and BGP neighbor connections\n"
11204 "Neighbor to display information about\n"
11205 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011206 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011207
11208DEFUN (show_bgp_view_rsclient,
11209 show_bgp_view_rsclient_cmd,
11210 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11211 SHOW_STR
11212 BGP_STR
11213 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011214 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011215 "Information about Route Server Client\n"
11216 NEIGHBOR_ADDR_STR)
11217{
11218 struct bgp_table *table;
11219 struct peer *peer;
11220
11221 if (argc == 2)
11222 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11223 else
11224 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11225
11226 if (! peer)
11227 return CMD_WARNING;
11228
11229 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11230 {
11231 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11232 VTY_NEWLINE);
11233 return CMD_WARNING;
11234 }
11235
11236 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11237 PEER_FLAG_RSERVER_CLIENT))
11238 {
11239 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11240 VTY_NEWLINE);
11241 return CMD_WARNING;
11242 }
11243
11244 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11245
ajs5a646652004-11-05 01:25:55 +000011246 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011247}
11248
11249ALIAS (show_bgp_view_rsclient,
11250 show_bgp_rsclient_cmd,
11251 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11252 SHOW_STR
11253 BGP_STR
11254 "Information about Route Server Client\n"
11255 NEIGHBOR_ADDR_STR)
11256
Michael Lambert95cbbd22010-07-23 14:43:04 -040011257DEFUN (show_bgp_view_ipv6_safi_rsclient,
11258 show_bgp_view_ipv6_safi_rsclient_cmd,
11259 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11260 SHOW_STR
11261 BGP_STR
11262 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011263 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011264 "Address family\n"
11265 "Address Family modifier\n"
11266 "Address Family modifier\n"
11267 "Information about Route Server Client\n"
11268 NEIGHBOR_ADDR_STR)
11269{
11270 struct bgp_table *table;
11271 struct peer *peer;
11272 safi_t safi;
11273
11274 if (argc == 3) {
11275 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11276 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11277 } else {
11278 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11279 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11280 }
11281
11282 if (! peer)
11283 return CMD_WARNING;
11284
11285 if (! peer->afc[AFI_IP6][safi])
11286 {
11287 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11288 VTY_NEWLINE);
11289 return CMD_WARNING;
11290 }
11291
11292 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11293 PEER_FLAG_RSERVER_CLIENT))
11294 {
11295 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11296 VTY_NEWLINE);
11297 return CMD_WARNING;
11298 }
11299
11300 table = peer->rib[AFI_IP6][safi];
11301
11302 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11303}
11304
11305ALIAS (show_bgp_view_ipv6_safi_rsclient,
11306 show_bgp_ipv6_safi_rsclient_cmd,
11307 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11308 SHOW_STR
11309 BGP_STR
11310 "Address family\n"
11311 "Address Family modifier\n"
11312 "Address Family modifier\n"
11313 "Information about Route Server Client\n"
11314 NEIGHBOR_ADDR_STR)
11315
paulfee0f4c2004-09-13 05:12:46 +000011316DEFUN (show_bgp_view_rsclient_route,
11317 show_bgp_view_rsclient_route_cmd,
11318 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11319 SHOW_STR
11320 BGP_STR
11321 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011322 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011323 "Information about Route Server Client\n"
11324 NEIGHBOR_ADDR_STR
11325 "Network in the BGP routing table to display\n")
11326{
11327 struct bgp *bgp;
11328 struct peer *peer;
11329
11330 /* BGP structure lookup. */
11331 if (argc == 3)
11332 {
11333 bgp = bgp_lookup_by_name (argv[0]);
11334 if (bgp == NULL)
11335 {
11336 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11337 return CMD_WARNING;
11338 }
11339 }
11340 else
11341 {
11342 bgp = bgp_get_default ();
11343 if (bgp == NULL)
11344 {
11345 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11346 return CMD_WARNING;
11347 }
11348 }
11349
11350 if (argc == 3)
11351 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11352 else
11353 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11354
11355 if (! peer)
11356 return CMD_WARNING;
11357
11358 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11359 {
11360 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11361 VTY_NEWLINE);
11362 return CMD_WARNING;
11363 }
11364
11365 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11366 PEER_FLAG_RSERVER_CLIENT))
11367 {
11368 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11369 VTY_NEWLINE);
11370 return CMD_WARNING;
11371 }
11372
11373 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11374 (argc == 3) ? argv[2] : argv[1],
11375 AFI_IP6, SAFI_UNICAST, NULL, 0);
11376}
11377
11378ALIAS (show_bgp_view_rsclient_route,
11379 show_bgp_rsclient_route_cmd,
11380 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11381 SHOW_STR
11382 BGP_STR
11383 "Information about Route Server Client\n"
11384 NEIGHBOR_ADDR_STR
11385 "Network in the BGP routing table to display\n")
11386
Michael Lambert95cbbd22010-07-23 14:43:04 -040011387DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11388 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11389 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11390 SHOW_STR
11391 BGP_STR
11392 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011393 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011394 "Address family\n"
11395 "Address Family modifier\n"
11396 "Address Family modifier\n"
11397 "Information about Route Server Client\n"
11398 NEIGHBOR_ADDR_STR
11399 "Network in the BGP routing table to display\n")
11400{
11401 struct bgp *bgp;
11402 struct peer *peer;
11403 safi_t safi;
11404
11405 /* BGP structure lookup. */
11406 if (argc == 4)
11407 {
11408 bgp = bgp_lookup_by_name (argv[0]);
11409 if (bgp == NULL)
11410 {
11411 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11412 return CMD_WARNING;
11413 }
11414 }
11415 else
11416 {
11417 bgp = bgp_get_default ();
11418 if (bgp == NULL)
11419 {
11420 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11421 return CMD_WARNING;
11422 }
11423 }
11424
11425 if (argc == 4) {
11426 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11427 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11428 } else {
11429 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11430 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11431 }
11432
11433 if (! peer)
11434 return CMD_WARNING;
11435
11436 if (! peer->afc[AFI_IP6][safi])
11437 {
11438 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11439 VTY_NEWLINE);
11440 return CMD_WARNING;
11441}
11442
11443 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11444 PEER_FLAG_RSERVER_CLIENT))
11445 {
11446 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11447 VTY_NEWLINE);
11448 return CMD_WARNING;
11449 }
11450
11451 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11452 (argc == 4) ? argv[3] : argv[2],
11453 AFI_IP6, safi, NULL, 0);
11454}
11455
11456ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11457 show_bgp_ipv6_safi_rsclient_route_cmd,
11458 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11459 SHOW_STR
11460 BGP_STR
11461 "Address family\n"
11462 "Address Family modifier\n"
11463 "Address Family modifier\n"
11464 "Information about Route Server Client\n"
11465 NEIGHBOR_ADDR_STR
11466 "Network in the BGP routing table to display\n")
11467
paulfee0f4c2004-09-13 05:12:46 +000011468DEFUN (show_bgp_view_rsclient_prefix,
11469 show_bgp_view_rsclient_prefix_cmd,
11470 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11471 SHOW_STR
11472 BGP_STR
11473 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011474 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011475 "Information about Route Server Client\n"
11476 NEIGHBOR_ADDR_STR
11477 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11478{
11479 struct bgp *bgp;
11480 struct peer *peer;
11481
11482 /* BGP structure lookup. */
11483 if (argc == 3)
11484 {
11485 bgp = bgp_lookup_by_name (argv[0]);
11486 if (bgp == NULL)
11487 {
11488 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11489 return CMD_WARNING;
11490 }
11491 }
11492 else
11493 {
11494 bgp = bgp_get_default ();
11495 if (bgp == NULL)
11496 {
11497 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11498 return CMD_WARNING;
11499 }
11500 }
11501
11502 if (argc == 3)
11503 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11504 else
11505 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11506
11507 if (! peer)
11508 return CMD_WARNING;
11509
11510 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11511 {
11512 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11513 VTY_NEWLINE);
11514 return CMD_WARNING;
11515 }
11516
11517 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11518 PEER_FLAG_RSERVER_CLIENT))
11519 {
11520 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11521 VTY_NEWLINE);
11522 return CMD_WARNING;
11523 }
11524
11525 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11526 (argc == 3) ? argv[2] : argv[1],
11527 AFI_IP6, SAFI_UNICAST, NULL, 1);
11528}
11529
11530ALIAS (show_bgp_view_rsclient_prefix,
11531 show_bgp_rsclient_prefix_cmd,
11532 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11533 SHOW_STR
11534 BGP_STR
11535 "Information about Route Server Client\n"
11536 NEIGHBOR_ADDR_STR
11537 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11538
Michael Lambert95cbbd22010-07-23 14:43:04 -040011539DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11540 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11541 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11542 SHOW_STR
11543 BGP_STR
11544 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011545 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011546 "Address family\n"
11547 "Address Family modifier\n"
11548 "Address Family modifier\n"
11549 "Information about Route Server Client\n"
11550 NEIGHBOR_ADDR_STR
11551 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11552{
11553 struct bgp *bgp;
11554 struct peer *peer;
11555 safi_t safi;
11556
11557 /* BGP structure lookup. */
11558 if (argc == 4)
11559 {
11560 bgp = bgp_lookup_by_name (argv[0]);
11561 if (bgp == NULL)
11562 {
11563 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11564 return CMD_WARNING;
11565 }
11566 }
11567 else
11568 {
11569 bgp = bgp_get_default ();
11570 if (bgp == NULL)
11571 {
11572 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11573 return CMD_WARNING;
11574 }
11575 }
11576
11577 if (argc == 4) {
11578 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11579 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11580 } else {
11581 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11582 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11583 }
11584
11585 if (! peer)
11586 return CMD_WARNING;
11587
11588 if (! peer->afc[AFI_IP6][safi])
11589 {
11590 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11591 VTY_NEWLINE);
11592 return CMD_WARNING;
11593}
11594
11595 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11596 PEER_FLAG_RSERVER_CLIENT))
11597{
11598 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11599 VTY_NEWLINE);
11600 return CMD_WARNING;
11601 }
11602
11603 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11604 (argc == 4) ? argv[3] : argv[2],
11605 AFI_IP6, safi, NULL, 1);
11606}
11607
11608ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11609 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11610 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11611 SHOW_STR
11612 BGP_STR
11613 "Address family\n"
11614 "Address Family modifier\n"
11615 "Address Family modifier\n"
11616 "Information about Route Server Client\n"
11617 NEIGHBOR_ADDR_STR
11618 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11619
paul718e3742002-12-13 20:15:29 +000011620#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020011621
paul718e3742002-12-13 20:15:29 +000011622struct bgp_table *bgp_distance_table;
11623
11624struct bgp_distance
11625{
11626 /* Distance value for the IP source prefix. */
11627 u_char distance;
11628
11629 /* Name of the access-list to be matched. */
11630 char *access_list;
11631};
11632
paul94f2b392005-06-28 12:44:16 +000011633static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011634bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011635{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011636 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011637}
11638
paul94f2b392005-06-28 12:44:16 +000011639static void
paul718e3742002-12-13 20:15:29 +000011640bgp_distance_free (struct bgp_distance *bdistance)
11641{
11642 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11643}
11644
paul94f2b392005-06-28 12:44:16 +000011645static int
paulfd79ac92004-10-13 05:06:08 +000011646bgp_distance_set (struct vty *vty, const char *distance_str,
11647 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011648{
11649 int ret;
11650 struct prefix_ipv4 p;
11651 u_char distance;
11652 struct bgp_node *rn;
11653 struct bgp_distance *bdistance;
11654
11655 ret = str2prefix_ipv4 (ip_str, &p);
11656 if (ret == 0)
11657 {
11658 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11659 return CMD_WARNING;
11660 }
11661
11662 distance = atoi (distance_str);
11663
11664 /* Get BGP distance node. */
11665 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11666 if (rn->info)
11667 {
11668 bdistance = rn->info;
11669 bgp_unlock_node (rn);
11670 }
11671 else
11672 {
11673 bdistance = bgp_distance_new ();
11674 rn->info = bdistance;
11675 }
11676
11677 /* Set distance value. */
11678 bdistance->distance = distance;
11679
11680 /* Reset access-list configuration. */
11681 if (bdistance->access_list)
11682 {
11683 free (bdistance->access_list);
11684 bdistance->access_list = NULL;
11685 }
11686 if (access_list_str)
11687 bdistance->access_list = strdup (access_list_str);
11688
11689 return CMD_SUCCESS;
11690}
11691
paul94f2b392005-06-28 12:44:16 +000011692static int
paulfd79ac92004-10-13 05:06:08 +000011693bgp_distance_unset (struct vty *vty, const char *distance_str,
11694 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011695{
11696 int ret;
11697 struct prefix_ipv4 p;
11698 u_char distance;
11699 struct bgp_node *rn;
11700 struct bgp_distance *bdistance;
11701
11702 ret = str2prefix_ipv4 (ip_str, &p);
11703 if (ret == 0)
11704 {
11705 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11706 return CMD_WARNING;
11707 }
11708
11709 distance = atoi (distance_str);
11710
11711 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11712 if (! rn)
11713 {
11714 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11715 return CMD_WARNING;
11716 }
11717
11718 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010011719
11720 if (bdistance->distance != distance)
11721 {
11722 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
11723 return CMD_WARNING;
11724 }
11725
paul718e3742002-12-13 20:15:29 +000011726 if (bdistance->access_list)
11727 free (bdistance->access_list);
11728 bgp_distance_free (bdistance);
11729
11730 rn->info = NULL;
11731 bgp_unlock_node (rn);
11732 bgp_unlock_node (rn);
11733
11734 return CMD_SUCCESS;
11735}
11736
paul718e3742002-12-13 20:15:29 +000011737/* Apply BGP information to distance method. */
11738u_char
11739bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11740{
11741 struct bgp_node *rn;
11742 struct prefix_ipv4 q;
11743 struct peer *peer;
11744 struct bgp_distance *bdistance;
11745 struct access_list *alist;
11746 struct bgp_static *bgp_static;
11747
11748 if (! bgp)
11749 return 0;
11750
11751 if (p->family != AF_INET)
11752 return 0;
11753
11754 peer = rinfo->peer;
11755
11756 if (peer->su.sa.sa_family != AF_INET)
11757 return 0;
11758
11759 memset (&q, 0, sizeof (struct prefix_ipv4));
11760 q.family = AF_INET;
11761 q.prefix = peer->su.sin.sin_addr;
11762 q.prefixlen = IPV4_MAX_BITLEN;
11763
11764 /* Check source address. */
11765 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11766 if (rn)
11767 {
11768 bdistance = rn->info;
11769 bgp_unlock_node (rn);
11770
11771 if (bdistance->access_list)
11772 {
11773 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11774 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11775 return bdistance->distance;
11776 }
11777 else
11778 return bdistance->distance;
11779 }
11780
11781 /* Backdoor check. */
11782 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11783 if (rn)
11784 {
11785 bgp_static = rn->info;
11786 bgp_unlock_node (rn);
11787
11788 if (bgp_static->backdoor)
11789 {
11790 if (bgp->distance_local)
11791 return bgp->distance_local;
11792 else
11793 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11794 }
11795 }
11796
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011797 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011798 {
11799 if (bgp->distance_ebgp)
11800 return bgp->distance_ebgp;
11801 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11802 }
11803 else
11804 {
11805 if (bgp->distance_ibgp)
11806 return bgp->distance_ibgp;
11807 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11808 }
11809}
11810
11811DEFUN (bgp_distance,
11812 bgp_distance_cmd,
11813 "distance bgp <1-255> <1-255> <1-255>",
11814 "Define an administrative distance\n"
11815 "BGP distance\n"
11816 "Distance for routes external to the AS\n"
11817 "Distance for routes internal to the AS\n"
11818 "Distance for local routes\n")
11819{
11820 struct bgp *bgp;
11821
11822 bgp = vty->index;
11823
11824 bgp->distance_ebgp = atoi (argv[0]);
11825 bgp->distance_ibgp = atoi (argv[1]);
11826 bgp->distance_local = atoi (argv[2]);
11827 return CMD_SUCCESS;
11828}
11829
11830DEFUN (no_bgp_distance,
11831 no_bgp_distance_cmd,
11832 "no distance bgp <1-255> <1-255> <1-255>",
11833 NO_STR
11834 "Define an administrative distance\n"
11835 "BGP distance\n"
11836 "Distance for routes external to the AS\n"
11837 "Distance for routes internal to the AS\n"
11838 "Distance for local routes\n")
11839{
11840 struct bgp *bgp;
11841
11842 bgp = vty->index;
11843
11844 bgp->distance_ebgp= 0;
11845 bgp->distance_ibgp = 0;
11846 bgp->distance_local = 0;
11847 return CMD_SUCCESS;
11848}
11849
11850ALIAS (no_bgp_distance,
11851 no_bgp_distance2_cmd,
11852 "no distance bgp",
11853 NO_STR
11854 "Define an administrative distance\n"
11855 "BGP distance\n")
11856
11857DEFUN (bgp_distance_source,
11858 bgp_distance_source_cmd,
11859 "distance <1-255> A.B.C.D/M",
11860 "Define an administrative distance\n"
11861 "Administrative distance\n"
11862 "IP source prefix\n")
11863{
11864 bgp_distance_set (vty, argv[0], argv[1], NULL);
11865 return CMD_SUCCESS;
11866}
11867
11868DEFUN (no_bgp_distance_source,
11869 no_bgp_distance_source_cmd,
11870 "no distance <1-255> A.B.C.D/M",
11871 NO_STR
11872 "Define an administrative distance\n"
11873 "Administrative distance\n"
11874 "IP source prefix\n")
11875{
11876 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11877 return CMD_SUCCESS;
11878}
11879
11880DEFUN (bgp_distance_source_access_list,
11881 bgp_distance_source_access_list_cmd,
11882 "distance <1-255> A.B.C.D/M WORD",
11883 "Define an administrative distance\n"
11884 "Administrative distance\n"
11885 "IP source prefix\n"
11886 "Access list name\n")
11887{
11888 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11889 return CMD_SUCCESS;
11890}
11891
11892DEFUN (no_bgp_distance_source_access_list,
11893 no_bgp_distance_source_access_list_cmd,
11894 "no distance <1-255> A.B.C.D/M WORD",
11895 NO_STR
11896 "Define an administrative distance\n"
11897 "Administrative distance\n"
11898 "IP source prefix\n"
11899 "Access list name\n")
11900{
11901 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11902 return CMD_SUCCESS;
11903}
David Lamparter6b0655a2014-06-04 06:53:35 +020011904
paul718e3742002-12-13 20:15:29 +000011905DEFUN (bgp_damp_set,
11906 bgp_damp_set_cmd,
11907 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11908 "BGP Specific commands\n"
11909 "Enable route-flap dampening\n"
11910 "Half-life time for the penalty\n"
11911 "Value to start reusing a route\n"
11912 "Value to start suppressing a route\n"
11913 "Maximum duration to suppress a stable route\n")
11914{
11915 struct bgp *bgp;
11916 int half = DEFAULT_HALF_LIFE * 60;
11917 int reuse = DEFAULT_REUSE;
11918 int suppress = DEFAULT_SUPPRESS;
11919 int max = 4 * half;
11920
11921 if (argc == 4)
11922 {
11923 half = atoi (argv[0]) * 60;
11924 reuse = atoi (argv[1]);
11925 suppress = atoi (argv[2]);
11926 max = atoi (argv[3]) * 60;
11927 }
11928 else if (argc == 1)
11929 {
11930 half = atoi (argv[0]) * 60;
11931 max = 4 * half;
11932 }
11933
11934 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000011935
11936 if (suppress < reuse)
11937 {
11938 vty_out (vty, "Suppress value cannot be less than reuse value %s",
11939 VTY_NEWLINE);
11940 return 0;
11941 }
11942
paul718e3742002-12-13 20:15:29 +000011943 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11944 half, reuse, suppress, max);
11945}
11946
11947ALIAS (bgp_damp_set,
11948 bgp_damp_set2_cmd,
11949 "bgp dampening <1-45>",
11950 "BGP Specific commands\n"
11951 "Enable route-flap dampening\n"
11952 "Half-life time for the penalty\n")
11953
11954ALIAS (bgp_damp_set,
11955 bgp_damp_set3_cmd,
11956 "bgp dampening",
11957 "BGP Specific commands\n"
11958 "Enable route-flap dampening\n")
11959
11960DEFUN (bgp_damp_unset,
11961 bgp_damp_unset_cmd,
11962 "no bgp dampening",
11963 NO_STR
11964 "BGP Specific commands\n"
11965 "Enable route-flap dampening\n")
11966{
11967 struct bgp *bgp;
11968
11969 bgp = vty->index;
11970 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11971}
11972
11973ALIAS (bgp_damp_unset,
11974 bgp_damp_unset2_cmd,
11975 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11976 NO_STR
11977 "BGP Specific commands\n"
11978 "Enable route-flap dampening\n"
11979 "Half-life time for the penalty\n"
11980 "Value to start reusing a route\n"
11981 "Value to start suppressing a route\n"
11982 "Maximum duration to suppress a stable route\n")
11983
11984DEFUN (show_ip_bgp_dampened_paths,
11985 show_ip_bgp_dampened_paths_cmd,
11986 "show ip bgp dampened-paths",
11987 SHOW_STR
11988 IP_STR
11989 BGP_STR
11990 "Display paths suppressed due to dampening\n")
11991{
ajs5a646652004-11-05 01:25:55 +000011992 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11993 NULL);
paul718e3742002-12-13 20:15:29 +000011994}
11995
11996DEFUN (show_ip_bgp_flap_statistics,
11997 show_ip_bgp_flap_statistics_cmd,
11998 "show ip bgp flap-statistics",
11999 SHOW_STR
12000 IP_STR
12001 BGP_STR
12002 "Display flap statistics of routes\n")
12003{
ajs5a646652004-11-05 01:25:55 +000012004 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12005 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012006}
David Lamparter6b0655a2014-06-04 06:53:35 +020012007
paul718e3742002-12-13 20:15:29 +000012008/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012009static int
paulfd79ac92004-10-13 05:06:08 +000012010bgp_clear_damp_route (struct vty *vty, const char *view_name,
12011 const char *ip_str, afi_t afi, safi_t safi,
12012 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012013{
12014 int ret;
12015 struct prefix match;
12016 struct bgp_node *rn;
12017 struct bgp_node *rm;
12018 struct bgp_info *ri;
12019 struct bgp_info *ri_temp;
12020 struct bgp *bgp;
12021 struct bgp_table *table;
12022
12023 /* BGP structure lookup. */
12024 if (view_name)
12025 {
12026 bgp = bgp_lookup_by_name (view_name);
12027 if (bgp == NULL)
12028 {
12029 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12030 return CMD_WARNING;
12031 }
12032 }
12033 else
12034 {
12035 bgp = bgp_get_default ();
12036 if (bgp == NULL)
12037 {
12038 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12039 return CMD_WARNING;
12040 }
12041 }
12042
12043 /* Check IP address argument. */
12044 ret = str2prefix (ip_str, &match);
12045 if (! ret)
12046 {
12047 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12048 return CMD_WARNING;
12049 }
12050
12051 match.family = afi2family (afi);
12052
12053 if (safi == SAFI_MPLS_VPN)
12054 {
12055 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12056 {
12057 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12058 continue;
12059
12060 if ((table = rn->info) != NULL)
12061 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012062 {
12063 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12064 {
12065 ri = rm->info;
12066 while (ri)
12067 {
12068 if (ri->extra && ri->extra->damp_info)
12069 {
12070 ri_temp = ri->next;
12071 bgp_damp_info_free (ri->extra->damp_info, 1);
12072 ri = ri_temp;
12073 }
12074 else
12075 ri = ri->next;
12076 }
12077 }
12078
12079 bgp_unlock_node (rm);
12080 }
paul718e3742002-12-13 20:15:29 +000012081 }
12082 }
12083 else
12084 {
12085 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012086 {
12087 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12088 {
12089 ri = rn->info;
12090 while (ri)
12091 {
12092 if (ri->extra && ri->extra->damp_info)
12093 {
12094 ri_temp = ri->next;
12095 bgp_damp_info_free (ri->extra->damp_info, 1);
12096 ri = ri_temp;
12097 }
12098 else
12099 ri = ri->next;
12100 }
12101 }
12102
12103 bgp_unlock_node (rn);
12104 }
paul718e3742002-12-13 20:15:29 +000012105 }
12106
12107 return CMD_SUCCESS;
12108}
12109
12110DEFUN (clear_ip_bgp_dampening,
12111 clear_ip_bgp_dampening_cmd,
12112 "clear ip bgp dampening",
12113 CLEAR_STR
12114 IP_STR
12115 BGP_STR
12116 "Clear route flap dampening information\n")
12117{
12118 bgp_damp_info_clean ();
12119 return CMD_SUCCESS;
12120}
12121
12122DEFUN (clear_ip_bgp_dampening_prefix,
12123 clear_ip_bgp_dampening_prefix_cmd,
12124 "clear ip bgp dampening A.B.C.D/M",
12125 CLEAR_STR
12126 IP_STR
12127 BGP_STR
12128 "Clear route flap dampening information\n"
12129 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12130{
12131 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12132 SAFI_UNICAST, NULL, 1);
12133}
12134
12135DEFUN (clear_ip_bgp_dampening_address,
12136 clear_ip_bgp_dampening_address_cmd,
12137 "clear ip bgp dampening A.B.C.D",
12138 CLEAR_STR
12139 IP_STR
12140 BGP_STR
12141 "Clear route flap dampening information\n"
12142 "Network to clear damping information\n")
12143{
12144 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12145 SAFI_UNICAST, NULL, 0);
12146}
12147
12148DEFUN (clear_ip_bgp_dampening_address_mask,
12149 clear_ip_bgp_dampening_address_mask_cmd,
12150 "clear ip bgp dampening A.B.C.D A.B.C.D",
12151 CLEAR_STR
12152 IP_STR
12153 BGP_STR
12154 "Clear route flap dampening information\n"
12155 "Network to clear damping information\n"
12156 "Network mask\n")
12157{
12158 int ret;
12159 char prefix_str[BUFSIZ];
12160
12161 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12162 if (! ret)
12163 {
12164 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12165 return CMD_WARNING;
12166 }
12167
12168 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12169 SAFI_UNICAST, NULL, 0);
12170}
David Lamparter6b0655a2014-06-04 06:53:35 +020012171
paul94f2b392005-06-28 12:44:16 +000012172static int
paul718e3742002-12-13 20:15:29 +000012173bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12174 afi_t afi, safi_t safi, int *write)
12175{
12176 struct bgp_node *prn;
12177 struct bgp_node *rn;
12178 struct bgp_table *table;
12179 struct prefix *p;
12180 struct prefix_rd *prd;
12181 struct bgp_static *bgp_static;
12182 u_int32_t label;
12183 char buf[SU_ADDRSTRLEN];
12184 char rdbuf[RD_ADDRSTRLEN];
12185
12186 /* Network configuration. */
12187 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12188 if ((table = prn->info) != NULL)
12189 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12190 if ((bgp_static = rn->info) != NULL)
12191 {
12192 p = &rn->p;
12193 prd = (struct prefix_rd *) &prn->p;
12194
12195 /* "address-family" display. */
12196 bgp_config_write_family_header (vty, afi, safi, write);
12197
12198 /* "network" configuration display. */
12199 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12200 label = decode_label (bgp_static->tag);
12201
12202 vty_out (vty, " network %s/%d rd %s tag %d",
12203 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12204 p->prefixlen,
12205 rdbuf, label);
12206 vty_out (vty, "%s", VTY_NEWLINE);
12207 }
12208 return 0;
12209}
12210
12211/* Configuration of static route announcement and aggregate
12212 information. */
12213int
12214bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12215 afi_t afi, safi_t safi, int *write)
12216{
12217 struct bgp_node *rn;
12218 struct prefix *p;
12219 struct bgp_static *bgp_static;
12220 struct bgp_aggregate *bgp_aggregate;
12221 char buf[SU_ADDRSTRLEN];
12222
12223 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12224 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12225
12226 /* Network configuration. */
12227 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12228 if ((bgp_static = rn->info) != NULL)
12229 {
12230 p = &rn->p;
12231
12232 /* "address-family" display. */
12233 bgp_config_write_family_header (vty, afi, safi, write);
12234
12235 /* "network" configuration display. */
12236 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12237 {
12238 u_int32_t destination;
12239 struct in_addr netmask;
12240
12241 destination = ntohl (p->u.prefix4.s_addr);
12242 masklen2ip (p->prefixlen, &netmask);
12243 vty_out (vty, " network %s",
12244 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12245
12246 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12247 || (IN_CLASSB (destination) && p->prefixlen == 16)
12248 || (IN_CLASSA (destination) && p->prefixlen == 8)
12249 || p->u.prefix4.s_addr == 0)
12250 {
12251 /* Natural mask is not display. */
12252 }
12253 else
12254 vty_out (vty, " mask %s", inet_ntoa (netmask));
12255 }
12256 else
12257 {
12258 vty_out (vty, " network %s/%d",
12259 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12260 p->prefixlen);
12261 }
12262
12263 if (bgp_static->rmap.name)
12264 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012265 else
12266 {
12267 if (bgp_static->backdoor)
12268 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012269 }
paul718e3742002-12-13 20:15:29 +000012270
12271 vty_out (vty, "%s", VTY_NEWLINE);
12272 }
12273
12274 /* Aggregate-address configuration. */
12275 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12276 if ((bgp_aggregate = rn->info) != NULL)
12277 {
12278 p = &rn->p;
12279
12280 /* "address-family" display. */
12281 bgp_config_write_family_header (vty, afi, safi, write);
12282
12283 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12284 {
12285 struct in_addr netmask;
12286
12287 masklen2ip (p->prefixlen, &netmask);
12288 vty_out (vty, " aggregate-address %s %s",
12289 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12290 inet_ntoa (netmask));
12291 }
12292 else
12293 {
12294 vty_out (vty, " aggregate-address %s/%d",
12295 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12296 p->prefixlen);
12297 }
12298
12299 if (bgp_aggregate->as_set)
12300 vty_out (vty, " as-set");
12301
12302 if (bgp_aggregate->summary_only)
12303 vty_out (vty, " summary-only");
12304
12305 vty_out (vty, "%s", VTY_NEWLINE);
12306 }
12307
12308 return 0;
12309}
12310
12311int
12312bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12313{
12314 struct bgp_node *rn;
12315 struct bgp_distance *bdistance;
12316
12317 /* Distance configuration. */
12318 if (bgp->distance_ebgp
12319 && bgp->distance_ibgp
12320 && bgp->distance_local
12321 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12322 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12323 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12324 vty_out (vty, " distance bgp %d %d %d%s",
12325 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12326 VTY_NEWLINE);
12327
12328 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12329 if ((bdistance = rn->info) != NULL)
12330 {
12331 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12332 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12333 bdistance->access_list ? bdistance->access_list : "",
12334 VTY_NEWLINE);
12335 }
12336
12337 return 0;
12338}
12339
12340/* Allocate routing table structure and install commands. */
12341void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012342bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012343{
12344 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012345 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012346
12347 /* IPv4 BGP commands. */
12348 install_element (BGP_NODE, &bgp_network_cmd);
12349 install_element (BGP_NODE, &bgp_network_mask_cmd);
12350 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12351 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12352 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12353 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12354 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12355 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12356 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12357 install_element (BGP_NODE, &no_bgp_network_cmd);
12358 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12359 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12360 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12361 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12362 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12363 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12364 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12365 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12366
12367 install_element (BGP_NODE, &aggregate_address_cmd);
12368 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12369 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12370 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12371 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12372 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12373 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12374 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12375 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12376 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12377 install_element (BGP_NODE, &no_aggregate_address_cmd);
12378 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12379 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12380 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12381 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12382 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12383 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12384 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12385 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12386 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12387
12388 /* IPv4 unicast configuration. */
12389 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12390 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12391 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12392 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12393 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12394 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012395 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012396 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12397 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12398 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12399 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12400 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012401
paul718e3742002-12-13 20:15:29 +000012402 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12403 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12404 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12405 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12406 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12407 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12408 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12409 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12410 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12411 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12412 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12413 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12414 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12415 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12416 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12417 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12418 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12419 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12420 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12421 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12422
12423 /* IPv4 multicast configuration. */
12424 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12425 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12426 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12427 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12428 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12429 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12430 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12431 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12432 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12433 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12434 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12435 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12436 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12437 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12438 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12439 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12440 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12441 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12442 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12443 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12444 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12445 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12446 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12447 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12448 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12449 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12450 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12451 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12452 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12453 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12454 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12455 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12456
12457 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12458 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012459 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012460 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12461 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012462 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012463 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12464 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12465 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12466 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012467 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012468 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12469 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12470 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12471 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12472 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12473 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12474 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12475 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12476 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12477 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12478 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12479 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12480 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12481 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12482 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12483 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12484 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12485 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12486 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12487 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12488 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12489 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12490 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12491 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12492 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012493 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12494 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12495 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12496 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12497 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012498 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12499 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12500 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12501 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12502 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12503 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12504 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12505 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12506 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12507 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12508 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12509 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12510 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12511 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12512 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12513 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12514 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12515 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012516 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012517 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12518 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12519 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12520 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12521 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12522 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12523 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12524 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12525 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12526 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12527 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12528 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12529 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12530 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12531 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12532 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012533 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012534 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012535 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012536 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012537 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012538 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012539 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12540 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012541 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012542 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012543 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012544 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012545 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012546 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012547
12548 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12549 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12550 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012551 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012552 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12553 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12554 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012555 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012556 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12557 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12558 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12559 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12560 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12561 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12562 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12563 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12564 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12565 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12566 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12567 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012568 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12569 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12570 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12571 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12572 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012573 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12574 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12575 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12576 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12577 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12578 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12579 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12580 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12581 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012582 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012583 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012584 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012585 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012586 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012587 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012588 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012589
12590 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12591 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012592 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012593 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12594 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012595 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012596 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12597 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12598 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12599 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012600 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012601 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12602 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12603 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12604 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12605 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12606 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12607 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12608 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12609 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12610 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12611 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12612 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12613 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12614 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12615 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12616 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12617 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12618 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12619 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12620 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12621 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12622 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12623 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12624 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12625 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012626 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12627 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12628 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12629 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12630 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012631 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12632 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12633 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12634 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12635 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12636 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12637 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12638 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12639 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12640 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12641 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12642 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12643 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12644 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12645 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12646 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12647 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12648 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012649 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012650 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12651 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12652 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12653 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12654 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12655 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12656 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12657 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12658 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12659 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12660 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12661 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12662 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12663 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12664 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12665 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012666 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012667 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012668 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012669 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012670 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012671 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012672 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12673 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012674 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012675 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012676 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012677 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012678 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012679 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012680
12681 /* BGP dampening clear commands */
12682 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12683 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12684 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12685 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12686
Paul Jakmaff7924f2006-09-04 01:10:36 +000012687 /* prefix count */
12688 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12689 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12690 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012691#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012692 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12693
paul718e3742002-12-13 20:15:29 +000012694 /* New config IPv6 BGP commands. */
12695 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12696 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12697 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12698 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12699
12700 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12701 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12702 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12703 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12704
G.Balaji73bfe0b2011-09-23 22:36:20 +053012705 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12706 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12707
paul718e3742002-12-13 20:15:29 +000012708 /* Old config IPv6 BGP commands. */
12709 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12710 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12711
12712 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12713 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12714 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12715 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12716
12717 install_element (VIEW_NODE, &show_bgp_cmd);
12718 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012719 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012720 install_element (VIEW_NODE, &show_bgp_route_cmd);
12721 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012722 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012723 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12724 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012725 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012726 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12727 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12728 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12729 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12730 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12731 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12732 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12733 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12734 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12735 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12736 install_element (VIEW_NODE, &show_bgp_community_cmd);
12737 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12738 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12739 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12740 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12741 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12742 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12743 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12744 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12745 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12746 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12747 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12748 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12749 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12750 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12751 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12752 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12753 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12754 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12755 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12756 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12757 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12758 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12759 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12760 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12761 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12762 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12763 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12764 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12765 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012766 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12767 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12768 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12769 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012770 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012771 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012772 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012773 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012774 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012775 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012776 install_element (VIEW_NODE, &show_bgp_view_cmd);
12777 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12778 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12779 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12780 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12781 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12782 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12783 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12784 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12785 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12786 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12787 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12788 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12789 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12790 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12791 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12792 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12793 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012794 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012795 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012796 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012797 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012798 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012799 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012800
12801 /* Restricted:
12802 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12803 */
12804 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12805 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012806 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012807 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12808 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012809 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012810 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12811 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12812 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12813 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12814 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12815 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12816 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12817 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12818 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12819 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12820 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12821 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12822 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12823 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12824 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12825 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12826 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012827 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012828 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012829 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012830 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12831 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12832 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12833 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12834 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12835 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12836 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012837 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012838 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012839 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012840
12841 install_element (ENABLE_NODE, &show_bgp_cmd);
12842 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012843 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012844 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12845 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012846 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012847 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12848 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012849 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012850 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12851 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12852 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12853 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12854 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12855 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12856 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12857 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12858 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12859 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12860 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12861 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12862 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12863 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12864 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12865 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12866 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12867 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12868 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12869 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12870 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12871 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12872 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12873 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12874 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12875 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12876 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12877 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12878 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12879 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12880 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12881 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12882 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12883 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12884 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12885 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12886 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12887 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12888 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12889 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012890 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12891 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12892 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12893 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012894 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012895 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012896 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012897 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012898 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012899 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012900 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12901 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12902 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12903 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12904 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12905 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12906 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12907 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12908 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12909 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12910 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12911 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12912 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12913 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12914 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12915 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12916 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12917 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012918 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012919 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012920 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012921 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012922 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012923 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012924
12925 /* Statistics */
12926 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12927 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12928 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12929 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12930
paul718e3742002-12-13 20:15:29 +000012931 /* old command */
12932 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12933 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12934 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12935 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12936 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12937 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12938 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12939 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12940 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12941 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12942 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12943 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12944 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12945 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12946 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12947 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12948 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12949 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12950 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12951 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12952 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12953 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12954 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12955 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12956 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12957 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12958 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12959 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12960 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12961 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12962 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12963 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12964 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12965 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12966 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12967 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012968
paul718e3742002-12-13 20:15:29 +000012969 /* old command */
12970 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12971 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12972 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12973 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12974 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12975 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12976 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12977 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12978 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12979 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12980 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12981 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12982 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12983 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12984 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12985 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12986 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12987 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12988 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12989 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12990 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12991 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12992 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12993 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12994 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12995 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12996 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12997 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12998 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12999 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13000 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13001 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13002 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13003 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13004 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13005 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13006
13007 /* old command */
13008 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13009 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13010 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13011 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13012
13013 /* old command */
13014 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13015 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13016 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13017 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13018
13019 /* old command */
13020 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13021 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13022 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13023 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13024#endif /* HAVE_IPV6 */
13025
13026 install_element (BGP_NODE, &bgp_distance_cmd);
13027 install_element (BGP_NODE, &no_bgp_distance_cmd);
13028 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13029 install_element (BGP_NODE, &bgp_distance_source_cmd);
13030 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13031 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13032 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13033
13034 install_element (BGP_NODE, &bgp_damp_set_cmd);
13035 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13036 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13037 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13038 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13039 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13040 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13041 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13042 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13043 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013044
13045 /* Deprecated AS-Pathlimit commands */
13046 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13047 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13048 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13049 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13050 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13051 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13052
13053 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13054 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13055 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13056 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13057 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13058 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13059
13060 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13061 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13062 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13063 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13064 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13065 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13066
13067 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13068 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13069 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13070 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13071 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13072 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13073
13074 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13075 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13076 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13077 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13078 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13079 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13080
13081 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13082 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13083 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13084 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13085 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13086 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013087
13088#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013089 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13090 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013091#endif
paul718e3742002-12-13 20:15:29 +000013092}
Chris Caputo228da422009-07-18 05:44:03 +000013093
13094void
13095bgp_route_finish (void)
13096{
13097 bgp_table_unlock (bgp_distance_table);
13098 bgp_distance_table = NULL;
13099}