blob: 04cbb8ab8dfa41d3713290f7e4cdb175a33fb770 [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
1669 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1670 sizeof (struct work_queue *));
1671 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
paul200df112005-06-01 11:17:05 +00001672}
1673
1674void
paulfee0f4c2004-09-13 05:12:46 +00001675bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1676{
paul200df112005-06-01 11:17:05 +00001677 struct bgp_process_queue *pqnode;
1678
1679 /* already scheduled for processing? */
1680 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1681 return;
1682
1683 if ( (bm->process_main_queue == NULL) ||
1684 (bm->process_rsclient_queue == NULL) )
1685 bgp_process_queue_init ();
1686
1687 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1688 sizeof (struct bgp_process_queue));
1689 if (!pqnode)
1690 return;
Chris Caputo228da422009-07-18 05:44:03 +00001691
1692 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001693 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001694 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001695 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001696 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001697 pqnode->afi = afi;
1698 pqnode->safi = safi;
1699
Avneesh Sachdev67174042012-08-17 08:19:49 -07001700 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001701 {
paul200df112005-06-01 11:17:05 +00001702 case BGP_TABLE_MAIN:
1703 work_queue_add (bm->process_main_queue, pqnode);
1704 break;
1705 case BGP_TABLE_RSCLIENT:
1706 work_queue_add (bm->process_rsclient_queue, pqnode);
1707 break;
paulfee0f4c2004-09-13 05:12:46 +00001708 }
paul200df112005-06-01 11:17:05 +00001709
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001710 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001711 return;
paulfee0f4c2004-09-13 05:12:46 +00001712}
hasso0a486e52005-02-01 20:57:17 +00001713
paul94f2b392005-06-28 12:44:16 +00001714static int
hasso0a486e52005-02-01 20:57:17 +00001715bgp_maximum_prefix_restart_timer (struct thread *thread)
1716{
1717 struct peer *peer;
1718
1719 peer = THREAD_ARG (thread);
1720 peer->t_pmax_restart = NULL;
1721
1722 if (BGP_DEBUG (events, EVENTS))
1723 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1724 peer->host);
1725
1726 peer_clear (peer);
1727
1728 return 0;
1729}
1730
paulfee0f4c2004-09-13 05:12:46 +00001731int
paul5228ad22004-06-04 17:58:18 +00001732bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1733 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001734{
hassoe0701b72004-05-20 09:19:34 +00001735 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1736 return 0;
1737
1738 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001739 {
hassoe0701b72004-05-20 09:19:34 +00001740 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1741 && ! always)
1742 return 0;
paul718e3742002-12-13 20:15:29 +00001743
hassoe0701b72004-05-20 09:19:34 +00001744 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001745 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1746 "limit %ld", afi_safi_print (afi, safi), peer->host,
1747 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001748 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001749
hassoe0701b72004-05-20 09:19:34 +00001750 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1751 return 0;
paul718e3742002-12-13 20:15:29 +00001752
hassoe0701b72004-05-20 09:19:34 +00001753 {
paul5228ad22004-06-04 17:58:18 +00001754 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001755
1756 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001757 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001758
1759 ndata[0] = (afi >> 8);
1760 ndata[1] = afi;
1761 ndata[2] = safi;
1762 ndata[3] = (peer->pmax[afi][safi] >> 24);
1763 ndata[4] = (peer->pmax[afi][safi] >> 16);
1764 ndata[5] = (peer->pmax[afi][safi] >> 8);
1765 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001766
1767 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1768 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1769 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1770 }
hasso0a486e52005-02-01 20:57:17 +00001771
1772 /* restart timer start */
1773 if (peer->pmax_restart[afi][safi])
1774 {
1775 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1776
1777 if (BGP_DEBUG (events, EVENTS))
1778 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1779 peer->host, peer->v_pmax_restart);
1780
1781 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1782 peer->v_pmax_restart);
1783 }
1784
hassoe0701b72004-05-20 09:19:34 +00001785 return 1;
paul718e3742002-12-13 20:15:29 +00001786 }
hassoe0701b72004-05-20 09:19:34 +00001787 else
1788 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1789
1790 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1791 {
1792 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1793 && ! always)
1794 return 0;
1795
1796 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001797 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1798 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1799 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001800 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1801 }
1802 else
1803 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001804 return 0;
1805}
1806
paulb40d9392005-08-22 22:34:41 +00001807/* Unconditionally remove the route from the RIB, without taking
1808 * damping into consideration (eg, because the session went down)
1809 */
paul94f2b392005-06-28 12:44:16 +00001810static void
paul718e3742002-12-13 20:15:29 +00001811bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1812 afi_t afi, safi_t safi)
1813{
paul902212c2006-02-05 17:51:19 +00001814 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1815
1816 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1817 bgp_info_delete (rn, ri); /* keep historical info */
1818
paulb40d9392005-08-22 22:34:41 +00001819 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001820}
1821
paul94f2b392005-06-28 12:44:16 +00001822static void
paul718e3742002-12-13 20:15:29 +00001823bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001824 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001825{
paul718e3742002-12-13 20:15:29 +00001826 int status = BGP_DAMP_NONE;
1827
paulb40d9392005-08-22 22:34:41 +00001828 /* apply dampening, if result is suppressed, we'll be retaining
1829 * the bgp_info in the RIB for historical reference.
1830 */
1831 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001832 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001833 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1834 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001835 {
paul902212c2006-02-05 17:51:19 +00001836 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1837 return;
1838 }
1839
1840 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001841}
1842
paul94f2b392005-06-28 12:44:16 +00001843static void
paulfee0f4c2004-09-13 05:12:46 +00001844bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1845 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1846 int sub_type, struct prefix_rd *prd, u_char *tag)
1847{
1848 struct bgp_node *rn;
1849 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001850 struct attr new_attr;
1851 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001852 struct attr *attr_new;
1853 struct attr *attr_new2;
1854 struct bgp_info *ri;
1855 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001856 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001857 char buf[SU_ADDRSTRLEN];
1858
1859 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1860 if (peer == rsclient)
1861 return;
1862
1863 bgp = peer->bgp;
1864 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1865
1866 /* Check previously received route. */
1867 for (ri = rn->info; ri; ri = ri->next)
1868 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1869 break;
1870
1871 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001872 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001873 {
1874 reason = "as-path contains our own AS;";
1875 goto filtered;
1876 }
1877
1878 /* Route reflector originator ID check. */
1879 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001880 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001881 {
1882 reason = "originator is us;";
1883 goto filtered;
1884 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001885
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001886 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001887 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001888
1889 /* Apply export policy. */
1890 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1891 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1892 {
1893 reason = "export-policy;";
1894 goto filtered;
1895 }
1896
1897 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001898
paulfee0f4c2004-09-13 05:12:46 +00001899 /* Apply import policy. */
1900 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1901 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001902 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001903
1904 reason = "import-policy;";
1905 goto filtered;
1906 }
1907
1908 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001909 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001910
1911 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001912 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001913 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001914 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001915 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001916 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001917 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001918 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001919
1920 reason = "martian next-hop;";
1921 goto filtered;
1922 }
1923 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001924
paulfee0f4c2004-09-13 05:12:46 +00001925 /* If the update is implicit withdraw. */
1926 if (ri)
1927 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001928 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001929
1930 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001931 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1932 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001933 {
1934
Paul Jakma1a392d42006-09-07 00:24:49 +00001935 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001936
1937 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001938 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001939 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1940 peer->host,
1941 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1942 p->prefixlen, rsclient->host);
1943
Chris Caputo228da422009-07-18 05:44:03 +00001944 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001945 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001946
Chris Caputo228da422009-07-18 05:44:03 +00001947 return;
paulfee0f4c2004-09-13 05:12:46 +00001948 }
1949
Paul Jakma16d2e242007-04-10 19:32:10 +00001950 /* Withdraw/Announce before we fully processed the withdraw */
1951 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1952 bgp_info_restore (rn, ri);
1953
paulfee0f4c2004-09-13 05:12:46 +00001954 /* Received Logging. */
1955 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001956 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001957 peer->host,
1958 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1959 p->prefixlen, rsclient->host);
1960
1961 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001962 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001963
1964 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001965 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001966 ri->attr = attr_new;
1967
1968 /* Update MPLS tag. */
1969 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001970 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001971
Paul Jakma1a392d42006-09-07 00:24:49 +00001972 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001973
1974 /* Process change. */
1975 bgp_process (bgp, rn, afi, safi);
1976 bgp_unlock_node (rn);
1977
1978 return;
1979 }
1980
1981 /* Received Logging. */
1982 if (BGP_DEBUG (update, UPDATE_IN))
1983 {
ajsd2c1f162004-12-08 21:10:20 +00001984 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001985 peer->host,
1986 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1987 p->prefixlen, rsclient->host);
1988 }
1989
1990 /* Make new BGP info. */
1991 new = bgp_info_new ();
1992 new->type = type;
1993 new->sub_type = sub_type;
1994 new->peer = peer;
1995 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03001996 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001997
1998 /* Update MPLS tag. */
1999 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002000 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002001
Paul Jakma1a392d42006-09-07 00:24:49 +00002002 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002003
2004 /* Register new BGP information. */
2005 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002006
2007 /* route_node_get lock */
2008 bgp_unlock_node (rn);
2009
paulfee0f4c2004-09-13 05:12:46 +00002010 /* Process change. */
2011 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002012
paulfee0f4c2004-09-13 05:12:46 +00002013 return;
2014
2015 filtered:
2016
2017 /* This BGP update is filtered. Log the reason then update BGP entry. */
2018 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002019 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002020 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2021 peer->host,
2022 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2023 p->prefixlen, rsclient->host, reason);
2024
2025 if (ri)
paulb40d9392005-08-22 22:34:41 +00002026 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002027
2028 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002029
paulfee0f4c2004-09-13 05:12:46 +00002030 return;
2031}
2032
paul94f2b392005-06-28 12:44:16 +00002033static void
paulfee0f4c2004-09-13 05:12:46 +00002034bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2035 struct peer *peer, struct prefix *p, int type, int sub_type,
2036 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002037{
paulfee0f4c2004-09-13 05:12:46 +00002038 struct bgp_node *rn;
2039 struct bgp_info *ri;
2040 char buf[SU_ADDRSTRLEN];
2041
2042 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002043 return;
paulfee0f4c2004-09-13 05:12:46 +00002044
2045 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2046
2047 /* Lookup withdrawn route. */
2048 for (ri = rn->info; ri; ri = ri->next)
2049 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2050 break;
2051
2052 /* Withdraw specified route from routing table. */
2053 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002054 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002055 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002056 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002057 "%s Can't find the route %s/%d", peer->host,
2058 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2059 p->prefixlen);
2060
2061 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002062 bgp_unlock_node (rn);
2063}
paulfee0f4c2004-09-13 05:12:46 +00002064
paul94f2b392005-06-28 12:44:16 +00002065static int
paulfee0f4c2004-09-13 05:12:46 +00002066bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002067 afi_t afi, safi_t safi, int type, int sub_type,
2068 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2069{
2070 int ret;
2071 int aspath_loop_count = 0;
2072 struct bgp_node *rn;
2073 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002074 struct attr new_attr;
2075 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002076 struct attr *attr_new;
2077 struct bgp_info *ri;
2078 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002079 const char *reason;
paul718e3742002-12-13 20:15:29 +00002080 char buf[SU_ADDRSTRLEN];
2081
2082 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002083 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002084
paul718e3742002-12-13 20:15:29 +00002085 /* When peer's soft reconfiguration enabled. Record input packet in
2086 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002087 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2088 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002089 bgp_adj_in_set (rn, peer, attr);
2090
2091 /* Check previously received route. */
2092 for (ri = rn->info; ri; ri = ri->next)
2093 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2094 break;
2095
2096 /* AS path local-as loop check. */
2097 if (peer->change_local_as)
2098 {
2099 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2100 aspath_loop_count = 1;
2101
2102 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2103 {
2104 reason = "as-path contains our own AS;";
2105 goto filtered;
2106 }
2107 }
2108
2109 /* AS path loop check. */
2110 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2111 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2112 && aspath_loop_check(attr->aspath, bgp->confed_id)
2113 > peer->allowas_in[afi][safi]))
2114 {
2115 reason = "as-path contains our own AS;";
2116 goto filtered;
2117 }
2118
2119 /* Route reflector originator ID check. */
2120 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002121 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002122 {
2123 reason = "originator is us;";
2124 goto filtered;
2125 }
2126
2127 /* Route reflector cluster ID check. */
2128 if (bgp_cluster_filter (peer, attr))
2129 {
2130 reason = "reflected from the same cluster;";
2131 goto filtered;
2132 }
2133
2134 /* Apply incoming filter. */
2135 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2136 {
2137 reason = "filter;";
2138 goto filtered;
2139 }
2140
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002141 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002142 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002143
David Lamparterc460e572014-06-04 00:54:58 +02002144 /* Apply incoming route-map.
2145 * NB: new_attr may now contain newly allocated values from route-map "set"
2146 * commands, so we need bgp_attr_flush in the error paths, until we intern
2147 * the attr (which takes over the memory references) */
paul718e3742002-12-13 20:15:29 +00002148 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2149 {
2150 reason = "route-map;";
David Lamparterc460e572014-06-04 00:54:58 +02002151 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002152 goto filtered;
2153 }
2154
2155 /* IPv4 unicast next hop check. */
2156 if (afi == AFI_IP && safi == SAFI_UNICAST)
2157 {
2158 /* If the peer is EBGP and nexthop is not on connected route,
2159 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002160 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002161 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002162 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002163 {
2164 reason = "non-connected next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002165 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002166 goto filtered;
2167 }
2168
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002169 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002170 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002171 if (new_attr.nexthop.s_addr == 0
2172 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2173 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002174 {
2175 reason = "martian next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002176 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002177 goto filtered;
2178 }
2179 }
2180
2181 attr_new = bgp_attr_intern (&new_attr);
2182
2183 /* If the update is implicit withdraw. */
2184 if (ri)
2185 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002186 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002187
2188 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002189 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2190 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002191 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002192 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002193
2194 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002195 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002196 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2197 {
2198 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002199 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002200 peer->host,
2201 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2202 p->prefixlen);
2203
paul902212c2006-02-05 17:51:19 +00002204 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2205 {
2206 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2207 bgp_process (bgp, rn, afi, safi);
2208 }
paul718e3742002-12-13 20:15:29 +00002209 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002210 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002211 {
2212 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002213 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002214 "%s rcvd %s/%d...duplicate ignored",
2215 peer->host,
2216 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2217 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002218
2219 /* graceful restart STALE flag unset. */
2220 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2221 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002222 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002223 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002224 }
paul718e3742002-12-13 20:15:29 +00002225 }
2226
2227 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002228 bgp_attr_unintern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002229
paul718e3742002-12-13 20:15:29 +00002230 return 0;
2231 }
2232
Paul Jakma16d2e242007-04-10 19:32:10 +00002233 /* Withdraw/Announce before we fully processed the withdraw */
2234 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2235 {
2236 if (BGP_DEBUG (update, UPDATE_IN))
2237 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2238 peer->host,
2239 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2240 p->prefixlen);
2241 bgp_info_restore (rn, ri);
2242 }
2243
paul718e3742002-12-13 20:15:29 +00002244 /* Received Logging. */
2245 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002246 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002247 peer->host,
2248 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2249 p->prefixlen);
2250
hasso93406d82005-02-02 14:40:33 +00002251 /* graceful restart STALE flag unset. */
2252 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002253 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002254
paul718e3742002-12-13 20:15:29 +00002255 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002256 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002257
2258 /* implicit withdraw, decrement aggregate and pcount here.
2259 * only if update is accepted, they'll increment below.
2260 */
paul902212c2006-02-05 17:51:19 +00002261 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2262
paul718e3742002-12-13 20:15:29 +00002263 /* Update bgp route dampening information. */
2264 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002265 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002266 {
2267 /* This is implicit withdraw so we should update dampening
2268 information. */
2269 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2270 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002271 }
2272
paul718e3742002-12-13 20:15:29 +00002273 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002274 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002275 ri->attr = attr_new;
2276
2277 /* Update MPLS tag. */
2278 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002279 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002280
2281 /* Update bgp route dampening information. */
2282 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002283 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002284 {
2285 /* Now we do normal update dampening. */
2286 ret = bgp_damp_update (ri, rn, afi, safi);
2287 if (ret == BGP_DAMP_SUPPRESSED)
2288 {
2289 bgp_unlock_node (rn);
2290 return 0;
2291 }
2292 }
2293
2294 /* Nexthop reachability check. */
2295 if ((afi == AFI_IP || afi == AFI_IP6)
2296 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002297 && (peer->sort == BGP_PEER_IBGP
2298 || peer->sort == BGP_PEER_CONFED
2299 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002300 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002301 {
2302 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002303 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002304 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002305 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002306 }
2307 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002308 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002309
2310 /* Process change. */
2311 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2312
2313 bgp_process (bgp, rn, afi, safi);
2314 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002315
paul718e3742002-12-13 20:15:29 +00002316 return 0;
2317 }
2318
2319 /* Received Logging. */
2320 if (BGP_DEBUG (update, UPDATE_IN))
2321 {
ajsd2c1f162004-12-08 21:10:20 +00002322 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002323 peer->host,
2324 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2325 p->prefixlen);
2326 }
2327
paul718e3742002-12-13 20:15:29 +00002328 /* Make new BGP info. */
2329 new = bgp_info_new ();
2330 new->type = type;
2331 new->sub_type = sub_type;
2332 new->peer = peer;
2333 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002334 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002335
2336 /* Update MPLS tag. */
2337 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002338 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002339
2340 /* Nexthop reachability check. */
2341 if ((afi == AFI_IP || afi == AFI_IP6)
2342 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002343 && (peer->sort == BGP_PEER_IBGP
2344 || peer->sort == BGP_PEER_CONFED
2345 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002346 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002347 {
2348 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002349 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002350 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002351 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002352 }
2353 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002354 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002355
paul902212c2006-02-05 17:51:19 +00002356 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002357 bgp_aggregate_increment (bgp, p, new, afi, safi);
2358
2359 /* Register new BGP information. */
2360 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002361
2362 /* route_node_get lock */
2363 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002364
paul718e3742002-12-13 20:15:29 +00002365 /* If maximum prefix count is configured and current prefix
2366 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002367 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2368 return -1;
paul718e3742002-12-13 20:15:29 +00002369
2370 /* Process change. */
2371 bgp_process (bgp, rn, afi, safi);
2372
2373 return 0;
2374
2375 /* This BGP update is filtered. Log the reason then update BGP
2376 entry. */
2377 filtered:
2378 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002379 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002380 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2381 peer->host,
2382 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2383 p->prefixlen, reason);
2384
2385 if (ri)
paulb40d9392005-08-22 22:34:41 +00002386 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002387
2388 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002389
paul718e3742002-12-13 20:15:29 +00002390 return 0;
2391}
2392
2393int
paulfee0f4c2004-09-13 05:12:46 +00002394bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2395 afi_t afi, safi_t safi, int type, int sub_type,
2396 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2397{
2398 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002399 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002400 struct bgp *bgp;
2401 int ret;
2402
2403 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2404 soft_reconfig);
2405
2406 bgp = peer->bgp;
2407
2408 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002409 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002410 {
2411 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2412 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2413 sub_type, prd, tag);
2414 }
2415
2416 return ret;
2417}
2418
2419int
paul718e3742002-12-13 20:15:29 +00002420bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002421 afi_t afi, safi_t safi, int type, int sub_type,
2422 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002423{
2424 struct bgp *bgp;
2425 char buf[SU_ADDRSTRLEN];
2426 struct bgp_node *rn;
2427 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002428 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002429 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002430
2431 bgp = peer->bgp;
2432
paulfee0f4c2004-09-13 05:12:46 +00002433 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002434 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002435 {
2436 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2437 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2438 }
2439
paul718e3742002-12-13 20:15:29 +00002440 /* Logging. */
2441 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002442 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002443 peer->host,
2444 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2445 p->prefixlen);
2446
2447 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002448 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002449
2450 /* If peer is soft reconfiguration enabled. Record input packet for
2451 further calculation. */
2452 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2453 && peer != bgp->peer_self)
2454 bgp_adj_in_unset (rn, peer);
2455
2456 /* Lookup withdrawn route. */
2457 for (ri = rn->info; ri; ri = ri->next)
2458 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2459 break;
2460
2461 /* Withdraw specified route from routing table. */
2462 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002463 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002464 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002465 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002466 "%s Can't find the route %s/%d", peer->host,
2467 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2468 p->prefixlen);
2469
2470 /* Unlock bgp_node_get() lock. */
2471 bgp_unlock_node (rn);
2472
2473 return 0;
2474}
David Lamparter6b0655a2014-06-04 06:53:35 +02002475
paul718e3742002-12-13 20:15:29 +00002476void
2477bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2478{
2479 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002480 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002481 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002482 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002483 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002484 struct bgp_node *rn;
2485 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002486 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002487
Paul Jakmab2497022007-06-14 11:17:58 +00002488 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002489 return;
2490
paul718e3742002-12-13 20:15:29 +00002491 bgp = peer->bgp;
2492 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002493
paul718e3742002-12-13 20:15:29 +00002494 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2495 aspath = attr.aspath;
2496 attr.local_pref = bgp->default_local_pref;
2497 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2498
2499 if (afi == AFI_IP)
2500 str2prefix ("0.0.0.0/0", &p);
2501#ifdef HAVE_IPV6
2502 else if (afi == AFI_IP6)
2503 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002504 struct attr_extra *ae = attr.extra;
2505
paul718e3742002-12-13 20:15:29 +00002506 str2prefix ("::/0", &p);
2507
2508 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002509 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002510 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002511 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002512
2513 /* If the peer is on shared nextwork and we have link-local
2514 nexthop set it. */
2515 if (peer->shared_network
2516 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2517 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002518 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002519 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002520 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002521 }
2522 }
2523#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002524
2525 if (peer->default_rmap[afi][safi].name)
2526 {
paulfee0f4c2004-09-13 05:12:46 +00002527 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002528 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2529 {
2530 for (ri = rn->info; ri; ri = ri->next)
2531 {
2532 struct attr dummy_attr;
2533 struct attr_extra dummy_extra;
2534 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002535
Christian Frankedcab1bb2012-12-07 16:45:52 +00002536 /* Provide dummy so the route-map can't modify the attributes */
2537 dummy_attr.extra = &dummy_extra;
2538 bgp_attr_dup(&dummy_attr, ri->attr);
2539 info.peer = ri->peer;
2540 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002541
Christian Frankedcab1bb2012-12-07 16:45:52 +00002542 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2543 RMAP_BGP, &info);
2544
2545 /* The route map might have set attributes. If we don't flush them
2546 * here, they will be leaked. */
2547 bgp_attr_flush(&dummy_attr);
2548 if (ret != RMAP_DENYMATCH)
2549 break;
2550 }
2551 if (ret != RMAP_DENYMATCH)
2552 break;
2553 }
paulfee0f4c2004-09-13 05:12:46 +00002554 bgp->peer_self->rmap_type = 0;
2555
paul718e3742002-12-13 20:15:29 +00002556 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002557 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002558 }
2559
2560 if (withdraw)
2561 {
2562 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2563 bgp_default_withdraw_send (peer, afi, safi);
2564 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2565 }
2566 else
2567 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002568 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2569 {
2570 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2571 bgp_default_update_send (peer, &attr, afi, safi, from);
2572 }
paul718e3742002-12-13 20:15:29 +00002573 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002574
2575 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002576 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002577}
David Lamparter6b0655a2014-06-04 06:53:35 +02002578
paul718e3742002-12-13 20:15:29 +00002579static void
2580bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002581 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002582{
2583 struct bgp_node *rn;
2584 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002585 struct attr attr;
2586 struct attr_extra extra;
2587
paul718e3742002-12-13 20:15:29 +00002588 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002589 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002590
2591 if (safi != SAFI_MPLS_VPN
2592 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2593 bgp_default_originate (peer, afi, safi, 0);
2594
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002595 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2596 attr.extra = &extra;
2597
paul718e3742002-12-13 20:15:29 +00002598 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2599 for (ri = rn->info; ri; ri = ri->next)
2600 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2601 {
paulfee0f4c2004-09-13 05:12:46 +00002602 if ( (rsclient) ?
2603 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2604 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002605 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2606 else
2607 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2608 }
2609}
2610
2611void
2612bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2613{
2614 struct bgp_node *rn;
2615 struct bgp_table *table;
2616
2617 if (peer->status != Established)
2618 return;
2619
2620 if (! peer->afc_nego[afi][safi])
2621 return;
2622
2623 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2624 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2625 return;
2626
2627 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002628 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002629 else
2630 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2631 rn = bgp_route_next(rn))
2632 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002633 bgp_announce_table (peer, afi, safi, table, 0);
2634
2635 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2636 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002637}
2638
2639void
2640bgp_announce_route_all (struct peer *peer)
2641{
2642 afi_t afi;
2643 safi_t safi;
2644
2645 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2646 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2647 bgp_announce_route (peer, afi, safi);
2648}
David Lamparter6b0655a2014-06-04 06:53:35 +02002649
paul718e3742002-12-13 20:15:29 +00002650static void
paulfee0f4c2004-09-13 05:12:46 +00002651bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002652 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002653{
2654 struct bgp_node *rn;
2655 struct bgp_adj_in *ain;
2656
2657 if (! table)
2658 table = rsclient->bgp->rib[afi][safi];
2659
2660 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2661 for (ain = rn->adj_in; ain; ain = ain->next)
2662 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002663 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002664 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002665
paulfee0f4c2004-09-13 05:12:46 +00002666 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002667 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002668 }
2669}
2670
2671void
2672bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2673{
2674 struct bgp_table *table;
2675 struct bgp_node *rn;
2676
2677 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002678 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002679
2680 else
2681 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2682 rn = bgp_route_next (rn))
2683 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002684 {
2685 struct prefix_rd prd;
2686 prd.family = AF_UNSPEC;
2687 prd.prefixlen = 64;
2688 memcpy(&prd.val, rn->p.u.val, 8);
2689
2690 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2691 }
paulfee0f4c2004-09-13 05:12:46 +00002692}
David Lamparter6b0655a2014-06-04 06:53:35 +02002693
paulfee0f4c2004-09-13 05:12:46 +00002694static void
paul718e3742002-12-13 20:15:29 +00002695bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002696 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002697{
2698 int ret;
2699 struct bgp_node *rn;
2700 struct bgp_adj_in *ain;
2701
2702 if (! table)
2703 table = peer->bgp->rib[afi][safi];
2704
2705 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2706 for (ain = rn->adj_in; ain; ain = ain->next)
2707 {
2708 if (ain->peer == peer)
2709 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002710 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002711 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002712
paul718e3742002-12-13 20:15:29 +00002713 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2714 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002715 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002716
paul718e3742002-12-13 20:15:29 +00002717 if (ret < 0)
2718 {
2719 bgp_unlock_node (rn);
2720 return;
2721 }
2722 continue;
2723 }
2724 }
2725}
2726
2727void
2728bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2729{
2730 struct bgp_node *rn;
2731 struct bgp_table *table;
2732
2733 if (peer->status != Established)
2734 return;
2735
2736 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002737 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002738 else
2739 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2740 rn = bgp_route_next (rn))
2741 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002742 {
2743 struct prefix_rd prd;
2744 prd.family = AF_UNSPEC;
2745 prd.prefixlen = 64;
2746 memcpy(&prd.val, rn->p.u.val, 8);
2747
2748 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2749 }
paul718e3742002-12-13 20:15:29 +00002750}
David Lamparter6b0655a2014-06-04 06:53:35 +02002751
Chris Caputo228da422009-07-18 05:44:03 +00002752
2753struct bgp_clear_node_queue
2754{
2755 struct bgp_node *rn;
2756 enum bgp_clear_route_type purpose;
2757};
2758
paul200df112005-06-01 11:17:05 +00002759static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002760bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002761{
Chris Caputo228da422009-07-18 05:44:03 +00002762 struct bgp_clear_node_queue *cnq = data;
2763 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002764 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002765 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002766 afi_t afi = bgp_node_table (rn)->afi;
2767 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002768
Paul Jakma64e580a2006-02-21 01:09:01 +00002769 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002770
Paul Jakma64e580a2006-02-21 01:09:01 +00002771 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002772 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002773 {
2774 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002775 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2776 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002777 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002778 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2779 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002780 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002781 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002782 break;
2783 }
paul200df112005-06-01 11:17:05 +00002784 return WQ_SUCCESS;
2785}
2786
2787static void
paul0fb58d52005-11-14 14:31:49 +00002788bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002789{
Chris Caputo228da422009-07-18 05:44:03 +00002790 struct bgp_clear_node_queue *cnq = data;
2791 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002792 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002793
2794 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002795 bgp_table_unlock (table);
2796 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002797}
2798
2799static void
paul94f2b392005-06-28 12:44:16 +00002800bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002801{
Paul Jakma64e580a2006-02-21 01:09:01 +00002802 struct peer *peer = wq->spec.data;
2803
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002804 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002805 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002806
2807 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002808}
2809
2810static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002811bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002812{
Paul Jakmaa2943652009-07-21 14:02:04 +01002813 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002814
Paul Jakmaa2943652009-07-21 14:02:04 +01002815 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002816#undef CLEAR_QUEUE_NAME_LEN
2817
2818 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002819 {
2820 zlog_err ("%s: Failed to allocate work queue", __func__);
2821 exit (1);
2822 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002823 peer->clear_node_queue->spec.hold = 10;
2824 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2825 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2826 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2827 peer->clear_node_queue->spec.max_retries = 0;
2828
2829 /* we only 'lock' this peer reference when the queue is actually active */
2830 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002831}
2832
paul718e3742002-12-13 20:15:29 +00002833static void
2834bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002835 struct bgp_table *table, struct peer *rsclient,
2836 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002837{
2838 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002839
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002840
paul718e3742002-12-13 20:15:29 +00002841 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002842 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002843
hasso6cf159b2005-03-21 10:28:14 +00002844 /* If still no table => afi/safi isn't configured at all or smth. */
2845 if (! table)
2846 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002847
2848 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2849 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002850 struct bgp_info *ri;
2851 struct bgp_adj_in *ain;
2852 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002853
2854 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2855 * queued for every clearing peer, regardless of whether it is
2856 * relevant to the peer at hand.
2857 *
2858 * Overview: There are 3 different indices which need to be
2859 * scrubbed, potentially, when a peer is removed:
2860 *
2861 * 1 peer's routes visible via the RIB (ie accepted routes)
2862 * 2 peer's routes visible by the (optional) peer's adj-in index
2863 * 3 other routes visible by the peer's adj-out index
2864 *
2865 * 3 there is no hurry in scrubbing, once the struct peer is
2866 * removed from bgp->peer, we could just GC such deleted peer's
2867 * adj-outs at our leisure.
2868 *
2869 * 1 and 2 must be 'scrubbed' in some way, at least made
2870 * invisible via RIB index before peer session is allowed to be
2871 * brought back up. So one needs to know when such a 'search' is
2872 * complete.
2873 *
2874 * Ideally:
2875 *
2876 * - there'd be a single global queue or a single RIB walker
2877 * - rather than tracking which route_nodes still need to be
2878 * examined on a peer basis, we'd track which peers still
2879 * aren't cleared
2880 *
2881 * Given that our per-peer prefix-counts now should be reliable,
2882 * this may actually be achievable. It doesn't seem to be a huge
2883 * problem at this time,
2884 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002885 for (ain = rn->adj_in; ain; ain = ain->next)
2886 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2887 {
2888 bgp_adj_in_remove (rn, ain);
2889 bgp_unlock_node (rn);
2890 break;
2891 }
2892 for (aout = rn->adj_out; aout; aout = aout->next)
2893 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2894 {
2895 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2896 bgp_unlock_node (rn);
2897 break;
2898 }
2899
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002900 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002901 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002902 {
Chris Caputo228da422009-07-18 05:44:03 +00002903 struct bgp_clear_node_queue *cnq;
2904
2905 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002906 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002907 bgp_lock_node (rn);
2908 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2909 sizeof (struct bgp_clear_node_queue));
2910 cnq->rn = rn;
2911 cnq->purpose = purpose;
2912 work_queue_add (peer->clear_node_queue, cnq);
2913 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002914 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002915 }
2916 return;
2917}
2918
2919void
Chris Caputo228da422009-07-18 05:44:03 +00002920bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2921 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002922{
2923 struct bgp_node *rn;
2924 struct bgp_table *table;
2925 struct peer *rsclient;
2926 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002927
Paul Jakma64e580a2006-02-21 01:09:01 +00002928 if (peer->clear_node_queue == NULL)
2929 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002930
Paul Jakmaca058a32006-09-14 02:58:49 +00002931 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2932 * Idle until it receives a Clearing_Completed event. This protects
2933 * against peers which flap faster than we can we clear, which could
2934 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002935 *
2936 * a) race with routes from the new session being installed before
2937 * clear_route_node visits the node (to delete the route of that
2938 * peer)
2939 * b) resource exhaustion, clear_route_node likely leads to an entry
2940 * on the process_main queue. Fast-flapping could cause that queue
2941 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002942 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002943 if (!peer->clear_node_queue->thread)
2944 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002945
Chris Caputo228da422009-07-18 05:44:03 +00002946 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002947 {
Chris Caputo228da422009-07-18 05:44:03 +00002948 case BGP_CLEAR_ROUTE_NORMAL:
2949 if (safi != SAFI_MPLS_VPN)
2950 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2951 else
2952 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2953 rn = bgp_route_next (rn))
2954 if ((table = rn->info) != NULL)
2955 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2956
2957 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2958 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2959 PEER_FLAG_RSERVER_CLIENT))
2960 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2961 break;
2962
2963 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2964 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2965 break;
2966
2967 default:
2968 assert (0);
2969 break;
paulfee0f4c2004-09-13 05:12:46 +00002970 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002971
Paul Jakmaca058a32006-09-14 02:58:49 +00002972 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002973 * completion function won't be run by workqueue code - call it here.
2974 * XXX: Actually, this assumption doesn't hold, see
2975 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002976 *
2977 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002978 * really needed if peer state is Established - peers in
2979 * pre-Established states shouldn't have any route-update state
2980 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002981 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002982 * We still can get here in pre-Established though, through
2983 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2984 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002985 *
2986 * At some future point, this check could be move to the top of the
2987 * function, and do a quick early-return when state is
2988 * pre-Established, avoiding above list and table scans. Once we're
2989 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002990 */
2991 if (!peer->clear_node_queue->thread)
2992 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002993}
2994
2995void
2996bgp_clear_route_all (struct peer *peer)
2997{
2998 afi_t afi;
2999 safi_t safi;
3000
3001 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3002 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003003 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003004}
3005
3006void
3007bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3008{
3009 struct bgp_table *table;
3010 struct bgp_node *rn;
3011 struct bgp_adj_in *ain;
3012
3013 table = peer->bgp->rib[afi][safi];
3014
3015 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3016 for (ain = rn->adj_in; ain ; ain = ain->next)
3017 if (ain->peer == peer)
3018 {
3019 bgp_adj_in_remove (rn, ain);
3020 bgp_unlock_node (rn);
3021 break;
3022 }
3023}
hasso93406d82005-02-02 14:40:33 +00003024
3025void
3026bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3027{
3028 struct bgp_node *rn;
3029 struct bgp_info *ri;
3030 struct bgp_table *table;
3031
3032 table = peer->bgp->rib[afi][safi];
3033
3034 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3035 {
3036 for (ri = rn->info; ri; ri = ri->next)
3037 if (ri->peer == peer)
3038 {
3039 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3040 bgp_rib_remove (rn, ri, peer, afi, safi);
3041 break;
3042 }
3043 }
3044}
David Lamparter6b0655a2014-06-04 06:53:35 +02003045
paul718e3742002-12-13 20:15:29 +00003046/* Delete all kernel routes. */
3047void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003048bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003049{
3050 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003051 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003052 struct bgp_node *rn;
3053 struct bgp_table *table;
3054 struct bgp_info *ri;
3055
paul1eb8ef22005-04-07 07:30:20 +00003056 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003057 {
3058 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3059
3060 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3061 for (ri = rn->info; ri; ri = ri->next)
3062 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3063 && ri->type == ZEBRA_ROUTE_BGP
3064 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003065 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003066
3067 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3068
3069 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3070 for (ri = rn->info; ri; ri = ri->next)
3071 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3072 && ri->type == ZEBRA_ROUTE_BGP
3073 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003074 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003075 }
3076}
3077
3078void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003079bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003080{
3081 vty_reset ();
3082 bgp_zclient_reset ();
3083 access_list_reset ();
3084 prefix_list_reset ();
3085}
David Lamparter6b0655a2014-06-04 06:53:35 +02003086
paul718e3742002-12-13 20:15:29 +00003087/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3088 value. */
3089int
3090bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3091{
3092 u_char *pnt;
3093 u_char *lim;
3094 struct prefix p;
3095 int psize;
3096 int ret;
3097
3098 /* Check peer status. */
3099 if (peer->status != Established)
3100 return 0;
3101
3102 pnt = packet->nlri;
3103 lim = pnt + packet->length;
3104
3105 for (; pnt < lim; pnt += psize)
3106 {
3107 /* Clear prefix structure. */
3108 memset (&p, 0, sizeof (struct prefix));
3109
3110 /* Fetch prefix length. */
3111 p.prefixlen = *pnt++;
3112 p.family = afi2family (packet->afi);
3113
3114 /* Already checked in nlri_sanity_check(). We do double check
3115 here. */
3116 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3117 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3118 return -1;
3119
3120 /* Packet size overflow check. */
3121 psize = PSIZE (p.prefixlen);
3122
3123 /* When packet overflow occur return immediately. */
3124 if (pnt + psize > lim)
3125 return -1;
3126
3127 /* Fetch prefix from NLRI packet. */
3128 memcpy (&p.u.prefix, pnt, psize);
3129
3130 /* Check address. */
3131 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3132 {
3133 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3134 {
paulf5ba3872004-07-09 12:11:31 +00003135 /*
3136 * From draft-ietf-idr-bgp4-22, Section 6.3:
3137 * If a BGP router receives an UPDATE message with a
3138 * semantically incorrect NLRI field, in which a prefix is
3139 * semantically incorrect (eg. an unexpected multicast IP
3140 * address), it should ignore the prefix.
3141 */
paul718e3742002-12-13 20:15:29 +00003142 zlog (peer->log, LOG_ERR,
3143 "IPv4 unicast NLRI is multicast address %s",
3144 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003145
paul718e3742002-12-13 20:15:29 +00003146 return -1;
3147 }
3148 }
3149
3150#ifdef HAVE_IPV6
3151 /* Check address. */
3152 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3153 {
3154 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3155 {
3156 char buf[BUFSIZ];
3157
3158 zlog (peer->log, LOG_WARNING,
3159 "IPv6 link-local NLRI received %s ignore this NLRI",
3160 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3161
3162 continue;
3163 }
3164 }
3165#endif /* HAVE_IPV6 */
3166
3167 /* Normal process. */
3168 if (attr)
3169 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3170 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3171 else
3172 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3173 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3174
3175 /* Address family configuration mismatch or maximum-prefix count
3176 overflow. */
3177 if (ret < 0)
3178 return -1;
3179 }
3180
3181 /* Packet length consistency check. */
3182 if (pnt != lim)
3183 return -1;
3184
3185 return 0;
3186}
3187
3188/* NLRI encode syntax check routine. */
3189int
3190bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3191 bgp_size_t length)
3192{
3193 u_char *end;
3194 u_char prefixlen;
3195 int psize;
3196
3197 end = pnt + length;
3198
3199 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3200 syntactic validity. If the field is syntactically incorrect,
3201 then the Error Subcode is set to Invalid Network Field. */
3202
3203 while (pnt < end)
3204 {
3205 prefixlen = *pnt++;
3206
3207 /* Prefix length check. */
3208 if ((afi == AFI_IP && prefixlen > 32)
3209 || (afi == AFI_IP6 && prefixlen > 128))
3210 {
3211 plog_err (peer->log,
3212 "%s [Error] Update packet error (wrong prefix length %d)",
3213 peer->host, prefixlen);
3214 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3215 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3216 return -1;
3217 }
3218
3219 /* Packet size overflow check. */
3220 psize = PSIZE (prefixlen);
3221
3222 if (pnt + psize > end)
3223 {
3224 plog_err (peer->log,
3225 "%s [Error] Update packet error"
3226 " (prefix data overflow prefix size is %d)",
3227 peer->host, psize);
3228 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3229 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3230 return -1;
3231 }
3232
3233 pnt += psize;
3234 }
3235
3236 /* Packet length consistency check. */
3237 if (pnt != end)
3238 {
3239 plog_err (peer->log,
3240 "%s [Error] Update packet error"
3241 " (prefix length mismatch with total length)",
3242 peer->host);
3243 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3244 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3245 return -1;
3246 }
3247 return 0;
3248}
David Lamparter6b0655a2014-06-04 06:53:35 +02003249
paul94f2b392005-06-28 12:44:16 +00003250static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003251bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003252{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003253 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003254}
3255
paul94f2b392005-06-28 12:44:16 +00003256static void
paul718e3742002-12-13 20:15:29 +00003257bgp_static_free (struct bgp_static *bgp_static)
3258{
3259 if (bgp_static->rmap.name)
3260 free (bgp_static->rmap.name);
3261 XFREE (MTYPE_BGP_STATIC, bgp_static);
3262}
3263
paul94f2b392005-06-28 12:44:16 +00003264static void
paulfee0f4c2004-09-13 05:12:46 +00003265bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3266 struct prefix *p, afi_t afi, safi_t safi)
3267{
3268 struct bgp_node *rn;
3269 struct bgp_info *ri;
3270
3271 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3272
3273 /* Check selected route and self inserted route. */
3274 for (ri = rn->info; ri; ri = ri->next)
3275 if (ri->peer == bgp->peer_self
3276 && ri->type == ZEBRA_ROUTE_BGP
3277 && ri->sub_type == BGP_ROUTE_STATIC)
3278 break;
3279
3280 /* Withdraw static BGP route from routing table. */
3281 if (ri)
3282 {
paulfee0f4c2004-09-13 05:12:46 +00003283 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003284 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003285 }
3286
3287 /* Unlock bgp_node_lookup. */
3288 bgp_unlock_node (rn);
3289}
3290
paul94f2b392005-06-28 12:44:16 +00003291static void
paulfee0f4c2004-09-13 05:12:46 +00003292bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003293 struct bgp_static *bgp_static,
3294 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003295{
3296 struct bgp_node *rn;
3297 struct bgp_info *ri;
3298 struct bgp_info *new;
3299 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003300 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003301 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003302 struct attr new_attr;
3303 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003304 struct bgp *bgp;
3305 int ret;
3306 char buf[SU_ADDRSTRLEN];
3307
3308 bgp = rsclient->bgp;
3309
Paul Jakma06e110f2006-05-12 23:29:22 +00003310 assert (bgp_static);
3311 if (!bgp_static)
3312 return;
3313
paulfee0f4c2004-09-13 05:12:46 +00003314 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3315
3316 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003317
3318 attr.nexthop = bgp_static->igpnexthop;
3319 attr.med = bgp_static->igpmetric;
3320 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003321
Paul Jakma41367172007-08-06 15:24:51 +00003322 if (bgp_static->atomic)
3323 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3324
paulfee0f4c2004-09-13 05:12:46 +00003325 /* Apply network route-map for export to this rsclient. */
3326 if (bgp_static->rmap.name)
3327 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003328 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003329 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003330 info.attr = &attr_tmp;
3331
paulfee0f4c2004-09-13 05:12:46 +00003332 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3333 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3334
3335 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3336
3337 rsclient->rmap_type = 0;
3338
3339 if (ret == RMAP_DENYMATCH)
3340 {
3341 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003342 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003343
3344 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003345 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003346 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003347 bgp_attr_extra_free (&attr);
3348
paulfee0f4c2004-09-13 05:12:46 +00003349 return;
3350 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003351 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003352 }
3353 else
3354 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003355
3356 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003357 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003358
paulfee0f4c2004-09-13 05:12:46 +00003359 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3360
Paul Jakmafb982c22007-05-04 20:15:47 +00003361 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3362 == RMAP_DENY)
3363 {
paulfee0f4c2004-09-13 05:12:46 +00003364 /* This BGP update is filtered. Log the reason then update BGP entry. */
3365 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003366 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003367 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3368 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3369 p->prefixlen, rsclient->host);
3370
3371 bgp->peer_self->rmap_type = 0;
3372
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003373 bgp_attr_unintern (&attr_new);
3374 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003375 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003376
3377 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3378
3379 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003380 }
paulfee0f4c2004-09-13 05:12:46 +00003381
3382 bgp->peer_self->rmap_type = 0;
3383
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003384 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003385 attr_new = bgp_attr_intern (&new_attr);
3386
3387 for (ri = rn->info; ri; ri = ri->next)
3388 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3389 && ri->sub_type == BGP_ROUTE_STATIC)
3390 break;
3391
3392 if (ri)
3393 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003394 if (attrhash_cmp (ri->attr, attr_new) &&
3395 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003396 {
3397 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003398 bgp_attr_unintern (&attr_new);
3399 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003400 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003401 return;
3402 }
3403 else
3404 {
3405 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003406 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003407
3408 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003409 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3410 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003411 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003412 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003413 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003414
3415 /* Process change. */
3416 bgp_process (bgp, rn, afi, safi);
3417 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003418 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003419 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003420 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003421 }
paulfee0f4c2004-09-13 05:12:46 +00003422 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003423
paulfee0f4c2004-09-13 05:12:46 +00003424 /* Make new BGP info. */
3425 new = bgp_info_new ();
3426 new->type = ZEBRA_ROUTE_BGP;
3427 new->sub_type = BGP_ROUTE_STATIC;
3428 new->peer = bgp->peer_self;
3429 SET_FLAG (new->flags, BGP_INFO_VALID);
3430 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003431 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003432
3433 /* Register new BGP information. */
3434 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003435
3436 /* route_node_get lock */
3437 bgp_unlock_node (rn);
3438
paulfee0f4c2004-09-13 05:12:46 +00003439 /* Process change. */
3440 bgp_process (bgp, rn, afi, safi);
3441
3442 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003443 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003444 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003445}
3446
paul94f2b392005-06-28 12:44:16 +00003447static void
paulfee0f4c2004-09-13 05:12:46 +00003448bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003449 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3450{
3451 struct bgp_node *rn;
3452 struct bgp_info *ri;
3453 struct bgp_info *new;
3454 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003455 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003456 struct attr *attr_new;
3457 int ret;
3458
Paul Jakmadd8103a2006-05-12 23:27:30 +00003459 assert (bgp_static);
3460 if (!bgp_static)
3461 return;
3462
paulfee0f4c2004-09-13 05:12:46 +00003463 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003464
3465 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003466
3467 attr.nexthop = bgp_static->igpnexthop;
3468 attr.med = bgp_static->igpmetric;
3469 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003470
Paul Jakma41367172007-08-06 15:24:51 +00003471 if (bgp_static->atomic)
3472 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3473
paul718e3742002-12-13 20:15:29 +00003474 /* Apply route-map. */
3475 if (bgp_static->rmap.name)
3476 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003477 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003478 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003479 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003480
paulfee0f4c2004-09-13 05:12:46 +00003481 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3482
paul718e3742002-12-13 20:15:29 +00003483 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003484
paulfee0f4c2004-09-13 05:12:46 +00003485 bgp->peer_self->rmap_type = 0;
3486
paul718e3742002-12-13 20:15:29 +00003487 if (ret == RMAP_DENYMATCH)
3488 {
3489 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003490 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003491
3492 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003493 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003494 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003495 bgp_static_withdraw (bgp, p, afi, safi);
3496 return;
3497 }
paul286e1e72003-08-08 00:24:31 +00003498 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003499 }
paul286e1e72003-08-08 00:24:31 +00003500 else
3501 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003502
3503 for (ri = rn->info; ri; ri = ri->next)
3504 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3505 && ri->sub_type == BGP_ROUTE_STATIC)
3506 break;
3507
3508 if (ri)
3509 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003510 if (attrhash_cmp (ri->attr, attr_new) &&
3511 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003512 {
3513 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003514 bgp_attr_unintern (&attr_new);
3515 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003516 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003517 return;
3518 }
3519 else
3520 {
3521 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003522 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003523
3524 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003525 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3526 bgp_info_restore(rn, ri);
3527 else
3528 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003529 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003530 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003531 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003532
3533 /* Process change. */
3534 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3535 bgp_process (bgp, rn, afi, safi);
3536 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003537 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003538 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003539 return;
3540 }
3541 }
3542
3543 /* Make new BGP info. */
3544 new = bgp_info_new ();
3545 new->type = ZEBRA_ROUTE_BGP;
3546 new->sub_type = BGP_ROUTE_STATIC;
3547 new->peer = bgp->peer_self;
3548 SET_FLAG (new->flags, BGP_INFO_VALID);
3549 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003550 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003551
3552 /* Aggregate address increment. */
3553 bgp_aggregate_increment (bgp, p, new, afi, safi);
3554
3555 /* Register new BGP information. */
3556 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003557
3558 /* route_node_get lock */
3559 bgp_unlock_node (rn);
3560
paul718e3742002-12-13 20:15:29 +00003561 /* Process change. */
3562 bgp_process (bgp, rn, afi, safi);
3563
3564 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003565 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003566 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003567}
3568
3569void
paulfee0f4c2004-09-13 05:12:46 +00003570bgp_static_update (struct bgp *bgp, struct prefix *p,
3571 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3572{
3573 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003574 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003575
3576 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3577
paul1eb8ef22005-04-07 07:30:20 +00003578 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003579 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003580 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3581 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003582 }
3583}
3584
paul94f2b392005-06-28 12:44:16 +00003585static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003586bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3587 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003588{
3589 struct bgp_node *rn;
3590 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003591
paulfee0f4c2004-09-13 05:12:46 +00003592 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003593
3594 /* Make new BGP info. */
3595 new = bgp_info_new ();
3596 new->type = ZEBRA_ROUTE_BGP;
3597 new->sub_type = BGP_ROUTE_STATIC;
3598 new->peer = bgp->peer_self;
3599 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3600 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003601 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003602 new->extra = bgp_info_extra_new();
3603 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003604
3605 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003606 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003607
3608 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003609 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003610
paul200df112005-06-01 11:17:05 +00003611 /* route_node_get lock */
3612 bgp_unlock_node (rn);
3613
paul718e3742002-12-13 20:15:29 +00003614 /* Process change. */
3615 bgp_process (bgp, rn, afi, safi);
3616}
3617
3618void
3619bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3620 safi_t safi)
3621{
3622 struct bgp_node *rn;
3623 struct bgp_info *ri;
3624
paulfee0f4c2004-09-13 05:12:46 +00003625 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003626
3627 /* Check selected route and self inserted route. */
3628 for (ri = rn->info; ri; ri = ri->next)
3629 if (ri->peer == bgp->peer_self
3630 && ri->type == ZEBRA_ROUTE_BGP
3631 && ri->sub_type == BGP_ROUTE_STATIC)
3632 break;
3633
3634 /* Withdraw static BGP route from routing table. */
3635 if (ri)
3636 {
3637 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003638 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003639 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003640 }
3641
3642 /* Unlock bgp_node_lookup. */
3643 bgp_unlock_node (rn);
3644}
3645
3646void
paulfee0f4c2004-09-13 05:12:46 +00003647bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3648{
3649 struct bgp_static *bgp_static;
3650 struct bgp *bgp;
3651 struct bgp_node *rn;
3652 struct prefix *p;
3653
3654 bgp = rsclient->bgp;
3655
3656 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3657 if ((bgp_static = rn->info) != NULL)
3658 {
3659 p = &rn->p;
3660
3661 bgp_static_update_rsclient (rsclient, p, bgp_static,
3662 afi, safi);
3663 }
3664}
3665
paul94f2b392005-06-28 12:44:16 +00003666static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003667bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3668 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003669{
3670 struct bgp_node *rn;
3671 struct bgp_info *ri;
3672
paulfee0f4c2004-09-13 05:12:46 +00003673 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003674
3675 /* Check selected route and self inserted route. */
3676 for (ri = rn->info; ri; ri = ri->next)
3677 if (ri->peer == bgp->peer_self
3678 && ri->type == ZEBRA_ROUTE_BGP
3679 && ri->sub_type == BGP_ROUTE_STATIC)
3680 break;
3681
3682 /* Withdraw static BGP route from routing table. */
3683 if (ri)
3684 {
3685 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003686 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003687 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003688 }
3689
3690 /* Unlock bgp_node_lookup. */
3691 bgp_unlock_node (rn);
3692}
3693
3694/* Configure static BGP network. When user don't run zebra, static
3695 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003696static int
paulfd79ac92004-10-13 05:06:08 +00003697bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003698 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003699{
3700 int ret;
3701 struct prefix p;
3702 struct bgp_static *bgp_static;
3703 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003704 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003705
3706 /* Convert IP prefix string to struct prefix. */
3707 ret = str2prefix (ip_str, &p);
3708 if (! ret)
3709 {
3710 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3711 return CMD_WARNING;
3712 }
3713#ifdef HAVE_IPV6
3714 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3715 {
3716 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3717 VTY_NEWLINE);
3718 return CMD_WARNING;
3719 }
3720#endif /* HAVE_IPV6 */
3721
3722 apply_mask (&p);
3723
3724 /* Set BGP static route configuration. */
3725 rn = bgp_node_get (bgp->route[afi][safi], &p);
3726
3727 if (rn->info)
3728 {
3729 /* Configuration change. */
3730 bgp_static = rn->info;
3731
3732 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003733 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3734 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003735
paul718e3742002-12-13 20:15:29 +00003736 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003737
paul718e3742002-12-13 20:15:29 +00003738 if (rmap)
3739 {
3740 if (bgp_static->rmap.name)
3741 free (bgp_static->rmap.name);
3742 bgp_static->rmap.name = strdup (rmap);
3743 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3744 }
3745 else
3746 {
3747 if (bgp_static->rmap.name)
3748 free (bgp_static->rmap.name);
3749 bgp_static->rmap.name = NULL;
3750 bgp_static->rmap.map = NULL;
3751 bgp_static->valid = 0;
3752 }
3753 bgp_unlock_node (rn);
3754 }
3755 else
3756 {
3757 /* New configuration. */
3758 bgp_static = bgp_static_new ();
3759 bgp_static->backdoor = backdoor;
3760 bgp_static->valid = 0;
3761 bgp_static->igpmetric = 0;
3762 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003763
paul718e3742002-12-13 20:15:29 +00003764 if (rmap)
3765 {
3766 if (bgp_static->rmap.name)
3767 free (bgp_static->rmap.name);
3768 bgp_static->rmap.name = strdup (rmap);
3769 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3770 }
3771 rn->info = bgp_static;
3772 }
3773
3774 /* If BGP scan is not enabled, we should install this route here. */
3775 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3776 {
3777 bgp_static->valid = 1;
3778
3779 if (need_update)
3780 bgp_static_withdraw (bgp, &p, afi, safi);
3781
3782 if (! bgp_static->backdoor)
3783 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3784 }
3785
3786 return CMD_SUCCESS;
3787}
3788
3789/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003790static int
paulfd79ac92004-10-13 05:06:08 +00003791bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003792 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003793{
3794 int ret;
3795 struct prefix p;
3796 struct bgp_static *bgp_static;
3797 struct bgp_node *rn;
3798
3799 /* Convert IP prefix string to struct prefix. */
3800 ret = str2prefix (ip_str, &p);
3801 if (! ret)
3802 {
3803 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3804 return CMD_WARNING;
3805 }
3806#ifdef HAVE_IPV6
3807 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3808 {
3809 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3810 VTY_NEWLINE);
3811 return CMD_WARNING;
3812 }
3813#endif /* HAVE_IPV6 */
3814
3815 apply_mask (&p);
3816
3817 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3818 if (! rn)
3819 {
3820 vty_out (vty, "%% Can't find specified static route configuration.%s",
3821 VTY_NEWLINE);
3822 return CMD_WARNING;
3823 }
3824
3825 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003826
paul718e3742002-12-13 20:15:29 +00003827 /* Update BGP RIB. */
3828 if (! bgp_static->backdoor)
3829 bgp_static_withdraw (bgp, &p, afi, safi);
3830
3831 /* Clear configuration. */
3832 bgp_static_free (bgp_static);
3833 rn->info = NULL;
3834 bgp_unlock_node (rn);
3835 bgp_unlock_node (rn);
3836
3837 return CMD_SUCCESS;
3838}
3839
3840/* Called from bgp_delete(). Delete all static routes from the BGP
3841 instance. */
3842void
3843bgp_static_delete (struct bgp *bgp)
3844{
3845 afi_t afi;
3846 safi_t safi;
3847 struct bgp_node *rn;
3848 struct bgp_node *rm;
3849 struct bgp_table *table;
3850 struct bgp_static *bgp_static;
3851
3852 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3853 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3854 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3855 if (rn->info != NULL)
3856 {
3857 if (safi == SAFI_MPLS_VPN)
3858 {
3859 table = rn->info;
3860
3861 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3862 {
3863 bgp_static = rn->info;
3864 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3865 AFI_IP, SAFI_MPLS_VPN,
3866 (struct prefix_rd *)&rn->p,
3867 bgp_static->tag);
3868 bgp_static_free (bgp_static);
3869 rn->info = NULL;
3870 bgp_unlock_node (rn);
3871 }
3872 }
3873 else
3874 {
3875 bgp_static = rn->info;
3876 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3877 bgp_static_free (bgp_static);
3878 rn->info = NULL;
3879 bgp_unlock_node (rn);
3880 }
3881 }
3882}
3883
3884int
paulfd79ac92004-10-13 05:06:08 +00003885bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3886 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003887{
3888 int ret;
3889 struct prefix p;
3890 struct prefix_rd prd;
3891 struct bgp *bgp;
3892 struct bgp_node *prn;
3893 struct bgp_node *rn;
3894 struct bgp_table *table;
3895 struct bgp_static *bgp_static;
3896 u_char tag[3];
3897
3898 bgp = vty->index;
3899
3900 ret = str2prefix (ip_str, &p);
3901 if (! ret)
3902 {
3903 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3904 return CMD_WARNING;
3905 }
3906 apply_mask (&p);
3907
3908 ret = str2prefix_rd (rd_str, &prd);
3909 if (! ret)
3910 {
3911 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3912 return CMD_WARNING;
3913 }
3914
3915 ret = str2tag (tag_str, tag);
3916 if (! ret)
3917 {
3918 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3919 return CMD_WARNING;
3920 }
3921
3922 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3923 (struct prefix *)&prd);
3924 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003925 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003926 else
3927 bgp_unlock_node (prn);
3928 table = prn->info;
3929
3930 rn = bgp_node_get (table, &p);
3931
3932 if (rn->info)
3933 {
3934 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3935 bgp_unlock_node (rn);
3936 }
3937 else
3938 {
3939 /* New configuration. */
3940 bgp_static = bgp_static_new ();
3941 bgp_static->valid = 1;
3942 memcpy (bgp_static->tag, tag, 3);
3943 rn->info = bgp_static;
3944
3945 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3946 }
3947
3948 return CMD_SUCCESS;
3949}
3950
3951/* Configure static BGP network. */
3952int
paulfd79ac92004-10-13 05:06:08 +00003953bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3954 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003955{
3956 int ret;
3957 struct bgp *bgp;
3958 struct prefix p;
3959 struct prefix_rd prd;
3960 struct bgp_node *prn;
3961 struct bgp_node *rn;
3962 struct bgp_table *table;
3963 struct bgp_static *bgp_static;
3964 u_char tag[3];
3965
3966 bgp = vty->index;
3967
3968 /* Convert IP prefix string to struct prefix. */
3969 ret = str2prefix (ip_str, &p);
3970 if (! ret)
3971 {
3972 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3973 return CMD_WARNING;
3974 }
3975 apply_mask (&p);
3976
3977 ret = str2prefix_rd (rd_str, &prd);
3978 if (! ret)
3979 {
3980 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3981 return CMD_WARNING;
3982 }
3983
3984 ret = str2tag (tag_str, tag);
3985 if (! ret)
3986 {
3987 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3988 return CMD_WARNING;
3989 }
3990
3991 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3992 (struct prefix *)&prd);
3993 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003994 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003995 else
3996 bgp_unlock_node (prn);
3997 table = prn->info;
3998
3999 rn = bgp_node_lookup (table, &p);
4000
4001 if (rn)
4002 {
4003 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4004
4005 bgp_static = rn->info;
4006 bgp_static_free (bgp_static);
4007 rn->info = NULL;
4008 bgp_unlock_node (rn);
4009 bgp_unlock_node (rn);
4010 }
4011 else
4012 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4013
4014 return CMD_SUCCESS;
4015}
David Lamparter6b0655a2014-06-04 06:53:35 +02004016
paul718e3742002-12-13 20:15:29 +00004017DEFUN (bgp_network,
4018 bgp_network_cmd,
4019 "network A.B.C.D/M",
4020 "Specify a network to announce via BGP\n"
4021 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4022{
4023 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004024 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004025}
4026
4027DEFUN (bgp_network_route_map,
4028 bgp_network_route_map_cmd,
4029 "network A.B.C.D/M route-map WORD",
4030 "Specify a network to announce via BGP\n"
4031 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4032 "Route-map to modify the attributes\n"
4033 "Name of the route map\n")
4034{
4035 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004036 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004037}
4038
4039DEFUN (bgp_network_backdoor,
4040 bgp_network_backdoor_cmd,
4041 "network A.B.C.D/M backdoor",
4042 "Specify a network to announce via BGP\n"
4043 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4044 "Specify a BGP backdoor route\n")
4045{
Paul Jakma41367172007-08-06 15:24:51 +00004046 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004047 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004048}
4049
4050DEFUN (bgp_network_mask,
4051 bgp_network_mask_cmd,
4052 "network A.B.C.D mask A.B.C.D",
4053 "Specify a network to announce via BGP\n"
4054 "Network number\n"
4055 "Network mask\n"
4056 "Network mask\n")
4057{
4058 int ret;
4059 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004060
paul718e3742002-12-13 20:15:29 +00004061 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4062 if (! ret)
4063 {
4064 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4065 return CMD_WARNING;
4066 }
4067
4068 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004069 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004070}
4071
4072DEFUN (bgp_network_mask_route_map,
4073 bgp_network_mask_route_map_cmd,
4074 "network A.B.C.D mask A.B.C.D route-map WORD",
4075 "Specify a network to announce via BGP\n"
4076 "Network number\n"
4077 "Network mask\n"
4078 "Network mask\n"
4079 "Route-map to modify the attributes\n"
4080 "Name of the route map\n")
4081{
4082 int ret;
4083 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004084
paul718e3742002-12-13 20:15:29 +00004085 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4086 if (! ret)
4087 {
4088 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4089 return CMD_WARNING;
4090 }
4091
4092 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004093 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004094}
4095
4096DEFUN (bgp_network_mask_backdoor,
4097 bgp_network_mask_backdoor_cmd,
4098 "network A.B.C.D mask A.B.C.D backdoor",
4099 "Specify a network to announce via BGP\n"
4100 "Network number\n"
4101 "Network mask\n"
4102 "Network mask\n"
4103 "Specify a BGP backdoor route\n")
4104{
4105 int ret;
4106 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004107
paul718e3742002-12-13 20:15:29 +00004108 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4109 if (! ret)
4110 {
4111 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4112 return CMD_WARNING;
4113 }
4114
Paul Jakma41367172007-08-06 15:24:51 +00004115 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004116 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004117}
4118
4119DEFUN (bgp_network_mask_natural,
4120 bgp_network_mask_natural_cmd,
4121 "network A.B.C.D",
4122 "Specify a network to announce via BGP\n"
4123 "Network number\n")
4124{
4125 int ret;
4126 char prefix_str[BUFSIZ];
4127
4128 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4129 if (! ret)
4130 {
4131 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4132 return CMD_WARNING;
4133 }
4134
4135 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004136 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004137}
4138
4139DEFUN (bgp_network_mask_natural_route_map,
4140 bgp_network_mask_natural_route_map_cmd,
4141 "network A.B.C.D route-map WORD",
4142 "Specify a network to announce via BGP\n"
4143 "Network number\n"
4144 "Route-map to modify the attributes\n"
4145 "Name of the route map\n")
4146{
4147 int ret;
4148 char prefix_str[BUFSIZ];
4149
4150 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4151 if (! ret)
4152 {
4153 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4154 return CMD_WARNING;
4155 }
4156
4157 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004158 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004159}
4160
4161DEFUN (bgp_network_mask_natural_backdoor,
4162 bgp_network_mask_natural_backdoor_cmd,
4163 "network A.B.C.D backdoor",
4164 "Specify a network to announce via BGP\n"
4165 "Network number\n"
4166 "Specify a BGP backdoor route\n")
4167{
4168 int ret;
4169 char prefix_str[BUFSIZ];
4170
4171 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4172 if (! ret)
4173 {
4174 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4175 return CMD_WARNING;
4176 }
4177
Paul Jakma41367172007-08-06 15:24:51 +00004178 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004179 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004180}
4181
4182DEFUN (no_bgp_network,
4183 no_bgp_network_cmd,
4184 "no network A.B.C.D/M",
4185 NO_STR
4186 "Specify a network to announce via BGP\n"
4187 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4188{
4189 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4190 bgp_node_safi (vty));
4191}
4192
4193ALIAS (no_bgp_network,
4194 no_bgp_network_route_map_cmd,
4195 "no network A.B.C.D/M route-map WORD",
4196 NO_STR
4197 "Specify a network to announce via BGP\n"
4198 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4199 "Route-map to modify the attributes\n"
4200 "Name of the route map\n")
4201
4202ALIAS (no_bgp_network,
4203 no_bgp_network_backdoor_cmd,
4204 "no network A.B.C.D/M backdoor",
4205 NO_STR
4206 "Specify a network to announce via BGP\n"
4207 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4208 "Specify a BGP backdoor route\n")
4209
4210DEFUN (no_bgp_network_mask,
4211 no_bgp_network_mask_cmd,
4212 "no network A.B.C.D mask A.B.C.D",
4213 NO_STR
4214 "Specify a network to announce via BGP\n"
4215 "Network number\n"
4216 "Network mask\n"
4217 "Network mask\n")
4218{
4219 int ret;
4220 char prefix_str[BUFSIZ];
4221
4222 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4223 if (! ret)
4224 {
4225 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4226 return CMD_WARNING;
4227 }
4228
4229 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4230 bgp_node_safi (vty));
4231}
4232
4233ALIAS (no_bgp_network_mask,
4234 no_bgp_network_mask_route_map_cmd,
4235 "no network A.B.C.D mask A.B.C.D route-map WORD",
4236 NO_STR
4237 "Specify a network to announce via BGP\n"
4238 "Network number\n"
4239 "Network mask\n"
4240 "Network mask\n"
4241 "Route-map to modify the attributes\n"
4242 "Name of the route map\n")
4243
4244ALIAS (no_bgp_network_mask,
4245 no_bgp_network_mask_backdoor_cmd,
4246 "no network A.B.C.D mask A.B.C.D backdoor",
4247 NO_STR
4248 "Specify a network to announce via BGP\n"
4249 "Network number\n"
4250 "Network mask\n"
4251 "Network mask\n"
4252 "Specify a BGP backdoor route\n")
4253
4254DEFUN (no_bgp_network_mask_natural,
4255 no_bgp_network_mask_natural_cmd,
4256 "no network A.B.C.D",
4257 NO_STR
4258 "Specify a network to announce via BGP\n"
4259 "Network number\n")
4260{
4261 int ret;
4262 char prefix_str[BUFSIZ];
4263
4264 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4265 if (! ret)
4266 {
4267 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4268 return CMD_WARNING;
4269 }
4270
4271 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4272 bgp_node_safi (vty));
4273}
4274
4275ALIAS (no_bgp_network_mask_natural,
4276 no_bgp_network_mask_natural_route_map_cmd,
4277 "no network A.B.C.D route-map WORD",
4278 NO_STR
4279 "Specify a network to announce via BGP\n"
4280 "Network number\n"
4281 "Route-map to modify the attributes\n"
4282 "Name of the route map\n")
4283
4284ALIAS (no_bgp_network_mask_natural,
4285 no_bgp_network_mask_natural_backdoor_cmd,
4286 "no network A.B.C.D backdoor",
4287 NO_STR
4288 "Specify a network to announce via BGP\n"
4289 "Network number\n"
4290 "Specify a BGP backdoor route\n")
4291
4292#ifdef HAVE_IPV6
4293DEFUN (ipv6_bgp_network,
4294 ipv6_bgp_network_cmd,
4295 "network X:X::X:X/M",
4296 "Specify a network to announce via BGP\n"
4297 "IPv6 prefix <network>/<length>\n")
4298{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304299 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004300 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004301}
4302
4303DEFUN (ipv6_bgp_network_route_map,
4304 ipv6_bgp_network_route_map_cmd,
4305 "network X:X::X:X/M route-map WORD",
4306 "Specify a network to announce via BGP\n"
4307 "IPv6 prefix <network>/<length>\n"
4308 "Route-map to modify the attributes\n"
4309 "Name of the route map\n")
4310{
4311 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004312 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004313}
4314
4315DEFUN (no_ipv6_bgp_network,
4316 no_ipv6_bgp_network_cmd,
4317 "no network X:X::X:X/M",
4318 NO_STR
4319 "Specify a network to announce via BGP\n"
4320 "IPv6 prefix <network>/<length>\n")
4321{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304322 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004323}
4324
4325ALIAS (no_ipv6_bgp_network,
4326 no_ipv6_bgp_network_route_map_cmd,
4327 "no network X:X::X:X/M route-map WORD",
4328 NO_STR
4329 "Specify a network to announce via BGP\n"
4330 "IPv6 prefix <network>/<length>\n"
4331 "Route-map to modify the attributes\n"
4332 "Name of the route map\n")
4333
4334ALIAS (ipv6_bgp_network,
4335 old_ipv6_bgp_network_cmd,
4336 "ipv6 bgp network X:X::X:X/M",
4337 IPV6_STR
4338 BGP_STR
4339 "Specify a network to announce via BGP\n"
4340 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4341
4342ALIAS (no_ipv6_bgp_network,
4343 old_no_ipv6_bgp_network_cmd,
4344 "no ipv6 bgp network X:X::X:X/M",
4345 NO_STR
4346 IPV6_STR
4347 BGP_STR
4348 "Specify a network to announce via BGP\n"
4349 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4350#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004351
4352/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4353ALIAS_DEPRECATED (bgp_network,
4354 bgp_network_ttl_cmd,
4355 "network A.B.C.D/M pathlimit <0-255>",
4356 "Specify a network to announce via BGP\n"
4357 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4358 "AS-Path hopcount limit attribute\n"
4359 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4360ALIAS_DEPRECATED (bgp_network_backdoor,
4361 bgp_network_backdoor_ttl_cmd,
4362 "network A.B.C.D/M backdoor pathlimit <0-255>",
4363 "Specify a network to announce via BGP\n"
4364 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4365 "Specify a BGP backdoor route\n"
4366 "AS-Path hopcount limit attribute\n"
4367 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4368ALIAS_DEPRECATED (bgp_network_mask,
4369 bgp_network_mask_ttl_cmd,
4370 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4371 "Specify a network to announce via BGP\n"
4372 "Network number\n"
4373 "Network mask\n"
4374 "Network mask\n"
4375 "AS-Path hopcount limit attribute\n"
4376 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4377ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4378 bgp_network_mask_backdoor_ttl_cmd,
4379 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4380 "Specify a network to announce via BGP\n"
4381 "Network number\n"
4382 "Network mask\n"
4383 "Network mask\n"
4384 "Specify a BGP backdoor route\n"
4385 "AS-Path hopcount limit attribute\n"
4386 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4387ALIAS_DEPRECATED (bgp_network_mask_natural,
4388 bgp_network_mask_natural_ttl_cmd,
4389 "network A.B.C.D pathlimit <0-255>",
4390 "Specify a network to announce via BGP\n"
4391 "Network number\n"
4392 "AS-Path hopcount limit attribute\n"
4393 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4394ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4395 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004396 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004397 "Specify a network to announce via BGP\n"
4398 "Network number\n"
4399 "Specify a BGP backdoor route\n"
4400 "AS-Path hopcount limit attribute\n"
4401 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4402ALIAS_DEPRECATED (no_bgp_network,
4403 no_bgp_network_ttl_cmd,
4404 "no network A.B.C.D/M pathlimit <0-255>",
4405 NO_STR
4406 "Specify a network to announce via BGP\n"
4407 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4408 "AS-Path hopcount limit attribute\n"
4409 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4410ALIAS_DEPRECATED (no_bgp_network,
4411 no_bgp_network_backdoor_ttl_cmd,
4412 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4413 NO_STR
4414 "Specify a network to announce via BGP\n"
4415 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4416 "Specify a BGP backdoor route\n"
4417 "AS-Path hopcount limit attribute\n"
4418 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4419ALIAS_DEPRECATED (no_bgp_network,
4420 no_bgp_network_mask_ttl_cmd,
4421 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4422 NO_STR
4423 "Specify a network to announce via BGP\n"
4424 "Network number\n"
4425 "Network mask\n"
4426 "Network mask\n"
4427 "AS-Path hopcount limit attribute\n"
4428 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4429ALIAS_DEPRECATED (no_bgp_network_mask,
4430 no_bgp_network_mask_backdoor_ttl_cmd,
4431 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4432 NO_STR
4433 "Specify a network to announce via BGP\n"
4434 "Network number\n"
4435 "Network mask\n"
4436 "Network mask\n"
4437 "Specify a BGP backdoor route\n"
4438 "AS-Path hopcount limit attribute\n"
4439 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4440ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4441 no_bgp_network_mask_natural_ttl_cmd,
4442 "no network A.B.C.D pathlimit <0-255>",
4443 NO_STR
4444 "Specify a network to announce via BGP\n"
4445 "Network number\n"
4446 "AS-Path hopcount limit attribute\n"
4447 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4448ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4449 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4450 "no network A.B.C.D backdoor pathlimit <0-255>",
4451 NO_STR
4452 "Specify a network to announce via BGP\n"
4453 "Network number\n"
4454 "Specify a BGP backdoor route\n"
4455 "AS-Path hopcount limit attribute\n"
4456 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004457#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004458ALIAS_DEPRECATED (ipv6_bgp_network,
4459 ipv6_bgp_network_ttl_cmd,
4460 "network X:X::X:X/M pathlimit <0-255>",
4461 "Specify a network to announce via BGP\n"
4462 "IPv6 prefix <network>/<length>\n"
4463 "AS-Path hopcount limit attribute\n"
4464 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4465ALIAS_DEPRECATED (no_ipv6_bgp_network,
4466 no_ipv6_bgp_network_ttl_cmd,
4467 "no network X:X::X:X/M pathlimit <0-255>",
4468 NO_STR
4469 "Specify a network to announce via BGP\n"
4470 "IPv6 prefix <network>/<length>\n"
4471 "AS-Path hopcount limit attribute\n"
4472 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004473#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02004474
paul718e3742002-12-13 20:15:29 +00004475/* Aggreagete address:
4476
4477 advertise-map Set condition to advertise attribute
4478 as-set Generate AS set path information
4479 attribute-map Set attributes of aggregate
4480 route-map Set parameters of aggregate
4481 summary-only Filter more specific routes from updates
4482 suppress-map Conditionally filter more specific routes from updates
4483 <cr>
4484 */
4485struct bgp_aggregate
4486{
4487 /* Summary-only flag. */
4488 u_char summary_only;
4489
4490 /* AS set generation. */
4491 u_char as_set;
4492
4493 /* Route-map for aggregated route. */
4494 struct route_map *map;
4495
4496 /* Suppress-count. */
4497 unsigned long count;
4498
4499 /* SAFI configuration. */
4500 safi_t safi;
4501};
4502
paul94f2b392005-06-28 12:44:16 +00004503static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004504bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004505{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004506 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004507}
4508
paul94f2b392005-06-28 12:44:16 +00004509static void
paul718e3742002-12-13 20:15:29 +00004510bgp_aggregate_free (struct bgp_aggregate *aggregate)
4511{
4512 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4513}
4514
paul94f2b392005-06-28 12:44:16 +00004515static void
paul718e3742002-12-13 20:15:29 +00004516bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4517 afi_t afi, safi_t safi, struct bgp_info *del,
4518 struct bgp_aggregate *aggregate)
4519{
4520 struct bgp_table *table;
4521 struct bgp_node *top;
4522 struct bgp_node *rn;
4523 u_char origin;
4524 struct aspath *aspath = NULL;
4525 struct aspath *asmerge = NULL;
4526 struct community *community = NULL;
4527 struct community *commerge = NULL;
4528 struct in_addr nexthop;
4529 u_int32_t med = 0;
4530 struct bgp_info *ri;
4531 struct bgp_info *new;
4532 int first = 1;
4533 unsigned long match = 0;
4534
4535 /* Record adding route's nexthop and med. */
4536 if (rinew)
4537 {
4538 nexthop = rinew->attr->nexthop;
4539 med = rinew->attr->med;
4540 }
4541
4542 /* ORIGIN attribute: If at least one route among routes that are
4543 aggregated has ORIGIN with the value INCOMPLETE, then the
4544 aggregated route must have the ORIGIN attribute with the value
4545 INCOMPLETE. Otherwise, if at least one route among routes that
4546 are aggregated has ORIGIN with the value EGP, then the aggregated
4547 route must have the origin attribute with the value EGP. In all
4548 other case the value of the ORIGIN attribute of the aggregated
4549 route is INTERNAL. */
4550 origin = BGP_ORIGIN_IGP;
4551
4552 table = bgp->rib[afi][safi];
4553
4554 top = bgp_node_get (table, p);
4555 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4556 if (rn->p.prefixlen > p->prefixlen)
4557 {
4558 match = 0;
4559
4560 for (ri = rn->info; ri; ri = ri->next)
4561 {
4562 if (BGP_INFO_HOLDDOWN (ri))
4563 continue;
4564
4565 if (del && ri == del)
4566 continue;
4567
4568 if (! rinew && first)
4569 {
4570 nexthop = ri->attr->nexthop;
4571 med = ri->attr->med;
4572 first = 0;
4573 }
4574
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,
7921#ifdef HAVE_IPV6
7922 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7923#else
7924 "show bgp view WORD ipv4 (unicast|multicast) community",
7925#endif
7926 SHOW_STR
7927 BGP_STR
7928 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007929 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007930 "Address family\n"
7931#ifdef HAVE_IPV6
7932 "Address family\n"
7933#endif
7934 "Address Family modifier\n"
7935 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00007936 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007937{
7938 int afi;
7939 int safi;
7940 struct bgp *bgp;
7941
7942 /* BGP structure lookup. */
7943 bgp = bgp_lookup_by_name (argv[0]);
7944 if (bgp == NULL)
7945 {
7946 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7947 return CMD_WARNING;
7948 }
7949
7950#ifdef HAVE_IPV6
7951 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7952 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7953#else
7954 afi = AFI_IP;
7955 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7956#endif
7957 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7958}
7959
7960DEFUN (show_bgp_view_afi_safi_community,
7961 show_bgp_view_afi_safi_community_cmd,
7962#ifdef HAVE_IPV6
7963 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7964#else
7965 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7966#endif
7967 SHOW_STR
7968 BGP_STR
7969 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007970 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007971 "Address family\n"
7972#ifdef HAVE_IPV6
7973 "Address family\n"
7974#endif
7975 "Address family modifier\n"
7976 "Address family modifier\n"
7977 "Display routes matching the communities\n"
7978 "community number\n"
7979 "Do not send outside local AS (well-known community)\n"
7980 "Do not advertise to any peer (well-known community)\n"
7981 "Do not export to next AS (well-known community)\n")
7982{
7983 int afi;
7984 int safi;
7985
7986#ifdef HAVE_IPV6
7987 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7988 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7989 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7990#else
7991 afi = AFI_IP;
7992 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7993 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
7994#endif
7995}
7996
7997ALIAS (show_bgp_view_afi_safi_community,
7998 show_bgp_view_afi_safi_community2_cmd,
7999#ifdef HAVE_IPV6
8000 "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)",
8001#else
8002 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8003#endif
8004 SHOW_STR
8005 BGP_STR
8006 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008007 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008008 "Address family\n"
8009#ifdef HAVE_IPV6
8010 "Address family\n"
8011#endif
8012 "Address family modifier\n"
8013 "Address family modifier\n"
8014 "Display routes matching the communities\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 "community number\n"
8020 "Do not send outside local AS (well-known community)\n"
8021 "Do not advertise to any peer (well-known community)\n"
8022 "Do not export to next AS (well-known community)\n")
8023
8024ALIAS (show_bgp_view_afi_safi_community,
8025 show_bgp_view_afi_safi_community3_cmd,
8026#ifdef HAVE_IPV6
8027 "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)",
8028#else
8029 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8030#endif
8031 SHOW_STR
8032 BGP_STR
8033 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008034 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008035 "Address family\n"
8036#ifdef HAVE_IPV6
8037 "Address family\n"
8038#endif
8039 "Address family modifier\n"
8040 "Address family modifier\n"
8041 "Display routes matching the communities\n"
8042 "community number\n"
8043 "Do not send outside local AS (well-known community)\n"
8044 "Do not advertise to any peer (well-known community)\n"
8045 "Do not export to next AS (well-known community)\n"
8046 "community number\n"
8047 "Do not send outside local AS (well-known community)\n"
8048 "Do not advertise to any peer (well-known community)\n"
8049 "Do not export to next AS (well-known community)\n"
8050 "community number\n"
8051 "Do not send outside local AS (well-known community)\n"
8052 "Do not advertise to any peer (well-known community)\n"
8053 "Do not export to next AS (well-known community)\n")
8054
8055ALIAS (show_bgp_view_afi_safi_community,
8056 show_bgp_view_afi_safi_community4_cmd,
8057#ifdef HAVE_IPV6
8058 "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)",
8059#else
8060 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8061#endif
8062 SHOW_STR
8063 BGP_STR
8064 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008065 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008066 "Address family\n"
8067#ifdef HAVE_IPV6
8068 "Address family\n"
8069#endif
8070 "Address family modifier\n"
8071 "Address family modifier\n"
8072 "Display routes matching the communities\n"
8073 "community number\n"
8074 "Do not send outside local AS (well-known community)\n"
8075 "Do not advertise to any peer (well-known community)\n"
8076 "Do not export to next AS (well-known community)\n"
8077 "community number\n"
8078 "Do not send outside local AS (well-known community)\n"
8079 "Do not advertise to any peer (well-known community)\n"
8080 "Do not export to next AS (well-known community)\n"
8081 "community number\n"
8082 "Do not send outside local AS (well-known community)\n"
8083 "Do not advertise to any peer (well-known community)\n"
8084 "Do not export to next AS (well-known community)\n"
8085 "community number\n"
8086 "Do not send outside local AS (well-known community)\n"
8087 "Do not advertise to any peer (well-known community)\n"
8088 "Do not export to next AS (well-known community)\n")
8089
paul718e3742002-12-13 20:15:29 +00008090DEFUN (show_ip_bgp_community_exact,
8091 show_ip_bgp_community_exact_cmd,
8092 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8093 SHOW_STR
8094 IP_STR
8095 BGP_STR
8096 "Display routes matching the communities\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{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008103 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008104}
8105
8106ALIAS (show_ip_bgp_community_exact,
8107 show_ip_bgp_community2_exact_cmd,
8108 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8109 SHOW_STR
8110 IP_STR
8111 BGP_STR
8112 "Display routes matching the communities\n"
8113 "community number\n"
8114 "Do not send outside local AS (well-known community)\n"
8115 "Do not advertise to any peer (well-known community)\n"
8116 "Do not export to next AS (well-known community)\n"
8117 "community number\n"
8118 "Do not send outside local AS (well-known community)\n"
8119 "Do not advertise to any peer (well-known community)\n"
8120 "Do not export to next AS (well-known community)\n"
8121 "Exact match of the communities")
8122
8123ALIAS (show_ip_bgp_community_exact,
8124 show_ip_bgp_community3_exact_cmd,
8125 "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",
8126 SHOW_STR
8127 IP_STR
8128 BGP_STR
8129 "Display routes matching the communities\n"
8130 "community number\n"
8131 "Do not send outside local AS (well-known community)\n"
8132 "Do not advertise to any peer (well-known community)\n"
8133 "Do not export to next AS (well-known community)\n"
8134 "community number\n"
8135 "Do not send outside local AS (well-known community)\n"
8136 "Do not advertise to any peer (well-known community)\n"
8137 "Do not export to next AS (well-known community)\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
8144ALIAS (show_ip_bgp_community_exact,
8145 show_ip_bgp_community4_exact_cmd,
8146 "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",
8147 SHOW_STR
8148 IP_STR
8149 BGP_STR
8150 "Display routes matching the communities\n"
8151 "community number\n"
8152 "Do not send outside local AS (well-known community)\n"
8153 "Do not advertise to any peer (well-known community)\n"
8154 "Do not export to next AS (well-known community)\n"
8155 "community number\n"
8156 "Do not send outside local AS (well-known community)\n"
8157 "Do not advertise to any peer (well-known community)\n"
8158 "Do not export to next AS (well-known community)\n"
8159 "community number\n"
8160 "Do not send outside local AS (well-known community)\n"
8161 "Do not advertise to any peer (well-known community)\n"
8162 "Do not export to next AS (well-known community)\n"
8163 "community number\n"
8164 "Do not send outside local AS (well-known community)\n"
8165 "Do not advertise to any peer (well-known community)\n"
8166 "Do not export to next AS (well-known community)\n"
8167 "Exact match of the communities")
8168
8169DEFUN (show_ip_bgp_ipv4_community_exact,
8170 show_ip_bgp_ipv4_community_exact_cmd,
8171 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8172 SHOW_STR
8173 IP_STR
8174 BGP_STR
8175 "Address family\n"
8176 "Address Family modifier\n"
8177 "Address Family modifier\n"
8178 "Display routes matching the communities\n"
8179 "community number\n"
8180 "Do not send outside local AS (well-known community)\n"
8181 "Do not advertise to any peer (well-known community)\n"
8182 "Do not export to next AS (well-known community)\n"
8183 "Exact match of the communities")
8184{
8185 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008186 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008187
Michael Lambert95cbbd22010-07-23 14:43:04 -04008188 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008189}
8190
8191ALIAS (show_ip_bgp_ipv4_community_exact,
8192 show_ip_bgp_ipv4_community2_exact_cmd,
8193 "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",
8194 SHOW_STR
8195 IP_STR
8196 BGP_STR
8197 "Address family\n"
8198 "Address Family modifier\n"
8199 "Address Family modifier\n"
8200 "Display routes matching the communities\n"
8201 "community number\n"
8202 "Do not send outside local AS (well-known community)\n"
8203 "Do not advertise to any peer (well-known community)\n"
8204 "Do not export to next AS (well-known community)\n"
8205 "community number\n"
8206 "Do not send outside local AS (well-known community)\n"
8207 "Do not advertise to any peer (well-known community)\n"
8208 "Do not export to next AS (well-known community)\n"
8209 "Exact match of the communities")
8210
8211ALIAS (show_ip_bgp_ipv4_community_exact,
8212 show_ip_bgp_ipv4_community3_exact_cmd,
8213 "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",
8214 SHOW_STR
8215 IP_STR
8216 BGP_STR
8217 "Address family\n"
8218 "Address Family modifier\n"
8219 "Address Family modifier\n"
8220 "Display routes matching the communities\n"
8221 "community number\n"
8222 "Do not send outside local AS (well-known community)\n"
8223 "Do not advertise to any peer (well-known community)\n"
8224 "Do not export to next AS (well-known community)\n"
8225 "community number\n"
8226 "Do not send outside local AS (well-known community)\n"
8227 "Do not advertise to any peer (well-known community)\n"
8228 "Do not export to next AS (well-known community)\n"
8229 "community number\n"
8230 "Do not send outside local AS (well-known community)\n"
8231 "Do not advertise to any peer (well-known community)\n"
8232 "Do not export to next AS (well-known community)\n"
8233 "Exact match of the communities")
8234
8235ALIAS (show_ip_bgp_ipv4_community_exact,
8236 show_ip_bgp_ipv4_community4_exact_cmd,
8237 "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",
8238 SHOW_STR
8239 IP_STR
8240 BGP_STR
8241 "Address family\n"
8242 "Address Family modifier\n"
8243 "Address Family modifier\n"
8244 "Display routes matching the communities\n"
8245 "community number\n"
8246 "Do not send outside local AS (well-known community)\n"
8247 "Do not advertise to any peer (well-known community)\n"
8248 "Do not export to next AS (well-known community)\n"
8249 "community number\n"
8250 "Do not send outside local AS (well-known community)\n"
8251 "Do not advertise to any peer (well-known community)\n"
8252 "Do not export to next AS (well-known community)\n"
8253 "community number\n"
8254 "Do not send outside local AS (well-known community)\n"
8255 "Do not advertise to any peer (well-known community)\n"
8256 "Do not export to next AS (well-known community)\n"
8257 "community number\n"
8258 "Do not send outside local AS (well-known community)\n"
8259 "Do not advertise to any peer (well-known community)\n"
8260 "Do not export to next AS (well-known community)\n"
8261 "Exact match of the communities")
8262
8263#ifdef HAVE_IPV6
8264DEFUN (show_bgp_community,
8265 show_bgp_community_cmd,
8266 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8267 SHOW_STR
8268 BGP_STR
8269 "Display routes matching the communities\n"
8270 "community number\n"
8271 "Do not send outside local AS (well-known community)\n"
8272 "Do not advertise to any peer (well-known community)\n"
8273 "Do not export to next AS (well-known community)\n")
8274{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008275 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008276}
8277
8278ALIAS (show_bgp_community,
8279 show_bgp_ipv6_community_cmd,
8280 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8281 SHOW_STR
8282 BGP_STR
8283 "Address family\n"
8284 "Display routes matching the communities\n"
8285 "community number\n"
8286 "Do not send outside local AS (well-known community)\n"
8287 "Do not advertise to any peer (well-known community)\n"
8288 "Do not export to next AS (well-known community)\n")
8289
8290ALIAS (show_bgp_community,
8291 show_bgp_community2_cmd,
8292 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8293 SHOW_STR
8294 BGP_STR
8295 "Display routes matching the communities\n"
8296 "community number\n"
8297 "Do not send outside local AS (well-known community)\n"
8298 "Do not advertise to any peer (well-known community)\n"
8299 "Do not export to next AS (well-known community)\n"
8300 "community number\n"
8301 "Do not send outside local AS (well-known community)\n"
8302 "Do not advertise to any peer (well-known community)\n"
8303 "Do not export to next AS (well-known community)\n")
8304
8305ALIAS (show_bgp_community,
8306 show_bgp_ipv6_community2_cmd,
8307 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8308 SHOW_STR
8309 BGP_STR
8310 "Address family\n"
8311 "Display routes matching the communities\n"
8312 "community number\n"
8313 "Do not send outside local AS (well-known community)\n"
8314 "Do not advertise to any peer (well-known community)\n"
8315 "Do not export to next AS (well-known community)\n"
8316 "community number\n"
8317 "Do not send outside local AS (well-known community)\n"
8318 "Do not advertise to any peer (well-known community)\n"
8319 "Do not export to next AS (well-known community)\n")
8320
8321ALIAS (show_bgp_community,
8322 show_bgp_community3_cmd,
8323 "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)",
8324 SHOW_STR
8325 BGP_STR
8326 "Display routes matching the communities\n"
8327 "community number\n"
8328 "Do not send outside local AS (well-known community)\n"
8329 "Do not advertise to any peer (well-known community)\n"
8330 "Do not export to next AS (well-known community)\n"
8331 "community number\n"
8332 "Do not send outside local AS (well-known community)\n"
8333 "Do not advertise to any peer (well-known community)\n"
8334 "Do not export to next AS (well-known community)\n"
8335 "community number\n"
8336 "Do not send outside local AS (well-known community)\n"
8337 "Do not advertise to any peer (well-known community)\n"
8338 "Do not export to next AS (well-known community)\n")
8339
8340ALIAS (show_bgp_community,
8341 show_bgp_ipv6_community3_cmd,
8342 "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)",
8343 SHOW_STR
8344 BGP_STR
8345 "Address family\n"
8346 "Display routes matching the communities\n"
8347 "community number\n"
8348 "Do not send outside local AS (well-known community)\n"
8349 "Do not advertise to any peer (well-known community)\n"
8350 "Do not export to next AS (well-known community)\n"
8351 "community number\n"
8352 "Do not send outside local AS (well-known community)\n"
8353 "Do not advertise to any peer (well-known community)\n"
8354 "Do not export to next AS (well-known community)\n"
8355 "community number\n"
8356 "Do not send outside local AS (well-known community)\n"
8357 "Do not advertise to any peer (well-known community)\n"
8358 "Do not export to next AS (well-known community)\n")
8359
8360ALIAS (show_bgp_community,
8361 show_bgp_community4_cmd,
8362 "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)",
8363 SHOW_STR
8364 BGP_STR
8365 "Display routes matching the communities\n"
8366 "community number\n"
8367 "Do not send outside local AS (well-known community)\n"
8368 "Do not advertise to any peer (well-known community)\n"
8369 "Do not export to next AS (well-known community)\n"
8370 "community number\n"
8371 "Do not send outside local AS (well-known community)\n"
8372 "Do not advertise to any peer (well-known community)\n"
8373 "Do not export to next AS (well-known community)\n"
8374 "community number\n"
8375 "Do not send outside local AS (well-known community)\n"
8376 "Do not advertise to any peer (well-known community)\n"
8377 "Do not export to next AS (well-known community)\n"
8378 "community number\n"
8379 "Do not send outside local AS (well-known community)\n"
8380 "Do not advertise to any peer (well-known community)\n"
8381 "Do not export to next AS (well-known community)\n")
8382
8383ALIAS (show_bgp_community,
8384 show_bgp_ipv6_community4_cmd,
8385 "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)",
8386 SHOW_STR
8387 BGP_STR
8388 "Address family\n"
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 "community number\n"
8399 "Do not send outside local AS (well-known community)\n"
8400 "Do not advertise to any peer (well-known community)\n"
8401 "Do not export to next AS (well-known community)\n"
8402 "community number\n"
8403 "Do not send outside local AS (well-known community)\n"
8404 "Do not advertise to any peer (well-known community)\n"
8405 "Do not export to next AS (well-known community)\n")
8406
8407/* old command */
8408DEFUN (show_ipv6_bgp_community,
8409 show_ipv6_bgp_community_cmd,
8410 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8411 SHOW_STR
8412 IPV6_STR
8413 BGP_STR
8414 "Display routes matching the communities\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{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008420 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008421}
8422
8423/* old command */
8424ALIAS (show_ipv6_bgp_community,
8425 show_ipv6_bgp_community2_cmd,
8426 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8427 SHOW_STR
8428 IPV6_STR
8429 BGP_STR
8430 "Display routes matching the communities\n"
8431 "community number\n"
8432 "Do not send outside local AS (well-known community)\n"
8433 "Do not advertise to any peer (well-known community)\n"
8434 "Do not export to next AS (well-known community)\n"
8435 "community number\n"
8436 "Do not send outside local AS (well-known community)\n"
8437 "Do not advertise to any peer (well-known community)\n"
8438 "Do not export to next AS (well-known community)\n")
8439
8440/* old command */
8441ALIAS (show_ipv6_bgp_community,
8442 show_ipv6_bgp_community3_cmd,
8443 "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)",
8444 SHOW_STR
8445 IPV6_STR
8446 BGP_STR
8447 "Display routes matching the communities\n"
8448 "community number\n"
8449 "Do not send outside local AS (well-known community)\n"
8450 "Do not advertise to any peer (well-known community)\n"
8451 "Do not export to next AS (well-known community)\n"
8452 "community number\n"
8453 "Do not send outside local AS (well-known community)\n"
8454 "Do not advertise to any peer (well-known community)\n"
8455 "Do not export to next AS (well-known community)\n"
8456 "community number\n"
8457 "Do not send outside local AS (well-known community)\n"
8458 "Do not advertise to any peer (well-known community)\n"
8459 "Do not export to next AS (well-known community)\n")
8460
8461/* old command */
8462ALIAS (show_ipv6_bgp_community,
8463 show_ipv6_bgp_community4_cmd,
8464 "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)",
8465 SHOW_STR
8466 IPV6_STR
8467 BGP_STR
8468 "Display routes matching the communities\n"
8469 "community number\n"
8470 "Do not send outside local AS (well-known community)\n"
8471 "Do not advertise to any peer (well-known community)\n"
8472 "Do not export to next AS (well-known community)\n"
8473 "community number\n"
8474 "Do not send outside local AS (well-known community)\n"
8475 "Do not advertise to any peer (well-known community)\n"
8476 "Do not export to next AS (well-known community)\n"
8477 "community number\n"
8478 "Do not send outside local AS (well-known community)\n"
8479 "Do not advertise to any peer (well-known community)\n"
8480 "Do not export to next AS (well-known community)\n"
8481 "community number\n"
8482 "Do not send outside local AS (well-known community)\n"
8483 "Do not advertise to any peer (well-known community)\n"
8484 "Do not export to next AS (well-known community)\n")
8485
8486DEFUN (show_bgp_community_exact,
8487 show_bgp_community_exact_cmd,
8488 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8489 SHOW_STR
8490 BGP_STR
8491 "Display routes matching the communities\n"
8492 "community number\n"
8493 "Do not send outside local AS (well-known community)\n"
8494 "Do not advertise to any peer (well-known community)\n"
8495 "Do not export to next AS (well-known community)\n"
8496 "Exact match of the communities")
8497{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008498 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008499}
8500
8501ALIAS (show_bgp_community_exact,
8502 show_bgp_ipv6_community_exact_cmd,
8503 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8504 SHOW_STR
8505 BGP_STR
8506 "Address family\n"
8507 "Display routes matching the communities\n"
8508 "community number\n"
8509 "Do not send outside local AS (well-known community)\n"
8510 "Do not advertise to any peer (well-known community)\n"
8511 "Do not export to next AS (well-known community)\n"
8512 "Exact match of the communities")
8513
8514ALIAS (show_bgp_community_exact,
8515 show_bgp_community2_exact_cmd,
8516 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8517 SHOW_STR
8518 BGP_STR
8519 "Display routes matching the communities\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 "community number\n"
8525 "Do not send outside local AS (well-known community)\n"
8526 "Do not advertise to any peer (well-known community)\n"
8527 "Do not export to next AS (well-known community)\n"
8528 "Exact match of the communities")
8529
8530ALIAS (show_bgp_community_exact,
8531 show_bgp_ipv6_community2_exact_cmd,
8532 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8533 SHOW_STR
8534 BGP_STR
8535 "Address family\n"
8536 "Display routes matching the communities\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_community3_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) 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 "Exact match of the communities")
8566
8567ALIAS (show_bgp_community_exact,
8568 show_bgp_ipv6_community3_exact_cmd,
8569 "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",
8570 SHOW_STR
8571 BGP_STR
8572 "Address family\n"
8573 "Display routes matching the communities\n"
8574 "community number\n"
8575 "Do not send outside local AS (well-known community)\n"
8576 "Do not advertise to any peer (well-known community)\n"
8577 "Do not export to next AS (well-known community)\n"
8578 "community number\n"
8579 "Do not send outside local AS (well-known community)\n"
8580 "Do not advertise to any peer (well-known community)\n"
8581 "Do not export to next AS (well-known community)\n"
8582 "community number\n"
8583 "Do not send outside local AS (well-known community)\n"
8584 "Do not advertise to any peer (well-known community)\n"
8585 "Do not export to next AS (well-known community)\n"
8586 "Exact match of the communities")
8587
8588ALIAS (show_bgp_community_exact,
8589 show_bgp_community4_exact_cmd,
8590 "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",
8591 SHOW_STR
8592 BGP_STR
8593 "Display routes matching the communities\n"
8594 "community number\n"
8595 "Do not send outside local AS (well-known community)\n"
8596 "Do not advertise to any peer (well-known community)\n"
8597 "Do not export to next AS (well-known community)\n"
8598 "community number\n"
8599 "Do not send outside local AS (well-known community)\n"
8600 "Do not advertise to any peer (well-known community)\n"
8601 "Do not export to next AS (well-known community)\n"
8602 "community number\n"
8603 "Do not send outside local AS (well-known community)\n"
8604 "Do not advertise to any peer (well-known community)\n"
8605 "Do not export to next AS (well-known community)\n"
8606 "community number\n"
8607 "Do not send outside local AS (well-known community)\n"
8608 "Do not advertise to any peer (well-known community)\n"
8609 "Do not export to next AS (well-known community)\n"
8610 "Exact match of the communities")
8611
8612ALIAS (show_bgp_community_exact,
8613 show_bgp_ipv6_community4_exact_cmd,
8614 "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",
8615 SHOW_STR
8616 BGP_STR
8617 "Address family\n"
8618 "Display routes matching the communities\n"
8619 "community number\n"
8620 "Do not send outside local AS (well-known community)\n"
8621 "Do not advertise to any peer (well-known community)\n"
8622 "Do not export to next AS (well-known community)\n"
8623 "community number\n"
8624 "Do not send outside local AS (well-known community)\n"
8625 "Do not advertise to any peer (well-known community)\n"
8626 "Do not export to next AS (well-known community)\n"
8627 "community number\n"
8628 "Do not send outside local AS (well-known community)\n"
8629 "Do not advertise to any peer (well-known community)\n"
8630 "Do not export to next AS (well-known community)\n"
8631 "community number\n"
8632 "Do not send outside local AS (well-known community)\n"
8633 "Do not advertise to any peer (well-known community)\n"
8634 "Do not export to next AS (well-known community)\n"
8635 "Exact match of the communities")
8636
8637/* old command */
8638DEFUN (show_ipv6_bgp_community_exact,
8639 show_ipv6_bgp_community_exact_cmd,
8640 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8641 SHOW_STR
8642 IPV6_STR
8643 BGP_STR
8644 "Display routes matching the communities\n"
8645 "community number\n"
8646 "Do not send outside local AS (well-known community)\n"
8647 "Do not advertise to any peer (well-known community)\n"
8648 "Do not export to next AS (well-known community)\n"
8649 "Exact match of the communities")
8650{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008651 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008652}
8653
8654/* old command */
8655ALIAS (show_ipv6_bgp_community_exact,
8656 show_ipv6_bgp_community2_exact_cmd,
8657 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8658 SHOW_STR
8659 IPV6_STR
8660 BGP_STR
8661 "Display routes matching the communities\n"
8662 "community number\n"
8663 "Do not send outside local AS (well-known community)\n"
8664 "Do not advertise to any peer (well-known community)\n"
8665 "Do not export to next AS (well-known community)\n"
8666 "community number\n"
8667 "Do not send outside local AS (well-known community)\n"
8668 "Do not advertise to any peer (well-known community)\n"
8669 "Do not export to next AS (well-known community)\n"
8670 "Exact match of the communities")
8671
8672/* old command */
8673ALIAS (show_ipv6_bgp_community_exact,
8674 show_ipv6_bgp_community3_exact_cmd,
8675 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8676 SHOW_STR
8677 IPV6_STR
8678 BGP_STR
8679 "Display routes matching the communities\n"
8680 "community number\n"
8681 "Do not send outside local AS (well-known community)\n"
8682 "Do not advertise to any peer (well-known community)\n"
8683 "Do not export to next AS (well-known community)\n"
8684 "community number\n"
8685 "Do not send outside local AS (well-known community)\n"
8686 "Do not advertise to any peer (well-known community)\n"
8687 "Do not export to next AS (well-known community)\n"
8688 "community number\n"
8689 "Do not send outside local AS (well-known community)\n"
8690 "Do not advertise to any peer (well-known community)\n"
8691 "Do not export to next AS (well-known community)\n"
8692 "Exact match of the communities")
8693
8694/* old command */
8695ALIAS (show_ipv6_bgp_community_exact,
8696 show_ipv6_bgp_community4_exact_cmd,
8697 "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",
8698 SHOW_STR
8699 IPV6_STR
8700 BGP_STR
8701 "Display routes matching the communities\n"
8702 "community number\n"
8703 "Do not send outside local AS (well-known community)\n"
8704 "Do not advertise to any peer (well-known community)\n"
8705 "Do not export to next AS (well-known community)\n"
8706 "community number\n"
8707 "Do not send outside local AS (well-known community)\n"
8708 "Do not advertise to any peer (well-known community)\n"
8709 "Do not export to next AS (well-known community)\n"
8710 "community number\n"
8711 "Do not send outside local AS (well-known community)\n"
8712 "Do not advertise to any peer (well-known community)\n"
8713 "Do not export to next AS (well-known community)\n"
8714 "community number\n"
8715 "Do not send outside local AS (well-known community)\n"
8716 "Do not advertise to any peer (well-known community)\n"
8717 "Do not export to next AS (well-known community)\n"
8718 "Exact match of the communities")
8719
8720/* old command */
8721DEFUN (show_ipv6_mbgp_community,
8722 show_ipv6_mbgp_community_cmd,
8723 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8724 SHOW_STR
8725 IPV6_STR
8726 MBGP_STR
8727 "Display routes matching the communities\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{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008733 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008734}
8735
8736/* old command */
8737ALIAS (show_ipv6_mbgp_community,
8738 show_ipv6_mbgp_community2_cmd,
8739 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8740 SHOW_STR
8741 IPV6_STR
8742 MBGP_STR
8743 "Display routes matching the communities\n"
8744 "community number\n"
8745 "Do not send outside local AS (well-known community)\n"
8746 "Do not advertise to any peer (well-known community)\n"
8747 "Do not export to next AS (well-known community)\n"
8748 "community number\n"
8749 "Do not send outside local AS (well-known community)\n"
8750 "Do not advertise to any peer (well-known community)\n"
8751 "Do not export to next AS (well-known community)\n")
8752
8753/* old command */
8754ALIAS (show_ipv6_mbgp_community,
8755 show_ipv6_mbgp_community3_cmd,
8756 "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)",
8757 SHOW_STR
8758 IPV6_STR
8759 MBGP_STR
8760 "Display routes matching the communities\n"
8761 "community number\n"
8762 "Do not send outside local AS (well-known community)\n"
8763 "Do not advertise to any peer (well-known community)\n"
8764 "Do not export to next AS (well-known community)\n"
8765 "community number\n"
8766 "Do not send outside local AS (well-known community)\n"
8767 "Do not advertise to any peer (well-known community)\n"
8768 "Do not export to next AS (well-known community)\n"
8769 "community number\n"
8770 "Do not send outside local AS (well-known community)\n"
8771 "Do not advertise to any peer (well-known community)\n"
8772 "Do not export to next AS (well-known community)\n")
8773
8774/* old command */
8775ALIAS (show_ipv6_mbgp_community,
8776 show_ipv6_mbgp_community4_cmd,
8777 "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)",
8778 SHOW_STR
8779 IPV6_STR
8780 MBGP_STR
8781 "Display routes matching the communities\n"
8782 "community number\n"
8783 "Do not send outside local AS (well-known community)\n"
8784 "Do not advertise to any peer (well-known community)\n"
8785 "Do not export to next AS (well-known community)\n"
8786 "community number\n"
8787 "Do not send outside local AS (well-known community)\n"
8788 "Do not advertise to any peer (well-known community)\n"
8789 "Do not export to next AS (well-known community)\n"
8790 "community number\n"
8791 "Do not send outside local AS (well-known community)\n"
8792 "Do not advertise to any peer (well-known community)\n"
8793 "Do not export to next AS (well-known community)\n"
8794 "community number\n"
8795 "Do not send outside local AS (well-known community)\n"
8796 "Do not advertise to any peer (well-known community)\n"
8797 "Do not export to next AS (well-known community)\n")
8798
8799/* old command */
8800DEFUN (show_ipv6_mbgp_community_exact,
8801 show_ipv6_mbgp_community_exact_cmd,
8802 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8803 SHOW_STR
8804 IPV6_STR
8805 MBGP_STR
8806 "Display routes matching the communities\n"
8807 "community number\n"
8808 "Do not send outside local AS (well-known community)\n"
8809 "Do not advertise to any peer (well-known community)\n"
8810 "Do not export to next AS (well-known community)\n"
8811 "Exact match of the communities")
8812{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008813 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008814}
8815
8816/* old command */
8817ALIAS (show_ipv6_mbgp_community_exact,
8818 show_ipv6_mbgp_community2_exact_cmd,
8819 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8820 SHOW_STR
8821 IPV6_STR
8822 MBGP_STR
8823 "Display routes matching the communities\n"
8824 "community number\n"
8825 "Do not send outside local AS (well-known community)\n"
8826 "Do not advertise to any peer (well-known community)\n"
8827 "Do not export to next AS (well-known community)\n"
8828 "community number\n"
8829 "Do not send outside local AS (well-known community)\n"
8830 "Do not advertise to any peer (well-known community)\n"
8831 "Do not export to next AS (well-known community)\n"
8832 "Exact match of the communities")
8833
8834/* old command */
8835ALIAS (show_ipv6_mbgp_community_exact,
8836 show_ipv6_mbgp_community3_exact_cmd,
8837 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8838 SHOW_STR
8839 IPV6_STR
8840 MBGP_STR
8841 "Display routes matching the communities\n"
8842 "community number\n"
8843 "Do not send outside local AS (well-known community)\n"
8844 "Do not advertise to any peer (well-known community)\n"
8845 "Do not export to next AS (well-known community)\n"
8846 "community number\n"
8847 "Do not send outside local AS (well-known community)\n"
8848 "Do not advertise to any peer (well-known community)\n"
8849 "Do not export to next AS (well-known community)\n"
8850 "community number\n"
8851 "Do not send outside local AS (well-known community)\n"
8852 "Do not advertise to any peer (well-known community)\n"
8853 "Do not export to next AS (well-known community)\n"
8854 "Exact match of the communities")
8855
8856/* old command */
8857ALIAS (show_ipv6_mbgp_community_exact,
8858 show_ipv6_mbgp_community4_exact_cmd,
8859 "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",
8860 SHOW_STR
8861 IPV6_STR
8862 MBGP_STR
8863 "Display routes matching the communities\n"
8864 "community number\n"
8865 "Do not send outside local AS (well-known community)\n"
8866 "Do not advertise to any peer (well-known community)\n"
8867 "Do not export to next AS (well-known community)\n"
8868 "community number\n"
8869 "Do not send outside local AS (well-known community)\n"
8870 "Do not advertise to any peer (well-known community)\n"
8871 "Do not export to next AS (well-known community)\n"
8872 "community number\n"
8873 "Do not send outside local AS (well-known community)\n"
8874 "Do not advertise to any peer (well-known community)\n"
8875 "Do not export to next AS (well-known community)\n"
8876 "community number\n"
8877 "Do not send outside local AS (well-known community)\n"
8878 "Do not advertise to any peer (well-known community)\n"
8879 "Do not export to next AS (well-known community)\n"
8880 "Exact match of the communities")
8881#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02008882
paul94f2b392005-06-28 12:44:16 +00008883static int
paulfd79ac92004-10-13 05:06:08 +00008884bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008885 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008886{
8887 struct community_list *list;
8888
hassofee6e4e2005-02-02 16:29:31 +00008889 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008890 if (list == NULL)
8891 {
8892 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8893 VTY_NEWLINE);
8894 return CMD_WARNING;
8895 }
8896
ajs5a646652004-11-05 01:25:55 +00008897 return bgp_show (vty, NULL, afi, safi,
8898 (exact ? bgp_show_type_community_list_exact :
8899 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008900}
8901
8902DEFUN (show_ip_bgp_community_list,
8903 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008904 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008905 SHOW_STR
8906 IP_STR
8907 BGP_STR
8908 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008909 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008910 "community-list name\n")
8911{
8912 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8913}
8914
8915DEFUN (show_ip_bgp_ipv4_community_list,
8916 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008917 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008918 SHOW_STR
8919 IP_STR
8920 BGP_STR
8921 "Address family\n"
8922 "Address Family modifier\n"
8923 "Address Family modifier\n"
8924 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008925 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008926 "community-list name\n")
8927{
8928 if (strncmp (argv[0], "m", 1) == 0)
8929 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8930
8931 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8932}
8933
8934DEFUN (show_ip_bgp_community_list_exact,
8935 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008936 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008937 SHOW_STR
8938 IP_STR
8939 BGP_STR
8940 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008941 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008942 "community-list name\n"
8943 "Exact match of the communities\n")
8944{
8945 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8946}
8947
8948DEFUN (show_ip_bgp_ipv4_community_list_exact,
8949 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008950 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008951 SHOW_STR
8952 IP_STR
8953 BGP_STR
8954 "Address family\n"
8955 "Address Family modifier\n"
8956 "Address Family modifier\n"
8957 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008958 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008959 "community-list name\n"
8960 "Exact match of the communities\n")
8961{
8962 if (strncmp (argv[0], "m", 1) == 0)
8963 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8964
8965 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8966}
8967
8968#ifdef HAVE_IPV6
8969DEFUN (show_bgp_community_list,
8970 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008971 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008972 SHOW_STR
8973 BGP_STR
8974 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008975 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008976 "community-list name\n")
8977{
8978 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8979}
8980
8981ALIAS (show_bgp_community_list,
8982 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008983 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008984 SHOW_STR
8985 BGP_STR
8986 "Address family\n"
8987 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008988 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008989 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008990
8991/* old command */
8992DEFUN (show_ipv6_bgp_community_list,
8993 show_ipv6_bgp_community_list_cmd,
8994 "show ipv6 bgp community-list WORD",
8995 SHOW_STR
8996 IPV6_STR
8997 BGP_STR
8998 "Display routes matching the community-list\n"
8999 "community-list name\n")
9000{
9001 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9002}
9003
9004/* old command */
9005DEFUN (show_ipv6_mbgp_community_list,
9006 show_ipv6_mbgp_community_list_cmd,
9007 "show ipv6 mbgp community-list WORD",
9008 SHOW_STR
9009 IPV6_STR
9010 MBGP_STR
9011 "Display routes matching the community-list\n"
9012 "community-list name\n")
9013{
9014 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
9015}
9016
9017DEFUN (show_bgp_community_list_exact,
9018 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009019 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009020 SHOW_STR
9021 BGP_STR
9022 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009023 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009024 "community-list name\n"
9025 "Exact match of the communities\n")
9026{
9027 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9028}
9029
9030ALIAS (show_bgp_community_list_exact,
9031 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009032 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009033 SHOW_STR
9034 BGP_STR
9035 "Address family\n"
9036 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009037 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009038 "community-list name\n"
9039 "Exact match of the communities\n")
9040
9041/* old command */
9042DEFUN (show_ipv6_bgp_community_list_exact,
9043 show_ipv6_bgp_community_list_exact_cmd,
9044 "show ipv6 bgp community-list WORD exact-match",
9045 SHOW_STR
9046 IPV6_STR
9047 BGP_STR
9048 "Display routes matching the community-list\n"
9049 "community-list name\n"
9050 "Exact match of the communities\n")
9051{
9052 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9053}
9054
9055/* old command */
9056DEFUN (show_ipv6_mbgp_community_list_exact,
9057 show_ipv6_mbgp_community_list_exact_cmd,
9058 "show ipv6 mbgp community-list WORD exact-match",
9059 SHOW_STR
9060 IPV6_STR
9061 MBGP_STR
9062 "Display routes matching the community-list\n"
9063 "community-list name\n"
9064 "Exact match of the communities\n")
9065{
9066 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9067}
9068#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009069
paul94f2b392005-06-28 12:44:16 +00009070static int
paulfd79ac92004-10-13 05:06:08 +00009071bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009072 safi_t safi, enum bgp_show_type type)
9073{
9074 int ret;
9075 struct prefix *p;
9076
9077 p = prefix_new();
9078
9079 ret = str2prefix (prefix, p);
9080 if (! ret)
9081 {
9082 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9083 return CMD_WARNING;
9084 }
9085
ajs5a646652004-11-05 01:25:55 +00009086 ret = bgp_show (vty, NULL, afi, safi, type, p);
9087 prefix_free(p);
9088 return ret;
paul718e3742002-12-13 20:15:29 +00009089}
9090
9091DEFUN (show_ip_bgp_prefix_longer,
9092 show_ip_bgp_prefix_longer_cmd,
9093 "show ip bgp A.B.C.D/M longer-prefixes",
9094 SHOW_STR
9095 IP_STR
9096 BGP_STR
9097 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9098 "Display route and more specific routes\n")
9099{
9100 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9101 bgp_show_type_prefix_longer);
9102}
9103
9104DEFUN (show_ip_bgp_flap_prefix_longer,
9105 show_ip_bgp_flap_prefix_longer_cmd,
9106 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9107 SHOW_STR
9108 IP_STR
9109 BGP_STR
9110 "Display flap statistics of routes\n"
9111 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9112 "Display route and more specific routes\n")
9113{
9114 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9115 bgp_show_type_flap_prefix_longer);
9116}
9117
9118DEFUN (show_ip_bgp_ipv4_prefix_longer,
9119 show_ip_bgp_ipv4_prefix_longer_cmd,
9120 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9121 SHOW_STR
9122 IP_STR
9123 BGP_STR
9124 "Address family\n"
9125 "Address Family modifier\n"
9126 "Address Family modifier\n"
9127 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9128 "Display route and more specific routes\n")
9129{
9130 if (strncmp (argv[0], "m", 1) == 0)
9131 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9132 bgp_show_type_prefix_longer);
9133
9134 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9135 bgp_show_type_prefix_longer);
9136}
9137
9138DEFUN (show_ip_bgp_flap_address,
9139 show_ip_bgp_flap_address_cmd,
9140 "show ip bgp flap-statistics A.B.C.D",
9141 SHOW_STR
9142 IP_STR
9143 BGP_STR
9144 "Display flap statistics of routes\n"
9145 "Network in the BGP routing table to display\n")
9146{
9147 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9148 bgp_show_type_flap_address);
9149}
9150
9151DEFUN (show_ip_bgp_flap_prefix,
9152 show_ip_bgp_flap_prefix_cmd,
9153 "show ip bgp flap-statistics A.B.C.D/M",
9154 SHOW_STR
9155 IP_STR
9156 BGP_STR
9157 "Display flap statistics of routes\n"
9158 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9159{
9160 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9161 bgp_show_type_flap_prefix);
9162}
9163#ifdef HAVE_IPV6
9164DEFUN (show_bgp_prefix_longer,
9165 show_bgp_prefix_longer_cmd,
9166 "show bgp X:X::X:X/M longer-prefixes",
9167 SHOW_STR
9168 BGP_STR
9169 "IPv6 prefix <network>/<length>\n"
9170 "Display route and more specific routes\n")
9171{
9172 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9173 bgp_show_type_prefix_longer);
9174}
9175
9176ALIAS (show_bgp_prefix_longer,
9177 show_bgp_ipv6_prefix_longer_cmd,
9178 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9179 SHOW_STR
9180 BGP_STR
9181 "Address family\n"
9182 "IPv6 prefix <network>/<length>\n"
9183 "Display route and more specific routes\n")
9184
9185/* old command */
9186DEFUN (show_ipv6_bgp_prefix_longer,
9187 show_ipv6_bgp_prefix_longer_cmd,
9188 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9189 SHOW_STR
9190 IPV6_STR
9191 BGP_STR
9192 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9193 "Display route and more specific routes\n")
9194{
9195 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9196 bgp_show_type_prefix_longer);
9197}
9198
9199/* old command */
9200DEFUN (show_ipv6_mbgp_prefix_longer,
9201 show_ipv6_mbgp_prefix_longer_cmd,
9202 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9203 SHOW_STR
9204 IPV6_STR
9205 MBGP_STR
9206 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9207 "Display route and more specific routes\n")
9208{
9209 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9210 bgp_show_type_prefix_longer);
9211}
9212#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009213
paul94f2b392005-06-28 12:44:16 +00009214static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009215peer_lookup_in_view (struct vty *vty, const char *view_name,
9216 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009217{
9218 int ret;
9219 struct bgp *bgp;
9220 struct peer *peer;
9221 union sockunion su;
9222
9223 /* BGP structure lookup. */
9224 if (view_name)
9225 {
9226 bgp = bgp_lookup_by_name (view_name);
9227 if (! bgp)
9228 {
9229 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9230 return NULL;
9231 }
9232 }
paul5228ad22004-06-04 17:58:18 +00009233 else
paulbb46e942003-10-24 19:02:03 +00009234 {
9235 bgp = bgp_get_default ();
9236 if (! bgp)
9237 {
9238 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9239 return NULL;
9240 }
9241 }
9242
9243 /* Get peer sockunion. */
9244 ret = str2sockunion (ip_str, &su);
9245 if (ret < 0)
9246 {
9247 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9248 return NULL;
9249 }
9250
9251 /* Peer structure lookup. */
9252 peer = peer_lookup (bgp, &su);
9253 if (! peer)
9254 {
9255 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9256 return NULL;
9257 }
9258
9259 return peer;
9260}
David Lamparter6b0655a2014-06-04 06:53:35 +02009261
Paul Jakma2815e612006-09-14 02:56:07 +00009262enum bgp_stats
9263{
9264 BGP_STATS_MAXBITLEN = 0,
9265 BGP_STATS_RIB,
9266 BGP_STATS_PREFIXES,
9267 BGP_STATS_TOTPLEN,
9268 BGP_STATS_UNAGGREGATEABLE,
9269 BGP_STATS_MAX_AGGREGATEABLE,
9270 BGP_STATS_AGGREGATES,
9271 BGP_STATS_SPACE,
9272 BGP_STATS_ASPATH_COUNT,
9273 BGP_STATS_ASPATH_MAXHOPS,
9274 BGP_STATS_ASPATH_TOTHOPS,
9275 BGP_STATS_ASPATH_MAXSIZE,
9276 BGP_STATS_ASPATH_TOTSIZE,
9277 BGP_STATS_ASN_HIGHEST,
9278 BGP_STATS_MAX,
9279};
paulbb46e942003-10-24 19:02:03 +00009280
Paul Jakma2815e612006-09-14 02:56:07 +00009281static const char *table_stats_strs[] =
9282{
9283 [BGP_STATS_PREFIXES] = "Total Prefixes",
9284 [BGP_STATS_TOTPLEN] = "Average prefix length",
9285 [BGP_STATS_RIB] = "Total Advertisements",
9286 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9287 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9288 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9289 [BGP_STATS_SPACE] = "Address space advertised",
9290 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9291 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9292 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9293 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9294 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9295 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9296 [BGP_STATS_MAX] = NULL,
9297};
9298
9299struct bgp_table_stats
9300{
9301 struct bgp_table *table;
9302 unsigned long long counts[BGP_STATS_MAX];
9303};
9304
9305#if 0
9306#define TALLY_SIGFIG 100000
9307static unsigned long
9308ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9309{
9310 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9311 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9312 unsigned long ret = newtot / count;
9313
9314 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9315 return ret + 1;
9316 else
9317 return ret;
9318}
9319#endif
9320
9321static int
9322bgp_table_stats_walker (struct thread *t)
9323{
9324 struct bgp_node *rn;
9325 struct bgp_node *top;
9326 struct bgp_table_stats *ts = THREAD_ARG (t);
9327 unsigned int space = 0;
9328
Paul Jakma53d9f672006-10-15 23:41:16 +00009329 if (!(top = bgp_table_top (ts->table)))
9330 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009331
9332 switch (top->p.family)
9333 {
9334 case AF_INET:
9335 space = IPV4_MAX_BITLEN;
9336 break;
9337 case AF_INET6:
9338 space = IPV6_MAX_BITLEN;
9339 break;
9340 }
9341
9342 ts->counts[BGP_STATS_MAXBITLEN] = space;
9343
9344 for (rn = top; rn; rn = bgp_route_next (rn))
9345 {
9346 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009347 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009348 unsigned int rinum = 0;
9349
9350 if (rn == top)
9351 continue;
9352
9353 if (!rn->info)
9354 continue;
9355
9356 ts->counts[BGP_STATS_PREFIXES]++;
9357 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9358
9359#if 0
9360 ts->counts[BGP_STATS_AVGPLEN]
9361 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9362 ts->counts[BGP_STATS_AVGPLEN],
9363 rn->p.prefixlen);
9364#endif
9365
9366 /* check if the prefix is included by any other announcements */
9367 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009368 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009369
9370 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009371 {
9372 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9373 /* announced address space */
9374 if (space)
9375 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9376 }
Paul Jakma2815e612006-09-14 02:56:07 +00009377 else if (prn->info)
9378 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9379
Paul Jakma2815e612006-09-14 02:56:07 +00009380 for (ri = rn->info; ri; ri = ri->next)
9381 {
9382 rinum++;
9383 ts->counts[BGP_STATS_RIB]++;
9384
9385 if (ri->attr &&
9386 (CHECK_FLAG (ri->attr->flag,
9387 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9388 ts->counts[BGP_STATS_AGGREGATES]++;
9389
9390 /* as-path stats */
9391 if (ri->attr && ri->attr->aspath)
9392 {
9393 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9394 unsigned int size = aspath_size (ri->attr->aspath);
9395 as_t highest = aspath_highest (ri->attr->aspath);
9396
9397 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9398
9399 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9400 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9401
9402 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9403 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9404
9405 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9406 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9407#if 0
9408 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9409 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9410 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9411 hops);
9412 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9413 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9414 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9415 size);
9416#endif
9417 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9418 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9419 }
9420 }
9421 }
9422 return 0;
9423}
9424
9425static int
9426bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9427{
9428 struct bgp_table_stats ts;
9429 unsigned int i;
9430
9431 if (!bgp->rib[afi][safi])
9432 {
9433 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9434 return CMD_WARNING;
9435 }
9436
9437 memset (&ts, 0, sizeof (ts));
9438 ts.table = bgp->rib[afi][safi];
9439 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9440
9441 vty_out (vty, "BGP %s RIB statistics%s%s",
9442 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9443
9444 for (i = 0; i < BGP_STATS_MAX; i++)
9445 {
9446 if (!table_stats_strs[i])
9447 continue;
9448
9449 switch (i)
9450 {
9451#if 0
9452 case BGP_STATS_ASPATH_AVGHOPS:
9453 case BGP_STATS_ASPATH_AVGSIZE:
9454 case BGP_STATS_AVGPLEN:
9455 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9456 vty_out (vty, "%12.2f",
9457 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9458 break;
9459#endif
9460 case BGP_STATS_ASPATH_TOTHOPS:
9461 case BGP_STATS_ASPATH_TOTSIZE:
9462 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9463 vty_out (vty, "%12.2f",
9464 ts.counts[i] ?
9465 (float)ts.counts[i] /
9466 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9467 : 0);
9468 break;
9469 case BGP_STATS_TOTPLEN:
9470 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9471 vty_out (vty, "%12.2f",
9472 ts.counts[i] ?
9473 (float)ts.counts[i] /
9474 (float)ts.counts[BGP_STATS_PREFIXES]
9475 : 0);
9476 break;
9477 case BGP_STATS_SPACE:
9478 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9479 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9480 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9481 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009482 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009483 vty_out (vty, "%12.2f%s",
9484 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009485 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009486 VTY_NEWLINE);
9487 vty_out (vty, "%30s: ", "/8 equivalent ");
9488 vty_out (vty, "%12.2f%s",
9489 (float)ts.counts[BGP_STATS_SPACE] /
9490 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9491 VTY_NEWLINE);
9492 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9493 break;
9494 vty_out (vty, "%30s: ", "/24 equivalent ");
9495 vty_out (vty, "%12.2f",
9496 (float)ts.counts[BGP_STATS_SPACE] /
9497 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9498 break;
9499 default:
9500 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9501 vty_out (vty, "%12llu", ts.counts[i]);
9502 }
9503
9504 vty_out (vty, "%s", VTY_NEWLINE);
9505 }
9506 return CMD_SUCCESS;
9507}
9508
9509static int
9510bgp_table_stats_vty (struct vty *vty, const char *name,
9511 const char *afi_str, const char *safi_str)
9512{
9513 struct bgp *bgp;
9514 afi_t afi;
9515 safi_t safi;
9516
9517 if (name)
9518 bgp = bgp_lookup_by_name (name);
9519 else
9520 bgp = bgp_get_default ();
9521
9522 if (!bgp)
9523 {
9524 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9525 return CMD_WARNING;
9526 }
9527 if (strncmp (afi_str, "ipv", 3) == 0)
9528 {
9529 if (strncmp (afi_str, "ipv4", 4) == 0)
9530 afi = AFI_IP;
9531 else if (strncmp (afi_str, "ipv6", 4) == 0)
9532 afi = AFI_IP6;
9533 else
9534 {
9535 vty_out (vty, "%% Invalid address family %s%s",
9536 afi_str, VTY_NEWLINE);
9537 return CMD_WARNING;
9538 }
9539 if (strncmp (safi_str, "m", 1) == 0)
9540 safi = SAFI_MULTICAST;
9541 else if (strncmp (safi_str, "u", 1) == 0)
9542 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009543 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9544 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009545 else
9546 {
9547 vty_out (vty, "%% Invalid subsequent address family %s%s",
9548 safi_str, VTY_NEWLINE);
9549 return CMD_WARNING;
9550 }
9551 }
9552 else
9553 {
9554 vty_out (vty, "%% Invalid address family %s%s",
9555 afi_str, VTY_NEWLINE);
9556 return CMD_WARNING;
9557 }
9558
Paul Jakma2815e612006-09-14 02:56:07 +00009559 return bgp_table_stats (vty, bgp, afi, safi);
9560}
9561
9562DEFUN (show_bgp_statistics,
9563 show_bgp_statistics_cmd,
9564 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9565 SHOW_STR
9566 BGP_STR
9567 "Address family\n"
9568 "Address family\n"
9569 "Address Family modifier\n"
9570 "Address Family modifier\n"
9571 "BGP RIB advertisement statistics\n")
9572{
9573 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9574}
9575
9576ALIAS (show_bgp_statistics,
9577 show_bgp_statistics_vpnv4_cmd,
9578 "show bgp (ipv4) (vpnv4) statistics",
9579 SHOW_STR
9580 BGP_STR
9581 "Address family\n"
9582 "Address Family modifier\n"
9583 "BGP RIB advertisement statistics\n")
9584
9585DEFUN (show_bgp_statistics_view,
9586 show_bgp_statistics_view_cmd,
9587 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9588 SHOW_STR
9589 BGP_STR
9590 "BGP view\n"
9591 "Address family\n"
9592 "Address family\n"
9593 "Address Family modifier\n"
9594 "Address Family modifier\n"
9595 "BGP RIB advertisement statistics\n")
9596{
9597 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9598}
9599
9600ALIAS (show_bgp_statistics_view,
9601 show_bgp_statistics_view_vpnv4_cmd,
9602 "show bgp view WORD (ipv4) (vpnv4) statistics",
9603 SHOW_STR
9604 BGP_STR
9605 "BGP view\n"
9606 "Address family\n"
9607 "Address Family modifier\n"
9608 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02009609
Paul Jakmaff7924f2006-09-04 01:10:36 +00009610enum bgp_pcounts
9611{
9612 PCOUNT_ADJ_IN = 0,
9613 PCOUNT_DAMPED,
9614 PCOUNT_REMOVED,
9615 PCOUNT_HISTORY,
9616 PCOUNT_STALE,
9617 PCOUNT_VALID,
9618 PCOUNT_ALL,
9619 PCOUNT_COUNTED,
9620 PCOUNT_PFCNT, /* the figure we display to users */
9621 PCOUNT_MAX,
9622};
9623
9624static const char *pcount_strs[] =
9625{
9626 [PCOUNT_ADJ_IN] = "Adj-in",
9627 [PCOUNT_DAMPED] = "Damped",
9628 [PCOUNT_REMOVED] = "Removed",
9629 [PCOUNT_HISTORY] = "History",
9630 [PCOUNT_STALE] = "Stale",
9631 [PCOUNT_VALID] = "Valid",
9632 [PCOUNT_ALL] = "All RIB",
9633 [PCOUNT_COUNTED] = "PfxCt counted",
9634 [PCOUNT_PFCNT] = "Useable",
9635 [PCOUNT_MAX] = NULL,
9636};
9637
Paul Jakma2815e612006-09-14 02:56:07 +00009638struct peer_pcounts
9639{
9640 unsigned int count[PCOUNT_MAX];
9641 const struct peer *peer;
9642 const struct bgp_table *table;
9643};
9644
Paul Jakmaff7924f2006-09-04 01:10:36 +00009645static int
Paul Jakma2815e612006-09-14 02:56:07 +00009646bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009647{
9648 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009649 struct peer_pcounts *pc = THREAD_ARG (t);
9650 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009651
Paul Jakma2815e612006-09-14 02:56:07 +00009652 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009653 {
9654 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009655 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009656
9657 for (ain = rn->adj_in; ain; ain = ain->next)
9658 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009659 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009660
Paul Jakmaff7924f2006-09-04 01:10:36 +00009661 for (ri = rn->info; ri; ri = ri->next)
9662 {
9663 char buf[SU_ADDRSTRLEN];
9664
9665 if (ri->peer != peer)
9666 continue;
9667
Paul Jakma2815e612006-09-14 02:56:07 +00009668 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009669
9670 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009671 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009672 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009673 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009674 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009675 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009676 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009677 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009678 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009679 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009680 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009681 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009682
9683 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9684 {
Paul Jakma2815e612006-09-14 02:56:07 +00009685 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009686 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009687 plog_warn (peer->log,
9688 "%s [pcount] %s/%d is counted but flags 0x%x",
9689 peer->host,
9690 inet_ntop(rn->p.family, &rn->p.u.prefix,
9691 buf, SU_ADDRSTRLEN),
9692 rn->p.prefixlen,
9693 ri->flags);
9694 }
9695 else
9696 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009697 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009698 plog_warn (peer->log,
9699 "%s [pcount] %s/%d not counted but flags 0x%x",
9700 peer->host,
9701 inet_ntop(rn->p.family, &rn->p.u.prefix,
9702 buf, SU_ADDRSTRLEN),
9703 rn->p.prefixlen,
9704 ri->flags);
9705 }
9706 }
9707 }
Paul Jakma2815e612006-09-14 02:56:07 +00009708 return 0;
9709}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009710
Paul Jakma2815e612006-09-14 02:56:07 +00009711static int
9712bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9713{
9714 struct peer_pcounts pcounts = { .peer = peer };
9715 unsigned int i;
9716
9717 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9718 || !peer->bgp->rib[afi][safi])
9719 {
9720 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9721 return CMD_WARNING;
9722 }
9723
9724 memset (&pcounts, 0, sizeof(pcounts));
9725 pcounts.peer = peer;
9726 pcounts.table = peer->bgp->rib[afi][safi];
9727
9728 /* in-place call via thread subsystem so as to record execution time
9729 * stats for the thread-walk (i.e. ensure this can't be blamed on
9730 * on just vty_read()).
9731 */
9732 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9733
Paul Jakmaff7924f2006-09-04 01:10:36 +00009734 vty_out (vty, "Prefix counts for %s, %s%s",
9735 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9736 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9737 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9738 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9739
9740 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009741 vty_out (vty, "%20s: %-10d%s",
9742 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009743
Paul Jakma2815e612006-09-14 02:56:07 +00009744 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009745 {
9746 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9747 peer->host, VTY_NEWLINE);
9748 vty_out (vty, "Please report this bug, with the above command output%s",
9749 VTY_NEWLINE);
9750 }
9751
9752 return CMD_SUCCESS;
9753}
9754
9755DEFUN (show_ip_bgp_neighbor_prefix_counts,
9756 show_ip_bgp_neighbor_prefix_counts_cmd,
9757 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9758 SHOW_STR
9759 IP_STR
9760 BGP_STR
9761 "Detailed information on TCP and BGP neighbor connections\n"
9762 "Neighbor to display information about\n"
9763 "Neighbor to display information about\n"
9764 "Display detailed prefix count information\n")
9765{
9766 struct peer *peer;
9767
9768 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9769 if (! peer)
9770 return CMD_WARNING;
9771
9772 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9773}
9774
9775DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9776 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9777 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9778 SHOW_STR
9779 BGP_STR
9780 "Address family\n"
9781 "Detailed information on TCP and BGP neighbor connections\n"
9782 "Neighbor to display information about\n"
9783 "Neighbor to display information about\n"
9784 "Display detailed prefix count information\n")
9785{
9786 struct peer *peer;
9787
9788 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9789 if (! peer)
9790 return CMD_WARNING;
9791
9792 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9793}
9794
9795DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9796 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9797 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9798 SHOW_STR
9799 IP_STR
9800 BGP_STR
9801 "Address family\n"
9802 "Address Family modifier\n"
9803 "Address Family modifier\n"
9804 "Detailed information on TCP and BGP neighbor connections\n"
9805 "Neighbor to display information about\n"
9806 "Neighbor to display information about\n"
9807 "Display detailed prefix count information\n")
9808{
9809 struct peer *peer;
9810
9811 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9812 if (! peer)
9813 return CMD_WARNING;
9814
9815 if (strncmp (argv[0], "m", 1) == 0)
9816 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9817
9818 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9819}
9820
9821DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9822 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9823 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9824 SHOW_STR
9825 IP_STR
9826 BGP_STR
9827 "Address family\n"
9828 "Address Family modifier\n"
9829 "Address Family modifier\n"
9830 "Detailed information on TCP and BGP neighbor connections\n"
9831 "Neighbor to display information about\n"
9832 "Neighbor to display information about\n"
9833 "Display detailed prefix count information\n")
9834{
9835 struct peer *peer;
9836
9837 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9838 if (! peer)
9839 return CMD_WARNING;
9840
9841 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9842}
9843
9844
paul94f2b392005-06-28 12:44:16 +00009845static void
paul718e3742002-12-13 20:15:29 +00009846show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9847 int in)
9848{
9849 struct bgp_table *table;
9850 struct bgp_adj_in *ain;
9851 struct bgp_adj_out *adj;
9852 unsigned long output_count;
9853 struct bgp_node *rn;
9854 int header1 = 1;
9855 struct bgp *bgp;
9856 int header2 = 1;
9857
paulbb46e942003-10-24 19:02:03 +00009858 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009859
9860 if (! bgp)
9861 return;
9862
9863 table = bgp->rib[afi][safi];
9864
9865 output_count = 0;
9866
9867 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9868 PEER_STATUS_DEFAULT_ORIGINATE))
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
9874 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9875 VTY_NEWLINE, VTY_NEWLINE);
9876 header1 = 0;
9877 }
9878
9879 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9880 if (in)
9881 {
9882 for (ain = rn->adj_in; ain; ain = ain->next)
9883 if (ain->peer == peer)
9884 {
9885 if (header1)
9886 {
9887 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 +00009888 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9889 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009890 header1 = 0;
9891 }
9892 if (header2)
9893 {
9894 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9895 header2 = 0;
9896 }
9897 if (ain->attr)
9898 {
9899 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9900 output_count++;
9901 }
9902 }
9903 }
9904 else
9905 {
9906 for (adj = rn->adj_out; adj; adj = adj->next)
9907 if (adj->peer == peer)
9908 {
9909 if (header1)
9910 {
9911 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 +00009912 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9913 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009914 header1 = 0;
9915 }
9916 if (header2)
9917 {
9918 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9919 header2 = 0;
9920 }
9921 if (adj->attr)
9922 {
9923 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9924 output_count++;
9925 }
9926 }
9927 }
9928
9929 if (output_count != 0)
9930 vty_out (vty, "%sTotal number of prefixes %ld%s",
9931 VTY_NEWLINE, output_count, VTY_NEWLINE);
9932}
9933
paul94f2b392005-06-28 12:44:16 +00009934static int
paulbb46e942003-10-24 19:02:03 +00009935peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9936{
paul718e3742002-12-13 20:15:29 +00009937 if (! peer || ! peer->afc[afi][safi])
9938 {
9939 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9940 return CMD_WARNING;
9941 }
9942
9943 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9944 {
9945 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9946 VTY_NEWLINE);
9947 return CMD_WARNING;
9948 }
9949
9950 show_adj_route (vty, peer, afi, safi, in);
9951
9952 return CMD_SUCCESS;
9953}
9954
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009955DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9956 show_ip_bgp_view_neighbor_advertised_route_cmd,
9957 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9958 SHOW_STR
9959 IP_STR
9960 BGP_STR
9961 "BGP view\n"
9962 "View name\n"
9963 "Detailed information on TCP and BGP neighbor connections\n"
9964 "Neighbor to display information about\n"
9965 "Neighbor to display information about\n"
9966 "Display the routes advertised to a BGP neighbor\n")
9967{
9968 struct peer *peer;
9969
9970 if (argc == 2)
9971 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9972 else
9973 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9974
9975 if (! peer)
9976 return CMD_WARNING;
9977
9978 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9979}
9980
9981ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009982 show_ip_bgp_neighbor_advertised_route_cmd,
9983 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9984 SHOW_STR
9985 IP_STR
9986 BGP_STR
9987 "Detailed information on TCP and BGP neighbor connections\n"
9988 "Neighbor to display information about\n"
9989 "Neighbor to display information about\n"
9990 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009991
9992DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9993 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9994 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9995 SHOW_STR
9996 IP_STR
9997 BGP_STR
9998 "Address family\n"
9999 "Address Family modifier\n"
10000 "Address Family modifier\n"
10001 "Detailed information on TCP and BGP neighbor connections\n"
10002 "Neighbor to display information about\n"
10003 "Neighbor to display information about\n"
10004 "Display the routes advertised to a BGP neighbor\n")
10005{
paulbb46e942003-10-24 19:02:03 +000010006 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010007
paulbb46e942003-10-24 19:02:03 +000010008 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10009 if (! peer)
10010 return CMD_WARNING;
10011
10012 if (strncmp (argv[0], "m", 1) == 0)
10013 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
10014
10015 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +000010016}
10017
10018#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010019DEFUN (show_bgp_view_neighbor_advertised_route,
10020 show_bgp_view_neighbor_advertised_route_cmd,
10021 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10022 SHOW_STR
10023 BGP_STR
10024 "BGP view\n"
10025 "View name\n"
10026 "Detailed information on TCP and BGP neighbor connections\n"
10027 "Neighbor to display information about\n"
10028 "Neighbor to display information about\n"
10029 "Display the routes advertised to a BGP neighbor\n")
10030{
10031 struct peer *peer;
10032
10033 if (argc == 2)
10034 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10035 else
10036 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10037
10038 if (! peer)
10039 return CMD_WARNING;
10040
10041 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10042}
10043
10044ALIAS (show_bgp_view_neighbor_advertised_route,
10045 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10046 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10047 SHOW_STR
10048 BGP_STR
10049 "BGP view\n"
10050 "View name\n"
10051 "Address family\n"
10052 "Detailed information on TCP and BGP neighbor connections\n"
10053 "Neighbor to display information about\n"
10054 "Neighbor to display information about\n"
10055 "Display the routes advertised to a BGP neighbor\n")
10056
10057DEFUN (show_bgp_view_neighbor_received_routes,
10058 show_bgp_view_neighbor_received_routes_cmd,
10059 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10060 SHOW_STR
10061 BGP_STR
10062 "BGP view\n"
10063 "View name\n"
10064 "Detailed information on TCP and BGP neighbor connections\n"
10065 "Neighbor to display information about\n"
10066 "Neighbor to display information about\n"
10067 "Display the received routes from neighbor\n")
10068{
10069 struct peer *peer;
10070
10071 if (argc == 2)
10072 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10073 else
10074 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10075
10076 if (! peer)
10077 return CMD_WARNING;
10078
10079 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10080}
10081
10082ALIAS (show_bgp_view_neighbor_received_routes,
10083 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10084 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10085 SHOW_STR
10086 BGP_STR
10087 "BGP view\n"
10088 "View name\n"
10089 "Address family\n"
10090 "Detailed information on TCP and BGP neighbor connections\n"
10091 "Neighbor to display information about\n"
10092 "Neighbor to display information about\n"
10093 "Display the received routes from neighbor\n")
10094
10095ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010096 show_bgp_neighbor_advertised_route_cmd,
10097 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10098 SHOW_STR
10099 BGP_STR
10100 "Detailed information on TCP and BGP neighbor connections\n"
10101 "Neighbor to display information about\n"
10102 "Neighbor to display information about\n"
10103 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010104
10105ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010106 show_bgp_ipv6_neighbor_advertised_route_cmd,
10107 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10108 SHOW_STR
10109 BGP_STR
10110 "Address family\n"
10111 "Detailed information on TCP and BGP neighbor connections\n"
10112 "Neighbor to display information about\n"
10113 "Neighbor to display information about\n"
10114 "Display the routes advertised to a BGP neighbor\n")
10115
10116/* old command */
paulbb46e942003-10-24 19:02:03 +000010117ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010118 ipv6_bgp_neighbor_advertised_route_cmd,
10119 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10120 SHOW_STR
10121 IPV6_STR
10122 BGP_STR
10123 "Detailed information on TCP and BGP neighbor connections\n"
10124 "Neighbor to display information about\n"
10125 "Neighbor to display information about\n"
10126 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010127
paul718e3742002-12-13 20:15:29 +000010128/* old command */
10129DEFUN (ipv6_mbgp_neighbor_advertised_route,
10130 ipv6_mbgp_neighbor_advertised_route_cmd,
10131 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10132 SHOW_STR
10133 IPV6_STR
10134 MBGP_STR
10135 "Detailed information on TCP and BGP neighbor connections\n"
10136 "Neighbor to display information about\n"
10137 "Neighbor to display information about\n"
10138 "Display the routes advertised to a BGP neighbor\n")
10139{
paulbb46e942003-10-24 19:02:03 +000010140 struct peer *peer;
10141
10142 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10143 if (! peer)
10144 return CMD_WARNING;
10145
10146 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010147}
10148#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010149
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010150DEFUN (show_ip_bgp_view_neighbor_received_routes,
10151 show_ip_bgp_view_neighbor_received_routes_cmd,
10152 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10153 SHOW_STR
10154 IP_STR
10155 BGP_STR
10156 "BGP view\n"
10157 "View name\n"
10158 "Detailed information on TCP and BGP neighbor connections\n"
10159 "Neighbor to display information about\n"
10160 "Neighbor to display information about\n"
10161 "Display the received routes from neighbor\n")
10162{
10163 struct peer *peer;
10164
10165 if (argc == 2)
10166 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10167 else
10168 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10169
10170 if (! peer)
10171 return CMD_WARNING;
10172
10173 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10174}
10175
10176ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010177 show_ip_bgp_neighbor_received_routes_cmd,
10178 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10179 SHOW_STR
10180 IP_STR
10181 BGP_STR
10182 "Detailed information on TCP and BGP neighbor connections\n"
10183 "Neighbor to display information about\n"
10184 "Neighbor to display information about\n"
10185 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010186
10187DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10188 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10189 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10190 SHOW_STR
10191 IP_STR
10192 BGP_STR
10193 "Address family\n"
10194 "Address Family modifier\n"
10195 "Address Family modifier\n"
10196 "Detailed information on TCP and BGP neighbor connections\n"
10197 "Neighbor to display information about\n"
10198 "Neighbor to display information about\n"
10199 "Display the received routes from neighbor\n")
10200{
paulbb46e942003-10-24 19:02:03 +000010201 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010202
paulbb46e942003-10-24 19:02:03 +000010203 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10204 if (! peer)
10205 return CMD_WARNING;
10206
10207 if (strncmp (argv[0], "m", 1) == 0)
10208 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10209
10210 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010211}
10212
Michael Lambert95cbbd22010-07-23 14:43:04 -040010213DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10214 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10215#ifdef HAVE_IPV6
10216 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10217#else
10218 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10219#endif
10220 SHOW_STR
10221 BGP_STR
10222 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010223 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010224 "Address family\n"
10225#ifdef HAVE_IPV6
10226 "Address family\n"
10227#endif
10228 "Address family modifier\n"
10229 "Address family modifier\n"
10230 "Detailed information on TCP and BGP neighbor connections\n"
10231 "Neighbor to display information about\n"
10232 "Neighbor to display information about\n"
10233 "Display the advertised routes to neighbor\n"
10234 "Display the received routes from neighbor\n")
10235{
10236 int afi;
10237 int safi;
10238 int in;
10239 struct peer *peer;
10240
10241#ifdef HAVE_IPV6
10242 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10243#else
10244 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10245#endif
10246
10247 if (! peer)
10248 return CMD_WARNING;
10249
10250#ifdef HAVE_IPV6
10251 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10252 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10253 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10254#else
10255 afi = AFI_IP;
10256 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10257 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10258#endif
10259
10260 return peer_adj_routes (vty, peer, afi, safi, in);
10261}
10262
paul718e3742002-12-13 20:15:29 +000010263DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10264 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10265 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10266 SHOW_STR
10267 IP_STR
10268 BGP_STR
10269 "Detailed information on TCP and BGP neighbor connections\n"
10270 "Neighbor to display information about\n"
10271 "Neighbor to display information about\n"
10272 "Display information received from a BGP neighbor\n"
10273 "Display the prefixlist filter\n")
10274{
10275 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010276 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010277 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010278 int count, ret;
paul718e3742002-12-13 20:15:29 +000010279
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010280 ret = str2sockunion (argv[0], &su);
10281 if (ret < 0)
10282 {
10283 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10284 return CMD_WARNING;
10285 }
paul718e3742002-12-13 20:15:29 +000010286
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010287 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010288 if (! peer)
10289 return CMD_WARNING;
10290
10291 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10292 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10293 if (count)
10294 {
10295 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10296 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10297 }
10298
10299 return CMD_SUCCESS;
10300}
10301
10302DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10303 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10304 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10305 SHOW_STR
10306 IP_STR
10307 BGP_STR
10308 "Address family\n"
10309 "Address Family modifier\n"
10310 "Address Family modifier\n"
10311 "Detailed information on TCP and BGP neighbor connections\n"
10312 "Neighbor to display information about\n"
10313 "Neighbor to display information about\n"
10314 "Display information received from a BGP neighbor\n"
10315 "Display the prefixlist filter\n")
10316{
10317 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010318 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010319 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010320 int count, ret;
paul718e3742002-12-13 20:15:29 +000010321
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010322 ret = str2sockunion (argv[1], &su);
10323 if (ret < 0)
10324 {
10325 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10326 return CMD_WARNING;
10327 }
paul718e3742002-12-13 20:15:29 +000010328
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010329 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010330 if (! peer)
10331 return CMD_WARNING;
10332
10333 if (strncmp (argv[0], "m", 1) == 0)
10334 {
10335 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10336 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10337 if (count)
10338 {
10339 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10340 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10341 }
10342 }
10343 else
10344 {
10345 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10346 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10347 if (count)
10348 {
10349 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10350 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10351 }
10352 }
10353
10354 return CMD_SUCCESS;
10355}
10356
10357
10358#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010359ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010360 show_bgp_neighbor_received_routes_cmd,
10361 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10362 SHOW_STR
10363 BGP_STR
10364 "Detailed information on TCP and BGP neighbor connections\n"
10365 "Neighbor to display information about\n"
10366 "Neighbor to display information about\n"
10367 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010368
paulbb46e942003-10-24 19:02:03 +000010369ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010370 show_bgp_ipv6_neighbor_received_routes_cmd,
10371 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10372 SHOW_STR
10373 BGP_STR
10374 "Address family\n"
10375 "Detailed information on TCP and BGP neighbor connections\n"
10376 "Neighbor to display information about\n"
10377 "Neighbor to display information about\n"
10378 "Display the received routes from neighbor\n")
10379
10380DEFUN (show_bgp_neighbor_received_prefix_filter,
10381 show_bgp_neighbor_received_prefix_filter_cmd,
10382 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10383 SHOW_STR
10384 BGP_STR
10385 "Detailed information on TCP and BGP neighbor connections\n"
10386 "Neighbor to display information about\n"
10387 "Neighbor to display information about\n"
10388 "Display information received from a BGP neighbor\n"
10389 "Display the prefixlist filter\n")
10390{
10391 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010392 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010393 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010394 int count, ret;
paul718e3742002-12-13 20:15:29 +000010395
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010396 ret = str2sockunion (argv[0], &su);
10397 if (ret < 0)
10398 {
10399 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10400 return CMD_WARNING;
10401 }
paul718e3742002-12-13 20:15:29 +000010402
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010403 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010404 if (! peer)
10405 return CMD_WARNING;
10406
10407 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10408 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10409 if (count)
10410 {
10411 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10412 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10413 }
10414
10415 return CMD_SUCCESS;
10416}
10417
10418ALIAS (show_bgp_neighbor_received_prefix_filter,
10419 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10420 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10421 SHOW_STR
10422 BGP_STR
10423 "Address family\n"
10424 "Detailed information on TCP and BGP neighbor connections\n"
10425 "Neighbor to display information about\n"
10426 "Neighbor to display information about\n"
10427 "Display information received from a BGP neighbor\n"
10428 "Display the prefixlist filter\n")
10429
10430/* old command */
paulbb46e942003-10-24 19:02:03 +000010431ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010432 ipv6_bgp_neighbor_received_routes_cmd,
10433 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10434 SHOW_STR
10435 IPV6_STR
10436 BGP_STR
10437 "Detailed information on TCP and BGP neighbor connections\n"
10438 "Neighbor to display information about\n"
10439 "Neighbor to display information about\n"
10440 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010441
10442/* old command */
10443DEFUN (ipv6_mbgp_neighbor_received_routes,
10444 ipv6_mbgp_neighbor_received_routes_cmd,
10445 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10446 SHOW_STR
10447 IPV6_STR
10448 MBGP_STR
10449 "Detailed information on TCP and BGP neighbor connections\n"
10450 "Neighbor to display information about\n"
10451 "Neighbor to display information about\n"
10452 "Display the received routes from neighbor\n")
10453{
paulbb46e942003-10-24 19:02:03 +000010454 struct peer *peer;
10455
10456 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10457 if (! peer)
10458 return CMD_WARNING;
10459
10460 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010461}
paulbb46e942003-10-24 19:02:03 +000010462
10463DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10464 show_bgp_view_neighbor_received_prefix_filter_cmd,
10465 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10466 SHOW_STR
10467 BGP_STR
10468 "BGP view\n"
10469 "View name\n"
10470 "Detailed information on TCP and BGP neighbor connections\n"
10471 "Neighbor to display information about\n"
10472 "Neighbor to display information about\n"
10473 "Display information received from a BGP neighbor\n"
10474 "Display the prefixlist filter\n")
10475{
10476 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010477 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010478 struct peer *peer;
10479 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010480 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010481
10482 /* BGP structure lookup. */
10483 bgp = bgp_lookup_by_name (argv[0]);
10484 if (bgp == NULL)
10485 {
10486 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10487 return CMD_WARNING;
10488 }
10489
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010490 ret = str2sockunion (argv[1], &su);
10491 if (ret < 0)
10492 {
10493 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10494 return CMD_WARNING;
10495 }
paulbb46e942003-10-24 19:02:03 +000010496
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010497 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010498 if (! peer)
10499 return CMD_WARNING;
10500
10501 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10502 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10503 if (count)
10504 {
10505 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10506 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10507 }
10508
10509 return CMD_SUCCESS;
10510}
10511
10512ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10513 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10514 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10515 SHOW_STR
10516 BGP_STR
10517 "BGP view\n"
10518 "View name\n"
10519 "Address family\n"
10520 "Detailed information on TCP and BGP neighbor connections\n"
10521 "Neighbor to display information about\n"
10522 "Neighbor to display information about\n"
10523 "Display information received from a BGP neighbor\n"
10524 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010525#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010526
paul94f2b392005-06-28 12:44:16 +000010527static int
paulbb46e942003-10-24 19:02:03 +000010528bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010529 safi_t safi, enum bgp_show_type type)
10530{
paul718e3742002-12-13 20:15:29 +000010531 if (! peer || ! peer->afc[afi][safi])
10532 {
10533 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010534 return CMD_WARNING;
10535 }
10536
ajs5a646652004-11-05 01:25:55 +000010537 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010538}
10539
10540DEFUN (show_ip_bgp_neighbor_routes,
10541 show_ip_bgp_neighbor_routes_cmd,
10542 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10543 SHOW_STR
10544 IP_STR
10545 BGP_STR
10546 "Detailed information on TCP and BGP neighbor connections\n"
10547 "Neighbor to display information about\n"
10548 "Neighbor to display information about\n"
10549 "Display routes learned from neighbor\n")
10550{
paulbb46e942003-10-24 19:02:03 +000010551 struct peer *peer;
10552
10553 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10554 if (! peer)
10555 return CMD_WARNING;
10556
10557 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010558 bgp_show_type_neighbor);
10559}
10560
10561DEFUN (show_ip_bgp_neighbor_flap,
10562 show_ip_bgp_neighbor_flap_cmd,
10563 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10564 SHOW_STR
10565 IP_STR
10566 BGP_STR
10567 "Detailed information on TCP and BGP neighbor connections\n"
10568 "Neighbor to display information about\n"
10569 "Neighbor to display information about\n"
10570 "Display flap statistics of the routes learned from neighbor\n")
10571{
paulbb46e942003-10-24 19:02:03 +000010572 struct peer *peer;
10573
10574 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10575 if (! peer)
10576 return CMD_WARNING;
10577
10578 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010579 bgp_show_type_flap_neighbor);
10580}
10581
10582DEFUN (show_ip_bgp_neighbor_damp,
10583 show_ip_bgp_neighbor_damp_cmd,
10584 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10585 SHOW_STR
10586 IP_STR
10587 BGP_STR
10588 "Detailed information on TCP and BGP neighbor connections\n"
10589 "Neighbor to display information about\n"
10590 "Neighbor to display information about\n"
10591 "Display the dampened routes received from neighbor\n")
10592{
paulbb46e942003-10-24 19:02:03 +000010593 struct peer *peer;
10594
10595 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10596 if (! peer)
10597 return CMD_WARNING;
10598
10599 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010600 bgp_show_type_damp_neighbor);
10601}
10602
10603DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10604 show_ip_bgp_ipv4_neighbor_routes_cmd,
10605 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10606 SHOW_STR
10607 IP_STR
10608 BGP_STR
10609 "Address family\n"
10610 "Address Family modifier\n"
10611 "Address Family modifier\n"
10612 "Detailed information on TCP and BGP neighbor connections\n"
10613 "Neighbor to display information about\n"
10614 "Neighbor to display information about\n"
10615 "Display routes learned from neighbor\n")
10616{
paulbb46e942003-10-24 19:02:03 +000010617 struct peer *peer;
10618
10619 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10620 if (! peer)
10621 return CMD_WARNING;
10622
paul718e3742002-12-13 20:15:29 +000010623 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010624 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010625 bgp_show_type_neighbor);
10626
paulbb46e942003-10-24 19:02:03 +000010627 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010628 bgp_show_type_neighbor);
10629}
paulbb46e942003-10-24 19:02:03 +000010630
paulfee0f4c2004-09-13 05:12:46 +000010631DEFUN (show_ip_bgp_view_rsclient,
10632 show_ip_bgp_view_rsclient_cmd,
10633 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10634 SHOW_STR
10635 IP_STR
10636 BGP_STR
10637 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010638 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010639 "Information about Route Server Client\n"
10640 NEIGHBOR_ADDR_STR)
10641{
10642 struct bgp_table *table;
10643 struct peer *peer;
10644
10645 if (argc == 2)
10646 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10647 else
10648 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10649
10650 if (! peer)
10651 return CMD_WARNING;
10652
10653 if (! peer->afc[AFI_IP][SAFI_UNICAST])
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_UNICAST],
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_UNICAST];
10669
ajs5a646652004-11-05 01:25:55 +000010670 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010671}
10672
10673ALIAS (show_ip_bgp_view_rsclient,
10674 show_ip_bgp_rsclient_cmd,
10675 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10676 SHOW_STR
10677 IP_STR
10678 BGP_STR
10679 "Information about Route Server Client\n"
10680 NEIGHBOR_ADDR_STR)
10681
Michael Lambert95cbbd22010-07-23 14:43:04 -040010682DEFUN (show_bgp_view_ipv4_safi_rsclient,
10683 show_bgp_view_ipv4_safi_rsclient_cmd,
10684 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10685 SHOW_STR
10686 BGP_STR
10687 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010688 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010689 "Address family\n"
10690 "Address Family modifier\n"
10691 "Address Family modifier\n"
10692 "Information about Route Server Client\n"
10693 NEIGHBOR_ADDR_STR)
10694{
10695 struct bgp_table *table;
10696 struct peer *peer;
10697 safi_t safi;
10698
10699 if (argc == 3) {
10700 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10701 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10702 } else {
10703 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10704 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10705 }
10706
10707 if (! peer)
10708 return CMD_WARNING;
10709
10710 if (! peer->afc[AFI_IP][safi])
10711 {
10712 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10713 VTY_NEWLINE);
10714 return CMD_WARNING;
10715 }
10716
10717 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10718 PEER_FLAG_RSERVER_CLIENT))
10719 {
10720 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10721 VTY_NEWLINE);
10722 return CMD_WARNING;
10723 }
10724
10725 table = peer->rib[AFI_IP][safi];
10726
10727 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10728}
10729
10730ALIAS (show_bgp_view_ipv4_safi_rsclient,
10731 show_bgp_ipv4_safi_rsclient_cmd,
10732 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10733 SHOW_STR
10734 BGP_STR
10735 "Address family\n"
10736 "Address Family modifier\n"
10737 "Address Family modifier\n"
10738 "Information about Route Server Client\n"
10739 NEIGHBOR_ADDR_STR)
10740
paulfee0f4c2004-09-13 05:12:46 +000010741DEFUN (show_ip_bgp_view_rsclient_route,
10742 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010743 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010744 SHOW_STR
10745 IP_STR
10746 BGP_STR
10747 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010748 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010749 "Information about Route Server Client\n"
10750 NEIGHBOR_ADDR_STR
10751 "Network in the BGP routing table to display\n")
10752{
10753 struct bgp *bgp;
10754 struct peer *peer;
10755
10756 /* BGP structure lookup. */
10757 if (argc == 3)
10758 {
10759 bgp = bgp_lookup_by_name (argv[0]);
10760 if (bgp == NULL)
10761 {
10762 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10763 return CMD_WARNING;
10764 }
10765 }
10766 else
10767 {
10768 bgp = bgp_get_default ();
10769 if (bgp == NULL)
10770 {
10771 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10772 return CMD_WARNING;
10773 }
10774 }
10775
10776 if (argc == 3)
10777 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10778 else
10779 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10780
10781 if (! peer)
10782 return CMD_WARNING;
10783
10784 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10785 {
10786 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10787 VTY_NEWLINE);
10788 return CMD_WARNING;
10789}
10790
10791 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10792 PEER_FLAG_RSERVER_CLIENT))
10793 {
10794 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10795 VTY_NEWLINE);
10796 return CMD_WARNING;
10797 }
10798
10799 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10800 (argc == 3) ? argv[2] : argv[1],
10801 AFI_IP, SAFI_UNICAST, NULL, 0);
10802}
10803
10804ALIAS (show_ip_bgp_view_rsclient_route,
10805 show_ip_bgp_rsclient_route_cmd,
10806 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10807 SHOW_STR
10808 IP_STR
10809 BGP_STR
10810 "Information about Route Server Client\n"
10811 NEIGHBOR_ADDR_STR
10812 "Network in the BGP routing table to display\n")
10813
Michael Lambert95cbbd22010-07-23 14:43:04 -040010814DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10815 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10816 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10817 SHOW_STR
10818 BGP_STR
10819 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010820 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010821 "Address family\n"
10822 "Address Family modifier\n"
10823 "Address Family modifier\n"
10824 "Information about Route Server Client\n"
10825 NEIGHBOR_ADDR_STR
10826 "Network in the BGP routing table to display\n")
10827{
10828 struct bgp *bgp;
10829 struct peer *peer;
10830 safi_t safi;
10831
10832 /* BGP structure lookup. */
10833 if (argc == 4)
10834 {
10835 bgp = bgp_lookup_by_name (argv[0]);
10836 if (bgp == NULL)
10837 {
10838 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10839 return CMD_WARNING;
10840 }
10841 }
10842 else
10843 {
10844 bgp = bgp_get_default ();
10845 if (bgp == NULL)
10846 {
10847 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10848 return CMD_WARNING;
10849 }
10850 }
10851
10852 if (argc == 4) {
10853 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10854 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10855 } else {
10856 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10857 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10858 }
10859
10860 if (! peer)
10861 return CMD_WARNING;
10862
10863 if (! peer->afc[AFI_IP][safi])
10864 {
10865 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10866 VTY_NEWLINE);
10867 return CMD_WARNING;
10868}
10869
10870 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10871 PEER_FLAG_RSERVER_CLIENT))
10872 {
10873 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10874 VTY_NEWLINE);
10875 return CMD_WARNING;
10876 }
10877
10878 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10879 (argc == 4) ? argv[3] : argv[2],
10880 AFI_IP, safi, NULL, 0);
10881}
10882
10883ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10884 show_bgp_ipv4_safi_rsclient_route_cmd,
10885 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10886 SHOW_STR
10887 BGP_STR
10888 "Address family\n"
10889 "Address Family modifier\n"
10890 "Address Family modifier\n"
10891 "Information about Route Server Client\n"
10892 NEIGHBOR_ADDR_STR
10893 "Network in the BGP routing table to display\n")
10894
paulfee0f4c2004-09-13 05:12:46 +000010895DEFUN (show_ip_bgp_view_rsclient_prefix,
10896 show_ip_bgp_view_rsclient_prefix_cmd,
10897 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10898 SHOW_STR
10899 IP_STR
10900 BGP_STR
10901 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010902 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010903 "Information about Route Server Client\n"
10904 NEIGHBOR_ADDR_STR
10905 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10906{
10907 struct bgp *bgp;
10908 struct peer *peer;
10909
10910 /* BGP structure lookup. */
10911 if (argc == 3)
10912 {
10913 bgp = bgp_lookup_by_name (argv[0]);
10914 if (bgp == NULL)
10915 {
10916 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10917 return CMD_WARNING;
10918 }
10919 }
10920 else
10921 {
10922 bgp = bgp_get_default ();
10923 if (bgp == NULL)
10924 {
10925 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10926 return CMD_WARNING;
10927 }
10928 }
10929
10930 if (argc == 3)
10931 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10932 else
10933 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10934
10935 if (! peer)
10936 return CMD_WARNING;
10937
10938 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10939 {
10940 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10941 VTY_NEWLINE);
10942 return CMD_WARNING;
10943}
10944
10945 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10946 PEER_FLAG_RSERVER_CLIENT))
10947{
10948 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10949 VTY_NEWLINE);
10950 return CMD_WARNING;
10951 }
10952
10953 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10954 (argc == 3) ? argv[2] : argv[1],
10955 AFI_IP, SAFI_UNICAST, NULL, 1);
10956}
10957
10958ALIAS (show_ip_bgp_view_rsclient_prefix,
10959 show_ip_bgp_rsclient_prefix_cmd,
10960 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10961 SHOW_STR
10962 IP_STR
10963 BGP_STR
10964 "Information about Route Server Client\n"
10965 NEIGHBOR_ADDR_STR
10966 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10967
Michael Lambert95cbbd22010-07-23 14:43:04 -040010968DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10969 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10970 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10971 SHOW_STR
10972 BGP_STR
10973 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010974 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010975 "Address family\n"
10976 "Address Family modifier\n"
10977 "Address Family modifier\n"
10978 "Information about Route Server Client\n"
10979 NEIGHBOR_ADDR_STR
10980 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10981{
10982 struct bgp *bgp;
10983 struct peer *peer;
10984 safi_t safi;
10985
10986 /* BGP structure lookup. */
10987 if (argc == 4)
10988 {
10989 bgp = bgp_lookup_by_name (argv[0]);
10990 if (bgp == NULL)
10991 {
10992 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10993 return CMD_WARNING;
10994 }
10995 }
10996 else
10997 {
10998 bgp = bgp_get_default ();
10999 if (bgp == NULL)
11000 {
11001 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11002 return CMD_WARNING;
11003 }
11004 }
11005
11006 if (argc == 4) {
11007 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11008 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11009 } else {
11010 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11011 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11012 }
11013
11014 if (! peer)
11015 return CMD_WARNING;
11016
11017 if (! peer->afc[AFI_IP][safi])
11018 {
11019 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11020 VTY_NEWLINE);
11021 return CMD_WARNING;
11022}
11023
11024 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11025 PEER_FLAG_RSERVER_CLIENT))
11026{
11027 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11028 VTY_NEWLINE);
11029 return CMD_WARNING;
11030 }
11031
11032 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11033 (argc == 4) ? argv[3] : argv[2],
11034 AFI_IP, safi, NULL, 1);
11035}
11036
11037ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11038 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11039 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11040 SHOW_STR
11041 BGP_STR
11042 "Address family\n"
11043 "Address Family modifier\n"
11044 "Address Family modifier\n"
11045 "Information about Route Server Client\n"
11046 NEIGHBOR_ADDR_STR
11047 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011048
paul718e3742002-12-13 20:15:29 +000011049#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011050DEFUN (show_bgp_view_neighbor_routes,
11051 show_bgp_view_neighbor_routes_cmd,
11052 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11053 SHOW_STR
11054 BGP_STR
11055 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011056 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011057 "Detailed information on TCP and BGP neighbor connections\n"
11058 "Neighbor to display information about\n"
11059 "Neighbor to display information about\n"
11060 "Display routes learned from neighbor\n")
11061{
11062 struct peer *peer;
11063
11064 if (argc == 2)
11065 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11066 else
11067 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11068
11069 if (! peer)
11070 return CMD_WARNING;
11071
11072 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11073 bgp_show_type_neighbor);
11074}
11075
11076ALIAS (show_bgp_view_neighbor_routes,
11077 show_bgp_view_ipv6_neighbor_routes_cmd,
11078 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11079 SHOW_STR
11080 BGP_STR
11081 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011082 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011083 "Address family\n"
11084 "Detailed information on TCP and BGP neighbor connections\n"
11085 "Neighbor to display information about\n"
11086 "Neighbor to display information about\n"
11087 "Display routes learned from neighbor\n")
11088
11089DEFUN (show_bgp_view_neighbor_damp,
11090 show_bgp_view_neighbor_damp_cmd,
11091 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11092 SHOW_STR
11093 BGP_STR
11094 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011095 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011096 "Detailed information on TCP and BGP neighbor connections\n"
11097 "Neighbor to display information about\n"
11098 "Neighbor to display information about\n"
11099 "Display the dampened routes received from neighbor\n")
11100{
11101 struct peer *peer;
11102
11103 if (argc == 2)
11104 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11105 else
11106 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11107
11108 if (! peer)
11109 return CMD_WARNING;
11110
11111 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11112 bgp_show_type_damp_neighbor);
11113}
11114
11115ALIAS (show_bgp_view_neighbor_damp,
11116 show_bgp_view_ipv6_neighbor_damp_cmd,
11117 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11118 SHOW_STR
11119 BGP_STR
11120 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011121 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011122 "Address family\n"
11123 "Detailed information on TCP and BGP neighbor connections\n"
11124 "Neighbor to display information about\n"
11125 "Neighbor to display information about\n"
11126 "Display the dampened routes received from neighbor\n")
11127
11128DEFUN (show_bgp_view_neighbor_flap,
11129 show_bgp_view_neighbor_flap_cmd,
11130 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11131 SHOW_STR
11132 BGP_STR
11133 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011134 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011135 "Detailed information on TCP and BGP neighbor connections\n"
11136 "Neighbor to display information about\n"
11137 "Neighbor to display information about\n"
11138 "Display flap statistics of the routes learned from neighbor\n")
11139{
11140 struct peer *peer;
11141
11142 if (argc == 2)
11143 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11144 else
11145 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11146
11147 if (! peer)
11148 return CMD_WARNING;
11149
11150 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11151 bgp_show_type_flap_neighbor);
11152}
11153
11154ALIAS (show_bgp_view_neighbor_flap,
11155 show_bgp_view_ipv6_neighbor_flap_cmd,
11156 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11157 SHOW_STR
11158 BGP_STR
11159 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011160 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011161 "Address family\n"
11162 "Detailed information on TCP and BGP neighbor connections\n"
11163 "Neighbor to display information about\n"
11164 "Neighbor to display information about\n"
11165 "Display flap statistics of the routes learned from neighbor\n")
11166
11167ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011168 show_bgp_neighbor_routes_cmd,
11169 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11170 SHOW_STR
11171 BGP_STR
11172 "Detailed information on TCP and BGP neighbor connections\n"
11173 "Neighbor to display information about\n"
11174 "Neighbor to display information about\n"
11175 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011176
paulbb46e942003-10-24 19:02:03 +000011177
11178ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011179 show_bgp_ipv6_neighbor_routes_cmd,
11180 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11181 SHOW_STR
11182 BGP_STR
11183 "Address family\n"
11184 "Detailed information on TCP and BGP neighbor connections\n"
11185 "Neighbor to display information about\n"
11186 "Neighbor to display information about\n"
11187 "Display routes learned from neighbor\n")
11188
11189/* old command */
paulbb46e942003-10-24 19:02:03 +000011190ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011191 ipv6_bgp_neighbor_routes_cmd,
11192 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11193 SHOW_STR
11194 IPV6_STR
11195 BGP_STR
11196 "Detailed information on TCP and BGP neighbor connections\n"
11197 "Neighbor to display information about\n"
11198 "Neighbor to display information about\n"
11199 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011200
11201/* old command */
11202DEFUN (ipv6_mbgp_neighbor_routes,
11203 ipv6_mbgp_neighbor_routes_cmd,
11204 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11205 SHOW_STR
11206 IPV6_STR
11207 MBGP_STR
11208 "Detailed information on TCP and BGP neighbor connections\n"
11209 "Neighbor to display information about\n"
11210 "Neighbor to display information about\n"
11211 "Display routes learned from neighbor\n")
11212{
paulbb46e942003-10-24 19:02:03 +000011213 struct peer *peer;
11214
11215 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11216 if (! peer)
11217 return CMD_WARNING;
11218
11219 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011220 bgp_show_type_neighbor);
11221}
paulbb46e942003-10-24 19:02:03 +000011222
11223ALIAS (show_bgp_view_neighbor_flap,
11224 show_bgp_neighbor_flap_cmd,
11225 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11226 SHOW_STR
11227 BGP_STR
11228 "Detailed information on TCP and BGP neighbor connections\n"
11229 "Neighbor to display information about\n"
11230 "Neighbor to display information about\n"
11231 "Display flap statistics of the routes learned from neighbor\n")
11232
11233ALIAS (show_bgp_view_neighbor_flap,
11234 show_bgp_ipv6_neighbor_flap_cmd,
11235 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11236 SHOW_STR
11237 BGP_STR
11238 "Address family\n"
11239 "Detailed information on TCP and BGP neighbor connections\n"
11240 "Neighbor to display information about\n"
11241 "Neighbor to display information about\n"
11242 "Display flap statistics of the routes learned from neighbor\n")
11243
11244ALIAS (show_bgp_view_neighbor_damp,
11245 show_bgp_neighbor_damp_cmd,
11246 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11247 SHOW_STR
11248 BGP_STR
11249 "Detailed information on TCP and BGP neighbor connections\n"
11250 "Neighbor to display information about\n"
11251 "Neighbor to display information about\n"
11252 "Display the dampened routes received from neighbor\n")
11253
11254ALIAS (show_bgp_view_neighbor_damp,
11255 show_bgp_ipv6_neighbor_damp_cmd,
11256 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11257 SHOW_STR
11258 BGP_STR
11259 "Address family\n"
11260 "Detailed information on TCP and BGP neighbor connections\n"
11261 "Neighbor to display information about\n"
11262 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011263 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011264
11265DEFUN (show_bgp_view_rsclient,
11266 show_bgp_view_rsclient_cmd,
11267 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11268 SHOW_STR
11269 BGP_STR
11270 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011271 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011272 "Information about Route Server Client\n"
11273 NEIGHBOR_ADDR_STR)
11274{
11275 struct bgp_table *table;
11276 struct peer *peer;
11277
11278 if (argc == 2)
11279 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11280 else
11281 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11282
11283 if (! peer)
11284 return CMD_WARNING;
11285
11286 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11287 {
11288 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11289 VTY_NEWLINE);
11290 return CMD_WARNING;
11291 }
11292
11293 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11294 PEER_FLAG_RSERVER_CLIENT))
11295 {
11296 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11297 VTY_NEWLINE);
11298 return CMD_WARNING;
11299 }
11300
11301 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11302
ajs5a646652004-11-05 01:25:55 +000011303 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011304}
11305
11306ALIAS (show_bgp_view_rsclient,
11307 show_bgp_rsclient_cmd,
11308 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11309 SHOW_STR
11310 BGP_STR
11311 "Information about Route Server Client\n"
11312 NEIGHBOR_ADDR_STR)
11313
Michael Lambert95cbbd22010-07-23 14:43:04 -040011314DEFUN (show_bgp_view_ipv6_safi_rsclient,
11315 show_bgp_view_ipv6_safi_rsclient_cmd,
11316 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11317 SHOW_STR
11318 BGP_STR
11319 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011320 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011321 "Address family\n"
11322 "Address Family modifier\n"
11323 "Address Family modifier\n"
11324 "Information about Route Server Client\n"
11325 NEIGHBOR_ADDR_STR)
11326{
11327 struct bgp_table *table;
11328 struct peer *peer;
11329 safi_t safi;
11330
11331 if (argc == 3) {
11332 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11333 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11334 } else {
11335 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11336 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11337 }
11338
11339 if (! peer)
11340 return CMD_WARNING;
11341
11342 if (! peer->afc[AFI_IP6][safi])
11343 {
11344 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11345 VTY_NEWLINE);
11346 return CMD_WARNING;
11347 }
11348
11349 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11350 PEER_FLAG_RSERVER_CLIENT))
11351 {
11352 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11353 VTY_NEWLINE);
11354 return CMD_WARNING;
11355 }
11356
11357 table = peer->rib[AFI_IP6][safi];
11358
11359 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11360}
11361
11362ALIAS (show_bgp_view_ipv6_safi_rsclient,
11363 show_bgp_ipv6_safi_rsclient_cmd,
11364 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11365 SHOW_STR
11366 BGP_STR
11367 "Address family\n"
11368 "Address Family modifier\n"
11369 "Address Family modifier\n"
11370 "Information about Route Server Client\n"
11371 NEIGHBOR_ADDR_STR)
11372
paulfee0f4c2004-09-13 05:12:46 +000011373DEFUN (show_bgp_view_rsclient_route,
11374 show_bgp_view_rsclient_route_cmd,
11375 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11376 SHOW_STR
11377 BGP_STR
11378 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011379 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011380 "Information about Route Server Client\n"
11381 NEIGHBOR_ADDR_STR
11382 "Network in the BGP routing table to display\n")
11383{
11384 struct bgp *bgp;
11385 struct peer *peer;
11386
11387 /* BGP structure lookup. */
11388 if (argc == 3)
11389 {
11390 bgp = bgp_lookup_by_name (argv[0]);
11391 if (bgp == NULL)
11392 {
11393 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11394 return CMD_WARNING;
11395 }
11396 }
11397 else
11398 {
11399 bgp = bgp_get_default ();
11400 if (bgp == NULL)
11401 {
11402 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11403 return CMD_WARNING;
11404 }
11405 }
11406
11407 if (argc == 3)
11408 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11409 else
11410 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11411
11412 if (! peer)
11413 return CMD_WARNING;
11414
11415 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11416 {
11417 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11418 VTY_NEWLINE);
11419 return CMD_WARNING;
11420 }
11421
11422 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11423 PEER_FLAG_RSERVER_CLIENT))
11424 {
11425 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11426 VTY_NEWLINE);
11427 return CMD_WARNING;
11428 }
11429
11430 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11431 (argc == 3) ? argv[2] : argv[1],
11432 AFI_IP6, SAFI_UNICAST, NULL, 0);
11433}
11434
11435ALIAS (show_bgp_view_rsclient_route,
11436 show_bgp_rsclient_route_cmd,
11437 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11438 SHOW_STR
11439 BGP_STR
11440 "Information about Route Server Client\n"
11441 NEIGHBOR_ADDR_STR
11442 "Network in the BGP routing table to display\n")
11443
Michael Lambert95cbbd22010-07-23 14:43:04 -040011444DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11445 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11446 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11447 SHOW_STR
11448 BGP_STR
11449 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011450 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011451 "Address family\n"
11452 "Address Family modifier\n"
11453 "Address Family modifier\n"
11454 "Information about Route Server Client\n"
11455 NEIGHBOR_ADDR_STR
11456 "Network in the BGP routing table to display\n")
11457{
11458 struct bgp *bgp;
11459 struct peer *peer;
11460 safi_t safi;
11461
11462 /* BGP structure lookup. */
11463 if (argc == 4)
11464 {
11465 bgp = bgp_lookup_by_name (argv[0]);
11466 if (bgp == NULL)
11467 {
11468 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11469 return CMD_WARNING;
11470 }
11471 }
11472 else
11473 {
11474 bgp = bgp_get_default ();
11475 if (bgp == NULL)
11476 {
11477 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11478 return CMD_WARNING;
11479 }
11480 }
11481
11482 if (argc == 4) {
11483 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11484 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11485 } else {
11486 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11487 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11488 }
11489
11490 if (! peer)
11491 return CMD_WARNING;
11492
11493 if (! peer->afc[AFI_IP6][safi])
11494 {
11495 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11496 VTY_NEWLINE);
11497 return CMD_WARNING;
11498}
11499
11500 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11501 PEER_FLAG_RSERVER_CLIENT))
11502 {
11503 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11504 VTY_NEWLINE);
11505 return CMD_WARNING;
11506 }
11507
11508 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11509 (argc == 4) ? argv[3] : argv[2],
11510 AFI_IP6, safi, NULL, 0);
11511}
11512
11513ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11514 show_bgp_ipv6_safi_rsclient_route_cmd,
11515 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11516 SHOW_STR
11517 BGP_STR
11518 "Address family\n"
11519 "Address Family modifier\n"
11520 "Address Family modifier\n"
11521 "Information about Route Server Client\n"
11522 NEIGHBOR_ADDR_STR
11523 "Network in the BGP routing table to display\n")
11524
paulfee0f4c2004-09-13 05:12:46 +000011525DEFUN (show_bgp_view_rsclient_prefix,
11526 show_bgp_view_rsclient_prefix_cmd,
11527 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11528 SHOW_STR
11529 BGP_STR
11530 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011531 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011532 "Information about Route Server Client\n"
11533 NEIGHBOR_ADDR_STR
11534 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11535{
11536 struct bgp *bgp;
11537 struct peer *peer;
11538
11539 /* BGP structure lookup. */
11540 if (argc == 3)
11541 {
11542 bgp = bgp_lookup_by_name (argv[0]);
11543 if (bgp == NULL)
11544 {
11545 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11546 return CMD_WARNING;
11547 }
11548 }
11549 else
11550 {
11551 bgp = bgp_get_default ();
11552 if (bgp == NULL)
11553 {
11554 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11555 return CMD_WARNING;
11556 }
11557 }
11558
11559 if (argc == 3)
11560 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11561 else
11562 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11563
11564 if (! peer)
11565 return CMD_WARNING;
11566
11567 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11568 {
11569 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11570 VTY_NEWLINE);
11571 return CMD_WARNING;
11572 }
11573
11574 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11575 PEER_FLAG_RSERVER_CLIENT))
11576 {
11577 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11578 VTY_NEWLINE);
11579 return CMD_WARNING;
11580 }
11581
11582 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11583 (argc == 3) ? argv[2] : argv[1],
11584 AFI_IP6, SAFI_UNICAST, NULL, 1);
11585}
11586
11587ALIAS (show_bgp_view_rsclient_prefix,
11588 show_bgp_rsclient_prefix_cmd,
11589 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11590 SHOW_STR
11591 BGP_STR
11592 "Information about Route Server Client\n"
11593 NEIGHBOR_ADDR_STR
11594 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11595
Michael Lambert95cbbd22010-07-23 14:43:04 -040011596DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11597 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11598 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11599 SHOW_STR
11600 BGP_STR
11601 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011602 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011603 "Address family\n"
11604 "Address Family modifier\n"
11605 "Address Family modifier\n"
11606 "Information about Route Server Client\n"
11607 NEIGHBOR_ADDR_STR
11608 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11609{
11610 struct bgp *bgp;
11611 struct peer *peer;
11612 safi_t safi;
11613
11614 /* BGP structure lookup. */
11615 if (argc == 4)
11616 {
11617 bgp = bgp_lookup_by_name (argv[0]);
11618 if (bgp == NULL)
11619 {
11620 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11621 return CMD_WARNING;
11622 }
11623 }
11624 else
11625 {
11626 bgp = bgp_get_default ();
11627 if (bgp == NULL)
11628 {
11629 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11630 return CMD_WARNING;
11631 }
11632 }
11633
11634 if (argc == 4) {
11635 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11636 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11637 } else {
11638 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11639 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11640 }
11641
11642 if (! peer)
11643 return CMD_WARNING;
11644
11645 if (! peer->afc[AFI_IP6][safi])
11646 {
11647 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11648 VTY_NEWLINE);
11649 return CMD_WARNING;
11650}
11651
11652 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11653 PEER_FLAG_RSERVER_CLIENT))
11654{
11655 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11656 VTY_NEWLINE);
11657 return CMD_WARNING;
11658 }
11659
11660 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11661 (argc == 4) ? argv[3] : argv[2],
11662 AFI_IP6, safi, NULL, 1);
11663}
11664
11665ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11666 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11667 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11668 SHOW_STR
11669 BGP_STR
11670 "Address family\n"
11671 "Address Family modifier\n"
11672 "Address Family modifier\n"
11673 "Information about Route Server Client\n"
11674 NEIGHBOR_ADDR_STR
11675 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11676
paul718e3742002-12-13 20:15:29 +000011677#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020011678
paul718e3742002-12-13 20:15:29 +000011679struct bgp_table *bgp_distance_table;
11680
11681struct bgp_distance
11682{
11683 /* Distance value for the IP source prefix. */
11684 u_char distance;
11685
11686 /* Name of the access-list to be matched. */
11687 char *access_list;
11688};
11689
paul94f2b392005-06-28 12:44:16 +000011690static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011691bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011692{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011693 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011694}
11695
paul94f2b392005-06-28 12:44:16 +000011696static void
paul718e3742002-12-13 20:15:29 +000011697bgp_distance_free (struct bgp_distance *bdistance)
11698{
11699 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11700}
11701
paul94f2b392005-06-28 12:44:16 +000011702static int
paulfd79ac92004-10-13 05:06:08 +000011703bgp_distance_set (struct vty *vty, const char *distance_str,
11704 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011705{
11706 int ret;
11707 struct prefix_ipv4 p;
11708 u_char distance;
11709 struct bgp_node *rn;
11710 struct bgp_distance *bdistance;
11711
11712 ret = str2prefix_ipv4 (ip_str, &p);
11713 if (ret == 0)
11714 {
11715 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11716 return CMD_WARNING;
11717 }
11718
11719 distance = atoi (distance_str);
11720
11721 /* Get BGP distance node. */
11722 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11723 if (rn->info)
11724 {
11725 bdistance = rn->info;
11726 bgp_unlock_node (rn);
11727 }
11728 else
11729 {
11730 bdistance = bgp_distance_new ();
11731 rn->info = bdistance;
11732 }
11733
11734 /* Set distance value. */
11735 bdistance->distance = distance;
11736
11737 /* Reset access-list configuration. */
11738 if (bdistance->access_list)
11739 {
11740 free (bdistance->access_list);
11741 bdistance->access_list = NULL;
11742 }
11743 if (access_list_str)
11744 bdistance->access_list = strdup (access_list_str);
11745
11746 return CMD_SUCCESS;
11747}
11748
paul94f2b392005-06-28 12:44:16 +000011749static int
paulfd79ac92004-10-13 05:06:08 +000011750bgp_distance_unset (struct vty *vty, const char *distance_str,
11751 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011752{
11753 int ret;
11754 struct prefix_ipv4 p;
11755 u_char distance;
11756 struct bgp_node *rn;
11757 struct bgp_distance *bdistance;
11758
11759 ret = str2prefix_ipv4 (ip_str, &p);
11760 if (ret == 0)
11761 {
11762 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11763 return CMD_WARNING;
11764 }
11765
11766 distance = atoi (distance_str);
11767
11768 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11769 if (! rn)
11770 {
11771 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11772 return CMD_WARNING;
11773 }
11774
11775 bdistance = rn->info;
11776
11777 if (bdistance->access_list)
11778 free (bdistance->access_list);
11779 bgp_distance_free (bdistance);
11780
11781 rn->info = NULL;
11782 bgp_unlock_node (rn);
11783 bgp_unlock_node (rn);
11784
11785 return CMD_SUCCESS;
11786}
11787
paul718e3742002-12-13 20:15:29 +000011788/* Apply BGP information to distance method. */
11789u_char
11790bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11791{
11792 struct bgp_node *rn;
11793 struct prefix_ipv4 q;
11794 struct peer *peer;
11795 struct bgp_distance *bdistance;
11796 struct access_list *alist;
11797 struct bgp_static *bgp_static;
11798
11799 if (! bgp)
11800 return 0;
11801
11802 if (p->family != AF_INET)
11803 return 0;
11804
11805 peer = rinfo->peer;
11806
11807 if (peer->su.sa.sa_family != AF_INET)
11808 return 0;
11809
11810 memset (&q, 0, sizeof (struct prefix_ipv4));
11811 q.family = AF_INET;
11812 q.prefix = peer->su.sin.sin_addr;
11813 q.prefixlen = IPV4_MAX_BITLEN;
11814
11815 /* Check source address. */
11816 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11817 if (rn)
11818 {
11819 bdistance = rn->info;
11820 bgp_unlock_node (rn);
11821
11822 if (bdistance->access_list)
11823 {
11824 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11825 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11826 return bdistance->distance;
11827 }
11828 else
11829 return bdistance->distance;
11830 }
11831
11832 /* Backdoor check. */
11833 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11834 if (rn)
11835 {
11836 bgp_static = rn->info;
11837 bgp_unlock_node (rn);
11838
11839 if (bgp_static->backdoor)
11840 {
11841 if (bgp->distance_local)
11842 return bgp->distance_local;
11843 else
11844 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11845 }
11846 }
11847
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011848 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011849 {
11850 if (bgp->distance_ebgp)
11851 return bgp->distance_ebgp;
11852 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11853 }
11854 else
11855 {
11856 if (bgp->distance_ibgp)
11857 return bgp->distance_ibgp;
11858 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11859 }
11860}
11861
11862DEFUN (bgp_distance,
11863 bgp_distance_cmd,
11864 "distance bgp <1-255> <1-255> <1-255>",
11865 "Define an administrative distance\n"
11866 "BGP distance\n"
11867 "Distance for routes external to the AS\n"
11868 "Distance for routes internal to the AS\n"
11869 "Distance for local routes\n")
11870{
11871 struct bgp *bgp;
11872
11873 bgp = vty->index;
11874
11875 bgp->distance_ebgp = atoi (argv[0]);
11876 bgp->distance_ibgp = atoi (argv[1]);
11877 bgp->distance_local = atoi (argv[2]);
11878 return CMD_SUCCESS;
11879}
11880
11881DEFUN (no_bgp_distance,
11882 no_bgp_distance_cmd,
11883 "no distance bgp <1-255> <1-255> <1-255>",
11884 NO_STR
11885 "Define an administrative distance\n"
11886 "BGP distance\n"
11887 "Distance for routes external to the AS\n"
11888 "Distance for routes internal to the AS\n"
11889 "Distance for local routes\n")
11890{
11891 struct bgp *bgp;
11892
11893 bgp = vty->index;
11894
11895 bgp->distance_ebgp= 0;
11896 bgp->distance_ibgp = 0;
11897 bgp->distance_local = 0;
11898 return CMD_SUCCESS;
11899}
11900
11901ALIAS (no_bgp_distance,
11902 no_bgp_distance2_cmd,
11903 "no distance bgp",
11904 NO_STR
11905 "Define an administrative distance\n"
11906 "BGP distance\n")
11907
11908DEFUN (bgp_distance_source,
11909 bgp_distance_source_cmd,
11910 "distance <1-255> A.B.C.D/M",
11911 "Define an administrative distance\n"
11912 "Administrative distance\n"
11913 "IP source prefix\n")
11914{
11915 bgp_distance_set (vty, argv[0], argv[1], NULL);
11916 return CMD_SUCCESS;
11917}
11918
11919DEFUN (no_bgp_distance_source,
11920 no_bgp_distance_source_cmd,
11921 "no distance <1-255> A.B.C.D/M",
11922 NO_STR
11923 "Define an administrative distance\n"
11924 "Administrative distance\n"
11925 "IP source prefix\n")
11926{
11927 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11928 return CMD_SUCCESS;
11929}
11930
11931DEFUN (bgp_distance_source_access_list,
11932 bgp_distance_source_access_list_cmd,
11933 "distance <1-255> A.B.C.D/M WORD",
11934 "Define an administrative distance\n"
11935 "Administrative distance\n"
11936 "IP source prefix\n"
11937 "Access list name\n")
11938{
11939 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11940 return CMD_SUCCESS;
11941}
11942
11943DEFUN (no_bgp_distance_source_access_list,
11944 no_bgp_distance_source_access_list_cmd,
11945 "no distance <1-255> A.B.C.D/M WORD",
11946 NO_STR
11947 "Define an administrative distance\n"
11948 "Administrative distance\n"
11949 "IP source prefix\n"
11950 "Access list name\n")
11951{
11952 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11953 return CMD_SUCCESS;
11954}
David Lamparter6b0655a2014-06-04 06:53:35 +020011955
paul718e3742002-12-13 20:15:29 +000011956DEFUN (bgp_damp_set,
11957 bgp_damp_set_cmd,
11958 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11959 "BGP Specific commands\n"
11960 "Enable route-flap dampening\n"
11961 "Half-life time for the penalty\n"
11962 "Value to start reusing a route\n"
11963 "Value to start suppressing a route\n"
11964 "Maximum duration to suppress a stable route\n")
11965{
11966 struct bgp *bgp;
11967 int half = DEFAULT_HALF_LIFE * 60;
11968 int reuse = DEFAULT_REUSE;
11969 int suppress = DEFAULT_SUPPRESS;
11970 int max = 4 * half;
11971
11972 if (argc == 4)
11973 {
11974 half = atoi (argv[0]) * 60;
11975 reuse = atoi (argv[1]);
11976 suppress = atoi (argv[2]);
11977 max = atoi (argv[3]) * 60;
11978 }
11979 else if (argc == 1)
11980 {
11981 half = atoi (argv[0]) * 60;
11982 max = 4 * half;
11983 }
11984
11985 bgp = vty->index;
11986 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11987 half, reuse, suppress, max);
11988}
11989
11990ALIAS (bgp_damp_set,
11991 bgp_damp_set2_cmd,
11992 "bgp dampening <1-45>",
11993 "BGP Specific commands\n"
11994 "Enable route-flap dampening\n"
11995 "Half-life time for the penalty\n")
11996
11997ALIAS (bgp_damp_set,
11998 bgp_damp_set3_cmd,
11999 "bgp dampening",
12000 "BGP Specific commands\n"
12001 "Enable route-flap dampening\n")
12002
12003DEFUN (bgp_damp_unset,
12004 bgp_damp_unset_cmd,
12005 "no bgp dampening",
12006 NO_STR
12007 "BGP Specific commands\n"
12008 "Enable route-flap dampening\n")
12009{
12010 struct bgp *bgp;
12011
12012 bgp = vty->index;
12013 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
12014}
12015
12016ALIAS (bgp_damp_unset,
12017 bgp_damp_unset2_cmd,
12018 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12019 NO_STR
12020 "BGP Specific commands\n"
12021 "Enable route-flap dampening\n"
12022 "Half-life time for the penalty\n"
12023 "Value to start reusing a route\n"
12024 "Value to start suppressing a route\n"
12025 "Maximum duration to suppress a stable route\n")
12026
12027DEFUN (show_ip_bgp_dampened_paths,
12028 show_ip_bgp_dampened_paths_cmd,
12029 "show ip bgp dampened-paths",
12030 SHOW_STR
12031 IP_STR
12032 BGP_STR
12033 "Display paths suppressed due to dampening\n")
12034{
ajs5a646652004-11-05 01:25:55 +000012035 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
12036 NULL);
paul718e3742002-12-13 20:15:29 +000012037}
12038
12039DEFUN (show_ip_bgp_flap_statistics,
12040 show_ip_bgp_flap_statistics_cmd,
12041 "show ip bgp flap-statistics",
12042 SHOW_STR
12043 IP_STR
12044 BGP_STR
12045 "Display flap statistics of routes\n")
12046{
ajs5a646652004-11-05 01:25:55 +000012047 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12048 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012049}
David Lamparter6b0655a2014-06-04 06:53:35 +020012050
paul718e3742002-12-13 20:15:29 +000012051/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012052static int
paulfd79ac92004-10-13 05:06:08 +000012053bgp_clear_damp_route (struct vty *vty, const char *view_name,
12054 const char *ip_str, afi_t afi, safi_t safi,
12055 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012056{
12057 int ret;
12058 struct prefix match;
12059 struct bgp_node *rn;
12060 struct bgp_node *rm;
12061 struct bgp_info *ri;
12062 struct bgp_info *ri_temp;
12063 struct bgp *bgp;
12064 struct bgp_table *table;
12065
12066 /* BGP structure lookup. */
12067 if (view_name)
12068 {
12069 bgp = bgp_lookup_by_name (view_name);
12070 if (bgp == NULL)
12071 {
12072 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12073 return CMD_WARNING;
12074 }
12075 }
12076 else
12077 {
12078 bgp = bgp_get_default ();
12079 if (bgp == NULL)
12080 {
12081 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12082 return CMD_WARNING;
12083 }
12084 }
12085
12086 /* Check IP address argument. */
12087 ret = str2prefix (ip_str, &match);
12088 if (! ret)
12089 {
12090 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12091 return CMD_WARNING;
12092 }
12093
12094 match.family = afi2family (afi);
12095
12096 if (safi == SAFI_MPLS_VPN)
12097 {
12098 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12099 {
12100 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12101 continue;
12102
12103 if ((table = rn->info) != NULL)
12104 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012105 {
12106 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12107 {
12108 ri = rm->info;
12109 while (ri)
12110 {
12111 if (ri->extra && ri->extra->damp_info)
12112 {
12113 ri_temp = ri->next;
12114 bgp_damp_info_free (ri->extra->damp_info, 1);
12115 ri = ri_temp;
12116 }
12117 else
12118 ri = ri->next;
12119 }
12120 }
12121
12122 bgp_unlock_node (rm);
12123 }
paul718e3742002-12-13 20:15:29 +000012124 }
12125 }
12126 else
12127 {
12128 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012129 {
12130 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12131 {
12132 ri = rn->info;
12133 while (ri)
12134 {
12135 if (ri->extra && ri->extra->damp_info)
12136 {
12137 ri_temp = ri->next;
12138 bgp_damp_info_free (ri->extra->damp_info, 1);
12139 ri = ri_temp;
12140 }
12141 else
12142 ri = ri->next;
12143 }
12144 }
12145
12146 bgp_unlock_node (rn);
12147 }
paul718e3742002-12-13 20:15:29 +000012148 }
12149
12150 return CMD_SUCCESS;
12151}
12152
12153DEFUN (clear_ip_bgp_dampening,
12154 clear_ip_bgp_dampening_cmd,
12155 "clear ip bgp dampening",
12156 CLEAR_STR
12157 IP_STR
12158 BGP_STR
12159 "Clear route flap dampening information\n")
12160{
12161 bgp_damp_info_clean ();
12162 return CMD_SUCCESS;
12163}
12164
12165DEFUN (clear_ip_bgp_dampening_prefix,
12166 clear_ip_bgp_dampening_prefix_cmd,
12167 "clear ip bgp dampening A.B.C.D/M",
12168 CLEAR_STR
12169 IP_STR
12170 BGP_STR
12171 "Clear route flap dampening information\n"
12172 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12173{
12174 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12175 SAFI_UNICAST, NULL, 1);
12176}
12177
12178DEFUN (clear_ip_bgp_dampening_address,
12179 clear_ip_bgp_dampening_address_cmd,
12180 "clear ip bgp dampening A.B.C.D",
12181 CLEAR_STR
12182 IP_STR
12183 BGP_STR
12184 "Clear route flap dampening information\n"
12185 "Network to clear damping information\n")
12186{
12187 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12188 SAFI_UNICAST, NULL, 0);
12189}
12190
12191DEFUN (clear_ip_bgp_dampening_address_mask,
12192 clear_ip_bgp_dampening_address_mask_cmd,
12193 "clear ip bgp dampening A.B.C.D A.B.C.D",
12194 CLEAR_STR
12195 IP_STR
12196 BGP_STR
12197 "Clear route flap dampening information\n"
12198 "Network to clear damping information\n"
12199 "Network mask\n")
12200{
12201 int ret;
12202 char prefix_str[BUFSIZ];
12203
12204 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12205 if (! ret)
12206 {
12207 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12208 return CMD_WARNING;
12209 }
12210
12211 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12212 SAFI_UNICAST, NULL, 0);
12213}
David Lamparter6b0655a2014-06-04 06:53:35 +020012214
paul94f2b392005-06-28 12:44:16 +000012215static int
paul718e3742002-12-13 20:15:29 +000012216bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12217 afi_t afi, safi_t safi, int *write)
12218{
12219 struct bgp_node *prn;
12220 struct bgp_node *rn;
12221 struct bgp_table *table;
12222 struct prefix *p;
12223 struct prefix_rd *prd;
12224 struct bgp_static *bgp_static;
12225 u_int32_t label;
12226 char buf[SU_ADDRSTRLEN];
12227 char rdbuf[RD_ADDRSTRLEN];
12228
12229 /* Network configuration. */
12230 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12231 if ((table = prn->info) != NULL)
12232 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12233 if ((bgp_static = rn->info) != NULL)
12234 {
12235 p = &rn->p;
12236 prd = (struct prefix_rd *) &prn->p;
12237
12238 /* "address-family" display. */
12239 bgp_config_write_family_header (vty, afi, safi, write);
12240
12241 /* "network" configuration display. */
12242 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12243 label = decode_label (bgp_static->tag);
12244
12245 vty_out (vty, " network %s/%d rd %s tag %d",
12246 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12247 p->prefixlen,
12248 rdbuf, label);
12249 vty_out (vty, "%s", VTY_NEWLINE);
12250 }
12251 return 0;
12252}
12253
12254/* Configuration of static route announcement and aggregate
12255 information. */
12256int
12257bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12258 afi_t afi, safi_t safi, int *write)
12259{
12260 struct bgp_node *rn;
12261 struct prefix *p;
12262 struct bgp_static *bgp_static;
12263 struct bgp_aggregate *bgp_aggregate;
12264 char buf[SU_ADDRSTRLEN];
12265
12266 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12267 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12268
12269 /* Network configuration. */
12270 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12271 if ((bgp_static = rn->info) != NULL)
12272 {
12273 p = &rn->p;
12274
12275 /* "address-family" display. */
12276 bgp_config_write_family_header (vty, afi, safi, write);
12277
12278 /* "network" configuration display. */
12279 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12280 {
12281 u_int32_t destination;
12282 struct in_addr netmask;
12283
12284 destination = ntohl (p->u.prefix4.s_addr);
12285 masklen2ip (p->prefixlen, &netmask);
12286 vty_out (vty, " network %s",
12287 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12288
12289 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12290 || (IN_CLASSB (destination) && p->prefixlen == 16)
12291 || (IN_CLASSA (destination) && p->prefixlen == 8)
12292 || p->u.prefix4.s_addr == 0)
12293 {
12294 /* Natural mask is not display. */
12295 }
12296 else
12297 vty_out (vty, " mask %s", inet_ntoa (netmask));
12298 }
12299 else
12300 {
12301 vty_out (vty, " network %s/%d",
12302 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12303 p->prefixlen);
12304 }
12305
12306 if (bgp_static->rmap.name)
12307 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012308 else
12309 {
12310 if (bgp_static->backdoor)
12311 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012312 }
paul718e3742002-12-13 20:15:29 +000012313
12314 vty_out (vty, "%s", VTY_NEWLINE);
12315 }
12316
12317 /* Aggregate-address configuration. */
12318 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12319 if ((bgp_aggregate = rn->info) != NULL)
12320 {
12321 p = &rn->p;
12322
12323 /* "address-family" display. */
12324 bgp_config_write_family_header (vty, afi, safi, write);
12325
12326 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12327 {
12328 struct in_addr netmask;
12329
12330 masklen2ip (p->prefixlen, &netmask);
12331 vty_out (vty, " aggregate-address %s %s",
12332 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12333 inet_ntoa (netmask));
12334 }
12335 else
12336 {
12337 vty_out (vty, " aggregate-address %s/%d",
12338 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12339 p->prefixlen);
12340 }
12341
12342 if (bgp_aggregate->as_set)
12343 vty_out (vty, " as-set");
12344
12345 if (bgp_aggregate->summary_only)
12346 vty_out (vty, " summary-only");
12347
12348 vty_out (vty, "%s", VTY_NEWLINE);
12349 }
12350
12351 return 0;
12352}
12353
12354int
12355bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12356{
12357 struct bgp_node *rn;
12358 struct bgp_distance *bdistance;
12359
12360 /* Distance configuration. */
12361 if (bgp->distance_ebgp
12362 && bgp->distance_ibgp
12363 && bgp->distance_local
12364 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12365 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12366 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12367 vty_out (vty, " distance bgp %d %d %d%s",
12368 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12369 VTY_NEWLINE);
12370
12371 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12372 if ((bdistance = rn->info) != NULL)
12373 {
12374 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12375 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12376 bdistance->access_list ? bdistance->access_list : "",
12377 VTY_NEWLINE);
12378 }
12379
12380 return 0;
12381}
12382
12383/* Allocate routing table structure and install commands. */
12384void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012385bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012386{
12387 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012388 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012389
12390 /* IPv4 BGP commands. */
12391 install_element (BGP_NODE, &bgp_network_cmd);
12392 install_element (BGP_NODE, &bgp_network_mask_cmd);
12393 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12394 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12395 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12396 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12397 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12398 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12399 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12400 install_element (BGP_NODE, &no_bgp_network_cmd);
12401 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12402 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12403 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12404 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12405 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12406 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12407 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12408 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12409
12410 install_element (BGP_NODE, &aggregate_address_cmd);
12411 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12412 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12413 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12414 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12415 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12416 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12417 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12418 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12419 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12420 install_element (BGP_NODE, &no_aggregate_address_cmd);
12421 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12422 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12423 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12424 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12425 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12426 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12427 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12428 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12429 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12430
12431 /* IPv4 unicast configuration. */
12432 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12433 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12434 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12435 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12436 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12437 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012438 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012439 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12440 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12441 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12442 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12443 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012444
paul718e3742002-12-13 20:15:29 +000012445 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12446 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12447 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12448 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12449 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12450 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12451 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12452 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12453 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12454 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12455 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12456 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12457 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12458 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12459 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12460 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12461 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12462 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12463 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12464 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12465
12466 /* IPv4 multicast configuration. */
12467 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12468 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12469 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12470 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12471 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12472 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12473 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12474 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12475 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12476 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12477 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12478 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12479 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12480 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12481 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12482 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12483 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12484 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12485 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12486 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12487 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12488 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12489 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12490 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12491 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12492 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12493 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12494 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12495 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12496 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12497 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12498 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12499
12500 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12501 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012502 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012503 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12504 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012505 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012506 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12507 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12508 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12509 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012510 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012511 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12512 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12513 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12514 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12515 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12516 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12517 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12518 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12519 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12520 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12521 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12522 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12523 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12524 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12525 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12526 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12527 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12528 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12529 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12530 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12531 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12532 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12533 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12534 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12535 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012536 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12537 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12538 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12539 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12540 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012541 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12542 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12543 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12544 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12545 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12546 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12547 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12548 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12549 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12550 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12551 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12552 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12553 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12554 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12555 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12556 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12557 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12558 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012559 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012560 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12561 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12562 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12563 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12564 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12565 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12566 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12567 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12568 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12569 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12570 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12571 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12572 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12573 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12574 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12575 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012576 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012577 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012578 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012579 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012580 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012581 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012582 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12583 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012584 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012585 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012586 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012587 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012588 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012589 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012590
12591 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12592 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12593 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012594 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012595 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12596 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12597 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012598 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012599 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12600 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12601 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12602 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12603 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12604 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12605 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12606 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12607 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12608 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12609 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12610 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012611 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12612 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12613 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12614 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12615 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012616 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12617 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12618 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12619 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12620 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12621 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12622 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12623 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12624 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012625 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012626 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012627 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012628 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012629 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012630 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012631 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012632
12633 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12634 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012635 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012636 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12637 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012638 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012639 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12640 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12641 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12642 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012643 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012644 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12645 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12646 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12647 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12648 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12649 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12650 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12651 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12652 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12653 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12654 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12655 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12656 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12657 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12658 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12659 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12660 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12661 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12662 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12663 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12664 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12665 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12666 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12667 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12668 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012669 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12670 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12671 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12672 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12673 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012674 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12675 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12676 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12677 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12678 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12679 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12680 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12681 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12682 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12683 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12684 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12685 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12686 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12687 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12688 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12689 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12690 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12691 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012692 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012693 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12694 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12695 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12696 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12697 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12698 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12699 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12700 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12701 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12702 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12703 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12704 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12705 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12706 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12707 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12708 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012709 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012710 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012711 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012712 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012713 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012714 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012715 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12716 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012717 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012718 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012719 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012720 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012721 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012722 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012723
12724 /* BGP dampening clear commands */
12725 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12726 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12727 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12728 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12729
Paul Jakmaff7924f2006-09-04 01:10:36 +000012730 /* prefix count */
12731 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12732 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12733 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012734#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012735 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12736
paul718e3742002-12-13 20:15:29 +000012737 /* New config IPv6 BGP commands. */
12738 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12739 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12740 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12741 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12742
12743 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12744 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12745 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12746 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12747
G.Balaji73bfe0b2011-09-23 22:36:20 +053012748 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12749 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12750
paul718e3742002-12-13 20:15:29 +000012751 /* Old config IPv6 BGP commands. */
12752 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12753 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12754
12755 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12756 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12757 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12758 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12759
12760 install_element (VIEW_NODE, &show_bgp_cmd);
12761 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012762 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012763 install_element (VIEW_NODE, &show_bgp_route_cmd);
12764 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012765 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012766 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12767 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012768 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012769 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12770 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12771 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12772 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12773 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12774 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12775 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12776 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12777 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12778 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12779 install_element (VIEW_NODE, &show_bgp_community_cmd);
12780 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12781 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12782 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12783 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12784 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12785 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12786 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12787 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12788 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12789 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12790 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12791 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12792 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12793 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12794 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12795 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12796 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12797 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12798 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12799 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12800 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12801 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12802 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12803 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12804 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12805 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12806 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12807 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12808 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012809 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12810 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12811 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12812 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012813 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012814 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012815 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012816 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012817 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012818 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012819 install_element (VIEW_NODE, &show_bgp_view_cmd);
12820 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12821 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12822 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12823 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12824 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12825 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12826 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12827 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12828 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12829 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12830 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12831 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12832 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12833 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12834 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12835 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12836 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012837 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012838 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012839 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012840 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012841 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012842 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012843
12844 /* Restricted:
12845 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12846 */
12847 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12848 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012849 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012850 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12851 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012852 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012853 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12854 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12855 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12856 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12857 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12858 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12859 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12860 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12861 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12862 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12863 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12864 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12865 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12866 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12867 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12868 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12869 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012870 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012871 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012872 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012873 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12874 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12875 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12876 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12877 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12878 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12879 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012880 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012881 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012882 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012883
12884 install_element (ENABLE_NODE, &show_bgp_cmd);
12885 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012886 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012887 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12888 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012889 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012890 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12891 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012892 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012893 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12894 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12895 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12896 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12897 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12898 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12899 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12900 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12901 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12902 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12903 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12904 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12905 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12906 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12907 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12908 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12909 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12910 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12911 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12912 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12913 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12914 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12915 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12916 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12917 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12918 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12919 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12920 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12921 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12922 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12923 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12924 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12925 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12926 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12927 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12928 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12929 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12930 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12931 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12932 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012933 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12934 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12935 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12936 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012937 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012938 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012939 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012940 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012941 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012942 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012943 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12944 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12945 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12946 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12947 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12948 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12949 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12950 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12951 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12952 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12953 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12954 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12955 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12956 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12957 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12958 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12959 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12960 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012961 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012962 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012963 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012964 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012965 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012966 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012967
12968 /* Statistics */
12969 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12970 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12971 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12972 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12973
paul718e3742002-12-13 20:15:29 +000012974 /* old command */
12975 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12976 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12977 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12978 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12979 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12980 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12981 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12982 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12983 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12984 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12985 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12986 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12987 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12988 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12989 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12990 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12991 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12992 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12993 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12994 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12995 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12996 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12997 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12998 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12999 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
13000 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
13001 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
13002 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
13003 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
13004 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
13005 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13006 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13007 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13008 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
13009 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13010 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000013011
paul718e3742002-12-13 20:15:29 +000013012 /* old command */
13013 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
13014 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
13015 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
13016 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
13017 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
13018 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
13019 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
13020 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
13021 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
13022 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
13023 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13024 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13025 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13026 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13027 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13028 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13029 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13030 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13031 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13032 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13033 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13034 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13035 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13036 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13037 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13038 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13039 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13040 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13041 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13042 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13043 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13044 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13045 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13046 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13047 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13048 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13049
13050 /* old command */
13051 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13052 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13053 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13054 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13055
13056 /* old command */
13057 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13058 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13059 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13060 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13061
13062 /* old command */
13063 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13064 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13065 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13066 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13067#endif /* HAVE_IPV6 */
13068
13069 install_element (BGP_NODE, &bgp_distance_cmd);
13070 install_element (BGP_NODE, &no_bgp_distance_cmd);
13071 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13072 install_element (BGP_NODE, &bgp_distance_source_cmd);
13073 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13074 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13075 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13076
13077 install_element (BGP_NODE, &bgp_damp_set_cmd);
13078 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13079 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13080 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13081 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13082 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13083 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13084 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13085 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13086 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013087
13088 /* Deprecated AS-Pathlimit commands */
13089 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13090 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13091 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13092 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13093 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13094 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13095
13096 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13097 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13098 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13099 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13100 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13101 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13102
13103 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13104 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13105 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13106 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13107 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13108 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13109
13110 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13111 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13112 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13113 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13114 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13115 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13116
13117 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13118 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13119 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13120 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13121 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13122 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13123
13124 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13125 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13126 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13127 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13128 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13129 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013130
13131#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013132 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13133 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013134#endif
paul718e3742002-12-13 20:15:29 +000013135}
Chris Caputo228da422009-07-18 05:44:03 +000013136
13137void
13138bgp_route_finish (void)
13139{
13140 bgp_table_unlock (bgp_distance_table);
13141 bgp_distance_table = NULL;
13142}