blob: 7de94615ab3cf707f3a039b493a766f1bf682e84 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* BGP routing information
2 Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
23#include "prefix.h"
24#include "linklist.h"
25#include "memory.h"
26#include "command.h"
27#include "stream.h"
28#include "filter.h"
29#include "str.h"
30#include "log.h"
31#include "routemap.h"
32#include "buffer.h"
33#include "sockunion.h"
34#include "plist.h"
35#include "thread.h"
paul200df112005-06-01 11:17:05 +000036#include "workqueue.h"
paul718e3742002-12-13 20:15:29 +000037
38#include "bgpd/bgpd.h"
39#include "bgpd/bgp_table.h"
40#include "bgpd/bgp_route.h"
41#include "bgpd/bgp_attr.h"
42#include "bgpd/bgp_debug.h"
43#include "bgpd/bgp_aspath.h"
44#include "bgpd/bgp_regex.h"
45#include "bgpd/bgp_community.h"
46#include "bgpd/bgp_ecommunity.h"
47#include "bgpd/bgp_clist.h"
48#include "bgpd/bgp_packet.h"
49#include "bgpd/bgp_filter.h"
50#include "bgpd/bgp_fsm.h"
51#include "bgpd/bgp_mplsvpn.h"
52#include "bgpd/bgp_nexthop.h"
53#include "bgpd/bgp_damp.h"
54#include "bgpd/bgp_advertise.h"
55#include "bgpd/bgp_zebra.h"
hasso0a486e52005-02-01 20:57:17 +000056#include "bgpd/bgp_vty.h"
Josh Bailey96450fa2011-07-20 20:45:12 -070057#include "bgpd/bgp_mpath.h"
paul718e3742002-12-13 20:15:29 +000058
59/* Extern from bgp_dump.c */
Stephen Hemmingerdde72582009-05-08 15:19:07 -070060extern const char *bgp_origin_str[];
61extern const char *bgp_origin_long_str[];
David Lamparter6b0655a2014-06-04 06:53:35 +020062
paul94f2b392005-06-28 12:44:16 +000063static struct bgp_node *
paulfee0f4c2004-09-13 05:12:46 +000064bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
paul718e3742002-12-13 20:15:29 +000065 struct prefix_rd *prd)
66{
67 struct bgp_node *rn;
68 struct bgp_node *prn = NULL;
Paul Jakmada5b30f2006-05-08 14:37:17 +000069
70 assert (table);
71 if (!table)
72 return NULL;
73
paul718e3742002-12-13 20:15:29 +000074 if (safi == SAFI_MPLS_VPN)
75 {
paulfee0f4c2004-09-13 05:12:46 +000076 prn = bgp_node_get (table, (struct prefix *) prd);
paul718e3742002-12-13 20:15:29 +000077
78 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +000079 prn->info = bgp_table_init (afi, safi);
paul718e3742002-12-13 20:15:29 +000080 else
81 bgp_unlock_node (prn);
82 table = prn->info;
83 }
paul718e3742002-12-13 20:15:29 +000084
85 rn = bgp_node_get (table, p);
86
87 if (safi == SAFI_MPLS_VPN)
88 rn->prn = prn;
89
90 return rn;
91}
David Lamparter6b0655a2014-06-04 06:53:35 +020092
Paul Jakmafb982c22007-05-04 20:15:47 +000093/* Allocate bgp_info_extra */
94static struct bgp_info_extra *
95bgp_info_extra_new (void)
96{
97 struct bgp_info_extra *new;
98 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
99 return new;
100}
101
102static void
103bgp_info_extra_free (struct bgp_info_extra **extra)
104{
105 if (extra && *extra)
106 {
107 if ((*extra)->damp_info)
108 bgp_damp_info_free ((*extra)->damp_info, 0);
109
110 (*extra)->damp_info = NULL;
111
112 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
113
114 *extra = NULL;
115 }
116}
117
118/* Get bgp_info extra information for the given bgp_info, lazy allocated
119 * if required.
120 */
121struct bgp_info_extra *
122bgp_info_extra_get (struct bgp_info *ri)
123{
124 if (!ri->extra)
125 ri->extra = bgp_info_extra_new();
126 return ri->extra;
127}
128
paul718e3742002-12-13 20:15:29 +0000129/* Allocate new bgp info structure. */
paul200df112005-06-01 11:17:05 +0000130static struct bgp_info *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -0800131bgp_info_new (void)
paul718e3742002-12-13 20:15:29 +0000132{
Stephen Hemminger393deb92008-08-18 14:13:29 -0700133 return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
paul718e3742002-12-13 20:15:29 +0000134}
135
136/* Free bgp route information. */
paul200df112005-06-01 11:17:05 +0000137static void
paul718e3742002-12-13 20:15:29 +0000138bgp_info_free (struct bgp_info *binfo)
139{
140 if (binfo->attr)
Paul Jakmaf6f434b2010-11-23 21:28:03 +0000141 bgp_attr_unintern (&binfo->attr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000142
143 bgp_info_extra_free (&binfo->extra);
Josh Baileyde8d5df2011-07-20 20:46:01 -0700144 bgp_info_mpath_free (&binfo->mpath);
paul718e3742002-12-13 20:15:29 +0000145
paul200df112005-06-01 11:17:05 +0000146 peer_unlock (binfo->peer); /* bgp_info peer reference */
147
paul718e3742002-12-13 20:15:29 +0000148 XFREE (MTYPE_BGP_ROUTE, binfo);
149}
150
paul200df112005-06-01 11:17:05 +0000151struct bgp_info *
152bgp_info_lock (struct bgp_info *binfo)
153{
154 binfo->lock++;
155 return binfo;
156}
157
158struct bgp_info *
159bgp_info_unlock (struct bgp_info *binfo)
160{
161 assert (binfo && binfo->lock > 0);
162 binfo->lock--;
163
164 if (binfo->lock == 0)
165 {
166#if 0
167 zlog_debug ("%s: unlocked and freeing", __func__);
168 zlog_backtrace (LOG_DEBUG);
169#endif
170 bgp_info_free (binfo);
171 return NULL;
172 }
173
174#if 0
175 if (binfo->lock == 1)
176 {
177 zlog_debug ("%s: unlocked to 1", __func__);
178 zlog_backtrace (LOG_DEBUG);
179 }
180#endif
181
182 return binfo;
183}
184
paul718e3742002-12-13 20:15:29 +0000185void
186bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
187{
188 struct bgp_info *top;
189
190 top = rn->info;
paul200df112005-06-01 11:17:05 +0000191
paul718e3742002-12-13 20:15:29 +0000192 ri->next = rn->info;
193 ri->prev = NULL;
194 if (top)
195 top->prev = ri;
196 rn->info = ri;
paul200df112005-06-01 11:17:05 +0000197
198 bgp_info_lock (ri);
199 bgp_lock_node (rn);
200 peer_lock (ri->peer); /* bgp_info peer reference */
paul718e3742002-12-13 20:15:29 +0000201}
202
paulb40d9392005-08-22 22:34:41 +0000203/* Do the actual removal of info from RIB, for use by bgp_process
204 completion callback *only* */
205static void
206bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
paul718e3742002-12-13 20:15:29 +0000207{
208 if (ri->next)
209 ri->next->prev = ri->prev;
210 if (ri->prev)
211 ri->prev->next = ri->next;
212 else
213 rn->info = ri->next;
paul200df112005-06-01 11:17:05 +0000214
Josh Baileyde8d5df2011-07-20 20:46:01 -0700215 bgp_info_mpath_dequeue (ri);
paul200df112005-06-01 11:17:05 +0000216 bgp_info_unlock (ri);
217 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000218}
219
paulb40d9392005-08-22 22:34:41 +0000220void
221bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
222{
Paul Jakma1a392d42006-09-07 00:24:49 +0000223 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
224 /* set of previous already took care of pcount */
paulb40d9392005-08-22 22:34:41 +0000225 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
226}
227
Andrew J. Schorr8d452102006-11-28 19:50:46 +0000228/* undo the effects of a previous call to bgp_info_delete; typically
229 called when a route is deleted and then quickly re-added before the
230 deletion has been processed */
231static void
232bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
233{
234 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
235 /* unset of previous already took care of pcount */
236 SET_FLAG (ri->flags, BGP_INFO_VALID);
237}
238
Paul Jakma1a392d42006-09-07 00:24:49 +0000239/* Adjust pcount as required */
240static void
241bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
242{
Avneesh Sachdev67174042012-08-17 08:19:49 -0700243 struct bgp_table *table;
244
245 assert (rn && bgp_node_table (rn));
Paul Jakma6f585442006-10-22 19:13:07 +0000246 assert (ri && ri->peer && ri->peer->bgp);
247
Avneesh Sachdev67174042012-08-17 08:19:49 -0700248 table = bgp_node_table (rn);
249
Paul Jakma1a392d42006-09-07 00:24:49 +0000250 /* Ignore 'pcount' for RS-client tables */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700251 if (table->type != BGP_TABLE_MAIN
Paul Jakma1a392d42006-09-07 00:24:49 +0000252 || ri->peer == ri->peer->bgp->peer_self)
253 return;
254
255 if (BGP_INFO_HOLDDOWN (ri)
256 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
257 {
258
259 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
260
261 /* slight hack, but more robust against errors. */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700262 if (ri->peer->pcount[table->afi][table->safi])
263 ri->peer->pcount[table->afi][table->safi]--;
Paul Jakma1a392d42006-09-07 00:24:49 +0000264 else
265 {
266 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
267 __func__, ri->peer->host);
268 zlog_backtrace (LOG_WARNING);
269 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
270 }
271 }
272 else if (!BGP_INFO_HOLDDOWN (ri)
273 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
274 {
275 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
Avneesh Sachdev67174042012-08-17 08:19:49 -0700276 ri->peer->pcount[table->afi][table->safi]++;
Paul Jakma1a392d42006-09-07 00:24:49 +0000277 }
278}
279
280
281/* Set/unset bgp_info flags, adjusting any other state as needed.
282 * This is here primarily to keep prefix-count in check.
283 */
284void
285bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
286{
287 SET_FLAG (ri->flags, flag);
288
289 /* early bath if we know it's not a flag that changes useability state */
290 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
291 return;
292
293 bgp_pcount_adjust (rn, ri);
294}
295
296void
297bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
298{
299 UNSET_FLAG (ri->flags, flag);
300
301 /* early bath if we know it's not a flag that changes useability state */
302 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
303 return;
304
305 bgp_pcount_adjust (rn, ri);
306}
307
paul718e3742002-12-13 20:15:29 +0000308/* Get MED value. If MED value is missing and "bgp bestpath
309 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000310static u_int32_t
paul718e3742002-12-13 20:15:29 +0000311bgp_med_value (struct attr *attr, struct bgp *bgp)
312{
313 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
314 return attr->med;
315 else
316 {
317 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000318 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000319 else
320 return 0;
321 }
322}
323
324/* Compare two bgp route entity. br is preferable then return 1. */
paul94f2b392005-06-28 12:44:16 +0000325static int
Josh Bailey96450fa2011-07-20 20:45:12 -0700326bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
327 int *paths_eq)
paul718e3742002-12-13 20:15:29 +0000328{
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000329 struct attr *newattr, *existattr;
330 struct attr_extra *newattre, *existattre;
331 bgp_peer_sort_t new_sort;
332 bgp_peer_sort_t exist_sort;
paul718e3742002-12-13 20:15:29 +0000333 u_int32_t new_pref;
334 u_int32_t exist_pref;
335 u_int32_t new_med;
336 u_int32_t exist_med;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000337 u_int32_t new_weight;
338 u_int32_t exist_weight;
339 uint32_t newm, existm;
paul718e3742002-12-13 20:15:29 +0000340 struct in_addr new_id;
341 struct in_addr exist_id;
342 int new_cluster;
343 int exist_cluster;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000344 int internal_as_route;
345 int confed_as_route;
paul718e3742002-12-13 20:15:29 +0000346 int ret;
Josh Bailey96450fa2011-07-20 20:45:12 -0700347
348 *paths_eq = 0;
paul718e3742002-12-13 20:15:29 +0000349
350 /* 0. Null check. */
351 if (new == NULL)
352 return 0;
353 if (exist == NULL)
354 return 1;
355
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000356 newattr = new->attr;
357 existattr = exist->attr;
358 newattre = newattr->extra;
359 existattre = existattr->extra;
360
paul718e3742002-12-13 20:15:29 +0000361 /* 1. Weight check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000362 new_weight = exist_weight = 0;
363
364 if (newattre)
365 new_weight = newattre->weight;
366 if (existattre)
367 exist_weight = existattre->weight;
368
Paul Jakmafb982c22007-05-04 20:15:47 +0000369 if (new_weight > exist_weight)
paul718e3742002-12-13 20:15:29 +0000370 return 1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000371 if (new_weight < exist_weight)
paul718e3742002-12-13 20:15:29 +0000372 return 0;
373
374 /* 2. Local preference check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000375 new_pref = exist_pref = bgp->default_local_pref;
paul718e3742002-12-13 20:15:29 +0000376
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000377 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
378 new_pref = newattr->local_pref;
379 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
380 exist_pref = existattr->local_pref;
381
paul718e3742002-12-13 20:15:29 +0000382 if (new_pref > exist_pref)
383 return 1;
384 if (new_pref < exist_pref)
385 return 0;
386
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000387 /* 3. Local route check. We prefer:
388 * - BGP_ROUTE_STATIC
389 * - BGP_ROUTE_AGGREGATE
390 * - BGP_ROUTE_REDISTRIBUTE
391 */
392 if (! (new->sub_type == BGP_ROUTE_NORMAL))
393 return 1;
394 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
395 return 0;
paul718e3742002-12-13 20:15:29 +0000396
397 /* 4. AS path length check. */
398 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
399 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000400 int exist_hops = aspath_count_hops (existattr->aspath);
401 int exist_confeds = aspath_count_confeds (existattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000402
hasso68118452005-04-08 15:40:36 +0000403 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
404 {
paulfe69a502005-09-10 16:55:02 +0000405 int aspath_hops;
406
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000407 aspath_hops = aspath_count_hops (newattr->aspath);
408 aspath_hops += aspath_count_confeds (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000409
410 if ( aspath_hops < (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000411 return 1;
paulfe69a502005-09-10 16:55:02 +0000412 if ( aspath_hops > (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000413 return 0;
414 }
415 else
416 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000417 int newhops = aspath_count_hops (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000418
419 if (newhops < exist_hops)
hasso68118452005-04-08 15:40:36 +0000420 return 1;
paulfe69a502005-09-10 16:55:02 +0000421 if (newhops > exist_hops)
hasso68118452005-04-08 15:40:36 +0000422 return 0;
423 }
paul718e3742002-12-13 20:15:29 +0000424 }
425
426 /* 5. Origin check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000427 if (newattr->origin < existattr->origin)
paul718e3742002-12-13 20:15:29 +0000428 return 1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000429 if (newattr->origin > existattr->origin)
paul718e3742002-12-13 20:15:29 +0000430 return 0;
431
432 /* 6. MED check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000433 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
434 && aspath_count_hops (existattr->aspath) == 0);
435 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
436 && aspath_count_confeds (existattr->aspath) > 0
437 && aspath_count_hops (newattr->aspath) == 0
438 && aspath_count_hops (existattr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000439
440 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
441 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
442 && confed_as_route)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000443 || aspath_cmp_left (newattr->aspath, existattr->aspath)
444 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
paul718e3742002-12-13 20:15:29 +0000445 || internal_as_route)
446 {
447 new_med = bgp_med_value (new->attr, bgp);
448 exist_med = bgp_med_value (exist->attr, bgp);
449
450 if (new_med < exist_med)
451 return 1;
452 if (new_med > exist_med)
453 return 0;
454 }
455
456 /* 7. Peer type check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000457 new_sort = new->peer->sort;
458 exist_sort = exist->peer->sort;
459
460 if (new_sort == BGP_PEER_EBGP
461 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
paul718e3742002-12-13 20:15:29 +0000462 return 1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000463 if (exist_sort == BGP_PEER_EBGP
464 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
paul718e3742002-12-13 20:15:29 +0000465 return 0;
466
467 /* 8. IGP metric check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000468 newm = existm = 0;
469
470 if (new->extra)
471 newm = new->extra->igpmetric;
472 if (exist->extra)
473 existm = exist->extra->igpmetric;
474
Josh Bailey96450fa2011-07-20 20:45:12 -0700475 if (newm < existm)
476 ret = 1;
477 if (newm > existm)
478 ret = 0;
paul718e3742002-12-13 20:15:29 +0000479
480 /* 9. Maximum path check. */
Josh Bailey96450fa2011-07-20 20:45:12 -0700481 if (newm == existm)
482 {
Pradosh Mohapatra2fdd4552013-09-07 07:02:36 +0000483 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
484 {
485
486 /*
487 * For the two paths, all comparison steps till IGP metric
488 * have succeeded - including AS_PATH hop count. Since 'bgp
489 * bestpath as-path multipath-relax' knob is on, we don't need
490 * an exact match of AS_PATH. Thus, mark the paths are equal.
491 * That will trigger both these paths to get into the multipath
492 * array.
493 */
494 *paths_eq = 1;
495 }
496 else if (new->peer->sort == BGP_PEER_IBGP)
Josh Bailey96450fa2011-07-20 20:45:12 -0700497 {
498 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
499 *paths_eq = 1;
500 }
501 else if (new->peer->as == exist->peer->as)
502 *paths_eq = 1;
503 }
504 else
505 {
506 /*
507 * TODO: If unequal cost ibgp multipath is enabled we can
508 * mark the paths as equal here instead of returning
509 */
510 return ret;
511 }
paul718e3742002-12-13 20:15:29 +0000512
513 /* 10. If both paths are external, prefer the path that was received
514 first (the oldest one). This step minimizes route-flap, since a
515 newer path won't displace an older one, even if it was the
516 preferred route based on the additional decision criteria below. */
517 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000518 && new_sort == BGP_PEER_EBGP
519 && exist_sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +0000520 {
521 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
522 return 1;
523 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
524 return 0;
525 }
526
vivekbd4b7f12014-09-30 15:54:45 -0700527 /* 11. Router-ID comparision. */
528 /* If one of the paths is "stale", the corresponding peer router-id will
529 * be 0 and would always win over the other path. If originator id is
530 * used for the comparision, it will decide which path is better.
531 */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000532 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
533 new_id.s_addr = newattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000534 else
535 new_id.s_addr = new->peer->remote_id.s_addr;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000536 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
537 exist_id.s_addr = existattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000538 else
539 exist_id.s_addr = exist->peer->remote_id.s_addr;
540
541 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
542 return 1;
543 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
544 return 0;
545
546 /* 12. Cluster length comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000547 new_cluster = exist_cluster = 0;
548
549 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
550 new_cluster = newattre->cluster->length;
551 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
552 exist_cluster = existattre->cluster->length;
paul718e3742002-12-13 20:15:29 +0000553
554 if (new_cluster < exist_cluster)
555 return 1;
556 if (new_cluster > exist_cluster)
557 return 0;
558
559 /* 13. Neighbor address comparision. */
vivekbd4b7f12014-09-30 15:54:45 -0700560 /* Do this only if neither path is "stale" as stale paths do not have
561 * valid peer information (as the connection may or may not be up).
562 */
563 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
564 return 1;
565 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
566 return 0;
Timo Teräs2820a012015-06-24 15:27:21 +0300567 /* locally configured routes to advertise do not have su_remote */
568 if (new->peer->su_remote == NULL)
569 return 0;
570 if (exist->peer->su_remote == NULL)
571 return 1;
572
paul718e3742002-12-13 20:15:29 +0000573 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
574
575 if (ret == 1)
576 return 0;
577 if (ret == -1)
578 return 1;
579
580 return 1;
581}
582
paul94f2b392005-06-28 12:44:16 +0000583static enum filter_type
paul718e3742002-12-13 20:15:29 +0000584bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
585 afi_t afi, safi_t safi)
586{
587 struct bgp_filter *filter;
588
589 filter = &peer->filter[afi][safi];
590
Paul Jakma650f76c2009-06-25 18:06:31 +0100591#define FILTER_EXIST_WARN(F,f,filter) \
592 if (BGP_DEBUG (update, UPDATE_IN) \
593 && !(F ## _IN (filter))) \
594 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
595 peer->host, #f, F ## _IN_NAME(filter));
596
597 if (DISTRIBUTE_IN_NAME (filter)) {
598 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
599
paul718e3742002-12-13 20:15:29 +0000600 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
601 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100602 }
paul718e3742002-12-13 20:15:29 +0000603
Paul Jakma650f76c2009-06-25 18:06:31 +0100604 if (PREFIX_LIST_IN_NAME (filter)) {
605 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
606
paul718e3742002-12-13 20:15:29 +0000607 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
608 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100609 }
paul718e3742002-12-13 20:15:29 +0000610
Paul Jakma650f76c2009-06-25 18:06:31 +0100611 if (FILTER_LIST_IN_NAME (filter)) {
612 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
613
paul718e3742002-12-13 20:15:29 +0000614 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
615 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100616 }
617
paul718e3742002-12-13 20:15:29 +0000618 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100619#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000620}
621
paul94f2b392005-06-28 12:44:16 +0000622static enum filter_type
paul718e3742002-12-13 20:15:29 +0000623bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
624 afi_t afi, safi_t safi)
625{
626 struct bgp_filter *filter;
627
628 filter = &peer->filter[afi][safi];
629
Paul Jakma650f76c2009-06-25 18:06:31 +0100630#define FILTER_EXIST_WARN(F,f,filter) \
631 if (BGP_DEBUG (update, UPDATE_OUT) \
632 && !(F ## _OUT (filter))) \
633 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
634 peer->host, #f, F ## _OUT_NAME(filter));
635
636 if (DISTRIBUTE_OUT_NAME (filter)) {
637 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
638
paul718e3742002-12-13 20:15:29 +0000639 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
640 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100641 }
paul718e3742002-12-13 20:15:29 +0000642
Paul Jakma650f76c2009-06-25 18:06:31 +0100643 if (PREFIX_LIST_OUT_NAME (filter)) {
644 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
645
paul718e3742002-12-13 20:15:29 +0000646 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
647 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100648 }
paul718e3742002-12-13 20:15:29 +0000649
Paul Jakma650f76c2009-06-25 18:06:31 +0100650 if (FILTER_LIST_OUT_NAME (filter)) {
651 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
652
paul718e3742002-12-13 20:15:29 +0000653 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
654 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100655 }
paul718e3742002-12-13 20:15:29 +0000656
657 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100658#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000659}
660
661/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000662static int
paul718e3742002-12-13 20:15:29 +0000663bgp_community_filter (struct peer *peer, struct attr *attr)
664{
665 if (attr->community)
666 {
667 /* NO_ADVERTISE check. */
668 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
669 return 1;
670
671 /* NO_EXPORT check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000672 if (peer->sort == BGP_PEER_EBGP &&
paul718e3742002-12-13 20:15:29 +0000673 community_include (attr->community, COMMUNITY_NO_EXPORT))
674 return 1;
675
676 /* NO_EXPORT_SUBCONFED check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000677 if (peer->sort == BGP_PEER_EBGP
678 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000679 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
680 return 1;
681 }
682 return 0;
683}
684
685/* Route reflection loop check. */
686static int
687bgp_cluster_filter (struct peer *peer, struct attr *attr)
688{
689 struct in_addr cluster_id;
690
Paul Jakmafb982c22007-05-04 20:15:47 +0000691 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000692 {
693 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
694 cluster_id = peer->bgp->cluster_id;
695 else
696 cluster_id = peer->bgp->router_id;
697
Paul Jakmafb982c22007-05-04 20:15:47 +0000698 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000699 return 1;
700 }
701 return 0;
702}
David Lamparter6b0655a2014-06-04 06:53:35 +0200703
paul94f2b392005-06-28 12:44:16 +0000704static int
paul718e3742002-12-13 20:15:29 +0000705bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
706 afi_t afi, safi_t safi)
707{
708 struct bgp_filter *filter;
709 struct bgp_info info;
710 route_map_result_t ret;
711
712 filter = &peer->filter[afi][safi];
713
714 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000715 if (peer->weight)
716 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000717
718 /* Route map apply. */
719 if (ROUTE_MAP_IN_NAME (filter))
720 {
721 /* Duplicate current value to new strucutre for modification. */
722 info.peer = peer;
723 info.attr = attr;
724
paulac41b2a2003-08-12 05:32:27 +0000725 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
726
paul718e3742002-12-13 20:15:29 +0000727 /* Apply BGP route map to the attribute. */
728 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000729
730 peer->rmap_type = 0;
731
paul718e3742002-12-13 20:15:29 +0000732 if (ret == RMAP_DENYMATCH)
David Lamparterc460e572014-06-04 00:54:58 +0200733 /* caller has multiple error paths with bgp_attr_flush() */
734 return RMAP_DENY;
paul718e3742002-12-13 20:15:29 +0000735 }
736 return RMAP_PERMIT;
737}
David Lamparter6b0655a2014-06-04 06:53:35 +0200738
paul94f2b392005-06-28 12:44:16 +0000739static int
paulfee0f4c2004-09-13 05:12:46 +0000740bgp_export_modifier (struct peer *rsclient, struct peer *peer,
741 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
742{
743 struct bgp_filter *filter;
744 struct bgp_info info;
745 route_map_result_t ret;
746
747 filter = &peer->filter[afi][safi];
748
749 /* Route map apply. */
750 if (ROUTE_MAP_EXPORT_NAME (filter))
751 {
752 /* Duplicate current value to new strucutre for modification. */
753 info.peer = rsclient;
754 info.attr = attr;
755
756 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
757
758 /* Apply BGP route map to the attribute. */
759 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
760
761 rsclient->rmap_type = 0;
762
763 if (ret == RMAP_DENYMATCH)
764 {
765 /* Free newly generated AS path and community by route-map. */
766 bgp_attr_flush (attr);
767 return RMAP_DENY;
768 }
769 }
770 return RMAP_PERMIT;
771}
772
paul94f2b392005-06-28 12:44:16 +0000773static int
paulfee0f4c2004-09-13 05:12:46 +0000774bgp_import_modifier (struct peer *rsclient, struct peer *peer,
775 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
776{
777 struct bgp_filter *filter;
778 struct bgp_info info;
779 route_map_result_t ret;
780
781 filter = &rsclient->filter[afi][safi];
782
783 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000784 if (peer->weight)
785 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000786
787 /* Route map apply. */
788 if (ROUTE_MAP_IMPORT_NAME (filter))
789 {
790 /* Duplicate current value to new strucutre for modification. */
791 info.peer = peer;
792 info.attr = attr;
793
794 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
795
796 /* Apply BGP route map to the attribute. */
797 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
798
799 peer->rmap_type = 0;
800
801 if (ret == RMAP_DENYMATCH)
802 {
803 /* Free newly generated AS path and community by route-map. */
804 bgp_attr_flush (attr);
805 return RMAP_DENY;
806 }
807 }
808 return RMAP_PERMIT;
809}
David Lamparter6b0655a2014-06-04 06:53:35 +0200810
paul94f2b392005-06-28 12:44:16 +0000811static int
paul718e3742002-12-13 20:15:29 +0000812bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
813 struct attr *attr, afi_t afi, safi_t safi)
814{
815 int ret;
816 char buf[SU_ADDRSTRLEN];
817 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000818 struct peer *from;
819 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000820 int transparent;
821 int reflect;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700822 struct attr *riattr;
paul718e3742002-12-13 20:15:29 +0000823
824 from = ri->peer;
825 filter = &peer->filter[afi][safi];
826 bgp = peer->bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700827 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paul718e3742002-12-13 20:15:29 +0000828
Paul Jakma750e8142008-07-22 21:11:48 +0000829 if (DISABLE_BGP_ANNOUNCE)
830 return 0;
paul718e3742002-12-13 20:15:29 +0000831
paulfee0f4c2004-09-13 05:12:46 +0000832 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
833 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
834 return 0;
835
paul718e3742002-12-13 20:15:29 +0000836 /* Do not send back route to sender. */
837 if (from == peer)
838 return 0;
839
840 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000841 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000842 if (! UNSUPPRESS_MAP_NAME (filter))
843 return 0;
844
845 /* Default route check. */
846 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
847 {
848 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
849 return 0;
850#ifdef HAVE_IPV6
851 else if (p->family == AF_INET6 && p->prefixlen == 0)
852 return 0;
853#endif /* HAVE_IPV6 */
854 }
855
paul286e1e72003-08-08 00:24:31 +0000856 /* Transparency check. */
857 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
858 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
859 transparent = 1;
860 else
861 transparent = 0;
862
paul718e3742002-12-13 20:15:29 +0000863 /* If community is not disabled check the no-export and local. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700864 if (! transparent && bgp_community_filter (peer, riattr))
paul718e3742002-12-13 20:15:29 +0000865 return 0;
866
867 /* If the attribute has originator-id and it is same as remote
868 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700869 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paul718e3742002-12-13 20:15:29 +0000870 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700871 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000872 {
873 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000874 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000875 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
876 peer->host,
877 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
878 p->prefixlen);
879 return 0;
880 }
881 }
882
883 /* ORF prefix-list filter check */
884 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
885 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
886 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
887 if (peer->orf_plist[afi][safi])
888 {
889 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
890 return 0;
891 }
892
893 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700894 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
paul718e3742002-12-13 20:15:29 +0000895 {
896 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000897 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000898 "%s [Update:SEND] %s/%d is filtered",
899 peer->host,
900 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
901 p->prefixlen);
902 return 0;
903 }
904
905#ifdef BGP_SEND_ASPATH_CHECK
906 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700907 if (aspath_loop_check (riattr->aspath, peer->as))
paul718e3742002-12-13 20:15:29 +0000908 {
909 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000910 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400911 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000912 peer->host, peer->as);
913 return 0;
914 }
915#endif /* BGP_SEND_ASPATH_CHECK */
916
917 /* If we're a CONFED we need to loop check the CONFED ID too */
918 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
919 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700920 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
paul718e3742002-12-13 20:15:29 +0000921 {
922 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000923 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400924 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000925 peer->host,
926 bgp->confed_id);
927 return 0;
928 }
929 }
930
931 /* Route-Reflect check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000932 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +0000933 reflect = 1;
934 else
935 reflect = 0;
936
937 /* IBGP reflection check. */
938 if (reflect)
939 {
940 /* A route from a Client peer. */
941 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
942 {
943 /* Reflect to all the Non-Client peers and also to the
944 Client peers other than the originator. Originator check
945 is already done. So there is noting to do. */
946 /* no bgp client-to-client reflection check. */
947 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
948 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
949 return 0;
950 }
951 else
952 {
953 /* A route from a Non-client peer. Reflect to all other
954 clients. */
955 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
956 return 0;
957 }
958 }
Paul Jakma41367172007-08-06 15:24:51 +0000959
paul718e3742002-12-13 20:15:29 +0000960 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700961 bgp_attr_dup (attr, riattr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000962
paul718e3742002-12-13 20:15:29 +0000963 /* If local-preference is not set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000964 if ((peer->sort == BGP_PEER_IBGP
965 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000966 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
967 {
968 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
969 attr->local_pref = bgp->default_local_pref;
970 }
971
Pradosh Mohapatra689bb662013-09-07 07:13:37 +0000972 /* If originator-id is not set and the route is to be reflected,
973 set the originator id */
974 if (peer && from && peer->sort == BGP_PEER_IBGP &&
975 from->sort == BGP_PEER_IBGP &&
976 (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
977 {
978 attr->extra = bgp_attr_extra_get(attr);
979 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
980 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
981 }
982
paul718e3742002-12-13 20:15:29 +0000983 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000984 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000985 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
986 {
987 if (ri->peer != bgp->peer_self && ! transparent
988 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
989 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
990 }
991
992 /* next-hop-set */
Timo Teräs9e7a53c2014-04-24 10:22:37 +0300993 if (transparent
994 || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
paul718e3742002-12-13 20:15:29 +0000995 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
996 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000997#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000998 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000999 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +00001000#endif /* HAVE_IPV6 */
1001 )))
paul718e3742002-12-13 20:15:29 +00001002 {
1003 /* NEXT-HOP Unchanged. */
1004 }
1005 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
1006 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
1007#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +00001008 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001009 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +00001010#endif /* HAVE_IPV6 */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001011 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001012 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
1013 {
1014 /* Set IPv4 nexthop. */
1015 if (p->family == AF_INET)
1016 {
1017 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001018 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1019 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +00001020 else
1021 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1022 }
1023#ifdef HAVE_IPV6
1024 /* Set IPv6 nexthop. */
1025 if (p->family == AF_INET6)
1026 {
1027 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001028 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001029 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001030 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001031 }
1032#endif /* HAVE_IPV6 */
1033 }
1034
1035#ifdef HAVE_IPV6
1036 if (p->family == AF_INET6)
1037 {
paulfee0f4c2004-09-13 05:12:46 +00001038 /* Left nexthop_local unchanged if so configured. */
1039 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1040 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1041 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001042 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1043 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001044 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001045 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001046 }
1047
1048 /* Default nexthop_local treatment for non-RS-Clients */
1049 else
1050 {
paul718e3742002-12-13 20:15:29 +00001051 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001052 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001053
1054 /* Set link-local address for shared network peer. */
1055 if (peer->shared_network
1056 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1057 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001058 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001059 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001060 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001061 }
1062
1063 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1064 address.*/
1065 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001066 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001067
1068 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1069 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001070 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001071 }
paulfee0f4c2004-09-13 05:12:46 +00001072
1073 }
paul718e3742002-12-13 20:15:29 +00001074#endif /* HAVE_IPV6 */
1075
1076 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001077 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001078 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1079 && aspath_private_as_check (attr->aspath))
1080 attr->aspath = aspath_empty_get ();
1081
1082 /* Route map & unsuppress-map apply. */
1083 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001084 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001085 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001086 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001087 struct attr dummy_attr;
1088 struct attr_extra dummy_extra;
1089
1090 dummy_attr.extra = &dummy_extra;
1091
paul718e3742002-12-13 20:15:29 +00001092 info.peer = peer;
1093 info.attr = attr;
1094
1095 /* The route reflector is not allowed to modify the attributes
1096 of the reflected IBGP routes. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001097 if (from->sort == BGP_PEER_IBGP
1098 && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +00001099 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001100 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001101 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001102 }
paulac41b2a2003-08-12 05:32:27 +00001103
1104 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1105
Paul Jakmafb982c22007-05-04 20:15:47 +00001106 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001107 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1108 else
1109 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1110
paulac41b2a2003-08-12 05:32:27 +00001111 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001112
paul718e3742002-12-13 20:15:29 +00001113 if (ret == RMAP_DENYMATCH)
1114 {
1115 bgp_attr_flush (attr);
1116 return 0;
1117 }
1118 }
1119 return 1;
1120}
1121
paul94f2b392005-06-28 12:44:16 +00001122static int
paulfee0f4c2004-09-13 05:12:46 +00001123bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1124 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001125{
paulfee0f4c2004-09-13 05:12:46 +00001126 int ret;
1127 char buf[SU_ADDRSTRLEN];
1128 struct bgp_filter *filter;
1129 struct bgp_info info;
1130 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001131 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001132
1133 from = ri->peer;
1134 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001135 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001136
Paul Jakma750e8142008-07-22 21:11:48 +00001137 if (DISABLE_BGP_ANNOUNCE)
1138 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001139
1140 /* Do not send back route to sender. */
1141 if (from == rsclient)
1142 return 0;
1143
1144 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001145 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001146 if (! UNSUPPRESS_MAP_NAME (filter))
1147 return 0;
1148
1149 /* Default route check. */
1150 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1151 PEER_STATUS_DEFAULT_ORIGINATE))
1152 {
1153 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1154 return 0;
1155#ifdef HAVE_IPV6
1156 else if (p->family == AF_INET6 && p->prefixlen == 0)
1157 return 0;
1158#endif /* HAVE_IPV6 */
1159 }
1160
1161 /* If the attribute has originator-id and it is same as remote
1162 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001163 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001164 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001165 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001166 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001167 {
1168 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001169 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001170 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1171 rsclient->host,
1172 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1173 p->prefixlen);
1174 return 0;
1175 }
1176 }
1177
1178 /* ORF prefix-list filter check */
1179 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1180 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1181 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1182 if (rsclient->orf_plist[afi][safi])
1183 {
1184 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1185 return 0;
1186 }
1187
1188 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001189 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001190 {
1191 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001192 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001193 "%s [Update:SEND] %s/%d is filtered",
1194 rsclient->host,
1195 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1196 p->prefixlen);
1197 return 0;
1198 }
1199
1200#ifdef BGP_SEND_ASPATH_CHECK
1201 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001202 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001203 {
1204 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001205 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001206 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001207 rsclient->host, rsclient->as);
1208 return 0;
1209 }
1210#endif /* BGP_SEND_ASPATH_CHECK */
1211
1212 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001213 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001214
1215 /* next-hop-set */
1216 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1217#ifdef HAVE_IPV6
1218 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001219 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001220#endif /* HAVE_IPV6 */
1221 )
1222 {
1223 /* Set IPv4 nexthop. */
1224 if (p->family == AF_INET)
1225 {
1226 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001227 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001228 IPV4_MAX_BYTELEN);
1229 else
1230 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1231 }
1232#ifdef HAVE_IPV6
1233 /* Set IPv6 nexthop. */
1234 if (p->family == AF_INET6)
1235 {
1236 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001237 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001238 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001239 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001240 }
1241#endif /* HAVE_IPV6 */
1242 }
1243
1244#ifdef HAVE_IPV6
1245 if (p->family == AF_INET6)
1246 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001247 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001248
paulfee0f4c2004-09-13 05:12:46 +00001249 /* Left nexthop_local unchanged if so configured. */
1250 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1251 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1252 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001253 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1254 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001255 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001256 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001257 }
1258
1259 /* Default nexthop_local treatment for RS-Clients */
1260 else
1261 {
1262 /* Announcer and RS-Client are both in the same network */
1263 if (rsclient->shared_network && from->shared_network &&
1264 (rsclient->ifindex == from->ifindex))
1265 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001266 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1267 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001268 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001269 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001270 }
1271
1272 /* Set link-local address for shared network peer. */
1273 else if (rsclient->shared_network
1274 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1275 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001276 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001277 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001278 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001279 }
1280
1281 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001282 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001283 }
1284
1285 }
1286#endif /* HAVE_IPV6 */
1287
1288
1289 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001290 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001291 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1292 && aspath_private_as_check (attr->aspath))
1293 attr->aspath = aspath_empty_get ();
1294
1295 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001296 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001297 {
1298 info.peer = rsclient;
1299 info.attr = attr;
1300
1301 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1302
Paul Jakmafb982c22007-05-04 20:15:47 +00001303 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001304 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1305 else
1306 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1307
1308 rsclient->rmap_type = 0;
1309
1310 if (ret == RMAP_DENYMATCH)
1311 {
1312 bgp_attr_flush (attr);
1313 return 0;
1314 }
1315 }
1316
1317 return 1;
1318}
1319
1320struct bgp_info_pair
1321{
1322 struct bgp_info *old;
1323 struct bgp_info *new;
1324};
1325
paul94f2b392005-06-28 12:44:16 +00001326static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001327bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1328 struct bgp_maxpaths_cfg *mpath_cfg,
1329 struct bgp_info_pair *result)
paulfee0f4c2004-09-13 05:12:46 +00001330{
paul718e3742002-12-13 20:15:29 +00001331 struct bgp_info *new_select;
1332 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001333 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001334 struct bgp_info *ri1;
1335 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001336 struct bgp_info *nextri = NULL;
Josh Bailey96450fa2011-07-20 20:45:12 -07001337 int paths_eq, do_mpath;
1338 struct list mp_list;
1339
1340 bgp_mp_list_init (&mp_list);
1341 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1342 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1343
paul718e3742002-12-13 20:15:29 +00001344 /* bgp deterministic-med */
1345 new_select = NULL;
1346 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1347 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1348 {
1349 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1350 continue;
1351 if (BGP_INFO_HOLDDOWN (ri1))
1352 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001353 if (ri1->peer && ri1->peer != bgp->peer_self)
1354 if (ri1->peer->status != Established)
1355 continue;
paul718e3742002-12-13 20:15:29 +00001356
1357 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001358 if (do_mpath)
1359 bgp_mp_list_add (&mp_list, ri1);
1360 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001361 if (ri1->next)
1362 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1363 {
1364 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1365 continue;
1366 if (BGP_INFO_HOLDDOWN (ri2))
1367 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001368 if (ri2->peer &&
1369 ri2->peer != bgp->peer_self &&
1370 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1371 if (ri2->peer->status != Established)
1372 continue;
paul718e3742002-12-13 20:15:29 +00001373
1374 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1375 || aspath_cmp_left_confed (ri1->attr->aspath,
1376 ri2->attr->aspath))
1377 {
Josh Bailey6918e742011-07-20 20:48:20 -07001378 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1379 old_select = ri2;
Josh Bailey96450fa2011-07-20 20:45:12 -07001380 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
paul718e3742002-12-13 20:15:29 +00001381 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001382 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001383 new_select = ri2;
Josh Bailey6918e742011-07-20 20:48:20 -07001384 if (do_mpath && !paths_eq)
1385 {
1386 bgp_mp_list_clear (&mp_list);
1387 bgp_mp_list_add (&mp_list, ri2);
1388 }
paul718e3742002-12-13 20:15:29 +00001389 }
1390
Josh Bailey6918e742011-07-20 20:48:20 -07001391 if (do_mpath && paths_eq)
1392 bgp_mp_list_add (&mp_list, ri2);
1393
Paul Jakma1a392d42006-09-07 00:24:49 +00001394 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001395 }
1396 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001397 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1398 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001399
1400 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1401 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001402 }
1403
1404 /* Check old selected route and new selected route. */
1405 old_select = NULL;
1406 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001407 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001408 {
1409 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1410 old_select = ri;
1411
1412 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001413 {
1414 /* reap REMOVED routes, if needs be
1415 * selected route must stay for a while longer though
1416 */
1417 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1418 && (ri != old_select))
1419 bgp_info_reap (rn, ri);
1420
1421 continue;
1422 }
paul718e3742002-12-13 20:15:29 +00001423
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001424 if (ri->peer &&
1425 ri->peer != bgp->peer_self &&
1426 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1427 if (ri->peer->status != Established)
1428 continue;
1429
paul718e3742002-12-13 20:15:29 +00001430 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1431 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1432 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001433 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001434 continue;
1435 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001436 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1437 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001438
Josh Bailey96450fa2011-07-20 20:45:12 -07001439 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1440 {
Josh Bailey6918e742011-07-20 20:48:20 -07001441 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1442 bgp_mp_dmed_deselect (new_select);
1443
Josh Bailey96450fa2011-07-20 20:45:12 -07001444 new_select = ri;
1445
1446 if (do_mpath && !paths_eq)
1447 {
1448 bgp_mp_list_clear (&mp_list);
1449 bgp_mp_list_add (&mp_list, ri);
1450 }
1451 }
Josh Bailey6918e742011-07-20 20:48:20 -07001452 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1453 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001454
1455 if (do_mpath && paths_eq)
1456 bgp_mp_list_add (&mp_list, ri);
paul718e3742002-12-13 20:15:29 +00001457 }
paulb40d9392005-08-22 22:34:41 +00001458
paulfee0f4c2004-09-13 05:12:46 +00001459
Josh Bailey6918e742011-07-20 20:48:20 -07001460 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1461 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
Josh Bailey96450fa2011-07-20 20:45:12 -07001462
Josh Bailey0b597ef2011-07-20 20:49:11 -07001463 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001464 bgp_mp_list_clear (&mp_list);
1465
1466 result->old = old_select;
1467 result->new = new_select;
1468
1469 return;
paulfee0f4c2004-09-13 05:12:46 +00001470}
1471
paul94f2b392005-06-28 12:44:16 +00001472static int
paulfee0f4c2004-09-13 05:12:46 +00001473bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001474 struct bgp_node *rn, afi_t afi, safi_t safi)
1475{
paulfee0f4c2004-09-13 05:12:46 +00001476 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001477 struct attr attr;
1478 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001479
1480 p = &rn->p;
1481
Paul Jakma9eda90c2007-08-30 13:36:17 +00001482 /* Announce route to Established peer. */
1483 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001484 return 0;
1485
Paul Jakma9eda90c2007-08-30 13:36:17 +00001486 /* Address family configuration check. */
1487 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001488 return 0;
1489
Paul Jakma9eda90c2007-08-30 13:36:17 +00001490 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001491 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1492 PEER_STATUS_ORF_WAIT_REFRESH))
1493 return 0;
1494
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001495 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1496 attr.extra = &extra;
1497
Avneesh Sachdev67174042012-08-17 08:19:49 -07001498 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001499 {
1500 case BGP_TABLE_MAIN:
1501 /* Announcement to peer->conf. If the route is filtered,
1502 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001503 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1504 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001505 else
1506 bgp_adj_out_unset (rn, peer, p, afi, safi);
1507 break;
1508 case BGP_TABLE_RSCLIENT:
1509 /* Announcement to peer->conf. If the route is filtered,
1510 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001511 if (selected &&
1512 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1513 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1514 else
1515 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001516 break;
1517 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001518
paulfee0f4c2004-09-13 05:12:46 +00001519 return 0;
paul200df112005-06-01 11:17:05 +00001520}
paulfee0f4c2004-09-13 05:12:46 +00001521
paul200df112005-06-01 11:17:05 +00001522struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001523{
paul200df112005-06-01 11:17:05 +00001524 struct bgp *bgp;
1525 struct bgp_node *rn;
1526 afi_t afi;
1527 safi_t safi;
1528};
1529
1530static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001531bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001532{
paul0fb58d52005-11-14 14:31:49 +00001533 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001534 struct bgp *bgp = pq->bgp;
1535 struct bgp_node *rn = pq->rn;
1536 afi_t afi = pq->afi;
1537 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001538 struct bgp_info *new_select;
1539 struct bgp_info *old_select;
1540 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001541 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001542 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001543
paulfee0f4c2004-09-13 05:12:46 +00001544 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001545 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001546 new_select = old_and_new.new;
1547 old_select = old_and_new.old;
1548
paul200df112005-06-01 11:17:05 +00001549 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1550 {
Chris Caputo228da422009-07-18 05:44:03 +00001551 if (rsclient->group)
1552 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1553 {
1554 /* Nothing to do. */
1555 if (old_select && old_select == new_select)
1556 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1557 continue;
paulfee0f4c2004-09-13 05:12:46 +00001558
Chris Caputo228da422009-07-18 05:44:03 +00001559 if (old_select)
1560 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1561 if (new_select)
1562 {
1563 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1564 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001565 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1566 }
paulfee0f4c2004-09-13 05:12:46 +00001567
Chris Caputo228da422009-07-18 05:44:03 +00001568 bgp_process_announce_selected (rsclient, new_select, rn,
1569 afi, safi);
1570 }
paul200df112005-06-01 11:17:05 +00001571 }
1572 else
1573 {
hassob7395792005-08-26 12:58:38 +00001574 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001575 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001576 if (new_select)
1577 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001578 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1579 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001580 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001581 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001582 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001583 }
paulfee0f4c2004-09-13 05:12:46 +00001584
paulb40d9392005-08-22 22:34:41 +00001585 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1586 bgp_info_reap (rn, old_select);
1587
paul200df112005-06-01 11:17:05 +00001588 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1589 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001590}
1591
paul200df112005-06-01 11:17:05 +00001592static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001593bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001594{
paul0fb58d52005-11-14 14:31:49 +00001595 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001596 struct bgp *bgp = pq->bgp;
1597 struct bgp_node *rn = pq->rn;
1598 afi_t afi = pq->afi;
1599 safi_t safi = pq->safi;
1600 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001601 struct bgp_info *new_select;
1602 struct bgp_info *old_select;
1603 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001604 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001605 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001606
paulfee0f4c2004-09-13 05:12:46 +00001607 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001608 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001609 old_select = old_and_new.old;
1610 new_select = old_and_new.new;
1611
1612 /* Nothing to do. */
1613 if (old_select && old_select == new_select)
1614 {
1615 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001616 {
Josh Bailey8196f132011-07-20 20:47:07 -07001617 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1618 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001619 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001620
Josh Bailey8196f132011-07-20 20:47:07 -07001621 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001622 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1623 return WQ_SUCCESS;
1624 }
paulfee0f4c2004-09-13 05:12:46 +00001625 }
paul718e3742002-12-13 20:15:29 +00001626
hasso338b3422005-02-23 14:27:24 +00001627 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001628 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001629 if (new_select)
1630 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001631 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1632 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001633 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001634 }
1635
1636
paul718e3742002-12-13 20:15:29 +00001637 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001638 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001639 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001640 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001641 }
1642
1643 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001644 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1645 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001646 {
1647 if (new_select
1648 && new_select->type == ZEBRA_ROUTE_BGP
1649 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001650 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001651 else
1652 {
1653 /* Withdraw the route from the kernel. */
1654 if (old_select
1655 && old_select->type == ZEBRA_ROUTE_BGP
1656 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001657 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001658 }
1659 }
paulb40d9392005-08-22 22:34:41 +00001660
1661 /* Reap old select bgp_info, it it has been removed */
1662 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1663 bgp_info_reap (rn, old_select);
1664
paul200df112005-06-01 11:17:05 +00001665 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1666 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001667}
1668
paul200df112005-06-01 11:17:05 +00001669static void
paul0fb58d52005-11-14 14:31:49 +00001670bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001671{
paul0fb58d52005-11-14 14:31:49 +00001672 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001673 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001674
Chris Caputo228da422009-07-18 05:44:03 +00001675 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001676 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001677 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001678 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1679}
1680
1681static void
1682bgp_process_queue_init (void)
1683{
1684 bm->process_main_queue
1685 = work_queue_new (bm->master, "process_main_queue");
1686 bm->process_rsclient_queue
1687 = work_queue_new (bm->master, "process_rsclient_queue");
1688
1689 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1690 {
1691 zlog_err ("%s: Failed to allocate work queue", __func__);
1692 exit (1);
1693 }
1694
1695 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001696 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001697 bm->process_main_queue->spec.max_retries = 0;
1698 bm->process_main_queue->spec.hold = 50;
1699
Paul Jakma838bbde2010-01-08 14:05:32 +00001700 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
David Lamparterd43f8b32015-03-03 08:54:54 +01001701 bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del;
1702 bm->process_rsclient_queue->spec.max_retries = 0;
1703 bm->process_rsclient_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001704}
1705
1706void
paulfee0f4c2004-09-13 05:12:46 +00001707bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1708{
paul200df112005-06-01 11:17:05 +00001709 struct bgp_process_queue *pqnode;
1710
1711 /* already scheduled for processing? */
1712 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1713 return;
1714
1715 if ( (bm->process_main_queue == NULL) ||
1716 (bm->process_rsclient_queue == NULL) )
1717 bgp_process_queue_init ();
1718
1719 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1720 sizeof (struct bgp_process_queue));
1721 if (!pqnode)
1722 return;
Chris Caputo228da422009-07-18 05:44:03 +00001723
1724 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001725 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001726 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001727 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001728 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001729 pqnode->afi = afi;
1730 pqnode->safi = safi;
1731
Avneesh Sachdev67174042012-08-17 08:19:49 -07001732 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001733 {
paul200df112005-06-01 11:17:05 +00001734 case BGP_TABLE_MAIN:
1735 work_queue_add (bm->process_main_queue, pqnode);
1736 break;
1737 case BGP_TABLE_RSCLIENT:
1738 work_queue_add (bm->process_rsclient_queue, pqnode);
1739 break;
paulfee0f4c2004-09-13 05:12:46 +00001740 }
paul200df112005-06-01 11:17:05 +00001741
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001742 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001743 return;
paulfee0f4c2004-09-13 05:12:46 +00001744}
hasso0a486e52005-02-01 20:57:17 +00001745
paul94f2b392005-06-28 12:44:16 +00001746static int
hasso0a486e52005-02-01 20:57:17 +00001747bgp_maximum_prefix_restart_timer (struct thread *thread)
1748{
1749 struct peer *peer;
1750
1751 peer = THREAD_ARG (thread);
1752 peer->t_pmax_restart = NULL;
1753
1754 if (BGP_DEBUG (events, EVENTS))
1755 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1756 peer->host);
1757
1758 peer_clear (peer);
1759
1760 return 0;
1761}
1762
paulfee0f4c2004-09-13 05:12:46 +00001763int
paul5228ad22004-06-04 17:58:18 +00001764bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1765 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001766{
hassoe0701b72004-05-20 09:19:34 +00001767 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1768 return 0;
1769
1770 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001771 {
hassoe0701b72004-05-20 09:19:34 +00001772 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1773 && ! always)
1774 return 0;
paul718e3742002-12-13 20:15:29 +00001775
hassoe0701b72004-05-20 09:19:34 +00001776 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001777 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1778 "limit %ld", afi_safi_print (afi, safi), peer->host,
1779 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001780 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001781
hassoe0701b72004-05-20 09:19:34 +00001782 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1783 return 0;
paul718e3742002-12-13 20:15:29 +00001784
hassoe0701b72004-05-20 09:19:34 +00001785 {
paul5228ad22004-06-04 17:58:18 +00001786 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001787
1788 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001789 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001790
1791 ndata[0] = (afi >> 8);
1792 ndata[1] = afi;
1793 ndata[2] = safi;
1794 ndata[3] = (peer->pmax[afi][safi] >> 24);
1795 ndata[4] = (peer->pmax[afi][safi] >> 16);
1796 ndata[5] = (peer->pmax[afi][safi] >> 8);
1797 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001798
1799 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1800 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1801 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1802 }
hasso0a486e52005-02-01 20:57:17 +00001803
1804 /* restart timer start */
1805 if (peer->pmax_restart[afi][safi])
1806 {
1807 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1808
1809 if (BGP_DEBUG (events, EVENTS))
1810 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1811 peer->host, peer->v_pmax_restart);
1812
1813 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1814 peer->v_pmax_restart);
1815 }
1816
hassoe0701b72004-05-20 09:19:34 +00001817 return 1;
paul718e3742002-12-13 20:15:29 +00001818 }
hassoe0701b72004-05-20 09:19:34 +00001819 else
1820 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1821
1822 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1823 {
1824 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1825 && ! always)
1826 return 0;
1827
1828 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001829 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1830 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1831 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001832 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1833 }
1834 else
1835 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001836 return 0;
1837}
1838
paulb40d9392005-08-22 22:34:41 +00001839/* Unconditionally remove the route from the RIB, without taking
1840 * damping into consideration (eg, because the session went down)
1841 */
paul94f2b392005-06-28 12:44:16 +00001842static void
paul718e3742002-12-13 20:15:29 +00001843bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1844 afi_t afi, safi_t safi)
1845{
paul902212c2006-02-05 17:51:19 +00001846 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1847
1848 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1849 bgp_info_delete (rn, ri); /* keep historical info */
1850
paulb40d9392005-08-22 22:34:41 +00001851 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001852}
1853
paul94f2b392005-06-28 12:44:16 +00001854static void
paul718e3742002-12-13 20:15:29 +00001855bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001856 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001857{
paul718e3742002-12-13 20:15:29 +00001858 int status = BGP_DAMP_NONE;
1859
paulb40d9392005-08-22 22:34:41 +00001860 /* apply dampening, if result is suppressed, we'll be retaining
1861 * the bgp_info in the RIB for historical reference.
1862 */
1863 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001864 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001865 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1866 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001867 {
paul902212c2006-02-05 17:51:19 +00001868 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1869 return;
1870 }
1871
1872 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001873}
1874
paul94f2b392005-06-28 12:44:16 +00001875static void
paulfee0f4c2004-09-13 05:12:46 +00001876bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1877 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1878 int sub_type, struct prefix_rd *prd, u_char *tag)
1879{
1880 struct bgp_node *rn;
1881 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001882 struct attr new_attr;
1883 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001884 struct attr *attr_new;
1885 struct attr *attr_new2;
1886 struct bgp_info *ri;
1887 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001888 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001889 char buf[SU_ADDRSTRLEN];
1890
1891 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1892 if (peer == rsclient)
1893 return;
1894
1895 bgp = peer->bgp;
1896 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1897
1898 /* Check previously received route. */
1899 for (ri = rn->info; ri; ri = ri->next)
1900 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1901 break;
1902
1903 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001904 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001905 {
1906 reason = "as-path contains our own AS;";
1907 goto filtered;
1908 }
1909
1910 /* Route reflector originator ID check. */
1911 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001912 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001913 {
1914 reason = "originator is us;";
1915 goto filtered;
1916 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001917
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001918 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001919 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001920
1921 /* Apply export policy. */
1922 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1923 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1924 {
1925 reason = "export-policy;";
1926 goto filtered;
1927 }
1928
1929 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001930
paulfee0f4c2004-09-13 05:12:46 +00001931 /* Apply import policy. */
1932 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1933 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001934 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001935
1936 reason = "import-policy;";
1937 goto filtered;
1938 }
1939
1940 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001941 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001942
1943 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001944 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001945 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001946 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001947 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001948 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001949 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001950 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001951
1952 reason = "martian next-hop;";
1953 goto filtered;
1954 }
1955 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001956
paulfee0f4c2004-09-13 05:12:46 +00001957 /* If the update is implicit withdraw. */
1958 if (ri)
1959 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001960 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001961
1962 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001963 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1964 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001965 {
1966
Paul Jakma1a392d42006-09-07 00:24:49 +00001967 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001968
1969 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001970 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001971 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1972 peer->host,
1973 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1974 p->prefixlen, rsclient->host);
1975
Chris Caputo228da422009-07-18 05:44:03 +00001976 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001977 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001978
Chris Caputo228da422009-07-18 05:44:03 +00001979 return;
paulfee0f4c2004-09-13 05:12:46 +00001980 }
1981
Paul Jakma16d2e242007-04-10 19:32:10 +00001982 /* Withdraw/Announce before we fully processed the withdraw */
1983 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1984 bgp_info_restore (rn, ri);
1985
paulfee0f4c2004-09-13 05:12:46 +00001986 /* Received Logging. */
1987 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001988 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001989 peer->host,
1990 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1991 p->prefixlen, rsclient->host);
1992
1993 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001994 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001995
1996 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001997 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001998 ri->attr = attr_new;
1999
2000 /* Update MPLS tag. */
2001 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002002 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002003
Paul Jakma1a392d42006-09-07 00:24:49 +00002004 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002005
2006 /* Process change. */
2007 bgp_process (bgp, rn, afi, safi);
2008 bgp_unlock_node (rn);
2009
2010 return;
2011 }
2012
2013 /* Received Logging. */
2014 if (BGP_DEBUG (update, UPDATE_IN))
2015 {
ajsd2c1f162004-12-08 21:10:20 +00002016 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002017 peer->host,
2018 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2019 p->prefixlen, rsclient->host);
2020 }
2021
2022 /* Make new BGP info. */
2023 new = bgp_info_new ();
2024 new->type = type;
2025 new->sub_type = sub_type;
2026 new->peer = peer;
2027 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002028 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00002029
2030 /* Update MPLS tag. */
2031 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002032 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002033
Paul Jakma1a392d42006-09-07 00:24:49 +00002034 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002035
2036 /* Register new BGP information. */
2037 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002038
2039 /* route_node_get lock */
2040 bgp_unlock_node (rn);
2041
paulfee0f4c2004-09-13 05:12:46 +00002042 /* Process change. */
2043 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002044
paulfee0f4c2004-09-13 05:12:46 +00002045 return;
2046
2047 filtered:
2048
2049 /* This BGP update is filtered. Log the reason then update BGP entry. */
2050 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002051 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002052 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2053 peer->host,
2054 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2055 p->prefixlen, rsclient->host, reason);
2056
2057 if (ri)
paulb40d9392005-08-22 22:34:41 +00002058 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002059
2060 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002061
paulfee0f4c2004-09-13 05:12:46 +00002062 return;
2063}
2064
paul94f2b392005-06-28 12:44:16 +00002065static void
paulfee0f4c2004-09-13 05:12:46 +00002066bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2067 struct peer *peer, struct prefix *p, int type, int sub_type,
2068 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002069{
paulfee0f4c2004-09-13 05:12:46 +00002070 struct bgp_node *rn;
2071 struct bgp_info *ri;
2072 char buf[SU_ADDRSTRLEN];
2073
2074 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002075 return;
paulfee0f4c2004-09-13 05:12:46 +00002076
2077 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2078
2079 /* Lookup withdrawn route. */
2080 for (ri = rn->info; ri; ri = ri->next)
2081 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2082 break;
2083
2084 /* Withdraw specified route from routing table. */
2085 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002086 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002087 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002088 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002089 "%s Can't find the route %s/%d", peer->host,
2090 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2091 p->prefixlen);
2092
2093 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002094 bgp_unlock_node (rn);
2095}
paulfee0f4c2004-09-13 05:12:46 +00002096
paul94f2b392005-06-28 12:44:16 +00002097static int
paulfee0f4c2004-09-13 05:12:46 +00002098bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002099 afi_t afi, safi_t safi, int type, int sub_type,
2100 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2101{
2102 int ret;
2103 int aspath_loop_count = 0;
2104 struct bgp_node *rn;
2105 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002106 struct attr new_attr;
2107 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002108 struct attr *attr_new;
2109 struct bgp_info *ri;
2110 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002111 const char *reason;
paul718e3742002-12-13 20:15:29 +00002112 char buf[SU_ADDRSTRLEN];
2113
2114 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002115 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002116
paul718e3742002-12-13 20:15:29 +00002117 /* When peer's soft reconfiguration enabled. Record input packet in
2118 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002119 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2120 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002121 bgp_adj_in_set (rn, peer, attr);
2122
2123 /* Check previously received route. */
2124 for (ri = rn->info; ri; ri = ri->next)
2125 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2126 break;
2127
2128 /* AS path local-as loop check. */
2129 if (peer->change_local_as)
2130 {
2131 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2132 aspath_loop_count = 1;
2133
2134 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2135 {
2136 reason = "as-path contains our own AS;";
2137 goto filtered;
2138 }
2139 }
2140
2141 /* AS path loop check. */
2142 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2143 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2144 && aspath_loop_check(attr->aspath, bgp->confed_id)
2145 > peer->allowas_in[afi][safi]))
2146 {
2147 reason = "as-path contains our own AS;";
2148 goto filtered;
2149 }
2150
2151 /* Route reflector originator ID check. */
2152 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002153 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002154 {
2155 reason = "originator is us;";
2156 goto filtered;
2157 }
2158
2159 /* Route reflector cluster ID check. */
2160 if (bgp_cluster_filter (peer, attr))
2161 {
2162 reason = "reflected from the same cluster;";
2163 goto filtered;
2164 }
2165
2166 /* Apply incoming filter. */
2167 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2168 {
2169 reason = "filter;";
2170 goto filtered;
2171 }
2172
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002173 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002174 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002175
David Lamparterc460e572014-06-04 00:54:58 +02002176 /* Apply incoming route-map.
2177 * NB: new_attr may now contain newly allocated values from route-map "set"
2178 * commands, so we need bgp_attr_flush in the error paths, until we intern
2179 * the attr (which takes over the memory references) */
paul718e3742002-12-13 20:15:29 +00002180 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2181 {
2182 reason = "route-map;";
David Lamparterc460e572014-06-04 00:54:58 +02002183 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002184 goto filtered;
2185 }
2186
2187 /* IPv4 unicast next hop check. */
2188 if (afi == AFI_IP && safi == SAFI_UNICAST)
2189 {
2190 /* If the peer is EBGP and nexthop is not on connected route,
2191 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002192 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002193 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002194 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002195 {
2196 reason = "non-connected next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002197 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002198 goto filtered;
2199 }
2200
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002201 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002202 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002203 if (new_attr.nexthop.s_addr == 0
2204 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2205 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002206 {
2207 reason = "martian next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002208 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002209 goto filtered;
2210 }
2211 }
2212
2213 attr_new = bgp_attr_intern (&new_attr);
2214
2215 /* If the update is implicit withdraw. */
2216 if (ri)
2217 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002218 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002219
2220 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002221 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2222 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002223 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002224 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002225
2226 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002227 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002228 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2229 {
2230 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002231 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002232 peer->host,
2233 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2234 p->prefixlen);
2235
paul902212c2006-02-05 17:51:19 +00002236 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2237 {
2238 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2239 bgp_process (bgp, rn, afi, safi);
2240 }
paul718e3742002-12-13 20:15:29 +00002241 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002242 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002243 {
2244 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002245 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002246 "%s rcvd %s/%d...duplicate ignored",
2247 peer->host,
2248 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2249 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002250
2251 /* graceful restart STALE flag unset. */
2252 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2253 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002254 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002255 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002256 }
paul718e3742002-12-13 20:15:29 +00002257 }
2258
2259 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002260 bgp_attr_unintern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002261
paul718e3742002-12-13 20:15:29 +00002262 return 0;
2263 }
2264
Paul Jakma16d2e242007-04-10 19:32:10 +00002265 /* Withdraw/Announce before we fully processed the withdraw */
2266 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2267 {
2268 if (BGP_DEBUG (update, UPDATE_IN))
2269 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2270 peer->host,
2271 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2272 p->prefixlen);
2273 bgp_info_restore (rn, ri);
2274 }
2275
paul718e3742002-12-13 20:15:29 +00002276 /* Received Logging. */
2277 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002278 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002279 peer->host,
2280 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2281 p->prefixlen);
2282
hasso93406d82005-02-02 14:40:33 +00002283 /* graceful restart STALE flag unset. */
2284 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002285 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002286
paul718e3742002-12-13 20:15:29 +00002287 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002288 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002289
2290 /* implicit withdraw, decrement aggregate and pcount here.
2291 * only if update is accepted, they'll increment below.
2292 */
paul902212c2006-02-05 17:51:19 +00002293 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2294
paul718e3742002-12-13 20:15:29 +00002295 /* Update bgp route dampening information. */
2296 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002297 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002298 {
2299 /* This is implicit withdraw so we should update dampening
2300 information. */
2301 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2302 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002303 }
2304
paul718e3742002-12-13 20:15:29 +00002305 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002306 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002307 ri->attr = attr_new;
2308
2309 /* Update MPLS tag. */
2310 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002311 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002312
2313 /* Update bgp route dampening information. */
2314 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002315 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002316 {
2317 /* Now we do normal update dampening. */
2318 ret = bgp_damp_update (ri, rn, afi, safi);
2319 if (ret == BGP_DAMP_SUPPRESSED)
2320 {
2321 bgp_unlock_node (rn);
2322 return 0;
2323 }
2324 }
2325
2326 /* Nexthop reachability check. */
2327 if ((afi == AFI_IP || afi == AFI_IP6)
2328 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002329 && (peer->sort == BGP_PEER_IBGP
2330 || peer->sort == BGP_PEER_CONFED
2331 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002332 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002333 {
2334 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002335 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002336 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002337 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002338 }
2339 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002340 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002341
2342 /* Process change. */
2343 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2344
2345 bgp_process (bgp, rn, afi, safi);
2346 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002347
paul718e3742002-12-13 20:15:29 +00002348 return 0;
2349 }
2350
2351 /* Received Logging. */
2352 if (BGP_DEBUG (update, UPDATE_IN))
2353 {
ajsd2c1f162004-12-08 21:10:20 +00002354 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002355 peer->host,
2356 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2357 p->prefixlen);
2358 }
2359
paul718e3742002-12-13 20:15:29 +00002360 /* Make new BGP info. */
2361 new = bgp_info_new ();
2362 new->type = type;
2363 new->sub_type = sub_type;
2364 new->peer = peer;
2365 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002366 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002367
2368 /* Update MPLS tag. */
2369 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002370 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002371
2372 /* Nexthop reachability check. */
2373 if ((afi == AFI_IP || afi == AFI_IP6)
2374 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002375 && (peer->sort == BGP_PEER_IBGP
2376 || peer->sort == BGP_PEER_CONFED
2377 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002378 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002379 {
2380 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002381 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002382 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002383 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002384 }
2385 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002386 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002387
paul902212c2006-02-05 17:51:19 +00002388 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002389 bgp_aggregate_increment (bgp, p, new, afi, safi);
2390
2391 /* Register new BGP information. */
2392 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002393
2394 /* route_node_get lock */
2395 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002396
paul718e3742002-12-13 20:15:29 +00002397 /* If maximum prefix count is configured and current prefix
2398 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002399 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2400 return -1;
paul718e3742002-12-13 20:15:29 +00002401
2402 /* Process change. */
2403 bgp_process (bgp, rn, afi, safi);
2404
2405 return 0;
2406
2407 /* This BGP update is filtered. Log the reason then update BGP
2408 entry. */
2409 filtered:
2410 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002411 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002412 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2413 peer->host,
2414 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2415 p->prefixlen, reason);
2416
2417 if (ri)
paulb40d9392005-08-22 22:34:41 +00002418 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002419
2420 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002421
paul718e3742002-12-13 20:15:29 +00002422 return 0;
2423}
2424
2425int
paulfee0f4c2004-09-13 05:12:46 +00002426bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2427 afi_t afi, safi_t safi, int type, int sub_type,
2428 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2429{
2430 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002431 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002432 struct bgp *bgp;
2433 int ret;
2434
2435 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2436 soft_reconfig);
2437
2438 bgp = peer->bgp;
2439
2440 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002441 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002442 {
2443 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2444 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2445 sub_type, prd, tag);
2446 }
2447
2448 return ret;
2449}
2450
2451int
paul718e3742002-12-13 20:15:29 +00002452bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002453 afi_t afi, safi_t safi, int type, int sub_type,
2454 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002455{
2456 struct bgp *bgp;
2457 char buf[SU_ADDRSTRLEN];
2458 struct bgp_node *rn;
2459 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002460 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002461 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002462
2463 bgp = peer->bgp;
2464
David Lamparter4584c232015-04-13 09:50:00 +02002465 /* Lookup node. */
2466 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2467
2468 /* Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2469 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2470 * the iteration over all RS clients.
2471 * Since we need to remove the entry from adj_in anyway, do that first and
2472 * if there was no entry, we don't need to do anything more. */
2473 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2474 && peer != bgp->peer_self)
2475 if (!bgp_adj_in_unset (rn, peer))
2476 {
2477 if (BGP_DEBUG (update, UPDATE_IN))
2478 zlog (peer->log, LOG_DEBUG, "%s withdrawing route %s/%d "
2479 "not in adj-in", peer->host,
2480 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2481 p->prefixlen);
2482 bgp_unlock_node (rn);
2483 return 0;
2484 }
2485
paulfee0f4c2004-09-13 05:12:46 +00002486 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002487 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002488 {
2489 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2490 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2491 }
2492
paul718e3742002-12-13 20:15:29 +00002493 /* Logging. */
2494 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002495 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002496 peer->host,
2497 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2498 p->prefixlen);
2499
paul718e3742002-12-13 20:15:29 +00002500 /* Lookup withdrawn route. */
2501 for (ri = rn->info; ri; ri = ri->next)
2502 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2503 break;
2504
2505 /* Withdraw specified route from routing table. */
2506 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002507 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002508 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002509 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002510 "%s Can't find the route %s/%d", peer->host,
2511 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2512 p->prefixlen);
2513
2514 /* Unlock bgp_node_get() lock. */
2515 bgp_unlock_node (rn);
2516
2517 return 0;
2518}
David Lamparter6b0655a2014-06-04 06:53:35 +02002519
paul718e3742002-12-13 20:15:29 +00002520void
2521bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2522{
2523 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002524 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002525 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002526 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002527 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002528 struct bgp_node *rn;
2529 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002530 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002531
Paul Jakmab2497022007-06-14 11:17:58 +00002532 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002533 return;
2534
paul718e3742002-12-13 20:15:29 +00002535 bgp = peer->bgp;
2536 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002537
paul718e3742002-12-13 20:15:29 +00002538 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2539 aspath = attr.aspath;
2540 attr.local_pref = bgp->default_local_pref;
2541 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2542
2543 if (afi == AFI_IP)
2544 str2prefix ("0.0.0.0/0", &p);
2545#ifdef HAVE_IPV6
2546 else if (afi == AFI_IP6)
2547 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002548 struct attr_extra *ae = attr.extra;
2549
paul718e3742002-12-13 20:15:29 +00002550 str2prefix ("::/0", &p);
2551
2552 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002553 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002554 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002555 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002556
2557 /* If the peer is on shared nextwork and we have link-local
2558 nexthop set it. */
2559 if (peer->shared_network
2560 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2561 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002562 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002563 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002564 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002565 }
2566 }
2567#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002568
2569 if (peer->default_rmap[afi][safi].name)
2570 {
paulfee0f4c2004-09-13 05:12:46 +00002571 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002572 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2573 {
2574 for (ri = rn->info; ri; ri = ri->next)
2575 {
2576 struct attr dummy_attr;
2577 struct attr_extra dummy_extra;
2578 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002579
Christian Frankedcab1bb2012-12-07 16:45:52 +00002580 /* Provide dummy so the route-map can't modify the attributes */
2581 dummy_attr.extra = &dummy_extra;
2582 bgp_attr_dup(&dummy_attr, ri->attr);
2583 info.peer = ri->peer;
2584 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002585
Christian Frankedcab1bb2012-12-07 16:45:52 +00002586 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2587 RMAP_BGP, &info);
2588
2589 /* The route map might have set attributes. If we don't flush them
2590 * here, they will be leaked. */
2591 bgp_attr_flush(&dummy_attr);
2592 if (ret != RMAP_DENYMATCH)
2593 break;
2594 }
2595 if (ret != RMAP_DENYMATCH)
2596 break;
2597 }
paulfee0f4c2004-09-13 05:12:46 +00002598 bgp->peer_self->rmap_type = 0;
2599
paul718e3742002-12-13 20:15:29 +00002600 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002601 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002602 }
2603
2604 if (withdraw)
2605 {
2606 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2607 bgp_default_withdraw_send (peer, afi, safi);
2608 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2609 }
2610 else
2611 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002612 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2613 {
2614 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2615 bgp_default_update_send (peer, &attr, afi, safi, from);
2616 }
paul718e3742002-12-13 20:15:29 +00002617 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002618
2619 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002620 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002621}
David Lamparter6b0655a2014-06-04 06:53:35 +02002622
paul718e3742002-12-13 20:15:29 +00002623static void
2624bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002625 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002626{
2627 struct bgp_node *rn;
2628 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002629 struct attr attr;
2630 struct attr_extra extra;
2631
paul718e3742002-12-13 20:15:29 +00002632 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002633 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002634
2635 if (safi != SAFI_MPLS_VPN
2636 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2637 bgp_default_originate (peer, afi, safi, 0);
2638
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002639 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2640 attr.extra = &extra;
2641
paul718e3742002-12-13 20:15:29 +00002642 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2643 for (ri = rn->info; ri; ri = ri->next)
2644 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2645 {
paulfee0f4c2004-09-13 05:12:46 +00002646 if ( (rsclient) ?
2647 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2648 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002649 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2650 else
2651 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2652 }
2653}
2654
2655void
2656bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2657{
2658 struct bgp_node *rn;
2659 struct bgp_table *table;
2660
2661 if (peer->status != Established)
2662 return;
2663
2664 if (! peer->afc_nego[afi][safi])
2665 return;
2666
2667 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2668 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2669 return;
2670
2671 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002672 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002673 else
2674 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2675 rn = bgp_route_next(rn))
2676 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002677 bgp_announce_table (peer, afi, safi, table, 0);
2678
2679 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2680 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002681}
2682
2683void
2684bgp_announce_route_all (struct peer *peer)
2685{
2686 afi_t afi;
2687 safi_t safi;
2688
2689 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2690 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2691 bgp_announce_route (peer, afi, safi);
2692}
David Lamparter6b0655a2014-06-04 06:53:35 +02002693
paul718e3742002-12-13 20:15:29 +00002694static void
paulfee0f4c2004-09-13 05:12:46 +00002695bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002696 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002697{
2698 struct bgp_node *rn;
2699 struct bgp_adj_in *ain;
2700
2701 if (! table)
2702 table = rsclient->bgp->rib[afi][safi];
2703
2704 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2705 for (ain = rn->adj_in; ain; ain = ain->next)
2706 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002707 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002708 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002709
paulfee0f4c2004-09-13 05:12:46 +00002710 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002711 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002712 }
2713}
2714
2715void
2716bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2717{
2718 struct bgp_table *table;
2719 struct bgp_node *rn;
2720
2721 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002722 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002723
2724 else
2725 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2726 rn = bgp_route_next (rn))
2727 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002728 {
2729 struct prefix_rd prd;
2730 prd.family = AF_UNSPEC;
2731 prd.prefixlen = 64;
2732 memcpy(&prd.val, rn->p.u.val, 8);
2733
2734 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2735 }
paulfee0f4c2004-09-13 05:12:46 +00002736}
David Lamparter6b0655a2014-06-04 06:53:35 +02002737
paulfee0f4c2004-09-13 05:12:46 +00002738static void
paul718e3742002-12-13 20:15:29 +00002739bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002740 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002741{
2742 int ret;
2743 struct bgp_node *rn;
2744 struct bgp_adj_in *ain;
2745
2746 if (! table)
2747 table = peer->bgp->rib[afi][safi];
2748
2749 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2750 for (ain = rn->adj_in; ain; ain = ain->next)
2751 {
2752 if (ain->peer == peer)
2753 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002754 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002755 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002756
paul718e3742002-12-13 20:15:29 +00002757 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2758 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002759 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002760
paul718e3742002-12-13 20:15:29 +00002761 if (ret < 0)
2762 {
2763 bgp_unlock_node (rn);
2764 return;
2765 }
2766 continue;
2767 }
2768 }
2769}
2770
2771void
2772bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2773{
2774 struct bgp_node *rn;
2775 struct bgp_table *table;
2776
2777 if (peer->status != Established)
2778 return;
2779
2780 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002781 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002782 else
2783 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2784 rn = bgp_route_next (rn))
2785 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002786 {
2787 struct prefix_rd prd;
2788 prd.family = AF_UNSPEC;
2789 prd.prefixlen = 64;
2790 memcpy(&prd.val, rn->p.u.val, 8);
2791
2792 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2793 }
paul718e3742002-12-13 20:15:29 +00002794}
David Lamparter6b0655a2014-06-04 06:53:35 +02002795
Chris Caputo228da422009-07-18 05:44:03 +00002796
2797struct bgp_clear_node_queue
2798{
2799 struct bgp_node *rn;
2800 enum bgp_clear_route_type purpose;
2801};
2802
paul200df112005-06-01 11:17:05 +00002803static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002804bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002805{
Chris Caputo228da422009-07-18 05:44:03 +00002806 struct bgp_clear_node_queue *cnq = data;
2807 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002808 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002809 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002810 afi_t afi = bgp_node_table (rn)->afi;
2811 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002812
Paul Jakma64e580a2006-02-21 01:09:01 +00002813 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002814
Paul Jakma64e580a2006-02-21 01:09:01 +00002815 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002816 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002817 {
2818 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002819 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2820 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002821 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002822 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2823 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002824 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002825 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002826 break;
2827 }
paul200df112005-06-01 11:17:05 +00002828 return WQ_SUCCESS;
2829}
2830
2831static void
paul0fb58d52005-11-14 14:31:49 +00002832bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002833{
Chris Caputo228da422009-07-18 05:44:03 +00002834 struct bgp_clear_node_queue *cnq = data;
2835 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002836 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002837
2838 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002839 bgp_table_unlock (table);
2840 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002841}
2842
2843static void
paul94f2b392005-06-28 12:44:16 +00002844bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002845{
Paul Jakma64e580a2006-02-21 01:09:01 +00002846 struct peer *peer = wq->spec.data;
2847
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002848 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002849 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002850
2851 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002852}
2853
2854static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002855bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002856{
Paul Jakmaa2943652009-07-21 14:02:04 +01002857 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002858
Paul Jakmaa2943652009-07-21 14:02:04 +01002859 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002860#undef CLEAR_QUEUE_NAME_LEN
2861
2862 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002863 {
2864 zlog_err ("%s: Failed to allocate work queue", __func__);
2865 exit (1);
2866 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002867 peer->clear_node_queue->spec.hold = 10;
2868 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2869 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2870 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2871 peer->clear_node_queue->spec.max_retries = 0;
2872
2873 /* we only 'lock' this peer reference when the queue is actually active */
2874 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002875}
2876
paul718e3742002-12-13 20:15:29 +00002877static void
2878bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002879 struct bgp_table *table, struct peer *rsclient,
2880 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002881{
2882 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002883
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002884
paul718e3742002-12-13 20:15:29 +00002885 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002886 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002887
hasso6cf159b2005-03-21 10:28:14 +00002888 /* If still no table => afi/safi isn't configured at all or smth. */
2889 if (! table)
2890 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002891
2892 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2893 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002894 struct bgp_info *ri;
2895 struct bgp_adj_in *ain;
2896 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002897
2898 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2899 * queued for every clearing peer, regardless of whether it is
2900 * relevant to the peer at hand.
2901 *
2902 * Overview: There are 3 different indices which need to be
2903 * scrubbed, potentially, when a peer is removed:
2904 *
2905 * 1 peer's routes visible via the RIB (ie accepted routes)
2906 * 2 peer's routes visible by the (optional) peer's adj-in index
2907 * 3 other routes visible by the peer's adj-out index
2908 *
2909 * 3 there is no hurry in scrubbing, once the struct peer is
2910 * removed from bgp->peer, we could just GC such deleted peer's
2911 * adj-outs at our leisure.
2912 *
2913 * 1 and 2 must be 'scrubbed' in some way, at least made
2914 * invisible via RIB index before peer session is allowed to be
2915 * brought back up. So one needs to know when such a 'search' is
2916 * complete.
2917 *
2918 * Ideally:
2919 *
2920 * - there'd be a single global queue or a single RIB walker
2921 * - rather than tracking which route_nodes still need to be
2922 * examined on a peer basis, we'd track which peers still
2923 * aren't cleared
2924 *
2925 * Given that our per-peer prefix-counts now should be reliable,
2926 * this may actually be achievable. It doesn't seem to be a huge
2927 * problem at this time,
2928 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002929 for (ain = rn->adj_in; ain; ain = ain->next)
2930 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2931 {
2932 bgp_adj_in_remove (rn, ain);
2933 bgp_unlock_node (rn);
2934 break;
2935 }
2936 for (aout = rn->adj_out; aout; aout = aout->next)
2937 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2938 {
2939 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2940 bgp_unlock_node (rn);
2941 break;
2942 }
2943
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002944 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002945 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002946 {
Chris Caputo228da422009-07-18 05:44:03 +00002947 struct bgp_clear_node_queue *cnq;
2948
2949 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002950 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002951 bgp_lock_node (rn);
2952 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2953 sizeof (struct bgp_clear_node_queue));
2954 cnq->rn = rn;
2955 cnq->purpose = purpose;
2956 work_queue_add (peer->clear_node_queue, cnq);
2957 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002958 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002959 }
2960 return;
2961}
2962
2963void
Chris Caputo228da422009-07-18 05:44:03 +00002964bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2965 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002966{
2967 struct bgp_node *rn;
2968 struct bgp_table *table;
2969 struct peer *rsclient;
2970 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002971
Paul Jakma64e580a2006-02-21 01:09:01 +00002972 if (peer->clear_node_queue == NULL)
2973 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002974
Paul Jakmaca058a32006-09-14 02:58:49 +00002975 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2976 * Idle until it receives a Clearing_Completed event. This protects
2977 * against peers which flap faster than we can we clear, which could
2978 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002979 *
2980 * a) race with routes from the new session being installed before
2981 * clear_route_node visits the node (to delete the route of that
2982 * peer)
2983 * b) resource exhaustion, clear_route_node likely leads to an entry
2984 * on the process_main queue. Fast-flapping could cause that queue
2985 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002986 */
Donald Sharp7ef42212015-03-30 06:32:52 -07002987
2988 /* lock peer in assumption that clear-node-queue will get nodes; if so,
2989 * the unlock will happen upon work-queue completion; other wise, the
2990 * unlock happens at the end of this function.
2991 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002992 if (!peer->clear_node_queue->thread)
Donald Sharp7ef42212015-03-30 06:32:52 -07002993 peer_lock (peer);
paulfee0f4c2004-09-13 05:12:46 +00002994
Chris Caputo228da422009-07-18 05:44:03 +00002995 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002996 {
Chris Caputo228da422009-07-18 05:44:03 +00002997 case BGP_CLEAR_ROUTE_NORMAL:
2998 if (safi != SAFI_MPLS_VPN)
2999 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
3000 else
3001 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3002 rn = bgp_route_next (rn))
3003 if ((table = rn->info) != NULL)
3004 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3005
3006 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
3007 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
3008 PEER_FLAG_RSERVER_CLIENT))
3009 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3010 break;
3011
3012 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
3013 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3014 break;
3015
3016 default:
3017 assert (0);
3018 break;
paulfee0f4c2004-09-13 05:12:46 +00003019 }
Donald Sharp7ef42212015-03-30 06:32:52 -07003020
3021 /* unlock if no nodes got added to the clear-node-queue. */
Paul Jakma65ca75e2006-05-04 08:08:15 +00003022 if (!peer->clear_node_queue->thread)
Donald Sharp7ef42212015-03-30 06:32:52 -07003023 peer_unlock (peer);
3024
paul718e3742002-12-13 20:15:29 +00003025}
3026
3027void
3028bgp_clear_route_all (struct peer *peer)
3029{
3030 afi_t afi;
3031 safi_t safi;
3032
3033 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3034 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003035 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003036}
3037
3038void
3039bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3040{
3041 struct bgp_table *table;
3042 struct bgp_node *rn;
3043 struct bgp_adj_in *ain;
3044
3045 table = peer->bgp->rib[afi][safi];
3046
3047 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3048 for (ain = rn->adj_in; ain ; ain = ain->next)
3049 if (ain->peer == peer)
3050 {
3051 bgp_adj_in_remove (rn, ain);
3052 bgp_unlock_node (rn);
3053 break;
3054 }
3055}
hasso93406d82005-02-02 14:40:33 +00003056
3057void
3058bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3059{
3060 struct bgp_node *rn;
3061 struct bgp_info *ri;
3062 struct bgp_table *table;
3063
3064 table = peer->bgp->rib[afi][safi];
3065
3066 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3067 {
3068 for (ri = rn->info; ri; ri = ri->next)
3069 if (ri->peer == peer)
3070 {
3071 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3072 bgp_rib_remove (rn, ri, peer, afi, safi);
3073 break;
3074 }
3075 }
3076}
David Lamparter6b0655a2014-06-04 06:53:35 +02003077
paul718e3742002-12-13 20:15:29 +00003078/* Delete all kernel routes. */
3079void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003080bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003081{
3082 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003083 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003084 struct bgp_node *rn;
3085 struct bgp_table *table;
3086 struct bgp_info *ri;
3087
paul1eb8ef22005-04-07 07:30:20 +00003088 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003089 {
3090 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3091
3092 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3093 for (ri = rn->info; ri; ri = ri->next)
3094 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3095 && ri->type == ZEBRA_ROUTE_BGP
3096 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003097 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003098
3099 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3100
3101 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3102 for (ri = rn->info; ri; ri = ri->next)
3103 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3104 && ri->type == ZEBRA_ROUTE_BGP
3105 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003106 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003107 }
3108}
3109
3110void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003111bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003112{
3113 vty_reset ();
3114 bgp_zclient_reset ();
3115 access_list_reset ();
3116 prefix_list_reset ();
3117}
David Lamparter6b0655a2014-06-04 06:53:35 +02003118
paul718e3742002-12-13 20:15:29 +00003119/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3120 value. */
3121int
3122bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3123{
3124 u_char *pnt;
3125 u_char *lim;
3126 struct prefix p;
3127 int psize;
3128 int ret;
3129
3130 /* Check peer status. */
3131 if (peer->status != Established)
3132 return 0;
3133
3134 pnt = packet->nlri;
3135 lim = pnt + packet->length;
3136
3137 for (; pnt < lim; pnt += psize)
3138 {
3139 /* Clear prefix structure. */
3140 memset (&p, 0, sizeof (struct prefix));
3141
3142 /* Fetch prefix length. */
3143 p.prefixlen = *pnt++;
3144 p.family = afi2family (packet->afi);
3145
3146 /* Already checked in nlri_sanity_check(). We do double check
3147 here. */
3148 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3149 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3150 return -1;
3151
3152 /* Packet size overflow check. */
3153 psize = PSIZE (p.prefixlen);
3154
3155 /* When packet overflow occur return immediately. */
3156 if (pnt + psize > lim)
3157 return -1;
3158
3159 /* Fetch prefix from NLRI packet. */
3160 memcpy (&p.u.prefix, pnt, psize);
3161
3162 /* Check address. */
3163 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3164 {
3165 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3166 {
paulf5ba3872004-07-09 12:11:31 +00003167 /*
3168 * From draft-ietf-idr-bgp4-22, Section 6.3:
3169 * If a BGP router receives an UPDATE message with a
3170 * semantically incorrect NLRI field, in which a prefix is
3171 * semantically incorrect (eg. an unexpected multicast IP
3172 * address), it should ignore the prefix.
3173 */
paul718e3742002-12-13 20:15:29 +00003174 zlog (peer->log, LOG_ERR,
3175 "IPv4 unicast NLRI is multicast address %s",
3176 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003177
paul718e3742002-12-13 20:15:29 +00003178 return -1;
3179 }
3180 }
3181
3182#ifdef HAVE_IPV6
3183 /* Check address. */
3184 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3185 {
3186 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3187 {
3188 char buf[BUFSIZ];
3189
3190 zlog (peer->log, LOG_WARNING,
3191 "IPv6 link-local NLRI received %s ignore this NLRI",
3192 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3193
3194 continue;
3195 }
3196 }
3197#endif /* HAVE_IPV6 */
3198
3199 /* Normal process. */
3200 if (attr)
3201 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3202 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3203 else
3204 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3205 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3206
3207 /* Address family configuration mismatch or maximum-prefix count
3208 overflow. */
3209 if (ret < 0)
3210 return -1;
3211 }
3212
3213 /* Packet length consistency check. */
3214 if (pnt != lim)
3215 return -1;
3216
3217 return 0;
3218}
3219
3220/* NLRI encode syntax check routine. */
3221int
3222bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3223 bgp_size_t length)
3224{
3225 u_char *end;
3226 u_char prefixlen;
3227 int psize;
3228
3229 end = pnt + length;
3230
3231 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3232 syntactic validity. If the field is syntactically incorrect,
3233 then the Error Subcode is set to Invalid Network Field. */
3234
3235 while (pnt < end)
3236 {
3237 prefixlen = *pnt++;
3238
3239 /* Prefix length check. */
3240 if ((afi == AFI_IP && prefixlen > 32)
3241 || (afi == AFI_IP6 && prefixlen > 128))
3242 {
3243 plog_err (peer->log,
3244 "%s [Error] Update packet error (wrong prefix length %d)",
3245 peer->host, prefixlen);
3246 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3247 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3248 return -1;
3249 }
3250
3251 /* Packet size overflow check. */
3252 psize = PSIZE (prefixlen);
3253
3254 if (pnt + psize > end)
3255 {
3256 plog_err (peer->log,
3257 "%s [Error] Update packet error"
3258 " (prefix data overflow prefix size is %d)",
3259 peer->host, psize);
3260 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3261 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3262 return -1;
3263 }
3264
3265 pnt += psize;
3266 }
3267
3268 /* Packet length consistency check. */
3269 if (pnt != end)
3270 {
3271 plog_err (peer->log,
3272 "%s [Error] Update packet error"
3273 " (prefix length mismatch with total length)",
3274 peer->host);
3275 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3276 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3277 return -1;
3278 }
3279 return 0;
3280}
David Lamparter6b0655a2014-06-04 06:53:35 +02003281
paul94f2b392005-06-28 12:44:16 +00003282static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003283bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003284{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003285 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003286}
3287
paul94f2b392005-06-28 12:44:16 +00003288static void
paul718e3742002-12-13 20:15:29 +00003289bgp_static_free (struct bgp_static *bgp_static)
3290{
3291 if (bgp_static->rmap.name)
3292 free (bgp_static->rmap.name);
3293 XFREE (MTYPE_BGP_STATIC, bgp_static);
3294}
3295
paul94f2b392005-06-28 12:44:16 +00003296static void
paulfee0f4c2004-09-13 05:12:46 +00003297bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3298 struct prefix *p, afi_t afi, safi_t safi)
3299{
3300 struct bgp_node *rn;
3301 struct bgp_info *ri;
3302
3303 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3304
3305 /* Check selected route and self inserted route. */
3306 for (ri = rn->info; ri; ri = ri->next)
3307 if (ri->peer == bgp->peer_self
3308 && ri->type == ZEBRA_ROUTE_BGP
3309 && ri->sub_type == BGP_ROUTE_STATIC)
3310 break;
3311
3312 /* Withdraw static BGP route from routing table. */
3313 if (ri)
3314 {
paulfee0f4c2004-09-13 05:12:46 +00003315 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003316 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003317 }
3318
3319 /* Unlock bgp_node_lookup. */
3320 bgp_unlock_node (rn);
3321}
3322
paul94f2b392005-06-28 12:44:16 +00003323static void
paulfee0f4c2004-09-13 05:12:46 +00003324bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003325 struct bgp_static *bgp_static,
3326 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003327{
3328 struct bgp_node *rn;
3329 struct bgp_info *ri;
3330 struct bgp_info *new;
3331 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003332 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003333 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003334 struct attr new_attr;
3335 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003336 struct bgp *bgp;
3337 int ret;
3338 char buf[SU_ADDRSTRLEN];
3339
3340 bgp = rsclient->bgp;
3341
Paul Jakma06e110f2006-05-12 23:29:22 +00003342 assert (bgp_static);
3343 if (!bgp_static)
3344 return;
3345
paulfee0f4c2004-09-13 05:12:46 +00003346 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3347
3348 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003349
3350 attr.nexthop = bgp_static->igpnexthop;
3351 attr.med = bgp_static->igpmetric;
3352 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003353
Paul Jakma41367172007-08-06 15:24:51 +00003354 if (bgp_static->atomic)
3355 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3356
paulfee0f4c2004-09-13 05:12:46 +00003357 /* Apply network route-map for export to this rsclient. */
3358 if (bgp_static->rmap.name)
3359 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003360 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003361 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003362 info.attr = &attr_tmp;
3363
paulfee0f4c2004-09-13 05:12:46 +00003364 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3365 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3366
3367 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3368
3369 rsclient->rmap_type = 0;
3370
3371 if (ret == RMAP_DENYMATCH)
3372 {
3373 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003374 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003375
3376 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003377 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003378 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003379 bgp_attr_extra_free (&attr);
3380
paulfee0f4c2004-09-13 05:12:46 +00003381 return;
3382 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003383 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003384 }
3385 else
3386 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003387
3388 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003389 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003390
paulfee0f4c2004-09-13 05:12:46 +00003391 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3392
Paul Jakmafb982c22007-05-04 20:15:47 +00003393 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3394 == RMAP_DENY)
3395 {
paulfee0f4c2004-09-13 05:12:46 +00003396 /* This BGP update is filtered. Log the reason then update BGP entry. */
3397 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003398 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003399 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3400 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3401 p->prefixlen, rsclient->host);
3402
3403 bgp->peer_self->rmap_type = 0;
3404
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003405 bgp_attr_unintern (&attr_new);
3406 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003407 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003408
3409 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3410
3411 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003412 }
paulfee0f4c2004-09-13 05:12:46 +00003413
3414 bgp->peer_self->rmap_type = 0;
3415
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003416 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003417 attr_new = bgp_attr_intern (&new_attr);
3418
3419 for (ri = rn->info; ri; ri = ri->next)
3420 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3421 && ri->sub_type == BGP_ROUTE_STATIC)
3422 break;
3423
3424 if (ri)
3425 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003426 if (attrhash_cmp (ri->attr, attr_new) &&
3427 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003428 {
3429 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003430 bgp_attr_unintern (&attr_new);
3431 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003432 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003433 return;
3434 }
3435 else
3436 {
3437 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003438 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003439
3440 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003441 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3442 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003443 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003444 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003445 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003446
3447 /* Process change. */
3448 bgp_process (bgp, rn, afi, safi);
3449 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003450 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003451 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003452 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003453 }
paulfee0f4c2004-09-13 05:12:46 +00003454 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003455
paulfee0f4c2004-09-13 05:12:46 +00003456 /* Make new BGP info. */
3457 new = bgp_info_new ();
3458 new->type = ZEBRA_ROUTE_BGP;
3459 new->sub_type = BGP_ROUTE_STATIC;
3460 new->peer = bgp->peer_self;
3461 SET_FLAG (new->flags, BGP_INFO_VALID);
3462 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003463 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003464
3465 /* Register new BGP information. */
3466 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003467
3468 /* route_node_get lock */
3469 bgp_unlock_node (rn);
3470
paulfee0f4c2004-09-13 05:12:46 +00003471 /* Process change. */
3472 bgp_process (bgp, rn, afi, safi);
3473
3474 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003475 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003476 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003477}
3478
paul94f2b392005-06-28 12:44:16 +00003479static void
paulfee0f4c2004-09-13 05:12:46 +00003480bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003481 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3482{
3483 struct bgp_node *rn;
3484 struct bgp_info *ri;
3485 struct bgp_info *new;
3486 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003487 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003488 struct attr *attr_new;
3489 int ret;
3490
Paul Jakmadd8103a2006-05-12 23:27:30 +00003491 assert (bgp_static);
3492 if (!bgp_static)
3493 return;
3494
paulfee0f4c2004-09-13 05:12:46 +00003495 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003496
3497 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003498
3499 attr.nexthop = bgp_static->igpnexthop;
3500 attr.med = bgp_static->igpmetric;
3501 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003502
Paul Jakma41367172007-08-06 15:24:51 +00003503 if (bgp_static->atomic)
3504 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3505
paul718e3742002-12-13 20:15:29 +00003506 /* Apply route-map. */
3507 if (bgp_static->rmap.name)
3508 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003509 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003510 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003511 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003512
paulfee0f4c2004-09-13 05:12:46 +00003513 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3514
paul718e3742002-12-13 20:15:29 +00003515 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003516
paulfee0f4c2004-09-13 05:12:46 +00003517 bgp->peer_self->rmap_type = 0;
3518
paul718e3742002-12-13 20:15:29 +00003519 if (ret == RMAP_DENYMATCH)
3520 {
3521 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003522 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003523
3524 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003525 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003526 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003527 bgp_static_withdraw (bgp, p, afi, safi);
3528 return;
3529 }
paul286e1e72003-08-08 00:24:31 +00003530 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003531 }
paul286e1e72003-08-08 00:24:31 +00003532 else
3533 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003534
3535 for (ri = rn->info; ri; ri = ri->next)
3536 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3537 && ri->sub_type == BGP_ROUTE_STATIC)
3538 break;
3539
3540 if (ri)
3541 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003542 if (attrhash_cmp (ri->attr, attr_new) &&
3543 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003544 {
3545 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003546 bgp_attr_unintern (&attr_new);
3547 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003548 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003549 return;
3550 }
3551 else
3552 {
3553 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003554 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003555
3556 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003557 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3558 bgp_info_restore(rn, ri);
3559 else
3560 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003561 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003562 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003563 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003564
3565 /* Process change. */
3566 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3567 bgp_process (bgp, rn, afi, safi);
3568 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003569 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003570 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003571 return;
3572 }
3573 }
3574
3575 /* Make new BGP info. */
3576 new = bgp_info_new ();
3577 new->type = ZEBRA_ROUTE_BGP;
3578 new->sub_type = BGP_ROUTE_STATIC;
3579 new->peer = bgp->peer_self;
3580 SET_FLAG (new->flags, BGP_INFO_VALID);
3581 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003582 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003583
3584 /* Aggregate address increment. */
3585 bgp_aggregate_increment (bgp, p, new, afi, safi);
3586
3587 /* Register new BGP information. */
3588 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003589
3590 /* route_node_get lock */
3591 bgp_unlock_node (rn);
3592
paul718e3742002-12-13 20:15:29 +00003593 /* Process change. */
3594 bgp_process (bgp, rn, afi, safi);
3595
3596 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003597 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003598 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003599}
3600
3601void
paulfee0f4c2004-09-13 05:12:46 +00003602bgp_static_update (struct bgp *bgp, struct prefix *p,
3603 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3604{
3605 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003606 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003607
3608 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3609
paul1eb8ef22005-04-07 07:30:20 +00003610 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003611 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003612 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3613 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003614 }
3615}
3616
paul94f2b392005-06-28 12:44:16 +00003617static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003618bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3619 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003620{
3621 struct bgp_node *rn;
3622 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003623
paulfee0f4c2004-09-13 05:12:46 +00003624 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003625
3626 /* Make new BGP info. */
3627 new = bgp_info_new ();
3628 new->type = ZEBRA_ROUTE_BGP;
3629 new->sub_type = BGP_ROUTE_STATIC;
3630 new->peer = bgp->peer_self;
3631 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3632 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003633 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003634 new->extra = bgp_info_extra_new();
3635 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003636
3637 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003638 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003639
3640 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003641 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003642
paul200df112005-06-01 11:17:05 +00003643 /* route_node_get lock */
3644 bgp_unlock_node (rn);
3645
paul718e3742002-12-13 20:15:29 +00003646 /* Process change. */
3647 bgp_process (bgp, rn, afi, safi);
3648}
3649
3650void
3651bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3652 safi_t safi)
3653{
3654 struct bgp_node *rn;
3655 struct bgp_info *ri;
3656
paulfee0f4c2004-09-13 05:12:46 +00003657 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003658
3659 /* Check selected route and self inserted route. */
3660 for (ri = rn->info; ri; ri = ri->next)
3661 if (ri->peer == bgp->peer_self
3662 && ri->type == ZEBRA_ROUTE_BGP
3663 && ri->sub_type == BGP_ROUTE_STATIC)
3664 break;
3665
3666 /* Withdraw static BGP route from routing table. */
3667 if (ri)
3668 {
3669 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003670 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003671 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003672 }
3673
3674 /* Unlock bgp_node_lookup. */
3675 bgp_unlock_node (rn);
3676}
3677
3678void
paulfee0f4c2004-09-13 05:12:46 +00003679bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3680{
3681 struct bgp_static *bgp_static;
3682 struct bgp *bgp;
3683 struct bgp_node *rn;
3684 struct prefix *p;
3685
3686 bgp = rsclient->bgp;
3687
3688 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3689 if ((bgp_static = rn->info) != NULL)
3690 {
3691 p = &rn->p;
3692
3693 bgp_static_update_rsclient (rsclient, p, bgp_static,
3694 afi, safi);
3695 }
3696}
3697
paul94f2b392005-06-28 12:44:16 +00003698static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003699bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3700 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003701{
3702 struct bgp_node *rn;
3703 struct bgp_info *ri;
3704
paulfee0f4c2004-09-13 05:12:46 +00003705 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003706
3707 /* Check selected route and self inserted route. */
3708 for (ri = rn->info; ri; ri = ri->next)
3709 if (ri->peer == bgp->peer_self
3710 && ri->type == ZEBRA_ROUTE_BGP
3711 && ri->sub_type == BGP_ROUTE_STATIC)
3712 break;
3713
3714 /* Withdraw static BGP route from routing table. */
3715 if (ri)
3716 {
3717 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003718 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003719 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003720 }
3721
3722 /* Unlock bgp_node_lookup. */
3723 bgp_unlock_node (rn);
3724}
3725
3726/* Configure static BGP network. When user don't run zebra, static
3727 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003728static int
paulfd79ac92004-10-13 05:06:08 +00003729bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003730 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003731{
3732 int ret;
3733 struct prefix p;
3734 struct bgp_static *bgp_static;
3735 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003736 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003737
3738 /* Convert IP prefix string to struct prefix. */
3739 ret = str2prefix (ip_str, &p);
3740 if (! ret)
3741 {
3742 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3743 return CMD_WARNING;
3744 }
3745#ifdef HAVE_IPV6
3746 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3747 {
3748 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3749 VTY_NEWLINE);
3750 return CMD_WARNING;
3751 }
3752#endif /* HAVE_IPV6 */
3753
3754 apply_mask (&p);
3755
3756 /* Set BGP static route configuration. */
3757 rn = bgp_node_get (bgp->route[afi][safi], &p);
3758
3759 if (rn->info)
3760 {
3761 /* Configuration change. */
3762 bgp_static = rn->info;
3763
3764 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003765 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3766 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003767
paul718e3742002-12-13 20:15:29 +00003768 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003769
paul718e3742002-12-13 20:15:29 +00003770 if (rmap)
3771 {
3772 if (bgp_static->rmap.name)
3773 free (bgp_static->rmap.name);
3774 bgp_static->rmap.name = strdup (rmap);
3775 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3776 }
3777 else
3778 {
3779 if (bgp_static->rmap.name)
3780 free (bgp_static->rmap.name);
3781 bgp_static->rmap.name = NULL;
3782 bgp_static->rmap.map = NULL;
3783 bgp_static->valid = 0;
3784 }
3785 bgp_unlock_node (rn);
3786 }
3787 else
3788 {
3789 /* New configuration. */
3790 bgp_static = bgp_static_new ();
3791 bgp_static->backdoor = backdoor;
3792 bgp_static->valid = 0;
3793 bgp_static->igpmetric = 0;
3794 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003795
paul718e3742002-12-13 20:15:29 +00003796 if (rmap)
3797 {
3798 if (bgp_static->rmap.name)
3799 free (bgp_static->rmap.name);
3800 bgp_static->rmap.name = strdup (rmap);
3801 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3802 }
3803 rn->info = bgp_static;
3804 }
3805
3806 /* If BGP scan is not enabled, we should install this route here. */
3807 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3808 {
3809 bgp_static->valid = 1;
3810
3811 if (need_update)
3812 bgp_static_withdraw (bgp, &p, afi, safi);
3813
3814 if (! bgp_static->backdoor)
3815 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3816 }
3817
3818 return CMD_SUCCESS;
3819}
3820
3821/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003822static int
paulfd79ac92004-10-13 05:06:08 +00003823bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003824 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003825{
3826 int ret;
3827 struct prefix p;
3828 struct bgp_static *bgp_static;
3829 struct bgp_node *rn;
3830
3831 /* Convert IP prefix string to struct prefix. */
3832 ret = str2prefix (ip_str, &p);
3833 if (! ret)
3834 {
3835 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3836 return CMD_WARNING;
3837 }
3838#ifdef HAVE_IPV6
3839 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3840 {
3841 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3842 VTY_NEWLINE);
3843 return CMD_WARNING;
3844 }
3845#endif /* HAVE_IPV6 */
3846
3847 apply_mask (&p);
3848
3849 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3850 if (! rn)
3851 {
3852 vty_out (vty, "%% Can't find specified static route configuration.%s",
3853 VTY_NEWLINE);
3854 return CMD_WARNING;
3855 }
3856
3857 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003858
paul718e3742002-12-13 20:15:29 +00003859 /* Update BGP RIB. */
3860 if (! bgp_static->backdoor)
3861 bgp_static_withdraw (bgp, &p, afi, safi);
3862
3863 /* Clear configuration. */
3864 bgp_static_free (bgp_static);
3865 rn->info = NULL;
3866 bgp_unlock_node (rn);
3867 bgp_unlock_node (rn);
3868
3869 return CMD_SUCCESS;
3870}
3871
3872/* Called from bgp_delete(). Delete all static routes from the BGP
3873 instance. */
3874void
3875bgp_static_delete (struct bgp *bgp)
3876{
3877 afi_t afi;
3878 safi_t safi;
3879 struct bgp_node *rn;
3880 struct bgp_node *rm;
3881 struct bgp_table *table;
3882 struct bgp_static *bgp_static;
3883
3884 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3885 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3886 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3887 if (rn->info != NULL)
3888 {
3889 if (safi == SAFI_MPLS_VPN)
3890 {
3891 table = rn->info;
3892
3893 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3894 {
3895 bgp_static = rn->info;
3896 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3897 AFI_IP, SAFI_MPLS_VPN,
3898 (struct prefix_rd *)&rn->p,
3899 bgp_static->tag);
3900 bgp_static_free (bgp_static);
3901 rn->info = NULL;
3902 bgp_unlock_node (rn);
3903 }
3904 }
3905 else
3906 {
3907 bgp_static = rn->info;
3908 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3909 bgp_static_free (bgp_static);
3910 rn->info = NULL;
3911 bgp_unlock_node (rn);
3912 }
3913 }
3914}
3915
3916int
paulfd79ac92004-10-13 05:06:08 +00003917bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3918 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003919{
3920 int ret;
3921 struct prefix p;
3922 struct prefix_rd prd;
3923 struct bgp *bgp;
3924 struct bgp_node *prn;
3925 struct bgp_node *rn;
3926 struct bgp_table *table;
3927 struct bgp_static *bgp_static;
3928 u_char tag[3];
3929
3930 bgp = vty->index;
3931
3932 ret = str2prefix (ip_str, &p);
3933 if (! ret)
3934 {
3935 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3936 return CMD_WARNING;
3937 }
3938 apply_mask (&p);
3939
3940 ret = str2prefix_rd (rd_str, &prd);
3941 if (! ret)
3942 {
3943 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3944 return CMD_WARNING;
3945 }
3946
3947 ret = str2tag (tag_str, tag);
3948 if (! ret)
3949 {
3950 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3951 return CMD_WARNING;
3952 }
3953
3954 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3955 (struct prefix *)&prd);
3956 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003957 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003958 else
3959 bgp_unlock_node (prn);
3960 table = prn->info;
3961
3962 rn = bgp_node_get (table, &p);
3963
3964 if (rn->info)
3965 {
3966 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3967 bgp_unlock_node (rn);
3968 }
3969 else
3970 {
3971 /* New configuration. */
3972 bgp_static = bgp_static_new ();
3973 bgp_static->valid = 1;
3974 memcpy (bgp_static->tag, tag, 3);
3975 rn->info = bgp_static;
3976
3977 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3978 }
3979
3980 return CMD_SUCCESS;
3981}
3982
3983/* Configure static BGP network. */
3984int
paulfd79ac92004-10-13 05:06:08 +00003985bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3986 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003987{
3988 int ret;
3989 struct bgp *bgp;
3990 struct prefix p;
3991 struct prefix_rd prd;
3992 struct bgp_node *prn;
3993 struct bgp_node *rn;
3994 struct bgp_table *table;
3995 struct bgp_static *bgp_static;
3996 u_char tag[3];
3997
3998 bgp = vty->index;
3999
4000 /* Convert IP prefix string to struct prefix. */
4001 ret = str2prefix (ip_str, &p);
4002 if (! ret)
4003 {
4004 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4005 return CMD_WARNING;
4006 }
4007 apply_mask (&p);
4008
4009 ret = str2prefix_rd (rd_str, &prd);
4010 if (! ret)
4011 {
4012 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4013 return CMD_WARNING;
4014 }
4015
4016 ret = str2tag (tag_str, tag);
4017 if (! ret)
4018 {
4019 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4020 return CMD_WARNING;
4021 }
4022
4023 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4024 (struct prefix *)&prd);
4025 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00004026 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00004027 else
4028 bgp_unlock_node (prn);
4029 table = prn->info;
4030
4031 rn = bgp_node_lookup (table, &p);
4032
4033 if (rn)
4034 {
4035 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4036
4037 bgp_static = rn->info;
4038 bgp_static_free (bgp_static);
4039 rn->info = NULL;
4040 bgp_unlock_node (rn);
4041 bgp_unlock_node (rn);
4042 }
4043 else
4044 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4045
4046 return CMD_SUCCESS;
4047}
David Lamparter6b0655a2014-06-04 06:53:35 +02004048
paul718e3742002-12-13 20:15:29 +00004049DEFUN (bgp_network,
4050 bgp_network_cmd,
4051 "network A.B.C.D/M",
4052 "Specify a network to announce via BGP\n"
4053 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4054{
4055 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004056 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004057}
4058
4059DEFUN (bgp_network_route_map,
4060 bgp_network_route_map_cmd,
4061 "network A.B.C.D/M route-map WORD",
4062 "Specify a network to announce via BGP\n"
4063 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4064 "Route-map to modify the attributes\n"
4065 "Name of the route map\n")
4066{
4067 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004068 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004069}
4070
4071DEFUN (bgp_network_backdoor,
4072 bgp_network_backdoor_cmd,
4073 "network A.B.C.D/M backdoor",
4074 "Specify a network to announce via BGP\n"
4075 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4076 "Specify a BGP backdoor route\n")
4077{
Paul Jakma41367172007-08-06 15:24:51 +00004078 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004079 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004080}
4081
4082DEFUN (bgp_network_mask,
4083 bgp_network_mask_cmd,
4084 "network A.B.C.D mask A.B.C.D",
4085 "Specify a network to announce via BGP\n"
4086 "Network number\n"
4087 "Network mask\n"
4088 "Network mask\n")
4089{
4090 int ret;
4091 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004092
paul718e3742002-12-13 20:15:29 +00004093 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4094 if (! ret)
4095 {
4096 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4097 return CMD_WARNING;
4098 }
4099
4100 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004101 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004102}
4103
4104DEFUN (bgp_network_mask_route_map,
4105 bgp_network_mask_route_map_cmd,
4106 "network A.B.C.D mask A.B.C.D route-map WORD",
4107 "Specify a network to announce via BGP\n"
4108 "Network number\n"
4109 "Network mask\n"
4110 "Network mask\n"
4111 "Route-map to modify the attributes\n"
4112 "Name of the route map\n")
4113{
4114 int ret;
4115 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004116
paul718e3742002-12-13 20:15:29 +00004117 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4118 if (! ret)
4119 {
4120 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4121 return CMD_WARNING;
4122 }
4123
4124 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004125 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004126}
4127
4128DEFUN (bgp_network_mask_backdoor,
4129 bgp_network_mask_backdoor_cmd,
4130 "network A.B.C.D mask A.B.C.D backdoor",
4131 "Specify a network to announce via BGP\n"
4132 "Network number\n"
4133 "Network mask\n"
4134 "Network mask\n"
4135 "Specify a BGP backdoor route\n")
4136{
4137 int ret;
4138 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004139
paul718e3742002-12-13 20:15:29 +00004140 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4141 if (! ret)
4142 {
4143 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4144 return CMD_WARNING;
4145 }
4146
Paul Jakma41367172007-08-06 15:24:51 +00004147 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004148 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004149}
4150
4151DEFUN (bgp_network_mask_natural,
4152 bgp_network_mask_natural_cmd,
4153 "network A.B.C.D",
4154 "Specify a network to announce via BGP\n"
4155 "Network number\n")
4156{
4157 int ret;
4158 char prefix_str[BUFSIZ];
4159
4160 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4161 if (! ret)
4162 {
4163 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4164 return CMD_WARNING;
4165 }
4166
4167 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004168 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004169}
4170
4171DEFUN (bgp_network_mask_natural_route_map,
4172 bgp_network_mask_natural_route_map_cmd,
4173 "network A.B.C.D route-map WORD",
4174 "Specify a network to announce via BGP\n"
4175 "Network number\n"
4176 "Route-map to modify the attributes\n"
4177 "Name of the route map\n")
4178{
4179 int ret;
4180 char prefix_str[BUFSIZ];
4181
4182 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4183 if (! ret)
4184 {
4185 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4186 return CMD_WARNING;
4187 }
4188
4189 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004190 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004191}
4192
4193DEFUN (bgp_network_mask_natural_backdoor,
4194 bgp_network_mask_natural_backdoor_cmd,
4195 "network A.B.C.D backdoor",
4196 "Specify a network to announce via BGP\n"
4197 "Network number\n"
4198 "Specify a BGP backdoor route\n")
4199{
4200 int ret;
4201 char prefix_str[BUFSIZ];
4202
4203 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4204 if (! ret)
4205 {
4206 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4207 return CMD_WARNING;
4208 }
4209
Paul Jakma41367172007-08-06 15:24:51 +00004210 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004211 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004212}
4213
4214DEFUN (no_bgp_network,
4215 no_bgp_network_cmd,
4216 "no network A.B.C.D/M",
4217 NO_STR
4218 "Specify a network to announce via BGP\n"
4219 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4220{
4221 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4222 bgp_node_safi (vty));
4223}
4224
4225ALIAS (no_bgp_network,
4226 no_bgp_network_route_map_cmd,
4227 "no network A.B.C.D/M route-map WORD",
4228 NO_STR
4229 "Specify a network to announce via BGP\n"
4230 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4231 "Route-map to modify the attributes\n"
4232 "Name of the route map\n")
4233
4234ALIAS (no_bgp_network,
4235 no_bgp_network_backdoor_cmd,
4236 "no network A.B.C.D/M backdoor",
4237 NO_STR
4238 "Specify a network to announce via BGP\n"
4239 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4240 "Specify a BGP backdoor route\n")
4241
4242DEFUN (no_bgp_network_mask,
4243 no_bgp_network_mask_cmd,
4244 "no network A.B.C.D mask A.B.C.D",
4245 NO_STR
4246 "Specify a network to announce via BGP\n"
4247 "Network number\n"
4248 "Network mask\n"
4249 "Network mask\n")
4250{
4251 int ret;
4252 char prefix_str[BUFSIZ];
4253
4254 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4255 if (! ret)
4256 {
4257 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4258 return CMD_WARNING;
4259 }
4260
4261 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4262 bgp_node_safi (vty));
4263}
4264
4265ALIAS (no_bgp_network_mask,
4266 no_bgp_network_mask_route_map_cmd,
4267 "no network A.B.C.D mask A.B.C.D route-map WORD",
4268 NO_STR
4269 "Specify a network to announce via BGP\n"
4270 "Network number\n"
4271 "Network mask\n"
4272 "Network mask\n"
4273 "Route-map to modify the attributes\n"
4274 "Name of the route map\n")
4275
4276ALIAS (no_bgp_network_mask,
4277 no_bgp_network_mask_backdoor_cmd,
4278 "no network A.B.C.D mask A.B.C.D backdoor",
4279 NO_STR
4280 "Specify a network to announce via BGP\n"
4281 "Network number\n"
4282 "Network mask\n"
4283 "Network mask\n"
4284 "Specify a BGP backdoor route\n")
4285
4286DEFUN (no_bgp_network_mask_natural,
4287 no_bgp_network_mask_natural_cmd,
4288 "no network A.B.C.D",
4289 NO_STR
4290 "Specify a network to announce via BGP\n"
4291 "Network number\n")
4292{
4293 int ret;
4294 char prefix_str[BUFSIZ];
4295
4296 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4297 if (! ret)
4298 {
4299 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4300 return CMD_WARNING;
4301 }
4302
4303 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4304 bgp_node_safi (vty));
4305}
4306
4307ALIAS (no_bgp_network_mask_natural,
4308 no_bgp_network_mask_natural_route_map_cmd,
4309 "no network A.B.C.D route-map WORD",
4310 NO_STR
4311 "Specify a network to announce via BGP\n"
4312 "Network number\n"
4313 "Route-map to modify the attributes\n"
4314 "Name of the route map\n")
4315
4316ALIAS (no_bgp_network_mask_natural,
4317 no_bgp_network_mask_natural_backdoor_cmd,
4318 "no network A.B.C.D backdoor",
4319 NO_STR
4320 "Specify a network to announce via BGP\n"
4321 "Network number\n"
4322 "Specify a BGP backdoor route\n")
4323
4324#ifdef HAVE_IPV6
4325DEFUN (ipv6_bgp_network,
4326 ipv6_bgp_network_cmd,
4327 "network X:X::X:X/M",
4328 "Specify a network to announce via BGP\n"
4329 "IPv6 prefix <network>/<length>\n")
4330{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304331 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004332 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004333}
4334
4335DEFUN (ipv6_bgp_network_route_map,
4336 ipv6_bgp_network_route_map_cmd,
4337 "network X:X::X:X/M route-map WORD",
4338 "Specify a network to announce via BGP\n"
4339 "IPv6 prefix <network>/<length>\n"
4340 "Route-map to modify the attributes\n"
4341 "Name of the route map\n")
4342{
4343 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004344 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004345}
4346
4347DEFUN (no_ipv6_bgp_network,
4348 no_ipv6_bgp_network_cmd,
4349 "no network X:X::X:X/M",
4350 NO_STR
4351 "Specify a network to announce via BGP\n"
4352 "IPv6 prefix <network>/<length>\n")
4353{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304354 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004355}
4356
4357ALIAS (no_ipv6_bgp_network,
4358 no_ipv6_bgp_network_route_map_cmd,
4359 "no network X:X::X:X/M route-map WORD",
4360 NO_STR
4361 "Specify a network to announce via BGP\n"
4362 "IPv6 prefix <network>/<length>\n"
4363 "Route-map to modify the attributes\n"
4364 "Name of the route map\n")
4365
4366ALIAS (ipv6_bgp_network,
4367 old_ipv6_bgp_network_cmd,
4368 "ipv6 bgp network X:X::X:X/M",
4369 IPV6_STR
4370 BGP_STR
4371 "Specify a network to announce via BGP\n"
4372 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4373
4374ALIAS (no_ipv6_bgp_network,
4375 old_no_ipv6_bgp_network_cmd,
4376 "no ipv6 bgp network X:X::X:X/M",
4377 NO_STR
4378 IPV6_STR
4379 BGP_STR
4380 "Specify a network to announce via BGP\n"
4381 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4382#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004383
4384/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4385ALIAS_DEPRECATED (bgp_network,
4386 bgp_network_ttl_cmd,
4387 "network A.B.C.D/M pathlimit <0-255>",
4388 "Specify a network to announce via BGP\n"
4389 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4390 "AS-Path hopcount limit attribute\n"
4391 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4392ALIAS_DEPRECATED (bgp_network_backdoor,
4393 bgp_network_backdoor_ttl_cmd,
4394 "network A.B.C.D/M backdoor pathlimit <0-255>",
4395 "Specify a network to announce via BGP\n"
4396 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4397 "Specify a BGP backdoor route\n"
4398 "AS-Path hopcount limit attribute\n"
4399 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4400ALIAS_DEPRECATED (bgp_network_mask,
4401 bgp_network_mask_ttl_cmd,
4402 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4403 "Specify a network to announce via BGP\n"
4404 "Network number\n"
4405 "Network mask\n"
4406 "Network mask\n"
4407 "AS-Path hopcount limit attribute\n"
4408 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4409ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4410 bgp_network_mask_backdoor_ttl_cmd,
4411 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4412 "Specify a network to announce via BGP\n"
4413 "Network number\n"
4414 "Network mask\n"
4415 "Network mask\n"
4416 "Specify a BGP backdoor route\n"
4417 "AS-Path hopcount limit attribute\n"
4418 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4419ALIAS_DEPRECATED (bgp_network_mask_natural,
4420 bgp_network_mask_natural_ttl_cmd,
4421 "network A.B.C.D pathlimit <0-255>",
4422 "Specify a network to announce via BGP\n"
4423 "Network number\n"
4424 "AS-Path hopcount limit attribute\n"
4425 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4426ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4427 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004428 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004429 "Specify a network to announce via BGP\n"
4430 "Network number\n"
4431 "Specify a BGP backdoor route\n"
4432 "AS-Path hopcount limit attribute\n"
4433 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4434ALIAS_DEPRECATED (no_bgp_network,
4435 no_bgp_network_ttl_cmd,
4436 "no network A.B.C.D/M pathlimit <0-255>",
4437 NO_STR
4438 "Specify a network to announce via BGP\n"
4439 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4440 "AS-Path hopcount limit attribute\n"
4441 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4442ALIAS_DEPRECATED (no_bgp_network,
4443 no_bgp_network_backdoor_ttl_cmd,
4444 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4445 NO_STR
4446 "Specify a network to announce via BGP\n"
4447 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4448 "Specify a BGP backdoor route\n"
4449 "AS-Path hopcount limit attribute\n"
4450 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4451ALIAS_DEPRECATED (no_bgp_network,
4452 no_bgp_network_mask_ttl_cmd,
4453 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4454 NO_STR
4455 "Specify a network to announce via BGP\n"
4456 "Network number\n"
4457 "Network mask\n"
4458 "Network mask\n"
4459 "AS-Path hopcount limit attribute\n"
4460 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4461ALIAS_DEPRECATED (no_bgp_network_mask,
4462 no_bgp_network_mask_backdoor_ttl_cmd,
4463 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4464 NO_STR
4465 "Specify a network to announce via BGP\n"
4466 "Network number\n"
4467 "Network mask\n"
4468 "Network mask\n"
4469 "Specify a BGP backdoor route\n"
4470 "AS-Path hopcount limit attribute\n"
4471 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4472ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4473 no_bgp_network_mask_natural_ttl_cmd,
4474 "no network A.B.C.D pathlimit <0-255>",
4475 NO_STR
4476 "Specify a network to announce via BGP\n"
4477 "Network number\n"
4478 "AS-Path hopcount limit attribute\n"
4479 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4480ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4481 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4482 "no network A.B.C.D backdoor pathlimit <0-255>",
4483 NO_STR
4484 "Specify a network to announce via BGP\n"
4485 "Network number\n"
4486 "Specify a BGP backdoor route\n"
4487 "AS-Path hopcount limit attribute\n"
4488 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004489#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004490ALIAS_DEPRECATED (ipv6_bgp_network,
4491 ipv6_bgp_network_ttl_cmd,
4492 "network X:X::X:X/M pathlimit <0-255>",
4493 "Specify a network to announce via BGP\n"
4494 "IPv6 prefix <network>/<length>\n"
4495 "AS-Path hopcount limit attribute\n"
4496 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4497ALIAS_DEPRECATED (no_ipv6_bgp_network,
4498 no_ipv6_bgp_network_ttl_cmd,
4499 "no network X:X::X:X/M pathlimit <0-255>",
4500 NO_STR
4501 "Specify a network to announce via BGP\n"
4502 "IPv6 prefix <network>/<length>\n"
4503 "AS-Path hopcount limit attribute\n"
4504 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004505#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02004506
paul718e3742002-12-13 20:15:29 +00004507/* Aggreagete address:
4508
4509 advertise-map Set condition to advertise attribute
4510 as-set Generate AS set path information
4511 attribute-map Set attributes of aggregate
4512 route-map Set parameters of aggregate
4513 summary-only Filter more specific routes from updates
4514 suppress-map Conditionally filter more specific routes from updates
4515 <cr>
4516 */
4517struct bgp_aggregate
4518{
4519 /* Summary-only flag. */
4520 u_char summary_only;
4521
4522 /* AS set generation. */
4523 u_char as_set;
4524
4525 /* Route-map for aggregated route. */
4526 struct route_map *map;
4527
4528 /* Suppress-count. */
4529 unsigned long count;
4530
4531 /* SAFI configuration. */
4532 safi_t safi;
4533};
4534
paul94f2b392005-06-28 12:44:16 +00004535static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004536bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004537{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004538 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004539}
4540
paul94f2b392005-06-28 12:44:16 +00004541static void
paul718e3742002-12-13 20:15:29 +00004542bgp_aggregate_free (struct bgp_aggregate *aggregate)
4543{
4544 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4545}
4546
paul94f2b392005-06-28 12:44:16 +00004547static void
paul718e3742002-12-13 20:15:29 +00004548bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4549 afi_t afi, safi_t safi, struct bgp_info *del,
4550 struct bgp_aggregate *aggregate)
4551{
4552 struct bgp_table *table;
4553 struct bgp_node *top;
4554 struct bgp_node *rn;
4555 u_char origin;
4556 struct aspath *aspath = NULL;
4557 struct aspath *asmerge = NULL;
4558 struct community *community = NULL;
4559 struct community *commerge = NULL;
paul718e3742002-12-13 20:15:29 +00004560 struct bgp_info *ri;
4561 struct bgp_info *new;
4562 int first = 1;
4563 unsigned long match = 0;
4564
paul718e3742002-12-13 20:15:29 +00004565 /* ORIGIN attribute: If at least one route among routes that are
4566 aggregated has ORIGIN with the value INCOMPLETE, then the
4567 aggregated route must have the ORIGIN attribute with the value
4568 INCOMPLETE. Otherwise, if at least one route among routes that
4569 are aggregated has ORIGIN with the value EGP, then the aggregated
4570 route must have the origin attribute with the value EGP. In all
4571 other case the value of the ORIGIN attribute of the aggregated
4572 route is INTERNAL. */
4573 origin = BGP_ORIGIN_IGP;
4574
4575 table = bgp->rib[afi][safi];
4576
4577 top = bgp_node_get (table, p);
4578 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4579 if (rn->p.prefixlen > p->prefixlen)
4580 {
4581 match = 0;
4582
4583 for (ri = rn->info; ri; ri = ri->next)
4584 {
4585 if (BGP_INFO_HOLDDOWN (ri))
4586 continue;
4587
4588 if (del && ri == del)
4589 continue;
4590
4591 if (! rinew && first)
Paul Jakma7aa9dce2014-09-19 14:42:23 +01004592 first = 0;
paul718e3742002-12-13 20:15:29 +00004593
4594#ifdef AGGREGATE_NEXTHOP_CHECK
4595 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4596 || ri->attr->med != med)
4597 {
4598 if (aspath)
4599 aspath_free (aspath);
4600 if (community)
4601 community_free (community);
4602 bgp_unlock_node (rn);
4603 bgp_unlock_node (top);
4604 return;
4605 }
4606#endif /* AGGREGATE_NEXTHOP_CHECK */
4607
4608 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4609 {
4610 if (aggregate->summary_only)
4611 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004612 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004613 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004614 match++;
4615 }
4616
4617 aggregate->count++;
4618
4619 if (aggregate->as_set)
4620 {
4621 if (origin < ri->attr->origin)
4622 origin = ri->attr->origin;
4623
4624 if (aspath)
4625 {
4626 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4627 aspath_free (aspath);
4628 aspath = asmerge;
4629 }
4630 else
4631 aspath = aspath_dup (ri->attr->aspath);
4632
4633 if (ri->attr->community)
4634 {
4635 if (community)
4636 {
4637 commerge = community_merge (community,
4638 ri->attr->community);
4639 community = community_uniq_sort (commerge);
4640 community_free (commerge);
4641 }
4642 else
4643 community = community_dup (ri->attr->community);
4644 }
4645 }
4646 }
4647 }
4648 if (match)
4649 bgp_process (bgp, rn, afi, safi);
4650 }
4651 bgp_unlock_node (top);
4652
4653 if (rinew)
4654 {
4655 aggregate->count++;
4656
4657 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004658 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004659
4660 if (aggregate->as_set)
4661 {
4662 if (origin < rinew->attr->origin)
4663 origin = rinew->attr->origin;
4664
4665 if (aspath)
4666 {
4667 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4668 aspath_free (aspath);
4669 aspath = asmerge;
4670 }
4671 else
4672 aspath = aspath_dup (rinew->attr->aspath);
4673
4674 if (rinew->attr->community)
4675 {
4676 if (community)
4677 {
4678 commerge = community_merge (community,
4679 rinew->attr->community);
4680 community = community_uniq_sort (commerge);
4681 community_free (commerge);
4682 }
4683 else
4684 community = community_dup (rinew->attr->community);
4685 }
4686 }
4687 }
4688
4689 if (aggregate->count > 0)
4690 {
4691 rn = bgp_node_get (table, p);
4692 new = bgp_info_new ();
4693 new->type = ZEBRA_ROUTE_BGP;
4694 new->sub_type = BGP_ROUTE_AGGREGATE;
4695 new->peer = bgp->peer_self;
4696 SET_FLAG (new->flags, BGP_INFO_VALID);
4697 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004698 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004699
4700 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004701 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004702 bgp_process (bgp, rn, afi, safi);
4703 }
4704 else
4705 {
4706 if (aspath)
4707 aspath_free (aspath);
4708 if (community)
4709 community_free (community);
4710 }
4711}
4712
4713void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4714 struct bgp_aggregate *);
4715
4716void
4717bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4718 struct bgp_info *ri, afi_t afi, safi_t safi)
4719{
4720 struct bgp_node *child;
4721 struct bgp_node *rn;
4722 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004723 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004724
4725 /* MPLS-VPN aggregation is not yet supported. */
4726 if (safi == SAFI_MPLS_VPN)
4727 return;
4728
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004729 table = bgp->aggregate[afi][safi];
4730
4731 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004732 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004733 return;
4734
paul718e3742002-12-13 20:15:29 +00004735 if (p->prefixlen == 0)
4736 return;
4737
4738 if (BGP_INFO_HOLDDOWN (ri))
4739 return;
4740
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004741 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004742
4743 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004744 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004745 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4746 {
4747 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004748 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004749 }
4750 bgp_unlock_node (child);
4751}
4752
4753void
4754bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4755 struct bgp_info *del, afi_t afi, safi_t safi)
4756{
4757 struct bgp_node *child;
4758 struct bgp_node *rn;
4759 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004760 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004761
4762 /* MPLS-VPN aggregation is not yet supported. */
4763 if (safi == SAFI_MPLS_VPN)
4764 return;
4765
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004766 table = bgp->aggregate[afi][safi];
4767
4768 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004769 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004770 return;
4771
paul718e3742002-12-13 20:15:29 +00004772 if (p->prefixlen == 0)
4773 return;
4774
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004775 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004776
4777 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004778 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004779 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4780 {
4781 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004782 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004783 }
4784 bgp_unlock_node (child);
4785}
4786
paul94f2b392005-06-28 12:44:16 +00004787static void
paul718e3742002-12-13 20:15:29 +00004788bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4789 struct bgp_aggregate *aggregate)
4790{
4791 struct bgp_table *table;
4792 struct bgp_node *top;
4793 struct bgp_node *rn;
4794 struct bgp_info *new;
4795 struct bgp_info *ri;
4796 unsigned long match;
4797 u_char origin = BGP_ORIGIN_IGP;
4798 struct aspath *aspath = NULL;
4799 struct aspath *asmerge = NULL;
4800 struct community *community = NULL;
4801 struct community *commerge = NULL;
4802
4803 table = bgp->rib[afi][safi];
4804
4805 /* Sanity check. */
4806 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4807 return;
4808 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4809 return;
4810
4811 /* If routes exists below this node, generate aggregate routes. */
4812 top = bgp_node_get (table, p);
4813 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4814 if (rn->p.prefixlen > p->prefixlen)
4815 {
4816 match = 0;
4817
4818 for (ri = rn->info; ri; ri = ri->next)
4819 {
4820 if (BGP_INFO_HOLDDOWN (ri))
4821 continue;
4822
4823 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4824 {
4825 /* summary-only aggregate route suppress aggregated
4826 route announcement. */
4827 if (aggregate->summary_only)
4828 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004829 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004830 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004831 match++;
4832 }
4833 /* as-set aggregate route generate origin, as path,
4834 community aggregation. */
4835 if (aggregate->as_set)
4836 {
4837 if (origin < ri->attr->origin)
4838 origin = ri->attr->origin;
4839
4840 if (aspath)
4841 {
4842 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4843 aspath_free (aspath);
4844 aspath = asmerge;
4845 }
4846 else
4847 aspath = aspath_dup (ri->attr->aspath);
4848
4849 if (ri->attr->community)
4850 {
4851 if (community)
4852 {
4853 commerge = community_merge (community,
4854 ri->attr->community);
4855 community = community_uniq_sort (commerge);
4856 community_free (commerge);
4857 }
4858 else
4859 community = community_dup (ri->attr->community);
4860 }
4861 }
4862 aggregate->count++;
4863 }
4864 }
4865
4866 /* If this node is suppressed, process the change. */
4867 if (match)
4868 bgp_process (bgp, rn, afi, safi);
4869 }
4870 bgp_unlock_node (top);
4871
4872 /* Add aggregate route to BGP table. */
4873 if (aggregate->count)
4874 {
4875 rn = bgp_node_get (table, p);
4876
4877 new = bgp_info_new ();
4878 new->type = ZEBRA_ROUTE_BGP;
4879 new->sub_type = BGP_ROUTE_AGGREGATE;
4880 new->peer = bgp->peer_self;
4881 SET_FLAG (new->flags, BGP_INFO_VALID);
4882 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004883 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004884
4885 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004886 bgp_unlock_node (rn);
4887
paul718e3742002-12-13 20:15:29 +00004888 /* Process change. */
4889 bgp_process (bgp, rn, afi, safi);
4890 }
4891}
4892
4893void
4894bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4895 safi_t safi, struct bgp_aggregate *aggregate)
4896{
4897 struct bgp_table *table;
4898 struct bgp_node *top;
4899 struct bgp_node *rn;
4900 struct bgp_info *ri;
4901 unsigned long match;
4902
4903 table = bgp->rib[afi][safi];
4904
4905 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4906 return;
4907 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4908 return;
4909
4910 /* If routes exists below this node, generate aggregate routes. */
4911 top = bgp_node_get (table, p);
4912 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4913 if (rn->p.prefixlen > p->prefixlen)
4914 {
4915 match = 0;
4916
4917 for (ri = rn->info; ri; ri = ri->next)
4918 {
4919 if (BGP_INFO_HOLDDOWN (ri))
4920 continue;
4921
4922 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4923 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004924 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004925 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004926 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004927
Paul Jakmafb982c22007-05-04 20:15:47 +00004928 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004929 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004930 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004931 match++;
4932 }
4933 }
4934 aggregate->count--;
4935 }
4936 }
4937
Paul Jakmafb982c22007-05-04 20:15:47 +00004938 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004939 if (match)
4940 bgp_process (bgp, rn, afi, safi);
4941 }
4942 bgp_unlock_node (top);
4943
4944 /* Delete aggregate route from BGP table. */
4945 rn = bgp_node_get (table, p);
4946
4947 for (ri = rn->info; ri; ri = ri->next)
4948 if (ri->peer == bgp->peer_self
4949 && ri->type == ZEBRA_ROUTE_BGP
4950 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4951 break;
4952
4953 /* Withdraw static BGP route from routing table. */
4954 if (ri)
4955 {
paul718e3742002-12-13 20:15:29 +00004956 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004957 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004958 }
4959
4960 /* Unlock bgp_node_lookup. */
4961 bgp_unlock_node (rn);
4962}
4963
4964/* Aggregate route attribute. */
4965#define AGGREGATE_SUMMARY_ONLY 1
4966#define AGGREGATE_AS_SET 1
4967
paul94f2b392005-06-28 12:44:16 +00004968static int
Robert Baysf6269b42010-08-05 10:26:28 -07004969bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4970 afi_t afi, safi_t safi)
4971{
4972 int ret;
4973 struct prefix p;
4974 struct bgp_node *rn;
4975 struct bgp *bgp;
4976 struct bgp_aggregate *aggregate;
4977
4978 /* Convert string to prefix structure. */
4979 ret = str2prefix (prefix_str, &p);
4980 if (!ret)
4981 {
4982 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4983 return CMD_WARNING;
4984 }
4985 apply_mask (&p);
4986
4987 /* Get BGP structure. */
4988 bgp = vty->index;
4989
4990 /* Old configuration check. */
4991 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4992 if (! rn)
4993 {
4994 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4995 VTY_NEWLINE);
4996 return CMD_WARNING;
4997 }
4998
4999 aggregate = rn->info;
5000 if (aggregate->safi & SAFI_UNICAST)
5001 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5002 if (aggregate->safi & SAFI_MULTICAST)
5003 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5004
5005 /* Unlock aggregate address configuration. */
5006 rn->info = NULL;
5007 bgp_aggregate_free (aggregate);
5008 bgp_unlock_node (rn);
5009 bgp_unlock_node (rn);
5010
5011 return CMD_SUCCESS;
5012}
5013
5014static int
5015bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00005016 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00005017 u_char summary_only, u_char as_set)
5018{
5019 int ret;
5020 struct prefix p;
5021 struct bgp_node *rn;
5022 struct bgp *bgp;
5023 struct bgp_aggregate *aggregate;
5024
5025 /* Convert string to prefix structure. */
5026 ret = str2prefix (prefix_str, &p);
5027 if (!ret)
5028 {
5029 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5030 return CMD_WARNING;
5031 }
5032 apply_mask (&p);
5033
5034 /* Get BGP structure. */
5035 bgp = vty->index;
5036
5037 /* Old configuration check. */
5038 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5039
5040 if (rn->info)
5041 {
5042 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005043 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005044 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5045 if (ret)
5046 {
Robert Bays368473f2010-08-05 10:26:29 -07005047 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5048 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005049 return CMD_WARNING;
5050 }
paul718e3742002-12-13 20:15:29 +00005051 }
5052
5053 /* Make aggregate address structure. */
5054 aggregate = bgp_aggregate_new ();
5055 aggregate->summary_only = summary_only;
5056 aggregate->as_set = as_set;
5057 aggregate->safi = safi;
5058 rn->info = aggregate;
5059
5060 /* Aggregate address insert into BGP routing table. */
5061 if (safi & SAFI_UNICAST)
5062 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5063 if (safi & SAFI_MULTICAST)
5064 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5065
5066 return CMD_SUCCESS;
5067}
5068
paul718e3742002-12-13 20:15:29 +00005069DEFUN (aggregate_address,
5070 aggregate_address_cmd,
5071 "aggregate-address A.B.C.D/M",
5072 "Configure BGP aggregate entries\n"
5073 "Aggregate prefix\n")
5074{
5075 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5076}
5077
5078DEFUN (aggregate_address_mask,
5079 aggregate_address_mask_cmd,
5080 "aggregate-address A.B.C.D A.B.C.D",
5081 "Configure BGP aggregate entries\n"
5082 "Aggregate address\n"
5083 "Aggregate mask\n")
5084{
5085 int ret;
5086 char prefix_str[BUFSIZ];
5087
5088 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5089
5090 if (! ret)
5091 {
5092 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5093 return CMD_WARNING;
5094 }
5095
5096 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5097 0, 0);
5098}
5099
5100DEFUN (aggregate_address_summary_only,
5101 aggregate_address_summary_only_cmd,
5102 "aggregate-address A.B.C.D/M summary-only",
5103 "Configure BGP aggregate entries\n"
5104 "Aggregate prefix\n"
5105 "Filter more specific routes from updates\n")
5106{
5107 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5108 AGGREGATE_SUMMARY_ONLY, 0);
5109}
5110
5111DEFUN (aggregate_address_mask_summary_only,
5112 aggregate_address_mask_summary_only_cmd,
5113 "aggregate-address A.B.C.D A.B.C.D summary-only",
5114 "Configure BGP aggregate entries\n"
5115 "Aggregate address\n"
5116 "Aggregate mask\n"
5117 "Filter more specific routes from updates\n")
5118{
5119 int ret;
5120 char prefix_str[BUFSIZ];
5121
5122 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5123
5124 if (! ret)
5125 {
5126 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5127 return CMD_WARNING;
5128 }
5129
5130 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5131 AGGREGATE_SUMMARY_ONLY, 0);
5132}
5133
5134DEFUN (aggregate_address_as_set,
5135 aggregate_address_as_set_cmd,
5136 "aggregate-address A.B.C.D/M as-set",
5137 "Configure BGP aggregate entries\n"
5138 "Aggregate prefix\n"
5139 "Generate AS set path information\n")
5140{
5141 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5142 0, AGGREGATE_AS_SET);
5143}
5144
5145DEFUN (aggregate_address_mask_as_set,
5146 aggregate_address_mask_as_set_cmd,
5147 "aggregate-address A.B.C.D A.B.C.D as-set",
5148 "Configure BGP aggregate entries\n"
5149 "Aggregate address\n"
5150 "Aggregate mask\n"
5151 "Generate AS set path information\n")
5152{
5153 int ret;
5154 char prefix_str[BUFSIZ];
5155
5156 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5157
5158 if (! ret)
5159 {
5160 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5161 return CMD_WARNING;
5162 }
5163
5164 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5165 0, AGGREGATE_AS_SET);
5166}
5167
5168
5169DEFUN (aggregate_address_as_set_summary,
5170 aggregate_address_as_set_summary_cmd,
5171 "aggregate-address A.B.C.D/M as-set summary-only",
5172 "Configure BGP aggregate entries\n"
5173 "Aggregate prefix\n"
5174 "Generate AS set path information\n"
5175 "Filter more specific routes from updates\n")
5176{
5177 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5178 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5179}
5180
5181ALIAS (aggregate_address_as_set_summary,
5182 aggregate_address_summary_as_set_cmd,
5183 "aggregate-address A.B.C.D/M summary-only as-set",
5184 "Configure BGP aggregate entries\n"
5185 "Aggregate prefix\n"
5186 "Filter more specific routes from updates\n"
5187 "Generate AS set path information\n")
5188
5189DEFUN (aggregate_address_mask_as_set_summary,
5190 aggregate_address_mask_as_set_summary_cmd,
5191 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5192 "Configure BGP aggregate entries\n"
5193 "Aggregate address\n"
5194 "Aggregate mask\n"
5195 "Generate AS set path information\n"
5196 "Filter more specific routes from updates\n")
5197{
5198 int ret;
5199 char prefix_str[BUFSIZ];
5200
5201 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5202
5203 if (! ret)
5204 {
5205 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5206 return CMD_WARNING;
5207 }
5208
5209 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5210 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5211}
5212
5213ALIAS (aggregate_address_mask_as_set_summary,
5214 aggregate_address_mask_summary_as_set_cmd,
5215 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5216 "Configure BGP aggregate entries\n"
5217 "Aggregate address\n"
5218 "Aggregate mask\n"
5219 "Filter more specific routes from updates\n"
5220 "Generate AS set path information\n")
5221
5222DEFUN (no_aggregate_address,
5223 no_aggregate_address_cmd,
5224 "no aggregate-address A.B.C.D/M",
5225 NO_STR
5226 "Configure BGP aggregate entries\n"
5227 "Aggregate prefix\n")
5228{
5229 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5230}
5231
5232ALIAS (no_aggregate_address,
5233 no_aggregate_address_summary_only_cmd,
5234 "no aggregate-address A.B.C.D/M summary-only",
5235 NO_STR
5236 "Configure BGP aggregate entries\n"
5237 "Aggregate prefix\n"
5238 "Filter more specific routes from updates\n")
5239
5240ALIAS (no_aggregate_address,
5241 no_aggregate_address_as_set_cmd,
5242 "no aggregate-address A.B.C.D/M as-set",
5243 NO_STR
5244 "Configure BGP aggregate entries\n"
5245 "Aggregate prefix\n"
5246 "Generate AS set path information\n")
5247
5248ALIAS (no_aggregate_address,
5249 no_aggregate_address_as_set_summary_cmd,
5250 "no aggregate-address A.B.C.D/M as-set summary-only",
5251 NO_STR
5252 "Configure BGP aggregate entries\n"
5253 "Aggregate prefix\n"
5254 "Generate AS set path information\n"
5255 "Filter more specific routes from updates\n")
5256
5257ALIAS (no_aggregate_address,
5258 no_aggregate_address_summary_as_set_cmd,
5259 "no aggregate-address A.B.C.D/M summary-only as-set",
5260 NO_STR
5261 "Configure BGP aggregate entries\n"
5262 "Aggregate prefix\n"
5263 "Filter more specific routes from updates\n"
5264 "Generate AS set path information\n")
5265
5266DEFUN (no_aggregate_address_mask,
5267 no_aggregate_address_mask_cmd,
5268 "no aggregate-address A.B.C.D A.B.C.D",
5269 NO_STR
5270 "Configure BGP aggregate entries\n"
5271 "Aggregate address\n"
5272 "Aggregate mask\n")
5273{
5274 int ret;
5275 char prefix_str[BUFSIZ];
5276
5277 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5278
5279 if (! ret)
5280 {
5281 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5282 return CMD_WARNING;
5283 }
5284
5285 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5286}
5287
5288ALIAS (no_aggregate_address_mask,
5289 no_aggregate_address_mask_summary_only_cmd,
5290 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5291 NO_STR
5292 "Configure BGP aggregate entries\n"
5293 "Aggregate address\n"
5294 "Aggregate mask\n"
5295 "Filter more specific routes from updates\n")
5296
5297ALIAS (no_aggregate_address_mask,
5298 no_aggregate_address_mask_as_set_cmd,
5299 "no aggregate-address A.B.C.D A.B.C.D as-set",
5300 NO_STR
5301 "Configure BGP aggregate entries\n"
5302 "Aggregate address\n"
5303 "Aggregate mask\n"
5304 "Generate AS set path information\n")
5305
5306ALIAS (no_aggregate_address_mask,
5307 no_aggregate_address_mask_as_set_summary_cmd,
5308 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5309 NO_STR
5310 "Configure BGP aggregate entries\n"
5311 "Aggregate address\n"
5312 "Aggregate mask\n"
5313 "Generate AS set path information\n"
5314 "Filter more specific routes from updates\n")
5315
5316ALIAS (no_aggregate_address_mask,
5317 no_aggregate_address_mask_summary_as_set_cmd,
5318 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5319 NO_STR
5320 "Configure BGP aggregate entries\n"
5321 "Aggregate address\n"
5322 "Aggregate mask\n"
5323 "Filter more specific routes from updates\n"
5324 "Generate AS set path information\n")
5325
5326#ifdef HAVE_IPV6
5327DEFUN (ipv6_aggregate_address,
5328 ipv6_aggregate_address_cmd,
5329 "aggregate-address X:X::X:X/M",
5330 "Configure BGP aggregate entries\n"
5331 "Aggregate prefix\n")
5332{
5333 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5334}
5335
5336DEFUN (ipv6_aggregate_address_summary_only,
5337 ipv6_aggregate_address_summary_only_cmd,
5338 "aggregate-address X:X::X:X/M summary-only",
5339 "Configure BGP aggregate entries\n"
5340 "Aggregate prefix\n"
5341 "Filter more specific routes from updates\n")
5342{
5343 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5344 AGGREGATE_SUMMARY_ONLY, 0);
5345}
5346
5347DEFUN (no_ipv6_aggregate_address,
5348 no_ipv6_aggregate_address_cmd,
5349 "no aggregate-address X:X::X:X/M",
5350 NO_STR
5351 "Configure BGP aggregate entries\n"
5352 "Aggregate prefix\n")
5353{
5354 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5355}
5356
5357DEFUN (no_ipv6_aggregate_address_summary_only,
5358 no_ipv6_aggregate_address_summary_only_cmd,
5359 "no aggregate-address X:X::X:X/M summary-only",
5360 NO_STR
5361 "Configure BGP aggregate entries\n"
5362 "Aggregate prefix\n"
5363 "Filter more specific routes from updates\n")
5364{
5365 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5366}
5367
5368ALIAS (ipv6_aggregate_address,
5369 old_ipv6_aggregate_address_cmd,
5370 "ipv6 bgp aggregate-address X:X::X:X/M",
5371 IPV6_STR
5372 BGP_STR
5373 "Configure BGP aggregate entries\n"
5374 "Aggregate prefix\n")
5375
5376ALIAS (ipv6_aggregate_address_summary_only,
5377 old_ipv6_aggregate_address_summary_only_cmd,
5378 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5379 IPV6_STR
5380 BGP_STR
5381 "Configure BGP aggregate entries\n"
5382 "Aggregate prefix\n"
5383 "Filter more specific routes from updates\n")
5384
5385ALIAS (no_ipv6_aggregate_address,
5386 old_no_ipv6_aggregate_address_cmd,
5387 "no ipv6 bgp aggregate-address X:X::X:X/M",
5388 NO_STR
5389 IPV6_STR
5390 BGP_STR
5391 "Configure BGP aggregate entries\n"
5392 "Aggregate prefix\n")
5393
5394ALIAS (no_ipv6_aggregate_address_summary_only,
5395 old_no_ipv6_aggregate_address_summary_only_cmd,
5396 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5397 NO_STR
5398 IPV6_STR
5399 BGP_STR
5400 "Configure BGP aggregate entries\n"
5401 "Aggregate prefix\n"
5402 "Filter more specific routes from updates\n")
5403#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02005404
paul718e3742002-12-13 20:15:29 +00005405/* Redistribute route treatment. */
5406void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005407bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5408 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005409 u_int32_t metric, u_char type)
5410{
5411 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005412 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005413 struct bgp_info *new;
5414 struct bgp_info *bi;
5415 struct bgp_info info;
5416 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005417 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005418 struct attr *new_attr;
5419 afi_t afi;
5420 int ret;
5421
5422 /* Make default attribute. */
5423 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5424 if (nexthop)
5425 attr.nexthop = *nexthop;
5426
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005427#ifdef HAVE_IPV6
5428 if (nexthop6)
5429 {
5430 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5431 extra->mp_nexthop_global = *nexthop6;
5432 extra->mp_nexthop_len = 16;
5433 }
5434#endif
5435
paul718e3742002-12-13 20:15:29 +00005436 attr.med = metric;
5437 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5438
paul1eb8ef22005-04-07 07:30:20 +00005439 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005440 {
5441 afi = family2afi (p->family);
5442
5443 if (bgp->redist[afi][type])
5444 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005445 struct attr attr_new;
5446 struct attr_extra extra_new;
5447
paul718e3742002-12-13 20:15:29 +00005448 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005449 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005450 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005451
5452 if (bgp->redist_metric_flag[afi][type])
5453 attr_new.med = bgp->redist_metric[afi][type];
5454
5455 /* Apply route-map. */
5456 if (bgp->rmap[afi][type].map)
5457 {
5458 info.peer = bgp->peer_self;
5459 info.attr = &attr_new;
5460
paulfee0f4c2004-09-13 05:12:46 +00005461 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5462
paul718e3742002-12-13 20:15:29 +00005463 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5464 &info);
paulfee0f4c2004-09-13 05:12:46 +00005465
5466 bgp->peer_self->rmap_type = 0;
5467
paul718e3742002-12-13 20:15:29 +00005468 if (ret == RMAP_DENYMATCH)
5469 {
5470 /* Free uninterned attribute. */
5471 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005472
paul718e3742002-12-13 20:15:29 +00005473 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005474 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005475 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005476 bgp_redistribute_delete (p, type);
5477 return;
5478 }
5479 }
5480
Paul Jakmafb982c22007-05-04 20:15:47 +00005481 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5482 afi, SAFI_UNICAST, p, NULL);
5483
paul718e3742002-12-13 20:15:29 +00005484 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005485
paul718e3742002-12-13 20:15:29 +00005486 for (bi = bn->info; bi; bi = bi->next)
5487 if (bi->peer == bgp->peer_self
5488 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5489 break;
5490
5491 if (bi)
5492 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005493 if (attrhash_cmp (bi->attr, new_attr) &&
5494 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005495 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005496 bgp_attr_unintern (&new_attr);
5497 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005498 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005499 bgp_unlock_node (bn);
5500 return;
5501 }
5502 else
5503 {
5504 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005505 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005506
5507 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005508 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5509 bgp_info_restore(bn, bi);
5510 else
5511 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005512 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005513 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005514 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005515
5516 /* Process change. */
5517 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5518 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5519 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005520 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005521 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005522 return;
5523 }
5524 }
5525
5526 new = bgp_info_new ();
5527 new->type = type;
5528 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5529 new->peer = bgp->peer_self;
5530 SET_FLAG (new->flags, BGP_INFO_VALID);
5531 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005532 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005533
5534 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5535 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005536 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005537 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5538 }
5539 }
5540
5541 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005542 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005543 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005544}
5545
5546void
5547bgp_redistribute_delete (struct prefix *p, u_char type)
5548{
5549 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005550 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005551 afi_t afi;
5552 struct bgp_node *rn;
5553 struct bgp_info *ri;
5554
paul1eb8ef22005-04-07 07:30:20 +00005555 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005556 {
5557 afi = family2afi (p->family);
5558
5559 if (bgp->redist[afi][type])
5560 {
paulfee0f4c2004-09-13 05:12:46 +00005561 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005562
5563 for (ri = rn->info; ri; ri = ri->next)
5564 if (ri->peer == bgp->peer_self
5565 && ri->type == type)
5566 break;
5567
5568 if (ri)
5569 {
5570 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005571 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005572 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005573 }
5574 bgp_unlock_node (rn);
5575 }
5576 }
5577}
5578
5579/* Withdraw specified route type's route. */
5580void
5581bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5582{
5583 struct bgp_node *rn;
5584 struct bgp_info *ri;
5585 struct bgp_table *table;
5586
5587 table = bgp->rib[afi][SAFI_UNICAST];
5588
5589 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5590 {
5591 for (ri = rn->info; ri; ri = ri->next)
5592 if (ri->peer == bgp->peer_self
5593 && ri->type == type)
5594 break;
5595
5596 if (ri)
5597 {
5598 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005599 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005600 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005601 }
5602 }
5603}
David Lamparter6b0655a2014-06-04 06:53:35 +02005604
paul718e3742002-12-13 20:15:29 +00005605/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005606static void
paul718e3742002-12-13 20:15:29 +00005607route_vty_out_route (struct prefix *p, struct vty *vty)
5608{
5609 int len;
5610 u_int32_t destination;
5611 char buf[BUFSIZ];
5612
5613 if (p->family == AF_INET)
5614 {
5615 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5616 destination = ntohl (p->u.prefix4.s_addr);
5617
5618 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5619 || (IN_CLASSB (destination) && p->prefixlen == 16)
5620 || (IN_CLASSA (destination) && p->prefixlen == 8)
5621 || p->u.prefix4.s_addr == 0)
5622 {
5623 /* When mask is natural, mask is not displayed. */
5624 }
5625 else
5626 len += vty_out (vty, "/%d", p->prefixlen);
5627 }
5628 else
5629 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5630 p->prefixlen);
5631
5632 len = 17 - len;
5633 if (len < 1)
5634 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5635 else
5636 vty_out (vty, "%*s", len, " ");
5637}
5638
paul718e3742002-12-13 20:15:29 +00005639enum bgp_display_type
5640{
5641 normal_list,
5642};
5643
paulb40d9392005-08-22 22:34:41 +00005644/* Print the short form route status for a bgp_info */
5645static void
5646route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005647{
paulb40d9392005-08-22 22:34:41 +00005648 /* Route status display. */
5649 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5650 vty_out (vty, "R");
5651 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005652 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005653 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005654 vty_out (vty, "s");
5655 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5656 vty_out (vty, "*");
5657 else
5658 vty_out (vty, " ");
5659
5660 /* Selected */
5661 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5662 vty_out (vty, "h");
5663 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5664 vty_out (vty, "d");
5665 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5666 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005667 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5668 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005669 else
5670 vty_out (vty, " ");
5671
5672 /* Internal route. */
5673 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5674 vty_out (vty, "i");
5675 else
paulb40d9392005-08-22 22:34:41 +00005676 vty_out (vty, " ");
5677}
5678
5679/* called from terminal list command */
5680void
5681route_vty_out (struct vty *vty, struct prefix *p,
5682 struct bgp_info *binfo, int display, safi_t safi)
5683{
5684 struct attr *attr;
5685
5686 /* short status lead text */
5687 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005688
5689 /* print prefix and mask */
5690 if (! display)
5691 route_vty_out_route (p, vty);
5692 else
5693 vty_out (vty, "%*s", 17, " ");
5694
5695 /* Print attribute */
5696 attr = binfo->attr;
5697 if (attr)
5698 {
5699 if (p->family == AF_INET)
5700 {
5701 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005702 vty_out (vty, "%-16s",
5703 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005704 else
5705 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5706 }
5707#ifdef HAVE_IPV6
5708 else if (p->family == AF_INET6)
5709 {
5710 int len;
5711 char buf[BUFSIZ];
5712
5713 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005714 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5715 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005716 len = 16 - len;
5717 if (len < 1)
5718 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5719 else
5720 vty_out (vty, "%*s", len, " ");
5721 }
5722#endif /* HAVE_IPV6 */
5723
5724 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005725 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005726 else
5727 vty_out (vty, " ");
5728
5729 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005730 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005731 else
5732 vty_out (vty, " ");
5733
Paul Jakmafb982c22007-05-04 20:15:47 +00005734 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005735
Paul Jakmab2518c12006-05-12 23:48:40 +00005736 /* Print aspath */
5737 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005738 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005739
Paul Jakmab2518c12006-05-12 23:48:40 +00005740 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005741 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005742 }
paul718e3742002-12-13 20:15:29 +00005743 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005744}
5745
5746/* called from terminal list command */
5747void
5748route_vty_out_tmp (struct vty *vty, struct prefix *p,
5749 struct attr *attr, safi_t safi)
5750{
5751 /* Route status display. */
5752 vty_out (vty, "*");
5753 vty_out (vty, ">");
5754 vty_out (vty, " ");
5755
5756 /* print prefix and mask */
5757 route_vty_out_route (p, vty);
5758
5759 /* Print attribute */
5760 if (attr)
5761 {
5762 if (p->family == AF_INET)
5763 {
5764 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005765 vty_out (vty, "%-16s",
5766 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005767 else
5768 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5769 }
5770#ifdef HAVE_IPV6
5771 else if (p->family == AF_INET6)
5772 {
5773 int len;
5774 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005775
5776 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005777
5778 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005779 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5780 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005781 len = 16 - len;
5782 if (len < 1)
5783 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5784 else
5785 vty_out (vty, "%*s", len, " ");
5786 }
5787#endif /* HAVE_IPV6 */
5788
5789 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005790 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005791 else
5792 vty_out (vty, " ");
5793
5794 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005795 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005796 else
5797 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005798
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005799 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005800
Paul Jakmab2518c12006-05-12 23:48:40 +00005801 /* Print aspath */
5802 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005803 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005804
Paul Jakmab2518c12006-05-12 23:48:40 +00005805 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005806 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005807 }
paul718e3742002-12-13 20:15:29 +00005808
5809 vty_out (vty, "%s", VTY_NEWLINE);
5810}
5811
ajs5a646652004-11-05 01:25:55 +00005812void
paul718e3742002-12-13 20:15:29 +00005813route_vty_out_tag (struct vty *vty, struct prefix *p,
5814 struct bgp_info *binfo, int display, safi_t safi)
5815{
5816 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005817 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005818
5819 if (!binfo->extra)
5820 return;
5821
paulb40d9392005-08-22 22:34:41 +00005822 /* short status lead text */
5823 route_vty_short_status_out (vty, binfo);
5824
paul718e3742002-12-13 20:15:29 +00005825 /* print prefix and mask */
5826 if (! display)
5827 route_vty_out_route (p, vty);
5828 else
5829 vty_out (vty, "%*s", 17, " ");
5830
5831 /* Print attribute */
5832 attr = binfo->attr;
5833 if (attr)
5834 {
5835 if (p->family == AF_INET)
5836 {
5837 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005838 vty_out (vty, "%-16s",
5839 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005840 else
5841 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5842 }
5843#ifdef HAVE_IPV6
5844 else if (p->family == AF_INET6)
5845 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005846 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005847 char buf[BUFSIZ];
5848 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005849 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005850 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005851 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5852 buf, BUFSIZ));
5853 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005854 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005855 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5856 buf, BUFSIZ),
5857 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5858 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005859
5860 }
5861#endif /* HAVE_IPV6 */
5862 }
5863
Paul Jakmafb982c22007-05-04 20:15:47 +00005864 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005865
5866 vty_out (vty, "notag/%d", label);
5867
5868 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005869}
5870
5871/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005872static void
paul718e3742002-12-13 20:15:29 +00005873damp_route_vty_out (struct vty *vty, struct prefix *p,
5874 struct bgp_info *binfo, int display, safi_t safi)
5875{
5876 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005877 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005878 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005879
paulb40d9392005-08-22 22:34:41 +00005880 /* short status lead text */
5881 route_vty_short_status_out (vty, binfo);
5882
paul718e3742002-12-13 20:15:29 +00005883 /* print prefix and mask */
5884 if (! display)
5885 route_vty_out_route (p, vty);
5886 else
5887 vty_out (vty, "%*s", 17, " ");
5888
5889 len = vty_out (vty, "%s", binfo->peer->host);
5890 len = 17 - len;
5891 if (len < 1)
5892 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5893 else
5894 vty_out (vty, "%*s", len, " ");
5895
Chris Caputo50aef6f2009-06-23 06:06:49 +00005896 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005897
5898 /* Print attribute */
5899 attr = binfo->attr;
5900 if (attr)
5901 {
5902 /* Print aspath */
5903 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005904 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005905
5906 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005907 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005908 }
5909 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005910}
5911
paul718e3742002-12-13 20:15:29 +00005912/* flap route */
ajs5a646652004-11-05 01:25:55 +00005913static void
paul718e3742002-12-13 20:15:29 +00005914flap_route_vty_out (struct vty *vty, struct prefix *p,
5915 struct bgp_info *binfo, int display, safi_t safi)
5916{
5917 struct attr *attr;
5918 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005919 char timebuf[BGP_UPTIME_LEN];
5920 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005921
5922 if (!binfo->extra)
5923 return;
5924
5925 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005926
paulb40d9392005-08-22 22:34:41 +00005927 /* short status lead text */
5928 route_vty_short_status_out (vty, binfo);
5929
paul718e3742002-12-13 20:15:29 +00005930 /* print prefix and mask */
5931 if (! display)
5932 route_vty_out_route (p, vty);
5933 else
5934 vty_out (vty, "%*s", 17, " ");
5935
5936 len = vty_out (vty, "%s", binfo->peer->host);
5937 len = 16 - len;
5938 if (len < 1)
5939 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5940 else
5941 vty_out (vty, "%*s", len, " ");
5942
5943 len = vty_out (vty, "%d", bdi->flap);
5944 len = 5 - len;
5945 if (len < 1)
5946 vty_out (vty, " ");
5947 else
5948 vty_out (vty, "%*s ", len, " ");
5949
5950 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5951 timebuf, BGP_UPTIME_LEN));
5952
5953 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5954 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005955 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005956 else
5957 vty_out (vty, "%*s ", 8, " ");
5958
5959 /* Print attribute */
5960 attr = binfo->attr;
5961 if (attr)
5962 {
5963 /* Print aspath */
5964 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005965 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005966
5967 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005968 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005969 }
5970 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005971}
5972
paul94f2b392005-06-28 12:44:16 +00005973static void
paul718e3742002-12-13 20:15:29 +00005974route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5975 struct bgp_info *binfo, afi_t afi, safi_t safi)
5976{
5977 char buf[INET6_ADDRSTRLEN];
5978 char buf1[BUFSIZ];
5979 struct attr *attr;
5980 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005981#ifdef HAVE_CLOCK_MONOTONIC
5982 time_t tbuf;
5983#endif
paul718e3742002-12-13 20:15:29 +00005984
5985 attr = binfo->attr;
5986
5987 if (attr)
5988 {
5989 /* Line1 display AS-path, Aggregator */
5990 if (attr->aspath)
5991 {
5992 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005993 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005994 vty_out (vty, "Local");
5995 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005996 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005997 }
5998
paulb40d9392005-08-22 22:34:41 +00005999 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6000 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00006001 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6002 vty_out (vty, ", (stale)");
6003 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006004 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006005 attr->extra->aggregator_as,
6006 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006007 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6008 vty_out (vty, ", (Received from a RR-client)");
6009 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6010 vty_out (vty, ", (Received from a RS-client)");
6011 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6012 vty_out (vty, ", (history entry)");
6013 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6014 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006015 vty_out (vty, "%s", VTY_NEWLINE);
6016
6017 /* Line2 display Next-hop, Neighbor, Router-id */
6018 if (p->family == AF_INET)
6019 {
6020 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006021 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006022 inet_ntoa (attr->nexthop));
6023 }
6024#ifdef HAVE_IPV6
6025 else
6026 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006027 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006028 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006029 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006030 buf, INET6_ADDRSTRLEN));
6031 }
6032#endif /* HAVE_IPV6 */
6033
6034 if (binfo->peer == bgp->peer_self)
6035 {
6036 vty_out (vty, " from %s ",
6037 p->family == AF_INET ? "0.0.0.0" : "::");
6038 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6039 }
6040 else
6041 {
6042 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6043 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006044 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006045 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006046 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006047 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006048 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006049 else
6050 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6051 }
6052 vty_out (vty, "%s", VTY_NEWLINE);
6053
6054#ifdef HAVE_IPV6
6055 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006056 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006057 {
6058 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006059 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006060 buf, INET6_ADDRSTRLEN),
6061 VTY_NEWLINE);
6062 }
6063#endif /* HAVE_IPV6 */
6064
6065 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6066 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6067
6068 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006069 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006070
6071 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006072 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006073 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006074 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006075
Paul Jakmafb982c22007-05-04 20:15:47 +00006076 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006077 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006078
6079 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6080 vty_out (vty, ", valid");
6081
6082 if (binfo->peer != bgp->peer_self)
6083 {
6084 if (binfo->peer->as == binfo->peer->local_as)
6085 vty_out (vty, ", internal");
6086 else
6087 vty_out (vty, ", %s",
6088 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6089 }
6090 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6091 vty_out (vty, ", aggregated, local");
6092 else if (binfo->type != ZEBRA_ROUTE_BGP)
6093 vty_out (vty, ", sourced");
6094 else
6095 vty_out (vty, ", sourced, local");
6096
6097 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6098 vty_out (vty, ", atomic-aggregate");
6099
Josh Baileyde8d5df2011-07-20 20:46:01 -07006100 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6101 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6102 bgp_info_mpath_count (binfo)))
6103 vty_out (vty, ", multipath");
6104
paul718e3742002-12-13 20:15:29 +00006105 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6106 vty_out (vty, ", best");
6107
6108 vty_out (vty, "%s", VTY_NEWLINE);
6109
6110 /* Line 4 display Community */
6111 if (attr->community)
6112 vty_out (vty, " Community: %s%s", attr->community->str,
6113 VTY_NEWLINE);
6114
6115 /* Line 5 display Extended-community */
6116 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006117 vty_out (vty, " Extended Community: %s%s",
6118 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006119
6120 /* Line 6 display Originator, Cluster-id */
6121 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6122 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6123 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006124 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006125 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006126 vty_out (vty, " Originator: %s",
6127 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006128
6129 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6130 {
6131 int i;
6132 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006133 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6134 vty_out (vty, "%s ",
6135 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006136 }
6137 vty_out (vty, "%s", VTY_NEWLINE);
6138 }
Paul Jakma41367172007-08-06 15:24:51 +00006139
Paul Jakmafb982c22007-05-04 20:15:47 +00006140 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006141 bgp_damp_info_vty (vty, binfo);
6142
6143 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006144#ifdef HAVE_CLOCK_MONOTONIC
6145 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006146 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006147#else
6148 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6149#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006150 }
6151 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006152}
6153
6154#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6155 "h history, * valid, > best, = multipath,%s"\
6156 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006157#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006158#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6159#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6160#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6161
6162enum bgp_show_type
6163{
6164 bgp_show_type_normal,
6165 bgp_show_type_regexp,
6166 bgp_show_type_prefix_list,
6167 bgp_show_type_filter_list,
6168 bgp_show_type_route_map,
6169 bgp_show_type_neighbor,
6170 bgp_show_type_cidr_only,
6171 bgp_show_type_prefix_longer,
6172 bgp_show_type_community_all,
6173 bgp_show_type_community,
6174 bgp_show_type_community_exact,
6175 bgp_show_type_community_list,
6176 bgp_show_type_community_list_exact,
6177 bgp_show_type_flap_statistics,
6178 bgp_show_type_flap_address,
6179 bgp_show_type_flap_prefix,
6180 bgp_show_type_flap_cidr_only,
6181 bgp_show_type_flap_regexp,
6182 bgp_show_type_flap_filter_list,
6183 bgp_show_type_flap_prefix_list,
6184 bgp_show_type_flap_prefix_longer,
6185 bgp_show_type_flap_route_map,
6186 bgp_show_type_flap_neighbor,
6187 bgp_show_type_dampend_paths,
6188 bgp_show_type_damp_neighbor
6189};
6190
ajs5a646652004-11-05 01:25:55 +00006191static int
paulfee0f4c2004-09-13 05:12:46 +00006192bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006193 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006194{
paul718e3742002-12-13 20:15:29 +00006195 struct bgp_info *ri;
6196 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006197 int header = 1;
paul718e3742002-12-13 20:15:29 +00006198 int display;
ajs5a646652004-11-05 01:25:55 +00006199 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006200
6201 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006202 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006203
paul718e3742002-12-13 20:15:29 +00006204 /* Start processing of routes. */
6205 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6206 if (rn->info != NULL)
6207 {
6208 display = 0;
6209
6210 for (ri = rn->info; ri; ri = ri->next)
6211 {
ajs5a646652004-11-05 01:25:55 +00006212 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006213 || type == bgp_show_type_flap_address
6214 || type == bgp_show_type_flap_prefix
6215 || type == bgp_show_type_flap_cidr_only
6216 || type == bgp_show_type_flap_regexp
6217 || type == bgp_show_type_flap_filter_list
6218 || type == bgp_show_type_flap_prefix_list
6219 || type == bgp_show_type_flap_prefix_longer
6220 || type == bgp_show_type_flap_route_map
6221 || type == bgp_show_type_flap_neighbor
6222 || type == bgp_show_type_dampend_paths
6223 || type == bgp_show_type_damp_neighbor)
6224 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006225 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006226 continue;
6227 }
6228 if (type == bgp_show_type_regexp
6229 || type == bgp_show_type_flap_regexp)
6230 {
ajs5a646652004-11-05 01:25:55 +00006231 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006232
6233 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6234 continue;
6235 }
6236 if (type == bgp_show_type_prefix_list
6237 || type == bgp_show_type_flap_prefix_list)
6238 {
ajs5a646652004-11-05 01:25:55 +00006239 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006240
6241 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6242 continue;
6243 }
6244 if (type == bgp_show_type_filter_list
6245 || type == bgp_show_type_flap_filter_list)
6246 {
ajs5a646652004-11-05 01:25:55 +00006247 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006248
6249 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6250 continue;
6251 }
6252 if (type == bgp_show_type_route_map
6253 || type == bgp_show_type_flap_route_map)
6254 {
ajs5a646652004-11-05 01:25:55 +00006255 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006256 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006257 struct attr dummy_attr;
6258 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006259 int ret;
6260
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006261 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006262 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006263
paul718e3742002-12-13 20:15:29 +00006264 binfo.peer = ri->peer;
6265 binfo.attr = &dummy_attr;
6266
6267 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006268 if (ret == RMAP_DENYMATCH)
6269 continue;
6270 }
6271 if (type == bgp_show_type_neighbor
6272 || type == bgp_show_type_flap_neighbor
6273 || type == bgp_show_type_damp_neighbor)
6274 {
ajs5a646652004-11-05 01:25:55 +00006275 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006276
6277 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6278 continue;
6279 }
6280 if (type == bgp_show_type_cidr_only
6281 || type == bgp_show_type_flap_cidr_only)
6282 {
6283 u_int32_t destination;
6284
6285 destination = ntohl (rn->p.u.prefix4.s_addr);
6286 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6287 continue;
6288 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6289 continue;
6290 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6291 continue;
6292 }
6293 if (type == bgp_show_type_prefix_longer
6294 || type == bgp_show_type_flap_prefix_longer)
6295 {
ajs5a646652004-11-05 01:25:55 +00006296 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006297
6298 if (! prefix_match (p, &rn->p))
6299 continue;
6300 }
6301 if (type == bgp_show_type_community_all)
6302 {
6303 if (! ri->attr->community)
6304 continue;
6305 }
6306 if (type == bgp_show_type_community)
6307 {
ajs5a646652004-11-05 01:25:55 +00006308 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006309
6310 if (! ri->attr->community ||
6311 ! community_match (ri->attr->community, com))
6312 continue;
6313 }
6314 if (type == bgp_show_type_community_exact)
6315 {
ajs5a646652004-11-05 01:25:55 +00006316 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006317
6318 if (! ri->attr->community ||
6319 ! community_cmp (ri->attr->community, com))
6320 continue;
6321 }
6322 if (type == bgp_show_type_community_list)
6323 {
ajs5a646652004-11-05 01:25:55 +00006324 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006325
6326 if (! community_list_match (ri->attr->community, list))
6327 continue;
6328 }
6329 if (type == bgp_show_type_community_list_exact)
6330 {
ajs5a646652004-11-05 01:25:55 +00006331 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006332
6333 if (! community_list_exact_match (ri->attr->community, list))
6334 continue;
6335 }
6336 if (type == bgp_show_type_flap_address
6337 || type == bgp_show_type_flap_prefix)
6338 {
ajs5a646652004-11-05 01:25:55 +00006339 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006340
6341 if (! prefix_match (&rn->p, p))
6342 continue;
6343
6344 if (type == bgp_show_type_flap_prefix)
6345 if (p->prefixlen != rn->p.prefixlen)
6346 continue;
6347 }
6348 if (type == bgp_show_type_dampend_paths
6349 || type == bgp_show_type_damp_neighbor)
6350 {
6351 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6352 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6353 continue;
6354 }
6355
6356 if (header)
6357 {
hasso93406d82005-02-02 14:40:33 +00006358 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6359 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6360 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006361 if (type == bgp_show_type_dampend_paths
6362 || type == bgp_show_type_damp_neighbor)
6363 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6364 else if (type == bgp_show_type_flap_statistics
6365 || type == bgp_show_type_flap_address
6366 || type == bgp_show_type_flap_prefix
6367 || type == bgp_show_type_flap_cidr_only
6368 || type == bgp_show_type_flap_regexp
6369 || type == bgp_show_type_flap_filter_list
6370 || type == bgp_show_type_flap_prefix_list
6371 || type == bgp_show_type_flap_prefix_longer
6372 || type == bgp_show_type_flap_route_map
6373 || type == bgp_show_type_flap_neighbor)
6374 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6375 else
6376 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006377 header = 0;
6378 }
6379
6380 if (type == bgp_show_type_dampend_paths
6381 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006382 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006383 else if (type == bgp_show_type_flap_statistics
6384 || type == bgp_show_type_flap_address
6385 || type == bgp_show_type_flap_prefix
6386 || type == bgp_show_type_flap_cidr_only
6387 || type == bgp_show_type_flap_regexp
6388 || type == bgp_show_type_flap_filter_list
6389 || type == bgp_show_type_flap_prefix_list
6390 || type == bgp_show_type_flap_prefix_longer
6391 || type == bgp_show_type_flap_route_map
6392 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006393 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006394 else
ajs5a646652004-11-05 01:25:55 +00006395 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006396 display++;
6397 }
6398 if (display)
ajs5a646652004-11-05 01:25:55 +00006399 output_count++;
paul718e3742002-12-13 20:15:29 +00006400 }
6401
6402 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006403 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006404 {
6405 if (type == bgp_show_type_normal)
6406 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6407 }
6408 else
6409 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006410 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006411
6412 return CMD_SUCCESS;
6413}
6414
ajs5a646652004-11-05 01:25:55 +00006415static int
paulfee0f4c2004-09-13 05:12:46 +00006416bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006417 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006418{
6419 struct bgp_table *table;
6420
6421 if (bgp == NULL) {
6422 bgp = bgp_get_default ();
6423 }
6424
6425 if (bgp == NULL)
6426 {
6427 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6428 return CMD_WARNING;
6429 }
6430
6431
6432 table = bgp->rib[afi][safi];
6433
ajs5a646652004-11-05 01:25:55 +00006434 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006435}
6436
paul718e3742002-12-13 20:15:29 +00006437/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006438static void
paul718e3742002-12-13 20:15:29 +00006439route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6440 struct bgp_node *rn,
6441 struct prefix_rd *prd, afi_t afi, safi_t safi)
6442{
6443 struct bgp_info *ri;
6444 struct prefix *p;
6445 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006446 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006447 char buf1[INET6_ADDRSTRLEN];
6448 char buf2[INET6_ADDRSTRLEN];
6449 int count = 0;
6450 int best = 0;
6451 int suppress = 0;
6452 int no_export = 0;
6453 int no_advertise = 0;
6454 int local_as = 0;
6455 int first = 0;
6456
6457 p = &rn->p;
6458 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6459 (safi == SAFI_MPLS_VPN ?
6460 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6461 safi == SAFI_MPLS_VPN ? ":" : "",
6462 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6463 p->prefixlen, VTY_NEWLINE);
6464
6465 for (ri = rn->info; ri; ri = ri->next)
6466 {
6467 count++;
6468 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6469 {
6470 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006471 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006472 suppress = 1;
6473 if (ri->attr->community != NULL)
6474 {
6475 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6476 no_advertise = 1;
6477 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6478 no_export = 1;
6479 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6480 local_as = 1;
6481 }
6482 }
6483 }
6484
6485 vty_out (vty, "Paths: (%d available", count);
6486 if (best)
6487 {
6488 vty_out (vty, ", best #%d", best);
6489 if (safi == SAFI_UNICAST)
6490 vty_out (vty, ", table Default-IP-Routing-Table");
6491 }
6492 else
6493 vty_out (vty, ", no best path");
6494 if (no_advertise)
6495 vty_out (vty, ", not advertised to any peer");
6496 else if (no_export)
6497 vty_out (vty, ", not advertised to EBGP peer");
6498 else if (local_as)
6499 vty_out (vty, ", not advertised outside local AS");
6500 if (suppress)
6501 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6502 vty_out (vty, ")%s", VTY_NEWLINE);
6503
6504 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006505 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006506 {
6507 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6508 {
6509 if (! first)
6510 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6511 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6512 first = 1;
6513 }
6514 }
6515 if (! first)
6516 vty_out (vty, " Not advertised to any peer");
6517 vty_out (vty, "%s", VTY_NEWLINE);
6518}
6519
6520/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006521static int
paulfee0f4c2004-09-13 05:12:46 +00006522bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006523 struct bgp_table *rib, const char *ip_str,
6524 afi_t afi, safi_t safi, struct prefix_rd *prd,
6525 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006526{
6527 int ret;
6528 int header;
6529 int display = 0;
6530 struct prefix match;
6531 struct bgp_node *rn;
6532 struct bgp_node *rm;
6533 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006534 struct bgp_table *table;
6535
paul718e3742002-12-13 20:15:29 +00006536 /* Check IP address argument. */
6537 ret = str2prefix (ip_str, &match);
6538 if (! ret)
6539 {
6540 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6541 return CMD_WARNING;
6542 }
6543
6544 match.family = afi2family (afi);
6545
6546 if (safi == SAFI_MPLS_VPN)
6547 {
paulfee0f4c2004-09-13 05:12:46 +00006548 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006549 {
6550 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6551 continue;
6552
6553 if ((table = rn->info) != NULL)
6554 {
6555 header = 1;
6556
6557 if ((rm = bgp_node_match (table, &match)) != NULL)
6558 {
6559 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006560 {
6561 bgp_unlock_node (rm);
6562 continue;
6563 }
paul718e3742002-12-13 20:15:29 +00006564
6565 for (ri = rm->info; ri; ri = ri->next)
6566 {
6567 if (header)
6568 {
6569 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6570 AFI_IP, SAFI_MPLS_VPN);
6571
6572 header = 0;
6573 }
6574 display++;
6575 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6576 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006577
6578 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006579 }
6580 }
6581 }
6582 }
6583 else
6584 {
6585 header = 1;
6586
paulfee0f4c2004-09-13 05:12:46 +00006587 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006588 {
6589 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6590 {
6591 for (ri = rn->info; ri; ri = ri->next)
6592 {
6593 if (header)
6594 {
6595 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6596 header = 0;
6597 }
6598 display++;
6599 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6600 }
6601 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006602
6603 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006604 }
6605 }
6606
6607 if (! display)
6608 {
6609 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6610 return CMD_WARNING;
6611 }
6612
6613 return CMD_SUCCESS;
6614}
6615
paulfee0f4c2004-09-13 05:12:46 +00006616/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006617static int
paulfd79ac92004-10-13 05:06:08 +00006618bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006619 afi_t afi, safi_t safi, struct prefix_rd *prd,
6620 int prefix_check)
6621{
6622 struct bgp *bgp;
6623
6624 /* BGP structure lookup. */
6625 if (view_name)
6626 {
6627 bgp = bgp_lookup_by_name (view_name);
6628 if (bgp == NULL)
6629 {
6630 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6631 return CMD_WARNING;
6632 }
6633 }
6634 else
6635 {
6636 bgp = bgp_get_default ();
6637 if (bgp == NULL)
6638 {
6639 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6640 return CMD_WARNING;
6641 }
6642 }
6643
6644 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6645 afi, safi, prd, prefix_check);
6646}
6647
paul718e3742002-12-13 20:15:29 +00006648/* BGP route print out function. */
6649DEFUN (show_ip_bgp,
6650 show_ip_bgp_cmd,
6651 "show ip bgp",
6652 SHOW_STR
6653 IP_STR
6654 BGP_STR)
6655{
ajs5a646652004-11-05 01:25:55 +00006656 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006657}
6658
6659DEFUN (show_ip_bgp_ipv4,
6660 show_ip_bgp_ipv4_cmd,
6661 "show ip bgp ipv4 (unicast|multicast)",
6662 SHOW_STR
6663 IP_STR
6664 BGP_STR
6665 "Address family\n"
6666 "Address Family modifier\n"
6667 "Address Family modifier\n")
6668{
6669 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006670 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6671 NULL);
paul718e3742002-12-13 20:15:29 +00006672
ajs5a646652004-11-05 01:25:55 +00006673 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006674}
6675
Michael Lambert95cbbd22010-07-23 14:43:04 -04006676ALIAS (show_ip_bgp_ipv4,
6677 show_bgp_ipv4_safi_cmd,
6678 "show bgp ipv4 (unicast|multicast)",
6679 SHOW_STR
6680 BGP_STR
6681 "Address family\n"
6682 "Address Family modifier\n"
6683 "Address Family modifier\n")
6684
paul718e3742002-12-13 20:15:29 +00006685DEFUN (show_ip_bgp_route,
6686 show_ip_bgp_route_cmd,
6687 "show ip bgp A.B.C.D",
6688 SHOW_STR
6689 IP_STR
6690 BGP_STR
6691 "Network in the BGP routing table to display\n")
6692{
6693 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6694}
6695
6696DEFUN (show_ip_bgp_ipv4_route,
6697 show_ip_bgp_ipv4_route_cmd,
6698 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6699 SHOW_STR
6700 IP_STR
6701 BGP_STR
6702 "Address family\n"
6703 "Address Family modifier\n"
6704 "Address Family modifier\n"
6705 "Network in the BGP routing table to display\n")
6706{
6707 if (strncmp (argv[0], "m", 1) == 0)
6708 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6709
6710 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6711}
6712
Michael Lambert95cbbd22010-07-23 14:43:04 -04006713ALIAS (show_ip_bgp_ipv4_route,
6714 show_bgp_ipv4_safi_route_cmd,
6715 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6716 SHOW_STR
6717 BGP_STR
6718 "Address family\n"
6719 "Address Family modifier\n"
6720 "Address Family modifier\n"
6721 "Network in the BGP routing table to display\n")
6722
paul718e3742002-12-13 20:15:29 +00006723DEFUN (show_ip_bgp_vpnv4_all_route,
6724 show_ip_bgp_vpnv4_all_route_cmd,
6725 "show ip bgp vpnv4 all A.B.C.D",
6726 SHOW_STR
6727 IP_STR
6728 BGP_STR
6729 "Display VPNv4 NLRI specific information\n"
6730 "Display information about all VPNv4 NLRIs\n"
6731 "Network in the BGP routing table to display\n")
6732{
6733 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6734}
6735
6736DEFUN (show_ip_bgp_vpnv4_rd_route,
6737 show_ip_bgp_vpnv4_rd_route_cmd,
6738 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6739 SHOW_STR
6740 IP_STR
6741 BGP_STR
6742 "Display VPNv4 NLRI specific information\n"
6743 "Display information for a route distinguisher\n"
6744 "VPN Route Distinguisher\n"
6745 "Network in the BGP routing table to display\n")
6746{
6747 int ret;
6748 struct prefix_rd prd;
6749
6750 ret = str2prefix_rd (argv[0], &prd);
6751 if (! ret)
6752 {
6753 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6754 return CMD_WARNING;
6755 }
6756 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6757}
6758
6759DEFUN (show_ip_bgp_prefix,
6760 show_ip_bgp_prefix_cmd,
6761 "show ip bgp A.B.C.D/M",
6762 SHOW_STR
6763 IP_STR
6764 BGP_STR
6765 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6766{
6767 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6768}
6769
6770DEFUN (show_ip_bgp_ipv4_prefix,
6771 show_ip_bgp_ipv4_prefix_cmd,
6772 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6773 SHOW_STR
6774 IP_STR
6775 BGP_STR
6776 "Address family\n"
6777 "Address Family modifier\n"
6778 "Address Family modifier\n"
6779 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6780{
6781 if (strncmp (argv[0], "m", 1) == 0)
6782 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6783
6784 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6785}
6786
Michael Lambert95cbbd22010-07-23 14:43:04 -04006787ALIAS (show_ip_bgp_ipv4_prefix,
6788 show_bgp_ipv4_safi_prefix_cmd,
6789 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6790 SHOW_STR
6791 BGP_STR
6792 "Address family\n"
6793 "Address Family modifier\n"
6794 "Address Family modifier\n"
6795 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6796
paul718e3742002-12-13 20:15:29 +00006797DEFUN (show_ip_bgp_vpnv4_all_prefix,
6798 show_ip_bgp_vpnv4_all_prefix_cmd,
6799 "show ip bgp vpnv4 all A.B.C.D/M",
6800 SHOW_STR
6801 IP_STR
6802 BGP_STR
6803 "Display VPNv4 NLRI specific information\n"
6804 "Display information about all VPNv4 NLRIs\n"
6805 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6806{
6807 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6808}
6809
6810DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6811 show_ip_bgp_vpnv4_rd_prefix_cmd,
6812 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6813 SHOW_STR
6814 IP_STR
6815 BGP_STR
6816 "Display VPNv4 NLRI specific information\n"
6817 "Display information for a route distinguisher\n"
6818 "VPN Route Distinguisher\n"
6819 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6820{
6821 int ret;
6822 struct prefix_rd prd;
6823
6824 ret = str2prefix_rd (argv[0], &prd);
6825 if (! ret)
6826 {
6827 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6828 return CMD_WARNING;
6829 }
6830 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6831}
6832
6833DEFUN (show_ip_bgp_view,
6834 show_ip_bgp_view_cmd,
6835 "show ip bgp view WORD",
6836 SHOW_STR
6837 IP_STR
6838 BGP_STR
6839 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006840 "View name\n")
paul718e3742002-12-13 20:15:29 +00006841{
paulbb46e942003-10-24 19:02:03 +00006842 struct bgp *bgp;
6843
6844 /* BGP structure lookup. */
6845 bgp = bgp_lookup_by_name (argv[0]);
6846 if (bgp == NULL)
6847 {
6848 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6849 return CMD_WARNING;
6850 }
6851
ajs5a646652004-11-05 01:25:55 +00006852 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006853}
6854
6855DEFUN (show_ip_bgp_view_route,
6856 show_ip_bgp_view_route_cmd,
6857 "show ip bgp view WORD A.B.C.D",
6858 SHOW_STR
6859 IP_STR
6860 BGP_STR
6861 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006862 "View name\n"
paul718e3742002-12-13 20:15:29 +00006863 "Network in the BGP routing table to display\n")
6864{
6865 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6866}
6867
6868DEFUN (show_ip_bgp_view_prefix,
6869 show_ip_bgp_view_prefix_cmd,
6870 "show ip bgp view WORD A.B.C.D/M",
6871 SHOW_STR
6872 IP_STR
6873 BGP_STR
6874 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006875 "View name\n"
paul718e3742002-12-13 20:15:29 +00006876 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6877{
6878 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6879}
6880
6881#ifdef HAVE_IPV6
6882DEFUN (show_bgp,
6883 show_bgp_cmd,
6884 "show bgp",
6885 SHOW_STR
6886 BGP_STR)
6887{
ajs5a646652004-11-05 01:25:55 +00006888 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6889 NULL);
paul718e3742002-12-13 20:15:29 +00006890}
6891
6892ALIAS (show_bgp,
6893 show_bgp_ipv6_cmd,
6894 "show bgp ipv6",
6895 SHOW_STR
6896 BGP_STR
6897 "Address family\n")
6898
Michael Lambert95cbbd22010-07-23 14:43:04 -04006899DEFUN (show_bgp_ipv6_safi,
6900 show_bgp_ipv6_safi_cmd,
6901 "show bgp ipv6 (unicast|multicast)",
6902 SHOW_STR
6903 BGP_STR
6904 "Address family\n"
6905 "Address Family modifier\n"
6906 "Address Family modifier\n")
6907{
6908 if (strncmp (argv[0], "m", 1) == 0)
6909 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6910 NULL);
6911
6912 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6913}
6914
paul718e3742002-12-13 20:15:29 +00006915/* old command */
6916DEFUN (show_ipv6_bgp,
6917 show_ipv6_bgp_cmd,
6918 "show ipv6 bgp",
6919 SHOW_STR
6920 IP_STR
6921 BGP_STR)
6922{
ajs5a646652004-11-05 01:25:55 +00006923 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6924 NULL);
paul718e3742002-12-13 20:15:29 +00006925}
6926
6927DEFUN (show_bgp_route,
6928 show_bgp_route_cmd,
6929 "show bgp X:X::X:X",
6930 SHOW_STR
6931 BGP_STR
6932 "Network in the BGP routing table to display\n")
6933{
6934 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6935}
6936
6937ALIAS (show_bgp_route,
6938 show_bgp_ipv6_route_cmd,
6939 "show bgp ipv6 X:X::X:X",
6940 SHOW_STR
6941 BGP_STR
6942 "Address family\n"
6943 "Network in the BGP routing table to display\n")
6944
Michael Lambert95cbbd22010-07-23 14:43:04 -04006945DEFUN (show_bgp_ipv6_safi_route,
6946 show_bgp_ipv6_safi_route_cmd,
6947 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6948 SHOW_STR
6949 BGP_STR
6950 "Address family\n"
6951 "Address Family modifier\n"
6952 "Address Family modifier\n"
6953 "Network in the BGP routing table to display\n")
6954{
6955 if (strncmp (argv[0], "m", 1) == 0)
6956 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6957
6958 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6959}
6960
paul718e3742002-12-13 20:15:29 +00006961/* old command */
6962DEFUN (show_ipv6_bgp_route,
6963 show_ipv6_bgp_route_cmd,
6964 "show ipv6 bgp X:X::X:X",
6965 SHOW_STR
6966 IP_STR
6967 BGP_STR
6968 "Network in the BGP routing table to display\n")
6969{
6970 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6971}
6972
6973DEFUN (show_bgp_prefix,
6974 show_bgp_prefix_cmd,
6975 "show bgp X:X::X:X/M",
6976 SHOW_STR
6977 BGP_STR
6978 "IPv6 prefix <network>/<length>\n")
6979{
6980 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6981}
6982
6983ALIAS (show_bgp_prefix,
6984 show_bgp_ipv6_prefix_cmd,
6985 "show bgp ipv6 X:X::X:X/M",
6986 SHOW_STR
6987 BGP_STR
6988 "Address family\n"
6989 "IPv6 prefix <network>/<length>\n")
6990
Michael Lambert95cbbd22010-07-23 14:43:04 -04006991DEFUN (show_bgp_ipv6_safi_prefix,
6992 show_bgp_ipv6_safi_prefix_cmd,
6993 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6994 SHOW_STR
6995 BGP_STR
6996 "Address family\n"
6997 "Address Family modifier\n"
6998 "Address Family modifier\n"
6999 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7000{
7001 if (strncmp (argv[0], "m", 1) == 0)
7002 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7003
7004 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7005}
7006
paul718e3742002-12-13 20:15:29 +00007007/* old command */
7008DEFUN (show_ipv6_bgp_prefix,
7009 show_ipv6_bgp_prefix_cmd,
7010 "show ipv6 bgp X:X::X:X/M",
7011 SHOW_STR
7012 IP_STR
7013 BGP_STR
7014 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7015{
7016 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7017}
7018
paulbb46e942003-10-24 19:02:03 +00007019DEFUN (show_bgp_view,
7020 show_bgp_view_cmd,
7021 "show bgp view WORD",
7022 SHOW_STR
7023 BGP_STR
7024 "BGP view\n"
7025 "View name\n")
7026{
7027 struct bgp *bgp;
7028
7029 /* BGP structure lookup. */
7030 bgp = bgp_lookup_by_name (argv[0]);
7031 if (bgp == NULL)
7032 {
7033 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7034 return CMD_WARNING;
7035 }
7036
ajs5a646652004-11-05 01:25:55 +00007037 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007038}
7039
7040ALIAS (show_bgp_view,
7041 show_bgp_view_ipv6_cmd,
7042 "show bgp view WORD ipv6",
7043 SHOW_STR
7044 BGP_STR
7045 "BGP view\n"
7046 "View name\n"
7047 "Address family\n")
7048
7049DEFUN (show_bgp_view_route,
7050 show_bgp_view_route_cmd,
7051 "show bgp view WORD X:X::X:X",
7052 SHOW_STR
7053 BGP_STR
7054 "BGP view\n"
7055 "View name\n"
7056 "Network in the BGP routing table to display\n")
7057{
7058 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7059}
7060
7061ALIAS (show_bgp_view_route,
7062 show_bgp_view_ipv6_route_cmd,
7063 "show bgp view WORD ipv6 X:X::X:X",
7064 SHOW_STR
7065 BGP_STR
7066 "BGP view\n"
7067 "View name\n"
7068 "Address family\n"
7069 "Network in the BGP routing table to display\n")
7070
7071DEFUN (show_bgp_view_prefix,
7072 show_bgp_view_prefix_cmd,
7073 "show bgp view WORD X:X::X:X/M",
7074 SHOW_STR
7075 BGP_STR
7076 "BGP view\n"
7077 "View name\n"
7078 "IPv6 prefix <network>/<length>\n")
7079{
7080 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7081}
7082
7083ALIAS (show_bgp_view_prefix,
7084 show_bgp_view_ipv6_prefix_cmd,
7085 "show bgp view WORD ipv6 X:X::X:X/M",
7086 SHOW_STR
7087 BGP_STR
7088 "BGP view\n"
7089 "View name\n"
7090 "Address family\n"
7091 "IPv6 prefix <network>/<length>\n")
7092
paul718e3742002-12-13 20:15:29 +00007093/* old command */
7094DEFUN (show_ipv6_mbgp,
7095 show_ipv6_mbgp_cmd,
7096 "show ipv6 mbgp",
7097 SHOW_STR
7098 IP_STR
7099 MBGP_STR)
7100{
ajs5a646652004-11-05 01:25:55 +00007101 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7102 NULL);
paul718e3742002-12-13 20:15:29 +00007103}
7104
7105/* old command */
7106DEFUN (show_ipv6_mbgp_route,
7107 show_ipv6_mbgp_route_cmd,
7108 "show ipv6 mbgp X:X::X:X",
7109 SHOW_STR
7110 IP_STR
7111 MBGP_STR
7112 "Network in the MBGP routing table to display\n")
7113{
7114 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7115}
7116
7117/* old command */
7118DEFUN (show_ipv6_mbgp_prefix,
7119 show_ipv6_mbgp_prefix_cmd,
7120 "show ipv6 mbgp X:X::X:X/M",
7121 SHOW_STR
7122 IP_STR
7123 MBGP_STR
7124 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7125{
7126 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7127}
7128#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02007129
paul718e3742002-12-13 20:15:29 +00007130
paul94f2b392005-06-28 12:44:16 +00007131static int
paulfd79ac92004-10-13 05:06:08 +00007132bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007133 safi_t safi, enum bgp_show_type type)
7134{
7135 int i;
7136 struct buffer *b;
7137 char *regstr;
7138 int first;
7139 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007140 int rc;
paul718e3742002-12-13 20:15:29 +00007141
7142 first = 0;
7143 b = buffer_new (1024);
7144 for (i = 0; i < argc; i++)
7145 {
7146 if (first)
7147 buffer_putc (b, ' ');
7148 else
7149 {
7150 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7151 continue;
7152 first = 1;
7153 }
7154
7155 buffer_putstr (b, argv[i]);
7156 }
7157 buffer_putc (b, '\0');
7158
7159 regstr = buffer_getstr (b);
7160 buffer_free (b);
7161
7162 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007163 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007164 if (! regex)
7165 {
7166 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7167 VTY_NEWLINE);
7168 return CMD_WARNING;
7169 }
7170
ajs5a646652004-11-05 01:25:55 +00007171 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7172 bgp_regex_free (regex);
7173 return rc;
paul718e3742002-12-13 20:15:29 +00007174}
7175
7176DEFUN (show_ip_bgp_regexp,
7177 show_ip_bgp_regexp_cmd,
7178 "show ip bgp regexp .LINE",
7179 SHOW_STR
7180 IP_STR
7181 BGP_STR
7182 "Display routes matching the AS path regular expression\n"
7183 "A regular-expression to match the BGP AS paths\n")
7184{
7185 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7186 bgp_show_type_regexp);
7187}
7188
7189DEFUN (show_ip_bgp_flap_regexp,
7190 show_ip_bgp_flap_regexp_cmd,
7191 "show ip bgp flap-statistics regexp .LINE",
7192 SHOW_STR
7193 IP_STR
7194 BGP_STR
7195 "Display flap statistics of routes\n"
7196 "Display routes matching the AS path regular expression\n"
7197 "A regular-expression to match the BGP AS paths\n")
7198{
7199 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7200 bgp_show_type_flap_regexp);
7201}
7202
Balaji3921cc52015-05-16 23:12:17 +05307203ALIAS (show_ip_bgp_flap_regexp,
7204 show_ip_bgp_damp_flap_regexp_cmd,
7205 "show ip bgp dampening flap-statistics regexp .LINE",
7206 SHOW_STR
7207 IP_STR
7208 BGP_STR
7209 "Display detailed information about dampening\n"
7210 "Display flap statistics of routes\n"
7211 "Display routes matching the AS path regular expression\n"
7212 "A regular-expression to match the BGP AS paths\n")
7213
paul718e3742002-12-13 20:15:29 +00007214DEFUN (show_ip_bgp_ipv4_regexp,
7215 show_ip_bgp_ipv4_regexp_cmd,
7216 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7217 SHOW_STR
7218 IP_STR
7219 BGP_STR
7220 "Address family\n"
7221 "Address Family modifier\n"
7222 "Address Family modifier\n"
7223 "Display routes matching the AS path regular expression\n"
7224 "A regular-expression to match the BGP AS paths\n")
7225{
7226 if (strncmp (argv[0], "m", 1) == 0)
7227 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7228 bgp_show_type_regexp);
7229
7230 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7231 bgp_show_type_regexp);
7232}
7233
7234#ifdef HAVE_IPV6
7235DEFUN (show_bgp_regexp,
7236 show_bgp_regexp_cmd,
7237 "show bgp regexp .LINE",
7238 SHOW_STR
7239 BGP_STR
7240 "Display routes matching the AS path regular expression\n"
7241 "A regular-expression to match the BGP AS paths\n")
7242{
7243 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7244 bgp_show_type_regexp);
7245}
7246
7247ALIAS (show_bgp_regexp,
7248 show_bgp_ipv6_regexp_cmd,
7249 "show bgp ipv6 regexp .LINE",
7250 SHOW_STR
7251 BGP_STR
7252 "Address family\n"
7253 "Display routes matching the AS path regular expression\n"
7254 "A regular-expression to match the BGP AS paths\n")
7255
7256/* old command */
7257DEFUN (show_ipv6_bgp_regexp,
7258 show_ipv6_bgp_regexp_cmd,
7259 "show ipv6 bgp regexp .LINE",
7260 SHOW_STR
7261 IP_STR
7262 BGP_STR
7263 "Display routes matching the AS path regular expression\n"
7264 "A regular-expression to match the BGP AS paths\n")
7265{
7266 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7267 bgp_show_type_regexp);
7268}
7269
7270/* old command */
7271DEFUN (show_ipv6_mbgp_regexp,
7272 show_ipv6_mbgp_regexp_cmd,
7273 "show ipv6 mbgp regexp .LINE",
7274 SHOW_STR
7275 IP_STR
7276 BGP_STR
7277 "Display routes matching the AS path regular expression\n"
7278 "A regular-expression to match the MBGP AS paths\n")
7279{
7280 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7281 bgp_show_type_regexp);
7282}
7283#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007284
paul94f2b392005-06-28 12:44:16 +00007285static int
paulfd79ac92004-10-13 05:06:08 +00007286bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007287 safi_t safi, enum bgp_show_type type)
7288{
7289 struct prefix_list *plist;
7290
7291 plist = prefix_list_lookup (afi, prefix_list_str);
7292 if (plist == NULL)
7293 {
7294 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7295 prefix_list_str, VTY_NEWLINE);
7296 return CMD_WARNING;
7297 }
7298
ajs5a646652004-11-05 01:25:55 +00007299 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007300}
7301
7302DEFUN (show_ip_bgp_prefix_list,
7303 show_ip_bgp_prefix_list_cmd,
7304 "show ip bgp prefix-list WORD",
7305 SHOW_STR
7306 IP_STR
7307 BGP_STR
7308 "Display routes conforming to the prefix-list\n"
7309 "IP prefix-list name\n")
7310{
7311 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7312 bgp_show_type_prefix_list);
7313}
7314
7315DEFUN (show_ip_bgp_flap_prefix_list,
7316 show_ip_bgp_flap_prefix_list_cmd,
7317 "show ip bgp flap-statistics prefix-list WORD",
7318 SHOW_STR
7319 IP_STR
7320 BGP_STR
7321 "Display flap statistics of routes\n"
7322 "Display routes conforming to the prefix-list\n"
7323 "IP prefix-list name\n")
7324{
7325 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7326 bgp_show_type_flap_prefix_list);
7327}
7328
Balaji3921cc52015-05-16 23:12:17 +05307329ALIAS (show_ip_bgp_flap_prefix_list,
7330 show_ip_bgp_damp_flap_prefix_list_cmd,
7331 "show ip bgp dampening flap-statistics prefix-list WORD",
7332 SHOW_STR
7333 IP_STR
7334 BGP_STR
7335 "Display detailed information about dampening\n"
7336 "Display flap statistics of routes\n"
7337 "Display routes conforming to the prefix-list\n"
7338 "IP prefix-list name\n")
7339
paul718e3742002-12-13 20:15:29 +00007340DEFUN (show_ip_bgp_ipv4_prefix_list,
7341 show_ip_bgp_ipv4_prefix_list_cmd,
7342 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7343 SHOW_STR
7344 IP_STR
7345 BGP_STR
7346 "Address family\n"
7347 "Address Family modifier\n"
7348 "Address Family modifier\n"
7349 "Display routes conforming to the prefix-list\n"
7350 "IP prefix-list name\n")
7351{
7352 if (strncmp (argv[0], "m", 1) == 0)
7353 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7354 bgp_show_type_prefix_list);
7355
7356 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7357 bgp_show_type_prefix_list);
7358}
7359
7360#ifdef HAVE_IPV6
7361DEFUN (show_bgp_prefix_list,
7362 show_bgp_prefix_list_cmd,
7363 "show bgp prefix-list WORD",
7364 SHOW_STR
7365 BGP_STR
7366 "Display routes conforming to the prefix-list\n"
7367 "IPv6 prefix-list name\n")
7368{
7369 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7370 bgp_show_type_prefix_list);
7371}
7372
7373ALIAS (show_bgp_prefix_list,
7374 show_bgp_ipv6_prefix_list_cmd,
7375 "show bgp ipv6 prefix-list WORD",
7376 SHOW_STR
7377 BGP_STR
7378 "Address family\n"
7379 "Display routes conforming to the prefix-list\n"
7380 "IPv6 prefix-list name\n")
7381
7382/* old command */
7383DEFUN (show_ipv6_bgp_prefix_list,
7384 show_ipv6_bgp_prefix_list_cmd,
7385 "show ipv6 bgp prefix-list WORD",
7386 SHOW_STR
7387 IPV6_STR
7388 BGP_STR
7389 "Display routes matching the prefix-list\n"
7390 "IPv6 prefix-list name\n")
7391{
7392 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7393 bgp_show_type_prefix_list);
7394}
7395
7396/* old command */
7397DEFUN (show_ipv6_mbgp_prefix_list,
7398 show_ipv6_mbgp_prefix_list_cmd,
7399 "show ipv6 mbgp prefix-list WORD",
7400 SHOW_STR
7401 IPV6_STR
7402 MBGP_STR
7403 "Display routes matching the prefix-list\n"
7404 "IPv6 prefix-list name\n")
7405{
7406 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7407 bgp_show_type_prefix_list);
7408}
7409#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007410
paul94f2b392005-06-28 12:44:16 +00007411static int
paulfd79ac92004-10-13 05:06:08 +00007412bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007413 safi_t safi, enum bgp_show_type type)
7414{
7415 struct as_list *as_list;
7416
7417 as_list = as_list_lookup (filter);
7418 if (as_list == NULL)
7419 {
7420 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7421 return CMD_WARNING;
7422 }
7423
ajs5a646652004-11-05 01:25:55 +00007424 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007425}
7426
7427DEFUN (show_ip_bgp_filter_list,
7428 show_ip_bgp_filter_list_cmd,
7429 "show ip bgp filter-list WORD",
7430 SHOW_STR
7431 IP_STR
7432 BGP_STR
7433 "Display routes conforming to the filter-list\n"
7434 "Regular expression access list name\n")
7435{
7436 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7437 bgp_show_type_filter_list);
7438}
7439
7440DEFUN (show_ip_bgp_flap_filter_list,
7441 show_ip_bgp_flap_filter_list_cmd,
7442 "show ip bgp flap-statistics filter-list WORD",
7443 SHOW_STR
7444 IP_STR
7445 BGP_STR
7446 "Display flap statistics of routes\n"
7447 "Display routes conforming to the filter-list\n"
7448 "Regular expression access list name\n")
7449{
7450 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7451 bgp_show_type_flap_filter_list);
7452}
7453
Balaji3921cc52015-05-16 23:12:17 +05307454ALIAS (show_ip_bgp_flap_filter_list,
7455 show_ip_bgp_damp_flap_filter_list_cmd,
7456 "show ip bgp dampening flap-statistics filter-list WORD",
7457 SHOW_STR
7458 IP_STR
7459 BGP_STR
7460 "Display detailed information about dampening\n"
7461 "Display flap statistics of routes\n"
7462 "Display routes conforming to the filter-list\n"
7463 "Regular expression access list name\n")
7464
paul718e3742002-12-13 20:15:29 +00007465DEFUN (show_ip_bgp_ipv4_filter_list,
7466 show_ip_bgp_ipv4_filter_list_cmd,
7467 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7468 SHOW_STR
7469 IP_STR
7470 BGP_STR
7471 "Address family\n"
7472 "Address Family modifier\n"
7473 "Address Family modifier\n"
7474 "Display routes conforming to the filter-list\n"
7475 "Regular expression access list name\n")
7476{
7477 if (strncmp (argv[0], "m", 1) == 0)
7478 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7479 bgp_show_type_filter_list);
7480
7481 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7482 bgp_show_type_filter_list);
7483}
7484
7485#ifdef HAVE_IPV6
7486DEFUN (show_bgp_filter_list,
7487 show_bgp_filter_list_cmd,
7488 "show bgp filter-list WORD",
7489 SHOW_STR
7490 BGP_STR
7491 "Display routes conforming to the filter-list\n"
7492 "Regular expression access list name\n")
7493{
7494 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7495 bgp_show_type_filter_list);
7496}
7497
7498ALIAS (show_bgp_filter_list,
7499 show_bgp_ipv6_filter_list_cmd,
7500 "show bgp ipv6 filter-list WORD",
7501 SHOW_STR
7502 BGP_STR
7503 "Address family\n"
7504 "Display routes conforming to the filter-list\n"
7505 "Regular expression access list name\n")
7506
7507/* old command */
7508DEFUN (show_ipv6_bgp_filter_list,
7509 show_ipv6_bgp_filter_list_cmd,
7510 "show ipv6 bgp filter-list WORD",
7511 SHOW_STR
7512 IPV6_STR
7513 BGP_STR
7514 "Display routes conforming to the filter-list\n"
7515 "Regular expression access list name\n")
7516{
7517 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7518 bgp_show_type_filter_list);
7519}
7520
7521/* old command */
7522DEFUN (show_ipv6_mbgp_filter_list,
7523 show_ipv6_mbgp_filter_list_cmd,
7524 "show ipv6 mbgp filter-list WORD",
7525 SHOW_STR
7526 IPV6_STR
7527 MBGP_STR
7528 "Display routes conforming to the filter-list\n"
7529 "Regular expression access list name\n")
7530{
7531 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7532 bgp_show_type_filter_list);
7533}
7534#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007535
Balaji3921cc52015-05-16 23:12:17 +05307536DEFUN (show_ip_bgp_dampening_info,
7537 show_ip_bgp_dampening_params_cmd,
7538 "show ip bgp dampening parameters",
7539 SHOW_STR
7540 IP_STR
7541 BGP_STR
7542 "Display detailed information about dampening\n"
7543 "Display detail of configured dampening parameters\n")
7544{
7545 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
7546}
7547
paul94f2b392005-06-28 12:44:16 +00007548static int
paulfd79ac92004-10-13 05:06:08 +00007549bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007550 safi_t safi, enum bgp_show_type type)
7551{
7552 struct route_map *rmap;
7553
7554 rmap = route_map_lookup_by_name (rmap_str);
7555 if (! rmap)
7556 {
7557 vty_out (vty, "%% %s is not a valid route-map name%s",
7558 rmap_str, VTY_NEWLINE);
7559 return CMD_WARNING;
7560 }
7561
ajs5a646652004-11-05 01:25:55 +00007562 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007563}
7564
7565DEFUN (show_ip_bgp_route_map,
7566 show_ip_bgp_route_map_cmd,
7567 "show ip bgp route-map WORD",
7568 SHOW_STR
7569 IP_STR
7570 BGP_STR
7571 "Display routes matching the route-map\n"
7572 "A route-map to match on\n")
7573{
7574 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7575 bgp_show_type_route_map);
7576}
7577
7578DEFUN (show_ip_bgp_flap_route_map,
7579 show_ip_bgp_flap_route_map_cmd,
7580 "show ip bgp flap-statistics route-map WORD",
7581 SHOW_STR
7582 IP_STR
7583 BGP_STR
7584 "Display flap statistics of routes\n"
7585 "Display routes matching the route-map\n"
7586 "A route-map to match on\n")
7587{
7588 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7589 bgp_show_type_flap_route_map);
7590}
7591
Balaji3921cc52015-05-16 23:12:17 +05307592ALIAS (show_ip_bgp_flap_route_map,
7593 show_ip_bgp_damp_flap_route_map_cmd,
7594 "show ip bgp dampening flap-statistics route-map WORD",
7595 SHOW_STR
7596 IP_STR
7597 BGP_STR
7598 "Display detailed information about dampening\n"
7599 "Display flap statistics of routes\n"
7600 "Display routes matching the route-map\n"
7601 "A route-map to match on\n")
7602
paul718e3742002-12-13 20:15:29 +00007603DEFUN (show_ip_bgp_ipv4_route_map,
7604 show_ip_bgp_ipv4_route_map_cmd,
7605 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7606 SHOW_STR
7607 IP_STR
7608 BGP_STR
7609 "Address family\n"
7610 "Address Family modifier\n"
7611 "Address Family modifier\n"
7612 "Display routes matching the route-map\n"
7613 "A route-map to match on\n")
7614{
7615 if (strncmp (argv[0], "m", 1) == 0)
7616 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7617 bgp_show_type_route_map);
7618
7619 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7620 bgp_show_type_route_map);
7621}
7622
7623DEFUN (show_bgp_route_map,
7624 show_bgp_route_map_cmd,
7625 "show bgp route-map WORD",
7626 SHOW_STR
7627 BGP_STR
7628 "Display routes matching the route-map\n"
7629 "A route-map to match on\n")
7630{
7631 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7632 bgp_show_type_route_map);
7633}
7634
7635ALIAS (show_bgp_route_map,
7636 show_bgp_ipv6_route_map_cmd,
7637 "show bgp ipv6 route-map WORD",
7638 SHOW_STR
7639 BGP_STR
7640 "Address family\n"
7641 "Display routes matching the route-map\n"
7642 "A route-map to match on\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02007643
paul718e3742002-12-13 20:15:29 +00007644DEFUN (show_ip_bgp_cidr_only,
7645 show_ip_bgp_cidr_only_cmd,
7646 "show ip bgp cidr-only",
7647 SHOW_STR
7648 IP_STR
7649 BGP_STR
7650 "Display only routes with non-natural netmasks\n")
7651{
7652 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007653 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007654}
7655
7656DEFUN (show_ip_bgp_flap_cidr_only,
7657 show_ip_bgp_flap_cidr_only_cmd,
7658 "show ip bgp flap-statistics cidr-only",
7659 SHOW_STR
7660 IP_STR
7661 BGP_STR
7662 "Display flap statistics of routes\n"
7663 "Display only routes with non-natural netmasks\n")
7664{
7665 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007666 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007667}
7668
Balaji3921cc52015-05-16 23:12:17 +05307669ALIAS (show_ip_bgp_flap_cidr_only,
7670 show_ip_bgp_damp_flap_cidr_only_cmd,
7671 "show ip bgp dampening flap-statistics cidr-only",
7672 SHOW_STR
7673 IP_STR
7674 BGP_STR
7675 "Display detailed information about dampening\n"
7676 "Display flap statistics of routes\n"
7677 "Display only routes with non-natural netmasks\n")
7678
paul718e3742002-12-13 20:15:29 +00007679DEFUN (show_ip_bgp_ipv4_cidr_only,
7680 show_ip_bgp_ipv4_cidr_only_cmd,
7681 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7682 SHOW_STR
7683 IP_STR
7684 BGP_STR
7685 "Address family\n"
7686 "Address Family modifier\n"
7687 "Address Family modifier\n"
7688 "Display only routes with non-natural netmasks\n")
7689{
7690 if (strncmp (argv[0], "m", 1) == 0)
7691 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007692 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007693
7694 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007695 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007696}
David Lamparter6b0655a2014-06-04 06:53:35 +02007697
paul718e3742002-12-13 20:15:29 +00007698DEFUN (show_ip_bgp_community_all,
7699 show_ip_bgp_community_all_cmd,
7700 "show ip bgp community",
7701 SHOW_STR
7702 IP_STR
7703 BGP_STR
7704 "Display routes matching the communities\n")
7705{
7706 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007707 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007708}
7709
7710DEFUN (show_ip_bgp_ipv4_community_all,
7711 show_ip_bgp_ipv4_community_all_cmd,
7712 "show ip bgp ipv4 (unicast|multicast) community",
7713 SHOW_STR
7714 IP_STR
7715 BGP_STR
7716 "Address family\n"
7717 "Address Family modifier\n"
7718 "Address Family modifier\n"
7719 "Display routes matching the communities\n")
7720{
7721 if (strncmp (argv[0], "m", 1) == 0)
7722 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007723 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007724
7725 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007726 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007727}
7728
7729#ifdef HAVE_IPV6
7730DEFUN (show_bgp_community_all,
7731 show_bgp_community_all_cmd,
7732 "show bgp community",
7733 SHOW_STR
7734 BGP_STR
7735 "Display routes matching the communities\n")
7736{
7737 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007738 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007739}
7740
7741ALIAS (show_bgp_community_all,
7742 show_bgp_ipv6_community_all_cmd,
7743 "show bgp ipv6 community",
7744 SHOW_STR
7745 BGP_STR
7746 "Address family\n"
7747 "Display routes matching the communities\n")
7748
7749/* old command */
7750DEFUN (show_ipv6_bgp_community_all,
7751 show_ipv6_bgp_community_all_cmd,
7752 "show ipv6 bgp community",
7753 SHOW_STR
7754 IPV6_STR
7755 BGP_STR
7756 "Display routes matching the communities\n")
7757{
7758 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007759 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007760}
7761
7762/* old command */
7763DEFUN (show_ipv6_mbgp_community_all,
7764 show_ipv6_mbgp_community_all_cmd,
7765 "show ipv6 mbgp community",
7766 SHOW_STR
7767 IPV6_STR
7768 MBGP_STR
7769 "Display routes matching the communities\n")
7770{
7771 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007772 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007773}
7774#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007775
paul94f2b392005-06-28 12:44:16 +00007776static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007777bgp_show_community (struct vty *vty, const char *view_name, int argc,
7778 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007779{
7780 struct community *com;
7781 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007782 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007783 int i;
7784 char *str;
7785 int first = 0;
7786
Michael Lambert95cbbd22010-07-23 14:43:04 -04007787 /* BGP structure lookup */
7788 if (view_name)
7789 {
7790 bgp = bgp_lookup_by_name (view_name);
7791 if (bgp == NULL)
7792 {
7793 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7794 return CMD_WARNING;
7795 }
7796 }
7797 else
7798 {
7799 bgp = bgp_get_default ();
7800 if (bgp == NULL)
7801 {
7802 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7803 return CMD_WARNING;
7804 }
7805 }
7806
paul718e3742002-12-13 20:15:29 +00007807 b = buffer_new (1024);
7808 for (i = 0; i < argc; i++)
7809 {
7810 if (first)
7811 buffer_putc (b, ' ');
7812 else
7813 {
7814 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7815 continue;
7816 first = 1;
7817 }
7818
7819 buffer_putstr (b, argv[i]);
7820 }
7821 buffer_putc (b, '\0');
7822
7823 str = buffer_getstr (b);
7824 buffer_free (b);
7825
7826 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007827 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007828 if (! com)
7829 {
7830 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7831 return CMD_WARNING;
7832 }
7833
Michael Lambert95cbbd22010-07-23 14:43:04 -04007834 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007835 (exact ? bgp_show_type_community_exact :
7836 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007837}
7838
7839DEFUN (show_ip_bgp_community,
7840 show_ip_bgp_community_cmd,
7841 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7842 SHOW_STR
7843 IP_STR
7844 BGP_STR
7845 "Display routes matching the communities\n"
7846 "community number\n"
7847 "Do not send outside local AS (well-known community)\n"
7848 "Do not advertise to any peer (well-known community)\n"
7849 "Do not export to next AS (well-known community)\n")
7850{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007851 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007852}
7853
7854ALIAS (show_ip_bgp_community,
7855 show_ip_bgp_community2_cmd,
7856 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7857 SHOW_STR
7858 IP_STR
7859 BGP_STR
7860 "Display routes matching the communities\n"
7861 "community number\n"
7862 "Do not send outside local AS (well-known community)\n"
7863 "Do not advertise to any peer (well-known community)\n"
7864 "Do not export to next AS (well-known community)\n"
7865 "community number\n"
7866 "Do not send outside local AS (well-known community)\n"
7867 "Do not advertise to any peer (well-known community)\n"
7868 "Do not export to next AS (well-known community)\n")
7869
7870ALIAS (show_ip_bgp_community,
7871 show_ip_bgp_community3_cmd,
7872 "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)",
7873 SHOW_STR
7874 IP_STR
7875 BGP_STR
7876 "Display routes matching the communities\n"
7877 "community number\n"
7878 "Do not send outside local AS (well-known community)\n"
7879 "Do not advertise to any peer (well-known community)\n"
7880 "Do not export to next AS (well-known community)\n"
7881 "community number\n"
7882 "Do not send outside local AS (well-known community)\n"
7883 "Do not advertise to any peer (well-known community)\n"
7884 "Do not export to next AS (well-known community)\n"
7885 "community number\n"
7886 "Do not send outside local AS (well-known community)\n"
7887 "Do not advertise to any peer (well-known community)\n"
7888 "Do not export to next AS (well-known community)\n")
7889
7890ALIAS (show_ip_bgp_community,
7891 show_ip_bgp_community4_cmd,
7892 "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)",
7893 SHOW_STR
7894 IP_STR
7895 BGP_STR
7896 "Display routes matching the communities\n"
7897 "community number\n"
7898 "Do not send outside local AS (well-known community)\n"
7899 "Do not advertise to any peer (well-known community)\n"
7900 "Do not export to next AS (well-known community)\n"
7901 "community number\n"
7902 "Do not send outside local AS (well-known community)\n"
7903 "Do not advertise to any peer (well-known community)\n"
7904 "Do not export to next AS (well-known community)\n"
7905 "community number\n"
7906 "Do not send outside local AS (well-known community)\n"
7907 "Do not advertise to any peer (well-known community)\n"
7908 "Do not export to next AS (well-known community)\n"
7909 "community number\n"
7910 "Do not send outside local AS (well-known community)\n"
7911 "Do not advertise to any peer (well-known community)\n"
7912 "Do not export to next AS (well-known community)\n")
7913
7914DEFUN (show_ip_bgp_ipv4_community,
7915 show_ip_bgp_ipv4_community_cmd,
7916 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7917 SHOW_STR
7918 IP_STR
7919 BGP_STR
7920 "Address family\n"
7921 "Address Family modifier\n"
7922 "Address Family modifier\n"
7923 "Display routes matching the communities\n"
7924 "community number\n"
7925 "Do not send outside local AS (well-known community)\n"
7926 "Do not advertise to any peer (well-known community)\n"
7927 "Do not export to next AS (well-known community)\n")
7928{
7929 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007930 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007931
Michael Lambert95cbbd22010-07-23 14:43:04 -04007932 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007933}
7934
7935ALIAS (show_ip_bgp_ipv4_community,
7936 show_ip_bgp_ipv4_community2_cmd,
7937 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7938 SHOW_STR
7939 IP_STR
7940 BGP_STR
7941 "Address family\n"
7942 "Address Family modifier\n"
7943 "Address Family modifier\n"
7944 "Display routes matching the communities\n"
7945 "community number\n"
7946 "Do not send outside local AS (well-known community)\n"
7947 "Do not advertise to any peer (well-known community)\n"
7948 "Do not export to next AS (well-known community)\n"
7949 "community number\n"
7950 "Do not send outside local AS (well-known community)\n"
7951 "Do not advertise to any peer (well-known community)\n"
7952 "Do not export to next AS (well-known community)\n")
7953
7954ALIAS (show_ip_bgp_ipv4_community,
7955 show_ip_bgp_ipv4_community3_cmd,
7956 "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)",
7957 SHOW_STR
7958 IP_STR
7959 BGP_STR
7960 "Address family\n"
7961 "Address Family modifier\n"
7962 "Address Family modifier\n"
7963 "Display routes matching the communities\n"
7964 "community number\n"
7965 "Do not send outside local AS (well-known community)\n"
7966 "Do not advertise to any peer (well-known community)\n"
7967 "Do not export to next AS (well-known community)\n"
7968 "community number\n"
7969 "Do not send outside local AS (well-known community)\n"
7970 "Do not advertise to any peer (well-known community)\n"
7971 "Do not export to next AS (well-known community)\n"
7972 "community number\n"
7973 "Do not send outside local AS (well-known community)\n"
7974 "Do not advertise to any peer (well-known community)\n"
7975 "Do not export to next AS (well-known community)\n")
7976
7977ALIAS (show_ip_bgp_ipv4_community,
7978 show_ip_bgp_ipv4_community4_cmd,
7979 "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)",
7980 SHOW_STR
7981 IP_STR
7982 BGP_STR
7983 "Address family\n"
7984 "Address Family modifier\n"
7985 "Address Family modifier\n"
7986 "Display routes matching the communities\n"
7987 "community number\n"
7988 "Do not send outside local AS (well-known community)\n"
7989 "Do not advertise to any peer (well-known community)\n"
7990 "Do not export to next AS (well-known community)\n"
7991 "community number\n"
7992 "Do not send outside local AS (well-known community)\n"
7993 "Do not advertise to any peer (well-known community)\n"
7994 "Do not export to next AS (well-known community)\n"
7995 "community number\n"
7996 "Do not send outside local AS (well-known community)\n"
7997 "Do not advertise to any peer (well-known community)\n"
7998 "Do not export to next AS (well-known community)\n"
7999 "community number\n"
8000 "Do not send outside local AS (well-known community)\n"
8001 "Do not advertise to any peer (well-known community)\n"
8002 "Do not export to next AS (well-known community)\n")
8003
Michael Lambert95cbbd22010-07-23 14:43:04 -04008004DEFUN (show_bgp_view_afi_safi_community_all,
8005 show_bgp_view_afi_safi_community_all_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008006 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008007 SHOW_STR
8008 BGP_STR
8009 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008010 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008011 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008012 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008013 "Address Family modifier\n"
8014 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00008015 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04008016{
8017 int afi;
8018 int safi;
8019 struct bgp *bgp;
8020
8021 /* BGP structure lookup. */
8022 bgp = bgp_lookup_by_name (argv[0]);
8023 if (bgp == NULL)
8024 {
8025 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8026 return CMD_WARNING;
8027 }
8028
Michael Lambert95cbbd22010-07-23 14:43:04 -04008029 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8030 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Michael Lambert95cbbd22010-07-23 14:43:04 -04008031 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
8032}
8033
8034DEFUN (show_bgp_view_afi_safi_community,
8035 show_bgp_view_afi_safi_community_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008036 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008037 SHOW_STR
8038 BGP_STR
8039 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008040 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008041 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008042 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008043 "Address family modifier\n"
8044 "Address family modifier\n"
8045 "Display routes matching the communities\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{
8051 int afi;
8052 int safi;
8053
Michael Lambert95cbbd22010-07-23 14:43:04 -04008054 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8055 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8056 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Michael Lambert95cbbd22010-07-23 14:43:04 -04008057}
8058
8059ALIAS (show_bgp_view_afi_safi_community,
8060 show_bgp_view_afi_safi_community2_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008061 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008062 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"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008067 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008068 "Address family modifier\n"
8069 "Address family modifier\n"
8070 "Display routes matching the communities\n"
8071 "community number\n"
8072 "Do not send outside local AS (well-known community)\n"
8073 "Do not advertise to any peer (well-known community)\n"
8074 "Do not export to next AS (well-known community)\n"
8075 "community number\n"
8076 "Do not send outside local AS (well-known community)\n"
8077 "Do not advertise to any peer (well-known community)\n"
8078 "Do not export to next AS (well-known community)\n")
8079
8080ALIAS (show_bgp_view_afi_safi_community,
8081 show_bgp_view_afi_safi_community3_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008082 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008083 SHOW_STR
8084 BGP_STR
8085 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008086 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008087 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008088 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008089 "Address family modifier\n"
8090 "Address family modifier\n"
8091 "Display routes matching the communities\n"
8092 "community number\n"
8093 "Do not send outside local AS (well-known community)\n"
8094 "Do not advertise to any peer (well-known community)\n"
8095 "Do not export to next AS (well-known community)\n"
8096 "community number\n"
8097 "Do not send outside local AS (well-known community)\n"
8098 "Do not advertise to any peer (well-known community)\n"
8099 "Do not export to next AS (well-known community)\n"
8100 "community number\n"
8101 "Do not send outside local AS (well-known community)\n"
8102 "Do not advertise to any peer (well-known community)\n"
8103 "Do not export to next AS (well-known community)\n")
8104
8105ALIAS (show_bgp_view_afi_safi_community,
8106 show_bgp_view_afi_safi_community4_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008107 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008108 SHOW_STR
8109 BGP_STR
8110 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008111 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008112 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008113 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008114 "Address family modifier\n"
8115 "Address family modifier\n"
8116 "Display routes matching the communities\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 "community number\n"
8122 "Do not send outside local AS (well-known community)\n"
8123 "Do not advertise to any peer (well-known community)\n"
8124 "Do not export to next AS (well-known community)\n"
8125 "community number\n"
8126 "Do not send outside local AS (well-known community)\n"
8127 "Do not advertise to any peer (well-known community)\n"
8128 "Do not export to next AS (well-known community)\n"
8129 "community number\n"
8130 "Do not send outside local AS (well-known community)\n"
8131 "Do not advertise to any peer (well-known community)\n"
8132 "Do not export to next AS (well-known community)\n")
8133
paul718e3742002-12-13 20:15:29 +00008134DEFUN (show_ip_bgp_community_exact,
8135 show_ip_bgp_community_exact_cmd,
8136 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8137 SHOW_STR
8138 IP_STR
8139 BGP_STR
8140 "Display routes matching the communities\n"
8141 "community number\n"
8142 "Do not send outside local AS (well-known community)\n"
8143 "Do not advertise to any peer (well-known community)\n"
8144 "Do not export to next AS (well-known community)\n"
8145 "Exact match of the communities")
8146{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008147 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008148}
8149
8150ALIAS (show_ip_bgp_community_exact,
8151 show_ip_bgp_community2_exact_cmd,
8152 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8153 SHOW_STR
8154 IP_STR
8155 BGP_STR
8156 "Display routes matching the communities\n"
8157 "community number\n"
8158 "Do not send outside local AS (well-known community)\n"
8159 "Do not advertise to any peer (well-known community)\n"
8160 "Do not export to next AS (well-known community)\n"
8161 "community number\n"
8162 "Do not send outside local AS (well-known community)\n"
8163 "Do not advertise to any peer (well-known community)\n"
8164 "Do not export to next AS (well-known community)\n"
8165 "Exact match of the communities")
8166
8167ALIAS (show_ip_bgp_community_exact,
8168 show_ip_bgp_community3_exact_cmd,
8169 "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",
8170 SHOW_STR
8171 IP_STR
8172 BGP_STR
8173 "Display routes matching the communities\n"
8174 "community number\n"
8175 "Do not send outside local AS (well-known community)\n"
8176 "Do not advertise to any peer (well-known community)\n"
8177 "Do not export to next AS (well-known community)\n"
8178 "community number\n"
8179 "Do not send outside local AS (well-known community)\n"
8180 "Do not advertise to any peer (well-known community)\n"
8181 "Do not export to next AS (well-known community)\n"
8182 "community number\n"
8183 "Do not send outside local AS (well-known community)\n"
8184 "Do not advertise to any peer (well-known community)\n"
8185 "Do not export to next AS (well-known community)\n"
8186 "Exact match of the communities")
8187
8188ALIAS (show_ip_bgp_community_exact,
8189 show_ip_bgp_community4_exact_cmd,
8190 "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",
8191 SHOW_STR
8192 IP_STR
8193 BGP_STR
8194 "Display routes matching the communities\n"
8195 "community number\n"
8196 "Do not send outside local AS (well-known community)\n"
8197 "Do not advertise to any peer (well-known community)\n"
8198 "Do not export to next AS (well-known community)\n"
8199 "community number\n"
8200 "Do not send outside local AS (well-known community)\n"
8201 "Do not advertise to any peer (well-known community)\n"
8202 "Do not export to next AS (well-known community)\n"
8203 "community number\n"
8204 "Do not send outside local AS (well-known community)\n"
8205 "Do not advertise to any peer (well-known community)\n"
8206 "Do not export to next AS (well-known community)\n"
8207 "community number\n"
8208 "Do not send outside local AS (well-known community)\n"
8209 "Do not advertise to any peer (well-known community)\n"
8210 "Do not export to next AS (well-known community)\n"
8211 "Exact match of the communities")
8212
8213DEFUN (show_ip_bgp_ipv4_community_exact,
8214 show_ip_bgp_ipv4_community_exact_cmd,
8215 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8216 SHOW_STR
8217 IP_STR
8218 BGP_STR
8219 "Address family\n"
8220 "Address Family modifier\n"
8221 "Address Family modifier\n"
8222 "Display routes matching the communities\n"
8223 "community number\n"
8224 "Do not send outside local AS (well-known community)\n"
8225 "Do not advertise to any peer (well-known community)\n"
8226 "Do not export to next AS (well-known community)\n"
8227 "Exact match of the communities")
8228{
8229 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008230 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008231
Michael Lambert95cbbd22010-07-23 14:43:04 -04008232 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008233}
8234
8235ALIAS (show_ip_bgp_ipv4_community_exact,
8236 show_ip_bgp_ipv4_community2_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) 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 "Exact match of the communities")
8254
8255ALIAS (show_ip_bgp_ipv4_community_exact,
8256 show_ip_bgp_ipv4_community3_exact_cmd,
8257 "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",
8258 SHOW_STR
8259 IP_STR
8260 BGP_STR
8261 "Address family\n"
8262 "Address Family modifier\n"
8263 "Address Family modifier\n"
8264 "Display routes matching the communities\n"
8265 "community number\n"
8266 "Do not send outside local AS (well-known community)\n"
8267 "Do not advertise to any peer (well-known community)\n"
8268 "Do not export to next AS (well-known community)\n"
8269 "community number\n"
8270 "Do not send outside local AS (well-known community)\n"
8271 "Do not advertise to any peer (well-known community)\n"
8272 "Do not export to next AS (well-known community)\n"
8273 "community number\n"
8274 "Do not send outside local AS (well-known community)\n"
8275 "Do not advertise to any peer (well-known community)\n"
8276 "Do not export to next AS (well-known community)\n"
8277 "Exact match of the communities")
8278
8279ALIAS (show_ip_bgp_ipv4_community_exact,
8280 show_ip_bgp_ipv4_community4_exact_cmd,
8281 "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",
8282 SHOW_STR
8283 IP_STR
8284 BGP_STR
8285 "Address family\n"
8286 "Address Family modifier\n"
8287 "Address Family modifier\n"
8288 "Display routes matching the communities\n"
8289 "community number\n"
8290 "Do not send outside local AS (well-known community)\n"
8291 "Do not advertise to any peer (well-known community)\n"
8292 "Do not export to next AS (well-known community)\n"
8293 "community number\n"
8294 "Do not send outside local AS (well-known community)\n"
8295 "Do not advertise to any peer (well-known community)\n"
8296 "Do not export to next AS (well-known community)\n"
8297 "community number\n"
8298 "Do not send outside local AS (well-known community)\n"
8299 "Do not advertise to any peer (well-known community)\n"
8300 "Do not export to next AS (well-known community)\n"
8301 "community number\n"
8302 "Do not send outside local AS (well-known community)\n"
8303 "Do not advertise to any peer (well-known community)\n"
8304 "Do not export to next AS (well-known community)\n"
8305 "Exact match of the communities")
8306
8307#ifdef HAVE_IPV6
8308DEFUN (show_bgp_community,
8309 show_bgp_community_cmd,
8310 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8311 SHOW_STR
8312 BGP_STR
8313 "Display routes matching the communities\n"
8314 "community number\n"
8315 "Do not send outside local AS (well-known community)\n"
8316 "Do not advertise to any peer (well-known community)\n"
8317 "Do not export to next AS (well-known community)\n")
8318{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008319 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008320}
8321
8322ALIAS (show_bgp_community,
8323 show_bgp_ipv6_community_cmd,
8324 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8325 SHOW_STR
8326 BGP_STR
8327 "Address family\n"
8328 "Display routes matching the communities\n"
8329 "community number\n"
8330 "Do not send outside local AS (well-known community)\n"
8331 "Do not advertise to any peer (well-known community)\n"
8332 "Do not export to next AS (well-known community)\n")
8333
8334ALIAS (show_bgp_community,
8335 show_bgp_community2_cmd,
8336 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8337 SHOW_STR
8338 BGP_STR
8339 "Display routes matching the communities\n"
8340 "community number\n"
8341 "Do not send outside local AS (well-known community)\n"
8342 "Do not advertise to any peer (well-known community)\n"
8343 "Do not export to next AS (well-known community)\n"
8344 "community number\n"
8345 "Do not send outside local AS (well-known community)\n"
8346 "Do not advertise to any peer (well-known community)\n"
8347 "Do not export to next AS (well-known community)\n")
8348
8349ALIAS (show_bgp_community,
8350 show_bgp_ipv6_community2_cmd,
8351 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8352 SHOW_STR
8353 BGP_STR
8354 "Address family\n"
8355 "Display routes matching the communities\n"
8356 "community number\n"
8357 "Do not send outside local AS (well-known community)\n"
8358 "Do not advertise to any peer (well-known community)\n"
8359 "Do not export to next AS (well-known community)\n"
8360 "community number\n"
8361 "Do not send outside local AS (well-known community)\n"
8362 "Do not advertise to any peer (well-known community)\n"
8363 "Do not export to next AS (well-known community)\n")
8364
8365ALIAS (show_bgp_community,
8366 show_bgp_community3_cmd,
8367 "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)",
8368 SHOW_STR
8369 BGP_STR
8370 "Display routes matching the communities\n"
8371 "community number\n"
8372 "Do not send outside local AS (well-known community)\n"
8373 "Do not advertise to any peer (well-known community)\n"
8374 "Do not export to next AS (well-known community)\n"
8375 "community number\n"
8376 "Do not send outside local AS (well-known community)\n"
8377 "Do not advertise to any peer (well-known community)\n"
8378 "Do not export to next AS (well-known community)\n"
8379 "community number\n"
8380 "Do not send outside local AS (well-known community)\n"
8381 "Do not advertise to any peer (well-known community)\n"
8382 "Do not export to next AS (well-known community)\n")
8383
8384ALIAS (show_bgp_community,
8385 show_bgp_ipv6_community3_cmd,
8386 "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)",
8387 SHOW_STR
8388 BGP_STR
8389 "Address family\n"
8390 "Display routes matching the communities\n"
8391 "community number\n"
8392 "Do not send outside local AS (well-known community)\n"
8393 "Do not advertise to any peer (well-known community)\n"
8394 "Do not export to next AS (well-known community)\n"
8395 "community number\n"
8396 "Do not send outside local AS (well-known community)\n"
8397 "Do not advertise to any peer (well-known community)\n"
8398 "Do not export to next AS (well-known community)\n"
8399 "community number\n"
8400 "Do not send outside local AS (well-known community)\n"
8401 "Do not advertise to any peer (well-known community)\n"
8402 "Do not export to next AS (well-known community)\n")
8403
8404ALIAS (show_bgp_community,
8405 show_bgp_community4_cmd,
8406 "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)",
8407 SHOW_STR
8408 BGP_STR
8409 "Display routes matching the communities\n"
8410 "community number\n"
8411 "Do not send outside local AS (well-known community)\n"
8412 "Do not advertise to any peer (well-known community)\n"
8413 "Do not export to next AS (well-known community)\n"
8414 "community number\n"
8415 "Do not send outside local AS (well-known community)\n"
8416 "Do not advertise to any peer (well-known community)\n"
8417 "Do not export to next AS (well-known community)\n"
8418 "community number\n"
8419 "Do not send outside local AS (well-known community)\n"
8420 "Do not advertise to any peer (well-known community)\n"
8421 "Do not export to next AS (well-known community)\n"
8422 "community number\n"
8423 "Do not send outside local AS (well-known community)\n"
8424 "Do not advertise to any peer (well-known community)\n"
8425 "Do not export to next AS (well-known community)\n")
8426
8427ALIAS (show_bgp_community,
8428 show_bgp_ipv6_community4_cmd,
8429 "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)",
8430 SHOW_STR
8431 BGP_STR
8432 "Address family\n"
8433 "Display routes matching the communities\n"
8434 "community number\n"
8435 "Do not send outside local AS (well-known community)\n"
8436 "Do not advertise to any peer (well-known community)\n"
8437 "Do not export to next AS (well-known community)\n"
8438 "community number\n"
8439 "Do not send outside local AS (well-known community)\n"
8440 "Do not advertise to any peer (well-known community)\n"
8441 "Do not export to next AS (well-known community)\n"
8442 "community number\n"
8443 "Do not send outside local AS (well-known community)\n"
8444 "Do not advertise to any peer (well-known community)\n"
8445 "Do not export to next AS (well-known community)\n"
8446 "community number\n"
8447 "Do not send outside local AS (well-known community)\n"
8448 "Do not advertise to any peer (well-known community)\n"
8449 "Do not export to next AS (well-known community)\n")
8450
8451/* old command */
8452DEFUN (show_ipv6_bgp_community,
8453 show_ipv6_bgp_community_cmd,
8454 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8455 SHOW_STR
8456 IPV6_STR
8457 BGP_STR
8458 "Display routes matching the communities\n"
8459 "community number\n"
8460 "Do not send outside local AS (well-known community)\n"
8461 "Do not advertise to any peer (well-known community)\n"
8462 "Do not export to next AS (well-known community)\n")
8463{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008464 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008465}
8466
8467/* old command */
8468ALIAS (show_ipv6_bgp_community,
8469 show_ipv6_bgp_community2_cmd,
8470 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8471 SHOW_STR
8472 IPV6_STR
8473 BGP_STR
8474 "Display routes matching the communities\n"
8475 "community number\n"
8476 "Do not send outside local AS (well-known community)\n"
8477 "Do not advertise to any peer (well-known community)\n"
8478 "Do not export to next AS (well-known community)\n"
8479 "community number\n"
8480 "Do not send outside local AS (well-known community)\n"
8481 "Do not advertise to any peer (well-known community)\n"
8482 "Do not export to next AS (well-known community)\n")
8483
8484/* old command */
8485ALIAS (show_ipv6_bgp_community,
8486 show_ipv6_bgp_community3_cmd,
8487 "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)",
8488 SHOW_STR
8489 IPV6_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 "community number\n"
8497 "Do not send outside local AS (well-known community)\n"
8498 "Do not advertise to any peer (well-known community)\n"
8499 "Do not export to next AS (well-known community)\n"
8500 "community number\n"
8501 "Do not send outside local AS (well-known community)\n"
8502 "Do not advertise to any peer (well-known community)\n"
8503 "Do not export to next AS (well-known community)\n")
8504
8505/* old command */
8506ALIAS (show_ipv6_bgp_community,
8507 show_ipv6_bgp_community4_cmd,
8508 "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)",
8509 SHOW_STR
8510 IPV6_STR
8511 BGP_STR
8512 "Display routes matching the communities\n"
8513 "community number\n"
8514 "Do not send outside local AS (well-known community)\n"
8515 "Do not advertise to any peer (well-known community)\n"
8516 "Do not export to next AS (well-known community)\n"
8517 "community number\n"
8518 "Do not send outside local AS (well-known community)\n"
8519 "Do not advertise to any peer (well-known community)\n"
8520 "Do not export to next AS (well-known community)\n"
8521 "community number\n"
8522 "Do not send outside local AS (well-known community)\n"
8523 "Do not advertise to any peer (well-known community)\n"
8524 "Do not export to next AS (well-known community)\n"
8525 "community number\n"
8526 "Do not send outside local AS (well-known community)\n"
8527 "Do not advertise to any peer (well-known community)\n"
8528 "Do not export to next AS (well-known community)\n")
8529
8530DEFUN (show_bgp_community_exact,
8531 show_bgp_community_exact_cmd,
8532 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8533 SHOW_STR
8534 BGP_STR
8535 "Display routes matching the communities\n"
8536 "community number\n"
8537 "Do not send outside local AS (well-known community)\n"
8538 "Do not advertise to any peer (well-known community)\n"
8539 "Do not export to next AS (well-known community)\n"
8540 "Exact match of the communities")
8541{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008542 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008543}
8544
8545ALIAS (show_bgp_community_exact,
8546 show_bgp_ipv6_community_exact_cmd,
8547 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8548 SHOW_STR
8549 BGP_STR
8550 "Address family\n"
8551 "Display routes matching the communities\n"
8552 "community number\n"
8553 "Do not send outside local AS (well-known community)\n"
8554 "Do not advertise to any peer (well-known community)\n"
8555 "Do not export to next AS (well-known community)\n"
8556 "Exact match of the communities")
8557
8558ALIAS (show_bgp_community_exact,
8559 show_bgp_community2_exact_cmd,
8560 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8561 SHOW_STR
8562 BGP_STR
8563 "Display routes matching the communities\n"
8564 "community number\n"
8565 "Do not send outside local AS (well-known community)\n"
8566 "Do not advertise to any peer (well-known community)\n"
8567 "Do not export to next AS (well-known community)\n"
8568 "community number\n"
8569 "Do not send outside local AS (well-known community)\n"
8570 "Do not advertise to any peer (well-known community)\n"
8571 "Do not export to next AS (well-known community)\n"
8572 "Exact match of the communities")
8573
8574ALIAS (show_bgp_community_exact,
8575 show_bgp_ipv6_community2_exact_cmd,
8576 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8577 SHOW_STR
8578 BGP_STR
8579 "Address family\n"
8580 "Display routes matching the communities\n"
8581 "community number\n"
8582 "Do not send outside local AS (well-known community)\n"
8583 "Do not advertise to any peer (well-known community)\n"
8584 "Do not export to next AS (well-known community)\n"
8585 "community number\n"
8586 "Do not send outside local AS (well-known community)\n"
8587 "Do not advertise to any peer (well-known community)\n"
8588 "Do not export to next AS (well-known community)\n"
8589 "Exact match of the communities")
8590
8591ALIAS (show_bgp_community_exact,
8592 show_bgp_community3_exact_cmd,
8593 "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",
8594 SHOW_STR
8595 BGP_STR
8596 "Display routes matching the communities\n"
8597 "community number\n"
8598 "Do not send outside local AS (well-known community)\n"
8599 "Do not advertise to any peer (well-known community)\n"
8600 "Do not export to next AS (well-known community)\n"
8601 "community number\n"
8602 "Do not send outside local AS (well-known community)\n"
8603 "Do not advertise to any peer (well-known community)\n"
8604 "Do not export to next AS (well-known community)\n"
8605 "community number\n"
8606 "Do not send outside local AS (well-known community)\n"
8607 "Do not advertise to any peer (well-known community)\n"
8608 "Do not export to next AS (well-known community)\n"
8609 "Exact match of the communities")
8610
8611ALIAS (show_bgp_community_exact,
8612 show_bgp_ipv6_community3_exact_cmd,
8613 "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",
8614 SHOW_STR
8615 BGP_STR
8616 "Address family\n"
8617 "Display routes matching the communities\n"
8618 "community number\n"
8619 "Do not send outside local AS (well-known community)\n"
8620 "Do not advertise to any peer (well-known community)\n"
8621 "Do not export to next AS (well-known community)\n"
8622 "community number\n"
8623 "Do not send outside local AS (well-known community)\n"
8624 "Do not advertise to any peer (well-known community)\n"
8625 "Do not export to next AS (well-known community)\n"
8626 "community number\n"
8627 "Do not send outside local AS (well-known community)\n"
8628 "Do not advertise to any peer (well-known community)\n"
8629 "Do not export to next AS (well-known community)\n"
8630 "Exact match of the communities")
8631
8632ALIAS (show_bgp_community_exact,
8633 show_bgp_community4_exact_cmd,
8634 "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",
8635 SHOW_STR
8636 BGP_STR
8637 "Display routes matching the communities\n"
8638 "community number\n"
8639 "Do not send outside local AS (well-known community)\n"
8640 "Do not advertise to any peer (well-known community)\n"
8641 "Do not export to next AS (well-known community)\n"
8642 "community number\n"
8643 "Do not send outside local AS (well-known community)\n"
8644 "Do not advertise to any peer (well-known community)\n"
8645 "Do not export to next AS (well-known community)\n"
8646 "community number\n"
8647 "Do not send outside local AS (well-known community)\n"
8648 "Do not advertise to any peer (well-known community)\n"
8649 "Do not export to next AS (well-known community)\n"
8650 "community number\n"
8651 "Do not send outside local AS (well-known community)\n"
8652 "Do not advertise to any peer (well-known community)\n"
8653 "Do not export to next AS (well-known community)\n"
8654 "Exact match of the communities")
8655
8656ALIAS (show_bgp_community_exact,
8657 show_bgp_ipv6_community4_exact_cmd,
8658 "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",
8659 SHOW_STR
8660 BGP_STR
8661 "Address family\n"
8662 "Display routes matching the communities\n"
8663 "community number\n"
8664 "Do not send outside local AS (well-known community)\n"
8665 "Do not advertise to any peer (well-known community)\n"
8666 "Do not export to next AS (well-known community)\n"
8667 "community number\n"
8668 "Do not send outside local AS (well-known community)\n"
8669 "Do not advertise to any peer (well-known community)\n"
8670 "Do not export to next AS (well-known community)\n"
8671 "community number\n"
8672 "Do not send outside local AS (well-known community)\n"
8673 "Do not advertise to any peer (well-known community)\n"
8674 "Do not export to next AS (well-known community)\n"
8675 "community number\n"
8676 "Do not send outside local AS (well-known community)\n"
8677 "Do not advertise to any peer (well-known community)\n"
8678 "Do not export to next AS (well-known community)\n"
8679 "Exact match of the communities")
8680
8681/* old command */
8682DEFUN (show_ipv6_bgp_community_exact,
8683 show_ipv6_bgp_community_exact_cmd,
8684 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8685 SHOW_STR
8686 IPV6_STR
8687 BGP_STR
8688 "Display routes matching the communities\n"
8689 "community number\n"
8690 "Do not send outside local AS (well-known community)\n"
8691 "Do not advertise to any peer (well-known community)\n"
8692 "Do not export to next AS (well-known community)\n"
8693 "Exact match of the communities")
8694{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008695 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008696}
8697
8698/* old command */
8699ALIAS (show_ipv6_bgp_community_exact,
8700 show_ipv6_bgp_community2_exact_cmd,
8701 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8702 SHOW_STR
8703 IPV6_STR
8704 BGP_STR
8705 "Display routes matching the communities\n"
8706 "community number\n"
8707 "Do not send outside local AS (well-known community)\n"
8708 "Do not advertise to any peer (well-known community)\n"
8709 "Do not export to next AS (well-known community)\n"
8710 "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 "Exact match of the communities")
8715
8716/* old command */
8717ALIAS (show_ipv6_bgp_community_exact,
8718 show_ipv6_bgp_community3_exact_cmd,
8719 "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",
8720 SHOW_STR
8721 IPV6_STR
8722 BGP_STR
8723 "Display routes matching the communities\n"
8724 "community number\n"
8725 "Do not send outside local AS (well-known community)\n"
8726 "Do not advertise to any peer (well-known community)\n"
8727 "Do not export to next AS (well-known community)\n"
8728 "community number\n"
8729 "Do not send outside local AS (well-known community)\n"
8730 "Do not advertise to any peer (well-known community)\n"
8731 "Do not export to next AS (well-known community)\n"
8732 "community number\n"
8733 "Do not send outside local AS (well-known community)\n"
8734 "Do not advertise to any peer (well-known community)\n"
8735 "Do not export to next AS (well-known community)\n"
8736 "Exact match of the communities")
8737
8738/* old command */
8739ALIAS (show_ipv6_bgp_community_exact,
8740 show_ipv6_bgp_community4_exact_cmd,
8741 "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",
8742 SHOW_STR
8743 IPV6_STR
8744 BGP_STR
8745 "Display routes matching the communities\n"
8746 "community number\n"
8747 "Do not send outside local AS (well-known community)\n"
8748 "Do not advertise to any peer (well-known community)\n"
8749 "Do not export to next AS (well-known community)\n"
8750 "community number\n"
8751 "Do not send outside local AS (well-known community)\n"
8752 "Do not advertise to any peer (well-known community)\n"
8753 "Do not export to next AS (well-known community)\n"
8754 "community number\n"
8755 "Do not send outside local AS (well-known community)\n"
8756 "Do not advertise to any peer (well-known community)\n"
8757 "Do not export to next AS (well-known community)\n"
8758 "community number\n"
8759 "Do not send outside local AS (well-known community)\n"
8760 "Do not advertise to any peer (well-known community)\n"
8761 "Do not export to next AS (well-known community)\n"
8762 "Exact match of the communities")
8763
8764/* old command */
8765DEFUN (show_ipv6_mbgp_community,
8766 show_ipv6_mbgp_community_cmd,
8767 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8768 SHOW_STR
8769 IPV6_STR
8770 MBGP_STR
8771 "Display routes matching the communities\n"
8772 "community number\n"
8773 "Do not send outside local AS (well-known community)\n"
8774 "Do not advertise to any peer (well-known community)\n"
8775 "Do not export to next AS (well-known community)\n")
8776{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008777 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008778}
8779
8780/* old command */
8781ALIAS (show_ipv6_mbgp_community,
8782 show_ipv6_mbgp_community2_cmd,
8783 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8784 SHOW_STR
8785 IPV6_STR
8786 MBGP_STR
8787 "Display routes matching the communities\n"
8788 "community number\n"
8789 "Do not send outside local AS (well-known community)\n"
8790 "Do not advertise to any peer (well-known community)\n"
8791 "Do not export to next AS (well-known community)\n"
8792 "community number\n"
8793 "Do not send outside local AS (well-known community)\n"
8794 "Do not advertise to any peer (well-known community)\n"
8795 "Do not export to next AS (well-known community)\n")
8796
8797/* old command */
8798ALIAS (show_ipv6_mbgp_community,
8799 show_ipv6_mbgp_community3_cmd,
8800 "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)",
8801 SHOW_STR
8802 IPV6_STR
8803 MBGP_STR
8804 "Display routes matching the communities\n"
8805 "community number\n"
8806 "Do not send outside local AS (well-known community)\n"
8807 "Do not advertise to any peer (well-known community)\n"
8808 "Do not export to next AS (well-known community)\n"
8809 "community number\n"
8810 "Do not send outside local AS (well-known community)\n"
8811 "Do not advertise to any peer (well-known community)\n"
8812 "Do not export to next AS (well-known community)\n"
8813 "community number\n"
8814 "Do not send outside local AS (well-known community)\n"
8815 "Do not advertise to any peer (well-known community)\n"
8816 "Do not export to next AS (well-known community)\n")
8817
8818/* old command */
8819ALIAS (show_ipv6_mbgp_community,
8820 show_ipv6_mbgp_community4_cmd,
8821 "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)",
8822 SHOW_STR
8823 IPV6_STR
8824 MBGP_STR
8825 "Display routes matching the communities\n"
8826 "community number\n"
8827 "Do not send outside local AS (well-known community)\n"
8828 "Do not advertise to any peer (well-known community)\n"
8829 "Do not export to next AS (well-known community)\n"
8830 "community number\n"
8831 "Do not send outside local AS (well-known community)\n"
8832 "Do not advertise to any peer (well-known community)\n"
8833 "Do not export to next AS (well-known community)\n"
8834 "community number\n"
8835 "Do not send outside local AS (well-known community)\n"
8836 "Do not advertise to any peer (well-known community)\n"
8837 "Do not export to next AS (well-known community)\n"
8838 "community number\n"
8839 "Do not send outside local AS (well-known community)\n"
8840 "Do not advertise to any peer (well-known community)\n"
8841 "Do not export to next AS (well-known community)\n")
8842
8843/* old command */
8844DEFUN (show_ipv6_mbgp_community_exact,
8845 show_ipv6_mbgp_community_exact_cmd,
8846 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8847 SHOW_STR
8848 IPV6_STR
8849 MBGP_STR
8850 "Display routes matching the communities\n"
8851 "community number\n"
8852 "Do not send outside local AS (well-known community)\n"
8853 "Do not advertise to any peer (well-known community)\n"
8854 "Do not export to next AS (well-known community)\n"
8855 "Exact match of the communities")
8856{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008857 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008858}
8859
8860/* old command */
8861ALIAS (show_ipv6_mbgp_community_exact,
8862 show_ipv6_mbgp_community2_exact_cmd,
8863 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8864 SHOW_STR
8865 IPV6_STR
8866 MBGP_STR
8867 "Display routes matching the communities\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 "Exact match of the communities")
8877
8878/* old command */
8879ALIAS (show_ipv6_mbgp_community_exact,
8880 show_ipv6_mbgp_community3_exact_cmd,
8881 "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",
8882 SHOW_STR
8883 IPV6_STR
8884 MBGP_STR
8885 "Display routes matching the communities\n"
8886 "community number\n"
8887 "Do not send outside local AS (well-known community)\n"
8888 "Do not advertise to any peer (well-known community)\n"
8889 "Do not export to next AS (well-known community)\n"
8890 "community number\n"
8891 "Do not send outside local AS (well-known community)\n"
8892 "Do not advertise to any peer (well-known community)\n"
8893 "Do not export to next AS (well-known community)\n"
8894 "community number\n"
8895 "Do not send outside local AS (well-known community)\n"
8896 "Do not advertise to any peer (well-known community)\n"
8897 "Do not export to next AS (well-known community)\n"
8898 "Exact match of the communities")
8899
8900/* old command */
8901ALIAS (show_ipv6_mbgp_community_exact,
8902 show_ipv6_mbgp_community4_exact_cmd,
8903 "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",
8904 SHOW_STR
8905 IPV6_STR
8906 MBGP_STR
8907 "Display routes matching the communities\n"
8908 "community number\n"
8909 "Do not send outside local AS (well-known community)\n"
8910 "Do not advertise to any peer (well-known community)\n"
8911 "Do not export to next AS (well-known community)\n"
8912 "community number\n"
8913 "Do not send outside local AS (well-known community)\n"
8914 "Do not advertise to any peer (well-known community)\n"
8915 "Do not export to next AS (well-known community)\n"
8916 "community number\n"
8917 "Do not send outside local AS (well-known community)\n"
8918 "Do not advertise to any peer (well-known community)\n"
8919 "Do not export to next AS (well-known community)\n"
8920 "community number\n"
8921 "Do not send outside local AS (well-known community)\n"
8922 "Do not advertise to any peer (well-known community)\n"
8923 "Do not export to next AS (well-known community)\n"
8924 "Exact match of the communities")
8925#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02008926
paul94f2b392005-06-28 12:44:16 +00008927static int
paulfd79ac92004-10-13 05:06:08 +00008928bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008929 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008930{
8931 struct community_list *list;
8932
hassofee6e4e2005-02-02 16:29:31 +00008933 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008934 if (list == NULL)
8935 {
8936 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8937 VTY_NEWLINE);
8938 return CMD_WARNING;
8939 }
8940
ajs5a646652004-11-05 01:25:55 +00008941 return bgp_show (vty, NULL, afi, safi,
8942 (exact ? bgp_show_type_community_list_exact :
8943 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008944}
8945
8946DEFUN (show_ip_bgp_community_list,
8947 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008948 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008949 SHOW_STR
8950 IP_STR
8951 BGP_STR
8952 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008953 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008954 "community-list name\n")
8955{
8956 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8957}
8958
8959DEFUN (show_ip_bgp_ipv4_community_list,
8960 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008961 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008962 SHOW_STR
8963 IP_STR
8964 BGP_STR
8965 "Address family\n"
8966 "Address Family modifier\n"
8967 "Address Family modifier\n"
8968 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008969 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008970 "community-list name\n")
8971{
8972 if (strncmp (argv[0], "m", 1) == 0)
8973 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8974
8975 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8976}
8977
8978DEFUN (show_ip_bgp_community_list_exact,
8979 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008980 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008981 SHOW_STR
8982 IP_STR
8983 BGP_STR
8984 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008985 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008986 "community-list name\n"
8987 "Exact match of the communities\n")
8988{
8989 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8990}
8991
8992DEFUN (show_ip_bgp_ipv4_community_list_exact,
8993 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008994 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008995 SHOW_STR
8996 IP_STR
8997 BGP_STR
8998 "Address family\n"
8999 "Address Family modifier\n"
9000 "Address Family modifier\n"
9001 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009002 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009003 "community-list name\n"
9004 "Exact match of the communities\n")
9005{
9006 if (strncmp (argv[0], "m", 1) == 0)
9007 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
9008
9009 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
9010}
9011
9012#ifdef HAVE_IPV6
9013DEFUN (show_bgp_community_list,
9014 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009015 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009016 SHOW_STR
9017 BGP_STR
9018 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009019 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009020 "community-list name\n")
9021{
9022 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9023}
9024
9025ALIAS (show_bgp_community_list,
9026 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009027 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009028 SHOW_STR
9029 BGP_STR
9030 "Address family\n"
9031 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009032 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00009033 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00009034
9035/* old command */
9036DEFUN (show_ipv6_bgp_community_list,
9037 show_ipv6_bgp_community_list_cmd,
9038 "show ipv6 bgp community-list WORD",
9039 SHOW_STR
9040 IPV6_STR
9041 BGP_STR
9042 "Display routes matching the community-list\n"
9043 "community-list name\n")
9044{
9045 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9046}
9047
9048/* old command */
9049DEFUN (show_ipv6_mbgp_community_list,
9050 show_ipv6_mbgp_community_list_cmd,
9051 "show ipv6 mbgp community-list WORD",
9052 SHOW_STR
9053 IPV6_STR
9054 MBGP_STR
9055 "Display routes matching the community-list\n"
9056 "community-list name\n")
9057{
9058 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
9059}
9060
9061DEFUN (show_bgp_community_list_exact,
9062 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009063 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009064 SHOW_STR
9065 BGP_STR
9066 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009067 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009068 "community-list name\n"
9069 "Exact match of the communities\n")
9070{
9071 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9072}
9073
9074ALIAS (show_bgp_community_list_exact,
9075 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009076 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009077 SHOW_STR
9078 BGP_STR
9079 "Address family\n"
9080 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009081 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009082 "community-list name\n"
9083 "Exact match of the communities\n")
9084
9085/* old command */
9086DEFUN (show_ipv6_bgp_community_list_exact,
9087 show_ipv6_bgp_community_list_exact_cmd,
9088 "show ipv6 bgp community-list WORD exact-match",
9089 SHOW_STR
9090 IPV6_STR
9091 BGP_STR
9092 "Display routes matching the community-list\n"
9093 "community-list name\n"
9094 "Exact match of the communities\n")
9095{
9096 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9097}
9098
9099/* old command */
9100DEFUN (show_ipv6_mbgp_community_list_exact,
9101 show_ipv6_mbgp_community_list_exact_cmd,
9102 "show ipv6 mbgp community-list WORD exact-match",
9103 SHOW_STR
9104 IPV6_STR
9105 MBGP_STR
9106 "Display routes matching the community-list\n"
9107 "community-list name\n"
9108 "Exact match of the communities\n")
9109{
9110 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9111}
9112#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009113
paul94f2b392005-06-28 12:44:16 +00009114static int
paulfd79ac92004-10-13 05:06:08 +00009115bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009116 safi_t safi, enum bgp_show_type type)
9117{
9118 int ret;
9119 struct prefix *p;
9120
9121 p = prefix_new();
9122
9123 ret = str2prefix (prefix, p);
9124 if (! ret)
9125 {
9126 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9127 return CMD_WARNING;
9128 }
9129
ajs5a646652004-11-05 01:25:55 +00009130 ret = bgp_show (vty, NULL, afi, safi, type, p);
9131 prefix_free(p);
9132 return ret;
paul718e3742002-12-13 20:15:29 +00009133}
9134
9135DEFUN (show_ip_bgp_prefix_longer,
9136 show_ip_bgp_prefix_longer_cmd,
9137 "show ip bgp A.B.C.D/M longer-prefixes",
9138 SHOW_STR
9139 IP_STR
9140 BGP_STR
9141 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9142 "Display route and more specific routes\n")
9143{
9144 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9145 bgp_show_type_prefix_longer);
9146}
9147
9148DEFUN (show_ip_bgp_flap_prefix_longer,
9149 show_ip_bgp_flap_prefix_longer_cmd,
9150 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9151 SHOW_STR
9152 IP_STR
9153 BGP_STR
9154 "Display flap statistics of routes\n"
9155 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9156 "Display route and more specific routes\n")
9157{
9158 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9159 bgp_show_type_flap_prefix_longer);
9160}
9161
Balaji3921cc52015-05-16 23:12:17 +05309162ALIAS (show_ip_bgp_flap_prefix_longer,
9163 show_ip_bgp_damp_flap_prefix_longer_cmd,
9164 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
9165 SHOW_STR
9166 IP_STR
9167 BGP_STR
9168 "Display detailed information about dampening\n"
9169 "Display flap statistics of routes\n"
9170 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9171 "Display route and more specific routes\n")
9172
paul718e3742002-12-13 20:15:29 +00009173DEFUN (show_ip_bgp_ipv4_prefix_longer,
9174 show_ip_bgp_ipv4_prefix_longer_cmd,
9175 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9176 SHOW_STR
9177 IP_STR
9178 BGP_STR
9179 "Address family\n"
9180 "Address Family modifier\n"
9181 "Address Family modifier\n"
9182 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9183 "Display route and more specific routes\n")
9184{
9185 if (strncmp (argv[0], "m", 1) == 0)
9186 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9187 bgp_show_type_prefix_longer);
9188
9189 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9190 bgp_show_type_prefix_longer);
9191}
9192
9193DEFUN (show_ip_bgp_flap_address,
9194 show_ip_bgp_flap_address_cmd,
9195 "show ip bgp flap-statistics A.B.C.D",
9196 SHOW_STR
9197 IP_STR
9198 BGP_STR
9199 "Display flap statistics of routes\n"
9200 "Network in the BGP routing table to display\n")
9201{
9202 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9203 bgp_show_type_flap_address);
9204}
9205
Balaji3921cc52015-05-16 23:12:17 +05309206ALIAS (show_ip_bgp_flap_address,
9207 show_ip_bgp_damp_flap_address_cmd,
9208 "show ip bgp dampening flap-statistics A.B.C.D",
9209 SHOW_STR
9210 IP_STR
9211 BGP_STR
9212 "Display detailed information about dampening\n"
9213 "Display flap statistics of routes\n"
9214 "Network in the BGP routing table to display\n")
9215
paul718e3742002-12-13 20:15:29 +00009216DEFUN (show_ip_bgp_flap_prefix,
9217 show_ip_bgp_flap_prefix_cmd,
9218 "show ip bgp flap-statistics A.B.C.D/M",
9219 SHOW_STR
9220 IP_STR
9221 BGP_STR
9222 "Display flap statistics of routes\n"
9223 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9224{
9225 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9226 bgp_show_type_flap_prefix);
9227}
Balaji3921cc52015-05-16 23:12:17 +05309228
9229ALIAS (show_ip_bgp_flap_prefix,
9230 show_ip_bgp_damp_flap_prefix_cmd,
9231 "show ip bgp dampening flap-statistics A.B.C.D/M",
9232 SHOW_STR
9233 IP_STR
9234 BGP_STR
9235 "Display detailed information about dampening\n"
9236 "Display flap statistics of routes\n"
9237 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9238
paul718e3742002-12-13 20:15:29 +00009239#ifdef HAVE_IPV6
9240DEFUN (show_bgp_prefix_longer,
9241 show_bgp_prefix_longer_cmd,
9242 "show bgp X:X::X:X/M longer-prefixes",
9243 SHOW_STR
9244 BGP_STR
9245 "IPv6 prefix <network>/<length>\n"
9246 "Display route and more specific routes\n")
9247{
9248 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9249 bgp_show_type_prefix_longer);
9250}
9251
9252ALIAS (show_bgp_prefix_longer,
9253 show_bgp_ipv6_prefix_longer_cmd,
9254 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9255 SHOW_STR
9256 BGP_STR
9257 "Address family\n"
9258 "IPv6 prefix <network>/<length>\n"
9259 "Display route and more specific routes\n")
9260
9261/* old command */
9262DEFUN (show_ipv6_bgp_prefix_longer,
9263 show_ipv6_bgp_prefix_longer_cmd,
9264 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9265 SHOW_STR
9266 IPV6_STR
9267 BGP_STR
9268 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9269 "Display route and more specific routes\n")
9270{
9271 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9272 bgp_show_type_prefix_longer);
9273}
9274
9275/* old command */
9276DEFUN (show_ipv6_mbgp_prefix_longer,
9277 show_ipv6_mbgp_prefix_longer_cmd,
9278 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9279 SHOW_STR
9280 IPV6_STR
9281 MBGP_STR
9282 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9283 "Display route and more specific routes\n")
9284{
9285 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9286 bgp_show_type_prefix_longer);
9287}
9288#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009289
paul94f2b392005-06-28 12:44:16 +00009290static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009291peer_lookup_in_view (struct vty *vty, const char *view_name,
9292 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009293{
9294 int ret;
9295 struct bgp *bgp;
9296 struct peer *peer;
9297 union sockunion su;
9298
9299 /* BGP structure lookup. */
9300 if (view_name)
9301 {
9302 bgp = bgp_lookup_by_name (view_name);
9303 if (! bgp)
9304 {
9305 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9306 return NULL;
9307 }
9308 }
paul5228ad22004-06-04 17:58:18 +00009309 else
paulbb46e942003-10-24 19:02:03 +00009310 {
9311 bgp = bgp_get_default ();
9312 if (! bgp)
9313 {
9314 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9315 return NULL;
9316 }
9317 }
9318
9319 /* Get peer sockunion. */
9320 ret = str2sockunion (ip_str, &su);
9321 if (ret < 0)
9322 {
9323 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9324 return NULL;
9325 }
9326
9327 /* Peer structure lookup. */
9328 peer = peer_lookup (bgp, &su);
9329 if (! peer)
9330 {
9331 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9332 return NULL;
9333 }
9334
9335 return peer;
9336}
David Lamparter6b0655a2014-06-04 06:53:35 +02009337
Paul Jakma2815e612006-09-14 02:56:07 +00009338enum bgp_stats
9339{
9340 BGP_STATS_MAXBITLEN = 0,
9341 BGP_STATS_RIB,
9342 BGP_STATS_PREFIXES,
9343 BGP_STATS_TOTPLEN,
9344 BGP_STATS_UNAGGREGATEABLE,
9345 BGP_STATS_MAX_AGGREGATEABLE,
9346 BGP_STATS_AGGREGATES,
9347 BGP_STATS_SPACE,
9348 BGP_STATS_ASPATH_COUNT,
9349 BGP_STATS_ASPATH_MAXHOPS,
9350 BGP_STATS_ASPATH_TOTHOPS,
9351 BGP_STATS_ASPATH_MAXSIZE,
9352 BGP_STATS_ASPATH_TOTSIZE,
9353 BGP_STATS_ASN_HIGHEST,
9354 BGP_STATS_MAX,
9355};
paulbb46e942003-10-24 19:02:03 +00009356
Paul Jakma2815e612006-09-14 02:56:07 +00009357static const char *table_stats_strs[] =
9358{
9359 [BGP_STATS_PREFIXES] = "Total Prefixes",
9360 [BGP_STATS_TOTPLEN] = "Average prefix length",
9361 [BGP_STATS_RIB] = "Total Advertisements",
9362 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9363 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9364 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9365 [BGP_STATS_SPACE] = "Address space advertised",
9366 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9367 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9368 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9369 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9370 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9371 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9372 [BGP_STATS_MAX] = NULL,
9373};
9374
9375struct bgp_table_stats
9376{
9377 struct bgp_table *table;
9378 unsigned long long counts[BGP_STATS_MAX];
9379};
9380
9381#if 0
9382#define TALLY_SIGFIG 100000
9383static unsigned long
9384ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9385{
9386 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9387 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9388 unsigned long ret = newtot / count;
9389
9390 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9391 return ret + 1;
9392 else
9393 return ret;
9394}
9395#endif
9396
9397static int
9398bgp_table_stats_walker (struct thread *t)
9399{
9400 struct bgp_node *rn;
9401 struct bgp_node *top;
9402 struct bgp_table_stats *ts = THREAD_ARG (t);
9403 unsigned int space = 0;
9404
Paul Jakma53d9f672006-10-15 23:41:16 +00009405 if (!(top = bgp_table_top (ts->table)))
9406 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009407
9408 switch (top->p.family)
9409 {
9410 case AF_INET:
9411 space = IPV4_MAX_BITLEN;
9412 break;
9413 case AF_INET6:
9414 space = IPV6_MAX_BITLEN;
9415 break;
9416 }
9417
9418 ts->counts[BGP_STATS_MAXBITLEN] = space;
9419
9420 for (rn = top; rn; rn = bgp_route_next (rn))
9421 {
9422 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009423 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009424 unsigned int rinum = 0;
9425
9426 if (rn == top)
9427 continue;
9428
9429 if (!rn->info)
9430 continue;
9431
9432 ts->counts[BGP_STATS_PREFIXES]++;
9433 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9434
9435#if 0
9436 ts->counts[BGP_STATS_AVGPLEN]
9437 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9438 ts->counts[BGP_STATS_AVGPLEN],
9439 rn->p.prefixlen);
9440#endif
9441
9442 /* check if the prefix is included by any other announcements */
9443 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009444 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009445
9446 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009447 {
9448 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9449 /* announced address space */
9450 if (space)
9451 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9452 }
Paul Jakma2815e612006-09-14 02:56:07 +00009453 else if (prn->info)
9454 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9455
Paul Jakma2815e612006-09-14 02:56:07 +00009456 for (ri = rn->info; ri; ri = ri->next)
9457 {
9458 rinum++;
9459 ts->counts[BGP_STATS_RIB]++;
9460
9461 if (ri->attr &&
9462 (CHECK_FLAG (ri->attr->flag,
9463 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9464 ts->counts[BGP_STATS_AGGREGATES]++;
9465
9466 /* as-path stats */
9467 if (ri->attr && ri->attr->aspath)
9468 {
9469 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9470 unsigned int size = aspath_size (ri->attr->aspath);
9471 as_t highest = aspath_highest (ri->attr->aspath);
9472
9473 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9474
9475 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9476 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9477
9478 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9479 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9480
9481 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9482 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9483#if 0
9484 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9485 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9486 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9487 hops);
9488 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9489 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9490 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9491 size);
9492#endif
9493 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9494 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9495 }
9496 }
9497 }
9498 return 0;
9499}
9500
9501static int
9502bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9503{
9504 struct bgp_table_stats ts;
9505 unsigned int i;
9506
9507 if (!bgp->rib[afi][safi])
9508 {
9509 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9510 return CMD_WARNING;
9511 }
9512
9513 memset (&ts, 0, sizeof (ts));
9514 ts.table = bgp->rib[afi][safi];
9515 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9516
9517 vty_out (vty, "BGP %s RIB statistics%s%s",
9518 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9519
9520 for (i = 0; i < BGP_STATS_MAX; i++)
9521 {
9522 if (!table_stats_strs[i])
9523 continue;
9524
9525 switch (i)
9526 {
9527#if 0
9528 case BGP_STATS_ASPATH_AVGHOPS:
9529 case BGP_STATS_ASPATH_AVGSIZE:
9530 case BGP_STATS_AVGPLEN:
9531 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9532 vty_out (vty, "%12.2f",
9533 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9534 break;
9535#endif
9536 case BGP_STATS_ASPATH_TOTHOPS:
9537 case BGP_STATS_ASPATH_TOTSIZE:
9538 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9539 vty_out (vty, "%12.2f",
9540 ts.counts[i] ?
9541 (float)ts.counts[i] /
9542 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9543 : 0);
9544 break;
9545 case BGP_STATS_TOTPLEN:
9546 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9547 vty_out (vty, "%12.2f",
9548 ts.counts[i] ?
9549 (float)ts.counts[i] /
9550 (float)ts.counts[BGP_STATS_PREFIXES]
9551 : 0);
9552 break;
9553 case BGP_STATS_SPACE:
9554 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9555 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9556 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9557 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009558 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009559 vty_out (vty, "%12.2f%s",
9560 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009561 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009562 VTY_NEWLINE);
9563 vty_out (vty, "%30s: ", "/8 equivalent ");
9564 vty_out (vty, "%12.2f%s",
9565 (float)ts.counts[BGP_STATS_SPACE] /
9566 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9567 VTY_NEWLINE);
9568 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9569 break;
9570 vty_out (vty, "%30s: ", "/24 equivalent ");
9571 vty_out (vty, "%12.2f",
9572 (float)ts.counts[BGP_STATS_SPACE] /
9573 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9574 break;
9575 default:
9576 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9577 vty_out (vty, "%12llu", ts.counts[i]);
9578 }
9579
9580 vty_out (vty, "%s", VTY_NEWLINE);
9581 }
9582 return CMD_SUCCESS;
9583}
9584
9585static int
9586bgp_table_stats_vty (struct vty *vty, const char *name,
9587 const char *afi_str, const char *safi_str)
9588{
9589 struct bgp *bgp;
9590 afi_t afi;
9591 safi_t safi;
9592
9593 if (name)
9594 bgp = bgp_lookup_by_name (name);
9595 else
9596 bgp = bgp_get_default ();
9597
9598 if (!bgp)
9599 {
9600 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9601 return CMD_WARNING;
9602 }
9603 if (strncmp (afi_str, "ipv", 3) == 0)
9604 {
9605 if (strncmp (afi_str, "ipv4", 4) == 0)
9606 afi = AFI_IP;
9607 else if (strncmp (afi_str, "ipv6", 4) == 0)
9608 afi = AFI_IP6;
9609 else
9610 {
9611 vty_out (vty, "%% Invalid address family %s%s",
9612 afi_str, VTY_NEWLINE);
9613 return CMD_WARNING;
9614 }
9615 if (strncmp (safi_str, "m", 1) == 0)
9616 safi = SAFI_MULTICAST;
9617 else if (strncmp (safi_str, "u", 1) == 0)
9618 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009619 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9620 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009621 else
9622 {
9623 vty_out (vty, "%% Invalid subsequent address family %s%s",
9624 safi_str, VTY_NEWLINE);
9625 return CMD_WARNING;
9626 }
9627 }
9628 else
9629 {
9630 vty_out (vty, "%% Invalid address family %s%s",
9631 afi_str, VTY_NEWLINE);
9632 return CMD_WARNING;
9633 }
9634
Paul Jakma2815e612006-09-14 02:56:07 +00009635 return bgp_table_stats (vty, bgp, afi, safi);
9636}
9637
9638DEFUN (show_bgp_statistics,
9639 show_bgp_statistics_cmd,
9640 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9641 SHOW_STR
9642 BGP_STR
9643 "Address family\n"
9644 "Address family\n"
9645 "Address Family modifier\n"
9646 "Address Family modifier\n"
9647 "BGP RIB advertisement statistics\n")
9648{
9649 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9650}
9651
9652ALIAS (show_bgp_statistics,
9653 show_bgp_statistics_vpnv4_cmd,
9654 "show bgp (ipv4) (vpnv4) statistics",
9655 SHOW_STR
9656 BGP_STR
9657 "Address family\n"
9658 "Address Family modifier\n"
9659 "BGP RIB advertisement statistics\n")
9660
9661DEFUN (show_bgp_statistics_view,
9662 show_bgp_statistics_view_cmd,
9663 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9664 SHOW_STR
9665 BGP_STR
9666 "BGP view\n"
9667 "Address family\n"
9668 "Address family\n"
9669 "Address Family modifier\n"
9670 "Address Family modifier\n"
9671 "BGP RIB advertisement statistics\n")
9672{
9673 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9674}
9675
9676ALIAS (show_bgp_statistics_view,
9677 show_bgp_statistics_view_vpnv4_cmd,
9678 "show bgp view WORD (ipv4) (vpnv4) statistics",
9679 SHOW_STR
9680 BGP_STR
9681 "BGP view\n"
9682 "Address family\n"
9683 "Address Family modifier\n"
9684 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02009685
Paul Jakmaff7924f2006-09-04 01:10:36 +00009686enum bgp_pcounts
9687{
9688 PCOUNT_ADJ_IN = 0,
9689 PCOUNT_DAMPED,
9690 PCOUNT_REMOVED,
9691 PCOUNT_HISTORY,
9692 PCOUNT_STALE,
9693 PCOUNT_VALID,
9694 PCOUNT_ALL,
9695 PCOUNT_COUNTED,
9696 PCOUNT_PFCNT, /* the figure we display to users */
9697 PCOUNT_MAX,
9698};
9699
9700static const char *pcount_strs[] =
9701{
9702 [PCOUNT_ADJ_IN] = "Adj-in",
9703 [PCOUNT_DAMPED] = "Damped",
9704 [PCOUNT_REMOVED] = "Removed",
9705 [PCOUNT_HISTORY] = "History",
9706 [PCOUNT_STALE] = "Stale",
9707 [PCOUNT_VALID] = "Valid",
9708 [PCOUNT_ALL] = "All RIB",
9709 [PCOUNT_COUNTED] = "PfxCt counted",
9710 [PCOUNT_PFCNT] = "Useable",
9711 [PCOUNT_MAX] = NULL,
9712};
9713
Paul Jakma2815e612006-09-14 02:56:07 +00009714struct peer_pcounts
9715{
9716 unsigned int count[PCOUNT_MAX];
9717 const struct peer *peer;
9718 const struct bgp_table *table;
9719};
9720
Paul Jakmaff7924f2006-09-04 01:10:36 +00009721static int
Paul Jakma2815e612006-09-14 02:56:07 +00009722bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009723{
9724 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009725 struct peer_pcounts *pc = THREAD_ARG (t);
9726 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009727
Paul Jakma2815e612006-09-14 02:56:07 +00009728 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009729 {
9730 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009731 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009732
9733 for (ain = rn->adj_in; ain; ain = ain->next)
9734 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009735 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009736
Paul Jakmaff7924f2006-09-04 01:10:36 +00009737 for (ri = rn->info; ri; ri = ri->next)
9738 {
9739 char buf[SU_ADDRSTRLEN];
9740
9741 if (ri->peer != peer)
9742 continue;
9743
Paul Jakma2815e612006-09-14 02:56:07 +00009744 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009745
9746 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009747 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009748 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009749 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009750 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009751 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009752 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009753 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009754 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009755 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009756 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009757 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009758
9759 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9760 {
Paul Jakma2815e612006-09-14 02:56:07 +00009761 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009762 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009763 plog_warn (peer->log,
9764 "%s [pcount] %s/%d is counted but flags 0x%x",
9765 peer->host,
9766 inet_ntop(rn->p.family, &rn->p.u.prefix,
9767 buf, SU_ADDRSTRLEN),
9768 rn->p.prefixlen,
9769 ri->flags);
9770 }
9771 else
9772 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009773 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009774 plog_warn (peer->log,
9775 "%s [pcount] %s/%d not counted but flags 0x%x",
9776 peer->host,
9777 inet_ntop(rn->p.family, &rn->p.u.prefix,
9778 buf, SU_ADDRSTRLEN),
9779 rn->p.prefixlen,
9780 ri->flags);
9781 }
9782 }
9783 }
Paul Jakma2815e612006-09-14 02:56:07 +00009784 return 0;
9785}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009786
Paul Jakma2815e612006-09-14 02:56:07 +00009787static int
9788bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9789{
9790 struct peer_pcounts pcounts = { .peer = peer };
9791 unsigned int i;
9792
9793 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9794 || !peer->bgp->rib[afi][safi])
9795 {
9796 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9797 return CMD_WARNING;
9798 }
9799
9800 memset (&pcounts, 0, sizeof(pcounts));
9801 pcounts.peer = peer;
9802 pcounts.table = peer->bgp->rib[afi][safi];
9803
9804 /* in-place call via thread subsystem so as to record execution time
9805 * stats for the thread-walk (i.e. ensure this can't be blamed on
9806 * on just vty_read()).
9807 */
9808 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9809
Paul Jakmaff7924f2006-09-04 01:10:36 +00009810 vty_out (vty, "Prefix counts for %s, %s%s",
9811 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9812 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9813 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9814 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9815
9816 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009817 vty_out (vty, "%20s: %-10d%s",
9818 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009819
Paul Jakma2815e612006-09-14 02:56:07 +00009820 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009821 {
9822 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9823 peer->host, VTY_NEWLINE);
9824 vty_out (vty, "Please report this bug, with the above command output%s",
9825 VTY_NEWLINE);
9826 }
9827
9828 return CMD_SUCCESS;
9829}
9830
9831DEFUN (show_ip_bgp_neighbor_prefix_counts,
9832 show_ip_bgp_neighbor_prefix_counts_cmd,
9833 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9834 SHOW_STR
9835 IP_STR
9836 BGP_STR
9837 "Detailed information on TCP and BGP neighbor connections\n"
9838 "Neighbor to display information about\n"
9839 "Neighbor to display information about\n"
9840 "Display detailed prefix count information\n")
9841{
9842 struct peer *peer;
9843
9844 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9845 if (! peer)
9846 return CMD_WARNING;
9847
9848 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9849}
9850
9851DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9852 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9853 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9854 SHOW_STR
9855 BGP_STR
9856 "Address family\n"
9857 "Detailed information on TCP and BGP neighbor connections\n"
9858 "Neighbor to display information about\n"
9859 "Neighbor to display information about\n"
9860 "Display detailed prefix count information\n")
9861{
9862 struct peer *peer;
9863
9864 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9865 if (! peer)
9866 return CMD_WARNING;
9867
9868 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9869}
9870
9871DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9872 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9873 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9874 SHOW_STR
9875 IP_STR
9876 BGP_STR
9877 "Address family\n"
9878 "Address Family modifier\n"
9879 "Address Family modifier\n"
9880 "Detailed information on TCP and BGP neighbor connections\n"
9881 "Neighbor to display information about\n"
9882 "Neighbor to display information about\n"
9883 "Display detailed prefix count information\n")
9884{
9885 struct peer *peer;
9886
9887 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9888 if (! peer)
9889 return CMD_WARNING;
9890
9891 if (strncmp (argv[0], "m", 1) == 0)
9892 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9893
9894 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9895}
9896
9897DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9898 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9899 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9900 SHOW_STR
9901 IP_STR
9902 BGP_STR
9903 "Address family\n"
9904 "Address Family modifier\n"
9905 "Address Family modifier\n"
9906 "Detailed information on TCP and BGP neighbor connections\n"
9907 "Neighbor to display information about\n"
9908 "Neighbor to display information about\n"
9909 "Display detailed prefix count information\n")
9910{
9911 struct peer *peer;
9912
9913 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9914 if (! peer)
9915 return CMD_WARNING;
9916
9917 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9918}
9919
9920
paul94f2b392005-06-28 12:44:16 +00009921static void
paul718e3742002-12-13 20:15:29 +00009922show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9923 int in)
9924{
9925 struct bgp_table *table;
9926 struct bgp_adj_in *ain;
9927 struct bgp_adj_out *adj;
9928 unsigned long output_count;
9929 struct bgp_node *rn;
9930 int header1 = 1;
9931 struct bgp *bgp;
9932 int header2 = 1;
9933
paulbb46e942003-10-24 19:02:03 +00009934 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009935
9936 if (! bgp)
9937 return;
9938
9939 table = bgp->rib[afi][safi];
9940
9941 output_count = 0;
9942
9943 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9944 PEER_STATUS_DEFAULT_ORIGINATE))
9945 {
9946 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 +00009947 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9948 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009949
9950 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9951 VTY_NEWLINE, VTY_NEWLINE);
9952 header1 = 0;
9953 }
9954
9955 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9956 if (in)
9957 {
9958 for (ain = rn->adj_in; ain; ain = ain->next)
9959 if (ain->peer == peer)
9960 {
9961 if (header1)
9962 {
9963 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 +00009964 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9965 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009966 header1 = 0;
9967 }
9968 if (header2)
9969 {
9970 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9971 header2 = 0;
9972 }
9973 if (ain->attr)
9974 {
9975 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9976 output_count++;
9977 }
9978 }
9979 }
9980 else
9981 {
9982 for (adj = rn->adj_out; adj; adj = adj->next)
9983 if (adj->peer == peer)
9984 {
9985 if (header1)
9986 {
9987 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 +00009988 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9989 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009990 header1 = 0;
9991 }
9992 if (header2)
9993 {
9994 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9995 header2 = 0;
9996 }
9997 if (adj->attr)
9998 {
9999 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
10000 output_count++;
10001 }
10002 }
10003 }
10004
10005 if (output_count != 0)
10006 vty_out (vty, "%sTotal number of prefixes %ld%s",
10007 VTY_NEWLINE, output_count, VTY_NEWLINE);
10008}
10009
paul94f2b392005-06-28 12:44:16 +000010010static int
paulbb46e942003-10-24 19:02:03 +000010011peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
10012{
paul718e3742002-12-13 20:15:29 +000010013 if (! peer || ! peer->afc[afi][safi])
10014 {
10015 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10016 return CMD_WARNING;
10017 }
10018
10019 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10020 {
10021 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
10022 VTY_NEWLINE);
10023 return CMD_WARNING;
10024 }
10025
10026 show_adj_route (vty, peer, afi, safi, in);
10027
10028 return CMD_SUCCESS;
10029}
10030
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010031DEFUN (show_ip_bgp_view_neighbor_advertised_route,
10032 show_ip_bgp_view_neighbor_advertised_route_cmd,
10033 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10034 SHOW_STR
10035 IP_STR
10036 BGP_STR
10037 "BGP view\n"
10038 "View name\n"
10039 "Detailed information on TCP and BGP neighbor connections\n"
10040 "Neighbor to display information about\n"
10041 "Neighbor to display information about\n"
10042 "Display the routes advertised to a BGP neighbor\n")
10043{
10044 struct peer *peer;
10045
10046 if (argc == 2)
10047 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10048 else
10049 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10050
10051 if (! peer)
10052 return CMD_WARNING;
10053
10054 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
10055}
10056
10057ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010058 show_ip_bgp_neighbor_advertised_route_cmd,
10059 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10060 SHOW_STR
10061 IP_STR
10062 BGP_STR
10063 "Detailed information on TCP and BGP neighbor connections\n"
10064 "Neighbor to display information about\n"
10065 "Neighbor to display information about\n"
10066 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +000010067
10068DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
10069 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
10070 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10071 SHOW_STR
10072 IP_STR
10073 BGP_STR
10074 "Address family\n"
10075 "Address Family modifier\n"
10076 "Address Family modifier\n"
10077 "Detailed information on TCP and BGP neighbor connections\n"
10078 "Neighbor to display information about\n"
10079 "Neighbor to display information about\n"
10080 "Display the routes advertised to a BGP neighbor\n")
10081{
paulbb46e942003-10-24 19:02:03 +000010082 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010083
paulbb46e942003-10-24 19:02:03 +000010084 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10085 if (! peer)
10086 return CMD_WARNING;
10087
10088 if (strncmp (argv[0], "m", 1) == 0)
10089 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
10090
10091 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +000010092}
10093
10094#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010095DEFUN (show_bgp_view_neighbor_advertised_route,
10096 show_bgp_view_neighbor_advertised_route_cmd,
10097 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10098 SHOW_STR
10099 BGP_STR
10100 "BGP view\n"
10101 "View name\n"
10102 "Detailed information on TCP and BGP neighbor connections\n"
10103 "Neighbor to display information about\n"
10104 "Neighbor to display information about\n"
10105 "Display the routes advertised to a BGP neighbor\n")
10106{
10107 struct peer *peer;
10108
10109 if (argc == 2)
10110 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10111 else
10112 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10113
10114 if (! peer)
10115 return CMD_WARNING;
10116
10117 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10118}
10119
10120ALIAS (show_bgp_view_neighbor_advertised_route,
10121 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10122 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10123 SHOW_STR
10124 BGP_STR
10125 "BGP view\n"
10126 "View name\n"
10127 "Address family\n"
10128 "Detailed information on TCP and BGP neighbor connections\n"
10129 "Neighbor to display information about\n"
10130 "Neighbor to display information about\n"
10131 "Display the routes advertised to a BGP neighbor\n")
10132
10133DEFUN (show_bgp_view_neighbor_received_routes,
10134 show_bgp_view_neighbor_received_routes_cmd,
10135 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10136 SHOW_STR
10137 BGP_STR
10138 "BGP view\n"
10139 "View name\n"
10140 "Detailed information on TCP and BGP neighbor connections\n"
10141 "Neighbor to display information about\n"
10142 "Neighbor to display information about\n"
10143 "Display the received routes from neighbor\n")
10144{
10145 struct peer *peer;
10146
10147 if (argc == 2)
10148 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10149 else
10150 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10151
10152 if (! peer)
10153 return CMD_WARNING;
10154
10155 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10156}
10157
10158ALIAS (show_bgp_view_neighbor_received_routes,
10159 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10160 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10161 SHOW_STR
10162 BGP_STR
10163 "BGP view\n"
10164 "View name\n"
10165 "Address family\n"
10166 "Detailed information on TCP and BGP neighbor connections\n"
10167 "Neighbor to display information about\n"
10168 "Neighbor to display information about\n"
10169 "Display the received routes from neighbor\n")
10170
10171ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010172 show_bgp_neighbor_advertised_route_cmd,
10173 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10174 SHOW_STR
10175 BGP_STR
10176 "Detailed information on TCP and BGP neighbor connections\n"
10177 "Neighbor to display information about\n"
10178 "Neighbor to display information about\n"
10179 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010180
10181ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010182 show_bgp_ipv6_neighbor_advertised_route_cmd,
10183 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10184 SHOW_STR
10185 BGP_STR
10186 "Address family\n"
10187 "Detailed information on TCP and BGP neighbor connections\n"
10188 "Neighbor to display information about\n"
10189 "Neighbor to display information about\n"
10190 "Display the routes advertised to a BGP neighbor\n")
10191
10192/* old command */
paulbb46e942003-10-24 19:02:03 +000010193ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010194 ipv6_bgp_neighbor_advertised_route_cmd,
10195 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10196 SHOW_STR
10197 IPV6_STR
10198 BGP_STR
10199 "Detailed information on TCP and BGP neighbor connections\n"
10200 "Neighbor to display information about\n"
10201 "Neighbor to display information about\n"
10202 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010203
paul718e3742002-12-13 20:15:29 +000010204/* old command */
10205DEFUN (ipv6_mbgp_neighbor_advertised_route,
10206 ipv6_mbgp_neighbor_advertised_route_cmd,
10207 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10208 SHOW_STR
10209 IPV6_STR
10210 MBGP_STR
10211 "Detailed information on TCP and BGP neighbor connections\n"
10212 "Neighbor to display information about\n"
10213 "Neighbor to display information about\n"
10214 "Display the routes advertised to a BGP neighbor\n")
10215{
paulbb46e942003-10-24 19:02:03 +000010216 struct peer *peer;
10217
10218 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10219 if (! peer)
10220 return CMD_WARNING;
10221
10222 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010223}
10224#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010225
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010226DEFUN (show_ip_bgp_view_neighbor_received_routes,
10227 show_ip_bgp_view_neighbor_received_routes_cmd,
10228 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10229 SHOW_STR
10230 IP_STR
10231 BGP_STR
10232 "BGP view\n"
10233 "View name\n"
10234 "Detailed information on TCP and BGP neighbor connections\n"
10235 "Neighbor to display information about\n"
10236 "Neighbor to display information about\n"
10237 "Display the received routes from neighbor\n")
10238{
10239 struct peer *peer;
10240
10241 if (argc == 2)
10242 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10243 else
10244 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10245
10246 if (! peer)
10247 return CMD_WARNING;
10248
10249 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10250}
10251
10252ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010253 show_ip_bgp_neighbor_received_routes_cmd,
10254 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10255 SHOW_STR
10256 IP_STR
10257 BGP_STR
10258 "Detailed information on TCP and BGP neighbor connections\n"
10259 "Neighbor to display information about\n"
10260 "Neighbor to display information about\n"
10261 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010262
10263DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10264 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10265 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10266 SHOW_STR
10267 IP_STR
10268 BGP_STR
10269 "Address family\n"
10270 "Address Family modifier\n"
10271 "Address Family modifier\n"
10272 "Detailed information on TCP and BGP neighbor connections\n"
10273 "Neighbor to display information about\n"
10274 "Neighbor to display information about\n"
10275 "Display the received routes from neighbor\n")
10276{
paulbb46e942003-10-24 19:02:03 +000010277 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010278
paulbb46e942003-10-24 19:02:03 +000010279 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10280 if (! peer)
10281 return CMD_WARNING;
10282
10283 if (strncmp (argv[0], "m", 1) == 0)
10284 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10285
10286 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010287}
10288
Michael Lambert95cbbd22010-07-23 14:43:04 -040010289DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10290 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010291 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
Michael Lambert95cbbd22010-07-23 14:43:04 -040010292 SHOW_STR
10293 BGP_STR
10294 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010295 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010296 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010297 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010298 "Address family modifier\n"
10299 "Address family modifier\n"
10300 "Detailed information on TCP and BGP neighbor connections\n"
10301 "Neighbor to display information about\n"
10302 "Neighbor to display information about\n"
10303 "Display the advertised routes to neighbor\n"
10304 "Display the received routes from neighbor\n")
10305{
10306 int afi;
10307 int safi;
10308 int in;
10309 struct peer *peer;
10310
David Lamparter94bad672015-03-03 08:52:22 +010010311 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010312
10313 if (! peer)
10314 return CMD_WARNING;
10315
Michael Lambert95cbbd22010-07-23 14:43:04 -040010316 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10317 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10318 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010319
10320 return peer_adj_routes (vty, peer, afi, safi, in);
10321}
10322
paul718e3742002-12-13 20:15:29 +000010323DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10324 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10325 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10326 SHOW_STR
10327 IP_STR
10328 BGP_STR
10329 "Detailed information on TCP and BGP neighbor connections\n"
10330 "Neighbor to display information about\n"
10331 "Neighbor to display information about\n"
10332 "Display information received from a BGP neighbor\n"
10333 "Display the prefixlist filter\n")
10334{
10335 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010336 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010337 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010338 int count, ret;
paul718e3742002-12-13 20:15:29 +000010339
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010340 ret = str2sockunion (argv[0], &su);
10341 if (ret < 0)
10342 {
10343 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10344 return CMD_WARNING;
10345 }
paul718e3742002-12-13 20:15:29 +000010346
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010347 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010348 if (! peer)
10349 return CMD_WARNING;
10350
10351 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10352 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10353 if (count)
10354 {
10355 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10356 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10357 }
10358
10359 return CMD_SUCCESS;
10360}
10361
10362DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10363 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10364 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10365 SHOW_STR
10366 IP_STR
10367 BGP_STR
10368 "Address family\n"
10369 "Address Family modifier\n"
10370 "Address Family modifier\n"
10371 "Detailed information on TCP and BGP neighbor connections\n"
10372 "Neighbor to display information about\n"
10373 "Neighbor to display information about\n"
10374 "Display information received from a BGP neighbor\n"
10375 "Display the prefixlist filter\n")
10376{
10377 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010378 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010379 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010380 int count, ret;
paul718e3742002-12-13 20:15:29 +000010381
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010382 ret = str2sockunion (argv[1], &su);
10383 if (ret < 0)
10384 {
10385 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10386 return CMD_WARNING;
10387 }
paul718e3742002-12-13 20:15:29 +000010388
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010389 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010390 if (! peer)
10391 return CMD_WARNING;
10392
10393 if (strncmp (argv[0], "m", 1) == 0)
10394 {
10395 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10396 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10397 if (count)
10398 {
10399 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10400 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10401 }
10402 }
10403 else
10404 {
10405 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10406 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10407 if (count)
10408 {
10409 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10410 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10411 }
10412 }
10413
10414 return CMD_SUCCESS;
10415}
10416
10417
10418#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010419ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010420 show_bgp_neighbor_received_routes_cmd,
10421 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10422 SHOW_STR
10423 BGP_STR
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 the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010428
paulbb46e942003-10-24 19:02:03 +000010429ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010430 show_bgp_ipv6_neighbor_received_routes_cmd,
10431 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10432 SHOW_STR
10433 BGP_STR
10434 "Address family\n"
10435 "Detailed information on TCP and BGP neighbor connections\n"
10436 "Neighbor to display information about\n"
10437 "Neighbor to display information about\n"
10438 "Display the received routes from neighbor\n")
10439
10440DEFUN (show_bgp_neighbor_received_prefix_filter,
10441 show_bgp_neighbor_received_prefix_filter_cmd,
10442 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10443 SHOW_STR
10444 BGP_STR
10445 "Detailed information on TCP and BGP neighbor connections\n"
10446 "Neighbor to display information about\n"
10447 "Neighbor to display information about\n"
10448 "Display information received from a BGP neighbor\n"
10449 "Display the prefixlist filter\n")
10450{
10451 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010452 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010453 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010454 int count, ret;
paul718e3742002-12-13 20:15:29 +000010455
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010456 ret = str2sockunion (argv[0], &su);
10457 if (ret < 0)
10458 {
10459 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10460 return CMD_WARNING;
10461 }
paul718e3742002-12-13 20:15:29 +000010462
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010463 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010464 if (! peer)
10465 return CMD_WARNING;
10466
10467 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10468 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10469 if (count)
10470 {
10471 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10472 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10473 }
10474
10475 return CMD_SUCCESS;
10476}
10477
10478ALIAS (show_bgp_neighbor_received_prefix_filter,
10479 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10480 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10481 SHOW_STR
10482 BGP_STR
10483 "Address family\n"
10484 "Detailed information on TCP and BGP neighbor connections\n"
10485 "Neighbor to display information about\n"
10486 "Neighbor to display information about\n"
10487 "Display information received from a BGP neighbor\n"
10488 "Display the prefixlist filter\n")
10489
10490/* old command */
paulbb46e942003-10-24 19:02:03 +000010491ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010492 ipv6_bgp_neighbor_received_routes_cmd,
10493 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10494 SHOW_STR
10495 IPV6_STR
10496 BGP_STR
10497 "Detailed information on TCP and BGP neighbor connections\n"
10498 "Neighbor to display information about\n"
10499 "Neighbor to display information about\n"
10500 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010501
10502/* old command */
10503DEFUN (ipv6_mbgp_neighbor_received_routes,
10504 ipv6_mbgp_neighbor_received_routes_cmd,
10505 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10506 SHOW_STR
10507 IPV6_STR
10508 MBGP_STR
10509 "Detailed information on TCP and BGP neighbor connections\n"
10510 "Neighbor to display information about\n"
10511 "Neighbor to display information about\n"
10512 "Display the received routes from neighbor\n")
10513{
paulbb46e942003-10-24 19:02:03 +000010514 struct peer *peer;
10515
10516 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10517 if (! peer)
10518 return CMD_WARNING;
10519
10520 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010521}
paulbb46e942003-10-24 19:02:03 +000010522
10523DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10524 show_bgp_view_neighbor_received_prefix_filter_cmd,
10525 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10526 SHOW_STR
10527 BGP_STR
10528 "BGP view\n"
10529 "View name\n"
10530 "Detailed information on TCP and BGP neighbor connections\n"
10531 "Neighbor to display information about\n"
10532 "Neighbor to display information about\n"
10533 "Display information received from a BGP neighbor\n"
10534 "Display the prefixlist filter\n")
10535{
10536 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010537 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010538 struct peer *peer;
10539 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010540 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010541
10542 /* BGP structure lookup. */
10543 bgp = bgp_lookup_by_name (argv[0]);
10544 if (bgp == NULL)
10545 {
10546 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10547 return CMD_WARNING;
10548 }
10549
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010550 ret = str2sockunion (argv[1], &su);
10551 if (ret < 0)
10552 {
10553 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10554 return CMD_WARNING;
10555 }
paulbb46e942003-10-24 19:02:03 +000010556
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010557 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010558 if (! peer)
10559 return CMD_WARNING;
10560
10561 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10562 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10563 if (count)
10564 {
10565 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10566 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10567 }
10568
10569 return CMD_SUCCESS;
10570}
10571
10572ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10573 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10574 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10575 SHOW_STR
10576 BGP_STR
10577 "BGP view\n"
10578 "View name\n"
10579 "Address family\n"
10580 "Detailed information on TCP and BGP neighbor connections\n"
10581 "Neighbor to display information about\n"
10582 "Neighbor to display information about\n"
10583 "Display information received from a BGP neighbor\n"
10584 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010585#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010586
paul94f2b392005-06-28 12:44:16 +000010587static int
paulbb46e942003-10-24 19:02:03 +000010588bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010589 safi_t safi, enum bgp_show_type type)
10590{
paul718e3742002-12-13 20:15:29 +000010591 if (! peer || ! peer->afc[afi][safi])
10592 {
10593 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010594 return CMD_WARNING;
10595 }
10596
ajs5a646652004-11-05 01:25:55 +000010597 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010598}
10599
10600DEFUN (show_ip_bgp_neighbor_routes,
10601 show_ip_bgp_neighbor_routes_cmd,
10602 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10603 SHOW_STR
10604 IP_STR
10605 BGP_STR
10606 "Detailed information on TCP and BGP neighbor connections\n"
10607 "Neighbor to display information about\n"
10608 "Neighbor to display information about\n"
10609 "Display routes learned from neighbor\n")
10610{
paulbb46e942003-10-24 19:02:03 +000010611 struct peer *peer;
10612
10613 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10614 if (! peer)
10615 return CMD_WARNING;
10616
10617 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010618 bgp_show_type_neighbor);
10619}
10620
10621DEFUN (show_ip_bgp_neighbor_flap,
10622 show_ip_bgp_neighbor_flap_cmd,
10623 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10624 SHOW_STR
10625 IP_STR
10626 BGP_STR
10627 "Detailed information on TCP and BGP neighbor connections\n"
10628 "Neighbor to display information about\n"
10629 "Neighbor to display information about\n"
10630 "Display flap statistics of the routes learned from neighbor\n")
10631{
paulbb46e942003-10-24 19:02:03 +000010632 struct peer *peer;
10633
10634 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10635 if (! peer)
10636 return CMD_WARNING;
10637
10638 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010639 bgp_show_type_flap_neighbor);
10640}
10641
10642DEFUN (show_ip_bgp_neighbor_damp,
10643 show_ip_bgp_neighbor_damp_cmd,
10644 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10645 SHOW_STR
10646 IP_STR
10647 BGP_STR
10648 "Detailed information on TCP and BGP neighbor connections\n"
10649 "Neighbor to display information about\n"
10650 "Neighbor to display information about\n"
10651 "Display the dampened routes received from neighbor\n")
10652{
paulbb46e942003-10-24 19:02:03 +000010653 struct peer *peer;
10654
10655 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10656 if (! peer)
10657 return CMD_WARNING;
10658
10659 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010660 bgp_show_type_damp_neighbor);
10661}
10662
10663DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10664 show_ip_bgp_ipv4_neighbor_routes_cmd,
10665 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10666 SHOW_STR
10667 IP_STR
10668 BGP_STR
10669 "Address family\n"
10670 "Address Family modifier\n"
10671 "Address Family modifier\n"
10672 "Detailed information on TCP and BGP neighbor connections\n"
10673 "Neighbor to display information about\n"
10674 "Neighbor to display information about\n"
10675 "Display routes learned from neighbor\n")
10676{
paulbb46e942003-10-24 19:02:03 +000010677 struct peer *peer;
10678
10679 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10680 if (! peer)
10681 return CMD_WARNING;
10682
paul718e3742002-12-13 20:15:29 +000010683 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010684 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010685 bgp_show_type_neighbor);
10686
paulbb46e942003-10-24 19:02:03 +000010687 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010688 bgp_show_type_neighbor);
10689}
paulbb46e942003-10-24 19:02:03 +000010690
paulfee0f4c2004-09-13 05:12:46 +000010691DEFUN (show_ip_bgp_view_rsclient,
10692 show_ip_bgp_view_rsclient_cmd,
10693 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10694 SHOW_STR
10695 IP_STR
10696 BGP_STR
10697 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010698 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010699 "Information about Route Server Client\n"
10700 NEIGHBOR_ADDR_STR)
10701{
10702 struct bgp_table *table;
10703 struct peer *peer;
10704
10705 if (argc == 2)
10706 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10707 else
10708 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10709
10710 if (! peer)
10711 return CMD_WARNING;
10712
10713 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10714 {
10715 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10716 VTY_NEWLINE);
10717 return CMD_WARNING;
10718 }
10719
10720 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10721 PEER_FLAG_RSERVER_CLIENT))
10722 {
10723 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10724 VTY_NEWLINE);
10725 return CMD_WARNING;
10726 }
10727
10728 table = peer->rib[AFI_IP][SAFI_UNICAST];
10729
ajs5a646652004-11-05 01:25:55 +000010730 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010731}
10732
10733ALIAS (show_ip_bgp_view_rsclient,
10734 show_ip_bgp_rsclient_cmd,
10735 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10736 SHOW_STR
10737 IP_STR
10738 BGP_STR
10739 "Information about Route Server Client\n"
10740 NEIGHBOR_ADDR_STR)
10741
Michael Lambert95cbbd22010-07-23 14:43:04 -040010742DEFUN (show_bgp_view_ipv4_safi_rsclient,
10743 show_bgp_view_ipv4_safi_rsclient_cmd,
10744 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10745 SHOW_STR
10746 BGP_STR
10747 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010748 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010749 "Address family\n"
10750 "Address Family modifier\n"
10751 "Address Family modifier\n"
10752 "Information about Route Server Client\n"
10753 NEIGHBOR_ADDR_STR)
10754{
10755 struct bgp_table *table;
10756 struct peer *peer;
10757 safi_t safi;
10758
10759 if (argc == 3) {
10760 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10761 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10762 } else {
10763 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10764 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10765 }
10766
10767 if (! peer)
10768 return CMD_WARNING;
10769
10770 if (! peer->afc[AFI_IP][safi])
10771 {
10772 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10773 VTY_NEWLINE);
10774 return CMD_WARNING;
10775 }
10776
10777 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10778 PEER_FLAG_RSERVER_CLIENT))
10779 {
10780 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10781 VTY_NEWLINE);
10782 return CMD_WARNING;
10783 }
10784
10785 table = peer->rib[AFI_IP][safi];
10786
10787 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10788}
10789
10790ALIAS (show_bgp_view_ipv4_safi_rsclient,
10791 show_bgp_ipv4_safi_rsclient_cmd,
10792 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10793 SHOW_STR
10794 BGP_STR
10795 "Address family\n"
10796 "Address Family modifier\n"
10797 "Address Family modifier\n"
10798 "Information about Route Server Client\n"
10799 NEIGHBOR_ADDR_STR)
10800
paulfee0f4c2004-09-13 05:12:46 +000010801DEFUN (show_ip_bgp_view_rsclient_route,
10802 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010803 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010804 SHOW_STR
10805 IP_STR
10806 BGP_STR
10807 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010808 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010809 "Information about Route Server Client\n"
10810 NEIGHBOR_ADDR_STR
10811 "Network in the BGP routing table to display\n")
10812{
10813 struct bgp *bgp;
10814 struct peer *peer;
10815
10816 /* BGP structure lookup. */
10817 if (argc == 3)
10818 {
10819 bgp = bgp_lookup_by_name (argv[0]);
10820 if (bgp == NULL)
10821 {
10822 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10823 return CMD_WARNING;
10824 }
10825 }
10826 else
10827 {
10828 bgp = bgp_get_default ();
10829 if (bgp == NULL)
10830 {
10831 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10832 return CMD_WARNING;
10833 }
10834 }
10835
10836 if (argc == 3)
10837 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10838 else
10839 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10840
10841 if (! peer)
10842 return CMD_WARNING;
10843
10844 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10845 {
10846 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10847 VTY_NEWLINE);
10848 return CMD_WARNING;
10849}
10850
10851 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10852 PEER_FLAG_RSERVER_CLIENT))
10853 {
10854 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10855 VTY_NEWLINE);
10856 return CMD_WARNING;
10857 }
10858
10859 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10860 (argc == 3) ? argv[2] : argv[1],
10861 AFI_IP, SAFI_UNICAST, NULL, 0);
10862}
10863
10864ALIAS (show_ip_bgp_view_rsclient_route,
10865 show_ip_bgp_rsclient_route_cmd,
10866 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10867 SHOW_STR
10868 IP_STR
10869 BGP_STR
10870 "Information about Route Server Client\n"
10871 NEIGHBOR_ADDR_STR
10872 "Network in the BGP routing table to display\n")
10873
Michael Lambert95cbbd22010-07-23 14:43:04 -040010874DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10875 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10876 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10877 SHOW_STR
10878 BGP_STR
10879 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010880 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010881 "Address family\n"
10882 "Address Family modifier\n"
10883 "Address Family modifier\n"
10884 "Information about Route Server Client\n"
10885 NEIGHBOR_ADDR_STR
10886 "Network in the BGP routing table to display\n")
10887{
10888 struct bgp *bgp;
10889 struct peer *peer;
10890 safi_t safi;
10891
10892 /* BGP structure lookup. */
10893 if (argc == 4)
10894 {
10895 bgp = bgp_lookup_by_name (argv[0]);
10896 if (bgp == NULL)
10897 {
10898 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10899 return CMD_WARNING;
10900 }
10901 }
10902 else
10903 {
10904 bgp = bgp_get_default ();
10905 if (bgp == NULL)
10906 {
10907 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10908 return CMD_WARNING;
10909 }
10910 }
10911
10912 if (argc == 4) {
10913 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10914 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10915 } else {
10916 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10917 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10918 }
10919
10920 if (! peer)
10921 return CMD_WARNING;
10922
10923 if (! peer->afc[AFI_IP][safi])
10924 {
10925 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10926 VTY_NEWLINE);
10927 return CMD_WARNING;
10928}
10929
10930 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10931 PEER_FLAG_RSERVER_CLIENT))
10932 {
10933 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10934 VTY_NEWLINE);
10935 return CMD_WARNING;
10936 }
10937
10938 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10939 (argc == 4) ? argv[3] : argv[2],
10940 AFI_IP, safi, NULL, 0);
10941}
10942
10943ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10944 show_bgp_ipv4_safi_rsclient_route_cmd,
10945 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10946 SHOW_STR
10947 BGP_STR
10948 "Address family\n"
10949 "Address Family modifier\n"
10950 "Address Family modifier\n"
10951 "Information about Route Server Client\n"
10952 NEIGHBOR_ADDR_STR
10953 "Network in the BGP routing table to display\n")
10954
paulfee0f4c2004-09-13 05:12:46 +000010955DEFUN (show_ip_bgp_view_rsclient_prefix,
10956 show_ip_bgp_view_rsclient_prefix_cmd,
10957 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10958 SHOW_STR
10959 IP_STR
10960 BGP_STR
10961 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010962 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010963 "Information about Route Server Client\n"
10964 NEIGHBOR_ADDR_STR
10965 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10966{
10967 struct bgp *bgp;
10968 struct peer *peer;
10969
10970 /* BGP structure lookup. */
10971 if (argc == 3)
10972 {
10973 bgp = bgp_lookup_by_name (argv[0]);
10974 if (bgp == NULL)
10975 {
10976 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10977 return CMD_WARNING;
10978 }
10979 }
10980 else
10981 {
10982 bgp = bgp_get_default ();
10983 if (bgp == NULL)
10984 {
10985 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10986 return CMD_WARNING;
10987 }
10988 }
10989
10990 if (argc == 3)
10991 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10992 else
10993 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10994
10995 if (! peer)
10996 return CMD_WARNING;
10997
10998 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10999 {
11000 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11001 VTY_NEWLINE);
11002 return CMD_WARNING;
11003}
11004
11005 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
11006 PEER_FLAG_RSERVER_CLIENT))
11007{
11008 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11009 VTY_NEWLINE);
11010 return CMD_WARNING;
11011 }
11012
11013 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
11014 (argc == 3) ? argv[2] : argv[1],
11015 AFI_IP, SAFI_UNICAST, NULL, 1);
11016}
11017
11018ALIAS (show_ip_bgp_view_rsclient_prefix,
11019 show_ip_bgp_rsclient_prefix_cmd,
11020 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11021 SHOW_STR
11022 IP_STR
11023 BGP_STR
11024 "Information about Route Server Client\n"
11025 NEIGHBOR_ADDR_STR
11026 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11027
Michael Lambert95cbbd22010-07-23 14:43:04 -040011028DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
11029 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
11030 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11031 SHOW_STR
11032 BGP_STR
11033 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011034 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011035 "Address family\n"
11036 "Address Family modifier\n"
11037 "Address Family modifier\n"
11038 "Information about Route Server Client\n"
11039 NEIGHBOR_ADDR_STR
11040 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11041{
11042 struct bgp *bgp;
11043 struct peer *peer;
11044 safi_t safi;
11045
11046 /* BGP structure lookup. */
11047 if (argc == 4)
11048 {
11049 bgp = bgp_lookup_by_name (argv[0]);
11050 if (bgp == NULL)
11051 {
11052 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11053 return CMD_WARNING;
11054 }
11055 }
11056 else
11057 {
11058 bgp = bgp_get_default ();
11059 if (bgp == NULL)
11060 {
11061 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11062 return CMD_WARNING;
11063 }
11064 }
11065
11066 if (argc == 4) {
11067 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11068 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11069 } else {
11070 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11071 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11072 }
11073
11074 if (! peer)
11075 return CMD_WARNING;
11076
11077 if (! peer->afc[AFI_IP][safi])
11078 {
11079 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11080 VTY_NEWLINE);
11081 return CMD_WARNING;
11082}
11083
11084 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11085 PEER_FLAG_RSERVER_CLIENT))
11086{
11087 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11088 VTY_NEWLINE);
11089 return CMD_WARNING;
11090 }
11091
11092 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11093 (argc == 4) ? argv[3] : argv[2],
11094 AFI_IP, safi, NULL, 1);
11095}
11096
11097ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11098 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11099 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11100 SHOW_STR
11101 BGP_STR
11102 "Address family\n"
11103 "Address Family modifier\n"
11104 "Address Family modifier\n"
11105 "Information about Route Server Client\n"
11106 NEIGHBOR_ADDR_STR
11107 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011108
paul718e3742002-12-13 20:15:29 +000011109#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011110DEFUN (show_bgp_view_neighbor_routes,
11111 show_bgp_view_neighbor_routes_cmd,
11112 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11113 SHOW_STR
11114 BGP_STR
11115 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011116 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011117 "Detailed information on TCP and BGP neighbor connections\n"
11118 "Neighbor to display information about\n"
11119 "Neighbor to display information about\n"
11120 "Display routes learned from neighbor\n")
11121{
11122 struct peer *peer;
11123
11124 if (argc == 2)
11125 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11126 else
11127 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11128
11129 if (! peer)
11130 return CMD_WARNING;
11131
11132 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11133 bgp_show_type_neighbor);
11134}
11135
11136ALIAS (show_bgp_view_neighbor_routes,
11137 show_bgp_view_ipv6_neighbor_routes_cmd,
11138 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11139 SHOW_STR
11140 BGP_STR
11141 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011142 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011143 "Address family\n"
11144 "Detailed information on TCP and BGP neighbor connections\n"
11145 "Neighbor to display information about\n"
11146 "Neighbor to display information about\n"
11147 "Display routes learned from neighbor\n")
11148
11149DEFUN (show_bgp_view_neighbor_damp,
11150 show_bgp_view_neighbor_damp_cmd,
11151 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11152 SHOW_STR
11153 BGP_STR
11154 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011155 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011156 "Detailed information on TCP and BGP neighbor connections\n"
11157 "Neighbor to display information about\n"
11158 "Neighbor to display information about\n"
11159 "Display the dampened routes received from neighbor\n")
11160{
11161 struct peer *peer;
11162
11163 if (argc == 2)
11164 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11165 else
11166 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11167
11168 if (! peer)
11169 return CMD_WARNING;
11170
11171 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11172 bgp_show_type_damp_neighbor);
11173}
11174
11175ALIAS (show_bgp_view_neighbor_damp,
11176 show_bgp_view_ipv6_neighbor_damp_cmd,
11177 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11178 SHOW_STR
11179 BGP_STR
11180 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011181 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011182 "Address family\n"
11183 "Detailed information on TCP and BGP neighbor connections\n"
11184 "Neighbor to display information about\n"
11185 "Neighbor to display information about\n"
11186 "Display the dampened routes received from neighbor\n")
11187
11188DEFUN (show_bgp_view_neighbor_flap,
11189 show_bgp_view_neighbor_flap_cmd,
11190 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11191 SHOW_STR
11192 BGP_STR
11193 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011194 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011195 "Detailed information on TCP and BGP neighbor connections\n"
11196 "Neighbor to display information about\n"
11197 "Neighbor to display information about\n"
11198 "Display flap statistics of the routes learned from neighbor\n")
11199{
11200 struct peer *peer;
11201
11202 if (argc == 2)
11203 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11204 else
11205 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11206
11207 if (! peer)
11208 return CMD_WARNING;
11209
11210 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11211 bgp_show_type_flap_neighbor);
11212}
11213
11214ALIAS (show_bgp_view_neighbor_flap,
11215 show_bgp_view_ipv6_neighbor_flap_cmd,
11216 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11217 SHOW_STR
11218 BGP_STR
11219 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011220 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011221 "Address family\n"
11222 "Detailed information on TCP and BGP neighbor connections\n"
11223 "Neighbor to display information about\n"
11224 "Neighbor to display information about\n"
11225 "Display flap statistics of the routes learned from neighbor\n")
11226
11227ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011228 show_bgp_neighbor_routes_cmd,
11229 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11230 SHOW_STR
11231 BGP_STR
11232 "Detailed information on TCP and BGP neighbor connections\n"
11233 "Neighbor to display information about\n"
11234 "Neighbor to display information about\n"
11235 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011236
paulbb46e942003-10-24 19:02:03 +000011237
11238ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011239 show_bgp_ipv6_neighbor_routes_cmd,
11240 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11241 SHOW_STR
11242 BGP_STR
11243 "Address family\n"
11244 "Detailed information on TCP and BGP neighbor connections\n"
11245 "Neighbor to display information about\n"
11246 "Neighbor to display information about\n"
11247 "Display routes learned from neighbor\n")
11248
11249/* old command */
paulbb46e942003-10-24 19:02:03 +000011250ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011251 ipv6_bgp_neighbor_routes_cmd,
11252 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11253 SHOW_STR
11254 IPV6_STR
11255 BGP_STR
11256 "Detailed information on TCP and BGP neighbor connections\n"
11257 "Neighbor to display information about\n"
11258 "Neighbor to display information about\n"
11259 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011260
11261/* old command */
11262DEFUN (ipv6_mbgp_neighbor_routes,
11263 ipv6_mbgp_neighbor_routes_cmd,
11264 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11265 SHOW_STR
11266 IPV6_STR
11267 MBGP_STR
11268 "Detailed information on TCP and BGP neighbor connections\n"
11269 "Neighbor to display information about\n"
11270 "Neighbor to display information about\n"
11271 "Display routes learned from neighbor\n")
11272{
paulbb46e942003-10-24 19:02:03 +000011273 struct peer *peer;
11274
11275 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11276 if (! peer)
11277 return CMD_WARNING;
11278
11279 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011280 bgp_show_type_neighbor);
11281}
paulbb46e942003-10-24 19:02:03 +000011282
11283ALIAS (show_bgp_view_neighbor_flap,
11284 show_bgp_neighbor_flap_cmd,
11285 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11286 SHOW_STR
11287 BGP_STR
11288 "Detailed information on TCP and BGP neighbor connections\n"
11289 "Neighbor to display information about\n"
11290 "Neighbor to display information about\n"
11291 "Display flap statistics of the routes learned from neighbor\n")
11292
11293ALIAS (show_bgp_view_neighbor_flap,
11294 show_bgp_ipv6_neighbor_flap_cmd,
11295 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11296 SHOW_STR
11297 BGP_STR
11298 "Address family\n"
11299 "Detailed information on TCP and BGP neighbor connections\n"
11300 "Neighbor to display information about\n"
11301 "Neighbor to display information about\n"
11302 "Display flap statistics of the routes learned from neighbor\n")
11303
11304ALIAS (show_bgp_view_neighbor_damp,
11305 show_bgp_neighbor_damp_cmd,
11306 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11307 SHOW_STR
11308 BGP_STR
11309 "Detailed information on TCP and BGP neighbor connections\n"
11310 "Neighbor to display information about\n"
11311 "Neighbor to display information about\n"
11312 "Display the dampened routes received from neighbor\n")
11313
11314ALIAS (show_bgp_view_neighbor_damp,
11315 show_bgp_ipv6_neighbor_damp_cmd,
11316 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11317 SHOW_STR
11318 BGP_STR
11319 "Address family\n"
11320 "Detailed information on TCP and BGP neighbor connections\n"
11321 "Neighbor to display information about\n"
11322 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011323 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011324
11325DEFUN (show_bgp_view_rsclient,
11326 show_bgp_view_rsclient_cmd,
11327 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11328 SHOW_STR
11329 BGP_STR
11330 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011331 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011332 "Information about Route Server Client\n"
11333 NEIGHBOR_ADDR_STR)
11334{
11335 struct bgp_table *table;
11336 struct peer *peer;
11337
11338 if (argc == 2)
11339 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11340 else
11341 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11342
11343 if (! peer)
11344 return CMD_WARNING;
11345
11346 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11347 {
11348 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11349 VTY_NEWLINE);
11350 return CMD_WARNING;
11351 }
11352
11353 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11354 PEER_FLAG_RSERVER_CLIENT))
11355 {
11356 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11357 VTY_NEWLINE);
11358 return CMD_WARNING;
11359 }
11360
11361 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11362
ajs5a646652004-11-05 01:25:55 +000011363 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011364}
11365
11366ALIAS (show_bgp_view_rsclient,
11367 show_bgp_rsclient_cmd,
11368 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11369 SHOW_STR
11370 BGP_STR
11371 "Information about Route Server Client\n"
11372 NEIGHBOR_ADDR_STR)
11373
Michael Lambert95cbbd22010-07-23 14:43:04 -040011374DEFUN (show_bgp_view_ipv6_safi_rsclient,
11375 show_bgp_view_ipv6_safi_rsclient_cmd,
11376 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11377 SHOW_STR
11378 BGP_STR
11379 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011380 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011381 "Address family\n"
11382 "Address Family modifier\n"
11383 "Address Family modifier\n"
11384 "Information about Route Server Client\n"
11385 NEIGHBOR_ADDR_STR)
11386{
11387 struct bgp_table *table;
11388 struct peer *peer;
11389 safi_t safi;
11390
11391 if (argc == 3) {
11392 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11393 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11394 } else {
11395 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11396 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11397 }
11398
11399 if (! peer)
11400 return CMD_WARNING;
11401
11402 if (! peer->afc[AFI_IP6][safi])
11403 {
11404 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11405 VTY_NEWLINE);
11406 return CMD_WARNING;
11407 }
11408
11409 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11410 PEER_FLAG_RSERVER_CLIENT))
11411 {
11412 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11413 VTY_NEWLINE);
11414 return CMD_WARNING;
11415 }
11416
11417 table = peer->rib[AFI_IP6][safi];
11418
11419 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11420}
11421
11422ALIAS (show_bgp_view_ipv6_safi_rsclient,
11423 show_bgp_ipv6_safi_rsclient_cmd,
11424 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11425 SHOW_STR
11426 BGP_STR
11427 "Address family\n"
11428 "Address Family modifier\n"
11429 "Address Family modifier\n"
11430 "Information about Route Server Client\n"
11431 NEIGHBOR_ADDR_STR)
11432
paulfee0f4c2004-09-13 05:12:46 +000011433DEFUN (show_bgp_view_rsclient_route,
11434 show_bgp_view_rsclient_route_cmd,
11435 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11436 SHOW_STR
11437 BGP_STR
11438 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011439 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011440 "Information about Route Server Client\n"
11441 NEIGHBOR_ADDR_STR
11442 "Network in the BGP routing table to display\n")
11443{
11444 struct bgp *bgp;
11445 struct peer *peer;
11446
11447 /* BGP structure lookup. */
11448 if (argc == 3)
11449 {
11450 bgp = bgp_lookup_by_name (argv[0]);
11451 if (bgp == NULL)
11452 {
11453 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11454 return CMD_WARNING;
11455 }
11456 }
11457 else
11458 {
11459 bgp = bgp_get_default ();
11460 if (bgp == NULL)
11461 {
11462 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11463 return CMD_WARNING;
11464 }
11465 }
11466
11467 if (argc == 3)
11468 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11469 else
11470 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11471
11472 if (! peer)
11473 return CMD_WARNING;
11474
11475 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11476 {
11477 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11478 VTY_NEWLINE);
11479 return CMD_WARNING;
11480 }
11481
11482 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11483 PEER_FLAG_RSERVER_CLIENT))
11484 {
11485 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11486 VTY_NEWLINE);
11487 return CMD_WARNING;
11488 }
11489
11490 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11491 (argc == 3) ? argv[2] : argv[1],
11492 AFI_IP6, SAFI_UNICAST, NULL, 0);
11493}
11494
11495ALIAS (show_bgp_view_rsclient_route,
11496 show_bgp_rsclient_route_cmd,
11497 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11498 SHOW_STR
11499 BGP_STR
11500 "Information about Route Server Client\n"
11501 NEIGHBOR_ADDR_STR
11502 "Network in the BGP routing table to display\n")
11503
Michael Lambert95cbbd22010-07-23 14:43:04 -040011504DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11505 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11506 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11507 SHOW_STR
11508 BGP_STR
11509 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011510 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011511 "Address family\n"
11512 "Address Family modifier\n"
11513 "Address Family modifier\n"
11514 "Information about Route Server Client\n"
11515 NEIGHBOR_ADDR_STR
11516 "Network in the BGP routing table to display\n")
11517{
11518 struct bgp *bgp;
11519 struct peer *peer;
11520 safi_t safi;
11521
11522 /* BGP structure lookup. */
11523 if (argc == 4)
11524 {
11525 bgp = bgp_lookup_by_name (argv[0]);
11526 if (bgp == NULL)
11527 {
11528 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11529 return CMD_WARNING;
11530 }
11531 }
11532 else
11533 {
11534 bgp = bgp_get_default ();
11535 if (bgp == NULL)
11536 {
11537 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11538 return CMD_WARNING;
11539 }
11540 }
11541
11542 if (argc == 4) {
11543 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11544 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11545 } else {
11546 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11547 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11548 }
11549
11550 if (! peer)
11551 return CMD_WARNING;
11552
11553 if (! peer->afc[AFI_IP6][safi])
11554 {
11555 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11556 VTY_NEWLINE);
11557 return CMD_WARNING;
11558}
11559
11560 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11561 PEER_FLAG_RSERVER_CLIENT))
11562 {
11563 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11564 VTY_NEWLINE);
11565 return CMD_WARNING;
11566 }
11567
11568 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11569 (argc == 4) ? argv[3] : argv[2],
11570 AFI_IP6, safi, NULL, 0);
11571}
11572
11573ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11574 show_bgp_ipv6_safi_rsclient_route_cmd,
11575 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11576 SHOW_STR
11577 BGP_STR
11578 "Address family\n"
11579 "Address Family modifier\n"
11580 "Address Family modifier\n"
11581 "Information about Route Server Client\n"
11582 NEIGHBOR_ADDR_STR
11583 "Network in the BGP routing table to display\n")
11584
paulfee0f4c2004-09-13 05:12:46 +000011585DEFUN (show_bgp_view_rsclient_prefix,
11586 show_bgp_view_rsclient_prefix_cmd,
11587 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11588 SHOW_STR
11589 BGP_STR
11590 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011591 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011592 "Information about Route Server Client\n"
11593 NEIGHBOR_ADDR_STR
11594 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11595{
11596 struct bgp *bgp;
11597 struct peer *peer;
11598
11599 /* BGP structure lookup. */
11600 if (argc == 3)
11601 {
11602 bgp = bgp_lookup_by_name (argv[0]);
11603 if (bgp == NULL)
11604 {
11605 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11606 return CMD_WARNING;
11607 }
11608 }
11609 else
11610 {
11611 bgp = bgp_get_default ();
11612 if (bgp == NULL)
11613 {
11614 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11615 return CMD_WARNING;
11616 }
11617 }
11618
11619 if (argc == 3)
11620 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11621 else
11622 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11623
11624 if (! peer)
11625 return CMD_WARNING;
11626
11627 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11628 {
11629 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11630 VTY_NEWLINE);
11631 return CMD_WARNING;
11632 }
11633
11634 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11635 PEER_FLAG_RSERVER_CLIENT))
11636 {
11637 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11638 VTY_NEWLINE);
11639 return CMD_WARNING;
11640 }
11641
11642 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11643 (argc == 3) ? argv[2] : argv[1],
11644 AFI_IP6, SAFI_UNICAST, NULL, 1);
11645}
11646
11647ALIAS (show_bgp_view_rsclient_prefix,
11648 show_bgp_rsclient_prefix_cmd,
11649 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11650 SHOW_STR
11651 BGP_STR
11652 "Information about Route Server Client\n"
11653 NEIGHBOR_ADDR_STR
11654 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11655
Michael Lambert95cbbd22010-07-23 14:43:04 -040011656DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11657 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11658 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11659 SHOW_STR
11660 BGP_STR
11661 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011662 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011663 "Address family\n"
11664 "Address Family modifier\n"
11665 "Address Family modifier\n"
11666 "Information about Route Server Client\n"
11667 NEIGHBOR_ADDR_STR
11668 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11669{
11670 struct bgp *bgp;
11671 struct peer *peer;
11672 safi_t safi;
11673
11674 /* BGP structure lookup. */
11675 if (argc == 4)
11676 {
11677 bgp = bgp_lookup_by_name (argv[0]);
11678 if (bgp == NULL)
11679 {
11680 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11681 return CMD_WARNING;
11682 }
11683 }
11684 else
11685 {
11686 bgp = bgp_get_default ();
11687 if (bgp == NULL)
11688 {
11689 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11690 return CMD_WARNING;
11691 }
11692 }
11693
11694 if (argc == 4) {
11695 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11696 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11697 } else {
11698 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11699 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11700 }
11701
11702 if (! peer)
11703 return CMD_WARNING;
11704
11705 if (! peer->afc[AFI_IP6][safi])
11706 {
11707 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11708 VTY_NEWLINE);
11709 return CMD_WARNING;
11710}
11711
11712 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11713 PEER_FLAG_RSERVER_CLIENT))
11714{
11715 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11716 VTY_NEWLINE);
11717 return CMD_WARNING;
11718 }
11719
11720 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11721 (argc == 4) ? argv[3] : argv[2],
11722 AFI_IP6, safi, NULL, 1);
11723}
11724
11725ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11726 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11727 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11728 SHOW_STR
11729 BGP_STR
11730 "Address family\n"
11731 "Address Family modifier\n"
11732 "Address Family modifier\n"
11733 "Information about Route Server Client\n"
11734 NEIGHBOR_ADDR_STR
11735 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11736
paul718e3742002-12-13 20:15:29 +000011737#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020011738
paul718e3742002-12-13 20:15:29 +000011739struct bgp_table *bgp_distance_table;
11740
11741struct bgp_distance
11742{
11743 /* Distance value for the IP source prefix. */
11744 u_char distance;
11745
11746 /* Name of the access-list to be matched. */
11747 char *access_list;
11748};
11749
paul94f2b392005-06-28 12:44:16 +000011750static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011751bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011752{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011753 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011754}
11755
paul94f2b392005-06-28 12:44:16 +000011756static void
paul718e3742002-12-13 20:15:29 +000011757bgp_distance_free (struct bgp_distance *bdistance)
11758{
11759 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11760}
11761
paul94f2b392005-06-28 12:44:16 +000011762static int
paulfd79ac92004-10-13 05:06:08 +000011763bgp_distance_set (struct vty *vty, const char *distance_str,
11764 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011765{
11766 int ret;
11767 struct prefix_ipv4 p;
11768 u_char distance;
11769 struct bgp_node *rn;
11770 struct bgp_distance *bdistance;
11771
11772 ret = str2prefix_ipv4 (ip_str, &p);
11773 if (ret == 0)
11774 {
11775 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11776 return CMD_WARNING;
11777 }
11778
11779 distance = atoi (distance_str);
11780
11781 /* Get BGP distance node. */
11782 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11783 if (rn->info)
11784 {
11785 bdistance = rn->info;
11786 bgp_unlock_node (rn);
11787 }
11788 else
11789 {
11790 bdistance = bgp_distance_new ();
11791 rn->info = bdistance;
11792 }
11793
11794 /* Set distance value. */
11795 bdistance->distance = distance;
11796
11797 /* Reset access-list configuration. */
11798 if (bdistance->access_list)
11799 {
11800 free (bdistance->access_list);
11801 bdistance->access_list = NULL;
11802 }
11803 if (access_list_str)
11804 bdistance->access_list = strdup (access_list_str);
11805
11806 return CMD_SUCCESS;
11807}
11808
paul94f2b392005-06-28 12:44:16 +000011809static int
paulfd79ac92004-10-13 05:06:08 +000011810bgp_distance_unset (struct vty *vty, const char *distance_str,
11811 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011812{
11813 int ret;
11814 struct prefix_ipv4 p;
11815 u_char distance;
11816 struct bgp_node *rn;
11817 struct bgp_distance *bdistance;
11818
11819 ret = str2prefix_ipv4 (ip_str, &p);
11820 if (ret == 0)
11821 {
11822 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11823 return CMD_WARNING;
11824 }
11825
11826 distance = atoi (distance_str);
11827
11828 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11829 if (! rn)
11830 {
11831 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11832 return CMD_WARNING;
11833 }
11834
11835 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010011836
11837 if (bdistance->distance != distance)
11838 {
11839 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
11840 return CMD_WARNING;
11841 }
11842
paul718e3742002-12-13 20:15:29 +000011843 if (bdistance->access_list)
11844 free (bdistance->access_list);
11845 bgp_distance_free (bdistance);
11846
11847 rn->info = NULL;
11848 bgp_unlock_node (rn);
11849 bgp_unlock_node (rn);
11850
11851 return CMD_SUCCESS;
11852}
11853
paul718e3742002-12-13 20:15:29 +000011854/* Apply BGP information to distance method. */
11855u_char
11856bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11857{
11858 struct bgp_node *rn;
11859 struct prefix_ipv4 q;
11860 struct peer *peer;
11861 struct bgp_distance *bdistance;
11862 struct access_list *alist;
11863 struct bgp_static *bgp_static;
11864
11865 if (! bgp)
11866 return 0;
11867
11868 if (p->family != AF_INET)
11869 return 0;
11870
11871 peer = rinfo->peer;
11872
11873 if (peer->su.sa.sa_family != AF_INET)
11874 return 0;
11875
11876 memset (&q, 0, sizeof (struct prefix_ipv4));
11877 q.family = AF_INET;
11878 q.prefix = peer->su.sin.sin_addr;
11879 q.prefixlen = IPV4_MAX_BITLEN;
11880
11881 /* Check source address. */
11882 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11883 if (rn)
11884 {
11885 bdistance = rn->info;
11886 bgp_unlock_node (rn);
11887
11888 if (bdistance->access_list)
11889 {
11890 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11891 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11892 return bdistance->distance;
11893 }
11894 else
11895 return bdistance->distance;
11896 }
11897
11898 /* Backdoor check. */
11899 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11900 if (rn)
11901 {
11902 bgp_static = rn->info;
11903 bgp_unlock_node (rn);
11904
11905 if (bgp_static->backdoor)
11906 {
11907 if (bgp->distance_local)
11908 return bgp->distance_local;
11909 else
11910 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11911 }
11912 }
11913
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011914 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011915 {
11916 if (bgp->distance_ebgp)
11917 return bgp->distance_ebgp;
11918 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11919 }
11920 else
11921 {
11922 if (bgp->distance_ibgp)
11923 return bgp->distance_ibgp;
11924 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11925 }
11926}
11927
11928DEFUN (bgp_distance,
11929 bgp_distance_cmd,
11930 "distance bgp <1-255> <1-255> <1-255>",
11931 "Define an administrative distance\n"
11932 "BGP distance\n"
11933 "Distance for routes external to the AS\n"
11934 "Distance for routes internal to the AS\n"
11935 "Distance for local routes\n")
11936{
11937 struct bgp *bgp;
11938
11939 bgp = vty->index;
11940
11941 bgp->distance_ebgp = atoi (argv[0]);
11942 bgp->distance_ibgp = atoi (argv[1]);
11943 bgp->distance_local = atoi (argv[2]);
11944 return CMD_SUCCESS;
11945}
11946
11947DEFUN (no_bgp_distance,
11948 no_bgp_distance_cmd,
11949 "no distance bgp <1-255> <1-255> <1-255>",
11950 NO_STR
11951 "Define an administrative distance\n"
11952 "BGP distance\n"
11953 "Distance for routes external to the AS\n"
11954 "Distance for routes internal to the AS\n"
11955 "Distance for local routes\n")
11956{
11957 struct bgp *bgp;
11958
11959 bgp = vty->index;
11960
11961 bgp->distance_ebgp= 0;
11962 bgp->distance_ibgp = 0;
11963 bgp->distance_local = 0;
11964 return CMD_SUCCESS;
11965}
11966
11967ALIAS (no_bgp_distance,
11968 no_bgp_distance2_cmd,
11969 "no distance bgp",
11970 NO_STR
11971 "Define an administrative distance\n"
11972 "BGP distance\n")
11973
11974DEFUN (bgp_distance_source,
11975 bgp_distance_source_cmd,
11976 "distance <1-255> A.B.C.D/M",
11977 "Define an administrative distance\n"
11978 "Administrative distance\n"
11979 "IP source prefix\n")
11980{
11981 bgp_distance_set (vty, argv[0], argv[1], NULL);
11982 return CMD_SUCCESS;
11983}
11984
11985DEFUN (no_bgp_distance_source,
11986 no_bgp_distance_source_cmd,
11987 "no distance <1-255> A.B.C.D/M",
11988 NO_STR
11989 "Define an administrative distance\n"
11990 "Administrative distance\n"
11991 "IP source prefix\n")
11992{
11993 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11994 return CMD_SUCCESS;
11995}
11996
11997DEFUN (bgp_distance_source_access_list,
11998 bgp_distance_source_access_list_cmd,
11999 "distance <1-255> A.B.C.D/M WORD",
12000 "Define an administrative distance\n"
12001 "Administrative distance\n"
12002 "IP source prefix\n"
12003 "Access list name\n")
12004{
12005 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
12006 return CMD_SUCCESS;
12007}
12008
12009DEFUN (no_bgp_distance_source_access_list,
12010 no_bgp_distance_source_access_list_cmd,
12011 "no distance <1-255> A.B.C.D/M WORD",
12012 NO_STR
12013 "Define an administrative distance\n"
12014 "Administrative distance\n"
12015 "IP source prefix\n"
12016 "Access list name\n")
12017{
12018 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
12019 return CMD_SUCCESS;
12020}
David Lamparter6b0655a2014-06-04 06:53:35 +020012021
paul718e3742002-12-13 20:15:29 +000012022DEFUN (bgp_damp_set,
12023 bgp_damp_set_cmd,
12024 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12025 "BGP Specific commands\n"
12026 "Enable route-flap dampening\n"
12027 "Half-life time for the penalty\n"
12028 "Value to start reusing a route\n"
12029 "Value to start suppressing a route\n"
12030 "Maximum duration to suppress a stable route\n")
12031{
12032 struct bgp *bgp;
12033 int half = DEFAULT_HALF_LIFE * 60;
12034 int reuse = DEFAULT_REUSE;
12035 int suppress = DEFAULT_SUPPRESS;
12036 int max = 4 * half;
12037
12038 if (argc == 4)
12039 {
12040 half = atoi (argv[0]) * 60;
12041 reuse = atoi (argv[1]);
12042 suppress = atoi (argv[2]);
12043 max = atoi (argv[3]) * 60;
12044 }
12045 else if (argc == 1)
12046 {
12047 half = atoi (argv[0]) * 60;
12048 max = 4 * half;
12049 }
12050
12051 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000012052
12053 if (suppress < reuse)
12054 {
12055 vty_out (vty, "Suppress value cannot be less than reuse value %s",
12056 VTY_NEWLINE);
12057 return 0;
12058 }
12059
paul718e3742002-12-13 20:15:29 +000012060 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
12061 half, reuse, suppress, max);
12062}
12063
12064ALIAS (bgp_damp_set,
12065 bgp_damp_set2_cmd,
12066 "bgp dampening <1-45>",
12067 "BGP Specific commands\n"
12068 "Enable route-flap dampening\n"
12069 "Half-life time for the penalty\n")
12070
12071ALIAS (bgp_damp_set,
12072 bgp_damp_set3_cmd,
12073 "bgp dampening",
12074 "BGP Specific commands\n"
12075 "Enable route-flap dampening\n")
12076
12077DEFUN (bgp_damp_unset,
12078 bgp_damp_unset_cmd,
12079 "no bgp dampening",
12080 NO_STR
12081 "BGP Specific commands\n"
12082 "Enable route-flap dampening\n")
12083{
12084 struct bgp *bgp;
12085
12086 bgp = vty->index;
12087 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
12088}
12089
12090ALIAS (bgp_damp_unset,
12091 bgp_damp_unset2_cmd,
12092 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12093 NO_STR
12094 "BGP Specific commands\n"
12095 "Enable route-flap dampening\n"
12096 "Half-life time for the penalty\n"
12097 "Value to start reusing a route\n"
12098 "Value to start suppressing a route\n"
12099 "Maximum duration to suppress a stable route\n")
12100
12101DEFUN (show_ip_bgp_dampened_paths,
12102 show_ip_bgp_dampened_paths_cmd,
12103 "show ip bgp dampened-paths",
12104 SHOW_STR
12105 IP_STR
12106 BGP_STR
12107 "Display paths suppressed due to dampening\n")
12108{
ajs5a646652004-11-05 01:25:55 +000012109 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
12110 NULL);
paul718e3742002-12-13 20:15:29 +000012111}
12112
Balaji3921cc52015-05-16 23:12:17 +053012113ALIAS (show_ip_bgp_dampened_paths,
12114 show_ip_bgp_damp_dampened_paths_cmd,
12115 "show ip bgp dampening dampened-paths",
12116 SHOW_STR
12117 IP_STR
12118 BGP_STR
12119 "Display detailed information about dampening\n"
12120 "Display paths suppressed due to dampening\n")
12121
paul718e3742002-12-13 20:15:29 +000012122DEFUN (show_ip_bgp_flap_statistics,
12123 show_ip_bgp_flap_statistics_cmd,
12124 "show ip bgp flap-statistics",
12125 SHOW_STR
12126 IP_STR
12127 BGP_STR
12128 "Display flap statistics of routes\n")
12129{
ajs5a646652004-11-05 01:25:55 +000012130 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12131 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012132}
David Lamparter6b0655a2014-06-04 06:53:35 +020012133
Balaji3921cc52015-05-16 23:12:17 +053012134ALIAS (show_ip_bgp_flap_statistics,
12135 show_ip_bgp_damp_flap_statistics_cmd,
12136 "show ip bgp dampening flap-statistics",
12137 SHOW_STR
12138 IP_STR
12139 BGP_STR
12140 "Display detailed information about dampening\n"
12141 "Display flap statistics of routes\n")
12142
paul718e3742002-12-13 20:15:29 +000012143/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012144static int
paulfd79ac92004-10-13 05:06:08 +000012145bgp_clear_damp_route (struct vty *vty, const char *view_name,
12146 const char *ip_str, afi_t afi, safi_t safi,
12147 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012148{
12149 int ret;
12150 struct prefix match;
12151 struct bgp_node *rn;
12152 struct bgp_node *rm;
12153 struct bgp_info *ri;
12154 struct bgp_info *ri_temp;
12155 struct bgp *bgp;
12156 struct bgp_table *table;
12157
12158 /* BGP structure lookup. */
12159 if (view_name)
12160 {
12161 bgp = bgp_lookup_by_name (view_name);
12162 if (bgp == NULL)
12163 {
12164 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12165 return CMD_WARNING;
12166 }
12167 }
12168 else
12169 {
12170 bgp = bgp_get_default ();
12171 if (bgp == NULL)
12172 {
12173 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12174 return CMD_WARNING;
12175 }
12176 }
12177
12178 /* Check IP address argument. */
12179 ret = str2prefix (ip_str, &match);
12180 if (! ret)
12181 {
12182 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12183 return CMD_WARNING;
12184 }
12185
12186 match.family = afi2family (afi);
12187
12188 if (safi == SAFI_MPLS_VPN)
12189 {
12190 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12191 {
12192 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12193 continue;
12194
12195 if ((table = rn->info) != NULL)
12196 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012197 {
12198 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12199 {
12200 ri = rm->info;
12201 while (ri)
12202 {
12203 if (ri->extra && ri->extra->damp_info)
12204 {
12205 ri_temp = ri->next;
12206 bgp_damp_info_free (ri->extra->damp_info, 1);
12207 ri = ri_temp;
12208 }
12209 else
12210 ri = ri->next;
12211 }
12212 }
12213
12214 bgp_unlock_node (rm);
12215 }
paul718e3742002-12-13 20:15:29 +000012216 }
12217 }
12218 else
12219 {
12220 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012221 {
12222 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12223 {
12224 ri = rn->info;
12225 while (ri)
12226 {
12227 if (ri->extra && ri->extra->damp_info)
12228 {
12229 ri_temp = ri->next;
12230 bgp_damp_info_free (ri->extra->damp_info, 1);
12231 ri = ri_temp;
12232 }
12233 else
12234 ri = ri->next;
12235 }
12236 }
12237
12238 bgp_unlock_node (rn);
12239 }
paul718e3742002-12-13 20:15:29 +000012240 }
12241
12242 return CMD_SUCCESS;
12243}
12244
12245DEFUN (clear_ip_bgp_dampening,
12246 clear_ip_bgp_dampening_cmd,
12247 "clear ip bgp dampening",
12248 CLEAR_STR
12249 IP_STR
12250 BGP_STR
12251 "Clear route flap dampening information\n")
12252{
12253 bgp_damp_info_clean ();
12254 return CMD_SUCCESS;
12255}
12256
12257DEFUN (clear_ip_bgp_dampening_prefix,
12258 clear_ip_bgp_dampening_prefix_cmd,
12259 "clear ip bgp dampening A.B.C.D/M",
12260 CLEAR_STR
12261 IP_STR
12262 BGP_STR
12263 "Clear route flap dampening information\n"
12264 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12265{
12266 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12267 SAFI_UNICAST, NULL, 1);
12268}
12269
12270DEFUN (clear_ip_bgp_dampening_address,
12271 clear_ip_bgp_dampening_address_cmd,
12272 "clear ip bgp dampening A.B.C.D",
12273 CLEAR_STR
12274 IP_STR
12275 BGP_STR
12276 "Clear route flap dampening information\n"
12277 "Network to clear damping information\n")
12278{
12279 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12280 SAFI_UNICAST, NULL, 0);
12281}
12282
12283DEFUN (clear_ip_bgp_dampening_address_mask,
12284 clear_ip_bgp_dampening_address_mask_cmd,
12285 "clear ip bgp dampening A.B.C.D A.B.C.D",
12286 CLEAR_STR
12287 IP_STR
12288 BGP_STR
12289 "Clear route flap dampening information\n"
12290 "Network to clear damping information\n"
12291 "Network mask\n")
12292{
12293 int ret;
12294 char prefix_str[BUFSIZ];
12295
12296 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12297 if (! ret)
12298 {
12299 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12300 return CMD_WARNING;
12301 }
12302
12303 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12304 SAFI_UNICAST, NULL, 0);
12305}
David Lamparter6b0655a2014-06-04 06:53:35 +020012306
paul94f2b392005-06-28 12:44:16 +000012307static int
paul718e3742002-12-13 20:15:29 +000012308bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12309 afi_t afi, safi_t safi, int *write)
12310{
12311 struct bgp_node *prn;
12312 struct bgp_node *rn;
12313 struct bgp_table *table;
12314 struct prefix *p;
12315 struct prefix_rd *prd;
12316 struct bgp_static *bgp_static;
12317 u_int32_t label;
12318 char buf[SU_ADDRSTRLEN];
12319 char rdbuf[RD_ADDRSTRLEN];
12320
12321 /* Network configuration. */
12322 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12323 if ((table = prn->info) != NULL)
12324 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12325 if ((bgp_static = rn->info) != NULL)
12326 {
12327 p = &rn->p;
12328 prd = (struct prefix_rd *) &prn->p;
12329
12330 /* "address-family" display. */
12331 bgp_config_write_family_header (vty, afi, safi, write);
12332
12333 /* "network" configuration display. */
12334 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12335 label = decode_label (bgp_static->tag);
12336
12337 vty_out (vty, " network %s/%d rd %s tag %d",
12338 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12339 p->prefixlen,
12340 rdbuf, label);
12341 vty_out (vty, "%s", VTY_NEWLINE);
12342 }
12343 return 0;
12344}
12345
12346/* Configuration of static route announcement and aggregate
12347 information. */
12348int
12349bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12350 afi_t afi, safi_t safi, int *write)
12351{
12352 struct bgp_node *rn;
12353 struct prefix *p;
12354 struct bgp_static *bgp_static;
12355 struct bgp_aggregate *bgp_aggregate;
12356 char buf[SU_ADDRSTRLEN];
12357
12358 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12359 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12360
12361 /* Network configuration. */
12362 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12363 if ((bgp_static = rn->info) != NULL)
12364 {
12365 p = &rn->p;
12366
12367 /* "address-family" display. */
12368 bgp_config_write_family_header (vty, afi, safi, write);
12369
12370 /* "network" configuration display. */
12371 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12372 {
12373 u_int32_t destination;
12374 struct in_addr netmask;
12375
12376 destination = ntohl (p->u.prefix4.s_addr);
12377 masklen2ip (p->prefixlen, &netmask);
12378 vty_out (vty, " network %s",
12379 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12380
12381 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12382 || (IN_CLASSB (destination) && p->prefixlen == 16)
12383 || (IN_CLASSA (destination) && p->prefixlen == 8)
12384 || p->u.prefix4.s_addr == 0)
12385 {
12386 /* Natural mask is not display. */
12387 }
12388 else
12389 vty_out (vty, " mask %s", inet_ntoa (netmask));
12390 }
12391 else
12392 {
12393 vty_out (vty, " network %s/%d",
12394 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12395 p->prefixlen);
12396 }
12397
12398 if (bgp_static->rmap.name)
12399 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012400 else
12401 {
12402 if (bgp_static->backdoor)
12403 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012404 }
paul718e3742002-12-13 20:15:29 +000012405
12406 vty_out (vty, "%s", VTY_NEWLINE);
12407 }
12408
12409 /* Aggregate-address configuration. */
12410 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12411 if ((bgp_aggregate = rn->info) != NULL)
12412 {
12413 p = &rn->p;
12414
12415 /* "address-family" display. */
12416 bgp_config_write_family_header (vty, afi, safi, write);
12417
12418 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12419 {
12420 struct in_addr netmask;
12421
12422 masklen2ip (p->prefixlen, &netmask);
12423 vty_out (vty, " aggregate-address %s %s",
12424 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12425 inet_ntoa (netmask));
12426 }
12427 else
12428 {
12429 vty_out (vty, " aggregate-address %s/%d",
12430 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12431 p->prefixlen);
12432 }
12433
12434 if (bgp_aggregate->as_set)
12435 vty_out (vty, " as-set");
12436
12437 if (bgp_aggregate->summary_only)
12438 vty_out (vty, " summary-only");
12439
12440 vty_out (vty, "%s", VTY_NEWLINE);
12441 }
12442
12443 return 0;
12444}
12445
12446int
12447bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12448{
12449 struct bgp_node *rn;
12450 struct bgp_distance *bdistance;
12451
12452 /* Distance configuration. */
12453 if (bgp->distance_ebgp
12454 && bgp->distance_ibgp
12455 && bgp->distance_local
12456 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12457 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12458 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12459 vty_out (vty, " distance bgp %d %d %d%s",
12460 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12461 VTY_NEWLINE);
12462
12463 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12464 if ((bdistance = rn->info) != NULL)
12465 {
12466 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12467 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12468 bdistance->access_list ? bdistance->access_list : "",
12469 VTY_NEWLINE);
12470 }
12471
12472 return 0;
12473}
12474
12475/* Allocate routing table structure and install commands. */
12476void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012477bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012478{
12479 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012480 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012481
12482 /* IPv4 BGP commands. */
12483 install_element (BGP_NODE, &bgp_network_cmd);
12484 install_element (BGP_NODE, &bgp_network_mask_cmd);
12485 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12486 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12487 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12488 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12489 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12490 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12491 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12492 install_element (BGP_NODE, &no_bgp_network_cmd);
12493 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12494 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12495 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12496 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12497 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12498 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12499 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12500 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12501
12502 install_element (BGP_NODE, &aggregate_address_cmd);
12503 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12504 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12505 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12506 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12507 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12508 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12509 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12510 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12511 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12512 install_element (BGP_NODE, &no_aggregate_address_cmd);
12513 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12514 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12515 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12516 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12517 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12518 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12519 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12520 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12521 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12522
12523 /* IPv4 unicast configuration. */
12524 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12525 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12526 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12527 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12528 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12529 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012530 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012531 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12532 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12533 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12534 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12535 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012536
paul718e3742002-12-13 20:15:29 +000012537 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12538 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12539 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12540 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12541 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12542 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12543 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12544 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12545 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12546 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12547 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12548 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12549 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12550 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12551 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12552 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12553 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12554 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12555 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12556 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12557
12558 /* IPv4 multicast configuration. */
12559 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12560 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12561 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12562 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12563 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12564 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12565 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12566 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12567 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12568 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12569 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12570 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12571 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12572 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12573 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12574 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12575 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12576 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12577 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12578 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12579 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12580 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12581 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12582 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12583 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12584 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12585 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12586 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12587 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12588 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12589 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12590 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12591
12592 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12593 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012594 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012595 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12596 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012597 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012598 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12599 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12600 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12601 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012602 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012603 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12604 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12605 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12606 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12607 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12608 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12609 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12610 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12611 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12612 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12613 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12614 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12615 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12616 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12617 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12618 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12619 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12620 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12621 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12622 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12623 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12624 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12625 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12626 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12627 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012628 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12629 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12630 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12631 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12632 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012633 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12634 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12635 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12636 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12637 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12638 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12639 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12640 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12641 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12642 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12643 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12644 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12645 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12646 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12647 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12648 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12649 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12650 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012651 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012652 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12653 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12654 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12655 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012656 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
paul718e3742002-12-13 20:15:29 +000012657 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012658 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
paul718e3742002-12-13 20:15:29 +000012659 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012660 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
paul718e3742002-12-13 20:15:29 +000012661 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012662 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
paul718e3742002-12-13 20:15:29 +000012663 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12664 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012665 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
paul718e3742002-12-13 20:15:29 +000012666 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12667 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012668 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000012669 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012670 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000012671 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012672 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000012673 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012674 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
paul718e3742002-12-13 20:15:29 +000012675 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12676 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012677 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012678 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012679 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012680 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012681 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012682 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012683 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12684 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012685 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012686 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012687 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012688 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012689 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012690 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012691
12692 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12693 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12694 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012695 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012696 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12697 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12698 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012699 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012700 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12701 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12702 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12703 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12704 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12705 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12706 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12707 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12708 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12709 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12710 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12711 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012712 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12713 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12714 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12715 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12716 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012717 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12718 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12719 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12720 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12721 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12722 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12723 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12724 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12725 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012726 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012727 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012728 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012729 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012730 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012731 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012732 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012733
12734 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12735 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012736 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012737 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12738 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012739 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012740 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12741 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12742 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12743 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012744 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012745 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12746 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12747 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12748 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12749 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12750 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12751 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12752 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12753 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12754 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12755 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12756 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12757 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12758 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12759 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12760 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12761 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12762 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12763 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12764 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12765 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12766 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12767 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12768 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12769 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012770 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12771 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12772 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12773 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12774 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012775 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12776 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12777 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12778 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12779 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12780 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12781 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12782 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12783 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12784 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12785 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12786 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12787 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12788 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12789 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12790 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12791 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12792 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012793 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012794 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12795 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12796 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12797 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012798 install_element (ENABLE_NODE, &show_ip_bgp_dampening_params_cmd);
paul718e3742002-12-13 20:15:29 +000012799 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012800 install_element (ENABLE_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
paul718e3742002-12-13 20:15:29 +000012801 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012802 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
paul718e3742002-12-13 20:15:29 +000012803 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012804 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_address_cmd);
paul718e3742002-12-13 20:15:29 +000012805 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12806 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012807 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
paul718e3742002-12-13 20:15:29 +000012808 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012809 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_regexp_cmd);
paul718e3742002-12-13 20:15:29 +000012810 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012811 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000012812 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012813 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
12814 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000012815 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012816 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000012817 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012818 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
paul718e3742002-12-13 20:15:29 +000012819 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12820 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012821 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012822 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012823 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012824 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012825 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012826 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012827 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12828 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012829 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012830 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012831 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012832 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012833 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012834 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012835
12836 /* BGP dampening clear commands */
12837 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12838 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12839 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12840 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12841
Paul Jakmaff7924f2006-09-04 01:10:36 +000012842 /* prefix count */
12843 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12844 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12845 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012846#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012847 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12848
paul718e3742002-12-13 20:15:29 +000012849 /* New config IPv6 BGP commands. */
12850 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12851 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12852 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12853 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12854
12855 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12856 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12857 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12858 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12859
G.Balaji73bfe0b2011-09-23 22:36:20 +053012860 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12861 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12862
paul718e3742002-12-13 20:15:29 +000012863 /* Old config IPv6 BGP commands. */
12864 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12865 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12866
12867 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12868 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12869 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12870 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12871
12872 install_element (VIEW_NODE, &show_bgp_cmd);
12873 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012874 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012875 install_element (VIEW_NODE, &show_bgp_route_cmd);
12876 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012877 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012878 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12879 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012880 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012881 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12882 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12883 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12884 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12885 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12886 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12887 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12888 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12889 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12890 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12891 install_element (VIEW_NODE, &show_bgp_community_cmd);
12892 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12893 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12894 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12895 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12896 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12897 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12898 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12899 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12900 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12901 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12902 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12903 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12904 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12905 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12906 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12907 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12908 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12909 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12910 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12911 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12912 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12913 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12914 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12915 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12916 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12917 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12918 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12919 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12920 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012921 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12922 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12923 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12924 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012925 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012926 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012927 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012928 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012929 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012930 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012931 install_element (VIEW_NODE, &show_bgp_view_cmd);
12932 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12933 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12934 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12935 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12936 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12937 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12938 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12939 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12940 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12941 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12942 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12943 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12944 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12945 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12946 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12947 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12948 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012949 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012950 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012951 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012952 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012953 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012954 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012955
12956 /* Restricted:
12957 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12958 */
12959 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12960 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012961 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012962 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12963 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012964 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012965 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12966 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12967 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12968 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12969 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12970 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12971 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12972 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12973 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12974 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12975 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12976 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12977 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12978 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12979 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12980 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12981 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012982 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012983 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012984 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012985 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12986 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12987 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12988 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12989 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12990 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12991 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012992 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012993 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012994 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012995
12996 install_element (ENABLE_NODE, &show_bgp_cmd);
12997 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012998 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012999 install_element (ENABLE_NODE, &show_bgp_route_cmd);
13000 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013001 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000013002 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
13003 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013004 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013005 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
13006 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
13007 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
13008 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
13009 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
13010 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
13011 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
13012 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
13013 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
13014 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
13015 install_element (ENABLE_NODE, &show_bgp_community_cmd);
13016 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
13017 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
13018 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
13019 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
13020 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
13021 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
13022 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
13023 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
13024 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
13025 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
13026 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
13027 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
13028 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
13029 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
13030 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
13031 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
13032 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
13033 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
13034 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
13035 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
13036 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
13037 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
13038 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
13039 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
13040 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
13041 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
13042 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
13043 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
13044 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000013045 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
13046 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
13047 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
13048 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013049 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013050 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013051 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013052 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013053 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013054 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000013055 install_element (ENABLE_NODE, &show_bgp_view_cmd);
13056 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
13057 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
13058 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
13059 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
13060 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
13061 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
13062 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
13063 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
13064 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
13065 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
13066 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
13067 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13068 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13069 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
13070 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
13071 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
13072 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013073 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013074 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013075 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013076 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013077 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013078 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000013079
13080 /* Statistics */
13081 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
13082 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
13083 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
13084 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
13085
paul718e3742002-12-13 20:15:29 +000013086 /* old command */
13087 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
13088 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
13089 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
13090 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
13091 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
13092 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
13093 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
13094 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
13095 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
13096 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
13097 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
13098 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
13099 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
13100 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
13101 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
13102 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
13103 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13104 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13105 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
13106 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
13107 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
13108 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
13109 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13110 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
13111 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
13112 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
13113 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
13114 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
13115 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
13116 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
13117 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13118 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13119 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13120 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
13121 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13122 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000013123
paul718e3742002-12-13 20:15:29 +000013124 /* old command */
13125 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
13126 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
13127 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
13128 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
13129 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
13130 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
13131 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
13132 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
13133 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
13134 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
13135 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13136 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13137 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13138 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13139 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13140 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13141 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13142 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13143 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13144 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13145 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13146 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13147 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13148 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13149 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13150 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13151 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13152 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13153 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13154 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13155 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13156 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13157 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13158 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13159 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13160 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13161
13162 /* old command */
13163 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13164 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13165 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13166 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13167
13168 /* old command */
13169 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13170 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13171 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13172 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13173
13174 /* old command */
13175 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13176 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13177 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13178 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13179#endif /* HAVE_IPV6 */
13180
13181 install_element (BGP_NODE, &bgp_distance_cmd);
13182 install_element (BGP_NODE, &no_bgp_distance_cmd);
13183 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13184 install_element (BGP_NODE, &bgp_distance_source_cmd);
13185 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13186 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13187 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13188
13189 install_element (BGP_NODE, &bgp_damp_set_cmd);
13190 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13191 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13192 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13193 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13194 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13195 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13196 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13197 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13198 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013199
13200 /* Deprecated AS-Pathlimit commands */
13201 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13202 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13203 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13204 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13205 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13206 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13207
13208 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13209 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13210 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13211 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13212 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13213 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13214
13215 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13216 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13217 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13218 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13219 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13220 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13221
13222 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13223 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13224 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13225 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13226 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13227 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13228
13229 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13230 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13231 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13232 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13233 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13234 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13235
13236 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13237 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13238 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13239 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13240 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13241 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013242
13243#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013244 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13245 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013246#endif
paul718e3742002-12-13 20:15:29 +000013247}
Chris Caputo228da422009-07-18 05:44:03 +000013248
13249void
13250bgp_route_finish (void)
13251{
13252 bgp_table_unlock (bgp_distance_table);
13253 bgp_distance_table = NULL;
13254}